bouncevalidator 0.0.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.
@@ -0,0 +1,398 @@
1
+ /**
2
+ * Reachability status of an email address
3
+ */
4
+ type Reachability = "safe" | "invalid" | "risky" | "unknown";
5
+ /**
6
+ * Syntax validation result
7
+ */
8
+ interface SyntaxResult {
9
+ /** The original email address */
10
+ address: string;
11
+ /** The domain part of the email */
12
+ domain: string;
13
+ /** The username/local part of the email */
14
+ username: string;
15
+ /** Whether the email has valid syntax */
16
+ isValidSyntax: boolean;
17
+ /** Normalized email address (lowercase, trimmed) */
18
+ normalizedEmail: string;
19
+ /** Suggested correction for common typos */
20
+ suggestion: string | null;
21
+ }
22
+ /**
23
+ * MX record verification result
24
+ */
25
+ interface MxResult {
26
+ /** Whether the domain accepts mail */
27
+ acceptsMail: boolean;
28
+ /** List of MX records found */
29
+ records: string[];
30
+ }
31
+ /**
32
+ * SMTP error information
33
+ */
34
+ interface SmtpError {
35
+ /** Type of error encountered */
36
+ type: string;
37
+ /** Human-readable error message */
38
+ message: string;
39
+ }
40
+ /**
41
+ * SMTP verification result
42
+ */
43
+ interface SmtpResult {
44
+ /** Whether SMTP verification was successful */
45
+ canConnectSmtp: boolean;
46
+ /** Whether the mailbox exists */
47
+ isDeliverable: boolean;
48
+ /** Whether the server is a catch-all */
49
+ isCatchAll: boolean;
50
+ /** Error information if verification failed */
51
+ error: SmtpError | null;
52
+ }
53
+ /**
54
+ * Miscellaneous email information
55
+ */
56
+ interface MiscResult {
57
+ /** Whether the email is from a disposable domain */
58
+ isDisposable: boolean;
59
+ /** Whether the email is a role-based account */
60
+ isRoleAccount: boolean;
61
+ /** Whether the email is from a free provider */
62
+ isFreeProvider: boolean;
63
+ /** Gravatar URL if available */
64
+ gravatarUrl: string | null;
65
+ }
66
+ /**
67
+ * Complete email validation result
68
+ */
69
+ interface ValidationResult {
70
+ /** The original input email */
71
+ input: string;
72
+ /** Overall reachability status */
73
+ isReachable: Reachability;
74
+ /** Syntax validation result */
75
+ syntax: SyntaxResult;
76
+ /** MX record verification result */
77
+ mx: MxResult;
78
+ /** SMTP verification result */
79
+ smtp: SmtpResult;
80
+ /** Miscellaneous information */
81
+ misc: MiscResult;
82
+ }
83
+ /**
84
+ * Configuration options for email validation
85
+ */
86
+ interface ValidationOptions {
87
+ /** SMTP connection timeout in milliseconds (default: 10000) */
88
+ smtpTimeout?: number;
89
+ /** Whether to perform SMTP verification (default: true) */
90
+ verifySmtp?: boolean;
91
+ /** Whether to check for disposable emails (default: true) */
92
+ checkDisposable?: boolean;
93
+ /** Whether to check for role-based accounts (default: true) */
94
+ checkRoleAccount?: boolean;
95
+ /** Whether to check for free providers (default: true) */
96
+ checkFreeProvider?: boolean;
97
+ /** Whether to check for Gravatar (default: false) */
98
+ checkGravatar?: boolean;
99
+ /** Custom HELO/EHLO hostname */
100
+ heloHost?: string;
101
+ /** Custom sender address for MAIL FROM */
102
+ senderAddress?: string;
103
+ /** DNS cache TTL in milliseconds (default: 300000 = 5 minutes) */
104
+ dnsCacheTtl?: number;
105
+ /** Whether to use DNS cache (default: true) */
106
+ useDnsCache?: boolean;
107
+ /** Whether to detect catch-all domains (default: true) */
108
+ detectCatchAll?: boolean;
109
+ /** Proxy configuration for SMTP connections */
110
+ proxy?: {
111
+ host: string;
112
+ port: number;
113
+ type: "socks4" | "socks5" | "http";
114
+ };
115
+ }
116
+ /**
117
+ * Options for bulk validation
118
+ */
119
+ interface BulkValidationOptions extends ValidationOptions {
120
+ /** Maximum concurrent validations (default: 5) */
121
+ concurrency?: number;
122
+ /** Delay between validations in milliseconds (default: 0) */
123
+ delayBetween?: number;
124
+ /** Callback for progress updates */
125
+ onProgress?: (completed: number, total: number, result: ValidationResult) => void;
126
+ }
127
+ /**
128
+ * DNS cache entry
129
+ */
130
+ interface DnsCacheEntry {
131
+ /** Cached MX records */
132
+ records: string[];
133
+ /** Whether the domain accepts mail */
134
+ acceptsMail: boolean;
135
+ /** Timestamp when the entry was cached */
136
+ timestamp: number;
137
+ }
138
+
139
+ /**
140
+ * Validate email syntax
141
+ * @param email The email address to validate
142
+ * @returns SyntaxResult with validation details
143
+ */
144
+ declare function validateSyntax(email: string): SyntaxResult;
145
+ /**
146
+ * Quick check if an email has valid syntax
147
+ * @param email The email to check
148
+ * @returns true if syntax is valid
149
+ */
150
+ declare function isValidSyntax(email: string): boolean;
151
+
152
+ /**
153
+ * Simple in-memory DNS cache with TTL support
154
+ */
155
+ declare class DnsCache {
156
+ private cache;
157
+ private ttl;
158
+ /**
159
+ * Create a new DNS cache
160
+ * @param ttl Time-to-live in milliseconds (default: 5 minutes)
161
+ */
162
+ constructor(ttl?: number);
163
+ /**
164
+ * Get a cached entry for a domain
165
+ * @param domain The domain to look up
166
+ * @returns The cached entry or null if not found/expired
167
+ */
168
+ get(domain: string): DnsCacheEntry | null;
169
+ /**
170
+ * Set a cache entry for a domain
171
+ * @param domain The domain to cache
172
+ * @param records The MX records
173
+ * @param acceptsMail Whether the domain accepts mail
174
+ */
175
+ set(domain: string, records: string[], acceptsMail: boolean): void;
176
+ /**
177
+ * Clear all cached entries
178
+ */
179
+ clear(): void;
180
+ /**
181
+ * Remove expired entries from the cache
182
+ */
183
+ cleanup(): void;
184
+ /**
185
+ * Get the number of cached entries
186
+ */
187
+ get size(): number;
188
+ /**
189
+ * Set the TTL for the cache
190
+ * @param ttl Time-to-live in milliseconds
191
+ */
192
+ setTtl(ttl: number): void;
193
+ }
194
+ declare const globalDnsCache: DnsCache;
195
+
196
+ /**
197
+ * Verify MX records for a domain
198
+ * @param domain The domain to verify
199
+ * @param options Validation options
200
+ * @returns MxResult with verification details
201
+ */
202
+ declare function verifyMx(domain: string, options?: ValidationOptions, cache?: DnsCache): Promise<MxResult>;
203
+ /**
204
+ * Check if a domain has valid MX records
205
+ * @param domain The domain to check
206
+ * @returns true if domain has valid MX records
207
+ */
208
+ declare function hasMxRecords(domain: string): Promise<boolean>;
209
+ /**
210
+ * Get MX records for a domain, sorted by priority
211
+ * @param domain The domain to lookup
212
+ * @returns Array of MX hostnames sorted by priority
213
+ */
214
+ declare function getMxRecords(domain: string): Promise<string[]>;
215
+
216
+ /**
217
+ * Check if an email is from a disposable domain
218
+ */
219
+ declare function checkDisposable(domain: string): boolean;
220
+ /**
221
+ * Check if an email is a role-based account
222
+ */
223
+ declare function checkRoleAccount(username: string): boolean;
224
+ /**
225
+ * Check if an email is from a free provider
226
+ */
227
+ declare function checkFreeProvider(domain: string): boolean;
228
+ /**
229
+ * Perform miscellaneous checks on an email
230
+ * @param email The email address
231
+ * @param options Validation options
232
+ * @returns MiscResult with check results
233
+ */
234
+ declare function checkMisc(email: string, options?: ValidationOptions): Promise<MiscResult>;
235
+
236
+ /**
237
+ * Normalize an email address
238
+ * - Trims whitespace
239
+ * - Converts to lowercase
240
+ * - Removes dots from Gmail usernames (optional)
241
+ *
242
+ * @param email The email to normalize
243
+ * @param options Normalization options
244
+ * @returns Normalized email address
245
+ */
246
+ declare function normalizeEmail(email: string, options?: {
247
+ /** Remove dots from Gmail-style addresses */
248
+ removeDots?: boolean;
249
+ /** Remove plus addressing suffix */
250
+ removePlusAddressing?: boolean;
251
+ }): string;
252
+ /**
253
+ * Extract parts from an email address
254
+ * @param email The email address
255
+ * @returns Object with username and domain, or null if invalid
256
+ */
257
+ declare function extractParts(email: string): {
258
+ username: string;
259
+ domain: string;
260
+ } | null;
261
+
262
+ /**
263
+ * Get a suggested correction for a domain
264
+ * @param domain The domain to check for typos
265
+ * @returns Suggested domain or null if no suggestion
266
+ */
267
+ declare function getSuggestion(domain: string): string | null;
268
+ /**
269
+ * Get a suggestion for the full email address
270
+ * @param email The email to check for typos
271
+ * @returns Suggested email or null if no suggestion
272
+ */
273
+ declare function getEmailSuggestion(email: string): string | null;
274
+
275
+ /**
276
+ * SMTP error types
277
+ */
278
+ declare const SmtpErrorType: {
279
+ readonly CONNECTION_FAILED: "ConnectionFailed";
280
+ readonly TIMEOUT: "Timeout";
281
+ readonly INVALID_RESPONSE: "InvalidResponse";
282
+ readonly HELO_FAILED: "HeloFailed";
283
+ readonly MAIL_FROM_FAILED: "MailFromFailed";
284
+ readonly RCPT_TO_FAILED: "RcptToFailed";
285
+ readonly MAILBOX_NOT_FOUND: "MailboxNotFound";
286
+ readonly MAILBOX_DISABLED: "MailboxDisabled";
287
+ readonly GREYLISTED: "Greylisted";
288
+ readonly BLOCKED: "Blocked";
289
+ readonly UNKNOWN: "Unknown";
290
+ };
291
+ /**
292
+ * Try SMTP verification against multiple MX hosts
293
+ * Falls back to the next host if the first fails
294
+ */
295
+ declare function verifySmtpWithFallback(email: string, mxHosts: string[], options?: ValidationOptions): Promise<SmtpResult>;
296
+
297
+ /**
298
+ * List of known disposable email domains
299
+ * This list includes temporary email services that should be flagged
300
+ */
301
+ declare const disposableDomains: Set<string>;
302
+ /**
303
+ * Check if a domain is a known disposable email domain
304
+ */
305
+ declare function isDisposableDomain(domain: string): boolean;
306
+
307
+ /**
308
+ * List of known role-based email prefixes
309
+ * These are email addresses that typically go to a group or role rather than an individual
310
+ */
311
+ declare const rolePrefixes: Set<string>;
312
+ /**
313
+ * Check if an email prefix is a role-based account
314
+ */
315
+ declare function isRolePrefix(prefix: string): boolean;
316
+
317
+ /**
318
+ * List of known free email providers
319
+ * These are legitimate email services that offer free accounts
320
+ */
321
+ declare const freeProviders: Set<string>;
322
+ /**
323
+ * Check if a domain is a known free email provider
324
+ */
325
+ declare function isFreeProvider(domain: string): boolean;
326
+
327
+ /**
328
+ * Validate a single email address
329
+ *
330
+ * @param email The email address to validate
331
+ * @param options Validation options
332
+ * @returns Promise resolving to ValidationResult
333
+ *
334
+ * @example
335
+ * ```typescript
336
+ * import { validate } from 'bouncevalidator';
337
+ *
338
+ * const result = await validate('user@example.com');
339
+ * console.log(result.isReachable); // 'safe', 'invalid', 'risky', or 'unknown'
340
+ * ```
341
+ */
342
+ declare function validate(email: string, options?: ValidationOptions): Promise<ValidationResult>;
343
+ /**
344
+ * Validate multiple email addresses
345
+ *
346
+ * @param emails Array of email addresses to validate
347
+ * @param options Bulk validation options
348
+ * @returns Promise resolving to array of ValidationResults
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * import { validateBulk } from 'bouncevalidator';
353
+ *
354
+ * const results = await validateBulk([
355
+ * 'user1@example.com',
356
+ * 'user2@example.com'
357
+ * ], { concurrency: 5 });
358
+ * ```
359
+ */
360
+ declare function validateBulk(emails: string[], options?: BulkValidationOptions): Promise<ValidationResult[]>;
361
+ /**
362
+ * Quick validation - only checks syntax and MX records
363
+ * Much faster than full validation as it skips SMTP verification
364
+ *
365
+ * @param email The email address to validate
366
+ * @returns Promise resolving to ValidationResult
367
+ */
368
+ declare function validateQuick(email: string): Promise<ValidationResult>;
369
+ /**
370
+ * Clear the DNS cache
371
+ */
372
+ declare function clearDnsCache(): void;
373
+ /**
374
+ * Get the current DNS cache size
375
+ */
376
+ declare function getDnsCacheSize(): number;
377
+ declare const _default: {
378
+ validate: typeof validate;
379
+ validateBulk: typeof validateBulk;
380
+ validateQuick: typeof validateQuick;
381
+ clearDnsCache: typeof clearDnsCache;
382
+ getDnsCacheSize: typeof getDnsCacheSize;
383
+ normalizeEmail: typeof normalizeEmail;
384
+ extractParts: typeof extractParts;
385
+ getSuggestion: typeof getSuggestion;
386
+ getEmailSuggestion: typeof getEmailSuggestion;
387
+ validateSyntax: typeof validateSyntax;
388
+ isValidSyntax: typeof isValidSyntax;
389
+ verifyMx: typeof verifyMx;
390
+ hasMxRecords: typeof hasMxRecords;
391
+ getMxRecords: typeof getMxRecords;
392
+ checkMisc: typeof checkMisc;
393
+ checkDisposable: typeof checkDisposable;
394
+ checkRoleAccount: typeof checkRoleAccount;
395
+ checkFreeProvider: typeof checkFreeProvider;
396
+ };
397
+
398
+ export { type BulkValidationOptions, DnsCache, type DnsCacheEntry, type MiscResult, type MxResult, type Reachability, type SmtpError, SmtpErrorType, type SmtpResult, type SyntaxResult, type ValidationOptions, type ValidationResult, checkDisposable, checkFreeProvider, checkMisc, checkRoleAccount, clearDnsCache, _default as default, disposableDomains, extractParts, freeProviders, getDnsCacheSize, getEmailSuggestion, getMxRecords, getSuggestion, globalDnsCache, hasMxRecords, isDisposableDomain, isFreeProvider, isRolePrefix, isValidSyntax, normalizeEmail, rolePrefixes, validate, validateBulk, validateQuick, validateSyntax, verifyMx, verifySmtpWithFallback as verifySmtp };