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/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# proxymail-qa
|
|
2
2
|
|
|
3
3
|
Test the emails your app sends, end to end, from Playwright, Cypress,
|
|
4
|
-
Puppeteer, Jest, Vitest
|
|
4
|
+
Puppeteer, Jest, Vitest, any Node script or the command line. Create a disposable address, sign
|
|
5
5
|
up with it, and get the verification code or link in one call that waits for
|
|
6
6
|
it. Then:
|
|
7
7
|
|
|
@@ -94,32 +94,56 @@ test('sign-up sends one code', async ({ page, qa }) => {
|
|
|
94
94
|
|
|
95
95
|
## Cypress
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
`cy.proxymail` has the client's methods. Each runs in Node through one task,
|
|
98
|
+
so the API key never reaches the browser. Register the task in
|
|
99
|
+
`cypress.config.ts`:
|
|
98
100
|
|
|
99
101
|
```ts
|
|
100
|
-
import {
|
|
102
|
+
import { setupProxyMailQA } from 'proxymail-qa/cypress/plugin';
|
|
101
103
|
|
|
102
104
|
export default defineConfig({
|
|
103
105
|
e2e: {
|
|
104
106
|
setupNodeEvents(on) {
|
|
105
|
-
|
|
106
|
-
on('task', {
|
|
107
|
-
createAddress: () => qa.createAddress({ persona: true }),
|
|
108
|
-
waitForLink: (address: string) => qa.waitForLink(address, { type: 'verify' }),
|
|
109
|
-
});
|
|
107
|
+
setupProxyMailQA(on); // reads PROXYMAIL_QA_API_KEY
|
|
110
108
|
},
|
|
111
109
|
},
|
|
112
110
|
});
|
|
113
111
|
```
|
|
114
112
|
|
|
113
|
+
Add the commands in the support file (`cypress/support/e2e.ts`) with
|
|
114
|
+
`import 'proxymail-qa/cypress';`, then:
|
|
115
|
+
|
|
115
116
|
```js
|
|
116
|
-
cy.
|
|
117
|
+
cy.proxymail.createAddress({ persona: true }).then(({ address }) => {
|
|
117
118
|
cy.get('[name=email]').type(address);
|
|
118
119
|
cy.contains('Sign up').click();
|
|
119
|
-
cy.
|
|
120
|
+
cy.proxymail.waitForLink(address, { type: 'verify' }).then(({ value }) => cy.visit(value));
|
|
120
121
|
});
|
|
121
122
|
```
|
|
122
123
|
|
|
124
|
+
Waits get their timeout and a margin, so Cypress's task timeout doesn't cut
|
|
125
|
+
them short. In a run, each call says which test it came from.
|
|
126
|
+
`cy.proxymail` has every method except `withAccount` and a run's start and
|
|
127
|
+
finish.
|
|
128
|
+
|
|
129
|
+
## Command line
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
npx proxymail-qa new --password --country JP # an address, password and persona
|
|
133
|
+
npx proxymail-qa wait-code <address> # the code from its newest email
|
|
134
|
+
npx proxymail-qa wait-link <address> --type reset
|
|
135
|
+
npx proxymail-qa persona <address>
|
|
136
|
+
npx proxymail-qa form-values form.json # what to type in each field
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
It reads the key from `PROXYMAIL_QA_API_KEY` only. In a terminal it labels
|
|
140
|
+
what it shows; piped, it prints just the value (the address, then the
|
|
141
|
+
password on a second line when you ask for one), so scripts can read it.
|
|
142
|
+
`--json` gives the whole answer. It exits 1 when the API refuses or nothing
|
|
143
|
+
arrives, with the reason on standard error, and 2 for a wrong command.
|
|
144
|
+
`npx proxymail-qa help <command>` lists the options. Guide:
|
|
145
|
+
https://proxymail.qa/docs/cli
|
|
146
|
+
|
|
123
147
|
## More
|
|
124
148
|
|
|
125
149
|
```ts
|
|
@@ -134,12 +158,18 @@ const [teen] = await qa.listAddresses({ tags: ['age-gate'], country: 'GB', maxAg
|
|
|
134
158
|
const account = await qa.signInAccount({ site: 'staging.example.com', tags: ['verified'] });
|
|
135
159
|
|
|
136
160
|
// How many addresses this project can still create: Free has 500 in total
|
|
137
|
-
// and 50 a day (limit null on Team). Past
|
|
161
|
+
// and 50 a day (limit null on Team). Past the 500, createAddress throws a 402
|
|
162
|
+
// plan_required; past the day's 50, a 429 daily_limit until midnight UTC.
|
|
138
163
|
const { addresses } = await qa.project();
|
|
139
164
|
|
|
140
165
|
// Testing on localhost? Links to it then pass checkEmail's local-links check.
|
|
141
166
|
await qa.markDevHost('localhost:3000');
|
|
142
167
|
|
|
168
|
+
// A two-factor sign-in: the authenticator app's code, worked out on this
|
|
169
|
+
// machine from the secret (or otpauth:// address) the app showed at set-up.
|
|
170
|
+
// The secret never reaches Proxy Mail QA.
|
|
171
|
+
const totp = await qa.totpCode(process.env.ACME_TOTP_SECRET!, { minSecondsLeft: 5 });
|
|
172
|
+
|
|
143
173
|
// The link that opens a mobile app (myapp://…) when the email also has a web one.
|
|
144
174
|
const { value: appLink } = await qa.waitForLink(address, { app: true });
|
|
145
175
|
|
|
@@ -175,6 +205,56 @@ const { values } = await qa.formValues({
|
|
|
175
205
|
],
|
|
176
206
|
});
|
|
177
207
|
|
|
208
|
+
// The form's own questions too: the project's custom fields come back with
|
|
209
|
+
// kind 'custom', and fields nobody taught with kind 'guess' (check those suit
|
|
210
|
+
// your test). On a sign-up over several screens, send each screen's fields
|
|
211
|
+
// with the same address, and its site and page, so custom fields kept to them
|
|
212
|
+
// apply.
|
|
213
|
+
const { values: teamStep } = await qa.formValues({
|
|
214
|
+
address,
|
|
215
|
+
site: 'staging.example.com',
|
|
216
|
+
page: '/signup/team',
|
|
217
|
+
fields: [{ id: 'size', type: 'select', label: 'Company size', required: true, options: [{ value: '1-10' }, { value: '11-50' }] }],
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// In a native app, send the screen's name instead of its page (not both).
|
|
221
|
+
await qa.formValues({ address, screen: 'Team details', fields: [{ id: 'role', type: 'text', label: 'Your role' }] });
|
|
222
|
+
|
|
223
|
+
// formValues is for sign-up forms. A sign-in or password reset form sent with
|
|
224
|
+
// the address you signed up with gets only the email or username; without an
|
|
225
|
+
// address, the API refuses it (409) and makes no account.
|
|
226
|
+
|
|
227
|
+
// Teach a field once for the project: everyone's tests and Proxy Mail QA for
|
|
228
|
+
// Chrome 0.9.0 and later fill it the same way. Where only leads change custom
|
|
229
|
+
// fields, this asks them instead (status 'requested'), unless your key's
|
|
230
|
+
// creator leads the project (you_lead): then it's saved straight away.
|
|
231
|
+
await qa.saveCustomField({ name: 'Company size', match: { on: 'words', text: 'company size' }, value: { kind: 'option', option: '11-50' } });
|
|
232
|
+
|
|
233
|
+
// No test value in mind? { kind: 'generate' } makes up one that suits the
|
|
234
|
+
// field, the same one for the same account, on any field but a tick box.
|
|
235
|
+
await qa.saveCustomField({ name: 'Job title', match: { on: 'words', text: 'job title' }, value: { kind: 'generate' } });
|
|
236
|
+
|
|
237
|
+
// On a site in several languages, one custom field can hold the label in each.
|
|
238
|
+
// Saving replaces the custom field, so send every phrase to keep.
|
|
239
|
+
await qa.saveCustomField({
|
|
240
|
+
name: 'Referral code',
|
|
241
|
+
match: { on: 'words', text: 'referral code', also: ['empfehlungscode', 'code de parrainage'] },
|
|
242
|
+
value: { kind: 'leave' },
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// A sign-up over several screens: each site's sign-up screens, and whether
|
|
246
|
+
// Proxy Mail QA for Chrome 0.9.0 and later fills each screen by itself.
|
|
247
|
+
// Change them only when the person asks. On a locked project these ask the
|
|
248
|
+
// leads instead (status 'requested'), unless your key's creator leads it
|
|
249
|
+
// (you_lead): then the change is made straight away.
|
|
250
|
+
const { sites } = await qa.sites();
|
|
251
|
+
await qa.addSite('staging.example.com', 'staging'); // only a site that doesn't look live
|
|
252
|
+
await qa.setCustomFieldEnabled('a-custom-field-id', false);
|
|
253
|
+
await qa.setStandardField('company', false); // that box is left empty
|
|
254
|
+
await qa.setMultiStep('staging.example.com', true);
|
|
255
|
+
const saved = await qa.saveSignupScreen({ site: 'staging.example.com', page: '/signup/team', label: 'Team details' });
|
|
256
|
+
await qa.removeSignupScreen(saved.screen.id);
|
|
257
|
+
|
|
178
258
|
// Borrow an account in the state the test needs. Your hooks make one when
|
|
179
259
|
// none is free, confirm its state and put it back; they talk to your app,
|
|
180
260
|
// Proxy Mail QA never does.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ProxyMailQA, type ClientOptions } from './index.js';
|
|
2
|
+
export interface CliIo {
|
|
3
|
+
env: Record<string, string | undefined>;
|
|
4
|
+
out: (text: string) => void;
|
|
5
|
+
err: (text: string) => void;
|
|
6
|
+
tty: boolean;
|
|
7
|
+
readFile: (path: string) => Promise<string>;
|
|
8
|
+
readStdin: () => Promise<string>;
|
|
9
|
+
version: string;
|
|
10
|
+
client?: (options: ClientOptions) => ProxyMailQA;
|
|
11
|
+
}
|
|
12
|
+
type Flag = 'boolean' | 'string';
|
|
13
|
+
interface Parsed {
|
|
14
|
+
args: string[];
|
|
15
|
+
flags: Record<string, string | boolean>;
|
|
16
|
+
}
|
|
17
|
+
export declare function parseFlags(argv: string[], spec: Record<string, Flag>): Parsed;
|
|
18
|
+
export declare function runCli(argv: string[], io: CliIo): Promise<number>;
|
|
19
|
+
export {};
|
package/dist/cli-main.js
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// The proxymail-qa command (FM-14): the client's methods for terminals, npm
|
|
2
|
+
// scripts, JetBrains run configurations and CI. cli.ts runs it with Node's
|
|
3
|
+
// process; everything it touches comes in through io, so the tests run it
|
|
4
|
+
// without Node.
|
|
5
|
+
//
|
|
6
|
+
// The API key comes only from PROXYMAIL_QA_API_KEY, never from a flag, so it
|
|
7
|
+
// stays out of shell history and the process list.
|
|
8
|
+
import { ProxyMailQA, ProxyMailQAError, } from './index.js';
|
|
9
|
+
const NEW_FLAGS = {
|
|
10
|
+
persona: 'boolean',
|
|
11
|
+
password: 'boolean',
|
|
12
|
+
country: 'string',
|
|
13
|
+
age: 'string',
|
|
14
|
+
dob: 'string',
|
|
15
|
+
'one-name': 'boolean',
|
|
16
|
+
label: 'string',
|
|
17
|
+
name: 'string',
|
|
18
|
+
domain: 'string',
|
|
19
|
+
days: 'string',
|
|
20
|
+
site: 'string',
|
|
21
|
+
environment: 'string',
|
|
22
|
+
json: 'boolean',
|
|
23
|
+
};
|
|
24
|
+
const WAIT_FLAGS = {
|
|
25
|
+
type: 'string',
|
|
26
|
+
timeout: 'string',
|
|
27
|
+
since: 'string',
|
|
28
|
+
service: 'string',
|
|
29
|
+
unused: 'boolean',
|
|
30
|
+
site: 'string',
|
|
31
|
+
json: 'boolean',
|
|
32
|
+
};
|
|
33
|
+
const COMMANDS = {
|
|
34
|
+
new: { flags: NEW_FLAGS, args: 0, usage: NEW_USAGE() },
|
|
35
|
+
'wait-code': { flags: WAIT_FLAGS, args: 1, usage: WAIT_USAGE('code') },
|
|
36
|
+
'wait-link': { flags: { ...WAIT_FLAGS, app: 'boolean' }, args: 1, usage: WAIT_USAGE('link') },
|
|
37
|
+
persona: {
|
|
38
|
+
flags: { json: 'boolean' },
|
|
39
|
+
args: 1,
|
|
40
|
+
usage: 'proxymail-qa persona <address> [--json]\n\nThe test account’s persona: name, username, date of birth and country.',
|
|
41
|
+
},
|
|
42
|
+
'form-values': {
|
|
43
|
+
flags: {
|
|
44
|
+
address: 'string',
|
|
45
|
+
site: 'string',
|
|
46
|
+
page: 'string',
|
|
47
|
+
screen: 'string',
|
|
48
|
+
environment: 'string',
|
|
49
|
+
guess: 'string',
|
|
50
|
+
country: 'string',
|
|
51
|
+
age: 'string',
|
|
52
|
+
dob: 'string',
|
|
53
|
+
'one-name': 'boolean',
|
|
54
|
+
label: 'string',
|
|
55
|
+
domain: 'string',
|
|
56
|
+
days: 'string',
|
|
57
|
+
},
|
|
58
|
+
args: 1,
|
|
59
|
+
usage: FORM_USAGE(),
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
function NEW_USAGE() {
|
|
63
|
+
return `proxymail-qa new [options]
|
|
64
|
+
|
|
65
|
+
Makes a test address with a persona (a made-up name, username and date of
|
|
66
|
+
birth). In a terminal it shows them all; piped, it prints the address, and the
|
|
67
|
+
password on a second line when you ask for one.
|
|
68
|
+
|
|
69
|
+
--password Also make a password, saved on the address. Shown once.
|
|
70
|
+
--country <code> Where the persona lives: JP, IN, PK, GB…
|
|
71
|
+
--age <band> adult, over21, under18, under15, under13, any,
|
|
72
|
+
turns18tomorrow or turned18today
|
|
73
|
+
--dob <YYYY-MM-DD> A date of birth instead of an age band
|
|
74
|
+
--one-name One name and no family name
|
|
75
|
+
--no-persona Just the address
|
|
76
|
+
--label <text> A label to find it by
|
|
77
|
+
--name <name> The part before the @ (random when left out)
|
|
78
|
+
--domain <domain> One of your project's mail domains
|
|
79
|
+
--days <n> How long it lasts
|
|
80
|
+
--site <host> Where it's used, such as staging.example.com
|
|
81
|
+
--environment <env> staging, local…
|
|
82
|
+
--json Everything as JSON`;
|
|
83
|
+
}
|
|
84
|
+
function WAIT_USAGE(kind) {
|
|
85
|
+
const types = kind === 'code' ? 'otp (the default), coupon or any' : 'verify, magic_signin, invite, reset, unsubscribe or any; several with commas';
|
|
86
|
+
return `proxymail-qa wait-${kind} <address> [options]
|
|
87
|
+
|
|
88
|
+
Waits for the ${kind} from the newest email and prints it. Exits 1 with the
|
|
89
|
+
reason when nothing arrives in time.
|
|
90
|
+
|
|
91
|
+
--type <type> ${types}
|
|
92
|
+
--timeout <seconds> How long to wait (default 30)
|
|
93
|
+
--since <time> Only email after this time (ISO 8601). Default: the
|
|
94
|
+
last 15 minutes
|
|
95
|
+
--service <name> Only email from this service, by name or domain
|
|
96
|
+
--unused Only a ${kind} nobody has used yet${kind === 'link' ? '\n --app The link that opens a mobile app' : ''}
|
|
97
|
+
--site <host> The site the test started on, for the link check
|
|
98
|
+
--json The whole match as JSON`;
|
|
99
|
+
}
|
|
100
|
+
function FORM_USAGE() {
|
|
101
|
+
return `proxymail-qa form-values <file> [options]
|
|
102
|
+
|
|
103
|
+
What to type in each field of a form. The file is JSON: a list of fields
|
|
104
|
+
({ "id", "type", "name", "label", "autocomplete"… }) or { "fields": [...] }
|
|
105
|
+
with any of the options below. Use - to read it from standard input. Prints
|
|
106
|
+
JSON: the address, persona, password (when one was made) and a value per field.
|
|
107
|
+
|
|
108
|
+
--address <address> Fill for this address instead of making a new one
|
|
109
|
+
--site <host> The site, for custom fields set to one site
|
|
110
|
+
--page <path> The page, such as /signup
|
|
111
|
+
--screen <name> A native app screen, instead of page
|
|
112
|
+
--environment <env> staging, local…
|
|
113
|
+
--guess <mode> all, required or off, for fields nobody taught
|
|
114
|
+
--country <code> For a new address: where the persona lives
|
|
115
|
+
--age <band> For a new address: an age band
|
|
116
|
+
--dob <YYYY-MM-DD> For a new address: a date of birth
|
|
117
|
+
--one-name For a new address: one name only
|
|
118
|
+
--label, --domain, --days As for new`;
|
|
119
|
+
}
|
|
120
|
+
const HELP = (version) => `proxymail-qa ${version}: test inboxes for sign-up, login and password reset
|
|
121
|
+
|
|
122
|
+
proxymail-qa new [--password] [--country JP] Make a test address
|
|
123
|
+
proxymail-qa wait-code <address> Wait for its code
|
|
124
|
+
proxymail-qa wait-link <address> Wait for its link
|
|
125
|
+
proxymail-qa persona <address> Show its persona
|
|
126
|
+
proxymail-qa form-values <file> What to type in a form
|
|
127
|
+
|
|
128
|
+
proxymail-qa help <command> shows a command's options.
|
|
129
|
+
|
|
130
|
+
Set PROXYMAIL_QA_API_KEY to an API key from Project settings → API keys in
|
|
131
|
+
app.proxymail.qa. In a run (PROXYMAIL_QA_RUN, which the GitHub Action sets),
|
|
132
|
+
every call is added to the run's report.
|
|
133
|
+
|
|
134
|
+
More: https://proxymail.qa/docs/cli`;
|
|
135
|
+
class UsageError extends Error {
|
|
136
|
+
}
|
|
137
|
+
// A small parser, the same on every Node version: --flag, --flag value,
|
|
138
|
+
// --flag=value, and --no-flag for switches.
|
|
139
|
+
export function parseFlags(argv, spec) {
|
|
140
|
+
const parsed = { args: [], flags: {} };
|
|
141
|
+
for (let i = 0; i < argv.length; i++) {
|
|
142
|
+
const arg = argv[i];
|
|
143
|
+
if (arg === '--') {
|
|
144
|
+
parsed.args.push(...argv.slice(i + 1));
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
if (!arg.startsWith('--') || arg === '-') {
|
|
148
|
+
if (arg.startsWith('-') && arg !== '-')
|
|
149
|
+
throw new UsageError(`Unknown option ${arg}.`);
|
|
150
|
+
parsed.args.push(arg);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const [rawName, inline] = splitOnce(arg.slice(2), '=');
|
|
154
|
+
const negated = rawName.startsWith('no-') && spec[rawName.slice(3)] === 'boolean';
|
|
155
|
+
const name = negated ? rawName.slice(3) : rawName;
|
|
156
|
+
const kind = spec[name];
|
|
157
|
+
if (!kind)
|
|
158
|
+
throw new UsageError(`Unknown option --${rawName}.`);
|
|
159
|
+
if (kind === 'boolean') {
|
|
160
|
+
if (inline !== undefined)
|
|
161
|
+
throw new UsageError(`--${name} takes no value.`);
|
|
162
|
+
parsed.flags[name] = !negated;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const value = inline ?? argv[++i];
|
|
166
|
+
if (value === undefined || (inline === undefined && value.startsWith('--')))
|
|
167
|
+
throw new UsageError(`--${name} needs a value.`);
|
|
168
|
+
parsed.flags[name] = value;
|
|
169
|
+
}
|
|
170
|
+
return parsed;
|
|
171
|
+
}
|
|
172
|
+
function splitOnce(text, separator) {
|
|
173
|
+
const at = text.indexOf(separator);
|
|
174
|
+
return at < 0 ? [text, undefined] : [text.slice(0, at), text.slice(at + 1)];
|
|
175
|
+
}
|
|
176
|
+
const str = (flags, name) => (typeof flags[name] === 'string' ? flags[name] : undefined);
|
|
177
|
+
function int(flags, name) {
|
|
178
|
+
const value = str(flags, name);
|
|
179
|
+
if (value === undefined)
|
|
180
|
+
return undefined;
|
|
181
|
+
if (!/^\d+$/.test(value))
|
|
182
|
+
throw new UsageError(`--${name} takes a whole number.`);
|
|
183
|
+
return Number(value);
|
|
184
|
+
}
|
|
185
|
+
function since(flags) {
|
|
186
|
+
const value = str(flags, 'since');
|
|
187
|
+
if (value === undefined)
|
|
188
|
+
return undefined;
|
|
189
|
+
if (Number.isNaN(Date.parse(value)))
|
|
190
|
+
throw new UsageError('--since takes a date and time, such as 2026-11-13T18:00:00Z.');
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
// Labelled lines, the labels padded to one width.
|
|
194
|
+
function lines(rows) {
|
|
195
|
+
const shown = rows.filter((row) => row[1] !== null && row[1] !== undefined && row[1] !== '');
|
|
196
|
+
const width = Math.max(...shown.map(([label]) => label.length));
|
|
197
|
+
return shown.map(([label, value]) => `${label.padEnd(width)} ${value}`).join('\n');
|
|
198
|
+
}
|
|
199
|
+
function personaRows(persona) {
|
|
200
|
+
if (!persona)
|
|
201
|
+
return [];
|
|
202
|
+
return [
|
|
203
|
+
['First name', persona.first_name],
|
|
204
|
+
['Last name', persona.last_name],
|
|
205
|
+
['Username', persona.username],
|
|
206
|
+
['Date of birth', persona.date_of_birth],
|
|
207
|
+
['Country', persona.country],
|
|
208
|
+
];
|
|
209
|
+
}
|
|
210
|
+
function matchLines(match, kind) {
|
|
211
|
+
return lines([
|
|
212
|
+
[kind, match.value],
|
|
213
|
+
['From', match.service ?? match.service_domain],
|
|
214
|
+
['Expires', match.expires_at],
|
|
215
|
+
['Note', match.note],
|
|
216
|
+
['Link check', match.link_site?.status === 'fail' ? match.link_site.detail : undefined],
|
|
217
|
+
]);
|
|
218
|
+
}
|
|
219
|
+
function readFields(text, source) {
|
|
220
|
+
let data;
|
|
221
|
+
try {
|
|
222
|
+
data = JSON.parse(text);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
throw new UsageError(`${source} isn’t JSON: give a list of fields, or { "fields": [...] }.`);
|
|
226
|
+
}
|
|
227
|
+
if (Array.isArray(data))
|
|
228
|
+
return { fields: data, options: {} };
|
|
229
|
+
if (data && typeof data === 'object' && Array.isArray(data.fields)) {
|
|
230
|
+
const { fields, ...options } = data;
|
|
231
|
+
return { fields, options };
|
|
232
|
+
}
|
|
233
|
+
throw new UsageError(`${source} has no fields: give a list of fields, or { "fields": [...] }.`);
|
|
234
|
+
}
|
|
235
|
+
// Runs one command and returns the exit code: 0 done, 1 the API said no or
|
|
236
|
+
// nothing arrived, 2 the command was wrong.
|
|
237
|
+
export async function runCli(argv, io) {
|
|
238
|
+
const [command, ...rest] = argv;
|
|
239
|
+
if (command === undefined || command === 'help' || command === '--help' || command === '-h') {
|
|
240
|
+
const about = rest[0] && COMMANDS[rest[0]];
|
|
241
|
+
io.out(about ? about.usage : HELP(io.version));
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
if (command === '--version' || command === '-v') {
|
|
245
|
+
io.out(io.version);
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
const spec = COMMANDS[command];
|
|
249
|
+
if (!spec) {
|
|
250
|
+
io.err(`Unknown command ${command}.\n\n${HELP(io.version)}`);
|
|
251
|
+
return 2;
|
|
252
|
+
}
|
|
253
|
+
let parsed;
|
|
254
|
+
try {
|
|
255
|
+
if (rest.includes('--help') || rest.includes('-h')) {
|
|
256
|
+
io.out(spec.usage);
|
|
257
|
+
return 0;
|
|
258
|
+
}
|
|
259
|
+
parsed = parseFlags(rest, spec.flags);
|
|
260
|
+
if (parsed.args.length !== spec.args)
|
|
261
|
+
throw new UsageError(spec.args ? `${command} takes one ${command === 'form-values' ? 'file' : 'address'}.` : `${command} takes no arguments.`);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (!(error instanceof UsageError))
|
|
265
|
+
throw error;
|
|
266
|
+
io.err(`${error.message}\n\n${spec.usage}`);
|
|
267
|
+
return 2;
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
const make = io.client ?? ((options) => new ProxyMailQA(options));
|
|
271
|
+
const env = io.env;
|
|
272
|
+
if (!env.PROXYMAIL_QA_API_KEY) {
|
|
273
|
+
io.err('Set PROXYMAIL_QA_API_KEY to an API key from Project settings → API keys in app.proxymail.qa.');
|
|
274
|
+
return 2;
|
|
275
|
+
}
|
|
276
|
+
const qa = make({ apiKey: env.PROXYMAIL_QA_API_KEY });
|
|
277
|
+
const { args, flags } = parsed;
|
|
278
|
+
const json = flags.json === true;
|
|
279
|
+
const show = (value) => io.out(JSON.stringify(value, null, io.tty ? 2 : undefined));
|
|
280
|
+
if (command === 'new') {
|
|
281
|
+
const created = await qa.createAddress({
|
|
282
|
+
persona: flags.persona !== false,
|
|
283
|
+
password: flags.password === true || undefined,
|
|
284
|
+
country: str(flags, 'country')?.toUpperCase(),
|
|
285
|
+
age: str(flags, 'age'),
|
|
286
|
+
dateOfBirth: str(flags, 'dob'),
|
|
287
|
+
oneName: flags['one-name'] === true || undefined,
|
|
288
|
+
label: str(flags, 'label'),
|
|
289
|
+
name: str(flags, 'name'),
|
|
290
|
+
domain: str(flags, 'domain'),
|
|
291
|
+
lifetimeDays: int(flags, 'days'),
|
|
292
|
+
site: str(flags, 'site'),
|
|
293
|
+
environment: str(flags, 'environment'),
|
|
294
|
+
});
|
|
295
|
+
if (json)
|
|
296
|
+
show(created);
|
|
297
|
+
else if (io.tty)
|
|
298
|
+
io.out(lines([['Address', created.address], ['Password', created.password], ...personaRows(created.persona), ['Lasts until', created.expires_at]]));
|
|
299
|
+
else
|
|
300
|
+
io.out([created.address, created.password].filter(Boolean).join('\n'));
|
|
301
|
+
return 0;
|
|
302
|
+
}
|
|
303
|
+
if (command === 'wait-code' || command === 'wait-link') {
|
|
304
|
+
const options = {
|
|
305
|
+
timeout: int(flags, 'timeout'),
|
|
306
|
+
since: since(flags),
|
|
307
|
+
service: str(flags, 'service'),
|
|
308
|
+
unused: flags.unused === true || undefined,
|
|
309
|
+
expectSite: str(flags, 'site'),
|
|
310
|
+
};
|
|
311
|
+
const type = str(flags, 'type');
|
|
312
|
+
if (!io.tty && !json)
|
|
313
|
+
io.err(`Waiting for a ${command === 'wait-code' ? 'code' : 'link'}…`);
|
|
314
|
+
const match = command === 'wait-code'
|
|
315
|
+
? await qa.waitForCode(args[0], { ...options, type: type })
|
|
316
|
+
: await qa.waitForLink(args[0], {
|
|
317
|
+
...options,
|
|
318
|
+
type: type?.includes(',') ? type.split(',') : type,
|
|
319
|
+
app: flags.app === true || undefined,
|
|
320
|
+
});
|
|
321
|
+
if (json)
|
|
322
|
+
show(match);
|
|
323
|
+
else
|
|
324
|
+
io.out(io.tty ? matchLines(match, command === 'wait-code' ? 'Code' : 'Link') : match.value);
|
|
325
|
+
return 0;
|
|
326
|
+
}
|
|
327
|
+
if (command === 'persona') {
|
|
328
|
+
const address = await qa.getAddress(args[0]);
|
|
329
|
+
if (json)
|
|
330
|
+
show(address.persona);
|
|
331
|
+
else if (!address.persona)
|
|
332
|
+
io.out('No persona on this address.');
|
|
333
|
+
else
|
|
334
|
+
io.out(lines(personaRows(address.persona)));
|
|
335
|
+
return 0;
|
|
336
|
+
}
|
|
337
|
+
// form-values
|
|
338
|
+
const source = args[0];
|
|
339
|
+
const text = source === '-' ? await io.readStdin() : await io.readFile(source);
|
|
340
|
+
const { fields, options } = readFields(text, source === '-' ? 'Standard input' : source);
|
|
341
|
+
const values = await qa.formValues({
|
|
342
|
+
...options,
|
|
343
|
+
fields,
|
|
344
|
+
address: str(flags, 'address') ?? options.address,
|
|
345
|
+
site: str(flags, 'site') ?? options.site,
|
|
346
|
+
page: str(flags, 'page') ?? options.page,
|
|
347
|
+
screen: str(flags, 'screen') ?? options.screen,
|
|
348
|
+
environment: str(flags, 'environment') ?? options.environment,
|
|
349
|
+
guess: str(flags, 'guess') ?? options.guess,
|
|
350
|
+
country: str(flags, 'country')?.toUpperCase() ?? options.country,
|
|
351
|
+
age: str(flags, 'age') ?? options.age,
|
|
352
|
+
dateOfBirth: str(flags, 'dob') ?? options.dateOfBirth,
|
|
353
|
+
oneName: flags['one-name'] === true ? true : options.oneName,
|
|
354
|
+
label: str(flags, 'label') ?? options.label,
|
|
355
|
+
domain: str(flags, 'domain') ?? options.domain,
|
|
356
|
+
lifetimeDays: int(flags, 'days') ?? options.lifetimeDays,
|
|
357
|
+
});
|
|
358
|
+
show(values);
|
|
359
|
+
return 0;
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
if (error instanceof UsageError) {
|
|
363
|
+
io.err(`${error.message}\n\n${spec.usage}`);
|
|
364
|
+
return 2;
|
|
365
|
+
}
|
|
366
|
+
if (error instanceof ProxyMailQAError) {
|
|
367
|
+
io.err([error.message, error.help && `More: ${error.help}`].filter(Boolean).join('\n'));
|
|
368
|
+
return 1;
|
|
369
|
+
}
|
|
370
|
+
io.err(error instanceof Error ? error.message : String(error));
|
|
371
|
+
return 1;
|
|
372
|
+
}
|
|
373
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// npx proxymail-qa …: runs cli-main.ts with Node's process. The client has no
|
|
3
|
+
// Node types (it runs wherever fetch does), so this file names just the parts
|
|
4
|
+
// of process it uses.
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
import { runCli } from './cli-main.js';
|
|
7
|
+
const node = globalThis.process;
|
|
8
|
+
async function readStdin() {
|
|
9
|
+
const decoder = new TextDecoder();
|
|
10
|
+
let text = '';
|
|
11
|
+
for await (const chunk of node.stdin)
|
|
12
|
+
text += typeof chunk === 'string' ? chunk : decoder.decode(chunk, { stream: true });
|
|
13
|
+
return text + decoder.decode();
|
|
14
|
+
}
|
|
15
|
+
async function version() {
|
|
16
|
+
const meta = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
17
|
+
return meta.version;
|
|
18
|
+
}
|
|
19
|
+
node.exitCode = await runCli(node.argv.slice(2), {
|
|
20
|
+
env: node.env,
|
|
21
|
+
out: (text) => void node.stdout.write(`${text}\n`),
|
|
22
|
+
err: (text) => void node.stderr.write(`${text}\n`),
|
|
23
|
+
tty: node.stdout.isTTY === true,
|
|
24
|
+
readFile: (path) => readFile(path, 'utf8'),
|
|
25
|
+
readStdin,
|
|
26
|
+
version: await version(),
|
|
27
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const CYPRESS_METHODS: readonly ["project", "updateProject", "customFields", "saveCustomField", "deleteCustomField", "setCustomFieldEnabled", "setStandardField", "sites", "addSite", "setMultiStep", "saveSignupScreen", "removeSignupScreen", "createAddress", "formValues", "listAddresses", "signInAccount", "totpCode", "listFormSections", "signupStarters", "getFormSection", "followsFormat", "signupForms", "signupForm", "saveSignupForm", "deleteSignupForm", "signupFormCode", "signupFormTest", "cleanupList", "markDevHost", "getAddress", "checkOutAccount", "extendCheckout", "returnAccount", "updateAddress", "deleteAddress", "markSubmitted", "waitForCode", "waitForLink", "messages", "countEmails", "checkEmail", "expectNoEmail", "markUnsubscribed", "markResubscribed", "checkUnsubscribe", "consent", "recordConsent", "recordCouponResult", "checkSequence", "offers", "checkDelivery", "variants", "nameVariants", "passwordVariants", "flowChecks", "setPassword", "savedPassword", "getRun", "runReport", "listRuns", "addRunNote"];
|
|
2
|
+
export type CypressMethod = (typeof CYPRESS_METHODS)[number];
|
|
3
|
+
export declare const NOT_IN_CYPRESS: readonly ["forTest", "withAccount", "startRun", "finishRun", "recordTest", "recordTestTotals"];
|
|
4
|
+
export declare const CYPRESS_TASK = "proxymail-qa";
|
|
5
|
+
export interface CypressTaskCall {
|
|
6
|
+
method: string;
|
|
7
|
+
args: unknown[];
|
|
8
|
+
test?: string | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// The client methods cy.proxymail has (FM-15): every public method except
|
|
2
|
+
// forTest (each command already names its test), withAccount (its hooks are
|
|
3
|
+
// functions, which can't cross from the browser to Node), and a run's start,
|
|
4
|
+
// finish and results, which belong to the CI job or setupNodeEvents.
|
|
5
|
+
export const CYPRESS_METHODS = [
|
|
6
|
+
'project',
|
|
7
|
+
'updateProject',
|
|
8
|
+
'customFields',
|
|
9
|
+
'saveCustomField',
|
|
10
|
+
'deleteCustomField',
|
|
11
|
+
'setCustomFieldEnabled',
|
|
12
|
+
'setStandardField',
|
|
13
|
+
'sites',
|
|
14
|
+
'addSite',
|
|
15
|
+
'setMultiStep',
|
|
16
|
+
'saveSignupScreen',
|
|
17
|
+
'removeSignupScreen',
|
|
18
|
+
'createAddress',
|
|
19
|
+
'formValues',
|
|
20
|
+
'listAddresses',
|
|
21
|
+
'signInAccount',
|
|
22
|
+
'totpCode',
|
|
23
|
+
'listFormSections',
|
|
24
|
+
'signupStarters',
|
|
25
|
+
'getFormSection',
|
|
26
|
+
'followsFormat',
|
|
27
|
+
'signupForms',
|
|
28
|
+
'signupForm',
|
|
29
|
+
'saveSignupForm',
|
|
30
|
+
'deleteSignupForm',
|
|
31
|
+
'signupFormCode',
|
|
32
|
+
'signupFormTest',
|
|
33
|
+
'cleanupList',
|
|
34
|
+
'markDevHost',
|
|
35
|
+
'getAddress',
|
|
36
|
+
'checkOutAccount',
|
|
37
|
+
'extendCheckout',
|
|
38
|
+
'returnAccount',
|
|
39
|
+
'updateAddress',
|
|
40
|
+
'deleteAddress',
|
|
41
|
+
'markSubmitted',
|
|
42
|
+
'waitForCode',
|
|
43
|
+
'waitForLink',
|
|
44
|
+
'messages',
|
|
45
|
+
'countEmails',
|
|
46
|
+
'checkEmail',
|
|
47
|
+
'expectNoEmail',
|
|
48
|
+
'markUnsubscribed',
|
|
49
|
+
'markResubscribed',
|
|
50
|
+
'checkUnsubscribe',
|
|
51
|
+
'consent',
|
|
52
|
+
'recordConsent',
|
|
53
|
+
'recordCouponResult',
|
|
54
|
+
'checkSequence',
|
|
55
|
+
'offers',
|
|
56
|
+
'checkDelivery',
|
|
57
|
+
'variants',
|
|
58
|
+
'nameVariants',
|
|
59
|
+
'passwordVariants',
|
|
60
|
+
'flowChecks',
|
|
61
|
+
'setPassword',
|
|
62
|
+
'savedPassword',
|
|
63
|
+
'getRun',
|
|
64
|
+
'runReport',
|
|
65
|
+
'listRuns',
|
|
66
|
+
'addRunNote',
|
|
67
|
+
];
|
|
68
|
+
// Left out on purpose; a test checks every public method is in one list.
|
|
69
|
+
export const NOT_IN_CYPRESS = ['forTest', 'withAccount', 'startRun', 'finishRun', 'recordTest', 'recordTestTotals'];
|
|
70
|
+
// The task setupProxyMailQA registers and cy.proxymail calls.
|
|
71
|
+
export const CYPRESS_TASK = 'proxymail-qa';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CypressTaskCall } from './cypress-methods.js';
|
|
2
|
+
import { type ClientOptions } from './index.js';
|
|
3
|
+
export type CypressOn = (event: 'task', tasks: Record<string, (arg: CypressTaskCall) => unknown>) => void;
|
|
4
|
+
export declare function setupProxyMailQA(on: CypressOn, options?: ClientOptions): void;
|