@primitivedotdev/sdk 0.17.0 → 0.19.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 +165 -65
- package/dist/api/generated/index.js +1 -1
- package/dist/api/generated/sdk.gen.js +49 -1
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.js +39 -7
- package/dist/{api-DrAZhxS-.js → api-C5VR_Opg.js} +81 -7
- package/dist/contract/index.d.ts +2 -2
- package/dist/contract/index.js +1 -1
- package/dist/{index-CbEivn3S.d.ts → index-CDlwyxdp.d.ts} +7 -7
- package/dist/{index-CHWqMBs6.d.ts → index-oRkCqj6u.d.ts} +195 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/oclif/api-command.js +176 -92
- package/dist/oclif/auth.js +168 -0
- package/dist/oclif/commands/emails-latest.js +54 -35
- package/dist/oclif/commands/login.js +233 -0
- package/dist/oclif/commands/logout.js +87 -0
- package/dist/oclif/commands/send.js +61 -34
- package/dist/oclif/commands/whoami.js +51 -32
- package/dist/oclif/fish-completion.js +1 -1
- package/dist/oclif/index.js +6 -0
- package/dist/openapi/openapi.generated.js +385 -2
- package/dist/openapi/operations.generated.js +178 -1
- package/dist/webhook/index.d.ts +1 -1
- package/dist/webhook/index.js +1 -1
- package/dist/{webhook-zkN4wUTs.js → webhook-rUjGV6Zu.js} +4 -4
- package/oclif.manifest.json +507 -38
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,31 +1,77 @@
|
|
|
1
1
|
# `@primitivedotdev/sdk`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official Node.js SDK and command-line tool for [Primitive](https://primitive.dev), an email API for sending and receiving programmatic mail.
|
|
4
4
|
|
|
5
|
-
The
|
|
6
|
-
automation:
|
|
5
|
+
The package ships two things in one install:
|
|
7
6
|
|
|
8
|
-
- `
|
|
9
|
-
-
|
|
10
|
-
- `client.send(...)`
|
|
11
|
-
- `client.reply(...)`
|
|
12
|
-
- `client.forward(...)`
|
|
7
|
+
- A **`primitive` CLI** for interactive use, scripts, and agent workflows. Sends mail, reads inbound, inspects send history, manages domains and webhook endpoints, all in one binary.
|
|
8
|
+
- A **typed Node library** for programmatic integration in app code. Receives and verifies inbound webhooks, sends mail, parses raw MIME, and exposes the full HTTP API as generated functions.
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
tooling, raw MIME parsing, and the CLI still exist as named exports or subpath
|
|
16
|
-
imports.
|
|
10
|
+
Pick whichever fits the call site. The two share the same auth (`PRIMITIVE_API_KEY`), the same data shapes, and the same OpenAPI spec.
|
|
17
11
|
|
|
18
|
-
##
|
|
12
|
+
## Install
|
|
19
13
|
|
|
20
|
-
|
|
14
|
+
```bash
|
|
15
|
+
npm install @primitivedotdev/sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
For one-off CLI use, `npx @primitivedotdev/sdk@latest <command>` works without installing.
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
Requires Node.js 22 or newer.
|
|
21
|
+
|
|
22
|
+
## Set your API key
|
|
23
|
+
|
|
24
|
+
Get a key from your [dashboard](https://primitive.dev) and export it. Both the CLI and the library default to reading `PRIMITIVE_API_KEY` from the environment.
|
|
23
25
|
|
|
24
26
|
```bash
|
|
25
|
-
|
|
27
|
+
export PRIMITIVE_API_KEY=prim_...
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
##
|
|
30
|
+
## Command line
|
|
31
|
+
|
|
32
|
+
Everything below assumes `PRIMITIVE_API_KEY` is set. Each command also accepts `--api-key <value>` if you want to pass it explicitly.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Confirm the key is live and see which account it authenticates.
|
|
36
|
+
primitive whoami
|
|
37
|
+
|
|
38
|
+
# Send an email. --wait blocks until the receiving MTA returns a delivery
|
|
39
|
+
# outcome (a synchronous SMTP 250 from Gmail, etc.); without it, the call
|
|
40
|
+
# returns once Primitive has accepted the message for delivery.
|
|
41
|
+
primitive send --to alice@example.com --body "Hi Alice!" --wait
|
|
42
|
+
|
|
43
|
+
# See the most recent inbound emails as a compact text table.
|
|
44
|
+
# IDs are full UUIDs when piped, truncated for interactive terminals.
|
|
45
|
+
primitive emails:latest --limit 5
|
|
46
|
+
|
|
47
|
+
# Read one inbound's full record (body, headers, threading metadata).
|
|
48
|
+
primitive emails:get-email --id <uuid>
|
|
49
|
+
|
|
50
|
+
# Reply to an inbound. Threading and the "Re:" subject are derived
|
|
51
|
+
# server-side from the parent message; you supply only the body.
|
|
52
|
+
primitive sending:reply-to-email --id <inbound-id> --body-text "..."
|
|
53
|
+
|
|
54
|
+
# See where you are allowed to send. Returns a typed list of
|
|
55
|
+
# permission rules (managed-zone wildcards, your own verified domains,
|
|
56
|
+
# specific addresses with grants). The send-mail call enforces these
|
|
57
|
+
# at request time.
|
|
58
|
+
primitive sending:get-send-permissions
|
|
59
|
+
|
|
60
|
+
# Look up an operation's request/response schema, including per-field
|
|
61
|
+
# descriptions sourced from the OpenAPI spec.
|
|
62
|
+
primitive describe emails:get-email
|
|
63
|
+
primitive describe sending:send-email
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Run `primitive --help` for the full topic list and `primitive <topic> --help` for the commands within each. Every command accepts `--help`, and the descriptions are detailed enough that the CLI is self-documenting for most workflows.
|
|
67
|
+
|
|
68
|
+
## Library
|
|
69
|
+
|
|
70
|
+
The default root import is intentionally small and centered on the two most common app-code use cases: receiving inbound webhook deliveries and sending mail.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import primitive from "@primitivedotdev/sdk";
|
|
74
|
+
```
|
|
29
75
|
|
|
30
76
|
### Receive and reply in a Next.js route
|
|
31
77
|
|
|
@@ -50,6 +96,8 @@ export async function POST(req: Request) {
|
|
|
50
96
|
}
|
|
51
97
|
```
|
|
52
98
|
|
|
99
|
+
`primitive.receive(...)` reads the request body, verifies the HMAC-SHA256 signature against your account secret (rejecting expired or tampered deliveries), and returns a normalized email object. `client.reply(email, ...)` derives threading and the `Re:` subject from the parent message server-side.
|
|
100
|
+
|
|
53
101
|
### Send a new email
|
|
54
102
|
|
|
55
103
|
```ts
|
|
@@ -64,9 +112,6 @@ const result = await client.send({
|
|
|
64
112
|
to: "alice@example.com",
|
|
65
113
|
subject: "Hello",
|
|
66
114
|
bodyText: "Hi there",
|
|
67
|
-
// Use a unique key per logical send. Reusing a key returns the original
|
|
68
|
-
// response from the first send, which is how retries are deduplicated.
|
|
69
|
-
idempotencyKey: "customer-key-abc123",
|
|
70
115
|
wait: true,
|
|
71
116
|
waitTimeoutMs: 5000,
|
|
72
117
|
});
|
|
@@ -74,27 +119,57 @@ const result = await client.send({
|
|
|
74
119
|
console.log(result.id, result.status, result.queueId, result.deliveryStatus);
|
|
75
120
|
```
|
|
76
121
|
|
|
77
|
-
`send`, `reply`, and `forward` keep the HTTP request open until Primitive's
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
122
|
+
`send`, `reply`, and `forward` keep the HTTP request open until Primitive's downstream SMTP transaction completes. In production, configure your runtime or transport with a request timeout long enough for SMTP delivery, typically 30 to 60 seconds.
|
|
123
|
+
|
|
124
|
+
### Per-call request options
|
|
125
|
+
|
|
126
|
+
Every client method accepts an optional second argument with cancellation, timeout, header, and idempotency controls:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
interface RequestOptions {
|
|
130
|
+
// Cancel the in-flight request when this signal fires. Surfaces as AbortError.
|
|
131
|
+
signal?: AbortSignal;
|
|
132
|
+
// Per-call timeout in milliseconds. Composed with `signal` so either fires.
|
|
133
|
+
timeout?: number;
|
|
134
|
+
// Per-call headers merged on top of client-level headers. Last write wins.
|
|
135
|
+
headers?: Record<string, string>;
|
|
136
|
+
// Idempotency key for safe retries. Sent as the Idempotency-Key request header.
|
|
137
|
+
idempotencyKey?: string;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Cap a single send at 15 seconds:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
await client.send(
|
|
145
|
+
{ from, to, subject, bodyText },
|
|
146
|
+
{ signal: AbortSignal.timeout(15000) },
|
|
147
|
+
);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Idempotency key for safe retries (reusing a key returns the original response, so a retried network call deduplicates against the first send):
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
await client.send(
|
|
154
|
+
{ from, to, subject, bodyText },
|
|
155
|
+
{ idempotencyKey: "customer-key-abc123" },
|
|
156
|
+
);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Client-level config (default fetch, base URL, default headers passed to `primitive.client({...})`) still applies to every call. Per-call `RequestOptions` overrides or merges on top: headers merge (per-call wins on conflict), `signal` and `timeout` compose so the first to fire wins.
|
|
81
160
|
|
|
82
161
|
### About `wait` mode
|
|
83
162
|
|
|
84
|
-
When `wait: true`, the call returns the first downstream SMTP outcome (or
|
|
85
|
-
`waitTimeoutMs`, default 30000). Possible terminal `deliveryStatus` values:
|
|
163
|
+
When `wait: true`, the call returns the first downstream SMTP outcome (or `waitTimeoutMs`, default 30000). Possible terminal `deliveryStatus` values:
|
|
86
164
|
|
|
87
165
|
- `delivered` accepted by the receiving MTA
|
|
88
166
|
- `bounced` rejected by the receiving MTA (the response is still 200 OK)
|
|
89
167
|
- `deferred` temporary failure, the receiving MTA may retry
|
|
90
|
-
- `wait_timeout` no outcome was observed in time. Treat as "outcome unknown."
|
|
91
|
-
The send may still complete after the response returns.
|
|
168
|
+
- `wait_timeout` no outcome was observed in time. Treat as "outcome unknown." The send may still complete after the response returns.
|
|
92
169
|
|
|
93
170
|
### Reply from a different address
|
|
94
171
|
|
|
95
|
-
`reply()` defaults the From address to the inbound recipient (the address that
|
|
96
|
-
received the email). When your verified outbound domain differs from your
|
|
97
|
-
inbound domain, pass `from` explicitly:
|
|
172
|
+
`reply()` defaults the From address to the inbound recipient (the address that received the email). When your verified outbound domain differs from your inbound domain, pass `from` explicitly:
|
|
98
173
|
|
|
99
174
|
```ts
|
|
100
175
|
await client.reply(email, {
|
|
@@ -105,8 +180,7 @@ await client.reply(email, {
|
|
|
105
180
|
|
|
106
181
|
### HTML replies and waiting on the delivery outcome
|
|
107
182
|
|
|
108
|
-
`reply()` accepts `html` as a sibling of `text`, plus the same `wait` flag the
|
|
109
|
-
top-level `send()` takes:
|
|
183
|
+
`reply()` accepts `html` as a sibling of `text`, plus the same `wait` flag the top-level `send()` takes:
|
|
110
184
|
|
|
111
185
|
```ts
|
|
112
186
|
await client.reply(email, {
|
|
@@ -116,14 +190,9 @@ await client.reply(email, {
|
|
|
116
190
|
});
|
|
117
191
|
```
|
|
118
192
|
|
|
119
|
-
`subject` is intentionally not accepted on `reply()`. Gmail's Conversation View
|
|
120
|
-
needs both a References match and a normalized-subject match to thread, so a
|
|
121
|
-
custom subject silently breaks the thread for half the recipient population.
|
|
122
|
-
Use `client.send(...)` if you need full subject control.
|
|
193
|
+
`subject` is intentionally not accepted on `reply()`. Gmail's Conversation View needs both a References match and a normalized-subject match to thread, so a custom subject silently breaks the thread for half the recipient population. Use `client.send(...)` if you need full subject control.
|
|
123
194
|
|
|
124
|
-
If the inbound row is not in a state we can reply to (no `Message-Id` recorded,
|
|
125
|
-
or content was discarded), the API returns `inbound_not_repliable` (HTTP 422)
|
|
126
|
-
and the SDK throws.
|
|
195
|
+
If the inbound row is not in a state we can reply to (no `Message-Id` recorded, or content was discarded), the API returns `inbound_not_repliable` (HTTP 422) and the SDK throws.
|
|
127
196
|
|
|
128
197
|
### Forward an inbound email
|
|
129
198
|
|
|
@@ -136,37 +205,35 @@ await client.forward(email, {
|
|
|
136
205
|
|
|
137
206
|
## The normalized email object
|
|
138
207
|
|
|
139
|
-
`primitive.receive(...)` returns a normalized inbound email object that keeps the
|
|
140
|
-
common case clean:
|
|
208
|
+
`primitive.receive(...)` returns a normalized inbound email object that keeps the common case clean:
|
|
141
209
|
|
|
142
210
|
```ts
|
|
143
|
-
email.sender.address
|
|
144
|
-
email.sender.name
|
|
211
|
+
email.sender.address;
|
|
212
|
+
email.sender.name;
|
|
145
213
|
|
|
146
|
-
email.receivedBy
|
|
147
|
-
email.receivedByAll
|
|
214
|
+
email.receivedBy;
|
|
215
|
+
email.receivedByAll;
|
|
148
216
|
|
|
149
|
-
email.replyTarget.address
|
|
150
|
-
email.replySubject
|
|
151
|
-
email.forwardSubject
|
|
217
|
+
email.replyTarget.address;
|
|
218
|
+
email.replySubject;
|
|
219
|
+
email.forwardSubject;
|
|
152
220
|
|
|
153
|
-
email.subject
|
|
154
|
-
email.text
|
|
221
|
+
email.subject;
|
|
222
|
+
email.text;
|
|
155
223
|
|
|
156
|
-
email.thread.messageId
|
|
157
|
-
email.thread.references
|
|
224
|
+
email.thread.messageId;
|
|
225
|
+
email.thread.references;
|
|
158
226
|
|
|
159
|
-
email.raw
|
|
227
|
+
email.raw;
|
|
160
228
|
```
|
|
161
229
|
|
|
162
230
|
Use `email.raw` when you need the original validated webhook event shape.
|
|
163
231
|
|
|
164
|
-
##
|
|
232
|
+
## Lower-level surfaces
|
|
165
233
|
|
|
166
|
-
### Explicit receive form
|
|
234
|
+
### Explicit `receive` form
|
|
167
235
|
|
|
168
|
-
If your framework does not expose a standard `Request`, use the lower-level
|
|
169
|
-
form:
|
|
236
|
+
If your framework does not expose a standard `Request`, use the lower-level form:
|
|
170
237
|
|
|
171
238
|
```ts
|
|
172
239
|
const email = primitive.receive({
|
|
@@ -176,9 +243,9 @@ const email = primitive.receive({
|
|
|
176
243
|
});
|
|
177
244
|
```
|
|
178
245
|
|
|
179
|
-
### Generated API
|
|
246
|
+
### Generated API client
|
|
180
247
|
|
|
181
|
-
|
|
248
|
+
The full HTTP API is exposed as a generated client. Use it when the high-level helpers don't cover what you need:
|
|
182
249
|
|
|
183
250
|
```ts
|
|
184
251
|
import { PrimitiveApiClient, getAccount } from "@primitivedotdev/sdk/api";
|
|
@@ -187,13 +254,46 @@ const api = new PrimitiveApiClient({ apiKey: process.env.PRIMITIVE_API_KEY });
|
|
|
187
254
|
const result = await getAccount({ client: api.client });
|
|
188
255
|
```
|
|
189
256
|
|
|
190
|
-
###
|
|
257
|
+
### Webhook signature verification
|
|
258
|
+
|
|
259
|
+
`primitive.receive(...)` handles verification automatically. If you need to verify a delivery yourself (a different language reverse-proxying through Node, a one-off audit, etc.), the wire format is:
|
|
260
|
+
|
|
261
|
+
- Header: `Primitive-Signature: t=<unix-seconds>,v1=<hex>`. A legacy `MyMX-Signature` header carries the same value for back-compat.
|
|
262
|
+
- Signed string: `${timestamp}.${rawBody}` where `rawBody` is the exact request bytes before any JSON decoding.
|
|
263
|
+
- Signature: HMAC-SHA256, hex-encoded.
|
|
264
|
+
- Secret: returned by `GET /account/webhook-secret`. Use as a UTF-8 string; do not base64-decode despite the base64-shaped output.
|
|
265
|
+
- Tolerance: reject deliveries with a timestamp more than 5 minutes off your wall-clock.
|
|
266
|
+
|
|
267
|
+
The Node helper:
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
import { verifyWebhookSignature } from "@primitivedotdev/sdk/webhook";
|
|
271
|
+
|
|
272
|
+
verifyWebhookSignature({
|
|
273
|
+
rawBody: rawBodyString,
|
|
274
|
+
signatureHeader: req.headers["primitive-signature"] as string,
|
|
275
|
+
secret: process.env.PRIMITIVE_WEBHOOK_SECRET!,
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
`rawBody` must be the exact bytes of the HTTP body (string or Buffer) before any JSON parsing. `signatureHeader` is the value of the `Primitive-Signature` header verbatim. Throws `WebhookVerificationError` on mismatch, expired timestamp, or malformed input. Pass `toleranceSeconds` to override the default 300-second replay window.
|
|
280
|
+
|
|
281
|
+
For most app-code callers, `primitive.receive(...)` from the root import handles both the body extraction and verification in one call (see "Receive and reply in a Next.js route" above). Reach for `verifyWebhookSignature` directly when your framework doesn't expose a standard `Request` and you've already pulled the raw body and header value yourself.
|
|
282
|
+
|
|
283
|
+
For the full reference (response codes, replay protection details), see the API-level "Webhook signing" section in the [OpenAPI spec](https://primitive.dev/api/v1/openapi).
|
|
284
|
+
|
|
285
|
+
### Other subpath imports
|
|
286
|
+
|
|
287
|
+
- `@primitivedotdev/sdk/openapi` exports the OpenAPI document and the operation manifest as JSON. Useful for tools that want the spec inline.
|
|
288
|
+
- `@primitivedotdev/sdk/contract` builds and signs webhook payloads. Useful for tests or replaying inbound events through your own handler.
|
|
289
|
+
- `@primitivedotdev/sdk/parser` parses raw `.eml` files and bundles attachments. Useful when you receive inbound mail through a different path (forwarded `.eml` files, archived storage) and want the same normalization the webhook receiver applies.
|
|
290
|
+
|
|
291
|
+
## Going further
|
|
191
292
|
|
|
192
|
-
-
|
|
193
|
-
-
|
|
194
|
-
-
|
|
195
|
-
-
|
|
196
|
-
- `primitive` CLI
|
|
293
|
+
- [primitive.dev/docs](https://primitive.dev/docs) for product docs (quickstart, webhook payload reference, FAQ).
|
|
294
|
+
- [primitive.dev/api/v1/openapi](https://primitive.dev/api/v1/openapi) for the machine-readable OpenAPI spec.
|
|
295
|
+
- `primitive list-operations` for the same spec as a JSON manifest, fetched from the bundled SDK.
|
|
296
|
+
- `primitive describe <command>` for the inlined request/response schema of a single operation, including per-field descriptions.
|
|
197
297
|
|
|
198
298
|
## Development
|
|
199
299
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
export { addDomain, createEndpoint, createFilter, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, discardEmailContent, downloadAttachments, downloadRawEmail, getAccount, getEmail, getSendPermissions, getSentEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, listSentEmails, replayDelivery, replayEmailWebhooks, replyToEmail, rotateWebhookSecret, sendEmail, testEndpoint, updateAccount, updateDomain, updateEndpoint, updateFilter, verifyDomain } from './sdk.gen.js';
|
|
2
|
+
export { addDomain, cliLogout, createEndpoint, createFilter, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, discardEmailContent, downloadAttachments, downloadRawEmail, getAccount, getEmail, getSendPermissions, getSentEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, listSentEmails, pollCliLogin, replayDelivery, replayEmailWebhooks, replyToEmail, rotateWebhookSecret, sendEmail, startCliLogin, testEndpoint, updateAccount, updateDomain, updateEndpoint, updateFilter, verifyDomain } from './sdk.gen.js';
|
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
2
|
import { client } from './client.gen.js';
|
|
3
|
+
/**
|
|
4
|
+
* Start CLI browser login
|
|
5
|
+
*
|
|
6
|
+
* Starts a browser-assisted CLI login session. The response includes a
|
|
7
|
+
* device code for polling and a user code that the user approves in the
|
|
8
|
+
* browser. This endpoint does not require an API key.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export const startCliLogin = (options) => (options?.client ?? client).post({
|
|
12
|
+
url: '/cli/login/start',
|
|
13
|
+
...options,
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
...options?.headers
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Poll CLI browser login
|
|
21
|
+
*
|
|
22
|
+
* Polls a CLI login session until the browser approval either succeeds,
|
|
23
|
+
* is denied, expires, or is polled too quickly. The API key is generated
|
|
24
|
+
* only after approval and is returned exactly once.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export const pollCliLogin = (options) => (options.client ?? client).post({
|
|
28
|
+
url: '/cli/login/poll',
|
|
29
|
+
...options,
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
...options.headers
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Revoke the current CLI API key
|
|
37
|
+
*
|
|
38
|
+
* Revokes the API key used to authenticate the request. CLI clients use
|
|
39
|
+
* this endpoint during `primitive logout` before removing local credentials.
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
export const cliLogout = (options) => (options?.client ?? client).post({
|
|
43
|
+
security: [{ scheme: 'bearer', type: 'http' }],
|
|
44
|
+
url: '/cli/logout',
|
|
45
|
+
...options,
|
|
46
|
+
headers: {
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
...options?.headers
|
|
49
|
+
}
|
|
50
|
+
});
|
|
3
51
|
/**
|
|
4
52
|
* Get account info
|
|
5
53
|
*/
|
|
@@ -290,7 +338,7 @@ export const replayEmailWebhooks = (options) => (options.client ?? client).post(
|
|
|
290
338
|
* dashboard at Settings > Webhooks). When the toggle is off, this
|
|
291
339
|
* endpoint returns `403` with code `discard_not_enabled` and a
|
|
292
340
|
* message pointing the human at the dashboard. There is intentionally
|
|
293
|
-
* no API to flip this toggle
|
|
341
|
+
* no API to flip this toggle. Opting in to a destructive,
|
|
294
342
|
* non-reversible operation must be a deliberate human click in the
|
|
295
343
|
* UI.
|
|
296
344
|
*
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { Account, AccountUpdated, AddDomainData, AddDomainError, AddDomainErrors, AddDomainInput, AddDomainResponse, AddDomainResponses, Auth, ClientOptions, CreateClientConfig, CreateEndpointData, CreateEndpointError, CreateEndpointErrors, CreateEndpointInput, CreateEndpointResponse, CreateEndpointResponses, CreateFilterData, CreateFilterError, CreateFilterErrors, CreateFilterInput, CreateFilterResponse, CreateFilterResponses, Cursor, DEFAULT_BASE_URL, DeleteDomainData, DeleteDomainError, DeleteDomainErrors, DeleteDomainResponse, DeleteDomainResponses, DeleteEmailData, DeleteEmailError, DeleteEmailErrors, DeleteEmailResponse, DeleteEmailResponses, DeleteEndpointData, DeleteEndpointError, DeleteEndpointErrors, DeleteEndpointResponse, DeleteEndpointResponses, DeleteFilterData, DeleteFilterError, DeleteFilterErrors, DeleteFilterResponse, DeleteFilterResponses, DeliveryStatus, DeliverySummary, DiscardContentResult, DiscardEmailContentData, DiscardEmailContentError, DiscardEmailContentErrors, DiscardEmailContentResponse, DiscardEmailContentResponses, Domain, DomainVerifyResult, DownloadAttachmentsData, DownloadAttachmentsError, DownloadAttachmentsErrors, DownloadAttachmentsResponse, DownloadAttachmentsResponses, DownloadRawEmailData, DownloadRawEmailError, DownloadRawEmailErrors, DownloadRawEmailResponse, DownloadRawEmailResponses, EmailDetail, EmailDetailReply, EmailStatus, EmailSummary, EmailWebhookStatus, Endpoint, ErrorResponse, Filter, ForwardInput, GateDenial, GateFix, GetAccountData, GetAccountError, GetAccountErrors, GetAccountResponse, GetAccountResponses, GetEmailData, GetEmailError, GetEmailErrors, GetEmailResponse, GetEmailResponses, GetSendPermissionsData, GetSendPermissionsError, GetSendPermissionsErrors, GetSendPermissionsResponse, GetSendPermissionsResponses, GetSentEmailData, GetSentEmailError, GetSentEmailErrors, GetSentEmailResponse, GetSentEmailResponses, GetStorageStatsData, GetStorageStatsError, GetStorageStatsErrors, GetStorageStatsResponse, GetStorageStatsResponses, GetWebhookSecretData, GetWebhookSecretError, GetWebhookSecretErrors, GetWebhookSecretResponse, GetWebhookSecretResponses, Limit, ListDeliveriesData, ListDeliveriesError, ListDeliveriesErrors, ListDeliveriesResponse, ListDeliveriesResponses, ListDomainsData, ListDomainsError, ListDomainsErrors, ListDomainsResponse, ListDomainsResponses, ListEmailsData, ListEmailsError, ListEmailsErrors, ListEmailsResponse, ListEmailsResponses, ListEndpointsData, ListEndpointsError, ListEndpointsErrors, ListEndpointsResponse, ListEndpointsResponses, ListEnvelope, ListFiltersData, ListFiltersError, ListFiltersErrors, ListFiltersResponse, ListFiltersResponses, ListSentEmailsData, ListSentEmailsError, ListSentEmailsErrors, ListSentEmailsResponse, ListSentEmailsResponses, Options, PaginationMeta, PrimitiveApiClient, PrimitiveApiClientOptions, PrimitiveApiError, PrimitiveApiErrorDetails, PrimitiveClient, PrimitiveClientOptions, Client as PrimitiveGeneratedApiClient, ClientOptions$1 as PrimitiveGeneratedApiClientOptions, Config as PrimitiveGeneratedApiConfig, Options$1 as PrimitiveGeneratedApiOptions, RequestOptions as PrimitiveGeneratedApiRequestOptions, RequestResult as PrimitiveGeneratedApiRequestResult, ReplayDeliveryData, ReplayDeliveryError, ReplayDeliveryErrors, ReplayDeliveryResponse, ReplayDeliveryResponses, ReplayEmailWebhooksData, ReplayEmailWebhooksError, ReplayEmailWebhooksErrors, ReplayEmailWebhooksResponse, ReplayEmailWebhooksResponses, ReplayResult, ReplyInput, ReplyToEmailData, ReplyToEmailError, ReplyToEmailErrors, ReplyToEmailResponse, ReplyToEmailResponses, ResourceId, ResponseStyle, RotateWebhookSecretData, RotateWebhookSecretError, RotateWebhookSecretErrors, RotateWebhookSecretResponse, RotateWebhookSecretResponses, SendEmailData, SendEmailError, SendEmailErrors, SendEmailResponse, SendEmailResponses, SendInput, SendMailInput, SendMailResult, SendPermissionAddress, SendPermissionAnyRecipient, SendPermissionManagedZone, SendPermissionRule, SendPermissionYourDomain, SendPermissionsMeta, SendResult, SendThreadInput, SentEmailDetail, SentEmailStatus, SentEmailSummary, StorageStats, SuccessEnvelope, TestEndpointData, TestEndpointError, TestEndpointErrors, TestEndpointResponse, TestEndpointResponses, TestResult, UnverifiedDomain, UpdateAccountData, UpdateAccountError, UpdateAccountErrors, UpdateAccountInput, UpdateAccountResponse, UpdateAccountResponses, UpdateDomainData, UpdateDomainError, UpdateDomainErrors, UpdateDomainInput, UpdateDomainResponse, UpdateDomainResponses, UpdateEndpointData, UpdateEndpointError, UpdateEndpointErrors, UpdateEndpointInput, UpdateEndpointResponse, UpdateEndpointResponses, UpdateFilterData, UpdateFilterError, UpdateFilterErrors, UpdateFilterInput, UpdateFilterResponse, UpdateFilterResponses, VerifiedDomain, VerifyDomainData, VerifyDomainError, VerifyDomainErrors, VerifyDomainResponse, VerifyDomainResponses, WebhookSecret, addDomain, client, createEndpoint, createFilter, createPrimitiveApiClient, createPrimitiveClient, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, discardEmailContent, downloadAttachments, downloadRawEmail, getAccount, getEmail, getSendPermissions, getSentEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, listSentEmails, operations, replayDelivery, replayEmailWebhooks, replyToEmail, rotateWebhookSecret, sendEmail, testEndpoint, updateAccount, updateDomain, updateEndpoint, updateFilter, verifyDomain };
|
|
1
|
+
import { $ as updateFilter, $i as UpdateDomainResponses, $n as GetWebhookSecretData, $r as ReplayResult, $t as DeliverySummary, A as getAccount, Ai as StartCliLoginInput, An as GetAccountErrors, Ar as ListFiltersResponses, At as CreateFilterResponses, B as listFilters, Bi as TestResult, Bn as GetSendPermissionsErrors, Br as PollCliLoginInput, Bt as DeleteEmailResponse, C as deleteDomain, Ca as Options$1, Ci as SendPermissionsMeta, Cn as Endpoint, Cr as ListEndpointsResponse, Ct as CreateEndpointResponse, D as discardEmailContent, Da as Auth, Di as StartCliLoginData, Dn as GateFix, Dr as ListFiltersError, Dt as CreateFilterErrors, E as deleteFilter, Ea as ResponseStyle, Ei as SentEmailSummary, En as GateDenial, Er as ListFiltersData, Et as CreateFilterError, F as getWebhookSecret, Fi as TestEndpointData, Fn as GetEmailErrors, Fr as ListSentEmailsResponses, Ft as DeleteDomainResponse, G as replyToEmail, Gi as UpdateAccountInput, Gn as GetSentEmailErrors, Gr as ReplayDeliveryErrors, Gt as DeleteEndpointResponse, H as pollCliLogin, Hi as UpdateAccountData, Hn as GetSendPermissionsResponses, Hr as PollCliLoginResponses, Ht as DeleteEndpointData, I as listDeliveries, Ii as TestEndpointError, In as GetEmailResponse, Ir as PaginationMeta, It as DeleteDomainResponses, J as startCliLogin, Ji as UpdateDomainData, Jn as GetStorageStatsData, Jr as ReplayEmailWebhooksData, Jt as DeleteFilterError, K as rotateWebhookSecret, Ki as UpdateAccountResponse, Kn as GetSentEmailResponse, Kr as ReplayDeliveryResponse, Kt as DeleteEndpointResponses, L as listDomains, Li as TestEndpointErrors, Ln as GetEmailResponses, Lr as PollCliLoginData, Lt as DeleteEmailData, M as getSendPermissions, Mi as StartCliLoginResponses, Mn as GetAccountResponses, Mr as ListSentEmailsError, Mt as DeleteDomainData, N as getSentEmail, Ni as StorageStats, Nn as GetEmailData, Nr as ListSentEmailsErrors, Nt as DeleteDomainError, O as downloadAttachments, Oi as StartCliLoginError, On as GetAccountData, Or as ListFiltersErrors, Ot as CreateFilterInput, P as getStorageStats, Pi as SuccessEnvelope, Pn as GetEmailError, Pr as ListSentEmailsResponse, Pt as DeleteDomainErrors, Q as updateEndpoint, Qi as UpdateDomainResponse, Qn as GetStorageStatsResponses, Qr as ReplayEmailWebhooksResponses, Qt as DeliveryStatus, R as listEmails, Ri as TestEndpointResponse, Rn as GetSendPermissionsData, Rr as PollCliLoginError, Rt as DeleteEmailError, S as createFilter, Sa as CreateClientConfig, Si as SendPermissionYourDomain, Sn as EmailWebhookStatus, Sr as ListEndpointsErrors, St as CreateEndpointInput, T as deleteEndpoint, Ta as RequestResult, Ti as SentEmailStatus, Tn as Filter, Tr as ListEnvelope, Tt as CreateFilterData, U as replayDelivery, Ui as UpdateAccountError, Un as GetSentEmailData, Ur as ReplayDeliveryData, Ut as DeleteEndpointError, V as listSentEmails, Vi as UnverifiedDomain, Vn as GetSendPermissionsResponse, Vr as PollCliLoginResponse, Vt as DeleteEmailResponses, W as replayEmailWebhooks, Wi as UpdateAccountErrors, Wn as GetSentEmailError, Wr as ReplayDeliveryError, Wt as DeleteEndpointErrors, X as updateAccount, Xi as UpdateDomainErrors, Xn as GetStorageStatsErrors, Xr as ReplayEmailWebhooksErrors, Xt as DeleteFilterResponse, Y as testEndpoint, Yi as UpdateDomainError, Yn as GetStorageStatsError, Yr as ReplayEmailWebhooksError, Yt as DeleteFilterErrors, Z as updateDomain, Zi as UpdateDomainInput, Zn as GetStorageStatsResponse, Zr as ReplayEmailWebhooksResponse, Zt as DeleteFilterResponses, _ as operations, _a as VerifyDomainResponses, _i as SendMailResult, _n as DownloadRawEmailResponses, _r as ListEmailsErrors, _t as CliLogoutResult, a as PrimitiveApiError, aa as UpdateEndpointResponses, ai as ResourceId, an as DiscardEmailContentResponses, ar as ListDeliveriesData, at as AddDomainErrors, b as cliLogout, ba as ClientOptions$1, bi as SendPermissionManagedZone, bn as EmailStatus, br as ListEndpointsData, bt as CreateEndpointError, c as PrimitiveClientOptions, ca as UpdateFilterErrors, ci as RotateWebhookSecretErrors, cn as DownloadAttachmentsData, cr as ListDeliveriesResponse, ct as AddDomainResponses, d as SendInput, da as UpdateFilterResponses, di as SendEmailData, dn as DownloadAttachmentsResponse, dr as ListDomainsError, dt as CliLogoutData, ea as UpdateEndpointData, ei as ReplyToEmailData, en as DiscardContentResult, er as GetWebhookSecretError, et as verifyDomain, f as SendResult, fa as VerifiedDomain, fi as SendEmailError, fn as DownloadAttachmentsResponses, fr as ListDomainsErrors, ft as CliLogoutError, g as createPrimitiveClient, ga as VerifyDomainResponse, gi as SendMailInput, gn as DownloadRawEmailResponse, gr as ListEmailsError, gt as CliLogoutResponses, h as createPrimitiveApiClient, ha as VerifyDomainErrors, hi as SendEmailResponses, hn as DownloadRawEmailErrors, hr as ListEmailsData, ht as CliLogoutResponse, i as PrimitiveApiClientOptions, ia as UpdateEndpointResponse, ii as ReplyToEmailResponses, in as DiscardEmailContentResponse, ir as Limit, it as AddDomainError, j as getEmail, ji as StartCliLoginResponse, jn as GetAccountResponse, jr as ListSentEmailsData, jt as Cursor, k as downloadRawEmail, ki as StartCliLoginErrors, kn as GetAccountError, kr as ListFiltersResponse, kt as CreateFilterResponse, l as ReplyInput, la as UpdateFilterInput, li as RotateWebhookSecretResponse, ln as DownloadAttachmentsError, lr as ListDeliveriesResponses, lt as CliLoginPollResult, m as client, ma as VerifyDomainError, mi as SendEmailResponse, mn as DownloadRawEmailError, mr as ListDomainsResponses, mt as CliLogoutInput, n as ForwardInput, na as UpdateEndpointErrors, ni as ReplyToEmailErrors, nn as DiscardEmailContentError, nr as GetWebhookSecretResponse, nt as AccountUpdated, o as PrimitiveApiErrorDetails, oa as UpdateFilterData, oi as RotateWebhookSecretData, on as Domain, or as ListDeliveriesError, ot as AddDomainInput, p as SendThreadInput, pa as VerifyDomainData, pi as SendEmailErrors, pn as DownloadRawEmailData, pr as ListDomainsResponse, pt as CliLogoutErrors, q as sendEmail, qi as UpdateAccountResponses, qn as GetSentEmailResponses, qr as ReplayDeliveryResponses, qt as DeleteFilterData, r as PrimitiveApiClient, ra as UpdateEndpointInput, ri as ReplyToEmailResponse, rn as DiscardEmailContentErrors, rr as GetWebhookSecretResponses, rt as AddDomainData, s as PrimitiveClient, sa as UpdateFilterError, si as RotateWebhookSecretError, sn as DomainVerifyResult, sr as ListDeliveriesErrors, st as AddDomainResponse, t as DEFAULT_BASE_URL, ta as UpdateEndpointError, ti as ReplyToEmailError, tn as DiscardEmailContentData, tr as GetWebhookSecretErrors, tt as Account, u as RequestOptions$1, ua as UpdateFilterResponse, ui as RotateWebhookSecretResponses, un as DownloadAttachmentsErrors, ur as ListDomainsData, ut as CliLoginStartResult, v as Options, va as WebhookSecret, vi as SendPermissionAddress, vn as EmailDetail, vr as ListEmailsResponse, vt as ClientOptions, w as deleteEmail, wa as RequestOptions, wi as SentEmailDetail, wn as ErrorResponse, wr as ListEndpointsResponses, wt as CreateEndpointResponses, x as createEndpoint, xa as Config, xi as SendPermissionRule, xn as EmailSummary, xr as ListEndpointsError, xt as CreateEndpointErrors, y as addDomain, ya as Client, yi as SendPermissionAnyRecipient, yn as EmailDetailReply, yr as ListEmailsResponses, yt as CreateEndpointData, z as listEndpoints, zi as TestEndpointResponses, zn as GetSendPermissionsError, zr as PollCliLoginErrors, zt as DeleteEmailErrors } from "../index-oRkCqj6u.js";
|
|
2
|
+
export { Account, AccountUpdated, AddDomainData, AddDomainError, AddDomainErrors, AddDomainInput, AddDomainResponse, AddDomainResponses, Auth, CliLoginPollResult, CliLoginStartResult, CliLogoutData, CliLogoutError, CliLogoutErrors, CliLogoutInput, CliLogoutResponse, CliLogoutResponses, CliLogoutResult, ClientOptions, CreateClientConfig, CreateEndpointData, CreateEndpointError, CreateEndpointErrors, CreateEndpointInput, CreateEndpointResponse, CreateEndpointResponses, CreateFilterData, CreateFilterError, CreateFilterErrors, CreateFilterInput, CreateFilterResponse, CreateFilterResponses, Cursor, DEFAULT_BASE_URL, DeleteDomainData, DeleteDomainError, DeleteDomainErrors, DeleteDomainResponse, DeleteDomainResponses, DeleteEmailData, DeleteEmailError, DeleteEmailErrors, DeleteEmailResponse, DeleteEmailResponses, DeleteEndpointData, DeleteEndpointError, DeleteEndpointErrors, DeleteEndpointResponse, DeleteEndpointResponses, DeleteFilterData, DeleteFilterError, DeleteFilterErrors, DeleteFilterResponse, DeleteFilterResponses, DeliveryStatus, DeliverySummary, DiscardContentResult, DiscardEmailContentData, DiscardEmailContentError, DiscardEmailContentErrors, DiscardEmailContentResponse, DiscardEmailContentResponses, Domain, DomainVerifyResult, DownloadAttachmentsData, DownloadAttachmentsError, DownloadAttachmentsErrors, DownloadAttachmentsResponse, DownloadAttachmentsResponses, DownloadRawEmailData, DownloadRawEmailError, DownloadRawEmailErrors, DownloadRawEmailResponse, DownloadRawEmailResponses, EmailDetail, EmailDetailReply, EmailStatus, EmailSummary, EmailWebhookStatus, Endpoint, ErrorResponse, Filter, ForwardInput, GateDenial, GateFix, GetAccountData, GetAccountError, GetAccountErrors, GetAccountResponse, GetAccountResponses, GetEmailData, GetEmailError, GetEmailErrors, GetEmailResponse, GetEmailResponses, GetSendPermissionsData, GetSendPermissionsError, GetSendPermissionsErrors, GetSendPermissionsResponse, GetSendPermissionsResponses, GetSentEmailData, GetSentEmailError, GetSentEmailErrors, GetSentEmailResponse, GetSentEmailResponses, GetStorageStatsData, GetStorageStatsError, GetStorageStatsErrors, GetStorageStatsResponse, GetStorageStatsResponses, GetWebhookSecretData, GetWebhookSecretError, GetWebhookSecretErrors, GetWebhookSecretResponse, GetWebhookSecretResponses, Limit, ListDeliveriesData, ListDeliveriesError, ListDeliveriesErrors, ListDeliveriesResponse, ListDeliveriesResponses, ListDomainsData, ListDomainsError, ListDomainsErrors, ListDomainsResponse, ListDomainsResponses, ListEmailsData, ListEmailsError, ListEmailsErrors, ListEmailsResponse, ListEmailsResponses, ListEndpointsData, ListEndpointsError, ListEndpointsErrors, ListEndpointsResponse, ListEndpointsResponses, ListEnvelope, ListFiltersData, ListFiltersError, ListFiltersErrors, ListFiltersResponse, ListFiltersResponses, ListSentEmailsData, ListSentEmailsError, ListSentEmailsErrors, ListSentEmailsResponse, ListSentEmailsResponses, Options, PaginationMeta, PollCliLoginData, PollCliLoginError, PollCliLoginErrors, PollCliLoginInput, PollCliLoginResponse, PollCliLoginResponses, PrimitiveApiClient, PrimitiveApiClientOptions, PrimitiveApiError, PrimitiveApiErrorDetails, PrimitiveClient, PrimitiveClientOptions, Client as PrimitiveGeneratedApiClient, ClientOptions$1 as PrimitiveGeneratedApiClientOptions, Config as PrimitiveGeneratedApiConfig, Options$1 as PrimitiveGeneratedApiOptions, RequestOptions as PrimitiveGeneratedApiRequestOptions, RequestResult as PrimitiveGeneratedApiRequestResult, ReplayDeliveryData, ReplayDeliveryError, ReplayDeliveryErrors, ReplayDeliveryResponse, ReplayDeliveryResponses, ReplayEmailWebhooksData, ReplayEmailWebhooksError, ReplayEmailWebhooksErrors, ReplayEmailWebhooksResponse, ReplayEmailWebhooksResponses, ReplayResult, ReplyInput, ReplyToEmailData, ReplyToEmailError, ReplyToEmailErrors, ReplyToEmailResponse, ReplyToEmailResponses, RequestOptions$1 as RequestOptions, ResourceId, ResponseStyle, RotateWebhookSecretData, RotateWebhookSecretError, RotateWebhookSecretErrors, RotateWebhookSecretResponse, RotateWebhookSecretResponses, SendEmailData, SendEmailError, SendEmailErrors, SendEmailResponse, SendEmailResponses, SendInput, SendMailInput, SendMailResult, SendPermissionAddress, SendPermissionAnyRecipient, SendPermissionManagedZone, SendPermissionRule, SendPermissionYourDomain, SendPermissionsMeta, SendResult, SendThreadInput, SentEmailDetail, SentEmailStatus, SentEmailSummary, StartCliLoginData, StartCliLoginError, StartCliLoginErrors, StartCliLoginInput, StartCliLoginResponse, StartCliLoginResponses, StorageStats, SuccessEnvelope, TestEndpointData, TestEndpointError, TestEndpointErrors, TestEndpointResponse, TestEndpointResponses, TestResult, UnverifiedDomain, UpdateAccountData, UpdateAccountError, UpdateAccountErrors, UpdateAccountInput, UpdateAccountResponse, UpdateAccountResponses, UpdateDomainData, UpdateDomainError, UpdateDomainErrors, UpdateDomainInput, UpdateDomainResponse, UpdateDomainResponses, UpdateEndpointData, UpdateEndpointError, UpdateEndpointErrors, UpdateEndpointInput, UpdateEndpointResponse, UpdateEndpointResponses, UpdateFilterData, UpdateFilterError, UpdateFilterErrors, UpdateFilterInput, UpdateFilterResponse, UpdateFilterResponses, VerifiedDomain, VerifyDomainData, VerifyDomainError, VerifyDomainErrors, VerifyDomainResponse, VerifyDomainResponses, WebhookSecret, addDomain, cliLogout, client, createEndpoint, createFilter, createPrimitiveApiClient, createPrimitiveClient, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, discardEmailContent, downloadAttachments, downloadRawEmail, getAccount, getEmail, getSendPermissions, getSentEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, listSentEmails, operations, pollCliLogin, replayDelivery, replayEmailWebhooks, replyToEmail, rotateWebhookSecret, sendEmail, startCliLogin, testEndpoint, updateAccount, updateDomain, updateEndpoint, updateFilter, verifyDomain };
|
package/dist/api/index.js
CHANGED
|
@@ -140,6 +140,11 @@ export class PrimitiveApiError extends Error {
|
|
|
140
140
|
this.details = options.details;
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
+
function isAbortLikeError(error) {
|
|
144
|
+
if (!(error instanceof Error))
|
|
145
|
+
return false;
|
|
146
|
+
return error.name === "AbortError" || error.name === "TimeoutError";
|
|
147
|
+
}
|
|
143
148
|
function parseRetryAfterHeader(response) {
|
|
144
149
|
if (!response)
|
|
145
150
|
return undefined;
|
|
@@ -166,8 +171,33 @@ export class PrimitiveApiClient {
|
|
|
166
171
|
return this.client.setConfig(config);
|
|
167
172
|
}
|
|
168
173
|
}
|
|
174
|
+
function resolveRequestOptions(options) {
|
|
175
|
+
const signals = [];
|
|
176
|
+
if (options?.signal)
|
|
177
|
+
signals.push(options.signal);
|
|
178
|
+
if (options?.timeout !== undefined) {
|
|
179
|
+
signals.push(AbortSignal.timeout(options.timeout));
|
|
180
|
+
}
|
|
181
|
+
const signal = signals.length === 0
|
|
182
|
+
? undefined
|
|
183
|
+
: signals.length === 1
|
|
184
|
+
? signals[0]
|
|
185
|
+
: AbortSignal.any(signals);
|
|
186
|
+
const headers = {
|
|
187
|
+
...(options?.headers ?? {}),
|
|
188
|
+
...(options?.idempotencyKey
|
|
189
|
+
? { "Idempotency-Key": options.idempotencyKey }
|
|
190
|
+
: {}),
|
|
191
|
+
};
|
|
192
|
+
const resolved = {};
|
|
193
|
+
if (signal)
|
|
194
|
+
resolved.signal = signal;
|
|
195
|
+
if (Object.keys(headers).length > 0)
|
|
196
|
+
resolved.headers = headers;
|
|
197
|
+
return resolved;
|
|
198
|
+
}
|
|
169
199
|
export class PrimitiveClient extends PrimitiveApiClient {
|
|
170
|
-
async send(input) {
|
|
200
|
+
async send(input, options) {
|
|
171
201
|
validateSendInput(input);
|
|
172
202
|
const body = {
|
|
173
203
|
from: input.from,
|
|
@@ -188,9 +218,7 @@ export class PrimitiveClient extends PrimitiveApiClient {
|
|
|
188
218
|
};
|
|
189
219
|
const result = await generatedOperations.sendEmail({
|
|
190
220
|
body,
|
|
191
|
-
...(
|
|
192
|
-
? { headers: { "Idempotency-Key": input.idempotencyKey } }
|
|
193
|
-
: {}),
|
|
221
|
+
...resolveRequestOptions(options),
|
|
194
222
|
client: this.client,
|
|
195
223
|
responseStyle: "fields",
|
|
196
224
|
});
|
|
@@ -210,7 +238,7 @@ export class PrimitiveClient extends PrimitiveApiClient {
|
|
|
210
238
|
* subject match to thread, so a custom subject silently breaks the
|
|
211
239
|
* thread for half the recipient population.
|
|
212
240
|
*/
|
|
213
|
-
async reply(email, input) {
|
|
241
|
+
async reply(email, input, options) {
|
|
214
242
|
const resolved = typeof input === "string" ? { text: input } : input;
|
|
215
243
|
// Reject the subject override at runtime so a JS caller (no TS
|
|
216
244
|
// types) gets the same loud error as a TS caller. Without this,
|
|
@@ -234,19 +262,20 @@ export class PrimitiveClient extends PrimitiveApiClient {
|
|
|
234
262
|
const result = await generatedOperations.replyToEmail({
|
|
235
263
|
body,
|
|
236
264
|
path: { id: email.id },
|
|
265
|
+
...resolveRequestOptions(options),
|
|
237
266
|
client: this.client,
|
|
238
267
|
responseStyle: "fields",
|
|
239
268
|
});
|
|
240
269
|
return unwrapSendResult(result);
|
|
241
270
|
}
|
|
242
|
-
async forward(email, input) {
|
|
271
|
+
async forward(email, input, options) {
|
|
243
272
|
validateForwardInput(input);
|
|
244
273
|
return this.send({
|
|
245
274
|
from: input.from ?? email.receivedBy,
|
|
246
275
|
to: input.to,
|
|
247
276
|
subject: input.subject ?? email.forwardSubject,
|
|
248
277
|
bodyText: buildForwardText(email, input.bodyText),
|
|
249
|
-
});
|
|
278
|
+
}, options);
|
|
250
279
|
}
|
|
251
280
|
}
|
|
252
281
|
function buildForwardText(email, intro) {
|
|
@@ -276,6 +305,9 @@ function buildForwardText(email, intro) {
|
|
|
276
305
|
function unwrapSendResult(result) {
|
|
277
306
|
const response = result.response;
|
|
278
307
|
if (result.error) {
|
|
308
|
+
if (isAbortLikeError(result.error)) {
|
|
309
|
+
throw result.error;
|
|
310
|
+
}
|
|
279
311
|
const parsed = parseApiErrorPayload(result.error);
|
|
280
312
|
throw new PrimitiveApiError(parsed.message, {
|
|
281
313
|
payload: result.error,
|