@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.js
CHANGED
|
@@ -6,6 +6,25 @@ var node_dns = require('node:dns');
|
|
|
6
6
|
var stringSimilarityJs = require('string-similarity-js');
|
|
7
7
|
var net = require('node:net');
|
|
8
8
|
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var net__namespace = /*#__PURE__*/_interopNamespaceDefault(net);
|
|
27
|
+
|
|
9
28
|
class LRUAdapter {
|
|
10
29
|
constructor(maxSize = 1e3, ttlMs = 36e5) {
|
|
11
30
|
this.lru = tinyLru.lru(maxSize, ttlMs);
|
|
@@ -42,67 +61,71 @@ class LRUAdapter {
|
|
|
42
61
|
}
|
|
43
62
|
}
|
|
44
63
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
const DEFAULT_CACHE_OPTIONS = {
|
|
65
|
+
ttl: {
|
|
66
|
+
mx: 36e5,
|
|
67
|
+
// 1 hour
|
|
68
|
+
disposable: 864e5,
|
|
69
|
+
// 24 hours
|
|
70
|
+
free: 864e5,
|
|
71
|
+
// 24 hours
|
|
72
|
+
domainValid: 864e5,
|
|
73
|
+
// 24 hours
|
|
74
|
+
smtp: 18e5,
|
|
75
|
+
// 30 minutes
|
|
76
|
+
domainSuggestion: 864e5,
|
|
77
|
+
// 24 hours
|
|
78
|
+
whois: 36e5
|
|
79
|
+
// 1 hour
|
|
80
|
+
},
|
|
81
|
+
maxSize: {
|
|
82
|
+
mx: 500,
|
|
83
|
+
disposable: 1e3,
|
|
84
|
+
free: 1e3,
|
|
85
|
+
domainValid: 1e3,
|
|
86
|
+
smtp: 500,
|
|
87
|
+
domainSuggestion: 1e3,
|
|
88
|
+
whois: 200
|
|
89
|
+
}
|
|
69
90
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
91
|
+
let defaultCacheInstance = null;
|
|
92
|
+
function getDefaultCache() {
|
|
93
|
+
if (!defaultCacheInstance) {
|
|
94
|
+
defaultCacheInstance = {
|
|
95
|
+
mx: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.mx, DEFAULT_CACHE_OPTIONS.ttl.mx),
|
|
96
|
+
disposable: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.disposable, DEFAULT_CACHE_OPTIONS.ttl.disposable),
|
|
97
|
+
free: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.free, DEFAULT_CACHE_OPTIONS.ttl.free),
|
|
98
|
+
domainValid: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.domainValid, DEFAULT_CACHE_OPTIONS.ttl.domainValid),
|
|
99
|
+
smtp: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.smtp, DEFAULT_CACHE_OPTIONS.ttl.smtp),
|
|
100
|
+
domainSuggestion: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.domainSuggestion, DEFAULT_CACHE_OPTIONS.ttl.domainSuggestion),
|
|
101
|
+
whois: new LRUAdapter(DEFAULT_CACHE_OPTIONS.maxSize.whois, DEFAULT_CACHE_OPTIONS.ttl.whois)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return defaultCacheInstance;
|
|
105
|
+
}
|
|
106
|
+
function getCacheStore(cache, key) {
|
|
107
|
+
return (cache === null || cache === void 0 ? void 0 : cache[key]) || getDefaultCache()[key];
|
|
83
108
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
domainSuggestionCache.clear();
|
|
98
|
-
whoisCache.clear();
|
|
109
|
+
function clearDefaultCache() {
|
|
110
|
+
if (defaultCacheInstance) {
|
|
111
|
+
defaultCacheInstance.mx.clear();
|
|
112
|
+
defaultCacheInstance.disposable.clear();
|
|
113
|
+
defaultCacheInstance.free.clear();
|
|
114
|
+
defaultCacheInstance.domainValid.clear();
|
|
115
|
+
defaultCacheInstance.smtp.clear();
|
|
116
|
+
defaultCacheInstance.domainSuggestion.clear();
|
|
117
|
+
defaultCacheInstance.whois.clear();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function resetDefaultCache() {
|
|
121
|
+
defaultCacheInstance = null;
|
|
99
122
|
}
|
|
100
123
|
|
|
101
124
|
async function resolveMxRecords(params) {
|
|
102
125
|
const { domain, cache, logger } = params;
|
|
103
126
|
const log = logger || (() => {
|
|
104
127
|
});
|
|
105
|
-
const cacheStore =
|
|
128
|
+
const cacheStore = getCacheStore(cache, "mx");
|
|
106
129
|
const cached = await cacheStore.get(domain);
|
|
107
130
|
if (cached !== null && cached !== void 0) {
|
|
108
131
|
log(`[resolveMxRecords] Cache hit for ${domain}: ${cached.length} MX records`);
|
|
@@ -266,24 +289,24 @@ function defaultDomainSuggestionMethod(domain, commonDomains) {
|
|
|
266
289
|
}
|
|
267
290
|
return null;
|
|
268
291
|
}
|
|
269
|
-
async function defaultDomainSuggestionMethodAsync(domain, commonDomains) {
|
|
270
|
-
return defaultDomainSuggestionMethodImpl(domain, commonDomains);
|
|
292
|
+
async function defaultDomainSuggestionMethodAsync(domain, commonDomains, cache) {
|
|
293
|
+
return defaultDomainSuggestionMethodImpl(domain, commonDomains, cache);
|
|
271
294
|
}
|
|
272
|
-
async function defaultDomainSuggestionMethodImpl(domain, commonDomains) {
|
|
295
|
+
async function defaultDomainSuggestionMethodImpl(domain, commonDomains, cache) {
|
|
273
296
|
if (!domain || domain.length < 3) {
|
|
274
297
|
return null;
|
|
275
298
|
}
|
|
276
299
|
const domainsToCheck = commonDomains || COMMON_EMAIL_DOMAINS;
|
|
277
300
|
const lowerDomain = domain.toLowerCase();
|
|
278
301
|
const cacheKey = `${lowerDomain}:${domainsToCheck.length}`;
|
|
279
|
-
const
|
|
280
|
-
const cached =
|
|
302
|
+
const cacheStore = getCacheStore(cache, "domainSuggestion");
|
|
303
|
+
const cached = await cacheStore.get(cacheKey);
|
|
281
304
|
const resolved = cached && typeof cached === "object" && "then" in cached ? await cached : cached;
|
|
282
305
|
if (resolved !== null && resolved !== void 0) {
|
|
283
|
-
return resolved
|
|
306
|
+
return resolved;
|
|
284
307
|
}
|
|
285
308
|
if (domainsToCheck.includes(lowerDomain)) {
|
|
286
|
-
await
|
|
309
|
+
await cacheStore.set(cacheKey, null);
|
|
287
310
|
return null;
|
|
288
311
|
}
|
|
289
312
|
for (const [correctDomain, typos] of Object.entries(TYPO_PATTERNS)) {
|
|
@@ -294,7 +317,7 @@ async function defaultDomainSuggestionMethodImpl(domain, commonDomains) {
|
|
|
294
317
|
confidence: 0.95
|
|
295
318
|
// High confidence for known typo patterns
|
|
296
319
|
};
|
|
297
|
-
await
|
|
320
|
+
await cacheStore.set(cacheKey, result);
|
|
298
321
|
return result;
|
|
299
322
|
}
|
|
300
323
|
}
|
|
@@ -322,7 +345,7 @@ async function defaultDomainSuggestionMethodImpl(domain, commonDomains) {
|
|
|
322
345
|
}
|
|
323
346
|
if (bestMatch) {
|
|
324
347
|
if (bestMatch.domain.charAt(0) !== lowerDomain.charAt(0) && bestMatch.similarity < 0.9) {
|
|
325
|
-
await
|
|
348
|
+
await cacheStore.set(cacheKey, null);
|
|
326
349
|
return null;
|
|
327
350
|
}
|
|
328
351
|
const result = {
|
|
@@ -330,10 +353,10 @@ async function defaultDomainSuggestionMethodImpl(domain, commonDomains) {
|
|
|
330
353
|
suggested: bestMatch.domain,
|
|
331
354
|
confidence: bestMatch.similarity
|
|
332
355
|
};
|
|
333
|
-
await
|
|
356
|
+
await cacheStore.set(cacheKey, result);
|
|
334
357
|
return result;
|
|
335
358
|
}
|
|
336
|
-
await
|
|
359
|
+
await cacheStore.set(cacheKey, null);
|
|
337
360
|
return null;
|
|
338
361
|
}
|
|
339
362
|
function suggestDomain(params) {
|
|
@@ -350,7 +373,7 @@ function suggestDomain(params) {
|
|
|
350
373
|
}
|
|
351
374
|
return defaultDomainSuggestionMethod(domain, commonDomains);
|
|
352
375
|
}
|
|
353
|
-
async function suggestEmailDomain(email, commonDomains) {
|
|
376
|
+
async function suggestEmailDomain(email, commonDomains, cache) {
|
|
354
377
|
if (!email || !email.includes("@")) {
|
|
355
378
|
return null;
|
|
356
379
|
}
|
|
@@ -358,7 +381,7 @@ async function suggestEmailDomain(email, commonDomains) {
|
|
|
358
381
|
if (!domain || !localPart) {
|
|
359
382
|
return null;
|
|
360
383
|
}
|
|
361
|
-
const suggestion = await defaultDomainSuggestionMethodAsync(domain, commonDomains);
|
|
384
|
+
const suggestion = await defaultDomainSuggestionMethodAsync(domain, commonDomains, cache);
|
|
362
385
|
if (suggestion) {
|
|
363
386
|
return {
|
|
364
387
|
original: email,
|
|
@@ -1139,7 +1162,7 @@ async function attemptVerification(params) {
|
|
|
1139
1162
|
const { mxRecord, local, domain, port, timeout, log, attempt } = params;
|
|
1140
1163
|
return new Promise((resolve) => {
|
|
1141
1164
|
log(`[verifyMailboxSMTP] connecting to ${mxRecord}:${port} (attempt ${attempt + 1})`);
|
|
1142
|
-
const socket =
|
|
1165
|
+
const socket = net__namespace.connect({
|
|
1143
1166
|
host: mxRecord,
|
|
1144
1167
|
port
|
|
1145
1168
|
});
|
|
@@ -1238,7 +1261,7 @@ async function isValidEmailDomain(emailOrDomain, cache) {
|
|
|
1238
1261
|
if (!emailDomain) {
|
|
1239
1262
|
return false;
|
|
1240
1263
|
}
|
|
1241
|
-
const cacheStore =
|
|
1264
|
+
const cacheStore = getCacheStore(cache, "domainValid");
|
|
1242
1265
|
const cached = await cacheStore.get(emailDomain);
|
|
1243
1266
|
if (cached !== null && cached !== void 0) {
|
|
1244
1267
|
return cached;
|
|
@@ -1746,7 +1769,7 @@ function queryWhoisServer(domain, server, timeout = 5e3, debug = false) {
|
|
|
1746
1769
|
const log = debug ? console.debug : (..._args) => {
|
|
1747
1770
|
};
|
|
1748
1771
|
return new Promise((resolve, reject) => {
|
|
1749
|
-
const client = new
|
|
1772
|
+
const client = new net__namespace.Socket();
|
|
1750
1773
|
let data = "";
|
|
1751
1774
|
log(`[whois] querying ${server} for domain ${domain}`);
|
|
1752
1775
|
const timer = setTimeout(() => {
|
|
@@ -1776,14 +1799,14 @@ function queryWhoisServer(domain, server, timeout = 5e3, debug = false) {
|
|
|
1776
1799
|
});
|
|
1777
1800
|
});
|
|
1778
1801
|
}
|
|
1779
|
-
async function getWhoisData(domain, timeout = 5e3, debug = false) {
|
|
1802
|
+
async function getWhoisData(domain, timeout = 5e3, debug = false, cache) {
|
|
1780
1803
|
var _a;
|
|
1781
1804
|
const log = debug ? console.debug : (..._args) => {
|
|
1782
1805
|
};
|
|
1783
1806
|
const cacheKey = `whois:${domain}`;
|
|
1784
|
-
const
|
|
1807
|
+
const cacheStore = getCacheStore(cache, "whois");
|
|
1785
1808
|
log(`[whois] getting WHOIS data for ${domain}`);
|
|
1786
|
-
const cached = await
|
|
1809
|
+
const cached = await cacheStore.get(cacheKey);
|
|
1787
1810
|
if (cached !== null && cached !== void 0) {
|
|
1788
1811
|
log(`[whois] using cached data for ${domain}`);
|
|
1789
1812
|
return cached;
|
|
@@ -1805,19 +1828,19 @@ async function getWhoisData(domain, timeout = 5e3, debug = false) {
|
|
|
1805
1828
|
log(`[whois] IANA referred to ${referredServer} for ${domain}`);
|
|
1806
1829
|
const whoisResponse2 = await queryWhoisServer(domain, referredServer, timeout, debug);
|
|
1807
1830
|
const whoisData3 = parseWhoisData({ rawData: whoisResponse2, domain });
|
|
1808
|
-
await
|
|
1831
|
+
await cacheStore.set(cacheKey, whoisData3);
|
|
1809
1832
|
log(`[whois] successfully retrieved and cached WHOIS data from referred server for ${domain}`);
|
|
1810
1833
|
return whoisData3;
|
|
1811
1834
|
}
|
|
1812
1835
|
const whoisData2 = parseWhoisData({ rawData: ianaResponse, domain });
|
|
1813
|
-
await
|
|
1836
|
+
await cacheStore.set(cacheKey, whoisData2);
|
|
1814
1837
|
log(`[whois] successfully retrieved and cached WHOIS data from IANA for ${domain}`);
|
|
1815
1838
|
return whoisData2;
|
|
1816
1839
|
}
|
|
1817
1840
|
log(`[whois] using WHOIS server ${whoisServer} for TLD ${tld}`);
|
|
1818
1841
|
const whoisResponse = await queryWhoisServer(domain, whoisServer, timeout, debug);
|
|
1819
1842
|
const whoisData = parseWhoisData({ rawData: whoisResponse, domain });
|
|
1820
|
-
await
|
|
1843
|
+
await cacheStore.set(cacheKey, whoisData);
|
|
1821
1844
|
log(`[whois] successfully retrieved and cached WHOIS data for ${domain}`);
|
|
1822
1845
|
return whoisData;
|
|
1823
1846
|
} catch (_error) {
|
|
@@ -1825,7 +1848,7 @@ async function getWhoisData(domain, timeout = 5e3, debug = false) {
|
|
|
1825
1848
|
return null;
|
|
1826
1849
|
}
|
|
1827
1850
|
}
|
|
1828
|
-
async function getDomainAge(domain, timeout = 5e3, debug = false) {
|
|
1851
|
+
async function getDomainAge(domain, timeout = 5e3, debug = false, cache) {
|
|
1829
1852
|
const log = debug ? console.debug : (..._args) => {
|
|
1830
1853
|
};
|
|
1831
1854
|
try {
|
|
@@ -1839,7 +1862,7 @@ async function getDomainAge(domain, timeout = 5e3, debug = false) {
|
|
|
1839
1862
|
log(`[whois] domain validation failed: ${cleanDomain}`);
|
|
1840
1863
|
return null;
|
|
1841
1864
|
}
|
|
1842
|
-
const whoisData = await getWhoisData(cleanDomain, timeout, debug);
|
|
1865
|
+
const whoisData = await getWhoisData(cleanDomain, timeout, debug, cache);
|
|
1843
1866
|
if (!whoisData || !whoisData.creationDate) {
|
|
1844
1867
|
log(`[whois] no creation date found for ${cleanDomain}`);
|
|
1845
1868
|
return null;
|
|
@@ -1863,7 +1886,7 @@ async function getDomainAge(domain, timeout = 5e3, debug = false) {
|
|
|
1863
1886
|
return null;
|
|
1864
1887
|
}
|
|
1865
1888
|
}
|
|
1866
|
-
async function getDomainRegistrationStatus(domain, timeout = 5e3, debug = false) {
|
|
1889
|
+
async function getDomainRegistrationStatus(domain, timeout = 5e3, debug = false, cache) {
|
|
1867
1890
|
const log = debug ? console.debug : (..._args) => {
|
|
1868
1891
|
};
|
|
1869
1892
|
try {
|
|
@@ -1877,7 +1900,7 @@ async function getDomainRegistrationStatus(domain, timeout = 5e3, debug = false)
|
|
|
1877
1900
|
log(`[whois] domain validation failed: ${cleanDomain}`);
|
|
1878
1901
|
return null;
|
|
1879
1902
|
}
|
|
1880
|
-
const whoisData = await getWhoisData(cleanDomain, timeout, debug);
|
|
1903
|
+
const whoisData = await getWhoisData(cleanDomain, timeout, debug, cache);
|
|
1881
1904
|
if (!whoisData || whoisData.isAvailable) {
|
|
1882
1905
|
log(`[whois] domain ${cleanDomain} is available or not registered`);
|
|
1883
1906
|
return {
|
|
@@ -2112,109 +2135,6 @@ function createErrorResult(email, _error) {
|
|
|
2112
2135
|
};
|
|
2113
2136
|
}
|
|
2114
2137
|
|
|
2115
|
-
const CacheFactory = {
|
|
2116
|
-
/**
|
|
2117
|
-
* Create a cache with LRU (tiny-lru) backend
|
|
2118
|
-
*/
|
|
2119
|
-
createLRUCache(customTtl) {
|
|
2120
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2121
|
-
return {
|
|
2122
|
-
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),
|
|
2123
|
-
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),
|
|
2124
|
-
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),
|
|
2125
|
-
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),
|
|
2126
|
-
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),
|
|
2127
|
-
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),
|
|
2128
|
-
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)
|
|
2129
|
-
};
|
|
2130
|
-
},
|
|
2131
|
-
/**
|
|
2132
|
-
* Create a cache with Redis backend
|
|
2133
|
-
*/
|
|
2134
|
-
createRedisCache(redis, options) {
|
|
2135
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2136
|
-
const { keyPrefix = "email_validator:", customTtl, jsonSerializer } = options !== null && options !== void 0 ? options : {};
|
|
2137
|
-
return {
|
|
2138
|
-
mx: new RedisAdapter(redis, {
|
|
2139
|
-
keyPrefix: `${keyPrefix}mx:`,
|
|
2140
|
-
defaultTtlMs: (_a = customTtl === null || customTtl === void 0 ? void 0 : customTtl.mx) !== null && _a !== void 0 ? _a : DEFAULT_CACHE_TTL.mx,
|
|
2141
|
-
jsonSerializer
|
|
2142
|
-
}),
|
|
2143
|
-
disposable: new RedisAdapter(redis, {
|
|
2144
|
-
keyPrefix: `${keyPrefix}disposable:`,
|
|
2145
|
-
defaultTtlMs: (_b = customTtl === null || customTtl === void 0 ? void 0 : customTtl.disposable) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TTL.disposable,
|
|
2146
|
-
jsonSerializer
|
|
2147
|
-
}),
|
|
2148
|
-
free: new RedisAdapter(redis, {
|
|
2149
|
-
keyPrefix: `${keyPrefix}free:`,
|
|
2150
|
-
defaultTtlMs: (_c = customTtl === null || customTtl === void 0 ? void 0 : customTtl.free) !== null && _c !== void 0 ? _c : DEFAULT_CACHE_TTL.free,
|
|
2151
|
-
jsonSerializer
|
|
2152
|
-
}),
|
|
2153
|
-
domainValid: new RedisAdapter(redis, {
|
|
2154
|
-
keyPrefix: `${keyPrefix}domain_valid:`,
|
|
2155
|
-
defaultTtlMs: (_d = customTtl === null || customTtl === void 0 ? void 0 : customTtl.domainValid) !== null && _d !== void 0 ? _d : DEFAULT_CACHE_TTL.domainValid,
|
|
2156
|
-
jsonSerializer
|
|
2157
|
-
}),
|
|
2158
|
-
smtp: new RedisAdapter(redis, {
|
|
2159
|
-
keyPrefix: `${keyPrefix}smtp:`,
|
|
2160
|
-
defaultTtlMs: (_e = customTtl === null || customTtl === void 0 ? void 0 : customTtl.smtp) !== null && _e !== void 0 ? _e : DEFAULT_CACHE_TTL.smtp,
|
|
2161
|
-
jsonSerializer
|
|
2162
|
-
}),
|
|
2163
|
-
domainSuggestion: new RedisAdapter(redis, {
|
|
2164
|
-
keyPrefix: `${keyPrefix}domain_suggestion:`,
|
|
2165
|
-
defaultTtlMs: (_f = customTtl === null || customTtl === void 0 ? void 0 : customTtl.domainSuggestion) !== null && _f !== void 0 ? _f : DEFAULT_CACHE_TTL.domainSuggestion,
|
|
2166
|
-
jsonSerializer
|
|
2167
|
-
}),
|
|
2168
|
-
whois: new RedisAdapter(redis, {
|
|
2169
|
-
keyPrefix: `${keyPrefix}whois:`,
|
|
2170
|
-
defaultTtlMs: (_g = customTtl === null || customTtl === void 0 ? void 0 : customTtl.whois) !== null && _g !== void 0 ? _g : DEFAULT_CACHE_TTL.whois,
|
|
2171
|
-
jsonSerializer
|
|
2172
|
-
})
|
|
2173
|
-
};
|
|
2174
|
-
},
|
|
2175
|
-
/**
|
|
2176
|
-
* Create a cache with custom backend
|
|
2177
|
-
*/
|
|
2178
|
-
createCustomCache(storeFactory, customTtl) {
|
|
2179
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2180
|
-
return {
|
|
2181
|
-
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),
|
|
2182
|
-
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),
|
|
2183
|
-
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),
|
|
2184
|
-
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),
|
|
2185
|
-
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),
|
|
2186
|
-
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),
|
|
2187
|
-
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)
|
|
2188
|
-
};
|
|
2189
|
-
},
|
|
2190
|
-
/**
|
|
2191
|
-
* Create a mixed cache with different backends for different cache types
|
|
2192
|
-
*/
|
|
2193
|
-
createMixedCache(config) {
|
|
2194
|
-
const createCache = (cacheType, config2) => {
|
|
2195
|
-
var _a, _b;
|
|
2196
|
-
if (config2 === null || config2 === void 0 ? void 0 : config2.store) {
|
|
2197
|
-
return config2.store;
|
|
2198
|
-
}
|
|
2199
|
-
const ttlMs = (_a = config2 === null || config2 === void 0 ? void 0 : config2.ttlMs) !== null && _a !== void 0 ? _a : DEFAULT_CACHE_TTL[cacheType];
|
|
2200
|
-
const maxSize = (_b = config2 === null || config2 === void 0 ? void 0 : config2.maxSize) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_SIZE[cacheType];
|
|
2201
|
-
if ((config2 === null || config2 === void 0 ? void 0 : config2.store) && "get" in config2.store && "set" in config2.store) {
|
|
2202
|
-
return config2.store;
|
|
2203
|
-
}
|
|
2204
|
-
return new LRUAdapter(maxSize, ttlMs);
|
|
2205
|
-
};
|
|
2206
|
-
return {
|
|
2207
|
-
mx: createCache("mx", config.mx),
|
|
2208
|
-
disposable: createCache("disposable", config.disposable),
|
|
2209
|
-
free: createCache("free", config.free),
|
|
2210
|
-
domainValid: createCache("domainValid", config.domainValid),
|
|
2211
|
-
smtp: createCache("smtp", config.smtp),
|
|
2212
|
-
domainSuggestion: createCache("domainSuggestion", config.domainSuggestion),
|
|
2213
|
-
whois: createCache("whois", config.whois)
|
|
2214
|
-
};
|
|
2215
|
-
}
|
|
2216
|
-
};
|
|
2217
|
-
|
|
2218
2138
|
let disposableEmailProviders;
|
|
2219
2139
|
let freeEmailProviders;
|
|
2220
2140
|
async function isDisposableEmail(params) {
|
|
@@ -2226,7 +2146,7 @@ async function isDisposableEmail(params) {
|
|
|
2226
2146
|
if (!emailDomain) {
|
|
2227
2147
|
return false;
|
|
2228
2148
|
}
|
|
2229
|
-
const cacheStore =
|
|
2149
|
+
const cacheStore = getCacheStore(cache, "disposable");
|
|
2230
2150
|
let cached;
|
|
2231
2151
|
try {
|
|
2232
2152
|
cached = await cacheStore.get(emailDomain);
|
|
@@ -2259,7 +2179,7 @@ async function isFreeEmail(params) {
|
|
|
2259
2179
|
if (!emailDomain) {
|
|
2260
2180
|
return false;
|
|
2261
2181
|
}
|
|
2262
|
-
const cacheStore =
|
|
2182
|
+
const cacheStore = getCacheStore(cache, "free");
|
|
2263
2183
|
let cached;
|
|
2264
2184
|
try {
|
|
2265
2185
|
cached = await cacheStore.get(emailDomain);
|
|
@@ -2370,7 +2290,7 @@ async function verifyEmail(params) {
|
|
|
2370
2290
|
if (checkDomainAge && !shouldSkipDomainWhois) {
|
|
2371
2291
|
log(`[verifyEmail] Checking domain age for ${domain}`);
|
|
2372
2292
|
try {
|
|
2373
|
-
result.domainAge = await getDomainAge(domain, whoisTimeout, debug);
|
|
2293
|
+
result.domainAge = await getDomainAge(domain, whoisTimeout, debug, params.cache);
|
|
2374
2294
|
log(`[verifyEmail] Domain age result:`, result.domainAge ? `${result.domainAge.ageInDays} days` : "null");
|
|
2375
2295
|
} catch (err) {
|
|
2376
2296
|
log("[verifyEmail] Failed to get domain age", err);
|
|
@@ -2382,7 +2302,7 @@ async function verifyEmail(params) {
|
|
|
2382
2302
|
if (checkDomainRegistration && !shouldSkipDomainWhois) {
|
|
2383
2303
|
log(`[verifyEmail] Checking domain registration status for ${domain}`);
|
|
2384
2304
|
try {
|
|
2385
|
-
result.domainRegistration = await getDomainRegistrationStatus(domain, whoisTimeout, debug);
|
|
2305
|
+
result.domainRegistration = await getDomainRegistrationStatus(domain, whoisTimeout, debug, params.cache);
|
|
2386
2306
|
log(`[verifyEmail] Domain registration result:`, ((_a = result.domainRegistration) === null || _a === void 0 ? void 0 : _a.isRegistered) ? "registered" : "not registered");
|
|
2387
2307
|
} catch (err) {
|
|
2388
2308
|
log("[verifyEmail] Failed to get domain registration status", err);
|
|
@@ -2402,7 +2322,7 @@ async function verifyEmail(params) {
|
|
|
2402
2322
|
}
|
|
2403
2323
|
if (verifySmtp && mxRecords.length > 0) {
|
|
2404
2324
|
const cacheKey = `${emailAddress}:smtp`;
|
|
2405
|
-
const smtpCacheInstance =
|
|
2325
|
+
const smtpCacheInstance = getCacheStore(params.cache, "smtp");
|
|
2406
2326
|
const cachedSmtp = await smtpCacheInstance.get(cacheKey);
|
|
2407
2327
|
if (cachedSmtp !== null && cachedSmtp !== void 0) {
|
|
2408
2328
|
result.validSmtp = cachedSmtp;
|
|
@@ -2461,17 +2381,17 @@ async function verifyEmail(params) {
|
|
|
2461
2381
|
}
|
|
2462
2382
|
|
|
2463
2383
|
exports.COMMON_EMAIL_DOMAINS = COMMON_EMAIL_DOMAINS;
|
|
2464
|
-
exports.
|
|
2465
|
-
exports.DEFAULT_CACHE_SIZE = DEFAULT_CACHE_SIZE;
|
|
2466
|
-
exports.DEFAULT_CACHE_TTL = DEFAULT_CACHE_TTL;
|
|
2384
|
+
exports.DEFAULT_CACHE_OPTIONS = DEFAULT_CACHE_OPTIONS;
|
|
2467
2385
|
exports.LRUAdapter = LRUAdapter;
|
|
2468
2386
|
exports.RedisAdapter = RedisAdapter;
|
|
2469
|
-
exports.
|
|
2387
|
+
exports.clearDefaultCache = clearDefaultCache;
|
|
2470
2388
|
exports.defaultDomainSuggestionMethod = defaultDomainSuggestionMethod;
|
|
2471
2389
|
exports.defaultNameDetectionMethod = defaultNameDetectionMethod;
|
|
2472
2390
|
exports.detectName = detectName;
|
|
2473
2391
|
exports.detectNameFromEmail = detectNameFromEmail;
|
|
2474
2392
|
exports.domainPorts = domainPorts;
|
|
2393
|
+
exports.getCacheStore = getCacheStore;
|
|
2394
|
+
exports.getDefaultCache = getDefaultCache;
|
|
2475
2395
|
exports.getDomainAge = getDomainAge;
|
|
2476
2396
|
exports.getDomainRegistrationStatus = getDomainRegistrationStatus;
|
|
2477
2397
|
exports.getDomainSimilarity = getDomainSimilarity;
|
|
@@ -2480,6 +2400,7 @@ exports.isDisposableEmail = isDisposableEmail;
|
|
|
2480
2400
|
exports.isFreeEmail = isFreeEmail;
|
|
2481
2401
|
exports.isValidEmail = isValidEmail;
|
|
2482
2402
|
exports.isValidEmailDomain = isValidEmailDomain;
|
|
2403
|
+
exports.resetDefaultCache = resetDefaultCache;
|
|
2483
2404
|
exports.suggestDomain = suggestDomain;
|
|
2484
2405
|
exports.suggestEmailDomain = suggestEmailDomain;
|
|
2485
2406
|
exports.verifyEmail = verifyEmail;
|