@mailpier/inbox 0.0.0-stage → 0.1.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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +99 -2
- package/dist/chunk-FR6JEAV7.js +317 -0
- package/dist/client-CqysQIQJ.d.cts +194 -0
- package/dist/client-CqysQIQJ.d.ts +194 -0
- package/dist/cypress/commands.cjs +79 -0
- package/dist/cypress/commands.d.cts +48 -0
- package/dist/cypress/commands.d.ts +48 -0
- package/dist/cypress/commands.js +53 -0
- package/dist/cypress/index.cjs +358 -0
- package/dist/cypress/index.d.cts +32 -0
- package/dist/cypress/index.d.ts +32 -0
- package/dist/cypress/index.js +27 -0
- package/dist/index.cjs +349 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +18 -0
- package/dist/playwright.cjs +410 -0
- package/dist/playwright.d.cts +50 -0
- package/dist/playwright.d.ts +50 -0
- package/dist/playwright.js +78 -0
- package/dist/testing/index.cjs +350 -0
- package/dist/testing/index.d.cts +75 -0
- package/dist/testing/index.d.ts +75 -0
- package/dist/testing/index.js +321 -0
- package/package.json +107 -4
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/cypress/index.ts
|
|
21
|
+
var cypress_exports = {};
|
|
22
|
+
__export(cypress_exports, {
|
|
23
|
+
mailpierTasks: () => mailpierTasks
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(cypress_exports);
|
|
26
|
+
|
|
27
|
+
// src/errors.ts
|
|
28
|
+
var MailPierInboxError = class extends Error {
|
|
29
|
+
status;
|
|
30
|
+
/** Set on 429: seconds to wait before the next call. */
|
|
31
|
+
retryAfterSeconds;
|
|
32
|
+
constructor(status, message, retryAfterSeconds) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "MailPierInboxError";
|
|
35
|
+
this.status = status;
|
|
36
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var MailPierTimeoutError = class extends Error {
|
|
40
|
+
address;
|
|
41
|
+
timeoutMs;
|
|
42
|
+
constructor(address, timeoutMs, subjectContains) {
|
|
43
|
+
super(`No mail to ${address}${subjectContains ? ` with "${subjectContains}" in the subject` : ""} arrived within ${Math.round(timeoutMs / 1e3)} seconds.`);
|
|
44
|
+
this.name = "MailPierTimeoutError";
|
|
45
|
+
this.address = address;
|
|
46
|
+
this.timeoutMs = timeoutMs;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/message.ts
|
|
51
|
+
var InboxMessage = class {
|
|
52
|
+
id;
|
|
53
|
+
receivedUtc;
|
|
54
|
+
from;
|
|
55
|
+
to = [];
|
|
56
|
+
subject;
|
|
57
|
+
sizeBytes = 0;
|
|
58
|
+
hasAttachments = false;
|
|
59
|
+
text;
|
|
60
|
+
html;
|
|
61
|
+
headers;
|
|
62
|
+
links = [];
|
|
63
|
+
codes = [];
|
|
64
|
+
attachments = [];
|
|
65
|
+
auth;
|
|
66
|
+
spam;
|
|
67
|
+
constructor(data) {
|
|
68
|
+
Object.assign(this, data);
|
|
69
|
+
this.to = Array.isArray(data.to) ? data.to : [];
|
|
70
|
+
this.links = Array.isArray(data.links) ? data.links.filter((l) => l && typeof l.href === "string") : [];
|
|
71
|
+
this.codes = normaliseCodes(data.codes);
|
|
72
|
+
this.attachments = Array.isArray(data.attachments) ? data.attachments : [];
|
|
73
|
+
}
|
|
74
|
+
/** The first one-time code in the mail (best guess first), or undefined when it has none. */
|
|
75
|
+
get code() {
|
|
76
|
+
return this.codes[0];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The first link whose address (or text) contains `contains` (case-insensitive), or the first link when it is omitted;
|
|
80
|
+
* undefined when none matches.
|
|
81
|
+
*/
|
|
82
|
+
firstLink(contains) {
|
|
83
|
+
if (contains === void 0 || contains === null || contains === "") return this.links[0]?.href;
|
|
84
|
+
const needle = contains.toLowerCase();
|
|
85
|
+
return this.links.find((l) => l.href.toLowerCase().includes(needle) || (l.text ?? "").toLowerCase().includes(needle))?.href;
|
|
86
|
+
}
|
|
87
|
+
/** The plain JSON (what the API returned), e.g. to pass through a Cypress task. */
|
|
88
|
+
toJSON() {
|
|
89
|
+
const { ...plain } = this;
|
|
90
|
+
return { ...plain, code: this.code };
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
function normaliseCodes(codes) {
|
|
94
|
+
if (!Array.isArray(codes)) return [];
|
|
95
|
+
const out = [];
|
|
96
|
+
for (const c of codes) {
|
|
97
|
+
if (typeof c === "string" && c.length > 0) out.push(c);
|
|
98
|
+
else if (c && typeof c === "object") {
|
|
99
|
+
for (const k of ["value", "code", "Value", "Code"]) {
|
|
100
|
+
const v = c[k];
|
|
101
|
+
if (typeof v === "string" && v.length > 0) {
|
|
102
|
+
out.push(v);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/client.ts
|
|
112
|
+
var DEFAULT_BASE_URL = "https://api.mailpier.io";
|
|
113
|
+
var MAX_POLL_SECONDS = 120;
|
|
114
|
+
var VERSION = "0.1.0";
|
|
115
|
+
var sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
116
|
+
if (signal?.aborted) return reject(signal.reason);
|
|
117
|
+
const t = setTimeout(() => {
|
|
118
|
+
signal?.removeEventListener("abort", onAbort);
|
|
119
|
+
resolve();
|
|
120
|
+
}, ms);
|
|
121
|
+
const onAbort = () => {
|
|
122
|
+
clearTimeout(t);
|
|
123
|
+
reject(signal.reason);
|
|
124
|
+
};
|
|
125
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
126
|
+
});
|
|
127
|
+
function iso(t) {
|
|
128
|
+
if (t === void 0) return void 0;
|
|
129
|
+
return typeof t === "string" ? t : t.toISOString();
|
|
130
|
+
}
|
|
131
|
+
function env(name) {
|
|
132
|
+
const p = globalThis.process;
|
|
133
|
+
const v = p?.env?.[name];
|
|
134
|
+
return v && v.trim() ? v.trim() : void 0;
|
|
135
|
+
}
|
|
136
|
+
var MailPierInbox = class {
|
|
137
|
+
baseUrl;
|
|
138
|
+
apiKey;
|
|
139
|
+
maxRetries;
|
|
140
|
+
maxRetryDelayMs;
|
|
141
|
+
fetchImpl;
|
|
142
|
+
constructor(options = {}) {
|
|
143
|
+
const key = (options.apiKey ?? env("MAILPIER_API_KEY") ?? "").trim();
|
|
144
|
+
if (!key) throw new Error("An API key (mpi_...) is required: pass { apiKey } or set MAILPIER_API_KEY.");
|
|
145
|
+
this.apiKey = key;
|
|
146
|
+
this.baseUrl = (options.baseUrl ?? env("MAILPIER_BASE_URL") ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
147
|
+
this.maxRetries = Math.max(0, options.maxRetries ?? 5);
|
|
148
|
+
this.maxRetryDelayMs = Math.max(0, options.maxRetryDelayMs ?? 6e4);
|
|
149
|
+
const f = options.fetch ?? globalThis.fetch;
|
|
150
|
+
if (!f) throw new Error("No fetch available: use Node 18 or later, or pass { fetch }.");
|
|
151
|
+
this.fetchImpl = f;
|
|
152
|
+
}
|
|
153
|
+
/** A fresh random address of the key's environment, e.g. `signup-k3v9q2mz7a@qa.acme.mailpier.io`. */
|
|
154
|
+
async newAddress(options = {}) {
|
|
155
|
+
const body = {};
|
|
156
|
+
if (options.domain) body.domain = options.domain;
|
|
157
|
+
if (options.prefix) body.prefix = options.prefix;
|
|
158
|
+
const resp = await this.request("POST", "/v1/addresses", {}, { body: JSON.stringify(body) });
|
|
159
|
+
const json = await resp.json();
|
|
160
|
+
if (!json?.address) throw new MailPierInboxError(resp.status, "The server returned no address.");
|
|
161
|
+
return json.address;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Waits until a mail to `to` arrives and returns it (the OLDEST match received at or after `since`).
|
|
165
|
+
* Throws MailPierTimeoutError when nothing arrives within `timeoutMs`.
|
|
166
|
+
*/
|
|
167
|
+
async waitForMessage(options) {
|
|
168
|
+
const to = options.to?.trim();
|
|
169
|
+
if (!to) throw new Error("waitForMessage needs { to: address }.");
|
|
170
|
+
const timeoutMs = options.timeoutMs ?? 6e4;
|
|
171
|
+
if (!(timeoutMs > 0)) throw new Error("timeoutMs must be greater than 0.");
|
|
172
|
+
const deadline = Date.now() + timeoutMs;
|
|
173
|
+
const since = iso(options.since);
|
|
174
|
+
for (; ; ) {
|
|
175
|
+
const left = deadline - Date.now();
|
|
176
|
+
const seconds = Math.min(Math.max(Math.ceil(left / 1e3), 1), MAX_POLL_SECONDS);
|
|
177
|
+
const resp = await this.request("GET", "/v1/messages/wait", {
|
|
178
|
+
to,
|
|
179
|
+
subject: options.subjectContains,
|
|
180
|
+
since,
|
|
181
|
+
afterId: since ? options.afterId : void 0,
|
|
182
|
+
timeoutSeconds: seconds
|
|
183
|
+
}, { signal: options.signal, timeoutMs: (seconds + 30) * 1e3 });
|
|
184
|
+
if (resp.status !== 204) return new InboxMessage(await resp.json());
|
|
185
|
+
if (Date.now() >= deadline) throw new MailPierTimeoutError(to, timeoutMs, options.subjectContains);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Waits for the next mail to `to` after `previous` (one you already received): passes its receivedUtc as `since` and its id as
|
|
190
|
+
* `afterId`, so a mail stored in the same millisecond is not missed and `previous` itself is never returned again.
|
|
191
|
+
*/
|
|
192
|
+
waitForNextMessage(previous, options) {
|
|
193
|
+
return this.waitForMessage({ ...options, since: previous.receivedUtc, afterId: previous.id });
|
|
194
|
+
}
|
|
195
|
+
/** Mail of the environment, newest first (at most 100 per call). */
|
|
196
|
+
async listMessages(options = {}) {
|
|
197
|
+
const since = iso(options.since);
|
|
198
|
+
const resp = await this.request("GET", "/v1/messages", {
|
|
199
|
+
to: options.to,
|
|
200
|
+
subject: options.subjectContains,
|
|
201
|
+
since,
|
|
202
|
+
afterId: since ? options.afterId : void 0,
|
|
203
|
+
take: options.take ?? 50,
|
|
204
|
+
skip: options.skip ?? 0
|
|
205
|
+
}, { signal: options.signal });
|
|
206
|
+
const json = await resp.json();
|
|
207
|
+
return json?.items ?? [];
|
|
208
|
+
}
|
|
209
|
+
/** One mail with its text, HTML, headers, links, codes and attachment list; null when it does not exist (or expired). */
|
|
210
|
+
async getMessage(id) {
|
|
211
|
+
const resp = await this.request("GET", `/v1/messages/${encodeURIComponent(id)}`, {}, { allow404: true });
|
|
212
|
+
if (resp.status === 404) return null;
|
|
213
|
+
return new InboxMessage(await resp.json());
|
|
214
|
+
}
|
|
215
|
+
/** The original message (.eml bytes); null when it does not exist. */
|
|
216
|
+
getRaw(id) {
|
|
217
|
+
return this.download(`/v1/messages/${encodeURIComponent(id)}/raw`);
|
|
218
|
+
}
|
|
219
|
+
/** One attachment's bytes; null when it does not exist. */
|
|
220
|
+
getAttachment(id, index) {
|
|
221
|
+
return this.download(`/v1/messages/${encodeURIComponent(id)}/attachments/${index}`);
|
|
222
|
+
}
|
|
223
|
+
/** Deletes one mail. False when it did not exist. Throws (409) when the mail was also sent outside this environment. */
|
|
224
|
+
async deleteMessage(id) {
|
|
225
|
+
const resp = await this.request("DELETE", `/v1/messages/${encodeURIComponent(id)}`, {}, { allow404: true });
|
|
226
|
+
return resp.status !== 404;
|
|
227
|
+
}
|
|
228
|
+
/** Deletes every mail to one address; returns how many were deleted. */
|
|
229
|
+
async deleteAll(to) {
|
|
230
|
+
return (await this.deleteAllDetailed(to)).deleted;
|
|
231
|
+
}
|
|
232
|
+
/** Like deleteAll, but also says how many shared mails were skipped. */
|
|
233
|
+
async deleteAllDetailed(to) {
|
|
234
|
+
if (!to?.trim()) throw new Error("deleteAll needs the address.");
|
|
235
|
+
const resp = await this.request("DELETE", "/v1/messages", { to: to.trim() });
|
|
236
|
+
const json = await resp.json();
|
|
237
|
+
return { deleted: json?.deleted ?? 0, skippedShared: json?.skippedShared ?? 0 };
|
|
238
|
+
}
|
|
239
|
+
/** The key's account, environment, domains, plan and usage (GET /v1/me). */
|
|
240
|
+
async me() {
|
|
241
|
+
const resp = await this.request("GET", "/v1/me", {});
|
|
242
|
+
return await resp.json();
|
|
243
|
+
}
|
|
244
|
+
// ------------------------------------------------------------------ plumbing
|
|
245
|
+
async download(path) {
|
|
246
|
+
const resp = await this.request("GET", path, {}, { allow404: true, accept: "*/*" });
|
|
247
|
+
if (resp.status === 404) return null;
|
|
248
|
+
return new Uint8Array(await resp.arrayBuffer());
|
|
249
|
+
}
|
|
250
|
+
url(path, query) {
|
|
251
|
+
const q = new URLSearchParams();
|
|
252
|
+
for (const [k, v] of Object.entries(query)) if (v !== void 0 && v !== null && v !== "") q.set(k, String(v));
|
|
253
|
+
const s = q.toString();
|
|
254
|
+
return `${this.baseUrl}${path}${s ? `?${s}` : ""}`;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* One call with retries: 429 waits Retry-After (default 1 s), 502/503/504 and network errors back off 0.5, 1, 2, 4 ... s
|
|
258
|
+
* (both capped at maxRetryDelayMs). Other errors throw MailPierInboxError with the server's {"error": "..."} text.
|
|
259
|
+
*/
|
|
260
|
+
async request(method, path, query, o = {}) {
|
|
261
|
+
const url = this.url(path, query);
|
|
262
|
+
const headers = {
|
|
263
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
264
|
+
Accept: o.accept ?? "application/json",
|
|
265
|
+
"User-Agent": `mailpier-inbox-node/${VERSION}`
|
|
266
|
+
};
|
|
267
|
+
if (o.body !== void 0) headers["Content-Type"] = "application/json";
|
|
268
|
+
for (let attempt = 0; ; attempt++) {
|
|
269
|
+
const ctl = new AbortController();
|
|
270
|
+
const timer = setTimeout(
|
|
271
|
+
() => ctl.abort(new Error(`No answer within ${Math.round((o.timeoutMs ?? 6e4) / 1e3)} s.`)),
|
|
272
|
+
o.timeoutMs ?? 6e4
|
|
273
|
+
);
|
|
274
|
+
const onAbort = () => ctl.abort(o.signal.reason);
|
|
275
|
+
if (o.signal?.aborted) onAbort();
|
|
276
|
+
else o.signal?.addEventListener("abort", onAbort, { once: true });
|
|
277
|
+
let resp;
|
|
278
|
+
try {
|
|
279
|
+
resp = await this.fetchImpl(url, { method, headers, body: o.body, signal: ctl.signal });
|
|
280
|
+
} catch (err) {
|
|
281
|
+
clearTimeout(timer);
|
|
282
|
+
o.signal?.removeEventListener("abort", onAbort);
|
|
283
|
+
if (o.signal?.aborted) throw err;
|
|
284
|
+
if (attempt >= this.maxRetries) {
|
|
285
|
+
throw new MailPierInboxError(0, `Could not reach MailPier Inbox at ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`);
|
|
286
|
+
}
|
|
287
|
+
await sleep(this.backoff(attempt), o.signal);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
clearTimeout(timer);
|
|
291
|
+
o.signal?.removeEventListener("abort", onAbort);
|
|
292
|
+
if (resp.ok || o.allow404 && resp.status === 404) return resp;
|
|
293
|
+
const message = await errorText(resp);
|
|
294
|
+
if (resp.status === 429) {
|
|
295
|
+
const retryAfter = parseRetryAfter(resp.headers.get("Retry-After"));
|
|
296
|
+
if (attempt < this.maxRetries) {
|
|
297
|
+
await sleep(Math.min((retryAfter ?? 1) * 1e3, this.maxRetryDelayMs), o.signal);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
throw new MailPierInboxError(429, message ?? "Too many requests.", retryAfter);
|
|
301
|
+
}
|
|
302
|
+
if ((resp.status === 502 || resp.status === 503 || resp.status === 504) && attempt < this.maxRetries) {
|
|
303
|
+
await sleep(this.backoff(attempt), o.signal);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
throw new MailPierInboxError(resp.status, message ?? `MailPier Inbox answered ${resp.status}.`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
backoff(attempt) {
|
|
310
|
+
return Math.min(500 * 2 ** attempt, this.maxRetryDelayMs);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
async function errorText(resp) {
|
|
314
|
+
try {
|
|
315
|
+
const text = await resp.text();
|
|
316
|
+
if (!text) return void 0;
|
|
317
|
+
try {
|
|
318
|
+
const e = JSON.parse(text).error;
|
|
319
|
+
return typeof e === "string" && e ? `${e} (HTTP ${resp.status})` : void 0;
|
|
320
|
+
} catch {
|
|
321
|
+
return void 0;
|
|
322
|
+
}
|
|
323
|
+
} catch {
|
|
324
|
+
return void 0;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function parseRetryAfter(v) {
|
|
328
|
+
if (!v) return void 0;
|
|
329
|
+
const n = Number.parseInt(v, 10);
|
|
330
|
+
if (Number.isFinite(n) && n >= 0) return n;
|
|
331
|
+
const t = Date.parse(v);
|
|
332
|
+
return Number.isFinite(t) ? Math.max(0, Math.ceil((t - Date.now()) / 1e3)) : void 0;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/cypress/tasks.ts
|
|
336
|
+
function mailpierTasks(options = {}) {
|
|
337
|
+
let client;
|
|
338
|
+
const inbox = () => client ??= new MailPierInbox(options);
|
|
339
|
+
return {
|
|
340
|
+
"mailpier:newAddress": async (args) => inbox().newAddress({ prefix: args?.prefix, domain: args?.domain }),
|
|
341
|
+
"mailpier:waitForMessage": async (args) => {
|
|
342
|
+
if (!args?.to) throw new Error("mailpier:waitForMessage needs { to }.");
|
|
343
|
+
const m = await inbox().waitForMessage({
|
|
344
|
+
to: args.to,
|
|
345
|
+
subjectContains: args.subjectContains,
|
|
346
|
+
timeoutMs: args.timeoutMs,
|
|
347
|
+
since: args.since,
|
|
348
|
+
afterId: args.afterId
|
|
349
|
+
});
|
|
350
|
+
return { ...m.toJSON(), code: m.code ?? null, firstLink: m.firstLink() ?? null };
|
|
351
|
+
},
|
|
352
|
+
"mailpier:deleteAll": async (args) => inbox().deleteAll(args.to)
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
356
|
+
0 && (module.exports = {
|
|
357
|
+
mailpierTasks
|
|
358
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InboxMessageData, MailPierInboxOptions } from '../index.cjs';
|
|
2
|
+
|
|
3
|
+
interface MailPierWaitTaskArgs {
|
|
4
|
+
to: string;
|
|
5
|
+
subjectContains?: string;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
/** ISO time; only mail received at or after it. */
|
|
8
|
+
since?: string;
|
|
9
|
+
/** With since: skip this message id (use the previous message's receivedUtc + id to get the next one). */
|
|
10
|
+
afterId?: string;
|
|
11
|
+
}
|
|
12
|
+
/** What cy.mailpierWaitForMessage yields: the message JSON plus `code` and `firstLink` (any link). */
|
|
13
|
+
type MailPierTaskMessage = InboxMessageData & {
|
|
14
|
+
code: string | null;
|
|
15
|
+
firstLink: string | null;
|
|
16
|
+
};
|
|
17
|
+
interface MailPierTasks {
|
|
18
|
+
"mailpier:newAddress"(args?: {
|
|
19
|
+
prefix?: string;
|
|
20
|
+
domain?: string;
|
|
21
|
+
} | null): Promise<string>;
|
|
22
|
+
"mailpier:waitForMessage"(args: MailPierWaitTaskArgs): Promise<MailPierTaskMessage>;
|
|
23
|
+
"mailpier:deleteAll"(args: {
|
|
24
|
+
to: string;
|
|
25
|
+
}): Promise<number>;
|
|
26
|
+
[name: string]: (args: never) => unknown;
|
|
27
|
+
}
|
|
28
|
+
/** The cy.task handlers. Options default to MAILPIER_API_KEY / MAILPIER_BASE_URL in the Cypress Node process. */
|
|
29
|
+
declare function mailpierTasks(options?: MailPierInboxOptions): MailPierTasks;
|
|
30
|
+
|
|
31
|
+
export { mailpierTasks };
|
|
32
|
+
export type { MailPierTaskMessage, MailPierTasks, MailPierWaitTaskArgs };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InboxMessageData, MailPierInboxOptions } from '../index.js';
|
|
2
|
+
|
|
3
|
+
interface MailPierWaitTaskArgs {
|
|
4
|
+
to: string;
|
|
5
|
+
subjectContains?: string;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
/** ISO time; only mail received at or after it. */
|
|
8
|
+
since?: string;
|
|
9
|
+
/** With since: skip this message id (use the previous message's receivedUtc + id to get the next one). */
|
|
10
|
+
afterId?: string;
|
|
11
|
+
}
|
|
12
|
+
/** What cy.mailpierWaitForMessage yields: the message JSON plus `code` and `firstLink` (any link). */
|
|
13
|
+
type MailPierTaskMessage = InboxMessageData & {
|
|
14
|
+
code: string | null;
|
|
15
|
+
firstLink: string | null;
|
|
16
|
+
};
|
|
17
|
+
interface MailPierTasks {
|
|
18
|
+
"mailpier:newAddress"(args?: {
|
|
19
|
+
prefix?: string;
|
|
20
|
+
domain?: string;
|
|
21
|
+
} | null): Promise<string>;
|
|
22
|
+
"mailpier:waitForMessage"(args: MailPierWaitTaskArgs): Promise<MailPierTaskMessage>;
|
|
23
|
+
"mailpier:deleteAll"(args: {
|
|
24
|
+
to: string;
|
|
25
|
+
}): Promise<number>;
|
|
26
|
+
[name: string]: (args: never) => unknown;
|
|
27
|
+
}
|
|
28
|
+
/** The cy.task handlers. Options default to MAILPIER_API_KEY / MAILPIER_BASE_URL in the Cypress Node process. */
|
|
29
|
+
declare function mailpierTasks(options?: MailPierInboxOptions): MailPierTasks;
|
|
30
|
+
|
|
31
|
+
export { mailpierTasks };
|
|
32
|
+
export type { MailPierTaskMessage, MailPierTasks, MailPierWaitTaskArgs };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MailPierInbox
|
|
3
|
+
} from "../chunk-FR6JEAV7.js";
|
|
4
|
+
|
|
5
|
+
// src/cypress/tasks.ts
|
|
6
|
+
function mailpierTasks(options = {}) {
|
|
7
|
+
let client;
|
|
8
|
+
const inbox = () => client ??= new MailPierInbox(options);
|
|
9
|
+
return {
|
|
10
|
+
"mailpier:newAddress": async (args) => inbox().newAddress({ prefix: args?.prefix, domain: args?.domain }),
|
|
11
|
+
"mailpier:waitForMessage": async (args) => {
|
|
12
|
+
if (!args?.to) throw new Error("mailpier:waitForMessage needs { to }.");
|
|
13
|
+
const m = await inbox().waitForMessage({
|
|
14
|
+
to: args.to,
|
|
15
|
+
subjectContains: args.subjectContains,
|
|
16
|
+
timeoutMs: args.timeoutMs,
|
|
17
|
+
since: args.since,
|
|
18
|
+
afterId: args.afterId
|
|
19
|
+
});
|
|
20
|
+
return { ...m.toJSON(), code: m.code ?? null, firstLink: m.firstLink() ?? null };
|
|
21
|
+
},
|
|
22
|
+
"mailpier:deleteAll": async (args) => inbox().deleteAll(args.to)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
mailpierTasks
|
|
27
|
+
};
|