@flowmails/flowmails-sdk 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -5
- package/dist/index.cjs +299 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +541 -18
- package/dist/index.d.ts +541 -18
- package/dist/index.js +299 -21
- package/dist/index.js.map +1 -1
- package/package.json +28 -12
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,233 @@ interface SendAttachment {
|
|
|
11
11
|
content: string | Uint8Array;
|
|
12
12
|
mimeType?: string;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* One event in the durable log — what arrived, where, and from whom.
|
|
16
|
+
*
|
|
17
|
+
* The event carries **routing facts plus the subject line**, never a
|
|
18
|
+
* body: that is the platform's core promise (`docs/agent-platform.md`
|
|
19
|
+
* §4.2), and the body is opt-in through {@link MessageDetail}. The
|
|
20
|
+
* `messageId` is the SMTP `Message-ID` — the key every content read
|
|
21
|
+
* takes.
|
|
22
|
+
*/
|
|
23
|
+
interface AgentEvent {
|
|
24
|
+
/** The cursor value. Treat it as opaque; pass it back as `after`. */
|
|
25
|
+
id: string;
|
|
26
|
+
/** The SMTP `Message-ID`. Pass this to `messages.get()`. */
|
|
27
|
+
messageId: string;
|
|
28
|
+
/** `inbound.received` — the only event type the platform emits. */
|
|
29
|
+
event: string;
|
|
30
|
+
/** The mailbox the message landed in, e.g. `billing@yourapp.com`. */
|
|
31
|
+
recipient: string;
|
|
32
|
+
/** The sender, when the receive worker could determine it. */
|
|
33
|
+
sender: string | null;
|
|
34
|
+
/** The subject line — the one content field on the event. */
|
|
35
|
+
subject: string | null;
|
|
36
|
+
/** ISO-8601 timestamp of when the platform recorded the event. */
|
|
37
|
+
createdAt: string;
|
|
38
|
+
}
|
|
39
|
+
/** Options for {@link AgentEvents.list}. */
|
|
40
|
+
interface ListEventsOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Cursor: return events **after** this event id. Pass the
|
|
43
|
+
* `nextCursor` of the previous page. Treat it as opaque — it is an
|
|
44
|
+
* event id, not a timestamp, because two events can land in the
|
|
45
|
+
* same millisecond and a cursor that can skip a row loses mail.
|
|
46
|
+
*/
|
|
47
|
+
after?: string;
|
|
48
|
+
/** Page size. The platform caps it; ask for what you will drain. */
|
|
49
|
+
limit?: number;
|
|
50
|
+
/** Exact recipient address filter. */
|
|
51
|
+
recipient?: string;
|
|
52
|
+
/** Exact sender address filter. */
|
|
53
|
+
sender?: string;
|
|
54
|
+
/** Case-insensitive **substring** of the subject. */
|
|
55
|
+
subject?: string;
|
|
56
|
+
}
|
|
57
|
+
/** One page of the event log. */
|
|
58
|
+
interface ListEventsResult {
|
|
59
|
+
events: AgentEvent[];
|
|
60
|
+
/**
|
|
61
|
+
* The cursor to pass as `after` on the next call. Present whenever
|
|
62
|
+
* the page was not empty; absent when the log is drained.
|
|
63
|
+
*/
|
|
64
|
+
nextCursor?: string;
|
|
65
|
+
}
|
|
66
|
+
/** Options for {@link AgentWaits.create}. */
|
|
67
|
+
interface CreateWaitOptions {
|
|
68
|
+
/** The mailbox to watch, e.g. `billing@yourapp.com`. */
|
|
69
|
+
address: string;
|
|
70
|
+
/** Only resolve for mail from this sender. */
|
|
71
|
+
sender?: string;
|
|
72
|
+
/** Only resolve for a subject containing this substring. */
|
|
73
|
+
subject?: string;
|
|
74
|
+
/**
|
|
75
|
+
* How long to keep the wait open, in milliseconds. Defaults to 15
|
|
76
|
+
* minutes; the platform caps it at 24 hours.
|
|
77
|
+
*/
|
|
78
|
+
timeoutMs?: number;
|
|
79
|
+
}
|
|
80
|
+
/** A durable wait, as the platform reports it. */
|
|
81
|
+
interface WaitStatus {
|
|
82
|
+
waitId: string;
|
|
83
|
+
/** `pending` → `resolved` (a message landed) or `expired`. */
|
|
84
|
+
status: "pending" | "resolved" | "expired";
|
|
85
|
+
address: string;
|
|
86
|
+
sender: string | null;
|
|
87
|
+
subject: string | null;
|
|
88
|
+
/** The SMTP `Message-ID` that resolved the wait, when it resolved. */
|
|
89
|
+
resolvedMessageId: string | null;
|
|
90
|
+
/** ISO-8601 deadline. A wait past it reads as `expired`. */
|
|
91
|
+
expiresAt: string | number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A newly-opened wait.
|
|
95
|
+
*
|
|
96
|
+
* Returned **immediately** — the platform writes a row and answers,
|
|
97
|
+
* it never suspends the request. A verification mail arrives minutes
|
|
98
|
+
* to hours later and an edge request dies long before that, so the
|
|
99
|
+
* wait is durable state the agent polls with {@link AgentWaits.get}.
|
|
100
|
+
*/
|
|
101
|
+
interface CreateWaitResult extends WaitStatus {
|
|
102
|
+
/** A hint for the poll loop: check again in a few seconds. */
|
|
103
|
+
pollAfterMs: number;
|
|
104
|
+
}
|
|
105
|
+
/** The full content of one message. Fetched, never pushed. */
|
|
106
|
+
interface MessageDetail {
|
|
107
|
+
/** The worker's numeric row id. */
|
|
108
|
+
id: number | string;
|
|
109
|
+
/** The SMTP `Message-ID` the event carried. */
|
|
110
|
+
messageId: string;
|
|
111
|
+
from: string;
|
|
112
|
+
fromName: string | null;
|
|
113
|
+
to: string;
|
|
114
|
+
toName: string | null;
|
|
115
|
+
subject: string | null;
|
|
116
|
+
/** Plain-text body. Ideal for regexing a verification code out. */
|
|
117
|
+
text: string | null;
|
|
118
|
+
/** Rendered HTML body, when the message had one. */
|
|
119
|
+
html: string | null;
|
|
120
|
+
receivedAt: string | null;
|
|
121
|
+
attachments: Array<{
|
|
122
|
+
filename: string | null;
|
|
123
|
+
mimeType: string | null;
|
|
124
|
+
size: number | null;
|
|
125
|
+
url: string | null;
|
|
126
|
+
}>;
|
|
127
|
+
}
|
|
128
|
+
/** One address (mailbox) the platform accepts mail for. */
|
|
129
|
+
interface AgentAddress {
|
|
130
|
+
address: string;
|
|
131
|
+
localPart: string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* One domain on the account.
|
|
135
|
+
*
|
|
136
|
+
* `routingMode` decides whether a new address needs anything to
|
|
137
|
+
* happen: on `catchall` every local part already delivers, on
|
|
138
|
+
* `rules` only the listed ones do.
|
|
139
|
+
*/
|
|
140
|
+
interface AgentDomain {
|
|
141
|
+
id: string;
|
|
142
|
+
name: string;
|
|
143
|
+
routingMode: "catchall" | "rules";
|
|
144
|
+
localParts: string[];
|
|
145
|
+
/** False when the per-account receive worker is not deployed yet. */
|
|
146
|
+
ready: boolean;
|
|
147
|
+
}
|
|
148
|
+
/** Result of {@link AgentAddresses.create}. */
|
|
149
|
+
interface CreateAddressResult {
|
|
150
|
+
address: string;
|
|
151
|
+
localPart: string;
|
|
152
|
+
domainId: string;
|
|
153
|
+
domain: string;
|
|
154
|
+
/** False when the address already existed — the call is idempotent. */
|
|
155
|
+
created: boolean;
|
|
156
|
+
routingMode?: "catchall" | "rules";
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* One message of a conversation chain.
|
|
160
|
+
*
|
|
161
|
+
* It extends {@link MessageDetail} because the thread route uses the
|
|
162
|
+
* **same projection** the single-message read uses — the same
|
|
163
|
+
* fields, the same shape. The only addition is the truncation flag.
|
|
164
|
+
*/
|
|
165
|
+
interface ThreadMessage extends MessageDetail {
|
|
166
|
+
/**
|
|
167
|
+
* `1` when the receive worker shortened the body.
|
|
168
|
+
*
|
|
169
|
+
* The worker returns a bounded window of the chain and truncates
|
|
170
|
+
* the bodies of the non-current members — a long thread must not
|
|
171
|
+
* become a way to pull a whole mailbox. `total` / `hasMoreOlder` /
|
|
172
|
+
* `hasMoreNewer` say whether the chain extends past the window.
|
|
173
|
+
*/
|
|
174
|
+
bodyTruncated: 0 | 1;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A conversation chain — `docs/agent-platform.md` §10.8 AP-27.
|
|
178
|
+
*/
|
|
179
|
+
interface ThreadDetail {
|
|
180
|
+
/** The conversation **root's** SMTP `Message-ID`. */
|
|
181
|
+
threadId: string;
|
|
182
|
+
/** The platform domain id the chain was read from. */
|
|
183
|
+
domainId: string;
|
|
184
|
+
/** The domain name the chain was read from. */
|
|
185
|
+
domain: string;
|
|
186
|
+
/** The full chain length — not just the returned window. */
|
|
187
|
+
total: number;
|
|
188
|
+
/** The chain extends past the window, older side. */
|
|
189
|
+
hasMoreOlder: boolean;
|
|
190
|
+
/** The chain extends past the window, newer side. */
|
|
191
|
+
hasMoreNewer: boolean;
|
|
192
|
+
/** The chain, oldest first. */
|
|
193
|
+
messages: ThreadMessage[];
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* One search hit.
|
|
197
|
+
*
|
|
198
|
+
* Addressing, the subject and a short preview — never the body. The
|
|
199
|
+
* body is fetched per message, through {@link AgentMessages.get},
|
|
200
|
+
* when the agent decides a message matters.
|
|
201
|
+
*/
|
|
202
|
+
interface SearchMessageHit {
|
|
203
|
+
/** The worker's row id. Accepted by {@link AgentMessages.get}. */
|
|
204
|
+
id: number | null;
|
|
205
|
+
/** The SMTP `Message-ID`, when the sender supplied one. */
|
|
206
|
+
messageId: string;
|
|
207
|
+
from: string | null;
|
|
208
|
+
fromName: string | null;
|
|
209
|
+
to: string | null;
|
|
210
|
+
toName: string | null;
|
|
211
|
+
subject: string | null;
|
|
212
|
+
receivedAt: string | null;
|
|
213
|
+
/** A short plain-text preview of the body. */
|
|
214
|
+
preview: string | null;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The arguments of a mailbox search.
|
|
218
|
+
*
|
|
219
|
+
* `domainId` is required on the call (not in this shape) because the
|
|
220
|
+
* receive worker's search path is domain-scoped: one domain, one
|
|
221
|
+
* round-trip, one stable ordering. `GET /api/agent/domains` is the
|
|
222
|
+
* call that answers it.
|
|
223
|
+
*/
|
|
224
|
+
interface SearchMessagesOptions {
|
|
225
|
+
/** The query. At least two characters — the platform refuses less. */
|
|
226
|
+
q: string;
|
|
227
|
+
/** The page size. */
|
|
228
|
+
limit?: number;
|
|
229
|
+
/** Which field to match. Defaults to `body` (subject + from + to + text). */
|
|
230
|
+
field?: "subject" | "from" | "to" | "body";
|
|
231
|
+
/** Which mailbox direction. Defaults to `receive`. */
|
|
232
|
+
type?: "receive" | "send";
|
|
233
|
+
}
|
|
234
|
+
/** The result of a mailbox search. */
|
|
235
|
+
interface SearchMessagesResult {
|
|
236
|
+
messages: SearchMessageHit[];
|
|
237
|
+
/** How many rows match the filter, ignoring `limit`. */
|
|
238
|
+
total: number;
|
|
239
|
+
domainId: string;
|
|
240
|
+
}
|
|
14
241
|
/**
|
|
15
242
|
* Composed send payload.
|
|
16
243
|
*
|
|
@@ -30,6 +257,21 @@ interface SendOptions {
|
|
|
30
257
|
to: string | string[];
|
|
31
258
|
/** Optional reply-to override. */
|
|
32
259
|
replyTo?: string;
|
|
260
|
+
/**
|
|
261
|
+
* Reply in thread: the SMTP `Message-ID` (or numeric id) of the
|
|
262
|
+
* message being answered.
|
|
263
|
+
*
|
|
264
|
+
* When set, the SDK backend resolves the parent row and derives
|
|
265
|
+
* the `In-Reply-To` / `References` headers and the thread anchor,
|
|
266
|
+
* so the recipient's mail client threads your message with the
|
|
267
|
+
* original conversation — and the dashboard shows it in the same
|
|
268
|
+
* thread. The caller supplies the **parent**, never the headers:
|
|
269
|
+
* deriving `References` by hand is how threads fork.
|
|
270
|
+
*
|
|
271
|
+
* A parent with no `Message-ID` header is rejected: there is
|
|
272
|
+
* nothing to point `In-Reply-To` at.
|
|
273
|
+
*/
|
|
274
|
+
replyToMessageId?: string;
|
|
33
275
|
/** Subject line — required, non-empty. */
|
|
34
276
|
subject: string;
|
|
35
277
|
/** Plain-text body. Required iff `html` is also missing. */
|
|
@@ -40,32 +282,101 @@ interface SendOptions {
|
|
|
40
282
|
html?: string;
|
|
41
283
|
/** Attachments. */
|
|
42
284
|
attachments?: SendAttachment[];
|
|
285
|
+
/**
|
|
286
|
+
* Idempotency key — the same key under the same account and the
|
|
287
|
+
* same request returns the **original** result and does not send
|
|
288
|
+
* twice.
|
|
289
|
+
*
|
|
290
|
+
* Give every send a key you can rebuild after a timeout (a UUID
|
|
291
|
+
* per logical mail, not per attempt) and a retry becomes free: the
|
|
292
|
+
* backend replays the first answer instead of delivering a second
|
|
293
|
+
* message.
|
|
294
|
+
*
|
|
295
|
+
* The key is scoped to the **account**, not globally — two accounts
|
|
296
|
+
* may use the same string. Reusing one key for a *different* payload
|
|
297
|
+
* is a client bug and is refused with `idempotency_key_conflict`
|
|
298
|
+
* (409) rather than answered with the first result.
|
|
299
|
+
*/
|
|
300
|
+
idempotencyKey?: string;
|
|
43
301
|
}
|
|
44
302
|
/**
|
|
45
|
-
* Result of a successful send.
|
|
46
|
-
* in `apps/web/app/routes/home.tsx`:
|
|
303
|
+
* Result of a successful send.
|
|
47
304
|
*
|
|
48
|
-
*
|
|
305
|
+
* `id` is the platform's row id; `messageId` is the SMTP `Message-ID`
|
|
306
|
+
* the relay assigned, which is the key every read path takes — pass
|
|
307
|
+
* it to {@link AgentMessages.get} to read a reply, or to
|
|
308
|
+
* {@link AgentMessages.status} to poll delivery.
|
|
49
309
|
*/
|
|
50
310
|
interface SendResult {
|
|
51
311
|
/** Numeric email row id (stringified for JSON safety). */
|
|
52
312
|
id: string;
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
313
|
+
/** The row's lifecycle state at send time. */
|
|
314
|
+
status: string;
|
|
315
|
+
/**
|
|
316
|
+
* The SMTP `Message-ID` the relay assigned (the receive worker's
|
|
317
|
+
* `resendEmailId`). Empty when the send failed before the relay
|
|
318
|
+
* accepted it.
|
|
319
|
+
*/
|
|
320
|
+
messageId?: string;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* What the credential behind the client is allowed to do, and which
|
|
324
|
+
* account it belongs to.
|
|
325
|
+
*
|
|
326
|
+
* This is the **connection check** (`docs/agent-platform.md` §10.8
|
|
327
|
+
* AP-05): it answers "is my key live, which account is it, which
|
|
328
|
+
* domain may it send from, and what may it do?" without sending a
|
|
329
|
+
* single message — the only two ways to get that answer before it
|
|
330
|
+
* existed were to send real mail or to fail.
|
|
331
|
+
*/
|
|
332
|
+
interface AccountInfo {
|
|
333
|
+
/** The account the credential belongs to. */
|
|
334
|
+
userId: string;
|
|
335
|
+
/**
|
|
336
|
+
* The domain the credential is bound to — the constraint on
|
|
337
|
+
* sending. `null` when the credential carries no binding.
|
|
338
|
+
*/
|
|
339
|
+
domain: string | null;
|
|
340
|
+
/** The per-account receive worker the credential sends through. */
|
|
341
|
+
workerHost: string | null;
|
|
342
|
+
/**
|
|
343
|
+
* Which credential type answered: `"sdk_key"` (the dashboard's
|
|
344
|
+
* domain-bound API key) or `"agent_credential"` (a scoped
|
|
345
|
+
* credential issued for one set of capabilities).
|
|
346
|
+
*/
|
|
347
|
+
credentialType: string;
|
|
348
|
+
/** The scopes this credential holds. */
|
|
349
|
+
scopes: string[];
|
|
57
350
|
}
|
|
58
351
|
interface FlowmailsOptions {
|
|
59
352
|
/** `fm_<32+hex>` API key issued in `apps/web/app/routes/dashboard/settings/api-keys.tsx`. */
|
|
60
353
|
apiKey: string;
|
|
61
354
|
/** Override the SDK backend base URL. Defaults to `https://sdk.flowmails.net`. */
|
|
62
355
|
baseURL?: string;
|
|
356
|
+
/**
|
|
357
|
+
* The **platform** origin, used by the listen half of the surface
|
|
358
|
+
* (`fm.events`, `fm.messages`, `fm.waits`, `fm.addresses`). The
|
|
359
|
+
* send path goes to {@link baseURL} (the SDK backend); the event
|
|
360
|
+
* log, the durable wait and the message read live on the platform
|
|
361
|
+
* worker, which is a different deployment.
|
|
362
|
+
*
|
|
363
|
+
* Defaults to `https://flowmails.net`. Set it for a self-hosted or
|
|
364
|
+
* staging deployment — the same API key authenticates both.
|
|
365
|
+
*/
|
|
366
|
+
platformURL?: string;
|
|
63
367
|
/** Inject a `fetch` implementation (Workers environments, test harnesses). */
|
|
64
368
|
fetch?: typeof globalThis.fetch;
|
|
65
369
|
/**
|
|
66
|
-
* Number of automatic retries on transient failures (5xx, 408,
|
|
67
|
-
* 429). Defaults to 2. Set to 0 to
|
|
68
|
-
* bounded; doesn't apply to 4xx
|
|
370
|
+
* Number of automatic retries on transient failures (5xx, 408, and
|
|
371
|
+
* a 429 that asks for another attempt). Defaults to 2. Set to 0 to
|
|
372
|
+
* disable. The retry budget is bounded; doesn't apply to 4xx
|
|
373
|
+
* validation / auth failures.
|
|
374
|
+
*
|
|
375
|
+
* A **quota** refusal (429 `rate_limit_exceeded`) is deliberately
|
|
376
|
+
* NOT retried: the window is an hour, a retry inside it cannot
|
|
377
|
+
* succeed, and it would only burn another slot. The error carries
|
|
378
|
+
* `limit` / `remaining` / `resetAt` so the caller can wait for the
|
|
379
|
+
* window instead of guessing.
|
|
69
380
|
*/
|
|
70
381
|
maxRetries?: number;
|
|
71
382
|
/**
|
|
@@ -79,26 +390,218 @@ interface FlowmailsOptions {
|
|
|
79
390
|
declare class Flowmails {
|
|
80
391
|
private readonly apiKey;
|
|
81
392
|
private readonly baseURL;
|
|
393
|
+
private readonly platformURL;
|
|
82
394
|
private readonly fetchFn;
|
|
83
395
|
private readonly maxRetries;
|
|
84
396
|
private readonly requestId?;
|
|
85
397
|
constructor(opts: FlowmailsOptions);
|
|
86
398
|
/**
|
|
87
|
-
* Send mail through the SDK backend.
|
|
399
|
+
* Send mail through the SDK backend.
|
|
400
|
+
*
|
|
401
|
+
* Pass `replyToMessageId` to answer a message in thread — the SDK
|
|
402
|
+
* backend resolves the parent and derives the `In-Reply-To` /
|
|
403
|
+
* `References` headers and the thread anchor, so the recipient's
|
|
404
|
+
* client threads it with the original conversation.
|
|
88
405
|
*
|
|
89
|
-
* Returns `{ id, status
|
|
406
|
+
* Returns `{ id, status, messageId }` on success; throws one of
|
|
90
407
|
* `AuthenticationError` / `ValidationError` / `RateLimitError` /
|
|
91
408
|
* `UpstreamError` on failure (all subclasses of `FlowmailsError`).
|
|
92
409
|
*/
|
|
93
410
|
send(opts: SendOptions): Promise<SendResult>;
|
|
94
411
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
412
|
+
* The connection check — who the credential is.
|
|
413
|
+
*
|
|
414
|
+
* `flowmails test` (the CLI's documented first command) and every
|
|
415
|
+
* "is my setup right?" question end here. It verifies the key,
|
|
416
|
+
* names the account, names the bound domain and reports the
|
|
417
|
+
* scopes — and it sends nothing, so running it can never mail
|
|
418
|
+
* somebody by accident.
|
|
419
|
+
*
|
|
420
|
+
* @throws {AuthenticationError} when the key is missing, malformed
|
|
421
|
+
* or revoked.
|
|
422
|
+
*/
|
|
423
|
+
me(): Promise<AccountInfo>;
|
|
424
|
+
/**
|
|
425
|
+
* The event log — the listen half of the surface, read with a
|
|
426
|
+
* cursor.
|
|
427
|
+
*
|
|
428
|
+
* ```ts
|
|
429
|
+
* const fm = new Flowmails({ apiKey: process.env.FLOWMAILS_API_KEY! });
|
|
430
|
+
* let after: string | undefined;
|
|
431
|
+
* for (;;) {
|
|
432
|
+
* const page = await fm.events.list({ after, subject: "invoice" });
|
|
433
|
+
* for (const event of page.events) { … }
|
|
434
|
+
* after = page.nextCursor ?? after;
|
|
435
|
+
* }
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
readonly events: AgentEvents;
|
|
439
|
+
/**
|
|
440
|
+
* Read one message by its SMTP `Message-ID` — the id the event
|
|
441
|
+
* carried.
|
|
442
|
+
*
|
|
443
|
+
* The event log deliberately hands over routing facts and a
|
|
444
|
+
* subject and never a body (§4.2), so the content is an explicit
|
|
445
|
+
* ask. This is that ask.
|
|
446
|
+
*/
|
|
447
|
+
readonly messages: AgentMessages;
|
|
448
|
+
/**
|
|
449
|
+
* The conversation a message belongs to.
|
|
450
|
+
*
|
|
451
|
+
* The core listen/reply loop can store the message ids itself;
|
|
452
|
+
* this is for the agent that wants the platform to reconstruct the
|
|
453
|
+
* chain. The chain is read from the **conversation root's** SMTP
|
|
454
|
+
* `Message-ID`, which is exactly what `email.threadId` holds.
|
|
455
|
+
*/
|
|
456
|
+
readonly threads: AgentThreads;
|
|
457
|
+
/**
|
|
458
|
+
* The durable wait — the one thing an agent cannot build for
|
|
459
|
+
* itself.
|
|
460
|
+
*
|
|
461
|
+
* A suspended HTTP request dies on the edge long before a
|
|
462
|
+
* verification mail arrives (minutes to hours later), so the wait
|
|
463
|
+
* is a row on the platform and the agent polls it. `create()`
|
|
464
|
+
* answers **immediately**; it does not block.
|
|
465
|
+
*/
|
|
466
|
+
readonly waits: AgentWaits;
|
|
467
|
+
/**
|
|
468
|
+
* The addresses (mailboxes) the key's account owns, and the one
|
|
469
|
+
* narrow write the agent surface has: create a single one.
|
|
470
|
+
*/
|
|
471
|
+
readonly addresses: AgentAddresses;
|
|
472
|
+
/**
|
|
473
|
+
* Private: the one request path, with retry + backoff + error
|
|
474
|
+
* mapping shared by every public method.
|
|
475
|
+
*
|
|
476
|
+
* `origin` is explicit because the surface spans two deployments:
|
|
477
|
+
* the SDK backend (`baseURL`) for sending, the platform
|
|
478
|
+
* (`platformURL`) for reading and waiting. `method` is explicit
|
|
479
|
+
* because the listen endpoints are GETs — the v0.1 helper was
|
|
480
|
+
* POST-only, which is why reading used to mean hand-rolling HTTP.
|
|
99
481
|
*/
|
|
100
482
|
private request;
|
|
101
483
|
}
|
|
484
|
+
/**
|
|
485
|
+
* The event log namespace — see {@link Flowmails.events}.
|
|
486
|
+
*/
|
|
487
|
+
interface AgentEvents {
|
|
488
|
+
/**
|
|
489
|
+
* One page of the log, oldest first, after `opts.after`.
|
|
490
|
+
*
|
|
491
|
+
* The cursor is an **event id**, never a timestamp: two events can
|
|
492
|
+
* land in the same millisecond, and a cursor that can skip a row
|
|
493
|
+
* loses mail. An unknown cursor is a `ValidationError`, never an
|
|
494
|
+
* empty page — "no new events" would silently stop the agent
|
|
495
|
+
* seeing mail.
|
|
496
|
+
*/
|
|
497
|
+
list(opts?: ListEventsOptions): Promise<ListEventsResult>;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* The message-read namespace — see {@link Flowmails.messages}.
|
|
501
|
+
*/
|
|
502
|
+
interface AgentMessages {
|
|
503
|
+
/** Fetch the full content of one message by SMTP `Message-ID`. */
|
|
504
|
+
get(messageId: string, opts?: {
|
|
505
|
+
domainId?: string;
|
|
506
|
+
}): Promise<MessageDetail>;
|
|
507
|
+
/** Poll a sent message's delivery state by row id or `Message-ID`. */
|
|
508
|
+
status(id: string): Promise<SendStatus>;
|
|
509
|
+
/**
|
|
510
|
+
* `search_emails`: look **back** through the mailbox.
|
|
511
|
+
*
|
|
512
|
+
* The event log is the primary listen path — a cursor over what
|
|
513
|
+
* just arrived. Search is the history path: "what did that
|
|
514
|
+
* supplier mail me last quarter?" is not an event-log question,
|
|
515
|
+
* and the event log carries no body.
|
|
516
|
+
*
|
|
517
|
+
* A result carries addressing, the subject and a short **preview**;
|
|
518
|
+
* the body is fetched per message with {@link AgentMessages.get},
|
|
519
|
+
* so a search is never a way to pull the whole mailbox through a
|
|
520
|
+
* query parameter.
|
|
521
|
+
*/
|
|
522
|
+
search(domainId: string, opts: SearchMessagesOptions): Promise<SearchMessagesResult>;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* The conversation namespace — see {@link Flowmails.threads}.
|
|
526
|
+
*/
|
|
527
|
+
interface AgentThreads {
|
|
528
|
+
/**
|
|
529
|
+
* Read the conversation a message belongs to.
|
|
530
|
+
*
|
|
531
|
+
* `threadId` is the conversation **root's** SMTP `Message-ID` —
|
|
532
|
+
* the value `email.threadId` holds, never an intermediate parent's.
|
|
533
|
+
* An agent that holds an intermediate message id still gets the
|
|
534
|
+
* whole chain: the platform resolves it to its row and reads the
|
|
535
|
+
* chain from that row's own anchor.
|
|
536
|
+
*/
|
|
537
|
+
get(threadId: string, opts?: {
|
|
538
|
+
domainId?: string;
|
|
539
|
+
}): Promise<ThreadDetail>;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* The durable-wait namespace — see {@link Flowmails.waits}.
|
|
543
|
+
*/
|
|
544
|
+
interface AgentWaits {
|
|
545
|
+
/** Open a wait. Answers immediately; poll {@link AgentWaits.get}. */
|
|
546
|
+
create(opts: CreateWaitOptions): Promise<CreateWaitResult>;
|
|
547
|
+
/** Read a wait. A wait past its deadline reads as `expired`. */
|
|
548
|
+
get(waitId: string): Promise<WaitStatus>;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* The address namespace — see {@link Flowmails.addresses}.
|
|
552
|
+
*/
|
|
553
|
+
interface AgentAddresses {
|
|
554
|
+
/** `list_domains`: every domain on the key's account. */
|
|
555
|
+
listDomains(): Promise<AgentDomain[]>;
|
|
556
|
+
/** `list_addresses`: one domain's local parts and routing mode. */
|
|
557
|
+
list(domainId: string): Promise<{
|
|
558
|
+
domainId: string;
|
|
559
|
+
domain: string;
|
|
560
|
+
routingMode: "catchall" | "rules";
|
|
561
|
+
localParts: string[];
|
|
562
|
+
addresses: string[];
|
|
563
|
+
/** True when every local part already delivers (catch-all mode). */
|
|
564
|
+
acceptsAnyLocalPart: boolean;
|
|
565
|
+
}>;
|
|
566
|
+
/**
|
|
567
|
+
* `create_address`: add **one** local part.
|
|
568
|
+
*
|
|
569
|
+
* Idempotent — creating an address that already exists answers
|
|
570
|
+
* with `created: false` rather than an error. It never changes the
|
|
571
|
+
* routing mode, never removes a part and never clears the table:
|
|
572
|
+
* mode changes and route-table editing stay dashboard-only.
|
|
573
|
+
*/
|
|
574
|
+
create(domainId: string, localPart: string): Promise<CreateAddressResult>;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* A sent message's delivery state.
|
|
578
|
+
*
|
|
579
|
+
* `status` is the receive worker's lifecycle literal, so an agent can
|
|
580
|
+
* distinguish "the relay took it" from "the recipient's server
|
|
581
|
+
* accepted it" from "it bounced" — the v0.1 SDK collapsed all of them
|
|
582
|
+
* into `"queued"` and dropped the relay's `Message-ID` with them.
|
|
583
|
+
*/
|
|
584
|
+
interface SendStatus {
|
|
585
|
+
/** The worker's row id. */
|
|
586
|
+
id: string;
|
|
587
|
+
/**
|
|
588
|
+
* `sent` (the relay accepted it) or `failed` (the relay rejected it)
|
|
589
|
+
* — those are the two the receive worker writes for an outbound
|
|
590
|
+
* message today.
|
|
591
|
+
*
|
|
592
|
+
* The vocabulary also holds `delivered` / `bounced` / `complained` /
|
|
593
|
+
* `delayed`, and the backend maps them if they appear, but the
|
|
594
|
+
* worker has no DSN or bounce ingestion and never writes them. **A
|
|
595
|
+
* bounce is not observable today.**
|
|
596
|
+
*/
|
|
597
|
+
status: string;
|
|
598
|
+
/** The SMTP `Message-ID`; empty when the relay never accepted it. */
|
|
599
|
+
messageId: string;
|
|
600
|
+
/** The relay's error string when `status` is `failed`, else null. */
|
|
601
|
+
sendFeedback: string | null;
|
|
602
|
+
/** `CURRENT_TIMESTAMP` from the worker; opaque to the SDK. */
|
|
603
|
+
createdAt: string | null;
|
|
604
|
+
}
|
|
102
605
|
|
|
103
606
|
/**
|
|
104
607
|
* Public error hierarchy. Mirrors the SDK backend's JSON contract
|
|
@@ -134,9 +637,29 @@ declare class ValidationError extends FlowmailsError {
|
|
|
134
637
|
}
|
|
135
638
|
/**
|
|
136
639
|
* 408 / 429 — request was rate-limited or timed out. Retryable.
|
|
640
|
+
*
|
|
641
|
+
* A 429 from Flowmails is either a **quota refusal**
|
|
642
|
+
* (`rate_limit_exceeded`) or a request that is **already running**
|
|
643
|
+
* (`idempotency_key_in_progress`). The two need different handling,
|
|
644
|
+
* so the quota facts travel on the error:
|
|
645
|
+
*
|
|
646
|
+
* - `limit` — the limit that was hit.
|
|
647
|
+
* - `remaining` — how many sends are left in the window (`0` when the
|
|
648
|
+
* quota is exhausted).
|
|
649
|
+
* - `resetAt` — ISO-8601 instant the window rolls over.
|
|
137
650
|
*/
|
|
138
651
|
declare class RateLimitError extends FlowmailsError {
|
|
139
|
-
|
|
652
|
+
/** The limit that was hit, when the server named one. */
|
|
653
|
+
readonly limit?: number;
|
|
654
|
+
/** The sends left in the window, when the server named one. */
|
|
655
|
+
readonly remaining?: number;
|
|
656
|
+
/** ISO-8601 instant the window rolls over, when the server named one. */
|
|
657
|
+
readonly resetAt?: string;
|
|
658
|
+
constructor(code?: string, status?: number, facts?: {
|
|
659
|
+
limit?: number;
|
|
660
|
+
remaining?: number;
|
|
661
|
+
resetAt?: string;
|
|
662
|
+
});
|
|
140
663
|
}
|
|
141
664
|
/**
|
|
142
665
|
* 502 / 504 — the SDK backend couldn't reach the upstream
|
|
@@ -148,4 +671,4 @@ declare class UpstreamError extends FlowmailsError {
|
|
|
148
671
|
constructor(code: string, upstreamMessage: string | undefined, status?: number);
|
|
149
672
|
}
|
|
150
673
|
|
|
151
|
-
export { AuthenticationError, Flowmails, FlowmailsError, type FlowmailsOptions, RateLimitError, type SendAttachment, type SendOptions, type SendResult, UpstreamError, ValidationError };
|
|
674
|
+
export { type AccountInfo, type AgentAddress, type AgentAddresses, type AgentDomain, type AgentEvent, type AgentEvents, type AgentMessages, type AgentThreads, type AgentWaits, AuthenticationError, type CreateAddressResult, type CreateWaitOptions, type CreateWaitResult, Flowmails, FlowmailsError, type FlowmailsOptions, type ListEventsOptions, type ListEventsResult, type MessageDetail, RateLimitError, type SearchMessageHit, type SearchMessagesOptions, type SearchMessagesResult, type SendAttachment, type SendOptions, type SendResult, type SendStatus, type ThreadDetail, type ThreadMessage, UpstreamError, ValidationError, type WaitStatus };
|