@emailcheck/email-validator-js 2.13.1-beta.8 → 2.13.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/README.md +135 -181
- package/dist/cache-interface.d.ts +6 -74
- package/dist/cache.d.ts +34 -30
- package/dist/domain-suggester.d.ts +4 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.esm.js +88 -187
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +112 -191
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/whois.d.ts +3 -2
- package/package.json +1 -1
- package/dist/cache-factory.d.ts +0 -39
package/dist/index.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isValid, parse } from 'psl';
|
|
|
2
2
|
import { lru } from 'tiny-lru';
|
|
3
3
|
import { promises } from 'node:dns';
|
|
4
4
|
import { stringSimilarity } from 'string-similarity-js';
|
|
5
|
-
import net from 'node:net';
|
|
5
|
+
import * as net from 'node:net';
|
|
6
6
|
|
|
7
7
|
class LRUAdapter {
|
|
8
8
|
constructor(maxSize = 1e3, ttlMs = 36e5) {
|
|
@@ -40,67 +40,71 @@ class LRUAdapter {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
43
|
+
const DEFAULT_CACHE_OPTIONS = {
|
|
44
|
+
ttl: {
|
|
45
|
+
mx: 36e5,
|
|
46
|
+
// 1 hour
|
|
47
|
+
disposable: 864e5,
|
|
48
|
+
// 24 hours
|
|
49
|
+
free: 864e5,
|
|
50
|
+
// 24 hours
|
|
51
|
+
domainValid: 864e5,
|
|
52
|
+
// 24 hours
|
|
53
|
+
smtp: 18e5,
|
|
54
|
+
// 30 minutes
|
|
55
|
+
domainSuggestion: 864e5,
|
|
56
|
+
// 24 hours
|
|
57
|
+
whois: 36e5
|
|
58
|
+
// 1 hour
|
|
59
|
+
},
|
|
60
|
+
maxSize: {
|
|
61
|
+
mx: 500,
|
|
62
|
+
disposable: 1e3,
|
|
63
|
+
free: 1e3,
|
|
64
|
+
domainValid: 1e3,
|
|
65
|
+
smtp: 500,
|
|
66
|
+
domainSuggestion: 1e3,
|
|
67
|
+
whois: 200
|
|
68
|
+
}
|
|
67
69
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
let defaultCacheInstance = null;
|
|
71
|
+
function getDefaultCache() {
|
|
72
|
+
if (!defaultCacheInstance) {
|
|
73
|
+
defaultCacheInstance = {
|
|
74
|
+
mx: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.mx, DEFAULT_CACHE_OPTIONS.ttl.mx),
|
|
75
|
+
disposable: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.disposable, DEFAULT_CACHE_OPTIONS.ttl.disposable),
|
|
76
|
+
free: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.free, DEFAULT_CACHE_OPTIONS.ttl.free),
|
|
77
|
+
domainValid: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.domainValid, DEFAULT_CACHE_OPTIONS.ttl.domainValid),
|
|
78
|
+
smtp: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.smtp, DEFAULT_CACHE_OPTIONS.ttl.smtp),
|
|
79
|
+
domainSuggestion: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.domainSuggestion, DEFAULT_CACHE_OPTIONS.ttl.domainSuggestion),
|
|
80
|
+
whois: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.whois, DEFAULT_CACHE_OPTIONS.ttl.whois)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return defaultCacheInstance;
|
|
84
|
+
}
|
|
85
|
+
function getCacheStore(cache, key) {
|
|
86
|
+
return (cache === null || cache === void 0 ? void 0 : cache[key]) || getDefaultCache()[key];
|
|
87
|
+
}
|
|
88
|
+
function clearDefaultCache() {
|
|
89
|
+
if (defaultCacheInstance) {
|
|
90
|
+
defaultCacheInstance.mx.clear();
|
|
91
|
+
defaultCacheInstance.disposable.clear();
|
|
92
|
+
defaultCacheInstance.free.clear();
|
|
93
|
+
defaultCacheInstance.domainValid.clear();
|
|
94
|
+
defaultCacheInstance.smtp.clear();
|
|
95
|
+
defaultCacheInstance.domainSuggestion.clear();
|
|
96
|
+
defaultCacheInstance.whois.clear();
|
|
97
|
+
}
|
|
81
98
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const freeCacheStore = (passedCache) => getCacheStore(freeCache, "free", passedCache);
|
|
85
|
-
const domainValidCacheStore = (passedCache) => getCacheStore(domainValidCache, "domainValid", passedCache);
|
|
86
|
-
const smtpCacheStore = (passedCache) => getCacheStore(smtpCache, "smtp", passedCache);
|
|
87
|
-
const domainSuggestionCacheStore = (passedCache) => getCacheStore(domainSuggestionCache, "domainSuggestion", passedCache);
|
|
88
|
-
const whoisCacheStore = (passedCache) => getCacheStore(whoisCache, "whois", passedCache);
|
|
89
|
-
function clearAllCaches() {
|
|
90
|
-
mxCache.clear();
|
|
91
|
-
disposableCache.clear();
|
|
92
|
-
freeCache.clear();
|
|
93
|
-
domainValidCache.clear();
|
|
94
|
-
smtpCache.clear();
|
|
95
|
-
domainSuggestionCache.clear();
|
|
96
|
-
whoisCache.clear();
|
|
99
|
+
function resetDefaultCache() {
|
|
100
|
+
defaultCacheInstance = null;
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
async function resolveMxRecords(params) {
|
|
100
104
|
const { domain, cache, logger } = params;
|
|
101
105
|
const log = logger || (() => {
|
|
102
106
|
});
|
|
103
|
-
const cacheStore =
|
|
107
|
+
const cacheStore = getCacheStore(cache, "mx");
|
|
104
108
|
const cached = await cacheStore.get(domain);
|
|
105
109
|
if (cached !== null && cached !== void 0) {
|
|
106
110
|
log(`[resolveMxRecords] Cache hit for ${domain}: ${cached.length} MX records`);
|
|
@@ -264,24 +268,24 @@ function defaultDomainSuggestionMethod(domain, commonDomains) {
|
|
|
264
268
|
}
|
|
265
269
|
return null;
|
|
266
270
|
}
|
|
267
|
-
async function defaultDomainSuggestionMethodAsync(domain, commonDomains) {
|
|
268
|
-
return defaultDomainSuggestionMethodImpl(domain, commonDomains);
|
|
271
|
+
async function defaultDomainSuggestionMethodAsync(domain, commonDomains, cache) {
|
|
272
|
+
return defaultDomainSuggestionMethodImpl(domain, commonDomains, cache);
|
|
269
273
|
}
|
|
270
|
-
async function defaultDomainSuggestionMethodImpl(domain, commonDomains) {
|
|
274
|
+
async function defaultDomainSuggestionMethodImpl(domain, commonDomains, cache) {
|
|
271
275
|
if (!domain || domain.length < 3) {
|
|
272
276
|
return null;
|
|
273
277
|
}
|
|
274
278
|
const domainsToCheck = commonDomains || COMMON_EMAIL_DOMAINS;
|
|
275
279
|
const lowerDomain = domain.toLowerCase();
|
|
276
280
|
const cacheKey = `${lowerDomain}:${domainsToCheck.length}`;
|
|
277
|
-
const
|
|
278
|
-
const cached =
|
|
281
|
+
const cacheStore = getCacheStore(cache, "domainSuggestion");
|
|
282
|
+
const cached = await cacheStore.get(cacheKey);
|
|
279
283
|
const resolved = cached && typeof cached === "object" && "then" in cached ? await cached : cached;
|
|
280
284
|
if (resolved !== null && resolved !== void 0) {
|
|
281
|
-
return resolved
|
|
285
|
+
return resolved;
|
|
282
286
|
}
|
|
283
287
|
if (domainsToCheck.includes(lowerDomain)) {
|
|
284
|
-
await
|
|
288
|
+
await cacheStore.set(cacheKey, null);
|
|
285
289
|
return null;
|
|
286
290
|
}
|
|
287
291
|
for (const [correctDomain, typos] of Object.entries(TYPO_PATTERNS)) {
|
|
@@ -292,7 +296,7 @@ async function defaultDomainSuggestionMethodImpl(domain, commonDomains) {
|
|
|
292
296
|
confidence: 0.95
|
|
293
297
|
// High confidence for known typo patterns
|
|
294
298
|
};
|
|
295
|
-
await
|
|
299
|
+
await cacheStore.set(cacheKey, result);
|
|
296
300
|
return result;
|
|
297
301
|
}
|
|
298
302
|
}
|
|
@@ -320,7 +324,7 @@ async function defaultDomainSuggestionMethodImpl(domain, commonDomains) {
|
|
|
320
324
|
}
|
|
321
325
|
if (bestMatch) {
|
|
322
326
|
if (bestMatch.domain.charAt(0) !== lowerDomain.charAt(0) && bestMatch.similarity < 0.9) {
|
|
323
|
-
await
|
|
327
|
+
await cacheStore.set(cacheKey, null);
|
|
324
328
|
return null;
|
|
325
329
|
}
|
|
326
330
|
const result = {
|
|
@@ -328,10 +332,10 @@ async function defaultDomainSuggestionMethodImpl(domain, commonDomains) {
|
|
|
328
332
|
suggested: bestMatch.domain,
|
|
329
333
|
confidence: bestMatch.similarity
|
|
330
334
|
};
|
|
331
|
-
await
|
|
335
|
+
await cacheStore.set(cacheKey, result);
|
|
332
336
|
return result;
|
|
333
337
|
}
|
|
334
|
-
await
|
|
338
|
+
await cacheStore.set(cacheKey, null);
|
|
335
339
|
return null;
|
|
336
340
|
}
|
|
337
341
|
function suggestDomain(params) {
|
|
@@ -348,7 +352,7 @@ function suggestDomain(params) {
|
|
|
348
352
|
}
|
|
349
353
|
return defaultDomainSuggestionMethod(domain, commonDomains);
|
|
350
354
|
}
|
|
351
|
-
async function suggestEmailDomain(email, commonDomains) {
|
|
355
|
+
async function suggestEmailDomain(email, commonDomains, cache) {
|
|
352
356
|
if (!email || !email.includes("@")) {
|
|
353
357
|
return null;
|
|
354
358
|
}
|
|
@@ -356,7 +360,7 @@ async function suggestEmailDomain(email, commonDomains) {
|
|
|
356
360
|
if (!domain || !localPart) {
|
|
357
361
|
return null;
|
|
358
362
|
}
|
|
359
|
-
const suggestion = await defaultDomainSuggestionMethodAsync(domain, commonDomains);
|
|
363
|
+
const suggestion = await defaultDomainSuggestionMethodAsync(domain, commonDomains, cache);
|
|
360
364
|
if (suggestion) {
|
|
361
365
|
return {
|
|
362
366
|
original: email,
|
|
@@ -1236,7 +1240,7 @@ async function isValidEmailDomain(emailOrDomain, cache) {
|
|
|
1236
1240
|
if (!emailDomain) {
|
|
1237
1241
|
return false;
|
|
1238
1242
|
}
|
|
1239
|
-
const cacheStore =
|
|
1243
|
+
const cacheStore = getCacheStore(cache, "domainValid");
|
|
1240
1244
|
const cached = await cacheStore.get(emailDomain);
|
|
1241
1245
|
if (cached !== null && cached !== void 0) {
|
|
1242
1246
|
return cached;
|
|
@@ -1774,14 +1778,14 @@ function queryWhoisServer(domain, server, timeout = 5e3, debug = false) {
|
|
|
1774
1778
|
});
|
|
1775
1779
|
});
|
|
1776
1780
|
}
|
|
1777
|
-
async function getWhoisData(domain, timeout = 5e3, debug = false) {
|
|
1781
|
+
async function getWhoisData(domain, timeout = 5e3, debug = false, cache) {
|
|
1778
1782
|
var _a;
|
|
1779
1783
|
const log = debug ? console.debug : (..._args) => {
|
|
1780
1784
|
};
|
|
1781
1785
|
const cacheKey = `whois:${domain}`;
|
|
1782
|
-
const
|
|
1786
|
+
const cacheStore = getCacheStore(cache, "whois");
|
|
1783
1787
|
log(`[whois] getting WHOIS data for ${domain}`);
|
|
1784
|
-
const cached = await
|
|
1788
|
+
const cached = await cacheStore.get(cacheKey);
|
|
1785
1789
|
if (cached !== null && cached !== void 0) {
|
|
1786
1790
|
log(`[whois] using cached data for ${domain}`);
|
|
1787
1791
|
return cached;
|
|
@@ -1803,19 +1807,19 @@ async function getWhoisData(domain, timeout = 5e3, debug = false) {
|
|
|
1803
1807
|
log(`[whois] IANA referred to ${referredServer} for ${domain}`);
|
|
1804
1808
|
const whoisResponse2 = await queryWhoisServer(domain, referredServer, timeout, debug);
|
|
1805
1809
|
const whoisData3 = parseWhoisData({ rawData: whoisResponse2, domain });
|
|
1806
|
-
await
|
|
1810
|
+
await cacheStore.set(cacheKey, whoisData3);
|
|
1807
1811
|
log(`[whois] successfully retrieved and cached WHOIS data from referred server for ${domain}`);
|
|
1808
1812
|
return whoisData3;
|
|
1809
1813
|
}
|
|
1810
1814
|
const whoisData2 = parseWhoisData({ rawData: ianaResponse, domain });
|
|
1811
|
-
await
|
|
1815
|
+
await cacheStore.set(cacheKey, whoisData2);
|
|
1812
1816
|
log(`[whois] successfully retrieved and cached WHOIS data from IANA for ${domain}`);
|
|
1813
1817
|
return whoisData2;
|
|
1814
1818
|
}
|
|
1815
1819
|
log(`[whois] using WHOIS server ${whoisServer} for TLD ${tld}`);
|
|
1816
1820
|
const whoisResponse = await queryWhoisServer(domain, whoisServer, timeout, debug);
|
|
1817
1821
|
const whoisData = parseWhoisData({ rawData: whoisResponse, domain });
|
|
1818
|
-
await
|
|
1822
|
+
await cacheStore.set(cacheKey, whoisData);
|
|
1819
1823
|
log(`[whois] successfully retrieved and cached WHOIS data for ${domain}`);
|
|
1820
1824
|
return whoisData;
|
|
1821
1825
|
} catch (_error) {
|
|
@@ -1823,7 +1827,7 @@ async function getWhoisData(domain, timeout = 5e3, debug = false) {
|
|
|
1823
1827
|
return null;
|
|
1824
1828
|
}
|
|
1825
1829
|
}
|
|
1826
|
-
async function getDomainAge(domain, timeout = 5e3, debug = false) {
|
|
1830
|
+
async function getDomainAge(domain, timeout = 5e3, debug = false, cache) {
|
|
1827
1831
|
const log = debug ? console.debug : (..._args) => {
|
|
1828
1832
|
};
|
|
1829
1833
|
try {
|
|
@@ -1837,7 +1841,7 @@ async function getDomainAge(domain, timeout = 5e3, debug = false) {
|
|
|
1837
1841
|
log(`[whois] domain validation failed: ${cleanDomain}`);
|
|
1838
1842
|
return null;
|
|
1839
1843
|
}
|
|
1840
|
-
const whoisData = await getWhoisData(cleanDomain, timeout, debug);
|
|
1844
|
+
const whoisData = await getWhoisData(cleanDomain, timeout, debug, cache);
|
|
1841
1845
|
if (!whoisData || !whoisData.creationDate) {
|
|
1842
1846
|
log(`[whois] no creation date found for ${cleanDomain}`);
|
|
1843
1847
|
return null;
|
|
@@ -1861,7 +1865,7 @@ async function getDomainAge(domain, timeout = 5e3, debug = false) {
|
|
|
1861
1865
|
return null;
|
|
1862
1866
|
}
|
|
1863
1867
|
}
|
|
1864
|
-
async function getDomainRegistrationStatus(domain, timeout = 5e3, debug = false) {
|
|
1868
|
+
async function getDomainRegistrationStatus(domain, timeout = 5e3, debug = false, cache) {
|
|
1865
1869
|
const log = debug ? console.debug : (..._args) => {
|
|
1866
1870
|
};
|
|
1867
1871
|
try {
|
|
@@ -1875,7 +1879,7 @@ async function getDomainRegistrationStatus(domain, timeout = 5e3, debug = false)
|
|
|
1875
1879
|
log(`[whois] domain validation failed: ${cleanDomain}`);
|
|
1876
1880
|
return null;
|
|
1877
1881
|
}
|
|
1878
|
-
const whoisData = await getWhoisData(cleanDomain, timeout, debug);
|
|
1882
|
+
const whoisData = await getWhoisData(cleanDomain, timeout, debug, cache);
|
|
1879
1883
|
if (!whoisData || whoisData.isAvailable) {
|
|
1880
1884
|
log(`[whois] domain ${cleanDomain} is available or not registered`);
|
|
1881
1885
|
return {
|
|
@@ -2110,109 +2114,6 @@ function createErrorResult(email, _error) {
|
|
|
2110
2114
|
};
|
|
2111
2115
|
}
|
|
2112
2116
|
|
|
2113
|
-
const CacheFactory = {
|
|
2114
|
-
/**
|
|
2115
|
-
* Create a cache with LRU (tiny-lru) backend
|
|
2116
|
-
*/
|
|
2117
|
-
createLRUCache(customTtl) {
|
|
2118
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2119
|
-
return {
|
|
2120
|
-
mx: new LRUAdapter(DEFAULT_CACHE_SIZE.mx, (_a = customTtl === null || customTtl === void 0 ? void 0 : customTtl.mx) !== null && _a !== void 0 ? _a : DEFAULT_CACHE_TTL.mx),
|
|
2121
|
-
disposable: new LRUAdapter(DEFAULT_CACHE_SIZE.disposable, (_b = customTtl === null || customTtl === void 0 ? void 0 : customTtl.disposable) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TTL.disposable),
|
|
2122
|
-
free: new LRUAdapter(DEFAULT_CACHE_SIZE.free, (_c = customTtl === null || customTtl === void 0 ? void 0 : customTtl.free) !== null && _c !== void 0 ? _c : DEFAULT_CACHE_TTL.free),
|
|
2123
|
-
domainValid: new LRUAdapter(DEFAULT_CACHE_SIZE.domainValid, (_d = customTtl === null || customTtl === void 0 ? void 0 : customTtl.domainValid) !== null && _d !== void 0 ? _d : DEFAULT_CACHE_TTL.domainValid),
|
|
2124
|
-
smtp: new LRUAdapter(DEFAULT_CACHE_SIZE.smtp, (_e = customTtl === null || customTtl === void 0 ? void 0 : customTtl.smtp) !== null && _e !== void 0 ? _e : DEFAULT_CACHE_TTL.smtp),
|
|
2125
|
-
domainSuggestion: new LRUAdapter(DEFAULT_CACHE_SIZE.domainSuggestion, (_f = customTtl === null || customTtl === void 0 ? void 0 : customTtl.domainSuggestion) !== null && _f !== void 0 ? _f : DEFAULT_CACHE_TTL.domainSuggestion),
|
|
2126
|
-
whois: new LRUAdapter(DEFAULT_CACHE_SIZE.whois, (_g = customTtl === null || customTtl === void 0 ? void 0 : customTtl.whois) !== null && _g !== void 0 ? _g : DEFAULT_CACHE_TTL.whois)
|
|
2127
|
-
};
|
|
2128
|
-
},
|
|
2129
|
-
/**
|
|
2130
|
-
* Create a cache with Redis backend
|
|
2131
|
-
*/
|
|
2132
|
-
createRedisCache(redis, options) {
|
|
2133
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2134
|
-
const { keyPrefix = "email_validator:", customTtl, jsonSerializer } = options !== null && options !== void 0 ? options : {};
|
|
2135
|
-
return {
|
|
2136
|
-
mx: new RedisAdapter(redis, {
|
|
2137
|
-
keyPrefix: `${keyPrefix}mx:`,
|
|
2138
|
-
defaultTtlMs: (_a = customTtl === null || customTtl === void 0 ? void 0 : customTtl.mx) !== null && _a !== void 0 ? _a : DEFAULT_CACHE_TTL.mx,
|
|
2139
|
-
jsonSerializer
|
|
2140
|
-
}),
|
|
2141
|
-
disposable: new RedisAdapter(redis, {
|
|
2142
|
-
keyPrefix: `${keyPrefix}disposable:`,
|
|
2143
|
-
defaultTtlMs: (_b = customTtl === null || customTtl === void 0 ? void 0 : customTtl.disposable) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TTL.disposable,
|
|
2144
|
-
jsonSerializer
|
|
2145
|
-
}),
|
|
2146
|
-
free: new RedisAdapter(redis, {
|
|
2147
|
-
keyPrefix: `${keyPrefix}free:`,
|
|
2148
|
-
defaultTtlMs: (_c = customTtl === null || customTtl === void 0 ? void 0 : customTtl.free) !== null && _c !== void 0 ? _c : DEFAULT_CACHE_TTL.free,
|
|
2149
|
-
jsonSerializer
|
|
2150
|
-
}),
|
|
2151
|
-
domainValid: new RedisAdapter(redis, {
|
|
2152
|
-
keyPrefix: `${keyPrefix}domain_valid:`,
|
|
2153
|
-
defaultTtlMs: (_d = customTtl === null || customTtl === void 0 ? void 0 : customTtl.domainValid) !== null && _d !== void 0 ? _d : DEFAULT_CACHE_TTL.domainValid,
|
|
2154
|
-
jsonSerializer
|
|
2155
|
-
}),
|
|
2156
|
-
smtp: new RedisAdapter(redis, {
|
|
2157
|
-
keyPrefix: `${keyPrefix}smtp:`,
|
|
2158
|
-
defaultTtlMs: (_e = customTtl === null || customTtl === void 0 ? void 0 : customTtl.smtp) !== null && _e !== void 0 ? _e : DEFAULT_CACHE_TTL.smtp,
|
|
2159
|
-
jsonSerializer
|
|
2160
|
-
}),
|
|
2161
|
-
domainSuggestion: new RedisAdapter(redis, {
|
|
2162
|
-
keyPrefix: `${keyPrefix}domain_suggestion:`,
|
|
2163
|
-
defaultTtlMs: (_f = customTtl === null || customTtl === void 0 ? void 0 : customTtl.domainSuggestion) !== null && _f !== void 0 ? _f : DEFAULT_CACHE_TTL.domainSuggestion,
|
|
2164
|
-
jsonSerializer
|
|
2165
|
-
}),
|
|
2166
|
-
whois: new RedisAdapter(redis, {
|
|
2167
|
-
keyPrefix: `${keyPrefix}whois:`,
|
|
2168
|
-
defaultTtlMs: (_g = customTtl === null || customTtl === void 0 ? void 0 : customTtl.whois) !== null && _g !== void 0 ? _g : DEFAULT_CACHE_TTL.whois,
|
|
2169
|
-
jsonSerializer
|
|
2170
|
-
})
|
|
2171
|
-
};
|
|
2172
|
-
},
|
|
2173
|
-
/**
|
|
2174
|
-
* Create a cache with custom backend
|
|
2175
|
-
*/
|
|
2176
|
-
createCustomCache(storeFactory, customTtl) {
|
|
2177
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2178
|
-
return {
|
|
2179
|
-
mx: storeFactory("mx", (_a = customTtl === null || customTtl === void 0 ? void 0 : customTtl.mx) !== null && _a !== void 0 ? _a : DEFAULT_CACHE_TTL.mx, DEFAULT_CACHE_SIZE.mx),
|
|
2180
|
-
disposable: storeFactory("disposable", (_b = customTtl === null || customTtl === void 0 ? void 0 : customTtl.disposable) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TTL.disposable, DEFAULT_CACHE_SIZE.disposable),
|
|
2181
|
-
free: storeFactory("free", (_c = customTtl === null || customTtl === void 0 ? void 0 : customTtl.free) !== null && _c !== void 0 ? _c : DEFAULT_CACHE_TTL.free, DEFAULT_CACHE_SIZE.free),
|
|
2182
|
-
domainValid: storeFactory("domainValid", (_d = customTtl === null || customTtl === void 0 ? void 0 : customTtl.domainValid) !== null && _d !== void 0 ? _d : DEFAULT_CACHE_TTL.domainValid, DEFAULT_CACHE_SIZE.domainValid),
|
|
2183
|
-
smtp: storeFactory("smtp", (_e = customTtl === null || customTtl === void 0 ? void 0 : customTtl.smtp) !== null && _e !== void 0 ? _e : DEFAULT_CACHE_TTL.smtp, DEFAULT_CACHE_SIZE.smtp),
|
|
2184
|
-
domainSuggestion: storeFactory("domainSuggestion", (_f = customTtl === null || customTtl === void 0 ? void 0 : customTtl.domainSuggestion) !== null && _f !== void 0 ? _f : DEFAULT_CACHE_TTL.domainSuggestion, DEFAULT_CACHE_SIZE.domainSuggestion),
|
|
2185
|
-
whois: storeFactory("whois", (_g = customTtl === null || customTtl === void 0 ? void 0 : customTtl.whois) !== null && _g !== void 0 ? _g : DEFAULT_CACHE_TTL.whois, DEFAULT_CACHE_SIZE.whois)
|
|
2186
|
-
};
|
|
2187
|
-
},
|
|
2188
|
-
/**
|
|
2189
|
-
* Create a mixed cache with different backends for different cache types
|
|
2190
|
-
*/
|
|
2191
|
-
createMixedCache(config) {
|
|
2192
|
-
const createCache = (cacheType, config2) => {
|
|
2193
|
-
var _a, _b;
|
|
2194
|
-
if (config2 === null || config2 === void 0 ? void 0 : config2.store) {
|
|
2195
|
-
return config2.store;
|
|
2196
|
-
}
|
|
2197
|
-
const ttlMs = (_a = config2 === null || config2 === void 0 ? void 0 : config2.ttlMs) !== null && _a !== void 0 ? _a : DEFAULT_CACHE_TTL[cacheType];
|
|
2198
|
-
const maxSize = (_b = config2 === null || config2 === void 0 ? void 0 : config2.maxSize) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_SIZE[cacheType];
|
|
2199
|
-
if ((config2 === null || config2 === void 0 ? void 0 : config2.store) && "get" in config2.store && "set" in config2.store) {
|
|
2200
|
-
return config2.store;
|
|
2201
|
-
}
|
|
2202
|
-
return new LRUAdapter(maxSize, ttlMs);
|
|
2203
|
-
};
|
|
2204
|
-
return {
|
|
2205
|
-
mx: createCache("mx", config.mx),
|
|
2206
|
-
disposable: createCache("disposable", config.disposable),
|
|
2207
|
-
free: createCache("free", config.free),
|
|
2208
|
-
domainValid: createCache("domainValid", config.domainValid),
|
|
2209
|
-
smtp: createCache("smtp", config.smtp),
|
|
2210
|
-
domainSuggestion: createCache("domainSuggestion", config.domainSuggestion),
|
|
2211
|
-
whois: createCache("whois", config.whois)
|
|
2212
|
-
};
|
|
2213
|
-
}
|
|
2214
|
-
};
|
|
2215
|
-
|
|
2216
2117
|
let disposableEmailProviders;
|
|
2217
2118
|
let freeEmailProviders;
|
|
2218
2119
|
async function isDisposableEmail(params) {
|
|
@@ -2224,7 +2125,7 @@ async function isDisposableEmail(params) {
|
|
|
2224
2125
|
if (!emailDomain) {
|
|
2225
2126
|
return false;
|
|
2226
2127
|
}
|
|
2227
|
-
const cacheStore =
|
|
2128
|
+
const cacheStore = getCacheStore(cache, "disposable");
|
|
2228
2129
|
let cached;
|
|
2229
2130
|
try {
|
|
2230
2131
|
cached = await cacheStore.get(emailDomain);
|
|
@@ -2257,7 +2158,7 @@ async function isFreeEmail(params) {
|
|
|
2257
2158
|
if (!emailDomain) {
|
|
2258
2159
|
return false;
|
|
2259
2160
|
}
|
|
2260
|
-
const cacheStore =
|
|
2161
|
+
const cacheStore = getCacheStore(cache, "free");
|
|
2261
2162
|
let cached;
|
|
2262
2163
|
try {
|
|
2263
2164
|
cached = await cacheStore.get(emailDomain);
|
|
@@ -2368,7 +2269,7 @@ async function verifyEmail(params) {
|
|
|
2368
2269
|
if (checkDomainAge && !shouldSkipDomainWhois) {
|
|
2369
2270
|
log(`[verifyEmail] Checking domain age for ${domain}`);
|
|
2370
2271
|
try {
|
|
2371
|
-
result.domainAge = await getDomainAge(domain, whoisTimeout, debug);
|
|
2272
|
+
result.domainAge = await getDomainAge(domain, whoisTimeout, debug, params.cache);
|
|
2372
2273
|
log(`[verifyEmail] Domain age result:`, result.domainAge ? `${result.domainAge.ageInDays} days` : "null");
|
|
2373
2274
|
} catch (err) {
|
|
2374
2275
|
log("[verifyEmail] Failed to get domain age", err);
|
|
@@ -2380,7 +2281,7 @@ async function verifyEmail(params) {
|
|
|
2380
2281
|
if (checkDomainRegistration && !shouldSkipDomainWhois) {
|
|
2381
2282
|
log(`[verifyEmail] Checking domain registration status for ${domain}`);
|
|
2382
2283
|
try {
|
|
2383
|
-
result.domainRegistration = await getDomainRegistrationStatus(domain, whoisTimeout, debug);
|
|
2284
|
+
result.domainRegistration = await getDomainRegistrationStatus(domain, whoisTimeout, debug, params.cache);
|
|
2384
2285
|
log(`[verifyEmail] Domain registration result:`, ((_a = result.domainRegistration) === null || _a === void 0 ? void 0 : _a.isRegistered) ? "registered" : "not registered");
|
|
2385
2286
|
} catch (err) {
|
|
2386
2287
|
log("[verifyEmail] Failed to get domain registration status", err);
|
|
@@ -2400,7 +2301,7 @@ async function verifyEmail(params) {
|
|
|
2400
2301
|
}
|
|
2401
2302
|
if (verifySmtp && mxRecords.length > 0) {
|
|
2402
2303
|
const cacheKey = `${emailAddress}:smtp`;
|
|
2403
|
-
const smtpCacheInstance =
|
|
2304
|
+
const smtpCacheInstance = getCacheStore(params.cache, "smtp");
|
|
2404
2305
|
const cachedSmtp = await smtpCacheInstance.get(cacheKey);
|
|
2405
2306
|
if (cachedSmtp !== null && cachedSmtp !== void 0) {
|
|
2406
2307
|
result.validSmtp = cachedSmtp;
|
|
@@ -2458,5 +2359,5 @@ async function verifyEmail(params) {
|
|
|
2458
2359
|
return result;
|
|
2459
2360
|
}
|
|
2460
2361
|
|
|
2461
|
-
export { COMMON_EMAIL_DOMAINS,
|
|
2362
|
+
export { COMMON_EMAIL_DOMAINS, DEFAULT_CACHE_OPTIONS, LRUAdapter, RedisAdapter, VerificationErrorCode, clearDefaultCache, defaultDomainSuggestionMethod, defaultNameDetectionMethod, detectName, detectNameFromEmail, domainPorts, getCacheStore, getDefaultCache, getDomainAge, getDomainRegistrationStatus, getDomainSimilarity, isCommonDomain, isDisposableEmail, isFreeEmail, isValidEmail, isValidEmailDomain, resetDefaultCache, suggestDomain, suggestEmailDomain, verifyEmail, verifyEmailBatch };
|
|
2462
2363
|
//# sourceMappingURL=index.esm.js.map
|