@plexuslabs/simmail 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,55 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1 (2026-10-14)
4
+
5
+ Covers the whole customer API, and adds an object layer on top of the plain calls.
6
+
7
+ - **Every endpoint**: mailboxes and folders, reading, raw messages and attachments, marking and moving,
8
+ threads, injecting, signatures, rescue and retry; logins; people (memory, relations, learning from
9
+ mail, temperaments); cases (people, initiate, regenerate, the story); jobs; the event log and the
10
+ live event stream (`events()`, an async iterator); AI, pace, recipients, links, retention and Spam &
11
+ Junk settings; faults and scenarios; inspection and insights; webhooks; the World; `universes`,
12
+ `status` and connection details.
13
+ - **Objects**: `Message`, `Mailbox`, `Persona`, `Case`, `Job` and `Account`, with the API's fields,
14
+ camelCase getters and methods (`msg.reply()`, `msg.waitForReply()`, `mailbox.waitForEmail()`,
15
+ `persona.runDue()`, `deal.initiate()`, …). Waits and lists return them. They are supersets of the
16
+ 0.1.0 answers, so code reading `msg.magic_links` keeps working.
17
+ - **Groups**: `mail.personas`, `mail.cases`, `mail.clock`, `mail.jobs`, `mail.world`, `mail.faults`,
18
+ `mail.recipients`, `mail.webhooks`, `mail.insights`, `mail.events`, `mail.accounts`, `mail.inspect`,
19
+ `mail.behaviour`. Each is also callable as the 0.1.0 method of the same name.
20
+ - **Test addresses**: `mail.testAddress({ tag })` makes a fresh address (a `TestAddress` with
21
+ `waitForEmail()`, `expectNoEmail()`, `list()` and `cleanup()`); `mail.tag(name)` works on every
22
+ address with a tag; `listMessages` and `deleteMessages` across addresses.
23
+ - **Waits**: `waitForEmail` takes several addresses or `*@domain`, `tag`, `count` (waits for n),
24
+ `since`, `exclude`, `subjectRegex`/`bodyRegex` (a RegExp works), `header`, `hasAttachment`,
25
+ `attachmentName` and `linkDomain`; a timeout says what almost matched (`nearMisses`).
26
+ `expectNoEmail` passes when nothing comes. `waitForEvent` (`persona.waitFor("replied")`) waits for
27
+ something a person does; `waitForThread` (`msg.waitUntilQuiet()`) for a conversation to go quiet,
28
+ as a `Conversation`.
29
+ - **Jobs**: filters (`persona`, `kind`, `dueBefore`, `limit`) and `runDue` (`mail.jobs.runDue()`,
30
+ `persona.runDue()`), on the server.
31
+ - **Named values** for every setting with fixed choices (`Temperament`, `FaultScenario`,
32
+ `MailboxStatus`, `EventType`, `EventAlias`, `ErrorCode`, …), each the API's plain string, generated
33
+ from `GET /api/schema` (`sdk/tools/gen_enums.py`); `EnumInfo` and `describe()` give each value's
34
+ label and description. `mail.schema()` returns the schema itself.
35
+ - **Errors by kind**, chosen by the server's error code: `ValidationError`, `AuthError`,
36
+ `PlanLimitError`, `ForbiddenError`, `NotFoundError`, `WaitTimeoutError`, `ConflictError`,
37
+ `UnexpectedEmailError`, `IdempotencyError`, `RateLimitedError`, all `SimmailError`, which carries
38
+ `code`, `requestId`, `field`, `allowed` and `nearMisses`.
39
+ - **Safe retries**: every `send` and `inject` has its own Idempotency-Key (yours with
40
+ `idempotencyKey`, none with `false`), and answers say `replayed`. GETs and keyed writes are tried
41
+ again after a network error, 502 or 503 (`retries`, default 2). `mail.withRequestId(id)` sends your
42
+ own request id; answers and errors carry `requestId`.
43
+
44
+ ## 0.1.0
45
+
46
+ First release.
47
+
48
+ - `waitForEmail`, `waitForReply`: wait for the next email to an address, or a person's reply; codes and magic links already pulled out.
49
+ - `extract`: codes and links from any text or HTML.
50
+ - `mailboxes`, `messages`, `message`: what is in the universe's mailboxes.
51
+ - `send` (with `inReplyTo`), `health` (the inspection report).
52
+ - `accounts`, `createAccount`: your app's SMTP/IMAP logins.
53
+ - `personas`, `createPersona`, `pushCase`.
54
+ - `clock`, `advance`, `freeze`, `speed`, `live`.
55
+ - Settings from `SIMMAIL_URL`, `SIMMAIL_API_KEY`, `SIMMAIL_UNIVERSE`; errors as `SimmailError` with the HTTP status.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,209 @@
1
- # Temporary Holding Version
1
+ # @plexuslabs/simmail
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
+ The official JavaScript and TypeScript client for [simmail](https://www.simmail.dev): a simulated email
4
+ world for testing apps and email agents. Wait for the email your app sends, pull out the code or
5
+ link, get replies from simulated people, and drive the whole world: people, cases, the clock, the
6
+ World's inbound mail, faults, recipients and webhooks.
7
+
8
+ No dependencies; Node 18 or newer. Full docs: https://www.simmail.dev/docs/
9
+
10
+ ```sh
11
+ npm install --save-dev @plexuslabs/simmail
12
+ ```
13
+
14
+ ## Setup
15
+
16
+ The client reads its settings from the environment, or takes them in `new Simmail({...})`:
17
+
18
+ | Variable | Meaning |
19
+ | --- | --- |
20
+ | `SIMMAIL_URL` | Your universe's server, such as `https://c1.simmail.dev` (shown on your account page). |
21
+ | `SIMMAIL_API_KEY` | An API key, `smk_…` (Organization → API keys). |
22
+ | `SIMMAIL_UNIVERSE` | Optional: only needed when the key can reach more than one universe. |
23
+
24
+ Your app sends through simmail's SMTP as usual (the dashboard's *Get started* shows the settings);
25
+ this client is for your tests and tools.
26
+
27
+ ## Wait for an email and use its code (Playwright)
28
+
29
+ ```js
30
+ import { test, expect } from "@playwright/test";
31
+ import { Simmail } from "@plexuslabs/simmail";
32
+
33
+ const mail = new Simmail();
34
+
35
+ test("new users can verify their email", async ({ page }) => {
36
+ const email = `user-${Date.now()}@yourcompany.test`;
37
+ await page.goto("/signup");
38
+ await page.fill("#email", email);
39
+
40
+ const waiting = mail.mailbox(email).waitForEmail({ subject: "verify", timeout: "20s" });
41
+ await page.click("text=Create account");
42
+ const msg = await waiting;
43
+
44
+ expect(msg.codes).toHaveLength(1);
45
+ await page.fill("#code", msg.codes[0]); // or: await page.goto(msg.magicLinks[0])
46
+ });
47
+ ```
48
+
49
+ Start the wait before the click: a wait only sees mail that arrives after it starts, unless you
50
+ pass `existing: true`.
51
+
52
+ ## A fresh address per test
53
+
54
+ ```js
55
+ const addr = await mail.testAddress({ tag: "signup" }); // such as t-k3x9q@inbox.test
56
+ await page.fill("#email", addr.address);
57
+ await page.click("text=Create account");
58
+
59
+ const welcome = await addr.waitForEmail({ subjectRegex: /welcome/i, timeout: "20s" });
60
+ await addr.expectNoEmail({ within: "5s", subject: "verify" }); // no second email
61
+ await addr.cleanup(); // or mail.tag("signup").cleanup()
62
+ ```
63
+
64
+ `waitForEmail` also takes several addresses or `*@domain`, `count` (wait for n emails), `since`,
65
+ `exclude`, `bodyRegex`, `header`, `hasAttachment`, `attachmentName` and `linkDomain`. When nothing
66
+ matches, the `WaitTimeoutError` lists what almost did and why (`nearMisses`).
67
+
68
+ ## Objects you can act on
69
+
70
+ Answers come back as objects with the API's fields and methods for what you do next:
71
+
72
+ ```js
73
+ import { Simmail, Folder } from "@plexuslabs/simmail";
74
+
75
+ const msg = await mail.mailbox("app@yourcompany.test").waitForEmail({ from: "dana@harbor.test" });
76
+ await msg.reply({ text: "Thanks, Dana. Tuesday works." }); // threaded, from the mailbox it is in
77
+ const answer = await msg.waitForReply(); // Dana's next email in this thread
78
+ await msg.markRead();
79
+ await msg.move(Folder.Archive);
80
+ const report = await msg.health(); // for mail your app sent: spam score, links
81
+
82
+ for await (const m of mail.mailbox("dana@harbor.test").messages({ folder: Folder.Junk })) {
83
+ console.log(m.subject, m.isRead);
84
+ }
85
+ ```
86
+
87
+ | Object | What it has |
88
+ | --- | --- |
89
+ | `Message` | `messageId`, `from`, `to`, `subject`, `text`, `html`, `codes`, `magicLinks`, `attachments`; `full()`, `reply()`, `waitForReply()`, `waitUntilQuiet()`, `health()`, `source()`, `attachment(n)`, `markRead()`, `move()` |
90
+ | `Mailbox` | `address`, counts; `waitForEmail()`, `messages()` (async iterator), `list()`, `send()`, `inject()`, `folders()`, `threads()`, `setStatus()` |
91
+ | `Persona` | the person's fields; `update()`, `pause()`, `remember()`, `memory()`, `relations()`, `jobs()`, `runDue()`, `waitFor()`, `waitForReply()`, `mailbox()` |
92
+ | `Case` | `people`, `story`; `push()`, `addPeople()`, `initiate()`, `regenerate()`, `editStory()` |
93
+ | `Job` | `kind`, `state`, `due`; `run()`, `skip()`, `bounce()`, `reschedule()` |
94
+ | `TestAddress` | a fresh address (a `Mailbox`); `waitForEmail()`, `expectNoEmail()`, `list()`, `cleanup()` |
95
+ | `Conversation` | `messages`, `latest`; `waitUntilQuiet()`, `reply()` |
96
+ | `SimEvent` | `kind`, `data`, `personaId`, `messageId`; `persona()` |
97
+ | `Account` | a login; `update()`, `test()`, `delete()` |
98
+
99
+ Every object still has the API's own field names (`msg.message_id`, `msg.magic_links`), `.raw`
100
+ for the answer as it came, and serialises to it with `JSON.stringify`.
101
+
102
+ ## People, cases and the clock
103
+
104
+ ```js
105
+ import { Simmail, Temperament, LinkHabit, JobKind, EventAlias } from "@plexuslabs/simmail";
106
+
107
+ const dana = await mail.personas.create({
108
+ name: "Dana Reyes",
109
+ addresses: ["dana@harbor.test"],
110
+ temperament: Temperament.Skeptical,
111
+ style: { links: LinkHabit.Wary },
112
+ });
113
+
114
+ const deal = await mail.cases.push("deal-1701", {
115
+ title: "Sale of 1701 Clark Street",
116
+ people: [{ ref: "seller", name: "Dana Reyes", addresses: ["dana@harbor.test"] }],
117
+ });
118
+ await deal.initiate({ persona: dana.id, to: "agent@yourcompany.test", intent: "ask about the offer" });
119
+
120
+ await mail.clock.advance("2d"); // follow-ups and nudges that were due happen
121
+ await dana.runDue({ kind: JobKind.Reply }); // or run her pending replies now
122
+
123
+ const sent = await dana.waitFor(EventAlias.Replied, { fast: true }); // or "declined", "clicked", "bounced"
124
+ const talk = await msg.waitUntilQuiet({ quiet: "10s" }); // the whole conversation, once it settles
125
+ console.log(talk.messages.length, talk.latest.subject);
126
+ ```
127
+
128
+ ## Chaos, recipients, webhooks and the World
129
+
130
+ ```js
131
+ import { FaultScenario, MailboxStatus, StreamKind, EventType } from "@plexuslabs/simmail";
132
+
133
+ await mail.faults.add(FaultScenario.GmailRate, { match: "@gmail.com" }); // Gmail rate-limits you
134
+ await mail.recipients.setStatus("old-client@harbor.test", MailboxStatus.Disabled);
135
+ await mail.webhooks.set([{ url: "https://hooks.yourcompany.test/simmail", events: [EventType.PersonaSent, "link.*"] }]);
136
+ await mail.world.set({
137
+ company: { name: "Acme Realty", domain: "acme-realty.test" },
138
+ streams: [{ name: "Website leads", kind: StreamKind.Lead, to: ["sales@acme-realty.test"], per_day: 6, enabled: true }],
139
+ });
140
+
141
+ for await (const event of mail.events({ since: 0 })) { // the live stream
142
+ if (event.kind === EventType.PersonaSent) break;
143
+ }
144
+ ```
145
+
146
+ Each group (`mail.personas`, `mail.cases`, `mail.clock`, `mail.jobs`, `mail.world`, `mail.faults`,
147
+ `mail.recipients`, `mail.webhooks`, `mail.insights`, `mail.events`, `mail.accounts`, `mail.inspect`,
148
+ `mail.behaviour`) has the calls for that part of the API. The 0.1.0 methods (`mail.clock()`,
149
+ `mail.advance("2d")`, `mail.waitForEmail({ to })`, …) still work as before.
150
+
151
+ ## Named values
152
+
153
+ Every setting with fixed choices has named constants: `Temperament`, `Knows`, `Life`, `Length`,
154
+ `Formality`, `MailClient`, `LinkHabit`, `SpamFilter`, `Access`, `Stance`, `MailboxStatus`, `BadKind`,
155
+ `FailAt`, `Stranger`, `Folder`, `AiMode`, `MissingSite`, `LocalLinks`, `Protocol`, `Role`,
156
+ `PersonaSource`, `StreamKind`, `FaultKind`, `FaultStage`, `FaultScenario`, `JobKind`, `JobState`,
157
+ `StoryBy`, `EventType`, `EventAlias`, `ErrorCode`. Each is the API's plain string
158
+ (`Temperament.Skeptical === "skeptical"`), so the string works too. They are generated from the
159
+ server's `GET /api/schema`; `EnumInfo.Temperament.skeptical.description` and
160
+ `describe("Temperament", value)` give the words the dashboard shows.
161
+
162
+ ## What's covered
163
+
164
+ | Area | Calls |
165
+ | --- | --- |
166
+ | Waiting | `waitForEmail`, `expectNoEmail`, `waitForReply`, `waitForEvent`, `waitForThread`, `extract` |
167
+ | Test addresses | `testAddress`, `createAddress`, `tag`, `listMessages`, `deleteMessages` |
168
+ | Mail | `mailboxes`, `mailbox`, `folders`, `messages`, `message`, `rawMessage`, `attachment`, `updateMessage`, `threads`, `setMailboxStatus`, `send`, `inject`, `signature`, `setSignature`, `rescue`, `retry` |
169
+ | Logins | `accounts`, `createAccount`, `updateAccount`, `deleteAccount`, `testAccount` |
170
+ | People | `personas`, `persona`, `createPersona`, `updatePersona`, `deletePersona`, `personaFromMail`, `temperaments`, `memory`, `addMemory`, `clearMemory`, `addMemoryByExternal`, `relations`, `forgetRelations` |
171
+ | Cases | `cases`, `getCase`, `pushCase`, `addCasePeople`, `initiateCase`, `regenerateCase`, `editCaseStory`, `deleteCase` |
172
+ | Clock and jobs | `clock`, `advance`, `freeze`, `speed`, `live`, `jobs`, `runDue`, `runJob`, `skipJob`, `bounceJob`, `rescheduleJob` |
173
+ | Events | `events` (live stream), `log` |
174
+ | Behaviour | `ai`, `setAi`, `aiBudget`, `pace`, `setPace`, `recipients`, `setRecipients`, `links`, `setLinks`, `retention`, `setRetention`, `pruneRetention`, `junkSettings`, `setJunkSettings` |
175
+ | Chaos | `faults`, `setFaults`, `faultScenarios`, `addFaultScenario` |
176
+ | Inspection | `health`, `insights`, `insightShares`, `shareInsights`, `revokeInsightShare` |
177
+ | Webhooks and the World | `webhooks`, `setWebhooks`, `world`, `setWorld`, `sendFromStream` |
178
+ | Who and where | `me`, `universes`, `status`, `connection`, `connectionCert`, `schema` |
179
+
180
+ Anything else is one `mail.request(method, path, body, query)` call.
181
+
182
+ ## Errors
183
+
184
+ A failed call throws a `SimmailError` with the HTTP `status`, the server's message, its `code` (an
185
+ `ErrorCode`) and `requestId`. The subclasses say which kind: `ValidationError` (400, with `field` and
186
+ `allowed`), `AuthError` (401), `PlanLimitError` (402), `ForbiddenError` (403), `NotFoundError` (404),
187
+ `WaitTimeoutError` (408, with `nearMisses`), `ConflictError` (409, such as a person who decided not
188
+ to reply), `UnexpectedEmailError` (409, from `expectNoEmail`, with the `email`), `IdempotencyError`
189
+ (422) and `RateLimitedError` (429, with `retryAfter`).
190
+
191
+ Every `send` and `inject` carries its own Idempotency-Key, so the client can safely try a write
192
+ again: GETs and keyed writes are retried after a network error, 502 or 503 (`retries`, default 2),
193
+ and an answer the server had already given says `replayed: true`. To follow a request in the
194
+ server's logs, use `mail.withRequestId("ci-1234")`.
195
+
196
+ ```js
197
+ import { WaitTimeoutError } from "@plexuslabs/simmail";
198
+
199
+ try {
200
+ await mail.mailbox(email).waitForEmail({ subject: "verify", timeout: "10s" });
201
+ } catch (e) {
202
+ if (e instanceof WaitTimeoutError) console.log("nothing arrived", e.nearMisses);
203
+ else throw e;
204
+ }
205
+ ```
206
+
207
+ ## License
208
+
209
+ Apache-2.0
package/enums.d.ts ADDED
@@ -0,0 +1,103 @@
1
+ // Generated by sdk/tools/gen_enums.py from GET /api/schema (version 1). Do not edit by hand.
2
+
3
+ type OneOf<T> = T[keyof T];
4
+
5
+ /** How a person tends to answer. */
6
+ export declare const Temperament: { readonly Responsive: "responsive"; readonly Busy: "busy"; readonly Procedural: "procedural"; readonly Skeptical: "skeptical"; readonly Flaky: "flaky"; readonly Difficult: "difficult"; readonly Ghost: "ghost" };
7
+ export type Temperament = OneOf<typeof Temperament>;
8
+ /** How much a person knows about their case. */
9
+ export declare const Knows: { readonly All: "all"; readonly Some: "some"; readonly Little: "little" };
10
+ export type Knows = OneOf<typeof Knows>;
11
+ /** Whose hours a person's replies keep. */
12
+ export declare const Life: { readonly Work: "work"; readonly Personal: "personal"; readonly Both: "both" };
13
+ export type Life = OneOf<typeof Life>;
14
+ /** How long a person writes. */
15
+ export declare const Length: { readonly Short: "short"; readonly Medium: "medium"; readonly Long: "long" };
16
+ export type Length = OneOf<typeof Length>;
17
+ /** How formally a person writes. */
18
+ export declare const Formality: { readonly Casual: "casual"; readonly Neutral: "neutral"; readonly Formal: "formal" };
19
+ export type Formality = OneOf<typeof Formality>;
20
+ /** A person's mail program: how their mail looks. */
21
+ export declare const MailClient: { readonly Gmail: "gmail"; readonly Outlook: "outlook"; readonly Apple: "apple"; readonly IPhone: "iphone"; readonly Android: "android"; readonly Plain: "plain" };
22
+ export type MailClient = OneOf<typeof MailClient>;
23
+ /** Whether a person clicks links in mail. */
24
+ export declare const LinkHabit: { readonly Usual: "usual"; readonly Curious: "curious"; readonly Wary: "wary"; readonly Never: "never" };
25
+ export type LinkHabit = OneOf<typeof LinkHabit>;
26
+ /** A person's provider's spam filter. */
27
+ export declare const SpamFilter: { readonly Strict: "strict"; readonly Normal: "normal"; readonly Lenient: "lenient"; readonly None: "none" };
28
+ export type SpamFilter = OneOf<typeof SpamFilter>;
29
+ /** How a person takes in mail. */
30
+ export declare const Access: { readonly ScreenReader: "screen_reader"; readonly LowVision: "low_vision" };
31
+ export type Access = OneOf<typeof Access>;
32
+ /** How a person feels about a sender (it follows the conversation). */
33
+ export declare const Stance: { readonly Warm: "warm"; readonly Neutral: "neutral"; readonly Wary: "wary"; readonly Annoyed: "annoyed"; readonly Done: "done" };
34
+ export type Stance = OneOf<typeof Stance>;
35
+ /** What a bad address does. */
36
+ export declare const BadKind: { readonly Blocked: "blocked"; readonly Disabled: "disabled"; readonly Domain: "domain"; readonly Full: "full"; readonly Unknown: "unknown" };
37
+ export type BadKind = OneOf<typeof BadKind>;
38
+ /** When a bad address fails. */
39
+ export declare const FailAt: { readonly Dsn: "dsn"; readonly Rcpt: "rcpt" };
40
+ export type FailAt = OneOf<typeof FailAt>;
41
+ /** Who is behind a never-seen address. */
42
+ export declare const Stranger: { readonly Off: "off"; readonly Basic: "basic"; readonly Ai: "ai" };
43
+ export type Stranger = OneOf<typeof Stranger>;
44
+ /** A fixed outcome for one address as a recipient (ok clears it). */
45
+ export declare const MailboxStatus: { readonly Ok: "ok"; readonly Blocked: "blocked"; readonly Disabled: "disabled"; readonly Domain: "domain"; readonly Full: "full"; readonly Unknown: "unknown" };
46
+ export type MailboxStatus = OneOf<typeof MailboxStatus>;
47
+ /** What a fault rule does. */
48
+ export declare const FaultKind: { readonly Error: "error"; readonly Greylist: "greylist"; readonly Rate: "rate"; readonly Drop: "drop" };
49
+ export type FaultKind = OneOf<typeof FaultKind>;
50
+ /** When in the SMTP conversation a fault rule acts. */
51
+ export declare const FaultStage: { readonly Mail: "mail"; readonly Rcpt: "rcpt"; readonly Data: "data" };
52
+ export type FaultStage = OneOf<typeof FaultStage>;
53
+ /** Real providers' failures, ready made. */
54
+ export declare const FaultScenario: { readonly GmailUnauthenticated: "gmail-unauthenticated"; readonly GmailRate: "gmail-rate"; readonly GmailNoUser: "gmail-no-user"; readonly GmailOverQuota: "gmail-over-quota"; readonly MicrosoftBusy: "microsoft-busy"; readonly MicrosoftBlocked: "microsoft-blocked"; readonly MicrosoftAccessDenied: "microsoft-access-denied"; readonly YahooDeferred: "yahoo-deferred"; readonly YahooPolicy: "yahoo-policy"; readonly Greylisting: "greylisting"; readonly RateLimit: "rate-limit"; readonly Drop: "drop"; readonly Slow: "slow"; readonly MailboxFull: "mailbox-full" };
55
+ export type FaultScenario = OneOf<typeof FaultScenario>;
56
+ /** When a sender's website does not exist. */
57
+ export declare const MissingSite: { readonly Imagine: "imagine"; readonly Notice: "notice" };
58
+ export type MissingSite = OneOf<typeof MissingSite>;
59
+ /** Links to your own machine or network. */
60
+ export declare const LocalLinks: { readonly Ignore: "ignore"; readonly Broken: "broken" };
61
+ export type LocalLinks = OneOf<typeof LocalLinks>;
62
+ /** What an inbound stream of the World sends. */
63
+ export declare const StreamKind: { readonly Lead: "lead"; readonly Support: "support"; readonly Vendor: "vendor"; readonly Partner: "partner"; readonly Customer: "customer"; readonly Newsletter: "newsletter"; readonly Spam: "spam"; readonly Phishing: "phishing"; readonly Custom: "custom" };
64
+ export type StreamKind = OneOf<typeof StreamKind>;
65
+ /** AI writing on or off. */
66
+ export declare const AiMode: { readonly On: "on"; readonly Off: "off" };
67
+ export type AiMode = OneOf<typeof AiMode>;
68
+ /** Event types, for waits, the event stream and webhooks (a name ending in * matches a prefix). */
69
+ export declare const EventType: { readonly MailDelivered: "mail.delivered"; readonly MailRetried: "mail.retried"; readonly MailDeleted: "mail.deleted"; readonly PersonaReceived: "persona.received"; readonly PersonaSent: "persona.sent"; readonly PersonaIgnored: "persona.ignored"; readonly PersonaBatched: "persona.batched"; readonly PersonaJunked: "persona.junked"; readonly PersonaRescued: "persona.rescued"; readonly PersonaBounced: "persona.bounced"; readonly PersonaPromised: "persona.promised"; readonly PersonaWaiting: "persona.waiting"; readonly PersonaCreated: "persona.created"; readonly PersonaUpdated: "persona.updated"; readonly PersonaMemory: "persona.memory"; readonly LinkOpened: "link.opened"; readonly LinkSkipped: "link.skipped"; readonly LinkFailed: "link.failed"; readonly LinkSender: "link.sender"; readonly InspectScored: "inspect.scored"; readonly InspectLinks: "inspect.links"; readonly WorldMail: "world.mail"; readonly WorldUpdated: "world.updated"; readonly JobScheduled: "job.scheduled"; readonly JobUpdated: "job.updated"; readonly JobDone: "job.done"; readonly JobSkipped: "job.skipped"; readonly JobFailed: "job.failed"; readonly CaseUpdated: "case.updated"; readonly Clock: "clock"; readonly Pace: "pace"; readonly FaultsUpdated: "faults.updated"; readonly JunkSettings: "junk.settings"; readonly NetworkUpdated: "network.updated"; readonly RetentionPruned: "retention.pruned"; readonly WebhookFailed: "webhook.failed"; readonly WriterFallback: "writer.fallback"; readonly AiMode: "ai.mode"; readonly AuthOk: "auth.ok"; readonly AuthFailed: "auth.failed"; readonly CheckReceived: "check.received"; readonly CheckDone: "check.done"; readonly CheckRefused: "check.refused" };
70
+ export type EventType = OneOf<typeof EventType> | (string & {});
71
+ /** What a planned job is. */
72
+ export declare const JobKind: { readonly Reply: "reply"; readonly Followup: "followup"; readonly Correction: "correction"; readonly OutOfOffice: "ooo"; readonly Bounce: "bounce"; readonly Initiate: "initiate"; readonly Deliver: "deliver"; readonly Nudge: "nudge"; readonly Dsn: "dsn"; readonly World: "world"; readonly Visit: "visit" };
73
+ export type JobKind = OneOf<typeof JobKind>;
74
+ /** Where a job stands. */
75
+ export declare const JobState: { readonly Pending: "pending"; readonly Done: "done"; readonly Skipped: "skipped"; readonly Failed: "failed" };
76
+ export type JobState = OneOf<typeof JobState>;
77
+ /** Common folders (any folder name works too). */
78
+ export declare const Folder: { readonly Inbox: "INBOX"; readonly Sent: "Sent"; readonly Drafts: "Drafts"; readonly Archive: "Archive"; readonly Trash: "Trash"; readonly Junk: "Junk" };
79
+ export type Folder = OneOf<typeof Folder> | (string & {});
80
+ /** Which protocol a login test tries. */
81
+ export declare const Protocol: { readonly Smtp: "smtp"; readonly Imap: "imap" };
82
+ export type Protocol = OneOf<typeof Protocol>;
83
+ /** A role in a universe. */
84
+ export declare const Role: { readonly Viewer: "viewer"; readonly Member: "member"; readonly Admin: "admin"; readonly Owner: "owner" };
85
+ export type Role = OneOf<typeof Role>;
86
+ /** Where a persona came from. */
87
+ export declare const PersonaSource: { readonly Api: "api"; readonly Case: "case"; readonly Stranger: "stranger"; readonly World: "world"; readonly Mail: "mail"; readonly Config: "config" };
88
+ export type PersonaSource = OneOf<typeof PersonaSource>;
89
+ /** Who wrote a case's story. */
90
+ export declare const StoryBy: { readonly Ai: "ai"; readonly Template: "template"; readonly Edited: "edited" };
91
+ export type StoryBy = OneOf<typeof StoryBy>;
92
+ /** Friendlier names the event wait accepts for common events. */
93
+ export declare const EventAlias: { readonly Delivered: "delivered"; readonly Received: "received"; readonly Replied: "replied"; readonly Sent: "sent"; readonly Declined: "declined"; readonly Ignored: "ignored"; readonly Junked: "junked"; readonly Bounced: "bounced"; readonly Clicked: "clicked"; readonly OpenedLink: "opened_link"; readonly Promised: "promised"; readonly Rescued: "rescued" };
94
+ export type EventAlias = OneOf<typeof EventAlias>;
95
+ /** The code every error answer carries. */
96
+ export declare const ErrorCode: { readonly BadRequest: "bad_request"; readonly InvalidValue: "invalid_value"; readonly InvalidRegex: "invalid_regex"; readonly Unauthorized: "unauthorized"; readonly NotInPlan: "not_in_plan"; readonly Forbidden: "forbidden"; readonly NotFound: "not_found"; readonly MethodNotAllowed: "method_not_allowed"; readonly Timeout: "timeout"; readonly WaitTimeout: "wait_timeout"; readonly Conflict: "conflict"; readonly UnexpectedEmail: "unexpected_email"; readonly TooLarge: "too_large"; readonly Unprocessable: "unprocessable"; readonly IdempotencyMismatch: "idempotency_mismatch"; readonly RateLimited: "rate_limited"; readonly InternalError: "internal_error"; readonly BadGateway: "bad_gateway"; readonly Unavailable: "unavailable" };
97
+ export type ErrorCode = OneOf<typeof ErrorCode>;
98
+
99
+ export interface EnumValueInfo { label?: string; description?: string; feature?: string }
100
+ /** Each enum value's label, description and plan feature. */
101
+ export declare const EnumInfo: { readonly [enumName: string]: { readonly [value: string]: EnumValueInfo } };
102
+ /** The label of a value, such as describe("Temperament", "skeptical"). */
103
+ export declare function describe(enumName: string, value: string): string;