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