saci.cc 1.1.0 → 1.3.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 +27 -7
- package/dist/index.d.ts +30 -3
- package/dist/index.js +19 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ console.log(inbox.address); // a1b2c3d4e5f60718@saci.cc
|
|
|
23
23
|
// ...sign up with inbox.address...
|
|
24
24
|
|
|
25
25
|
const code = await inbox.waitForCode(); // "482913"
|
|
26
|
+
// or, when the email has a button instead of a code:
|
|
27
|
+
const link = await inbox.waitForLink(); // "https://your-app.com/verify?token=..."
|
|
26
28
|
```
|
|
27
29
|
|
|
28
30
|
## Playwright
|
|
@@ -111,7 +113,7 @@ it("signs up with a verification code", () => {
|
|
|
111
113
|
|
|
112
114
|
### `createInbox(options?)`
|
|
113
115
|
|
|
114
|
-
Creates an inbox and returns an `Inbox`. Without `name` the address is random (16 hex characters)
|
|
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).
|
|
115
117
|
|
|
116
118
|
### `inbox.waitForCode(options?)`, `inbox.waitForLink(options?)`, `inbox.waitForEmail(options?)`
|
|
117
119
|
|
|
@@ -123,7 +125,7 @@ Wait for an email and return its verification code, a link in it, or the whole e
|
|
|
123
125
|
| `subject` | Only emails whose subject contains this text (case-insensitive) or matches a RegExp |
|
|
124
126
|
| `after` | Only emails received after this `Date` or ISO string |
|
|
125
127
|
| `timeout` | Milliseconds to wait. Default `60000` |
|
|
126
|
-
| `match` | `waitForLink` only: the link must contain this text or match a RegExp. Without it, the first link |
|
|
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 |
|
|
127
129
|
|
|
128
130
|
An email looks like this:
|
|
129
131
|
|
|
@@ -136,7 +138,9 @@ An email looks like this:
|
|
|
136
138
|
html: "<p>Your code is <b>482913</b></p>",
|
|
137
139
|
text: "Your code is 482913",
|
|
138
140
|
verificationCode: "482913", // or null
|
|
139
|
-
|
|
141
|
+
// The link to confirm the address, sign in, activate the account or reset the password, or null
|
|
142
|
+
verificationLink: "https://github.com/users/confirm_verification/7f3e...",
|
|
143
|
+
links: ["https://github.com/users/confirm_verification/7f3e...", "https://github.com/settings/emails"],
|
|
140
144
|
attachments: [{ index: 0, filename: "invoice.pdf", contentType: "application/pdf", size: 48213, inline: false, url: "https://..." }],
|
|
141
145
|
}
|
|
142
146
|
```
|
|
@@ -144,20 +148,36 @@ An email looks like this:
|
|
|
144
148
|
### Other methods
|
|
145
149
|
|
|
146
150
|
- `inbox.address`: the email address (`String(inbox)` gives the same).
|
|
147
|
-
- `inbox.list()`: summaries of the emails in the inbox, newest first
|
|
151
|
+
- `inbox.list()`: summaries of the emails in the inbox, newest first, with `verificationCode` and `verificationLink`.
|
|
148
152
|
- `inbox.get(messageId)`: one email in full.
|
|
149
153
|
- `inbox.delete(messageId)` and `inbox.clear()`: delete one email or all of them.
|
|
150
154
|
- `new Saci().inbox(address)`: an `Inbox` for an address created earlier.
|
|
151
155
|
- `new Saci({ apiKey })`: pass the key instead of using `SACI_API_KEY`.
|
|
152
156
|
- `new Saci({ baseUrl, fetch })`: point at another deployment or pass your own `fetch`.
|
|
153
157
|
|
|
154
|
-
Failed requests throw `SaciError`,
|
|
158
|
+
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.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { SaciError } from "saci.cc";
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
await saci.createInbox();
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof SaciError && error.status === 402) {
|
|
167
|
+
console.log(`Out of inboxes until ${error.body?.resetsAt}`);
|
|
168
|
+
}
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
155
172
|
|
|
156
173
|
## Limits
|
|
157
174
|
|
|
158
|
-
-
|
|
175
|
+
- 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.
|
|
176
|
+
- 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.
|
|
159
177
|
- Emails are deleted about a day after they arrive.
|
|
160
|
-
-
|
|
178
|
+
- 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.
|
|
179
|
+
- 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)).
|
|
180
|
+
- Plans and prices: [saci.cc/en/pricing](https://saci.cc/en/pricing/).
|
|
161
181
|
- Addresses only receive email.
|
|
162
182
|
|
|
163
183
|
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.
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ export interface EmailSummary {
|
|
|
4
4
|
from: string;
|
|
5
5
|
subject: string;
|
|
6
6
|
receivedAt?: string;
|
|
7
|
+
/** The verification code, found by the API when the email arrived */
|
|
8
|
+
verificationCode?: string | null;
|
|
9
|
+
/** The link to confirm the address or sign in, found by the API when the email arrived */
|
|
10
|
+
verificationLink?: string | null;
|
|
7
11
|
}
|
|
8
12
|
export interface Attachment {
|
|
9
13
|
index: number;
|
|
@@ -20,6 +24,8 @@ export interface Email extends EmailSummary {
|
|
|
20
24
|
text: string | null;
|
|
21
25
|
/** The verification code found in the subject or body, if any */
|
|
22
26
|
verificationCode: string | null;
|
|
27
|
+
/** The link to click to confirm the address, sign in (magic link), activate the account or reset the password, if any */
|
|
28
|
+
verificationLink: string | null;
|
|
23
29
|
links: string[];
|
|
24
30
|
attachments: Attachment[];
|
|
25
31
|
}
|
|
@@ -41,12 +47,30 @@ export interface WaitOptions {
|
|
|
41
47
|
timeout?: number;
|
|
42
48
|
}
|
|
43
49
|
export interface WaitForLinkOptions extends WaitOptions {
|
|
44
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Only links that contain this text or match this pattern. Without it, the link to confirm
|
|
52
|
+
* the address or sign in, or else the first link.
|
|
53
|
+
*/
|
|
45
54
|
match?: string | RegExp;
|
|
46
55
|
}
|
|
56
|
+
/** What the API answered with an error: always `error`, plus details for some statuses */
|
|
57
|
+
export interface SaciErrorBody {
|
|
58
|
+
error: string;
|
|
59
|
+
/** 402: the free plan's monthly inboxes */
|
|
60
|
+
limit?: number;
|
|
61
|
+
/** 402: when the monthly count starts over (ISO date) */
|
|
62
|
+
resetsAt?: string;
|
|
63
|
+
/** 402: a paid plan lifts the limit (https://saci.cc/pricing/) */
|
|
64
|
+
upgrade?: boolean;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
47
67
|
export declare class SaciError extends Error {
|
|
48
68
|
readonly status: number;
|
|
49
|
-
|
|
69
|
+
/** The API's JSON answer, when there was one */
|
|
70
|
+
readonly body: SaciErrorBody | null;
|
|
71
|
+
constructor(message: string, status: number,
|
|
72
|
+
/** The API's JSON answer, when there was one */
|
|
73
|
+
body?: SaciErrorBody | null);
|
|
50
74
|
}
|
|
51
75
|
export declare class SaciTimeoutError extends Error {
|
|
52
76
|
constructor(message: string);
|
|
@@ -80,7 +104,10 @@ export declare class Inbox {
|
|
|
80
104
|
waitForEmail(options?: WaitOptions): Promise<Email>;
|
|
81
105
|
/** Waits for an email with a verification code and returns the code, e.g. "482913" */
|
|
82
106
|
waitForCode(options?: WaitOptions): Promise<string>;
|
|
83
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Waits for an email with a link and returns it: the one matching `match`, if given,
|
|
109
|
+
* otherwise the link to confirm the address or sign in, or else the first link
|
|
110
|
+
*/
|
|
84
111
|
waitForLink(options?: WaitForLinkOptions): Promise<string>;
|
|
85
112
|
private waitFor;
|
|
86
113
|
toString(): string;
|
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
|
}
|
|
@@ -59,8 +63,9 @@ export class Saci {
|
|
|
59
63
|
continue;
|
|
60
64
|
}
|
|
61
65
|
if (!res.ok) {
|
|
66
|
+
// 402 (the free plan's monthly inboxes) isn't retried: it lasts until the month turns
|
|
62
67
|
const body = (await res.json().catch(() => null));
|
|
63
|
-
throw new SaciError(`${method} ${path} failed with ${res.status}: ${body?.error ?? res.statusText}`, res.status);
|
|
68
|
+
throw new SaciError(`${method} ${path} failed with ${res.status}: ${body?.error ?? res.statusText}`, res.status, body);
|
|
64
69
|
}
|
|
65
70
|
return (res.status === 204 ? undefined : await res.json());
|
|
66
71
|
}
|
|
@@ -96,15 +101,21 @@ export class Inbox {
|
|
|
96
101
|
}
|
|
97
102
|
/** Waits for an email with a verification code and returns the code, e.g. "482913" */
|
|
98
103
|
waitForCode(options = {}) {
|
|
99
|
-
return this.waitFor(options, (email) => email.verificationCode, "verification code");
|
|
104
|
+
return this.waitFor(options, (email) => email.verificationCode, "verification code", (summary) => summary.verificationCode);
|
|
100
105
|
}
|
|
101
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Waits for an email with a link and returns it: the one matching `match`, if given,
|
|
108
|
+
* otherwise the link to confirm the address or sign in, or else the first link
|
|
109
|
+
*/
|
|
102
110
|
waitForLink(options = {}) {
|
|
103
|
-
|
|
111
|
+
const { match } = options;
|
|
112
|
+
const verification = (email) => email.verificationLink && matches(email.verificationLink, match) ? email.verificationLink : null;
|
|
113
|
+
return this.waitFor(options, (email) => verification(email) ?? email.links.find((link) => matches(link, match)) ?? null, match === undefined ? "link" : `link matching ${match}`, verification);
|
|
104
114
|
}
|
|
105
115
|
// Long-polls the inbox until `pick` finds something in an email that passes the filters.
|
|
106
|
-
// Each email is opened at most once; newer emails are checked first.
|
|
107
|
-
|
|
116
|
+
// Each email is opened at most once; newer emails are checked first. The list already has
|
|
117
|
+
// the code and link the API found, so `fromSummary` can answer without opening the email.
|
|
118
|
+
async waitFor(options, pick, what, fromSummary) {
|
|
108
119
|
const deadline = Date.now() + (options.timeout ?? DEFAULT_TIMEOUT_MS);
|
|
109
120
|
const after = options.after === undefined ? NaN : new Date(options.after).getTime();
|
|
110
121
|
const checked = new Set();
|
|
@@ -124,7 +135,7 @@ export class Inbox {
|
|
|
124
135
|
continue;
|
|
125
136
|
if (!matches(summary.from, options.from) || !matches(summary.subject, options.subject))
|
|
126
137
|
continue;
|
|
127
|
-
const found = pick(await this.get(summary.messageId));
|
|
138
|
+
const found = fromSummary?.(summary) ?? pick(await this.get(summary.messageId));
|
|
128
139
|
if (found !== null && found !== undefined)
|
|
129
140
|
return found;
|
|
130
141
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saci.cc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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",
|