mailbreeze 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.
@@ -0,0 +1,1280 @@
1
+ /**
2
+ * Parameters for creating an attachment upload.
3
+ */
4
+ interface CreateAttachmentUploadParams {
5
+ /** Original filename */
6
+ fileName: string;
7
+ /** MIME type of the file */
8
+ contentType: string;
9
+ /** File size in bytes */
10
+ fileSize: number;
11
+ }
12
+ /**
13
+ * Result of creating an attachment upload.
14
+ */
15
+ interface CreateAttachmentUploadResult {
16
+ /** Attachment ID to use when sending emails */
17
+ attachmentId: string;
18
+ /** Presigned URL for uploading the file */
19
+ uploadUrl: string;
20
+ /** Upload token for confirmation */
21
+ uploadToken: string;
22
+ /** Expiration time for the upload URL */
23
+ expiresAt: string;
24
+ }
25
+ /**
26
+ * Parameters for confirming an attachment upload.
27
+ */
28
+ interface ConfirmAttachmentParams {
29
+ /** Upload token received from createUpload */
30
+ uploadToken: string;
31
+ }
32
+ /**
33
+ * Attachment record.
34
+ */
35
+ interface Attachment {
36
+ id: string;
37
+ fileName: string;
38
+ contentType: string;
39
+ fileSize: number;
40
+ status: "pending" | "uploaded" | "expired";
41
+ createdAt: string;
42
+ expiresAt: string;
43
+ }
44
+
45
+ /**
46
+ * Pagination information returned with list endpoints.
47
+ */
48
+ interface Pagination {
49
+ page: number;
50
+ limit: number;
51
+ total: number;
52
+ totalPages: number;
53
+ hasNext: boolean;
54
+ hasPrev: boolean;
55
+ }
56
+ /**
57
+ * Paginated list response.
58
+ */
59
+ interface PaginatedList<T> {
60
+ data: T[];
61
+ pagination: Pagination;
62
+ }
63
+ /**
64
+ * Common query parameters for list endpoints.
65
+ */
66
+ interface ListParams {
67
+ page?: number;
68
+ limit?: number;
69
+ }
70
+ /**
71
+ * SDK configuration options.
72
+ */
73
+ interface MailBreezeConfig {
74
+ /** Your MailBreeze API key (starts with sk_) */
75
+ apiKey: string;
76
+ /** Base URL for the API (defaults to https://api.mailbreeze.com) */
77
+ baseUrl?: string;
78
+ /** Request timeout in milliseconds (defaults to 30000) */
79
+ timeout?: number;
80
+ /** Maximum number of retries for failed requests (defaults to 3) */
81
+ maxRetries?: number;
82
+ /** Authentication style: 'header' uses X-API-Key, 'bearer' uses Authorization header */
83
+ authStyle?: "header" | "bearer";
84
+ }
85
+ /**
86
+ * Domain context header for multi-tenant operations.
87
+ */
88
+ interface DomainContext {
89
+ domainId: string;
90
+ }
91
+
92
+ /**
93
+ * Parameters for enrolling a contact in an automation.
94
+ */
95
+ interface EnrollParams {
96
+ /** Automation ID to enroll in */
97
+ automationId: string;
98
+ /** Contact ID to enroll */
99
+ contactId: string;
100
+ /** Optional variables to pass to the automation */
101
+ variables?: Record<string, unknown>;
102
+ }
103
+ /**
104
+ * Result of enrolling a contact.
105
+ */
106
+ interface EnrollResult {
107
+ /** Enrollment ID */
108
+ enrollmentId: string;
109
+ /** Current status */
110
+ status: "active" | "paused" | "completed" | "cancelled";
111
+ /** When enrolled */
112
+ enrolledAt: string;
113
+ }
114
+ /**
115
+ * Enrollment record.
116
+ */
117
+ interface Enrollment {
118
+ id: string;
119
+ automationId: string;
120
+ automationName: string;
121
+ contactId: string;
122
+ contactEmail: string;
123
+ status: "active" | "paused" | "completed" | "cancelled";
124
+ currentStep: number;
125
+ totalSteps: number;
126
+ variables?: Record<string, unknown>;
127
+ enrolledAt: string;
128
+ completedAt?: string;
129
+ cancelledAt?: string;
130
+ }
131
+ /**
132
+ * Parameters for listing enrollments.
133
+ */
134
+ interface ListEnrollmentsParams extends ListParams {
135
+ /** Filter by automation ID */
136
+ automationId?: string;
137
+ /** Filter by status */
138
+ status?: "active" | "paused" | "completed" | "cancelled";
139
+ }
140
+ /**
141
+ * Result of cancelling an enrollment.
142
+ */
143
+ interface CancelEnrollmentResult {
144
+ /** Whether cancellation was successful */
145
+ cancelled: boolean;
146
+ /** Cancellation timestamp */
147
+ cancelledAt: string;
148
+ }
149
+
150
+ /**
151
+ * Parameters for creating a contact.
152
+ */
153
+ interface CreateContactParams {
154
+ /** Contact's email address */
155
+ email: string;
156
+ /** First name */
157
+ firstName?: string;
158
+ /** Last name */
159
+ lastName?: string;
160
+ /** Phone number */
161
+ phoneNumber?: string;
162
+ /** Custom fields defined in the contact list */
163
+ customFields?: Record<string, unknown>;
164
+ /** Source of the contact (e.g., 'api', 'import', 'form') */
165
+ source?: string;
166
+ }
167
+ /**
168
+ * Parameters for updating a contact.
169
+ */
170
+ interface UpdateContactParams {
171
+ /** First name */
172
+ firstName?: string;
173
+ /** Last name */
174
+ lastName?: string;
175
+ /** Phone number */
176
+ phoneNumber?: string;
177
+ /** Custom fields defined in the contact list */
178
+ customFields?: Record<string, unknown>;
179
+ }
180
+ /**
181
+ * Contact record.
182
+ */
183
+ interface Contact {
184
+ id: string;
185
+ email: string;
186
+ firstName?: string;
187
+ lastName?: string;
188
+ phoneNumber?: string;
189
+ customFields?: Record<string, unknown>;
190
+ status: "active" | "unsubscribed" | "bounced" | "complained" | "suppressed";
191
+ source: string;
192
+ createdAt: string;
193
+ updatedAt: string;
194
+ subscribedAt?: string;
195
+ unsubscribedAt?: string;
196
+ }
197
+ /**
198
+ * Parameters for listing contacts.
199
+ */
200
+ interface ListContactsParams extends ListParams {
201
+ /** Filter by status */
202
+ status?: "active" | "unsubscribed" | "bounced" | "complained" | "suppressed";
203
+ }
204
+ /**
205
+ * Reason for suppressing a contact.
206
+ */
207
+ type SuppressReason = "manual" | "unsubscribed" | "bounced" | "complained" | "spam_trap";
208
+
209
+ /**
210
+ * Parameters for sending an email.
211
+ */
212
+ interface SendEmailParams {
213
+ /** Sender email address (must match verified domain) */
214
+ from: string;
215
+ /** Recipient email address(es) */
216
+ to: string | string[];
217
+ /** Email subject line */
218
+ subject?: string;
219
+ /** HTML content of the email */
220
+ html?: string;
221
+ /** Plain text content of the email */
222
+ text?: string;
223
+ /** Template ID to use instead of raw content */
224
+ templateId?: string;
225
+ /** Variables to substitute in the template */
226
+ variables?: Record<string, unknown>;
227
+ /** IDs of uploaded attachments to include */
228
+ attachmentIds?: string[];
229
+ /** Optional CC recipients */
230
+ cc?: string | string[];
231
+ /** Optional BCC recipients */
232
+ bcc?: string | string[];
233
+ /** Optional reply-to address */
234
+ replyTo?: string;
235
+ /** Custom headers to include */
236
+ headers?: Record<string, string>;
237
+ /** Idempotency key for safe retries */
238
+ idempotencyKey?: string;
239
+ }
240
+ /**
241
+ * Result of sending an email.
242
+ */
243
+ interface SendEmailResult {
244
+ /** Unique email ID */
245
+ id: string;
246
+ /** Current status */
247
+ status: "queued" | "sent" | "delivered" | "bounced" | "failed";
248
+ /** Message ID (SMTP) */
249
+ messageId?: string;
250
+ /** Timestamp when queued */
251
+ createdAt: string;
252
+ }
253
+ /**
254
+ * Email record returned from list/get.
255
+ */
256
+ interface Email {
257
+ id: string;
258
+ from: string;
259
+ to: string[];
260
+ cc?: string[];
261
+ bcc?: string[];
262
+ subject: string;
263
+ status: "queued" | "sent" | "delivered" | "bounced" | "failed";
264
+ messageId?: string;
265
+ templateId?: string;
266
+ createdAt: string;
267
+ sentAt?: string;
268
+ deliveredAt?: string;
269
+ openedAt?: string;
270
+ clickedAt?: string;
271
+ }
272
+ /**
273
+ * Parameters for listing emails.
274
+ */
275
+ interface ListEmailsParams extends ListParams {
276
+ /** Filter by status */
277
+ status?: "queued" | "sent" | "delivered" | "bounced" | "failed";
278
+ /** Filter by recipient email */
279
+ to?: string;
280
+ /** Filter by sender email */
281
+ from?: string;
282
+ /** Filter by date range start */
283
+ startDate?: string;
284
+ /** Filter by date range end */
285
+ endDate?: string;
286
+ }
287
+ /**
288
+ * Email statistics.
289
+ */
290
+ interface EmailStats {
291
+ sent: number;
292
+ delivered: number;
293
+ bounced: number;
294
+ opened: number;
295
+ clicked: number;
296
+ complained: number;
297
+ deliveryRate: number;
298
+ openRate: number;
299
+ clickRate: number;
300
+ bounceRate: number;
301
+ }
302
+
303
+ /**
304
+ * Parameters for creating a contact list.
305
+ */
306
+ interface CreateListParams {
307
+ /** List name */
308
+ name: string;
309
+ /** Optional description */
310
+ description?: string;
311
+ /** Custom field definitions */
312
+ customFields?: CustomFieldDefinition[];
313
+ }
314
+ /**
315
+ * Parameters for updating a contact list.
316
+ */
317
+ interface UpdateListParams {
318
+ /** List name */
319
+ name?: string;
320
+ /** Optional description */
321
+ description?: string;
322
+ /** Custom field definitions */
323
+ customFields?: CustomFieldDefinition[];
324
+ }
325
+ /**
326
+ * Custom field definition for a contact list.
327
+ */
328
+ interface CustomFieldDefinition {
329
+ /** Field key (used in API) */
330
+ key: string;
331
+ /** Display label */
332
+ label: string;
333
+ /** Field type */
334
+ type: "text" | "number" | "date" | "boolean" | "select";
335
+ /** Whether field is required */
336
+ required?: boolean;
337
+ /** Default value */
338
+ defaultValue?: unknown;
339
+ /** Options for select type */
340
+ options?: string[];
341
+ }
342
+ /**
343
+ * Contact list record.
344
+ */
345
+ interface ContactList {
346
+ id: string;
347
+ name: string;
348
+ description?: string;
349
+ customFields: CustomFieldDefinition[];
350
+ contactCount: number;
351
+ createdAt: string;
352
+ updatedAt: string;
353
+ }
354
+ /**
355
+ * Parameters for listing contact lists.
356
+ */
357
+ type ListListsParams = ListParams;
358
+ /**
359
+ * Contact list statistics.
360
+ */
361
+ interface ListStats {
362
+ totalContacts: number;
363
+ activeContacts: number;
364
+ unsubscribedContacts: number;
365
+ bouncedContacts: number;
366
+ complainedContacts: number;
367
+ suppressedContacts: number;
368
+ }
369
+
370
+ /**
371
+ * Result of verifying a single email.
372
+ */
373
+ interface VerifyEmailResult {
374
+ /** The email address that was verified */
375
+ email: string;
376
+ /** Whether the email is valid and deliverable */
377
+ isValid: boolean;
378
+ /** Detailed result category */
379
+ result: "valid" | "invalid" | "risky" | "unknown";
380
+ /** Reason for the result */
381
+ reason: string;
382
+ /** Whether this was a cached result */
383
+ cached: boolean;
384
+ /** Risk score (0-100, lower is better) */
385
+ riskScore?: number;
386
+ /** Additional details */
387
+ details?: {
388
+ isFreeProvider?: boolean;
389
+ isDisposable?: boolean;
390
+ isRoleAccount?: boolean;
391
+ hasMxRecords?: boolean;
392
+ isSpamTrap?: boolean;
393
+ };
394
+ }
395
+ /**
396
+ * Parameters for batch verification.
397
+ */
398
+ interface BatchVerifyParams {
399
+ /** Array of email addresses to verify (max 1000) */
400
+ emails: string[];
401
+ }
402
+ /**
403
+ * Result of starting a batch verification.
404
+ */
405
+ interface BatchVerifyResult {
406
+ /** Verification batch ID for polling */
407
+ verificationId: string;
408
+ /** Total emails in batch */
409
+ totalEmails: number;
410
+ /** Credits deducted for this batch */
411
+ creditsDeducted: number;
412
+ /** Current status */
413
+ status: "pending" | "processing" | "completed" | "failed";
414
+ /** Results (only populated when all emails are cached) */
415
+ results?: VerifyEmailResult[];
416
+ }
417
+ /**
418
+ * Batch verification status response.
419
+ */
420
+ interface VerificationStatus {
421
+ id: string;
422
+ status: "pending" | "processing" | "completed" | "failed";
423
+ totalEmails: number;
424
+ processedEmails: number;
425
+ creditsDeducted: number;
426
+ createdAt: string;
427
+ completedAt?: string;
428
+ /** Results when completed */
429
+ results?: VerifyEmailResult[];
430
+ /** Analytics summary when completed */
431
+ analytics?: {
432
+ valid: number;
433
+ invalid: number;
434
+ risky: number;
435
+ unknown: number;
436
+ };
437
+ }
438
+ /**
439
+ * Parameters for listing verifications.
440
+ */
441
+ interface ListVerificationsParams extends ListParams {
442
+ /** Filter by status */
443
+ status?: "pending" | "processing" | "completed" | "failed";
444
+ }
445
+ /**
446
+ * Verification statistics.
447
+ */
448
+ interface VerificationStats {
449
+ totalVerified: number;
450
+ valid: number;
451
+ invalid: number;
452
+ risky: number;
453
+ unknown: number;
454
+ cached: number;
455
+ creditsUsed: number;
456
+ }
457
+
458
+ interface FetcherConfig {
459
+ apiKey: string;
460
+ baseUrl: string;
461
+ timeout: number;
462
+ maxRetries: number;
463
+ authStyle?: "header" | "bearer";
464
+ }
465
+ interface RequestOptions {
466
+ idempotencyKey?: string;
467
+ timeout?: number;
468
+ }
469
+ /**
470
+ * HTTP client for making requests to the MailBreeze API.
471
+ * Handles authentication, retries, timeouts, and error mapping.
472
+ */
473
+ declare class Fetcher {
474
+ private readonly config;
475
+ constructor(config: FetcherConfig);
476
+ /**
477
+ * Make an HTTP request to the API.
478
+ *
479
+ * @param method - HTTP method
480
+ * @param path - API path (will be appended to baseUrl)
481
+ * @param body - Request body (for POST/PUT/PATCH)
482
+ * @param query - Query parameters
483
+ * @param options - Additional request options
484
+ * @returns Parsed response data
485
+ */
486
+ request<T>(method: string, path: string, body?: Record<string, unknown>, query?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
487
+ private executeRequest;
488
+ private handleResponse;
489
+ private buildUrl;
490
+ private buildHeaders;
491
+ private isRetryable;
492
+ private getRetryDelay;
493
+ private sleep;
494
+ }
495
+
496
+ /**
497
+ * Base class for all API resources.
498
+ * Provides common functionality for making API requests.
499
+ */
500
+ declare abstract class BaseResource {
501
+ protected readonly fetcher: Fetcher;
502
+ protected readonly domainId?: string;
503
+ constructor(fetcher: Fetcher, domainId?: string);
504
+ /**
505
+ * Make a GET request.
506
+ */
507
+ protected _get<T>(path: string, query?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
508
+ /**
509
+ * Make a POST request.
510
+ */
511
+ protected _post<T>(path: string, body?: object, query?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
512
+ /**
513
+ * Make a PUT request.
514
+ */
515
+ protected _put<T>(path: string, body?: object, query?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
516
+ /**
517
+ * Make a PATCH request.
518
+ */
519
+ protected _patch<T>(path: string, body?: object, query?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
520
+ /**
521
+ * Make a DELETE request.
522
+ */
523
+ protected _delete<T>(path: string, query?: Record<string, unknown>, options?: RequestOptions): Promise<T>;
524
+ /**
525
+ * Build the full path including any base path for the resource.
526
+ */
527
+ protected buildPath(path: string): string;
528
+ /**
529
+ * Add domain ID to query params if configured.
530
+ */
531
+ private addDomainId;
532
+ /**
533
+ * Helper to extract pagination from list response.
534
+ */
535
+ protected extractPaginatedList<T>(response: {
536
+ data: T[];
537
+ pagination: PaginatedList<T>["pagination"];
538
+ } | T[]): PaginatedList<T>;
539
+ /**
540
+ * Convert list params to query object.
541
+ */
542
+ protected listParamsToQuery(params?: ListParams): Record<string, unknown> | undefined;
543
+ }
544
+
545
+ /**
546
+ * Email attachment handling.
547
+ *
548
+ * Attachments use a two-step process:
549
+ * 1. Create an upload URL with `createUpload()`
550
+ * 2. Upload the file directly to the URL
551
+ * 3. Confirm the upload with `confirm()`
552
+ * 4. Use the attachment ID when sending emails
553
+ *
554
+ * @example
555
+ * ```ts
556
+ * // Create upload
557
+ * const { attachmentId, uploadUrl, uploadToken } = await mailbreeze.attachments.createUpload({
558
+ * fileName: "report.pdf",
559
+ * contentType: "application/pdf",
560
+ * fileSize: 1024000,
561
+ * });
562
+ *
563
+ * // Upload file directly
564
+ * await fetch(uploadUrl, {
565
+ * method: "PUT",
566
+ * body: fileBuffer,
567
+ * headers: { "Content-Type": "application/pdf" },
568
+ * });
569
+ *
570
+ * // Confirm upload
571
+ * const attachment = await mailbreeze.attachments.confirm({
572
+ * uploadToken,
573
+ * });
574
+ *
575
+ * // Use in email
576
+ * await mailbreeze.emails.send({
577
+ * from: "hello@yourdomain.com",
578
+ * to: "user@example.com",
579
+ * subject: "Your report",
580
+ * html: "<p>Please find the report attached.</p>",
581
+ * attachmentIds: [attachmentId],
582
+ * });
583
+ * ```
584
+ */
585
+ declare class Attachments extends BaseResource {
586
+ /**
587
+ * Create a presigned URL for uploading an attachment.
588
+ *
589
+ * @param params - Attachment metadata
590
+ * @returns Upload URL and attachment ID
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * const { attachmentId, uploadUrl, uploadToken, expiresAt } =
595
+ * await mailbreeze.attachments.createUpload({
596
+ * fileName: "document.pdf",
597
+ * contentType: "application/pdf",
598
+ * fileSize: 2048000,
599
+ * });
600
+ * ```
601
+ */
602
+ createUpload(params: CreateAttachmentUploadParams): Promise<CreateAttachmentUploadResult>;
603
+ /**
604
+ * Confirm that an attachment has been uploaded.
605
+ *
606
+ * Must be called after uploading the file to the presigned URL.
607
+ * The attachment is only available for use after confirmation.
608
+ *
609
+ * @param params - Confirmation parameters including upload token
610
+ * @returns Confirmed attachment record
611
+ *
612
+ * @example
613
+ * ```ts
614
+ * const attachment = await mailbreeze.attachments.confirm({
615
+ * uploadToken: "token_xxx",
616
+ * });
617
+ * console.log(attachment.status); // "uploaded"
618
+ * ```
619
+ */
620
+ confirm(params: ConfirmAttachmentParams): Promise<Attachment>;
621
+ }
622
+
623
+ /**
624
+ * Automation enrollment management.
625
+ *
626
+ * Enroll contacts in automations, list enrollments, and cancel them.
627
+ *
628
+ * @example
629
+ * ```ts
630
+ * // Enroll a contact
631
+ * const enrollment = await mailbreeze.automations.enroll({
632
+ * automationId: "auto_xxx",
633
+ * contactId: "contact_xxx",
634
+ * variables: { couponCode: "WELCOME10" },
635
+ * });
636
+ *
637
+ * // List active enrollments
638
+ * const { data } = await mailbreeze.automations.enrollments.list({
639
+ * status: "active",
640
+ * });
641
+ * ```
642
+ */
643
+ declare class Automations extends BaseResource {
644
+ /**
645
+ * Enrollments sub-resource for listing and cancelling.
646
+ */
647
+ readonly enrollments: AutomationEnrollments;
648
+ constructor(fetcher: Fetcher, domainId?: string);
649
+ /**
650
+ * Enroll a contact in an automation.
651
+ *
652
+ * @param params - Enrollment parameters
653
+ * @returns Enrollment result
654
+ *
655
+ * @example
656
+ * ```ts
657
+ * const enrollment = await mailbreeze.automations.enroll({
658
+ * automationId: "auto_welcome",
659
+ * contactId: "contact_xxx",
660
+ * variables: { firstName: "John" },
661
+ * });
662
+ * console.log(enrollment.enrollmentId);
663
+ * ```
664
+ */
665
+ enroll(params: EnrollParams): Promise<EnrollResult>;
666
+ }
667
+ /**
668
+ * Automation enrollments sub-resource.
669
+ */
670
+ declare class AutomationEnrollments extends BaseResource {
671
+ /**
672
+ * List automation enrollments.
673
+ *
674
+ * @param params - Filter and pagination options
675
+ * @returns Paginated list of enrollments
676
+ *
677
+ * @example
678
+ * ```ts
679
+ * const { data, pagination } = await mailbreeze.automations.enrollments.list({
680
+ * automationId: "auto_xxx",
681
+ * status: "active",
682
+ * });
683
+ * ```
684
+ */
685
+ list(params?: ListEnrollmentsParams): Promise<PaginatedList<Enrollment>>;
686
+ /**
687
+ * Cancel an enrollment.
688
+ *
689
+ * The contact will stop receiving emails from this automation.
690
+ *
691
+ * @param enrollmentId - Enrollment ID
692
+ * @returns Cancellation result
693
+ *
694
+ * @example
695
+ * ```ts
696
+ * const result = await mailbreeze.automations.enrollments.cancel("enroll_xxx");
697
+ * console.log(result.cancelled); // true
698
+ * ```
699
+ */
700
+ cancel(enrollmentId: string): Promise<CancelEnrollmentResult>;
701
+ }
702
+
703
+ /**
704
+ * Contact management within a list.
705
+ *
706
+ * All contact operations require a list context. Get a contacts instance
707
+ * by calling `mailbreeze.contacts(listId)`.
708
+ *
709
+ * @example
710
+ * ```ts
711
+ * const contacts = mailbreeze.contacts("list_xxx");
712
+ *
713
+ * // Create a contact
714
+ * const contact = await contacts.create({
715
+ * email: "user@example.com",
716
+ * firstName: "John",
717
+ * lastName: "Doe",
718
+ * customFields: { company: "Acme Inc" },
719
+ * });
720
+ *
721
+ * // List contacts
722
+ * const { data, pagination } = await contacts.list({ status: "active" });
723
+ * ```
724
+ */
725
+ declare class Contacts extends BaseResource {
726
+ private readonly listId;
727
+ constructor(fetcher: Fetcher, listId: string, domainId?: string);
728
+ protected buildPath(path: string): string;
729
+ /**
730
+ * Create a new contact in the list.
731
+ *
732
+ * @param params - Contact data
733
+ * @returns Created contact record
734
+ *
735
+ * @example
736
+ * ```ts
737
+ * const contact = await contacts.create({
738
+ * email: "user@example.com",
739
+ * firstName: "Jane",
740
+ * lastName: "Smith",
741
+ * customFields: { plan: "pro" },
742
+ * });
743
+ * ```
744
+ */
745
+ create(params: CreateContactParams): Promise<Contact>;
746
+ /**
747
+ * List contacts in the list.
748
+ *
749
+ * @param params - Filter and pagination options
750
+ * @returns Paginated list of contacts
751
+ *
752
+ * @example
753
+ * ```ts
754
+ * const { data, pagination } = await contacts.list({
755
+ * status: "active",
756
+ * page: 1,
757
+ * limit: 50,
758
+ * });
759
+ * ```
760
+ */
761
+ list(params?: ListContactsParams): Promise<PaginatedList<Contact>>;
762
+ /**
763
+ * Get a contact by ID.
764
+ *
765
+ * @param id - Contact ID
766
+ * @returns Contact record
767
+ *
768
+ * @example
769
+ * ```ts
770
+ * const contact = await contacts.get("contact_xxx");
771
+ * ```
772
+ */
773
+ get(id: string): Promise<Contact>;
774
+ /**
775
+ * Update a contact.
776
+ *
777
+ * @param id - Contact ID
778
+ * @param params - Fields to update
779
+ * @returns Updated contact record
780
+ *
781
+ * @example
782
+ * ```ts
783
+ * const contact = await contacts.update("contact_xxx", {
784
+ * firstName: "Updated Name",
785
+ * customFields: { plan: "enterprise" },
786
+ * });
787
+ * ```
788
+ */
789
+ update(id: string, params: UpdateContactParams): Promise<Contact>;
790
+ /**
791
+ * Delete a contact.
792
+ *
793
+ * @param id - Contact ID
794
+ * @returns void
795
+ *
796
+ * @example
797
+ * ```ts
798
+ * await contacts.delete("contact_xxx");
799
+ * ```
800
+ */
801
+ delete(id: string): Promise<void>;
802
+ /**
803
+ * Suppress a contact.
804
+ *
805
+ * Suppressed contacts will not receive any emails.
806
+ * This is different from unsubscribing - suppression is
807
+ * typically used for bounces, complaints, or manual removal.
808
+ *
809
+ * @param id - Contact ID
810
+ * @param reason - Reason for suppression
811
+ * @returns void
812
+ *
813
+ * @example
814
+ * ```ts
815
+ * await contacts.suppress("contact_xxx", "manual");
816
+ * ```
817
+ */
818
+ suppress(id: string, reason: SuppressReason): Promise<void>;
819
+ }
820
+
821
+ /**
822
+ * Email sending and management.
823
+ *
824
+ * @example
825
+ * ```ts
826
+ * // Send an email
827
+ * const result = await mailbreeze.emails.send({
828
+ * from: "hello@yourdomain.com",
829
+ * to: "user@example.com",
830
+ * subject: "Welcome!",
831
+ * html: "<h1>Welcome to our platform!</h1>",
832
+ * });
833
+ *
834
+ * // Send with a template
835
+ * const result = await mailbreeze.emails.send({
836
+ * from: "hello@yourdomain.com",
837
+ * to: "user@example.com",
838
+ * templateId: "welcome-template",
839
+ * variables: { name: "John", plan: "Pro" },
840
+ * });
841
+ * ```
842
+ */
843
+ declare class Emails extends BaseResource {
844
+ /**
845
+ * Send an email.
846
+ *
847
+ * @param params - Email parameters
848
+ * @returns Send result with email ID and status
849
+ *
850
+ * @example
851
+ * ```ts
852
+ * const result = await mailbreeze.emails.send({
853
+ * from: "hello@yourdomain.com",
854
+ * to: "user@example.com",
855
+ * subject: "Hello",
856
+ * html: "<p>Hello World!</p>",
857
+ * });
858
+ * console.log(result.id); // email_xxx
859
+ * ```
860
+ */
861
+ send(params: SendEmailParams): Promise<SendEmailResult>;
862
+ /**
863
+ * List sent emails with optional filtering.
864
+ *
865
+ * @param params - Filter and pagination options
866
+ * @returns Paginated list of emails
867
+ *
868
+ * @example
869
+ * ```ts
870
+ * const { data, pagination } = await mailbreeze.emails.list({
871
+ * status: "delivered",
872
+ * page: 1,
873
+ * limit: 20,
874
+ * });
875
+ * ```
876
+ */
877
+ list(params?: ListEmailsParams): Promise<PaginatedList<Email>>;
878
+ /**
879
+ * Get a single email by ID.
880
+ *
881
+ * @param id - Email ID
882
+ * @returns Email record
883
+ *
884
+ * @example
885
+ * ```ts
886
+ * const email = await mailbreeze.emails.get("email_xxx");
887
+ * console.log(email.status); // "delivered"
888
+ * ```
889
+ */
890
+ get(id: string): Promise<Email>;
891
+ /**
892
+ * Get email statistics for the domain.
893
+ *
894
+ * @returns Email statistics including delivery rates
895
+ *
896
+ * @example
897
+ * ```ts
898
+ * const stats = await mailbreeze.emails.stats();
899
+ * console.log(stats.deliveryRate); // 0.98
900
+ * ```
901
+ */
902
+ stats(): Promise<EmailStats>;
903
+ }
904
+
905
+ /**
906
+ * Contact list management.
907
+ *
908
+ * @example
909
+ * ```ts
910
+ * // Create a list
911
+ * const list = await mailbreeze.lists.create({
912
+ * name: "Newsletter Subscribers",
913
+ * description: "Weekly newsletter recipients",
914
+ * customFields: [
915
+ * { key: "company", label: "Company", type: "text" },
916
+ * { key: "plan", label: "Plan", type: "select", options: ["free", "pro", "enterprise"] },
917
+ * ],
918
+ * });
919
+ *
920
+ * // Get list stats
921
+ * const stats = await mailbreeze.lists.stats(list.id);
922
+ * console.log(stats.activeContacts);
923
+ * ```
924
+ */
925
+ declare class Lists extends BaseResource {
926
+ /**
927
+ * Create a new contact list.
928
+ *
929
+ * @param params - List configuration
930
+ * @returns Created list record
931
+ *
932
+ * @example
933
+ * ```ts
934
+ * const list = await mailbreeze.lists.create({
935
+ * name: "VIP Customers",
936
+ * customFields: [
937
+ * { key: "tier", label: "Tier", type: "select", options: ["gold", "platinum"] },
938
+ * ],
939
+ * });
940
+ * ```
941
+ */
942
+ create(params: CreateListParams): Promise<ContactList>;
943
+ /**
944
+ * List all contact lists.
945
+ *
946
+ * @param params - Pagination options
947
+ * @returns Paginated list of contact lists
948
+ *
949
+ * @example
950
+ * ```ts
951
+ * const { data, pagination } = await mailbreeze.lists.list({ page: 1, limit: 10 });
952
+ * ```
953
+ */
954
+ list(params?: ListListsParams): Promise<PaginatedList<ContactList>>;
955
+ /**
956
+ * Get a contact list by ID.
957
+ *
958
+ * @param id - List ID
959
+ * @returns Contact list record
960
+ *
961
+ * @example
962
+ * ```ts
963
+ * const list = await mailbreeze.lists.get("list_xxx");
964
+ * ```
965
+ */
966
+ get(id: string): Promise<ContactList>;
967
+ /**
968
+ * Update a contact list.
969
+ *
970
+ * @param id - List ID
971
+ * @param params - Fields to update
972
+ * @returns Updated list record
973
+ *
974
+ * @example
975
+ * ```ts
976
+ * const list = await mailbreeze.lists.update("list_xxx", {
977
+ * name: "Updated List Name",
978
+ * });
979
+ * ```
980
+ */
981
+ update(id: string, params: UpdateListParams): Promise<ContactList>;
982
+ /**
983
+ * Delete a contact list.
984
+ *
985
+ * Warning: This will also delete all contacts in the list.
986
+ *
987
+ * @param id - List ID
988
+ * @returns void
989
+ *
990
+ * @example
991
+ * ```ts
992
+ * await mailbreeze.lists.delete("list_xxx");
993
+ * ```
994
+ */
995
+ delete(id: string): Promise<void>;
996
+ /**
997
+ * Get statistics for a contact list.
998
+ *
999
+ * @param id - List ID
1000
+ * @returns List statistics
1001
+ *
1002
+ * @example
1003
+ * ```ts
1004
+ * const stats = await mailbreeze.lists.stats("list_xxx");
1005
+ * console.log(`Active: ${stats.activeContacts}, Bounced: ${stats.bouncedContacts}`);
1006
+ * ```
1007
+ */
1008
+ stats(id: string): Promise<ListStats>;
1009
+ }
1010
+
1011
+ /**
1012
+ * Email verification services.
1013
+ *
1014
+ * Verify email addresses before sending to reduce bounces
1015
+ * and protect sender reputation.
1016
+ *
1017
+ * @example
1018
+ * ```ts
1019
+ * // Verify a single email
1020
+ * const result = await mailbreeze.verification.verify("user@example.com");
1021
+ * if (result.isValid) {
1022
+ * // Safe to send
1023
+ * }
1024
+ *
1025
+ * // Batch verification
1026
+ * const batch = await mailbreeze.verification.batch({
1027
+ * emails: ["user1@example.com", "user2@example.com"],
1028
+ * });
1029
+ *
1030
+ * // Poll for results
1031
+ * const status = await mailbreeze.verification.get(batch.verificationId);
1032
+ * ```
1033
+ */
1034
+ declare class Verification extends BaseResource {
1035
+ /**
1036
+ * Verify a single email address.
1037
+ *
1038
+ * This is a synchronous operation - the result is returned immediately.
1039
+ * Results are cached for 24 hours.
1040
+ *
1041
+ * @param email - Email address to verify
1042
+ * @returns Verification result
1043
+ *
1044
+ * @example
1045
+ * ```ts
1046
+ * const result = await mailbreeze.verification.verify("test@example.com");
1047
+ * console.log(result.isValid); // true
1048
+ * console.log(result.result); // "valid"
1049
+ * console.log(result.details?.isDisposable); // false
1050
+ * ```
1051
+ */
1052
+ verify(email: string): Promise<VerifyEmailResult>;
1053
+ /**
1054
+ * Start batch verification.
1055
+ *
1056
+ * Submits a batch of emails for verification. For large batches,
1057
+ * results are processed asynchronously - poll with `get()` for status.
1058
+ *
1059
+ * If all emails are cached, results are returned immediately.
1060
+ *
1061
+ * @param params - Batch parameters including emails array
1062
+ * @returns Batch verification result with ID for polling
1063
+ *
1064
+ * @example
1065
+ * ```ts
1066
+ * const batch = await mailbreeze.verification.batch({
1067
+ * emails: ["user1@example.com", "user2@example.com", "user3@example.com"],
1068
+ * });
1069
+ *
1070
+ * if (batch.results) {
1071
+ * // All cached - results available immediately
1072
+ * console.log(batch.results);
1073
+ * } else {
1074
+ * // Poll for results
1075
+ * const status = await mailbreeze.verification.get(batch.verificationId);
1076
+ * }
1077
+ * ```
1078
+ */
1079
+ batch(params: BatchVerifyParams): Promise<BatchVerifyResult>;
1080
+ /**
1081
+ * Get verification batch status and results.
1082
+ *
1083
+ * @param verificationId - Verification batch ID
1084
+ * @returns Current status and results when complete
1085
+ *
1086
+ * @example
1087
+ * ```ts
1088
+ * const status = await mailbreeze.verification.get("ver_xxx");
1089
+ * if (status.status === "completed") {
1090
+ * console.log(status.results);
1091
+ * console.log(status.analytics);
1092
+ * }
1093
+ * ```
1094
+ */
1095
+ get(verificationId: string): Promise<VerificationStatus>;
1096
+ /**
1097
+ * List verification batches.
1098
+ *
1099
+ * @param params - Filter and pagination options
1100
+ * @returns Paginated list of verification batches
1101
+ *
1102
+ * @example
1103
+ * ```ts
1104
+ * const { data, pagination } = await mailbreeze.verification.list({
1105
+ * status: "completed",
1106
+ * page: 1,
1107
+ * });
1108
+ * ```
1109
+ */
1110
+ list(params?: ListVerificationsParams): Promise<PaginatedList<VerificationStatus>>;
1111
+ /**
1112
+ * Get verification statistics.
1113
+ *
1114
+ * @returns Aggregate verification stats
1115
+ *
1116
+ * @example
1117
+ * ```ts
1118
+ * const stats = await mailbreeze.verification.stats();
1119
+ * console.log(`Verified: ${stats.totalVerified}, Valid: ${stats.valid}`);
1120
+ * ```
1121
+ */
1122
+ stats(): Promise<VerificationStats>;
1123
+ }
1124
+
1125
+ /**
1126
+ * MailBreeze SDK client.
1127
+ *
1128
+ * Create a client with your API key to access all MailBreeze APIs.
1129
+ *
1130
+ * @example
1131
+ * ```ts
1132
+ * import { MailBreeze } from "mailbreeze";
1133
+ *
1134
+ * const mailbreeze = new MailBreeze({
1135
+ * apiKey: "sk_live_xxx",
1136
+ * });
1137
+ *
1138
+ * // Send an email
1139
+ * const result = await mailbreeze.emails.send({
1140
+ * from: "hello@yourdomain.com",
1141
+ * to: "user@example.com",
1142
+ * subject: "Hello!",
1143
+ * html: "<h1>Welcome!</h1>",
1144
+ * });
1145
+ *
1146
+ * // Create a contact
1147
+ * const contacts = mailbreeze.contacts("list_xxx");
1148
+ * const contact = await contacts.create({
1149
+ * email: "user@example.com",
1150
+ * firstName: "John",
1151
+ * });
1152
+ * ```
1153
+ */
1154
+ declare class MailBreeze {
1155
+ /**
1156
+ * Email sending and management.
1157
+ */
1158
+ readonly emails: Emails;
1159
+ /**
1160
+ * Email attachment handling.
1161
+ */
1162
+ readonly attachments: Attachments;
1163
+ /**
1164
+ * Contact list management.
1165
+ */
1166
+ readonly lists: Lists;
1167
+ /**
1168
+ * Email verification services.
1169
+ */
1170
+ readonly verification: Verification;
1171
+ /**
1172
+ * Automation enrollment management.
1173
+ */
1174
+ readonly automations: Automations;
1175
+ private readonly fetcher;
1176
+ private readonly domainId?;
1177
+ /**
1178
+ * Create a new MailBreeze client.
1179
+ *
1180
+ * @param config - Client configuration
1181
+ *
1182
+ * @example
1183
+ * ```ts
1184
+ * // Basic usage
1185
+ * const mailbreeze = new MailBreeze({
1186
+ * apiKey: "sk_live_xxx",
1187
+ * });
1188
+ *
1189
+ * // With custom options
1190
+ * const mailbreeze = new MailBreeze({
1191
+ * apiKey: "sk_live_xxx",
1192
+ * baseUrl: "https://api.eu.mailbreeze.com",
1193
+ * timeout: 60000,
1194
+ * maxRetries: 5,
1195
+ * });
1196
+ * ```
1197
+ */
1198
+ constructor(config: MailBreezeConfig);
1199
+ /**
1200
+ * Get a contacts resource for a specific list.
1201
+ *
1202
+ * @param listId - Contact list ID
1203
+ * @returns Contacts resource bound to the list
1204
+ *
1205
+ * @example
1206
+ * ```ts
1207
+ * const contacts = mailbreeze.contacts("list_xxx");
1208
+ *
1209
+ * // Create a contact in this list
1210
+ * const contact = await contacts.create({
1211
+ * email: "user@example.com",
1212
+ * });
1213
+ *
1214
+ * // List contacts in this list
1215
+ * const { data } = await contacts.list();
1216
+ * ```
1217
+ */
1218
+ contacts(listId: string): Contacts;
1219
+ }
1220
+
1221
+ /**
1222
+ * Base error class for all MailBreeze SDK errors.
1223
+ * All API-related errors extend from this class.
1224
+ */
1225
+ declare class MailBreezeError extends Error {
1226
+ /** Error code for programmatic handling */
1227
+ readonly code: string;
1228
+ /** HTTP status code (if applicable) */
1229
+ readonly statusCode?: number;
1230
+ /** Unique request ID for debugging with support */
1231
+ readonly requestId?: string;
1232
+ /** Additional error details (e.g., field-level validation errors) */
1233
+ readonly details?: Record<string, unknown>;
1234
+ constructor(message: string, code: string, statusCode?: number, requestId?: string, details?: Record<string, unknown>);
1235
+ /**
1236
+ * Serialize error to JSON-friendly object.
1237
+ * Useful for logging and error reporting.
1238
+ */
1239
+ toJSON(): Record<string, unknown>;
1240
+ }
1241
+ /**
1242
+ * Authentication failed (401).
1243
+ * Thrown when API key is missing, invalid, or expired.
1244
+ */
1245
+ declare class AuthenticationError extends MailBreezeError {
1246
+ constructor(message: string, code?: string, requestId?: string);
1247
+ }
1248
+ /**
1249
+ * Validation failed (400).
1250
+ * Thrown when request data fails validation.
1251
+ */
1252
+ declare class ValidationError extends MailBreezeError {
1253
+ constructor(message: string, code?: string, requestId?: string, details?: Record<string, unknown>);
1254
+ }
1255
+ /**
1256
+ * Resource not found (404).
1257
+ * Thrown when the requested resource does not exist.
1258
+ */
1259
+ declare class NotFoundError extends MailBreezeError {
1260
+ constructor(message: string, code?: string, requestId?: string);
1261
+ }
1262
+ /**
1263
+ * Rate limit exceeded (429).
1264
+ * Thrown when too many requests are made in a time window.
1265
+ */
1266
+ declare class RateLimitError extends MailBreezeError {
1267
+ /** Seconds to wait before retrying */
1268
+ readonly retryAfter?: number;
1269
+ constructor(message: string, code?: string, requestId?: string, retryAfter?: number);
1270
+ toJSON(): Record<string, unknown>;
1271
+ }
1272
+ /**
1273
+ * Server error (5xx).
1274
+ * Thrown when the API encounters an internal error.
1275
+ */
1276
+ declare class ServerError extends MailBreezeError {
1277
+ constructor(message: string, code?: string, statusCode?: number, requestId?: string);
1278
+ }
1279
+
1280
+ export { type Attachment, AuthenticationError, type BatchVerifyParams, type BatchVerifyResult, type CancelEnrollmentResult, type ConfirmAttachmentParams, type Contact, type ContactList, type CreateAttachmentUploadParams, type CreateAttachmentUploadResult, type CreateContactParams, type CreateListParams, type CustomFieldDefinition, type DomainContext, type Email, type EmailStats, type EnrollParams, type EnrollResult, type Enrollment, type ListContactsParams, type ListEmailsParams, type ListEnrollmentsParams, type ListListsParams, type ListParams, type ListStats, type ListVerificationsParams, MailBreeze, type MailBreezeConfig, MailBreezeError, NotFoundError, type PaginatedList, type Pagination, RateLimitError, type SendEmailParams, type SendEmailResult, ServerError, type SuppressReason, type UpdateContactParams, type UpdateListParams, ValidationError, type VerificationStats, type VerificationStatus, type VerifyEmailResult };