@openemail/sdk 0.0.1 → 0.0.3

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.
Files changed (6) hide show
  1. package/README.md +4 -4
  2. package/index.cjs +1270 -208
  3. package/index.d.cts +2091 -132
  4. package/index.d.ts +2091 -132
  5. package/index.js +1256 -209
  6. package/package.json +3 -3
package/index.cjs CHANGED
@@ -2,7 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "0.0.1";
5
+ const BROADCAST_STATUSES = {
6
+ SCHEDULED: 'scheduled',
7
+ QUEUED: 'queued',
8
+ SENDING: 'sending',
9
+ SENT: 'sent',
10
+ CANCELLED: 'cancelled',
11
+ FAILED: 'failed'
12
+ };
13
+
14
+ var version = "0.0.3";
6
15
 
7
16
  const BUILD_BASE_URL = 'https://api.openemail.uk';
8
17
 
@@ -10,6 +19,7 @@ const DEFAULTS = {
10
19
  BASE_URL: BUILD_BASE_URL,
11
20
  MAX_RETRIES: 2,
12
21
  TIMEOUT_MS: 30_000,
22
+ UPLOAD_TIMEOUT_MS: 600_000,
13
23
  USER_AGENT: `openemail-sdk/${version}`
14
24
  };
15
25
  const BROWSER_REFUSAL = [
@@ -42,46 +52,63 @@ const CLIENT_MESSAGES = {
42
52
  BASE_URL_SHAPE: 'is not a usable base URL. Pass an origin such as "https://api.openemail.uk", or the http origin of a server you run yourself.',
43
53
  NO_FETCH: 'No global fetch is available. Pass one as { fetch }, or run on Node 20+, Bun, Deno, Cloudflare Workers or a browser.',
44
54
  EMPTY_SEGMENT: 'An id must not be empty.',
55
+ FILENAME_REQUIRED: 'A file name is required. Pass it as { filename }, the name the file is stored and downloaded under.',
45
56
  DOT_SEGMENT: 'is not a usable id: a path segment made only of dots is removed by URL parsers, so the request would reach a different endpoint.'
46
57
  };
47
58
 
48
- const MESSAGE_ENCRYPTION_FORMATS = [
49
- 'pgp-mime',
50
- 'pgp-signed',
51
- 'pgp-inline',
52
- 'smime-encrypted',
53
- 'smime-signed'
59
+ const PEOPLE_SORTS = {
60
+ RECENT: 'recent',
61
+ NAME: 'name',
62
+ THREADS: 'threads'
63
+ };
64
+ const CONTACT_THREAD_SORTS = {
65
+ NEWEST: 'newest',
66
+ OLDEST: 'oldest',
67
+ SENDER: 'sender',
68
+ SUBJECT: 'subject'
69
+ };
70
+ const CONTACT_BLOCK_LISTS = {
71
+ BLOCKED_SENDERS: 'blockedSenders',
72
+ BLOCKED_DOMAINS: 'blockedDomains'
73
+ };
74
+ const CONTACT_PHOTO_TYPES = {
75
+ PNG: 'image/png',
76
+ JPEG: 'image/jpeg',
77
+ WEBP: 'image/webp',
78
+ GIF: 'image/gif'
79
+ };
80
+
81
+ const MESSAGE_ENCRYPTION_FORMATS = {
82
+ PGP_MIME: 'pgp-mime',
83
+ PGP_SIGNED: 'pgp-signed',
84
+ PGP_INLINE: 'pgp-inline',
85
+ SMIME_ENCRYPTED: 'smime-encrypted',
86
+ SMIME_SIGNED: 'smime-signed'
87
+ };
88
+ const SEALED_ENCRYPTION_FORMATS = [
89
+ MESSAGE_ENCRYPTION_FORMATS.PGP_MIME,
90
+ MESSAGE_ENCRYPTION_FORMATS.PGP_INLINE,
91
+ MESSAGE_ENCRYPTION_FORMATS.SMIME_ENCRYPTED
54
92
  ];
55
- const SEALED_ENCRYPTION_FORMATS = ['pgp-mime', 'pgp-inline', 'smime-encrypted'];
56
93
  const BASE64_CHUNK_SIZE = 0x8000;
57
94
 
58
- const ERROR_TYPES = [
59
- 'invalid_request_error',
60
- 'authentication_error',
61
- 'permission_error',
62
- 'not_found_error',
63
- 'conflict_error',
64
- 'validation_error',
65
- 'rate_limit_error',
66
- 'api_error'
67
- ];
68
- const ERROR_TYPE = {
69
- INVALID_REQUEST: 'invalid_request_error',
70
- AUTHENTICATION: 'authentication_error',
71
- PERMISSION: 'permission_error',
72
- NOT_FOUND: 'not_found_error',
73
- CONFLICT: 'conflict_error',
74
- VALIDATION: 'validation_error',
75
- RATE_LIMIT: 'rate_limit_error',
76
- API: 'api_error'
95
+ const ERROR_TYPES = {
96
+ INVALID_REQUEST_ERROR: 'invalid_request_error',
97
+ AUTHENTICATION_ERROR: 'authentication_error',
98
+ PERMISSION_ERROR: 'permission_error',
99
+ NOT_FOUND_ERROR: 'not_found_error',
100
+ CONFLICT_ERROR: 'conflict_error',
101
+ VALIDATION_ERROR: 'validation_error',
102
+ RATE_LIMIT_ERROR: 'rate_limit_error',
103
+ API_ERROR: 'api_error'
77
104
  };
78
105
  const ERROR_TYPE_BY_STATUS = {
79
- 401: ERROR_TYPE.AUTHENTICATION,
80
- 403: ERROR_TYPE.PERMISSION,
81
- 404: ERROR_TYPE.NOT_FOUND,
82
- 409: ERROR_TYPE.CONFLICT,
83
- 422: ERROR_TYPE.VALIDATION,
84
- 429: ERROR_TYPE.RATE_LIMIT
106
+ 401: ERROR_TYPES.AUTHENTICATION_ERROR,
107
+ 403: ERROR_TYPES.PERMISSION_ERROR,
108
+ 404: ERROR_TYPES.NOT_FOUND_ERROR,
109
+ 409: ERROR_TYPES.CONFLICT_ERROR,
110
+ 422: ERROR_TYPES.VALIDATION_ERROR,
111
+ 429: ERROR_TYPES.RATE_LIMIT_ERROR
85
112
  };
86
113
  const ERROR_CODES = {
87
114
  INSUFFICIENT_SCOPE: 'insufficient_scope',
@@ -92,9 +119,35 @@ const ERROR_NAMES = {
92
119
  NETWORK: 'OpenEmailNetworkError',
93
120
  TIMEOUT: 'TimeoutError'};
94
121
 
122
+ const FILE_SORTS = {
123
+ NEWEST: 'newest',
124
+ OLDEST: 'oldest',
125
+ LARGEST: 'largest',
126
+ NAME: 'name'
127
+ };
128
+ const FILE_KINDS = {
129
+ IMAGE: 'image',
130
+ PDF: 'pdf',
131
+ AUDIO: 'audio',
132
+ VIDEO: 'video',
133
+ TEXT: 'text'
134
+ };
135
+ const FILE_DIRECTIONS = {
136
+ INBOUND: 'inbound',
137
+ OUTBOUND: 'outbound',
138
+ UPLOADED: 'uploaded'
139
+ };
140
+ const FILE_USAGES = {
141
+ RECEIVED: 'received',
142
+ SENT: 'sent',
143
+ LINKED: 'linked',
144
+ SCHEDULED: 'scheduled'
145
+ };
146
+
95
147
  const HTTP_METHODS = {
96
148
  GET: 'GET',
97
149
  POST: 'POST',
150
+ PUT: 'PUT',
98
151
  PATCH: 'PATCH',
99
152
  DELETE: 'DELETE'
100
153
  };
@@ -109,7 +162,8 @@ const HEADER_KEYS = {
109
162
  };
110
163
  const CONTENT_TYPES = {
111
164
  JSON: 'application/json',
112
- CALENDAR: 'text/calendar'
165
+ CALENDAR: 'text/calendar',
166
+ OCTET_STREAM: 'application/octet-stream'
113
167
  };
114
168
  const RETRY = {
115
169
  STATUSES: [408, 429, 500, 502, 503, 504],
@@ -121,6 +175,28 @@ const RETRY = {
121
175
  };
122
176
  const IDEMPOTENCY_KEY_PREFIX = 'oe-';
123
177
 
178
+ const PROVIDER_IMPORT_RESOURCES = {
179
+ SUPPRESSIONS: 'suppressions',
180
+ AUDIENCES: 'audiences',
181
+ CONTACTS: 'contacts',
182
+ TEMPLATES: 'templates',
183
+ WEBHOOKS: 'webhooks',
184
+ DOMAINS: 'domains',
185
+ API_KEYS: 'api-keys'
186
+ };
187
+ const PROVIDER_IMPORT_STATUSES = {
188
+ QUEUED: 'queued',
189
+ RUNNING: 'running',
190
+ COMPLETED: 'completed',
191
+ FAILED: 'failed',
192
+ CANCELLED: 'cancelled'
193
+ };
194
+ const PROVIDER_IMPORT_DOMAIN_STATES = {
195
+ ABSENT: 'absent',
196
+ ADDED: 'added',
197
+ VERIFIED: 'verified'
198
+ };
199
+
124
200
  const LANGUAGES = [
125
201
  { code: 'en', label: 'English', native: 'English', flag: '🇬🇧', rtl: false },
126
202
  { code: 'es', label: 'Spanish', native: 'Español', flag: '🇪🇸', rtl: false },
@@ -357,6 +433,7 @@ const CURSOR_STYLES = {
357
433
  };
358
434
  const QUERY_KEYS = {
359
435
  LIMIT: 'limit',
436
+ CURSOR: 'cursor',
360
437
  STATUS: 'status',
361
438
  FROM: 'from',
362
439
  TO: 'to',
@@ -374,13 +451,42 @@ const QUERY_KEYS = {
374
451
  GRAIN: 'grain',
375
452
  OFFSET_MINUTES: 'offsetMinutes',
376
453
  INCLUDE_MACHINE: 'includeMachine',
377
- REASSIGN_TO: 'reassignTo'
454
+ REASSIGN_TO: 'reassignTo',
455
+ SOURCE: 'source',
456
+ ADDRESS: 'address',
457
+ SEARCH: 'search',
458
+ SORT: 'sort',
459
+ PAGE: 'page',
460
+ PAGE_SIZE: 'pageSize',
461
+ VERSION: 'version',
462
+ TRACKED: 'tracked',
463
+ Q: 'q',
464
+ AUDIENCE_IDS: 'audienceIds',
465
+ AUDIENCE_ID: 'audienceId',
466
+ BROADCAST_ID: 'broadcastId',
467
+ EMAIL: 'email',
468
+ BLOCKED: 'blocked',
469
+ DATE_FROM: 'dateFrom',
470
+ DATE_TO: 'dateTo',
471
+ FROM_CONTACTS: 'fromContacts',
472
+ REASON: 'reason',
473
+ KIND: 'kind',
474
+ ENDPOINT_IDS: 'endpointIds',
475
+ KEY_IDS: 'keyIds',
476
+ SINCE: 'since',
477
+ UNTIL: 'until',
478
+ FAILED_ONLY: 'failedOnly',
479
+ FILENAME: 'filename'
378
480
  };
379
481
  const LIST_SEPARATOR = ',';
380
482
 
381
483
  const PATHS = {
382
484
  PING: '/ping',
485
+ KEYS: '/keys',
486
+ KEYS_REQUESTS: '/keys/requests',
487
+ KEYS_ACTIVITY: '/keys/activity',
383
488
  KEYS_SELF: '/keys/self',
489
+ KEYS_SELF_ROTATE: '/keys/self/rotate',
384
490
  ADDRESSES: '/addresses',
385
491
  LANGUAGES: '/languages',
386
492
  EMAILS: '/emails',
@@ -389,10 +495,25 @@ const PATHS = {
389
495
  THREADS: '/threads',
390
496
  DRAFTS: '/drafts',
391
497
  LABELS: '/labels',
498
+ LABELS_COLORS: '/labels/colors',
392
499
  CONTACTS: '/contacts',
500
+ CONTACTS_PEOPLE: '/contacts/people',
501
+ CONTACTS_BATCH_DELETE: '/contacts/batch-delete',
502
+ AUDIENCES: '/audiences',
503
+ AUDIENCES_GROWTH: '/audiences/growth',
504
+ BROADCASTS: '/broadcasts',
505
+ BROADCASTS_PREVIEW: '/broadcasts/preview',
393
506
  DOMAINS: '/domains',
394
507
  WEBHOOKS: '/webhooks',
508
+ WEBHOOKS_DELIVERIES: '/webhooks/deliveries',
509
+ WEBHOOKS_ACTIVITY: '/webhooks/activity',
510
+ IMPORTS: '/imports',
511
+ PROVIDER_IMPORTS: '/provider-imports',
512
+ PROVIDER_IMPORTS_INSPECT: '/provider-imports/inspect',
395
513
  TEMPLATES: '/templates',
514
+ TEMPLATES_FONTS: '/templates/fonts',
515
+ TEMPLATES_RENDER: '/templates/render',
516
+ TEMPLATES_STARTERS: '/templates/starters',
396
517
  RULES: '/rules',
397
518
  RULES_RUNS: '/rules/runs',
398
519
  RULES_REORDER: '/rules/reorder',
@@ -403,28 +524,59 @@ const PATHS = {
403
524
  ROLES: '/roles',
404
525
  ROLES_PERMISSIONS: '/roles/permissions',
405
526
  MEMBERS: '/members',
527
+ MEMBERS_INVITATIONS: '/members/invitations',
528
+ SUPPRESSIONS: '/suppressions',
529
+ FILES: '/files',
530
+ FILES_STATS: '/files/stats',
531
+ FILES_BATCH_DELETE: '/files/batch-delete',
406
532
  TEMP_MAIL_DOMAINS: '/temp-mail/domains',
407
533
  TEMP_MAIL_INBOXES: '/temp-mail/inboxes'
408
534
  };
409
535
  const SEGMENTS = {
536
+ ACTIVITY: 'activity',
410
537
  ADDRESSES: 'addresses',
538
+ ANALYTICS: 'analytics',
411
539
  ATTACHMENTS: 'attachments',
540
+ AUDIENCES: 'audiences',
541
+ BATCH: 'batch',
542
+ BATCH_REMOVE: 'batch-remove',
543
+ BLOCK: 'block',
412
544
  CANCEL: 'cancel',
545
+ CHUNKS: 'chunks',
413
546
  CLICKS: 'clicks',
547
+ CONTACTS: 'contacts',
548
+ CONTENT: 'content',
414
549
  DELIVERIES: 'deliveries',
550
+ DUPLICATE: 'duplicate',
551
+ EMPTY: 'empty',
415
552
  EVENTS: 'events',
416
553
  EXTEND: 'extend',
554
+ FAILURES: 'failures',
555
+ FILES: 'files',
417
556
  ICS: 'ics',
557
+ IMPORT: 'import',
558
+ LINKS: 'links',
418
559
  MESSAGES: 'messages',
419
560
  OPENS: 'opens',
561
+ PHOTO: 'photo',
420
562
  PREVIEW: 'preview',
563
+ REPLAY: 'replay',
564
+ REQUESTS: 'requests',
565
+ RESEND: 'resend',
566
+ RESTORE: 'restore',
567
+ REVOKE: 'revoke',
568
+ ROTATE: 'rotate',
421
569
  ROTATE_SECRET: 'rotate-secret',
422
570
  SEND: 'send',
571
+ SENDS: 'sends',
423
572
  SNOOZE: 'snooze',
573
+ START: 'start',
424
574
  TEST: 'test',
575
+ THREADS: 'threads',
425
576
  TRACKING: 'tracking',
426
577
  TRASH: 'trash',
427
578
  UNSNOOZE: 'unsnooze',
579
+ UPLOAD: 'upload',
428
580
  VERSIONS: 'versions'
429
581
  };
430
582
 
@@ -434,89 +586,135 @@ const UPDATE_NOTICE = {
434
586
  ENV_DISABLE: 'OPENEMAIL_DISABLE_UPDATE_NOTICE',
435
587
  TIMEOUT_MS: 2_000,
436
588
  PACKAGE: '@openemail/sdk',
437
- CHANGELOG_URL: 'https://www.npmjs.com/package/@openemail/sdk?activeTab=versions',
589
+ CHANGELOG_URL: 'https://openemail.uk/docs/sdk/changelog',
438
590
  ICON: 'ℹ'
439
591
  };
440
592
 
441
- const RULE_FIELDS = [
442
- 'from',
443
- 'from_domain',
444
- 'envelope_from',
445
- 'to',
446
- 'cc',
447
- 'bcc',
448
- 'recipient',
449
- 'reply_to',
450
- 'delivered_to',
451
- 'subject',
452
- 'body',
453
- 'header',
454
- 'list_id',
455
- 'attachment_name',
456
- 'attachment_type',
457
- 'has_attachment',
458
- 'attachment_size',
459
- 'message_size',
460
- 'spam',
461
- 'hour',
462
- 'weekday'
463
- ];
464
- const RULE_OPERATORS = ['matches', 'contains', 'equals', 'starts_with', 'ends_with', 'gt', 'lt'];
465
- const RULE_ACTIONS = [
466
- 'label',
467
- 'remove_label',
468
- 'archive',
469
- 'mark_read',
470
- 'star',
471
- 'spam',
472
- 'trash',
473
- 'forward',
474
- 'reply',
475
- 'block_sender',
476
- 'reject'
477
- ];
593
+ const RULE_FIELDS = {
594
+ FROM: 'from',
595
+ FROM_DOMAIN: 'from_domain',
596
+ ENVELOPE_FROM: 'envelope_from',
597
+ TO: 'to',
598
+ CC: 'cc',
599
+ BCC: 'bcc',
600
+ RECIPIENT: 'recipient',
601
+ REPLY_TO: 'reply_to',
602
+ DELIVERED_TO: 'delivered_to',
603
+ SUBJECT: 'subject',
604
+ BODY: 'body',
605
+ HEADER: 'header',
606
+ LIST_ID: 'list_id',
607
+ ATTACHMENT_NAME: 'attachment_name',
608
+ ATTACHMENT_TYPE: 'attachment_type',
609
+ HAS_ATTACHMENT: 'has_attachment',
610
+ ATTACHMENT_SIZE: 'attachment_size',
611
+ MESSAGE_SIZE: 'message_size',
612
+ SPAM: 'spam',
613
+ HOUR: 'hour',
614
+ WEEKDAY: 'weekday'
615
+ };
616
+ const RULE_OPERATORS = {
617
+ MATCHES: 'matches',
618
+ CONTAINS: 'contains',
619
+ EQUALS: 'equals',
620
+ STARTS_WITH: 'starts_with',
621
+ ENDS_WITH: 'ends_with',
622
+ GT: 'gt',
623
+ LT: 'lt'
624
+ };
625
+ const RULE_ACTIONS = {
626
+ LABEL: 'label',
627
+ REMOVE_LABEL: 'remove_label',
628
+ ARCHIVE: 'archive',
629
+ MARK_READ: 'mark_read',
630
+ STAR: 'star',
631
+ SPAM: 'spam',
632
+ TRASH: 'trash',
633
+ FORWARD: 'forward',
634
+ REPLY: 'reply',
635
+ BLOCK_SENDER: 'block_sender',
636
+ REJECT: 'reject'
637
+ };
478
638
 
479
- const API_SCOPES = [
480
- 'emails:send',
481
- 'emails:read',
482
- 'drafts:read',
483
- 'drafts:write',
484
- 'threads:read',
485
- 'threads:write',
486
- 'labels:read',
487
- 'labels:write',
488
- 'contacts:read',
489
- 'calendar:read',
490
- 'calendar:write',
491
- 'templates:read',
492
- 'templates:write',
493
- 'domains:read',
494
- 'domains:write',
495
- 'webhooks:read',
496
- 'webhooks:write',
497
- 'rules:read',
498
- 'rules:write',
499
- 'connections:read',
500
- 'members:read',
501
- 'members:write',
502
- 'roles:read',
503
- 'roles:write',
504
- 'settings:read',
505
- 'settings:write'
506
- ];
639
+ const API_SCOPES = {
640
+ EMAILS_SEND: 'emails:send',
641
+ EMAILS_READ: 'emails:read',
642
+ DRAFTS_READ: 'drafts:read',
643
+ DRAFTS_WRITE: 'drafts:write',
644
+ THREADS_READ: 'threads:read',
645
+ THREADS_WRITE: 'threads:write',
646
+ LABELS_READ: 'labels:read',
647
+ LABELS_WRITE: 'labels:write',
648
+ CONTACTS_READ: 'contacts:read',
649
+ CONTACTS_WRITE: 'contacts:write',
650
+ AUDIENCES_READ: 'audiences:read',
651
+ AUDIENCES_WRITE: 'audiences:write',
652
+ CALENDAR_READ: 'calendar:read',
653
+ CALENDAR_WRITE: 'calendar:write',
654
+ TEMPLATES_READ: 'templates:read',
655
+ TEMPLATES_WRITE: 'templates:write',
656
+ DOMAINS_READ: 'domains:read',
657
+ DOMAINS_WRITE: 'domains:write',
658
+ WEBHOOKS_READ: 'webhooks:read',
659
+ WEBHOOKS_WRITE: 'webhooks:write',
660
+ RULES_READ: 'rules:read',
661
+ RULES_WRITE: 'rules:write',
662
+ CONNECTIONS_READ: 'connections:read',
663
+ MEMBERS_READ: 'members:read',
664
+ MEMBERS_WRITE: 'members:write',
665
+ ROLES_READ: 'roles:read',
666
+ ROLES_WRITE: 'roles:write',
667
+ SETTINGS_READ: 'settings:read',
668
+ SETTINGS_WRITE: 'settings:write',
669
+ KEYS_WRITE: 'keys:write',
670
+ KEYS_READ: 'keys:read',
671
+ KEYS_MANAGE: 'keys:manage'
672
+ };
507
673
 
508
- const WEBHOOK_EVENTS = [
509
- 'email.received',
510
- 'email.sent',
511
- 'email.failed',
512
- 'email.cancelled',
513
- 'email.scheduled',
514
- 'email.queued',
515
- 'email.bounced',
516
- 'email.complained',
517
- 'email.opened',
518
- 'email.clicked'
519
- ];
674
+ const SUPPRESSION_REASONS = {
675
+ BOUNCE: 'bounce',
676
+ COMPLAINT: 'complaint',
677
+ MANUAL: 'manual'
678
+ };
679
+
680
+ const THREAD_SORTS = {
681
+ NEWEST: 'newest',
682
+ OLDEST: 'oldest',
683
+ SENDER: 'sender',
684
+ SUBJECT: 'subject'
685
+ };
686
+
687
+ const WEBHOOK_EVENTS = {
688
+ EMAIL_RECEIVED: 'email.received',
689
+ EMAIL_REPLIED: 'email.replied',
690
+ EMAIL_SENT: 'email.sent',
691
+ EMAIL_FAILED: 'email.failed',
692
+ EMAIL_CANCELLED: 'email.cancelled',
693
+ EMAIL_SCHEDULED: 'email.scheduled',
694
+ EMAIL_QUEUED: 'email.queued',
695
+ EMAIL_DELIVERED: 'email.delivered',
696
+ EMAIL_DELIVERY_DELAYED: 'email.delivery_delayed',
697
+ EMAIL_BOUNCED: 'email.bounced',
698
+ EMAIL_COMPLAINED: 'email.complained',
699
+ EMAIL_SUPPRESSED: 'email.suppressed',
700
+ EMAIL_OPENED: 'email.opened',
701
+ EMAIL_CLICKED: 'email.clicked',
702
+ EMAIL_DOWNLOADED: 'email.downloaded',
703
+ DOMAIN_VERIFIED: 'domain.verified',
704
+ DOMAIN_SENDING_CHANGED: 'domain.sending_changed',
705
+ DOMAIN_DELETED: 'domain.deleted',
706
+ SUPPRESSION_ADDED: 'suppression.added',
707
+ SUPPRESSION_REMOVED: 'suppression.removed'
708
+ };
709
+ const WEBHOOK_REPLAY_ERROR_CODES = {
710
+ RESOURCE_NOT_FOUND: 'resource_not_found',
711
+ WEBHOOK_DISABLED: 'webhook_disabled',
712
+ EVENT_NOT_SUBSCRIBED: 'event_not_subscribed',
713
+ EVENT_OUT_OF_SCOPE: 'event_out_of_scope',
714
+ DELIVERY_NOT_REPLAYABLE: 'delivery_not_replayable',
715
+ RETRY_IN_PROGRESS: 'retry_in_progress',
716
+ REPLAY_IN_PROGRESS: 'replay_in_progress'
717
+ };
520
718
  const WEBHOOK_HEADERS = {
521
719
  SIGNATURE: 'X-OpenEmail-Signature',
522
720
  EVENT: 'X-OpenEmail-Event',
@@ -549,6 +747,108 @@ const ENDPOINT_SCHEME_PATTERN = /^[a-z][a-z0-9+.-]*:\/\//i;
549
747
  const RETRYABLE_STATUSES = new Set(RETRY.STATUSES);
550
748
  const RETRYABLE_METHODS = new Set(RETRY.METHODS);
551
749
 
750
+ ({
751
+ scopes: [API_SCOPES.KEYS_MANAGE]});
752
+
753
+ ({
754
+ scopes: [API_SCOPES.KEYS_MANAGE]});
755
+
756
+ ({
757
+ scopes: [API_SCOPES.KEYS_READ]});
758
+
759
+ ({
760
+ scopes: [API_SCOPES.KEYS_READ]});
761
+
762
+ ({
763
+ scopes: [API_SCOPES.KEYS_READ]});
764
+
765
+ ({
766
+ scopes: [API_SCOPES.KEYS_READ]});
767
+
768
+ ({
769
+ scopes: [API_SCOPES.KEYS_READ]});
770
+
771
+ ({
772
+ scopes: [API_SCOPES.KEYS_READ]});
773
+
774
+ ({
775
+ scopes: [API_SCOPES.KEYS_READ]});
776
+
777
+ ({
778
+ scopes: [API_SCOPES.KEYS_READ]});
779
+
780
+ ({
781
+ scopes: [API_SCOPES.KEYS_READ]});
782
+
783
+ ({
784
+ scopes: [API_SCOPES.KEYS_READ]});
785
+
786
+ ({
787
+ scopes: [API_SCOPES.KEYS_READ]});
788
+
789
+ ({
790
+ scopes: [API_SCOPES.KEYS_READ]});
791
+
792
+ ({
793
+ scopes: [API_SCOPES.KEYS_READ]});
794
+
795
+ ({
796
+ scopes: [API_SCOPES.KEYS_READ]});
797
+
798
+ ({
799
+ scopes: [API_SCOPES.KEYS_READ]});
800
+
801
+ ({
802
+ scopes: [API_SCOPES.KEYS_READ]});
803
+
804
+ ({
805
+ scopes: [API_SCOPES.KEYS_MANAGE]});
806
+
807
+ ({
808
+ scopes: [API_SCOPES.KEYS_MANAGE]});
809
+
810
+ ({
811
+ scopes: [API_SCOPES.KEYS_MANAGE]});
812
+
813
+ ({
814
+ scopes: [API_SCOPES.KEYS_WRITE]});
815
+
816
+ ({
817
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
818
+
819
+ ({
820
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
821
+
822
+ ({
823
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
824
+
825
+ ({
826
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
827
+
828
+ ({
829
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
830
+
831
+ ({
832
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
833
+
834
+ ({
835
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
836
+
837
+ ({
838
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
839
+
840
+ ({
841
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
842
+
843
+ ({
844
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
845
+
846
+ ({
847
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
848
+
849
+ ({
850
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
851
+
552
852
  const IsApiKey = (value) => typeof value === 'string' && (value.startsWith(API_KEY_PREFIXES.LIVE) || value.startsWith(API_KEY_PREFIXES.TEST));
553
853
  const ModeOf = (apiKey) => apiKey.startsWith(API_KEY_PREFIXES.TEST) ? API_KEY_MODES.TEST : API_KEY_MODES.LIVE;
554
854
  const AssertApiKey = (apiKey, where) => {
@@ -586,28 +886,28 @@ class OpenEmailApiError extends Error {
586
886
  this.retryAfterSeconds = retryAfterSeconds;
587
887
  }
588
888
  get isAuth() {
589
- return this.type === ERROR_TYPE.AUTHENTICATION;
889
+ return this.type === ERROR_TYPES.AUTHENTICATION_ERROR;
590
890
  }
591
891
  get isPermission() {
592
- return this.type === ERROR_TYPE.PERMISSION;
892
+ return this.type === ERROR_TYPES.PERMISSION_ERROR;
593
893
  }
594
894
  get isScopeMissing() {
595
895
  return this.code === ERROR_CODES.INSUFFICIENT_SCOPE;
596
896
  }
597
897
  get isInvalidRequest() {
598
- return this.type === ERROR_TYPE.INVALID_REQUEST;
898
+ return this.type === ERROR_TYPES.INVALID_REQUEST_ERROR;
599
899
  }
600
900
  get isValidation() {
601
- return this.type === ERROR_TYPE.VALIDATION;
901
+ return this.type === ERROR_TYPES.VALIDATION_ERROR;
602
902
  }
603
903
  get isNotFound() {
604
- return this.type === ERROR_TYPE.NOT_FOUND;
904
+ return this.type === ERROR_TYPES.NOT_FOUND_ERROR;
605
905
  }
606
906
  get isConflict() {
607
- return this.type === ERROR_TYPE.CONFLICT;
907
+ return this.type === ERROR_TYPES.CONFLICT_ERROR;
608
908
  }
609
909
  get isRateLimited() {
610
- return this.type === ERROR_TYPE.RATE_LIMIT;
910
+ return this.type === ERROR_TYPES.RATE_LIMIT_ERROR;
611
911
  }
612
912
  get isServerError() {
613
913
  return this.status !== null && this.status >= 500;
@@ -773,12 +1073,13 @@ const Sleep = (ms, signal) => new Promise((resolve, reject) => {
773
1073
  signal?.addEventListener('abort', onAbort, { once: true });
774
1074
  });
775
1075
 
776
- const IsErrorType = (value) => typeof value === 'string' && ERROR_TYPES.includes(value);
1076
+ const errorTypes = new Set(Object.values(ERROR_TYPES));
1077
+ const IsErrorType = (value) => typeof value === 'string' && errorTypes.has(value);
777
1078
  const TypeForStatus = (status) => {
778
1079
  if (status >= 500)
779
- return ERROR_TYPE.API;
1080
+ return ERROR_TYPES.API_ERROR;
780
1081
  const mapped = ERROR_TYPE_BY_STATUS[status];
781
- return IsErrorType(mapped) ? mapped : ERROR_TYPE.INVALID_REQUEST;
1082
+ return IsErrorType(mapped) ? mapped : ERROR_TYPES.INVALID_REQUEST_ERROR;
782
1083
  };
783
1084
  const ReadPayload = (body) => {
784
1085
  if (typeof body !== 'object' || body === null || !('error' in body))
@@ -853,11 +1154,13 @@ class Transport {
853
1154
  const method = (options.method ?? HTTP_METHODS.GET).toUpperCase();
854
1155
  const url = BuildUrl(this.baseUrl, path, options.query);
855
1156
  const headers = this.headersFor(options);
856
- const body = options.body === undefined ? undefined : JSON.stringify(options.body);
1157
+ const body = options.raw !== undefined
1158
+ ? options.raw
1159
+ : options.body === undefined ? undefined : JSON.stringify(options.body);
857
1160
  const repeatable = options.repeatable ?? RETRYABLE_METHODS.has(method);
858
1161
  let attempt = 0;
859
1162
  for (;;) {
860
- const outcome = await this.attempt(url, method, headers, body, options.signal);
1163
+ const outcome = await this.attempt(url, method, headers, body, options.signal, options.binary === true, options.timeoutMs ?? this.timeoutMs);
861
1164
  if (outcome instanceof OpenEmailNetworkError) {
862
1165
  if (options.signal?.aborted || !repeatable || attempt >= this.maxRetries)
863
1166
  throw outcome;
@@ -865,7 +1168,9 @@ class Transport {
865
1168
  attempt += 1;
866
1169
  continue;
867
1170
  }
868
- const { response, text } = outcome;
1171
+ const { response, text, bytes } = outcome;
1172
+ if (response.ok && bytes !== undefined)
1173
+ return bytes;
869
1174
  if (response.ok)
870
1175
  return this.parse(response, text, options.accept);
871
1176
  const retryAfter = RetryAfter(response.headers.get(HEADER_KEYS.RETRY_AFTER));
@@ -887,7 +1192,9 @@ class Transport {
887
1192
  };
888
1193
  if (!IsBrowser())
889
1194
  headers[HEADER_KEYS.USER_AGENT] = this.userAgent;
890
- if (options.body !== undefined)
1195
+ if (options.raw !== undefined)
1196
+ headers[HEADER_KEYS.CONTENT_TYPE] = options.contentType ?? CONTENT_TYPES.OCTET_STREAM;
1197
+ else if (options.body !== undefined)
891
1198
  headers[HEADER_KEYS.CONTENT_TYPE] = CONTENT_TYPES.JSON;
892
1199
  if (options.anonymous !== true) {
893
1200
  if (options.apiKey !== undefined)
@@ -900,13 +1207,13 @@ class Transport {
900
1207
  headers[HEADER_KEYS.IDEMPOTENCY_KEY] = options.idempotencyKey ?? IdempotencyKey();
901
1208
  return headers;
902
1209
  }
903
- async attempt(url, method, headers, body, signal) {
904
- const deadline = Deadline(this.timeoutMs, signal);
1210
+ async attempt(url, method, headers, body, signal, binary, timeoutMs) {
1211
+ const deadline = Deadline(timeoutMs, signal);
905
1212
  const Failure = (error, fallback) => {
906
1213
  if (signal?.aborted)
907
1214
  return new OpenEmailNetworkError('Request aborted by the caller.', error);
908
1215
  if (deadline.timedOut())
909
- return new OpenEmailNetworkError(`Request timed out after ${this.timeoutMs}ms.`, error, true);
1216
+ return new OpenEmailNetworkError(`Request timed out after ${timeoutMs}ms.`, error, true);
910
1217
  return new OpenEmailNetworkError(`${fallback}: ${Describe(error)}`, error);
911
1218
  };
912
1219
  try {
@@ -918,6 +1225,8 @@ class Transport {
918
1225
  return Failure(error, `Could not reach ${this.baseUrl}`);
919
1226
  }
920
1227
  try {
1228
+ if (binary && response.ok)
1229
+ return { response, text: '', bytes: new Uint8Array(await response.arrayBuffer()) };
921
1230
  return { response, text: await response.text() };
922
1231
  }
923
1232
  catch (error) {
@@ -941,24 +1250,13 @@ class Transport {
941
1250
  throw new OpenEmailApiError({
942
1251
  message: `The API answered ${response.status} with a body that is not JSON.`,
943
1252
  status: response.status,
944
- type: ERROR_TYPE.API,
1253
+ type: ERROR_TYPES.API_ERROR,
945
1254
  code: ERROR_CODES.UNRECOGNISED_RESPONSE,
946
1255
  requestId: response.headers.get(HEADER_KEYS.REQUEST_ID) ?? undefined
947
1256
  });
948
1257
  }
949
1258
  }
950
1259
 
951
- const Addresses = (transport) => ({
952
- list: async (options = {}) => {
953
- const envelope = await transport.request(PATHS.ADDRESSES, { signal: options.signal, apiKey: options.apiKey });
954
- return {
955
- unrestricted: envelope.unrestricted,
956
- addresses: envelope.data ?? [],
957
- domains: envelope.domains ?? []
958
- };
959
- }
960
- });
961
-
962
1260
  const FetchPage = async (transport, path, style, options = {}, query = {}) => {
963
1261
  const payload = await transport.request(path, {
964
1262
  query: { ...query, [QUERY_KEYS.LIMIT]: options.limit, [style.PARAM]: options.cursor },
@@ -1014,11 +1312,31 @@ const ThreadMessageAttachmentsPath = (id, messageId) => `${ThreadPath(id)}/${SEG
1014
1312
  const DraftPath = (id) => `${PATHS.DRAFTS}/${Segment(id)}`;
1015
1313
  const LabelPath = (id) => `${PATHS.LABELS}/${Segment(id)}`;
1016
1314
  const ContactPath = (email) => `${PATHS.CONTACTS}/${Segment(email)}`;
1315
+ const ContactChildPath = (email, segment) => `${ContactPath(email)}/${segment}`;
1316
+ const AudiencePath = (id) => `${PATHS.AUDIENCES}/${Segment(id)}`;
1317
+ const AudienceChildPath = (id, segment) => `${AudiencePath(id)}/${segment}`;
1318
+ const AudienceContactsPath = (id) => `${AudiencePath(id)}/${SEGMENTS.CONTACTS}`;
1319
+ const AudienceContactsChildPath = (id, segment) => `${AudienceContactsPath(id)}/${segment}`;
1320
+ const AudienceContactPath = (id, email) => `${AudienceContactsPath(id)}/${Segment(email)}`;
1321
+ const BroadcastPath = (id) => `${PATHS.BROADCASTS}/${Segment(id)}`;
1322
+ const BroadcastChildPath = (id, segment) => `${BroadcastPath(id)}/${segment}`;
1017
1323
  const DomainPath = (id) => `${PATHS.DOMAINS}/${Segment(id)}`;
1018
1324
  const WebhookPath = (id) => `${PATHS.WEBHOOKS}/${Segment(id)}`;
1019
1325
  const WebhookChildPath = (id, segment) => `${WebhookPath(id)}/${segment}`;
1326
+ const WebhookDeliveryPath = (id, deliveryId) => `${WebhookChildPath(id, SEGMENTS.DELIVERIES)}/${Segment(deliveryId)}`;
1327
+ const WebhookDeliveryReplayPath = (id, deliveryId) => `${WebhookDeliveryPath(id, deliveryId)}/${SEGMENTS.REPLAY}`;
1328
+ const KeyPath = (id) => `${PATHS.KEYS}/${Segment(id)}`;
1329
+ const KeyChildPath = (id, segment) => `${KeyPath(id)}/${segment}`;
1330
+ const ImportPath = (id) => `${PATHS.IMPORTS}/${Segment(id)}`;
1331
+ const ProviderImportPath = (id) => `${PATHS.PROVIDER_IMPORTS}/${Segment(id)}`;
1332
+ const ProviderImportChildPath = (id, segment) => `${ProviderImportPath(id)}/${segment}`;
1333
+ const ImportChildPath = (id, segment) => `${ImportPath(id)}/${segment}`;
1334
+ const ImportChunkPath = (id, file, chunk) => `${ImportPath(id)}/${SEGMENTS.FILES}/${Segment(String(file))}/${SEGMENTS.CHUNKS}/${Segment(String(chunk))}`;
1020
1335
  const TemplatePath = (idOrSlug) => `${PATHS.TEMPLATES}/${Segment(idOrSlug)}`;
1021
1336
  const TemplateChildPath = (idOrSlug, segment) => `${TemplatePath(idOrSlug)}/${segment}`;
1337
+ const TemplateStarterPath = (slug) => `${PATHS.TEMPLATES_STARTERS}/${Segment(slug)}`;
1338
+ const TemplateVersionPath = (idOrSlug, version) => `${TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS)}/${Segment(String(version))}`;
1339
+ const TemplateVersionChildPath = (idOrSlug, version, segment) => `${TemplateVersionPath(idOrSlug, version)}/${segment}`;
1022
1340
  const RulePath = (id) => `${PATHS.RULES}/${Segment(id)}`;
1023
1341
  const RuleChildPath = (id, segment) => `${RulePath(id)}/${segment}`;
1024
1342
  const TrackingPath = (id) => `${PATHS.TRACKING}/${Segment(id)}`;
@@ -1029,12 +1347,131 @@ const RolePath = (id) => `${PATHS.ROLES}/${Segment(id)}`;
1029
1347
  const MemberPath = (userId) => `${PATHS.MEMBERS}/${Segment(userId)}`;
1030
1348
  const MemberAddressesPath = (userId) => `${MemberPath(userId)}/${SEGMENTS.ADDRESSES}`;
1031
1349
  const MemberAddressPath = (userId, addressId) => `${MemberAddressesPath(userId)}/${Segment(addressId)}`;
1350
+ const MemberInvitationPath = (id) => `${PATHS.MEMBERS_INVITATIONS}/${Segment(id)}`;
1351
+ const MemberInvitationResendPath = (id) => `${MemberInvitationPath(id)}/${SEGMENTS.RESEND}`;
1352
+ const SuppressionPath = (id) => `${PATHS.SUPPRESSIONS}/${Segment(id)}`;
1353
+ const FilePath = (id) => `${PATHS.FILES}/${Segment(id)}`;
1354
+ const FileChildPath = (id, segment) => `${FilePath(id)}/${segment}`;
1032
1355
  const TempInboxPath = (id) => `${PATHS.TEMP_MAIL_INBOXES}/${Segment(id)}`;
1033
1356
  const TempInboxExtendPath = (id) => `${TempInboxPath(id)}/${SEGMENTS.EXTEND}`;
1034
1357
  const TempMessagesPath = (id) => `${TempInboxPath(id)}/${SEGMENTS.MESSAGES}`;
1035
1358
  const TempMessagePath = (id, messageId) => `${TempMessagesPath(id)}/${Segment(messageId)}`;
1036
1359
  const TempMessageAttachmentsPath = (id, messageId) => `${TempMessagePath(id, messageId)}/${SEGMENTS.ATTACHMENTS}`;
1037
1360
 
1361
+ const Addresses = (transport) => {
1362
+ const page = async (options = {}) => {
1363
+ const envelope = await transport.request(PATHS.ADDRESSES, {
1364
+ query: { [QUERY_KEYS.LIMIT]: options.limit, [CURSOR_STYLES.CURSOR.PARAM]: options.cursor },
1365
+ signal: options.signal,
1366
+ apiKey: options.apiKey
1367
+ });
1368
+ const nextCursor = typeof envelope.nextCursor === 'string' && envelope.nextCursor.length > 0 ? envelope.nextCursor : null;
1369
+ return {
1370
+ unrestricted: envelope.unrestricted,
1371
+ addresses: envelope.data ?? [],
1372
+ domains: envelope.domains ?? [],
1373
+ hasMore: typeof envelope.hasMore === 'boolean' ? envelope.hasMore : nextCursor !== null,
1374
+ nextCursor
1375
+ };
1376
+ };
1377
+ return {
1378
+ list: page,
1379
+ listAll: async (options = {}) => {
1380
+ let current = await page(options);
1381
+ const addresses = [...current.addresses];
1382
+ while (current.hasMore && current.nextCursor) {
1383
+ current = await page({ ...options, cursor: current.nextCursor });
1384
+ addresses.push(...current.addresses);
1385
+ }
1386
+ return { unrestricted: current.unrestricted, addresses, domains: current.domains };
1387
+ },
1388
+ iterate: (options = {}) => IteratePages(transport, PATHS.ADDRESSES, CURSOR_STYLES.CURSOR, options)
1389
+ };
1390
+ };
1391
+
1392
+ const MemberQuery = (options) => ({
1393
+ [QUERY_KEYS.Q]: options.q,
1394
+ [QUERY_KEYS.SOURCE]: options.source,
1395
+ [QUERY_KEYS.SORT]: options.sort
1396
+ });
1397
+ const GrowthQuery = (options) => ({
1398
+ [QUERY_KEYS.AUDIENCE_IDS]: options.audienceIds?.join(LIST_SEPARATOR),
1399
+ [QUERY_KEYS.DAYS]: options.days,
1400
+ [QUERY_KEYS.MINUTES]: options.minutes,
1401
+ [QUERY_KEYS.GRAIN]: options.grain,
1402
+ [QUERY_KEYS.OFFSET_MINUTES]: options.offsetMinutes
1403
+ });
1404
+ const Audiences = (transport) => ({
1405
+ list: (options = {}) => FetchPage(transport, PATHS.AUDIENCES, CURSOR_STYLES.CURSOR, options),
1406
+ listAll: (options = {}) => CollectAll(transport, PATHS.AUDIENCES, CURSOR_STYLES.CURSOR, options),
1407
+ iterate: (options = {}) => IteratePages(transport, PATHS.AUDIENCES, CURSOR_STYLES.CURSOR, options),
1408
+ growth: (options = {}) => transport.request(PATHS.AUDIENCES_GROWTH, {
1409
+ query: GrowthQuery(options),
1410
+ signal: options.signal,
1411
+ apiKey: options.apiKey
1412
+ }),
1413
+ get: (id, options = {}) => transport.request(AudiencePath(id), { signal: options.signal, apiKey: options.apiKey }),
1414
+ create: (body, options = {}) => transport.request(PATHS.AUDIENCES, {
1415
+ method: HTTP_METHODS.POST,
1416
+ body,
1417
+ signal: options.signal,
1418
+ apiKey: options.apiKey
1419
+ }),
1420
+ update: (id, patch, options = {}) => transport.request(AudiencePath(id), {
1421
+ method: HTTP_METHODS.PATCH,
1422
+ body: patch,
1423
+ repeatable: true,
1424
+ signal: options.signal,
1425
+ apiKey: options.apiKey
1426
+ }),
1427
+ delete: (id, options = {}) => transport.request(AudiencePath(id), {
1428
+ method: HTTP_METHODS.DELETE,
1429
+ signal: options.signal,
1430
+ apiKey: options.apiKey
1431
+ }),
1432
+ empty: (id, options = {}) => transport.request(AudienceChildPath(id, SEGMENTS.EMPTY), {
1433
+ method: HTTP_METHODS.POST,
1434
+ signal: options.signal,
1435
+ apiKey: options.apiKey
1436
+ }),
1437
+ listContacts: (id, options = {}) => FetchPage(transport, AudienceContactsPath(id), CURSOR_STYLES.CURSOR, options, MemberQuery(options)),
1438
+ listAllContacts: (id, options = {}) => CollectAll(transport, AudienceContactsPath(id), CURSOR_STYLES.CURSOR, options, MemberQuery(options)),
1439
+ iterateContacts: (id, options = {}) => IteratePages(transport, AudienceContactsPath(id), CURSOR_STYLES.CURSOR, options, MemberQuery(options)),
1440
+ addContact: (id, body, options = {}) => transport.request(AudienceContactsPath(id), {
1441
+ method: HTTP_METHODS.POST,
1442
+ body,
1443
+ repeatable: true,
1444
+ signal: options.signal,
1445
+ apiKey: options.apiKey
1446
+ }),
1447
+ removeContact: (id, email, options = {}) => transport.request(AudienceContactPath(id, email), {
1448
+ method: HTTP_METHODS.DELETE,
1449
+ signal: options.signal,
1450
+ apiKey: options.apiKey
1451
+ }),
1452
+ addContacts: (id, body, options = {}) => transport.request(AudienceContactsChildPath(id, SEGMENTS.BATCH), {
1453
+ method: HTTP_METHODS.POST,
1454
+ body,
1455
+ repeatable: true,
1456
+ signal: options.signal,
1457
+ apiKey: options.apiKey
1458
+ }),
1459
+ removeContacts: (id, body, options = {}) => transport.request(AudienceContactsChildPath(id, SEGMENTS.BATCH_REMOVE), {
1460
+ method: HTTP_METHODS.POST,
1461
+ body,
1462
+ repeatable: true,
1463
+ signal: options.signal,
1464
+ apiKey: options.apiKey
1465
+ }),
1466
+ importContacts: (id, body, options = {}) => transport.request(AudienceChildPath(id, SEGMENTS.IMPORT), {
1467
+ method: HTTP_METHODS.POST,
1468
+ body,
1469
+ repeatable: true,
1470
+ signal: options.signal,
1471
+ apiKey: options.apiKey
1472
+ })
1473
+ });
1474
+
1038
1475
  const ToBase64 = (bytes) => {
1039
1476
  const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
1040
1477
  let binary = '';
@@ -1050,11 +1487,13 @@ const Many = (value) => {
1050
1487
  return Array.isArray(value) ? value : [value];
1051
1488
  };
1052
1489
  const Instant = (value) => value instanceof Date ? value.toISOString() : value;
1053
- const Attachment = (attachment) => ({
1054
- filename: attachment.filename,
1055
- content: typeof attachment.content === 'string' ? attachment.content : ToBase64(attachment.content),
1056
- ...(attachment.contentType === undefined ? {} : { contentType: attachment.contentType })
1057
- });
1490
+ const Attachment = (attachment) => 'fileId' in attachment
1491
+ ? { fileId: attachment.fileId }
1492
+ : {
1493
+ filename: attachment.filename,
1494
+ content: typeof attachment.content === 'string' ? attachment.content : ToBase64(attachment.content),
1495
+ ...(attachment.contentType === undefined ? {} : { contentType: attachment.contentType })
1496
+ };
1058
1497
  const EmailToWire = (body) => ({
1059
1498
  ...body,
1060
1499
  to: Many(body.to),
@@ -1072,12 +1511,47 @@ const TemplateSendToWire = (body) => ({
1072
1511
  });
1073
1512
  const ToInstant = Instant;
1074
1513
 
1075
- const Calendar = (transport) => ({
1076
- listEvents: (options) => FetchList(transport, PATHS.CALENDAR_EVENTS, options, {
1077
- [QUERY_KEYS.FROM]: ToInstant(options.from),
1078
- [QUERY_KEYS.TO]: ToInstant(options.to),
1079
- [QUERY_KEYS.TIMEZONE]: options.timezone
1514
+ const ListQuery$a = (options) => ({
1515
+ [QUERY_KEYS.AUDIENCE_ID]: options.audienceId
1516
+ });
1517
+ const Broadcasts = (transport) => ({
1518
+ preview: (body, options = {}) => transport.request(PATHS.BROADCASTS_PREVIEW, {
1519
+ method: HTTP_METHODS.POST,
1520
+ body: { audienceIds: body.audienceIds },
1521
+ repeatable: true,
1522
+ signal: options.signal,
1523
+ apiKey: options.apiKey
1080
1524
  }),
1525
+ send: (body, options = {}) => transport.request(PATHS.BROADCASTS, {
1526
+ method: HTTP_METHODS.POST,
1527
+ body: { ...body, scheduledAt: ToInstant(body.scheduledAt) },
1528
+ idempotent: true,
1529
+ idempotencyKey: options.idempotencyKey,
1530
+ repeatable: true,
1531
+ signal: options.signal,
1532
+ apiKey: options.apiKey
1533
+ }),
1534
+ list: (options = {}) => FetchPage(transport, PATHS.BROADCASTS, CURSOR_STYLES.CURSOR, options, ListQuery$a(options)),
1535
+ listAll: (options = {}) => CollectAll(transport, PATHS.BROADCASTS, CURSOR_STYLES.CURSOR, options, ListQuery$a(options)),
1536
+ iterate: (options = {}) => IteratePages(transport, PATHS.BROADCASTS, CURSOR_STYLES.CURSOR, options, ListQuery$a(options)),
1537
+ get: (id, options = {}) => transport.request(BroadcastPath(id), { signal: options.signal, apiKey: options.apiKey }),
1538
+ cancel: (id, options = {}) => transport.request(BroadcastChildPath(id, SEGMENTS.CANCEL), {
1539
+ method: HTTP_METHODS.POST,
1540
+ repeatable: true,
1541
+ signal: options.signal,
1542
+ apiKey: options.apiKey
1543
+ })
1544
+ });
1545
+
1546
+ const RangeQuery = (options) => ({
1547
+ [QUERY_KEYS.FROM]: ToInstant(options.from),
1548
+ [QUERY_KEYS.TO]: ToInstant(options.to),
1549
+ [QUERY_KEYS.TIMEZONE]: options.timezone
1550
+ });
1551
+ const Calendar = (transport) => ({
1552
+ listEvents: (options) => FetchPage(transport, PATHS.CALENDAR_EVENTS, CURSOR_STYLES.CURSOR, options, RangeQuery(options)),
1553
+ listAllEvents: (options) => CollectAll(transport, PATHS.CALENDAR_EVENTS, CURSOR_STYLES.CURSOR, options, RangeQuery(options)),
1554
+ iterateEvents: (options) => IteratePages(transport, PATHS.CALENDAR_EVENTS, CURSOR_STYLES.CURSOR, options, RangeQuery(options)),
1081
1555
  getEvent: (id, options = {}) => transport.request(CalendarEventPath(id), { signal: options.signal, apiKey: options.apiKey }),
1082
1556
  getEventIcs: (id, options = {}) => transport.request(CalendarEventIcsPath(id), {
1083
1557
  accept: CONTENT_TYPES.CALENDAR,
@@ -1086,21 +1560,150 @@ const Calendar = (transport) => ({
1086
1560
  })
1087
1561
  });
1088
1562
 
1563
+ const ListQuery$9 = (options) => ({
1564
+ [QUERY_KEYS.SOURCE]: options.source,
1565
+ [QUERY_KEYS.Q]: options.q
1566
+ });
1567
+ const PeopleQuery = (options) => ({
1568
+ [QUERY_KEYS.Q]: options.q,
1569
+ [QUERY_KEYS.EMAIL]: options.email,
1570
+ [QUERY_KEYS.SORT]: options.sort,
1571
+ [QUERY_KEYS.BLOCKED]: options.blocked === undefined ? undefined : String(options.blocked)
1572
+ });
1573
+ const ThreadQuery = (options) => ({
1574
+ [QUERY_KEYS.Q]: options.q,
1575
+ [QUERY_KEYS.SORT]: options.sort
1576
+ });
1577
+ const ActivityQuery = (options) => ({
1578
+ [QUERY_KEYS.MINUTES]: options.minutes,
1579
+ [QUERY_KEYS.GRAIN]: options.grain,
1580
+ [QUERY_KEYS.OFFSET_MINUTES]: options.offsetMinutes
1581
+ });
1582
+ const PhotoType = (data, options) => {
1583
+ if (options.contentType)
1584
+ return options.contentType;
1585
+ return typeof Blob !== 'undefined' && data instanceof Blob && data.type ? data.type : undefined;
1586
+ };
1089
1587
  const Contacts = (transport) => ({
1090
- list: (options = {}) => FetchList(transport, PATHS.CONTACTS, options, { [QUERY_KEYS.LIMIT]: options.limit }),
1091
- get: (email, options = {}) => transport.request(ContactPath(email), { signal: options.signal, apiKey: options.apiKey })
1588
+ list: (options = {}) => FetchPage(transport, PATHS.CONTACTS, CURSOR_STYLES.CURSOR, options, ListQuery$9(options)),
1589
+ listAll: (options = {}) => CollectAll(transport, PATHS.CONTACTS, CURSOR_STYLES.CURSOR, options, ListQuery$9(options)),
1590
+ iterate: (options = {}) => IteratePages(transport, PATHS.CONTACTS, CURSOR_STYLES.CURSOR, options, ListQuery$9(options)),
1591
+ get: (email, options = {}) => transport.request(ContactPath(email), { signal: options.signal, apiKey: options.apiKey }),
1592
+ create: (body, options = {}) => transport.request(PATHS.CONTACTS, {
1593
+ method: HTTP_METHODS.POST,
1594
+ body,
1595
+ signal: options.signal,
1596
+ apiKey: options.apiKey
1597
+ }),
1598
+ update: (email, patch, options = {}) => transport.request(ContactPath(email), {
1599
+ method: HTTP_METHODS.PATCH,
1600
+ body: patch,
1601
+ repeatable: true,
1602
+ signal: options.signal,
1603
+ apiKey: options.apiKey
1604
+ }),
1605
+ delete: (email, options = {}) => transport.request(ContactPath(email), {
1606
+ method: HTTP_METHODS.DELETE,
1607
+ signal: options.signal,
1608
+ apiKey: options.apiKey
1609
+ }),
1610
+ setAudiences: (email, body, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.AUDIENCES), {
1611
+ method: HTTP_METHODS.PUT,
1612
+ body,
1613
+ repeatable: true,
1614
+ signal: options.signal,
1615
+ apiKey: options.apiKey
1616
+ }),
1617
+ listPeople: async (options = {}) => {
1618
+ const payload = await transport.request(PATHS.CONTACTS_PEOPLE, {
1619
+ query: {
1620
+ ...PeopleQuery(options),
1621
+ [QUERY_KEYS.LIMIT]: options.limit,
1622
+ [CURSOR_STYLES.CURSOR.PARAM]: options.cursor
1623
+ },
1624
+ signal: options.signal,
1625
+ apiKey: options.apiKey
1626
+ });
1627
+ const next = payload?.[CURSOR_STYLES.CURSOR.FIELD];
1628
+ const nextCursor = typeof next === 'string' && next.length > 0 ? next : null;
1629
+ return {
1630
+ items: (Array.isArray(payload?.data) ? payload.data : []),
1631
+ hasMore: typeof payload?.hasMore === 'boolean' ? payload.hasMore : nextCursor !== null,
1632
+ nextCursor,
1633
+ seen: payload?.seen === true
1634
+ };
1635
+ },
1636
+ listAllPeople: (options = {}) => CollectAll(transport, PATHS.CONTACTS_PEOPLE, CURSOR_STYLES.CURSOR, options, PeopleQuery(options)),
1637
+ iteratePeople: (options = {}) => IteratePages(transport, PATHS.CONTACTS_PEOPLE, CURSOR_STYLES.CURSOR, options, PeopleQuery(options)),
1638
+ save: (email, body = {}, options = {}) => transport.request(ContactPath(email), {
1639
+ method: HTTP_METHODS.PUT,
1640
+ body,
1641
+ repeatable: true,
1642
+ signal: options.signal,
1643
+ apiKey: options.apiKey
1644
+ }),
1645
+ deleteMany: (emails, options = {}) => transport.request(PATHS.CONTACTS_BATCH_DELETE, {
1646
+ method: HTTP_METHODS.POST,
1647
+ body: { emails },
1648
+ repeatable: true,
1649
+ signal: options.signal,
1650
+ apiKey: options.apiKey
1651
+ }),
1652
+ setPhoto: (email, data, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.PHOTO), {
1653
+ method: HTTP_METHODS.PUT,
1654
+ raw: data,
1655
+ contentType: PhotoType(data, options),
1656
+ repeatable: true,
1657
+ signal: options.signal,
1658
+ apiKey: options.apiKey
1659
+ }),
1660
+ removePhoto: (email, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.PHOTO), {
1661
+ method: HTTP_METHODS.DELETE,
1662
+ repeatable: true,
1663
+ signal: options.signal,
1664
+ apiKey: options.apiKey
1665
+ }),
1666
+ block: (email, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.BLOCK), {
1667
+ method: HTTP_METHODS.POST,
1668
+ repeatable: true,
1669
+ signal: options.signal,
1670
+ apiKey: options.apiKey
1671
+ }),
1672
+ unblock: (email, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.BLOCK), {
1673
+ method: HTTP_METHODS.DELETE,
1674
+ repeatable: true,
1675
+ signal: options.signal,
1676
+ apiKey: options.apiKey
1677
+ }),
1678
+ listThreads: (email, options = {}) => FetchPage(transport, ContactChildPath(email, SEGMENTS.THREADS), CURSOR_STYLES.CURSOR, options, ThreadQuery(options)),
1679
+ listAllThreads: (email, options = {}) => CollectAll(transport, ContactChildPath(email, SEGMENTS.THREADS), CURSOR_STYLES.CURSOR, options, ThreadQuery(options)),
1680
+ iterateThreads: (email, options = {}) => IteratePages(transport, ContactChildPath(email, SEGMENTS.THREADS), CURSOR_STYLES.CURSOR, options, ThreadQuery(options)),
1681
+ activity: (email, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.ACTIVITY), {
1682
+ query: ActivityQuery(options),
1683
+ signal: options.signal,
1684
+ apiKey: options.apiKey
1685
+ })
1092
1686
  });
1093
1687
 
1094
1688
  const Domains = (transport) => ({
1095
- list: (options = {}) => FetchList(transport, PATHS.DOMAINS, options),
1096
- get: (id, options = {}) => transport.request(DomainPath(id), { signal: options.signal, apiKey: options.apiKey })
1689
+ list: (options = {}) => FetchPage(transport, PATHS.DOMAINS, CURSOR_STYLES.CURSOR, options),
1690
+ listAll: (options = {}) => CollectAll(transport, PATHS.DOMAINS, CURSOR_STYLES.CURSOR, options),
1691
+ iterate: (options = {}) => IteratePages(transport, PATHS.DOMAINS, CURSOR_STYLES.CURSOR, options),
1692
+ get: (id, options = {}) => transport.request(DomainPath(id), { signal: options.signal, apiKey: options.apiKey }),
1693
+ update: (id, patch, options = {}) => transport.request(DomainPath(id), {
1694
+ method: HTTP_METHODS.PATCH,
1695
+ body: patch,
1696
+ repeatable: true,
1697
+ signal: options.signal,
1698
+ apiKey: options.apiKey
1699
+ })
1097
1700
  });
1098
1701
 
1099
- const ListQuery$4 = (options) => ({ [QUERY_KEYS.QUERY]: options.query });
1702
+ const ListQuery$8 = (options) => ({ [QUERY_KEYS.QUERY]: options.query });
1100
1703
  const Drafts = (transport) => ({
1101
- list: (options = {}) => FetchPage(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$4(options)),
1102
- listAll: (options = {}) => CollectAll(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$4(options)),
1103
- iterate: (options = {}) => IteratePages(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$4(options)),
1704
+ list: (options = {}) => FetchPage(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$8(options)),
1705
+ listAll: (options = {}) => CollectAll(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$8(options)),
1706
+ iterate: (options = {}) => IteratePages(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$8(options)),
1104
1707
  get: (id, options = {}) => transport.request(DraftPath(id), { signal: options.signal, apiKey: options.apiKey }),
1105
1708
  create: (body, options = {}) => transport.request(PATHS.DRAFTS, {
1106
1709
  method: HTTP_METHODS.POST,
@@ -1121,9 +1724,10 @@ const Drafts = (transport) => ({
1121
1724
  })
1122
1725
  });
1123
1726
 
1124
- const ListQuery$3 = (options) => ({
1727
+ const ListQuery$7 = (options) => ({
1125
1728
  [QUERY_KEYS.STATUS]: Array.isArray(options.status) ? options.status.join(LIST_SEPARATOR) : options.status,
1126
- [QUERY_KEYS.FROM]: options.from
1729
+ [QUERY_KEYS.FROM]: options.from,
1730
+ [QUERY_KEYS.BROADCAST_ID]: options.broadcastId
1127
1731
  });
1128
1732
  const Emails = (transport) => ({
1129
1733
  send: (body, options = {}) => transport.request(PATHS.EMAILS, {
@@ -1153,11 +1757,13 @@ const Emails = (transport) => ({
1153
1757
  signal: options.signal,
1154
1758
  apiKey: options.apiKey
1155
1759
  }),
1156
- list: (options = {}) => FetchPage(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
1157
- listAll: (options = {}) => CollectAll(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
1158
- iterate: (options = {}) => IteratePages(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
1760
+ list: (options = {}) => FetchPage(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$7(options)),
1761
+ listAll: (options = {}) => CollectAll(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$7(options)),
1762
+ iterate: (options = {}) => IteratePages(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$7(options)),
1159
1763
  get: (id, options = {}) => transport.request(EmailPath(id), { signal: options.signal, apiKey: options.apiKey }),
1160
- listEvents: (id, options = {}) => FetchList(transport, EmailChildPath(id, SEGMENTS.EVENTS), options),
1764
+ listEvents: (id, options = {}) => FetchPage(transport, EmailChildPath(id, SEGMENTS.EVENTS), CURSOR_STYLES.CURSOR, options),
1765
+ listAllEvents: (id, options = {}) => CollectAll(transport, EmailChildPath(id, SEGMENTS.EVENTS), CURSOR_STYLES.CURSOR, options),
1766
+ iterateEvents: (id, options = {}) => IteratePages(transport, EmailChildPath(id, SEGMENTS.EVENTS), CURSOR_STYLES.CURSOR, options),
1161
1767
  getTracking: (id, options = {}) => transport.request(EmailChildPath(id, SEGMENTS.TRACKING), { signal: options.signal, apiKey: options.apiKey }),
1162
1768
  cancel: (id, options = {}) => transport.request(EmailChildPath(id, SEGMENTS.CANCEL), {
1163
1769
  method: HTTP_METHODS.POST,
@@ -1174,8 +1780,238 @@ const Emails = (transport) => ({
1174
1780
  })
1175
1781
  });
1176
1782
 
1783
+ const ListQuery$6 = (options) => ({
1784
+ [QUERY_KEYS.Q]: options.q,
1785
+ [QUERY_KEYS.KIND]: options.kind,
1786
+ [QUERY_KEYS.SORT]: options.sort
1787
+ });
1788
+ const UploadName = (options) => {
1789
+ const filename = typeof options?.filename === 'string' ? options.filename.trim() : '';
1790
+ if (!filename)
1791
+ throw new Error(CLIENT_MESSAGES.FILENAME_REQUIRED);
1792
+ return filename;
1793
+ };
1794
+ const UploadType = (data, options) => {
1795
+ if (options.contentType)
1796
+ return options.contentType;
1797
+ return typeof Blob !== 'undefined' && data instanceof Blob && data.type ? data.type : undefined;
1798
+ };
1799
+ const UploadTimeout = (transport, options) => {
1800
+ if (options.timeoutMs !== undefined)
1801
+ return options.timeoutMs;
1802
+ return transport.timeoutMs > 0 ? Math.max(transport.timeoutMs, DEFAULTS.UPLOAD_TIMEOUT_MS) : transport.timeoutMs;
1803
+ };
1804
+ const Files = (transport) => ({
1805
+ list: (options = {}) => FetchPage(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1806
+ listAll: (options = {}) => CollectAll(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1807
+ iterate: (options = {}) => IteratePages(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1808
+ get: (id, options = {}) => transport.request(FilePath(id), { signal: options.signal, apiKey: options.apiKey }),
1809
+ stats: (options = {}) => transport.request(PATHS.FILES_STATS, { signal: options.signal, apiKey: options.apiKey }),
1810
+ download: (id, options = {}) => transport.request(FileChildPath(id, SEGMENTS.CONTENT), {
1811
+ binary: true,
1812
+ signal: options.signal,
1813
+ apiKey: options.apiKey
1814
+ }),
1815
+ listLinks: (id, options = {}) => FetchPage(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1816
+ listAllLinks: (id, options = {}) => CollectAll(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1817
+ iterateLinks: (id, options = {}) => IteratePages(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1818
+ upload: (data, options) => transport.request(PATHS.FILES, {
1819
+ method: HTTP_METHODS.POST,
1820
+ query: { [QUERY_KEYS.FILENAME]: UploadName(options) },
1821
+ raw: data,
1822
+ contentType: UploadType(data, options),
1823
+ timeoutMs: UploadTimeout(transport, options),
1824
+ signal: options.signal,
1825
+ apiKey: options.apiKey
1826
+ }),
1827
+ delete: (id, options = {}) => transport.request(FilePath(id), {
1828
+ method: HTTP_METHODS.DELETE,
1829
+ signal: options.signal,
1830
+ apiKey: options.apiKey
1831
+ }),
1832
+ deleteMany: (ids, options = {}) => transport.request(PATHS.FILES_BATCH_DELETE, {
1833
+ method: HTTP_METHODS.POST,
1834
+ body: { ids },
1835
+ signal: options.signal,
1836
+ apiKey: options.apiKey
1837
+ })
1838
+ });
1839
+
1840
+ const ListQuery$5 = (options) => ({ addressId: options.addressId });
1841
+ const SizeOf = (data) => data instanceof Blob ? data.size : data.byteLength;
1842
+ const SliceOf = (data, start, end) => {
1843
+ if (data instanceof Blob)
1844
+ return data.slice(start, end);
1845
+ if (data instanceof Uint8Array)
1846
+ return data.subarray(start, end);
1847
+ return new Uint8Array(data, start, end - start);
1848
+ };
1849
+ const Imports = (transport) => {
1850
+ const create = (body, options = {}) => transport.request(PATHS.IMPORTS, {
1851
+ method: HTTP_METHODS.POST,
1852
+ body,
1853
+ signal: options.signal,
1854
+ apiKey: options.apiKey
1855
+ });
1856
+ const uploadChunk = (id, file, chunk, data, options = {}) => transport.request(ImportChunkPath(id, file, chunk), {
1857
+ method: HTTP_METHODS.PUT,
1858
+ raw: data,
1859
+ repeatable: true,
1860
+ signal: options.signal,
1861
+ apiKey: options.apiKey
1862
+ });
1863
+ const start = (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.START), {
1864
+ method: HTTP_METHODS.POST,
1865
+ repeatable: true,
1866
+ signal: options.signal,
1867
+ apiKey: options.apiKey
1868
+ });
1869
+ return {
1870
+ list: (options = {}) => FetchPage(transport, PATHS.IMPORTS, CURSOR_STYLES.CURSOR, options, ListQuery$5(options)),
1871
+ listAll: (options = {}) => CollectAll(transport, PATHS.IMPORTS, CURSOR_STYLES.CURSOR, options, ListQuery$5(options)),
1872
+ iterate: (options = {}) => IteratePages(transport, PATHS.IMPORTS, CURSOR_STYLES.CURSOR, options, ListQuery$5(options)),
1873
+ get: (id, options = {}) => transport.request(ImportPath(id), { signal: options.signal, apiKey: options.apiKey }),
1874
+ create,
1875
+ uploadState: (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.UPLOAD), {
1876
+ signal: options.signal,
1877
+ apiKey: options.apiKey
1878
+ }),
1879
+ uploadChunk,
1880
+ start,
1881
+ cancel: (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.CANCEL), {
1882
+ method: HTTP_METHODS.POST,
1883
+ signal: options.signal,
1884
+ apiKey: options.apiKey
1885
+ }),
1886
+ listFailures: (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.FAILURES), {
1887
+ query: { after: options.after, limit: options.limit },
1888
+ signal: options.signal,
1889
+ apiKey: options.apiKey
1890
+ }),
1891
+ deleteUpload: (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.UPLOAD), {
1892
+ method: HTTP_METHODS.DELETE,
1893
+ signal: options.signal,
1894
+ apiKey: options.apiKey
1895
+ }),
1896
+ importFiles: async (input, options = {}) => {
1897
+ const created = await create({
1898
+ addressId: input.addressId,
1899
+ files: input.files.map(file => ({ name: file.name, bytes: SizeOf(file.data) })),
1900
+ options: input.options
1901
+ }, options);
1902
+ if (input.files.length === 0)
1903
+ return created;
1904
+ const total = created.totalBytes;
1905
+ let uploaded = 0;
1906
+ for (const [index, file] of input.files.entries()) {
1907
+ const chunks = created.files[index]?.chunks ?? 1;
1908
+ for (let chunk = 0; chunk < chunks; chunk++) {
1909
+ const begin = chunk * created.chunkBytes;
1910
+ const end = Math.min(SizeOf(file.data), begin + created.chunkBytes);
1911
+ await uploadChunk(created.id, index, chunk, SliceOf(file.data, begin, end), options);
1912
+ uploaded += end - begin;
1913
+ input.onProgress?.(uploaded, total);
1914
+ }
1915
+ }
1916
+ return start(created.id, options);
1917
+ }
1918
+ };
1919
+ };
1920
+
1921
+ const WindowQuery$2 = (options) => ({
1922
+ [QUERY_KEYS.SINCE]: options.since === undefined ? undefined : ToInstant(options.since),
1923
+ [QUERY_KEYS.UNTIL]: options.until === undefined ? undefined : ToInstant(options.until)
1924
+ });
1925
+ const RequestQuery = (options) => ({
1926
+ ...WindowQuery$2(options),
1927
+ [QUERY_KEYS.FAILED_ONLY]: options.failedOnly === undefined ? undefined : String(options.failedOnly)
1928
+ });
1929
+ const WorkspaceRequestQuery = (options) => ({
1930
+ ...RequestQuery(options),
1931
+ [QUERY_KEYS.KEY_IDS]: options.keyIds?.join(LIST_SEPARATOR)
1932
+ });
1933
+ const WorkspaceActivityQuery$1 = (options) => ({
1934
+ ...WindowQuery$2(options),
1935
+ [QUERY_KEYS.KEY_IDS]: options.keyIds?.join(LIST_SEPARATOR)
1936
+ });
1937
+ const Keys = (transport) => ({
1938
+ list: (options = {}) => FetchPage(transport, PATHS.KEYS, CURSOR_STYLES.CURSOR, options),
1939
+ listAll: (options = {}) => CollectAll(transport, PATHS.KEYS, CURSOR_STYLES.CURSOR, options),
1940
+ iterate: (options = {}) => IteratePages(transport, PATHS.KEYS, CURSOR_STYLES.CURSOR, options),
1941
+ get: (id, options = {}) => transport.request(KeyPath(id), { signal: options.signal, apiKey: options.apiKey }),
1942
+ create: (body, options = {}) => transport.request(PATHS.KEYS, {
1943
+ method: HTTP_METHODS.POST,
1944
+ body,
1945
+ signal: options.signal,
1946
+ apiKey: options.apiKey
1947
+ }),
1948
+ update: (id, patch, options = {}) => transport.request(KeyPath(id), {
1949
+ method: HTTP_METHODS.PATCH,
1950
+ body: patch,
1951
+ repeatable: true,
1952
+ signal: options.signal,
1953
+ apiKey: options.apiKey
1954
+ }),
1955
+ delete: (id, options = {}) => transport.request(KeyPath(id), {
1956
+ method: HTTP_METHODS.DELETE,
1957
+ signal: options.signal,
1958
+ apiKey: options.apiKey
1959
+ }),
1960
+ rotate: (id, options = {}) => transport.request(KeyChildPath(id, SEGMENTS.ROTATE), {
1961
+ method: HTTP_METHODS.POST,
1962
+ signal: options.signal,
1963
+ apiKey: options.apiKey
1964
+ }),
1965
+ revoke: (id, body = {}, options = {}) => transport.request(KeyChildPath(id, SEGMENTS.REVOKE), {
1966
+ method: HTTP_METHODS.POST,
1967
+ body,
1968
+ repeatable: true,
1969
+ signal: options.signal,
1970
+ apiKey: options.apiKey
1971
+ }),
1972
+ listRequests: (id, options = {}) => FetchPage(transport, KeyChildPath(id, SEGMENTS.REQUESTS), CURSOR_STYLES.CURSOR, options, RequestQuery(options)),
1973
+ listAllRequests: (id, options = {}) => CollectAll(transport, KeyChildPath(id, SEGMENTS.REQUESTS), CURSOR_STYLES.CURSOR, options, RequestQuery(options)),
1974
+ iterateRequests: (id, options = {}) => IteratePages(transport, KeyChildPath(id, SEGMENTS.REQUESTS), CURSOR_STYLES.CURSOR, options, RequestQuery(options)),
1975
+ listActivity: (id, options = {}) => FetchPage(transport, KeyChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery$2(options)),
1976
+ listAllActivity: (id, options = {}) => CollectAll(transport, KeyChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery$2(options)),
1977
+ iterateActivity: (id, options = {}) => IteratePages(transport, KeyChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery$2(options)),
1978
+ listWorkspaceRequests: (options = {}) => FetchPage(transport, PATHS.KEYS_REQUESTS, CURSOR_STYLES.CURSOR, options, WorkspaceRequestQuery(options)),
1979
+ listAllWorkspaceRequests: (options = {}) => CollectAll(transport, PATHS.KEYS_REQUESTS, CURSOR_STYLES.CURSOR, options, WorkspaceRequestQuery(options)),
1980
+ iterateWorkspaceRequests: (options = {}) => IteratePages(transport, PATHS.KEYS_REQUESTS, CURSOR_STYLES.CURSOR, options, WorkspaceRequestQuery(options)),
1981
+ listWorkspaceActivity: (options = {}) => FetchPage(transport, PATHS.KEYS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery$1(options)),
1982
+ listAllWorkspaceActivity: (options = {}) => CollectAll(transport, PATHS.KEYS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery$1(options)),
1983
+ iterateWorkspaceActivity: (options = {}) => IteratePages(transport, PATHS.KEYS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery$1(options))
1984
+ });
1985
+
1986
+ const ProviderImports = (transport) => ({
1987
+ inspect: (apiKey, options = {}) => transport.request(PATHS.PROVIDER_IMPORTS_INSPECT, {
1988
+ method: HTTP_METHODS.POST,
1989
+ body: { apiKey },
1990
+ signal: options.signal,
1991
+ apiKey: options.apiKey
1992
+ }),
1993
+ create: (body, options = {}) => transport.request(PATHS.PROVIDER_IMPORTS, {
1994
+ method: HTTP_METHODS.POST,
1995
+ body,
1996
+ signal: options.signal,
1997
+ apiKey: options.apiKey
1998
+ }),
1999
+ list: (options = {}) => FetchPage(transport, PATHS.PROVIDER_IMPORTS, CURSOR_STYLES.CURSOR, options),
2000
+ listAll: (options = {}) => CollectAll(transport, PATHS.PROVIDER_IMPORTS, CURSOR_STYLES.CURSOR, options),
2001
+ iterate: (options = {}) => IteratePages(transport, PATHS.PROVIDER_IMPORTS, CURSOR_STYLES.CURSOR, options),
2002
+ get: (id, options = {}) => transport.request(ProviderImportPath(id), { signal: options.signal, apiKey: options.apiKey }),
2003
+ cancel: (id, options = {}) => transport.request(ProviderImportChildPath(id, SEGMENTS.CANCEL), {
2004
+ method: HTTP_METHODS.POST,
2005
+ signal: options.signal,
2006
+ apiKey: options.apiKey
2007
+ })
2008
+ });
2009
+
1177
2010
  const Labels = (transport) => ({
1178
- list: (options = {}) => FetchList(transport, PATHS.LABELS, options),
2011
+ list: (options = {}) => FetchPage(transport, PATHS.LABELS, CURSOR_STYLES.CURSOR, options),
2012
+ listAll: (options = {}) => CollectAll(transport, PATHS.LABELS, CURSOR_STYLES.CURSOR, options),
2013
+ iterate: (options = {}) => IteratePages(transport, PATHS.LABELS, CURSOR_STYLES.CURSOR, options),
2014
+ listColors: (options = {}) => FetchList(transport, PATHS.LABELS_COLORS, options),
1179
2015
  get: (id, options = {}) => transport.request(LabelPath(id), { signal: options.signal, apiKey: options.apiKey }),
1180
2016
  create: (body, options = {}) => transport.request(PATHS.LABELS, {
1181
2017
  method: HTTP_METHODS.POST,
@@ -1183,9 +2019,9 @@ const Labels = (transport) => ({
1183
2019
  signal: options.signal,
1184
2020
  apiKey: options.apiKey
1185
2021
  }),
1186
- update: (id, body, options = {}) => transport.request(LabelPath(id), {
2022
+ update: (id, patch, options = {}) => transport.request(LabelPath(id), {
1187
2023
  method: HTTP_METHODS.PATCH,
1188
- body,
2024
+ body: patch,
1189
2025
  repeatable: true,
1190
2026
  signal: options.signal,
1191
2027
  apiKey: options.apiKey
@@ -1203,11 +2039,18 @@ const Languages = (transport) => ({
1203
2039
 
1204
2040
  const Me = (transport) => ({
1205
2041
  get: (options = {}) => transport.request(PATHS.KEYS_SELF, { signal: options.signal, apiKey: options.apiKey }),
1206
- ping: (options = {}) => transport.request(PATHS.PING, { signal: options.signal, apiKey: options.apiKey })
2042
+ ping: (options = {}) => transport.request(PATHS.PING, { signal: options.signal, apiKey: options.apiKey }),
2043
+ rotate: (options = {}) => transport.request(PATHS.KEYS_SELF_ROTATE, {
2044
+ method: HTTP_METHODS.POST,
2045
+ signal: options.signal,
2046
+ apiKey: options.apiKey
2047
+ })
1207
2048
  });
1208
2049
 
1209
2050
  const Members = (transport) => ({
1210
- list: (options = {}) => FetchList(transport, PATHS.MEMBERS, options),
2051
+ list: (options = {}) => FetchPage(transport, PATHS.MEMBERS, CURSOR_STYLES.CURSOR, options),
2052
+ listAll: (options = {}) => CollectAll(transport, PATHS.MEMBERS, CURSOR_STYLES.CURSOR, options),
2053
+ iterate: (options = {}) => IteratePages(transport, PATHS.MEMBERS, CURSOR_STYLES.CURSOR, options),
1211
2054
  get: (userId, options = {}) => transport.request(MemberPath(userId), { signal: options.signal, apiKey: options.apiKey }),
1212
2055
  add: (body, options = {}) => transport.request(PATHS.MEMBERS, {
1213
2056
  method: HTTP_METHODS.POST,
@@ -1238,11 +2081,26 @@ const Members = (transport) => ({
1238
2081
  method: HTTP_METHODS.DELETE,
1239
2082
  signal: options.signal,
1240
2083
  apiKey: options.apiKey
2084
+ }),
2085
+ listInvitations: (options = {}) => FetchPage(transport, PATHS.MEMBERS_INVITATIONS, CURSOR_STYLES.CURSOR, options),
2086
+ listAllInvitations: (options = {}) => CollectAll(transport, PATHS.MEMBERS_INVITATIONS, CURSOR_STYLES.CURSOR, options),
2087
+ iterateInvitations: (options = {}) => IteratePages(transport, PATHS.MEMBERS_INVITATIONS, CURSOR_STYLES.CURSOR, options),
2088
+ revokeInvitation: (invitationId, options = {}) => transport.request(MemberInvitationPath(invitationId), {
2089
+ method: HTTP_METHODS.DELETE,
2090
+ signal: options.signal,
2091
+ apiKey: options.apiKey
2092
+ }),
2093
+ resendInvitation: (invitationId, options = {}) => transport.request(MemberInvitationResendPath(invitationId), {
2094
+ method: HTTP_METHODS.POST,
2095
+ signal: options.signal,
2096
+ apiKey: options.apiKey
1241
2097
  })
1242
2098
  });
1243
2099
 
1244
2100
  const Roles = (transport) => ({
1245
- list: (options = {}) => FetchList(transport, PATHS.ROLES, options),
2101
+ list: (options = {}) => FetchPage(transport, PATHS.ROLES, CURSOR_STYLES.CURSOR, options),
2102
+ listAll: (options = {}) => CollectAll(transport, PATHS.ROLES, CURSOR_STYLES.CURSOR, options),
2103
+ iterate: (options = {}) => IteratePages(transport, PATHS.ROLES, CURSOR_STYLES.CURSOR, options),
1246
2104
  get: (id, options = {}) => transport.request(RolePath(id), { signal: options.signal, apiKey: options.apiKey }),
1247
2105
  create: (body, options = {}) => transport.request(PATHS.ROLES, {
1248
2106
  method: HTTP_METHODS.POST,
@@ -1266,7 +2124,7 @@ const Roles = (transport) => ({
1266
2124
  listPermissions: (options = {}) => FetchList(transport, PATHS.ROLES_PERMISSIONS, options)
1267
2125
  });
1268
2126
 
1269
- const ListQuery$2 = (options) => ({
2127
+ const ListQuery$4 = (options) => ({
1270
2128
  [QUERY_KEYS.ENABLED]: options.enabled === undefined ? undefined : String(options.enabled)
1271
2129
  });
1272
2130
  const RunsQuery = (options) => ({
@@ -1274,9 +2132,9 @@ const RunsQuery = (options) => ({
1274
2132
  [QUERY_KEYS.THREAD_ID]: options.threadId
1275
2133
  });
1276
2134
  const Rules = (transport) => ({
1277
- list: (options = {}) => FetchPage(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
1278
- listAll: (options = {}) => CollectAll(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
1279
- iterate: (options = {}) => IteratePages(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
2135
+ list: (options = {}) => FetchPage(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$4(options)),
2136
+ listAll: (options = {}) => CollectAll(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$4(options)),
2137
+ iterate: (options = {}) => IteratePages(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$4(options)),
1280
2138
  get: (id, options = {}) => transport.request(RulePath(id), { signal: options.signal, apiKey: options.apiKey }),
1281
2139
  create: (body, options = {}) => transport.request(PATHS.RULES, {
1282
2140
  method: HTTP_METHODS.POST,
@@ -1318,9 +2176,14 @@ const Rules = (transport) => ({
1318
2176
  });
1319
2177
 
1320
2178
  const Settings = (transport) => ({
1321
- get: (options = {}) => transport.request(PATHS.SETTINGS, { signal: options.signal, apiKey: options.apiKey }),
2179
+ get: (options = {}) => transport.request(PATHS.SETTINGS, {
2180
+ query: { [QUERY_KEYS.ADDRESS]: options.address },
2181
+ signal: options.signal,
2182
+ apiKey: options.apiKey
2183
+ }),
1322
2184
  update: (patch, options = {}) => transport.request(PATHS.SETTINGS, {
1323
2185
  method: HTTP_METHODS.PATCH,
2186
+ query: { [QUERY_KEYS.ADDRESS]: options.address },
1324
2187
  body: patch,
1325
2188
  repeatable: true,
1326
2189
  signal: options.signal,
@@ -1328,6 +2191,54 @@ const Settings = (transport) => ({
1328
2191
  })
1329
2192
  });
1330
2193
 
2194
+ const ListQuery$3 = (options) => ({
2195
+ [QUERY_KEYS.Q]: options.q,
2196
+ [QUERY_KEYS.REASON]: options.reason
2197
+ });
2198
+ const Suppressions = (transport) => ({
2199
+ list: (options = {}) => FetchPage(transport, PATHS.SUPPRESSIONS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
2200
+ listAll: (options = {}) => CollectAll(transport, PATHS.SUPPRESSIONS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
2201
+ iterate: (options = {}) => IteratePages(transport, PATHS.SUPPRESSIONS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
2202
+ get: (id, options = {}) => transport.request(SuppressionPath(id), { signal: options.signal, apiKey: options.apiKey }),
2203
+ add: (body, options = {}) => transport.request(PATHS.SUPPRESSIONS, {
2204
+ method: HTTP_METHODS.POST,
2205
+ body,
2206
+ repeatable: true,
2207
+ signal: options.signal,
2208
+ apiKey: options.apiKey
2209
+ }),
2210
+ remove: (id, options = {}) => transport.request(SuppressionPath(id), {
2211
+ method: HTTP_METHODS.DELETE,
2212
+ signal: options.signal,
2213
+ apiKey: options.apiKey
2214
+ })
2215
+ });
2216
+
2217
+ const MessagePage = async (transport, inboxId, options) => {
2218
+ const envelope = await transport.request(TempMessagesPath(inboxId), {
2219
+ query: { [QUERY_KEYS.LIMIT]: options.limit, [QUERY_KEYS.CURSOR]: options.cursor },
2220
+ inboxToken: options.inboxToken,
2221
+ signal: options.signal
2222
+ });
2223
+ const nextCursor = typeof envelope?.nextCursor === 'string' && envelope.nextCursor.length > 0 ? envelope.nextCursor : null;
2224
+ return {
2225
+ items: envelope?.data ?? [],
2226
+ hasMore: typeof envelope?.hasMore === 'boolean' ? envelope.hasMore : nextCursor !== null,
2227
+ nextCursor,
2228
+ expiresAt: envelope?.expiresAt
2229
+ };
2230
+ };
2231
+ const IterateMessages = async function* (transport, inboxId, options) {
2232
+ let cursor = options.cursor;
2233
+ for (;;) {
2234
+ const page = await MessagePage(transport, inboxId, { ...options, cursor });
2235
+ for (const item of page.items)
2236
+ yield item;
2237
+ if (!page.hasMore || !page.nextCursor || page.nextCursor === cursor)
2238
+ return;
2239
+ cursor = page.nextCursor;
2240
+ }
2241
+ };
1331
2242
  const TempMail = (transport) => ({
1332
2243
  listDomains: async (options = {}) => (await transport.request(PATHS.TEMP_MAIL_DOMAINS, {
1333
2244
  anonymous: true,
@@ -1353,14 +2264,14 @@ const TempMail = (transport) => ({
1353
2264
  inboxToken: options.inboxToken,
1354
2265
  signal: options.signal
1355
2266
  }),
1356
- listMessages: async (inboxId, options = {}) => {
1357
- const envelope = await transport.request(TempMessagesPath(inboxId), {
1358
- query: { [QUERY_KEYS.LIMIT]: options.limit },
1359
- inboxToken: options.inboxToken,
1360
- signal: options.signal
1361
- });
1362
- return { items: envelope?.data ?? [], expiresAt: envelope?.expiresAt };
2267
+ listMessages: (inboxId, options = {}) => MessagePage(transport, inboxId, options),
2268
+ listAllMessages: async (inboxId, options = {}) => {
2269
+ const all = [];
2270
+ for await (const message of IterateMessages(transport, inboxId, options))
2271
+ all.push(message);
2272
+ return all;
1363
2273
  },
2274
+ iterateMessages: (inboxId, options = {}) => IterateMessages(transport, inboxId, options),
1364
2275
  getMessage: (inboxId, messageId, options = {}) => transport.request(TempMessagePath(inboxId, messageId), {
1365
2276
  inboxToken: options.inboxToken,
1366
2277
  signal: options.signal
@@ -1376,11 +2287,32 @@ const TempMail = (transport) => ({
1376
2287
  }))?.data ?? []
1377
2288
  });
1378
2289
 
1379
- const ListQuery$1 = (options) => ({ [QUERY_KEYS.STATUS]: options.status });
2290
+ const ListQuery$2 = (options) => ({
2291
+ [QUERY_KEYS.STATUS]: options.status,
2292
+ [QUERY_KEYS.SEARCH]: options.search,
2293
+ [QUERY_KEYS.SORT]: options.sort
2294
+ });
2295
+ const Flag$1 = (value) => value === undefined ? undefined : String(value);
2296
+ const WindowQuery$1 = (options) => ({
2297
+ [QUERY_KEYS.DAYS]: options.days,
2298
+ [QUERY_KEYS.MINUTES]: options.minutes,
2299
+ [QUERY_KEYS.GRAIN]: options.grain,
2300
+ [QUERY_KEYS.OFFSET_MINUTES]: options.offsetMinutes
2301
+ });
1380
2302
  const Templates = (transport) => ({
1381
- list: (options = {}) => FetchPage(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$1(options)),
1382
- listAll: (options = {}) => CollectAll(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$1(options)),
1383
- iterate: (options = {}) => IteratePages(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$1(options)),
2303
+ list: (options = {}) => FetchPage(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
2304
+ listAll: (options = {}) => CollectAll(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
2305
+ iterate: (options = {}) => IteratePages(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
2306
+ listStarters: (options = {}) => FetchList(transport, PATHS.TEMPLATES_STARTERS, options),
2307
+ listFonts: (options = {}) => FetchList(transport, PATHS.TEMPLATES_FONTS, options),
2308
+ getStarter: (slug, options = {}) => transport.request(TemplateStarterPath(slug), { signal: options.signal, apiKey: options.apiKey }),
2309
+ render: (body, options = {}) => transport.request(PATHS.TEMPLATES_RENDER, {
2310
+ method: HTTP_METHODS.POST,
2311
+ body,
2312
+ repeatable: true,
2313
+ signal: options.signal,
2314
+ apiKey: options.apiKey
2315
+ }),
1384
2316
  get: (idOrSlug, options = {}) => transport.request(TemplatePath(idOrSlug), { signal: options.signal, apiKey: options.apiKey }),
1385
2317
  create: (body, options = {}) => transport.request(PATHS.TEMPLATES, {
1386
2318
  method: HTTP_METHODS.POST,
@@ -1399,7 +2331,33 @@ const Templates = (transport) => ({
1399
2331
  signal: options.signal,
1400
2332
  apiKey: options.apiKey
1401
2333
  }),
1402
- listVersions: (idOrSlug, options = {}) => FetchList(transport, TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), options),
2334
+ duplicate: (idOrSlug, body = {}, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.DUPLICATE), {
2335
+ method: HTTP_METHODS.POST,
2336
+ body,
2337
+ signal: options.signal,
2338
+ apiKey: options.apiKey
2339
+ }),
2340
+ replaceContent: (idOrSlug, body, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.CONTENT), {
2341
+ method: HTTP_METHODS.POST,
2342
+ body,
2343
+ signal: options.signal,
2344
+ apiKey: options.apiKey
2345
+ }),
2346
+ listVersions: (idOrSlug, options = {}) => FetchPage(transport, TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), CURSOR_STYLES.CURSOR, options),
2347
+ listAllVersions: (idOrSlug, options = {}) => CollectAll(transport, TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), CURSOR_STYLES.CURSOR, options),
2348
+ iterateVersions: (idOrSlug, options = {}) => IteratePages(transport, TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), CURSOR_STYLES.CURSOR, options),
2349
+ getVersion: (idOrSlug, version, options = {}) => transport.request(TemplateVersionPath(idOrSlug, version), { signal: options.signal, apiKey: options.apiKey }),
2350
+ deleteVersion: (idOrSlug, version, options = {}) => transport.request(TemplateVersionPath(idOrSlug, version), {
2351
+ method: HTTP_METHODS.DELETE,
2352
+ signal: options.signal,
2353
+ apiKey: options.apiKey
2354
+ }),
2355
+ restoreVersion: (idOrSlug, version, body = {}, options = {}) => transport.request(TemplateVersionChildPath(idOrSlug, version, SEGMENTS.RESTORE), {
2356
+ method: HTTP_METHODS.POST,
2357
+ body,
2358
+ signal: options.signal,
2359
+ apiKey: options.apiKey
2360
+ }),
1403
2361
  publish: (idOrSlug, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), {
1404
2362
  method: HTTP_METHODS.POST,
1405
2363
  repeatable: true,
@@ -1413,6 +2371,34 @@ const Templates = (transport) => ({
1413
2371
  signal: options.signal,
1414
2372
  apiKey: options.apiKey
1415
2373
  }),
2374
+ getAnalytics: (idOrSlug, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.ANALYTICS), {
2375
+ query: WindowQuery$1(options),
2376
+ signal: options.signal,
2377
+ apiKey: options.apiKey
2378
+ }),
2379
+ listSends: async (idOrSlug, options = {}) => {
2380
+ const envelope = await transport.request(TemplateChildPath(idOrSlug, SEGMENTS.SENDS), {
2381
+ query: {
2382
+ ...WindowQuery$1(options),
2383
+ [QUERY_KEYS.PAGE]: options.page,
2384
+ [QUERY_KEYS.PAGE_SIZE]: options.pageSize,
2385
+ [QUERY_KEYS.SEARCH]: options.search,
2386
+ [QUERY_KEYS.SOURCE]: options.source,
2387
+ [QUERY_KEYS.VERSION]: options.version,
2388
+ [QUERY_KEYS.OPENED]: Flag$1(options.opened),
2389
+ [QUERY_KEYS.CLICKED]: Flag$1(options.clicked),
2390
+ [QUERY_KEYS.TRACKED]: Flag$1(options.tracked)
2391
+ },
2392
+ signal: options.signal,
2393
+ apiKey: options.apiKey
2394
+ });
2395
+ return {
2396
+ items: envelope?.data ?? [],
2397
+ total: envelope?.total ?? 0,
2398
+ page: envelope?.page ?? 1,
2399
+ pageSize: envelope?.pageSize ?? 0
2400
+ };
2401
+ },
1416
2402
  send: (idOrSlug, body, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.SEND), {
1417
2403
  method: HTTP_METHODS.POST,
1418
2404
  body: TemplateSendToWire(body),
@@ -1424,15 +2410,19 @@ const Templates = (transport) => ({
1424
2410
  })
1425
2411
  });
1426
2412
 
1427
- const ListQuery = (options) => ({
2413
+ const ListQuery$1 = (options) => ({
1428
2414
  [QUERY_KEYS.FOLDER]: options.folder,
1429
2415
  [QUERY_KEYS.QUERY]: options.query,
1430
- [QUERY_KEYS.LABEL_IDS]: Array.isArray(options.labelIds) ? options.labelIds.join(LIST_SEPARATOR) : options.labelIds
2416
+ [QUERY_KEYS.LABEL_IDS]: Array.isArray(options.labelIds) ? options.labelIds.join(LIST_SEPARATOR) : options.labelIds,
2417
+ [QUERY_KEYS.SORT]: options.sort,
2418
+ [QUERY_KEYS.DATE_FROM]: options.dateFrom === undefined ? undefined : ToInstant(options.dateFrom),
2419
+ [QUERY_KEYS.DATE_TO]: options.dateTo === undefined ? undefined : ToInstant(options.dateTo),
2420
+ [QUERY_KEYS.FROM_CONTACTS]: options.fromContacts === undefined ? undefined : String(options.fromContacts)
1431
2421
  });
1432
2422
  const Threads = (transport) => ({
1433
- list: (options = {}) => FetchPage(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery(options)),
1434
- listAll: (options = {}) => CollectAll(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery(options)),
1435
- iterate: (options = {}) => IteratePages(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery(options)),
2423
+ list: (options = {}) => FetchPage(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$1(options)),
2424
+ listAll: (options = {}) => CollectAll(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$1(options)),
2425
+ iterate: (options = {}) => IteratePages(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$1(options)),
1436
2426
  get: (id, options = {}) => transport.request(ThreadPath(id), { signal: options.signal, apiKey: options.apiKey }),
1437
2427
  update: (id, patch, options = {}) => transport.request(ThreadPath(id), {
1438
2428
  method: HTTP_METHODS.PATCH,
@@ -1465,18 +2455,19 @@ const Threads = (transport) => ({
1465
2455
 
1466
2456
  const Flag = (value) => value === undefined ? undefined : String(value);
1467
2457
  const HitQuery = (options) => ({
1468
- [QUERY_KEYS.INCLUDE_MACHINE]: Flag(options.includeMachine),
1469
- [QUERY_KEYS.LIMIT]: options.limit
2458
+ [QUERY_KEYS.INCLUDE_MACHINE]: Flag(options.includeMachine)
2459
+ });
2460
+ const ListQuery = (options) => ({
2461
+ [QUERY_KEYS.OPENED]: Flag(options.opened),
2462
+ [QUERY_KEYS.CLICKED]: Flag(options.clicked),
2463
+ [QUERY_KEYS.DAYS]: options.days,
2464
+ [QUERY_KEYS.MINUTES]: options.minutes,
2465
+ [QUERY_KEYS.GRAIN]: options.grain
1470
2466
  });
1471
2467
  const Tracking = (transport) => ({
1472
- list: (options = {}) => FetchList(transport, PATHS.TRACKING, options, {
1473
- [QUERY_KEYS.OPENED]: Flag(options.opened),
1474
- [QUERY_KEYS.CLICKED]: Flag(options.clicked),
1475
- [QUERY_KEYS.DAYS]: options.days,
1476
- [QUERY_KEYS.MINUTES]: options.minutes,
1477
- [QUERY_KEYS.GRAIN]: options.grain,
1478
- [QUERY_KEYS.LIMIT]: options.limit
1479
- }),
2468
+ list: (options = {}) => FetchPage(transport, PATHS.TRACKING, CURSOR_STYLES.CURSOR, options, ListQuery(options)),
2469
+ listAll: (options = {}) => CollectAll(transport, PATHS.TRACKING, CURSOR_STYLES.CURSOR, options, ListQuery(options)),
2470
+ iterate: (options = {}) => IteratePages(transport, PATHS.TRACKING, CURSOR_STYLES.CURSOR, options, ListQuery(options)),
1480
2471
  getStats: (options = {}) => transport.request(PATHS.TRACKING_STATS, {
1481
2472
  query: {
1482
2473
  [QUERY_KEYS.DAYS]: options.days,
@@ -1488,12 +2479,34 @@ const Tracking = (transport) => ({
1488
2479
  apiKey: options.apiKey
1489
2480
  }),
1490
2481
  get: (id, options = {}) => transport.request(TrackingPath(id), { signal: options.signal, apiKey: options.apiKey }),
1491
- listOpens: (id, options = {}) => FetchList(transport, TrackingChildPath(id, SEGMENTS.OPENS), options, HitQuery(options)),
1492
- listClicks: (id, options = {}) => FetchList(transport, TrackingChildPath(id, SEGMENTS.CLICKS), options, HitQuery(options))
2482
+ listOpens: (id, options = {}) => FetchPage(transport, TrackingChildPath(id, SEGMENTS.OPENS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2483
+ listAllOpens: (id, options = {}) => CollectAll(transport, TrackingChildPath(id, SEGMENTS.OPENS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2484
+ iterateOpens: (id, options = {}) => IteratePages(transport, TrackingChildPath(id, SEGMENTS.OPENS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2485
+ listClicks: (id, options = {}) => FetchPage(transport, TrackingChildPath(id, SEGMENTS.CLICKS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2486
+ listAllClicks: (id, options = {}) => CollectAll(transport, TrackingChildPath(id, SEGMENTS.CLICKS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2487
+ iterateClicks: (id, options = {}) => IteratePages(transport, TrackingChildPath(id, SEGMENTS.CLICKS), CURSOR_STYLES.CURSOR, options, HitQuery(options))
1493
2488
  });
1494
2489
 
2490
+ const WindowQuery = (options) => ({
2491
+ [QUERY_KEYS.SINCE]: options.since === undefined ? undefined : ToInstant(options.since),
2492
+ [QUERY_KEYS.UNTIL]: options.until === undefined ? undefined : ToInstant(options.until)
2493
+ });
2494
+ const DeliveryQuery = (options) => ({
2495
+ ...WindowQuery(options),
2496
+ [QUERY_KEYS.STATUS]: options.status
2497
+ });
2498
+ const WorkspaceDeliveryQuery = (options) => ({
2499
+ ...DeliveryQuery(options),
2500
+ [QUERY_KEYS.ENDPOINT_IDS]: options.endpointIds?.join(LIST_SEPARATOR)
2501
+ });
2502
+ const WorkspaceActivityQuery = (options) => ({
2503
+ ...WindowQuery(options),
2504
+ [QUERY_KEYS.ENDPOINT_IDS]: options.endpointIds?.join(LIST_SEPARATOR)
2505
+ });
1495
2506
  const Webhooks = (transport) => ({
1496
- list: (options = {}) => FetchList(transport, PATHS.WEBHOOKS, options),
2507
+ list: (options = {}) => FetchPage(transport, PATHS.WEBHOOKS, CURSOR_STYLES.CURSOR, options),
2508
+ listAll: (options = {}) => CollectAll(transport, PATHS.WEBHOOKS, CURSOR_STYLES.CURSOR, options),
2509
+ iterate: (options = {}) => IteratePages(transport, PATHS.WEBHOOKS, CURSOR_STYLES.CURSOR, options),
1497
2510
  get: (id, options = {}) => transport.request(WebhookPath(id), { signal: options.signal, apiKey: options.apiKey }),
1498
2511
  create: (body, options = {}) => transport.request(PATHS.WEBHOOKS, {
1499
2512
  method: HTTP_METHODS.POST,
@@ -1523,13 +2536,34 @@ const Webhooks = (transport) => ({
1523
2536
  signal: options.signal,
1524
2537
  apiKey: options.apiKey
1525
2538
  }),
1526
- listDeliveries: (id, options = {}) => FetchList(transport, WebhookChildPath(id, SEGMENTS.DELIVERIES), options)
2539
+ listDeliveries: (id, options = {}) => FetchPage(transport, WebhookChildPath(id, SEGMENTS.DELIVERIES), CURSOR_STYLES.CURSOR, options, DeliveryQuery(options)),
2540
+ listAllDeliveries: (id, options = {}) => CollectAll(transport, WebhookChildPath(id, SEGMENTS.DELIVERIES), CURSOR_STYLES.CURSOR, options, DeliveryQuery(options)),
2541
+ iterateDeliveries: (id, options = {}) => IteratePages(transport, WebhookChildPath(id, SEGMENTS.DELIVERIES), CURSOR_STYLES.CURSOR, options, DeliveryQuery(options)),
2542
+ listWorkspaceDeliveries: (options = {}) => FetchPage(transport, PATHS.WEBHOOKS_DELIVERIES, CURSOR_STYLES.CURSOR, options, WorkspaceDeliveryQuery(options)),
2543
+ listAllWorkspaceDeliveries: (options = {}) => CollectAll(transport, PATHS.WEBHOOKS_DELIVERIES, CURSOR_STYLES.CURSOR, options, WorkspaceDeliveryQuery(options)),
2544
+ iterateWorkspaceDeliveries: (options = {}) => IteratePages(transport, PATHS.WEBHOOKS_DELIVERIES, CURSOR_STYLES.CURSOR, options, WorkspaceDeliveryQuery(options)),
2545
+ listActivity: (id, options = {}) => FetchPage(transport, WebhookChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery(options)),
2546
+ listAllActivity: (id, options = {}) => CollectAll(transport, WebhookChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery(options)),
2547
+ iterateActivity: (id, options = {}) => IteratePages(transport, WebhookChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery(options)),
2548
+ listWorkspaceActivity: (options = {}) => FetchPage(transport, PATHS.WEBHOOKS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery(options)),
2549
+ listAllWorkspaceActivity: (options = {}) => CollectAll(transport, PATHS.WEBHOOKS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery(options)),
2550
+ iterateWorkspaceActivity: (options = {}) => IteratePages(transport, PATHS.WEBHOOKS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery(options)),
2551
+ getDelivery: (id, deliveryId, options = {}) => transport.request(WebhookDeliveryPath(id, deliveryId), {
2552
+ signal: options.signal,
2553
+ apiKey: options.apiKey
2554
+ }),
2555
+ replayDelivery: (id, deliveryId, options = {}) => transport.request(WebhookDeliveryReplayPath(id, deliveryId), {
2556
+ method: HTTP_METHODS.POST,
2557
+ signal: options.signal,
2558
+ apiKey: options.apiKey
2559
+ })
1527
2560
  });
1528
2561
 
1529
2562
  class OpenEmail {
1530
2563
  transport;
1531
2564
  mode;
1532
2565
  me;
2566
+ keys;
1533
2567
  addresses;
1534
2568
  languages;
1535
2569
  emails;
@@ -1539,13 +2573,19 @@ class OpenEmail {
1539
2573
  drafts;
1540
2574
  labels;
1541
2575
  contacts;
2576
+ audiences;
2577
+ broadcasts;
1542
2578
  domains;
1543
2579
  rules;
1544
2580
  webhooks;
2581
+ imports;
2582
+ providerImports;
1545
2583
  calendar;
1546
2584
  settings;
1547
2585
  roles;
1548
2586
  members;
2587
+ suppressions;
2588
+ files;
1549
2589
  tempMail;
1550
2590
  constructor(configuration) {
1551
2591
  const options = typeof configuration === 'string' ? { apiKey: configuration } : configuration;
@@ -1555,6 +2595,7 @@ class OpenEmail {
1555
2595
  this.transport = new Transport(options);
1556
2596
  this.mode = ModeOf(options.apiKey);
1557
2597
  this.me = Me(this.transport);
2598
+ this.keys = Keys(this.transport);
1558
2599
  this.addresses = Addresses(this.transport);
1559
2600
  this.languages = Languages(this.transport);
1560
2601
  this.emails = Emails(this.transport);
@@ -1564,13 +2605,19 @@ class OpenEmail {
1564
2605
  this.drafts = Drafts(this.transport);
1565
2606
  this.labels = Labels(this.transport);
1566
2607
  this.contacts = Contacts(this.transport);
2608
+ this.audiences = Audiences(this.transport);
2609
+ this.broadcasts = Broadcasts(this.transport);
1567
2610
  this.domains = Domains(this.transport);
1568
2611
  this.rules = Rules(this.transport);
1569
2612
  this.webhooks = Webhooks(this.transport);
2613
+ this.imports = Imports(this.transport);
2614
+ this.providerImports = ProviderImports(this.transport);
1570
2615
  this.calendar = Calendar(this.transport);
1571
2616
  this.settings = Settings(this.transport);
1572
2617
  this.roles = Roles(this.transport);
1573
2618
  this.members = Members(this.transport);
2619
+ this.suppressions = Suppressions(this.transport);
2620
+ this.files = Files(this.transport);
1574
2621
  this.tempMail = TempMail(this.transport);
1575
2622
  }
1576
2623
  get raw() {
@@ -1746,18 +2793,33 @@ const languageByCode = LanguageByCode;
1746
2793
  const isRtlLanguage = IsRtlLanguage;
1747
2794
 
1748
2795
  exports.API_SCOPES = API_SCOPES;
2796
+ exports.BROADCAST_STATUSES = BROADCAST_STATUSES;
2797
+ exports.CONTACT_BLOCK_LISTS = CONTACT_BLOCK_LISTS;
2798
+ exports.CONTACT_PHOTO_TYPES = CONTACT_PHOTO_TYPES;
2799
+ exports.CONTACT_THREAD_SORTS = CONTACT_THREAD_SORTS;
1749
2800
  exports.ERROR_TYPES = ERROR_TYPES;
2801
+ exports.FILE_DIRECTIONS = FILE_DIRECTIONS;
2802
+ exports.FILE_KINDS = FILE_KINDS;
2803
+ exports.FILE_SORTS = FILE_SORTS;
2804
+ exports.FILE_USAGES = FILE_USAGES;
1750
2805
  exports.LANGUAGES = LANGUAGES;
1751
2806
  exports.MESSAGE_ENCRYPTION_FORMATS = MESSAGE_ENCRYPTION_FORMATS;
1752
2807
  exports.OpenEmail = OpenEmail;
1753
2808
  exports.OpenEmailApiError = OpenEmailApiError;
1754
2809
  exports.OpenEmailNetworkError = OpenEmailNetworkError;
1755
2810
  exports.PAGE_LIMITS = PAGE_LIMITS;
2811
+ exports.PEOPLE_SORTS = PEOPLE_SORTS;
2812
+ exports.PROVIDER_IMPORT_DOMAIN_STATES = PROVIDER_IMPORT_DOMAIN_STATES;
2813
+ exports.PROVIDER_IMPORT_RESOURCES = PROVIDER_IMPORT_RESOURCES;
2814
+ exports.PROVIDER_IMPORT_STATUSES = PROVIDER_IMPORT_STATUSES;
1756
2815
  exports.RULE_ACTIONS = RULE_ACTIONS;
1757
2816
  exports.RULE_FIELDS = RULE_FIELDS;
1758
2817
  exports.RULE_OPERATORS = RULE_OPERATORS;
2818
+ exports.SUPPRESSION_REASONS = SUPPRESSION_REASONS;
2819
+ exports.THREAD_SORTS = THREAD_SORTS;
1759
2820
  exports.VERSION = VERSION;
1760
2821
  exports.WEBHOOK_EVENTS = WEBHOOK_EVENTS;
2822
+ exports.WEBHOOK_REPLAY_ERROR_CODES = WEBHOOK_REPLAY_ERROR_CODES;
1761
2823
  exports.WEBHOOK_SIGNATURE_HEADERS = WEBHOOK_SIGNATURE_HEADERS;
1762
2824
  exports.createClient = createClient;
1763
2825
  exports.createOpenEmail = createOpenEmail;