saci.cc 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rafael Franco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,166 @@
1
- # Temporary Holding Version
1
+ # saci.cc
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Temporary email inboxes for end-to-end tests. Create an address on [saci.cc](https://saci.cc), use it to sign up in your app, and wait for the verification code or confirmation link.
4
+
5
+ Free, no account, no API key. No dependencies; works in Node 18+, Bun, Deno and browsers.
6
+
7
+ ```bash
8
+ npm install --save-dev saci.cc
9
+ ```
10
+
11
+ ```ts
12
+ import { createInbox } from "saci.cc";
13
+
14
+ const inbox = await createInbox();
15
+ console.log(inbox.address); // a1b2c3d4e5f60718@saci.cc
16
+
17
+ // ...sign up with inbox.address...
18
+
19
+ const code = await inbox.waitForCode(); // "482913"
20
+ ```
21
+
22
+ ## Playwright
23
+
24
+ ```ts
25
+ import { test, expect } from "@playwright/test";
26
+ import { createInbox } from "saci.cc";
27
+
28
+ test("sign up with a verification code", async ({ page }) => {
29
+ test.setTimeout(90_000); // waiting for an email can take longer than the default 30 s
30
+
31
+ const inbox = await createInbox();
32
+ await page.goto("https://your-app.com/signup");
33
+ await page.getByLabel("Email").fill(inbox.address);
34
+ await page.getByLabel("Password").fill("correct horse battery staple");
35
+ await page.getByRole("button", { name: "Sign up" }).click();
36
+
37
+ const code = await inbox.waitForCode({ from: "your-app.com" });
38
+ await page.getByLabel("Verification code").fill(code);
39
+ await page.getByRole("button", { name: "Verify" }).click();
40
+ await expect(page.getByText("Welcome")).toBeVisible();
41
+ });
42
+
43
+ test("reset a password", async ({ page }) => {
44
+ test.setTimeout(90_000);
45
+
46
+ const inbox = await createInbox();
47
+ // ...create an account with inbox.address...
48
+
49
+ const requestedAt = new Date();
50
+ await page.goto("https://your-app.com/forgot-password");
51
+ await page.getByLabel("Email").fill(inbox.address);
52
+ await page.getByRole("button", { name: "Send link" }).click();
53
+
54
+ // `after` skips the emails that were already in the inbox
55
+ const link = await inbox.waitForLink({ match: "/reset-password", after: requestedAt });
56
+ await page.goto(link);
57
+ await page.getByLabel("New password").fill("another horse battery staple");
58
+ await page.getByRole("button", { name: "Save" }).click();
59
+ });
60
+ ```
61
+
62
+ ## Cypress
63
+
64
+ Cypress tests run in the browser, so call saci from Node with tasks in `cypress.config.ts`:
65
+
66
+ ```ts
67
+ import { defineConfig } from "cypress";
68
+ import { Saci } from "saci.cc";
69
+
70
+ const saci = new Saci();
71
+
72
+ export default defineConfig({
73
+ e2e: {
74
+ setupNodeEvents(on) {
75
+ on("task", {
76
+ createInbox: async () => (await saci.createInbox()).address,
77
+ waitForCode: (address: string) => saci.inbox(address).waitForCode(),
78
+ waitForLink: ({ address, match }: { address: string; match: string }) =>
79
+ saci.inbox(address).waitForLink({ match }),
80
+ });
81
+ },
82
+ },
83
+ });
84
+ ```
85
+
86
+ ```ts
87
+ it("signs up with a verification code", () => {
88
+ cy.task<string>("createInbox").then((address) => {
89
+ cy.visit("/signup");
90
+ cy.get("input[name=email]").type(address);
91
+ cy.get("input[name=password]").type("correct horse battery staple");
92
+ cy.contains("button", "Sign up").click();
93
+
94
+ // cy.task gives up after 60 s by default; give the email time to arrive
95
+ cy.task<string>("waitForCode", address, { timeout: 90_000 }).then((code) => {
96
+ cy.get("input[name=code]").type(code);
97
+ cy.contains("button", "Verify").click();
98
+ cy.contains("Welcome");
99
+ });
100
+ });
101
+ });
102
+ ```
103
+
104
+ ## API
105
+
106
+ ### `createInbox(options?)`
107
+
108
+ Creates an inbox and returns an `Inbox`. Without `name` the address is random (16 hex characters), so nobody else can guess it. With `name: "signup-test"` you get `signup-test@saci.cc`, which anyone can read.
109
+
110
+ ### `inbox.waitForCode(options?)`, `inbox.waitForLink(options?)`, `inbox.waitForEmail(options?)`
111
+
112
+ Wait for an email and return its verification code, a link in it, or the whole email. They keep waiting until something matches or the timeout runs out, then throw `SaciTimeoutError`.
113
+
114
+ | Option | Description |
115
+ | --------- | ------------------------------------------------------------------------------- |
116
+ | `from` | Only emails whose sender contains this text (case-insensitive) or matches a RegExp |
117
+ | `subject` | Only emails whose subject contains this text (case-insensitive) or matches a RegExp |
118
+ | `after` | Only emails received after this `Date` or ISO string |
119
+ | `timeout` | Milliseconds to wait. Default `60000` |
120
+ | `match` | `waitForLink` only: the link must contain this text or match a RegExp. Without it, the first link |
121
+
122
+ An email looks like this:
123
+
124
+ ```ts
125
+ {
126
+ messageId: "0100019a2b3c4d5e-...",
127
+ from: "GitHub <noreply@github.com>",
128
+ subject: "[GitHub] Please verify your email address",
129
+ receivedAt: "2026-10-20T15:30:00.000Z",
130
+ html: "<p>Your code is <b>482913</b></p>",
131
+ text: "Your code is 482913",
132
+ verificationCode: "482913", // or null
133
+ links: ["https://github.com/settings/emails"],
134
+ attachments: [{ index: 0, filename: "invoice.pdf", contentType: "application/pdf", size: 48213, inline: false, url: "https://..." }],
135
+ }
136
+ ```
137
+
138
+ ### Other methods
139
+
140
+ - `inbox.address`: the email address (`String(inbox)` gives the same).
141
+ - `inbox.list()`: summaries of the emails in the inbox, newest first.
142
+ - `inbox.get(messageId)`: one email in full.
143
+ - `inbox.delete(messageId)` and `inbox.clear()`: delete one email or all of them.
144
+ - `new Saci().inbox(address)`: an `Inbox` for an address created earlier.
145
+ - `new Saci({ baseUrl, fetch })`: point at another deployment or pass your own `fetch`.
146
+
147
+ Failed requests throw `SaciError`, which has the HTTP `status`.
148
+
149
+ ## Limits
150
+
151
+ - 120 requests per minute per IP. The client waits and retries when it gets a 429.
152
+ - Emails are deleted about a day after they arrive.
153
+ - There are no passwords: anyone who knows an address can read its inbox. Don't use it for anything sensitive.
154
+ - Addresses only receive email.
155
+
156
+ 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.
157
+
158
+ ## Development
159
+
160
+ ```bash
161
+ npm install
162
+ npm test
163
+ npm run build
164
+ ```
165
+
166
+ Every push to `main` is released by [semantic-release](https://github.com/semantic-release/semantic-release): the version comes from the commit messages ([Conventional Commits](https://www.conventionalcommits.org/): `fix:` → patch, `feat:` → minor, `BREAKING CHANGE:` → major), and the package is published to npm with a GitHub release and a `CHANGELOG.md` entry.
@@ -0,0 +1,88 @@
1
+ export declare const DEFAULT_BASE_URL = "https://saci.cc/api";
2
+ export interface EmailSummary {
3
+ messageId: string;
4
+ from: string;
5
+ subject: string;
6
+ receivedAt?: string;
7
+ }
8
+ export interface Attachment {
9
+ index: number;
10
+ filename: string;
11
+ contentType: string;
12
+ size: number;
13
+ /** Shown inside the email body (e.g. an embedded image) rather than attached */
14
+ inline: boolean;
15
+ /** Redirects to a download link that works for a few minutes */
16
+ url: string;
17
+ }
18
+ export interface Email extends EmailSummary {
19
+ html: string | null;
20
+ text: string | null;
21
+ /** The verification code found in the subject or body, if any */
22
+ verificationCode: string | null;
23
+ links: string[];
24
+ attachments: Attachment[];
25
+ }
26
+ export interface SaciOptions {
27
+ /** Defaults to https://saci.cc/api */
28
+ baseUrl?: string;
29
+ fetch?: typeof fetch;
30
+ }
31
+ export interface WaitOptions {
32
+ /** Only emails whose sender contains this text (case-insensitive) or matches this pattern */
33
+ from?: string | RegExp;
34
+ /** Only emails whose subject contains this text (case-insensitive) or matches this pattern */
35
+ subject?: string | RegExp;
36
+ /** Only emails received after this moment. Useful when the inbox already has emails. */
37
+ after?: Date | string;
38
+ /** How long to wait, in milliseconds. Defaults to 60 seconds. */
39
+ timeout?: number;
40
+ }
41
+ export interface WaitForLinkOptions extends WaitOptions {
42
+ /** Only links that contain this text or match this pattern. Without it, the first link. */
43
+ match?: string | RegExp;
44
+ }
45
+ export declare class SaciError extends Error {
46
+ readonly status: number;
47
+ constructor(message: string, status: number);
48
+ }
49
+ export declare class SaciTimeoutError extends Error {
50
+ constructor(message: string);
51
+ }
52
+ export declare class Saci {
53
+ readonly baseUrl: string;
54
+ private readonly fetch;
55
+ constructor(options?: SaciOptions);
56
+ /** Creates an inbox. Without a name the address is random, which keeps it private. */
57
+ createInbox(options?: {
58
+ name?: string;
59
+ }): Promise<Inbox>;
60
+ /** An inbox that already exists, e.g. one created in another test step */
61
+ inbox(address: string): Inbox;
62
+ /** @internal */
63
+ request<T>(method: "GET" | "POST" | "DELETE", path: string): Promise<T>;
64
+ }
65
+ export declare class Inbox {
66
+ private readonly saci;
67
+ readonly address: string;
68
+ constructor(saci: Saci, address: string);
69
+ private path;
70
+ /** The emails in the inbox, newest first */
71
+ list(): Promise<EmailSummary[]>;
72
+ get(messageId: string): Promise<Email>;
73
+ delete(messageId: string): Promise<void>;
74
+ /** Deletes every email in the inbox and returns how many there were */
75
+ clear(): Promise<number>;
76
+ /** Waits for an email that matches the filters and returns it in full */
77
+ waitForEmail(options?: WaitOptions): Promise<Email>;
78
+ /** Waits for an email with a verification code and returns the code, e.g. "482913" */
79
+ waitForCode(options?: WaitOptions): Promise<string>;
80
+ /** Waits for an email with a link (matching `match`, if given) and returns the link */
81
+ waitForLink(options?: WaitForLinkOptions): Promise<string>;
82
+ private waitFor;
83
+ toString(): string;
84
+ }
85
+ /** Creates an inbox on saci.cc. Shortcut for `new Saci().createInbox()`. */
86
+ export declare const createInbox: (options?: {
87
+ name?: string;
88
+ }) => Promise<Inbox>;
package/dist/index.js ADDED
@@ -0,0 +1,137 @@
1
+ // Client for the saci.cc API: create temporary inboxes and wait for emails, verification
2
+ // codes and links. No dependencies; needs a global fetch (Node 18+, Deno, Bun, browsers).
3
+ export const DEFAULT_BASE_URL = "https://saci.cc/api";
4
+ /** The API holds a request open for at most this long while waiting for an email */
5
+ const MAX_WAIT_SECONDS = 25;
6
+ const DEFAULT_TIMEOUT_MS = 60_000;
7
+ const MAX_RATE_LIMIT_RETRIES = 3;
8
+ export class SaciError extends Error {
9
+ status;
10
+ constructor(message, status) {
11
+ super(message);
12
+ this.status = status;
13
+ this.name = "SaciError";
14
+ }
15
+ }
16
+ export class SaciTimeoutError extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = "SaciTimeoutError";
20
+ }
21
+ }
22
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
23
+ const matches = (value, filter) => filter === undefined ||
24
+ (typeof filter === "string" ? value.toLowerCase().includes(filter.toLowerCase()) : filter.test(value));
25
+ const timeOf = (date) => (date ? Date.parse(date) : NaN);
26
+ export class Saci {
27
+ baseUrl;
28
+ fetch;
29
+ constructor(options = {}) {
30
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
31
+ this.fetch = options.fetch ?? ((...args) => globalThis.fetch(...args));
32
+ }
33
+ /** Creates an inbox. Without a name the address is random, which keeps it private. */
34
+ async createInbox(options = {}) {
35
+ const query = options.name === undefined ? "" : `?name=${encodeURIComponent(options.name)}`;
36
+ const { address } = await this.request("POST", `/addresses${query}`);
37
+ return new Inbox(this, address);
38
+ }
39
+ /** An inbox that already exists, e.g. one created in another test step */
40
+ inbox(address) {
41
+ return new Inbox(this, address);
42
+ }
43
+ /** @internal */
44
+ async request(method, path) {
45
+ for (let attempt = 0;; attempt++) {
46
+ const res = await this.fetch(this.baseUrl + path, { method });
47
+ // Over the per-IP rate limit: wait as long as the API asks, then try again
48
+ if (res.status === 429 && attempt < MAX_RATE_LIMIT_RETRIES) {
49
+ const retryAfter = Number(res.headers.get("retry-after") ?? NaN);
50
+ await sleep((Number.isFinite(retryAfter) ? retryAfter : 5) * 1000);
51
+ continue;
52
+ }
53
+ if (!res.ok) {
54
+ const body = (await res.json().catch(() => null));
55
+ throw new SaciError(`${method} ${path} failed with ${res.status}: ${body?.error ?? res.statusText}`, res.status);
56
+ }
57
+ return (res.status === 204 ? undefined : await res.json());
58
+ }
59
+ }
60
+ }
61
+ export class Inbox {
62
+ saci;
63
+ address;
64
+ constructor(saci, address) {
65
+ this.saci = saci;
66
+ this.address = address;
67
+ }
68
+ path(suffix = "") {
69
+ return `/addresses/${encodeURIComponent(this.address)}/emails${suffix}`;
70
+ }
71
+ /** The emails in the inbox, newest first */
72
+ async list() {
73
+ return (await this.saci.request("GET", this.path())).emails;
74
+ }
75
+ async get(messageId) {
76
+ return this.saci.request("GET", this.path(`/${encodeURIComponent(messageId)}`));
77
+ }
78
+ async delete(messageId) {
79
+ await this.saci.request("DELETE", this.path(`/${encodeURIComponent(messageId)}`));
80
+ }
81
+ /** Deletes every email in the inbox and returns how many there were */
82
+ async clear() {
83
+ return (await this.saci.request("DELETE", this.path())).deleted;
84
+ }
85
+ /** Waits for an email that matches the filters and returns it in full */
86
+ waitForEmail(options = {}) {
87
+ return this.waitFor(options, (email) => email, "matching email");
88
+ }
89
+ /** Waits for an email with a verification code and returns the code, e.g. "482913" */
90
+ waitForCode(options = {}) {
91
+ return this.waitFor(options, (email) => email.verificationCode, "verification code");
92
+ }
93
+ /** Waits for an email with a link (matching `match`, if given) and returns the link */
94
+ waitForLink(options = {}) {
95
+ return this.waitFor(options, (email) => email.links.find((link) => matches(link, options.match)) ?? null, options.match === undefined ? "link" : `link matching ${options.match}`);
96
+ }
97
+ // Long-polls the inbox until `pick` finds something in an email that passes the filters.
98
+ // Each email is opened at most once; newer emails are checked first.
99
+ async waitFor(options, pick, what) {
100
+ const deadline = Date.now() + (options.timeout ?? DEFAULT_TIMEOUT_MS);
101
+ const after = options.after === undefined ? NaN : new Date(options.after).getTime();
102
+ const checked = new Set();
103
+ // The API returns as soon as there's an email received after `cursor`
104
+ let cursor = Number.isNaN(after) ? undefined : new Date(after).toISOString();
105
+ for (;;) {
106
+ const wait = Math.min(Math.max(Math.ceil((deadline - Date.now()) / 1000), 0), MAX_WAIT_SECONDS);
107
+ const query = new URLSearchParams({ wait: String(wait) });
108
+ if (cursor)
109
+ query.set("after", cursor);
110
+ const { emails } = await this.saci.request("GET", this.path(`?${query}`));
111
+ for (const summary of emails) {
112
+ if (checked.has(summary.messageId))
113
+ continue;
114
+ checked.add(summary.messageId);
115
+ if (!Number.isNaN(after) && !(timeOf(summary.receivedAt) > after))
116
+ continue;
117
+ if (!matches(summary.from, options.from) || !matches(summary.subject, options.subject))
118
+ continue;
119
+ const found = pick(await this.get(summary.messageId));
120
+ if (found !== null && found !== undefined)
121
+ return found;
122
+ }
123
+ const newest = Math.max(...emails.map((e) => timeOf(e.receivedAt)).filter((t) => !Number.isNaN(t)));
124
+ if (Number.isFinite(newest) && (!cursor || newest > Date.parse(cursor)))
125
+ cursor = new Date(newest).toISOString();
126
+ if (Date.now() >= deadline) {
127
+ throw new SaciTimeoutError(`No ${what} arrived at ${this.address} within ${options.timeout ?? DEFAULT_TIMEOUT_MS} ms`);
128
+ }
129
+ }
130
+ }
131
+ toString() {
132
+ return this.address;
133
+ }
134
+ }
135
+ const defaultClient = new Saci();
136
+ /** Creates an inbox on saci.cc. Shortcut for `new Saci().createInbox()`. */
137
+ export const createInbox = (options) => defaultClient.createInbox(options);
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "saci.cc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Temporary email inboxes for end-to-end tests: wait for verification codes and links from saci.cc",
5
+ "keywords": [
6
+ "temporary email",
7
+ "disposable email",
8
+ "email testing",
9
+ "e2e",
10
+ "playwright",
11
+ "cypress",
12
+ "otp",
13
+ "verification code"
14
+ ],
15
+ "homepage": "https://saci.cc/en/docs/",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/rfoel/saci.cc-client.git"
19
+ },
20
+ "license": "MIT",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "engines": {
32
+ "node": ">=18"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.build.json",
36
+ "typecheck": "tsc --noEmit",
37
+ "test": "vitest run",
38
+ "prepublishOnly": "npm run build"
39
+ },
40
+ "devDependencies": {
41
+ "@semantic-release/changelog": "^7.0.0",
42
+ "@semantic-release/git": "^11.0.1",
43
+ "semantic-release": "^25.0.9",
44
+ "typescript": "^7.0.2",
45
+ "vitest": "^5.0.5"
46
+ }
47
+ }