@openemail/sdk 0.0.2 → 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.
package/index.cjs CHANGED
@@ -11,7 +11,7 @@ const BROADCAST_STATUSES = {
11
11
  FAILED: 'failed'
12
12
  };
13
13
 
14
- var version = "0.0.2";
14
+ var version = "0.0.3";
15
15
 
16
16
  const BUILD_BASE_URL = 'https://api.openemail.uk';
17
17
 
@@ -19,6 +19,7 @@ const DEFAULTS = {
19
19
  BASE_URL: BUILD_BASE_URL,
20
20
  MAX_RETRIES: 2,
21
21
  TIMEOUT_MS: 30_000,
22
+ UPLOAD_TIMEOUT_MS: 600_000,
22
23
  USER_AGENT: `openemail-sdk/${version}`
23
24
  };
24
25
  const BROWSER_REFUSAL = [
@@ -51,6 +52,7 @@ const CLIENT_MESSAGES = {
51
52
  BASE_URL_SHAPE: 'is not a usable base URL. Pass an origin such as "https://api.openemail.uk", or the http origin of a server you run yourself.',
52
53
  NO_FETCH: 'No global fetch is available. Pass one as { fetch }, or run on Node 20+, Bun, Deno, Cloudflare Workers or a browser.',
53
54
  EMPTY_SEGMENT: 'An id must not be empty.',
55
+ FILENAME_REQUIRED: 'A file name is required. Pass it as { filename }, the name the file is stored and downloaded under.',
54
56
  DOT_SEGMENT: 'is not a usable id: a path segment made only of dots is removed by URL parsers, so the request would reach a different endpoint.'
55
57
  };
56
58
 
@@ -132,7 +134,14 @@ const FILE_KINDS = {
132
134
  };
133
135
  const FILE_DIRECTIONS = {
134
136
  INBOUND: 'inbound',
135
- OUTBOUND: 'outbound'
137
+ OUTBOUND: 'outbound',
138
+ UPLOADED: 'uploaded'
139
+ };
140
+ const FILE_USAGES = {
141
+ RECEIVED: 'received',
142
+ SENT: 'sent',
143
+ LINKED: 'linked',
144
+ SCHEDULED: 'scheduled'
136
145
  };
137
146
 
138
147
  const HTTP_METHODS = {
@@ -466,7 +475,8 @@ const QUERY_KEYS = {
466
475
  KEY_IDS: 'keyIds',
467
476
  SINCE: 'since',
468
477
  UNTIL: 'until',
469
- FAILED_ONLY: 'failedOnly'
478
+ FAILED_ONLY: 'failedOnly',
479
+ FILENAME: 'filename'
470
480
  };
471
481
  const LIST_SEPARATOR = ',';
472
482
 
@@ -517,6 +527,8 @@ const PATHS = {
517
527
  MEMBERS_INVITATIONS: '/members/invitations',
518
528
  SUPPRESSIONS: '/suppressions',
519
529
  FILES: '/files',
530
+ FILES_STATS: '/files/stats',
531
+ FILES_BATCH_DELETE: '/files/batch-delete',
520
532
  TEMP_MAIL_DOMAINS: '/temp-mail/domains',
521
533
  TEMP_MAIL_INBOXES: '/temp-mail/inboxes'
522
534
  };
@@ -1148,7 +1160,7 @@ class Transport {
1148
1160
  const repeatable = options.repeatable ?? RETRYABLE_METHODS.has(method);
1149
1161
  let attempt = 0;
1150
1162
  for (;;) {
1151
- const outcome = await this.attempt(url, method, headers, body, options.signal, options.binary === true);
1163
+ const outcome = await this.attempt(url, method, headers, body, options.signal, options.binary === true, options.timeoutMs ?? this.timeoutMs);
1152
1164
  if (outcome instanceof OpenEmailNetworkError) {
1153
1165
  if (options.signal?.aborted || !repeatable || attempt >= this.maxRetries)
1154
1166
  throw outcome;
@@ -1195,13 +1207,13 @@ class Transport {
1195
1207
  headers[HEADER_KEYS.IDEMPOTENCY_KEY] = options.idempotencyKey ?? IdempotencyKey();
1196
1208
  return headers;
1197
1209
  }
1198
- async attempt(url, method, headers, body, signal, binary) {
1199
- const deadline = Deadline(this.timeoutMs, signal);
1210
+ async attempt(url, method, headers, body, signal, binary, timeoutMs) {
1211
+ const deadline = Deadline(timeoutMs, signal);
1200
1212
  const Failure = (error, fallback) => {
1201
1213
  if (signal?.aborted)
1202
1214
  return new OpenEmailNetworkError('Request aborted by the caller.', error);
1203
1215
  if (deadline.timedOut())
1204
- return new OpenEmailNetworkError(`Request timed out after ${this.timeoutMs}ms.`, error, true);
1216
+ return new OpenEmailNetworkError(`Request timed out after ${timeoutMs}ms.`, error, true);
1205
1217
  return new OpenEmailNetworkError(`${fallback}: ${Describe(error)}`, error);
1206
1218
  };
1207
1219
  try {
@@ -1773,11 +1785,28 @@ const ListQuery$6 = (options) => ({
1773
1785
  [QUERY_KEYS.KIND]: options.kind,
1774
1786
  [QUERY_KEYS.SORT]: options.sort
1775
1787
  });
1788
+ const UploadName = (options) => {
1789
+ const filename = typeof options?.filename === 'string' ? options.filename.trim() : '';
1790
+ if (!filename)
1791
+ throw new Error(CLIENT_MESSAGES.FILENAME_REQUIRED);
1792
+ return filename;
1793
+ };
1794
+ const UploadType = (data, options) => {
1795
+ if (options.contentType)
1796
+ return options.contentType;
1797
+ return typeof Blob !== 'undefined' && data instanceof Blob && data.type ? data.type : undefined;
1798
+ };
1799
+ const UploadTimeout = (transport, options) => {
1800
+ if (options.timeoutMs !== undefined)
1801
+ return options.timeoutMs;
1802
+ return transport.timeoutMs > 0 ? Math.max(transport.timeoutMs, DEFAULTS.UPLOAD_TIMEOUT_MS) : transport.timeoutMs;
1803
+ };
1776
1804
  const Files = (transport) => ({
1777
1805
  list: (options = {}) => FetchPage(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1778
1806
  listAll: (options = {}) => CollectAll(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1779
1807
  iterate: (options = {}) => IteratePages(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1780
1808
  get: (id, options = {}) => transport.request(FilePath(id), { signal: options.signal, apiKey: options.apiKey }),
1809
+ stats: (options = {}) => transport.request(PATHS.FILES_STATS, { signal: options.signal, apiKey: options.apiKey }),
1781
1810
  download: (id, options = {}) => transport.request(FileChildPath(id, SEGMENTS.CONTENT), {
1782
1811
  binary: true,
1783
1812
  signal: options.signal,
@@ -1786,10 +1815,25 @@ const Files = (transport) => ({
1786
1815
  listLinks: (id, options = {}) => FetchPage(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1787
1816
  listAllLinks: (id, options = {}) => CollectAll(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1788
1817
  iterateLinks: (id, options = {}) => IteratePages(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1818
+ upload: (data, options) => transport.request(PATHS.FILES, {
1819
+ method: HTTP_METHODS.POST,
1820
+ query: { [QUERY_KEYS.FILENAME]: UploadName(options) },
1821
+ raw: data,
1822
+ contentType: UploadType(data, options),
1823
+ timeoutMs: UploadTimeout(transport, options),
1824
+ signal: options.signal,
1825
+ apiKey: options.apiKey
1826
+ }),
1789
1827
  delete: (id, options = {}) => transport.request(FilePath(id), {
1790
1828
  method: HTTP_METHODS.DELETE,
1791
1829
  signal: options.signal,
1792
1830
  apiKey: options.apiKey
1831
+ }),
1832
+ deleteMany: (ids, options = {}) => transport.request(PATHS.FILES_BATCH_DELETE, {
1833
+ method: HTTP_METHODS.POST,
1834
+ body: { ids },
1835
+ signal: options.signal,
1836
+ apiKey: options.apiKey
1793
1837
  })
1794
1838
  });
1795
1839
 
@@ -2757,6 +2801,7 @@ exports.ERROR_TYPES = ERROR_TYPES;
2757
2801
  exports.FILE_DIRECTIONS = FILE_DIRECTIONS;
2758
2802
  exports.FILE_KINDS = FILE_KINDS;
2759
2803
  exports.FILE_SORTS = FILE_SORTS;
2804
+ exports.FILE_USAGES = FILE_USAGES;
2760
2805
  exports.LANGUAGES = LANGUAGES;
2761
2806
  exports.MESSAGE_ENCRYPTION_FORMATS = MESSAGE_ENCRYPTION_FORMATS;
2762
2807
  exports.OpenEmail = OpenEmail;
package/index.d.cts CHANGED
@@ -132,6 +132,7 @@ type AudienceCreate = {
132
132
  type AudienceGrowthBucket = {
133
133
  bucket: string;
134
134
  added: number;
135
+ unsubscribed: number;
135
136
  };
136
137
 
137
138
  declare const HIT_KINDS: {
@@ -160,15 +161,19 @@ type AudienceGrowthSeries = {
160
161
  name: string;
161
162
  builtin: boolean;
162
163
  total: number;
164
+ subscribed: number;
163
165
  before: number;
164
166
  added: number;
167
+ unsubscribed: number;
165
168
  buckets: Array<AudienceGrowthBucket>;
166
169
  };
167
170
 
168
171
  type AudienceGrowthTotals = {
169
172
  contacts: number;
173
+ subscribed: number;
170
174
  memberships: number;
171
175
  added: number;
176
+ unsubscribed: number;
172
177
  lists: number;
173
178
  busiest: string | null;
174
179
  };
@@ -937,11 +942,14 @@ declare const Files: (transport: Transport) => {
937
942
  listAll: (options?: FileListOptions) => Promise<Array<FileResource>>;
938
943
  iterate: (options?: FileListOptions) => AsyncGenerator<FileResource, void, undefined>;
939
944
  get: (id: string, options?: RequestScope) => Promise<FileResource>;
945
+ stats: (options?: RequestScope) => Promise<FileStatsResource>;
940
946
  download: (id: string, options?: RequestScope) => Promise<Uint8Array>;
941
947
  listLinks: (id: string, options?: ListOptions) => Promise<Page<FileLinkResource>>;
942
948
  listAllLinks: (id: string, options?: ListOptions) => Promise<Array<FileLinkResource>>;
943
949
  iterateLinks: (id: string, options?: ListOptions) => AsyncGenerator<FileLinkResource, void, undefined>;
950
+ upload: (data: RawBody, options: FileUploadOptions) => Promise<FileResource>;
944
951
  delete: (id: string, options?: RequestScope) => Promise<DeletedFileResource>;
952
+ deleteMany: (ids: Array<string>, options?: RequestScope) => Promise<FileBatchDeleteResource>;
945
953
  };
946
954
 
947
955
  declare const Imports: (transport: Transport) => {
@@ -1220,6 +1228,7 @@ type RequestOptions = {
1220
1228
  repeatable?: boolean;
1221
1229
  accept?: string;
1222
1230
  binary?: boolean;
1231
+ timeoutMs?: number;
1223
1232
  };
1224
1233
 
1225
1234
  type SendScope = RequestScope & {
@@ -1572,6 +1581,12 @@ type DeletedFileResource = {
1572
1581
  deleted: true;
1573
1582
  };
1574
1583
 
1584
+ type FileAddressCount = {
1585
+ address: string;
1586
+ files: number;
1587
+ bytes: number;
1588
+ };
1589
+
1575
1590
  declare const FILE_SORTS: {
1576
1591
  readonly NEWEST: "newest";
1577
1592
  readonly OLDEST: "oldest";
@@ -1588,12 +1603,52 @@ declare const FILE_KINDS: {
1588
1603
  declare const FILE_DIRECTIONS: {
1589
1604
  readonly INBOUND: "inbound";
1590
1605
  readonly OUTBOUND: "outbound";
1606
+ readonly UPLOADED: "uploaded";
1607
+ };
1608
+ interface FileUsages {
1609
+ RECEIVED: 'received';
1610
+ SENT: 'sent';
1611
+ LINKED: 'linked';
1612
+ SCHEDULED: 'scheduled';
1613
+ }
1614
+ type FileUsage = FileUsages[keyof FileUsages];
1615
+ declare const FILE_USAGES: FileUsages;
1616
+
1617
+ type FileKept = {
1618
+ id: string;
1619
+ filename: string;
1620
+ usage: FileUsage;
1621
+ reason: string;
1622
+ };
1623
+
1624
+ type FileBatchDeleteResource = {
1625
+ object: 'file_batch_delete';
1626
+ deleted: Array<string>;
1627
+ kept: Array<FileKept>;
1628
+ missing: Array<string>;
1629
+ };
1630
+
1631
+ type FileCount = {
1632
+ files: number;
1633
+ bytes: number;
1634
+ };
1635
+
1636
+ type FileDayCount = {
1637
+ day: string;
1638
+ files: number;
1639
+ bytes: number;
1591
1640
  };
1592
1641
 
1593
1642
  type FileDirection = (typeof FILE_DIRECTIONS)[keyof typeof FILE_DIRECTIONS];
1594
1643
 
1595
1644
  type FileKind = (typeof FILE_KINDS)[keyof typeof FILE_KINDS];
1596
1645
 
1646
+ type FileLinkCount = {
1647
+ shares: number;
1648
+ downloads: number;
1649
+ lastDownloadAt: string | null;
1650
+ };
1651
+
1597
1652
  type FileLinkResource = {
1598
1653
  object: 'file_link';
1599
1654
  id: string;
@@ -1627,9 +1682,35 @@ type FileResource = {
1627
1682
  threadId: string | null;
1628
1683
  messageId: string | null;
1629
1684
  deliveredTo: string | null;
1685
+ usage: FileUsage | null;
1686
+ deletable: boolean;
1630
1687
  createdAt: string;
1631
1688
  };
1632
1689
 
1690
+ type FileTypeCount = {
1691
+ mimeType: string;
1692
+ files: number;
1693
+ bytes: number;
1694
+ };
1695
+
1696
+ type FileStatsResource = {
1697
+ object: 'file_stats';
1698
+ totals: FileCount;
1699
+ received: FileCount;
1700
+ sent: FileCount;
1701
+ uploaded: FileCount;
1702
+ types: Array<FileTypeCount>;
1703
+ byDay: Array<FileDayCount>;
1704
+ addresses: Array<FileAddressCount>;
1705
+ links: FileLinkCount;
1706
+ };
1707
+
1708
+ type FileUploadOptions = RequestScope & {
1709
+ filename: string;
1710
+ contentType?: string;
1711
+ timeoutMs?: number;
1712
+ };
1713
+
1633
1714
  type ImportChunkResource = {
1634
1715
  object: 'import_chunk';
1635
1716
  file: number;
@@ -3326,7 +3407,7 @@ declare class Transport {
3326
3407
  readonly baseUrl: string;
3327
3408
  private readonly fetchImpl;
3328
3409
  private readonly maxRetries;
3329
- private readonly timeoutMs;
3410
+ readonly timeoutMs: number;
3330
3411
  private readonly userAgent;
3331
3412
  private readonly headers;
3332
3413
  constructor(options: TransportOptions & {
@@ -3405,5 +3486,5 @@ declare const resolveLanguage: (input: string | null | undefined) => LanguageRes
3405
3486
  declare const languageByCode: (code: string | null | undefined) => LanguageResource | undefined;
3406
3487
  declare const isRtlLanguage: (code: string | null | undefined) => boolean;
3407
3488
 
3408
- export { API_SCOPES, BROADCAST_STATUSES, CONTACT_BLOCK_LISTS, CONTACT_PHOTO_TYPES, CONTACT_THREAD_SORTS, ERROR_TYPES, FILE_DIRECTIONS, FILE_KINDS, FILE_SORTS, 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 };
3409
- export type { AddressBookPage, AddressBookResource, AddressResource, ApiErrorPayload, ApiErrorProps, ApiKeyActivityListOptions, ApiKeyActivityResource, ApiKeyCreate, ApiKeyEventType, ApiKeyMode, ApiKeyPatch, ApiKeyRequestListOptions, ApiKeyRequestResource, ApiKeyResource, ApiKeyRevoke, ApiKeyStatus, ApiKeyWorkspaceActivityListOptions, ApiKeyWorkspaceRequestListOptions, ApiScope, AttachmentDeliveryMode, AttachmentInput, AttachmentResource, AudienceBatchAddResource, AudienceBatchRemoveResource, AudienceBuiltin, AudienceContactAdd, AudienceContactListOptions, AudienceContactResource, AudienceContactsBatch, AudienceCreate, AudienceGrowthBucket, AudienceGrowthOptions, AudienceGrowthResource, AudienceGrowthSeries, AudienceGrowthTotals, AudienceImport, AudienceImportResource, AudienceImportRow, AudienceListOptions, AudienceMemberResource, AudienceMemberSort, AudiencePatch, AudienceResource, AuditActorKind, AuditActorResource, BatchItemResource, BatchResultResource, BroadcastCounts, BroadcastCreate, BroadcastListOptions, BroadcastPreviewInput, BroadcastPreviewResource, BroadcastResource, BroadcastStatus, BuiltinRole, CalendarAttendeeResource, CalendarEventResource, CalendarOccurrenceResource, CalendarRangeOptions, ClientOptions, ConsolePermission, ContactActivityBucket, ContactActivityOptions, ContactActivityResource, ContactActivityTotals, ContactAudienceResource, ContactAudiencesSet, ContactBatchDeleteResource, ContactBlockList, ContactBlockResource, ContactBlockRule, ContactCreate, ContactDetailResource, ContactListOptions, ContactPatch, ContactPhotoOptions, ContactPhotoType, ContactReplyTime, ContactResource, ContactSave, ContactSource, ContactThreadListOptions, ContactThreadResource, ContactThreadSort, CreatedApiKeyResource, CreatedTempInboxResource, CreatedWebhookResource, DeletedApiKeyResource, DeletedAudienceResource, DeletedContactResource, DeletedDraftResource, DeletedFileResource, DeletedLabelResource, DeletedRoleResource, DeletedRuleResource, DeletedTempInboxResource, DeletedTempMessageResource, DeletedTemplateResource, DeletedTemplateVersionResource, DeletedWebhookResource, DomainDetailResource, DomainPatch, DomainResource, DomainSendingState, DomainStorage, DomainStorageState, DomainTracking, DomainTrackingState, DraftInput, DraftListOptions, DraftResource, DraftSummaryResource, EmailClickedData, EmailDownloadedData, EmailEventResource, EmailListOptions, EmailOpenedData, EmailRecipientResource, EmailResource, EmailSend, EmailSource, EmailStatus, EmailTrackingSummary, EmailTranslate, EmailTranslationResource, EmailTransport, EmptiedAudienceResource, ErrorType, FetchLike, FileDirection, FileKind, FileLinkResource, FileListOptions, FileResource, FileSort, HitKind, ImportChunkResource, ImportCounts, ImportCreate, ImportFailurePage, ImportFailureReason, ImportFailureResource, ImportFailuresOptions, ImportFileDescriptor, ImportFileInfo, ImportFilesInput, ImportFormat, ImportListOptions, ImportOptions, ImportProgress, ImportResource, ImportSource, ImportStatus, ImportUploadResource, InboxScope, InlineAttachmentInput, InvitationResource, KeyResource, LabelColor, LabelColorInput, LabelColorKind, LabelColorResource, LabelInput, LabelPatch, LabelResource, LanguageResource, ListOptions, LogWindow, MemberAccess, MemberAdd, MemberAddressGrant, MemberAddressResource, MemberDomainResource, MemberPatch, MemberResource, MessageEncryption, MessageEncryptionFormat, MessageEncryptionPartRole, MessageResource, Page, PeoplePage, PeopleSort, Permission, PermissionResource, PersonListOptions, PersonResource, PingResource, ProviderImportCount, ProviderImportCreate, ProviderImportDomainState, ProviderImportListOptions, ProviderImportReport, ProviderImportResource, ProviderImportResourceKind, ProviderImportStatus, ProviderInventoryResource, RawBody, RecipientInput, RecipientKind, RecipientStatus, RemovedAudienceContactResource, RemovedMemberResource, RemovedSuppressionResource, RequestOptions, RequestScope, RevokedInvitationResource, RoleCreate, RoleDeleteOptions, RolePatch, RoleResource, RotatedApiKeyResource, RotatedKeyResource, RuleAction, RuleActionType, RuleCondition, RuleConditionInput, RuleCreate, RuleField, RuleListOptions, RuleMatchMode, RuleOperator, RulePatch, RuleResource, RuleRunListOptions, RuleRunResource, RuleTestInput, RuleTestResource, RuleTestWarningCode, SavedDraftResource, SendScope, SendTranslateOptions, SendableDomainResource, SentBroadcastResource, SentEmailResource, SentTemplateEmailResource, SettingsOptions, SettingsPatch, SettingsResource, SnoozedThreadResource, StoredAttachmentInput, SuppressionAdd, SuppressionListOptions, SuppressionReason, SuppressionResource, TempDomainResource, TempInboxCreate, TempInboxResource, TempMailOptions, TempMessageDetailResource, TempMessageListOptions, TempMessageResource, TempMessagesResource, TemplateAnalyticsOptions, TemplateAnalyticsResource, TemplateBlock, TemplateBlockKind, TemplateCategory, TemplateContent, TemplateContentSource, TemplateCreate, TemplateDetailResource, TemplateDocument, TemplateDuplicate, TemplateEngine, TemplateFont, TemplateFontFormat, TemplateFontResource, TemplateFontStyle, TemplateListOptions, TemplatePatch, TemplatePreviewInput, TemplatePreviewResource, TemplatePreviewWarningCode, TemplateProp, TemplateRenderInput, TemplateRenderResource, TemplateResource, TemplateRestoreInput, TemplateRestoredResource, TemplateSend, TemplateSendListOptions, TemplateSendResource, TemplateSendsResource, TemplateSlot, TemplateSort, TemplateStarterDetailResource, TemplateStarterResource, TemplateStatus, TemplateValueKind, TemplateVersionResource, TemplateVersionState, ThreadListOptions, ThreadPatch, ThreadResource, ThreadSort, ThreadSummaryResource, TrackingClickResource, TrackingGrain, TrackingHitOptions, TrackingLinkResource, TrackingListOptions, TrackingOpenResource, TrackingRecipientResource, TrackingRequest, TrackingResource, TrackingStatsOptions, TrackingStatsResource, TrackingSummary, TranslateOptions, TranslationResource, TransportOptions, TrashedThreadResource, UpdatedThreadResource, VerifyWebhookProps, WebhookActivityListOptions, WebhookActivityResource, WebhookChangeType, WebhookCreate, WebhookDeliveryAttempt, WebhookDeliveryDetailResource, WebhookDeliveryListOptions, WebhookDeliveryResource, WebhookDeliveryStatus, WebhookEvent, WebhookPatch, WebhookPayload, WebhookReplayErrorCode, WebhookReplayRefusal, WebhookReplayResource, WebhookResource, WebhookSignatureHeaders, WebhookTestResource, WebhookWorkspaceActivityListOptions, WebhookWorkspaceDeliveryListOptions };
3489
+ 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 };
3490
+ export type { AddressBookPage, AddressBookResource, AddressResource, ApiErrorPayload, ApiErrorProps, ApiKeyActivityListOptions, ApiKeyActivityResource, ApiKeyCreate, ApiKeyEventType, ApiKeyMode, ApiKeyPatch, ApiKeyRequestListOptions, ApiKeyRequestResource, ApiKeyResource, ApiKeyRevoke, ApiKeyStatus, ApiKeyWorkspaceActivityListOptions, ApiKeyWorkspaceRequestListOptions, ApiScope, AttachmentDeliveryMode, AttachmentInput, AttachmentResource, AudienceBatchAddResource, AudienceBatchRemoveResource, AudienceBuiltin, AudienceContactAdd, AudienceContactListOptions, AudienceContactResource, AudienceContactsBatch, AudienceCreate, AudienceGrowthBucket, AudienceGrowthOptions, AudienceGrowthResource, AudienceGrowthSeries, AudienceGrowthTotals, AudienceImport, AudienceImportResource, AudienceImportRow, AudienceListOptions, AudienceMemberResource, AudienceMemberSort, AudiencePatch, AudienceResource, AuditActorKind, AuditActorResource, BatchItemResource, BatchResultResource, BroadcastCounts, BroadcastCreate, BroadcastListOptions, BroadcastPreviewInput, BroadcastPreviewResource, BroadcastResource, BroadcastStatus, BuiltinRole, CalendarAttendeeResource, CalendarEventResource, CalendarOccurrenceResource, CalendarRangeOptions, ClientOptions, ConsolePermission, ContactActivityBucket, ContactActivityOptions, ContactActivityResource, ContactActivityTotals, ContactAudienceResource, ContactAudiencesSet, ContactBatchDeleteResource, ContactBlockList, ContactBlockResource, ContactBlockRule, ContactCreate, ContactDetailResource, ContactListOptions, ContactPatch, ContactPhotoOptions, ContactPhotoType, ContactReplyTime, ContactResource, ContactSave, ContactSource, ContactThreadListOptions, ContactThreadResource, ContactThreadSort, CreatedApiKeyResource, CreatedTempInboxResource, CreatedWebhookResource, DeletedApiKeyResource, DeletedAudienceResource, DeletedContactResource, DeletedDraftResource, DeletedFileResource, DeletedLabelResource, DeletedRoleResource, DeletedRuleResource, DeletedTempInboxResource, DeletedTempMessageResource, DeletedTemplateResource, DeletedTemplateVersionResource, DeletedWebhookResource, DomainDetailResource, DomainPatch, DomainResource, DomainSendingState, DomainStorage, DomainStorageState, DomainTracking, DomainTrackingState, DraftInput, DraftListOptions, DraftResource, DraftSummaryResource, EmailClickedData, EmailDownloadedData, EmailEventResource, EmailListOptions, EmailOpenedData, EmailRecipientResource, EmailResource, EmailSend, EmailSource, EmailStatus, EmailTrackingSummary, EmailTranslate, EmailTranslationResource, EmailTransport, EmptiedAudienceResource, ErrorType, FetchLike, FileAddressCount, FileBatchDeleteResource, FileCount, FileDayCount, FileDirection, FileKept, FileKind, FileLinkCount, FileLinkResource, FileListOptions, FileResource, FileSort, FileStatsResource, FileTypeCount, FileUploadOptions, FileUsage, HitKind, ImportChunkResource, ImportCounts, ImportCreate, ImportFailurePage, ImportFailureReason, ImportFailureResource, ImportFailuresOptions, ImportFileDescriptor, ImportFileInfo, ImportFilesInput, ImportFormat, ImportListOptions, ImportOptions, ImportProgress, ImportResource, ImportSource, ImportStatus, ImportUploadResource, InboxScope, InlineAttachmentInput, InvitationResource, KeyResource, LabelColor, LabelColorInput, LabelColorKind, LabelColorResource, LabelInput, LabelPatch, LabelResource, LanguageResource, ListOptions, LogWindow, MemberAccess, MemberAdd, MemberAddressGrant, MemberAddressResource, MemberDomainResource, MemberPatch, MemberResource, MessageEncryption, MessageEncryptionFormat, MessageEncryptionPartRole, MessageResource, Page, PeoplePage, PeopleSort, Permission, PermissionResource, PersonListOptions, PersonResource, PingResource, ProviderImportCount, ProviderImportCreate, ProviderImportDomainState, ProviderImportListOptions, ProviderImportReport, ProviderImportResource, ProviderImportResourceKind, ProviderImportStatus, ProviderInventoryResource, RawBody, RecipientInput, RecipientKind, RecipientStatus, RemovedAudienceContactResource, RemovedMemberResource, RemovedSuppressionResource, RequestOptions, RequestScope, RevokedInvitationResource, RoleCreate, RoleDeleteOptions, RolePatch, RoleResource, RotatedApiKeyResource, RotatedKeyResource, RuleAction, RuleActionType, RuleCondition, RuleConditionInput, RuleCreate, RuleField, RuleListOptions, RuleMatchMode, RuleOperator, RulePatch, RuleResource, RuleRunListOptions, RuleRunResource, RuleTestInput, RuleTestResource, RuleTestWarningCode, SavedDraftResource, SendScope, SendTranslateOptions, SendableDomainResource, SentBroadcastResource, SentEmailResource, SentTemplateEmailResource, SettingsOptions, SettingsPatch, SettingsResource, SnoozedThreadResource, StoredAttachmentInput, SuppressionAdd, SuppressionListOptions, SuppressionReason, SuppressionResource, TempDomainResource, TempInboxCreate, TempInboxResource, TempMailOptions, TempMessageDetailResource, TempMessageListOptions, TempMessageResource, TempMessagesResource, TemplateAnalyticsOptions, TemplateAnalyticsResource, TemplateBlock, TemplateBlockKind, TemplateCategory, TemplateContent, TemplateContentSource, TemplateCreate, TemplateDetailResource, TemplateDocument, TemplateDuplicate, TemplateEngine, TemplateFont, TemplateFontFormat, TemplateFontResource, TemplateFontStyle, TemplateListOptions, TemplatePatch, TemplatePreviewInput, TemplatePreviewResource, TemplatePreviewWarningCode, TemplateProp, TemplateRenderInput, TemplateRenderResource, TemplateResource, TemplateRestoreInput, TemplateRestoredResource, TemplateSend, TemplateSendListOptions, TemplateSendResource, TemplateSendsResource, TemplateSlot, TemplateSort, TemplateStarterDetailResource, TemplateStarterResource, TemplateStatus, TemplateValueKind, TemplateVersionResource, TemplateVersionState, ThreadListOptions, ThreadPatch, ThreadResource, ThreadSort, ThreadSummaryResource, TrackingClickResource, TrackingGrain, TrackingHitOptions, TrackingLinkResource, TrackingListOptions, TrackingOpenResource, TrackingRecipientResource, TrackingRequest, TrackingResource, TrackingStatsOptions, TrackingStatsResource, TrackingSummary, TranslateOptions, TranslationResource, TransportOptions, TrashedThreadResource, UpdatedThreadResource, VerifyWebhookProps, WebhookActivityListOptions, WebhookActivityResource, WebhookChangeType, WebhookCreate, WebhookDeliveryAttempt, WebhookDeliveryDetailResource, WebhookDeliveryListOptions, WebhookDeliveryResource, WebhookDeliveryStatus, WebhookEvent, WebhookPatch, WebhookPayload, WebhookReplayErrorCode, WebhookReplayRefusal, WebhookReplayResource, WebhookResource, WebhookSignatureHeaders, WebhookTestResource, WebhookWorkspaceActivityListOptions, WebhookWorkspaceDeliveryListOptions };
package/index.d.ts CHANGED
@@ -132,6 +132,7 @@ type AudienceCreate = {
132
132
  type AudienceGrowthBucket = {
133
133
  bucket: string;
134
134
  added: number;
135
+ unsubscribed: number;
135
136
  };
136
137
 
137
138
  declare const HIT_KINDS: {
@@ -160,15 +161,19 @@ type AudienceGrowthSeries = {
160
161
  name: string;
161
162
  builtin: boolean;
162
163
  total: number;
164
+ subscribed: number;
163
165
  before: number;
164
166
  added: number;
167
+ unsubscribed: number;
165
168
  buckets: Array<AudienceGrowthBucket>;
166
169
  };
167
170
 
168
171
  type AudienceGrowthTotals = {
169
172
  contacts: number;
173
+ subscribed: number;
170
174
  memberships: number;
171
175
  added: number;
176
+ unsubscribed: number;
172
177
  lists: number;
173
178
  busiest: string | null;
174
179
  };
@@ -937,11 +942,14 @@ declare const Files: (transport: Transport) => {
937
942
  listAll: (options?: FileListOptions) => Promise<Array<FileResource>>;
938
943
  iterate: (options?: FileListOptions) => AsyncGenerator<FileResource, void, undefined>;
939
944
  get: (id: string, options?: RequestScope) => Promise<FileResource>;
945
+ stats: (options?: RequestScope) => Promise<FileStatsResource>;
940
946
  download: (id: string, options?: RequestScope) => Promise<Uint8Array>;
941
947
  listLinks: (id: string, options?: ListOptions) => Promise<Page<FileLinkResource>>;
942
948
  listAllLinks: (id: string, options?: ListOptions) => Promise<Array<FileLinkResource>>;
943
949
  iterateLinks: (id: string, options?: ListOptions) => AsyncGenerator<FileLinkResource, void, undefined>;
950
+ upload: (data: RawBody, options: FileUploadOptions) => Promise<FileResource>;
944
951
  delete: (id: string, options?: RequestScope) => Promise<DeletedFileResource>;
952
+ deleteMany: (ids: Array<string>, options?: RequestScope) => Promise<FileBatchDeleteResource>;
945
953
  };
946
954
 
947
955
  declare const Imports: (transport: Transport) => {
@@ -1220,6 +1228,7 @@ type RequestOptions = {
1220
1228
  repeatable?: boolean;
1221
1229
  accept?: string;
1222
1230
  binary?: boolean;
1231
+ timeoutMs?: number;
1223
1232
  };
1224
1233
 
1225
1234
  type SendScope = RequestScope & {
@@ -1572,6 +1581,12 @@ type DeletedFileResource = {
1572
1581
  deleted: true;
1573
1582
  };
1574
1583
 
1584
+ type FileAddressCount = {
1585
+ address: string;
1586
+ files: number;
1587
+ bytes: number;
1588
+ };
1589
+
1575
1590
  declare const FILE_SORTS: {
1576
1591
  readonly NEWEST: "newest";
1577
1592
  readonly OLDEST: "oldest";
@@ -1588,12 +1603,52 @@ declare const FILE_KINDS: {
1588
1603
  declare const FILE_DIRECTIONS: {
1589
1604
  readonly INBOUND: "inbound";
1590
1605
  readonly OUTBOUND: "outbound";
1606
+ readonly UPLOADED: "uploaded";
1607
+ };
1608
+ interface FileUsages {
1609
+ RECEIVED: 'received';
1610
+ SENT: 'sent';
1611
+ LINKED: 'linked';
1612
+ SCHEDULED: 'scheduled';
1613
+ }
1614
+ type FileUsage = FileUsages[keyof FileUsages];
1615
+ declare const FILE_USAGES: FileUsages;
1616
+
1617
+ type FileKept = {
1618
+ id: string;
1619
+ filename: string;
1620
+ usage: FileUsage;
1621
+ reason: string;
1622
+ };
1623
+
1624
+ type FileBatchDeleteResource = {
1625
+ object: 'file_batch_delete';
1626
+ deleted: Array<string>;
1627
+ kept: Array<FileKept>;
1628
+ missing: Array<string>;
1629
+ };
1630
+
1631
+ type FileCount = {
1632
+ files: number;
1633
+ bytes: number;
1634
+ };
1635
+
1636
+ type FileDayCount = {
1637
+ day: string;
1638
+ files: number;
1639
+ bytes: number;
1591
1640
  };
1592
1641
 
1593
1642
  type FileDirection = (typeof FILE_DIRECTIONS)[keyof typeof FILE_DIRECTIONS];
1594
1643
 
1595
1644
  type FileKind = (typeof FILE_KINDS)[keyof typeof FILE_KINDS];
1596
1645
 
1646
+ type FileLinkCount = {
1647
+ shares: number;
1648
+ downloads: number;
1649
+ lastDownloadAt: string | null;
1650
+ };
1651
+
1597
1652
  type FileLinkResource = {
1598
1653
  object: 'file_link';
1599
1654
  id: string;
@@ -1627,9 +1682,35 @@ type FileResource = {
1627
1682
  threadId: string | null;
1628
1683
  messageId: string | null;
1629
1684
  deliveredTo: string | null;
1685
+ usage: FileUsage | null;
1686
+ deletable: boolean;
1630
1687
  createdAt: string;
1631
1688
  };
1632
1689
 
1690
+ type FileTypeCount = {
1691
+ mimeType: string;
1692
+ files: number;
1693
+ bytes: number;
1694
+ };
1695
+
1696
+ type FileStatsResource = {
1697
+ object: 'file_stats';
1698
+ totals: FileCount;
1699
+ received: FileCount;
1700
+ sent: FileCount;
1701
+ uploaded: FileCount;
1702
+ types: Array<FileTypeCount>;
1703
+ byDay: Array<FileDayCount>;
1704
+ addresses: Array<FileAddressCount>;
1705
+ links: FileLinkCount;
1706
+ };
1707
+
1708
+ type FileUploadOptions = RequestScope & {
1709
+ filename: string;
1710
+ contentType?: string;
1711
+ timeoutMs?: number;
1712
+ };
1713
+
1633
1714
  type ImportChunkResource = {
1634
1715
  object: 'import_chunk';
1635
1716
  file: number;
@@ -3326,7 +3407,7 @@ declare class Transport {
3326
3407
  readonly baseUrl: string;
3327
3408
  private readonly fetchImpl;
3328
3409
  private readonly maxRetries;
3329
- private readonly timeoutMs;
3410
+ readonly timeoutMs: number;
3330
3411
  private readonly userAgent;
3331
3412
  private readonly headers;
3332
3413
  constructor(options: TransportOptions & {
@@ -3405,5 +3486,5 @@ declare const resolveLanguage: (input: string | null | undefined) => LanguageRes
3405
3486
  declare const languageByCode: (code: string | null | undefined) => LanguageResource | undefined;
3406
3487
  declare const isRtlLanguage: (code: string | null | undefined) => boolean;
3407
3488
 
3408
- export { API_SCOPES, BROADCAST_STATUSES, CONTACT_BLOCK_LISTS, CONTACT_PHOTO_TYPES, CONTACT_THREAD_SORTS, ERROR_TYPES, FILE_DIRECTIONS, FILE_KINDS, FILE_SORTS, 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 };
3409
- export type { AddressBookPage, AddressBookResource, AddressResource, ApiErrorPayload, ApiErrorProps, ApiKeyActivityListOptions, ApiKeyActivityResource, ApiKeyCreate, ApiKeyEventType, ApiKeyMode, ApiKeyPatch, ApiKeyRequestListOptions, ApiKeyRequestResource, ApiKeyResource, ApiKeyRevoke, ApiKeyStatus, ApiKeyWorkspaceActivityListOptions, ApiKeyWorkspaceRequestListOptions, ApiScope, AttachmentDeliveryMode, AttachmentInput, AttachmentResource, AudienceBatchAddResource, AudienceBatchRemoveResource, AudienceBuiltin, AudienceContactAdd, AudienceContactListOptions, AudienceContactResource, AudienceContactsBatch, AudienceCreate, AudienceGrowthBucket, AudienceGrowthOptions, AudienceGrowthResource, AudienceGrowthSeries, AudienceGrowthTotals, AudienceImport, AudienceImportResource, AudienceImportRow, AudienceListOptions, AudienceMemberResource, AudienceMemberSort, AudiencePatch, AudienceResource, AuditActorKind, AuditActorResource, BatchItemResource, BatchResultResource, BroadcastCounts, BroadcastCreate, BroadcastListOptions, BroadcastPreviewInput, BroadcastPreviewResource, BroadcastResource, BroadcastStatus, BuiltinRole, CalendarAttendeeResource, CalendarEventResource, CalendarOccurrenceResource, CalendarRangeOptions, ClientOptions, ConsolePermission, ContactActivityBucket, ContactActivityOptions, ContactActivityResource, ContactActivityTotals, ContactAudienceResource, ContactAudiencesSet, ContactBatchDeleteResource, ContactBlockList, ContactBlockResource, ContactBlockRule, ContactCreate, ContactDetailResource, ContactListOptions, ContactPatch, ContactPhotoOptions, ContactPhotoType, ContactReplyTime, ContactResource, ContactSave, ContactSource, ContactThreadListOptions, ContactThreadResource, ContactThreadSort, CreatedApiKeyResource, CreatedTempInboxResource, CreatedWebhookResource, DeletedApiKeyResource, DeletedAudienceResource, DeletedContactResource, DeletedDraftResource, DeletedFileResource, DeletedLabelResource, DeletedRoleResource, DeletedRuleResource, DeletedTempInboxResource, DeletedTempMessageResource, DeletedTemplateResource, DeletedTemplateVersionResource, DeletedWebhookResource, DomainDetailResource, DomainPatch, DomainResource, DomainSendingState, DomainStorage, DomainStorageState, DomainTracking, DomainTrackingState, DraftInput, DraftListOptions, DraftResource, DraftSummaryResource, EmailClickedData, EmailDownloadedData, EmailEventResource, EmailListOptions, EmailOpenedData, EmailRecipientResource, EmailResource, EmailSend, EmailSource, EmailStatus, EmailTrackingSummary, EmailTranslate, EmailTranslationResource, EmailTransport, EmptiedAudienceResource, ErrorType, FetchLike, FileDirection, FileKind, FileLinkResource, FileListOptions, FileResource, FileSort, HitKind, ImportChunkResource, ImportCounts, ImportCreate, ImportFailurePage, ImportFailureReason, ImportFailureResource, ImportFailuresOptions, ImportFileDescriptor, ImportFileInfo, ImportFilesInput, ImportFormat, ImportListOptions, ImportOptions, ImportProgress, ImportResource, ImportSource, ImportStatus, ImportUploadResource, InboxScope, InlineAttachmentInput, InvitationResource, KeyResource, LabelColor, LabelColorInput, LabelColorKind, LabelColorResource, LabelInput, LabelPatch, LabelResource, LanguageResource, ListOptions, LogWindow, MemberAccess, MemberAdd, MemberAddressGrant, MemberAddressResource, MemberDomainResource, MemberPatch, MemberResource, MessageEncryption, MessageEncryptionFormat, MessageEncryptionPartRole, MessageResource, Page, PeoplePage, PeopleSort, Permission, PermissionResource, PersonListOptions, PersonResource, PingResource, ProviderImportCount, ProviderImportCreate, ProviderImportDomainState, ProviderImportListOptions, ProviderImportReport, ProviderImportResource, ProviderImportResourceKind, ProviderImportStatus, ProviderInventoryResource, RawBody, RecipientInput, RecipientKind, RecipientStatus, RemovedAudienceContactResource, RemovedMemberResource, RemovedSuppressionResource, RequestOptions, RequestScope, RevokedInvitationResource, RoleCreate, RoleDeleteOptions, RolePatch, RoleResource, RotatedApiKeyResource, RotatedKeyResource, RuleAction, RuleActionType, RuleCondition, RuleConditionInput, RuleCreate, RuleField, RuleListOptions, RuleMatchMode, RuleOperator, RulePatch, RuleResource, RuleRunListOptions, RuleRunResource, RuleTestInput, RuleTestResource, RuleTestWarningCode, SavedDraftResource, SendScope, SendTranslateOptions, SendableDomainResource, SentBroadcastResource, SentEmailResource, SentTemplateEmailResource, SettingsOptions, SettingsPatch, SettingsResource, SnoozedThreadResource, StoredAttachmentInput, SuppressionAdd, SuppressionListOptions, SuppressionReason, SuppressionResource, TempDomainResource, TempInboxCreate, TempInboxResource, TempMailOptions, TempMessageDetailResource, TempMessageListOptions, TempMessageResource, TempMessagesResource, TemplateAnalyticsOptions, TemplateAnalyticsResource, TemplateBlock, TemplateBlockKind, TemplateCategory, TemplateContent, TemplateContentSource, TemplateCreate, TemplateDetailResource, TemplateDocument, TemplateDuplicate, TemplateEngine, TemplateFont, TemplateFontFormat, TemplateFontResource, TemplateFontStyle, TemplateListOptions, TemplatePatch, TemplatePreviewInput, TemplatePreviewResource, TemplatePreviewWarningCode, TemplateProp, TemplateRenderInput, TemplateRenderResource, TemplateResource, TemplateRestoreInput, TemplateRestoredResource, TemplateSend, TemplateSendListOptions, TemplateSendResource, TemplateSendsResource, TemplateSlot, TemplateSort, TemplateStarterDetailResource, TemplateStarterResource, TemplateStatus, TemplateValueKind, TemplateVersionResource, TemplateVersionState, ThreadListOptions, ThreadPatch, ThreadResource, ThreadSort, ThreadSummaryResource, TrackingClickResource, TrackingGrain, TrackingHitOptions, TrackingLinkResource, TrackingListOptions, TrackingOpenResource, TrackingRecipientResource, TrackingRequest, TrackingResource, TrackingStatsOptions, TrackingStatsResource, TrackingSummary, TranslateOptions, TranslationResource, TransportOptions, TrashedThreadResource, UpdatedThreadResource, VerifyWebhookProps, WebhookActivityListOptions, WebhookActivityResource, WebhookChangeType, WebhookCreate, WebhookDeliveryAttempt, WebhookDeliveryDetailResource, WebhookDeliveryListOptions, WebhookDeliveryResource, WebhookDeliveryStatus, WebhookEvent, WebhookPatch, WebhookPayload, WebhookReplayErrorCode, WebhookReplayRefusal, WebhookReplayResource, WebhookResource, WebhookSignatureHeaders, WebhookTestResource, WebhookWorkspaceActivityListOptions, WebhookWorkspaceDeliveryListOptions };
3489
+ 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 };
3490
+ export type { AddressBookPage, AddressBookResource, AddressResource, ApiErrorPayload, ApiErrorProps, ApiKeyActivityListOptions, ApiKeyActivityResource, ApiKeyCreate, ApiKeyEventType, ApiKeyMode, ApiKeyPatch, ApiKeyRequestListOptions, ApiKeyRequestResource, ApiKeyResource, ApiKeyRevoke, ApiKeyStatus, ApiKeyWorkspaceActivityListOptions, ApiKeyWorkspaceRequestListOptions, ApiScope, AttachmentDeliveryMode, AttachmentInput, AttachmentResource, AudienceBatchAddResource, AudienceBatchRemoveResource, AudienceBuiltin, AudienceContactAdd, AudienceContactListOptions, AudienceContactResource, AudienceContactsBatch, AudienceCreate, AudienceGrowthBucket, AudienceGrowthOptions, AudienceGrowthResource, AudienceGrowthSeries, AudienceGrowthTotals, AudienceImport, AudienceImportResource, AudienceImportRow, AudienceListOptions, AudienceMemberResource, AudienceMemberSort, AudiencePatch, AudienceResource, AuditActorKind, AuditActorResource, BatchItemResource, BatchResultResource, BroadcastCounts, BroadcastCreate, BroadcastListOptions, BroadcastPreviewInput, BroadcastPreviewResource, BroadcastResource, BroadcastStatus, BuiltinRole, CalendarAttendeeResource, CalendarEventResource, CalendarOccurrenceResource, CalendarRangeOptions, ClientOptions, ConsolePermission, ContactActivityBucket, ContactActivityOptions, ContactActivityResource, ContactActivityTotals, ContactAudienceResource, ContactAudiencesSet, ContactBatchDeleteResource, ContactBlockList, ContactBlockResource, ContactBlockRule, ContactCreate, ContactDetailResource, ContactListOptions, ContactPatch, ContactPhotoOptions, ContactPhotoType, ContactReplyTime, ContactResource, ContactSave, ContactSource, ContactThreadListOptions, ContactThreadResource, ContactThreadSort, CreatedApiKeyResource, CreatedTempInboxResource, CreatedWebhookResource, DeletedApiKeyResource, DeletedAudienceResource, DeletedContactResource, DeletedDraftResource, DeletedFileResource, DeletedLabelResource, DeletedRoleResource, DeletedRuleResource, DeletedTempInboxResource, DeletedTempMessageResource, DeletedTemplateResource, DeletedTemplateVersionResource, DeletedWebhookResource, DomainDetailResource, DomainPatch, DomainResource, DomainSendingState, DomainStorage, DomainStorageState, DomainTracking, DomainTrackingState, DraftInput, DraftListOptions, DraftResource, DraftSummaryResource, EmailClickedData, EmailDownloadedData, EmailEventResource, EmailListOptions, EmailOpenedData, EmailRecipientResource, EmailResource, EmailSend, EmailSource, EmailStatus, EmailTrackingSummary, EmailTranslate, EmailTranslationResource, EmailTransport, EmptiedAudienceResource, ErrorType, FetchLike, FileAddressCount, FileBatchDeleteResource, FileCount, FileDayCount, FileDirection, FileKept, FileKind, FileLinkCount, FileLinkResource, FileListOptions, FileResource, FileSort, FileStatsResource, FileTypeCount, FileUploadOptions, FileUsage, HitKind, ImportChunkResource, ImportCounts, ImportCreate, ImportFailurePage, ImportFailureReason, ImportFailureResource, ImportFailuresOptions, ImportFileDescriptor, ImportFileInfo, ImportFilesInput, ImportFormat, ImportListOptions, ImportOptions, ImportProgress, ImportResource, ImportSource, ImportStatus, ImportUploadResource, InboxScope, InlineAttachmentInput, InvitationResource, KeyResource, LabelColor, LabelColorInput, LabelColorKind, LabelColorResource, LabelInput, LabelPatch, LabelResource, LanguageResource, ListOptions, LogWindow, MemberAccess, MemberAdd, MemberAddressGrant, MemberAddressResource, MemberDomainResource, MemberPatch, MemberResource, MessageEncryption, MessageEncryptionFormat, MessageEncryptionPartRole, MessageResource, Page, PeoplePage, PeopleSort, Permission, PermissionResource, PersonListOptions, PersonResource, PingResource, ProviderImportCount, ProviderImportCreate, ProviderImportDomainState, ProviderImportListOptions, ProviderImportReport, ProviderImportResource, ProviderImportResourceKind, ProviderImportStatus, ProviderInventoryResource, RawBody, RecipientInput, RecipientKind, RecipientStatus, RemovedAudienceContactResource, RemovedMemberResource, RemovedSuppressionResource, RequestOptions, RequestScope, RevokedInvitationResource, RoleCreate, RoleDeleteOptions, RolePatch, RoleResource, RotatedApiKeyResource, RotatedKeyResource, RuleAction, RuleActionType, RuleCondition, RuleConditionInput, RuleCreate, RuleField, RuleListOptions, RuleMatchMode, RuleOperator, RulePatch, RuleResource, RuleRunListOptions, RuleRunResource, RuleTestInput, RuleTestResource, RuleTestWarningCode, SavedDraftResource, SendScope, SendTranslateOptions, SendableDomainResource, SentBroadcastResource, SentEmailResource, SentTemplateEmailResource, SettingsOptions, SettingsPatch, SettingsResource, SnoozedThreadResource, StoredAttachmentInput, SuppressionAdd, SuppressionListOptions, SuppressionReason, SuppressionResource, TempDomainResource, TempInboxCreate, TempInboxResource, TempMailOptions, TempMessageDetailResource, TempMessageListOptions, TempMessageResource, TempMessagesResource, TemplateAnalyticsOptions, TemplateAnalyticsResource, TemplateBlock, TemplateBlockKind, TemplateCategory, TemplateContent, TemplateContentSource, TemplateCreate, TemplateDetailResource, TemplateDocument, TemplateDuplicate, TemplateEngine, TemplateFont, TemplateFontFormat, TemplateFontResource, TemplateFontStyle, TemplateListOptions, TemplatePatch, TemplatePreviewInput, TemplatePreviewResource, TemplatePreviewWarningCode, TemplateProp, TemplateRenderInput, TemplateRenderResource, TemplateResource, TemplateRestoreInput, TemplateRestoredResource, TemplateSend, TemplateSendListOptions, TemplateSendResource, TemplateSendsResource, TemplateSlot, TemplateSort, TemplateStarterDetailResource, TemplateStarterResource, TemplateStatus, TemplateValueKind, TemplateVersionResource, TemplateVersionState, ThreadListOptions, ThreadPatch, ThreadResource, ThreadSort, ThreadSummaryResource, TrackingClickResource, TrackingGrain, TrackingHitOptions, TrackingLinkResource, TrackingListOptions, TrackingOpenResource, TrackingRecipientResource, TrackingRequest, TrackingResource, TrackingStatsOptions, TrackingStatsResource, TrackingSummary, TranslateOptions, TranslationResource, TransportOptions, TrashedThreadResource, UpdatedThreadResource, VerifyWebhookProps, WebhookActivityListOptions, WebhookActivityResource, WebhookChangeType, WebhookCreate, WebhookDeliveryAttempt, WebhookDeliveryDetailResource, WebhookDeliveryListOptions, WebhookDeliveryResource, WebhookDeliveryStatus, WebhookEvent, WebhookPatch, WebhookPayload, WebhookReplayErrorCode, WebhookReplayRefusal, WebhookReplayResource, WebhookResource, WebhookSignatureHeaders, WebhookTestResource, WebhookWorkspaceActivityListOptions, WebhookWorkspaceDeliveryListOptions };
package/index.js CHANGED
@@ -7,7 +7,7 @@ const BROADCAST_STATUSES = {
7
7
  FAILED: 'failed'
8
8
  };
9
9
 
10
- var version = "0.0.2";
10
+ var version = "0.0.3";
11
11
 
12
12
  const BUILD_BASE_URL = 'https://api.openemail.uk';
13
13
 
@@ -15,6 +15,7 @@ const DEFAULTS = {
15
15
  BASE_URL: BUILD_BASE_URL,
16
16
  MAX_RETRIES: 2,
17
17
  TIMEOUT_MS: 30_000,
18
+ UPLOAD_TIMEOUT_MS: 600_000,
18
19
  USER_AGENT: `openemail-sdk/${version}`
19
20
  };
20
21
  const BROWSER_REFUSAL = [
@@ -47,6 +48,7 @@ const CLIENT_MESSAGES = {
47
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.',
48
49
  NO_FETCH: 'No global fetch is available. Pass one as { fetch }, or run on Node 20+, Bun, Deno, Cloudflare Workers or a browser.',
49
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.',
50
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.'
51
53
  };
52
54
 
@@ -128,7 +130,14 @@ const FILE_KINDS = {
128
130
  };
129
131
  const FILE_DIRECTIONS = {
130
132
  INBOUND: 'inbound',
131
- OUTBOUND: 'outbound'
133
+ OUTBOUND: 'outbound',
134
+ UPLOADED: 'uploaded'
135
+ };
136
+ const FILE_USAGES = {
137
+ RECEIVED: 'received',
138
+ SENT: 'sent',
139
+ LINKED: 'linked',
140
+ SCHEDULED: 'scheduled'
132
141
  };
133
142
 
134
143
  const HTTP_METHODS = {
@@ -462,7 +471,8 @@ const QUERY_KEYS = {
462
471
  KEY_IDS: 'keyIds',
463
472
  SINCE: 'since',
464
473
  UNTIL: 'until',
465
- FAILED_ONLY: 'failedOnly'
474
+ FAILED_ONLY: 'failedOnly',
475
+ FILENAME: 'filename'
466
476
  };
467
477
  const LIST_SEPARATOR = ',';
468
478
 
@@ -513,6 +523,8 @@ const PATHS = {
513
523
  MEMBERS_INVITATIONS: '/members/invitations',
514
524
  SUPPRESSIONS: '/suppressions',
515
525
  FILES: '/files',
526
+ FILES_STATS: '/files/stats',
527
+ FILES_BATCH_DELETE: '/files/batch-delete',
516
528
  TEMP_MAIL_DOMAINS: '/temp-mail/domains',
517
529
  TEMP_MAIL_INBOXES: '/temp-mail/inboxes'
518
530
  };
@@ -1144,7 +1156,7 @@ class Transport {
1144
1156
  const repeatable = options.repeatable ?? RETRYABLE_METHODS.has(method);
1145
1157
  let attempt = 0;
1146
1158
  for (;;) {
1147
- const outcome = await this.attempt(url, method, headers, body, options.signal, options.binary === true);
1159
+ const outcome = await this.attempt(url, method, headers, body, options.signal, options.binary === true, options.timeoutMs ?? this.timeoutMs);
1148
1160
  if (outcome instanceof OpenEmailNetworkError) {
1149
1161
  if (options.signal?.aborted || !repeatable || attempt >= this.maxRetries)
1150
1162
  throw outcome;
@@ -1191,13 +1203,13 @@ class Transport {
1191
1203
  headers[HEADER_KEYS.IDEMPOTENCY_KEY] = options.idempotencyKey ?? IdempotencyKey();
1192
1204
  return headers;
1193
1205
  }
1194
- async attempt(url, method, headers, body, signal, binary) {
1195
- const deadline = Deadline(this.timeoutMs, signal);
1206
+ async attempt(url, method, headers, body, signal, binary, timeoutMs) {
1207
+ const deadline = Deadline(timeoutMs, signal);
1196
1208
  const Failure = (error, fallback) => {
1197
1209
  if (signal?.aborted)
1198
1210
  return new OpenEmailNetworkError('Request aborted by the caller.', error);
1199
1211
  if (deadline.timedOut())
1200
- return new OpenEmailNetworkError(`Request timed out after ${this.timeoutMs}ms.`, error, true);
1212
+ return new OpenEmailNetworkError(`Request timed out after ${timeoutMs}ms.`, error, true);
1201
1213
  return new OpenEmailNetworkError(`${fallback}: ${Describe(error)}`, error);
1202
1214
  };
1203
1215
  try {
@@ -1769,11 +1781,28 @@ const ListQuery$6 = (options) => ({
1769
1781
  [QUERY_KEYS.KIND]: options.kind,
1770
1782
  [QUERY_KEYS.SORT]: options.sort
1771
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
+ };
1772
1800
  const Files = (transport) => ({
1773
1801
  list: (options = {}) => FetchPage(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1774
1802
  listAll: (options = {}) => CollectAll(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1775
1803
  iterate: (options = {}) => IteratePages(transport, PATHS.FILES, CURSOR_STYLES.CURSOR, options, ListQuery$6(options)),
1776
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 }),
1777
1806
  download: (id, options = {}) => transport.request(FileChildPath(id, SEGMENTS.CONTENT), {
1778
1807
  binary: true,
1779
1808
  signal: options.signal,
@@ -1782,10 +1811,25 @@ const Files = (transport) => ({
1782
1811
  listLinks: (id, options = {}) => FetchPage(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1783
1812
  listAllLinks: (id, options = {}) => CollectAll(transport, FileChildPath(id, SEGMENTS.LINKS), CURSOR_STYLES.CURSOR, options),
1784
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
+ }),
1785
1823
  delete: (id, options = {}) => transport.request(FilePath(id), {
1786
1824
  method: HTTP_METHODS.DELETE,
1787
1825
  signal: options.signal,
1788
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
1789
1833
  })
1790
1834
  });
1791
1835
 
@@ -2744,4 +2788,4 @@ const resolveLanguage = ResolveLanguage;
2744
2788
  const languageByCode = LanguageByCode;
2745
2789
  const isRtlLanguage = IsRtlLanguage;
2746
2790
 
2747
- export { API_SCOPES, BROADCAST_STATUSES, CONTACT_BLOCK_LISTS, CONTACT_PHOTO_TYPES, CONTACT_THREAD_SORTS, ERROR_TYPES, FILE_DIRECTIONS, FILE_KINDS, FILE_SORTS, 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 };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openemail/sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "author": "OpenEmail",
5
5
  "license": "UNLICENSED",
6
6
  "description": "The official TypeScript SDK for the OpenEmail API. Send email and broadcasts, work with threads, drafts, labels, templates, rules, webhooks, tracking, contacts, audiences, domains, suppressions, files, API keys, roles, members, mailbox imports and disposable inboxes from code.",