saci.cc 1.1.0 → 1.2.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 +10 -5
- package/dist/index.d.ts +14 -2
- package/dist/index.js +12 -6
- package/package.json +1 -1
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: 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,7 +148,7 @@ 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.
|
|
@@ -157,7 +161,8 @@ Failed requests throw `SaciError`, which has the HTTP `status`. A missing or rev
|
|
|
157
161
|
|
|
158
162
|
- 120 requests per minute per API key's account. The client waits and retries when it gets a 429.
|
|
159
163
|
- Emails are deleted about a day after they arrive.
|
|
160
|
-
-
|
|
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? 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)).
|
|
161
166
|
- Addresses only receive email.
|
|
162
167
|
|
|
163
168
|
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,7 +47,10 @@ 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
|
}
|
|
47
56
|
export declare class SaciError extends Error {
|
|
@@ -80,7 +89,10 @@ export declare class Inbox {
|
|
|
80
89
|
waitForEmail(options?: WaitOptions): Promise<Email>;
|
|
81
90
|
/** Waits for an email with a verification code and returns the code, e.g. "482913" */
|
|
82
91
|
waitForCode(options?: WaitOptions): Promise<string>;
|
|
83
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Waits for an email with a link and returns it: the one matching `match`, if given,
|
|
94
|
+
* otherwise the link to confirm the address or sign in, or else the first link
|
|
95
|
+
*/
|
|
84
96
|
waitForLink(options?: WaitForLinkOptions): Promise<string>;
|
|
85
97
|
private waitFor;
|
|
86
98
|
toString(): string;
|
package/dist/index.js
CHANGED
|
@@ -96,15 +96,21 @@ export class Inbox {
|
|
|
96
96
|
}
|
|
97
97
|
/** Waits for an email with a verification code and returns the code, e.g. "482913" */
|
|
98
98
|
waitForCode(options = {}) {
|
|
99
|
-
return this.waitFor(options, (email) => email.verificationCode, "verification code");
|
|
99
|
+
return this.waitFor(options, (email) => email.verificationCode, "verification code", (summary) => summary.verificationCode);
|
|
100
100
|
}
|
|
101
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Waits for an email with a link and returns it: the one matching `match`, if given,
|
|
103
|
+
* otherwise the link to confirm the address or sign in, or else the first link
|
|
104
|
+
*/
|
|
102
105
|
waitForLink(options = {}) {
|
|
103
|
-
|
|
106
|
+
const { match } = options;
|
|
107
|
+
const verification = (email) => email.verificationLink && matches(email.verificationLink, match) ? email.verificationLink : null;
|
|
108
|
+
return this.waitFor(options, (email) => verification(email) ?? email.links.find((link) => matches(link, match)) ?? null, match === undefined ? "link" : `link matching ${match}`, verification);
|
|
104
109
|
}
|
|
105
110
|
// 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
|
-
|
|
111
|
+
// Each email is opened at most once; newer emails are checked first. The list already has
|
|
112
|
+
// the code and link the API found, so `fromSummary` can answer without opening the email.
|
|
113
|
+
async waitFor(options, pick, what, fromSummary) {
|
|
108
114
|
const deadline = Date.now() + (options.timeout ?? DEFAULT_TIMEOUT_MS);
|
|
109
115
|
const after = options.after === undefined ? NaN : new Date(options.after).getTime();
|
|
110
116
|
const checked = new Set();
|
|
@@ -124,7 +130,7 @@ export class Inbox {
|
|
|
124
130
|
continue;
|
|
125
131
|
if (!matches(summary.from, options.from) || !matches(summary.subject, options.subject))
|
|
126
132
|
continue;
|
|
127
|
-
const found = pick(await this.get(summary.messageId));
|
|
133
|
+
const found = fromSummary?.(summary) ?? pick(await this.get(summary.messageId));
|
|
128
134
|
if (found !== null && found !== undefined)
|
|
129
135
|
return found;
|
|
130
136
|
}
|