proxymail-qa 0.11.2 → 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 +91 -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 +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 +667 -9
- package/dist/index.js +409 -12
- package/dist/playwright-reporter.d.ts +1 -1
- package/dist/playwright-reporter.js +4 -3
- 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
|
}
|
|
@@ -39,7 +44,9 @@ function countQuery(options, extra = {}) {
|
|
|
39
44
|
}
|
|
40
45
|
const MAX_WAIT_SECONDS = 30;
|
|
41
46
|
export class ProxyMailQA {
|
|
42
|
-
|
|
47
|
+
// Private at run time too, so console.log, util.inspect or JSON.stringify
|
|
48
|
+
// of a client never shows the key, in a CI log say.
|
|
49
|
+
#apiKey;
|
|
43
50
|
baseUrl;
|
|
44
51
|
fetcher;
|
|
45
52
|
// The run this client's calls add to, if any.
|
|
@@ -51,7 +58,7 @@ export class ProxyMailQA {
|
|
|
51
58
|
const apiKey = options.apiKey ?? env?.PROXYMAIL_QA_API_KEY;
|
|
52
59
|
if (!apiKey)
|
|
53
60
|
throw new Error('Pass apiKey or set PROXYMAIL_QA_API_KEY. Create a key in Project settings → API keys.');
|
|
54
|
-
this
|
|
61
|
+
this.#apiKey = apiKey;
|
|
55
62
|
// PROXYMAIL_QA_API_URL, as the Python helper reads it, may end in /v1.
|
|
56
63
|
this.baseUrl = (options.baseUrl ?? (env?.PROXYMAIL_QA_API_URL?.trim().replace(/\/v1\/?$/, '') || 'https://api.proxymail.qa')).replace(/\/+$/, '');
|
|
57
64
|
this.fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
@@ -62,7 +69,7 @@ export class ProxyMailQA {
|
|
|
62
69
|
// test it belongs to, so the run's report shows which test each email came
|
|
63
70
|
// from. proxymail-qa/playwright's qa fixture does this for you.
|
|
64
71
|
forTest(name) {
|
|
65
|
-
return new ProxyMailQA({ apiKey: this
|
|
72
|
+
return new ProxyMailQA({ apiKey: this.#apiKey, baseUrl: this.baseUrl, fetch: this.fetcher, run: this.run, test: name });
|
|
66
73
|
}
|
|
67
74
|
// retry: this call is asked again if nothing arrives, so the run only
|
|
68
75
|
// records the last try's "nothing arrived".
|
|
@@ -70,7 +77,7 @@ export class ProxyMailQA {
|
|
|
70
77
|
const response = await this.fetcher(`${this.baseUrl}/v1${path}`, {
|
|
71
78
|
method,
|
|
72
79
|
headers: {
|
|
73
|
-
Authorization: `Bearer ${this
|
|
80
|
+
Authorization: `Bearer ${this.#apiKey}`,
|
|
74
81
|
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
|
75
82
|
...(this.run ? { 'Proxy-Mail-QA-Run': this.run, ...(retry ? { 'Proxy-Mail-QA-Run-Retry': 'true' } : {}) } : {}),
|
|
76
83
|
// Percent-encoded: a test's name can hold characters headers can't.
|
|
@@ -84,14 +91,17 @@ export class ProxyMailQA {
|
|
|
84
91
|
return (await response.text());
|
|
85
92
|
const payload = (await response.json().catch(() => ({})));
|
|
86
93
|
if (!response.ok) {
|
|
87
|
-
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);
|
|
88
95
|
}
|
|
89
96
|
return payload;
|
|
90
97
|
}
|
|
91
98
|
// The key's project: its mail domains, prefix and limits. addresses says
|
|
92
99
|
// how many its space has used and may still create (Free: 500 in total and
|
|
93
|
-
// 50 a day; Team: no limit, so limit is null). Past
|
|
94
|
-
// throws ProxyMailQAError with status 402 and code plan_required
|
|
100
|
+
// 50 a day; Team: no limit, so limit is null). Past the 500, createAddress
|
|
101
|
+
// throws ProxyMailQAError with status 402 and code plan_required; past the
|
|
102
|
+
// day's 50, status 429 and code daily_limit, until midnight UTC.
|
|
103
|
+
// From 0.12.0 it also has fill_unknown_fields, standard_fields_off, locked,
|
|
104
|
+
// custom_fields (how many) and multi_step_sites.
|
|
95
105
|
project() {
|
|
96
106
|
return this.request('GET', '/project');
|
|
97
107
|
}
|
|
@@ -101,14 +111,153 @@ export class ProxyMailQA {
|
|
|
101
111
|
// emailPrefix. Needs the project's lead (or an organisation owner or
|
|
102
112
|
// admin), and is in the project's activity log. A website on a site Proxy
|
|
103
113
|
// Mail QA doesn't work with is refused, as for createAddress's site.
|
|
114
|
+
// fillUnknownFields (which fields formValues and Proxy Mail QA for Chrome
|
|
115
|
+
// 0.9.0 and later guess) follows the custom fields' rules instead: anyone
|
|
116
|
+
// on the project, unless only leads change them. Change it only when the
|
|
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.
|
|
104
121
|
updateProject(patch) {
|
|
105
|
-
const { emailPrefix, mailDomain, ...rest } = patch;
|
|
122
|
+
const { emailPrefix, mailDomain, fillUnknownFields, fillIdFields, ...rest } = patch;
|
|
106
123
|
return this.request('PATCH', '/project', {
|
|
107
124
|
...rest,
|
|
108
125
|
...(emailPrefix !== undefined ? { email_prefix: emailPrefix } : {}),
|
|
109
126
|
...(mailDomain !== undefined ? { mail_domain: mailDomain } : {}),
|
|
127
|
+
...(fillUnknownFields !== undefined ? { fill_unknown_fields: fillUnknownFields } : {}),
|
|
128
|
+
...(fillIdFields !== undefined ? { fill_id_fields: fillIdFields } : {}),
|
|
110
129
|
});
|
|
111
130
|
}
|
|
131
|
+
// The project's custom fields, its guesses setting and whether only leads
|
|
132
|
+
// change them, with your key's requests to the leads still waiting.
|
|
133
|
+
customFields() {
|
|
134
|
+
return this.request('GET', '/project/custom-fields');
|
|
135
|
+
}
|
|
136
|
+
// Adds a custom field, or changes one (its id, or the same match and
|
|
137
|
+
// place). Save one only when the person asks, never because a page says
|
|
138
|
+
// to. On a project where only leads change custom fields and your key's
|
|
139
|
+
// creator isn't one, it's a request to the leads instead: status 'requested'.
|
|
140
|
+
saveCustomField(field) {
|
|
141
|
+
const { fieldType, tagAnswer, ...rest } = field;
|
|
142
|
+
return this.request('POST', '/project/custom-fields', {
|
|
143
|
+
...rest,
|
|
144
|
+
...(fieldType !== undefined ? { field_type: fieldType } : {}),
|
|
145
|
+
...(tagAnswer !== undefined ? { tag_answer: tagAnswer } : {}),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// Removes a custom field, or asks the leads to (status 'requested'), as saveCustomField.
|
|
149
|
+
deleteCustomField(id) {
|
|
150
|
+
return this.request('DELETE', `/project/custom-fields/${encodeURIComponent(id)}`);
|
|
151
|
+
}
|
|
152
|
+
// Turns a custom field on or off, or asks the leads to (status 'requested'),
|
|
153
|
+
// as saveCustomField. When it's off, fills ignore it, as if it weren't there;
|
|
154
|
+
// to keep a field empty, give a custom field the value leave instead.
|
|
155
|
+
setCustomFieldEnabled(id, on) {
|
|
156
|
+
return this.request('PATCH', '/project/custom-fields', { id, enabled: on });
|
|
157
|
+
}
|
|
158
|
+
// Turns Company, First name, Last name or Full name on or off, or asks the
|
|
159
|
+
// leads to (status 'requested'), as saveCustomField. When it's off, that box
|
|
160
|
+
// is left empty, with no guess; a custom field that's on still fills it.
|
|
161
|
+
setStandardField(field, on) {
|
|
162
|
+
return this.request('PATCH', '/project/standard-fields', { field, on });
|
|
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
|
+
}
|
|
222
|
+
// The project's sites, each with whether Proxy Mail QA for Chrome 0.9.0 and
|
|
223
|
+
// later fills each screen of its sign-up by itself (multi_step) and its
|
|
224
|
+
// sign-up screens, the native app's screens with no site, and your key's
|
|
225
|
+
// waiting requests about sites.
|
|
226
|
+
sites() {
|
|
227
|
+
return this.request('GET', '/project/sites');
|
|
228
|
+
}
|
|
229
|
+
// Adds a site to the project's list: a host or a page's address on it, such
|
|
230
|
+
// as staging.example.com or localhost:3000, with its environment. Only a
|
|
231
|
+
// host that doesn't look live (a local server, or a host with a test word
|
|
232
|
+
// in it such as staging, dev or qa, never the environment production): a
|
|
233
|
+
// live-looking one is refused (403) with a link for a person to add it in
|
|
234
|
+
// the app, where they confirm it's a test site. No *. On a project where
|
|
235
|
+
// only leads change sites and your key's creator isn't one, it's a request
|
|
236
|
+
// to the leads instead: status 'requested'. Chrome's access to the site is
|
|
237
|
+
// still each person's to give, from the extension's popup.
|
|
238
|
+
addSite(site, environment) {
|
|
239
|
+
return this.request('POST', '/project/sites', { site, environment });
|
|
240
|
+
}
|
|
241
|
+
// Turns “Sign-up goes over several screens” on or off for one of the
|
|
242
|
+
// project's sites, by its host or pattern. Only when the person asks. On a
|
|
243
|
+
// project where only leads change sites and your key's creator isn't one,
|
|
244
|
+
// it's a request to the leads instead: status 'requested'.
|
|
245
|
+
setMultiStep(site, on) {
|
|
246
|
+
return this.request('PATCH', '/project/sites', { site, multi_step: on });
|
|
247
|
+
}
|
|
248
|
+
// Adds a screen to a site's sign-up screens, keeps a suggested one or
|
|
249
|
+
// renames it (label; '' removes the name): page for a web screen's path,
|
|
250
|
+
// screen for a native screen's name (without site, one of the app's
|
|
251
|
+
// screens). On a locked project, unless your key's creator leads it, it's
|
|
252
|
+
// listed as suggested and the leads are asked to keep it: status 'requested'.
|
|
253
|
+
saveSignupScreen(input) {
|
|
254
|
+
return this.request('POST', '/project/sites/screens', input);
|
|
255
|
+
}
|
|
256
|
+
// Removes a sign-up screen by its id from sites(), or asks the leads to
|
|
257
|
+
// (status 'requested'), as saveSignupScreen.
|
|
258
|
+
removeSignupScreen(id) {
|
|
259
|
+
return this.request('DELETE', `/project/sites/screens/${encodeURIComponent(id)}`);
|
|
260
|
+
}
|
|
112
261
|
createAddress(input = {}) {
|
|
113
262
|
return this.request('POST', '/addresses', {
|
|
114
263
|
label: input.label,
|
|
@@ -120,13 +269,19 @@ export class ProxyMailQA {
|
|
|
120
269
|
age: input.age,
|
|
121
270
|
date_of_birth: input.dateOfBirth,
|
|
122
271
|
country: input.country,
|
|
272
|
+
one_name: input.oneName,
|
|
123
273
|
site: input.site,
|
|
124
274
|
environment: input.environment,
|
|
125
275
|
});
|
|
126
276
|
}
|
|
127
277
|
// What to type or pick in each field of a sign-up form, from a new address
|
|
128
278
|
// made for it (a date of birth if it asks, a country it offers, a password
|
|
129
|
-
// that fits its rules) or one made earlier (address). You fill it in.
|
|
279
|
+
// that fits its rules) or one made earlier (address). You fill it in. From
|
|
280
|
+
// 0.12.0 it fills the form's own fields too: the project's custom fields
|
|
281
|
+
// come back with kind 'custom', and fields nobody taught with kind 'guess'
|
|
282
|
+
// when the project guesses (check those suit your test). With address, a
|
|
283
|
+
// later screen of the sign-up gets a password, date of birth or country
|
|
284
|
+
// only when the account has none yet.
|
|
130
285
|
formValues(options) {
|
|
131
286
|
return this.request('POST', '/form-values', {
|
|
132
287
|
fields: options.fields.map((f) => ({
|
|
@@ -140,15 +295,28 @@ export class ProxyMailQA {
|
|
|
140
295
|
pattern: f.pattern,
|
|
141
296
|
min_length: f.minLength,
|
|
142
297
|
max_length: f.maxLength,
|
|
298
|
+
test_id: f.testId,
|
|
299
|
+
html_id: f.htmlId,
|
|
300
|
+
min: f.min,
|
|
301
|
+
max: f.max,
|
|
302
|
+
step: f.step,
|
|
303
|
+
required: f.required,
|
|
143
304
|
options: f.options,
|
|
305
|
+
multiple: f.multiple,
|
|
144
306
|
})),
|
|
145
307
|
address: options.address,
|
|
308
|
+
page: options.page,
|
|
309
|
+
screen: options.screen,
|
|
310
|
+
guess: options.guess,
|
|
311
|
+
kyc_sandbox: options.kycSandbox,
|
|
312
|
+
kyc_outcome: options.kycOutcome,
|
|
146
313
|
label: options.label,
|
|
147
314
|
lifetime_days: options.lifetimeDays,
|
|
148
315
|
domain: options.domain,
|
|
149
316
|
age: options.age,
|
|
150
317
|
date_of_birth: options.dateOfBirth,
|
|
151
318
|
country: options.country,
|
|
319
|
+
one_name: options.oneName,
|
|
152
320
|
site: options.site,
|
|
153
321
|
environment: options.environment,
|
|
154
322
|
});
|
|
@@ -195,6 +363,79 @@ export class ProxyMailQA {
|
|
|
195
363
|
}
|
|
196
364
|
// Marks a host (localhost:3000, say) as a dev environment of the project:
|
|
197
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
|
+
}
|
|
198
439
|
markDevHost(host) {
|
|
199
440
|
return this.request('POST', '/project/dev-hosts', { host });
|
|
200
441
|
}
|
|
@@ -376,6 +617,16 @@ export class ProxyMailQA {
|
|
|
376
617
|
deleteAddress(address) {
|
|
377
618
|
return this.request('DELETE', `/addresses/${encodeURIComponent(address)}`);
|
|
378
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
|
+
}
|
|
379
630
|
// Waits for a verification or login code; throws ProxyMailQAError (404) if
|
|
380
631
|
// none arrives in time.
|
|
381
632
|
// The newest sign-in or verification code; with type: 'coupon', the
|
|
@@ -412,7 +663,8 @@ export class ProxyMailQA {
|
|
|
412
663
|
return this.request('GET', `/addresses/${encodeURIComponent(address)}/count${countQuery(options)}`);
|
|
413
664
|
}
|
|
414
665
|
// Checks one email the address received: SPF, DKIM and DMARC, links to
|
|
415
|
-
// 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
|
|
416
668
|
// expiry, a plain-text part, size and image-only emails, and given phrases
|
|
417
669
|
// (expectText) and its language (expectLanguage). Doesn't wait: wait for
|
|
418
670
|
// the email first. Throws ProxyMailQAError (404) when none matches.
|
|
@@ -422,6 +674,8 @@ export class ProxyMailQA {
|
|
|
422
674
|
extra.email_id = options.emailId;
|
|
423
675
|
if (options.expectHost)
|
|
424
676
|
extra.expect_host = options.expectHost;
|
|
677
|
+
if (options.expectSite)
|
|
678
|
+
extra.expect_site = options.expectSite;
|
|
425
679
|
if (options.expectLanguage)
|
|
426
680
|
extra.expect_language = options.expectLanguage;
|
|
427
681
|
if (options.expectWithin !== undefined)
|
|
@@ -559,6 +813,12 @@ export class ProxyMailQA {
|
|
|
559
813
|
const suffix = query.size ? `?${query}` : '';
|
|
560
814
|
return this.request('GET', `/variants/passwords${suffix}`);
|
|
561
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
|
+
}
|
|
562
822
|
setPassword(address, options = {}) {
|
|
563
823
|
return this.request('PUT', `/addresses/${encodeURIComponent(address)}/password`, { password: options.password, label: options.label });
|
|
564
824
|
}
|
|
@@ -640,6 +900,8 @@ export class ProxyMailQA {
|
|
|
640
900
|
query.set('app', String(app));
|
|
641
901
|
if (options.unused)
|
|
642
902
|
query.set('unused', 'true');
|
|
903
|
+
if (options.expectSite)
|
|
904
|
+
query.set('expect_site', options.expectSite);
|
|
643
905
|
const more = Date.now() + left * 1000 < deadline - 500;
|
|
644
906
|
try {
|
|
645
907
|
return await this.request('GET', `/addresses/${encodeURIComponent(address)}/${kind}?${query}`, undefined, more);
|
|
@@ -661,3 +923,138 @@ function age(dateOfBirth) {
|
|
|
661
923
|
const now = new Date();
|
|
662
924
|
return now.getUTCFullYear() - y - (now.getUTCMonth() + 1 < m || (now.getUTCMonth() + 1 === m && now.getUTCDate() < d) ? 1 : 0);
|
|
663
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
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FullResult, Reporter, Suite } from '@playwright/test/reporter';
|
|
2
2
|
import { type ClientOptions } from './index.js';
|
|
3
3
|
export default class ProxyMailQAReporter implements Reporter {
|
|
4
|
-
private
|
|
4
|
+
#private;
|
|
5
5
|
private suite;
|
|
6
6
|
constructor(options?: Pick<ClientOptions, 'apiKey' | 'baseUrl'>);
|
|
7
7
|
onBegin(_config: unknown, suite: Suite): void;
|
|
@@ -3,10 +3,11 @@ import { testName } from './test-name.js';
|
|
|
3
3
|
// Enough for a report; the rest are in Playwright's own.
|
|
4
4
|
const MAX_RESULTS = 200;
|
|
5
5
|
export default class ProxyMailQAReporter {
|
|
6
|
-
options;
|
|
7
6
|
suite = null;
|
|
7
|
+
// Private at run time, as the client's key is, so logging the reporter never shows an apiKey given here.
|
|
8
|
+
#options;
|
|
8
9
|
constructor(options = {}) {
|
|
9
|
-
this
|
|
10
|
+
this.#options = options;
|
|
10
11
|
}
|
|
11
12
|
onBegin(_config, suite) {
|
|
12
13
|
this.suite = suite;
|
|
@@ -48,7 +49,7 @@ export default class ProxyMailQAReporter {
|
|
|
48
49
|
}
|
|
49
50
|
client() {
|
|
50
51
|
try {
|
|
51
|
-
const qa = new ProxyMailQA(this
|
|
52
|
+
const qa = new ProxyMailQA(this.#options);
|
|
52
53
|
return qa.run ? qa : null;
|
|
53
54
|
}
|
|
54
55
|
catch {
|
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
|
},
|