@mailpier/inbox 0.0.0-stage → 0.1.1
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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +159 -2
- package/dist/chunk-2NMZ2IWD.js +524 -0
- package/dist/cli.cjs +751 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +244 -0
- package/dist/client-DD8Tr4-3.d.cts +415 -0
- package/dist/client-DD8Tr4-3.d.ts +415 -0
- package/dist/cypress/commands.cjs +94 -0
- package/dist/cypress/commands.d.cts +58 -0
- package/dist/cypress/commands.d.ts +58 -0
- package/dist/cypress/commands.js +68 -0
- package/dist/cypress/index.cjs +575 -0
- package/dist/cypress/index.d.cts +47 -0
- package/dist/cypress/index.d.ts +47 -0
- package/dist/cypress/index.js +40 -0
- package/dist/index.cjs +557 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +22 -0
- package/dist/playwright.cjs +639 -0
- package/dist/playwright.d.cts +65 -0
- package/dist/playwright.d.ts +65 -0
- package/dist/playwright.js +104 -0
- package/dist/testing/index.cjs +683 -0
- package/dist/testing/index.d.cts +106 -0
- package/dist/testing/index.d.ts +106 -0
- package/dist/testing/index.js +654 -0
- package/package.json +112 -4
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as _playwright_test from '@playwright/test';
|
|
2
|
+
import { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
|
|
3
|
+
export { expect } from '@playwright/test';
|
|
4
|
+
import { MailPierInbox, NewAddressOptions, InboxMessage, WebhookUrl, WebhookRequest, MailPierInboxOptions } from './index.cjs';
|
|
5
|
+
|
|
6
|
+
interface InboxWaitOptions {
|
|
7
|
+
/** Only a mail whose subject contains this (case-insensitive). */
|
|
8
|
+
subjectContains?: string;
|
|
9
|
+
/** Default 60000. */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
interface WebhookWaitOptions {
|
|
13
|
+
/** Only this method (case-insensitive). */
|
|
14
|
+
method?: string;
|
|
15
|
+
/** Default 60. */
|
|
16
|
+
timeoutSeconds?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The `inbox` fixture. Every address it hands out remembers when it was made, so a wait only returns mail sent after that
|
|
20
|
+
* (an old mail to a reused address is never picked up by mistake).
|
|
21
|
+
*/
|
|
22
|
+
declare class PlaywrightInbox {
|
|
23
|
+
/** The underlying client, for anything else (listMessages, getRaw, getAttachment ...). */
|
|
24
|
+
readonly client: MailPierInbox;
|
|
25
|
+
private readonly created;
|
|
26
|
+
private readonly lastSeen;
|
|
27
|
+
private readonly lastWebhook;
|
|
28
|
+
private readonly started;
|
|
29
|
+
constructor(client: MailPierInbox);
|
|
30
|
+
/** A fresh address of the key's environment. */
|
|
31
|
+
newAddress(options?: NewAddressOptions): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Waits for the next mail to `address`: the first call returns the first mail since newAddress(), each later call the mail
|
|
34
|
+
* after the one returned before.
|
|
35
|
+
*/
|
|
36
|
+
waitForMessage(address: string, options?: InboxWaitOptions): Promise<InboxMessage>;
|
|
37
|
+
/** Waits for the next mail to `address` and returns its one-time code; throws when the mail has none. */
|
|
38
|
+
waitForCode(address: string, options?: InboxWaitOptions): Promise<string>;
|
|
39
|
+
/** Waits for the next mail to `address` and returns its first link containing `contains` (any link when omitted). */
|
|
40
|
+
waitForLink(address: string, contains?: string, options?: InboxWaitOptions): Promise<string>;
|
|
41
|
+
/** The webhook catch URL with a fresh random path: give `url` to your app, then `waitForWebhook(path)`. */
|
|
42
|
+
createWebhookUrl(): Promise<WebhookUrl>;
|
|
43
|
+
/**
|
|
44
|
+
* Waits for the next request to the catch URL whose path starts with `path`: the first call returns the first one since this
|
|
45
|
+
* fixture started (an old request to a fixed path like "/stripe" is never picked up), each later call the one after it.
|
|
46
|
+
*/
|
|
47
|
+
waitForWebhook(path: string, options?: WebhookWaitOptions): Promise<WebhookRequest>;
|
|
48
|
+
/** Addresses handed out by this fixture instance. */
|
|
49
|
+
get addresses(): string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface MailPierFixtures {
|
|
53
|
+
inbox: PlaywrightInbox;
|
|
54
|
+
/** Client options (apiKey, baseUrl ...); default from MAILPIER_API_KEY / MAILPIER_BASE_URL. Set with test.use(). */
|
|
55
|
+
mailpierOptions: MailPierInboxOptions;
|
|
56
|
+
/** Delete the mail of every address the test created when it ends. Default false. */
|
|
57
|
+
mailpierCleanup: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** The fixtures, to merge into your own test: `base.extend<MailPierFixtures>(mailpierFixtures)`. */
|
|
60
|
+
declare const mailpierFixtures: Fixtures<MailPierFixtures, object, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
61
|
+
/** Playwright's `test` with the `inbox` fixture. */
|
|
62
|
+
declare const test: _playwright_test.TestType<PlaywrightTestArgs & PlaywrightTestOptions & MailPierFixtures, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
63
|
+
|
|
64
|
+
export { PlaywrightInbox, mailpierFixtures, test };
|
|
65
|
+
export type { InboxWaitOptions, MailPierFixtures, WebhookWaitOptions };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as _playwright_test from '@playwright/test';
|
|
2
|
+
import { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
|
|
3
|
+
export { expect } from '@playwright/test';
|
|
4
|
+
import { MailPierInbox, NewAddressOptions, InboxMessage, WebhookUrl, WebhookRequest, MailPierInboxOptions } from './index.js';
|
|
5
|
+
|
|
6
|
+
interface InboxWaitOptions {
|
|
7
|
+
/** Only a mail whose subject contains this (case-insensitive). */
|
|
8
|
+
subjectContains?: string;
|
|
9
|
+
/** Default 60000. */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
interface WebhookWaitOptions {
|
|
13
|
+
/** Only this method (case-insensitive). */
|
|
14
|
+
method?: string;
|
|
15
|
+
/** Default 60. */
|
|
16
|
+
timeoutSeconds?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The `inbox` fixture. Every address it hands out remembers when it was made, so a wait only returns mail sent after that
|
|
20
|
+
* (an old mail to a reused address is never picked up by mistake).
|
|
21
|
+
*/
|
|
22
|
+
declare class PlaywrightInbox {
|
|
23
|
+
/** The underlying client, for anything else (listMessages, getRaw, getAttachment ...). */
|
|
24
|
+
readonly client: MailPierInbox;
|
|
25
|
+
private readonly created;
|
|
26
|
+
private readonly lastSeen;
|
|
27
|
+
private readonly lastWebhook;
|
|
28
|
+
private readonly started;
|
|
29
|
+
constructor(client: MailPierInbox);
|
|
30
|
+
/** A fresh address of the key's environment. */
|
|
31
|
+
newAddress(options?: NewAddressOptions): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Waits for the next mail to `address`: the first call returns the first mail since newAddress(), each later call the mail
|
|
34
|
+
* after the one returned before.
|
|
35
|
+
*/
|
|
36
|
+
waitForMessage(address: string, options?: InboxWaitOptions): Promise<InboxMessage>;
|
|
37
|
+
/** Waits for the next mail to `address` and returns its one-time code; throws when the mail has none. */
|
|
38
|
+
waitForCode(address: string, options?: InboxWaitOptions): Promise<string>;
|
|
39
|
+
/** Waits for the next mail to `address` and returns its first link containing `contains` (any link when omitted). */
|
|
40
|
+
waitForLink(address: string, contains?: string, options?: InboxWaitOptions): Promise<string>;
|
|
41
|
+
/** The webhook catch URL with a fresh random path: give `url` to your app, then `waitForWebhook(path)`. */
|
|
42
|
+
createWebhookUrl(): Promise<WebhookUrl>;
|
|
43
|
+
/**
|
|
44
|
+
* Waits for the next request to the catch URL whose path starts with `path`: the first call returns the first one since this
|
|
45
|
+
* fixture started (an old request to a fixed path like "/stripe" is never picked up), each later call the one after it.
|
|
46
|
+
*/
|
|
47
|
+
waitForWebhook(path: string, options?: WebhookWaitOptions): Promise<WebhookRequest>;
|
|
48
|
+
/** Addresses handed out by this fixture instance. */
|
|
49
|
+
get addresses(): string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface MailPierFixtures {
|
|
53
|
+
inbox: PlaywrightInbox;
|
|
54
|
+
/** Client options (apiKey, baseUrl ...); default from MAILPIER_API_KEY / MAILPIER_BASE_URL. Set with test.use(). */
|
|
55
|
+
mailpierOptions: MailPierInboxOptions;
|
|
56
|
+
/** Delete the mail of every address the test created when it ends. Default false. */
|
|
57
|
+
mailpierCleanup: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** The fixtures, to merge into your own test: `base.extend<MailPierFixtures>(mailpierFixtures)`. */
|
|
60
|
+
declare const mailpierFixtures: Fixtures<MailPierFixtures, object, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
61
|
+
/** Playwright's `test` with the `inbox` fixture. */
|
|
62
|
+
declare const test: _playwright_test.TestType<PlaywrightTestArgs & PlaywrightTestOptions & MailPierFixtures, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
63
|
+
|
|
64
|
+
export { PlaywrightInbox, mailpierFixtures, test };
|
|
65
|
+
export type { InboxWaitOptions, MailPierFixtures, WebhookWaitOptions };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MailPierInbox,
|
|
3
|
+
webhookPath
|
|
4
|
+
} from "./chunk-2NMZ2IWD.js";
|
|
5
|
+
|
|
6
|
+
// src/playwright.ts
|
|
7
|
+
import { test as base } from "@playwright/test";
|
|
8
|
+
|
|
9
|
+
// src/inboxSession.ts
|
|
10
|
+
var PlaywrightInbox = class {
|
|
11
|
+
/** The underlying client, for anything else (listMessages, getRaw, getAttachment ...). */
|
|
12
|
+
client;
|
|
13
|
+
created = /* @__PURE__ */ new Map();
|
|
14
|
+
lastSeen = /* @__PURE__ */ new Map();
|
|
15
|
+
lastWebhook = /* @__PURE__ */ new Map();
|
|
16
|
+
started = new Date(Date.now() - 1e3);
|
|
17
|
+
// one second of slack for clock skew
|
|
18
|
+
constructor(client) {
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
/** A fresh address of the key's environment. */
|
|
22
|
+
async newAddress(options = {}) {
|
|
23
|
+
const started = new Date(Date.now() - 1e3);
|
|
24
|
+
const address = await this.client.newAddress(options);
|
|
25
|
+
this.created.set(address.toLowerCase(), started);
|
|
26
|
+
return address;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Waits for the next mail to `address`: the first call returns the first mail since newAddress(), each later call the mail
|
|
30
|
+
* after the one returned before.
|
|
31
|
+
*/
|
|
32
|
+
async waitForMessage(address, options = {}) {
|
|
33
|
+
const key = address.toLowerCase();
|
|
34
|
+
const previous = this.lastSeen.get(key);
|
|
35
|
+
const message = previous ? await this.client.waitForNextMessage(previous, { to: address, ...options }) : await this.client.waitForMessage({ to: address, since: this.created.get(key), ...options });
|
|
36
|
+
this.lastSeen.set(key, message);
|
|
37
|
+
return message;
|
|
38
|
+
}
|
|
39
|
+
/** Waits for the next mail to `address` and returns its one-time code; throws when the mail has none. */
|
|
40
|
+
async waitForCode(address, options = {}) {
|
|
41
|
+
const m = await this.waitForMessage(address, options);
|
|
42
|
+
if (!m.code) throw new Error(`The mail "${m.subject ?? ""}" to ${address} holds no one-time code.`);
|
|
43
|
+
return m.code;
|
|
44
|
+
}
|
|
45
|
+
/** Waits for the next mail to `address` and returns its first link containing `contains` (any link when omitted). */
|
|
46
|
+
async waitForLink(address, contains, options = {}) {
|
|
47
|
+
const m = await this.waitForMessage(address, options);
|
|
48
|
+
const link = m.firstLink(contains);
|
|
49
|
+
if (!link) throw new Error(`The mail "${m.subject ?? ""}" to ${address} holds no link${contains ? ` containing "${contains}"` : ""}.`);
|
|
50
|
+
return link;
|
|
51
|
+
}
|
|
52
|
+
/** The webhook catch URL with a fresh random path: give `url` to your app, then `waitForWebhook(path)`. */
|
|
53
|
+
createWebhookUrl() {
|
|
54
|
+
return this.client.createWebhookUrl();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Waits for the next request to the catch URL whose path starts with `path`: the first call returns the first one since this
|
|
58
|
+
* fixture started (an old request to a fixed path like "/stripe" is never picked up), each later call the one after it.
|
|
59
|
+
*/
|
|
60
|
+
async waitForWebhook(path, options = {}) {
|
|
61
|
+
const p = webhookPath(path) ?? "/";
|
|
62
|
+
const method = options.method?.trim().toUpperCase() || void 0;
|
|
63
|
+
const key = `${method ?? "*"} ${p}`;
|
|
64
|
+
const afterId = this.lastWebhook.get(key);
|
|
65
|
+
const request = await this.client.waitForWebhook({
|
|
66
|
+
path: p,
|
|
67
|
+
method,
|
|
68
|
+
timeoutSeconds: options.timeoutSeconds,
|
|
69
|
+
...afterId !== void 0 ? { afterId } : { since: this.started }
|
|
70
|
+
});
|
|
71
|
+
this.lastWebhook.set(key, request.id);
|
|
72
|
+
return request;
|
|
73
|
+
}
|
|
74
|
+
/** Addresses handed out by this fixture instance. */
|
|
75
|
+
get addresses() {
|
|
76
|
+
return [...this.created.keys()];
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/playwright.ts
|
|
81
|
+
import { expect } from "@playwright/test";
|
|
82
|
+
var mailpierFixtures = {
|
|
83
|
+
mailpierOptions: [{}, { option: true }],
|
|
84
|
+
mailpierCleanup: [false, { option: true }],
|
|
85
|
+
inbox: async ({ mailpierOptions, mailpierCleanup }, use) => {
|
|
86
|
+
const inbox = new PlaywrightInbox(new MailPierInbox(mailpierOptions));
|
|
87
|
+
await use(inbox);
|
|
88
|
+
if (mailpierCleanup) {
|
|
89
|
+
for (const a of inbox.addresses) {
|
|
90
|
+
try {
|
|
91
|
+
await inbox.client.deleteAll(a);
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var test = base.extend(mailpierFixtures);
|
|
99
|
+
export {
|
|
100
|
+
PlaywrightInbox,
|
|
101
|
+
expect,
|
|
102
|
+
mailpierFixtures,
|
|
103
|
+
test
|
|
104
|
+
};
|