@emailcheck/email-validator-js 2.13.1-beta.0 → 2.13.1-beta.2
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 +62 -77
- package/dist/index.d.ts +3 -7
- package/dist/index.esm.js +97 -154
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +96 -154
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +10 -35
- package/dist/whois.d.ts +2 -2
- package/package.json +3 -2
package/dist/index.esm.js
CHANGED
|
@@ -1732,37 +1732,50 @@ const WHOIS_SERVERS = {
|
|
|
1732
1732
|
ar: "whois.nic.ar",
|
|
1733
1733
|
cl: "whois.nic.cl"
|
|
1734
1734
|
};
|
|
1735
|
-
function queryWhoisServer(domain, server, timeout = 5e3) {
|
|
1735
|
+
function queryWhoisServer(domain, server, timeout = 5e3, debug = false) {
|
|
1736
|
+
const log = debug ? console.debug : (..._args) => {
|
|
1737
|
+
};
|
|
1736
1738
|
return new Promise((resolve, reject) => {
|
|
1737
1739
|
const client = new net.Socket();
|
|
1738
1740
|
let data = "";
|
|
1741
|
+
log(`[whois] querying ${server} for domain ${domain}`);
|
|
1739
1742
|
const timer = setTimeout(() => {
|
|
1743
|
+
log(`[whois] timeout after ${timeout}ms for ${domain} at ${server}`);
|
|
1740
1744
|
client.destroy();
|
|
1741
1745
|
reject(new Error("WHOIS query timeout"));
|
|
1742
1746
|
}, timeout);
|
|
1743
1747
|
client.connect(43, server, () => {
|
|
1748
|
+
log(`[whois] connected to ${server}, sending query for ${domain}`);
|
|
1744
1749
|
client.write(`${domain}\r
|
|
1745
1750
|
`);
|
|
1746
1751
|
});
|
|
1747
1752
|
client.on("data", (chunk) => {
|
|
1748
|
-
|
|
1753
|
+
const chunkStr = chunk.toString();
|
|
1754
|
+
data += chunkStr;
|
|
1755
|
+
log(`[whois] received ${chunkStr.length} bytes from ${server}`);
|
|
1749
1756
|
});
|
|
1750
1757
|
client.on("close", () => {
|
|
1751
1758
|
clearTimeout(timer);
|
|
1759
|
+
log(`[whois] connection closed, received total ${data.length} bytes from ${server}`);
|
|
1752
1760
|
resolve(data);
|
|
1753
1761
|
});
|
|
1754
1762
|
client.on("error", (err) => {
|
|
1755
1763
|
clearTimeout(timer);
|
|
1764
|
+
log(`[whois] error querying ${server}: ${err.message}`);
|
|
1756
1765
|
reject(err);
|
|
1757
1766
|
});
|
|
1758
1767
|
});
|
|
1759
1768
|
}
|
|
1760
|
-
async function getWhoisData(domain, timeout = 5e3) {
|
|
1769
|
+
async function getWhoisData(domain, timeout = 5e3, debug = false) {
|
|
1761
1770
|
var _a;
|
|
1771
|
+
const log = debug ? console.debug : (..._args) => {
|
|
1772
|
+
};
|
|
1762
1773
|
const cacheKey = `whois:${domain}`;
|
|
1763
1774
|
const cache = whoisCacheStore();
|
|
1775
|
+
log(`[whois] getting WHOIS data for ${domain}`);
|
|
1764
1776
|
const cached = await cache.get(cacheKey);
|
|
1765
1777
|
if (cached !== null && cached !== void 0) {
|
|
1778
|
+
log(`[whois] using cached data for ${domain}`);
|
|
1766
1779
|
return cached;
|
|
1767
1780
|
}
|
|
1768
1781
|
try {
|
|
@@ -1770,41 +1783,55 @@ async function getWhoisData(domain, timeout = 5e3) {
|
|
|
1770
1783
|
if (!tld) {
|
|
1771
1784
|
throw new Error("Invalid domain");
|
|
1772
1785
|
}
|
|
1786
|
+
log(`[whois] extracted TLD: ${tld} for domain: ${domain}`);
|
|
1773
1787
|
const whoisServer = WHOIS_SERVERS[tld];
|
|
1774
1788
|
if (!whoisServer) {
|
|
1789
|
+
log(`[whois] no specific server for TLD ${tld}, trying IANA`);
|
|
1775
1790
|
const defaultServer = "whois.iana.org";
|
|
1776
|
-
const ianaResponse = await queryWhoisServer(domain, defaultServer, timeout);
|
|
1791
|
+
const ianaResponse = await queryWhoisServer(domain, defaultServer, timeout, debug);
|
|
1777
1792
|
const referMatch = ianaResponse.match(/refer:\s+(\S+)/i);
|
|
1778
1793
|
if (referMatch === null || referMatch === void 0 ? void 0 : referMatch[1]) {
|
|
1779
1794
|
const referredServer = referMatch[1];
|
|
1780
|
-
|
|
1795
|
+
log(`[whois] IANA referred to ${referredServer} for ${domain}`);
|
|
1796
|
+
const whoisResponse2 = await queryWhoisServer(domain, referredServer, timeout, debug);
|
|
1781
1797
|
const whoisData3 = parseWhoisData({ rawData: whoisResponse2, domain });
|
|
1782
1798
|
await cache.set(cacheKey, whoisData3);
|
|
1799
|
+
log(`[whois] successfully retrieved and cached WHOIS data from referred server for ${domain}`);
|
|
1783
1800
|
return whoisData3;
|
|
1784
1801
|
}
|
|
1785
1802
|
const whoisData2 = parseWhoisData({ rawData: ianaResponse, domain });
|
|
1786
1803
|
await cache.set(cacheKey, whoisData2);
|
|
1804
|
+
log(`[whois] successfully retrieved and cached WHOIS data from IANA for ${domain}`);
|
|
1787
1805
|
return whoisData2;
|
|
1788
1806
|
}
|
|
1789
|
-
|
|
1807
|
+
log(`[whois] using WHOIS server ${whoisServer} for TLD ${tld}`);
|
|
1808
|
+
const whoisResponse = await queryWhoisServer(domain, whoisServer, timeout, debug);
|
|
1790
1809
|
const whoisData = parseWhoisData({ rawData: whoisResponse, domain });
|
|
1791
1810
|
await cache.set(cacheKey, whoisData);
|
|
1811
|
+
log(`[whois] successfully retrieved and cached WHOIS data for ${domain}`);
|
|
1792
1812
|
return whoisData;
|
|
1793
1813
|
} catch (_error) {
|
|
1814
|
+
log(`[whois] failed to get WHOIS data for ${domain}: ${_error instanceof Error ? _error.message : "Unknown error"}`);
|
|
1794
1815
|
return null;
|
|
1795
1816
|
}
|
|
1796
1817
|
}
|
|
1797
|
-
async function getDomainAge(domain, timeout = 5e3) {
|
|
1818
|
+
async function getDomainAge(domain, timeout = 5e3, debug = false) {
|
|
1819
|
+
const log = debug ? console.debug : (..._args) => {
|
|
1820
|
+
};
|
|
1798
1821
|
try {
|
|
1799
1822
|
const cleanDomain = domain.replace(/^https?:\/\//, "").split("/")[0].split("@").pop();
|
|
1800
1823
|
if (!cleanDomain) {
|
|
1824
|
+
log(`[whois] invalid domain format: ${domain}`);
|
|
1801
1825
|
return null;
|
|
1802
1826
|
}
|
|
1827
|
+
log(`[whois] checking domain age for ${cleanDomain}`);
|
|
1803
1828
|
if (!isValid(cleanDomain)) {
|
|
1829
|
+
log(`[whois] domain validation failed: ${cleanDomain}`);
|
|
1804
1830
|
return null;
|
|
1805
1831
|
}
|
|
1806
|
-
const whoisData = await getWhoisData(cleanDomain, timeout);
|
|
1832
|
+
const whoisData = await getWhoisData(cleanDomain, timeout, debug);
|
|
1807
1833
|
if (!whoisData || !whoisData.creationDate) {
|
|
1834
|
+
log(`[whois] no creation date found for ${cleanDomain}`);
|
|
1808
1835
|
return null;
|
|
1809
1836
|
}
|
|
1810
1837
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -1812,6 +1839,7 @@ async function getDomainAge(domain, timeout = 5e3) {
|
|
|
1812
1839
|
const ageInMilliseconds = now.getTime() - creationDate.getTime();
|
|
1813
1840
|
const ageInDays = Math.floor(ageInMilliseconds / (1e3 * 60 * 60 * 24));
|
|
1814
1841
|
const ageInYears = ageInDays / 365.25;
|
|
1842
|
+
log(`[whois] calculated age for ${cleanDomain}: ${ageInDays} days (${ageInYears.toFixed(2)} years)`);
|
|
1815
1843
|
return {
|
|
1816
1844
|
domain: cleanDomain,
|
|
1817
1845
|
creationDate,
|
|
@@ -1821,20 +1849,27 @@ async function getDomainAge(domain, timeout = 5e3) {
|
|
|
1821
1849
|
updatedDate: whoisData.updatedDate ? new Date(whoisData.updatedDate) : null
|
|
1822
1850
|
};
|
|
1823
1851
|
} catch (_error) {
|
|
1852
|
+
log(`[whois] error getting domain age for ${domain}: ${_error instanceof Error ? _error.message : "Unknown error"}`);
|
|
1824
1853
|
return null;
|
|
1825
1854
|
}
|
|
1826
1855
|
}
|
|
1827
|
-
async function getDomainRegistrationStatus(domain, timeout = 5e3) {
|
|
1856
|
+
async function getDomainRegistrationStatus(domain, timeout = 5e3, debug = false) {
|
|
1857
|
+
const log = debug ? console.debug : (..._args) => {
|
|
1858
|
+
};
|
|
1828
1859
|
try {
|
|
1829
1860
|
const cleanDomain = domain.replace(/^https?:\/\//, "").split("/")[0].split("@").pop();
|
|
1830
1861
|
if (!cleanDomain) {
|
|
1862
|
+
log(`[whois] invalid domain format: ${domain}`);
|
|
1831
1863
|
return null;
|
|
1832
1864
|
}
|
|
1865
|
+
log(`[whois] checking domain registration status for ${cleanDomain}`);
|
|
1833
1866
|
if (!isValid(cleanDomain)) {
|
|
1867
|
+
log(`[whois] domain validation failed: ${cleanDomain}`);
|
|
1834
1868
|
return null;
|
|
1835
1869
|
}
|
|
1836
|
-
const whoisData = await getWhoisData(cleanDomain, timeout);
|
|
1870
|
+
const whoisData = await getWhoisData(cleanDomain, timeout, debug);
|
|
1837
1871
|
if (!whoisData || whoisData.isAvailable) {
|
|
1872
|
+
log(`[whois] domain ${cleanDomain} is available or not registered`);
|
|
1838
1873
|
return {
|
|
1839
1874
|
domain: cleanDomain,
|
|
1840
1875
|
isRegistered: false,
|
|
@@ -1862,6 +1897,7 @@ async function getDomainRegistrationStatus(domain, timeout = 5e3) {
|
|
|
1862
1897
|
if (!isExpired) {
|
|
1863
1898
|
daysUntilExpiration = Math.floor((expirationTime - currentTime) / (1e3 * 60 * 60 * 24));
|
|
1864
1899
|
}
|
|
1900
|
+
log(`[whois] domain ${cleanDomain} expires in ${daysUntilExpiration} days`);
|
|
1865
1901
|
}
|
|
1866
1902
|
const statusList = whoisData.status || [];
|
|
1867
1903
|
const formattedStatusList = statusList.map((s) => {
|
|
@@ -1870,6 +1906,7 @@ async function getDomainRegistrationStatus(domain, timeout = 5e3) {
|
|
|
1870
1906
|
});
|
|
1871
1907
|
const isPendingDelete = formattedStatusList.some((s) => s.toLowerCase().includes("pendingdelete") || s.toLowerCase().includes("redemption"));
|
|
1872
1908
|
const isLocked = formattedStatusList.some((s) => s.toLowerCase().includes("clienttransferprohibited") || s.toLowerCase().includes("servertransferprohibited"));
|
|
1909
|
+
log(`[whois] domain ${cleanDomain} - registered: ${isRegistered}, expired: ${isExpired}, locked: ${isLocked}, pending delete: ${isPendingDelete}`);
|
|
1873
1910
|
return {
|
|
1874
1911
|
domain: cleanDomain,
|
|
1875
1912
|
isRegistered,
|
|
@@ -1884,6 +1921,7 @@ async function getDomainRegistrationStatus(domain, timeout = 5e3) {
|
|
|
1884
1921
|
isLocked
|
|
1885
1922
|
};
|
|
1886
1923
|
} catch (_error) {
|
|
1924
|
+
log(`[whois] error getting domain registration status for ${domain}: ${_error instanceof Error ? _error.message : "Unknown error"}`);
|
|
1887
1925
|
return null;
|
|
1888
1926
|
}
|
|
1889
1927
|
}
|
|
@@ -1902,7 +1940,7 @@ async function verifyEmailBatch(params) {
|
|
|
1902
1940
|
for (const batch of batches) {
|
|
1903
1941
|
const batchPromises = batch.map(async (email) => {
|
|
1904
1942
|
try {
|
|
1905
|
-
const result = await
|
|
1943
|
+
const result = await verifyEmail({
|
|
1906
1944
|
emailAddress: email,
|
|
1907
1945
|
timeout,
|
|
1908
1946
|
verifyMx,
|
|
@@ -1916,7 +1954,7 @@ async function verifyEmailBatch(params) {
|
|
|
1916
1954
|
commonDomains,
|
|
1917
1955
|
cache
|
|
1918
1956
|
});
|
|
1919
|
-
if (result.
|
|
1957
|
+
if (result.validFormat) {
|
|
1920
1958
|
totalValid++;
|
|
1921
1959
|
} else {
|
|
1922
1960
|
totalInvalid++;
|
|
@@ -1926,7 +1964,7 @@ async function verifyEmailBatch(params) {
|
|
|
1926
1964
|
totalErrors++;
|
|
1927
1965
|
return {
|
|
1928
1966
|
email,
|
|
1929
|
-
result:
|
|
1967
|
+
result: createErrorResult(email)
|
|
1930
1968
|
};
|
|
1931
1969
|
}
|
|
1932
1970
|
});
|
|
@@ -1946,18 +1984,18 @@ async function verifyEmailBatch(params) {
|
|
|
1946
1984
|
}
|
|
1947
1985
|
};
|
|
1948
1986
|
}
|
|
1949
|
-
function
|
|
1987
|
+
function createErrorResult(email, _error) {
|
|
1950
1988
|
return {
|
|
1951
|
-
valid: false,
|
|
1952
1989
|
email,
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1990
|
+
validFormat: false,
|
|
1991
|
+
validMx: null,
|
|
1992
|
+
validSmtp: null,
|
|
1993
|
+
isDisposable: false,
|
|
1994
|
+
isFree: false,
|
|
1958
1995
|
metadata: {
|
|
1959
1996
|
verificationTime: 0,
|
|
1960
|
-
cached: false
|
|
1997
|
+
cached: false,
|
|
1998
|
+
error: VerificationErrorCode.SMTP_CONNECTION_FAILED
|
|
1961
1999
|
}
|
|
1962
2000
|
};
|
|
1963
2001
|
}
|
|
@@ -2022,129 +2060,30 @@ const domainPorts = {
|
|
|
2022
2060
|
"ovh.net": 465
|
|
2023
2061
|
};
|
|
2024
2062
|
async function verifyEmail(params) {
|
|
2025
|
-
const { emailAddress, timeout = 4e3, verifyMx = false, verifySmtp = false, debug = false, detectName: detectName2 = false, nameDetectionMethod, suggestDomain: suggestDomain2 = false, domainSuggestionMethod, commonDomains, checkDomainAge = false, checkDomainRegistration = false, whoisTimeout = 5e3 } = params;
|
|
2026
|
-
const result = { validFormat: false, validMx: null, validSmtp: null };
|
|
2027
|
-
const log = debug ? console.debug : (..._args) => {
|
|
2028
|
-
};
|
|
2029
|
-
let mxRecords;
|
|
2030
|
-
if (!isValidEmail(emailAddress)) {
|
|
2031
|
-
log("[verifyEmail] Failed on wellFormed check");
|
|
2032
|
-
return result;
|
|
2033
|
-
}
|
|
2034
|
-
const [local, domain] = emailAddress.split("@");
|
|
2035
|
-
if (!domain || !local) {
|
|
2036
|
-
log("[verifyEmail] Failed on wellFormed check");
|
|
2037
|
-
return result;
|
|
2038
|
-
}
|
|
2039
|
-
result.validFormat = true;
|
|
2040
|
-
if (detectName2) {
|
|
2041
|
-
result.detectedName = detectNameFromEmail({
|
|
2042
|
-
email: emailAddress,
|
|
2043
|
-
customMethod: nameDetectionMethod
|
|
2044
|
-
});
|
|
2045
|
-
}
|
|
2046
|
-
if (suggestDomain2) {
|
|
2047
|
-
const [, emailDomain] = emailAddress.split("@");
|
|
2048
|
-
if (emailDomain) {
|
|
2049
|
-
result.domainSuggestion = domainSuggestionMethod ? domainSuggestionMethod(emailDomain) : await suggestEmailDomain(emailAddress, commonDomains);
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
if (checkDomainAge) {
|
|
2053
|
-
try {
|
|
2054
|
-
result.domainAge = await getDomainAge(domain, whoisTimeout);
|
|
2055
|
-
} catch (err) {
|
|
2056
|
-
log("[verifyEmail] Failed to get domain age", err);
|
|
2057
|
-
result.domainAge = null;
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
if (checkDomainRegistration) {
|
|
2061
|
-
try {
|
|
2062
|
-
result.domainRegistration = await getDomainRegistrationStatus(domain, whoisTimeout);
|
|
2063
|
-
} catch (err) {
|
|
2064
|
-
log("[verifyEmail] Failed to get domain registration status", err);
|
|
2065
|
-
result.domainRegistration = null;
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
if (!verifyMx && !verifySmtp)
|
|
2069
|
-
return result;
|
|
2070
|
-
try {
|
|
2071
|
-
mxRecords = await resolveMxRecords(domain, params.cache);
|
|
2072
|
-
log("[verifyEmail] Found MX records", mxRecords);
|
|
2073
|
-
} catch (err) {
|
|
2074
|
-
log("[verifyEmail] Failed to resolve MX records", err);
|
|
2075
|
-
mxRecords = [];
|
|
2076
|
-
}
|
|
2077
|
-
if (verifyMx || verifySmtp) {
|
|
2078
|
-
result.validMx = mxRecords && mxRecords.length > 0;
|
|
2079
|
-
}
|
|
2080
|
-
if (verifySmtp && !(mxRecords === null || mxRecords === void 0 ? void 0 : mxRecords.length)) {
|
|
2081
|
-
result.validSmtp = false;
|
|
2082
|
-
}
|
|
2083
|
-
if (verifySmtp && (mxRecords === null || mxRecords === void 0 ? void 0 : mxRecords.length) > 0) {
|
|
2084
|
-
const cacheKey = `${emailAddress}:smtp`;
|
|
2085
|
-
const smtpCacheInstance = smtpCacheStore(params.cache);
|
|
2086
|
-
const cachedSmtp = await smtpCacheInstance.get(cacheKey);
|
|
2087
|
-
if (cachedSmtp !== null && cachedSmtp !== void 0) {
|
|
2088
|
-
result.validSmtp = cachedSmtp;
|
|
2089
|
-
if (detectName2 && !result.detectedName) {
|
|
2090
|
-
result.detectedName = detectNameFromEmail({
|
|
2091
|
-
email: emailAddress,
|
|
2092
|
-
customMethod: nameDetectionMethod
|
|
2093
|
-
});
|
|
2094
|
-
}
|
|
2095
|
-
return result;
|
|
2096
|
-
}
|
|
2097
|
-
let domainPort = params.smtpPort;
|
|
2098
|
-
if (!domainPort) {
|
|
2099
|
-
const mxDomain = parse(mxRecords[0]);
|
|
2100
|
-
if ("domain" in mxDomain && mxDomain.domain) {
|
|
2101
|
-
domainPort = domainPorts[mxDomain.domain];
|
|
2102
|
-
log(`[verifyEmail] Found mxDomain ${mxDomain.domain} with port ${domainPort}`);
|
|
2103
|
-
}
|
|
2104
|
-
if ("error" in mxDomain) {
|
|
2105
|
-
log(`[verifyEmail] Failed to parse mxDomain ${mxDomain.error}`);
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
const smtpResult = await verifyMailboxSMTP({
|
|
2109
|
-
local,
|
|
2110
|
-
domain,
|
|
2111
|
-
mxRecords,
|
|
2112
|
-
timeout,
|
|
2113
|
-
debug,
|
|
2114
|
-
port: domainPort,
|
|
2115
|
-
retryAttempts: params.retryAttempts
|
|
2116
|
-
});
|
|
2117
|
-
await smtpCacheInstance.set(cacheKey, smtpResult);
|
|
2118
|
-
result.validSmtp = smtpResult;
|
|
2119
|
-
}
|
|
2120
|
-
return result;
|
|
2121
|
-
}
|
|
2122
|
-
async function verifyEmailDetailed(params) {
|
|
2123
2063
|
const { emailAddress, timeout = 4e3, verifyMx = true, verifySmtp = false, debug = false, checkDisposable = true, checkFree = true, detectName: detectName2 = false, nameDetectionMethod, suggestDomain: suggestDomain2 = true, domainSuggestionMethod, commonDomains, checkDomainAge = false, checkDomainRegistration = false, whoisTimeout = 5e3 } = params;
|
|
2124
2064
|
const startTime = Date.now();
|
|
2125
2065
|
const log = debug ? console.debug : (..._args) => {
|
|
2126
2066
|
};
|
|
2127
2067
|
const result = {
|
|
2128
|
-
valid: false,
|
|
2129
2068
|
email: emailAddress,
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2069
|
+
validFormat: false,
|
|
2070
|
+
validMx: null,
|
|
2071
|
+
validSmtp: null,
|
|
2072
|
+
isDisposable: false,
|
|
2073
|
+
isFree: false,
|
|
2135
2074
|
metadata: {
|
|
2136
2075
|
verificationTime: 0,
|
|
2137
2076
|
cached: false
|
|
2138
2077
|
}
|
|
2139
2078
|
};
|
|
2140
2079
|
if (!isValidEmail(emailAddress)) {
|
|
2141
|
-
result.format.error = VerificationErrorCode.INVALID_FORMAT;
|
|
2142
2080
|
if (result.metadata) {
|
|
2143
2081
|
result.metadata.verificationTime = Date.now() - startTime;
|
|
2082
|
+
result.metadata.error = VerificationErrorCode.INVALID_FORMAT;
|
|
2144
2083
|
}
|
|
2145
2084
|
return result;
|
|
2146
2085
|
}
|
|
2147
|
-
result.
|
|
2086
|
+
result.validFormat = true;
|
|
2148
2087
|
if (detectName2) {
|
|
2149
2088
|
result.detectedName = detectNameFromEmail({
|
|
2150
2089
|
email: emailAddress,
|
|
@@ -2154,64 +2093,67 @@ async function verifyEmailDetailed(params) {
|
|
|
2154
2093
|
if (suggestDomain2) {
|
|
2155
2094
|
const [, emailDomain] = emailAddress.split("@");
|
|
2156
2095
|
if (emailDomain) {
|
|
2157
|
-
|
|
2096
|
+
const suggestion = domainSuggestionMethod ? domainSuggestionMethod(emailDomain) : await suggestEmailDomain(emailAddress, commonDomains);
|
|
2097
|
+
if (suggestion) {
|
|
2098
|
+
result.domainSuggestion = suggestion;
|
|
2099
|
+
} else {
|
|
2100
|
+
result.domainSuggestion = null;
|
|
2101
|
+
}
|
|
2158
2102
|
}
|
|
2159
2103
|
}
|
|
2160
2104
|
const [local, domain] = emailAddress.split("@");
|
|
2161
2105
|
if (!domain || !local) {
|
|
2162
|
-
result.format.error = VerificationErrorCode.INVALID_FORMAT;
|
|
2163
2106
|
if (result.metadata) {
|
|
2164
2107
|
result.metadata.verificationTime = Date.now() - startTime;
|
|
2108
|
+
result.metadata.error = VerificationErrorCode.INVALID_FORMAT;
|
|
2165
2109
|
}
|
|
2166
2110
|
return result;
|
|
2167
2111
|
}
|
|
2168
2112
|
if (!await isValidEmailDomain(domain, params.cache)) {
|
|
2169
|
-
result.domain.error = VerificationErrorCode.INVALID_DOMAIN;
|
|
2170
2113
|
if (result.metadata) {
|
|
2171
2114
|
result.metadata.verificationTime = Date.now() - startTime;
|
|
2115
|
+
result.metadata.error = VerificationErrorCode.INVALID_DOMAIN;
|
|
2172
2116
|
}
|
|
2173
2117
|
return result;
|
|
2174
2118
|
}
|
|
2175
2119
|
if (checkDisposable) {
|
|
2176
|
-
result.
|
|
2177
|
-
if (result.
|
|
2178
|
-
result.
|
|
2179
|
-
result.domain.error = VerificationErrorCode.DISPOSABLE_EMAIL;
|
|
2120
|
+
result.isDisposable = await isDisposableEmail(emailAddress, params.cache);
|
|
2121
|
+
if (result.isDisposable && result.metadata) {
|
|
2122
|
+
result.metadata.error = VerificationErrorCode.DISPOSABLE_EMAIL;
|
|
2180
2123
|
}
|
|
2181
2124
|
}
|
|
2182
2125
|
if (checkFree) {
|
|
2183
|
-
result.
|
|
2126
|
+
result.isFree = await isFreeEmail(emailAddress, params.cache);
|
|
2184
2127
|
}
|
|
2185
2128
|
if (checkDomainAge) {
|
|
2186
2129
|
try {
|
|
2187
|
-
result.domainAge = await getDomainAge(domain, whoisTimeout);
|
|
2130
|
+
result.domainAge = await getDomainAge(domain, whoisTimeout, debug);
|
|
2188
2131
|
} catch (err) {
|
|
2189
|
-
log("[
|
|
2132
|
+
log("[verifyEmail] Failed to get domain age", err);
|
|
2190
2133
|
result.domainAge = null;
|
|
2191
2134
|
}
|
|
2192
2135
|
}
|
|
2193
2136
|
if (checkDomainRegistration) {
|
|
2194
2137
|
try {
|
|
2195
|
-
result.domainRegistration = await getDomainRegistrationStatus(domain, whoisTimeout);
|
|
2138
|
+
result.domainRegistration = await getDomainRegistrationStatus(domain, whoisTimeout, debug);
|
|
2196
2139
|
} catch (err) {
|
|
2197
|
-
log("[
|
|
2140
|
+
log("[verifyEmail] Failed to get domain registration status", err);
|
|
2198
2141
|
result.domainRegistration = null;
|
|
2199
2142
|
}
|
|
2200
2143
|
}
|
|
2201
2144
|
if (verifyMx || verifySmtp) {
|
|
2202
2145
|
try {
|
|
2203
2146
|
const mxRecords = await resolveMxRecords(domain, params.cache);
|
|
2204
|
-
result.
|
|
2205
|
-
result.
|
|
2206
|
-
|
|
2207
|
-
result.domain.error = VerificationErrorCode.NO_MX_RECORDS;
|
|
2147
|
+
result.validMx = mxRecords.length > 0;
|
|
2148
|
+
if (!result.validMx && result.metadata) {
|
|
2149
|
+
result.metadata.error = VerificationErrorCode.NO_MX_RECORDS;
|
|
2208
2150
|
}
|
|
2209
2151
|
if (verifySmtp && mxRecords.length > 0) {
|
|
2210
2152
|
const cacheKey = `${emailAddress}:smtp`;
|
|
2211
2153
|
const smtpCacheInstance = smtpCacheStore(params.cache);
|
|
2212
2154
|
const cachedSmtp = await smtpCacheInstance.get(cacheKey);
|
|
2213
2155
|
if (cachedSmtp !== null && cachedSmtp !== void 0) {
|
|
2214
|
-
result.
|
|
2156
|
+
result.validSmtp = cachedSmtp;
|
|
2215
2157
|
if (result.metadata) {
|
|
2216
2158
|
result.metadata.cached = true;
|
|
2217
2159
|
}
|
|
@@ -2239,26 +2181,27 @@ async function verifyEmailDetailed(params) {
|
|
|
2239
2181
|
retryAttempts: params.retryAttempts
|
|
2240
2182
|
});
|
|
2241
2183
|
await smtpCacheInstance.set(cacheKey, smtpResult);
|
|
2242
|
-
result.
|
|
2184
|
+
result.validSmtp = smtpResult;
|
|
2243
2185
|
}
|
|
2244
|
-
if (result.
|
|
2245
|
-
result.
|
|
2246
|
-
} else if (result.
|
|
2247
|
-
result.
|
|
2186
|
+
if (result.validSmtp === false && result.metadata) {
|
|
2187
|
+
result.metadata.error = VerificationErrorCode.MAILBOX_NOT_FOUND;
|
|
2188
|
+
} else if (result.validSmtp === null && result.metadata) {
|
|
2189
|
+
result.metadata.error = VerificationErrorCode.SMTP_CONNECTION_FAILED;
|
|
2248
2190
|
}
|
|
2249
2191
|
}
|
|
2250
2192
|
} catch (err) {
|
|
2251
|
-
log("[
|
|
2252
|
-
result.
|
|
2253
|
-
result.
|
|
2193
|
+
log("[verifyEmail] Failed to resolve MX records", err);
|
|
2194
|
+
result.validMx = false;
|
|
2195
|
+
if (result.metadata) {
|
|
2196
|
+
result.metadata.error = VerificationErrorCode.NO_MX_RECORDS;
|
|
2197
|
+
}
|
|
2254
2198
|
}
|
|
2255
2199
|
}
|
|
2256
|
-
result.valid = result.format.valid && result.domain.valid !== false && result.smtp.valid !== false && !result.disposable;
|
|
2257
2200
|
if (result.metadata) {
|
|
2258
2201
|
result.metadata.verificationTime = Date.now() - startTime;
|
|
2259
2202
|
}
|
|
2260
2203
|
return result;
|
|
2261
2204
|
}
|
|
2262
2205
|
|
|
2263
|
-
export { COMMON_EMAIL_DOMAINS, VerificationErrorCode, clearAllCaches, defaultDomainSuggestionMethod, defaultNameDetectionMethod, detectName, detectNameFromEmail, domainPorts, getDomainAge, getDomainRegistrationStatus, getDomainSimilarity, isCommonDomain, isDisposableEmail, isFreeEmail, isValidEmail, isValidEmailDomain, suggestDomain, suggestEmailDomain, verifyEmail, verifyEmailBatch
|
|
2206
|
+
export { COMMON_EMAIL_DOMAINS, VerificationErrorCode, clearAllCaches, defaultDomainSuggestionMethod, defaultNameDetectionMethod, detectName, detectNameFromEmail, domainPorts, getDomainAge, getDomainRegistrationStatus, getDomainSimilarity, isCommonDomain, isDisposableEmail, isFreeEmail, isValidEmail, isValidEmailDomain, suggestDomain, suggestEmailDomain, verifyEmail, verifyEmailBatch };
|
|
2264
2207
|
//# sourceMappingURL=index.esm.js.map
|