bavimail 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 +2 -0
- package/dist/index.cjs +883 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +879 -0
- package/dist/index.d.ts +879 -0
- package/dist/index.js +866 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
interface HttpClientOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
declare class HttpClient {
|
|
6
|
+
private readonly apiKey;
|
|
7
|
+
private readonly baseUrl;
|
|
8
|
+
constructor(options: HttpClientOptions);
|
|
9
|
+
private headers;
|
|
10
|
+
request<T>(method: string, path: string, options?: {
|
|
11
|
+
body?: Record<string, unknown>;
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
}): Promise<T>;
|
|
14
|
+
requestBytes(method: string, path: string, options?: {
|
|
15
|
+
params?: Record<string, unknown>;
|
|
16
|
+
}): Promise<ArrayBuffer>;
|
|
17
|
+
private buildUrl;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare abstract class BaseResource {
|
|
21
|
+
protected readonly http: HttpClient;
|
|
22
|
+
constructor(http: HttpClient);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Alias {
|
|
26
|
+
id: string;
|
|
27
|
+
userId: string;
|
|
28
|
+
domainId: string;
|
|
29
|
+
alias: string;
|
|
30
|
+
fullEmail: string;
|
|
31
|
+
domainName: string;
|
|
32
|
+
signatureHtml: string | null;
|
|
33
|
+
signatureText: string | null;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
updatedAt: string;
|
|
36
|
+
}
|
|
37
|
+
interface AliasCreateParams {
|
|
38
|
+
domainId: string;
|
|
39
|
+
alias: string;
|
|
40
|
+
signatureHtml?: string | null;
|
|
41
|
+
}
|
|
42
|
+
interface AliasUpdateParams {
|
|
43
|
+
alias: string;
|
|
44
|
+
signatureHtml?: string | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type DomainStatus = "pending" | "verifying" | "verified" | "failed";
|
|
48
|
+
type EmailProviderKey = "AWS";
|
|
49
|
+
type DNSRecordVerificationStatus = "verified" | "not_configured" | "incorrect_value" | "checking" | "error";
|
|
50
|
+
type MailFromStatus = "not_started" | "pending" | "success" | "failed" | "temporary_failure";
|
|
51
|
+
interface Domain {
|
|
52
|
+
id: string;
|
|
53
|
+
userId: string;
|
|
54
|
+
domain: string;
|
|
55
|
+
status: DomainStatus;
|
|
56
|
+
isActive: boolean;
|
|
57
|
+
providerKey: EmailProviderKey;
|
|
58
|
+
providerConfig: Record<string, unknown> | null;
|
|
59
|
+
sesVerificationToken: string | null;
|
|
60
|
+
sesDkimTokens: string[] | null;
|
|
61
|
+
sesMailFromDomain: string | null;
|
|
62
|
+
sesMailFromStatus: MailFromStatus | null;
|
|
63
|
+
sesMailFromError: string | null;
|
|
64
|
+
verifiedAt: string | null;
|
|
65
|
+
lastVerificationAttempt: string | null;
|
|
66
|
+
verificationError: string | null;
|
|
67
|
+
stripTrackingOnRead: boolean;
|
|
68
|
+
createdAt: string;
|
|
69
|
+
updatedAt: string;
|
|
70
|
+
}
|
|
71
|
+
interface DomainCreateParams {
|
|
72
|
+
domain: string;
|
|
73
|
+
providerKey: EmailProviderKey;
|
|
74
|
+
providerConfig?: Record<string, unknown> | null;
|
|
75
|
+
}
|
|
76
|
+
interface DomainUpdateParams {
|
|
77
|
+
isActive?: boolean | null;
|
|
78
|
+
providerConfig?: Record<string, unknown> | null;
|
|
79
|
+
stripTrackingOnRead?: boolean | null;
|
|
80
|
+
}
|
|
81
|
+
interface DNSRecord {
|
|
82
|
+
type: string;
|
|
83
|
+
name: string;
|
|
84
|
+
value: string;
|
|
85
|
+
priority: number | null;
|
|
86
|
+
ttl: number | null;
|
|
87
|
+
description: string | null;
|
|
88
|
+
}
|
|
89
|
+
interface DNSRecordWithStatus extends DNSRecord {
|
|
90
|
+
status: DNSRecordVerificationStatus;
|
|
91
|
+
actualValue: string | null;
|
|
92
|
+
errorMessage: string | null;
|
|
93
|
+
lastChecked: string;
|
|
94
|
+
}
|
|
95
|
+
interface DNSVerificationProgress {
|
|
96
|
+
totalRecords: number;
|
|
97
|
+
verified: number;
|
|
98
|
+
notConfigured: number;
|
|
99
|
+
incorrect: number;
|
|
100
|
+
errors: number;
|
|
101
|
+
}
|
|
102
|
+
interface MailFromStatusInfo {
|
|
103
|
+
mailFromDomain: string | null;
|
|
104
|
+
status: MailFromStatus;
|
|
105
|
+
error: string | null;
|
|
106
|
+
message: string;
|
|
107
|
+
}
|
|
108
|
+
interface DNSVerificationResponse {
|
|
109
|
+
domain: string;
|
|
110
|
+
overallProgress: DNSVerificationProgress;
|
|
111
|
+
records: DNSRecordWithStatus[];
|
|
112
|
+
mailFromStatus: MailFromStatusInfo | null;
|
|
113
|
+
lastChecked: string;
|
|
114
|
+
}
|
|
115
|
+
interface DomainSetup {
|
|
116
|
+
domain: string;
|
|
117
|
+
dnsRecords: DNSRecord[];
|
|
118
|
+
verificationInstructions: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type EmailStatus = "scheduled" | "queued" | "sending" | "sent" | "delivered" | "failed" | "bounced" | "complained" | "cancelled";
|
|
122
|
+
type TagType = "tag" | "folder";
|
|
123
|
+
type TaggedBy = "user" | "system" | "rule";
|
|
124
|
+
type WebhookEventType = "email.inbound.received" | "email.outbound.sent" | "email.outbound.failed" | "email.outbound.opened" | "email.outbound.clicked" | "email.outbound.scheduled" | "email.outbound.cancelled" | "domain.verified" | "domain.failed" | "webhook.test";
|
|
125
|
+
|
|
126
|
+
interface AttachmentMetadata {
|
|
127
|
+
filename: string;
|
|
128
|
+
sizeBytes: number;
|
|
129
|
+
mimeType: string;
|
|
130
|
+
contentId: string | null;
|
|
131
|
+
}
|
|
132
|
+
interface AttachmentCreateParams {
|
|
133
|
+
filename: string;
|
|
134
|
+
content: string;
|
|
135
|
+
mimeType?: string | null;
|
|
136
|
+
contentId?: string | null;
|
|
137
|
+
}
|
|
138
|
+
interface Email {
|
|
139
|
+
id: string;
|
|
140
|
+
userId: string;
|
|
141
|
+
aliasId: string;
|
|
142
|
+
domainId: string;
|
|
143
|
+
conversationId: string | null;
|
|
144
|
+
fromEmail: string;
|
|
145
|
+
toEmail: string;
|
|
146
|
+
subject: string;
|
|
147
|
+
bodyText: string;
|
|
148
|
+
bodyHtml: string | null;
|
|
149
|
+
inReplyTo: string | null;
|
|
150
|
+
references: string | null;
|
|
151
|
+
attachments: AttachmentMetadata[] | null;
|
|
152
|
+
attachmentCount: number;
|
|
153
|
+
providerMessageId: string;
|
|
154
|
+
providerMetadata: Record<string, unknown>;
|
|
155
|
+
status: EmailStatus;
|
|
156
|
+
sentAt: string | null;
|
|
157
|
+
deliveredAt: string | null;
|
|
158
|
+
errorMessage: string | null;
|
|
159
|
+
sendAt: string | null;
|
|
160
|
+
sendAtTimezone: string | null;
|
|
161
|
+
sendAtUtc: string | null;
|
|
162
|
+
cancelledAt: string | null;
|
|
163
|
+
trackingId: string | null;
|
|
164
|
+
trackOpens: boolean;
|
|
165
|
+
firstOpenedAt: string | null;
|
|
166
|
+
openCount: number;
|
|
167
|
+
trackClicks: boolean;
|
|
168
|
+
clickCount: number;
|
|
169
|
+
firstClickedAt: string | null;
|
|
170
|
+
lastClickedAt: string | null;
|
|
171
|
+
trackedLinksCount: number;
|
|
172
|
+
aliasName: string | null;
|
|
173
|
+
domainName: string | null;
|
|
174
|
+
createdAt: string;
|
|
175
|
+
updatedAt: string;
|
|
176
|
+
}
|
|
177
|
+
interface EmailSendParams {
|
|
178
|
+
aliasId: string;
|
|
179
|
+
toEmail: string;
|
|
180
|
+
subject: string;
|
|
181
|
+
body: string;
|
|
182
|
+
trackOpens?: boolean;
|
|
183
|
+
trackClicks?: boolean;
|
|
184
|
+
clickTrackingPatterns?: string[] | null;
|
|
185
|
+
conversationId?: string | null;
|
|
186
|
+
inReplyTo?: string | null;
|
|
187
|
+
sendAt?: string | null;
|
|
188
|
+
sendAtTimezone?: string | null;
|
|
189
|
+
attachments?: AttachmentCreateParams[] | null;
|
|
190
|
+
}
|
|
191
|
+
interface EmailClickListResponse {
|
|
192
|
+
clicks: EmailClick[];
|
|
193
|
+
total: number;
|
|
194
|
+
limit: number;
|
|
195
|
+
offset: number;
|
|
196
|
+
}
|
|
197
|
+
interface EmailClick {
|
|
198
|
+
id: string;
|
|
199
|
+
linkId: string;
|
|
200
|
+
originalUrl: string;
|
|
201
|
+
position: number;
|
|
202
|
+
clickedAt: string;
|
|
203
|
+
userAgent: string | null;
|
|
204
|
+
ipAddress: string | null;
|
|
205
|
+
referer: string | null;
|
|
206
|
+
deviceType: string | null;
|
|
207
|
+
browserName: string | null;
|
|
208
|
+
osName: string | null;
|
|
209
|
+
isFirstClick: boolean;
|
|
210
|
+
isBot: boolean;
|
|
211
|
+
botReason: string | null;
|
|
212
|
+
createdAt: string;
|
|
213
|
+
updatedAt: string;
|
|
214
|
+
}
|
|
215
|
+
interface TrackedLink {
|
|
216
|
+
id: string;
|
|
217
|
+
linkId: string;
|
|
218
|
+
originalUrl: string;
|
|
219
|
+
position: number;
|
|
220
|
+
anchorText: string | null;
|
|
221
|
+
clickCount: number;
|
|
222
|
+
uniqueClickCount: number;
|
|
223
|
+
firstClickedAt: string | null;
|
|
224
|
+
lastClickedAt: string | null;
|
|
225
|
+
createdAt: string;
|
|
226
|
+
updatedAt: string;
|
|
227
|
+
}
|
|
228
|
+
interface BatchEmailResponse {
|
|
229
|
+
total: number;
|
|
230
|
+
accepted: number;
|
|
231
|
+
rejected: number;
|
|
232
|
+
results: BatchEmailItemResult[];
|
|
233
|
+
}
|
|
234
|
+
interface BatchEmailItemResult {
|
|
235
|
+
index: number;
|
|
236
|
+
status: string;
|
|
237
|
+
email: Email | null;
|
|
238
|
+
error: BatchEmailItemError | null;
|
|
239
|
+
}
|
|
240
|
+
interface BatchEmailItemError {
|
|
241
|
+
message: string;
|
|
242
|
+
code: string | null;
|
|
243
|
+
category: string | null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
interface Tag {
|
|
247
|
+
id: string;
|
|
248
|
+
userId: string;
|
|
249
|
+
name: string;
|
|
250
|
+
description: string | null;
|
|
251
|
+
type: TagType;
|
|
252
|
+
color: string | null;
|
|
253
|
+
icon: string | null;
|
|
254
|
+
sortOrder: number;
|
|
255
|
+
isPinned: boolean;
|
|
256
|
+
isSystem: boolean;
|
|
257
|
+
emailCount: number;
|
|
258
|
+
isVisible: boolean;
|
|
259
|
+
createdAt: string;
|
|
260
|
+
updatedAt: string;
|
|
261
|
+
}
|
|
262
|
+
interface TagSummary {
|
|
263
|
+
id: string;
|
|
264
|
+
name: string;
|
|
265
|
+
type: TagType;
|
|
266
|
+
color: string | null;
|
|
267
|
+
icon: string | null;
|
|
268
|
+
}
|
|
269
|
+
interface TagCreateParams {
|
|
270
|
+
name: string;
|
|
271
|
+
description?: string | null;
|
|
272
|
+
type?: TagType;
|
|
273
|
+
color?: string | null;
|
|
274
|
+
icon?: string | null;
|
|
275
|
+
sortOrder?: number;
|
|
276
|
+
isPinned?: boolean;
|
|
277
|
+
}
|
|
278
|
+
interface TagUpdateParams {
|
|
279
|
+
name?: string | null;
|
|
280
|
+
description?: string | null;
|
|
281
|
+
type?: TagType | null;
|
|
282
|
+
color?: string | null;
|
|
283
|
+
icon?: string | null;
|
|
284
|
+
sortOrder?: number | null;
|
|
285
|
+
isPinned?: boolean | null;
|
|
286
|
+
isVisible?: boolean | null;
|
|
287
|
+
}
|
|
288
|
+
interface EmailTag {
|
|
289
|
+
tag: TagSummary;
|
|
290
|
+
taggedAt: string;
|
|
291
|
+
taggedBy: TaggedBy;
|
|
292
|
+
note: string | null;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface Verdict {
|
|
296
|
+
status: string;
|
|
297
|
+
details: string | null;
|
|
298
|
+
}
|
|
299
|
+
interface InboundAttachmentMetadata {
|
|
300
|
+
filename: string | null;
|
|
301
|
+
sizeBytes: number;
|
|
302
|
+
mimeType: string;
|
|
303
|
+
contentId: string | null;
|
|
304
|
+
isInline: boolean;
|
|
305
|
+
storageUri: string | null;
|
|
306
|
+
storageScheme: string | null;
|
|
307
|
+
}
|
|
308
|
+
interface InboundEmailSummary {
|
|
309
|
+
id: string;
|
|
310
|
+
userId: string;
|
|
311
|
+
aliasId: string;
|
|
312
|
+
domainId: string;
|
|
313
|
+
conversationId: string | null;
|
|
314
|
+
fromEmail: string;
|
|
315
|
+
fromName: string | null;
|
|
316
|
+
subject: string;
|
|
317
|
+
providerReceivedAt: string;
|
|
318
|
+
processedAt: string | null;
|
|
319
|
+
processingError: string | null;
|
|
320
|
+
providerMessageId: string;
|
|
321
|
+
rawEmailUri: string;
|
|
322
|
+
providerMetadata: Record<string, unknown>;
|
|
323
|
+
aliasName: string;
|
|
324
|
+
domainName: string;
|
|
325
|
+
fullEmail: string;
|
|
326
|
+
attachmentCount: number;
|
|
327
|
+
hasHtml: boolean;
|
|
328
|
+
tags: TagSummary[];
|
|
329
|
+
createdAt: string;
|
|
330
|
+
updatedAt: string;
|
|
331
|
+
}
|
|
332
|
+
interface InboundEmailDetail {
|
|
333
|
+
id: string;
|
|
334
|
+
userId: string;
|
|
335
|
+
aliasId: string;
|
|
336
|
+
domainId: string;
|
|
337
|
+
conversationId: string | null;
|
|
338
|
+
fromEmail: string;
|
|
339
|
+
fromName: string | null;
|
|
340
|
+
replyTo: string | null;
|
|
341
|
+
toEmail: string;
|
|
342
|
+
ccEmails: string[] | null;
|
|
343
|
+
bccEmails: string[] | null;
|
|
344
|
+
subject: string;
|
|
345
|
+
bodyText: string | null;
|
|
346
|
+
bodyHtml: string | null;
|
|
347
|
+
rawEmailSize: number | null;
|
|
348
|
+
headers: Record<string, string> | null;
|
|
349
|
+
messageId: string | null;
|
|
350
|
+
inReplyTo: string | null;
|
|
351
|
+
references: string[] | null;
|
|
352
|
+
attachments: InboundAttachmentMetadata[] | null;
|
|
353
|
+
providerMessageId: string;
|
|
354
|
+
providerReceivedAt: string;
|
|
355
|
+
spamVerdict: Verdict | null;
|
|
356
|
+
virusVerdict: Verdict | null;
|
|
357
|
+
spfVerdict: Verdict | null;
|
|
358
|
+
dkimVerdict: Verdict | null;
|
|
359
|
+
dmarcVerdict: Verdict | null;
|
|
360
|
+
processedAt: string | null;
|
|
361
|
+
processingError: string | null;
|
|
362
|
+
aliasName: string;
|
|
363
|
+
domainName: string;
|
|
364
|
+
fullEmail: string;
|
|
365
|
+
attachmentCount: number;
|
|
366
|
+
hasHtml: boolean;
|
|
367
|
+
rawEmailUri: string;
|
|
368
|
+
providerMetadata: Record<string, unknown>;
|
|
369
|
+
tags: TagSummary[];
|
|
370
|
+
createdAt: string;
|
|
371
|
+
updatedAt: string;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
interface ConversationSummary {
|
|
375
|
+
id: string;
|
|
376
|
+
userId: string;
|
|
377
|
+
subject: string;
|
|
378
|
+
firstMessageAt: string;
|
|
379
|
+
lastMessageAt: string;
|
|
380
|
+
messageCount: number;
|
|
381
|
+
firstFromEmail: string | null;
|
|
382
|
+
firstToEmail: string | null;
|
|
383
|
+
totalAttachmentCount: number;
|
|
384
|
+
createdAt: string;
|
|
385
|
+
updatedAt: string;
|
|
386
|
+
}
|
|
387
|
+
interface ConversationDetail {
|
|
388
|
+
id: string;
|
|
389
|
+
userId: string;
|
|
390
|
+
subject: string;
|
|
391
|
+
firstMessageAt: string;
|
|
392
|
+
lastMessageAt: string;
|
|
393
|
+
messageCount: number;
|
|
394
|
+
messages: ConversationMessage[];
|
|
395
|
+
createdAt: string;
|
|
396
|
+
updatedAt: string;
|
|
397
|
+
}
|
|
398
|
+
interface ConversationMessage {
|
|
399
|
+
id: string;
|
|
400
|
+
direction: string;
|
|
401
|
+
fromEmail: string;
|
|
402
|
+
fromName: string | null;
|
|
403
|
+
toEmail: string;
|
|
404
|
+
subject: string;
|
|
405
|
+
timestamp: string;
|
|
406
|
+
bodyText: string | null;
|
|
407
|
+
bodyHtml: string | null;
|
|
408
|
+
attachmentCount: number;
|
|
409
|
+
messageId: string | null;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
interface Webhook {
|
|
413
|
+
id: string;
|
|
414
|
+
url: string;
|
|
415
|
+
description: string | null;
|
|
416
|
+
eventTypes: string[];
|
|
417
|
+
isActive: boolean;
|
|
418
|
+
isVerified: boolean;
|
|
419
|
+
consecutiveFailures: number;
|
|
420
|
+
disabledAt: string | null;
|
|
421
|
+
integrationId: string | null;
|
|
422
|
+
createdAt: string;
|
|
423
|
+
updatedAt: string;
|
|
424
|
+
}
|
|
425
|
+
interface WebhookCreated extends Webhook {
|
|
426
|
+
secret: string;
|
|
427
|
+
}
|
|
428
|
+
interface WebhookSecret {
|
|
429
|
+
secret: string;
|
|
430
|
+
}
|
|
431
|
+
interface WebhookCreateParams {
|
|
432
|
+
url: string;
|
|
433
|
+
eventTypes: WebhookEventType[];
|
|
434
|
+
description?: string | null;
|
|
435
|
+
}
|
|
436
|
+
interface WebhookUpdateParams {
|
|
437
|
+
url?: string | null;
|
|
438
|
+
eventTypes?: WebhookEventType[] | null;
|
|
439
|
+
description?: string | null;
|
|
440
|
+
isActive?: boolean | null;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
interface IntegrationInfo {
|
|
444
|
+
id: string;
|
|
445
|
+
displayName: string;
|
|
446
|
+
authMode: string;
|
|
447
|
+
}
|
|
448
|
+
interface BootstrapApiKeyResponse {
|
|
449
|
+
apiKey: string;
|
|
450
|
+
created: boolean;
|
|
451
|
+
expiresAt: string | null;
|
|
452
|
+
}
|
|
453
|
+
interface RevokeApiKeyResponse {
|
|
454
|
+
revoked: boolean;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
interface WebhookEvent<T = unknown> {
|
|
458
|
+
eventId: string;
|
|
459
|
+
eventType: WebhookEventType;
|
|
460
|
+
timestamp: string;
|
|
461
|
+
data: T;
|
|
462
|
+
}
|
|
463
|
+
interface InboundReceivedData {
|
|
464
|
+
emailId: string;
|
|
465
|
+
aliasId: string;
|
|
466
|
+
domainId: string;
|
|
467
|
+
fromEmail: string;
|
|
468
|
+
fromName: string | null;
|
|
469
|
+
toEmail: string;
|
|
470
|
+
subject: string | null;
|
|
471
|
+
bodyPreview: string | null;
|
|
472
|
+
receivedAt: string | null;
|
|
473
|
+
attachmentCount: number;
|
|
474
|
+
hasHtml: boolean;
|
|
475
|
+
}
|
|
476
|
+
interface OutboundSentData {
|
|
477
|
+
emailId: string;
|
|
478
|
+
fromEmail: string;
|
|
479
|
+
toEmail: string;
|
|
480
|
+
subject: string | null;
|
|
481
|
+
bodyPreview: string | null;
|
|
482
|
+
sentAt: string | null;
|
|
483
|
+
providerMessageId: string | null;
|
|
484
|
+
}
|
|
485
|
+
interface OutboundFailedData {
|
|
486
|
+
emailId: string;
|
|
487
|
+
fromEmail: string;
|
|
488
|
+
toEmail: string;
|
|
489
|
+
subject: string | null;
|
|
490
|
+
errorMessage: string | null;
|
|
491
|
+
}
|
|
492
|
+
interface OutboundOpenedData {
|
|
493
|
+
emailId: string;
|
|
494
|
+
fromEmail: string;
|
|
495
|
+
toEmail: string;
|
|
496
|
+
subject: string | null;
|
|
497
|
+
openedAt: string | null;
|
|
498
|
+
isFirstOpen: boolean;
|
|
499
|
+
isBot: boolean;
|
|
500
|
+
botReason: string | null;
|
|
501
|
+
openCount: number;
|
|
502
|
+
}
|
|
503
|
+
interface OutboundClickedData {
|
|
504
|
+
emailId: string;
|
|
505
|
+
fromEmail: string;
|
|
506
|
+
toEmail: string;
|
|
507
|
+
subject: string | null;
|
|
508
|
+
linkId: string;
|
|
509
|
+
originalUrl: string;
|
|
510
|
+
position: number | null;
|
|
511
|
+
anchorText: string | null;
|
|
512
|
+
clickedAt: string | null;
|
|
513
|
+
isFirstClick: boolean;
|
|
514
|
+
isBot: boolean;
|
|
515
|
+
botReason: string | null;
|
|
516
|
+
deviceType: string | null;
|
|
517
|
+
browserName: string | null;
|
|
518
|
+
osName: string | null;
|
|
519
|
+
linkClickCount: number;
|
|
520
|
+
linkUniqueClickCount: number;
|
|
521
|
+
emailClickCount: number;
|
|
522
|
+
}
|
|
523
|
+
interface OutboundScheduledData {
|
|
524
|
+
emailId: string;
|
|
525
|
+
fromEmail: string;
|
|
526
|
+
toEmail: string;
|
|
527
|
+
subject: string | null;
|
|
528
|
+
sendAt: string | null;
|
|
529
|
+
sendAtTimezone: string | null;
|
|
530
|
+
sendAtUtc: string | null;
|
|
531
|
+
}
|
|
532
|
+
interface OutboundCancelledData {
|
|
533
|
+
emailId: string;
|
|
534
|
+
fromEmail: string;
|
|
535
|
+
toEmail: string;
|
|
536
|
+
subject: string | null;
|
|
537
|
+
cancelledAt: string | null;
|
|
538
|
+
}
|
|
539
|
+
interface DomainVerifiedData {
|
|
540
|
+
domainId: string;
|
|
541
|
+
domain: string;
|
|
542
|
+
verifiedAt: string | null;
|
|
543
|
+
}
|
|
544
|
+
interface DomainFailedData {
|
|
545
|
+
domainId: string;
|
|
546
|
+
domain: string;
|
|
547
|
+
error: string | null;
|
|
548
|
+
}
|
|
549
|
+
interface WebhookTestData {
|
|
550
|
+
webhookId: string;
|
|
551
|
+
test: boolean;
|
|
552
|
+
}
|
|
553
|
+
interface EventDataMap {
|
|
554
|
+
"email.inbound.received": InboundReceivedData;
|
|
555
|
+
"email.outbound.sent": OutboundSentData;
|
|
556
|
+
"email.outbound.failed": OutboundFailedData;
|
|
557
|
+
"email.outbound.opened": OutboundOpenedData;
|
|
558
|
+
"email.outbound.clicked": OutboundClickedData;
|
|
559
|
+
"email.outbound.scheduled": OutboundScheduledData;
|
|
560
|
+
"email.outbound.cancelled": OutboundCancelledData;
|
|
561
|
+
"domain.verified": DomainVerifiedData;
|
|
562
|
+
"domain.failed": DomainFailedData;
|
|
563
|
+
"webhook.test": WebhookTestData;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
declare class Domains extends BaseResource {
|
|
567
|
+
/** Register a new domain. */
|
|
568
|
+
create(params: DomainCreateParams): Promise<Domain>;
|
|
569
|
+
/** List all domains. */
|
|
570
|
+
list(): Promise<Domain[]>;
|
|
571
|
+
/** Get a domain by ID. */
|
|
572
|
+
get(domainId: string): Promise<Domain>;
|
|
573
|
+
/** Get DNS setup instructions for a domain. */
|
|
574
|
+
getSetup(domainId: string): Promise<DomainSetup>;
|
|
575
|
+
/** Get live DNS verification status. */
|
|
576
|
+
getDnsStatus(domainId: string, options?: {
|
|
577
|
+
forceRefresh?: boolean;
|
|
578
|
+
}): Promise<DNSVerificationResponse>;
|
|
579
|
+
/** Trigger domain verification. */
|
|
580
|
+
verify(domainId: string, options?: {
|
|
581
|
+
force?: boolean;
|
|
582
|
+
}): Promise<Record<string, unknown>>;
|
|
583
|
+
/** Update domain settings. */
|
|
584
|
+
update(domainId: string, params: DomainUpdateParams): Promise<Domain>;
|
|
585
|
+
/** Delete a domain. */
|
|
586
|
+
delete(domainId: string): Promise<void>;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
declare class Aliases extends BaseResource {
|
|
590
|
+
/** Create a new email alias. */
|
|
591
|
+
create(params: AliasCreateParams): Promise<Alias>;
|
|
592
|
+
/** List aliases, optionally filtered by domain. */
|
|
593
|
+
list(options?: {
|
|
594
|
+
domainId?: string;
|
|
595
|
+
}): Promise<Alias[]>;
|
|
596
|
+
/** Get an alias by ID. */
|
|
597
|
+
get(aliasId: string): Promise<Alias>;
|
|
598
|
+
/** Update an alias. */
|
|
599
|
+
update(aliasId: string, params: AliasUpdateParams): Promise<Alias>;
|
|
600
|
+
/** Delete an alias. */
|
|
601
|
+
delete(aliasId: string): Promise<void>;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
declare class Emails extends BaseResource {
|
|
605
|
+
/** Send an email. */
|
|
606
|
+
send(params: EmailSendParams): Promise<Email>;
|
|
607
|
+
/** List sent emails with optional filters. */
|
|
608
|
+
list(options?: {
|
|
609
|
+
aliasId?: string;
|
|
610
|
+
limit?: number;
|
|
611
|
+
offset?: number;
|
|
612
|
+
}): Promise<Email[]>;
|
|
613
|
+
/** Get a sent email by ID. */
|
|
614
|
+
get(emailId: string): Promise<Email>;
|
|
615
|
+
/** Send a batch of emails. */
|
|
616
|
+
batchSend(emails: EmailSendParams[]): Promise<BatchEmailResponse>;
|
|
617
|
+
/** Cancel a scheduled email. */
|
|
618
|
+
cancel(emailId: string): Promise<Email>;
|
|
619
|
+
/** List click events for an email. */
|
|
620
|
+
listClicks(emailId: string, options?: {
|
|
621
|
+
linkId?: string;
|
|
622
|
+
includeBots?: boolean;
|
|
623
|
+
limit?: number;
|
|
624
|
+
offset?: number;
|
|
625
|
+
}): Promise<EmailClickListResponse>;
|
|
626
|
+
/** List tracked links in an email. */
|
|
627
|
+
listLinks(emailId: string): Promise<TrackedLink[]>;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
declare class InboundEmails extends BaseResource {
|
|
631
|
+
/** List inbound emails with optional filters. */
|
|
632
|
+
list(options?: {
|
|
633
|
+
aliasId?: string;
|
|
634
|
+
tagIds?: string[];
|
|
635
|
+
tagMatch?: "any" | "all";
|
|
636
|
+
limit?: number;
|
|
637
|
+
offset?: number;
|
|
638
|
+
}): Promise<InboundEmailSummary[]>;
|
|
639
|
+
/** Get full details of an inbound email. */
|
|
640
|
+
get(emailId: string): Promise<InboundEmailDetail>;
|
|
641
|
+
/** Download the raw RFC822 email. */
|
|
642
|
+
downloadRaw(emailId: string): Promise<ArrayBuffer>;
|
|
643
|
+
/** Download an attachment by zero-based index. */
|
|
644
|
+
downloadAttachment(emailId: string, index: number): Promise<ArrayBuffer>;
|
|
645
|
+
/** Delete an inbound email. */
|
|
646
|
+
delete(emailId: string): Promise<void>;
|
|
647
|
+
/** Add tags to an inbound email. */
|
|
648
|
+
addTags(emailId: string, tagIds: string[], note?: string | null): Promise<EmailTag[]>;
|
|
649
|
+
/** Get tags for an inbound email. */
|
|
650
|
+
getTags(emailId: string): Promise<EmailTag[]>;
|
|
651
|
+
/** Replace all tags on an inbound email. */
|
|
652
|
+
replaceTags(emailId: string, tagIds: string[], note?: string | null): Promise<EmailTag[]>;
|
|
653
|
+
/** Remove a single tag from an inbound email. */
|
|
654
|
+
removeTag(emailId: string, tagId: string): Promise<void>;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
declare class Conversations extends BaseResource {
|
|
658
|
+
/** List conversation threads with optional filters. */
|
|
659
|
+
list(options?: {
|
|
660
|
+
aliasId?: string;
|
|
661
|
+
domainId?: string;
|
|
662
|
+
limit?: number;
|
|
663
|
+
offset?: number;
|
|
664
|
+
}): Promise<ConversationSummary[]>;
|
|
665
|
+
/** Get a conversation with all messages. */
|
|
666
|
+
get(conversationId: string): Promise<ConversationDetail>;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
declare class Tags extends BaseResource {
|
|
670
|
+
/** Create a new tag. */
|
|
671
|
+
create(params: TagCreateParams): Promise<Tag>;
|
|
672
|
+
/** List tags. */
|
|
673
|
+
list(options?: {
|
|
674
|
+
includeHidden?: boolean;
|
|
675
|
+
}): Promise<Tag[]>;
|
|
676
|
+
/** Get a tag by ID. */
|
|
677
|
+
get(tagId: string): Promise<Tag>;
|
|
678
|
+
/** Update a tag. */
|
|
679
|
+
update(tagId: string, params: TagUpdateParams): Promise<Tag>;
|
|
680
|
+
/** Delete a tag. */
|
|
681
|
+
delete(tagId: string): Promise<void>;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
declare class Webhooks extends BaseResource {
|
|
685
|
+
/** Create a new webhook subscription. Returns secret (shown once). */
|
|
686
|
+
create(params: WebhookCreateParams): Promise<WebhookCreated>;
|
|
687
|
+
/** List all webhooks. */
|
|
688
|
+
list(): Promise<Webhook[]>;
|
|
689
|
+
/** Get a webhook by ID. */
|
|
690
|
+
get(webhookId: string): Promise<Webhook>;
|
|
691
|
+
/** Update a webhook. */
|
|
692
|
+
update(webhookId: string, params: WebhookUpdateParams): Promise<Webhook>;
|
|
693
|
+
/** Delete a webhook. */
|
|
694
|
+
delete(webhookId: string): Promise<void>;
|
|
695
|
+
/** Verify a webhook URL with the verification code. */
|
|
696
|
+
verify(webhookId: string, verificationCode: string): Promise<Webhook>;
|
|
697
|
+
/** Resend the verification code for a webhook. */
|
|
698
|
+
resendVerification(webhookId: string): Promise<Webhook>;
|
|
699
|
+
/** Send a test event to the webhook. */
|
|
700
|
+
test(webhookId: string): Promise<Record<string, unknown>>;
|
|
701
|
+
/** Rotate the webhook's HMAC signing secret. */
|
|
702
|
+
rotateSecret(webhookId: string): Promise<WebhookSecret>;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/** Handler for a specific webhook event. */
|
|
706
|
+
type EventHandler<T = unknown> = (event: WebhookEvent<T>) => void | Promise<void>;
|
|
707
|
+
/** Error callback invoked when a handler throws. */
|
|
708
|
+
type ErrorHandler = (error: unknown, event: WebhookEvent) => void | Promise<void>;
|
|
709
|
+
/** Internal handler map: event type string → array of handler functions. */
|
|
710
|
+
type HandlerMap = Map<string, EventHandler<any>[]>;
|
|
711
|
+
/**
|
|
712
|
+
* Web Standard webhook request handler.
|
|
713
|
+
*
|
|
714
|
+
* Accepts a `Request` and returns a `Response`, making it compatible with
|
|
715
|
+
* Next.js App Router, Hono, Bun, Deno, Cloudflare Workers, and any other
|
|
716
|
+
* runtime that implements the Web Standard `Request`/`Response` API.
|
|
717
|
+
*/
|
|
718
|
+
declare class WebhookRequestHandler {
|
|
719
|
+
private readonly handlers;
|
|
720
|
+
private readonly secret;
|
|
721
|
+
private readonly path;
|
|
722
|
+
private readonly onError?;
|
|
723
|
+
constructor(options: {
|
|
724
|
+
handlers: HandlerMap;
|
|
725
|
+
secret: string;
|
|
726
|
+
path?: string;
|
|
727
|
+
onError?: ErrorHandler;
|
|
728
|
+
});
|
|
729
|
+
/** Handle an incoming Web Standard Request. */
|
|
730
|
+
fetch(request: Request): Promise<Response>;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
interface ListenOptions {
|
|
734
|
+
/** Public URL where Bavimail will send webhooks (triggers auto-create). */
|
|
735
|
+
webhookUrl?: string;
|
|
736
|
+
/** Pre-existing webhook HMAC secret (skip auto-create). */
|
|
737
|
+
secret?: string;
|
|
738
|
+
/** Port to listen on (default: 8000). */
|
|
739
|
+
port?: number;
|
|
740
|
+
/** Host to bind to (default: "0.0.0.0"). */
|
|
741
|
+
host?: string;
|
|
742
|
+
/** URL path for the webhook endpoint (default: "/webhooks"). */
|
|
743
|
+
path?: string;
|
|
744
|
+
/** Delete the auto-created webhook on shutdown (default: true). */
|
|
745
|
+
cleanup?: boolean;
|
|
746
|
+
/** AbortSignal for programmatic shutdown. */
|
|
747
|
+
signal?: AbortSignal;
|
|
748
|
+
/** Error handler for individual handler failures. */
|
|
749
|
+
onError?: ErrorHandler;
|
|
750
|
+
/** Description for the auto-created webhook. */
|
|
751
|
+
description?: string;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
interface BavimailOptions {
|
|
755
|
+
/** Your Bavimail API key. */
|
|
756
|
+
apiKey: string;
|
|
757
|
+
/** Override the base API URL (default: https://api.bavimail.com). */
|
|
758
|
+
baseUrl?: string;
|
|
759
|
+
}
|
|
760
|
+
declare class Bavimail {
|
|
761
|
+
private readonly http;
|
|
762
|
+
private readonly _handlers;
|
|
763
|
+
/** Domain management (register, verify, DNS status). */
|
|
764
|
+
readonly domains: Domains;
|
|
765
|
+
/** Email alias management. */
|
|
766
|
+
readonly aliases: Aliases;
|
|
767
|
+
/** Outbound email sending and tracking. */
|
|
768
|
+
readonly emails: Emails;
|
|
769
|
+
/** Inbound email retrieval and tagging. */
|
|
770
|
+
readonly inboundEmails: InboundEmails;
|
|
771
|
+
/** Conversation thread management. */
|
|
772
|
+
readonly conversations: Conversations;
|
|
773
|
+
/** Tag management for organizing emails. */
|
|
774
|
+
readonly tags: Tags;
|
|
775
|
+
/** Webhook subscription management. */
|
|
776
|
+
readonly webhooks: Webhooks;
|
|
777
|
+
constructor(options: BavimailOptions);
|
|
778
|
+
/** Register a handler for a single event type. */
|
|
779
|
+
on<E extends WebhookEventType>(eventType: E, handler: EventHandler<EventDataMap[E]>): void;
|
|
780
|
+
/** Register a handler for multiple event types. */
|
|
781
|
+
on<E extends WebhookEventType>(eventType: E[], handler: EventHandler<EventDataMap[E]>): void;
|
|
782
|
+
/**
|
|
783
|
+
* Start a standalone HTTP server that receives and dispatches webhook events.
|
|
784
|
+
*
|
|
785
|
+
* If `webhookUrl` is provided, a webhook is auto-created via the API and
|
|
786
|
+
* cleaned up on shutdown. If `secret` is provided instead, the server uses
|
|
787
|
+
* the pre-existing webhook secret directly.
|
|
788
|
+
*/
|
|
789
|
+
listen(options: ListenOptions): Promise<void>;
|
|
790
|
+
/**
|
|
791
|
+
* Create a Web Standard webhook request handler for framework integration.
|
|
792
|
+
*
|
|
793
|
+
* The returned handler's `.fetch(request)` method accepts a `Request` and
|
|
794
|
+
* returns a `Response`, compatible with Next.js App Router, Hono, Bun, Deno,
|
|
795
|
+
* Cloudflare Workers, and similar runtimes.
|
|
796
|
+
*/
|
|
797
|
+
createHandler(options: {
|
|
798
|
+
secret: string;
|
|
799
|
+
path?: string;
|
|
800
|
+
onError?: ErrorHandler;
|
|
801
|
+
}): WebhookRequestHandler;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
declare class BavimailError extends Error {
|
|
805
|
+
constructor(message: string);
|
|
806
|
+
}
|
|
807
|
+
declare class APIError extends BavimailError {
|
|
808
|
+
readonly statusCode: number;
|
|
809
|
+
readonly code: string | null;
|
|
810
|
+
readonly category: string | null;
|
|
811
|
+
readonly context: Record<string, unknown> | null;
|
|
812
|
+
readonly requestId: string | null;
|
|
813
|
+
constructor(message: string, statusCode: number, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
814
|
+
}
|
|
815
|
+
declare class NotFoundError extends APIError {
|
|
816
|
+
constructor(message: string, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
817
|
+
}
|
|
818
|
+
declare class ValidationError extends APIError {
|
|
819
|
+
constructor(message: string, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
820
|
+
}
|
|
821
|
+
declare class ConflictError extends APIError {
|
|
822
|
+
constructor(message: string, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
823
|
+
}
|
|
824
|
+
declare class AuthenticationError extends APIError {
|
|
825
|
+
constructor(message: string, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
826
|
+
}
|
|
827
|
+
declare class ForbiddenError extends APIError {
|
|
828
|
+
constructor(message: string, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
829
|
+
}
|
|
830
|
+
declare class RateLimitError extends APIError {
|
|
831
|
+
constructor(message: string, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
832
|
+
}
|
|
833
|
+
declare class InternalServerError extends APIError {
|
|
834
|
+
constructor(message: string, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
835
|
+
}
|
|
836
|
+
declare class ProviderError extends APIError {
|
|
837
|
+
constructor(message: string, statusCode?: number, code?: string | null, category?: string | null, context?: Record<string, unknown> | null, requestId?: string | null);
|
|
838
|
+
}
|
|
839
|
+
declare class WebhookVerificationError extends BavimailError {
|
|
840
|
+
constructor(message: string);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Async generator that auto-paginates through list endpoints.
|
|
845
|
+
*
|
|
846
|
+
* Usage:
|
|
847
|
+
* ```ts
|
|
848
|
+
* for await (const email of iterPages(
|
|
849
|
+
* (opts) => client.emails.list(opts),
|
|
850
|
+
* { pageSize: 50 }
|
|
851
|
+
* )) {
|
|
852
|
+
* console.log(email.subject);
|
|
853
|
+
* }
|
|
854
|
+
* ```
|
|
855
|
+
*/
|
|
856
|
+
declare function iterPages<T>(method: (params: {
|
|
857
|
+
limit?: number;
|
|
858
|
+
offset?: number;
|
|
859
|
+
}) => Promise<T[]>, options?: {
|
|
860
|
+
pageSize?: number;
|
|
861
|
+
params?: Record<string, unknown>;
|
|
862
|
+
}): AsyncGenerator<T, void, undefined>;
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Verify an incoming webhook signature and parse the event.
|
|
866
|
+
*
|
|
867
|
+
* Uses the Web Crypto API (available in browsers and Node.js 18+).
|
|
868
|
+
*
|
|
869
|
+
* @param payload - Raw request body string
|
|
870
|
+
* @param signature - Value of the `x-webhook-signature` header
|
|
871
|
+
* @param timestamp - Value of the `x-webhook-timestamp` header
|
|
872
|
+
* @param secret - Your webhook HMAC signing secret
|
|
873
|
+
* @param toleranceSeconds - Max age of the timestamp in seconds (default: 300 = 5 min)
|
|
874
|
+
*/
|
|
875
|
+
declare function verifyWebhookSignature<E extends WebhookEventType = WebhookEventType>(payload: string, signature: string, timestamp: string, secret: string, toleranceSeconds?: number): Promise<WebhookEvent<E extends keyof EventDataMap ? EventDataMap[E] : unknown>>;
|
|
876
|
+
|
|
877
|
+
declare const VERSION = "0.1.0";
|
|
878
|
+
|
|
879
|
+
export { APIError, type Alias, type AliasCreateParams, type AliasUpdateParams, type AttachmentCreateParams, type AttachmentMetadata, AuthenticationError, type BatchEmailItemError, type BatchEmailItemResult, type BatchEmailResponse, Bavimail, BavimailError, type BavimailOptions, type BootstrapApiKeyResponse, ConflictError, type ConversationDetail, type ConversationMessage, type ConversationSummary, type DNSRecord, type DNSRecordVerificationStatus, type DNSRecordWithStatus, type DNSVerificationProgress, type DNSVerificationResponse, type Domain, type DomainCreateParams, type DomainFailedData, type DomainSetup, type DomainStatus, type DomainUpdateParams, type DomainVerifiedData, type Email, type EmailClick, type EmailClickListResponse, type EmailProviderKey, type EmailSendParams, type EmailStatus, type EmailTag, type ErrorHandler, type EventDataMap, type EventHandler, ForbiddenError, type InboundAttachmentMetadata, type InboundEmailDetail, type InboundEmailSummary, type InboundReceivedData, type IntegrationInfo, InternalServerError, type ListenOptions, type MailFromStatus, type MailFromStatusInfo, NotFoundError, type OutboundCancelledData, type OutboundClickedData, type OutboundFailedData, type OutboundOpenedData, type OutboundScheduledData, type OutboundSentData, ProviderError, RateLimitError, type RevokeApiKeyResponse, type Tag, type TagCreateParams, type TagSummary, type TagType, type TagUpdateParams, type TaggedBy, type TrackedLink, VERSION, ValidationError, type Verdict, type Webhook, type WebhookCreateParams, type WebhookCreated, type WebhookEvent, type WebhookEventType, WebhookRequestHandler, type WebhookSecret, type WebhookTestData, type WebhookUpdateParams, WebhookVerificationError, iterPages, verifyWebhookSignature };
|