saci.cc 1.2.0 → 1.4.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 +30 -5
- package/dist/index.d.ts +29 -3
- package/dist/index.js +22 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -113,7 +113,7 @@ it("signs up with a verification code", () => {
|
|
|
113
113
|
|
|
114
114
|
### `createInbox(options?)`
|
|
115
115
|
|
|
116
|
-
Creates an inbox and returns an `Inbox`. Without `name` the address is random (16 hex characters). With `name: "signup-test"` you get `signup-test@saci.cc`. Either way the inbox belongs to your API key's account for 7 days: only that account can read it, and nobody else can create the same name (a `SaciError` with status 409).
|
|
116
|
+
Creates an inbox and returns an `Inbox`. Without `name` the address is random (16 hex characters). With `name: "signup-test"` you get `signup-test@saci.cc`. Either way the inbox belongs to your API key's account for 7 days (30 on Pro, 90 on Team): only that account can read it, and nobody else can create the same name (a `SaciError` with status 409).
|
|
117
117
|
|
|
118
118
|
### `inbox.waitForCode(options?)`, `inbox.waitForLink(options?)`, `inbox.waitForEmail(options?)`
|
|
119
119
|
|
|
@@ -126,6 +126,7 @@ Wait for an email and return its verification code, a link in it, or the whole e
|
|
|
126
126
|
| `after` | Only emails received after this `Date` or ISO string |
|
|
127
127
|
| `timeout` | Milliseconds to wait. Default `60000` |
|
|
128
128
|
| `match` | `waitForLink` only: the link must contain this text or match a RegExp. Without it, the link to confirm the address or sign in (see `verificationLink`), or else the first link |
|
|
129
|
+
| `origin` | `waitForCode` only: the code must come from an [OTP-Token header](https://www.ietf.org/archive/id/draft-goto-otp-token-01.html) bound to this site, e.g. `"https://your-app.com"` or `"your-app.com"`. Emails without the header don't count, so use it only when your app sends it |
|
|
129
130
|
|
|
130
131
|
An email looks like this:
|
|
131
132
|
|
|
@@ -138,6 +139,8 @@ An email looks like this:
|
|
|
138
139
|
html: "<p>Your code is <b>482913</b></p>",
|
|
139
140
|
text: "Your code is 482913",
|
|
140
141
|
verificationCode: "482913", // or null
|
|
142
|
+
// The site the code is for, when the sender put it in an OTP-Token header; otherwise null
|
|
143
|
+
verificationCodeOrigin: null,
|
|
141
144
|
// The link to confirm the address, sign in, activate the account or reset the password, or null
|
|
142
145
|
verificationLink: "https://github.com/users/confirm_verification/7f3e...",
|
|
143
146
|
links: ["https://github.com/users/confirm_verification/7f3e...", "https://github.com/settings/emails"],
|
|
@@ -155,18 +158,40 @@ An email looks like this:
|
|
|
155
158
|
- `new Saci({ apiKey })`: pass the key instead of using `SACI_API_KEY`.
|
|
156
159
|
- `new Saci({ baseUrl, fetch })`: point at another deployment or pass your own `fetch`.
|
|
157
160
|
|
|
158
|
-
Failed requests throw `SaciError`,
|
|
161
|
+
Failed requests throw `SaciError`, with the HTTP `status` and the API's JSON answer in `body`. A missing or revoked key gives a 401. On the Free plan, a 402 means the account created its 1,000 inboxes for the month: `body.resetsAt` says when the count starts over, and it isn't retried.
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
import { SaciError } from "saci.cc";
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
await saci.createInbox();
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (error instanceof SaciError && error.status === 402) {
|
|
170
|
+
console.log(`Out of inboxes until ${error.body?.resetsAt}`);
|
|
171
|
+
}
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
159
175
|
|
|
160
176
|
## Limits
|
|
161
177
|
|
|
162
|
-
-
|
|
178
|
+
- Requests per minute per account, across its keys: 120 on Free, 600 on Pro, 2,000 on Team. The client waits and retries when it gets a 429.
|
|
179
|
+
- Inboxes created with your keys: 1,000 a month on Free, no cap on Pro and Team. Past that, `createInbox` throws a `SaciError` with status 402.
|
|
163
180
|
- Emails are deleted about a day after they arrive.
|
|
164
|
-
- Inboxes created with your key are private to your account for 7 days. Still, it's a service for tests and sign-ups: don't use it for anything sensitive.
|
|
165
|
-
- Want to be told instead of waiting?
|
|
181
|
+
- Inboxes created with your key are private to your account for 7 days (30 on Pro, 90 on Team). Still, it's a service for tests and sign-ups: don't use it for anything sensitive.
|
|
182
|
+
- Want to be told instead of waiting? On Pro and Team, set a webhook on [saci.cc/en/account](https://saci.cc/en/account/) and each email is POSTed to your URL ([format](https://saci.cc/en/docs/#webhooks)).
|
|
183
|
+
- Plans and prices: [saci.cc/en/pricing](https://saci.cc/en/pricing/).
|
|
166
184
|
- Addresses only receive email.
|
|
167
185
|
|
|
168
186
|
The full HTTP API is documented at [saci.cc/en/docs](https://saci.cc/en/docs/). There's also an [MCP server](https://saci.cc/en/mcp/) for AI agents.
|
|
169
187
|
|
|
188
|
+
## Guides
|
|
189
|
+
|
|
190
|
+
- [Test email verification in Playwright](https://saci.cc/en/blog/playwright-email-verification/)
|
|
191
|
+
- [Test password reset end to end](https://saci.cc/en/blog/password-reset-tests/)
|
|
192
|
+
- [Email tests in GitHub Actions: secrets, shards and limits](https://saci.cc/en/blog/github-actions-email-tests/)
|
|
193
|
+
- [Email verification in Selenium and Puppeteer](https://saci.cc/en/blog/selenium-puppeteer-email/)
|
|
194
|
+
|
|
170
195
|
## Development
|
|
171
196
|
|
|
172
197
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface EmailSummary {
|
|
|
6
6
|
receivedAt?: string;
|
|
7
7
|
/** The verification code, found by the API when the email arrived */
|
|
8
8
|
verificationCode?: string | null;
|
|
9
|
+
/** The site the sender bound the code to in an OTP-Token header, e.g. "https://your-app.com" */
|
|
10
|
+
verificationCodeOrigin?: string | null;
|
|
9
11
|
/** The link to confirm the address or sign in, found by the API when the email arrived */
|
|
10
12
|
verificationLink?: string | null;
|
|
11
13
|
}
|
|
@@ -22,8 +24,10 @@ export interface Attachment {
|
|
|
22
24
|
export interface Email extends EmailSummary {
|
|
23
25
|
html: string | null;
|
|
24
26
|
text: string | null;
|
|
25
|
-
/** The verification code
|
|
27
|
+
/** The verification code from the OTP-Token header, subject or body, if any */
|
|
26
28
|
verificationCode: string | null;
|
|
29
|
+
/** The site the sender bound the code to, when it came from an OTP-Token header */
|
|
30
|
+
verificationCodeOrigin: string | null;
|
|
27
31
|
/** The link to click to confirm the address, sign in (magic link), activate the account or reset the password, if any */
|
|
28
32
|
verificationLink: string | null;
|
|
29
33
|
links: string[];
|
|
@@ -46,6 +50,13 @@ export interface WaitOptions {
|
|
|
46
50
|
/** How long to wait, in milliseconds. Defaults to 60 seconds. */
|
|
47
51
|
timeout?: number;
|
|
48
52
|
}
|
|
53
|
+
export interface WaitForCodeOptions extends WaitOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Only codes the sender bound to this site with an OTP-Token header, e.g.
|
|
56
|
+
* "https://your-app.com" or "your-app.com". Emails without the header don't count.
|
|
57
|
+
*/
|
|
58
|
+
origin?: string;
|
|
59
|
+
}
|
|
49
60
|
export interface WaitForLinkOptions extends WaitOptions {
|
|
50
61
|
/**
|
|
51
62
|
* Only links that contain this text or match this pattern. Without it, the link to confirm
|
|
@@ -53,9 +64,24 @@ export interface WaitForLinkOptions extends WaitOptions {
|
|
|
53
64
|
*/
|
|
54
65
|
match?: string | RegExp;
|
|
55
66
|
}
|
|
67
|
+
/** What the API answered with an error: always `error`, plus details for some statuses */
|
|
68
|
+
export interface SaciErrorBody {
|
|
69
|
+
error: string;
|
|
70
|
+
/** 402: the free plan's monthly inboxes */
|
|
71
|
+
limit?: number;
|
|
72
|
+
/** 402: when the monthly count starts over (ISO date) */
|
|
73
|
+
resetsAt?: string;
|
|
74
|
+
/** 402: a paid plan lifts the limit (https://saci.cc/pricing/) */
|
|
75
|
+
upgrade?: boolean;
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
}
|
|
56
78
|
export declare class SaciError extends Error {
|
|
57
79
|
readonly status: number;
|
|
58
|
-
|
|
80
|
+
/** The API's JSON answer, when there was one */
|
|
81
|
+
readonly body: SaciErrorBody | null;
|
|
82
|
+
constructor(message: string, status: number,
|
|
83
|
+
/** The API's JSON answer, when there was one */
|
|
84
|
+
body?: SaciErrorBody | null);
|
|
59
85
|
}
|
|
60
86
|
export declare class SaciTimeoutError extends Error {
|
|
61
87
|
constructor(message: string);
|
|
@@ -88,7 +114,7 @@ export declare class Inbox {
|
|
|
88
114
|
/** Waits for an email that matches the filters and returns it in full */
|
|
89
115
|
waitForEmail(options?: WaitOptions): Promise<Email>;
|
|
90
116
|
/** Waits for an email with a verification code and returns the code, e.g. "482913" */
|
|
91
|
-
waitForCode(options?:
|
|
117
|
+
waitForCode(options?: WaitForCodeOptions): Promise<string>;
|
|
92
118
|
/**
|
|
93
119
|
* Waits for an email with a link and returns it: the one matching `match`, if given,
|
|
94
120
|
* otherwise the link to confirm the address or sign in, or else the first link
|
package/dist/index.js
CHANGED
|
@@ -9,9 +9,13 @@ const MAX_RATE_LIMIT_RETRIES = 3;
|
|
|
9
9
|
const envApiKey = () => globalThis.process?.env?.SACI_API_KEY;
|
|
10
10
|
export class SaciError extends Error {
|
|
11
11
|
status;
|
|
12
|
-
|
|
12
|
+
body;
|
|
13
|
+
constructor(message, status,
|
|
14
|
+
/** The API's JSON answer, when there was one */
|
|
15
|
+
body = null) {
|
|
13
16
|
super(message);
|
|
14
17
|
this.status = status;
|
|
18
|
+
this.body = body;
|
|
15
19
|
this.name = "SaciError";
|
|
16
20
|
}
|
|
17
21
|
}
|
|
@@ -25,6 +29,18 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
25
29
|
const matches = (value, filter) => filter === undefined ||
|
|
26
30
|
(typeof filter === "string" ? value.toLowerCase().includes(filter.toLowerCase()) : filter.test(value));
|
|
27
31
|
const timeOf = (date) => (date ? Date.parse(date) : NaN);
|
|
32
|
+
// "your-app.com" or "https://Your-App.com/login" as the API returns origins: "https://your-app.com"
|
|
33
|
+
function normalizeOrigin(input) {
|
|
34
|
+
const value = input.trim();
|
|
35
|
+
let origin = "null";
|
|
36
|
+
try {
|
|
37
|
+
origin = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(value) ? value : `https://${value}`).origin;
|
|
38
|
+
}
|
|
39
|
+
catch { }
|
|
40
|
+
if (origin === "null")
|
|
41
|
+
throw new TypeError(`origin must be a site like https://your-app.com, got ${JSON.stringify(input)}`);
|
|
42
|
+
return origin;
|
|
43
|
+
}
|
|
28
44
|
export class Saci {
|
|
29
45
|
baseUrl;
|
|
30
46
|
fetch;
|
|
@@ -59,8 +75,9 @@ export class Saci {
|
|
|
59
75
|
continue;
|
|
60
76
|
}
|
|
61
77
|
if (!res.ok) {
|
|
78
|
+
// 402 (the free plan's monthly inboxes) isn't retried: it lasts until the month turns
|
|
62
79
|
const body = (await res.json().catch(() => null));
|
|
63
|
-
throw new SaciError(`${method} ${path} failed with ${res.status}: ${body?.error ?? res.statusText}`, res.status);
|
|
80
|
+
throw new SaciError(`${method} ${path} failed with ${res.status}: ${body?.error ?? res.statusText}`, res.status, body);
|
|
64
81
|
}
|
|
65
82
|
return (res.status === 204 ? undefined : await res.json());
|
|
66
83
|
}
|
|
@@ -96,7 +113,9 @@ export class Inbox {
|
|
|
96
113
|
}
|
|
97
114
|
/** Waits for an email with a verification code and returns the code, e.g. "482913" */
|
|
98
115
|
waitForCode(options = {}) {
|
|
99
|
-
|
|
116
|
+
const origin = options.origin === undefined ? undefined : normalizeOrigin(options.origin);
|
|
117
|
+
const code = (email) => email.verificationCode && (!origin || email.verificationCodeOrigin === origin) ? email.verificationCode : null;
|
|
118
|
+
return this.waitFor(options, code, origin ? `verification code for ${origin}` : "verification code", code);
|
|
100
119
|
}
|
|
101
120
|
/**
|
|
102
121
|
* Waits for an email with a link and returns it: the one matching `match`, if given,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saci.cc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Temporary email inboxes for end-to-end tests: wait for verification codes and links from saci.cc",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"temporary email",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"homepage": "https://saci.cc/en/docs/",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/
|
|
18
|
+
"url": "git+https://github.com/saci-cc/saci.cc-client.git"
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"type": "module",
|