import {z} from 'zod' export type EmailValidationVerifyRequest = {email: string, TeamId?: string | undefined}; export type CreateApiEmailValidationVerifyArgs = {body: EmailValidationVerifyRequest}; export type CreateApiEmailValidationVerifyOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const emailValidationVerifyResponse = z.object({success: z.boolean().optional(), data: z.object({email: z.string(), valid: z.boolean(), validators: z.record(z.string(), z.unknown()), credits_used: z.number().int(), email_hash: z.string().optional(), domain: z.string().optional(), is_role_based: z.boolean().optional(), is_abuse_email: z.boolean().optional(), is_free_provider: z.boolean().optional(), is_disallowed: z.boolean().optional(), validity_score: z.number().int().gte(0).lte(100).optional(), risk_level: z.enum(["LOW", "MEDIUM", "HIGH", "CRITICAL"]).optional(), confidence: z.enum(["NONE", "LOW", "MEDIUM", "HIGH"]).optional(), email_provider: z.string().nullable().optional(), email_security_service: z.string().nullable().optional(), bounce_type_breakdown: z.record(z.string(), z.unknown()).nullable().optional(), total_sends: z.number().int().optional(), hard_bounce_count: z.number().int().optional(), reply_count: z.number().int().optional(), has_historical_data: z.boolean().optional()}).optional(), request_id: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Verify email (SMTP) * * POST /email-validation/verify */ export const createApiEmailValidationVerify = async (args: CreateApiEmailValidationVerifyArgs, options?: CreateApiEmailValidationVerifyOptions) => { const {baseUrl = "https://api.supersend.io/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/email-validation/verify${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(emailValidationVerifyResponse, await res.json()) };