@emailverifier/sdk 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.roleLocalParts = void 0;
4
+ exports.roleLocalParts = new Set([
5
+ 'abuse',
6
+ 'access',
7
+ 'account',
8
+ 'accounting',
9
+ 'accounts',
10
+ 'ap',
11
+ 'accountspayable',
12
+ 'accountsreceivable',
13
+ 'ar',
14
+ 'affiliate',
15
+ 'affiliates',
16
+ 'ambassador',
17
+ 'ambassadors',
18
+ 'admin',
19
+ 'adminteam',
20
+ 'administration',
21
+ 'ads',
22
+ 'advertising',
23
+ 'academy',
24
+ 'alerts',
25
+ 'all',
26
+ 'api',
27
+ 'appointments',
28
+ 'autoreply',
29
+ 'autoresponder',
30
+ 'automated',
31
+ 'automation',
32
+ 'audit',
33
+ 'benefits',
34
+ 'beta',
35
+ 'betatest',
36
+ 'betatesters',
37
+ 'billing',
38
+ 'bursar',
39
+ 'bizdev',
40
+ 'bookings',
41
+ 'businessdevelopment',
42
+ 'campaigns',
43
+ 'bounce',
44
+ 'bounces',
45
+ 'brand',
46
+ 'branding',
47
+ 'careers',
48
+ 'channel',
49
+ 'clients',
50
+ 'clientcare',
51
+ 'clientrelations',
52
+ 'clientservice',
53
+ 'clientservices',
54
+ 'clientsuccess',
55
+ 'chargebacks',
56
+ 'claims',
57
+ 'collections',
58
+ 'compliance',
59
+ 'complianceteam',
60
+ 'contact',
61
+ 'contactus',
62
+ 'contract',
63
+ 'contracting',
64
+ 'contracts',
65
+ 'community',
66
+ 'communications',
67
+ 'comms',
68
+ 'content',
69
+ 'concierge',
70
+ 'controller',
71
+ 'counsel',
72
+ 'ceo',
73
+ 'cfo',
74
+ 'coo',
75
+ 'creator',
76
+ 'creators',
77
+ 'cto',
78
+ 'customercare',
79
+ 'customerengagement',
80
+ 'customerhelp',
81
+ 'customersupport',
82
+ 'customerservice',
83
+ 'customersuccess',
84
+ 'customerexperience',
85
+ 'customerrelations',
86
+ 'cx',
87
+ 'data',
88
+ 'dataprotection',
89
+ 'deliverability',
90
+ 'delivery',
91
+ 'dispatch',
92
+ 'disputes',
93
+ 'admissions',
94
+ 'alumni',
95
+ 'developers',
96
+ 'devops',
97
+ 'dns',
98
+ 'donations',
99
+ 'donotreply',
100
+ 'donotrespond',
101
+ 'dpo',
102
+ 'editor',
103
+ 'editorial',
104
+ 'email',
105
+ 'enablement',
106
+ 'engineering',
107
+ 'enquiries',
108
+ 'enquiry',
109
+ 'ecommerce',
110
+ 'escalation',
111
+ 'escalations',
112
+ 'events',
113
+ 'everyone',
114
+ 'facilities',
115
+ 'financialaid',
116
+ 'fulfillment',
117
+ 'finance',
118
+ 'founder',
119
+ 'founders',
120
+ 'feedback',
121
+ 'fundraising',
122
+ 'giving',
123
+ 'grant',
124
+ 'grants',
125
+ 'fraud',
126
+ 'frontdesk',
127
+ 'gdpr',
128
+ 'growth',
129
+ 'hello',
130
+ 'help',
131
+ 'helpcenter',
132
+ 'helpdesk',
133
+ 'hostmaster',
134
+ 'hr',
135
+ 'identity',
136
+ 'info',
137
+ 'invoices',
138
+ 'insurance',
139
+ 'infosec',
140
+ 'incident',
141
+ 'incidentresponse',
142
+ 'incidents',
143
+ 'inventory',
144
+ 'investorrelations',
145
+ 'investors',
146
+ 'it',
147
+ 'jobs',
148
+ 'legal',
149
+ 'legalteam',
150
+ 'leasing',
151
+ 'leadership',
152
+ 'learning',
153
+ 'leads',
154
+ 'licensing',
155
+ 'list',
156
+ 'mailinglist',
157
+ 'login',
158
+ 'logistics',
159
+ 'mail',
160
+ 'mailerdaemon',
161
+ 'management',
162
+ 'marketing',
163
+ 'media',
164
+ 'medicalrecords',
165
+ 'memberservices',
166
+ 'messages',
167
+ 'network',
168
+ 'newsletter',
169
+ 'noc',
170
+ 'noreply',
171
+ 'no-reply',
172
+ 'noresponse',
173
+ 'notifications',
174
+ 'office',
175
+ 'officeadmin',
176
+ 'onboarding',
177
+ 'onboardingteam',
178
+ 'operations',
179
+ 'ops',
180
+ 'orders',
181
+ 'owner',
182
+ 'partners',
183
+ 'partnerships',
184
+ 'payments',
185
+ 'payables',
186
+ 'patients',
187
+ 'people',
188
+ 'peopleops',
189
+ 'payroll',
190
+ 'paralegal',
191
+ 'preferencecenter',
192
+ 'preferences',
193
+ 'podcast',
194
+ 'postmaster',
195
+ 'press',
196
+ 'product',
197
+ 'productfeedback',
198
+ 'privacy',
199
+ 'privacyteam',
200
+ 'procurement',
201
+ 'promotions',
202
+ 'purchasing',
203
+ 'propertymanagement',
204
+ 'pr',
205
+ 'quotes',
206
+ 'qa',
207
+ 'quality',
208
+ 'qualityassurance',
209
+ 'r&d',
210
+ 'recruiting',
211
+ 'registrar',
212
+ 'research',
213
+ 'researchteam',
214
+ 'reply',
215
+ 'replyto',
216
+ 'referrals',
217
+ 'repairs',
218
+ 'reservations',
219
+ 'receipts',
220
+ 'records',
221
+ 'reception',
222
+ 'receptiondesk',
223
+ 'receivables',
224
+ 'refunds',
225
+ 'resellers',
226
+ 'reliability',
227
+ 'renewal',
228
+ 'renewals',
229
+ 'retail',
230
+ 'risk',
231
+ 'returns',
232
+ 'rentals',
233
+ 'sales',
234
+ 'salesteam',
235
+ 'salesops',
236
+ 'scheduling',
237
+ 'scholarship',
238
+ 'scholarships',
239
+ 'security',
240
+ 'securityalerts',
241
+ 'securityteam',
242
+ 'service',
243
+ 'servicedesk',
244
+ 'shipping',
245
+ 'social',
246
+ 'socialmedia',
247
+ 'sponsorship',
248
+ 'sponsorships',
249
+ 'staff',
250
+ 'status',
251
+ 'store',
252
+ 'subscriptions',
253
+ 'success',
254
+ 'support',
255
+ 'supportdesk',
256
+ 'supportteam',
257
+ 'supplychain',
258
+ 'sysadmin',
259
+ 'system',
260
+ 'soc2',
261
+ 'talent',
262
+ 'team',
263
+ 'test',
264
+ 'testing',
265
+ 'technicalsupport',
266
+ 'techsupport',
267
+ 'trust',
268
+ 'trustandsafety',
269
+ 'trustsafety',
270
+ 'transactional',
271
+ 'training',
272
+ 'trials',
273
+ 'updates',
274
+ 'uptime',
275
+ 'unsubscribe',
276
+ 'userresearch',
277
+ 'vendor',
278
+ 'vendors',
279
+ 'vip',
280
+ 'vipsupport',
281
+ 'warehouse',
282
+ 'uxresearch',
283
+ 'verification',
284
+ 'verify',
285
+ 'volunteer',
286
+ 'volunteers',
287
+ 'webinar',
288
+ 'webinars',
289
+ 'workshops',
290
+ 'webmaster',
291
+ 'workplace'
292
+ ]);
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ import { EmailVerifier } from './client.js';
3
+ import { analyzeEmail } from './offline.js';
4
+ const help = `emailverifier
5
+
6
+ Usage:
7
+ emailverifier check <email> [--json]
8
+ emailverifier verify <email> [--json]
9
+ emailverifier domain <domain> [--json]
10
+ emailverifier usage [--json]
11
+
12
+ check runs locally without network access. verify, domain, and usage require
13
+ EMAILVERIFIER_API_KEY. They never read an API key from a command-line argument.`;
14
+ function fail(message) {
15
+ console.error(message);
16
+ process.exit(1);
17
+ }
18
+ function print(value, compact) {
19
+ console.log(JSON.stringify(value, null, compact ? 0 : 2));
20
+ }
21
+ async function run() {
22
+ const args = process.argv.slice(2);
23
+ const json = args.includes('--json');
24
+ const positional = args.filter(arg => arg !== '--json');
25
+ const [command, value, ...extra] = positional;
26
+ if (!command || command === '--help' || command === '-h') {
27
+ console.log(help);
28
+ return;
29
+ }
30
+ if (extra.length)
31
+ fail('Too many arguments. Run emailverifier --help for usage.');
32
+ if (command === 'check') {
33
+ if (!value)
34
+ fail('An email address is required.');
35
+ print(analyzeEmail(value), json);
36
+ return;
37
+ }
38
+ const apiKey = process.env.EMAILVERIFIER_API_KEY;
39
+ if (!apiKey)
40
+ fail('EMAILVERIFIER_API_KEY is required for remote commands.');
41
+ const client = new EmailVerifier({
42
+ apiKey,
43
+ baseUrl: process.env.EMAILVERIFIER_BASE_URL
44
+ });
45
+ if (command === 'verify') {
46
+ if (!value)
47
+ fail('An email address is required.');
48
+ print(await client.verify(value), json);
49
+ return;
50
+ }
51
+ if (command === 'domain') {
52
+ if (!value)
53
+ fail('A domain is required.');
54
+ print(await client.checkDomain(value), json);
55
+ return;
56
+ }
57
+ if (command === 'usage') {
58
+ if (value)
59
+ fail('The usage command does not accept an argument.');
60
+ print(await client.getUsage(), json);
61
+ return;
62
+ }
63
+ fail(`Unknown command: ${command}`);
64
+ }
65
+ run().catch((error) => {
66
+ fail(error instanceof Error ? error.message : 'The command failed.');
67
+ });
@@ -0,0 +1,71 @@
1
+ export class EmailVerifierError extends Error {
2
+ status;
3
+ response;
4
+ constructor(message, status, response) {
5
+ super(message);
6
+ this.name = 'EmailVerifierError';
7
+ this.status = status;
8
+ this.response = response;
9
+ }
10
+ }
11
+ export class EmailVerifier {
12
+ #apiKey;
13
+ #baseUrl;
14
+ constructor(options) {
15
+ if (!options?.apiKey?.trim())
16
+ throw new TypeError('EmailVerifier requires an API key.');
17
+ this.#apiKey = options.apiKey.trim();
18
+ this.#baseUrl = (options.baseUrl ?? 'https://emailverifier.dev').replace(/\/+$/, '');
19
+ const url = new URL(this.#baseUrl);
20
+ if (url.protocol !== 'https:' && url.hostname !== 'localhost' && url.hostname !== '127.0.0.1') {
21
+ throw new TypeError('EmailVerifier baseUrl must use HTTPS unless it points to localhost.');
22
+ }
23
+ }
24
+ verify(email, options) {
25
+ return this.#request('/api/v1/verify', {
26
+ method: 'POST',
27
+ body: JSON.stringify({ email }),
28
+ signal: options?.signal
29
+ });
30
+ }
31
+ checkDomain(domain, options) {
32
+ return this.#request(`/api/v1/domains/${encodeURIComponent(domain)}`, {
33
+ method: 'GET',
34
+ signal: options?.signal
35
+ });
36
+ }
37
+ getUsage(options) {
38
+ return this.#request('/api/v1/usage', {
39
+ method: 'GET',
40
+ signal: options?.signal
41
+ });
42
+ }
43
+ async #request(path, init) {
44
+ const response = await fetch(`${this.#baseUrl}${path}`, {
45
+ ...init,
46
+ headers: {
47
+ accept: 'application/json',
48
+ 'content-type': 'application/json',
49
+ 'x-api-key': this.#apiKey
50
+ }
51
+ });
52
+ const text = await response.text();
53
+ let body = null;
54
+ if (text) {
55
+ try {
56
+ body = JSON.parse(text);
57
+ }
58
+ catch {
59
+ body = text;
60
+ }
61
+ }
62
+ if (!response.ok) {
63
+ const message = body && typeof body === 'object' && 'statusMessage' in body
64
+ && typeof body.statusMessage === 'string'
65
+ ? body.statusMessage
66
+ : `emailverifier.dev returned HTTP ${response.status}.`;
67
+ throw new EmailVerifierError(message, response.status, body);
68
+ }
69
+ return body;
70
+ }
71
+ }