proxymail-qa 0.12.0 → 0.13.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/README.md +39 -10
- package/dist/cli-main.d.ts +19 -0
- package/dist/cli-main.js +373 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +27 -0
- package/dist/cypress-methods.d.ts +9 -0
- package/dist/cypress-methods.js +71 -0
- package/dist/cypress-plugin.d.ts +4 -0
- package/dist/cypress-plugin.js +28 -0
- package/dist/cypress.d.ts +32 -0
- package/dist/cypress.js +42 -0
- package/dist/index.d.ts +464 -6
- package/dist/index.js +306 -6
- package/package.json +19 -4
package/dist/index.js
CHANGED
|
@@ -4,20 +4,25 @@
|
|
|
4
4
|
// Playwright, Cypress tasks and other runtimes with fetch.
|
|
5
5
|
// An API error. When a wait finds nothing, hint says why as far as Proxy Mail
|
|
6
6
|
// QA can tell (an email provider in sandbox mode, say) and refused lists any
|
|
7
|
-
// mail it turned away; both are in the message too.
|
|
7
|
+
// mail it turned away; both are in the message too. From 0.13.0, why says
|
|
8
|
+
// which case it is and sharedSender names a platform's built-in sender.
|
|
8
9
|
export class ProxyMailQAError extends Error {
|
|
9
10
|
status;
|
|
10
11
|
code;
|
|
11
12
|
hint;
|
|
12
13
|
refused;
|
|
13
14
|
help;
|
|
14
|
-
|
|
15
|
+
why;
|
|
16
|
+
sharedSender;
|
|
17
|
+
constructor(status, code, message, hint, refused, help, why, sharedSender) {
|
|
15
18
|
super(hint ? `${message} ${hint}` : message);
|
|
16
19
|
this.status = status;
|
|
17
20
|
this.code = code;
|
|
18
21
|
this.hint = hint;
|
|
19
22
|
this.refused = refused;
|
|
20
23
|
this.help = help;
|
|
24
|
+
this.why = why;
|
|
25
|
+
this.sharedSender = sharedSender;
|
|
21
26
|
this.name = 'ProxyMailQAError';
|
|
22
27
|
}
|
|
23
28
|
}
|
|
@@ -86,7 +91,7 @@ export class ProxyMailQA {
|
|
|
86
91
|
return (await response.text());
|
|
87
92
|
const payload = (await response.json().catch(() => ({})));
|
|
88
93
|
if (!response.ok) {
|
|
89
|
-
throw new ProxyMailQAError(response.status, payload.error ?? 'error', payload.message ?? `Request failed with ${response.status}`, payload.hint, payload.refused, payload.help);
|
|
94
|
+
throw new ProxyMailQAError(response.status, payload.error ?? 'error', payload.message ?? `Request failed with ${response.status}`, payload.hint, payload.refused, payload.help, payload.why, payload.shared_sender);
|
|
90
95
|
}
|
|
91
96
|
return payload;
|
|
92
97
|
}
|
|
@@ -109,14 +114,18 @@ export class ProxyMailQA {
|
|
|
109
114
|
// fillUnknownFields (which fields formValues and Proxy Mail QA for Chrome
|
|
110
115
|
// 0.9.0 and later guess) follows the custom fields' rules instead: anyone
|
|
111
116
|
// on the project, unless only leads change them. Change it only when the
|
|
112
|
-
// person asks; for one call, pass guess to formValues.
|
|
117
|
+
// person asks; for one call, pass guess to formValues. fillIdFields (new in
|
|
118
|
+
// 0.13.0) true adds the five ID and tax number ready-made custom fields, or
|
|
119
|
+
// turns on those there, and false turns them off: a lead's key only, and
|
|
120
|
+
// only when the person asks.
|
|
113
121
|
updateProject(patch) {
|
|
114
|
-
const { emailPrefix, mailDomain, fillUnknownFields, ...rest } = patch;
|
|
122
|
+
const { emailPrefix, mailDomain, fillUnknownFields, fillIdFields, ...rest } = patch;
|
|
115
123
|
return this.request('PATCH', '/project', {
|
|
116
124
|
...rest,
|
|
117
125
|
...(emailPrefix !== undefined ? { email_prefix: emailPrefix } : {}),
|
|
118
126
|
...(mailDomain !== undefined ? { mail_domain: mailDomain } : {}),
|
|
119
127
|
...(fillUnknownFields !== undefined ? { fill_unknown_fields: fillUnknownFields } : {}),
|
|
128
|
+
...(fillIdFields !== undefined ? { fill_id_fields: fillIdFields } : {}),
|
|
120
129
|
});
|
|
121
130
|
}
|
|
122
131
|
// The project's custom fields, its guesses setting and whether only leads
|
|
@@ -152,6 +161,64 @@ export class ProxyMailQA {
|
|
|
152
161
|
setStandardField(field, on) {
|
|
153
162
|
return this.request('PATCH', '/project/standard-fields', { field, on });
|
|
154
163
|
}
|
|
164
|
+
// The project's sign-up forms, newest change first (New in 0.13.0).
|
|
165
|
+
signupForms() {
|
|
166
|
+
return this.request('GET', '/project/signup-forms');
|
|
167
|
+
}
|
|
168
|
+
// One sign-up form in full: its spec, the custom fields it needs and how
|
|
169
|
+
// each field gets its value (New in 0.13.0).
|
|
170
|
+
signupForm(id) {
|
|
171
|
+
return this.request('GET', `/project/signup-forms/${encodeURIComponent(id)}`);
|
|
172
|
+
}
|
|
173
|
+
// Saves a sign-up form: a new one, the one with this id, or the one with the
|
|
174
|
+
// same name (New in 0.13.0). It uses a custom field that already fills a
|
|
175
|
+
// field and makes ready-made ones only where nothing does; the answer says
|
|
176
|
+
// what fills each, any clashes and any leftovers, for options.choices and
|
|
177
|
+
// options.tidy on a second save once the person says. Save one only when
|
|
178
|
+
// the person asks. On a project where only leads change custom fields and
|
|
179
|
+
// your key's creator isn't one, it's one request to the leads instead
|
|
180
|
+
// (status 'requested'), and the form waits as a draft.
|
|
181
|
+
saveSignupForm(spec, id, options = {}) {
|
|
182
|
+
return this.request('POST', '/project/signup-forms', {
|
|
183
|
+
spec,
|
|
184
|
+
...(id ? { id } : {}),
|
|
185
|
+
...(options.choices ? { choices: options.choices } : {}),
|
|
186
|
+
...(options.tidy ? { tidy: options.tidy } : {}),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// Removes a sign-up form: whoever made it or a lead (New in 0.13.0). Its
|
|
190
|
+
// custom fields stay, unless removeCustomFields: then they go too, except
|
|
191
|
+
// any another form still uses, and the answer names those removed and kept.
|
|
192
|
+
deleteSignupForm(id, options = {}) {
|
|
193
|
+
const query = options.removeCustomFields ? '?remove_custom_fields=true' : '';
|
|
194
|
+
return this.request('DELETE', `/project/signup-forms/${encodeURIComponent(id)}${query}`);
|
|
195
|
+
}
|
|
196
|
+
// A sign-up form as code to put in your app (New in 0.13.0): each field
|
|
197
|
+
// checks what the spec asks for, with messages in the form's language and
|
|
198
|
+
// the data-testid its custom fields match. format defaults to
|
|
199
|
+
// 'react-hook-form'; requested: true gives the change waiting for a lead.
|
|
200
|
+
signupFormCode(id, options = {}) {
|
|
201
|
+
const query = new URLSearchParams();
|
|
202
|
+
if (options.format)
|
|
203
|
+
query.set('format', options.format);
|
|
204
|
+
if (options.requested)
|
|
205
|
+
query.set('requested', 'true');
|
|
206
|
+
const search = query.toString();
|
|
207
|
+
return this.request('GET', `/project/signup-forms/${encodeURIComponent(id)}/code${search ? `?${search}` : ''}`);
|
|
208
|
+
}
|
|
209
|
+
// Tests for a sign-up form (New in 0.13.0): each field gets values the form
|
|
210
|
+
// should take and ones it should refuse, with every other field filled in
|
|
211
|
+
// from a new test address. framework defaults to 'playwright';
|
|
212
|
+
// requested: true gives the change waiting for a lead.
|
|
213
|
+
signupFormTest(id, options = {}) {
|
|
214
|
+
const query = new URLSearchParams();
|
|
215
|
+
if (options.framework)
|
|
216
|
+
query.set('framework', options.framework);
|
|
217
|
+
if (options.requested)
|
|
218
|
+
query.set('requested', 'true');
|
|
219
|
+
const search = query.toString();
|
|
220
|
+
return this.request('GET', `/project/signup-forms/${encodeURIComponent(id)}/test${search ? `?${search}` : ''}`);
|
|
221
|
+
}
|
|
155
222
|
// The project's sites, each with whether Proxy Mail QA for Chrome 0.9.0 and
|
|
156
223
|
// later fills each screen of its sign-up by itself (multi_step) and its
|
|
157
224
|
// sign-up screens, the native app's screens with no site, and your key's
|
|
@@ -202,6 +269,7 @@ export class ProxyMailQA {
|
|
|
202
269
|
age: input.age,
|
|
203
270
|
date_of_birth: input.dateOfBirth,
|
|
204
271
|
country: input.country,
|
|
272
|
+
one_name: input.oneName,
|
|
205
273
|
site: input.site,
|
|
206
274
|
environment: input.environment,
|
|
207
275
|
});
|
|
@@ -240,12 +308,15 @@ export class ProxyMailQA {
|
|
|
240
308
|
page: options.page,
|
|
241
309
|
screen: options.screen,
|
|
242
310
|
guess: options.guess,
|
|
311
|
+
kyc_sandbox: options.kycSandbox,
|
|
312
|
+
kyc_outcome: options.kycOutcome,
|
|
243
313
|
label: options.label,
|
|
244
314
|
lifetime_days: options.lifetimeDays,
|
|
245
315
|
domain: options.domain,
|
|
246
316
|
age: options.age,
|
|
247
317
|
date_of_birth: options.dateOfBirth,
|
|
248
318
|
country: options.country,
|
|
319
|
+
one_name: options.oneName,
|
|
249
320
|
site: options.site,
|
|
250
321
|
environment: options.environment,
|
|
251
322
|
});
|
|
@@ -292,6 +363,79 @@ export class ProxyMailQA {
|
|
|
292
363
|
}
|
|
293
364
|
// Marks a host (localhost:3000, say) as a dev environment of the project:
|
|
294
365
|
// links to it then pass checkEmail's local-links check instead of failing.
|
|
366
|
+
// An authenticator app's code (TOTP, RFC 6238) for a test account with
|
|
367
|
+
// two-factor sign-in, worked out on this machine from the secret the app
|
|
368
|
+
// showed at set-up (its base32 key, or the otpauth:// address in its QR
|
|
369
|
+
// code). The secret never reaches Proxy Mail QA. The same as the
|
|
370
|
+
// totpCode function; here so a test with a client needs no other import.
|
|
371
|
+
totpCode(secret, options = {}) {
|
|
372
|
+
return totpCode(secret, options);
|
|
373
|
+
}
|
|
374
|
+
// Starters to build a sign-up form from (New in 0.13.0): every one, or one
|
|
375
|
+
// by id, in a language or for a country. Save your version with
|
|
376
|
+
// saveSignupForm.
|
|
377
|
+
signupStarters(options = {}) {
|
|
378
|
+
const q = new URLSearchParams();
|
|
379
|
+
if (options.id)
|
|
380
|
+
q.set('id', options.id);
|
|
381
|
+
if (options.language)
|
|
382
|
+
q.set('language', options.language);
|
|
383
|
+
if (options.country)
|
|
384
|
+
q.set('country', options.country);
|
|
385
|
+
const query = q.toString();
|
|
386
|
+
return this.request('GET', `/signup-starters${query ? `?${query}` : ''}`);
|
|
387
|
+
}
|
|
388
|
+
// The field sections a sign-up form may ask for, by group, with the
|
|
389
|
+
// countries each ID or tax number has formats for (New in 0.13.0).
|
|
390
|
+
// kycSandbox adds that KYC vendor's sandbox values for kycOutcome.
|
|
391
|
+
listFormSections(options = {}) {
|
|
392
|
+
const q = new URLSearchParams();
|
|
393
|
+
if (options.country)
|
|
394
|
+
q.set('country', options.country);
|
|
395
|
+
if (options.group)
|
|
396
|
+
q.set('group', options.group);
|
|
397
|
+
if (options.kycSandbox)
|
|
398
|
+
q.set('kyc_sandbox', options.kycSandbox);
|
|
399
|
+
if (options.kycOutcome)
|
|
400
|
+
q.set('kyc_outcome', options.kycOutcome);
|
|
401
|
+
const query = q.toString();
|
|
402
|
+
return this.request('GET', `/form-sections${query ? `?${query}` : ''}`);
|
|
403
|
+
}
|
|
404
|
+
// One section: for an ID or tax number, its format in a country, a fake
|
|
405
|
+
// value that follows it, and variants. Give address to keep the value the
|
|
406
|
+
// same for that test account (New in 0.13.0).
|
|
407
|
+
getFormSection(id, options = {}) {
|
|
408
|
+
const q = new URLSearchParams();
|
|
409
|
+
if (options.country)
|
|
410
|
+
q.set('country', options.country);
|
|
411
|
+
if (options.address)
|
|
412
|
+
q.set('address', options.address);
|
|
413
|
+
if (options.kycSandbox)
|
|
414
|
+
q.set('kyc_sandbox', options.kycSandbox);
|
|
415
|
+
if (options.kycOutcome)
|
|
416
|
+
q.set('kyc_outcome', options.kycOutcome);
|
|
417
|
+
const query = q.toString();
|
|
418
|
+
return this.request('GET', `/form-sections/${encodeURIComponent(id)}${query ? `?${query}` : ''}`);
|
|
419
|
+
}
|
|
420
|
+
// Whether a value follows a format from getFormSection, worked out here;
|
|
421
|
+
// the same as the followsFormat function (New in 0.13.0).
|
|
422
|
+
followsFormat(format, value) {
|
|
423
|
+
return followsFormat(format, value);
|
|
424
|
+
}
|
|
425
|
+
// The test addresses this project used between from and to, to delete
|
|
426
|
+
// those test users from your app afterwards (New in 0.13.0).
|
|
427
|
+
cleanupList(options = {}) {
|
|
428
|
+
const q = new URLSearchParams();
|
|
429
|
+
const iso = (d) => (d instanceof Date ? d.toISOString() : d);
|
|
430
|
+
if (options.from !== undefined)
|
|
431
|
+
q.set('from', iso(options.from));
|
|
432
|
+
if (options.to !== undefined)
|
|
433
|
+
q.set('to', iso(options.to));
|
|
434
|
+
if (options.site)
|
|
435
|
+
q.set('site', options.site);
|
|
436
|
+
const query = q.toString();
|
|
437
|
+
return this.request('GET', `/cleanup-list${query ? `?${query}` : ''}`);
|
|
438
|
+
}
|
|
295
439
|
markDevHost(host) {
|
|
296
440
|
return this.request('POST', '/project/dev-hosts', { host });
|
|
297
441
|
}
|
|
@@ -473,6 +617,16 @@ export class ProxyMailQA {
|
|
|
473
617
|
deleteAddress(address) {
|
|
474
618
|
return this.request('DELETE', `/addresses/${encodeURIComponent(address)}`);
|
|
475
619
|
}
|
|
620
|
+
// Records that the test has just submitted a form with the address (a
|
|
621
|
+
// sign-up unless flow says otherwise), on site (a page URL, kept as host and
|
|
622
|
+
// path, with any part of the path that has an email address, an ID, a long
|
|
623
|
+
// number or a token in it hidden; never its query or fragment). The time is the
|
|
624
|
+
// server's: the wait that finds the code or link then returns
|
|
625
|
+
// time_to_email. Pass its submitted_at as since. Never send the form's
|
|
626
|
+
// contents.
|
|
627
|
+
markSubmitted(address, options = {}) {
|
|
628
|
+
return this.request('POST', `/addresses/${encodeURIComponent(address)}/submits`, { flow: options.flow, site: options.site });
|
|
629
|
+
}
|
|
476
630
|
// Waits for a verification or login code; throws ProxyMailQAError (404) if
|
|
477
631
|
// none arrives in time.
|
|
478
632
|
// The newest sign-in or verification code; with type: 'coupon', the
|
|
@@ -509,7 +663,8 @@ export class ProxyMailQA {
|
|
|
509
663
|
return this.request('GET', `/addresses/${encodeURIComponent(address)}/count${countQuery(options)}`);
|
|
510
664
|
}
|
|
511
665
|
// Checks one email the address received: SPF, DKIM and DMARC, links to
|
|
512
|
-
// localhost or plain http, where its link goes (expectHost)
|
|
666
|
+
// localhost or plain http, where its link goes (expectHost) and whether
|
|
667
|
+
// it goes back to the site the test started on (link_site), a stated
|
|
513
668
|
// expiry, a plain-text part, size and image-only emails, and given phrases
|
|
514
669
|
// (expectText) and its language (expectLanguage). Doesn't wait: wait for
|
|
515
670
|
// the email first. Throws ProxyMailQAError (404) when none matches.
|
|
@@ -519,6 +674,8 @@ export class ProxyMailQA {
|
|
|
519
674
|
extra.email_id = options.emailId;
|
|
520
675
|
if (options.expectHost)
|
|
521
676
|
extra.expect_host = options.expectHost;
|
|
677
|
+
if (options.expectSite)
|
|
678
|
+
extra.expect_site = options.expectSite;
|
|
522
679
|
if (options.expectLanguage)
|
|
523
680
|
extra.expect_language = options.expectLanguage;
|
|
524
681
|
if (options.expectWithin !== undefined)
|
|
@@ -656,6 +813,12 @@ export class ProxyMailQA {
|
|
|
656
813
|
const suffix = query.size ? `?${query}` : '';
|
|
657
814
|
return this.request('GET', `/variants/passwords${suffix}`);
|
|
658
815
|
}
|
|
816
|
+
// The checks to run on a sign-up, password reset or magic-link flow: a
|
|
817
|
+
// code working once, only the newest reset link working, a second person
|
|
818
|
+
// unable to see the first one's data. Each has steps, what to expect and why.
|
|
819
|
+
flowChecks(flow) {
|
|
820
|
+
return this.request('GET', `/flow-checks?flow=${encodeURIComponent(flow)}`);
|
|
821
|
+
}
|
|
659
822
|
setPassword(address, options = {}) {
|
|
660
823
|
return this.request('PUT', `/addresses/${encodeURIComponent(address)}/password`, { password: options.password, label: options.label });
|
|
661
824
|
}
|
|
@@ -737,6 +900,8 @@ export class ProxyMailQA {
|
|
|
737
900
|
query.set('app', String(app));
|
|
738
901
|
if (options.unused)
|
|
739
902
|
query.set('unused', 'true');
|
|
903
|
+
if (options.expectSite)
|
|
904
|
+
query.set('expect_site', options.expectSite);
|
|
740
905
|
const more = Date.now() + left * 1000 < deadline - 500;
|
|
741
906
|
try {
|
|
742
907
|
return await this.request('GET', `/addresses/${encodeURIComponent(address)}/${kind}?${query}`, undefined, more);
|
|
@@ -758,3 +923,138 @@ function age(dateOfBirth) {
|
|
|
758
923
|
const now = new Date();
|
|
759
924
|
return now.getUTCFullYear() - y - (now.getUTCMonth() + 1 < m || (now.getUTCMonth() + 1 === m && now.getUTCDate() < d) ? 1 : 0);
|
|
760
925
|
}
|
|
926
|
+
const BASE32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
927
|
+
function base32Bytes(secret) {
|
|
928
|
+
const clean = secret.replace(/[\s-]/g, '').replace(/=+$/, '').toUpperCase();
|
|
929
|
+
if (!clean)
|
|
930
|
+
throw new Error('The TOTP secret is empty.');
|
|
931
|
+
let bits = 0;
|
|
932
|
+
let value = 0;
|
|
933
|
+
const out = [];
|
|
934
|
+
for (const char of clean) {
|
|
935
|
+
const index = BASE32.indexOf(char);
|
|
936
|
+
if (index < 0)
|
|
937
|
+
throw new Error('The TOTP secret must be base32 (A to Z and 2 to 7), as the app shows it, or its otpauth:// address.');
|
|
938
|
+
value = (value << 5) | index;
|
|
939
|
+
bits += 5;
|
|
940
|
+
if (bits >= 8) {
|
|
941
|
+
out.push((value >>> (bits - 8)) & 0xff);
|
|
942
|
+
bits -= 8;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return new Uint8Array(out);
|
|
946
|
+
}
|
|
947
|
+
// The secret and any digits, period and algorithm an otpauth:// address gives.
|
|
948
|
+
function readTotpSecret(secret) {
|
|
949
|
+
if (!/^otpauth:\/\//i.test(secret.trim()))
|
|
950
|
+
return { key: secret };
|
|
951
|
+
const url = new URL(secret.trim());
|
|
952
|
+
if (url.hostname.toLowerCase() !== 'totp')
|
|
953
|
+
throw new Error('Only otpauth://totp/ addresses are time-based codes.');
|
|
954
|
+
const key = url.searchParams.get('secret');
|
|
955
|
+
if (!key)
|
|
956
|
+
throw new Error('The otpauth:// address has no secret.');
|
|
957
|
+
const algorithm = url.searchParams.get('algorithm')?.toUpperCase().replace(/^SHA(\d)/, 'SHA-$1');
|
|
958
|
+
const number = (name) => (url.searchParams.has(name) ? Number(url.searchParams.get(name)) : undefined);
|
|
959
|
+
return { key, digits: number('digits'), period: number('period'), algorithm };
|
|
960
|
+
}
|
|
961
|
+
async function hmac(algorithm, key, message) {
|
|
962
|
+
// Node 18 has Web Crypto only through node:crypto.
|
|
963
|
+
const subtle = globalThis.crypto?.subtle ?? (await import(/* @vite-ignore */ 'node:crypto')).webcrypto.subtle;
|
|
964
|
+
const cryptoKey = await subtle.importKey('raw', key, { name: 'HMAC', hash: algorithm }, false, ['sign']);
|
|
965
|
+
return new Uint8Array(await subtle.sign('HMAC', cryptoKey, message));
|
|
966
|
+
}
|
|
967
|
+
export async function totpCode(secret, options = {}) {
|
|
968
|
+
const given = readTotpSecret(secret);
|
|
969
|
+
const digits = options.digits ?? given.digits ?? 6;
|
|
970
|
+
const period = options.period ?? given.period ?? 30;
|
|
971
|
+
const algorithm = options.algorithm ?? given.algorithm ?? 'SHA-1';
|
|
972
|
+
if (!Number.isInteger(digits) || digits < 6 || digits > 10)
|
|
973
|
+
throw new Error('digits must be a whole number from 6 to 10.');
|
|
974
|
+
if (!Number.isInteger(period) || period < 1)
|
|
975
|
+
throw new Error('period must be a whole number of seconds.');
|
|
976
|
+
if (!['SHA-1', 'SHA-256', 'SHA-512'].includes(algorithm))
|
|
977
|
+
throw new Error('algorithm must be SHA-1, SHA-256 or SHA-512.');
|
|
978
|
+
const key = base32Bytes(given.key);
|
|
979
|
+
let ms = options.at === undefined ? Date.now() : options.at instanceof Date ? options.at.getTime() : options.at;
|
|
980
|
+
if (options.at === undefined && options.minSecondsLeft) {
|
|
981
|
+
const left = period - ((ms / 1000) % period);
|
|
982
|
+
if (left < Math.min(options.minSecondsLeft, period)) {
|
|
983
|
+
await new Promise((resolve) => setTimeout(resolve, Math.ceil(left * 1000) + 50));
|
|
984
|
+
ms = Date.now();
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
const counter = Math.floor(ms / 1000 / period);
|
|
988
|
+
const message = new Uint8Array(8);
|
|
989
|
+
new DataView(message.buffer).setBigUint64(0, BigInt(counter));
|
|
990
|
+
const mac = await hmac(algorithm, key, message);
|
|
991
|
+
const offset = mac[mac.length - 1] & 0x0f;
|
|
992
|
+
const binary = ((mac[offset] & 0x7f) << 24) | (mac[offset + 1] << 16) | (mac[offset + 2] << 8) | mac[offset + 3];
|
|
993
|
+
return String(binary % 10 ** digits).padStart(digits, '0');
|
|
994
|
+
}
|
|
995
|
+
// Whether a value follows a format from getFormSection: its shape and, where
|
|
996
|
+
// there is one, its check digit. It runs here, so an ID never leaves this
|
|
997
|
+
// machine. Following the format isn't being valid: only the issuer knows
|
|
998
|
+
// whether a number was given to anyone (New in 0.13.0).
|
|
999
|
+
export function followsFormat(format, value) {
|
|
1000
|
+
const compact = value.normalize('NFKC').toUpperCase().replace(/[\s.\-/]/g, '');
|
|
1001
|
+
if (!new RegExp(format.pattern).test(compact))
|
|
1002
|
+
return { follows: false, problem: `It doesn’t have the shape${format.shape ? ` (${format.shape})` : ''}.` };
|
|
1003
|
+
if (format.check && !FORMAT_CHECKS[format.check](compact))
|
|
1004
|
+
return { follows: false, problem: 'Its check digit is wrong.' };
|
|
1005
|
+
return { follows: true };
|
|
1006
|
+
}
|
|
1007
|
+
const numbers = (value) => [...value].map(Number);
|
|
1008
|
+
const VERHOEFF_D = [
|
|
1009
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
|
|
1010
|
+
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
|
|
1011
|
+
];
|
|
1012
|
+
const VERHOEFF_P = [
|
|
1013
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
|
|
1014
|
+
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 8, 5],
|
|
1015
|
+
];
|
|
1016
|
+
const mod11 = (value) => {
|
|
1017
|
+
const sum = numbers(value).reduce((total, n, i) => total + n * (value.length + 1 - i), 0);
|
|
1018
|
+
const r = (sum * 10) % 11;
|
|
1019
|
+
return String(r === 10 ? 0 : r);
|
|
1020
|
+
};
|
|
1021
|
+
const cnpjDigit = (value) => {
|
|
1022
|
+
let sum = 0;
|
|
1023
|
+
[...value].reverse().forEach((char, i) => (sum += (char.charCodeAt(0) - 48) * (2 + (i % 8))));
|
|
1024
|
+
const r = sum % 11;
|
|
1025
|
+
return String(r < 2 ? 0 : 11 - r);
|
|
1026
|
+
};
|
|
1027
|
+
const icao = (value) => {
|
|
1028
|
+
let sum = 0;
|
|
1029
|
+
[...value].forEach((char, i) => (sum += (char === '<' ? 0 : /\d/.test(char) ? Number(char) : char.charCodeAt(0) - 55) * [7, 3, 1][i % 3]));
|
|
1030
|
+
return String(sum % 10);
|
|
1031
|
+
};
|
|
1032
|
+
const FORMAT_CHECKS = {
|
|
1033
|
+
verhoeff: (value) => {
|
|
1034
|
+
let c = 0;
|
|
1035
|
+
numbers(value)
|
|
1036
|
+
.reverse()
|
|
1037
|
+
.forEach((n, i) => (c = VERHOEFF_D[c][VERHOEFF_P[i % 8][n]]));
|
|
1038
|
+
return c === 0;
|
|
1039
|
+
},
|
|
1040
|
+
cpf: (value) => {
|
|
1041
|
+
const first = mod11(value.slice(0, 9));
|
|
1042
|
+
return value.slice(9) === first + mod11(value.slice(0, 9) + first);
|
|
1043
|
+
},
|
|
1044
|
+
cnpj: (value) => {
|
|
1045
|
+
const first = cnpjDigit(value.slice(0, 12));
|
|
1046
|
+
return value.slice(12) === first + cnpjDigit(value.slice(0, 12) + first);
|
|
1047
|
+
},
|
|
1048
|
+
gb11643: (value) => value.slice(-1) === '10X98765432'[numbers(value.slice(0, 17)).reduce((total, n, i) => total + n * [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2][i], 0) % 11],
|
|
1049
|
+
my_number: (value) => {
|
|
1050
|
+
const r = numbers(value.slice(0, 11)).reverse().reduce((total, n, i) => total + n * (i < 6 ? i + 2 : i - 4), 0) % 11;
|
|
1051
|
+
return value.slice(-1) === String(r <= 1 ? 0 : 11 - r);
|
|
1052
|
+
},
|
|
1053
|
+
abn: (value) => numbers(value).reduce((total, n, i) => total + (i === 0 ? n - 1 : n) * [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19][i], 0) % 89 === 0,
|
|
1054
|
+
gb_vat: (value) => {
|
|
1055
|
+
const nine = value.replace(/^GB/, '');
|
|
1056
|
+
const sum = numbers(nine.slice(0, 7)).reduce((total, n, i) => total + n * (8 - i), 0) + Number(nine.slice(7, 9));
|
|
1057
|
+
return sum % 97 === 0 || (sum + 55) % 97 === 0;
|
|
1058
|
+
},
|
|
1059
|
+
icao: (value) => value.slice(-1) === icao(value.slice(0, -1)),
|
|
1060
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proxymail-qa",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Test every email your app sends from Playwright, Cypress, Jest, Vitest
|
|
3
|
+
"version": "0.13.0",
|
|
4
|
+
"description": "Test every email your app sends from Playwright, Cypress, Jest, Vitest, any Node script or the command line: disposable inboxes, sign-up codes, links and coupons, email checks, unsubscribe tests and run reports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Proxy Mail QA <hello@proxymail.qa> (https://proxymail.qa)",
|
|
7
7
|
"homepage": "https://proxymail.qa/docs/node",
|
|
@@ -32,11 +32,16 @@
|
|
|
32
32
|
"coupon",
|
|
33
33
|
"unsubscribe",
|
|
34
34
|
"marketing email",
|
|
35
|
-
"qa"
|
|
35
|
+
"qa",
|
|
36
|
+
"cli",
|
|
37
|
+
"cypress commands"
|
|
36
38
|
],
|
|
37
39
|
"type": "module",
|
|
38
40
|
"main": "./dist/index.js",
|
|
39
41
|
"types": "./dist/index.d.ts",
|
|
42
|
+
"bin": {
|
|
43
|
+
"proxymail-qa": "./dist/cli.js"
|
|
44
|
+
},
|
|
40
45
|
"exports": {
|
|
41
46
|
".": {
|
|
42
47
|
"types": "./dist/index.d.ts",
|
|
@@ -49,6 +54,14 @@
|
|
|
49
54
|
"./playwright/reporter": {
|
|
50
55
|
"types": "./dist/playwright-reporter.d.ts",
|
|
51
56
|
"default": "./dist/playwright-reporter.js"
|
|
57
|
+
},
|
|
58
|
+
"./cypress": {
|
|
59
|
+
"types": "./dist/cypress.d.ts",
|
|
60
|
+
"default": "./dist/cypress.js"
|
|
61
|
+
},
|
|
62
|
+
"./cypress/plugin": {
|
|
63
|
+
"types": "./dist/cypress-plugin.d.ts",
|
|
64
|
+
"default": "./dist/cypress-plugin.js"
|
|
52
65
|
}
|
|
53
66
|
},
|
|
54
67
|
"files": [
|
|
@@ -56,7 +69,9 @@
|
|
|
56
69
|
"README.md",
|
|
57
70
|
"LICENSE"
|
|
58
71
|
],
|
|
59
|
-
"sideEffects":
|
|
72
|
+
"sideEffects": [
|
|
73
|
+
"./dist/cypress.js"
|
|
74
|
+
],
|
|
60
75
|
"engines": {
|
|
61
76
|
"node": ">=18"
|
|
62
77
|
},
|