@mailsai/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +127 -0
- package/dist/index.d.ts +686 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +674 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
export type ClientOptions = {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
fetch?: typeof fetch;
|
|
5
|
+
};
|
|
6
|
+
export type Tag = {
|
|
7
|
+
name: string;
|
|
8
|
+
value: string;
|
|
9
|
+
};
|
|
10
|
+
export type Attachment = {
|
|
11
|
+
filename: string;
|
|
12
|
+
content_base64: string;
|
|
13
|
+
content_type: string;
|
|
14
|
+
};
|
|
15
|
+
export type SendInput = {
|
|
16
|
+
to: string | string[];
|
|
17
|
+
cc?: string[];
|
|
18
|
+
bcc?: string[];
|
|
19
|
+
subject: string;
|
|
20
|
+
body?: string;
|
|
21
|
+
body_text?: string;
|
|
22
|
+
body_html?: string;
|
|
23
|
+
reply_to?: string;
|
|
24
|
+
in_reply_to_message_id?: string;
|
|
25
|
+
/** RFC Message-IDs to stitch this message into an existing thread (References header). */
|
|
26
|
+
references?: string[];
|
|
27
|
+
/** Up to 10 attachments, base64-encoded. */
|
|
28
|
+
attachments?: Attachment[];
|
|
29
|
+
metadata?: Record<string, string>;
|
|
30
|
+
pool_hint?: "clean" | "mixed";
|
|
31
|
+
scheduled_at?: string;
|
|
32
|
+
tags?: Tag[];
|
|
33
|
+
idempotency_key?: string;
|
|
34
|
+
};
|
|
35
|
+
export type SendResult = {
|
|
36
|
+
id: string;
|
|
37
|
+
agent_id: string;
|
|
38
|
+
thread_id?: string;
|
|
39
|
+
to: string[];
|
|
40
|
+
subject: string;
|
|
41
|
+
routing_pool: "clean" | "mixed" | "outbound";
|
|
42
|
+
classifier_score: number;
|
|
43
|
+
status: "queued" | "scheduled" | "sent";
|
|
44
|
+
cost_usd: number;
|
|
45
|
+
scheduled_at?: string;
|
|
46
|
+
tags?: Tag[];
|
|
47
|
+
created_at: string;
|
|
48
|
+
};
|
|
49
|
+
export type ReplyInput = {
|
|
50
|
+
body?: string;
|
|
51
|
+
body_text?: string;
|
|
52
|
+
body_html?: string;
|
|
53
|
+
reply_all?: boolean;
|
|
54
|
+
cc?: string[];
|
|
55
|
+
bcc?: string[];
|
|
56
|
+
tags?: Tag[];
|
|
57
|
+
scheduled_at?: string;
|
|
58
|
+
};
|
|
59
|
+
export type ForwardInput = {
|
|
60
|
+
to: string | string[];
|
|
61
|
+
cc?: string[];
|
|
62
|
+
bcc?: string[];
|
|
63
|
+
subject?: string;
|
|
64
|
+
body_text?: string;
|
|
65
|
+
body_html?: string;
|
|
66
|
+
};
|
|
67
|
+
export type ListResult<T> = {
|
|
68
|
+
data: T[];
|
|
69
|
+
has_more: boolean;
|
|
70
|
+
next_cursor?: string;
|
|
71
|
+
};
|
|
72
|
+
export type TypedEvent = {
|
|
73
|
+
id: string;
|
|
74
|
+
/**
|
|
75
|
+
* Event type. Inbound: `reply.received` (a genuine reply to one of your sends),
|
|
76
|
+
* `message.received` (an authenticated cold/first-contact inbound — NOT a reply),
|
|
77
|
+
* `message.received.unauthenticated` (SPF+DKIM both failed). Outbound lifecycle:
|
|
78
|
+
* `message.sent` / `message.delivered` / `message.bounced` / `message.complained` /
|
|
79
|
+
* `message.scheduled`. Plus `suppression.added`, `agent.paused`/`agent.resumed`,
|
|
80
|
+
* and `draft.*`. Use `agent.onReply` for replies and `agent.onMessage` for cold inbound.
|
|
81
|
+
*/
|
|
82
|
+
type: string;
|
|
83
|
+
workspace_id: string;
|
|
84
|
+
agent_id?: string;
|
|
85
|
+
source_message_id?: string;
|
|
86
|
+
intent?: string;
|
|
87
|
+
urgency?: number;
|
|
88
|
+
injection_score?: number;
|
|
89
|
+
sender_reputation?: number;
|
|
90
|
+
/** Routing pool the source message used. Returned by events.list/get. */
|
|
91
|
+
routing_pool?: "clean" | "mixed" | "outbound";
|
|
92
|
+
entities?: Record<string, unknown>;
|
|
93
|
+
/** Only present on SSE stream events for some types; on list/get read `data.thread_id`. */
|
|
94
|
+
thread_id?: string;
|
|
95
|
+
test_mode: boolean;
|
|
96
|
+
data: Record<string, unknown>;
|
|
97
|
+
created_at: string | null;
|
|
98
|
+
};
|
|
99
|
+
export type AgentRow = {
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
email: string;
|
|
103
|
+
domain: string;
|
|
104
|
+
workspace_id: string;
|
|
105
|
+
status: "active" | "paused" | "archived";
|
|
106
|
+
created_at: string | null;
|
|
107
|
+
};
|
|
108
|
+
export type ThreadRow = {
|
|
109
|
+
id: string;
|
|
110
|
+
agent_id: string;
|
|
111
|
+
subject?: string;
|
|
112
|
+
last_message_at?: string;
|
|
113
|
+
message_count: number;
|
|
114
|
+
participants: string[];
|
|
115
|
+
labels: string[];
|
|
116
|
+
status: "open" | "closed" | "archived";
|
|
117
|
+
created_at: string | null;
|
|
118
|
+
updated_at: string | null;
|
|
119
|
+
};
|
|
120
|
+
export type ThreadDetail = ThreadRow & {
|
|
121
|
+
messages: Array<{
|
|
122
|
+
id: string;
|
|
123
|
+
direction: "outbound";
|
|
124
|
+
to: string[];
|
|
125
|
+
subject: string;
|
|
126
|
+
snippet: string;
|
|
127
|
+
status: string;
|
|
128
|
+
sent_at?: string;
|
|
129
|
+
scheduled_at?: string;
|
|
130
|
+
created_at: string | null;
|
|
131
|
+
} | {
|
|
132
|
+
id: string;
|
|
133
|
+
direction: "inbound";
|
|
134
|
+
from: string;
|
|
135
|
+
to: string;
|
|
136
|
+
subject?: string;
|
|
137
|
+
extracted_text?: string;
|
|
138
|
+
snippet: string;
|
|
139
|
+
received_at: string;
|
|
140
|
+
created_at: string | null;
|
|
141
|
+
}>;
|
|
142
|
+
};
|
|
143
|
+
export type ReceivedMessage = {
|
|
144
|
+
id: string;
|
|
145
|
+
agent_id: string;
|
|
146
|
+
thread_id?: string;
|
|
147
|
+
from: {
|
|
148
|
+
address: string;
|
|
149
|
+
name?: string;
|
|
150
|
+
};
|
|
151
|
+
to: string;
|
|
152
|
+
subject?: string;
|
|
153
|
+
extracted_text?: string;
|
|
154
|
+
body_text_excerpt?: string;
|
|
155
|
+
spf_pass?: boolean;
|
|
156
|
+
dkim_pass?: boolean;
|
|
157
|
+
received_at: string;
|
|
158
|
+
};
|
|
159
|
+
export type DraftRow = {
|
|
160
|
+
id: string;
|
|
161
|
+
agent_id: string;
|
|
162
|
+
to: string[];
|
|
163
|
+
subject?: string;
|
|
164
|
+
body_text?: string;
|
|
165
|
+
body_html?: string;
|
|
166
|
+
status: "draft" | "scheduled" | "sending" | "sent" | "failed" | "canceled";
|
|
167
|
+
send_at?: string;
|
|
168
|
+
sent_message_id?: string;
|
|
169
|
+
error_message?: string;
|
|
170
|
+
tags?: Tag[];
|
|
171
|
+
created_at: string | null;
|
|
172
|
+
updated_at: string | null;
|
|
173
|
+
};
|
|
174
|
+
export type SuppressionLookup = {
|
|
175
|
+
suppressed: boolean;
|
|
176
|
+
type?: "hard_bounce" | "complaint" | "unsubscribe";
|
|
177
|
+
scope?: string;
|
|
178
|
+
since?: string;
|
|
179
|
+
allowed?: {
|
|
180
|
+
id: string;
|
|
181
|
+
attestation: string;
|
|
182
|
+
created_at: string;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
export type ApiKeyRow = {
|
|
186
|
+
id: string;
|
|
187
|
+
prefix: string;
|
|
188
|
+
name: string | null;
|
|
189
|
+
mode: "live" | "test";
|
|
190
|
+
scopes: string[];
|
|
191
|
+
agent_id: string | null;
|
|
192
|
+
last_used_at: string | null;
|
|
193
|
+
expires_at: string | null;
|
|
194
|
+
revoked_at: string | null;
|
|
195
|
+
created_at: string | null;
|
|
196
|
+
};
|
|
197
|
+
export type WebhookRow = {
|
|
198
|
+
id: string;
|
|
199
|
+
url: string;
|
|
200
|
+
event_types: string[];
|
|
201
|
+
description: string | null;
|
|
202
|
+
active: boolean;
|
|
203
|
+
created_at: string | null;
|
|
204
|
+
};
|
|
205
|
+
export type WebhookDelivery = {
|
|
206
|
+
id: string;
|
|
207
|
+
webhook_endpoint_id: string;
|
|
208
|
+
event_id: string;
|
|
209
|
+
attempt_number: number;
|
|
210
|
+
status: "pending" | "succeeded" | "failed" | "dlq";
|
|
211
|
+
http_status?: number;
|
|
212
|
+
response_body_excerpt?: string;
|
|
213
|
+
next_retry_at?: string;
|
|
214
|
+
delivered_at?: string;
|
|
215
|
+
created_at: string | null;
|
|
216
|
+
};
|
|
217
|
+
export type LogEntry = {
|
|
218
|
+
id: string;
|
|
219
|
+
category: string;
|
|
220
|
+
action: string;
|
|
221
|
+
target_resource_id?: string;
|
|
222
|
+
metadata?: Record<string, unknown>;
|
|
223
|
+
created_at: string | null;
|
|
224
|
+
};
|
|
225
|
+
export type MeResult = {
|
|
226
|
+
api_key: {
|
|
227
|
+
id: string;
|
|
228
|
+
prefix?: string;
|
|
229
|
+
name: string | null;
|
|
230
|
+
mode: "live" | "test";
|
|
231
|
+
scopes: string[];
|
|
232
|
+
agent_id: string | null;
|
|
233
|
+
last_used_at: string | null;
|
|
234
|
+
created_at: string | null;
|
|
235
|
+
};
|
|
236
|
+
workspace: {
|
|
237
|
+
id: string;
|
|
238
|
+
slug: string;
|
|
239
|
+
display_name: string;
|
|
240
|
+
tier: string;
|
|
241
|
+
tier_status: string;
|
|
242
|
+
} | null;
|
|
243
|
+
agent: {
|
|
244
|
+
id: string;
|
|
245
|
+
name: string;
|
|
246
|
+
email: string;
|
|
247
|
+
} | null;
|
|
248
|
+
};
|
|
249
|
+
export type UsageResult = {
|
|
250
|
+
workspace_id: string;
|
|
251
|
+
tier: string;
|
|
252
|
+
tier_status: string;
|
|
253
|
+
period_start: string;
|
|
254
|
+
period_end: string;
|
|
255
|
+
usage: {
|
|
256
|
+
sends: number;
|
|
257
|
+
parses: number;
|
|
258
|
+
webhook_deliveries: number;
|
|
259
|
+
sends_cost_usd: number;
|
|
260
|
+
parses_cost_usd: number;
|
|
261
|
+
};
|
|
262
|
+
caps: {
|
|
263
|
+
monthly_sends: number;
|
|
264
|
+
monthly_parses: number;
|
|
265
|
+
agents: number | "unlimited";
|
|
266
|
+
hourly: number;
|
|
267
|
+
daily: number;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
declare class MailsError extends Error {
|
|
271
|
+
type: string;
|
|
272
|
+
code: string;
|
|
273
|
+
status: number;
|
|
274
|
+
requestId?: string;
|
|
275
|
+
param?: string;
|
|
276
|
+
constructor(opts: {
|
|
277
|
+
type: string;
|
|
278
|
+
code: string;
|
|
279
|
+
message: string;
|
|
280
|
+
status: number;
|
|
281
|
+
requestId?: string;
|
|
282
|
+
param?: string;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
declare class MailsClient {
|
|
286
|
+
private apiKey;
|
|
287
|
+
private baseUrl;
|
|
288
|
+
private fetchImpl;
|
|
289
|
+
messages: MessagesResource;
|
|
290
|
+
received: ReceivedResource;
|
|
291
|
+
threads: ThreadsResource;
|
|
292
|
+
drafts: DraftsResource;
|
|
293
|
+
events: EventsResource;
|
|
294
|
+
agents: AgentsResource;
|
|
295
|
+
suppression: SuppressionResource;
|
|
296
|
+
api_keys: ApiKeysResource;
|
|
297
|
+
webhooks: WebhooksResource;
|
|
298
|
+
reputation: ReputationResource;
|
|
299
|
+
billing: BillingResource;
|
|
300
|
+
logs: LogsResource;
|
|
301
|
+
constructor(opts?: ClientOptions);
|
|
302
|
+
agent(name: string): Agent;
|
|
303
|
+
send(agent: string, input: SendInput): Promise<SendResult>;
|
|
304
|
+
createAgent(name: string, options?: {
|
|
305
|
+
domain?: string;
|
|
306
|
+
allowlist_domains?: string[];
|
|
307
|
+
}): Promise<AgentRow>;
|
|
308
|
+
listAgents(opts?: {
|
|
309
|
+
limit?: number;
|
|
310
|
+
cursor?: string;
|
|
311
|
+
}): Promise<ListResult<AgentRow>>;
|
|
312
|
+
me(): Promise<MeResult>;
|
|
313
|
+
request<T = unknown>(method: string, path: string, body?: unknown, headersIn?: Record<string, string>): Promise<T>;
|
|
314
|
+
private _request;
|
|
315
|
+
requestText(method: string, path: string, body?: unknown, headersIn?: Record<string, string>): Promise<string>;
|
|
316
|
+
stream(opts: {
|
|
317
|
+
since?: string;
|
|
318
|
+
event_types?: string[];
|
|
319
|
+
onEvent: (e: TypedEvent) => void;
|
|
320
|
+
onError?: (err: Error) => void;
|
|
321
|
+
signal?: AbortSignal;
|
|
322
|
+
}): AbortController;
|
|
323
|
+
}
|
|
324
|
+
declare class MessagesResource {
|
|
325
|
+
private c;
|
|
326
|
+
constructor(c: MailsClient);
|
|
327
|
+
send(agent: string, input: SendInput): Promise<SendResult>;
|
|
328
|
+
batch(messages: Array<Omit<SendInput, "idempotency_key"> & {
|
|
329
|
+
agent: string;
|
|
330
|
+
}>, opts?: {
|
|
331
|
+
idempotency_key?: string;
|
|
332
|
+
}): Promise<{
|
|
333
|
+
data: Array<SendResult | {
|
|
334
|
+
error: {
|
|
335
|
+
type: string;
|
|
336
|
+
code: string;
|
|
337
|
+
message: string;
|
|
338
|
+
};
|
|
339
|
+
}>;
|
|
340
|
+
batch_size: number;
|
|
341
|
+
}>;
|
|
342
|
+
reply(id: string, input: ReplyInput): Promise<SendResult & {
|
|
343
|
+
in_reply_to_message_id: string;
|
|
344
|
+
}>;
|
|
345
|
+
forward(id: string, input: ForwardInput): Promise<SendResult & {
|
|
346
|
+
forwarded_from: string;
|
|
347
|
+
}>;
|
|
348
|
+
cancel(id: string): Promise<{
|
|
349
|
+
id: string;
|
|
350
|
+
status: "canceled";
|
|
351
|
+
canceled_at: string;
|
|
352
|
+
}>;
|
|
353
|
+
reschedule(id: string, scheduled_at: string): Promise<{
|
|
354
|
+
id: string;
|
|
355
|
+
scheduled_at: string;
|
|
356
|
+
status: "scheduled";
|
|
357
|
+
}>;
|
|
358
|
+
raw(id: string): Promise<string>;
|
|
359
|
+
list(opts?: {
|
|
360
|
+
limit?: number;
|
|
361
|
+
cursor?: string;
|
|
362
|
+
agent_id?: string;
|
|
363
|
+
thread_id?: string;
|
|
364
|
+
}): Promise<ListResult<SendResult>>;
|
|
365
|
+
get(id: string): Promise<SendResult>;
|
|
366
|
+
}
|
|
367
|
+
declare class ReceivedResource {
|
|
368
|
+
private c;
|
|
369
|
+
constructor(c: MailsClient);
|
|
370
|
+
list(opts?: {
|
|
371
|
+
limit?: number;
|
|
372
|
+
cursor?: string;
|
|
373
|
+
agent_id?: string;
|
|
374
|
+
thread_id?: string;
|
|
375
|
+
}): Promise<ListResult<ReceivedMessage>>;
|
|
376
|
+
get(id: string): Promise<ReceivedMessage & {
|
|
377
|
+
raw_url: string;
|
|
378
|
+
}>;
|
|
379
|
+
}
|
|
380
|
+
declare class ThreadsResource {
|
|
381
|
+
private c;
|
|
382
|
+
constructor(c: MailsClient);
|
|
383
|
+
list(opts?: {
|
|
384
|
+
limit?: number;
|
|
385
|
+
cursor?: string;
|
|
386
|
+
agent_id?: string;
|
|
387
|
+
status?: "open" | "closed" | "archived";
|
|
388
|
+
}): Promise<ListResult<ThreadRow>>;
|
|
389
|
+
get(id: string): Promise<ThreadDetail>;
|
|
390
|
+
update(id: string, patch: {
|
|
391
|
+
labels?: string[];
|
|
392
|
+
status?: "open" | "closed" | "archived";
|
|
393
|
+
}): Promise<ThreadRow>;
|
|
394
|
+
}
|
|
395
|
+
declare class DraftsResource {
|
|
396
|
+
private c;
|
|
397
|
+
constructor(c: MailsClient);
|
|
398
|
+
create(input: {
|
|
399
|
+
agent: string;
|
|
400
|
+
to: string | string[];
|
|
401
|
+
cc?: string[];
|
|
402
|
+
bcc?: string[];
|
|
403
|
+
subject?: string;
|
|
404
|
+
body_text?: string;
|
|
405
|
+
body_html?: string;
|
|
406
|
+
reply_to?: string;
|
|
407
|
+
in_reply_to_message_id?: string;
|
|
408
|
+
send_at?: string;
|
|
409
|
+
tags?: Tag[];
|
|
410
|
+
}): Promise<DraftRow>;
|
|
411
|
+
list(opts?: {
|
|
412
|
+
limit?: number;
|
|
413
|
+
cursor?: string;
|
|
414
|
+
status?: string;
|
|
415
|
+
}): Promise<ListResult<DraftRow>>;
|
|
416
|
+
get(id: string): Promise<DraftRow>;
|
|
417
|
+
update(id: string, patch: Record<string, unknown>): Promise<DraftRow>;
|
|
418
|
+
remove(id: string): Promise<{
|
|
419
|
+
id: string;
|
|
420
|
+
deleted_at: string;
|
|
421
|
+
}>;
|
|
422
|
+
send(id: string, opts?: {
|
|
423
|
+
send_at?: string;
|
|
424
|
+
}): Promise<{
|
|
425
|
+
id: string;
|
|
426
|
+
status: string;
|
|
427
|
+
message_id?: string;
|
|
428
|
+
thread_id?: string;
|
|
429
|
+
sent_at?: string;
|
|
430
|
+
send_at?: string;
|
|
431
|
+
}>;
|
|
432
|
+
}
|
|
433
|
+
declare class EventsResource {
|
|
434
|
+
private c;
|
|
435
|
+
constructor(c: MailsClient);
|
|
436
|
+
list(opts?: {
|
|
437
|
+
limit?: number;
|
|
438
|
+
cursor?: string;
|
|
439
|
+
event_type?: string;
|
|
440
|
+
agent_id?: string;
|
|
441
|
+
since?: string;
|
|
442
|
+
}): Promise<ListResult<TypedEvent>>;
|
|
443
|
+
get(id: string): Promise<TypedEvent>;
|
|
444
|
+
redeliver(id: string): Promise<{
|
|
445
|
+
event_id: string;
|
|
446
|
+
webhook_endpoint_ids: string[];
|
|
447
|
+
scheduled_at: string;
|
|
448
|
+
}>;
|
|
449
|
+
stream(opts: {
|
|
450
|
+
since?: string;
|
|
451
|
+
event_types?: string[];
|
|
452
|
+
onEvent: (e: TypedEvent) => void;
|
|
453
|
+
onError?: (err: Error) => void;
|
|
454
|
+
}): AbortController;
|
|
455
|
+
}
|
|
456
|
+
declare class AgentsResource {
|
|
457
|
+
private c;
|
|
458
|
+
constructor(c: MailsClient);
|
|
459
|
+
create(name: string, opts?: {
|
|
460
|
+
domain?: string;
|
|
461
|
+
allowlist_domains?: string[];
|
|
462
|
+
blocklist_domains?: string[];
|
|
463
|
+
/**
|
|
464
|
+
* Run the costed LLM intent/entity extractor on this agent's inbound. The
|
|
465
|
+
* prompt-injection scan ALWAYS runs regardless; this only gates the extra
|
|
466
|
+
* classification pass (the metered "classify (opt-in)"). Default false.
|
|
467
|
+
*/
|
|
468
|
+
classify_inbound?: boolean;
|
|
469
|
+
}): Promise<AgentRow>;
|
|
470
|
+
list(opts?: {
|
|
471
|
+
limit?: number;
|
|
472
|
+
cursor?: string;
|
|
473
|
+
}): Promise<ListResult<AgentRow>>;
|
|
474
|
+
get(id: string): Promise<AgentRow>;
|
|
475
|
+
update(id: string, patch: {
|
|
476
|
+
status?: "active" | "paused";
|
|
477
|
+
daily_send_limit?: number | null;
|
|
478
|
+
hourly_send_limit?: number | null;
|
|
479
|
+
allowlist_domains?: string[];
|
|
480
|
+
blocklist_domains?: string[];
|
|
481
|
+
classify_inbound?: boolean;
|
|
482
|
+
}): Promise<AgentRow>;
|
|
483
|
+
archive(id: string): Promise<{
|
|
484
|
+
id: string;
|
|
485
|
+
status: string;
|
|
486
|
+
archived_at: string;
|
|
487
|
+
}>;
|
|
488
|
+
}
|
|
489
|
+
declare class SuppressionResource {
|
|
490
|
+
private c;
|
|
491
|
+
constructor(c: MailsClient);
|
|
492
|
+
check(address: string): Promise<SuppressionLookup>;
|
|
493
|
+
list(opts?: {
|
|
494
|
+
limit?: number;
|
|
495
|
+
cursor?: string;
|
|
496
|
+
}): Promise<ListResult<{
|
|
497
|
+
id: string;
|
|
498
|
+
address: string;
|
|
499
|
+
attestation: string;
|
|
500
|
+
created_at: string;
|
|
501
|
+
}>>;
|
|
502
|
+
allow(address: string, attestation: string): Promise<{
|
|
503
|
+
id: string;
|
|
504
|
+
address: string;
|
|
505
|
+
attestation: string;
|
|
506
|
+
created_at: string;
|
|
507
|
+
}>;
|
|
508
|
+
revoke(id: string): Promise<{
|
|
509
|
+
id: string;
|
|
510
|
+
revoked_at: string;
|
|
511
|
+
}>;
|
|
512
|
+
}
|
|
513
|
+
declare class ApiKeysResource {
|
|
514
|
+
private c;
|
|
515
|
+
constructor(c: MailsClient);
|
|
516
|
+
create(input: {
|
|
517
|
+
name?: string;
|
|
518
|
+
agent_id?: string;
|
|
519
|
+
scopes?: ("send" | "read" | "manage")[];
|
|
520
|
+
mode?: "live" | "test";
|
|
521
|
+
expires_at?: string;
|
|
522
|
+
}): Promise<ApiKeyRow & {
|
|
523
|
+
key: string;
|
|
524
|
+
}>;
|
|
525
|
+
list(opts?: {
|
|
526
|
+
limit?: number;
|
|
527
|
+
cursor?: string;
|
|
528
|
+
}): Promise<ListResult<ApiKeyRow>>;
|
|
529
|
+
revoke(id: string): Promise<{
|
|
530
|
+
id: string;
|
|
531
|
+
revoked_at: string;
|
|
532
|
+
}>;
|
|
533
|
+
}
|
|
534
|
+
declare class WebhooksResource {
|
|
535
|
+
private c;
|
|
536
|
+
constructor(c: MailsClient);
|
|
537
|
+
create(input: {
|
|
538
|
+
url: string;
|
|
539
|
+
event_types?: string[];
|
|
540
|
+
description?: string;
|
|
541
|
+
}): Promise<WebhookRow & {
|
|
542
|
+
signing_secret: string;
|
|
543
|
+
}>;
|
|
544
|
+
list(opts?: {
|
|
545
|
+
limit?: number;
|
|
546
|
+
cursor?: string;
|
|
547
|
+
}): Promise<ListResult<WebhookRow>>;
|
|
548
|
+
update(id: string, patch: {
|
|
549
|
+
url?: string;
|
|
550
|
+
event_types?: string[];
|
|
551
|
+
description?: string;
|
|
552
|
+
active?: boolean;
|
|
553
|
+
}): Promise<WebhookRow>;
|
|
554
|
+
/** Send a signed test event to the endpoint to verify reachability + signature handling. */
|
|
555
|
+
test(id: string): Promise<{
|
|
556
|
+
ok: boolean;
|
|
557
|
+
http_status?: number;
|
|
558
|
+
error?: string;
|
|
559
|
+
}>;
|
|
560
|
+
remove(id: string): Promise<{
|
|
561
|
+
id: string;
|
|
562
|
+
deleted_at: string;
|
|
563
|
+
}>;
|
|
564
|
+
deliveries(webhookId: string, opts?: {
|
|
565
|
+
limit?: number;
|
|
566
|
+
cursor?: string;
|
|
567
|
+
}): Promise<ListResult<WebhookDelivery>>;
|
|
568
|
+
replayDelivery(deliveryId: string): Promise<{
|
|
569
|
+
delivery_id: string;
|
|
570
|
+
event_id: string;
|
|
571
|
+
scheduled: string[];
|
|
572
|
+
scheduled_at: string;
|
|
573
|
+
}>;
|
|
574
|
+
verify(body: string, signature: string, secret: string, toleranceSec?: number): TypedEvent | null;
|
|
575
|
+
}
|
|
576
|
+
declare class ReputationResource {
|
|
577
|
+
private c;
|
|
578
|
+
constructor(c: MailsClient);
|
|
579
|
+
get(agentId?: string): Promise<{
|
|
580
|
+
agent_id?: string;
|
|
581
|
+
workspace_id?: string;
|
|
582
|
+
reputation: number;
|
|
583
|
+
send_count_30d?: number;
|
|
584
|
+
bounce_count_30d?: number;
|
|
585
|
+
complaint_count_30d?: number;
|
|
586
|
+
reply_count_30d?: number;
|
|
587
|
+
}>;
|
|
588
|
+
}
|
|
589
|
+
declare class BillingResource {
|
|
590
|
+
private c;
|
|
591
|
+
constructor(c: MailsClient);
|
|
592
|
+
portal(returnUrl?: string): Promise<{
|
|
593
|
+
url: string;
|
|
594
|
+
mock: boolean;
|
|
595
|
+
}>;
|
|
596
|
+
usage(): Promise<UsageResult>;
|
|
597
|
+
}
|
|
598
|
+
declare class LogsResource {
|
|
599
|
+
private c;
|
|
600
|
+
constructor(c: MailsClient);
|
|
601
|
+
list(opts?: {
|
|
602
|
+
limit?: number;
|
|
603
|
+
cursor?: string;
|
|
604
|
+
category?: string;
|
|
605
|
+
action?: string;
|
|
606
|
+
}): Promise<ListResult<LogEntry>>;
|
|
607
|
+
}
|
|
608
|
+
declare class Agent {
|
|
609
|
+
private client;
|
|
610
|
+
private name;
|
|
611
|
+
private _id?;
|
|
612
|
+
constructor(client: MailsClient, name: string);
|
|
613
|
+
send(input: SendInput): Promise<SendResult>;
|
|
614
|
+
listReplies(opts?: {
|
|
615
|
+
limit?: number;
|
|
616
|
+
since?: string;
|
|
617
|
+
}): Promise<ListResult<TypedEvent>>;
|
|
618
|
+
/**
|
|
619
|
+
* List cold/first-contact inbound (`message.received`) for this agent — messages
|
|
620
|
+
* from senders that are NOT replies to one of your sends (new leads, support
|
|
621
|
+
* requests, strangers). Authenticated only; SPF+DKIM failures surface separately
|
|
622
|
+
* as `message.received.unauthenticated`. Mirrors {@link listReplies}.
|
|
623
|
+
*/
|
|
624
|
+
listMessages(opts?: {
|
|
625
|
+
limit?: number;
|
|
626
|
+
since?: string;
|
|
627
|
+
}): Promise<ListResult<TypedEvent>>;
|
|
628
|
+
reputation(): Promise<{
|
|
629
|
+
agent_id?: string;
|
|
630
|
+
workspace_id?: string;
|
|
631
|
+
reputation: number;
|
|
632
|
+
send_count_30d?: number;
|
|
633
|
+
bounce_count_30d?: number;
|
|
634
|
+
complaint_count_30d?: number;
|
|
635
|
+
reply_count_30d?: number;
|
|
636
|
+
}>;
|
|
637
|
+
/**
|
|
638
|
+
* Subscribe to reply.received events for this agent. Opens an SSE stream
|
|
639
|
+
* filtered server-side to reply.received and dispatches to `callback` for
|
|
640
|
+
* events matching this agent. Resolves the agent name → id once on first
|
|
641
|
+
* matching event so subsequent events skip the lookup.
|
|
642
|
+
*
|
|
643
|
+
* @returns AbortController — call `.abort()` to stop listening. Caller can
|
|
644
|
+
* also pass `opts.signal` to chain into an existing abort flow.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* const ctrl = agent.onReply((event) => {
|
|
648
|
+
* console.log(event.intent, event.entities);
|
|
649
|
+
* });
|
|
650
|
+
* // …later
|
|
651
|
+
* ctrl.abort();
|
|
652
|
+
*/
|
|
653
|
+
onReply(callback: (event: TypedEvent) => void | Promise<void>, opts?: {
|
|
654
|
+
onError?: (err: Error) => void;
|
|
655
|
+
since?: string;
|
|
656
|
+
signal?: AbortSignal;
|
|
657
|
+
}): AbortController;
|
|
658
|
+
/**
|
|
659
|
+
* Subscribe to cold/first-contact inbound (`message.received`) for this agent —
|
|
660
|
+
* new senders that are NOT replying to one of your sends. Same shape and
|
|
661
|
+
* agent-scoping as {@link onReply}; returns an AbortController.
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* const ctrl = agent.onMessage((event) => {
|
|
665
|
+
* if (event.intent === "sales_inquiry") routeToCrm(event);
|
|
666
|
+
* });
|
|
667
|
+
*/
|
|
668
|
+
onMessage(callback: (event: TypedEvent) => void | Promise<void>, opts?: {
|
|
669
|
+
onError?: (err: Error) => void;
|
|
670
|
+
since?: string;
|
|
671
|
+
signal?: AbortSignal;
|
|
672
|
+
}): AbortController;
|
|
673
|
+
/** Shared agent-scoped SSE subscription used by onReply/onMessage. */
|
|
674
|
+
private subscribe;
|
|
675
|
+
private resolveId;
|
|
676
|
+
}
|
|
677
|
+
export declare function createClient(opts?: ClientOptions): MailsClient;
|
|
678
|
+
export declare const mails: {
|
|
679
|
+
agent(name: string, opts?: ClientOptions): Agent;
|
|
680
|
+
send(agent: string, input: SendInput, opts?: ClientOptions): Promise<SendResult>;
|
|
681
|
+
webhooks: {
|
|
682
|
+
verify(body: string, signature: string, secret: string, toleranceSec?: number): TypedEvent | null;
|
|
683
|
+
};
|
|
684
|
+
};
|
|
685
|
+
export { MailsClient, Agent, MailsError };
|
|
686
|
+
//# sourceMappingURL=index.d.ts.map
|