@emailcheck/email-validator-js
Version:
Advanced email validation with MX records, SMTP verification, disposable email detection, batch processing, and caching. Production-ready with TypeScript support.
47 lines (46 loc) • 1.54 kB
TypeScript
import type { ValidateEmailOptions } from '../../types';
/** Hard limit on batch size enforced by every adapter. */
export declare const MAX_BATCH_SIZE = 100;
/** Shape of POST bodies and Lambda invocations across all serverless adapters. */
export interface ValidationRequestBody {
email?: string;
emails?: string[];
options?: ValidateEmailOptions;
}
export type ValidationDispatch = {
kind: 'single';
email: string;
options?: ValidateEmailOptions;
} | {
kind: 'batch';
emails: string[];
options?: ValidateEmailOptions;
};
export interface ValidationFailure {
kind: 'invalid';
status: 400;
message: string;
}
/**
* Validation for endpoints that accept ONLY a batch (`emails`). Returns
* a 400 failure if emails is missing/empty/oversized, or null when valid.
* Routed `/validate/batch` paths use this so error messages stay batch-specific.
*/
export type BatchValidation = {
ok: true;
emails: string[];
} | {
ok: false;
status: 400;
message: string;
};
export declare function validateBatchEmailsField(emails: unknown): BatchValidation;
/**
* Apply the rules every serverless adapter shares:
* 1. body must request either `email` or `emails`
* 2. `emails` must be a non-empty array of ≤ MAX_BATCH_SIZE entries
*
* Centralising this means a future rule change (say, raising the cap) lands
* in one place instead of three.
*/
export declare function classifyRequest(body: ValidationRequestBody | null | undefined): ValidationDispatch | ValidationFailure;