@openemail/sdk 0.0.1 → 0.0.2

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 +1223 -206
  3. package/index.d.cts +2009 -131
  4. package/index.d.ts +2009 -131
  5. package/index.js +1210 -207
  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.2";
6
15
 
7
16
  const BUILD_BASE_URL = 'https://api.openemail.uk';
8
17
 
@@ -45,43 +54,59 @@ const CLIENT_MESSAGES = {
45
54
  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
55
  };
47
56
 
48
- const MESSAGE_ENCRYPTION_FORMATS = [
49
- 'pgp-mime',
50
- 'pgp-signed',
51
- 'pgp-inline',
52
- 'smime-encrypted',
53
- 'smime-signed'
57
+ const PEOPLE_SORTS = {
58
+ RECENT: 'recent',
59
+ NAME: 'name',
60
+ THREADS: 'threads'
61
+ };
62
+ const CONTACT_THREAD_SORTS = {
63
+ NEWEST: 'newest',
64
+ OLDEST: 'oldest',
65
+ SENDER: 'sender',
66
+ SUBJECT: 'subject'
67
+ };
68
+ const CONTACT_BLOCK_LISTS = {
69
+ BLOCKED_SENDERS: 'blockedSenders',
70
+ BLOCKED_DOMAINS: 'blockedDomains'
71
+ };
72
+ const CONTACT_PHOTO_TYPES = {
73
+ PNG: 'image/png',
74
+ JPEG: 'image/jpeg',
75
+ WEBP: 'image/webp',
76
+ GIF: 'image/gif'
77
+ };
78
+
79
+ const MESSAGE_ENCRYPTION_FORMATS = {
80
+ PGP_MIME: 'pgp-mime',
81
+ PGP_SIGNED: 'pgp-signed',
82
+ PGP_INLINE: 'pgp-inline',
83
+ SMIME_ENCRYPTED: 'smime-encrypted',
84
+ SMIME_SIGNED: 'smime-signed'
85
+ };
86
+ const SEALED_ENCRYPTION_FORMATS = [
87
+ MESSAGE_ENCRYPTION_FORMATS.PGP_MIME,
88
+ MESSAGE_ENCRYPTION_FORMATS.PGP_INLINE,
89
+ MESSAGE_ENCRYPTION_FORMATS.SMIME_ENCRYPTED
54
90
  ];
55
- const SEALED_ENCRYPTION_FORMATS = ['pgp-mime', 'pgp-inline', 'smime-encrypted'];
56
91
  const BASE64_CHUNK_SIZE = 0x8000;
57
92
 
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'
93
+ const ERROR_TYPES = {
94
+ INVALID_REQUEST_ERROR: 'invalid_request_error',
95
+ AUTHENTICATION_ERROR: 'authentication_error',
96
+ PERMISSION_ERROR: 'permission_error',
97
+ NOT_FOUND_ERROR: 'not_found_error',
98
+ CONFLICT_ERROR: 'conflict_error',
99
+ VALIDATION_ERROR: 'validation_error',
100
+ RATE_LIMIT_ERROR: 'rate_limit_error',
101
+ API_ERROR: 'api_error'
77
102
  };
78
103
  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
104
+ 401: ERROR_TYPES.AUTHENTICATION_ERROR,
105
+ 403: ERROR_TYPES.PERMISSION_ERROR,
106
+ 404: ERROR_TYPES.NOT_FOUND_ERROR,
107
+ 409: ERROR_TYPES.CONFLICT_ERROR,
108
+ 422: ERROR_TYPES.VALIDATION_ERROR,
109
+ 429: ERROR_TYPES.RATE_LIMIT_ERROR
85
110
  };
86
111
  const ERROR_CODES = {
87
112
  INSUFFICIENT_SCOPE: 'insufficient_scope',
@@ -92,9 +117,28 @@ const ERROR_NAMES = {
92
117
  NETWORK: 'OpenEmailNetworkError',
93
118
  TIMEOUT: 'TimeoutError'};
94
119
 
120
+ const FILE_SORTS = {
121
+ NEWEST: 'newest',
122
+ OLDEST: 'oldest',
123
+ LARGEST: 'largest',
124
+ NAME: 'name'
125
+ };
126
+ const FILE_KINDS = {
127
+ IMAGE: 'image',
128
+ PDF: 'pdf',
129
+ AUDIO: 'audio',
130
+ VIDEO: 'video',
131
+ TEXT: 'text'
132
+ };
133
+ const FILE_DIRECTIONS = {
134
+ INBOUND: 'inbound',
135
+ OUTBOUND: 'outbound'
136
+ };
137
+
95
138
  const HTTP_METHODS = {
96
139
  GET: 'GET',
97
140
  POST: 'POST',
141
+ PUT: 'PUT',
98
142
  PATCH: 'PATCH',
99
143
  DELETE: 'DELETE'
100
144
  };
@@ -109,7 +153,8 @@ const HEADER_KEYS = {
109
153
  };
110
154
  const CONTENT_TYPES = {
111
155
  JSON: 'application/json',
112
- CALENDAR: 'text/calendar'
156
+ CALENDAR: 'text/calendar',
157
+ OCTET_STREAM: 'application/octet-stream'
113
158
  };
114
159
  const RETRY = {
115
160
  STATUSES: [408, 429, 500, 502, 503, 504],
@@ -121,6 +166,28 @@ const RETRY = {
121
166
  };
122
167
  const IDEMPOTENCY_KEY_PREFIX = 'oe-';
123
168
 
169
+ const PROVIDER_IMPORT_RESOURCES = {
170
+ SUPPRESSIONS: 'suppressions',
171
+ AUDIENCES: 'audiences',
172
+ CONTACTS: 'contacts',
173
+ TEMPLATES: 'templates',
174
+ WEBHOOKS: 'webhooks',
175
+ DOMAINS: 'domains',
176
+ API_KEYS: 'api-keys'
177
+ };
178
+ const PROVIDER_IMPORT_STATUSES = {
179
+ QUEUED: 'queued',
180
+ RUNNING: 'running',
181
+ COMPLETED: 'completed',
182
+ FAILED: 'failed',
183
+ CANCELLED: 'cancelled'
184
+ };
185
+ const PROVIDER_IMPORT_DOMAIN_STATES = {
186
+ ABSENT: 'absent',
187
+ ADDED: 'added',
188
+ VERIFIED: 'verified'
189
+ };
190
+
124
191
  const LANGUAGES = [
125
192
  { code: 'en', label: 'English', native: 'English', flag: '🇬🇧', rtl: false },
126
193
  { code: 'es', label: 'Spanish', native: 'Español', flag: '🇪🇸', rtl: false },
@@ -357,6 +424,7 @@ const CURSOR_STYLES = {
357
424
  };
358
425
  const QUERY_KEYS = {
359
426
  LIMIT: 'limit',
427
+ CURSOR: 'cursor',
360
428
  STATUS: 'status',
361
429
  FROM: 'from',
362
430
  TO: 'to',
@@ -374,13 +442,41 @@ const QUERY_KEYS = {
374
442
  GRAIN: 'grain',
375
443
  OFFSET_MINUTES: 'offsetMinutes',
376
444
  INCLUDE_MACHINE: 'includeMachine',
377
- REASSIGN_TO: 'reassignTo'
445
+ REASSIGN_TO: 'reassignTo',
446
+ SOURCE: 'source',
447
+ ADDRESS: 'address',
448
+ SEARCH: 'search',
449
+ SORT: 'sort',
450
+ PAGE: 'page',
451
+ PAGE_SIZE: 'pageSize',
452
+ VERSION: 'version',
453
+ TRACKED: 'tracked',
454
+ Q: 'q',
455
+ AUDIENCE_IDS: 'audienceIds',
456
+ AUDIENCE_ID: 'audienceId',
457
+ BROADCAST_ID: 'broadcastId',
458
+ EMAIL: 'email',
459
+ BLOCKED: 'blocked',
460
+ DATE_FROM: 'dateFrom',
461
+ DATE_TO: 'dateTo',
462
+ FROM_CONTACTS: 'fromContacts',
463
+ REASON: 'reason',
464
+ KIND: 'kind',
465
+ ENDPOINT_IDS: 'endpointIds',
466
+ KEY_IDS: 'keyIds',
467
+ SINCE: 'since',
468
+ UNTIL: 'until',
469
+ FAILED_ONLY: 'failedOnly'
378
470
  };
379
471
  const LIST_SEPARATOR = ',';
380
472
 
381
473
  const PATHS = {
382
474
  PING: '/ping',
475
+ KEYS: '/keys',
476
+ KEYS_REQUESTS: '/keys/requests',
477
+ KEYS_ACTIVITY: '/keys/activity',
383
478
  KEYS_SELF: '/keys/self',
479
+ KEYS_SELF_ROTATE: '/keys/self/rotate',
384
480
  ADDRESSES: '/addresses',
385
481
  LANGUAGES: '/languages',
386
482
  EMAILS: '/emails',
@@ -389,10 +485,25 @@ const PATHS = {
389
485
  THREADS: '/threads',
390
486
  DRAFTS: '/drafts',
391
487
  LABELS: '/labels',
488
+ LABELS_COLORS: '/labels/colors',
392
489
  CONTACTS: '/contacts',
490
+ CONTACTS_PEOPLE: '/contacts/people',
491
+ CONTACTS_BATCH_DELETE: '/contacts/batch-delete',
492
+ AUDIENCES: '/audiences',
493
+ AUDIENCES_GROWTH: '/audiences/growth',
494
+ BROADCASTS: '/broadcasts',
495
+ BROADCASTS_PREVIEW: '/broadcasts/preview',
393
496
  DOMAINS: '/domains',
394
497
  WEBHOOKS: '/webhooks',
498
+ WEBHOOKS_DELIVERIES: '/webhooks/deliveries',
499
+ WEBHOOKS_ACTIVITY: '/webhooks/activity',
500
+ IMPORTS: '/imports',
501
+ PROVIDER_IMPORTS: '/provider-imports',
502
+ PROVIDER_IMPORTS_INSPECT: '/provider-imports/inspect',
395
503
  TEMPLATES: '/templates',
504
+ TEMPLATES_FONTS: '/templates/fonts',
505
+ TEMPLATES_RENDER: '/templates/render',
506
+ TEMPLATES_STARTERS: '/templates/starters',
396
507
  RULES: '/rules',
397
508
  RULES_RUNS: '/rules/runs',
398
509
  RULES_REORDER: '/rules/reorder',
@@ -403,28 +514,57 @@ const PATHS = {
403
514
  ROLES: '/roles',
404
515
  ROLES_PERMISSIONS: '/roles/permissions',
405
516
  MEMBERS: '/members',
517
+ MEMBERS_INVITATIONS: '/members/invitations',
518
+ SUPPRESSIONS: '/suppressions',
519
+ FILES: '/files',
406
520
  TEMP_MAIL_DOMAINS: '/temp-mail/domains',
407
521
  TEMP_MAIL_INBOXES: '/temp-mail/inboxes'
408
522
  };
409
523
  const SEGMENTS = {
524
+ ACTIVITY: 'activity',
410
525
  ADDRESSES: 'addresses',
526
+ ANALYTICS: 'analytics',
411
527
  ATTACHMENTS: 'attachments',
528
+ AUDIENCES: 'audiences',
529
+ BATCH: 'batch',
530
+ BATCH_REMOVE: 'batch-remove',
531
+ BLOCK: 'block',
412
532
  CANCEL: 'cancel',
533
+ CHUNKS: 'chunks',
413
534
  CLICKS: 'clicks',
535
+ CONTACTS: 'contacts',
536
+ CONTENT: 'content',
414
537
  DELIVERIES: 'deliveries',
538
+ DUPLICATE: 'duplicate',
539
+ EMPTY: 'empty',
415
540
  EVENTS: 'events',
416
541
  EXTEND: 'extend',
542
+ FAILURES: 'failures',
543
+ FILES: 'files',
417
544
  ICS: 'ics',
545
+ IMPORT: 'import',
546
+ LINKS: 'links',
418
547
  MESSAGES: 'messages',
419
548
  OPENS: 'opens',
549
+ PHOTO: 'photo',
420
550
  PREVIEW: 'preview',
551
+ REPLAY: 'replay',
552
+ REQUESTS: 'requests',
553
+ RESEND: 'resend',
554
+ RESTORE: 'restore',
555
+ REVOKE: 'revoke',
556
+ ROTATE: 'rotate',
421
557
  ROTATE_SECRET: 'rotate-secret',
422
558
  SEND: 'send',
559
+ SENDS: 'sends',
423
560
  SNOOZE: 'snooze',
561
+ START: 'start',
424
562
  TEST: 'test',
563
+ THREADS: 'threads',
425
564
  TRACKING: 'tracking',
426
565
  TRASH: 'trash',
427
566
  UNSNOOZE: 'unsnooze',
567
+ UPLOAD: 'upload',
428
568
  VERSIONS: 'versions'
429
569
  };
430
570
 
@@ -434,89 +574,135 @@ const UPDATE_NOTICE = {
434
574
  ENV_DISABLE: 'OPENEMAIL_DISABLE_UPDATE_NOTICE',
435
575
  TIMEOUT_MS: 2_000,
436
576
  PACKAGE: '@openemail/sdk',
437
- CHANGELOG_URL: 'https://www.npmjs.com/package/@openemail/sdk?activeTab=versions',
577
+ CHANGELOG_URL: 'https://openemail.uk/docs/sdk/changelog',
438
578
  ICON: 'ℹ'
439
579
  };
440
580
 
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
- ];
581
+ const RULE_FIELDS = {
582
+ FROM: 'from',
583
+ FROM_DOMAIN: 'from_domain',
584
+ ENVELOPE_FROM: 'envelope_from',
585
+ TO: 'to',
586
+ CC: 'cc',
587
+ BCC: 'bcc',
588
+ RECIPIENT: 'recipient',
589
+ REPLY_TO: 'reply_to',
590
+ DELIVERED_TO: 'delivered_to',
591
+ SUBJECT: 'subject',
592
+ BODY: 'body',
593
+ HEADER: 'header',
594
+ LIST_ID: 'list_id',
595
+ ATTACHMENT_NAME: 'attachment_name',
596
+ ATTACHMENT_TYPE: 'attachment_type',
597
+ HAS_ATTACHMENT: 'has_attachment',
598
+ ATTACHMENT_SIZE: 'attachment_size',
599
+ MESSAGE_SIZE: 'message_size',
600
+ SPAM: 'spam',
601
+ HOUR: 'hour',
602
+ WEEKDAY: 'weekday'
603
+ };
604
+ const RULE_OPERATORS = {
605
+ MATCHES: 'matches',
606
+ CONTAINS: 'contains',
607
+ EQUALS: 'equals',
608
+ STARTS_WITH: 'starts_with',
609
+ ENDS_WITH: 'ends_with',
610
+ GT: 'gt',
611
+ LT: 'lt'
612
+ };
613
+ const RULE_ACTIONS = {
614
+ LABEL: 'label',
615
+ REMOVE_LABEL: 'remove_label',
616
+ ARCHIVE: 'archive',
617
+ MARK_READ: 'mark_read',
618
+ STAR: 'star',
619
+ SPAM: 'spam',
620
+ TRASH: 'trash',
621
+ FORWARD: 'forward',
622
+ REPLY: 'reply',
623
+ BLOCK_SENDER: 'block_sender',
624
+ REJECT: 'reject'
625
+ };
478
626
 
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
- ];
627
+ const API_SCOPES = {
628
+ EMAILS_SEND: 'emails:send',
629
+ EMAILS_READ: 'emails:read',
630
+ DRAFTS_READ: 'drafts:read',
631
+ DRAFTS_WRITE: 'drafts:write',
632
+ THREADS_READ: 'threads:read',
633
+ THREADS_WRITE: 'threads:write',
634
+ LABELS_READ: 'labels:read',
635
+ LABELS_WRITE: 'labels:write',
636
+ CONTACTS_READ: 'contacts:read',
637
+ CONTACTS_WRITE: 'contacts:write',
638
+ AUDIENCES_READ: 'audiences:read',
639
+ AUDIENCES_WRITE: 'audiences:write',
640
+ CALENDAR_READ: 'calendar:read',
641
+ CALENDAR_WRITE: 'calendar:write',
642
+ TEMPLATES_READ: 'templates:read',
643
+ TEMPLATES_WRITE: 'templates:write',
644
+ DOMAINS_READ: 'domains:read',
645
+ DOMAINS_WRITE: 'domains:write',
646
+ WEBHOOKS_READ: 'webhooks:read',
647
+ WEBHOOKS_WRITE: 'webhooks:write',
648
+ RULES_READ: 'rules:read',
649
+ RULES_WRITE: 'rules:write',
650
+ CONNECTIONS_READ: 'connections:read',
651
+ MEMBERS_READ: 'members:read',
652
+ MEMBERS_WRITE: 'members:write',
653
+ ROLES_READ: 'roles:read',
654
+ ROLES_WRITE: 'roles:write',
655
+ SETTINGS_READ: 'settings:read',
656
+ SETTINGS_WRITE: 'settings:write',
657
+ KEYS_WRITE: 'keys:write',
658
+ KEYS_READ: 'keys:read',
659
+ KEYS_MANAGE: 'keys:manage'
660
+ };
507
661
 
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
- ];
662
+ const SUPPRESSION_REASONS = {
663
+ BOUNCE: 'bounce',
664
+ COMPLAINT: 'complaint',
665
+ MANUAL: 'manual'
666
+ };
667
+
668
+ const THREAD_SORTS = {
669
+ NEWEST: 'newest',
670
+ OLDEST: 'oldest',
671
+ SENDER: 'sender',
672
+ SUBJECT: 'subject'
673
+ };
674
+
675
+ const WEBHOOK_EVENTS = {
676
+ EMAIL_RECEIVED: 'email.received',
677
+ EMAIL_REPLIED: 'email.replied',
678
+ EMAIL_SENT: 'email.sent',
679
+ EMAIL_FAILED: 'email.failed',
680
+ EMAIL_CANCELLED: 'email.cancelled',
681
+ EMAIL_SCHEDULED: 'email.scheduled',
682
+ EMAIL_QUEUED: 'email.queued',
683
+ EMAIL_DELIVERED: 'email.delivered',
684
+ EMAIL_DELIVERY_DELAYED: 'email.delivery_delayed',
685
+ EMAIL_BOUNCED: 'email.bounced',
686
+ EMAIL_COMPLAINED: 'email.complained',
687
+ EMAIL_SUPPRESSED: 'email.suppressed',
688
+ EMAIL_OPENED: 'email.opened',
689
+ EMAIL_CLICKED: 'email.clicked',
690
+ EMAIL_DOWNLOADED: 'email.downloaded',
691
+ DOMAIN_VERIFIED: 'domain.verified',
692
+ DOMAIN_SENDING_CHANGED: 'domain.sending_changed',
693
+ DOMAIN_DELETED: 'domain.deleted',
694
+ SUPPRESSION_ADDED: 'suppression.added',
695
+ SUPPRESSION_REMOVED: 'suppression.removed'
696
+ };
697
+ const WEBHOOK_REPLAY_ERROR_CODES = {
698
+ RESOURCE_NOT_FOUND: 'resource_not_found',
699
+ WEBHOOK_DISABLED: 'webhook_disabled',
700
+ EVENT_NOT_SUBSCRIBED: 'event_not_subscribed',
701
+ EVENT_OUT_OF_SCOPE: 'event_out_of_scope',
702
+ DELIVERY_NOT_REPLAYABLE: 'delivery_not_replayable',
703
+ RETRY_IN_PROGRESS: 'retry_in_progress',
704
+ REPLAY_IN_PROGRESS: 'replay_in_progress'
705
+ };
520
706
  const WEBHOOK_HEADERS = {
521
707
  SIGNATURE: 'X-OpenEmail-Signature',
522
708
  EVENT: 'X-OpenEmail-Event',
@@ -549,6 +735,108 @@ const ENDPOINT_SCHEME_PATTERN = /^[a-z][a-z0-9+.-]*:\/\//i;
549
735
  const RETRYABLE_STATUSES = new Set(RETRY.STATUSES);
550
736
  const RETRYABLE_METHODS = new Set(RETRY.METHODS);
551
737
 
738
+ ({
739
+ scopes: [API_SCOPES.KEYS_MANAGE]});
740
+
741
+ ({
742
+ scopes: [API_SCOPES.KEYS_MANAGE]});
743
+
744
+ ({
745
+ scopes: [API_SCOPES.KEYS_READ]});
746
+
747
+ ({
748
+ scopes: [API_SCOPES.KEYS_READ]});
749
+
750
+ ({
751
+ scopes: [API_SCOPES.KEYS_READ]});
752
+
753
+ ({
754
+ scopes: [API_SCOPES.KEYS_READ]});
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_MANAGE]});
794
+
795
+ ({
796
+ scopes: [API_SCOPES.KEYS_MANAGE]});
797
+
798
+ ({
799
+ scopes: [API_SCOPES.KEYS_MANAGE]});
800
+
801
+ ({
802
+ scopes: [API_SCOPES.KEYS_WRITE]});
803
+
804
+ ({
805
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
806
+
807
+ ({
808
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
809
+
810
+ ({
811
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
812
+
813
+ ({
814
+ scopes: [API_SCOPES.WEBHOOKS_READ]});
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
+
552
840
  const IsApiKey = (value) => typeof value === 'string' && (value.startsWith(API_KEY_PREFIXES.LIVE) || value.startsWith(API_KEY_PREFIXES.TEST));
553
841
  const ModeOf = (apiKey) => apiKey.startsWith(API_KEY_PREFIXES.TEST) ? API_KEY_MODES.TEST : API_KEY_MODES.LIVE;
554
842
  const AssertApiKey = (apiKey, where) => {
@@ -586,28 +874,28 @@ class OpenEmailApiError extends Error {
586
874
  this.retryAfterSeconds = retryAfterSeconds;
587
875
  }
588
876
  get isAuth() {
589
- return this.type === ERROR_TYPE.AUTHENTICATION;
877
+ return this.type === ERROR_TYPES.AUTHENTICATION_ERROR;
590
878
  }
591
879
  get isPermission() {
592
- return this.type === ERROR_TYPE.PERMISSION;
880
+ return this.type === ERROR_TYPES.PERMISSION_ERROR;
593
881
  }
594
882
  get isScopeMissing() {
595
883
  return this.code === ERROR_CODES.INSUFFICIENT_SCOPE;
596
884
  }
597
885
  get isInvalidRequest() {
598
- return this.type === ERROR_TYPE.INVALID_REQUEST;
886
+ return this.type === ERROR_TYPES.INVALID_REQUEST_ERROR;
599
887
  }
600
888
  get isValidation() {
601
- return this.type === ERROR_TYPE.VALIDATION;
889
+ return this.type === ERROR_TYPES.VALIDATION_ERROR;
602
890
  }
603
891
  get isNotFound() {
604
- return this.type === ERROR_TYPE.NOT_FOUND;
892
+ return this.type === ERROR_TYPES.NOT_FOUND_ERROR;
605
893
  }
606
894
  get isConflict() {
607
- return this.type === ERROR_TYPE.CONFLICT;
895
+ return this.type === ERROR_TYPES.CONFLICT_ERROR;
608
896
  }
609
897
  get isRateLimited() {
610
- return this.type === ERROR_TYPE.RATE_LIMIT;
898
+ return this.type === ERROR_TYPES.RATE_LIMIT_ERROR;
611
899
  }
612
900
  get isServerError() {
613
901
  return this.status !== null && this.status >= 500;
@@ -773,12 +1061,13 @@ const Sleep = (ms, signal) => new Promise((resolve, reject) => {
773
1061
  signal?.addEventListener('abort', onAbort, { once: true });
774
1062
  });
775
1063
 
776
- const IsErrorType = (value) => typeof value === 'string' && ERROR_TYPES.includes(value);
1064
+ const errorTypes = new Set(Object.values(ERROR_TYPES));
1065
+ const IsErrorType = (value) => typeof value === 'string' && errorTypes.has(value);
777
1066
  const TypeForStatus = (status) => {
778
1067
  if (status >= 500)
779
- return ERROR_TYPE.API;
1068
+ return ERROR_TYPES.API_ERROR;
780
1069
  const mapped = ERROR_TYPE_BY_STATUS[status];
781
- return IsErrorType(mapped) ? mapped : ERROR_TYPE.INVALID_REQUEST;
1070
+ return IsErrorType(mapped) ? mapped : ERROR_TYPES.INVALID_REQUEST_ERROR;
782
1071
  };
783
1072
  const ReadPayload = (body) => {
784
1073
  if (typeof body !== 'object' || body === null || !('error' in body))
@@ -853,11 +1142,13 @@ class Transport {
853
1142
  const method = (options.method ?? HTTP_METHODS.GET).toUpperCase();
854
1143
  const url = BuildUrl(this.baseUrl, path, options.query);
855
1144
  const headers = this.headersFor(options);
856
- const body = options.body === undefined ? undefined : JSON.stringify(options.body);
1145
+ const body = options.raw !== undefined
1146
+ ? options.raw
1147
+ : options.body === undefined ? undefined : JSON.stringify(options.body);
857
1148
  const repeatable = options.repeatable ?? RETRYABLE_METHODS.has(method);
858
1149
  let attempt = 0;
859
1150
  for (;;) {
860
- const outcome = await this.attempt(url, method, headers, body, options.signal);
1151
+ const outcome = await this.attempt(url, method, headers, body, options.signal, options.binary === true);
861
1152
  if (outcome instanceof OpenEmailNetworkError) {
862
1153
  if (options.signal?.aborted || !repeatable || attempt >= this.maxRetries)
863
1154
  throw outcome;
@@ -865,7 +1156,9 @@ class Transport {
865
1156
  attempt += 1;
866
1157
  continue;
867
1158
  }
868
- const { response, text } = outcome;
1159
+ const { response, text, bytes } = outcome;
1160
+ if (response.ok && bytes !== undefined)
1161
+ return bytes;
869
1162
  if (response.ok)
870
1163
  return this.parse(response, text, options.accept);
871
1164
  const retryAfter = RetryAfter(response.headers.get(HEADER_KEYS.RETRY_AFTER));
@@ -887,7 +1180,9 @@ class Transport {
887
1180
  };
888
1181
  if (!IsBrowser())
889
1182
  headers[HEADER_KEYS.USER_AGENT] = this.userAgent;
890
- if (options.body !== undefined)
1183
+ if (options.raw !== undefined)
1184
+ headers[HEADER_KEYS.CONTENT_TYPE] = options.contentType ?? CONTENT_TYPES.OCTET_STREAM;
1185
+ else if (options.body !== undefined)
891
1186
  headers[HEADER_KEYS.CONTENT_TYPE] = CONTENT_TYPES.JSON;
892
1187
  if (options.anonymous !== true) {
893
1188
  if (options.apiKey !== undefined)
@@ -900,7 +1195,7 @@ class Transport {
900
1195
  headers[HEADER_KEYS.IDEMPOTENCY_KEY] = options.idempotencyKey ?? IdempotencyKey();
901
1196
  return headers;
902
1197
  }
903
- async attempt(url, method, headers, body, signal) {
1198
+ async attempt(url, method, headers, body, signal, binary) {
904
1199
  const deadline = Deadline(this.timeoutMs, signal);
905
1200
  const Failure = (error, fallback) => {
906
1201
  if (signal?.aborted)
@@ -918,6 +1213,8 @@ class Transport {
918
1213
  return Failure(error, `Could not reach ${this.baseUrl}`);
919
1214
  }
920
1215
  try {
1216
+ if (binary && response.ok)
1217
+ return { response, text: '', bytes: new Uint8Array(await response.arrayBuffer()) };
921
1218
  return { response, text: await response.text() };
922
1219
  }
923
1220
  catch (error) {
@@ -941,24 +1238,13 @@ class Transport {
941
1238
  throw new OpenEmailApiError({
942
1239
  message: `The API answered ${response.status} with a body that is not JSON.`,
943
1240
  status: response.status,
944
- type: ERROR_TYPE.API,
1241
+ type: ERROR_TYPES.API_ERROR,
945
1242
  code: ERROR_CODES.UNRECOGNISED_RESPONSE,
946
1243
  requestId: response.headers.get(HEADER_KEYS.REQUEST_ID) ?? undefined
947
1244
  });
948
1245
  }
949
1246
  }
950
1247
 
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
1248
  const FetchPage = async (transport, path, style, options = {}, query = {}) => {
963
1249
  const payload = await transport.request(path, {
964
1250
  query: { ...query, [QUERY_KEYS.LIMIT]: options.limit, [style.PARAM]: options.cursor },
@@ -1014,11 +1300,31 @@ const ThreadMessageAttachmentsPath = (id, messageId) => `${ThreadPath(id)}/${SEG
1014
1300
  const DraftPath = (id) => `${PATHS.DRAFTS}/${Segment(id)}`;
1015
1301
  const LabelPath = (id) => `${PATHS.LABELS}/${Segment(id)}`;
1016
1302
  const ContactPath = (email) => `${PATHS.CONTACTS}/${Segment(email)}`;
1303
+ const ContactChildPath = (email, segment) => `${ContactPath(email)}/${segment}`;
1304
+ const AudiencePath = (id) => `${PATHS.AUDIENCES}/${Segment(id)}`;
1305
+ const AudienceChildPath = (id, segment) => `${AudiencePath(id)}/${segment}`;
1306
+ const AudienceContactsPath = (id) => `${AudiencePath(id)}/${SEGMENTS.CONTACTS}`;
1307
+ const AudienceContactsChildPath = (id, segment) => `${AudienceContactsPath(id)}/${segment}`;
1308
+ const AudienceContactPath = (id, email) => `${AudienceContactsPath(id)}/${Segment(email)}`;
1309
+ const BroadcastPath = (id) => `${PATHS.BROADCASTS}/${Segment(id)}`;
1310
+ const BroadcastChildPath = (id, segment) => `${BroadcastPath(id)}/${segment}`;
1017
1311
  const DomainPath = (id) => `${PATHS.DOMAINS}/${Segment(id)}`;
1018
1312
  const WebhookPath = (id) => `${PATHS.WEBHOOKS}/${Segment(id)}`;
1019
1313
  const WebhookChildPath = (id, segment) => `${WebhookPath(id)}/${segment}`;
1314
+ const WebhookDeliveryPath = (id, deliveryId) => `${WebhookChildPath(id, SEGMENTS.DELIVERIES)}/${Segment(deliveryId)}`;
1315
+ const WebhookDeliveryReplayPath = (id, deliveryId) => `${WebhookDeliveryPath(id, deliveryId)}/${SEGMENTS.REPLAY}`;
1316
+ const KeyPath = (id) => `${PATHS.KEYS}/${Segment(id)}`;
1317
+ const KeyChildPath = (id, segment) => `${KeyPath(id)}/${segment}`;
1318
+ const ImportPath = (id) => `${PATHS.IMPORTS}/${Segment(id)}`;
1319
+ const ProviderImportPath = (id) => `${PATHS.PROVIDER_IMPORTS}/${Segment(id)}`;
1320
+ const ProviderImportChildPath = (id, segment) => `${ProviderImportPath(id)}/${segment}`;
1321
+ const ImportChildPath = (id, segment) => `${ImportPath(id)}/${segment}`;
1322
+ const ImportChunkPath = (id, file, chunk) => `${ImportPath(id)}/${SEGMENTS.FILES}/${Segment(String(file))}/${SEGMENTS.CHUNKS}/${Segment(String(chunk))}`;
1020
1323
  const TemplatePath = (idOrSlug) => `${PATHS.TEMPLATES}/${Segment(idOrSlug)}`;
1021
1324
  const TemplateChildPath = (idOrSlug, segment) => `${TemplatePath(idOrSlug)}/${segment}`;
1325
+ const TemplateStarterPath = (slug) => `${PATHS.TEMPLATES_STARTERS}/${Segment(slug)}`;
1326
+ const TemplateVersionPath = (idOrSlug, version) => `${TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS)}/${Segment(String(version))}`;
1327
+ const TemplateVersionChildPath = (idOrSlug, version, segment) => `${TemplateVersionPath(idOrSlug, version)}/${segment}`;
1022
1328
  const RulePath = (id) => `${PATHS.RULES}/${Segment(id)}`;
1023
1329
  const RuleChildPath = (id, segment) => `${RulePath(id)}/${segment}`;
1024
1330
  const TrackingPath = (id) => `${PATHS.TRACKING}/${Segment(id)}`;
@@ -1029,12 +1335,131 @@ const RolePath = (id) => `${PATHS.ROLES}/${Segment(id)}`;
1029
1335
  const MemberPath = (userId) => `${PATHS.MEMBERS}/${Segment(userId)}`;
1030
1336
  const MemberAddressesPath = (userId) => `${MemberPath(userId)}/${SEGMENTS.ADDRESSES}`;
1031
1337
  const MemberAddressPath = (userId, addressId) => `${MemberAddressesPath(userId)}/${Segment(addressId)}`;
1338
+ const MemberInvitationPath = (id) => `${PATHS.MEMBERS_INVITATIONS}/${Segment(id)}`;
1339
+ const MemberInvitationResendPath = (id) => `${MemberInvitationPath(id)}/${SEGMENTS.RESEND}`;
1340
+ const SuppressionPath = (id) => `${PATHS.SUPPRESSIONS}/${Segment(id)}`;
1341
+ const FilePath = (id) => `${PATHS.FILES}/${Segment(id)}`;
1342
+ const FileChildPath = (id, segment) => `${FilePath(id)}/${segment}`;
1032
1343
  const TempInboxPath = (id) => `${PATHS.TEMP_MAIL_INBOXES}/${Segment(id)}`;
1033
1344
  const TempInboxExtendPath = (id) => `${TempInboxPath(id)}/${SEGMENTS.EXTEND}`;
1034
1345
  const TempMessagesPath = (id) => `${TempInboxPath(id)}/${SEGMENTS.MESSAGES}`;
1035
1346
  const TempMessagePath = (id, messageId) => `${TempMessagesPath(id)}/${Segment(messageId)}`;
1036
1347
  const TempMessageAttachmentsPath = (id, messageId) => `${TempMessagePath(id, messageId)}/${SEGMENTS.ATTACHMENTS}`;
1037
1348
 
1349
+ const Addresses = (transport) => {
1350
+ const page = async (options = {}) => {
1351
+ const envelope = await transport.request(PATHS.ADDRESSES, {
1352
+ query: { [QUERY_KEYS.LIMIT]: options.limit, [CURSOR_STYLES.CURSOR.PARAM]: options.cursor },
1353
+ signal: options.signal,
1354
+ apiKey: options.apiKey
1355
+ });
1356
+ const nextCursor = typeof envelope.nextCursor === 'string' && envelope.nextCursor.length > 0 ? envelope.nextCursor : null;
1357
+ return {
1358
+ unrestricted: envelope.unrestricted,
1359
+ addresses: envelope.data ?? [],
1360
+ domains: envelope.domains ?? [],
1361
+ hasMore: typeof envelope.hasMore === 'boolean' ? envelope.hasMore : nextCursor !== null,
1362
+ nextCursor
1363
+ };
1364
+ };
1365
+ return {
1366
+ list: page,
1367
+ listAll: async (options = {}) => {
1368
+ let current = await page(options);
1369
+ const addresses = [...current.addresses];
1370
+ while (current.hasMore && current.nextCursor) {
1371
+ current = await page({ ...options, cursor: current.nextCursor });
1372
+ addresses.push(...current.addresses);
1373
+ }
1374
+ return { unrestricted: current.unrestricted, addresses, domains: current.domains };
1375
+ },
1376
+ iterate: (options = {}) => IteratePages(transport, PATHS.ADDRESSES, CURSOR_STYLES.CURSOR, options)
1377
+ };
1378
+ };
1379
+
1380
+ const MemberQuery = (options) => ({
1381
+ [QUERY_KEYS.Q]: options.q,
1382
+ [QUERY_KEYS.SOURCE]: options.source,
1383
+ [QUERY_KEYS.SORT]: options.sort
1384
+ });
1385
+ const GrowthQuery = (options) => ({
1386
+ [QUERY_KEYS.AUDIENCE_IDS]: options.audienceIds?.join(LIST_SEPARATOR),
1387
+ [QUERY_KEYS.DAYS]: options.days,
1388
+ [QUERY_KEYS.MINUTES]: options.minutes,
1389
+ [QUERY_KEYS.GRAIN]: options.grain,
1390
+ [QUERY_KEYS.OFFSET_MINUTES]: options.offsetMinutes
1391
+ });
1392
+ const Audiences = (transport) => ({
1393
+ list: (options = {}) => FetchPage(transport, PATHS.AUDIENCES, CURSOR_STYLES.CURSOR, options),
1394
+ listAll: (options = {}) => CollectAll(transport, PATHS.AUDIENCES, CURSOR_STYLES.CURSOR, options),
1395
+ iterate: (options = {}) => IteratePages(transport, PATHS.AUDIENCES, CURSOR_STYLES.CURSOR, options),
1396
+ growth: (options = {}) => transport.request(PATHS.AUDIENCES_GROWTH, {
1397
+ query: GrowthQuery(options),
1398
+ signal: options.signal,
1399
+ apiKey: options.apiKey
1400
+ }),
1401
+ get: (id, options = {}) => transport.request(AudiencePath(id), { signal: options.signal, apiKey: options.apiKey }),
1402
+ create: (body, options = {}) => transport.request(PATHS.AUDIENCES, {
1403
+ method: HTTP_METHODS.POST,
1404
+ body,
1405
+ signal: options.signal,
1406
+ apiKey: options.apiKey
1407
+ }),
1408
+ update: (id, patch, options = {}) => transport.request(AudiencePath(id), {
1409
+ method: HTTP_METHODS.PATCH,
1410
+ body: patch,
1411
+ repeatable: true,
1412
+ signal: options.signal,
1413
+ apiKey: options.apiKey
1414
+ }),
1415
+ delete: (id, options = {}) => transport.request(AudiencePath(id), {
1416
+ method: HTTP_METHODS.DELETE,
1417
+ signal: options.signal,
1418
+ apiKey: options.apiKey
1419
+ }),
1420
+ empty: (id, options = {}) => transport.request(AudienceChildPath(id, SEGMENTS.EMPTY), {
1421
+ method: HTTP_METHODS.POST,
1422
+ signal: options.signal,
1423
+ apiKey: options.apiKey
1424
+ }),
1425
+ listContacts: (id, options = {}) => FetchPage(transport, AudienceContactsPath(id), CURSOR_STYLES.CURSOR, options, MemberQuery(options)),
1426
+ listAllContacts: (id, options = {}) => CollectAll(transport, AudienceContactsPath(id), CURSOR_STYLES.CURSOR, options, MemberQuery(options)),
1427
+ iterateContacts: (id, options = {}) => IteratePages(transport, AudienceContactsPath(id), CURSOR_STYLES.CURSOR, options, MemberQuery(options)),
1428
+ addContact: (id, body, options = {}) => transport.request(AudienceContactsPath(id), {
1429
+ method: HTTP_METHODS.POST,
1430
+ body,
1431
+ repeatable: true,
1432
+ signal: options.signal,
1433
+ apiKey: options.apiKey
1434
+ }),
1435
+ removeContact: (id, email, options = {}) => transport.request(AudienceContactPath(id, email), {
1436
+ method: HTTP_METHODS.DELETE,
1437
+ signal: options.signal,
1438
+ apiKey: options.apiKey
1439
+ }),
1440
+ addContacts: (id, body, options = {}) => transport.request(AudienceContactsChildPath(id, SEGMENTS.BATCH), {
1441
+ method: HTTP_METHODS.POST,
1442
+ body,
1443
+ repeatable: true,
1444
+ signal: options.signal,
1445
+ apiKey: options.apiKey
1446
+ }),
1447
+ removeContacts: (id, body, options = {}) => transport.request(AudienceContactsChildPath(id, SEGMENTS.BATCH_REMOVE), {
1448
+ method: HTTP_METHODS.POST,
1449
+ body,
1450
+ repeatable: true,
1451
+ signal: options.signal,
1452
+ apiKey: options.apiKey
1453
+ }),
1454
+ importContacts: (id, body, options = {}) => transport.request(AudienceChildPath(id, SEGMENTS.IMPORT), {
1455
+ method: HTTP_METHODS.POST,
1456
+ body,
1457
+ repeatable: true,
1458
+ signal: options.signal,
1459
+ apiKey: options.apiKey
1460
+ })
1461
+ });
1462
+
1038
1463
  const ToBase64 = (bytes) => {
1039
1464
  const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
1040
1465
  let binary = '';
@@ -1050,11 +1475,13 @@ const Many = (value) => {
1050
1475
  return Array.isArray(value) ? value : [value];
1051
1476
  };
1052
1477
  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
- });
1478
+ const Attachment = (attachment) => 'fileId' in attachment
1479
+ ? { fileId: attachment.fileId }
1480
+ : {
1481
+ filename: attachment.filename,
1482
+ content: typeof attachment.content === 'string' ? attachment.content : ToBase64(attachment.content),
1483
+ ...(attachment.contentType === undefined ? {} : { contentType: attachment.contentType })
1484
+ };
1058
1485
  const EmailToWire = (body) => ({
1059
1486
  ...body,
1060
1487
  to: Many(body.to),
@@ -1072,12 +1499,47 @@ const TemplateSendToWire = (body) => ({
1072
1499
  });
1073
1500
  const ToInstant = Instant;
1074
1501
 
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
1502
+ const ListQuery$a = (options) => ({
1503
+ [QUERY_KEYS.AUDIENCE_ID]: options.audienceId
1504
+ });
1505
+ const Broadcasts = (transport) => ({
1506
+ preview: (body, options = {}) => transport.request(PATHS.BROADCASTS_PREVIEW, {
1507
+ method: HTTP_METHODS.POST,
1508
+ body: { audienceIds: body.audienceIds },
1509
+ repeatable: true,
1510
+ signal: options.signal,
1511
+ apiKey: options.apiKey
1080
1512
  }),
1513
+ send: (body, options = {}) => transport.request(PATHS.BROADCASTS, {
1514
+ method: HTTP_METHODS.POST,
1515
+ body: { ...body, scheduledAt: ToInstant(body.scheduledAt) },
1516
+ idempotent: true,
1517
+ idempotencyKey: options.idempotencyKey,
1518
+ repeatable: true,
1519
+ signal: options.signal,
1520
+ apiKey: options.apiKey
1521
+ }),
1522
+ list: (options = {}) => FetchPage(transport, PATHS.BROADCASTS, CURSOR_STYLES.CURSOR, options, ListQuery$a(options)),
1523
+ listAll: (options = {}) => CollectAll(transport, PATHS.BROADCASTS, CURSOR_STYLES.CURSOR, options, ListQuery$a(options)),
1524
+ iterate: (options = {}) => IteratePages(transport, PATHS.BROADCASTS, CURSOR_STYLES.CURSOR, options, ListQuery$a(options)),
1525
+ get: (id, options = {}) => transport.request(BroadcastPath(id), { signal: options.signal, apiKey: options.apiKey }),
1526
+ cancel: (id, options = {}) => transport.request(BroadcastChildPath(id, SEGMENTS.CANCEL), {
1527
+ method: HTTP_METHODS.POST,
1528
+ repeatable: true,
1529
+ signal: options.signal,
1530
+ apiKey: options.apiKey
1531
+ })
1532
+ });
1533
+
1534
+ const RangeQuery = (options) => ({
1535
+ [QUERY_KEYS.FROM]: ToInstant(options.from),
1536
+ [QUERY_KEYS.TO]: ToInstant(options.to),
1537
+ [QUERY_KEYS.TIMEZONE]: options.timezone
1538
+ });
1539
+ const Calendar = (transport) => ({
1540
+ listEvents: (options) => FetchPage(transport, PATHS.CALENDAR_EVENTS, CURSOR_STYLES.CURSOR, options, RangeQuery(options)),
1541
+ listAllEvents: (options) => CollectAll(transport, PATHS.CALENDAR_EVENTS, CURSOR_STYLES.CURSOR, options, RangeQuery(options)),
1542
+ iterateEvents: (options) => IteratePages(transport, PATHS.CALENDAR_EVENTS, CURSOR_STYLES.CURSOR, options, RangeQuery(options)),
1081
1543
  getEvent: (id, options = {}) => transport.request(CalendarEventPath(id), { signal: options.signal, apiKey: options.apiKey }),
1082
1544
  getEventIcs: (id, options = {}) => transport.request(CalendarEventIcsPath(id), {
1083
1545
  accept: CONTENT_TYPES.CALENDAR,
@@ -1086,21 +1548,150 @@ const Calendar = (transport) => ({
1086
1548
  })
1087
1549
  });
1088
1550
 
1551
+ const ListQuery$9 = (options) => ({
1552
+ [QUERY_KEYS.SOURCE]: options.source,
1553
+ [QUERY_KEYS.Q]: options.q
1554
+ });
1555
+ const PeopleQuery = (options) => ({
1556
+ [QUERY_KEYS.Q]: options.q,
1557
+ [QUERY_KEYS.EMAIL]: options.email,
1558
+ [QUERY_KEYS.SORT]: options.sort,
1559
+ [QUERY_KEYS.BLOCKED]: options.blocked === undefined ? undefined : String(options.blocked)
1560
+ });
1561
+ const ThreadQuery = (options) => ({
1562
+ [QUERY_KEYS.Q]: options.q,
1563
+ [QUERY_KEYS.SORT]: options.sort
1564
+ });
1565
+ const ActivityQuery = (options) => ({
1566
+ [QUERY_KEYS.MINUTES]: options.minutes,
1567
+ [QUERY_KEYS.GRAIN]: options.grain,
1568
+ [QUERY_KEYS.OFFSET_MINUTES]: options.offsetMinutes
1569
+ });
1570
+ const PhotoType = (data, options) => {
1571
+ if (options.contentType)
1572
+ return options.contentType;
1573
+ return typeof Blob !== 'undefined' && data instanceof Blob && data.type ? data.type : undefined;
1574
+ };
1089
1575
  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 })
1576
+ list: (options = {}) => FetchPage(transport, PATHS.CONTACTS, CURSOR_STYLES.CURSOR, options, ListQuery$9(options)),
1577
+ listAll: (options = {}) => CollectAll(transport, PATHS.CONTACTS, CURSOR_STYLES.CURSOR, options, ListQuery$9(options)),
1578
+ iterate: (options = {}) => IteratePages(transport, PATHS.CONTACTS, CURSOR_STYLES.CURSOR, options, ListQuery$9(options)),
1579
+ get: (email, options = {}) => transport.request(ContactPath(email), { signal: options.signal, apiKey: options.apiKey }),
1580
+ create: (body, options = {}) => transport.request(PATHS.CONTACTS, {
1581
+ method: HTTP_METHODS.POST,
1582
+ body,
1583
+ signal: options.signal,
1584
+ apiKey: options.apiKey
1585
+ }),
1586
+ update: (email, patch, options = {}) => transport.request(ContactPath(email), {
1587
+ method: HTTP_METHODS.PATCH,
1588
+ body: patch,
1589
+ repeatable: true,
1590
+ signal: options.signal,
1591
+ apiKey: options.apiKey
1592
+ }),
1593
+ delete: (email, options = {}) => transport.request(ContactPath(email), {
1594
+ method: HTTP_METHODS.DELETE,
1595
+ signal: options.signal,
1596
+ apiKey: options.apiKey
1597
+ }),
1598
+ setAudiences: (email, body, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.AUDIENCES), {
1599
+ method: HTTP_METHODS.PUT,
1600
+ body,
1601
+ repeatable: true,
1602
+ signal: options.signal,
1603
+ apiKey: options.apiKey
1604
+ }),
1605
+ listPeople: async (options = {}) => {
1606
+ const payload = await transport.request(PATHS.CONTACTS_PEOPLE, {
1607
+ query: {
1608
+ ...PeopleQuery(options),
1609
+ [QUERY_KEYS.LIMIT]: options.limit,
1610
+ [CURSOR_STYLES.CURSOR.PARAM]: options.cursor
1611
+ },
1612
+ signal: options.signal,
1613
+ apiKey: options.apiKey
1614
+ });
1615
+ const next = payload?.[CURSOR_STYLES.CURSOR.FIELD];
1616
+ const nextCursor = typeof next === 'string' && next.length > 0 ? next : null;
1617
+ return {
1618
+ items: (Array.isArray(payload?.data) ? payload.data : []),
1619
+ hasMore: typeof payload?.hasMore === 'boolean' ? payload.hasMore : nextCursor !== null,
1620
+ nextCursor,
1621
+ seen: payload?.seen === true
1622
+ };
1623
+ },
1624
+ listAllPeople: (options = {}) => CollectAll(transport, PATHS.CONTACTS_PEOPLE, CURSOR_STYLES.CURSOR, options, PeopleQuery(options)),
1625
+ iteratePeople: (options = {}) => IteratePages(transport, PATHS.CONTACTS_PEOPLE, CURSOR_STYLES.CURSOR, options, PeopleQuery(options)),
1626
+ save: (email, body = {}, options = {}) => transport.request(ContactPath(email), {
1627
+ method: HTTP_METHODS.PUT,
1628
+ body,
1629
+ repeatable: true,
1630
+ signal: options.signal,
1631
+ apiKey: options.apiKey
1632
+ }),
1633
+ deleteMany: (emails, options = {}) => transport.request(PATHS.CONTACTS_BATCH_DELETE, {
1634
+ method: HTTP_METHODS.POST,
1635
+ body: { emails },
1636
+ repeatable: true,
1637
+ signal: options.signal,
1638
+ apiKey: options.apiKey
1639
+ }),
1640
+ setPhoto: (email, data, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.PHOTO), {
1641
+ method: HTTP_METHODS.PUT,
1642
+ raw: data,
1643
+ contentType: PhotoType(data, options),
1644
+ repeatable: true,
1645
+ signal: options.signal,
1646
+ apiKey: options.apiKey
1647
+ }),
1648
+ removePhoto: (email, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.PHOTO), {
1649
+ method: HTTP_METHODS.DELETE,
1650
+ repeatable: true,
1651
+ signal: options.signal,
1652
+ apiKey: options.apiKey
1653
+ }),
1654
+ block: (email, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.BLOCK), {
1655
+ method: HTTP_METHODS.POST,
1656
+ repeatable: true,
1657
+ signal: options.signal,
1658
+ apiKey: options.apiKey
1659
+ }),
1660
+ unblock: (email, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.BLOCK), {
1661
+ method: HTTP_METHODS.DELETE,
1662
+ repeatable: true,
1663
+ signal: options.signal,
1664
+ apiKey: options.apiKey
1665
+ }),
1666
+ listThreads: (email, options = {}) => FetchPage(transport, ContactChildPath(email, SEGMENTS.THREADS), CURSOR_STYLES.CURSOR, options, ThreadQuery(options)),
1667
+ listAllThreads: (email, options = {}) => CollectAll(transport, ContactChildPath(email, SEGMENTS.THREADS), CURSOR_STYLES.CURSOR, options, ThreadQuery(options)),
1668
+ iterateThreads: (email, options = {}) => IteratePages(transport, ContactChildPath(email, SEGMENTS.THREADS), CURSOR_STYLES.CURSOR, options, ThreadQuery(options)),
1669
+ activity: (email, options = {}) => transport.request(ContactChildPath(email, SEGMENTS.ACTIVITY), {
1670
+ query: ActivityQuery(options),
1671
+ signal: options.signal,
1672
+ apiKey: options.apiKey
1673
+ })
1092
1674
  });
1093
1675
 
1094
1676
  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 })
1677
+ list: (options = {}) => FetchPage(transport, PATHS.DOMAINS, CURSOR_STYLES.CURSOR, options),
1678
+ listAll: (options = {}) => CollectAll(transport, PATHS.DOMAINS, CURSOR_STYLES.CURSOR, options),
1679
+ iterate: (options = {}) => IteratePages(transport, PATHS.DOMAINS, CURSOR_STYLES.CURSOR, options),
1680
+ get: (id, options = {}) => transport.request(DomainPath(id), { signal: options.signal, apiKey: options.apiKey }),
1681
+ update: (id, patch, options = {}) => transport.request(DomainPath(id), {
1682
+ method: HTTP_METHODS.PATCH,
1683
+ body: patch,
1684
+ repeatable: true,
1685
+ signal: options.signal,
1686
+ apiKey: options.apiKey
1687
+ })
1097
1688
  });
1098
1689
 
1099
- const ListQuery$4 = (options) => ({ [QUERY_KEYS.QUERY]: options.query });
1690
+ const ListQuery$8 = (options) => ({ [QUERY_KEYS.QUERY]: options.query });
1100
1691
  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)),
1692
+ list: (options = {}) => FetchPage(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$8(options)),
1693
+ listAll: (options = {}) => CollectAll(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$8(options)),
1694
+ iterate: (options = {}) => IteratePages(transport, PATHS.DRAFTS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$8(options)),
1104
1695
  get: (id, options = {}) => transport.request(DraftPath(id), { signal: options.signal, apiKey: options.apiKey }),
1105
1696
  create: (body, options = {}) => transport.request(PATHS.DRAFTS, {
1106
1697
  method: HTTP_METHODS.POST,
@@ -1121,9 +1712,10 @@ const Drafts = (transport) => ({
1121
1712
  })
1122
1713
  });
1123
1714
 
1124
- const ListQuery$3 = (options) => ({
1715
+ const ListQuery$7 = (options) => ({
1125
1716
  [QUERY_KEYS.STATUS]: Array.isArray(options.status) ? options.status.join(LIST_SEPARATOR) : options.status,
1126
- [QUERY_KEYS.FROM]: options.from
1717
+ [QUERY_KEYS.FROM]: options.from,
1718
+ [QUERY_KEYS.BROADCAST_ID]: options.broadcastId
1127
1719
  });
1128
1720
  const Emails = (transport) => ({
1129
1721
  send: (body, options = {}) => transport.request(PATHS.EMAILS, {
@@ -1153,11 +1745,13 @@ const Emails = (transport) => ({
1153
1745
  signal: options.signal,
1154
1746
  apiKey: options.apiKey
1155
1747
  }),
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)),
1748
+ list: (options = {}) => FetchPage(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$7(options)),
1749
+ listAll: (options = {}) => CollectAll(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$7(options)),
1750
+ iterate: (options = {}) => IteratePages(transport, PATHS.EMAILS, CURSOR_STYLES.CURSOR, options, ListQuery$7(options)),
1159
1751
  get: (id, options = {}) => transport.request(EmailPath(id), { signal: options.signal, apiKey: options.apiKey }),
1160
- listEvents: (id, options = {}) => FetchList(transport, EmailChildPath(id, SEGMENTS.EVENTS), options),
1752
+ listEvents: (id, options = {}) => FetchPage(transport, EmailChildPath(id, SEGMENTS.EVENTS), CURSOR_STYLES.CURSOR, options),
1753
+ listAllEvents: (id, options = {}) => CollectAll(transport, EmailChildPath(id, SEGMENTS.EVENTS), CURSOR_STYLES.CURSOR, options),
1754
+ iterateEvents: (id, options = {}) => IteratePages(transport, EmailChildPath(id, SEGMENTS.EVENTS), CURSOR_STYLES.CURSOR, options),
1161
1755
  getTracking: (id, options = {}) => transport.request(EmailChildPath(id, SEGMENTS.TRACKING), { signal: options.signal, apiKey: options.apiKey }),
1162
1756
  cancel: (id, options = {}) => transport.request(EmailChildPath(id, SEGMENTS.CANCEL), {
1163
1757
  method: HTTP_METHODS.POST,
@@ -1174,8 +1768,206 @@ const Emails = (transport) => ({
1174
1768
  })
1175
1769
  });
1176
1770
 
1771
+ const ListQuery$6 = (options) => ({
1772
+ [QUERY_KEYS.Q]: options.q,
1773
+ [QUERY_KEYS.KIND]: options.kind,
1774
+ [QUERY_KEYS.SORT]: options.sort
1775
+ });
1776
+ const Files = (transport) => ({
1777
+ list: (options = {}) => FetchPage(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1778
+ listAll: (options = {}) => CollectAll(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1779
+ iterate: (options = {}) => IteratePages(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1780
+ get: (id, options = {}) => transport.request(FilePath(id), { signal: options.signal, apiKey: options.apiKey }),
1781
+ download: (id, options = {}) => transport.request(FileChildPath(id, SEGMENTS.CONTENT), {
1782
+ binary: true,
1783
+ signal: options.signal,
1784
+ apiKey: options.apiKey
1785
+ }),
1786
+ listLinks: (id, options = {}) => FetchPage(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1787
+ listAllLinks: (id, options = {}) => CollectAll(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1788
+ iterateLinks: (id, options = {}) => IteratePages(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1789
+ delete: (id, options = {}) => transport.request(FilePath(id), {
1790
+ method: HTTP_METHODS.DELETE,
1791
+ signal: options.signal,
1792
+ apiKey: options.apiKey
1793
+ })
1794
+ });
1795
+
1796
+ const ListQuery$5 = (options) => ({ addressId: options.addressId });
1797
+ const SizeOf = (data) => data instanceof Blob ? data.size : data.byteLength;
1798
+ const SliceOf = (data, start, end) => {
1799
+ if (data instanceof Blob)
1800
+ return data.slice(start, end);
1801
+ if (data instanceof Uint8Array)
1802
+ return data.subarray(start, end);
1803
+ return new Uint8Array(data, start, end - start);
1804
+ };
1805
+ const Imports = (transport) => {
1806
+ const create = (body, options = {}) => transport.request(PATHS.IMPORTS, {
1807
+ method: HTTP_METHODS.POST,
1808
+ body,
1809
+ signal: options.signal,
1810
+ apiKey: options.apiKey
1811
+ });
1812
+ const uploadChunk = (id, file, chunk, data, options = {}) => transport.request(ImportChunkPath(id, file, chunk), {
1813
+ method: HTTP_METHODS.PUT,
1814
+ raw: data,
1815
+ repeatable: true,
1816
+ signal: options.signal,
1817
+ apiKey: options.apiKey
1818
+ });
1819
+ const start = (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.START), {
1820
+ method: HTTP_METHODS.POST,
1821
+ repeatable: true,
1822
+ signal: options.signal,
1823
+ apiKey: options.apiKey
1824
+ });
1825
+ return {
1826
+ list: (options = {}) => FetchPage(transport, PATHS.IMPORTS, CURSOR_STYLES.CURSOR, options, ListQuery$5(options)),
1827
+ listAll: (options = {}) => CollectAll(transport, PATHS.IMPORTS, CURSOR_STYLES.CURSOR, options, ListQuery$5(options)),
1828
+ iterate: (options = {}) => IteratePages(transport, PATHS.IMPORTS, CURSOR_STYLES.CURSOR, options, ListQuery$5(options)),
1829
+ get: (id, options = {}) => transport.request(ImportPath(id), { signal: options.signal, apiKey: options.apiKey }),
1830
+ create,
1831
+ uploadState: (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.UPLOAD), {
1832
+ signal: options.signal,
1833
+ apiKey: options.apiKey
1834
+ }),
1835
+ uploadChunk,
1836
+ start,
1837
+ cancel: (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.CANCEL), {
1838
+ method: HTTP_METHODS.POST,
1839
+ signal: options.signal,
1840
+ apiKey: options.apiKey
1841
+ }),
1842
+ listFailures: (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.FAILURES), {
1843
+ query: { after: options.after, limit: options.limit },
1844
+ signal: options.signal,
1845
+ apiKey: options.apiKey
1846
+ }),
1847
+ deleteUpload: (id, options = {}) => transport.request(ImportChildPath(id, SEGMENTS.UPLOAD), {
1848
+ method: HTTP_METHODS.DELETE,
1849
+ signal: options.signal,
1850
+ apiKey: options.apiKey
1851
+ }),
1852
+ importFiles: async (input, options = {}) => {
1853
+ const created = await create({
1854
+ addressId: input.addressId,
1855
+ files: input.files.map(file => ({ name: file.name, bytes: SizeOf(file.data) })),
1856
+ options: input.options
1857
+ }, options);
1858
+ if (input.files.length === 0)
1859
+ return created;
1860
+ const total = created.totalBytes;
1861
+ let uploaded = 0;
1862
+ for (const [index, file] of input.files.entries()) {
1863
+ const chunks = created.files[index]?.chunks ?? 1;
1864
+ for (let chunk = 0; chunk < chunks; chunk++) {
1865
+ const begin = chunk * created.chunkBytes;
1866
+ const end = Math.min(SizeOf(file.data), begin + created.chunkBytes);
1867
+ await uploadChunk(created.id, index, chunk, SliceOf(file.data, begin, end), options);
1868
+ uploaded += end - begin;
1869
+ input.onProgress?.(uploaded, total);
1870
+ }
1871
+ }
1872
+ return start(created.id, options);
1873
+ }
1874
+ };
1875
+ };
1876
+
1877
+ const WindowQuery$2 = (options) => ({
1878
+ [QUERY_KEYS.SINCE]: options.since === undefined ? undefined : ToInstant(options.since),
1879
+ [QUERY_KEYS.UNTIL]: options.until === undefined ? undefined : ToInstant(options.until)
1880
+ });
1881
+ const RequestQuery = (options) => ({
1882
+ ...WindowQuery$2(options),
1883
+ [QUERY_KEYS.FAILED_ONLY]: options.failedOnly === undefined ? undefined : String(options.failedOnly)
1884
+ });
1885
+ const WorkspaceRequestQuery = (options) => ({
1886
+ ...RequestQuery(options),
1887
+ [QUERY_KEYS.KEY_IDS]: options.keyIds?.join(LIST_SEPARATOR)
1888
+ });
1889
+ const WorkspaceActivityQuery$1 = (options) => ({
1890
+ ...WindowQuery$2(options),
1891
+ [QUERY_KEYS.KEY_IDS]: options.keyIds?.join(LIST_SEPARATOR)
1892
+ });
1893
+ const Keys = (transport) => ({
1894
+ list: (options = {}) => FetchPage(transport, PATHS.KEYS, CURSOR_STYLES.CURSOR, options),
1895
+ listAll: (options = {}) => CollectAll(transport, PATHS.KEYS, CURSOR_STYLES.CURSOR, options),
1896
+ iterate: (options = {}) => IteratePages(transport, PATHS.KEYS, CURSOR_STYLES.CURSOR, options),
1897
+ get: (id, options = {}) => transport.request(KeyPath(id), { signal: options.signal, apiKey: options.apiKey }),
1898
+ create: (body, options = {}) => transport.request(PATHS.KEYS, {
1899
+ method: HTTP_METHODS.POST,
1900
+ body,
1901
+ signal: options.signal,
1902
+ apiKey: options.apiKey
1903
+ }),
1904
+ update: (id, patch, options = {}) => transport.request(KeyPath(id), {
1905
+ method: HTTP_METHODS.PATCH,
1906
+ body: patch,
1907
+ repeatable: true,
1908
+ signal: options.signal,
1909
+ apiKey: options.apiKey
1910
+ }),
1911
+ delete: (id, options = {}) => transport.request(KeyPath(id), {
1912
+ method: HTTP_METHODS.DELETE,
1913
+ signal: options.signal,
1914
+ apiKey: options.apiKey
1915
+ }),
1916
+ rotate: (id, options = {}) => transport.request(KeyChildPath(id, SEGMENTS.ROTATE), {
1917
+ method: HTTP_METHODS.POST,
1918
+ signal: options.signal,
1919
+ apiKey: options.apiKey
1920
+ }),
1921
+ revoke: (id, body = {}, options = {}) => transport.request(KeyChildPath(id, SEGMENTS.REVOKE), {
1922
+ method: HTTP_METHODS.POST,
1923
+ body,
1924
+ repeatable: true,
1925
+ signal: options.signal,
1926
+ apiKey: options.apiKey
1927
+ }),
1928
+ listRequests: (id, options = {}) => FetchPage(transport, KeyChildPath(id, SEGMENTS.REQUESTS), CURSOR_STYLES.CURSOR, options, RequestQuery(options)),
1929
+ listAllRequests: (id, options = {}) => CollectAll(transport, KeyChildPath(id, SEGMENTS.REQUESTS), CURSOR_STYLES.CURSOR, options, RequestQuery(options)),
1930
+ iterateRequests: (id, options = {}) => IteratePages(transport, KeyChildPath(id, SEGMENTS.REQUESTS), CURSOR_STYLES.CURSOR, options, RequestQuery(options)),
1931
+ listActivity: (id, options = {}) => FetchPage(transport, KeyChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery$2(options)),
1932
+ listAllActivity: (id, options = {}) => CollectAll(transport, KeyChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery$2(options)),
1933
+ iterateActivity: (id, options = {}) => IteratePages(transport, KeyChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery$2(options)),
1934
+ listWorkspaceRequests: (options = {}) => FetchPage(transport, PATHS.KEYS_REQUESTS, CURSOR_STYLES.CURSOR, options, WorkspaceRequestQuery(options)),
1935
+ listAllWorkspaceRequests: (options = {}) => CollectAll(transport, PATHS.KEYS_REQUESTS, CURSOR_STYLES.CURSOR, options, WorkspaceRequestQuery(options)),
1936
+ iterateWorkspaceRequests: (options = {}) => IteratePages(transport, PATHS.KEYS_REQUESTS, CURSOR_STYLES.CURSOR, options, WorkspaceRequestQuery(options)),
1937
+ listWorkspaceActivity: (options = {}) => FetchPage(transport, PATHS.KEYS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery$1(options)),
1938
+ listAllWorkspaceActivity: (options = {}) => CollectAll(transport, PATHS.KEYS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery$1(options)),
1939
+ iterateWorkspaceActivity: (options = {}) => IteratePages(transport, PATHS.KEYS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery$1(options))
1940
+ });
1941
+
1942
+ const ProviderImports = (transport) => ({
1943
+ inspect: (apiKey, options = {}) => transport.request(PATHS.PROVIDER_IMPORTS_INSPECT, {
1944
+ method: HTTP_METHODS.POST,
1945
+ body: { apiKey },
1946
+ signal: options.signal,
1947
+ apiKey: options.apiKey
1948
+ }),
1949
+ create: (body, options = {}) => transport.request(PATHS.PROVIDER_IMPORTS, {
1950
+ method: HTTP_METHODS.POST,
1951
+ body,
1952
+ signal: options.signal,
1953
+ apiKey: options.apiKey
1954
+ }),
1955
+ list: (options = {}) => FetchPage(transport, PATHS.PROVIDER_IMPORTS, CURSOR_STYLES.CURSOR, options),
1956
+ listAll: (options = {}) => CollectAll(transport, PATHS.PROVIDER_IMPORTS, CURSOR_STYLES.CURSOR, options),
1957
+ iterate: (options = {}) => IteratePages(transport, PATHS.PROVIDER_IMPORTS, CURSOR_STYLES.CURSOR, options),
1958
+ get: (id, options = {}) => transport.request(ProviderImportPath(id), { signal: options.signal, apiKey: options.apiKey }),
1959
+ cancel: (id, options = {}) => transport.request(ProviderImportChildPath(id, SEGMENTS.CANCEL), {
1960
+ method: HTTP_METHODS.POST,
1961
+ signal: options.signal,
1962
+ apiKey: options.apiKey
1963
+ })
1964
+ });
1965
+
1177
1966
  const Labels = (transport) => ({
1178
- list: (options = {}) => FetchList(transport, PATHS.LABELS, options),
1967
+ list: (options = {}) => FetchPage(transport, PATHS.LABELS, CURSOR_STYLES.CURSOR, options),
1968
+ listAll: (options = {}) => CollectAll(transport, PATHS.LABELS, CURSOR_STYLES.CURSOR, options),
1969
+ iterate: (options = {}) => IteratePages(transport, PATHS.LABELS, CURSOR_STYLES.CURSOR, options),
1970
+ listColors: (options = {}) => FetchList(transport, PATHS.LABELS_COLORS, options),
1179
1971
  get: (id, options = {}) => transport.request(LabelPath(id), { signal: options.signal, apiKey: options.apiKey }),
1180
1972
  create: (body, options = {}) => transport.request(PATHS.LABELS, {
1181
1973
  method: HTTP_METHODS.POST,
@@ -1183,9 +1975,9 @@ const Labels = (transport) => ({
1183
1975
  signal: options.signal,
1184
1976
  apiKey: options.apiKey
1185
1977
  }),
1186
- update: (id, body, options = {}) => transport.request(LabelPath(id), {
1978
+ update: (id, patch, options = {}) => transport.request(LabelPath(id), {
1187
1979
  method: HTTP_METHODS.PATCH,
1188
- body,
1980
+ body: patch,
1189
1981
  repeatable: true,
1190
1982
  signal: options.signal,
1191
1983
  apiKey: options.apiKey
@@ -1203,11 +1995,18 @@ const Languages = (transport) => ({
1203
1995
 
1204
1996
  const Me = (transport) => ({
1205
1997
  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 })
1998
+ ping: (options = {}) => transport.request(PATHS.PING, { signal: options.signal, apiKey: options.apiKey }),
1999
+ rotate: (options = {}) => transport.request(PATHS.KEYS_SELF_ROTATE, {
2000
+ method: HTTP_METHODS.POST,
2001
+ signal: options.signal,
2002
+ apiKey: options.apiKey
2003
+ })
1207
2004
  });
1208
2005
 
1209
2006
  const Members = (transport) => ({
1210
- list: (options = {}) => FetchList(transport, PATHS.MEMBERS, options),
2007
+ list: (options = {}) => FetchPage(transport, PATHS.MEMBERS, CURSOR_STYLES.CURSOR, options),
2008
+ listAll: (options = {}) => CollectAll(transport, PATHS.MEMBERS, CURSOR_STYLES.CURSOR, options),
2009
+ iterate: (options = {}) => IteratePages(transport, PATHS.MEMBERS, CURSOR_STYLES.CURSOR, options),
1211
2010
  get: (userId, options = {}) => transport.request(MemberPath(userId), { signal: options.signal, apiKey: options.apiKey }),
1212
2011
  add: (body, options = {}) => transport.request(PATHS.MEMBERS, {
1213
2012
  method: HTTP_METHODS.POST,
@@ -1238,11 +2037,26 @@ const Members = (transport) => ({
1238
2037
  method: HTTP_METHODS.DELETE,
1239
2038
  signal: options.signal,
1240
2039
  apiKey: options.apiKey
2040
+ }),
2041
+ listInvitations: (options = {}) => FetchPage(transport, PATHS.MEMBERS_INVITATIONS, CURSOR_STYLES.CURSOR, options),
2042
+ listAllInvitations: (options = {}) => CollectAll(transport, PATHS.MEMBERS_INVITATIONS, CURSOR_STYLES.CURSOR, options),
2043
+ iterateInvitations: (options = {}) => IteratePages(transport, PATHS.MEMBERS_INVITATIONS, CURSOR_STYLES.CURSOR, options),
2044
+ revokeInvitation: (invitationId, options = {}) => transport.request(MemberInvitationPath(invitationId), {
2045
+ method: HTTP_METHODS.DELETE,
2046
+ signal: options.signal,
2047
+ apiKey: options.apiKey
2048
+ }),
2049
+ resendInvitation: (invitationId, options = {}) => transport.request(MemberInvitationResendPath(invitationId), {
2050
+ method: HTTP_METHODS.POST,
2051
+ signal: options.signal,
2052
+ apiKey: options.apiKey
1241
2053
  })
1242
2054
  });
1243
2055
 
1244
2056
  const Roles = (transport) => ({
1245
- list: (options = {}) => FetchList(transport, PATHS.ROLES, options),
2057
+ list: (options = {}) => FetchPage(transport, PATHS.ROLES, CURSOR_STYLES.CURSOR, options),
2058
+ listAll: (options = {}) => CollectAll(transport, PATHS.ROLES, CURSOR_STYLES.CURSOR, options),
2059
+ iterate: (options = {}) => IteratePages(transport, PATHS.ROLES, CURSOR_STYLES.CURSOR, options),
1246
2060
  get: (id, options = {}) => transport.request(RolePath(id), { signal: options.signal, apiKey: options.apiKey }),
1247
2061
  create: (body, options = {}) => transport.request(PATHS.ROLES, {
1248
2062
  method: HTTP_METHODS.POST,
@@ -1266,7 +2080,7 @@ const Roles = (transport) => ({
1266
2080
  listPermissions: (options = {}) => FetchList(transport, PATHS.ROLES_PERMISSIONS, options)
1267
2081
  });
1268
2082
 
1269
- const ListQuery$2 = (options) => ({
2083
+ const ListQuery$4 = (options) => ({
1270
2084
  [QUERY_KEYS.ENABLED]: options.enabled === undefined ? undefined : String(options.enabled)
1271
2085
  });
1272
2086
  const RunsQuery = (options) => ({
@@ -1274,9 +2088,9 @@ const RunsQuery = (options) => ({
1274
2088
  [QUERY_KEYS.THREAD_ID]: options.threadId
1275
2089
  });
1276
2090
  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)),
2091
+ list: (options = {}) => FetchPage(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$4(options)),
2092
+ listAll: (options = {}) => CollectAll(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$4(options)),
2093
+ iterate: (options = {}) => IteratePages(transport, PATHS.RULES, CURSOR_STYLES.CURSOR, options, ListQuery$4(options)),
1280
2094
  get: (id, options = {}) => transport.request(RulePath(id), { signal: options.signal, apiKey: options.apiKey }),
1281
2095
  create: (body, options = {}) => transport.request(PATHS.RULES, {
1282
2096
  method: HTTP_METHODS.POST,
@@ -1318,9 +2132,14 @@ const Rules = (transport) => ({
1318
2132
  });
1319
2133
 
1320
2134
  const Settings = (transport) => ({
1321
- get: (options = {}) => transport.request(PATHS.SETTINGS, { signal: options.signal, apiKey: options.apiKey }),
2135
+ get: (options = {}) => transport.request(PATHS.SETTINGS, {
2136
+ query: { [QUERY_KEYS.ADDRESS]: options.address },
2137
+ signal: options.signal,
2138
+ apiKey: options.apiKey
2139
+ }),
1322
2140
  update: (patch, options = {}) => transport.request(PATHS.SETTINGS, {
1323
2141
  method: HTTP_METHODS.PATCH,
2142
+ query: { [QUERY_KEYS.ADDRESS]: options.address },
1324
2143
  body: patch,
1325
2144
  repeatable: true,
1326
2145
  signal: options.signal,
@@ -1328,6 +2147,54 @@ const Settings = (transport) => ({
1328
2147
  })
1329
2148
  });
1330
2149
 
2150
+ const ListQuery$3 = (options) => ({
2151
+ [QUERY_KEYS.Q]: options.q,
2152
+ [QUERY_KEYS.REASON]: options.reason
2153
+ });
2154
+ const Suppressions = (transport) => ({
2155
+ list: (options = {}) => FetchPage(transport, PATHS.SUPPRESSIONS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
2156
+ listAll: (options = {}) => CollectAll(transport, PATHS.SUPPRESSIONS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
2157
+ iterate: (options = {}) => IteratePages(transport, PATHS.SUPPRESSIONS, CURSOR_STYLES.CURSOR, options, ListQuery$3(options)),
2158
+ get: (id, options = {}) => transport.request(SuppressionPath(id), { signal: options.signal, apiKey: options.apiKey }),
2159
+ add: (body, options = {}) => transport.request(PATHS.SUPPRESSIONS, {
2160
+ method: HTTP_METHODS.POST,
2161
+ body,
2162
+ repeatable: true,
2163
+ signal: options.signal,
2164
+ apiKey: options.apiKey
2165
+ }),
2166
+ remove: (id, options = {}) => transport.request(SuppressionPath(id), {
2167
+ method: HTTP_METHODS.DELETE,
2168
+ signal: options.signal,
2169
+ apiKey: options.apiKey
2170
+ })
2171
+ });
2172
+
2173
+ const MessagePage = async (transport, inboxId, options) => {
2174
+ const envelope = await transport.request(TempMessagesPath(inboxId), {
2175
+ query: { [QUERY_KEYS.LIMIT]: options.limit, [QUERY_KEYS.CURSOR]: options.cursor },
2176
+ inboxToken: options.inboxToken,
2177
+ signal: options.signal
2178
+ });
2179
+ const nextCursor = typeof envelope?.nextCursor === 'string' && envelope.nextCursor.length > 0 ? envelope.nextCursor : null;
2180
+ return {
2181
+ items: envelope?.data ?? [],
2182
+ hasMore: typeof envelope?.hasMore === 'boolean' ? envelope.hasMore : nextCursor !== null,
2183
+ nextCursor,
2184
+ expiresAt: envelope?.expiresAt
2185
+ };
2186
+ };
2187
+ const IterateMessages = async function* (transport, inboxId, options) {
2188
+ let cursor = options.cursor;
2189
+ for (;;) {
2190
+ const page = await MessagePage(transport, inboxId, { ...options, cursor });
2191
+ for (const item of page.items)
2192
+ yield item;
2193
+ if (!page.hasMore || !page.nextCursor || page.nextCursor === cursor)
2194
+ return;
2195
+ cursor = page.nextCursor;
2196
+ }
2197
+ };
1331
2198
  const TempMail = (transport) => ({
1332
2199
  listDomains: async (options = {}) => (await transport.request(PATHS.TEMP_MAIL_DOMAINS, {
1333
2200
  anonymous: true,
@@ -1353,14 +2220,14 @@ const TempMail = (transport) => ({
1353
2220
  inboxToken: options.inboxToken,
1354
2221
  signal: options.signal
1355
2222
  }),
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 };
2223
+ listMessages: (inboxId, options = {}) => MessagePage(transport, inboxId, options),
2224
+ listAllMessages: async (inboxId, options = {}) => {
2225
+ const all = [];
2226
+ for await (const message of IterateMessages(transport, inboxId, options))
2227
+ all.push(message);
2228
+ return all;
1363
2229
  },
2230
+ iterateMessages: (inboxId, options = {}) => IterateMessages(transport, inboxId, options),
1364
2231
  getMessage: (inboxId, messageId, options = {}) => transport.request(TempMessagePath(inboxId, messageId), {
1365
2232
  inboxToken: options.inboxToken,
1366
2233
  signal: options.signal
@@ -1376,11 +2243,32 @@ const TempMail = (transport) => ({
1376
2243
  }))?.data ?? []
1377
2244
  });
1378
2245
 
1379
- const ListQuery$1 = (options) => ({ [QUERY_KEYS.STATUS]: options.status });
2246
+ const ListQuery$2 = (options) => ({
2247
+ [QUERY_KEYS.STATUS]: options.status,
2248
+ [QUERY_KEYS.SEARCH]: options.search,
2249
+ [QUERY_KEYS.SORT]: options.sort
2250
+ });
2251
+ const Flag$1 = (value) => value === undefined ? undefined : String(value);
2252
+ const WindowQuery$1 = (options) => ({
2253
+ [QUERY_KEYS.DAYS]: options.days,
2254
+ [QUERY_KEYS.MINUTES]: options.minutes,
2255
+ [QUERY_KEYS.GRAIN]: options.grain,
2256
+ [QUERY_KEYS.OFFSET_MINUTES]: options.offsetMinutes
2257
+ });
1380
2258
  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)),
2259
+ list: (options = {}) => FetchPage(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
2260
+ listAll: (options = {}) => CollectAll(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
2261
+ iterate: (options = {}) => IteratePages(transport, PATHS.TEMPLATES, CURSOR_STYLES.CURSOR, options, ListQuery$2(options)),
2262
+ listStarters: (options = {}) => FetchList(transport, PATHS.TEMPLATES_STARTERS, options),
2263
+ listFonts: (options = {}) => FetchList(transport, PATHS.TEMPLATES_FONTS, options),
2264
+ getStarter: (slug, options = {}) => transport.request(TemplateStarterPath(slug), { signal: options.signal, apiKey: options.apiKey }),
2265
+ render: (body, options = {}) => transport.request(PATHS.TEMPLATES_RENDER, {
2266
+ method: HTTP_METHODS.POST,
2267
+ body,
2268
+ repeatable: true,
2269
+ signal: options.signal,
2270
+ apiKey: options.apiKey
2271
+ }),
1384
2272
  get: (idOrSlug, options = {}) => transport.request(TemplatePath(idOrSlug), { signal: options.signal, apiKey: options.apiKey }),
1385
2273
  create: (body, options = {}) => transport.request(PATHS.TEMPLATES, {
1386
2274
  method: HTTP_METHODS.POST,
@@ -1399,7 +2287,33 @@ const Templates = (transport) => ({
1399
2287
  signal: options.signal,
1400
2288
  apiKey: options.apiKey
1401
2289
  }),
1402
- listVersions: (idOrSlug, options = {}) => FetchList(transport, TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), options),
2290
+ duplicate: (idOrSlug, body = {}, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.DUPLICATE), {
2291
+ method: HTTP_METHODS.POST,
2292
+ body,
2293
+ signal: options.signal,
2294
+ apiKey: options.apiKey
2295
+ }),
2296
+ replaceContent: (idOrSlug, body, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.CONTENT), {
2297
+ method: HTTP_METHODS.POST,
2298
+ body,
2299
+ signal: options.signal,
2300
+ apiKey: options.apiKey
2301
+ }),
2302
+ listVersions: (idOrSlug, options = {}) => FetchPage(transport, TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), CURSOR_STYLES.CURSOR, options),
2303
+ listAllVersions: (idOrSlug, options = {}) => CollectAll(transport, TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), CURSOR_STYLES.CURSOR, options),
2304
+ iterateVersions: (idOrSlug, options = {}) => IteratePages(transport, TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), CURSOR_STYLES.CURSOR, options),
2305
+ getVersion: (idOrSlug, version, options = {}) => transport.request(TemplateVersionPath(idOrSlug, version), { signal: options.signal, apiKey: options.apiKey }),
2306
+ deleteVersion: (idOrSlug, version, options = {}) => transport.request(TemplateVersionPath(idOrSlug, version), {
2307
+ method: HTTP_METHODS.DELETE,
2308
+ signal: options.signal,
2309
+ apiKey: options.apiKey
2310
+ }),
2311
+ restoreVersion: (idOrSlug, version, body = {}, options = {}) => transport.request(TemplateVersionChildPath(idOrSlug, version, SEGMENTS.RESTORE), {
2312
+ method: HTTP_METHODS.POST,
2313
+ body,
2314
+ signal: options.signal,
2315
+ apiKey: options.apiKey
2316
+ }),
1403
2317
  publish: (idOrSlug, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.VERSIONS), {
1404
2318
  method: HTTP_METHODS.POST,
1405
2319
  repeatable: true,
@@ -1413,6 +2327,34 @@ const Templates = (transport) => ({
1413
2327
  signal: options.signal,
1414
2328
  apiKey: options.apiKey
1415
2329
  }),
2330
+ getAnalytics: (idOrSlug, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.ANALYTICS), {
2331
+ query: WindowQuery$1(options),
2332
+ signal: options.signal,
2333
+ apiKey: options.apiKey
2334
+ }),
2335
+ listSends: async (idOrSlug, options = {}) => {
2336
+ const envelope = await transport.request(TemplateChildPath(idOrSlug, SEGMENTS.SENDS), {
2337
+ query: {
2338
+ ...WindowQuery$1(options),
2339
+ [QUERY_KEYS.PAGE]: options.page,
2340
+ [QUERY_KEYS.PAGE_SIZE]: options.pageSize,
2341
+ [QUERY_KEYS.SEARCH]: options.search,
2342
+ [QUERY_KEYS.SOURCE]: options.source,
2343
+ [QUERY_KEYS.VERSION]: options.version,
2344
+ [QUERY_KEYS.OPENED]: Flag$1(options.opened),
2345
+ [QUERY_KEYS.CLICKED]: Flag$1(options.clicked),
2346
+ [QUERY_KEYS.TRACKED]: Flag$1(options.tracked)
2347
+ },
2348
+ signal: options.signal,
2349
+ apiKey: options.apiKey
2350
+ });
2351
+ return {
2352
+ items: envelope?.data ?? [],
2353
+ total: envelope?.total ?? 0,
2354
+ page: envelope?.page ?? 1,
2355
+ pageSize: envelope?.pageSize ?? 0
2356
+ };
2357
+ },
1416
2358
  send: (idOrSlug, body, options = {}) => transport.request(TemplateChildPath(idOrSlug, SEGMENTS.SEND), {
1417
2359
  method: HTTP_METHODS.POST,
1418
2360
  body: TemplateSendToWire(body),
@@ -1424,15 +2366,19 @@ const Templates = (transport) => ({
1424
2366
  })
1425
2367
  });
1426
2368
 
1427
- const ListQuery = (options) => ({
2369
+ const ListQuery$1 = (options) => ({
1428
2370
  [QUERY_KEYS.FOLDER]: options.folder,
1429
2371
  [QUERY_KEYS.QUERY]: options.query,
1430
- [QUERY_KEYS.LABEL_IDS]: Array.isArray(options.labelIds) ? options.labelIds.join(LIST_SEPARATOR) : options.labelIds
2372
+ [QUERY_KEYS.LABEL_IDS]: Array.isArray(options.labelIds) ? options.labelIds.join(LIST_SEPARATOR) : options.labelIds,
2373
+ [QUERY_KEYS.SORT]: options.sort,
2374
+ [QUERY_KEYS.DATE_FROM]: options.dateFrom === undefined ? undefined : ToInstant(options.dateFrom),
2375
+ [QUERY_KEYS.DATE_TO]: options.dateTo === undefined ? undefined : ToInstant(options.dateTo),
2376
+ [QUERY_KEYS.FROM_CONTACTS]: options.fromContacts === undefined ? undefined : String(options.fromContacts)
1431
2377
  });
1432
2378
  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)),
2379
+ list: (options = {}) => FetchPage(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$1(options)),
2380
+ listAll: (options = {}) => CollectAll(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$1(options)),
2381
+ iterate: (options = {}) => IteratePages(transport, PATHS.THREADS, CURSOR_STYLES.PAGE_TOKEN, options, ListQuery$1(options)),
1436
2382
  get: (id, options = {}) => transport.request(ThreadPath(id), { signal: options.signal, apiKey: options.apiKey }),
1437
2383
  update: (id, patch, options = {}) => transport.request(ThreadPath(id), {
1438
2384
  method: HTTP_METHODS.PATCH,
@@ -1465,18 +2411,19 @@ const Threads = (transport) => ({
1465
2411
 
1466
2412
  const Flag = (value) => value === undefined ? undefined : String(value);
1467
2413
  const HitQuery = (options) => ({
1468
- [QUERY_KEYS.INCLUDE_MACHINE]: Flag(options.includeMachine),
1469
- [QUERY_KEYS.LIMIT]: options.limit
2414
+ [QUERY_KEYS.INCLUDE_MACHINE]: Flag(options.includeMachine)
2415
+ });
2416
+ const ListQuery = (options) => ({
2417
+ [QUERY_KEYS.OPENED]: Flag(options.opened),
2418
+ [QUERY_KEYS.CLICKED]: Flag(options.clicked),
2419
+ [QUERY_KEYS.DAYS]: options.days,
2420
+ [QUERY_KEYS.MINUTES]: options.minutes,
2421
+ [QUERY_KEYS.GRAIN]: options.grain
1470
2422
  });
1471
2423
  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
- }),
2424
+ list: (options = {}) => FetchPage(transport, PATHS.TRACKING, CURSOR_STYLES.CURSOR, options, ListQuery(options)),
2425
+ listAll: (options = {}) => CollectAll(transport, PATHS.TRACKING, CURSOR_STYLES.CURSOR, options, ListQuery(options)),
2426
+ iterate: (options = {}) => IteratePages(transport, PATHS.TRACKING, CURSOR_STYLES.CURSOR, options, ListQuery(options)),
1480
2427
  getStats: (options = {}) => transport.request(PATHS.TRACKING_STATS, {
1481
2428
  query: {
1482
2429
  [QUERY_KEYS.DAYS]: options.days,
@@ -1488,12 +2435,34 @@ const Tracking = (transport) => ({
1488
2435
  apiKey: options.apiKey
1489
2436
  }),
1490
2437
  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))
2438
+ listOpens: (id, options = {}) => FetchPage(transport, TrackingChildPath(id, SEGMENTS.OPENS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2439
+ listAllOpens: (id, options = {}) => CollectAll(transport, TrackingChildPath(id, SEGMENTS.OPENS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2440
+ iterateOpens: (id, options = {}) => IteratePages(transport, TrackingChildPath(id, SEGMENTS.OPENS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2441
+ listClicks: (id, options = {}) => FetchPage(transport, TrackingChildPath(id, SEGMENTS.CLICKS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2442
+ listAllClicks: (id, options = {}) => CollectAll(transport, TrackingChildPath(id, SEGMENTS.CLICKS), CURSOR_STYLES.CURSOR, options, HitQuery(options)),
2443
+ iterateClicks: (id, options = {}) => IteratePages(transport, TrackingChildPath(id, SEGMENTS.CLICKS), CURSOR_STYLES.CURSOR, options, HitQuery(options))
1493
2444
  });
1494
2445
 
2446
+ const WindowQuery = (options) => ({
2447
+ [QUERY_KEYS.SINCE]: options.since === undefined ? undefined : ToInstant(options.since),
2448
+ [QUERY_KEYS.UNTIL]: options.until === undefined ? undefined : ToInstant(options.until)
2449
+ });
2450
+ const DeliveryQuery = (options) => ({
2451
+ ...WindowQuery(options),
2452
+ [QUERY_KEYS.STATUS]: options.status
2453
+ });
2454
+ const WorkspaceDeliveryQuery = (options) => ({
2455
+ ...DeliveryQuery(options),
2456
+ [QUERY_KEYS.ENDPOINT_IDS]: options.endpointIds?.join(LIST_SEPARATOR)
2457
+ });
2458
+ const WorkspaceActivityQuery = (options) => ({
2459
+ ...WindowQuery(options),
2460
+ [QUERY_KEYS.ENDPOINT_IDS]: options.endpointIds?.join(LIST_SEPARATOR)
2461
+ });
1495
2462
  const Webhooks = (transport) => ({
1496
- list: (options = {}) => FetchList(transport, PATHS.WEBHOOKS, options),
2463
+ list: (options = {}) => FetchPage(transport, PATHS.WEBHOOKS, CURSOR_STYLES.CURSOR, options),
2464
+ listAll: (options = {}) => CollectAll(transport, PATHS.WEBHOOKS, CURSOR_STYLES.CURSOR, options),
2465
+ iterate: (options = {}) => IteratePages(transport, PATHS.WEBHOOKS, CURSOR_STYLES.CURSOR, options),
1497
2466
  get: (id, options = {}) => transport.request(WebhookPath(id), { signal: options.signal, apiKey: options.apiKey }),
1498
2467
  create: (body, options = {}) => transport.request(PATHS.WEBHOOKS, {
1499
2468
  method: HTTP_METHODS.POST,
@@ -1523,13 +2492,34 @@ const Webhooks = (transport) => ({
1523
2492
  signal: options.signal,
1524
2493
  apiKey: options.apiKey
1525
2494
  }),
1526
- listDeliveries: (id, options = {}) => FetchList(transport, WebhookChildPath(id, SEGMENTS.DELIVERIES), options)
2495
+ listDeliveries: (id, options = {}) => FetchPage(transport, WebhookChildPath(id, SEGMENTS.DELIVERIES), CURSOR_STYLES.CURSOR, options, DeliveryQuery(options)),
2496
+ listAllDeliveries: (id, options = {}) => CollectAll(transport, WebhookChildPath(id, SEGMENTS.DELIVERIES), CURSOR_STYLES.CURSOR, options, DeliveryQuery(options)),
2497
+ iterateDeliveries: (id, options = {}) => IteratePages(transport, WebhookChildPath(id, SEGMENTS.DELIVERIES), CURSOR_STYLES.CURSOR, options, DeliveryQuery(options)),
2498
+ listWorkspaceDeliveries: (options = {}) => FetchPage(transport, PATHS.WEBHOOKS_DELIVERIES, CURSOR_STYLES.CURSOR, options, WorkspaceDeliveryQuery(options)),
2499
+ listAllWorkspaceDeliveries: (options = {}) => CollectAll(transport, PATHS.WEBHOOKS_DELIVERIES, CURSOR_STYLES.CURSOR, options, WorkspaceDeliveryQuery(options)),
2500
+ iterateWorkspaceDeliveries: (options = {}) => IteratePages(transport, PATHS.WEBHOOKS_DELIVERIES, CURSOR_STYLES.CURSOR, options, WorkspaceDeliveryQuery(options)),
2501
+ listActivity: (id, options = {}) => FetchPage(transport, WebhookChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery(options)),
2502
+ listAllActivity: (id, options = {}) => CollectAll(transport, WebhookChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery(options)),
2503
+ iterateActivity: (id, options = {}) => IteratePages(transport, WebhookChildPath(id, SEGMENTS.ACTIVITY), CURSOR_STYLES.CURSOR, options, WindowQuery(options)),
2504
+ listWorkspaceActivity: (options = {}) => FetchPage(transport, PATHS.WEBHOOKS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery(options)),
2505
+ listAllWorkspaceActivity: (options = {}) => CollectAll(transport, PATHS.WEBHOOKS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery(options)),
2506
+ iterateWorkspaceActivity: (options = {}) => IteratePages(transport, PATHS.WEBHOOKS_ACTIVITY, CURSOR_STYLES.CURSOR, options, WorkspaceActivityQuery(options)),
2507
+ getDelivery: (id, deliveryId, options = {}) => transport.request(WebhookDeliveryPath(id, deliveryId), {
2508
+ signal: options.signal,
2509
+ apiKey: options.apiKey
2510
+ }),
2511
+ replayDelivery: (id, deliveryId, options = {}) => transport.request(WebhookDeliveryReplayPath(id, deliveryId), {
2512
+ method: HTTP_METHODS.POST,
2513
+ signal: options.signal,
2514
+ apiKey: options.apiKey
2515
+ })
1527
2516
  });
1528
2517
 
1529
2518
  class OpenEmail {
1530
2519
  transport;
1531
2520
  mode;
1532
2521
  me;
2522
+ keys;
1533
2523
  addresses;
1534
2524
  languages;
1535
2525
  emails;
@@ -1539,13 +2529,19 @@ class OpenEmail {
1539
2529
  drafts;
1540
2530
  labels;
1541
2531
  contacts;
2532
+ audiences;
2533
+ broadcasts;
1542
2534
  domains;
1543
2535
  rules;
1544
2536
  webhooks;
2537
+ imports;
2538
+ providerImports;
1545
2539
  calendar;
1546
2540
  settings;
1547
2541
  roles;
1548
2542
  members;
2543
+ suppressions;
2544
+ files;
1549
2545
  tempMail;
1550
2546
  constructor(configuration) {
1551
2547
  const options = typeof configuration === 'string' ? { apiKey: configuration } : configuration;
@@ -1555,6 +2551,7 @@ class OpenEmail {
1555
2551
  this.transport = new Transport(options);
1556
2552
  this.mode = ModeOf(options.apiKey);
1557
2553
  this.me = Me(this.transport);
2554
+ this.keys = Keys(this.transport);
1558
2555
  this.addresses = Addresses(this.transport);
1559
2556
  this.languages = Languages(this.transport);
1560
2557
  this.emails = Emails(this.transport);
@@ -1564,13 +2561,19 @@ class OpenEmail {
1564
2561
  this.drafts = Drafts(this.transport);
1565
2562
  this.labels = Labels(this.transport);
1566
2563
  this.contacts = Contacts(this.transport);
2564
+ this.audiences = Audiences(this.transport);
2565
+ this.broadcasts = Broadcasts(this.transport);
1567
2566
  this.domains = Domains(this.transport);
1568
2567
  this.rules = Rules(this.transport);
1569
2568
  this.webhooks = Webhooks(this.transport);
2569
+ this.imports = Imports(this.transport);
2570
+ this.providerImports = ProviderImports(this.transport);
1570
2571
  this.calendar = Calendar(this.transport);
1571
2572
  this.settings = Settings(this.transport);
1572
2573
  this.roles = Roles(this.transport);
1573
2574
  this.members = Members(this.transport);
2575
+ this.suppressions = Suppressions(this.transport);
2576
+ this.files = Files(this.transport);
1574
2577
  this.tempMail = TempMail(this.transport);
1575
2578
  }
1576
2579
  get raw() {
@@ -1746,18 +2749,32 @@ const languageByCode = LanguageByCode;
1746
2749
  const isRtlLanguage = IsRtlLanguage;
1747
2750
 
1748
2751
  exports.API_SCOPES = API_SCOPES;
2752
+ exports.BROADCAST_STATUSES = BROADCAST_STATUSES;
2753
+ exports.CONTACT_BLOCK_LISTS = CONTACT_BLOCK_LISTS;
2754
+ exports.CONTACT_PHOTO_TYPES = CONTACT_PHOTO_TYPES;
2755
+ exports.CONTACT_THREAD_SORTS = CONTACT_THREAD_SORTS;
1749
2756
  exports.ERROR_TYPES = ERROR_TYPES;
2757
+ exports.FILE_DIRECTIONS = FILE_DIRECTIONS;
2758
+ exports.FILE_KINDS = FILE_KINDS;
2759
+ exports.FILE_SORTS = FILE_SORTS;
1750
2760
  exports.LANGUAGES = LANGUAGES;
1751
2761
  exports.MESSAGE_ENCRYPTION_FORMATS = MESSAGE_ENCRYPTION_FORMATS;
1752
2762
  exports.OpenEmail = OpenEmail;
1753
2763
  exports.OpenEmailApiError = OpenEmailApiError;
1754
2764
  exports.OpenEmailNetworkError = OpenEmailNetworkError;
1755
2765
  exports.PAGE_LIMITS = PAGE_LIMITS;
2766
+ exports.PEOPLE_SORTS = PEOPLE_SORTS;
2767
+ exports.PROVIDER_IMPORT_DOMAIN_STATES = PROVIDER_IMPORT_DOMAIN_STATES;
2768
+ exports.PROVIDER_IMPORT_RESOURCES = PROVIDER_IMPORT_RESOURCES;
2769
+ exports.PROVIDER_IMPORT_STATUSES = PROVIDER_IMPORT_STATUSES;
1756
2770
  exports.RULE_ACTIONS = RULE_ACTIONS;
1757
2771
  exports.RULE_FIELDS = RULE_FIELDS;
1758
2772
  exports.RULE_OPERATORS = RULE_OPERATORS;
2773
+ exports.SUPPRESSION_REASONS = SUPPRESSION_REASONS;
2774
+ exports.THREAD_SORTS = THREAD_SORTS;
1759
2775
  exports.VERSION = VERSION;
1760
2776
  exports.WEBHOOK_EVENTS = WEBHOOK_EVENTS;
2777
+ exports.WEBHOOK_REPLAY_ERROR_CODES = WEBHOOK_REPLAY_ERROR_CODES;
1761
2778
  exports.WEBHOOK_SIGNATURE_HEADERS = WEBHOOK_SIGNATURE_HEADERS;
1762
2779
  exports.createClient = createClient;
1763
2780
  exports.createOpenEmail = createOpenEmail;