validmail 1.0.0-test → 1.0.0
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/CHANGELOG.md +18 -0
- package/README.md +534 -4
- package/dist/index.cjs +91 -0
- package/dist/index.d.cts +237 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.js +90 -0
- package/package.json +56 -7
- package/index.d.ts +0 -2
- package/index.js +0 -8
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";var re=Object.create;var k=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var de=(e,o)=>{for(var a in o)k(e,a,{get:o[a],enumerable:!0})},N=(e,o,a,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of me(o))!ce.call(e,n)&&n!==a&&k(e,n,{get:()=>o[n],enumerable:!(t=se(o,n))||t.enumerable});return e};var ue=(e,o,a)=>(a=e!=null?re(le(e)):{},N(o||!e||!e.__esModule?k(a,"default",{value:e,enumerable:!0}):a,e)),pe=e=>N(k({},"__esModule",{value:!0}),e);var Pe={};de(Pe,{checkMx:()=>j,checkSyntax:()=>M,clearCache:()=>q,default:()=>ze,disposableDomains:()=>y,isDisposable:()=>D,isRoleAccount:()=>O,isValidEmail:()=>oe,isValidEmailAsync:()=>ae,validate:()=>b,validateMany:()=>te,validateSync:()=>S});module.exports=pe(Pe);var fe=`
|
|
2
|
+
0-mail.com 0815.ru 0815.su 0clickemail.com 0wnd.net 0wnd.org 10mail.com 10mail.org 10minutemail.be
|
|
3
|
+
10minutemail.cf 10minutemail.co.uk 10minutemail.co.za 10minutemail.com 10minutemail.de
|
|
4
|
+
10minutemail.ga 10minutemail.gq 10minutemail.info 10minutemail.ml 10minutemail.net 10minutemail.nl
|
|
5
|
+
10minutemail.org 10minutemail.pro 10minutemail.us 10minutesmail.com 10minutesmail.net 10x9.com
|
|
6
|
+
12minutemail.com 12minutemail.net 15qm.com 1secmail.com 1secmail.net 1secmail.org 20mail.eu
|
|
7
|
+
20mail.it 20minutemail.com 20minutemail.it 2prong.com 30minutemail.com 33mail.com 4warding.com
|
|
8
|
+
4warding.net 4warding.org 60minutemail.com 675hosting.com 675hosting.net 675hosting.org 6ip.us
|
|
9
|
+
6paq.com 6url.com 75hosting.com 75hosting.net 75hosting.org 7tags.com 9ox.net a-bc.net abyssmail.com
|
|
10
|
+
afrobacon.com ajaxapp.net amilegit.com anonbox.net anonymbox.com antichef.com antichef.net
|
|
11
|
+
antispam.de armyspy.com beefmilk.com binkmail.com bio-muesli.net bobmail.info bofthew.com
|
|
12
|
+
boximail.com brefmail.com bugmenot.com bumpymail.com byom.de chammy.info chogmail.com
|
|
13
|
+
choicemail1.com clrmail.com cool.fr.nf correo.blogos.net cosmorph.com courriel.fr.nf
|
|
14
|
+
courrieltemporaire.com crazymailing.com curryworld.de cust.in cuvox.de dacoolest.com dandikmail.com
|
|
15
|
+
dayrep.com deadaddress.com deadspam.com despam.it despammed.com devnullmail.com dfgh.net
|
|
16
|
+
digitalsanctuary.com disbox.net disbox.org discard.email discardmail.com discardmail.de
|
|
17
|
+
disposableaddress.com disposableemailaddresses.com disposableinbox.com dispose.it disposeamail.com
|
|
18
|
+
disposemail.com dispostable.com dodgeit.com dodgit.com dodgit.org donemail.ru dontreg.com
|
|
19
|
+
dontsendmespam.de dropjar.com dropmail.me dump-email.info dumpandjunk.com dumpmail.de dumpyemail.com
|
|
20
|
+
e4ward.com einrot.com email-fake.com email60.com emaildienst.de emailfake.com emailias.com
|
|
21
|
+
emailigo.de emailinfive.com emailmiser.com emailondeck.com emailsensei.com emailtemporario.com.br
|
|
22
|
+
emailthe.net emailtmp.com emailwarden.com emailxfer.com emlhub.com emlpro.com emltmp.com emz.net
|
|
23
|
+
enterto.com ephemail.net esiix.com etranquil.com etranquil.net etranquil.org explodemail.com
|
|
24
|
+
eyepaste.com ezztt.com fakeinbox.com fakeinformation.com fakemail.fr fakemail.net
|
|
25
|
+
fakemailgenerator.com fastacura.com fastchevy.com fastchrysler.com fastkawasaki.com fastmazda.com
|
|
26
|
+
fastmitsubishi.com fastnissan.com fastsubaru.com fastsuzuki.com fasttoyota.com fastyamaha.com
|
|
27
|
+
fexbox.org fexpost.com filzmail.com fizmail.com fleckens.hu footard.com forgetmail.com fr33mail.info
|
|
28
|
+
frapmail.com freeml.net friendlymail.co.uk front14.org fudgerub.com garliclife.com generator.email
|
|
29
|
+
get1mail.com get2mail.fr getairmail.com getmails.eu getnada.com getonemail.com getonemail.net
|
|
30
|
+
ghosttexter.de girlsundertheinfluence.com gishpuppy.com givmail.com great-host.in greensloth.com
|
|
31
|
+
grr.la guerillamail.biz guerillamail.com guerillamail.de guerillamail.info guerillamail.net
|
|
32
|
+
guerillamail.org guerrillamail.biz guerrillamail.com guerrillamail.de guerrillamail.info
|
|
33
|
+
guerrillamail.net guerrillamail.org guerrillamailblock.com gustr.com h8s.org haltospam.com
|
|
34
|
+
harakirimail.com hatespam.org hidemail.de hochsitze.com hulapla.de icznn.com ieatspam.eu
|
|
35
|
+
ieatspam.info ihateyoualot.info iheartspam.org imails.info inboxalias.com inboxbear.com
|
|
36
|
+
inboxclean.com inboxclean.org inboxkitten.com incognitomail.com incognitomail.net incognitomail.org
|
|
37
|
+
insorg-mail.info ipoo.org irish2me.com jetable.com jetable.fr.nf jetable.net jetable.org jnxjn.com
|
|
38
|
+
jourrapide.com junk1e.com kasmail.com kaspop.com keepmymail.com killmail.com killmail.net
|
|
39
|
+
klassmaster.com klassmaster.net klzlk.com kulturbetrieb.info kurzepost.de kzccv.com
|
|
40
|
+
letthemeatspam.com lhsdv.com lifebyfood.com link2mail.net litedrop.com lookugly.com lortemail.dk
|
|
41
|
+
lr78.com m4ilweb.info maboard.com mail-temporaire.fr mail.by mail2rss.org mail333.com mail4trash.com
|
|
42
|
+
mailbidon.com mailcatch.com maildrop.cc maileater.com mailexpire.com mailforspam.com
|
|
43
|
+
mailfreeonline.com mailhazard.com mailhazard.us mailin8r.com mailinater.com mailinator.com
|
|
44
|
+
mailinator.net mailinator.org mailinator2.com mailincubator.com mailismagic.com mailme.lv
|
|
45
|
+
mailme24.com mailmetrash.com mailmoat.com mailnator.com mailnesia.com mailnull.com mailpoof.com
|
|
46
|
+
mailquack.com mailsac.com mailscrap.com mailsiphon.com mailslite.com mailtemp.info mailto.plus
|
|
47
|
+
mailtome.de mailtothis.com mailzilla.com mailzilla.org makemetheking.com manybrain.com mbx.cc
|
|
48
|
+
mega.zik.dj meinspamschutz.de meltmail.com merepost.com messagebeamer.de mierdamail.com
|
|
49
|
+
mintemail.com moakt.cc moakt.co moakt.com moakt.ws moburl.com mohmal.com moncourrier.fr.nf
|
|
50
|
+
monemail.fr.nf monmail.fr.nf mt2009.com mt2014.com mt2015.com mvrht.com mvrht.net mycleaninbox.net
|
|
51
|
+
mypartyclip.de myphantomemail.com myspaceinc.com myspaceinc.net myspaceinc.org myspacepimpedup.com
|
|
52
|
+
myspamless.com mytemp.email mytempemail.com mytempmail.com mytrashmail.com nada.email nepwk.com
|
|
53
|
+
nervmich.net nervtmich.net netzidiot.de neverbox.com no-spam.ws nobulk.com noclickemail.com
|
|
54
|
+
nogmailspam.info nomail.xl.cx nomail2me.com nomorespamemails.com nospam.ze.tc nospam4.us
|
|
55
|
+
nospamfor.us nospamthanks.info notmailinator.com nowmymail.com nurfuerspam.de nwldx.com
|
|
56
|
+
objectmail.com obobbo.com oneoffemail.com onewaymail.com oopi.org oosln.com ordinaryamerican.net
|
|
57
|
+
ourklips.com outlawspam.com ovpn.to owlpic.com pancakemail.com pimpedupmyspace.com pjjkp.com
|
|
58
|
+
pokemail.net politikerclub.de poofy.org pookmail.com proxymail.eu prtnx.com punkass.com
|
|
59
|
+
putthisinyourspamdatabase.com qiott.com quickinbox.com rcpt.at reallymymail.com recode.me
|
|
60
|
+
reconmail.com recursor.net regbypass.com rejectmail.com rhyta.com rklips.com rmqkr.net
|
|
61
|
+
robot-mail.com rppkn.com rtrtr.com s0ny.net safersignup.de safetymail.info safetypost.de sandelf.de
|
|
62
|
+
saynotospams.com selfdestructingmail.com sendspamhere.com sharklasers.com shieldedmail.com
|
|
63
|
+
shiftmail.com shitmail.me shortmail.net skeefmail.com slaskpost.se slopsbox.com smashmail.de
|
|
64
|
+
smellfear.com snakemail.com sneakemail.com sofimail.com sofort-mail.de sogetthis.com soodonims.com
|
|
65
|
+
spam.la spam.su spam4.me spamavert.com spambob.com spambob.net spambob.org spambog.com spambog.de
|
|
66
|
+
spambog.ru spambooger.com spambox.info spambox.us spamcannon.com spamcannon.net spamcero.com
|
|
67
|
+
spamcon.org spamcorptastic.com spamcowboy.com spamcowboy.net spamcowboy.org spamday.com spamex.com
|
|
68
|
+
spamfree24.com spamfree24.de spamfree24.eu spamfree24.info spamfree24.net spamfree24.org
|
|
69
|
+
spamgourmet.com spamgourmet.net spamgourmet.org spamherelots.com spamhereplease.com spamhole.com
|
|
70
|
+
spamify.com spaminator.de spamkill.info spaml.com spaml.de spammotel.com spamobox.com spamoff.de
|
|
71
|
+
spamslicer.com spamspot.com spamthis.co.uk spamthisplease.com spamtrail.com speed.1s.fr spymail.one
|
|
72
|
+
streetwisemail.com supergreatmail.com supermailer.jp superrito.com suremail.info tafmail.com
|
|
73
|
+
tagyourself.com teewars.org teleworm.com teleworm.us temp-mail.io temp-mail.org temp-mail.ru
|
|
74
|
+
tempail.com tempalias.com tempe-mail.com tempemail.biz tempemail.com tempemail.net tempinbox.co.uk
|
|
75
|
+
tempinbox.com tempmail.it tempmail2.com tempmaildemo.com tempmailer.com tempmailer.de tempmailo.com
|
|
76
|
+
tempomail.fr temporarily.de temporarioemail.com.br temporaryemail.net temporaryforwarding.com
|
|
77
|
+
temporaryinbox.com tempr.email thanksnospam.info thankyou2010.com thisisnotmyrealemail.com
|
|
78
|
+
throwam.com throwawayemailaddress.com throwawaymail.com tilien.com tmail.ws tmailinator.com
|
|
79
|
+
tmpbox.net tmpeml.com tmpmail.net tmpmail.org toiea.com tradermail.info trash-amil.com trash-mail.at
|
|
80
|
+
trash-mail.com trash-mail.de trash2009.com trashdevil.com trashdevil.de trashemail.de trashmail.at
|
|
81
|
+
trashmail.com trashmail.de trashmail.me trashmail.net trashmail.org trashmail.ws trashmailer.com
|
|
82
|
+
trashymail.com trashymail.net trbvm.com turual.com twinmail.de tyldd.com uggsrock.com upliftnow.com
|
|
83
|
+
uplipht.com vddaz.com venompen.com veryrealemail.com viditag.com viewcastmedia.com viewcastmedia.net
|
|
84
|
+
viewcastmedia.org vomoto.com webm4il.info wegwerfadresse.de wegwerfemail.de wegwerfmail.de
|
|
85
|
+
wegwerfmail.net wegwerfmail.org wetrainbayarea.com wetrainbayarea.org wh4f.org whyspam.me
|
|
86
|
+
willselfdestruct.com winemaven.info wronghead.com wuuvo.com wuzup.net wuzupmail.net wwjmp.com
|
|
87
|
+
wwwnew.eu xagloo.com xemaps.com xents.com xmaily.com xojxe.com xoxy.net yep.it yogamaven.com
|
|
88
|
+
yoggm.com yomail.info yopmail.com yopmail.fr yopmail.net yuurok.com zehnminutenmail.de zetmail.com
|
|
89
|
+
zippymail.info zoaxe.com zoemail.org
|
|
90
|
+
`,y=Object.freeze(fe.trim().split(/\s+/));var U=require("node:url");var ge=new Set(y),he=new Set("abuse accounting accounts admin administrator billing careers contact contactus customercare customerservice devnull dns enquiries enquiry feedback ftp hello help helpdesk hostmaster hr info inquiries inquiry investors jobs legal mail mailer-daemon marketing media newsletter no-reply no_reply noc noreply nobody null office orders postmaster press privacy recruiting root sales security service staff support sysadmin team tech undisclosed-recipients unsubscribe usenet uucp webmaster www".split(" "));function X(e){let o=String(e).trim().toLowerCase(),a=o.lastIndexOf("@");for(a!==-1&&(o=o.slice(a+1));o.startsWith(".");)o=o.slice(1);for(;o.endsWith(".");)o=o.slice(0,-1);return(/[^\x00-\x7f]/.test(o)||o.includes("xn--"))&&(o=(0,U.domainToASCII)(o)||o),o}var V=new WeakMap;function ye(e){return Array.isArray(e)?e.length:e instanceof Set?e.size:-1}function R(e){if(!e)return;if(typeof e=="string")throw new TypeError("Expected an array or Set of domains, not a string.");let o=ye(e),a=V.get(e);if(a&&a.size===o)return a.set;let t=new Set;for(let n of e){let s=X(n);s&&t.add(s)}return o!==-1&&V.set(e,{size:o,set:t}),t}function w(e,o){let a=e;for(;;){if(o.has(a))return a;let t=a.indexOf(".");if(t===-1)return;a=a.slice(t+1)}}function A(e){return w(e,ge)}function D(e){if(typeof e!="string")return!1;let o=X(e);return o!==""&&A(o)!==void 0}function E(e){let o=e.toLowerCase(),a=o.indexOf("+");return a>0&&(o=o.slice(0,a)),he.has(o)?o:void 0}function O(e){if(typeof e!="string")return!1;let o=e.trim(),a=o.lastIndexOf("@");return E(a===-1?o:o.slice(0,a))!==void 0}var h=ue(require("node:dns/promises"),1);var v=require("node:net"),_=require("node:url"),x=254,Q=64,B=253,H=63,xe={invalid_type:"Email must be a string.",empty:"Email is empty.",too_long:`Email is longer than ${x} characters.`,missing_at:'Email must contain an "@".',local_empty:'The part before "@" is empty.',local_too_long:`The part before "@" is longer than ${Q} characters.`,local_invalid_char:'The part before "@" contains a character that is not allowed',local_unicode:'The part before "@" contains non-ASCII characters.',local_dot:'The part before "@" cannot start or end with a dot or contain two dots in a row.',quoted_not_allowed:'Quoted local parts ("john doe"@example.com) are not allowed.',quoted_invalid:'The quoted part before "@" is malformed.',domain_empty:'The domain after "@" is empty.',domain_too_long:`The domain is longer than ${B} characters.`,domain_label_too_long:`A part of the domain is longer than ${H} characters.`,domain_invalid:"The domain is not a valid host name.",domain_no_tld:'The domain has no top-level domain (like ".com").',tld_invalid:"The top-level domain is not valid.",ip_literal_not_allowed:"IP address domains (user@[192.0.2.1]) are not allowed.",ip_literal_invalid:"The IP address literal is malformed."};function be(e){return e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===33||e>=35&&e<=39||e===42||e===43||e===45||e===47||e===61||e===63||e>=94&&e<=96||e>=123&&e<=126}function Y(e,o){let a=e.charCodeAt(o);if(a<160)return 0;if(a>=55296&&a<=56319){let t=e.charCodeAt(o+1);return t>=56320&&t<=57343?2:0}return a>=56320&&a<=57343?0:1}function W(e){let o=0;for(let a=0;a<e.length;a++){let t=e.charCodeAt(a);t<128?o+=1:t<2048?o+=2:t>=55296&&t<=56319?(o+=4,a++):o+=3}return o}function F(e,o){let a=e.charCodeAt(o);return a===32?"a space":a<32||a===127?`control character U+${a.toString(16).toUpperCase().padStart(4,"0")}`:`"${String.fromCodePoint(e.codePointAt(o))}"`}function ke(e,o){if(e.charCodeAt(0)===46||e.charCodeAt(e.length-1)===46)return{reason:"local_dot"};let a=!1;for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n===46){if(a)return{reason:"local_dot"};a=!0;continue}if(a=!1,n<128){if(!be(n))return{reason:"local_invalid_char",detail:F(e,t)};continue}if(!o)return{reason:"local_unicode"};let s=Y(e,t);if(s===0)return{reason:"local_invalid_char",detail:F(e,t)};t+=s-1}}function we(e,o){let a=e.length-1;if(a<2||e.charCodeAt(a)!==34)return!1;for(let t=1;t<a;t++){let n=e.charCodeAt(t);if(n===92){if(t++,t>=a)return!1;let s=e.charCodeAt(t);if(s<32||s>126)return!1}else{if(n===34)return!1;if(n>=32&&n<=126)continue;if(n>=128&&o){let s=Y(e,t);if(s===0)return!1;t+=s-1}else return!1}}return!0}function ve(e){for(let o=0;o<e.length;o++)if(e.charCodeAt(o)>127)return!1;return!0}function _e(e,o){if(e.length>B)return"domain_too_long";let a=e.split(".");for(let n of a){if(n.length===0)return"domain_invalid";if(n.length>H)return"domain_label_too_long";if(n.charCodeAt(0)===45||n.charCodeAt(n.length-1)===45)return"domain_invalid";for(let s=0;s<n.length;s++){let r=n.charCodeAt(s);if(!(r>=97&&r<=122||r>=48&&r<=57||r===45))return"domain_invalid"}}if(a.length<2&&o)return"domain_no_tld";let t=a[a.length-1];if(/^[0-9]+$/.test(t)||a.length>1&&t.length<2)return"tld_invalid"}function T(e,o={}){if(e.length===0)return{domain:"",asciiDomain:"",ipLiteral:!1,reason:"domain_empty"};if(e.charCodeAt(0)===91){let s=i=>({domain:e,asciiDomain:"",ipLiteral:!0,reason:i});if(!o.allowIpLiteral)return s("ip_literal_not_allowed");if(e.charCodeAt(e.length-1)!==93)return s("ip_literal_invalid");let r=e.slice(1,-1),m;if(r.slice(0,5).toLowerCase()==="ipv6:"){let i=r.slice(5);if(i.includes("%")||!(0,v.isIPv6)(i))return s("ip_literal_invalid");m=`[IPv6:${i.toLowerCase()}]`}else if((0,v.isIPv4)(r))m=`[${r}]`;else return s("ip_literal_invalid");return{domain:m,asciiDomain:m,ipLiteral:!0}}let a=e.toLowerCase(),t=a;if(!ve(a)||a.includes("xn--")){for(let s=0;s<a.length;s++){let r=a.charCodeAt(s);if(r<128&&!(r>=97&&r<=122||r>=48&&r<=57||r===45||r===46))return{domain:a,asciiDomain:"",ipLiteral:!1,reason:"domain_invalid"}}if(t=(0,_.domainToASCII)(a),!t)return{domain:a,asciiDomain:"",ipLiteral:!1,reason:"domain_invalid"}}let n=_e(t,o.requireTld!==!1);return n?{domain:a,asciiDomain:"",ipLiteral:!1,reason:n}:{domain:t.includes("xn--")?(0,_.domainToUnicode)(t):t,asciiDomain:t,ipLiteral:!1}}function u(e,o,a){if(!o)return{valid:!0,...e};let t=xe[o];return{valid:!1,reason:o,message:a?`${t}: ${a}.`:t,...e}}function M(e,o={}){let a={email:"",local:"",domain:"",asciiDomain:"",quoted:!1,ipLiteral:!1};if(typeof e!="string")return u(a,"invalid_type");let t=e.trim();if(a.email=t.length>x?t.slice(0,x):t,t.length===0)return u(a,"empty");if(t.length>x)return u(a,"too_long");let n=t.lastIndexOf("@");if(n===-1)return u(a,"missing_at");let s=t.slice(0,n),r=t.slice(n+1),m=s.charCodeAt(0)===34,i={email:t,local:s,domain:r.toLowerCase(),asciiDomain:"",quoted:m,ipLiteral:!1};if(s.length===0)return u(i,"local_empty");let c=o.allowUnicodeLocal===!0;if(m){if(!o.allowQuoted)return u(i,"quoted_not_allowed");if(!we(s,c))return u(i,"quoted_invalid")}else{let d=ke(s,c);if(d)return u(i,d.reason,d.detail)}if(W(s)>Q)return u(i,"local_too_long");let l=T(r,o);return i.domain=l.domain,i.ipLiteral=l.ipLiteral,l.reason?u(i,l.reason):(i.asciiDomain=l.asciiDomain,i.email=`${s}@${l.domain}`,W(s)+1+l.asciiDomain.length>x?(i.asciiDomain="",u(i,"too_long")):u(i))}var Me=5e3,Ce=3600*1e3,Se=1e4,Re={resolveMx:e=>h.resolveMx(e),resolve4:e=>h.resolve4(e),resolve6:e=>h.resolve6(e)},P=new WeakMap,G=new WeakMap;function q(){P=new WeakMap}function Ae(e,o){if(e===!1)return;if(e instanceof Map)return e;let a=P.get(o);return a||P.set(o,a=new Map),a}function L(e){let o=e?.code;return typeof o=="string"?o:void 0}var De=new Set(["ENODATA","ENOTFOUND","NXDOMAIN","ENONAME"]);function C(e,o,a=!0){let t={domain_not_found:`The domain "${o}" does not exist.`,no_mx:a?`The domain "${o}" has no mail server (no MX, A or AAAA records).`:`The domain "${o}" has no MX records.`,null_mx:`The domain "${o}" does not accept email (null MX record, RFC 7505).`};return{status:"fail",reason:e,message:t[e]}}function I(e,o){let a=L(e);if(a==="ETIMEOUT")return{status:"error",reason:"timeout",code:a,message:`DNS lookup for "${o}" timed out.`};let t=a??(e instanceof Error?e.message:String(e));return{status:"error",reason:"dns_error",...a?{code:a}:{},message:`DNS lookup for "${o}" failed: ${t}.`}}function Ee(e,o){return{status:"error",reason:"timeout",message:`DNS lookup for "${e}" timed out after ${o} ms.`}}function Oe(e){let o=typeof e=="string"?e.trim().toLowerCase():"";for(;o.endsWith(".");)o=o.slice(0,-1);return o}async function Te(e,o,a){let t;try{t=await e.resolveMx(o)??[]}catch(m){let i=L(m);if(i==="ENOTFOUND"||i==="NXDOMAIN"||i==="ENONAME")return C("domain_not_found",o);if(i!=="ENODATA")return I(m,o);t=[]}let n=[];for(let m of t){let i=Oe(m?.exchange);i!==""&&n.push({exchange:i,priority:Number(m.priority)||0})}if(t.length>0&&n.length===0)return C("null_mx",o);if(n.length>0)return n.sort((m,i)=>m.priority-i.priority),{status:"pass",records:n};if(!a)return C("no_mx",o,!1);let s=await Promise.allSettled([e.resolve4?e.resolve4(o):Promise.resolve([]),e.resolve6?e.resolve6(o):Promise.resolve([])]),r;for(let m of s)if(m.status==="fulfilled"){if(Array.isArray(m.value)&&m.value.length>0)return{status:"pass",implicit:!0,records:[{exchange:o,priority:0}]}}else De.has(L(m.reason)??"")||(r??(r=m.reason));return r===void 0?C("no_mx",o):I(r,o)}function J(e,o,a,t){return!(a>0&&a<1/0)&&!t?e:new Promise((n,s)=>{let r,m=()=>{i(),s(t.reason)},i=()=>{r!==void 0&&clearTimeout(r),t?.removeEventListener("abort",m)};a>0&&a<1/0&&(r=setTimeout(()=>{i(),n(Ee(o,a))},a)),t?.addEventListener("abort",m,{once:!0}),e.then(c=>{i(),n(c)},c=>{i(),s(c)})})}function z(e,o){let a={...e};return e.records&&(a.records=e.records.map(t=>({...t}))),o&&(a.cached=!0),a}async function $(e,o={}){let{signal:a}=o;a?.throwIfAborted();let t=o.resolver??Re,n=o.implicitMx!==!1,s=o.timeout??Me,r=o.cacheTtl??Ce,m=n?e:`${e} (no implicit mx)`,i=Ae(o.cache,t),c=i?.get(m);if(c){if(c.expires>Date.now())return z(c.value,!0);i.delete(m)}let l=G.get(t);l||G.set(t,l=new Map);let d=l.get(m);if(!d){let f=J(Te(t,e,n).catch(ne=>I(ne,e)),e,s,void 0),g=l;d=f.finally(()=>{g.get(m)===d&&g.delete(m)}),l.set(m,d)}let p=await J(d,e,s,a);if(i&&(p.status==="pass"||p.status==="fail")&&r>0)for(i.delete(m),i.set(m,{expires:Date.now()+r,value:z(p,!1)});i.size>Se;){let f=i.keys().next().value;if(f===void 0)break;i.delete(f)}return z(p,!1)}async function j(e,o={}){if(typeof e!="string")throw new TypeError("Expected a domain or email address string.");let a=e.trim(),t=T(a.slice(a.lastIndexOf("@")+1),{requireTld:!1});if(t.reason)throw new TypeError(`Invalid domain: "${a}"`);return $(t.asciiDomain,o)}function Z(e,o){let a=M(e,o),{valid:t,reason:n,message:s,...r}=a,m=a.valid?{status:"pass"}:{status:"fail",reason:a.reason,message:a.message};if(!a.valid)return{parts:r,checks:{syntax:m,disposable:{status:"skip",isDisposable:!1},role:{status:"skip",isRole:!1}},ok:!1};let i;if(r.ipLiteral)i={status:"skip",isDisposable:!1};else{let d=r.asciiDomain,p=A(d),f=w(d,R(o.blockDomains)??K),g=w(d,R(o.allowDomains)??K);f?i={status:"fail",reason:"blocked",message:`The domain "${r.domain}" is not allowed.`,isDisposable:!!p,match:f,source:"blockDomains"}:p&&o.disposable!==!1&&!g?i={status:"fail",reason:"disposable",message:`"${r.domain}" is a disposable email service.`,isDisposable:!0,match:p,source:"builtin"}:p&&g?i={status:"pass",isDisposable:!0,match:g,source:"allowDomains"}:i=p?{status:"pass",isDisposable:!0,match:p,source:"builtin"}:{status:"pass",isDisposable:!1}}let c=r.quoted?void 0:E(r.local),l=c?o.rejectRole?{status:"fail",reason:"role",message:`"${r.local}" is a role account, not a personal address.`,isRole:!0,role:c}:{status:"pass",isRole:!0,role:c}:{status:"pass",isRole:!1};return{parts:r,checks:{syntax:m,disposable:i,role:l},ok:i.status!=="fail"&&l.status!=="fail"}}var K=new Set;function ee(e,o,a){let t={...e.checks,mx:o},n=[t.syntax,t.disposable,t.role,t.mx];for(let r of n)if(r.status==="fail"||r.status==="error"&&!a)return{valid:!1,reason:r.reason,message:r.message,...e.parts,checks:t};let s={valid:!0,...e.parts,checks:t};return o.status==="pass"&&o.records&&(s.mxRecords=o.records),s}function S(e,o={}){return ee(Z(e,o),{status:"skip"},!1)}async function b(e,o={}){o.signal?.throwIfAborted();let a=Z(e,o),t={status:"skip"};return a.ok&&o.mx!==!1&&!a.parts.ipLiteral&&(t=await $(a.parts.asciiDomain,o)),ee(a,t,o.allowDnsErrors)}function oe(e,o){return S(e,o).valid}async function ae(e,o){return(await b(e,o)).valid}async function te(e,o={}){let a=Array.from(e),t=o.concurrency??10;if(!Number.isInteger(t)||t<1)throw new RangeError(`concurrency must be a positive integer, got ${String(t)}`);o.signal?.throwIfAborted();let n=new Array(a.length),s=0,r=async()=>{for(;s<a.length;){let m=s++;n[m]=await b(a[m],o)}};return await Promise.all(Array.from({length:Math.min(t,a.length)},r)),n}var ie=((e,o)=>b(e,o));Object.assign(ie,{validate:b,sync:S,validateSync:S,validateMany:te,checkSyntax:M,checkMx:j,isValidEmail:oe,isValidEmailAsync:ae,isDisposable:D,isRoleAccount:O,clearCache:q,disposableDomains:y});var ze=ie;0&&(module.exports={checkMx,checkSyntax,clearCache,disposableDomains,isDisposable,isRoleAccount,isValidEmail,isValidEmailAsync,validate,validateMany,validateSync});
|
|
91
|
+
var __d=module.exports.default;for(var __k in module.exports)if(!(__k in __d))__d[__k]=module.exports[__k];__d.default=__d;module.exports=__d;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/** The built-in disposable domain list (lowercase ASCII, sorted). */
|
|
2
|
+
declare const disposableDomains: readonly string[];
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* True if the email address (or bare domain) belongs to a known disposable email service.
|
|
6
|
+
* Subdomains match too: `x.mailinator.com` is disposable.
|
|
7
|
+
*/
|
|
8
|
+
declare function isDisposable(emailOrDomain: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* True if the address is a role account such as `admin@`, `support@` or `noreply@`.
|
|
11
|
+
* Sub-addresses count: `info+news@example.com` is a role account.
|
|
12
|
+
*/
|
|
13
|
+
declare function isRoleAccount(emailOrLocal: string): boolean;
|
|
14
|
+
|
|
15
|
+
/** An MX record: the mail server host name and its preference (lower is tried first). */
|
|
16
|
+
interface MxRecord {
|
|
17
|
+
exchange: string;
|
|
18
|
+
priority: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The DNS methods validmail uses. `dns.promises`, a `new dns.promises.Resolver()` (for custom
|
|
22
|
+
* DNS servers) and plain objects (for tests) all fit. Errors should carry Node's DNS error
|
|
23
|
+
* codes (`ENODATA`, `ENOTFOUND`, `ETIMEOUT`, ...) in `error.code`.
|
|
24
|
+
*/
|
|
25
|
+
interface Resolver {
|
|
26
|
+
resolveMx(hostname: string): Promise<MxRecord[]>;
|
|
27
|
+
/** Used for the implicit MX fallback (RFC 5321 §5.1). Optional. */
|
|
28
|
+
resolve4?(hostname: string): Promise<string[]>;
|
|
29
|
+
/** Used for the implicit MX fallback (RFC 5321 §5.1). Optional. */
|
|
30
|
+
resolve6?(hostname: string): Promise<string[]>;
|
|
31
|
+
}
|
|
32
|
+
/** Why the MX check failed or could not finish. */
|
|
33
|
+
type MxReason = 'domain_not_found' | 'no_mx' | 'null_mx' | 'timeout' | 'dns_error';
|
|
34
|
+
/**
|
|
35
|
+
* - `pass`: the domain can receive mail.
|
|
36
|
+
* - `fail`: it definitely cannot (no such domain, no mail server, null MX).
|
|
37
|
+
* - `error`: DNS did not answer in time or failed; the address may still be fine.
|
|
38
|
+
* - `skip`: the check did not run.
|
|
39
|
+
*/
|
|
40
|
+
type CheckStatus = 'pass' | 'fail' | 'skip' | 'error';
|
|
41
|
+
interface MxCheck {
|
|
42
|
+
status: CheckStatus;
|
|
43
|
+
reason?: MxReason;
|
|
44
|
+
message?: string;
|
|
45
|
+
/** Mail servers sorted by priority. For an implicit MX this is the domain itself with priority 0. */
|
|
46
|
+
records?: MxRecord[];
|
|
47
|
+
/** No MX records, but the domain has an A/AAAA address, which RFC 5321 §5.1 treats as its mail server. */
|
|
48
|
+
implicit?: boolean;
|
|
49
|
+
/** The result came from the cache. */
|
|
50
|
+
cached?: boolean;
|
|
51
|
+
/** DNS error code, when `status` is `error`. */
|
|
52
|
+
code?: string;
|
|
53
|
+
}
|
|
54
|
+
interface MxCacheEntry {
|
|
55
|
+
expires: number;
|
|
56
|
+
value: MxCheck;
|
|
57
|
+
}
|
|
58
|
+
interface MxOptions {
|
|
59
|
+
/** Milliseconds before the DNS check gives up with status `error` / reason `timeout`. `0` disables. Default `5000`. */
|
|
60
|
+
timeout?: number;
|
|
61
|
+
/** DNS resolver to use. Default: the system resolver (`node:dns/promises`). */
|
|
62
|
+
resolver?: Resolver;
|
|
63
|
+
/**
|
|
64
|
+
* Cache DNS results per domain. `true` (default) uses a built-in in-memory cache per resolver,
|
|
65
|
+
* `false` disables caching, or pass your own `Map` to control and share it.
|
|
66
|
+
* Only definite answers (`pass`/`fail`) are cached; errors and timeouts are not.
|
|
67
|
+
*/
|
|
68
|
+
cache?: boolean | Map<string, MxCacheEntry>;
|
|
69
|
+
/** How long cached results stay fresh, in milliseconds. Default `3600000` (1 hour). */
|
|
70
|
+
cacheTtl?: number;
|
|
71
|
+
/** Accept domains without MX records that have an A/AAAA address (RFC 5321 §5.1). Default `true`. */
|
|
72
|
+
implicitMx?: boolean;
|
|
73
|
+
/** Abort the lookup. The promise rejects with `signal.reason`. */
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
}
|
|
76
|
+
/** Empty the built-in DNS result caches. Caches you passed in with `cache: Map` are not touched. */
|
|
77
|
+
declare function clearCache(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Check whether a domain can receive email: MX records, falling back to A/AAAA (implicit MX),
|
|
80
|
+
* and detecting null MX (RFC 7505). Accepts a domain or a full address.
|
|
81
|
+
* Throws a `TypeError` if the domain is not a syntactically valid host name.
|
|
82
|
+
*/
|
|
83
|
+
declare function checkMx(domainOrEmail: string, options?: MxOptions): Promise<MxCheck>;
|
|
84
|
+
|
|
85
|
+
/** Why an address failed the syntax check. */
|
|
86
|
+
type SyntaxReason = 'invalid_type' | 'empty' | 'too_long' | 'missing_at' | 'local_empty' | 'local_too_long' | 'local_invalid_char' | 'local_unicode' | 'local_dot' | 'quoted_not_allowed' | 'quoted_invalid' | 'domain_empty' | 'domain_too_long' | 'domain_label_too_long' | 'domain_invalid' | 'domain_no_tld' | 'tld_invalid' | 'ip_literal_not_allowed' | 'ip_literal_invalid';
|
|
87
|
+
interface SyntaxOptions {
|
|
88
|
+
/** Accept quoted local parts such as `"john doe"@example.com`. Default `false`. */
|
|
89
|
+
allowQuoted?: boolean;
|
|
90
|
+
/** Accept address literals such as `user@[192.0.2.1]` and `user@[IPv6:2001:db8::1]`. Default `false`. */
|
|
91
|
+
allowIpLiteral?: boolean;
|
|
92
|
+
/** Accept non-ASCII characters in the local part (RFC 6531, SMTPUTF8). Default `false`. Unicode domains are always accepted. */
|
|
93
|
+
allowUnicodeLocal?: boolean;
|
|
94
|
+
/** Require a dot in the domain (`user@localhost` fails). Default `true`. */
|
|
95
|
+
requireTld?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** The parts of an address, normalized. Present on both valid and invalid results (best effort). */
|
|
98
|
+
interface EmailParts {
|
|
99
|
+
/** Normalized address: trimmed, domain lowercased (Unicode form for IDNs). */
|
|
100
|
+
email: string;
|
|
101
|
+
/** The part before the last `@`, unchanged (case is preserved). */
|
|
102
|
+
local: string;
|
|
103
|
+
/** Lowercased domain in Unicode form (`bücher.de`), or the bracketed literal for IP addresses. */
|
|
104
|
+
domain: string;
|
|
105
|
+
/** Domain in ASCII / punycode form (`xn--bcher-kva.de`), as used for DNS. Empty when the domain is invalid. */
|
|
106
|
+
asciiDomain: string;
|
|
107
|
+
/** The local part is a quoted string. */
|
|
108
|
+
quoted: boolean;
|
|
109
|
+
/** The domain is an address literal (`[192.0.2.1]`). */
|
|
110
|
+
ipLiteral: boolean;
|
|
111
|
+
}
|
|
112
|
+
/** `valid: true` with no reason, or `valid: false` with a reason code and a readable message. */
|
|
113
|
+
type Outcome<R extends string> = {
|
|
114
|
+
valid: true;
|
|
115
|
+
reason?: undefined;
|
|
116
|
+
message?: undefined;
|
|
117
|
+
} | {
|
|
118
|
+
valid: false;
|
|
119
|
+
reason: R;
|
|
120
|
+
message: string;
|
|
121
|
+
};
|
|
122
|
+
type SyntaxResult = EmailParts & Outcome<SyntaxReason>;
|
|
123
|
+
/**
|
|
124
|
+
* Check the syntax of an email address (RFC 5321/5322, practical subset). Never touches the network.
|
|
125
|
+
*
|
|
126
|
+
* Runs in linear time: there are no backtracking regular expressions, and input longer than
|
|
127
|
+
* 254 characters is rejected before it is scanned.
|
|
128
|
+
*/
|
|
129
|
+
declare function checkSyntax(email: string, options?: SyntaxOptions): SyntaxResult;
|
|
130
|
+
|
|
131
|
+
/** Why the disposable/blocklist check failed. */
|
|
132
|
+
type DisposableReason = 'disposable' | 'blocked';
|
|
133
|
+
/** Every reason an address can be rejected, in the order the checks run. */
|
|
134
|
+
type Reason = SyntaxReason | DisposableReason | 'role' | MxReason;
|
|
135
|
+
/** Options for the checks that run without DNS. */
|
|
136
|
+
interface SyncOptions extends SyntaxOptions {
|
|
137
|
+
/** Reject addresses at known disposable email services. Default `true`. */
|
|
138
|
+
disposable?: boolean;
|
|
139
|
+
/** Extra domains to reject (subdomains included). Always applied, even with `disposable: false`. */
|
|
140
|
+
blockDomains?: Iterable<string>;
|
|
141
|
+
/** Domains to exempt from the built-in disposable list (subdomains included). Does not override `blockDomains`. */
|
|
142
|
+
allowDomains?: Iterable<string>;
|
|
143
|
+
/** Reject role accounts such as `admin@`, `support@`, `noreply@`. Default `false` (they are only flagged). */
|
|
144
|
+
rejectRole?: boolean;
|
|
145
|
+
}
|
|
146
|
+
interface ValidmailOptions extends SyncOptions, MxOptions {
|
|
147
|
+
/** Check that the domain can receive mail (MX, with A/AAAA fallback). Default `true`. */
|
|
148
|
+
mx?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* When the DNS lookup times out or fails (SERVFAIL, network error), treat the address as valid
|
|
151
|
+
* instead of invalid. `checks.mx.status` is still `'error'`. Default `false`.
|
|
152
|
+
*/
|
|
153
|
+
allowDnsErrors?: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface ValidateManyOptions extends ValidmailOptions {
|
|
156
|
+
/** Maximum number of addresses validated at the same time. Default `10`. */
|
|
157
|
+
concurrency?: number;
|
|
158
|
+
}
|
|
159
|
+
interface SyntaxCheck {
|
|
160
|
+
status: 'pass' | 'fail';
|
|
161
|
+
reason?: SyntaxReason;
|
|
162
|
+
message?: string;
|
|
163
|
+
}
|
|
164
|
+
interface DisposableCheck {
|
|
165
|
+
status: 'pass' | 'fail' | 'skip';
|
|
166
|
+
reason?: DisposableReason;
|
|
167
|
+
message?: string;
|
|
168
|
+
/** The domain is on the built-in disposable list (even if `allowDomains` exempts it or `disposable: false`). */
|
|
169
|
+
isDisposable: boolean;
|
|
170
|
+
/** The list entry that matched, e.g. `mailinator.com` for `x.mailinator.com`. */
|
|
171
|
+
match?: string;
|
|
172
|
+
/** Which list matched. */
|
|
173
|
+
source?: 'builtin' | 'blockDomains' | 'allowDomains';
|
|
174
|
+
}
|
|
175
|
+
interface RoleCheck {
|
|
176
|
+
status: 'pass' | 'fail' | 'skip';
|
|
177
|
+
reason?: 'role';
|
|
178
|
+
message?: string;
|
|
179
|
+
/** The address is a role account such as `admin@` or `support@`. */
|
|
180
|
+
isRole: boolean;
|
|
181
|
+
/** The normalized role name, e.g. `support`. */
|
|
182
|
+
role?: string;
|
|
183
|
+
}
|
|
184
|
+
interface Checks {
|
|
185
|
+
syntax: SyntaxCheck;
|
|
186
|
+
disposable: DisposableCheck;
|
|
187
|
+
role: RoleCheck;
|
|
188
|
+
mx: MxCheck;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The result of `validmail()`. When `valid` is `false`, `reason` is the first failing check's
|
|
192
|
+
* reason code and `message` explains it. Every check's own detail is in `checks`.
|
|
193
|
+
*/
|
|
194
|
+
type ValidationResult = EmailParts & Outcome<Reason> & {
|
|
195
|
+
checks: Checks;
|
|
196
|
+
/** Mail servers sorted by priority, when the MX check passed. */
|
|
197
|
+
mxRecords?: MxRecord[];
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Validate an email address without DNS: syntax, disposable domains, blocklist and role accounts.
|
|
201
|
+
* `checks.mx.status` is always `'skip'`.
|
|
202
|
+
*/
|
|
203
|
+
declare function validateSync(email: string, options?: SyncOptions): ValidationResult;
|
|
204
|
+
/**
|
|
205
|
+
* Validate an email address: syntax, disposable domains, role accounts, then DNS (MX, with
|
|
206
|
+
* A/AAAA fallback and null MX detection). Resolves with a detailed result; never rejects for
|
|
207
|
+
* a bad address. Rejects only if `options.signal` aborts.
|
|
208
|
+
*/
|
|
209
|
+
declare function validate(email: string, options?: ValidmailOptions): Promise<ValidationResult>;
|
|
210
|
+
/** `true` if the address passes the checks that need no DNS (see `validateSync`). */
|
|
211
|
+
declare function isValidEmail(email: string, options?: SyncOptions): boolean;
|
|
212
|
+
/** `true` if the address passes every check, including DNS (see `validate`). */
|
|
213
|
+
declare function isValidEmailAsync(email: string, options?: ValidmailOptions): Promise<boolean>;
|
|
214
|
+
/**
|
|
215
|
+
* Validate many addresses with limited concurrency. Results are in input order. Addresses on
|
|
216
|
+
* the same domain share one DNS lookup.
|
|
217
|
+
*/
|
|
218
|
+
declare function validateMany(emails: Iterable<string>, options?: ValidateManyOptions): Promise<ValidationResult[]>;
|
|
219
|
+
interface Validmail {
|
|
220
|
+
/** Validate an email address, including DNS. Same as `validate`. */
|
|
221
|
+
(email: string, options?: ValidmailOptions): Promise<ValidationResult>;
|
|
222
|
+
validate: typeof validate;
|
|
223
|
+
sync: typeof validateSync;
|
|
224
|
+
validateSync: typeof validateSync;
|
|
225
|
+
validateMany: typeof validateMany;
|
|
226
|
+
checkSyntax: typeof checkSyntax;
|
|
227
|
+
checkMx: typeof checkMx;
|
|
228
|
+
isValidEmail: typeof isValidEmail;
|
|
229
|
+
isValidEmailAsync: typeof isValidEmailAsync;
|
|
230
|
+
isDisposable: typeof isDisposable;
|
|
231
|
+
isRoleAccount: typeof isRoleAccount;
|
|
232
|
+
clearCache: typeof clearCache;
|
|
233
|
+
disposableDomains: typeof disposableDomains;
|
|
234
|
+
}
|
|
235
|
+
declare const validmail: Validmail;
|
|
236
|
+
|
|
237
|
+
export { type CheckStatus, type Checks, type DisposableCheck, type DisposableReason, type EmailParts, type MxCacheEntry, type MxCheck, type MxOptions, type MxReason, type MxRecord, type Outcome, type Reason, type Resolver, type RoleCheck, type SyncOptions, type SyntaxCheck, type SyntaxOptions, type SyntaxReason, type SyntaxResult, type ValidateManyOptions, type ValidationResult, type Validmail, type ValidmailOptions, checkMx, checkSyntax, clearCache, validmail as default, disposableDomains, isDisposable, isRoleAccount, isValidEmail, isValidEmailAsync, validate, validateMany, validateSync };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/** The built-in disposable domain list (lowercase ASCII, sorted). */
|
|
2
|
+
declare const disposableDomains: readonly string[];
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* True if the email address (or bare domain) belongs to a known disposable email service.
|
|
6
|
+
* Subdomains match too: `x.mailinator.com` is disposable.
|
|
7
|
+
*/
|
|
8
|
+
declare function isDisposable(emailOrDomain: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* True if the address is a role account such as `admin@`, `support@` or `noreply@`.
|
|
11
|
+
* Sub-addresses count: `info+news@example.com` is a role account.
|
|
12
|
+
*/
|
|
13
|
+
declare function isRoleAccount(emailOrLocal: string): boolean;
|
|
14
|
+
|
|
15
|
+
/** An MX record: the mail server host name and its preference (lower is tried first). */
|
|
16
|
+
interface MxRecord {
|
|
17
|
+
exchange: string;
|
|
18
|
+
priority: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The DNS methods validmail uses. `dns.promises`, a `new dns.promises.Resolver()` (for custom
|
|
22
|
+
* DNS servers) and plain objects (for tests) all fit. Errors should carry Node's DNS error
|
|
23
|
+
* codes (`ENODATA`, `ENOTFOUND`, `ETIMEOUT`, ...) in `error.code`.
|
|
24
|
+
*/
|
|
25
|
+
interface Resolver {
|
|
26
|
+
resolveMx(hostname: string): Promise<MxRecord[]>;
|
|
27
|
+
/** Used for the implicit MX fallback (RFC 5321 §5.1). Optional. */
|
|
28
|
+
resolve4?(hostname: string): Promise<string[]>;
|
|
29
|
+
/** Used for the implicit MX fallback (RFC 5321 §5.1). Optional. */
|
|
30
|
+
resolve6?(hostname: string): Promise<string[]>;
|
|
31
|
+
}
|
|
32
|
+
/** Why the MX check failed or could not finish. */
|
|
33
|
+
type MxReason = 'domain_not_found' | 'no_mx' | 'null_mx' | 'timeout' | 'dns_error';
|
|
34
|
+
/**
|
|
35
|
+
* - `pass`: the domain can receive mail.
|
|
36
|
+
* - `fail`: it definitely cannot (no such domain, no mail server, null MX).
|
|
37
|
+
* - `error`: DNS did not answer in time or failed; the address may still be fine.
|
|
38
|
+
* - `skip`: the check did not run.
|
|
39
|
+
*/
|
|
40
|
+
type CheckStatus = 'pass' | 'fail' | 'skip' | 'error';
|
|
41
|
+
interface MxCheck {
|
|
42
|
+
status: CheckStatus;
|
|
43
|
+
reason?: MxReason;
|
|
44
|
+
message?: string;
|
|
45
|
+
/** Mail servers sorted by priority. For an implicit MX this is the domain itself with priority 0. */
|
|
46
|
+
records?: MxRecord[];
|
|
47
|
+
/** No MX records, but the domain has an A/AAAA address, which RFC 5321 §5.1 treats as its mail server. */
|
|
48
|
+
implicit?: boolean;
|
|
49
|
+
/** The result came from the cache. */
|
|
50
|
+
cached?: boolean;
|
|
51
|
+
/** DNS error code, when `status` is `error`. */
|
|
52
|
+
code?: string;
|
|
53
|
+
}
|
|
54
|
+
interface MxCacheEntry {
|
|
55
|
+
expires: number;
|
|
56
|
+
value: MxCheck;
|
|
57
|
+
}
|
|
58
|
+
interface MxOptions {
|
|
59
|
+
/** Milliseconds before the DNS check gives up with status `error` / reason `timeout`. `0` disables. Default `5000`. */
|
|
60
|
+
timeout?: number;
|
|
61
|
+
/** DNS resolver to use. Default: the system resolver (`node:dns/promises`). */
|
|
62
|
+
resolver?: Resolver;
|
|
63
|
+
/**
|
|
64
|
+
* Cache DNS results per domain. `true` (default) uses a built-in in-memory cache per resolver,
|
|
65
|
+
* `false` disables caching, or pass your own `Map` to control and share it.
|
|
66
|
+
* Only definite answers (`pass`/`fail`) are cached; errors and timeouts are not.
|
|
67
|
+
*/
|
|
68
|
+
cache?: boolean | Map<string, MxCacheEntry>;
|
|
69
|
+
/** How long cached results stay fresh, in milliseconds. Default `3600000` (1 hour). */
|
|
70
|
+
cacheTtl?: number;
|
|
71
|
+
/** Accept domains without MX records that have an A/AAAA address (RFC 5321 §5.1). Default `true`. */
|
|
72
|
+
implicitMx?: boolean;
|
|
73
|
+
/** Abort the lookup. The promise rejects with `signal.reason`. */
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
}
|
|
76
|
+
/** Empty the built-in DNS result caches. Caches you passed in with `cache: Map` are not touched. */
|
|
77
|
+
declare function clearCache(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Check whether a domain can receive email: MX records, falling back to A/AAAA (implicit MX),
|
|
80
|
+
* and detecting null MX (RFC 7505). Accepts a domain or a full address.
|
|
81
|
+
* Throws a `TypeError` if the domain is not a syntactically valid host name.
|
|
82
|
+
*/
|
|
83
|
+
declare function checkMx(domainOrEmail: string, options?: MxOptions): Promise<MxCheck>;
|
|
84
|
+
|
|
85
|
+
/** Why an address failed the syntax check. */
|
|
86
|
+
type SyntaxReason = 'invalid_type' | 'empty' | 'too_long' | 'missing_at' | 'local_empty' | 'local_too_long' | 'local_invalid_char' | 'local_unicode' | 'local_dot' | 'quoted_not_allowed' | 'quoted_invalid' | 'domain_empty' | 'domain_too_long' | 'domain_label_too_long' | 'domain_invalid' | 'domain_no_tld' | 'tld_invalid' | 'ip_literal_not_allowed' | 'ip_literal_invalid';
|
|
87
|
+
interface SyntaxOptions {
|
|
88
|
+
/** Accept quoted local parts such as `"john doe"@example.com`. Default `false`. */
|
|
89
|
+
allowQuoted?: boolean;
|
|
90
|
+
/** Accept address literals such as `user@[192.0.2.1]` and `user@[IPv6:2001:db8::1]`. Default `false`. */
|
|
91
|
+
allowIpLiteral?: boolean;
|
|
92
|
+
/** Accept non-ASCII characters in the local part (RFC 6531, SMTPUTF8). Default `false`. Unicode domains are always accepted. */
|
|
93
|
+
allowUnicodeLocal?: boolean;
|
|
94
|
+
/** Require a dot in the domain (`user@localhost` fails). Default `true`. */
|
|
95
|
+
requireTld?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** The parts of an address, normalized. Present on both valid and invalid results (best effort). */
|
|
98
|
+
interface EmailParts {
|
|
99
|
+
/** Normalized address: trimmed, domain lowercased (Unicode form for IDNs). */
|
|
100
|
+
email: string;
|
|
101
|
+
/** The part before the last `@`, unchanged (case is preserved). */
|
|
102
|
+
local: string;
|
|
103
|
+
/** Lowercased domain in Unicode form (`bücher.de`), or the bracketed literal for IP addresses. */
|
|
104
|
+
domain: string;
|
|
105
|
+
/** Domain in ASCII / punycode form (`xn--bcher-kva.de`), as used for DNS. Empty when the domain is invalid. */
|
|
106
|
+
asciiDomain: string;
|
|
107
|
+
/** The local part is a quoted string. */
|
|
108
|
+
quoted: boolean;
|
|
109
|
+
/** The domain is an address literal (`[192.0.2.1]`). */
|
|
110
|
+
ipLiteral: boolean;
|
|
111
|
+
}
|
|
112
|
+
/** `valid: true` with no reason, or `valid: false` with a reason code and a readable message. */
|
|
113
|
+
type Outcome<R extends string> = {
|
|
114
|
+
valid: true;
|
|
115
|
+
reason?: undefined;
|
|
116
|
+
message?: undefined;
|
|
117
|
+
} | {
|
|
118
|
+
valid: false;
|
|
119
|
+
reason: R;
|
|
120
|
+
message: string;
|
|
121
|
+
};
|
|
122
|
+
type SyntaxResult = EmailParts & Outcome<SyntaxReason>;
|
|
123
|
+
/**
|
|
124
|
+
* Check the syntax of an email address (RFC 5321/5322, practical subset). Never touches the network.
|
|
125
|
+
*
|
|
126
|
+
* Runs in linear time: there are no backtracking regular expressions, and input longer than
|
|
127
|
+
* 254 characters is rejected before it is scanned.
|
|
128
|
+
*/
|
|
129
|
+
declare function checkSyntax(email: string, options?: SyntaxOptions): SyntaxResult;
|
|
130
|
+
|
|
131
|
+
/** Why the disposable/blocklist check failed. */
|
|
132
|
+
type DisposableReason = 'disposable' | 'blocked';
|
|
133
|
+
/** Every reason an address can be rejected, in the order the checks run. */
|
|
134
|
+
type Reason = SyntaxReason | DisposableReason | 'role' | MxReason;
|
|
135
|
+
/** Options for the checks that run without DNS. */
|
|
136
|
+
interface SyncOptions extends SyntaxOptions {
|
|
137
|
+
/** Reject addresses at known disposable email services. Default `true`. */
|
|
138
|
+
disposable?: boolean;
|
|
139
|
+
/** Extra domains to reject (subdomains included). Always applied, even with `disposable: false`. */
|
|
140
|
+
blockDomains?: Iterable<string>;
|
|
141
|
+
/** Domains to exempt from the built-in disposable list (subdomains included). Does not override `blockDomains`. */
|
|
142
|
+
allowDomains?: Iterable<string>;
|
|
143
|
+
/** Reject role accounts such as `admin@`, `support@`, `noreply@`. Default `false` (they are only flagged). */
|
|
144
|
+
rejectRole?: boolean;
|
|
145
|
+
}
|
|
146
|
+
interface ValidmailOptions extends SyncOptions, MxOptions {
|
|
147
|
+
/** Check that the domain can receive mail (MX, with A/AAAA fallback). Default `true`. */
|
|
148
|
+
mx?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* When the DNS lookup times out or fails (SERVFAIL, network error), treat the address as valid
|
|
151
|
+
* instead of invalid. `checks.mx.status` is still `'error'`. Default `false`.
|
|
152
|
+
*/
|
|
153
|
+
allowDnsErrors?: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface ValidateManyOptions extends ValidmailOptions {
|
|
156
|
+
/** Maximum number of addresses validated at the same time. Default `10`. */
|
|
157
|
+
concurrency?: number;
|
|
158
|
+
}
|
|
159
|
+
interface SyntaxCheck {
|
|
160
|
+
status: 'pass' | 'fail';
|
|
161
|
+
reason?: SyntaxReason;
|
|
162
|
+
message?: string;
|
|
163
|
+
}
|
|
164
|
+
interface DisposableCheck {
|
|
165
|
+
status: 'pass' | 'fail' | 'skip';
|
|
166
|
+
reason?: DisposableReason;
|
|
167
|
+
message?: string;
|
|
168
|
+
/** The domain is on the built-in disposable list (even if `allowDomains` exempts it or `disposable: false`). */
|
|
169
|
+
isDisposable: boolean;
|
|
170
|
+
/** The list entry that matched, e.g. `mailinator.com` for `x.mailinator.com`. */
|
|
171
|
+
match?: string;
|
|
172
|
+
/** Which list matched. */
|
|
173
|
+
source?: 'builtin' | 'blockDomains' | 'allowDomains';
|
|
174
|
+
}
|
|
175
|
+
interface RoleCheck {
|
|
176
|
+
status: 'pass' | 'fail' | 'skip';
|
|
177
|
+
reason?: 'role';
|
|
178
|
+
message?: string;
|
|
179
|
+
/** The address is a role account such as `admin@` or `support@`. */
|
|
180
|
+
isRole: boolean;
|
|
181
|
+
/** The normalized role name, e.g. `support`. */
|
|
182
|
+
role?: string;
|
|
183
|
+
}
|
|
184
|
+
interface Checks {
|
|
185
|
+
syntax: SyntaxCheck;
|
|
186
|
+
disposable: DisposableCheck;
|
|
187
|
+
role: RoleCheck;
|
|
188
|
+
mx: MxCheck;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The result of `validmail()`. When `valid` is `false`, `reason` is the first failing check's
|
|
192
|
+
* reason code and `message` explains it. Every check's own detail is in `checks`.
|
|
193
|
+
*/
|
|
194
|
+
type ValidationResult = EmailParts & Outcome<Reason> & {
|
|
195
|
+
checks: Checks;
|
|
196
|
+
/** Mail servers sorted by priority, when the MX check passed. */
|
|
197
|
+
mxRecords?: MxRecord[];
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Validate an email address without DNS: syntax, disposable domains, blocklist and role accounts.
|
|
201
|
+
* `checks.mx.status` is always `'skip'`.
|
|
202
|
+
*/
|
|
203
|
+
declare function validateSync(email: string, options?: SyncOptions): ValidationResult;
|
|
204
|
+
/**
|
|
205
|
+
* Validate an email address: syntax, disposable domains, role accounts, then DNS (MX, with
|
|
206
|
+
* A/AAAA fallback and null MX detection). Resolves with a detailed result; never rejects for
|
|
207
|
+
* a bad address. Rejects only if `options.signal` aborts.
|
|
208
|
+
*/
|
|
209
|
+
declare function validate(email: string, options?: ValidmailOptions): Promise<ValidationResult>;
|
|
210
|
+
/** `true` if the address passes the checks that need no DNS (see `validateSync`). */
|
|
211
|
+
declare function isValidEmail(email: string, options?: SyncOptions): boolean;
|
|
212
|
+
/** `true` if the address passes every check, including DNS (see `validate`). */
|
|
213
|
+
declare function isValidEmailAsync(email: string, options?: ValidmailOptions): Promise<boolean>;
|
|
214
|
+
/**
|
|
215
|
+
* Validate many addresses with limited concurrency. Results are in input order. Addresses on
|
|
216
|
+
* the same domain share one DNS lookup.
|
|
217
|
+
*/
|
|
218
|
+
declare function validateMany(emails: Iterable<string>, options?: ValidateManyOptions): Promise<ValidationResult[]>;
|
|
219
|
+
interface Validmail {
|
|
220
|
+
/** Validate an email address, including DNS. Same as `validate`. */
|
|
221
|
+
(email: string, options?: ValidmailOptions): Promise<ValidationResult>;
|
|
222
|
+
validate: typeof validate;
|
|
223
|
+
sync: typeof validateSync;
|
|
224
|
+
validateSync: typeof validateSync;
|
|
225
|
+
validateMany: typeof validateMany;
|
|
226
|
+
checkSyntax: typeof checkSyntax;
|
|
227
|
+
checkMx: typeof checkMx;
|
|
228
|
+
isValidEmail: typeof isValidEmail;
|
|
229
|
+
isValidEmailAsync: typeof isValidEmailAsync;
|
|
230
|
+
isDisposable: typeof isDisposable;
|
|
231
|
+
isRoleAccount: typeof isRoleAccount;
|
|
232
|
+
clearCache: typeof clearCache;
|
|
233
|
+
disposableDomains: typeof disposableDomains;
|
|
234
|
+
}
|
|
235
|
+
declare const validmail: Validmail;
|
|
236
|
+
|
|
237
|
+
export { type CheckStatus, type Checks, type DisposableCheck, type DisposableReason, type EmailParts, type MxCacheEntry, type MxCheck, type MxOptions, type MxReason, type MxRecord, type Outcome, type Reason, type Resolver, type RoleCheck, type SyncOptions, type SyntaxCheck, type SyntaxOptions, type SyntaxReason, type SyntaxResult, type ValidateManyOptions, type ValidationResult, type Validmail, type ValidmailOptions, checkMx, checkSyntax, clearCache, validmail as default, disposableDomains, isDisposable, isRoleAccount, isValidEmail, isValidEmailAsync, validate, validateMany, validateSync };
|