@sapiom/tools 0.10.2 → 0.12.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/CHANGELOG.md +16 -0
- package/README.md +2 -1
- package/dist/cjs/_client/capability-call.d.ts +58 -0
- package/dist/cjs/_client/capability-call.d.ts.map +1 -0
- package/dist/cjs/_client/capability-call.js +68 -0
- package/dist/cjs/_client/capability-call.js.map +1 -0
- package/dist/cjs/_client/index.d.ts +1 -0
- package/dist/cjs/_client/index.d.ts.map +1 -1
- package/dist/cjs/_client/index.js +4 -1
- package/dist/cjs/_client/index.js.map +1 -1
- package/dist/cjs/client.d.ts +60 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +32 -0
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/content-generation/index.d.ts +6 -0
- package/dist/cjs/content-generation/index.d.ts.map +1 -1
- package/dist/cjs/content-generation/index.js +32 -20
- package/dist/cjs/content-generation/index.js.map +1 -1
- package/dist/cjs/email/errors.d.ts +16 -0
- package/dist/cjs/email/errors.d.ts.map +1 -0
- package/dist/cjs/email/errors.js +36 -0
- package/dist/cjs/email/errors.js.map +1 -0
- package/dist/cjs/email/index.d.ts +391 -0
- package/dist/cjs/email/index.d.ts.map +1 -0
- package/dist/cjs/email/index.js +465 -0
- package/dist/cjs/email/index.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/search/index.d.ts +6 -1
- package/dist/cjs/search/index.d.ts.map +1 -1
- package/dist/cjs/search/index.js +89 -90
- package/dist/cjs/search/index.js.map +1 -1
- package/dist/cjs/stub/index.d.ts.map +1 -1
- package/dist/cjs/stub/index.js +116 -0
- package/dist/cjs/stub/index.js.map +1 -1
- package/dist/esm/_client/capability-call.d.ts +58 -0
- package/dist/esm/_client/capability-call.d.ts.map +1 -0
- package/dist/esm/_client/capability-call.js +64 -0
- package/dist/esm/_client/capability-call.js.map +1 -0
- package/dist/esm/_client/index.d.ts +1 -0
- package/dist/esm/_client/index.d.ts.map +1 -1
- package/dist/esm/_client/index.js +1 -0
- package/dist/esm/_client/index.js.map +1 -1
- package/dist/esm/client.d.ts +60 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +32 -0
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/content-generation/index.d.ts +6 -0
- package/dist/esm/content-generation/index.d.ts.map +1 -1
- package/dist/esm/content-generation/index.js +33 -21
- package/dist/esm/content-generation/index.js.map +1 -1
- package/dist/esm/email/errors.d.ts +16 -0
- package/dist/esm/email/errors.d.ts.map +1 -0
- package/dist/esm/email/errors.js +31 -0
- package/dist/esm/email/errors.js.map +1 -0
- package/dist/esm/email/index.d.ts +391 -0
- package/dist/esm/email/index.d.ts.map +1 -0
- package/dist/esm/email/index.js +446 -0
- package/dist/esm/email/index.js.map +1 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/search/index.d.ts +6 -1
- package/dist/esm/search/index.d.ts.map +1 -1
- package/dist/esm/search/index.js +91 -92
- package/dist/esm/search/index.js.map +1 -1
- package/dist/esm/stub/index.d.ts.map +1 -1
- package/dist/esm/stub/index.js +116 -0
- package/dist/esm/stub/index.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +6 -1
- package/src/email/README.md +96 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# email
|
|
2
|
+
|
|
3
|
+
Programmatic transactional email. Create real, addressable inboxes, send and
|
|
4
|
+
receive messages, manage custom sending domains, read conversation threads, and
|
|
5
|
+
register webhooks for inbound events. Call it directly from your code, or from
|
|
6
|
+
within Sapiom workflow steps.
|
|
7
|
+
|
|
8
|
+
```typescript
|
|
9
|
+
import { createClient } from "@sapiom/tools";
|
|
10
|
+
const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
|
|
11
|
+
|
|
12
|
+
// Create an inbox, then send from it.
|
|
13
|
+
const inbox = await sapiom.email.inboxes.create({ username: "support" });
|
|
14
|
+
await sapiom.email.messages.send(inbox.inboxId, {
|
|
15
|
+
to: "customer@example.com",
|
|
16
|
+
subject: "Welcome",
|
|
17
|
+
text: "Thanks for signing up!",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Read what came in, and reply to it.
|
|
21
|
+
const { messages } = await sapiom.email.messages.list(inbox.inboxId);
|
|
22
|
+
const full = await sapiom.email.messages.get(
|
|
23
|
+
inbox.inboxId,
|
|
24
|
+
messages[0].messageId,
|
|
25
|
+
);
|
|
26
|
+
await sapiom.email.messages.reply(inbox.inboxId, full.messageId, {
|
|
27
|
+
text: "Happy to help!",
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Ambient import works too: `import { email } from "@sapiom/tools"`.
|
|
32
|
+
|
|
33
|
+
## Operations
|
|
34
|
+
|
|
35
|
+
Operations are grouped by resource:
|
|
36
|
+
|
|
37
|
+
- **`inboxes`** — `create`, `list`, `get`, `delete`
|
|
38
|
+
- **`messages`** — `send`, `list`, `get`, `reply`, `replyAll`, `forward`
|
|
39
|
+
- **`domains`** — `create`, `verify`, `get`, `list`, `delete`
|
|
40
|
+
- **`threads`** — `list`, `get`
|
|
41
|
+
- **`webhooks`** — `create`, `delete`
|
|
42
|
+
|
|
43
|
+
## Inboxes
|
|
44
|
+
|
|
45
|
+
An inbox is a real mailbox you own. Its `inboxId` **is its email address** — use it
|
|
46
|
+
directly as the recipient of inbound mail and as the first argument to every message
|
|
47
|
+
and thread call. `create` accepts an optional `username`, `displayName`, and a
|
|
48
|
+
verified custom `domain` (see below); omit them and you get a generated address on
|
|
49
|
+
the default domain.
|
|
50
|
+
|
|
51
|
+
## Messages
|
|
52
|
+
|
|
53
|
+
- `send` requires `to` (a single address or an array) and takes `cc` / `bcc` /
|
|
54
|
+
`replyTo`, `subject`, `text` and/or `html`, `labels`, and custom `headers`.
|
|
55
|
+
- `list` returns **metadata only** — no body. Call `get` for the full message,
|
|
56
|
+
which additionally includes `text` / `html` and `extractedText` / `extractedHtml`
|
|
57
|
+
(the "new" content with quoted reply history stripped — what you usually want when
|
|
58
|
+
processing a reply).
|
|
59
|
+
- `reply`, `replyAll`, and `forward` all return `{ messageId, threadId }`.
|
|
60
|
+
- Custom `headers` may not set address, identity, routing, or MIME headers (e.g.
|
|
61
|
+
`To`, `From`, `Reply-To`, `Subject`, `Content-Type`) — use the dedicated fields
|
|
62
|
+
for those; such headers are rejected.
|
|
63
|
+
|
|
64
|
+
## Domains
|
|
65
|
+
|
|
66
|
+
To send from your own domain, register it with `domains.create({ domain })`. The
|
|
67
|
+
response includes the DNS `records` you must publish. Once published, call
|
|
68
|
+
`domains.verify(domainId)`, then re-fetch with `domains.get(domainId)` to read the
|
|
69
|
+
updated `status` (`PENDING` → `VERIFIED`). `domains.list` returns domains without
|
|
70
|
+
their `status`/`records`; use `get` for the full detail.
|
|
71
|
+
|
|
72
|
+
## Threads
|
|
73
|
+
|
|
74
|
+
A thread groups the messages of a conversation. `threads.list` returns thread
|
|
75
|
+
summaries (without messages); `threads.get` returns the full thread including its
|
|
76
|
+
`messages` array.
|
|
77
|
+
|
|
78
|
+
## Webhooks
|
|
79
|
+
|
|
80
|
+
`webhooks.create({ url, eventType })` registers an HTTPS endpoint to receive inbound
|
|
81
|
+
events (e.g. `"message.received"`, or `"*"` for all). The response includes a
|
|
82
|
+
`secret` **returned only once** — store it to verify the signature on delivered
|
|
83
|
+
events.
|
|
84
|
+
|
|
85
|
+
## Gotchas
|
|
86
|
+
|
|
87
|
+
- **`inboxId` is the email address.** It contains `@` (and often `.`); pass it
|
|
88
|
+
as-is — the client handles URL encoding.
|
|
89
|
+
- **`list` is metadata-only.** `messages.list` and `threads.list` omit bodies /
|
|
90
|
+
messages; fetch the individual resource with `get` to read content.
|
|
91
|
+
- **The webhook `secret` is shown once.** It is present only on the `create`
|
|
92
|
+
response; capture it then.
|
|
93
|
+
- **Pagination** is cursor-based: pass the previous response's `nextPageToken` back
|
|
94
|
+
as `pageToken`.
|
|
95
|
+
- **Failed requests throw `EmailHttpError`** (carries `status` + parsed `body`),
|
|
96
|
+
exported from `@sapiom/tools`.
|