import type { ContactData, ContactField } from '../types'; import { type BrandConfig } from '../email/template'; import { type RateLimitConfig } from './rate-limit'; export interface ContactRouteResendConfig { /** Resend API key (read from env in the consuming app and passed here). */ apiKey: string; /** Sender, e.g. `"Acme "`. Domain must be verified in Resend. */ from: string; /** Recipient(s) of the notification email. */ to: string | string[]; /** * Which field becomes the email Reply-To. Defaults to the first `email` * field in the schema. Set to `null` to disable. */ replyToField?: string | null; } export interface ContactRouteTurnstileConfig { /** Turnstile secret key. */ secretKey: string; /** * When `false`, a failed/missing token is tolerated (verify-if-present). * Default `true` (a valid token is required). */ required?: boolean; } export interface ContactRouteHoneypotConfig { /** Disable the honeypot + time-trap entirely. Default enabled. */ enabled?: boolean; /** Minimum fill time in ms. Default 2000. */ minFillMs?: number; /** Maximum form age in ms. Default 30 minutes. */ maxAgeMs?: number; } export interface ContactSubmissionContext { data: ContactData; ip: string | null; userAgent: string | null; } export interface ContactRouteConfig { /** Field schema. Drives validation and the email layout. */ fields: ReadonlyArray; /** Resend delivery config. */ resend: ContactRouteResendConfig; /** Branding for the default email template. */ brand?: BrandConfig; /** Subject line or builder for the default template. */ subject?: string | ((data: ContactData) => string); /** Lead paragraph for the default template. */ intro?: string; /** * Provide your own email renderer instead of the built-in template. * Receives the validated data + request metadata. */ render?: (ctx: ContactSubmissionContext & { fields: ReadonlyArray; }) => { subject: string; html: string; }; /** Cloudflare Turnstile. Omit to skip captcha verification. */ turnstile?: ContactRouteTurnstileConfig; /** Honeypot + time-trap. Enabled by default. */ honeypot?: ContactRouteHoneypotConfig; /** Rate limiting. Pass `false` to disable, omit for in-memory defaults. */ rateLimit?: RateLimitConfig | false; /** * Optional side effect run before the email is sent (persist to a DB / CRM). * If it throws, the request fails with `server_error` and no email is sent. */ onSubmit?: (ctx: ContactSubmissionContext) => void | Promise; /** Attach IP + user-agent to the email and `onSubmit`. Default `true`. */ includeMeta?: boolean; } /** A Web-standard POST handler — assign it to `export const POST` in a route. */ export type ContactRouteHandler = (request: Request) => Promise; /** * Build a framework-neutral contact POST handler. Works as a Next.js App * Router route handler (`export const POST = createContactRoute(...)`) or in * any runtime that speaks the Fetch `Request`/`Response` API. * * Pipeline (cheapest checks first): parse → honeypot → validate → rate-limit * → Turnstile → onSubmit → email. */ export declare function createContactRoute(config: ContactRouteConfig): ContactRouteHandler; //# sourceMappingURL=create-route.d.ts.map