@xpoudy/free-tools 0.1.1 → 1.1.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/LICENSE +21 -0
- package/README.md +26 -7
- package/assets/calculators.js +175 -0
- package/assets/common.js +176 -0
- package/assets/copy.js +140 -0
- package/assets/dns.js +280 -0
- package/assets/lists.js +187 -0
- package/assets/mail.js +302 -0
- package/assets/message.js +47 -0
- package/assets/mirror-index.css +6 -0
- package/assets/reports.js +179 -0
- package/assets/toolbox-auth.js +229 -0
- package/assets/toolbox-campaign.js +154 -0
- package/assets/toolbox-compose.js +212 -0
- package/assets/toolbox-data.js +53 -0
- package/assets/toolbox-disposable-license.txt +24 -0
- package/assets/toolbox-disposable.js +1 -0
- package/assets/toolbox-domain.js +199 -0
- package/assets/toolbox-files.js +250 -0
- package/assets/toolbox-leads.js +133 -0
- package/assets/toolbox-measure.js +153 -0
- package/assets/toolbox-pdf-license.txt +177 -0
- package/assets/toolbox-pdf-worker.js +21 -0
- package/assets/toolbox-pdf.js +21 -0
- package/assets/toolbox-ui.js +285 -0
- package/assets/toolbox-vendor-data.js +6 -0
- package/assets/toolbox-vendor-licenses.txt +75 -0
- package/assets/toolbox-vendor-qr.js +8 -0
- package/assets/toolbox.css +14 -0
- package/assets/tools.css +112 -0
- package/assets/ui.js +257 -0
- package/catalog.json +3 -1
- package/favicon-32x32.png +0 -0
- package/index.html +1 -0
- package/index.js +3 -1
- package/package.json +17 -3
- package/tools/cold-email-volume-calculator/index.html +33 -0
package/assets/dns.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import {InputError, asciiDomain, modelResult, requiredText} from './common.js';
|
|
2
|
+
|
|
3
|
+
const providers = {
|
|
4
|
+
Google: 'https://dns.google/resolve',
|
|
5
|
+
Cloudflare: 'https://cloudflare-dns.com/dns-query'
|
|
6
|
+
};
|
|
7
|
+
const types = new Map(Object.entries({A:1,NS:2,CNAME:5,SOA:6,PTR:12,MX:15,TXT:16,AAAA:28,SRV:33,DS:43,RRSIG:46,DNSKEY:48,TLSA:52,HTTPS:65,CAA:257}));
|
|
8
|
+
const typeNames = new Map([...types].map(([name,id])=>[id,name]));
|
|
9
|
+
const statuses = new Map([[0,'OK'],[1,'Format error'],[2,'Resolver failure'],[3,'Name does not exist'],[4,'Unsupported query'],[5,'Query refused']]);
|
|
10
|
+
const shown = set => set.length ? String(set.length) : '0';
|
|
11
|
+
const flag = value => value ? 'Yes' : 'No';
|
|
12
|
+
|
|
13
|
+
export function hostname(input, attributes=false){
|
|
14
|
+
const raw=String(input??'').trim().replace(/\.$/,'');
|
|
15
|
+
const normal=asciiDomain(raw);
|
|
16
|
+
if(normal) return normal;
|
|
17
|
+
if(attributes && raw.length<=253 && raw.includes('.') && raw.split('.').every(x=>/^[a-z0-9_](?:[a-z0-9_-]{0,61}[a-z0-9_])?$/i.test(x))) return raw.toLowerCase();
|
|
18
|
+
throw new InputError('Enter a valid domain or hostname, such as example.com.');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function ipv4(value){
|
|
22
|
+
const parts=String(value??'').split('.');
|
|
23
|
+
if(parts.length!==4 || parts.some(x=>!(/^(0|[1-9]\d{0,2})$/.test(x)) || Number(x)>255)) return null;
|
|
24
|
+
return parts.map(Number);
|
|
25
|
+
}
|
|
26
|
+
export function ipv6(value){
|
|
27
|
+
let raw=String(value??'').toLowerCase();
|
|
28
|
+
if(raw.includes('.')){
|
|
29
|
+
const index=raw.lastIndexOf(':');
|
|
30
|
+
const mapped=ipv4(raw.slice(index+1));
|
|
31
|
+
if(index<0||!mapped) return null;
|
|
32
|
+
raw=raw.slice(0,index+1)+((mapped[0]<<8)+mapped[1]).toString(16)+':'+((mapped[2]<<8)+mapped[3]).toString(16);
|
|
33
|
+
}
|
|
34
|
+
const halves=raw.split('::');
|
|
35
|
+
if(halves.length>2)return null;
|
|
36
|
+
const left=halves[0]?halves[0].split(':'):[];
|
|
37
|
+
const right=halves[1]?halves[1].split(':'):[];
|
|
38
|
+
const count=left.length+right.length;
|
|
39
|
+
if((halves.length===1&&count!==8)||(halves.length===2&&count>=8)||[...left,...right].some(x=>!/^[a-f0-9]{1,4}$/.test(x))) return null;
|
|
40
|
+
return [...left,...Array(8-count).fill('0'),...right].map(x=>x.padStart(4,'0'));
|
|
41
|
+
}
|
|
42
|
+
export function reverseName(value){
|
|
43
|
+
const ip=String(value??'').trim();
|
|
44
|
+
const v4=ipv4(ip);
|
|
45
|
+
if(v4) return v4.slice().reverse().join('.')+'.in-addr.arpa';
|
|
46
|
+
const v6=ipv6(ip);
|
|
47
|
+
if(v6) return v6.join('').split('').reverse().join('.')+'.ip6.arpa';
|
|
48
|
+
throw new InputError('Enter a valid IPv4 or IPv6 address.');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function unquoteTxt(value){
|
|
52
|
+
const raw=String(value).trim();
|
|
53
|
+
if(!raw.startsWith('"'))return raw;
|
|
54
|
+
return [...raw.matchAll(/"((?:[^"\\]|\\.)*)"/g)].map(m=>m[1].replace(/\\([0-9]{3}|.)/g,(_,x)=>x.length===3?String.fromCharCode(Number(x)):x)).join('');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createDns(fetcher=fetch){
|
|
58
|
+
const cached=new Map();
|
|
59
|
+
return async function query(name,type,provider='Google',wantDnssec=false){
|
|
60
|
+
const key=[name,type,provider,wantDnssec].join('|');
|
|
61
|
+
if(cached.has(key))return cached.get(key);
|
|
62
|
+
if(cached.size>=45)throw new InputError('The lookup reached its query budget. Try a smaller set of records.');
|
|
63
|
+
const url=new URL(providers[provider]);
|
|
64
|
+
url.searchParams.set('name',name);
|
|
65
|
+
url.searchParams.set('type',String(types.get(type)));
|
|
66
|
+
if(wantDnssec) url.searchParams.set('do','1');
|
|
67
|
+
if(provider==='Google')url.searchParams.set('edns_client_subnet','0.0.0.0/0');
|
|
68
|
+
const operation=(async()=>{
|
|
69
|
+
let payload;
|
|
70
|
+
try{
|
|
71
|
+
const res=await fetcher(url,{headers:{Accept:'application/dns-json'},credentials:'omit',referrerPolicy:'no-referrer',redirect:'error',signal:AbortSignal.timeout(6500)});
|
|
72
|
+
if(!res.ok)throw new Error('DNS HTTP '+res.status);
|
|
73
|
+
payload=await res.json();
|
|
74
|
+
if(!Number.isInteger(payload.Status))throw new Error('Invalid DNS response');
|
|
75
|
+
}catch{
|
|
76
|
+
throw new InputError(provider+' did not return a usable DNS response. Try again in a moment.');
|
|
77
|
+
}
|
|
78
|
+
const answers=Array.isArray(payload.Answer)?payload.Answer.filter(x=>typeof x.data==='string'&&typeof x.name==='string').slice(0,150):[];
|
|
79
|
+
return {status:payload.Status, ad:payload.AD===true, truncated:payload.TC===true, all:answers, records:answers.filter(x=>x.type===types.get(type))};
|
|
80
|
+
})();
|
|
81
|
+
cached.set(key,operation);
|
|
82
|
+
return operation;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function recordsTable(answers){
|
|
86
|
+
return {columns:['Record name','Type','TTL (seconds)','Value'],rows:answers.map(x=>[x.name,typeNames.get(x.type)??x.type,x.TTL??'—',x.type===16?unquoteTxt(x.data):x.data])};
|
|
87
|
+
}
|
|
88
|
+
function reliable(reply){
|
|
89
|
+
if(reply.status!==0&&reply.status!==3)throw new InputError('DNS returned '+(statuses.get(reply.status)??`status ${reply.status}`)+'. Try again before changing records.');
|
|
90
|
+
if(reply.truncated)throw new InputError('The resolver truncated this response. The record set may be incomplete.');
|
|
91
|
+
return reply;
|
|
92
|
+
}
|
|
93
|
+
function dnsStatus(reply){return statuses.get(reply.status)??`DNS status ${reply.status}`;}
|
|
94
|
+
function lookupResult(name,type,reply){
|
|
95
|
+
reliable(reply);
|
|
96
|
+
const message=reply.status===3?'Name does not exist':reply.records.length?'Records found':'No records of this type';
|
|
97
|
+
return modelResult([['Query',type],['Result',message],['Matching records',shown(reply.records)],['Resolver validated DNSSEC',flag(reply.ad)]],{table:recordsTable(reply.all),notes:[`Queried ${name}. Results may be affected by cached DNS records.`]});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function dnsLookup(values,{query=createDns()}={}){
|
|
101
|
+
const type=String(values.record_type??'A');
|
|
102
|
+
if(!types.has(type))throw new InputError('Choose a supported record type.');
|
|
103
|
+
const name=type==='PTR'?reverseName(values.name):hostname(values.name,true);
|
|
104
|
+
return lookupResult(name,type,await query(name,type));
|
|
105
|
+
}
|
|
106
|
+
export async function mxLookup(values,{query=createDns()}={}){
|
|
107
|
+
const name=hostname(values.domain);
|
|
108
|
+
const reply=reliable(await query(name,'MX'));
|
|
109
|
+
const parsed=reply.records.map(r=>{const [priority,host]=r.data.trim().split(/\s+/);return {priority:Number(priority),host,ttl:r.TTL};}).filter(x=>Number.isInteger(x.priority)&&x.host).sort((a,b)=>a.priority-b.priority);
|
|
110
|
+
const nullMx=parsed.some(x=>x.host==='.');
|
|
111
|
+
const status=reply.status===3?'Domain does not exist':nullMx?(parsed.length===1&&parsed[0].priority===0?'This domain rejects incoming mail':'Null MX conflicts with other records'):parsed.length?'Mail exchangers found':'No explicit MX';
|
|
112
|
+
return modelResult([['Domain',name],['Routing status',status],['MX records',shown(parsed)]],{table:{columns:['Priority','Mail exchanger','TTL (seconds)'],rows:parsed.map(x=>[x.priority,x.host,x.ttl??'—'])},notes:['Lowest numeric priority is preferred. A missing MX record may fall back to address records when SMTP routing rules allow it.','Published records describe routing. They do not test whether a server accepts connections.']});
|
|
113
|
+
}
|
|
114
|
+
export async function ptrLookup(values,{query=createDns()}={}){
|
|
115
|
+
const ip=String(values.ip??'').trim();
|
|
116
|
+
const reverse=reverseName(ip);
|
|
117
|
+
const reply=reliable(await query(reverse,'PTR'));
|
|
118
|
+
const names=[...new Set(reply.records.map(x=>x.data.replace(/\.$/,'')))].slice(0,8);
|
|
119
|
+
const family=ipv4(ip)?'A':'AAAA';
|
|
120
|
+
const normalize=family==='A'?x=>ipv4(x)?.join('.'):x=>ipv6(x)?.join(':');
|
|
121
|
+
const rows=await Promise.all(names.map(async name=>{
|
|
122
|
+
try{
|
|
123
|
+
const result=reliable(await query(hostname(name),family));
|
|
124
|
+
const ips=result.records.map(x=>x.data);
|
|
125
|
+
return [name,ips.join(', ')||'No address record',ips.some(x=>normalize(x)===normalize(ip))?'Matches':'Does not match'];
|
|
126
|
+
}catch{return [name,'Unavailable','Could not verify'];}
|
|
127
|
+
}));
|
|
128
|
+
return modelResult([['IP address',ip],['PTR hosts checked',shown(names)],['Forward matches',shown(rows.filter(x=>x[2]==='Matches'))]],{table:{columns:['PTR hostname','Forward addresses','Forward check'],rows},notes:['Forward-confirmed reverse DNS requires at least one PTR hostname to resolve back to the original IP.',...(reply.records.length>8?['Only the first eight unique PTR targets were checked.']:[])]});
|
|
129
|
+
}
|
|
130
|
+
export async function propagation(values,{query=createDns()}={}){
|
|
131
|
+
const record=String(values.record_type??'A');
|
|
132
|
+
if(!types.has(record))throw new InputError('Choose a supported record type.');
|
|
133
|
+
const name=record==='PTR'?reverseName(values.name):hostname(values.name,true);
|
|
134
|
+
const runs=await Promise.allSettled(Object.keys(providers).map(provider=>query(name,record,provider)));
|
|
135
|
+
const rows=runs.map((item,i)=>{
|
|
136
|
+
const provider=Object.keys(providers)[i];
|
|
137
|
+
if(item.status==='rejected')return [provider,'Unavailable','—','—'];
|
|
138
|
+
const reply=item.value;
|
|
139
|
+
const content=reply.records.map(x=>record==='TXT'?unquoteTxt(x.data):x.data).sort().join('\n')||'—';
|
|
140
|
+
return [provider,reply.truncated?'Truncated':dnsStatus(reply),content,reply.records.map(x=>x.TTL).join(', ')||'—'];
|
|
141
|
+
});
|
|
142
|
+
const complete=rows.every(x=>x[1]==='OK'||x[1]==='Name does not exist');
|
|
143
|
+
const status=complete?(rows[0][1]===rows[1][1]&&rows[0][2]===rows[1][2]?'Resolvers agree':'Resolvers differ'):'Incomplete comparison';
|
|
144
|
+
return modelResult([['Comparison',status],['Resolvers sampled','2'],['Query',record+' '+name]],{table:{columns:['Resolver','DNS status','Record values','TTL (seconds)'],rows},notes:['This compares two public resolvers from this browser. It does not sample particular countries or predict when every cache will update.']});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function tags(record){
|
|
148
|
+
const output=new Map();
|
|
149
|
+
const duplicates=[];
|
|
150
|
+
const malformed=[];
|
|
151
|
+
for(const term of String(record).split(';').map(x=>x.trim()).filter(Boolean)){
|
|
152
|
+
const match=/^([A-Za-z][A-Za-z0-9_-]*)\s*=\s*(.*)$/s.exec(term);
|
|
153
|
+
if(!match)malformed.push(term);
|
|
154
|
+
else if(output.has(match[1].toLowerCase()))duplicates.push(match[1]);
|
|
155
|
+
else output.set(match[1].toLowerCase(),match[2]);
|
|
156
|
+
}
|
|
157
|
+
return {output,duplicates,malformed};
|
|
158
|
+
}
|
|
159
|
+
const txtRecords=(reply,pattern)=>reply.records.map(r=>unquoteTxt(r.data)).filter(t=>pattern.test(t));
|
|
160
|
+
export async function spfCheck(values,{query=createDns()}={}){
|
|
161
|
+
const domain=hostname(values.domain);
|
|
162
|
+
let budget=0;
|
|
163
|
+
let incomplete=false;
|
|
164
|
+
const rows=[];
|
|
165
|
+
const findings=[];
|
|
166
|
+
const active=new Set();
|
|
167
|
+
async function visit(name,depth){
|
|
168
|
+
if(active.has(name)){findings.push('Circular SPF include or redirect at '+name+'.');return;}
|
|
169
|
+
if(depth>12||rows.length>=36){incomplete=true;return;}
|
|
170
|
+
let list;
|
|
171
|
+
try{list=txtRecords(reliable(await query(name,'TXT')), /^v=spf1(?:\s|$)/i);}
|
|
172
|
+
catch(error){if(!depth)throw error;incomplete=true;findings.push('Could not resolve '+name+'.');return;}
|
|
173
|
+
rows.push([name,list.length===1?list[0]:`${list.length} SPF records found`]);
|
|
174
|
+
if(list.length!==1){findings.push(list.length?'Multiple SPF records at '+name+'.':'No SPF record at '+name+'.');return;}
|
|
175
|
+
active.add(name);
|
|
176
|
+
let redirect;
|
|
177
|
+
let terminal=false;
|
|
178
|
+
for(const token of list[0].split(/\s+/).slice(1)){
|
|
179
|
+
if(terminal)break;
|
|
180
|
+
const raw=token.replace(/^[+?~-]/,'');
|
|
181
|
+
if(/^redirect=/i.test(raw)){if(redirect) findings.push('More than one redirect at '+name+'.');redirect=raw.slice(9);continue;}
|
|
182
|
+
const match=/^(include|a|mx|ptr|exists)(?=[:/]|$)/i.exec(raw);
|
|
183
|
+
if(raw.toLowerCase()==='all'){terminal=true;continue;}
|
|
184
|
+
if(!match){if(!/^(?:ip[46]:|[\w.-]+=)/i.test(raw)) findings.push('Unrecognized SPF term '+raw+' at '+name+'.');continue;}
|
|
185
|
+
budget++;
|
|
186
|
+
if(match[1].toLowerCase()==='include') await follow(raw.slice(8),depth);
|
|
187
|
+
if(budget>=32){incomplete=true;break;}
|
|
188
|
+
}
|
|
189
|
+
if(redirect&&!terminal&&budget<32){budget++;await follow(redirect,depth);}
|
|
190
|
+
active.delete(name);
|
|
191
|
+
}
|
|
192
|
+
async function follow(target,depth){
|
|
193
|
+
if(target.includes('%')){incomplete=true;findings.push('A dynamic SPF macro needs an actual sender context.');return;}
|
|
194
|
+
try{await visit(hostname(target,true),depth+1);}catch{findings.push('Invalid or unavailable SPF target '+target+'.');incomplete=true;}
|
|
195
|
+
}
|
|
196
|
+
await visit(domain,0);
|
|
197
|
+
const state=budget>10?'Possible lookup limit issue':findings.length?'Review SPF findings':incomplete?'Trace incomplete':'No issue in this trace';
|
|
198
|
+
return modelResult([['Domain',domain],['Finding',state],['Potential lookup terms',String(budget)]],{table:{columns:['Policy domain','Published SPF record'],rows},notes:[...new Set(findings),...(incomplete?['The trace could not evaluate every branch.']:[]),'This counts possible DNS-triggering terms along the inspected branches. A real SPF evaluation can stop earlier when a mechanism matches.']});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function dmarcPolicy(domain,query){
|
|
202
|
+
const labels=domain.split('.');
|
|
203
|
+
let next=labels;
|
|
204
|
+
let first=true;
|
|
205
|
+
const checked=[];
|
|
206
|
+
while(next.length){
|
|
207
|
+
const suffix=next.join('.');
|
|
208
|
+
const name='_dmarc.'+suffix;
|
|
209
|
+
const reply=reliable(await query(name,'TXT'));
|
|
210
|
+
const records=txtRecords(reply,/^v\s*=\s*DMARC1\s*(?:;|$)/i);
|
|
211
|
+
checked.push([name,records.length?`${records.length} candidate record${records.length===1?'':'s'}`:'No candidate record']);
|
|
212
|
+
if(records.length>1)return {status:'Multiple DMARC records',record:records.join('\n'),source:name,checked};
|
|
213
|
+
if(records.length===1){
|
|
214
|
+
const parsed=tags(records[0]);
|
|
215
|
+
const usesPublicSuffix=suffix.split('.').length===1;
|
|
216
|
+
if(!usesPublicSuffix||parsed.output.get('psd')==='y'){
|
|
217
|
+
const policy=parsed.output.get('p');
|
|
218
|
+
let status='Policy found';
|
|
219
|
+
if(parsed.duplicates.length||parsed.malformed.length||!['none','quarantine','reject'].includes(policy))status='Review DMARC record';
|
|
220
|
+
return {status,record:records[0],source:name,checked,policy,exact:first};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
next=next.slice(next.length>=8?next.length-7:1);
|
|
224
|
+
first=false;
|
|
225
|
+
}
|
|
226
|
+
return {status:'No DMARC policy found',checked};
|
|
227
|
+
}
|
|
228
|
+
export async function dmarcCheck(values,{query=createDns()}={}){
|
|
229
|
+
const domain=hostname(values.domain);
|
|
230
|
+
const inspected=await dmarcPolicy(domain,query);
|
|
231
|
+
return modelResult([['Finding',inspected.status],['Published at',inspected.source??'—'],['Published p= policy',inspected.policy??'—']],{text:inspected.record,table:{columns:['DNS name checked','Observation'],rows:inspected.checked},notes:['A published policy does not prove that a particular message passed DMARC. Review message authentication and alignment separately.',...(inspected.exact===false?['This record was located above the exact domain. Subdomain policy tags and receiver behavior can affect the effective action.']:[])]});
|
|
232
|
+
}
|
|
233
|
+
function dkimName(domain,selector){
|
|
234
|
+
const raw=requiredText(selector,'a DKIM selector',128).trim().toLowerCase();
|
|
235
|
+
if(!raw.split('.').every(x=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(x))) throw new InputError('Enter a DKIM selector using DNS label letters, digits, or hyphens.');
|
|
236
|
+
return hostname(raw+'._domainkey.'+domain,true);
|
|
237
|
+
}
|
|
238
|
+
export async function dkimCheck(values,{query=createDns()}={}){
|
|
239
|
+
const name=dkimName(hostname(values.domain),values.selector);
|
|
240
|
+
const found=reliable(await query(name,'TXT'));
|
|
241
|
+
const list=txtRecords(found,/(?:^|;)\s*(?:v\s*=\s*DKIM1\s*(?:;|$)|p\s*=)/i);
|
|
242
|
+
let status='No DKIM key found', kind='—';
|
|
243
|
+
if(list.length>1)status='Multiple DKIM keys';
|
|
244
|
+
if(list.length===1){
|
|
245
|
+
const {output,duplicates,malformed}=tags(list[0]);
|
|
246
|
+
kind=output.get('k')??'rsa';
|
|
247
|
+
let key=output.get('p');
|
|
248
|
+
if(duplicates.length||malformed.length||key===undefined||(output.has('v')&&output.get('v')!=='DKIM1'))status='Malformed DKIM key record';
|
|
249
|
+
else if(!key.trim())status='Key revoked';
|
|
250
|
+
else {
|
|
251
|
+
key=key.replace(/\s/g,'');
|
|
252
|
+
try{
|
|
253
|
+
const bytes=Uint8Array.from(atob(key),x=>x.charCodeAt(0));
|
|
254
|
+
if(kind==='ed25519'&&bytes.length===32)status='Ed25519 key found';
|
|
255
|
+
else if(kind==='rsa'){
|
|
256
|
+
const algorithm={name:'RSASSA-PKCS1-v1_5',hash:'SHA-256'};
|
|
257
|
+
const imported=await crypto.subtle.importKey('spki',bytes,algorithm,false,['verify']);
|
|
258
|
+
status=imported.algorithm.modulusLength<1024?'RSA key is shorter than 1024 bits':`RSA ${imported.algorithm.modulusLength}-bit key found`;
|
|
259
|
+
}else status='Unsupported or invalid key type';
|
|
260
|
+
}catch{status='Public key could not be parsed';}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return modelResult([['Finding',status],['Public key type',kind],['DNS name',name]],{text:list.length===1?list[0]:undefined,table:recordsTable(found.all),notes:['This reads the public DNS key. A valid key alone does not verify that an email was signed by the matching private key.']});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export async function domainHealth(values,{query=createDns()}={}){
|
|
267
|
+
const domain=hostname(values.domain);
|
|
268
|
+
const selector=String(values.selector??'').trim();
|
|
269
|
+
if(selector)dkimName(domain,selector);
|
|
270
|
+
const runs=[['MX routing',()=>mxLookup({domain},{query})],['SPF policy',()=>spfCheck({domain},{query})],['DMARC policy',()=>dmarcCheck({domain},{query})]];
|
|
271
|
+
if(selector)runs.push(['DKIM selector',()=>dkimCheck({domain,selector},{query})]);
|
|
272
|
+
const results=await Promise.allSettled(runs.map(([,run])=>run()));
|
|
273
|
+
const rows=results.map((item,i)=>{
|
|
274
|
+
const response=item.status==='fulfilled'?item.value:null;
|
|
275
|
+
const metrics=new Map(response?.metrics??[]);
|
|
276
|
+
return [runs[i][0],metrics.get('Finding')??metrics.get('Routing status')??'Unavailable',metrics.get('Published at')??metrics.get('DNS name')??response?.notes?.[0]??'Try the individual checker.'];
|
|
277
|
+
});
|
|
278
|
+
if(!selector)rows.push(['DKIM selector','Not checked','Enter the selector from your email provider or the s= value in a DKIM-Signature header.']);
|
|
279
|
+
return modelResult([['Domain',domain],['Checks completed',String(results.filter(x=>x.status==='fulfilled').length)],['Checks unavailable',String(results.filter(x=>x.status==='rejected').length)]],{table:{columns:['Check','Finding','Next detail'],rows},notes:['These are public configuration checks. A sample email header is needed to see what a receiving server actually reported.']});
|
|
280
|
+
}
|
package/assets/lists.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import {InputError,parseCSV,columnIndex,keyFor,emailFormat,asciiDomain,requiredText,textList,
|
|
2
|
+
showInteger as whole,showPercent as percent,ratio,csvDownload,modelResult as result} from './common.js';
|
|
3
|
+
|
|
4
|
+
function sampleTable(columns,rows) {
|
|
5
|
+
return {columns,rows:rows.slice(0,40),total:rows.length};
|
|
6
|
+
}
|
|
7
|
+
const count=(label,list)=>[label,whole(list.length)];
|
|
8
|
+
const EMPTY = '—';
|
|
9
|
+
|
|
10
|
+
export function preflight(input) {
|
|
11
|
+
const file=parseCSV(input.csv,{loose:true});
|
|
12
|
+
const required=[...new Set(textList(input.required_columns).map(x=>x.toLowerCase()))];
|
|
13
|
+
const missing=required.filter(name=>!file.columns.some(column=>column.toLowerCase()===name));
|
|
14
|
+
const requiredIndices=required.filter(name=>!missing.includes(name)).map(name=>columnIndex(file.columns,name));
|
|
15
|
+
const email=columnIndex(file.columns,input.email_column,true);
|
|
16
|
+
const seen=new Set();
|
|
17
|
+
const width=new Set(file.widthIssues.map(row=>row.line));
|
|
18
|
+
const issues=[];
|
|
19
|
+
let fixedWidth=0, blank=0, invalid=0, review=0, duplicates=0;
|
|
20
|
+
for(const row of file.records){
|
|
21
|
+
const list=[];
|
|
22
|
+
if(width.has(row.line)){
|
|
23
|
+
fixedWidth++;
|
|
24
|
+
list.push('Expected '+file.columns.length+' cells; found '+row.cells.length+'.');
|
|
25
|
+
}
|
|
26
|
+
const absent=requiredIndices.filter(i=>!row.cells[i]?.trim()).map(i=>file.columns[i]);
|
|
27
|
+
if(absent.length){blank++;list.push('Missing '+absent.join(', ')+'.');}
|
|
28
|
+
const address=email>=0 ? row.cells[email]?.trim() : '';
|
|
29
|
+
if(address){
|
|
30
|
+
const check=emailFormat(address);
|
|
31
|
+
if(check.status==='Invalid'){invalid++;list.push(check.note);}
|
|
32
|
+
if(check.status==='Review'){review++;list.push(check.note);}
|
|
33
|
+
const key=check.key??keyFor(address);
|
|
34
|
+
if(seen.has(key)){duplicates++;list.push('Repeated address.');}
|
|
35
|
+
seen.add(key);
|
|
36
|
+
}
|
|
37
|
+
if(list.length) issues.push([row.line,address??'',list.join(' ')]);
|
|
38
|
+
}
|
|
39
|
+
const columns=['Source line','Email','What to review'];
|
|
40
|
+
return result([count('Data rows',file.records),count('Rows needing review',issues),count('Missing columns',missing),
|
|
41
|
+
['Wrong-width rows',whole(fixedWidth)],['Blank required fields',whole(blank)],
|
|
42
|
+
['Invalid email formats',whole(invalid)],['Emails to review',whole(review)],['Repeated emails',whole(duplicates)]],{
|
|
43
|
+
table:sampleTable(columns,issues),
|
|
44
|
+
downloads:issues.length ? [csvDownload('csv-preflight-issues.csv',columns,issues)] : [],
|
|
45
|
+
notes:[missing.length ? 'Missing required columns: '+missing.join(', ')+'.' : 'All requested column names are present.',
|
|
46
|
+
'Source lines refer to physical lines in the input, including quoted cells that span lines. Address checks cover format only.']});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function deduplicate(input) {
|
|
50
|
+
const {columns,records}=parseCSV(input.csv);
|
|
51
|
+
const key=columnIndex(columns,input.key_column);
|
|
52
|
+
const strategy=input.keep;
|
|
53
|
+
if(!['first','last','complete'].includes(strategy)) throw new InputError('Choose which duplicate record to keep.');
|
|
54
|
+
const grouped=new Map();
|
|
55
|
+
const retained=new Set();
|
|
56
|
+
let blanks=0;
|
|
57
|
+
for(const record of records){
|
|
58
|
+
const value=keyFor(record.cells[key],input.match_case==='yes');
|
|
59
|
+
if(!value){retained.add(record);blanks++;continue;}
|
|
60
|
+
if(!grouped.has(value)) grouped.set(value,[]);
|
|
61
|
+
grouped.get(value).push(record);
|
|
62
|
+
}
|
|
63
|
+
const filled=row=>row.cells.filter(v=>v.trim()).length;
|
|
64
|
+
const log=[];
|
|
65
|
+
for(const [value,group] of grouped){
|
|
66
|
+
let winner=group[0];
|
|
67
|
+
if(strategy==='last') winner=group.at(-1);
|
|
68
|
+
if(strategy==='complete'){
|
|
69
|
+
let best=filled(winner);
|
|
70
|
+
for(const other of group.slice(1)){
|
|
71
|
+
const score=filled(other);
|
|
72
|
+
if(score>best){winner=other;best=score;}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
retained.add(winner);
|
|
76
|
+
for(const item of group) if(item!==winner) log.push([value,item.line,winner.line]);
|
|
77
|
+
}
|
|
78
|
+
const clean=records.filter(record=>retained.has(record)).map(record=>record.cells);
|
|
79
|
+
const audit=['Matched value','Removed source line','Kept source line'];
|
|
80
|
+
return result([count('Rows before',records),count('Rows after',clean),count('Duplicate rows removed',log),['Blank keys kept',whole(blanks)]],{
|
|
81
|
+
table:sampleTable(audit,log),
|
|
82
|
+
downloads:[csvDownload('deduplicated-contacts.csv',columns,clean),csvDownload('duplicate-audit.csv',audit,log)],
|
|
83
|
+
notes:['Blank keys are kept because they may belong to different people. Ties for the most complete row keep the first record.',
|
|
84
|
+
'Review the kept rows before importing when different records hold different owners or contact preferences.']});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function indexedRows(file,key,matchCase,side) {
|
|
88
|
+
const index=columnIndex(file.columns,key);
|
|
89
|
+
const mapped=new Map();
|
|
90
|
+
for(const record of file.records){
|
|
91
|
+
const value=keyFor(record.cells[index],matchCase);
|
|
92
|
+
if(!value) throw new InputError(side+' has a blank match key at line '+record.line+'.');
|
|
93
|
+
if(mapped.has(value)) throw new InputError(side+' has duplicate match keys at lines '+mapped.get(value).line+' and '+record.line+'. Deduplicate first.');
|
|
94
|
+
mapped.set(value,record);
|
|
95
|
+
}
|
|
96
|
+
return mapped;
|
|
97
|
+
}
|
|
98
|
+
export function compareLists(input) {
|
|
99
|
+
const left=parseCSV(input.old_csv), right=parseCSV(input.new_csv);
|
|
100
|
+
const key=input.key_column, matchCase=input.match_case==='yes';
|
|
101
|
+
const before=indexedRows(left,key,matchCase,'Earlier list');
|
|
102
|
+
const after=indexedRows(right,key,matchCase,'Later list');
|
|
103
|
+
const leftByName=new Map(left.columns.map((column,i)=>[column.toLowerCase(),i]));
|
|
104
|
+
const rightByName=new Map(right.columns.map((column,i)=>[column.toLowerCase(),i]));
|
|
105
|
+
const fields=[...new Set([...leftByName.keys(),...rightByName.keys()])].filter(name=>name!==keyFor(key));
|
|
106
|
+
const addedColumns=right.columns.filter(c=>!leftByName.has(c.toLowerCase()));
|
|
107
|
+
const removedColumns=left.columns.filter(c=>!rightByName.has(c.toLowerCase()));
|
|
108
|
+
const changes=[];
|
|
109
|
+
const details=['Match key','Result','Earlier line','Later line','Changed fields'];
|
|
110
|
+
let created=0,removed=0,edited=0,unchanged=0;
|
|
111
|
+
for(const [value,oldRow] of before){
|
|
112
|
+
const newRow=after.get(value);
|
|
113
|
+
if(!newRow){removed++;changes.push([value,'Missing from later list',oldRow.line,EMPTY,'']);continue;}
|
|
114
|
+
const changed=fields.filter(field=>(oldRow.cells[leftByName.get(field)]??'')!==(newRow.cells[rightByName.get(field)]??''));
|
|
115
|
+
if(changed.length){edited++;changes.push([value,'Changed',oldRow.line,newRow.line,changed.join(', ')]);}
|
|
116
|
+
else unchanged++;
|
|
117
|
+
}
|
|
118
|
+
for(const [value,row] of after) if(!before.has(value)){created++;changes.push([value,'Added',EMPTY,row.line,'']);}
|
|
119
|
+
return result([['Added',whole(created)],['Missing',whole(removed)],['Changed',whole(edited)],['Unchanged',whole(unchanged)]],{
|
|
120
|
+
table:sampleTable(details,changes),
|
|
121
|
+
downloads:[csvDownload('lead-list-changes.csv',details,changes)],
|
|
122
|
+
notes:['Added columns: '+(addedColumns.join(', ')||'none')+'. Removed columns: '+(removedColumns.join(', ')||'none')+'.',
|
|
123
|
+
'Cell values are compared as text. A unique key is required in both lists.']});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function syntaxCheck(input) {
|
|
127
|
+
const raw=requiredText(input.addresses,'one or more email addresses');
|
|
128
|
+
const values=raw.split(/\r\n|\n|\r/).map(v=>v.trim()).filter(Boolean);
|
|
129
|
+
if(values.length>25000) throw new InputError('Check up to 25,000 addresses at once.');
|
|
130
|
+
const rows=values.map(address=>{
|
|
131
|
+
const check=emailFormat(address);
|
|
132
|
+
return [address,check.status,check.note];
|
|
133
|
+
});
|
|
134
|
+
const columns=['Address','Format result','Reason'];
|
|
135
|
+
return result([count('Checked',rows),count('Common format passes',rows.filter(r=>r[1]==='Format looks valid')),
|
|
136
|
+
count('Needs review',rows.filter(r=>r[1]==='Review')),count('Invalid format',rows.filter(r=>r[1]==='Invalid'))],{
|
|
137
|
+
table:sampleTable(columns,rows),downloads:[csvDownload('email-format-results.csv',columns,rows)],
|
|
138
|
+
notes:['A valid-looking format does not confirm that the inbox exists, can receive your message, or is eligible for outreach. Paste one address per line.']});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function suppressionEntries(value,kind) {
|
|
142
|
+
const lines=String(value??'').replace(/^\uFEFF/,'').split(/\r\n|\n|\r/).map(x=>x.trim()).filter(Boolean);
|
|
143
|
+
if(lines[0] && (kind==='email' ? /^(?:email|email address)$/i : /^domain$/i).test(lines[0])) lines.shift();
|
|
144
|
+
if(lines.length>25000) throw new InputError('Review up to 25,000 '+kind+' exclusions at a time.');
|
|
145
|
+
const set=new Set();
|
|
146
|
+
for(const [i,line] of lines.entries()){
|
|
147
|
+
const candidate=kind==='domain' ? asciiDomain(line) : emailFormat(line).key;
|
|
148
|
+
if(!candidate) throw new InputError('Invalid or unsupported '+kind+' exclusion at entry '+(i+1)+'. Correct it before generating an output.');
|
|
149
|
+
set.add(candidate);
|
|
150
|
+
}
|
|
151
|
+
return set;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function suppress(input) {
|
|
155
|
+
const file=parseCSV(input.csv), i=columnIndex(file.columns,input.email_column);
|
|
156
|
+
const emails=suppressionEntries(input.blocked_emails,'email');
|
|
157
|
+
const domains=suppressionEntries(input.blocked_domains,'domain');
|
|
158
|
+
if(!emails.size && !domains.size) throw new InputError('Enter at least one email address or domain to exclude.');
|
|
159
|
+
const includeChildren=input.subdomains==='yes';
|
|
160
|
+
const eligible=[], removed=[], review=[], audit=[];
|
|
161
|
+
for(const row of file.records){
|
|
162
|
+
const address=row.cells[i], check=emailFormat(address);
|
|
163
|
+
if(!check.key){
|
|
164
|
+
review.push(row.cells);
|
|
165
|
+
audit.push([row.line,address,'Review',check.note]);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
let domain=check.domain, domainMatch=domains.has(domain)?domain:'';
|
|
169
|
+
while(includeChildren && !domainMatch && domain.includes('.')){
|
|
170
|
+
domain=domain.slice(domain.indexOf('.')+1);
|
|
171
|
+
if(domains.has(domain)) domainMatch=domain;
|
|
172
|
+
}
|
|
173
|
+
if(emails.has(check.key)||domainMatch){
|
|
174
|
+
removed.push(row.cells);
|
|
175
|
+
audit.push([row.line,address,'Blocked',emails.has(check.key)?'Exact address match':'Excluded domain: '+domainMatch]);
|
|
176
|
+
} else eligible.push(row.cells);
|
|
177
|
+
}
|
|
178
|
+
const auditCols=['Source line','Address','Decision','Why'];
|
|
179
|
+
return result([count('Clear of supplied exclusions',eligible),count('Blocked',removed),count('Needs review',review),
|
|
180
|
+
['Excluded share',percent(ratio(removed.length,file.records.length))]],{
|
|
181
|
+
table:sampleTable(auditCols,audit),
|
|
182
|
+
downloads:[csvDownload('contacts-clear-of-input-rules.csv',file.columns,eligible),
|
|
183
|
+
csvDownload('blocked-contacts.csv',file.columns,removed),csvDownload('contacts-needing-review.csv',file.columns,review),
|
|
184
|
+
csvDownload('suppression-audit.csv',auditCols,audit)],
|
|
185
|
+
notes:['The clear file passed only the rules supplied here. Apply current restrictions and permissions before use.',
|
|
186
|
+
includeChildren?'Domain exclusions cover the domain and its subdomains.':'Domain exclusions match the exact domain.']});
|
|
187
|
+
}
|