proxymail-qa 0.12.0 → 0.14.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 +41 -11
- 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 +72 -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 +580 -6
- package/dist/index.js +333 -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,105 @@ 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, given only where one can never be a real person's, and
|
|
406
|
+
// variants. Give address to keep the value the same for that test account
|
|
407
|
+
// (New in 0.13.0).
|
|
408
|
+
getFormSection(id, options = {}) {
|
|
409
|
+
const q = new URLSearchParams();
|
|
410
|
+
if (options.country)
|
|
411
|
+
q.set('country', options.country);
|
|
412
|
+
if (options.address)
|
|
413
|
+
q.set('address', options.address);
|
|
414
|
+
if (options.kycSandbox)
|
|
415
|
+
q.set('kyc_sandbox', options.kycSandbox);
|
|
416
|
+
if (options.kycOutcome)
|
|
417
|
+
q.set('kyc_outcome', options.kycOutcome);
|
|
418
|
+
const query = q.toString();
|
|
419
|
+
return this.request('GET', `/form-sections/${encodeURIComponent(id)}${query ? `?${query}` : ''}`);
|
|
420
|
+
}
|
|
421
|
+
// Whether a value follows a format from getFormSection, worked out here;
|
|
422
|
+
// the same as the followsFormat function (New in 0.13.0).
|
|
423
|
+
followsFormat(format, value) {
|
|
424
|
+
return followsFormat(format, value);
|
|
425
|
+
}
|
|
426
|
+
// The test addresses this project used between from and to, to delete
|
|
427
|
+
// those test users from your app afterwards (New in 0.13.0).
|
|
428
|
+
cleanupList(options = {}) {
|
|
429
|
+
const q = new URLSearchParams();
|
|
430
|
+
const iso = (d) => (d instanceof Date ? d.toISOString() : d);
|
|
431
|
+
if (options.from !== undefined)
|
|
432
|
+
q.set('from', iso(options.from));
|
|
433
|
+
if (options.to !== undefined)
|
|
434
|
+
q.set('to', iso(options.to));
|
|
435
|
+
if (options.site)
|
|
436
|
+
q.set('site', options.site);
|
|
437
|
+
const query = q.toString();
|
|
438
|
+
return this.request('GET', `/cleanup-list${query ? `?${query}` : ''}`);
|
|
439
|
+
}
|
|
440
|
+
// A site's journey, as the Journeys page draws it, for all the project's
|
|
441
|
+
// test accounts or the ones the options pick (Journeys Lab; new in 0.14.0).
|
|
442
|
+
// A split path's filter works as the options too.
|
|
443
|
+
journey(options = {}) {
|
|
444
|
+
const o = options;
|
|
445
|
+
const q = new URLSearchParams();
|
|
446
|
+
// A comma inside a value is written %2C, as the page's address writes it.
|
|
447
|
+
const list = (items) => (items?.length ? items.map((item) => item.replace(/%/g, '%25').replace(/,/g, '%2C')).join(',') : null);
|
|
448
|
+
const put = (name, value) => {
|
|
449
|
+
if (value)
|
|
450
|
+
q.set(name, value);
|
|
451
|
+
};
|
|
452
|
+
put('site', o.site);
|
|
453
|
+
put('phase', o.phase);
|
|
454
|
+
put('country', list(o.country));
|
|
455
|
+
put('country_unknown', o.countryUnknown || o.country_unknown ? '1' : null);
|
|
456
|
+
put('age', list(o.age));
|
|
457
|
+
put('age_unknown', o.ageUnknown || o.age_unknown ? '1' : null);
|
|
458
|
+
put('any_tags', list(o.anyTags ?? o.any_tags));
|
|
459
|
+
put('address', o.address);
|
|
460
|
+
put('got_step', list(o.gotStep ?? o.got_step));
|
|
461
|
+
put('not_got_step', list(o.notGotStep ?? o.not_got_step));
|
|
462
|
+
const query = q.toString();
|
|
463
|
+
return this.request('GET', `/journeys${query ? `?${query}` : ''}`);
|
|
464
|
+
}
|
|
295
465
|
markDevHost(host) {
|
|
296
466
|
return this.request('POST', '/project/dev-hosts', { host });
|
|
297
467
|
}
|
|
@@ -473,6 +643,17 @@ export class ProxyMailQA {
|
|
|
473
643
|
deleteAddress(address) {
|
|
474
644
|
return this.request('DELETE', `/addresses/${encodeURIComponent(address)}`);
|
|
475
645
|
}
|
|
646
|
+
// Records that the test is about to submit a form with the address (a
|
|
647
|
+
// sign-up unless flow says otherwise), on site (a page URL, kept as host and
|
|
648
|
+
// path, with any part of the path that has an email address, an ID, a long
|
|
649
|
+
// number or a token in it hidden; never its query or fragment). Call it just
|
|
650
|
+
// before the test presses the button: the time is the server's, taken when
|
|
651
|
+
// the call arrives, so after the click a fast email can come first. Pass its
|
|
652
|
+
// submitted_at as since; the wait that finds the code or link then returns
|
|
653
|
+
// time_to_email. Never send the form's contents.
|
|
654
|
+
markSubmitted(address, options = {}) {
|
|
655
|
+
return this.request('POST', `/addresses/${encodeURIComponent(address)}/submits`, { flow: options.flow, site: options.site });
|
|
656
|
+
}
|
|
476
657
|
// Waits for a verification or login code; throws ProxyMailQAError (404) if
|
|
477
658
|
// none arrives in time.
|
|
478
659
|
// The newest sign-in or verification code; with type: 'coupon', the
|
|
@@ -509,7 +690,8 @@ export class ProxyMailQA {
|
|
|
509
690
|
return this.request('GET', `/addresses/${encodeURIComponent(address)}/count${countQuery(options)}`);
|
|
510
691
|
}
|
|
511
692
|
// Checks one email the address received: SPF, DKIM and DMARC, links to
|
|
512
|
-
// localhost or plain http, where its link goes (expectHost)
|
|
693
|
+
// localhost or plain http, where its link goes (expectHost) and whether
|
|
694
|
+
// it goes back to the site the test started on (link_site), a stated
|
|
513
695
|
// expiry, a plain-text part, size and image-only emails, and given phrases
|
|
514
696
|
// (expectText) and its language (expectLanguage). Doesn't wait: wait for
|
|
515
697
|
// the email first. Throws ProxyMailQAError (404) when none matches.
|
|
@@ -519,6 +701,8 @@ export class ProxyMailQA {
|
|
|
519
701
|
extra.email_id = options.emailId;
|
|
520
702
|
if (options.expectHost)
|
|
521
703
|
extra.expect_host = options.expectHost;
|
|
704
|
+
if (options.expectSite)
|
|
705
|
+
extra.expect_site = options.expectSite;
|
|
522
706
|
if (options.expectLanguage)
|
|
523
707
|
extra.expect_language = options.expectLanguage;
|
|
524
708
|
if (options.expectWithin !== undefined)
|
|
@@ -656,6 +840,12 @@ export class ProxyMailQA {
|
|
|
656
840
|
const suffix = query.size ? `?${query}` : '';
|
|
657
841
|
return this.request('GET', `/variants/passwords${suffix}`);
|
|
658
842
|
}
|
|
843
|
+
// The checks to run on a sign-up, password reset or magic-link flow: a
|
|
844
|
+
// code working once, only the newest reset link working, a second person
|
|
845
|
+
// unable to see the first one's data. Each has steps, what to expect and why.
|
|
846
|
+
flowChecks(flow) {
|
|
847
|
+
return this.request('GET', `/flow-checks?flow=${encodeURIComponent(flow)}`);
|
|
848
|
+
}
|
|
659
849
|
setPassword(address, options = {}) {
|
|
660
850
|
return this.request('PUT', `/addresses/${encodeURIComponent(address)}/password`, { password: options.password, label: options.label });
|
|
661
851
|
}
|
|
@@ -737,6 +927,8 @@ export class ProxyMailQA {
|
|
|
737
927
|
query.set('app', String(app));
|
|
738
928
|
if (options.unused)
|
|
739
929
|
query.set('unused', 'true');
|
|
930
|
+
if (options.expectSite)
|
|
931
|
+
query.set('expect_site', options.expectSite);
|
|
740
932
|
const more = Date.now() + left * 1000 < deadline - 500;
|
|
741
933
|
try {
|
|
742
934
|
return await this.request('GET', `/addresses/${encodeURIComponent(address)}/${kind}?${query}`, undefined, more);
|
|
@@ -758,3 +950,138 @@ function age(dateOfBirth) {
|
|
|
758
950
|
const now = new Date();
|
|
759
951
|
return now.getUTCFullYear() - y - (now.getUTCMonth() + 1 < m || (now.getUTCMonth() + 1 === m && now.getUTCDate() < d) ? 1 : 0);
|
|
760
952
|
}
|
|
953
|
+
const BASE32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
954
|
+
function base32Bytes(secret) {
|
|
955
|
+
const clean = secret.replace(/[\s-]/g, '').replace(/=+$/, '').toUpperCase();
|
|
956
|
+
if (!clean)
|
|
957
|
+
throw new Error('The TOTP secret is empty.');
|
|
958
|
+
let bits = 0;
|
|
959
|
+
let value = 0;
|
|
960
|
+
const out = [];
|
|
961
|
+
for (const char of clean) {
|
|
962
|
+
const index = BASE32.indexOf(char);
|
|
963
|
+
if (index < 0)
|
|
964
|
+
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.');
|
|
965
|
+
value = (value << 5) | index;
|
|
966
|
+
bits += 5;
|
|
967
|
+
if (bits >= 8) {
|
|
968
|
+
out.push((value >>> (bits - 8)) & 0xff);
|
|
969
|
+
bits -= 8;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return new Uint8Array(out);
|
|
973
|
+
}
|
|
974
|
+
// The secret and any digits, period and algorithm an otpauth:// address gives.
|
|
975
|
+
function readTotpSecret(secret) {
|
|
976
|
+
if (!/^otpauth:\/\//i.test(secret.trim()))
|
|
977
|
+
return { key: secret };
|
|
978
|
+
const url = new URL(secret.trim());
|
|
979
|
+
if (url.hostname.toLowerCase() !== 'totp')
|
|
980
|
+
throw new Error('Only otpauth://totp/ addresses are time-based codes.');
|
|
981
|
+
const key = url.searchParams.get('secret');
|
|
982
|
+
if (!key)
|
|
983
|
+
throw new Error('The otpauth:// address has no secret.');
|
|
984
|
+
const algorithm = url.searchParams.get('algorithm')?.toUpperCase().replace(/^SHA(\d)/, 'SHA-$1');
|
|
985
|
+
const number = (name) => (url.searchParams.has(name) ? Number(url.searchParams.get(name)) : undefined);
|
|
986
|
+
return { key, digits: number('digits'), period: number('period'), algorithm };
|
|
987
|
+
}
|
|
988
|
+
async function hmac(algorithm, key, message) {
|
|
989
|
+
// Node 18 has Web Crypto only through node:crypto.
|
|
990
|
+
const subtle = globalThis.crypto?.subtle ?? (await import(/* @vite-ignore */ 'node:crypto')).webcrypto.subtle;
|
|
991
|
+
const cryptoKey = await subtle.importKey('raw', key, { name: 'HMAC', hash: algorithm }, false, ['sign']);
|
|
992
|
+
return new Uint8Array(await subtle.sign('HMAC', cryptoKey, message));
|
|
993
|
+
}
|
|
994
|
+
export async function totpCode(secret, options = {}) {
|
|
995
|
+
const given = readTotpSecret(secret);
|
|
996
|
+
const digits = options.digits ?? given.digits ?? 6;
|
|
997
|
+
const period = options.period ?? given.period ?? 30;
|
|
998
|
+
const algorithm = options.algorithm ?? given.algorithm ?? 'SHA-1';
|
|
999
|
+
if (!Number.isInteger(digits) || digits < 6 || digits > 10)
|
|
1000
|
+
throw new Error('digits must be a whole number from 6 to 10.');
|
|
1001
|
+
if (!Number.isInteger(period) || period < 1)
|
|
1002
|
+
throw new Error('period must be a whole number of seconds.');
|
|
1003
|
+
if (!['SHA-1', 'SHA-256', 'SHA-512'].includes(algorithm))
|
|
1004
|
+
throw new Error('algorithm must be SHA-1, SHA-256 or SHA-512.');
|
|
1005
|
+
const key = base32Bytes(given.key);
|
|
1006
|
+
let ms = options.at === undefined ? Date.now() : options.at instanceof Date ? options.at.getTime() : options.at;
|
|
1007
|
+
if (options.at === undefined && options.minSecondsLeft) {
|
|
1008
|
+
const left = period - ((ms / 1000) % period);
|
|
1009
|
+
if (left < Math.min(options.minSecondsLeft, period)) {
|
|
1010
|
+
await new Promise((resolve) => setTimeout(resolve, Math.ceil(left * 1000) + 50));
|
|
1011
|
+
ms = Date.now();
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
const counter = Math.floor(ms / 1000 / period);
|
|
1015
|
+
const message = new Uint8Array(8);
|
|
1016
|
+
new DataView(message.buffer).setBigUint64(0, BigInt(counter));
|
|
1017
|
+
const mac = await hmac(algorithm, key, message);
|
|
1018
|
+
const offset = mac[mac.length - 1] & 0x0f;
|
|
1019
|
+
const binary = ((mac[offset] & 0x7f) << 24) | (mac[offset + 1] << 16) | (mac[offset + 2] << 8) | mac[offset + 3];
|
|
1020
|
+
return String(binary % 10 ** digits).padStart(digits, '0');
|
|
1021
|
+
}
|
|
1022
|
+
// Whether a value follows a format from getFormSection: its shape and, where
|
|
1023
|
+
// there is one, its check digit. It runs here, so an ID never leaves this
|
|
1024
|
+
// machine. Following the format isn't being valid: only the issuer knows
|
|
1025
|
+
// whether a number was given to anyone (New in 0.13.0).
|
|
1026
|
+
export function followsFormat(format, value) {
|
|
1027
|
+
const compact = value.normalize('NFKC').toUpperCase().replace(/[\s.\-/]/g, '');
|
|
1028
|
+
if (!new RegExp(format.pattern).test(compact))
|
|
1029
|
+
return { follows: false, problem: `It doesn’t have the shape${format.shape ? ` (${format.shape})` : ''}.` };
|
|
1030
|
+
if (format.check && !FORMAT_CHECKS[format.check](compact))
|
|
1031
|
+
return { follows: false, problem: 'Its check digit is wrong.' };
|
|
1032
|
+
return { follows: true };
|
|
1033
|
+
}
|
|
1034
|
+
const numbers = (value) => [...value].map(Number);
|
|
1035
|
+
const VERHOEFF_D = [
|
|
1036
|
+
[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],
|
|
1037
|
+
[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],
|
|
1038
|
+
];
|
|
1039
|
+
const VERHOEFF_P = [
|
|
1040
|
+
[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],
|
|
1041
|
+
[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],
|
|
1042
|
+
];
|
|
1043
|
+
const mod11 = (value) => {
|
|
1044
|
+
const sum = numbers(value).reduce((total, n, i) => total + n * (value.length + 1 - i), 0);
|
|
1045
|
+
const r = (sum * 10) % 11;
|
|
1046
|
+
return String(r === 10 ? 0 : r);
|
|
1047
|
+
};
|
|
1048
|
+
const cnpjDigit = (value) => {
|
|
1049
|
+
let sum = 0;
|
|
1050
|
+
[...value].reverse().forEach((char, i) => (sum += (char.charCodeAt(0) - 48) * (2 + (i % 8))));
|
|
1051
|
+
const r = sum % 11;
|
|
1052
|
+
return String(r < 2 ? 0 : 11 - r);
|
|
1053
|
+
};
|
|
1054
|
+
const icao = (value) => {
|
|
1055
|
+
let sum = 0;
|
|
1056
|
+
[...value].forEach((char, i) => (sum += (char === '<' ? 0 : /\d/.test(char) ? Number(char) : char.charCodeAt(0) - 55) * [7, 3, 1][i % 3]));
|
|
1057
|
+
return String(sum % 10);
|
|
1058
|
+
};
|
|
1059
|
+
const FORMAT_CHECKS = {
|
|
1060
|
+
verhoeff: (value) => {
|
|
1061
|
+
let c = 0;
|
|
1062
|
+
numbers(value)
|
|
1063
|
+
.reverse()
|
|
1064
|
+
.forEach((n, i) => (c = VERHOEFF_D[c][VERHOEFF_P[i % 8][n]]));
|
|
1065
|
+
return c === 0;
|
|
1066
|
+
},
|
|
1067
|
+
cpf: (value) => {
|
|
1068
|
+
const first = mod11(value.slice(0, 9));
|
|
1069
|
+
return value.slice(9) === first + mod11(value.slice(0, 9) + first);
|
|
1070
|
+
},
|
|
1071
|
+
cnpj: (value) => {
|
|
1072
|
+
const first = cnpjDigit(value.slice(0, 12));
|
|
1073
|
+
return value.slice(12) === first + cnpjDigit(value.slice(0, 12) + first);
|
|
1074
|
+
},
|
|
1075
|
+
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],
|
|
1076
|
+
my_number: (value) => {
|
|
1077
|
+
const r = numbers(value.slice(0, 11)).reverse().reduce((total, n, i) => total + n * (i < 6 ? i + 2 : i - 4), 0) % 11;
|
|
1078
|
+
return value.slice(-1) === String(r <= 1 ? 0 : 11 - r);
|
|
1079
|
+
},
|
|
1080
|
+
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,
|
|
1081
|
+
gb_vat: (value) => {
|
|
1082
|
+
const nine = value.replace(/^GB/, '');
|
|
1083
|
+
const sum = numbers(nine.slice(0, 7)).reduce((total, n, i) => total + n * (8 - i), 0) + Number(nine.slice(7, 9));
|
|
1084
|
+
return sum % 97 === 0 || (sum + 55) % 97 === 0;
|
|
1085
|
+
},
|
|
1086
|
+
icao: (value) => value.slice(-1) === icao(value.slice(0, -1)),
|
|
1087
|
+
};
|
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.14.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
|
},
|