mailtea-sdk 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -0
- package/dist/index.d.ts +960 -0
- package/dist/index.js +671 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,960 @@
|
|
|
1
|
+
/** A stored-template reference, used in place of inline `html`/`text`. */
|
|
2
|
+
interface TemplateRef {
|
|
3
|
+
id: string;
|
|
4
|
+
variables?: Record<string, string | number>;
|
|
5
|
+
}
|
|
6
|
+
/** Input for `emails.send`. Provide inline content (`html`/`text`) OR a `template`. */
|
|
7
|
+
interface SendEmailInput {
|
|
8
|
+
from: string;
|
|
9
|
+
to: string | string[];
|
|
10
|
+
subject: string;
|
|
11
|
+
html?: string;
|
|
12
|
+
text?: string;
|
|
13
|
+
template?: TemplateRef;
|
|
14
|
+
cc?: string | string[];
|
|
15
|
+
bcc?: string | string[];
|
|
16
|
+
reply_to?: string | string[];
|
|
17
|
+
/** ISO 8601 datetime to schedule the send. */
|
|
18
|
+
scheduled_at?: string;
|
|
19
|
+
tags?: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
value: string;
|
|
22
|
+
}>;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
attachments?: Array<{
|
|
25
|
+
filename: string;
|
|
26
|
+
/** Base64-encoded file content. */
|
|
27
|
+
content: string;
|
|
28
|
+
content_type?: string;
|
|
29
|
+
content_id?: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
/** One item in an `emails.batch` call — like `SendEmailInput` minus attachments/scheduling. */
|
|
33
|
+
type BatchEmailItemInput = Omit<SendEmailInput, "attachments" | "scheduled_at">;
|
|
34
|
+
/** Input for `emails.batch` (1–100 items). */
|
|
35
|
+
type BatchEmailInput = BatchEmailItemInput[];
|
|
36
|
+
/** Input for `emails.update` — currently only a reschedule. */
|
|
37
|
+
interface UpdateEmailInput {
|
|
38
|
+
scheduled_at: string;
|
|
39
|
+
}
|
|
40
|
+
interface SendEmailResponse {
|
|
41
|
+
id: string;
|
|
42
|
+
}
|
|
43
|
+
interface BatchEmailResponse {
|
|
44
|
+
data: {
|
|
45
|
+
id: string;
|
|
46
|
+
}[];
|
|
47
|
+
}
|
|
48
|
+
interface UpdateEmailResponse {
|
|
49
|
+
object: "email";
|
|
50
|
+
id: string;
|
|
51
|
+
}
|
|
52
|
+
interface CancelEmailResponse {
|
|
53
|
+
object: "email";
|
|
54
|
+
id: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Email lifecycle status. Mirrors the API's `last_event`. The open string union
|
|
58
|
+
* keeps autocomplete for known values while tolerating new ones.
|
|
59
|
+
*/
|
|
60
|
+
type EmailStatus = "queued" | "scheduled" | "sent" | "delivered" | "delivery_delayed" | "bounced" | "complained" | "failed" | "suppressed" | "canceled" | (string & {});
|
|
61
|
+
interface EmailTag {
|
|
62
|
+
name: string;
|
|
63
|
+
value: string;
|
|
64
|
+
}
|
|
65
|
+
interface EmailAttachmentMeta {
|
|
66
|
+
filename: string;
|
|
67
|
+
content_type: string;
|
|
68
|
+
size: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Shape returned by `emails.get(id)`. Date fields are ISO 8601 strings on the
|
|
72
|
+
* wire. `status` is a friendly alias the SDK derives from `last_event`.
|
|
73
|
+
*/
|
|
74
|
+
interface RetrievedEmail {
|
|
75
|
+
object: "email";
|
|
76
|
+
id: string;
|
|
77
|
+
from: string | null;
|
|
78
|
+
to: string | null;
|
|
79
|
+
cc: string | null;
|
|
80
|
+
bcc: string | null;
|
|
81
|
+
reply_to: string | null;
|
|
82
|
+
subject: string;
|
|
83
|
+
html: string | null;
|
|
84
|
+
text: string | null;
|
|
85
|
+
created_at: string | null;
|
|
86
|
+
scheduled_at: string | null;
|
|
87
|
+
/** Most recent delivery event (the raw API wire field). */
|
|
88
|
+
last_event: EmailStatus | null;
|
|
89
|
+
/** Friendly alias of `last_event`. */
|
|
90
|
+
status: EmailStatus | null;
|
|
91
|
+
delayed_at: string | null;
|
|
92
|
+
opened_at: string | null;
|
|
93
|
+
open_count: number;
|
|
94
|
+
clicked_at: string | null;
|
|
95
|
+
click_count: number;
|
|
96
|
+
tags: EmailTag[] | null;
|
|
97
|
+
headers: Record<string, string> | null;
|
|
98
|
+
attachments: EmailAttachmentMeta[];
|
|
99
|
+
}
|
|
100
|
+
/** A lightweight email row returned by `emails.list` (no body/attachments). */
|
|
101
|
+
interface EmailListItem {
|
|
102
|
+
object: "email";
|
|
103
|
+
id: string;
|
|
104
|
+
from: string | null;
|
|
105
|
+
to: string | null;
|
|
106
|
+
subject: string;
|
|
107
|
+
created_at: string | null;
|
|
108
|
+
scheduled_at: string | null;
|
|
109
|
+
last_event: EmailStatus | null;
|
|
110
|
+
open_count: number;
|
|
111
|
+
click_count: number;
|
|
112
|
+
tags: EmailTag[] | null;
|
|
113
|
+
}
|
|
114
|
+
/** Filters + offset pagination for `emails.list`. */
|
|
115
|
+
interface ListEmailsParams {
|
|
116
|
+
status?: EmailStatus;
|
|
117
|
+
tag_name?: string;
|
|
118
|
+
tag_value?: string;
|
|
119
|
+
/** ISO 8601 lower bound on `created_at`. */
|
|
120
|
+
from_date?: string;
|
|
121
|
+
/** ISO 8601 upper bound on `created_at`. */
|
|
122
|
+
to_date?: string;
|
|
123
|
+
/** Max results, 1–100 (default 50). */
|
|
124
|
+
limit?: number;
|
|
125
|
+
offset?: number;
|
|
126
|
+
}
|
|
127
|
+
/** Offset-paginated list returned by `emails.list`. */
|
|
128
|
+
interface EmailListResponse {
|
|
129
|
+
object: "list";
|
|
130
|
+
data: EmailListItem[];
|
|
131
|
+
total: number;
|
|
132
|
+
limit: number;
|
|
133
|
+
offset: number;
|
|
134
|
+
has_more: boolean;
|
|
135
|
+
}
|
|
136
|
+
/** Optional date window for `emails.analytics`. */
|
|
137
|
+
interface EmailAnalyticsParams {
|
|
138
|
+
/** ISO 8601 lower bound on `created_at`. */
|
|
139
|
+
from_date?: string;
|
|
140
|
+
/** ISO 8601 upper bound on `created_at`. */
|
|
141
|
+
to_date?: string;
|
|
142
|
+
}
|
|
143
|
+
/** Aggregate transactional metrics returned by `emails.analytics`. */
|
|
144
|
+
interface EmailAnalytics {
|
|
145
|
+
object: "analytics";
|
|
146
|
+
from_date: string | null;
|
|
147
|
+
to_date: string | null;
|
|
148
|
+
/** Emails created in the window. */
|
|
149
|
+
total: number;
|
|
150
|
+
/** Emails dispatched to the provider (total minus queued/scheduled/canceled); the rate denominator. */
|
|
151
|
+
sent: number;
|
|
152
|
+
delivered: number;
|
|
153
|
+
bounced: number;
|
|
154
|
+
/** Distinct emails with at least one open / click. */
|
|
155
|
+
opened: number;
|
|
156
|
+
clicked: number;
|
|
157
|
+
/** Sum of open / click events. */
|
|
158
|
+
total_opens: number;
|
|
159
|
+
total_clicks: number;
|
|
160
|
+
status_counts: Record<string, number>;
|
|
161
|
+
rates: {
|
|
162
|
+
/** delivered / sent */
|
|
163
|
+
delivery_rate: number;
|
|
164
|
+
/** bounced / sent */
|
|
165
|
+
bounce_rate: number;
|
|
166
|
+
/** opened / sent */
|
|
167
|
+
open_rate: number;
|
|
168
|
+
/** clicked / sent */
|
|
169
|
+
click_rate: number;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
type RequestFn = <T>(method: string, path: string, body?: unknown) => Promise<T>;
|
|
174
|
+
/** Standard list-response envelope used by the audience endpoints. */
|
|
175
|
+
interface ListResponse<T> {
|
|
176
|
+
object: "list";
|
|
177
|
+
data: T[];
|
|
178
|
+
has_more: boolean;
|
|
179
|
+
next_cursor?: string;
|
|
180
|
+
}
|
|
181
|
+
/** Standard delete-response envelope. */
|
|
182
|
+
interface DeletedResponse {
|
|
183
|
+
object: string;
|
|
184
|
+
id: string;
|
|
185
|
+
deleted: true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A lightweight inbound-email row returned by `emails.inbound.list` (no body/attachments). */
|
|
189
|
+
interface InboundEmailListItem {
|
|
190
|
+
/** Inbound email id (`rxemail_…`). */
|
|
191
|
+
id: string;
|
|
192
|
+
from: string;
|
|
193
|
+
to: string[];
|
|
194
|
+
cc: string[];
|
|
195
|
+
bcc: string[];
|
|
196
|
+
reply_to: string[];
|
|
197
|
+
subject: string;
|
|
198
|
+
message_id: string | null;
|
|
199
|
+
created_at: string;
|
|
200
|
+
}
|
|
201
|
+
/** Attachment metadata embedded in {@link RetrievedInboundEmail} (no download URL). */
|
|
202
|
+
interface InboundAttachmentMeta {
|
|
203
|
+
/** Attachment id (`rxatt_…`). */
|
|
204
|
+
id: string;
|
|
205
|
+
filename: string;
|
|
206
|
+
content_type: string;
|
|
207
|
+
content_disposition: string | null;
|
|
208
|
+
content_id: string | null;
|
|
209
|
+
size: number;
|
|
210
|
+
}
|
|
211
|
+
/** Shape returned by `emails.inbound.get(id)`. Date fields are ISO 8601 strings on the wire. */
|
|
212
|
+
interface RetrievedInboundEmail {
|
|
213
|
+
object: "email";
|
|
214
|
+
/** Inbound email id (`rxemail_…`). */
|
|
215
|
+
id: string;
|
|
216
|
+
from: string;
|
|
217
|
+
to: string[];
|
|
218
|
+
cc: string[];
|
|
219
|
+
bcc: string[];
|
|
220
|
+
reply_to: string[];
|
|
221
|
+
subject: string;
|
|
222
|
+
message_id: string | null;
|
|
223
|
+
in_reply_to: string | null;
|
|
224
|
+
references: string[];
|
|
225
|
+
html: string | null;
|
|
226
|
+
text: string | null;
|
|
227
|
+
headers: Record<string, string> | null;
|
|
228
|
+
created_at: string;
|
|
229
|
+
/** Short-lived signed URL to download the raw RFC 822 message. */
|
|
230
|
+
raw: {
|
|
231
|
+
download_url: string;
|
|
232
|
+
expires_at: string;
|
|
233
|
+
};
|
|
234
|
+
attachments: InboundAttachmentMeta[];
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* A downloadable inbound attachment, returned by `emails.inbound.attachments`.
|
|
238
|
+
* `object` is present on `get` and omitted from `list` rows.
|
|
239
|
+
*/
|
|
240
|
+
interface InboundAttachment {
|
|
241
|
+
object?: "attachment";
|
|
242
|
+
/** Attachment id (`rxatt_…`). */
|
|
243
|
+
id: string;
|
|
244
|
+
filename: string;
|
|
245
|
+
content_type: string;
|
|
246
|
+
content_disposition: string | null;
|
|
247
|
+
content_id: string | null;
|
|
248
|
+
size: number;
|
|
249
|
+
/** Short-lived signed URL to download the file; expires at `expires_at`. */
|
|
250
|
+
download_url: string;
|
|
251
|
+
expires_at: string;
|
|
252
|
+
}
|
|
253
|
+
/** Cursor pagination for `emails.inbound.list`. */
|
|
254
|
+
interface ListInboundEmailsParams {
|
|
255
|
+
publication_id: string;
|
|
256
|
+
/** Max results, 1–100 (default 20). */
|
|
257
|
+
limit?: number;
|
|
258
|
+
cursor?: string;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Input for `emails.inbound.reply`. Provide at least one of `html`/`text`.
|
|
262
|
+
*
|
|
263
|
+
* Threading (In-Reply-To / References), the reply target (To), and the `Re: `
|
|
264
|
+
* subject default are all derived by the server from the original inbound email
|
|
265
|
+
* — they are never accepted from the caller. Omit `from` to send from the
|
|
266
|
+
* verified email-purpose domain the mail was delivered to.
|
|
267
|
+
*/
|
|
268
|
+
interface InboundReplyInput {
|
|
269
|
+
from?: {
|
|
270
|
+
email: string;
|
|
271
|
+
name?: string;
|
|
272
|
+
};
|
|
273
|
+
subject?: string;
|
|
274
|
+
html?: string;
|
|
275
|
+
text?: string;
|
|
276
|
+
cc?: string[];
|
|
277
|
+
bcc?: string[];
|
|
278
|
+
idempotency_key?: string;
|
|
279
|
+
}
|
|
280
|
+
/** Response from `emails.inbound.reply`: the resulting transactional email (`txemail_…`). */
|
|
281
|
+
interface InboundReplyResponse {
|
|
282
|
+
/** Transactional email id (`txemail_…`). */
|
|
283
|
+
id: string;
|
|
284
|
+
status: string;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Attachments on a received email. Access via `mailtea.emails.inbound.attachments`.
|
|
288
|
+
* Each returned object carries a short-lived signed `download_url`.
|
|
289
|
+
*/
|
|
290
|
+
declare class InboundAttachments {
|
|
291
|
+
private readonly request;
|
|
292
|
+
constructor(request: RequestFn);
|
|
293
|
+
/** List an inbound email's attachments, each with a signed download URL. */
|
|
294
|
+
list(id: string): Promise<ListResponse<InboundAttachment>>;
|
|
295
|
+
/** Retrieve a single inbound attachment with a signed download URL. */
|
|
296
|
+
get(id: string, attachmentId: string): Promise<InboundAttachment>;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Inbound (received) emails. Access via `mailtea.emails.inbound`. List and
|
|
300
|
+
* retrieve mail delivered to your receiving domains, download attachments, and
|
|
301
|
+
* `reply()` — which threads correctly by construction and reuses the
|
|
302
|
+
* transactional send pipeline.
|
|
303
|
+
*/
|
|
304
|
+
declare class InboundEmails {
|
|
305
|
+
private readonly request;
|
|
306
|
+
/** Attachments on a received email. */
|
|
307
|
+
readonly attachments: InboundAttachments;
|
|
308
|
+
constructor(request: RequestFn);
|
|
309
|
+
/** List received emails in a publication (most recent first), cursor-paginated. */
|
|
310
|
+
list(params: ListInboundEmailsParams): Promise<ListResponse<InboundEmailListItem>>;
|
|
311
|
+
/** Retrieve a single received email, including its body, headers, and attachments. */
|
|
312
|
+
get(id: string): Promise<RetrievedInboundEmail>;
|
|
313
|
+
/**
|
|
314
|
+
* Reply to a received email. The reply target, threading headers, and the
|
|
315
|
+
* `Re: ` subject default are all server-derived — pass only the content.
|
|
316
|
+
*
|
|
317
|
+
* @returns the resulting transactional email's `id` and `status` (HTTP 202).
|
|
318
|
+
*/
|
|
319
|
+
reply(id: string, input: InboundReplyInput): Promise<InboundReplyResponse>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The `emails` resource. Access via `mailtea.emails`.
|
|
324
|
+
*/
|
|
325
|
+
declare class Emails {
|
|
326
|
+
private readonly request;
|
|
327
|
+
/** Inbound (received) emails: list, get, reply, and attachments. */
|
|
328
|
+
readonly inbound: InboundEmails;
|
|
329
|
+
constructor(request: RequestFn);
|
|
330
|
+
/**
|
|
331
|
+
* Send a transactional email.
|
|
332
|
+
*
|
|
333
|
+
* Provide either inline content (`html` and/or `text`) **or** a `template`
|
|
334
|
+
* reference — not both. `to`, `cc`, `bcc`, and `reply_to` each accept a single
|
|
335
|
+
* address or an array.
|
|
336
|
+
*
|
|
337
|
+
* @returns the new email's `id`.
|
|
338
|
+
*/
|
|
339
|
+
send(payload: SendEmailInput): Promise<SendEmailResponse>;
|
|
340
|
+
/**
|
|
341
|
+
* Send up to 100 emails in a single request. Batch items do not support
|
|
342
|
+
* `attachments` or `scheduled_at`.
|
|
343
|
+
*
|
|
344
|
+
* @returns `{ data: [{ id }, ...] }` in request order.
|
|
345
|
+
*/
|
|
346
|
+
batch(payload: BatchEmailInput): Promise<BatchEmailResponse>;
|
|
347
|
+
/**
|
|
348
|
+
* List transactional emails (most recent first), optionally filtered by
|
|
349
|
+
* status, tags, or a `created_at` date range, and offset-paginated.
|
|
350
|
+
*
|
|
351
|
+
* @returns `{ data, total, limit, offset, has_more }`.
|
|
352
|
+
*/
|
|
353
|
+
list(params?: ListEmailsParams): Promise<EmailListResponse>;
|
|
354
|
+
/**
|
|
355
|
+
* Aggregate transactional metrics over an optional date window: totals,
|
|
356
|
+
* delivered/bounced/open/click counts, per-status counts, and rates.
|
|
357
|
+
*/
|
|
358
|
+
analytics(params?: EmailAnalyticsParams): Promise<EmailAnalytics>;
|
|
359
|
+
/**
|
|
360
|
+
* Retrieve a single email with its current delivery status and tracking
|
|
361
|
+
* counters. The returned object exposes both `last_event` (the raw wire field)
|
|
362
|
+
* and a friendly `status` alias.
|
|
363
|
+
*/
|
|
364
|
+
get(id: string): Promise<RetrievedEmail>;
|
|
365
|
+
/**
|
|
366
|
+
* Update a scheduled email — currently only its `scheduled_at`. Only emails
|
|
367
|
+
* still in the `scheduled` state can be updated.
|
|
368
|
+
*/
|
|
369
|
+
update(id: string, payload: UpdateEmailInput): Promise<UpdateEmailResponse>;
|
|
370
|
+
/**
|
|
371
|
+
* Convenience wrapper over {@link Emails.update} for the common reschedule
|
|
372
|
+
* case.
|
|
373
|
+
*
|
|
374
|
+
* @param scheduledAt ISO 8601 datetime string.
|
|
375
|
+
*/
|
|
376
|
+
reschedule(id: string, scheduledAt: string): Promise<UpdateEmailResponse>;
|
|
377
|
+
/** Cancel a scheduled email before it sends. */
|
|
378
|
+
cancel(id: string): Promise<CancelEmailResponse>;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
type ContactStatus = "active" | "unsubscribed" | "suppressed";
|
|
382
|
+
interface Contact {
|
|
383
|
+
object: "contact";
|
|
384
|
+
id: string;
|
|
385
|
+
publication_id: string;
|
|
386
|
+
email: string;
|
|
387
|
+
status: ContactStatus;
|
|
388
|
+
created_at: string;
|
|
389
|
+
updated_at: string;
|
|
390
|
+
}
|
|
391
|
+
interface CreateContactInput {
|
|
392
|
+
publication_id: string;
|
|
393
|
+
email: string;
|
|
394
|
+
status?: ContactStatus;
|
|
395
|
+
}
|
|
396
|
+
interface UpdateContactInput {
|
|
397
|
+
publication_id: string;
|
|
398
|
+
status?: ContactStatus;
|
|
399
|
+
}
|
|
400
|
+
interface ListContactsParams {
|
|
401
|
+
publication_id: string;
|
|
402
|
+
limit?: number;
|
|
403
|
+
after?: string;
|
|
404
|
+
status?: ContactStatus;
|
|
405
|
+
search?: string;
|
|
406
|
+
}
|
|
407
|
+
/** The `contacts` resource. Access via `mailtea.contacts`. */
|
|
408
|
+
declare class Contacts {
|
|
409
|
+
private readonly request;
|
|
410
|
+
constructor(request: RequestFn);
|
|
411
|
+
/** Create (or upsert) a contact in a publication. */
|
|
412
|
+
create(input: CreateContactInput): Promise<Contact>;
|
|
413
|
+
/** List contacts in a publication. Supports cursor pagination via `after`. */
|
|
414
|
+
list(params: ListContactsParams): Promise<ListResponse<Contact>>;
|
|
415
|
+
/** Retrieve a single contact by id or email. */
|
|
416
|
+
get(idOrEmail: string, params: {
|
|
417
|
+
publication_id: string;
|
|
418
|
+
}): Promise<Contact>;
|
|
419
|
+
/** Update a contact's status. */
|
|
420
|
+
update(idOrEmail: string, input: UpdateContactInput): Promise<Contact>;
|
|
421
|
+
/** Delete a contact by id or email. */
|
|
422
|
+
delete(idOrEmail: string, params: {
|
|
423
|
+
publication_id: string;
|
|
424
|
+
}): Promise<DeletedResponse>;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
interface Segment {
|
|
428
|
+
object: "segment";
|
|
429
|
+
id: string;
|
|
430
|
+
publication_id: string;
|
|
431
|
+
name: string;
|
|
432
|
+
description: string;
|
|
433
|
+
status_filter: ContactStatus | null;
|
|
434
|
+
query_filter: string | null;
|
|
435
|
+
created_at: string;
|
|
436
|
+
updated_at: string;
|
|
437
|
+
}
|
|
438
|
+
interface CreateSegmentInput {
|
|
439
|
+
publication_id: string;
|
|
440
|
+
name: string;
|
|
441
|
+
description?: string;
|
|
442
|
+
status_filter?: ContactStatus;
|
|
443
|
+
query_filter?: string;
|
|
444
|
+
}
|
|
445
|
+
interface UpdateSegmentInput {
|
|
446
|
+
publication_id: string;
|
|
447
|
+
name?: string;
|
|
448
|
+
description?: string;
|
|
449
|
+
status_filter?: ContactStatus | null;
|
|
450
|
+
query_filter?: string | null;
|
|
451
|
+
}
|
|
452
|
+
interface ListSegmentsParams {
|
|
453
|
+
publication_id: string;
|
|
454
|
+
limit?: number;
|
|
455
|
+
after?: string;
|
|
456
|
+
}
|
|
457
|
+
/** The `segments` resource. Access via `mailtea.segments`. */
|
|
458
|
+
declare class Segments {
|
|
459
|
+
private readonly request;
|
|
460
|
+
constructor(request: RequestFn);
|
|
461
|
+
/** Create a segment. */
|
|
462
|
+
create(input: CreateSegmentInput): Promise<Segment>;
|
|
463
|
+
/** List segments in a publication. */
|
|
464
|
+
list(params: ListSegmentsParams): Promise<ListResponse<Segment>>;
|
|
465
|
+
/** Retrieve a single segment. */
|
|
466
|
+
get(id: string, params: {
|
|
467
|
+
publication_id: string;
|
|
468
|
+
}): Promise<Segment>;
|
|
469
|
+
/** Update a segment. */
|
|
470
|
+
update(id: string, input: UpdateSegmentInput): Promise<Segment>;
|
|
471
|
+
/** Delete a segment. */
|
|
472
|
+
delete(id: string, params: {
|
|
473
|
+
publication_id: string;
|
|
474
|
+
}): Promise<DeletedResponse>;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
type TagSubscription = "opt_in" | "opt_out";
|
|
478
|
+
type TagVisibility = "public" | "private";
|
|
479
|
+
interface Tag {
|
|
480
|
+
object: "tag";
|
|
481
|
+
id: string;
|
|
482
|
+
publication_id: string;
|
|
483
|
+
name: string;
|
|
484
|
+
description: string;
|
|
485
|
+
default_subscription: TagSubscription;
|
|
486
|
+
visibility: TagVisibility;
|
|
487
|
+
created_at: string;
|
|
488
|
+
updated_at: string;
|
|
489
|
+
}
|
|
490
|
+
interface CreateTagInput {
|
|
491
|
+
publication_id: string;
|
|
492
|
+
name: string;
|
|
493
|
+
default_subscription: TagSubscription;
|
|
494
|
+
description?: string;
|
|
495
|
+
visibility?: TagVisibility;
|
|
496
|
+
}
|
|
497
|
+
interface UpdateTagInput {
|
|
498
|
+
publication_id: string;
|
|
499
|
+
name?: string;
|
|
500
|
+
description?: string;
|
|
501
|
+
default_subscription?: TagSubscription;
|
|
502
|
+
visibility?: TagVisibility;
|
|
503
|
+
}
|
|
504
|
+
interface ListTagsParams {
|
|
505
|
+
publication_id: string;
|
|
506
|
+
limit?: number;
|
|
507
|
+
after?: string;
|
|
508
|
+
}
|
|
509
|
+
/** The `tags` resource. Access via `mailtea.tags`. */
|
|
510
|
+
declare class Tags {
|
|
511
|
+
private readonly request;
|
|
512
|
+
constructor(request: RequestFn);
|
|
513
|
+
/** Create a tag. */
|
|
514
|
+
create(input: CreateTagInput): Promise<Tag>;
|
|
515
|
+
/** List tags in a publication. */
|
|
516
|
+
list(params: ListTagsParams): Promise<ListResponse<Tag>>;
|
|
517
|
+
/** Retrieve a single tag. */
|
|
518
|
+
get(id: string, params: {
|
|
519
|
+
publication_id: string;
|
|
520
|
+
}): Promise<Tag>;
|
|
521
|
+
/** Update a tag. */
|
|
522
|
+
update(id: string, input: UpdateTagInput): Promise<Tag>;
|
|
523
|
+
/** Delete a tag. */
|
|
524
|
+
delete(id: string, params: {
|
|
525
|
+
publication_id: string;
|
|
526
|
+
}): Promise<DeletedResponse>;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Input for `posts.sendTest`. */
|
|
530
|
+
interface SendPostTestInput {
|
|
531
|
+
/** Up to 10 test recipients (yourself / teammates). */
|
|
532
|
+
recipients: string[];
|
|
533
|
+
/** Sender, e.g. `"Acme <hello@acme.com>"`. Must use a verified domain. */
|
|
534
|
+
from: string;
|
|
535
|
+
reply_to?: string;
|
|
536
|
+
}
|
|
537
|
+
/** Result of `posts.sendTest`. */
|
|
538
|
+
interface PostTestSendResult {
|
|
539
|
+
object: "test_send";
|
|
540
|
+
id: string;
|
|
541
|
+
sent_at: string;
|
|
542
|
+
from: string;
|
|
543
|
+
sent_to: string[];
|
|
544
|
+
failed_to: Array<{
|
|
545
|
+
address: string;
|
|
546
|
+
reason: string;
|
|
547
|
+
}>;
|
|
548
|
+
}
|
|
549
|
+
/** Input for `posts.create`. */
|
|
550
|
+
interface CreatePostInput {
|
|
551
|
+
/** Publication the post belongs to. */
|
|
552
|
+
publication_id: string;
|
|
553
|
+
/** Subject line (also the post's working title). */
|
|
554
|
+
subject: string;
|
|
555
|
+
/**
|
|
556
|
+
* Seed the post from a published server template (see the `templates` tools).
|
|
557
|
+
* Provide this OR `html` — not both. `{{variables}}` are substituted.
|
|
558
|
+
*/
|
|
559
|
+
template_id?: string;
|
|
560
|
+
/** Values substituted into the template's `{{variable}}` placeholders. */
|
|
561
|
+
variables?: Record<string, string | number>;
|
|
562
|
+
/** Inline HTML body (use this OR `template_id`). */
|
|
563
|
+
html?: string;
|
|
564
|
+
/** `newsletter` (default, can publish to the site) or `broadcast` (email-only). */
|
|
565
|
+
kind?: "newsletter" | "broadcast";
|
|
566
|
+
/** Send right after creating (requires the `issues:send` scope). */
|
|
567
|
+
send?: boolean;
|
|
568
|
+
/** ISO-8601; with `send`, schedules the send instead of sending now. */
|
|
569
|
+
scheduled_at?: string;
|
|
570
|
+
}
|
|
571
|
+
/** Result of `posts.create`. */
|
|
572
|
+
interface CreatePostResult {
|
|
573
|
+
/** The new post's id. */
|
|
574
|
+
id: string;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* The `posts` resource (newsletter posts/issues). Access via `mailtea.posts`.
|
|
578
|
+
*/
|
|
579
|
+
declare class Posts {
|
|
580
|
+
private readonly request;
|
|
581
|
+
constructor(request: RequestFn);
|
|
582
|
+
/**
|
|
583
|
+
* Create a newsletter post (draft by default). Seed it from a published
|
|
584
|
+
* server template with `template_id` + `variables`, or pass inline `html`.
|
|
585
|
+
* Set `send: true` to deliver immediately (or with `scheduled_at` to
|
|
586
|
+
* schedule) — that requires the `issues:send` scope. Returns `{ id }`.
|
|
587
|
+
*/
|
|
588
|
+
create(input: CreatePostInput): Promise<CreatePostResult>;
|
|
589
|
+
/**
|
|
590
|
+
* Send a TEST copy of a post to specific recipients to check it before
|
|
591
|
+
* subscribers see it. Renders the post exactly as a subscriber would receive
|
|
592
|
+
* it and delivers a one-shot `[TEST]` email — it does NOT send to the
|
|
593
|
+
* audience. Returns `{ sent_to, failed_to }`.
|
|
594
|
+
*/
|
|
595
|
+
sendTest(id: string, input: SendPostTestInput): Promise<PostTestSendResult>;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
type DomainStatus = "pending" | "verified";
|
|
599
|
+
type DomainPurpose = "email" | "site" | "both";
|
|
600
|
+
interface DomainRecord {
|
|
601
|
+
record?: string;
|
|
602
|
+
type: string;
|
|
603
|
+
name: string;
|
|
604
|
+
value: string;
|
|
605
|
+
status: DomainStatus;
|
|
606
|
+
}
|
|
607
|
+
interface Domain {
|
|
608
|
+
object: "domain";
|
|
609
|
+
id: string;
|
|
610
|
+
publication_id: string;
|
|
611
|
+
name: string;
|
|
612
|
+
status: DomainStatus;
|
|
613
|
+
purpose: DomainPurpose;
|
|
614
|
+
is_primary: boolean;
|
|
615
|
+
proxy_target: string;
|
|
616
|
+
/** DNS records to add before verifying. Present on create/get/verify. */
|
|
617
|
+
records?: DomainRecord[];
|
|
618
|
+
verified_at: string | null;
|
|
619
|
+
created_at: string;
|
|
620
|
+
updated_at: string;
|
|
621
|
+
}
|
|
622
|
+
interface CreateDomainInput {
|
|
623
|
+
publication_id: string;
|
|
624
|
+
name: string;
|
|
625
|
+
/** Use `email` or `both` for a sending `from` domain. Defaults to `site`. */
|
|
626
|
+
purpose?: DomainPurpose;
|
|
627
|
+
is_primary?: boolean;
|
|
628
|
+
proxy_target?: string;
|
|
629
|
+
}
|
|
630
|
+
interface UpdateDomainInput {
|
|
631
|
+
publication_id: string;
|
|
632
|
+
purpose?: DomainPurpose;
|
|
633
|
+
is_primary?: boolean;
|
|
634
|
+
proxy_target?: string;
|
|
635
|
+
}
|
|
636
|
+
interface ListDomainsParams {
|
|
637
|
+
publication_id: string;
|
|
638
|
+
limit?: number;
|
|
639
|
+
after?: string;
|
|
640
|
+
}
|
|
641
|
+
interface TrackingDomain {
|
|
642
|
+
object: "tracking_domain";
|
|
643
|
+
id: string;
|
|
644
|
+
domain_id: string;
|
|
645
|
+
subdomain: string;
|
|
646
|
+
full_name: string;
|
|
647
|
+
status: DomainStatus;
|
|
648
|
+
/** The CNAME record to add. Present on create/verify. */
|
|
649
|
+
records?: DomainRecord[];
|
|
650
|
+
verified_at: string | null;
|
|
651
|
+
created_at: string;
|
|
652
|
+
updated_at: string;
|
|
653
|
+
}
|
|
654
|
+
interface CreateTrackingDomainInput {
|
|
655
|
+
publication_id: string;
|
|
656
|
+
/** Sub-domain label (lowercase alphanumeric and hyphens), e.g. `links`. */
|
|
657
|
+
subdomain: string;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Tracking sub-domains (CNAME) under a domain — used to serve open-pixel and
|
|
661
|
+
* click-tracking links from your own domain. Access via `mailtea.domains.tracking`.
|
|
662
|
+
*/
|
|
663
|
+
declare class TrackingDomains {
|
|
664
|
+
private readonly request;
|
|
665
|
+
constructor(request: RequestFn);
|
|
666
|
+
/** Add a tracking sub-domain. The response `records` lists the CNAME to add. */
|
|
667
|
+
create(domainId: string, input: CreateTrackingDomainInput): Promise<TrackingDomain>;
|
|
668
|
+
/** List tracking sub-domains for a domain. */
|
|
669
|
+
list(domainId: string, params: {
|
|
670
|
+
publication_id: string;
|
|
671
|
+
}): Promise<{
|
|
672
|
+
object: "list";
|
|
673
|
+
data: TrackingDomain[];
|
|
674
|
+
}>;
|
|
675
|
+
/** Verify a tracking sub-domain by checking its CNAME record. */
|
|
676
|
+
verify(domainId: string, trackingDomainId: string, params: {
|
|
677
|
+
publication_id: string;
|
|
678
|
+
}): Promise<TrackingDomain>;
|
|
679
|
+
/** Delete a tracking sub-domain. */
|
|
680
|
+
delete(domainId: string, trackingDomainId: string, params: {
|
|
681
|
+
publication_id: string;
|
|
682
|
+
}): Promise<DeletedResponse>;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* The `domains` resource (email/site sending domains). Access via
|
|
686
|
+
* `mailtea.domains`. Register a domain, add the returned DNS `records`, then
|
|
687
|
+
* `verify()` it before sending from it.
|
|
688
|
+
*/
|
|
689
|
+
declare class Domains {
|
|
690
|
+
private readonly request;
|
|
691
|
+
/** Tracking sub-domains (CNAME) under a domain. */
|
|
692
|
+
readonly tracking: TrackingDomains;
|
|
693
|
+
constructor(request: RequestFn);
|
|
694
|
+
/** Register a domain. The response `records` lists the DNS records to add. */
|
|
695
|
+
create(input: CreateDomainInput): Promise<Domain>;
|
|
696
|
+
/** List domains in a publication. */
|
|
697
|
+
list(params: ListDomainsParams): Promise<ListResponse<Domain>>;
|
|
698
|
+
/** Retrieve a single domain, including its DNS `records`. */
|
|
699
|
+
get(id: string, params: {
|
|
700
|
+
publication_id: string;
|
|
701
|
+
}): Promise<Domain>;
|
|
702
|
+
/** Verify a domain by checking its DNS records; `status` becomes `verified`. */
|
|
703
|
+
verify(id: string, params: {
|
|
704
|
+
publication_id: string;
|
|
705
|
+
}): Promise<Domain>;
|
|
706
|
+
/** Update a domain's purpose, primary flag, or proxy target. */
|
|
707
|
+
update(id: string, input: UpdateDomainInput): Promise<Domain>;
|
|
708
|
+
/** Delete a domain. */
|
|
709
|
+
delete(id: string, params: {
|
|
710
|
+
publication_id: string;
|
|
711
|
+
}): Promise<DeletedResponse>;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
type WebhookStatus = "enabled" | "disabled";
|
|
715
|
+
type WebhookEvent = "email.received" | "email.sent" | "email.delivered" | "email.delivery_delayed" | "email.bounced" | "email.complained" | "email.opened" | "email.clicked" | "email.failed" | "email.suppressed" | "contact.created" | "contact.updated" | "contact.deleted" | "contact.unsubscribed";
|
|
716
|
+
interface Webhook {
|
|
717
|
+
object: "webhook";
|
|
718
|
+
id: string;
|
|
719
|
+
publication_id: string;
|
|
720
|
+
endpoint: string;
|
|
721
|
+
events: WebhookEvent[];
|
|
722
|
+
/** Returned only on create — store it to verify payload signatures. */
|
|
723
|
+
signing_secret?: string;
|
|
724
|
+
status: WebhookStatus;
|
|
725
|
+
created_at: string;
|
|
726
|
+
updated_at: string;
|
|
727
|
+
}
|
|
728
|
+
interface CreateWebhookInput {
|
|
729
|
+
publication_id: string;
|
|
730
|
+
endpoint: string;
|
|
731
|
+
events: WebhookEvent[];
|
|
732
|
+
}
|
|
733
|
+
interface UpdateWebhookInput {
|
|
734
|
+
publication_id: string;
|
|
735
|
+
endpoint?: string;
|
|
736
|
+
events?: WebhookEvent[];
|
|
737
|
+
status?: WebhookStatus;
|
|
738
|
+
}
|
|
739
|
+
interface ListWebhooksParams {
|
|
740
|
+
publication_id: string;
|
|
741
|
+
limit?: number;
|
|
742
|
+
after?: string;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* The `webhooks` resource (outbound event subscriptions). Access via
|
|
746
|
+
* `mailtea.webhooks`. `create()` returns the `signing_secret` once.
|
|
747
|
+
*/
|
|
748
|
+
declare class Webhooks {
|
|
749
|
+
private readonly request;
|
|
750
|
+
constructor(request: RequestFn);
|
|
751
|
+
/** Create a webhook. The response `signing_secret` is returned only once. */
|
|
752
|
+
create(input: CreateWebhookInput): Promise<Webhook>;
|
|
753
|
+
/** List webhooks in a publication (signing secrets omitted). */
|
|
754
|
+
list(params: ListWebhooksParams): Promise<ListResponse<Webhook>>;
|
|
755
|
+
/** Retrieve a single webhook. */
|
|
756
|
+
get(id: string, params: {
|
|
757
|
+
publication_id: string;
|
|
758
|
+
}): Promise<Webhook>;
|
|
759
|
+
/** Update a webhook's endpoint, events, or enabled/disabled status. */
|
|
760
|
+
update(id: string, input: UpdateWebhookInput): Promise<Webhook>;
|
|
761
|
+
/** Delete a webhook. */
|
|
762
|
+
delete(id: string, params: {
|
|
763
|
+
publication_id: string;
|
|
764
|
+
}): Promise<DeletedResponse>;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
type ContactPropertyType = "string" | "number";
|
|
768
|
+
interface ContactProperty {
|
|
769
|
+
object: "contact_property";
|
|
770
|
+
id: string;
|
|
771
|
+
key: string;
|
|
772
|
+
type: ContactPropertyType;
|
|
773
|
+
fallback_value: string | null;
|
|
774
|
+
description: string;
|
|
775
|
+
created_at: string;
|
|
776
|
+
}
|
|
777
|
+
interface CreateContactPropertyInput {
|
|
778
|
+
key: string;
|
|
779
|
+
type: ContactPropertyType;
|
|
780
|
+
fallback_value?: string | number;
|
|
781
|
+
description?: string;
|
|
782
|
+
}
|
|
783
|
+
interface UpdateContactPropertyInput {
|
|
784
|
+
/** Pass `null` to clear the fallback. */
|
|
785
|
+
fallback_value?: string | number | null;
|
|
786
|
+
description?: string;
|
|
787
|
+
}
|
|
788
|
+
interface ListContactPropertiesParams {
|
|
789
|
+
limit?: number;
|
|
790
|
+
after?: string;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* The `contactProperties` resource (custom contact fields). Access via
|
|
794
|
+
* `mailtea.contactProperties`. Definitions are team-scoped — no
|
|
795
|
+
* `publication_id`.
|
|
796
|
+
*/
|
|
797
|
+
declare class ContactProperties {
|
|
798
|
+
private readonly request;
|
|
799
|
+
constructor(request: RequestFn);
|
|
800
|
+
/** Define a custom contact property. */
|
|
801
|
+
create(input: CreateContactPropertyInput): Promise<ContactProperty>;
|
|
802
|
+
/** List the team's custom contact property definitions. */
|
|
803
|
+
list(params?: ListContactPropertiesParams): Promise<ListResponse<ContactProperty>>;
|
|
804
|
+
/** Update a property's fallback value or description. */
|
|
805
|
+
update(id: string, input: UpdateContactPropertyInput): Promise<ContactProperty>;
|
|
806
|
+
/** Delete a custom contact property. */
|
|
807
|
+
delete(id: string): Promise<DeletedResponse>;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
type ApiKeyPermission = "full_access" | "sending_access";
|
|
811
|
+
interface CreateApiKeyInput {
|
|
812
|
+
/** A label for the key. 1–50 characters. */
|
|
813
|
+
name: string;
|
|
814
|
+
/** Access level. Defaults to `full_access`. */
|
|
815
|
+
permission?: ApiKeyPermission;
|
|
816
|
+
/** Publication to scope a `sending_access` key to. */
|
|
817
|
+
domain_id?: string;
|
|
818
|
+
}
|
|
819
|
+
interface CreatedApiKey {
|
|
820
|
+
id: string;
|
|
821
|
+
/** The full token — returned ONCE on creation. Store it securely. */
|
|
822
|
+
token: string;
|
|
823
|
+
}
|
|
824
|
+
interface ApiKeyListItem {
|
|
825
|
+
id: string;
|
|
826
|
+
name: string;
|
|
827
|
+
created_at: string;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* The `apiKeys` resource. Access via `mailtea.apiKeys`. Requires a token with
|
|
831
|
+
* `settings:write`; a key can never be granted scopes the calling token does
|
|
832
|
+
* not already hold.
|
|
833
|
+
*/
|
|
834
|
+
declare class ApiKeys {
|
|
835
|
+
private readonly request;
|
|
836
|
+
constructor(request: RequestFn);
|
|
837
|
+
/**
|
|
838
|
+
* Create an API key. The `token` is returned ONCE — store it securely. The
|
|
839
|
+
* calling token must already hold every scope the new key would grant.
|
|
840
|
+
*/
|
|
841
|
+
create(input: CreateApiKeyInput): Promise<CreatedApiKey>;
|
|
842
|
+
/** List API keys (token values are never returned). */
|
|
843
|
+
list(): Promise<{
|
|
844
|
+
data: ApiKeyListItem[];
|
|
845
|
+
}>;
|
|
846
|
+
/** Revoke (delete) an API key by id. */
|
|
847
|
+
revoke(id: string): Promise<void>;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
interface MailteaOptions {
|
|
851
|
+
/** API key (`mt_pat_...` or `mt_svc_...`). Falls back to `MAILTEA_API_KEY`. */
|
|
852
|
+
apiKey?: string;
|
|
853
|
+
/** API base URL. Defaults to `https://api.mailtea.app`. */
|
|
854
|
+
baseUrl?: string;
|
|
855
|
+
/** Custom `fetch` implementation. Defaults to the global `fetch`. */
|
|
856
|
+
fetch?: typeof fetch;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* The Mailtea client. Construct it with an API key, then use its resources:
|
|
860
|
+
*
|
|
861
|
+
* ```ts
|
|
862
|
+
* import { Mailtea } from "mailtea-sdk";
|
|
863
|
+
*
|
|
864
|
+
* const mailtea = new Mailtea(process.env.MAILTEA_API_KEY);
|
|
865
|
+
* const { id } = await mailtea.emails.send({
|
|
866
|
+
* from: "you@yourdomain.com",
|
|
867
|
+
* to: "recipient@example.com",
|
|
868
|
+
* subject: "Hello",
|
|
869
|
+
* html: "<p>Sent with Mailtea.</p>"
|
|
870
|
+
* });
|
|
871
|
+
* ```
|
|
872
|
+
*
|
|
873
|
+
* The API key can be passed as a string, inside an options object, or omitted
|
|
874
|
+
* to read `MAILTEA_API_KEY` from the environment.
|
|
875
|
+
*/
|
|
876
|
+
declare class Mailtea {
|
|
877
|
+
/** The `emails` resource: send, batch, get, update, reschedule, cancel. */
|
|
878
|
+
readonly emails: Emails;
|
|
879
|
+
/** The `contacts` resource: create, list, get, update, delete. */
|
|
880
|
+
readonly contacts: Contacts;
|
|
881
|
+
/** The `segments` resource: create, list, get, update, delete. */
|
|
882
|
+
readonly segments: Segments;
|
|
883
|
+
/** The `tags` resource: create, list, get, update, delete. */
|
|
884
|
+
readonly tags: Tags;
|
|
885
|
+
/** The `posts` resource: sendTest (newsletter posts). */
|
|
886
|
+
readonly posts: Posts;
|
|
887
|
+
/** The `domains` resource: create, list, get, verify, update, delete. */
|
|
888
|
+
readonly domains: Domains;
|
|
889
|
+
/** The `webhooks` resource: create, list, get, update, delete. */
|
|
890
|
+
readonly webhooks: Webhooks;
|
|
891
|
+
/** The `contactProperties` resource: create, list, update, delete. */
|
|
892
|
+
readonly contactProperties: ContactProperties;
|
|
893
|
+
/** The `apiKeys` resource: create, list, revoke. */
|
|
894
|
+
readonly apiKeys: ApiKeys;
|
|
895
|
+
private readonly apiKey;
|
|
896
|
+
private readonly baseUrl;
|
|
897
|
+
private readonly fetchImpl;
|
|
898
|
+
constructor(apiKeyOrOptions?: string | MailteaOptions, maybeOptions?: MailteaOptions);
|
|
899
|
+
/** @internal Issue an authenticated request and map errors to MailteaError. */
|
|
900
|
+
private request;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
interface MailteaErrorInit {
|
|
904
|
+
/** HTTP status code, or `0` for client-side errors raised before a request. */
|
|
905
|
+
status: number;
|
|
906
|
+
/** Machine-readable code, when available (e.g. `missing_api_key`). */
|
|
907
|
+
code?: string;
|
|
908
|
+
/** Structured error payload from the API (e.g. Zod validation issues on 400). */
|
|
909
|
+
details?: unknown;
|
|
910
|
+
/** Value of the `x-request-id` response header, useful for support. */
|
|
911
|
+
requestId?: string;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Error thrown by the Mailtea SDK for both client-side problems (missing API
|
|
915
|
+
* key, no `fetch`) and non-2xx API responses. Inspect `status` and `details`
|
|
916
|
+
* to branch on validation vs. auth vs. not-found errors.
|
|
917
|
+
*/
|
|
918
|
+
declare class MailteaError extends Error {
|
|
919
|
+
readonly status: number;
|
|
920
|
+
readonly code?: string;
|
|
921
|
+
readonly details?: unknown;
|
|
922
|
+
readonly requestId?: string;
|
|
923
|
+
constructor(message: string, init: MailteaErrorInit);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/** Input for {@link signWebhook}. */
|
|
927
|
+
interface SignWebhookInput {
|
|
928
|
+
secret: string;
|
|
929
|
+
msgId: string;
|
|
930
|
+
/** Unix seconds — the same value sent in the `webhook-timestamp` header. */
|
|
931
|
+
timestamp: number;
|
|
932
|
+
payload: string;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Sign a webhook payload. Returns the `webhook-signature` header value in
|
|
936
|
+
* Standard Webhooks form: `v1,<base64 HMAC-SHA256>`.
|
|
937
|
+
*/
|
|
938
|
+
declare function signWebhook(input: SignWebhookInput): string;
|
|
939
|
+
/** Input for {@link verifyWebhookSignature}. */
|
|
940
|
+
interface VerifyWebhookSignatureInput {
|
|
941
|
+
secret: string;
|
|
942
|
+
msgId: string;
|
|
943
|
+
/** Unix seconds, as received in the `webhook-timestamp` header. */
|
|
944
|
+
timestamp: number;
|
|
945
|
+
payload: string;
|
|
946
|
+
signatureHeader: string;
|
|
947
|
+
/** Allowed clock skew each way. Default 5 minutes. */
|
|
948
|
+
toleranceSeconds?: number;
|
|
949
|
+
/** Injectable for tests. Unix seconds. */
|
|
950
|
+
now?: number;
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Verify a `webhook-signature` header against the expected HMAC. The header may
|
|
954
|
+
* carry multiple space-delimited `v1,<sig>` tokens (Standard Webhooks allows
|
|
955
|
+
* key rotation); a match against any `v1` token passes. Rejects when the
|
|
956
|
+
* timestamp is outside `toleranceSeconds` of `now` (replay protection).
|
|
957
|
+
*/
|
|
958
|
+
declare function verifyWebhookSignature(input: VerifyWebhookSignatureInput): boolean;
|
|
959
|
+
|
|
960
|
+
export { type ApiKeyListItem, type ApiKeyPermission, ApiKeys, type BatchEmailInput, type BatchEmailItemInput, type BatchEmailResponse, type CancelEmailResponse, type Contact, ContactProperties, type ContactProperty, type ContactPropertyType, type ContactStatus, Contacts, type CreateApiKeyInput, type CreateContactInput, type CreateContactPropertyInput, type CreateDomainInput, type CreatePostInput, type CreatePostResult, type CreateSegmentInput, type CreateTagInput, type CreateTrackingDomainInput, type CreateWebhookInput, type CreatedApiKey, type DeletedResponse, type Domain, type DomainPurpose, type DomainRecord, type DomainStatus, Domains, type EmailAnalytics, type EmailAnalyticsParams, type EmailAttachmentMeta, type EmailListItem, type EmailListResponse, type EmailStatus, type EmailTag, Emails, type InboundAttachment, type InboundAttachmentMeta, InboundAttachments, type InboundEmailListItem, InboundEmails, type InboundReplyInput, type InboundReplyResponse, type ListContactPropertiesParams, type ListContactsParams, type ListDomainsParams, type ListEmailsParams, type ListInboundEmailsParams, type ListResponse, type ListSegmentsParams, type ListTagsParams, type ListWebhooksParams, Mailtea, MailteaError, type MailteaErrorInit, type MailteaOptions, type PostTestSendResult, Posts, type RequestFn, type RetrievedEmail, type RetrievedInboundEmail, type Segment, Segments, type SendEmailInput, type SendEmailResponse, type SendPostTestInput, type SignWebhookInput, type Tag, type TagSubscription, type TagVisibility, Tags, type TemplateRef, type TrackingDomain, TrackingDomains, type UpdateContactInput, type UpdateContactPropertyInput, type UpdateDomainInput, type UpdateEmailInput, type UpdateEmailResponse, type UpdateSegmentInput, type UpdateTagInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type Webhook, type WebhookEvent, type WebhookStatus, Webhooks, signWebhook, verifyWebhookSignature };
|