-
Notifications
You must be signed in to change notification settings - Fork 453
Add Mailcheck integration: verify email and validate domain #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import type { ApiRequestOptions } from 'corsair/http'; | ||
| import type { OpenAPIConfig } from 'corsair/http'; | ||
| import { request } from 'corsair/http'; | ||
|
|
||
| export class MailcheckAPIError extends Error { | ||
| constructor( | ||
| message: string, | ||
| public readonly code?: string, | ||
| ) { | ||
| super(message); | ||
| this.name = 'MailcheckAPIError'; | ||
| } | ||
| } | ||
|
|
||
| // TODO: Update with your API base URL | ||
| const MAILCHECK_API_BASE = 'https://api.mailcheck.ing/v1'; | ||
|
|
||
| export async function makeMailcheckRequest<T>( | ||
| endpoint: string, | ||
| apiKey: string, | ||
| options: { | ||
| method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; | ||
| body?: Record<string, unknown>; | ||
| query?: Record<string, string | number | boolean | undefined>; | ||
| } = {}, | ||
| ): Promise<T> { | ||
| const { method = 'GET', body, query } = options; | ||
|
|
||
| const config: OpenAPIConfig = { | ||
| BASE: MAILCHECK_API_BASE, | ||
| VERSION: '1.0.0', | ||
| WITH_CREDENTIALS: false, | ||
| CREDENTIALS: 'omit', | ||
| TOKEN: apiKey, | ||
| HEADERS: { | ||
| 'Content-Type': 'application/json', | ||
|
|
||
| 'Authorization': apiKey, | ||
| }, | ||
| }; | ||
|
|
||
| const requestOptions: ApiRequestOptions = { | ||
| method, | ||
| url: endpoint, | ||
| body: | ||
| method === 'POST' || method === 'PUT' || method === 'PATCH' | ||
| ? body | ||
| : undefined, | ||
| mediaType: 'application/json; charset=utf-8', | ||
| query: method === 'GET' ? query : undefined, | ||
| }; | ||
|
|
||
| try { | ||
| return await request<T>(config, requestOptions); | ||
| } catch (error) { | ||
| if (error instanceof Error) { | ||
| throw new MailcheckAPIError(error.message); | ||
| } | ||
| throw new MailcheckAPIError('Unknown error'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { verifyEmail } from './verify-email'; | ||
| import { validateDomain } from './validate-domain'; | ||
|
|
||
| export const Mailcheck = { | ||
| verifyEmail, | ||
| validateDomain, | ||
| }; | ||
|
|
||
| export * from './types'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| const VerifyEmailInputSchema = z.object({ | ||
| email: z.string(), | ||
| verify: z.boolean().optional(), | ||
| check_breach: z.boolean().optional(), | ||
| }); | ||
| export type VerifyEmailInput = z.infer<typeof VerifyEmailInputSchema>; | ||
|
|
||
| const VerifyEmailResponseSchema = z.object({ | ||
| email: z.string(), | ||
| }).passthrough(); | ||
| export type VerifyEmailResponse = z.infer<typeof VerifyEmailResponseSchema>; | ||
|
|
||
| const ValidateDomainInputSchema = z.object({ | ||
| domain: z.string(), | ||
| }); | ||
| export type ValidateDomainInput = z.infer<typeof ValidateDomainInputSchema>; | ||
|
|
||
| const ValidateDomainResponseSchema = z.object({ | ||
| domain: z.string(), | ||
| }).passthrough(); | ||
| export type ValidateDomainResponse = z.infer<typeof ValidateDomainResponseSchema>; | ||
|
|
||
| export type MailcheckEndpointInputs = { | ||
| verifyEmail: VerifyEmailInput; | ||
| validateDomain: ValidateDomainInput; | ||
| }; | ||
|
|
||
| export type MailcheckEndpointOutputs = { | ||
| verifyEmail: VerifyEmailResponse; | ||
| validateDomain: ValidateDomainResponse; | ||
| }; | ||
|
|
||
| export const MailcheckEndpointInputSchemas = { | ||
| verifyEmail: VerifyEmailInputSchema, | ||
| validateDomain: ValidateDomainInputSchema, | ||
| } as const; | ||
|
|
||
| export const MailcheckEndpointOutputSchemas = { | ||
| verifyEmail: VerifyEmailResponseSchema, | ||
| validateDomain: ValidateDomainResponseSchema, | ||
| } as const; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||||||||||||||
| import { logEventFromContext } from 'corsair/core'; | ||||||||||||||||||
| import type { MailcheckEndpoints } from '..'; | ||||||||||||||||||
| import type { MailcheckEndpointOutputs } from './types'; | ||||||||||||||||||
| import { makeMailcheckRequest } from '../client'; | ||||||||||||||||||
|
|
||||||||||||||||||
| export const validateDomain: MailcheckEndpoints['validateDomain'] = async (ctx, input) => { | ||||||||||||||||||
| const response = await makeMailcheckRequest<MailcheckEndpointOutputs['validateDomain']>( | ||||||||||||||||||
| `domain/${input.domain}`, | ||||||||||||||||||
| ctx.key, | ||||||||||||||||||
| { method: 'GET' }, | ||||||||||||||||||
|
Comment on lines
+7
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Encode The input schema accepts arbitrary strings. A value that contains Proposed change- `domain/${input.domain}`,
+ `domain/${encodeURIComponent(input.domain)}`,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| await logEventFromContext(ctx, 'mailcheck.validate_domain', { ...input }, 'completed'); | ||||||||||||||||||
| return response; | ||||||||||||||||||
| }; | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||
| import { logEventFromContext } from 'corsair/core'; | ||||||||||||||||||||||
| import type { MailcheckEndpoints } from '..'; | ||||||||||||||||||||||
| import type { MailcheckEndpointOutputs } from './types'; | ||||||||||||||||||||||
| import { makeMailcheckRequest } from '../client'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export const verifyEmail: MailcheckEndpoints['verifyEmail'] = async (ctx, input) => { | ||||||||||||||||||||||
| const response = await makeMailcheckRequest<MailcheckEndpointOutputs['verifyEmail']>( | ||||||||||||||||||||||
| 'verify', | ||||||||||||||||||||||
| ctx.key, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| method: 'POST', | ||||||||||||||||||||||
| body: { | ||||||||||||||||||||||
| email: input.email, | ||||||||||||||||||||||
| verify: input.verify ?? true, | ||||||||||||||||||||||
| check_breach: input.check_breach ?? false, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| await logEventFromContext(ctx, 'mailcheck.verify_email', { ...input }, 'completed'); | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Do not persist the raw email address in the event payload. Line 20 sends Proposed change-await logEventFromContext(ctx, 'mailcheck.verify_email', { ...input }, 'completed');
+await logEventFromContext(
+ ctx,
+ 'mailcheck.verify_email',
+ {
+ verify: input.verify ?? true,
+ check_breach: input.check_breach ?? false,
+ },
+ 'completed',
+);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| return response; | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { ApiError } from 'corsair/http'; | ||
| import type { CorsairErrorHandler } from 'corsair/core'; | ||
|
|
||
| export const errorHandlers = { | ||
| RATE_LIMIT_ERROR: { | ||
| match: (error: Error) => { | ||
| if (error instanceof ApiError && error.status === 429) return true; | ||
| const msg = error.message.toLowerCase(); | ||
| return msg.includes('rate_limited') || msg.includes('429'); | ||
| }, | ||
| handler: async (error: Error) => { | ||
| let retryAfterMs: number | undefined; | ||
| if (error instanceof ApiError && error.retryAfter !== undefined) { | ||
| retryAfterMs = error.retryAfter; | ||
| } | ||
| return { maxRetries: 5, headersRetryAfterMs: retryAfterMs }; | ||
| }, | ||
| }, | ||
| AUTH_ERROR: { | ||
| match: (error: Error) => { | ||
| if (error instanceof ApiError && error.status === 401) return true; | ||
| const msg = error.message.toLowerCase(); | ||
| return msg.includes('unauthorized') || msg.includes('invalid_auth'); | ||
| }, | ||
| handler: async () => ({ maxRetries: 0 }), | ||
| }, | ||
| DEFAULT: { | ||
| match: () => true, | ||
| handler: async () => ({ maxRetries: 0 }), | ||
| }, | ||
| } satisfies CorsairErrorHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The published plugin still registers generator placeholders and unfinished OAuth and webhook tenant-routing logic; ordinary OAuth responses without the placeholder
tenant_external_idreturn no tenant link, preventing dependable webhook routing.Rule Used: Flag boilerplate residue from the plugin generator... (source)
Knowledge Base Used: The provider-plugin package pattern