proxymail-qa 0.9.0 → 0.10.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 CHANGED
@@ -1,8 +1,30 @@
1
1
  # proxymail-qa
2
2
 
3
- Disposable test inboxes for Playwright, Cypress and scripts. Create an address,
4
- sign up with it in the app you're testing, and get the verification code or
5
- link from the email in one call that waits for it.
3
+ Test the emails your app sends, end to end, from Playwright, Cypress,
4
+ Puppeteer, Jest, Vitest or any Node script. Create a disposable address, sign
5
+ up with it, and get the verification code or link in one call that waits for
6
+ it. Then:
7
+
8
+ - check an email was sent exactly once, or not at all
9
+ - check each email: SPF, DKIM and DMARC, links to localhost or the wrong host,
10
+ a stated expiry, plain text, language and phone layout
11
+ - sign up with a test persona (name, date of birth, country) and a saved
12
+ password, or an unusual address variant
13
+ - borrow a verified test account for sign-in tests and give it back
14
+ - wait for a coupon, record whether checkout took it, and catch an offer
15
+ given twice to versions of one address
16
+ - test unsubscribing: any marketing email from that sender afterwards fails
17
+ - check marketing emails: unsubscribe headers, a spam score and the consent
18
+ rules where the persona lives
19
+ - check a welcome series or drip campaign came in order and on time
20
+ - find out why an email didn't arrive
21
+ - group tests into a run whose report says which test each email came from
22
+
23
+ Checkout results, offers given twice, unsubscribing, consent, welcome series,
24
+ the marketing checks and the spam score are in
25
+ [Labs](https://proxymail.qa/docs/labs) for now: the key's creator switches
26
+ them on in the app under Account settings → Labs. Until then those methods
27
+ throw with a 403 that says so, and `checkEmail` leaves those checks out.
6
28
 
7
29
  Get an API key in [app.proxymail.qa](https://app.proxymail.qa) → Project
8
30
  settings → API keys (the Free plan includes it), and set it as
@@ -111,6 +133,10 @@ const [teen] = await qa.listAddresses({ tags: ['age-gate'], country: 'GB', maxAg
111
133
  // its password (needs a key with "Can read saved passwords"); null if none fits.
112
134
  const account = await qa.signInAccount({ site: 'staging.example.com', tags: ['verified'] });
113
135
 
136
+ // How many addresses this project can still create: Free has 500 in total
137
+ // and 50 a day (limit null on Team). Past it, createAddress throws a 402.
138
+ const { addresses } = await qa.project();
139
+
114
140
  // Testing on localhost? Links to it then pass checkEmail's local-links check.
115
141
  await qa.markDevHost('localhost:3000');
116
142
 
@@ -159,6 +185,18 @@ await qa.withAccount(
159
185
  },
160
186
  );
161
187
 
188
+ // Offers (Labs): wait for the coupon (offers can take minutes), apply it at
189
+ // checkout on staging with test payments, then record what the app said.
190
+ const coupon = await qa.waitForCode(address, { type: 'coupon', timeout: 600 });
191
+ await qa.recordCouponResult(address, 'accepted', { code: coupon.value });
192
+
193
+ // Unsubscribing (Labs): after the test unsubscribes in the app (Proxy Mail
194
+ // QA never opens the link), marketing from that sender fails; receipts can
195
+ // still come.
196
+ await qa.markUnsubscribed(address);
197
+ await qa.expectNoEmail(address, { category: 'marketing', since: new Date(), timeout: 300 });
198
+ const { passed } = await qa.checkUnsubscribe(address);
199
+
162
200
  // A run: this client's calls add what they saw, for a report on the pull
163
201
  // request. In GitHub Actions, the Proxy Mail QA action does this for you and
164
202
  // the client picks the run up from PROXYMAIL_QA_RUN.
package/dist/index.d.ts CHANGED
@@ -80,7 +80,7 @@ export interface FormValuesOptions extends Omit<CreateAddressInput, 'password' |
80
80
  }
81
81
  export interface FormValue {
82
82
  id: string;
83
- kind: 'email' | 'confirm_email' | 'first_name' | 'last_name' | 'full_name' | 'username' | 'password' | 'confirm_password' | 'date_of_birth' | 'birth_day' | 'birth_month' | 'birth_year' | 'country' | 'other';
83
+ kind: 'email' | 'confirm_email' | 'first_name' | 'last_name' | 'full_name' | 'username' | 'password' | 'confirm_password' | 'date_of_birth' | 'birth_day' | 'birth_month' | 'birth_year' | 'country' | 'marketing_consent' | 'other';
84
84
  value: string | null;
85
85
  note?: string;
86
86
  }
@@ -126,6 +126,9 @@ export interface Match {
126
126
  received_at: string;
127
127
  expires_at: string | null;
128
128
  email_id: string;
129
+ after_seconds?: number;
130
+ discount?: string | null;
131
+ valid_until?: string | null;
129
132
  }
130
133
  export interface CreateAddressInput {
131
134
  label?: string;
@@ -196,7 +199,8 @@ export interface WaitOptions {
196
199
  since?: Date | string;
197
200
  unused?: boolean;
198
201
  }
199
- export type LinkType = 'verify' | 'magic_signin' | 'invite' | 'reset' | 'any';
202
+ export type CodeType = 'otp' | 'coupon' | 'any';
203
+ export type LinkType = 'verify' | 'magic_signin' | 'invite' | 'reset' | 'unsubscribe' | 'list_unsubscribe' | 'any';
200
204
  export interface EmailSummary {
201
205
  received_at: string;
202
206
  service: string | null;
@@ -204,6 +208,16 @@ export interface EmailSummary {
204
208
  type: 'code' | 'link' | null;
205
209
  subtype: string | null;
206
210
  email_id: string;
211
+ after_seconds?: number;
212
+ category?: EmailCategory | null;
213
+ gap_seconds?: number | null;
214
+ attachments?: Array<{
215
+ type: string;
216
+ extension?: string;
217
+ size: number;
218
+ method?: string;
219
+ }>;
220
+ attachment_count?: number | null;
207
221
  }
208
222
  export interface EmailCount {
209
223
  address: string;
@@ -216,13 +230,114 @@ export interface CountOptions {
216
230
  service?: string;
217
231
  type?: 'code' | 'link';
218
232
  subtype?: CountSubtype | CountSubtype[];
233
+ category?: EmailCategory;
219
234
  }
220
- export type CountSubtype = 'otp' | 'coupon' | 'verify' | 'magic_signin' | 'invite' | 'reset' | 'other' | 'any';
221
- export type CheckId = 'spf' | 'dkim' | 'dmarc' | 'local_links' | 'plain_http' | 'expected_host' | 'expiry' | 'plain_text' | 'size' | 'images_only' | 'layout' | 'expected_text' | 'language';
235
+ export type EmailCategory = 'auth' | 'transactional' | 'marketing';
236
+ export type CountSubtype = 'otp' | 'coupon' | 'verify' | 'magic_signin' | 'invite' | 'reset' | 'other' | 'unsubscribe' | 'list_unsubscribe' | 'any';
237
+ export type CheckId = 'spf' | 'dkim' | 'dmarc' | 'local_links' | 'plain_http' | 'expected_host' | 'expiry' | 'coupon_expiry' | 'plain_text' | 'size' | 'images_only' | 'layout' | 'expected_text' | 'language' | 'arrival_time' | 'expected_attachment' | 'list_unsubscribe' | 'one_click_unsubscribe' | 'unsubscribe_link' | 'preheader' | 'after_unsubscribe' | 'offer_reuse' | 'coupon_result' | 'marketing_consent' | 'prechecked_consent' | 'double_opt_in' | 'unsubscribe_deadline' | 'postal_address' | 'sender_identity' | 'minor_marketing' | 'harmful_attachment' | 'spam_risk' | 'misleading_subject' | 'ad_label';
222
238
  export interface EmailCheck {
223
239
  check: CheckId;
224
240
  status: 'pass' | 'fail' | 'warn' | 'skip';
225
241
  detail: string;
242
+ score?: number;
243
+ markers?: Array<{
244
+ id: string;
245
+ points: number;
246
+ }>;
247
+ }
248
+ export interface UnsubscribeWatch {
249
+ id: string;
250
+ sender: string;
251
+ service: string | null;
252
+ unsubscribed_at: string;
253
+ via: 'app' | 'extension' | 'agent' | 'api';
254
+ grace_seconds?: number;
255
+ watching: boolean;
256
+ ended_at: string | null;
257
+ after_unsubscribe: Array<{
258
+ email_id: string;
259
+ received_at: string;
260
+ after_seconds: number;
261
+ }>;
262
+ }
263
+ export interface Consent {
264
+ address: string;
265
+ marketing: 'opted_in' | 'declined' | null;
266
+ prechecked: boolean | null;
267
+ at: string | null;
268
+ double_opt_in: 'confirmed' | 'pending' | null;
269
+ double_opt_in_at: string | null;
270
+ via: string | null;
271
+ country: string | null;
272
+ }
273
+ export interface CouponResults {
274
+ code: string;
275
+ email_id: string;
276
+ discount: string | null;
277
+ valid_until: string | null;
278
+ results: Array<{
279
+ result: 'accepted' | 'rejected' | 'error';
280
+ message: string | null;
281
+ discount_applied: string | null;
282
+ one_time: boolean;
283
+ at: string;
284
+ via: string;
285
+ }>;
286
+ check: EmailCheck | null;
287
+ }
288
+ export interface SequenceStep {
289
+ subject?: string;
290
+ category?: EmailCategory;
291
+ type?: 'code' | 'link';
292
+ after?: string | number;
293
+ within?: string | number;
294
+ }
295
+ export interface SequenceResult {
296
+ address: string;
297
+ since: string;
298
+ passed: boolean;
299
+ done: boolean;
300
+ steps: Array<{
301
+ step: number;
302
+ status: 'pass' | 'early' | 'late' | 'missing' | 'waiting';
303
+ email_id: string | null;
304
+ received_at: string | null;
305
+ expected_at: string | null;
306
+ off_seconds: number | null;
307
+ detail: string;
308
+ }>;
309
+ }
310
+ export interface Offers {
311
+ address: string;
312
+ passed: boolean;
313
+ offers: Array<{
314
+ sender: string;
315
+ service: string | null;
316
+ reused: boolean;
317
+ variants: string[];
318
+ same_code: boolean;
319
+ coupons: Array<{
320
+ variant: string;
321
+ code: string;
322
+ discount: string | null;
323
+ valid_until: string | null;
324
+ received_at: string;
325
+ email_id: string;
326
+ }>;
327
+ }>;
328
+ }
329
+ export interface AddressAllowance {
330
+ limited: boolean;
331
+ used: number;
332
+ limit: number | null;
333
+ left: number | null;
334
+ today: number;
335
+ per_day_limit: number | null;
336
+ }
337
+ export interface UnsubscribeStatus {
338
+ address: string;
339
+ passed: boolean;
340
+ watches: UnsubscribeWatch[];
226
341
  }
227
342
  export interface EmailChecks {
228
343
  address: string;
@@ -244,6 +359,8 @@ export interface CheckOptions extends CountOptions {
244
359
  expectHost?: string;
245
360
  expectText?: string[];
246
361
  expectLanguage?: string;
362
+ expectWithin?: number | string;
363
+ expectAttachment?: string[];
247
364
  }
248
365
  export interface NoEmail {
249
366
  address: string;
@@ -298,7 +415,18 @@ export declare class ProxyMailQA {
298
415
  constructor(options?: ClientOptions);
299
416
  forTest(name: string): ProxyMailQA;
300
417
  private request;
301
- project(): Promise<Record<string, unknown>>;
418
+ project(): Promise<Record<string, unknown> & {
419
+ addresses?: AddressAllowance;
420
+ }>;
421
+ updateProject(patch: {
422
+ name?: string;
423
+ website?: string | null;
424
+ environments?: string[];
425
+ emailPrefix?: string | null;
426
+ mailDomain?: string;
427
+ }): Promise<Record<string, unknown> & {
428
+ addresses?: AddressAllowance;
429
+ }>;
302
430
  createAddress(input: CreateAddressInput & {
303
431
  password: true;
304
432
  }): Promise<CreatedAddressWithPassword>;
@@ -327,7 +455,9 @@ export declare class ProxyMailQA {
327
455
  private note;
328
456
  updateAddress(address: string, patch: AddressPatch): Promise<Address>;
329
457
  deleteAddress(address: string): Promise<void>;
330
- waitForCode(address: string, options?: WaitOptions): Promise<Match>;
458
+ waitForCode(address: string, options?: WaitOptions & {
459
+ type?: CodeType;
460
+ }): Promise<Match>;
331
461
  waitForLink(address: string, options?: WaitOptions & {
332
462
  type?: LinkType | LinkType[];
333
463
  app?: boolean;
@@ -342,6 +472,36 @@ export declare class ProxyMailQA {
342
472
  expectNoEmail(address: string, options?: CountOptions & {
343
473
  timeout?: number;
344
474
  }): Promise<NoEmail>;
475
+ markUnsubscribed(address: string, options?: {
476
+ emailId?: string;
477
+ service?: string;
478
+ at?: Date | string;
479
+ grace?: string | number;
480
+ }): Promise<UnsubscribeWatch>;
481
+ markResubscribed(address: string, options?: {
482
+ emailId?: string;
483
+ service?: string;
484
+ }): Promise<UnsubscribeWatch>;
485
+ checkUnsubscribe(address: string): Promise<UnsubscribeStatus>;
486
+ recordConsent(address: string, consent: {
487
+ marketing?: 'opted_in' | 'declined' | null;
488
+ prechecked?: boolean;
489
+ doubleOptIn?: 'confirmed' | 'pending' | null;
490
+ at?: Date | string;
491
+ }): Promise<Consent>;
492
+ consent(address: string): Promise<Consent>;
493
+ recordCouponResult(address: string, result: 'accepted' | 'rejected' | 'error', options?: {
494
+ code?: string;
495
+ emailId?: string;
496
+ message?: string;
497
+ oneTime?: boolean;
498
+ discountApplied?: string;
499
+ at?: Date | string;
500
+ }): Promise<CouponResults>;
501
+ checkSequence(address: string, steps: SequenceStep[], options?: {
502
+ since?: Date | string;
503
+ }): Promise<SequenceResult>;
504
+ offers(address: string): Promise<Offers>;
345
505
  checkDelivery(address: string): Promise<DeliveryStatus>;
346
506
  variants(address: string): Promise<Variants>;
347
507
  setPassword(address: string, options: {
package/dist/index.js CHANGED
@@ -33,6 +33,8 @@ function countQuery(options, extra = {}) {
33
33
  const subtype = [options.subtype ?? []].flat().join(',');
34
34
  if (subtype)
35
35
  query.set('subtype', subtype);
36
+ if (options.category)
37
+ query.set('category', options.category);
36
38
  return query.size ? `?${query}` : '';
37
39
  }
38
40
  const MAX_WAIT_SECONDS = 30;
@@ -86,9 +88,26 @@ export class ProxyMailQA {
86
88
  }
87
89
  return payload;
88
90
  }
91
+ // The key's project: its mail domains, prefix and limits. addresses says
92
+ // 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 it, createAddress
94
+ // throws ProxyMailQAError with status 402 and code plan_required.
89
95
  project() {
90
96
  return this.request('GET', '/project');
91
97
  }
98
+ // Changes the key's project, as in Project settings: its name, website,
99
+ // environments, email prefix or default mail domain (one of project()'s
100
+ // mail_domains). Only the fields given change; null clears website or
101
+ // emailPrefix. Needs the project's lead (or an organisation owner or
102
+ // admin), and is in the project's activity log.
103
+ updateProject(patch) {
104
+ const { emailPrefix, mailDomain, ...rest } = patch;
105
+ return this.request('PATCH', '/project', {
106
+ ...rest,
107
+ ...(emailPrefix !== undefined ? { email_prefix: emailPrefix } : {}),
108
+ ...(mailDomain !== undefined ? { mail_domain: mailDomain } : {}),
109
+ });
110
+ }
92
111
  createAddress(input = {}) {
93
112
  return this.request('POST', '/addresses', {
94
113
  label: input.label,
@@ -358,8 +377,12 @@ export class ProxyMailQA {
358
377
  }
359
378
  // Waits for a verification or login code; throws ProxyMailQAError (404) if
360
379
  // none arrives in time.
380
+ // The newest sign-in or verification code; with type: 'coupon', the
381
+ // newest coupon or promo code, with its discount and valid-until date when
382
+ // the email states them. Offers often come minutes later: give a longer
383
+ // timeout (it repeats the request).
361
384
  waitForCode(address, options = {}) {
362
- return this.wait(address, 'code', options);
385
+ return this.wait(address, 'code', options, options.type && options.type !== 'otp' ? options.type : '');
363
386
  }
364
387
  // Waits for a verify, magic sign-in, invite or reset link. When an email has
365
388
  // both a web link and one that opens a mobile app (myapp://…), the web link
@@ -400,9 +423,13 @@ export class ProxyMailQA {
400
423
  extra.expect_host = options.expectHost;
401
424
  if (options.expectLanguage)
402
425
  extra.expect_language = options.expectLanguage;
426
+ if (options.expectWithin !== undefined)
427
+ extra.expect_within = String(options.expectWithin);
403
428
  let query = countQuery(options, extra);
404
429
  for (const phrase of options.expectText ?? [])
405
430
  query += `${query ? '&' : '?'}expect_text=${encodeURIComponent(phrase)}`;
431
+ for (const pattern of options.expectAttachment ?? [])
432
+ query += `${query ? '&' : '?'}expect_attachment=${encodeURIComponent(pattern)}`;
406
433
  return this.request('GET', `/addresses/${encodeURIComponent(address)}/checks${query}`);
407
434
  }
408
435
  // Resolves when no matching email arrives within timeout seconds (default
@@ -425,6 +452,80 @@ export class ProxyMailQA {
425
452
  return { address: result.address, since: result.since, until: result.until };
426
453
  }
427
454
  }
455
+ // markUnsubscribed to offers below are Marketing and offer emails, in Labs:
456
+ // the key's creator switches it on in Account settings → Labs. Until then
457
+ // they throw a 403 that says so.
458
+ // Records that the address unsubscribed from a sender, after the test did
459
+ // it in its own browser (Proxy Mail QA never opens unsubscribe links). Any
460
+ // later marketing email from that sender fails after_unsubscribe, however
461
+ // long after. Name the sender with emailId or service (a name or domain);
462
+ // with neither, the newest marketing email decides. at backdates it.
463
+ // grace ('2h', '1d', or seconds; up to 30 days): marketing within it after
464
+ // unsubscribing doesn't count, for mail already on its way.
465
+ markUnsubscribed(address, options = {}) {
466
+ return this.request('POST', `/addresses/${encodeURIComponent(address)}/unsubscribed`, {
467
+ email_id: options.emailId,
468
+ service: options.service,
469
+ at: options.at instanceof Date ? options.at.toISOString() : options.at,
470
+ grace: options.grace,
471
+ });
472
+ }
473
+ // The address subscribed again: ends the watch for that sender (the only
474
+ // one, when there's one).
475
+ markResubscribed(address, options = {}) {
476
+ const query = new URLSearchParams({ ...(options.service ? { service: options.service } : {}), ...(options.emailId ? { email_id: options.emailId } : {}) });
477
+ return this.request('DELETE', `/addresses/${encodeURIComponent(address)}/unsubscribed${query.size ? `?${query}` : ''}`);
478
+ }
479
+ // Each unsubscribe and the marketing emails that came after it, by id and
480
+ // how long after; passed is false when any came.
481
+ checkUnsubscribe(address) {
482
+ return this.request('GET', `/addresses/${encodeURIComponent(address)}/unsubscribed`);
483
+ }
484
+ // Records what the address agreed to at sign-up: marketing (opted_in or
485
+ // declined), prechecked (the box was ticked when the form loaded) and
486
+ // doubleOptIn (confirmed or pending). Only what's given changes. checkEmail
487
+ // then judges marketing email by the rules where the persona lives.
488
+ recordConsent(address, consent) {
489
+ return this.request('PUT', `/addresses/${encodeURIComponent(address)}/consent`, {
490
+ marketing: consent.marketing,
491
+ prechecked: consent.prechecked,
492
+ double_opt_in: consent.doubleOptIn,
493
+ at: consent.at instanceof Date ? consent.at.toISOString() : consent.at,
494
+ });
495
+ }
496
+ consent(address) {
497
+ return this.request('GET', `/addresses/${encodeURIComponent(address)}/consent`);
498
+ }
499
+ // After applying a coupon at checkout (on staging with test payments: never
500
+ // real card details), records what the app did: accepted, rejected or an
501
+ // error, with its message. The answer's check is the coupon_result verdict:
502
+ // it fails a coupon accepted after its end date, for an offer already given
503
+ // to another version of the address, or twice when oneTime.
504
+ recordCouponResult(address, result, options = {}) {
505
+ return this.request('POST', `/addresses/${encodeURIComponent(address)}/coupon-result`, {
506
+ result,
507
+ code: options.code,
508
+ email_id: options.emailId,
509
+ message: options.message,
510
+ one_time: options.oneTime,
511
+ discount_applied: options.discountApplied,
512
+ at: options.at instanceof Date ? options.at.toISOString() : options.at,
513
+ });
514
+ }
515
+ // Whether a welcome series or drip campaign came in order and on time after
516
+ // since: each step answers pass, early, late, missing or waiting.
517
+ checkSequence(address, steps, options = {}) {
518
+ return this.request('POST', `/addresses/${encodeURIComponent(address)}/sequence`, {
519
+ steps,
520
+ since: options.since instanceof Date ? options.since.toISOString() : options.since,
521
+ });
522
+ }
523
+ // Each sender's coupons and which version of the address each went to.
524
+ // Mail to name+promo1@… and NAME@… reaches one inbox, so passed is false
525
+ // when an offer reached two or more of them: one person got it twice.
526
+ offers(address) {
527
+ return this.request('GET', `/addresses/${encodeURIComponent(address)}/offers`);
528
+ }
428
529
  // What reached the address and what was refused, without waiting: for when
429
530
  // a wait comes back empty.
430
531
  checkDelivery(address) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "proxymail-qa",
3
- "version": "0.9.0",
4
- "description": "Disposable test inboxes for Playwright, Cypress and scripts: create an address, then wait for its verification code or link.",
3
+ "version": "0.10.0",
4
+ "description": "Test every email your app sends from Playwright, Cypress, Jest, Vitest or any Node script: 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",
@@ -20,6 +20,18 @@
20
20
  "email verification",
21
21
  "playwright",
22
22
  "cypress",
23
+ "puppeteer",
24
+ "jest",
25
+ "vitest",
26
+ "e2e",
27
+ "end-to-end testing",
28
+ "email deliverability",
29
+ "spf",
30
+ "dkim",
31
+ "test accounts",
32
+ "coupon",
33
+ "unsubscribe",
34
+ "marketing email",
23
35
  "qa"
24
36
  ],
25
37
  "type": "module",