@emailcheck/email-validator-js 4.0.0 → 5.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +60 -20
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.esm.js +70 -24
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +74 -23
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +242 -33
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -63,55 +63,140 @@ export interface VerificationResult {
|
|
|
63
63
|
transcript?: VerificationStep[];
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* Parameters for
|
|
66
|
+
* Parameters for `verifyEmail` — the high-level orchestrator that runs the
|
|
67
|
+
* full pipeline (syntax → typo / name / domain → disposable / free → WHOIS
|
|
68
|
+
* → MX → SMTP).
|
|
67
69
|
*/
|
|
68
70
|
export interface VerifyEmailParams {
|
|
71
|
+
/** The full email address to verify (`local@domain`). */
|
|
69
72
|
emailAddress: string;
|
|
70
|
-
|
|
73
|
+
/** Resolve MX records via DNS to confirm the domain accepts mail. Default: `true`. */
|
|
71
74
|
verifyMx?: boolean;
|
|
75
|
+
/** Open an SMTP connection to the highest-priority MX and probe `RCPT TO`. Default: `false`. */
|
|
72
76
|
verifySmtp?: boolean;
|
|
73
|
-
|
|
74
|
-
smtpPort?: number;
|
|
77
|
+
/** Check the address against the bundled disposable-provider list. Default: `true`. */
|
|
75
78
|
checkDisposable?: boolean;
|
|
79
|
+
/** Check the address against the bundled free-provider list. Default: `true`. */
|
|
76
80
|
checkFree?: boolean;
|
|
81
|
+
/** Extract first/last name from the local-part. Default: `false` (cheap, but not free). */
|
|
77
82
|
detectName?: boolean;
|
|
78
|
-
|
|
83
|
+
/** Suggest a corrected domain on typos (e.g. `gnail.com` → `gmail.com`). Default: `true`. */
|
|
79
84
|
suggestDomain?: boolean;
|
|
80
|
-
|
|
81
|
-
commonDomains?: string[];
|
|
85
|
+
/** Look up the domain creation date via WHOIS. Slow + external dep. Default: `false`. */
|
|
82
86
|
checkDomainAge?: boolean;
|
|
87
|
+
/** Look up domain registration status (registered / expired / locked). Default: `false`. */
|
|
83
88
|
checkDomainRegistration?: boolean;
|
|
84
|
-
|
|
89
|
+
/**
|
|
90
|
+
* When the address is identified as disposable, skip the (expensive) MX +
|
|
91
|
+
* SMTP probe and accept the disposable verdict as the final answer.
|
|
92
|
+
* Default: `false`.
|
|
93
|
+
*/
|
|
85
94
|
skipMxForDisposable?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* When the address is identified as disposable, skip the WHOIS checks too.
|
|
97
|
+
* Default: `false`.
|
|
98
|
+
*/
|
|
86
99
|
skipDomainWhoisForDisposable?: boolean;
|
|
100
|
+
/** Override the default name-detection heuristic. Receives the email; returns `DetectedName | null`. */
|
|
101
|
+
nameDetectionMethod?: NameDetectionMethod;
|
|
102
|
+
/** Override the default domain-suggestion heuristic. Receives the domain; returns `DomainSuggestion | null`. */
|
|
103
|
+
domainSuggestionMethod?: DomainSuggestionMethod;
|
|
104
|
+
/** Custom domain list for the typo suggester. Defaults to the bundled common-domain set. */
|
|
105
|
+
commonDomains?: string[];
|
|
106
|
+
/**
|
|
107
|
+
* Per-attempt timeout for the SMTP probe, in milliseconds. Bounds both the
|
|
108
|
+
* TCP/TLS connection setup AND the inactivity gap between SMTP commands
|
|
109
|
+
* within an attempt. Default: `4000` ms.
|
|
110
|
+
*
|
|
111
|
+
* To bound the total wall-clock across all MX × port attempts, use
|
|
112
|
+
* `smtpTotalDeadlineMs` instead. To control retries on connection-class
|
|
113
|
+
* failures, use `smtpRetry`.
|
|
114
|
+
*/
|
|
115
|
+
smtpPerAttemptTimeoutMs?: number;
|
|
116
|
+
/**
|
|
117
|
+
* Hard cap on total wall-clock time for the SMTP probe across all MX × port
|
|
118
|
+
* × retry attempts. Reasonable when calling from a request handler with a
|
|
119
|
+
* tight latency budget. Default: unbounded.
|
|
120
|
+
*/
|
|
121
|
+
smtpTotalDeadlineMs?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Stop the SMTP probe after this many connection-class failures in a row
|
|
124
|
+
* (counting `connection_error` / `connection_timeout` / `connection_closed`
|
|
125
|
+
* across MX × port attempts). Resets on any non-connection-class outcome.
|
|
126
|
+
* Default: unbounded.
|
|
127
|
+
*/
|
|
128
|
+
smtpMaxConsecutiveFailures?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Hard cap on how many MX hostnames the SMTP probe will try, regardless of
|
|
131
|
+
* how many DNS returned. Default: unbounded — try them all.
|
|
132
|
+
*/
|
|
133
|
+
smtpMaxMxHosts?: number;
|
|
134
|
+
/** Optional retry policy for connection-class failures on a single MX × port. Default: no retries. */
|
|
135
|
+
smtpRetry?: RetryPolicy;
|
|
136
|
+
/**
|
|
137
|
+
* Force a specific port for the SMTP probe (e.g. `587`). When set, this
|
|
138
|
+
* port is the only one tried — overrides the default `[25, 587, 465]` walk
|
|
139
|
+
* and any per-MX hint cached from a previous probe.
|
|
140
|
+
*/
|
|
141
|
+
smtpPort?: number;
|
|
142
|
+
/** Per-WHOIS-query timeout in milliseconds. Default: `5000`. */
|
|
143
|
+
whoisTimeoutMs?: number;
|
|
144
|
+
/** Optional shared cache for MX, WHOIS, disposable / free, SMTP, and domain results. */
|
|
87
145
|
cache?: Cache;
|
|
146
|
+
/** When true, the pipeline writes a per-line trace to `console.debug`. Default: `false`. */
|
|
147
|
+
debug?: boolean;
|
|
88
148
|
/**
|
|
89
|
-
* When true, populates `result.transcript` with a per-step trace
|
|
90
|
-
* every subsystem (syntax / disposable / free / MX / SMTP / WHOIS /
|
|
91
|
-
* detection / domain suggestion). Each step records timing +
|
|
92
|
-
*
|
|
93
|
-
*
|
|
149
|
+
* When true, populates `result.transcript` with a per-step structured trace
|
|
150
|
+
* covering every subsystem (syntax / disposable / free / MX / SMTP / WHOIS /
|
|
151
|
+
* name detection / domain suggestion). Each step records timing +
|
|
152
|
+
* step-specific details (raw WHOIS data, SMTP transcript, MX records, cache
|
|
153
|
+
* hit/miss, etc.). Safe to leave off for production; turn on for diagnostics
|
|
154
|
+
* or debug UIs. Default: `false`.
|
|
94
155
|
*/
|
|
95
156
|
captureTranscript?: boolean;
|
|
96
157
|
}
|
|
97
158
|
/**
|
|
98
|
-
* Parameters for
|
|
159
|
+
* Parameters for `verifyEmailBatch` — fan-out wrapper around `verifyEmail`
|
|
160
|
+
* that runs many addresses through the same pipeline with a concurrency cap.
|
|
99
161
|
*/
|
|
100
162
|
export interface BatchVerifyParams {
|
|
163
|
+
/** Email addresses to verify, in order. */
|
|
101
164
|
emailAddresses: string[];
|
|
165
|
+
/** Maximum number of in-flight `verifyEmail` calls. Default: `5`. */
|
|
102
166
|
concurrency?: number;
|
|
103
|
-
timeout
|
|
167
|
+
/** Per-attempt SMTP timeout in milliseconds (forwarded to each `verifyEmail` call). Default: `4000`. */
|
|
168
|
+
smtpPerAttemptTimeoutMs?: number;
|
|
169
|
+
/** Hard cap on total wall-clock for each individual SMTP probe. Forwarded to `verifyEmail`. */
|
|
170
|
+
smtpTotalDeadlineMs?: number;
|
|
171
|
+
/** Stop each individual SMTP probe after this many connection-class failures in a row. */
|
|
172
|
+
smtpMaxConsecutiveFailures?: number;
|
|
173
|
+
/** Hard cap on MX hostnames per individual SMTP probe. */
|
|
174
|
+
smtpMaxMxHosts?: number;
|
|
175
|
+
/** Optional retry policy per MX×port for each individual SMTP probe. */
|
|
176
|
+
smtpRetry?: RetryPolicy;
|
|
177
|
+
/** Resolve MX records per address. Default: `true`. */
|
|
104
178
|
verifyMx?: boolean;
|
|
179
|
+
/** Run the SMTP probe per address. Default: `false`. */
|
|
105
180
|
verifySmtp?: boolean;
|
|
181
|
+
/** Check disposable list per address. Default: `true`. */
|
|
106
182
|
checkDisposable?: boolean;
|
|
183
|
+
/** Check free-provider list per address. Default: `true`. */
|
|
107
184
|
checkFree?: boolean;
|
|
185
|
+
/** Extract first/last name from each local-part. Default: `false`. */
|
|
108
186
|
detectName?: boolean;
|
|
187
|
+
/** Override the name-detection heuristic. */
|
|
109
188
|
nameDetectionMethod?: NameDetectionMethod;
|
|
189
|
+
/** Suggest a corrected domain on typos. Default: `false` for batches (it's per-call cost). */
|
|
110
190
|
suggestDomain?: boolean;
|
|
191
|
+
/** Override the domain-suggestion heuristic. */
|
|
111
192
|
domainSuggestionMethod?: DomainSuggestionMethod;
|
|
193
|
+
/** Custom canonical-domain list for the typo suggester. */
|
|
112
194
|
commonDomains?: string[];
|
|
195
|
+
/** Skip MX/SMTP probe for disposable addresses. Default: `false`. */
|
|
113
196
|
skipMxForDisposable?: boolean;
|
|
197
|
+
/** Skip WHOIS lookups for disposable addresses. Default: `false`. */
|
|
114
198
|
skipDomainWhoisForDisposable?: boolean;
|
|
199
|
+
/** Optional shared cache (re-used across all addresses in the batch). */
|
|
115
200
|
cache?: Cache;
|
|
116
201
|
}
|
|
117
202
|
/**
|
|
@@ -282,47 +367,171 @@ export interface SMTPSequence {
|
|
|
282
367
|
/** Override MAIL FROM payload — supply with angle brackets or `<>` for null sender. */
|
|
283
368
|
from?: string;
|
|
284
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Optional retry policy for connection-class failures (timeout / connection
|
|
372
|
+
* error / connection closed) on a single MX × port. Definitive answers
|
|
373
|
+
* (250 / 550 / 552 / etc.) are never retried — they're stable verdicts.
|
|
374
|
+
*/
|
|
375
|
+
export interface RetryPolicy {
|
|
376
|
+
/**
|
|
377
|
+
* How many extra attempts to make on the same MX × port after a
|
|
378
|
+
* connection-class failure. `0` means no retry (the default).
|
|
379
|
+
*/
|
|
380
|
+
attempts: number;
|
|
381
|
+
/**
|
|
382
|
+
* Delay between retries, in milliseconds. With `backoff: 'exponential'`
|
|
383
|
+
* (the default), the actual delay is `delayMs * 2^(attemptIndex - 1)`.
|
|
384
|
+
* Default: `200` ms.
|
|
385
|
+
*/
|
|
386
|
+
delayMs?: number;
|
|
387
|
+
/**
|
|
388
|
+
* Backoff strategy between retries.
|
|
389
|
+
* - `'exponential'` (default): `delayMs * 2^(attemptIndex - 1)`.
|
|
390
|
+
* - `'fixed'`: every retry waits `delayMs` exactly.
|
|
391
|
+
*/
|
|
392
|
+
backoff?: 'exponential' | 'fixed';
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Options for `verifyMailboxSMTP` and `verifyEmail`'s SMTP probe.
|
|
396
|
+
*
|
|
397
|
+
* Time-budget defaults are tuned for a 4-MX × 3-port worst case. If you
|
|
398
|
+
* call this from a request handler with a tight latency budget, set
|
|
399
|
+
* `totalDeadlineMs` so the probe gives up before your handler does.
|
|
400
|
+
*/
|
|
285
401
|
export interface SMTPVerifyOptions {
|
|
402
|
+
/**
|
|
403
|
+
* Ports to walk per MX, in priority order. The probe stops on the first
|
|
404
|
+
* port that yields a definitive answer; indeterminate outcomes (timeout /
|
|
405
|
+
* connection error / etc.) fall through to the next port.
|
|
406
|
+
*
|
|
407
|
+
* Default: `[25, 587, 465]` — plain → STARTTLS-able → implicit-TLS.
|
|
408
|
+
*/
|
|
286
409
|
ports?: number[];
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Per-attempt timeout in milliseconds. Bounds both the TCP/TLS connection
|
|
412
|
+
* setup AND the inactivity gap between SMTP commands within an attempt.
|
|
413
|
+
* Each MX × port pair gets its own budget — to bound the total wall-clock,
|
|
414
|
+
* use `totalDeadlineMs` instead.
|
|
415
|
+
*
|
|
416
|
+
* Default: `3000` ms.
|
|
417
|
+
*/
|
|
418
|
+
perAttemptTimeoutMs?: number;
|
|
419
|
+
/**
|
|
420
|
+
* TLS configuration applied to implicit-TLS ports (465) and to STARTTLS
|
|
421
|
+
* upgrades on plaintext ports.
|
|
422
|
+
*
|
|
423
|
+
* - `true` (default): use sensible TLS defaults (`rejectUnauthorized: false`,
|
|
424
|
+
* `minVersion: 'TLSv1.2'`) — picks up CA quirks of long-tail MXes.
|
|
425
|
+
* - `false`: disable TLS entirely (port 465 will fail to handshake; STARTTLS
|
|
426
|
+
* step is skipped).
|
|
427
|
+
* - `SMTPTLSConfig` object: override individual fields. Merged onto the defaults.
|
|
428
|
+
*/
|
|
429
|
+
tlsConfig?: boolean | SMTPTLSConfig;
|
|
430
|
+
/**
|
|
431
|
+
* Hostname this client identifies itself as in the `EHLO` / `HELO` argument.
|
|
432
|
+
* Should be a real FQDN — `localhost` from a public IP is a textbook spam-bot
|
|
433
|
+
* signature and gets rejected by careful MXes.
|
|
434
|
+
*
|
|
435
|
+
* Default: `'localhost'`. Override with your delivery domain in production.
|
|
436
|
+
*/
|
|
437
|
+
heloHostname?: string;
|
|
438
|
+
/**
|
|
439
|
+
* Optional cache instance. When provided, the probe reuses prior verdicts
|
|
440
|
+
* keyed on `<primary mx>:<local>@<domain>` and remembers the last
|
|
441
|
+
* successful port per primary MX (so a re-probe skips the failed-port
|
|
442
|
+
* walk).
|
|
443
|
+
*
|
|
444
|
+
* Pass `null` or omit to skip caching entirely.
|
|
445
|
+
*/
|
|
290
446
|
cache?: Cache | null;
|
|
447
|
+
/**
|
|
448
|
+
* When true, a per-line `[SMTP] …` trace is written to `console.log`.
|
|
449
|
+
* Useful for diagnosing real-MX behavior; off by default for production.
|
|
450
|
+
*/
|
|
291
451
|
debug?: boolean;
|
|
292
452
|
/**
|
|
293
|
-
* When true, the returned `SmtpVerificationResult` carries `transcript`
|
|
294
|
-
* `commands` arrays prefixed with `<host>:<port>|s| …` /
|
|
295
|
-
* Aggregated across every
|
|
453
|
+
* When true, the returned `SmtpVerificationResult` carries `transcript`
|
|
454
|
+
* and `commands` arrays prefixed with `<host>:<port>|s| …` /
|
|
455
|
+
* `<host>:<port>|c| …`. Aggregated across every MX × port attempted.
|
|
296
456
|
*
|
|
297
|
-
* Default: `false`. The strings are O(
|
|
298
|
-
* need the trace.
|
|
457
|
+
* Default: `false`. The strings are O(N × wire-bytes); skip when you
|
|
458
|
+
* don't need the trace.
|
|
299
459
|
*/
|
|
300
460
|
captureTranscript?: boolean;
|
|
461
|
+
/**
|
|
462
|
+
* Hard cap on total wall-clock time for the entire probe (across all
|
|
463
|
+
* MX × port × retry attempts). When the deadline passes, the in-flight
|
|
464
|
+
* attempt is allowed to finish (it has its own per-attempt budget) and
|
|
465
|
+
* no new attempts are started.
|
|
466
|
+
*
|
|
467
|
+
* Use this to bound latency from a request-handler caller. A reasonable
|
|
468
|
+
* value matches your handler's deadline minus headroom for everything
|
|
469
|
+
* else it does.
|
|
470
|
+
*
|
|
471
|
+
* Default: unbounded — only `perAttemptTimeoutMs × ports.length × mxRecords.length`
|
|
472
|
+
* limits the worst case (e.g. `3000 × 3 × 4 = 36s`).
|
|
473
|
+
*/
|
|
474
|
+
totalDeadlineMs?: number;
|
|
475
|
+
/**
|
|
476
|
+
* Stop probing after this many connection-class failures in a row.
|
|
477
|
+
* Counts consecutive `connection_error` / `connection_timeout` /
|
|
478
|
+
* `connection_closed` outcomes across MX × port attempts; resets on any
|
|
479
|
+
* non-connection-class outcome. Useful for cutting off probes when the
|
|
480
|
+
* network path to the MX is wholly unreachable instead of waiting for
|
|
481
|
+
* every port × MX combination to time out.
|
|
482
|
+
*
|
|
483
|
+
* Default: unbounded.
|
|
484
|
+
*/
|
|
485
|
+
maxConsecutiveFailures?: number;
|
|
486
|
+
/**
|
|
487
|
+
* Hard cap on how many MX hostnames to try, regardless of how many were
|
|
488
|
+
* supplied in `mxRecords`. The probe walks them in priority order
|
|
489
|
+
* (`mxRecords[0]` first) and stops after this many.
|
|
490
|
+
*
|
|
491
|
+
* Default: unbounded.
|
|
492
|
+
*/
|
|
493
|
+
maxMxHosts?: number;
|
|
494
|
+
/**
|
|
495
|
+
* Optional retry policy for connection-class failures on a single MX × port.
|
|
496
|
+
* Definitive answers (250 / 550 / 552 / 421 / etc.) are never retried —
|
|
497
|
+
* they're stable verdicts.
|
|
498
|
+
*
|
|
499
|
+
* Default: no retries.
|
|
500
|
+
*/
|
|
501
|
+
retry?: RetryPolicy;
|
|
502
|
+
/**
|
|
503
|
+
* Override the per-attempt SMTP step list. Defaults to
|
|
504
|
+
* `[greeting, ehlo, startTls, mailFrom, rcptTo]` — covering the entire
|
|
505
|
+
* RFC 5321 envelope plus optional TLS upgrade. Most callers never need
|
|
506
|
+
* to override this; useful for advanced testing scenarios (e.g. probe
|
|
507
|
+
* RFC compliance with `[greeting, helo, mailFrom, rcptTo]`).
|
|
508
|
+
*/
|
|
301
509
|
sequence?: SMTPSequence;
|
|
302
510
|
/**
|
|
303
|
-
* Override the random
|
|
304
|
-
* Useful for deterministic tests; receives the real local-part
|
|
305
|
-
* so callers can derive a probe-local that matches the MX's
|
|
511
|
+
* Override the random local-part generator used by the catch-all dual
|
|
512
|
+
* probe. Useful for deterministic tests; receives the real local-part
|
|
513
|
+
* and domain so callers can derive a probe-local that matches the MX's
|
|
514
|
+
* syntax rules.
|
|
306
515
|
*
|
|
307
516
|
* Default: `<16 hex chars>-noexist` — long enough to never collide,
|
|
308
|
-
* structured so it's clearly synthetic and passes common syntax filters.
|
|
517
|
+
* structured so it's clearly synthetic, and passes common syntax filters.
|
|
309
518
|
*/
|
|
310
519
|
catchAllProbeLocal?: (realLocal: string, domain: string) => string;
|
|
311
520
|
/**
|
|
312
|
-
*
|
|
521
|
+
* SMTP PIPELINING (RFC 2920) — batch the envelope phase
|
|
313
522
|
* (RCPT TO real + RCPT TO probe + RSET) into one `socket.write()` when
|
|
314
523
|
* the MX advertises support.
|
|
315
524
|
*
|
|
316
|
-
* - `'auto'` (default): pipeline when EHLO multi-line includes
|
|
317
|
-
*
|
|
525
|
+
* - `'auto'` (default): pipeline when EHLO multi-line includes `PIPELINING`,
|
|
526
|
+
* sequential otherwise.
|
|
318
527
|
* - `'never'`: always sequential — useful for deterministic wire-level
|
|
319
|
-
* assertions in tests
|
|
528
|
+
* assertions in tests or when investigating a pipeline-buggy MX.
|
|
320
529
|
* - `'force'`: pipeline without checking — testing escape hatch.
|
|
321
530
|
*/
|
|
322
531
|
pipelining?: 'auto' | 'never' | 'force';
|
|
323
532
|
/**
|
|
324
|
-
*
|
|
325
|
-
*
|
|
533
|
+
* STARTTLS upgrade on plaintext ports (25, 587). Implicit-TLS ports (465)
|
|
534
|
+
* ignore this option — they're already TLS from the start.
|
|
326
535
|
*
|
|
327
536
|
* - `'auto'` (default): upgrade if the MX advertises STARTTLS in EHLO.
|
|
328
537
|
* Submission-port (587) MXes typically require this — without it,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emailcheck/email-validator-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Advanced email validation with MX records, SMTP verification, disposable email detection, batch processing, and caching. Production-ready with TypeScript support.",
|
|
6
6
|
"keywords": [
|