mailchannels-sdk 0.7.5 → 0.7.6

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.
@@ -87,15 +87,9 @@ const validatePagination = (pagination = {}) => {
87
87
  if (typeof offset === "number" && offset < 0) return createError("Offset must be greater than or equal to 0.");
88
88
  return null;
89
89
  };
90
- /**
91
- * Validates if a string is a valid email address
92
- */
93
90
  const isValidEmail = (email) => {
94
91
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
95
92
  };
96
- /**
97
- * Parses name-address pair string to MailChannels format
98
- */
99
93
  const parseRecipientString = (input) => {
100
94
  const trimmed = input.trim();
101
95
  const match = trimmed.match(/^([^<]*)<([^>]*)>$/);
@@ -110,9 +104,6 @@ const parseRecipientString = (input) => {
110
104
  if (!isValidEmail(trimmed)) return void 0;
111
105
  return { email: trimmed };
112
106
  };
113
- /**
114
- * Parses any recipient format to MailChannels format
115
- */
116
107
  const parseRecipient = (recipient) => {
117
108
  if (typeof recipient === "string") return parseRecipientString(recipient);
118
109
  if (!recipient?.email || !isValidEmail(recipient.email)) return void 0;
@@ -121,20 +112,12 @@ const parseRecipient = (recipient) => {
121
112
  name: recipient.name
122
113
  };
123
114
  };
124
- /**
125
- * Parses any array of recipients format to MailChannels format
126
- */
127
115
  const parseArrayRecipients = (recipients) => {
128
116
  if (!recipients) return void 0;
129
117
  const filtered = (typeof recipients === "string" ? [parseRecipientString(recipients)] : Array.isArray(recipients) ? recipients.map(parseRecipient) : [recipients]).filter((recipient) => Boolean(recipient));
130
118
  return filtered.length > 0 ? filtered : void 0;
131
119
  };
132
120
  const stripPemHeaders = (pem) => pem.replace(/-----[^-]+-----|\s|#.*$/gm, "");
133
- /**
134
- * Recursively removes undefined values from objects and arrays.
135
- * @param data - The data to clean
136
- * @returns The cleaned data with `undefined` properties removed
137
- */
138
121
  const clean = (data) => {
139
122
  if (Array.isArray(data)) {
140
123
  const result = [];
@@ -279,62 +262,12 @@ var Emails = class {
279
262
  error: null
280
263
  };
281
264
  }
282
- /**
283
- * Sends an email message to one or more recipients.
284
- * @param options - The email options to send.
285
- * @param dryRun - When set to `true`, the message will not be sent. Instead, the fully rendered message will be returned in the `data` property of the response. The default value is `false`.
286
- * @example
287
- * ```ts
288
- * const mailchannels = new MailChannels('your-api-key')
289
- * const { success, data, error } = await mailchannels.emails.send({
290
- * to: 'to@example.com',
291
- * from: 'from@example.com',
292
- * subject: 'Test',
293
- * html: 'Test'
294
- * })
295
- * ```
296
- */
297
265
  async send(options, dryRun = false) {
298
266
  return this._sendEmail(options, { dryRun });
299
267
  }
300
- /**
301
- * Queues an email message for asynchronous processing and returns immediately with a request ID.
302
- *
303
- * The email will be processed in the background, and you'll receive webhook events for all delivery status updates (e.g. `dropped`, `processed`, `delivered`, `hard-bounced`). These webhook events are identical to those sent for the synchronous /send endpoint.
304
- *
305
- * Use this endpoint when you need to send emails without waiting for processing to complete. This can improve your application's response time, especially when sending to multiple recipients.
306
- * @param options - The email options to send.
307
- * @example
308
- * ```ts
309
- * const mailchannels = new MailChannels('your-api-key')
310
- * const { data, error } = await mailchannels.emails.sendAsync({
311
- * to: 'to@example.com',
312
- * from: 'from@example.com',
313
- * subject: 'Test',
314
- * html: 'Test'
315
- * })
316
- * ```
317
- */
318
268
  async sendAsync(options) {
319
269
  return this._sendEmail(options, { async: true });
320
270
  }
321
- /**
322
- * Validates a domain's email authentication setup by retrieving its DKIM, SPF, and Domain Lockdown status. This endpoint checks whether the domain is properly configured for secure email delivery.
323
- * @param options - The domain options to check.
324
- * @example
325
- * ```ts
326
- * const mailchannels = new MailChannels('your-api-key')
327
- * const { data, error } = await mailchannels.emails.checkDomain({
328
- * dkim: [{
329
- * domain: 'example.com',
330
- * privateKey: 'your-private-key',
331
- * selector: 'mailchannels'
332
- * }],
333
- * domain: 'example.com',
334
- * senderId: 'sender-id'
335
- * })
336
- * ```
337
- */
338
271
  async checkDomain(options) {
339
272
  let error = null;
340
273
  const { dkim, domain, senderId } = options;
@@ -380,18 +313,6 @@ var Emails = class {
380
313
  error: null
381
314
  };
382
315
  }
383
- /**
384
- * Create a DKIM key pair for a specified domain and selector using the specified algorithm and key length, for the current customer.
385
- * @param domain - The domain to create the DKIM key for.
386
- * @param options - DKIM key creation options.
387
- * @example
388
- * ```ts
389
- * const mailchannels = new MailChannels('your-api-key')
390
- * const { data, error } = await mailchannels.emails.createDkimKey('example.com', {
391
- * selector: 'mailchannels'
392
- * })
393
- * ```
394
- */
395
316
  async createDkimKey(domain, options) {
396
317
  let error = null;
397
318
  if (!options.selector || options.selector.length > 63) {
@@ -439,18 +360,6 @@ var Emails = class {
439
360
  error: null
440
361
  };
441
362
  }
442
- /**
443
- * Search for DKIM keys by domain, with optional filters. If selector is provided, at most one key will be returned.
444
- * @param domain - The domain to search DKIM keys for.
445
- * @param options - The options to filter DKIM keys by.
446
- * @example
447
- * ```ts
448
- * const mailchannels = new MailChannels('your-api-key')
449
- * const { data, error } = await mailchannels.getDkimKeys('example.com', {
450
- * includeDnsRecord: true
451
- * })
452
- * ```
453
- */
454
363
  async getDkimKeys(domain, options) {
455
364
  let error = null;
456
365
  if (options?.selector && options.selector.length > 63) {
@@ -505,18 +414,6 @@ var Emails = class {
505
414
  error: null
506
415
  };
507
416
  }
508
- /**
509
- * Update fields of an existing DKIM key pair for the specified domain and selector, for the current customer. Currently, only the `status` field can be updated.
510
- * @param domain - The domain the DKIM key belongs to.
511
- * @param options - The options to update the DKIM key.
512
- * @example
513
- * ```ts
514
- * const mailchannels = new MailChannels('your-api-key')
515
- * const { success, error } = await mailchannels.emails.updateDkimKey('example.com', {
516
- * selector: 'mailchannels',
517
- * status: 'retired'
518
- * })
519
- */
520
417
  async updateDkimKey(domain, options) {
521
418
  let error = null;
522
419
  if (!options.selector || options.selector.length > 63) {
@@ -543,22 +440,6 @@ var Emails = class {
543
440
  error
544
441
  };
545
442
  }
546
- /**
547
- * Rotate an active DKIM key pair. Mark the original key as `rotated`, and create a new key pair with the required new key selector, reusing the same algorithm and key length. The rotated key remains valid for signing for a 3-day grace period, and is automatically changed to `retired` 2 weeks after rotation. Publish the new key to its DNS TXT record before rotated key expires for signing as emails sent with an unpublished key will fail DKIM validation by receiving providers. After the grace period, only the new key is valid for signing if published.
548
- * @param domain - The domain the DKIM key belongs to.
549
- * @param selector - The selector of the DKIM key to rotate.
550
- * @param options - The options to rotate the DKIM key.
551
- * @param options.newKey.selector - The selector for the new key pair. Must be a maximum of 63 characters.
552
- * @example
553
- * ```ts
554
- * const mailchannels = new MailChannels('your-api-key')
555
- * const { data, error } = await mailchannels.emails.rotateDkimKey('example.com', 'mailchannels', {
556
- * newKey: {
557
- * selector: 'new-selector'
558
- * }
559
- * })
560
- * ```
561
- */
562
443
  async rotateDkimKey(domain, selector, options) {
563
444
  let error = null;
564
445
  if (!selector || selector.length > 63) {
@@ -635,7 +516,6 @@ const ED25519 = {
635
516
  namedCurve: "Ed25519"
636
517
  };
637
518
  const encoder = new TextEncoder();
638
- const DEFAULT_TOLERANCE = 300;
639
519
  const HEADER_CONTENT_DIGEST = "content-digest";
640
520
  const HEADER_SIGNATURE = "signature";
641
521
  const HEADER_SIGNATURE_INPUT = "signature-input";
@@ -673,7 +553,7 @@ async function isValidWebhook(options) {
673
553
  if (!signature) return false;
674
554
  const values = extractInputValues(signatureInput);
675
555
  if (!values) return false;
676
- if (Math.floor(Date.now() / 1e3) - values.timestamp > DEFAULT_TOLERANCE) return false;
556
+ if (Math.floor(Date.now() / 1e3) - values.timestamp > 300) return false;
677
557
  const signingString = `"content-digest": ${contentDigest}
678
558
  "@signature-params": ("content-digest");created=${values.timestamp};alg="${values.algorithm}";keyid="${values.keyId}"`;
679
559
  let publicKey = options.publicKey;
@@ -697,15 +577,6 @@ var Webhooks = class Webhooks {
697
577
  constructor(mailchannels) {
698
578
  this.mailchannels = mailchannels;
699
579
  }
700
- /**
701
- * Enrolls the customer to receive event notifications via webhooks.
702
- * @param endpoint - The URL to receive event notifications. Must be no longer than `8000` characters.
703
- * @example
704
- * ```ts
705
- * const mailchannels = new MailChannels('your-api-key')
706
- * const { success, error } = mailchannels.webhooks.enroll('https://example.com/api/webhooks/mailchannels')
707
- * ```
708
- */
709
580
  async enroll(endpoint) {
710
581
  let error = null;
711
582
  if (!endpoint) {
@@ -735,14 +606,6 @@ var Webhooks = class Webhooks {
735
606
  error
736
607
  };
737
608
  }
738
- /**
739
- * Retrieves all registered webhook endpoints associated with the customer.
740
- * @example
741
- * ```ts
742
- * const mailchannels = new MailChannels('your-api-key')
743
- * const { data, error } = await mailchannels.webhooks.list()
744
- * ```
745
- */
746
609
  async list() {
747
610
  let error = null;
748
611
  const response = await this.mailchannels.get("/tx/v1/webhook", { onResponseError: async ({ response }) => {
@@ -760,14 +623,6 @@ var Webhooks = class Webhooks {
760
623
  error: null
761
624
  };
762
625
  }
763
- /**
764
- * Deletes all registered webhook endpoints for the customer.
765
- * @example
766
- * ```ts
767
- * const mailchannels = new MailChannels('your-api-key')
768
- * const { success, error } = await mailchannels.webhooks.delete()
769
- * ```
770
- */
771
626
  async delete() {
772
627
  let error = null;
773
628
  await this.mailchannels.delete("/tx/v1/webhook", { onResponseError: async ({ response }) => {
@@ -780,15 +635,6 @@ var Webhooks = class Webhooks {
780
635
  error
781
636
  };
782
637
  }
783
- /**
784
- * Retrieves the public key used to verify signatures on incoming webhook payloads.
785
- * @param id - The ID of the key.
786
- * @example
787
- * ```ts
788
- * const mailchannels = new MailChannels('your-api-key')
789
- * const { data, error } = await mailchannels.webhooks.getSigningKey('key-id')
790
- * ```
791
- */
792
638
  async getSigningKey(id) {
793
639
  let error = null;
794
640
  const response = await this.mailchannels.get("/tx/v1/webhook/public-key", {
@@ -815,15 +661,6 @@ var Webhooks = class Webhooks {
815
661
  error: null
816
662
  };
817
663
  }
818
- /**
819
- * Validates whether your enrolled webhook(s) respond with an HTTP `2xx` status code. Sends a test request to each webhook containing your customer handle, a hardcoded event type (`test`), a hardcoded sender email (`test@mailchannels.com`), a timestamp, a request ID (provided or generated), and an SMTP ID. The response includes the HTTP status code and body returned by each webhook.
820
- * @param requestId - Optional identifier in the webhook payload. If not provided, a value will be automatically generated. Must not exceed 28 characters.
821
- * @example
822
- * ```ts
823
- * const mailchannels = new MailChannels('your-api-key')
824
- * const { data, error } = await mailchannels.webhooks.validate('optional-request-id')
825
- * ```
826
- */
827
664
  async validate(requestId) {
828
665
  let error = null;
829
666
  if (requestId && requestId.length > 28) {
@@ -857,29 +694,56 @@ var Webhooks = class Webhooks {
857
694
  error: null
858
695
  };
859
696
  }
860
- /**
861
- * Verifies the authenticity of incoming webhook requests by validating their signatures using the provided options.
862
- * @param options - The options for verifying the webhook.
863
- * @example
864
- * ```ts
865
- * const isValid = await Webhooks.verify({ payload: rawBody, headers })
866
- * ```
867
- */
868
697
  static async verify(options) {
869
698
  return isValidWebhook(options).catch(() => false);
870
699
  }
871
- /**
872
- * Verifies the authenticity of incoming webhook requests by validating their signatures using the provided options.
873
- * @param options - The options for verifying the webhook.
874
- * @example
875
- * ```ts
876
- * const mailchannels = new MailChannels('your-api-key')
877
- * const isValid = await mailchannels.webhooks.verify({ payload: rawBody, headers })
878
- * ```
879
- */
880
700
  async verify(options) {
881
701
  return Webhooks.verify(options);
882
702
  }
703
+ async batches(options) {
704
+ let error = null;
705
+ error = validatePagination({
706
+ ...options,
707
+ max: 500
708
+ });
709
+ if (error) return {
710
+ data: null,
711
+ error
712
+ };
713
+ const response = await this.mailchannels.get("/tx/v1/webhook-batch", {
714
+ query: {
715
+ created_after: options?.createdAfter,
716
+ created_before: options?.createdBefore,
717
+ statuses: options?.statuses,
718
+ webhook: options?.webhook,
719
+ limit: options?.limit,
720
+ offset: options?.offset
721
+ },
722
+ onResponseError: async ({ response }) => {
723
+ error = getStatusError(response, { [ErrorCode.BadRequest]: "Bad Request." });
724
+ }
725
+ }).catch((e) => {
726
+ error ||= getResultError(e, "Failed to fetch webhook batches.");
727
+ return null;
728
+ });
729
+ if (!response) return {
730
+ data: null,
731
+ error
732
+ };
733
+ return {
734
+ data: clean(response.webhook_batches.map((batch) => ({
735
+ batchId: batch.batch_id,
736
+ createdAt: batch.created_at,
737
+ customerHandle: batch.customer_handle,
738
+ duration: batch.duration,
739
+ eventCount: batch.event_count,
740
+ status: batch.status,
741
+ statusCode: batch.status_code,
742
+ webhook: batch.webhook
743
+ }))),
744
+ error: null
745
+ };
746
+ }
883
747
  };
884
748
  var SubAccounts = class SubAccounts {
885
749
  static COMPANY_PATTERN = /^.{3,128}$/;
@@ -887,16 +751,6 @@ var SubAccounts = class SubAccounts {
887
751
  constructor(mailchannels) {
888
752
  this.mailchannels = mailchannels;
889
753
  }
890
- /**
891
- * Creates a new sub-account under the parent account. Each sub-account must have a unique handle composed solely of lowercase alphanumeric characters. If no handle is provided, a random handle will be generated. Note that Sub-accounts are only available to parent accounts on 100K and higher plans.
892
- * @param companyName - The name of the company associated with the sub-account. This name is used for display purposes only and does not affect the functionality of the sub-account. The length must be between 3 and 128 characters.
893
- * @param handle - A unique name for the sub-account to be created. The length must be between 3 and 128 characters, and it may contain only lowercase letters and numbers. If not provided, a random handle will be generated.
894
- * @example
895
- * ```ts
896
- * const mailchannels = new MailChannels('your-api-key')
897
- * const { data, error } = await mailchannels.subAccounts.create('My Company', 'validhandle123')
898
- * ```
899
- */
900
754
  async create(companyName, handle) {
901
755
  let error = null;
902
756
  if (!SubAccounts.COMPANY_PATTERN.test(companyName)) {
@@ -943,15 +797,6 @@ var SubAccounts = class SubAccounts {
943
797
  error: null
944
798
  };
945
799
  }
946
- /**
947
- * Retrieves all sub-accounts associated with the parent account. The response is paginated with a default limit of 1000 sub-accounts per page and an offset of 0.
948
- * @param options - The options to filter the list of sub-accounts.
949
- * @example
950
- * ```ts
951
- * const mailchannels = new MailChannels('your-api-key')
952
- * const { data, error } = await mailchannels.subAccounts.list()
953
- * ```
954
- */
955
800
  async list(options) {
956
801
  let error = null;
957
802
  error = validatePagination({
@@ -984,15 +829,6 @@ var SubAccounts = class SubAccounts {
984
829
  error: null
985
830
  };
986
831
  }
987
- /**
988
- * Deletes the sub-account identified by its handle.
989
- * @param handle - Handle of sub-account to be deleted.
990
- * @example
991
- * ```ts
992
- * const mailchannels = new MailChannels('your-api-key')
993
- * const { success, error } = await mailchannels.subAccounts.delete('validhandle123')
994
- * ```
995
- */
996
832
  async delete(handle) {
997
833
  let error = null;
998
834
  if (!handle) {
@@ -1012,15 +848,6 @@ var SubAccounts = class SubAccounts {
1012
848
  error
1013
849
  };
1014
850
  }
1015
- /**
1016
- * Suspends the sub-account identified by its handle. This action disables the account, preventing it from sending any emails until it is reactivated.
1017
- * @param handle - Handle of sub-account to be suspended.
1018
- * @example
1019
- * ```ts
1020
- * const mailchannels = new MailChannels('your-api-key')
1021
- * const { success, error } = await mailchannels.subAccounts.suspend('validhandle123')
1022
- * ```
1023
- */
1024
851
  async suspend(handle) {
1025
852
  let error = null;
1026
853
  if (!handle) {
@@ -1040,15 +867,6 @@ var SubAccounts = class SubAccounts {
1040
867
  error
1041
868
  };
1042
869
  }
1043
- /**
1044
- * Activates a suspended sub-account identified by its handle, restoring its ability to send emails.
1045
- * @param handle - Handle of sub-account to be activated.
1046
- * @example
1047
- * ```ts
1048
- * const mailchannels = new MailChannels('your-api-key')
1049
- * const { success, error } = await mailchannels.subAccounts.activate('validhandle123')
1050
- * ```
1051
- */
1052
870
  async activate(handle) {
1053
871
  let error = null;
1054
872
  if (!handle) {
@@ -1071,15 +889,6 @@ var SubAccounts = class SubAccounts {
1071
889
  error
1072
890
  };
1073
891
  }
1074
- /**
1075
- * Creates a new API key for the specified sub-account.
1076
- * @param handle - Handle of the sub-account to create API key for.
1077
- * @example
1078
- * ```ts
1079
- * const mailchannels = new MailChannels('your-api-key')
1080
- * const { data, error } = await mailchannels.subAccounts.createApiKey('validhandle123')
1081
- * ```
1082
- */
1083
892
  async createApiKey(handle) {
1084
893
  let error = null;
1085
894
  if (!handle) {
@@ -1111,16 +920,6 @@ var SubAccounts = class SubAccounts {
1111
920
  error: null
1112
921
  };
1113
922
  }
1114
- /**
1115
- * Retrieves details of all API keys associated with the specified sub-account. For security reasons, the full API key is not returned; only the key ID and a partially redacted version are provided.
1116
- * @param handle - Handle of the sub-account to retrieve the API key for.
1117
- * @param options - The options to filter the list of API keys.
1118
- * @example
1119
- * ```ts
1120
- * const mailchannels = new MailChannels('your-api-key')
1121
- * const { data, error } = await mailchannels.subAccounts.listApiKeys('validhandle123')
1122
- * ```
1123
- */
1124
923
  async listApiKeys(handle, options) {
1125
924
  let error = null;
1126
925
  if (!handle) {
@@ -1156,16 +955,6 @@ var SubAccounts = class SubAccounts {
1156
955
  error: null
1157
956
  };
1158
957
  }
1159
- /**
1160
- * Deletes the API key identified by its ID for the specified sub-account.
1161
- * @param handle - Handle of the sub-account for which the API key should be deleted.
1162
- * @param id - The ID of the API key to delete.
1163
- * @example
1164
- * ```ts
1165
- * const mailchannels = new MailChannels('your-api-key')
1166
- * const { success, error } = await mailchannels.subAccounts.deleteApiKey('validhandle123', 1)
1167
- * ```
1168
- */
1169
958
  async deleteApiKey(handle, id) {
1170
959
  let error = null;
1171
960
  if (!handle) {
@@ -1185,15 +974,6 @@ var SubAccounts = class SubAccounts {
1185
974
  error
1186
975
  };
1187
976
  }
1188
- /**
1189
- * Creates a new SMTP password for the specified sub-account.
1190
- * @param handle - Handle of the sub-account to create SMTP password for.
1191
- * @example
1192
- * ```ts
1193
- * const mailchannels = new MailChannels('your-api-key')
1194
- * const { data, error } = await mailchannels.subAccounts.createSmtpPassword('validhandle123')
1195
- * ```
1196
- */
1197
977
  async createSmtpPassword(handle) {
1198
978
  let error = null;
1199
979
  if (!handle) {
@@ -1226,15 +1006,6 @@ var SubAccounts = class SubAccounts {
1226
1006
  error: null
1227
1007
  };
1228
1008
  }
1229
- /**
1230
- * Retrieves details of all SMTP passwords associated with the specified sub-account. For security, the full SMTP password is not returned; only the password ID and a partially redacted version are provided.
1231
- * @param handle - Handle of the sub-account to retrieve the SMTP password for.
1232
- * @example
1233
- * ```ts
1234
- * const mailchannels = new MailChannels('your-api-key')
1235
- * const { data, error } = await mailchannels.subAccounts.listSmtpPasswords('validhandle123')
1236
- * ```
1237
- */
1238
1009
  async listSmtpPasswords(handle) {
1239
1010
  let error = null;
1240
1011
  if (!handle) {
@@ -1263,16 +1034,6 @@ var SubAccounts = class SubAccounts {
1263
1034
  error: null
1264
1035
  };
1265
1036
  }
1266
- /**
1267
- * Deletes the SMTP password identified by its ID for the specified sub-account.
1268
- * @param handle - Handle of the sub-account for which the SMTP password should be deleted.
1269
- * @param id - The ID of the SMTP password to delete.
1270
- * @example
1271
- * ```ts
1272
- * const mailchannels = new MailChannels('your-api-key')
1273
- * const { success, error } = await mailchannels.subAccounts.deleteSmtpPassword('validhandle123', 1)
1274
- * ```
1275
- */
1276
1037
  async deleteSmtpPassword(handle, id) {
1277
1038
  let error = null;
1278
1039
  if (!handle) {
@@ -1292,15 +1053,6 @@ var SubAccounts = class SubAccounts {
1292
1053
  error
1293
1054
  };
1294
1055
  }
1295
- /**
1296
- * Retrieves the limit of a specified sub-account. A value of `-1` indicates that the sub-account inherits the parent account's limit, allowing the sub-account to utilize any remaining capacity within the parent account's allocation.
1297
- * @param handle - Handle of the sub-account to retrieve the limit for.
1298
- * @example
1299
- * ```ts
1300
- * const mailchannels = new MailChannels('your-api-key')
1301
- * const { data, error } = await mailchannels.subAccounts.getLimit('validhandle123')
1302
- * ```
1303
- */
1304
1056
  async getLimit(handle) {
1305
1057
  let error = null;
1306
1058
  if (!handle) {
@@ -1325,16 +1077,6 @@ var SubAccounts = class SubAccounts {
1325
1077
  error: null
1326
1078
  };
1327
1079
  }
1328
- /**
1329
- * Sets the limit for the specified sub-account.
1330
- * @param handle - Handle of the sub-account to set limit for.
1331
- * @param limit - The limits to set for the sub-account. The minimum allowed sends is `0`
1332
- * @example
1333
- * ```ts
1334
- * const mailchannels = new MailChannels('your-api-key')
1335
- * const { success, error } = await mailchannels.subAccounts.setLimit('validhandle123', { sends: 1000 })
1336
- * ```
1337
- */
1338
1080
  async setLimit(handle, limit) {
1339
1081
  let error = null;
1340
1082
  if (!handle) {
@@ -1360,15 +1102,6 @@ var SubAccounts = class SubAccounts {
1360
1102
  error
1361
1103
  };
1362
1104
  }
1363
- /**
1364
- * Deletes the limit for the specified sub-account. After a successful deletion, the specified sub-account will be limited to the parent account's limit.
1365
- * @param handle - Handle of the sub-account to delete limit for.
1366
- * @example
1367
- * ```ts
1368
- * const mailchannels = new MailChannels('your-api-key')
1369
- * const { success, error } = await mailchannels.subAccounts.deleteLimit('validhandle123')
1370
- * ```
1371
- */
1372
1105
  async deleteLimit(handle) {
1373
1106
  let error = null;
1374
1107
  if (!handle) {
@@ -1388,15 +1121,6 @@ var SubAccounts = class SubAccounts {
1388
1121
  error
1389
1122
  };
1390
1123
  }
1391
- /**
1392
- * Retrieves usage statistics for the specified sub-account during the current billing period.
1393
- * @param handle - Handle of the sub-account to query usage stats for.
1394
- * @example
1395
- * ```ts
1396
- * const mailchannels = new MailChannels('your-api-key')
1397
- * const { data, error } = await mailchannels.subAccounts.getUsage('validhandle123')
1398
- * ```
1399
- */
1400
1124
  async getUsage(handle) {
1401
1125
  let error = null;
1402
1126
  if (!handle) {
@@ -1430,15 +1154,6 @@ var Metrics = class {
1430
1154
  constructor(mailchannels) {
1431
1155
  this.mailchannels = mailchannels;
1432
1156
  }
1433
- /**
1434
- * Retrieve engagement metrics for messages sent from your account, including counts of open and click events. Supports optional filters for time range, and campaign ID.
1435
- * @param options - Options to filter and customize the engagement metrics retrieval.
1436
- * @example
1437
- * ```ts
1438
- * const mailchannels = new MailChannels('your-api-key')
1439
- * const { data, error } = await mailchannels.metrics.engagement()
1440
- * ```
1441
- */
1442
1157
  async engagement(options) {
1443
1158
  let error = null;
1444
1159
  const response = await this.mailchannels.get("/tx/v1/metrics/engagement", {
@@ -1477,15 +1192,6 @@ var Metrics = class {
1477
1192
  error: null
1478
1193
  };
1479
1194
  }
1480
- /**
1481
- * Retrieve performance metrics for messages sent from your account, including counts of processed, delivered, hard-bounced events. Supports optional filters for time range, and campaign ID.
1482
- * @param options - Options to filter and customize the performance metrics retrieval.
1483
- * @example
1484
- * ```ts
1485
- * const mailchannels = new MailChannels('your-api-key')
1486
- * const { data, error } = await mailchannels.metrics.performance()
1487
- * ```
1488
- */
1489
1195
  async performance(options) {
1490
1196
  let error = null;
1491
1197
  const response = await this.mailchannels.get("/tx/v1/metrics/performance", {
@@ -1522,15 +1228,6 @@ var Metrics = class {
1522
1228
  error: null
1523
1229
  };
1524
1230
  }
1525
- /**
1526
- * Retrieve recipient behaviour metrics for messages sent from your account, including counts of unsubscribed events. Supports optional filters for time range, and campaign ID.
1527
- * @param options - Options to filter and customize the recipient behaviour metrics retrieval.
1528
- * @example
1529
- * ```ts
1530
- * const mailchannels = new MailChannels('your-api-key')
1531
- * const { data, error } = await mailchannels.metrics.recipientBehaviour()
1532
- * ```
1533
- */
1534
1231
  async recipientBehaviour(options) {
1535
1232
  let error = null;
1536
1233
  const response = await this.mailchannels.get("/tx/v1/metrics/recipient-behaviour", {
@@ -1565,15 +1262,6 @@ var Metrics = class {
1565
1262
  error: null
1566
1263
  };
1567
1264
  }
1568
- /**
1569
- * Retrieve volume metrics for messages sent from your account, including counts of processed, delivered and dropped events. Supports optional filters for time range and campaign ID.
1570
- * @param options - Options to filter and customize the volume metrics retrieval.
1571
- * @example
1572
- * ```ts
1573
- * const mailchannels = new MailChannels('your-api-key')
1574
- * const { data, error } = await mailchannels.metrics.volume()
1575
- * ```
1576
- */
1577
1265
  async volume(options) {
1578
1266
  let error = null;
1579
1267
  const response = await this.mailchannels.get("/tx/v1/metrics/volume", {
@@ -1610,14 +1298,6 @@ var Metrics = class {
1610
1298
  error: null
1611
1299
  };
1612
1300
  }
1613
- /**
1614
- * Retrieves usage statistics during the current billing period.
1615
- * @example
1616
- * ```ts
1617
- * const mailchannels = new MailChannels('your-api-key')
1618
- * const { data, error } = await mailchannels.metrics.usage()
1619
- * ```
1620
- */
1621
1301
  async usage() {
1622
1302
  let error = null;
1623
1303
  const response = await this.mailchannels.get("/tx/v1/usage", { onResponseError: async ({ response }) => {
@@ -1639,16 +1319,6 @@ var Metrics = class {
1639
1319
  error: null
1640
1320
  };
1641
1321
  }
1642
- /**
1643
- * Retrieves a list of senders, either sub-accounts or campaigns, with their associated message metrics. Sorted by total # of sent messages (processed + dropped). Supports optional filter for time range, and optional settings for limit, offset, and sort order. Note: senders without any messages in the given time range will not be included in the results. The default time range is from one month ago to now, and the default sort order is descending.
1644
- * @param type - The type of senders to retrieve metrics for. Can be either `sub-accounts` or `campaigns`.
1645
- * @param options - Optional filter options for time range, limit, offset, and sort order.
1646
- * @example
1647
- * ```ts
1648
- * const mailchannels = new MailChannels('your-api-key')
1649
- * const { data, error } = await mailchannels.metrics.senders('campaigns')
1650
- * ```
1651
- */
1652
1322
  async senders(type, options) {
1653
1323
  let error = null;
1654
1324
  error = validatePagination({
@@ -1695,16 +1365,6 @@ var Suppressions = class {
1695
1365
  constructor(mailchannels) {
1696
1366
  this.mailchannels = mailchannels;
1697
1367
  }
1698
- /**
1699
- * Creates suppression entries for the specified account. Parent accounts can create suppression entries for all associated sub-accounts. If `types` is not provided, it defaults to `non-transactional`. The operation is atomic, meaning all entries are successfully added or none are added if an error occurs.
1700
- * @param options - The details of the suppression entries to create.
1701
- * @example
1702
- * ```ts
1703
- * const mailchannels = new MailChannels('your-api-key')
1704
- * const { success, error } = await mailchannels.suppressions.create({
1705
- * // ...
1706
- * });
1707
- */
1708
1368
  async create(options) {
1709
1369
  let error = null;
1710
1370
  const { addToSubAccounts, entries } = options;
@@ -1733,16 +1393,6 @@ var Suppressions = class {
1733
1393
  error
1734
1394
  };
1735
1395
  }
1736
- /**
1737
- * Deletes suppression entry associated with the account based on the specified recipient and source.
1738
- * @param recipient - The email address of the suppression entry to delete.
1739
- * @param source - The source of the suppression entry to be deleted. If source is not provided, it defaults to `api`. If source is set to `all`, all suppression entries related to the specified recipient will be deleted.
1740
- * @example
1741
- * ```ts
1742
- * const mailchannels = new MailChannels('your-api-key')
1743
- * const { success, error } = await mailchannels.suppressions.delete('name@example.com', 'api');
1744
- * ```
1745
- */
1746
1396
  async delete(recipient, source) {
1747
1397
  let error = null;
1748
1398
  await this.mailchannels.delete(`/tx/v1/suppression-list/recipients/${recipient}`, {
@@ -1758,15 +1408,6 @@ var Suppressions = class {
1758
1408
  error
1759
1409
  };
1760
1410
  }
1761
- /**
1762
- * Retrieve suppression entries associated with the specified account. Supports filtering by recipient, source and creation date range. The response is paginated, with a default limit of `1000` entries per page and an offset of `0`.
1763
- * @param options - Options to filter and customize the suppression entries retrieval.
1764
- * @example
1765
- * ```ts
1766
- * const mailchannels = new MailChannels('your-api-key')
1767
- * const { data, error } = await mailchannels.suppressions.list();
1768
- * ```
1769
- */
1770
1411
  async list(options) {
1771
1412
  let error = null;
1772
1413
  error = validatePagination({
@@ -1815,18 +1456,6 @@ var Domains = class {
1815
1456
  constructor(mailchannels) {
1816
1457
  this.mailchannels = mailchannels;
1817
1458
  }
1818
- /**
1819
- * Provision a single domain to use MailChannels Inbound.
1820
- * @param options - The provision options and domain data.
1821
- * @example
1822
- * ```ts
1823
- * const mailchannels = new MailChannels('your-api-key')
1824
- * const { data, error } = await mailchannels.domains.provision({
1825
- * domain: 'example.com',
1826
- * subscriptionHandle: 'your-subscription-handle'
1827
- * })
1828
- * ```
1829
- */
1830
1459
  async provision(options) {
1831
1460
  let error = null;
1832
1461
  const { associateKey, overwrite, ...payload } = options;
@@ -1856,26 +1485,6 @@ var Domains = class {
1856
1485
  error: null
1857
1486
  };
1858
1487
  }
1859
- /**
1860
- * Provision up to 1000 domains to use MailChannels Inbound.
1861
- * @param options - The options to provision the domains.
1862
- * @param domains - A list of domain data to provision.
1863
- * @example
1864
- * ```ts
1865
- * const mailchannels = new MailChannels('your-api-key')
1866
- * const { data, error } = await mailchannels.domains.bulkProvision({
1867
- * subscriptionHandle: 'your-subscription-handle'
1868
- * }, [
1869
- * {
1870
- * domain: 'example.com',
1871
- * admins: ['support@example.com']
1872
- * },
1873
- * {
1874
- * domain: 'example2.com'
1875
- * }
1876
- * ])
1877
- * ```
1878
- */
1879
1488
  async bulkProvision(options, domains) {
1880
1489
  let error = null;
1881
1490
  const { associateKey, overwrite, subscriptionHandle } = options;
@@ -1919,15 +1528,6 @@ var Domains = class {
1919
1528
  error: null
1920
1529
  };
1921
1530
  }
1922
- /**
1923
- * Fetch a list of all domains associated with this API key.
1924
- * @param options - The options to filter the list of domains.
1925
- * @example
1926
- * ```ts
1927
- * const mailchannels = new MailChannels('your-api-key')
1928
- * const { data, error } = await mailchannels.domains.list()
1929
- * ```
1930
- */
1931
1531
  async list(options) {
1932
1532
  let error = null;
1933
1533
  error = validatePagination({
@@ -1959,15 +1559,6 @@ var Domains = class {
1959
1559
  error: null
1960
1560
  };
1961
1561
  }
1962
- /**
1963
- * De-provision a domain to cease protecting it with MailChannels Inbound.
1964
- * @param domain - The domain name to be removed.
1965
- * @example
1966
- * ```ts
1967
- * const mailchannels = new MailChannels('your-api-key')
1968
- * const { success, error } = await mailchannels.domains.delete('example.com')
1969
- * ```
1970
- */
1971
1562
  async delete(domain) {
1972
1563
  let error = null;
1973
1564
  if (!domain) {
@@ -1990,19 +1581,6 @@ var Domains = class {
1990
1581
  error
1991
1582
  };
1992
1583
  }
1993
- /**
1994
- * Add an entry to a domain blocklist or safelist.
1995
- * @param domain - The domain name.
1996
- * @param options - The options to add a list entry.
1997
- * @example
1998
- * ```ts
1999
- * const mailchannels = new MailChannels('your-api-key')
2000
- * const { data, error } = await mailchannels.domains.addListEntry('example.com', {
2001
- * listName: 'safelist',
2002
- * item: 'name@domain.com'
2003
- * })
2004
- * ```
2005
- */
2006
1584
  async addListEntry(domain, options) {
2007
1585
  const { listName, item } = options;
2008
1586
  let error = null;
@@ -2045,16 +1623,6 @@ var Domains = class {
2045
1623
  error: null
2046
1624
  };
2047
1625
  }
2048
- /**
2049
- * Get domain list entries.
2050
- * @param domain - The domain name.
2051
- * @param listName - The name of the list to fetch. This can be a `blocklist`, `safelist`, `blacklist`, or `whitelist`.
2052
- * @example
2053
- * ```ts
2054
- * const mailchannels = new MailChannels('your-api-key')
2055
- * const { data, error } = await mailchannels.domains.listEntries('example.com', 'safelist')
2056
- * ```
2057
- */
2058
1626
  async listEntries(domain, listName) {
2059
1627
  let error = null;
2060
1628
  if (!domain) {
@@ -2093,19 +1661,6 @@ var Domains = class {
2093
1661
  error: null
2094
1662
  };
2095
1663
  }
2096
- /**
2097
- * Delete item from domain list.
2098
- * @param email - The domain name whose list will be modified.
2099
- * @param options - The options for the list entry to delete.
2100
- * @example
2101
- * ```ts
2102
- * const mailchannels = new MailChannels('your-api-key')
2103
- * const { success, error } = await mailchannels.domains.deleteListEntry('example.com', {
2104
- * listName: 'safelist',
2105
- * item: 'name@domain.com'
2106
- * })
2107
- * ```
2108
- */
2109
1664
  async deleteListEntry(domain, options) {
2110
1665
  const { listName, item } = options;
2111
1666
  let error = null;
@@ -2139,15 +1694,6 @@ var Domains = class {
2139
1694
  error
2140
1695
  };
2141
1696
  }
2142
- /**
2143
- * Generate a link that allows a user to log in as a domain administrator.
2144
- * @param domain - The domain name.
2145
- * @example
2146
- * ```ts
2147
- * const mailchannels = new MailChannels('your-api-key')
2148
- * const { data, error } = await mailchannels.domains.createLoginLink('example.com')
2149
- * ```
2150
- */
2151
1697
  async createLoginLink(domain) {
2152
1698
  let error = null;
2153
1699
  if (!domain) {
@@ -2176,23 +1722,6 @@ var Domains = class {
2176
1722
  error: null
2177
1723
  };
2178
1724
  }
2179
- /**
2180
- * Sets the list of downstream addresses for the domain. This action deletes any existing downstream address for the domain before creating new ones. If the `records` parameter is an empty array, all downstream address records will be deleted.
2181
- * @param domain - The domain name.
2182
- * @param records - The list of records to set for the domain. A maximum of 10 records can be set.
2183
- * @example
2184
- * ```ts
2185
- * const mailchannels = new MailChannels('your-api-key')
2186
- * const { success, error } = await mailchannels.domains.setDownstreamAddress('example.com', [
2187
- * {
2188
- * port: 25,
2189
- * priority: 10,
2190
- * target: 'example.com.',
2191
- * weight: 10
2192
- * }
2193
- * ])
2194
- * ```
2195
- */
2196
1725
  async setDownstreamAddress(domain, records) {
2197
1726
  let error = null;
2198
1727
  if (!domain) {
@@ -2232,16 +1761,6 @@ var Domains = class {
2232
1761
  error
2233
1762
  };
2234
1763
  }
2235
- /**
2236
- * Retrieve stored downstream addresses for the domain.
2237
- * @param domain - The domain name.
2238
- * @param options - The options to filter the list of downstream addresses.
2239
- * @example
2240
- * ```ts
2241
- * const mailchannels = new MailChannels('your-api-key')
2242
- * const { data, error } = await mailchannels.domains.listDownstreamAddresses('example.com')
2243
- * ```
2244
- */
2245
1764
  async listDownstreamAddresses(domain, options) {
2246
1765
  let error = null;
2247
1766
  if (!domain) {
@@ -2277,16 +1796,6 @@ var Domains = class {
2277
1796
  error: null
2278
1797
  };
2279
1798
  }
2280
- /**
2281
- * Update the API key that is associated with a domain.
2282
- * @param domain - The domain name.
2283
- * @param key - The new API key to associate with this domain.
2284
- * @example
2285
- * ```ts
2286
- * const mailchannels = new MailChannels('your-api-key')
2287
- * const { success, error } = await mailchannels.domains.updateApiKey('example.com', 'your-api-key')
2288
- * ```
2289
- */
2290
1799
  async updateApiKey(domain, key) {
2291
1800
  let error = null;
2292
1801
  if (!domain) {
@@ -2319,15 +1828,6 @@ var Domains = class {
2319
1828
  error
2320
1829
  };
2321
1830
  }
2322
- /**
2323
- * Generate a batch of links that allow a user to log in as a domain administrator to their different domains.
2324
- * @param domains - The list of domain names. Maximum of `1000` links per request.
2325
- * @example
2326
- * ```ts
2327
- * const mailchannels = new MailChannels('your-api-key')
2328
- * const { data, error } = await mailchannels.domains.bulkCreateLoginLinks(['example.com', 'example2.com'])
2329
- * ```
2330
- */
2331
1831
  async bulkCreateLoginLinks(domains) {
2332
1832
  let error = null;
2333
1833
  if (!domains || !domains.length) {
@@ -2367,18 +1867,6 @@ var Lists = class {
2367
1867
  constructor(mailchannels) {
2368
1868
  this.mailchannels = mailchannels;
2369
1869
  }
2370
- /**
2371
- * Add item to account-level list
2372
- * @param options - The options for the list entry to add.
2373
- * @example
2374
- * ```ts
2375
- * const mailchannels = new MailChannels('your-api-key')
2376
- * const { data, error } = await mailchannels.lists.addListEntry({
2377
- * listName: 'safelist',
2378
- * item: 'name@domain.com'
2379
- * })
2380
- * ```
2381
- */
2382
1870
  async addListEntry(options) {
2383
1871
  let error = null;
2384
1872
  const { listName, item } = options;
@@ -2411,15 +1899,6 @@ var Lists = class {
2411
1899
  error: null
2412
1900
  };
2413
1901
  }
2414
- /**
2415
- * Get account-level list entries.
2416
- * @param listName - The name of the list to fetch. This can be a `blocklist`, `safelist`, `blacklist`, or `whitelist`.
2417
- * @example
2418
- * ```ts
2419
- * const mailchannels = new MailChannels('your-api-key')
2420
- * const { data, error } = await mailchannels.lists.listEntries('safelist')
2421
- * ```
2422
- */
2423
1902
  async listEntries(listName) {
2424
1903
  let error = null;
2425
1904
  if (!listName) {
@@ -2448,18 +1927,6 @@ var Lists = class {
2448
1927
  error: null
2449
1928
  };
2450
1929
  }
2451
- /**
2452
- * Delete item from account-level list.
2453
- * @param options - The options for the list entry to delete.
2454
- * @example
2455
- * ```ts
2456
- * const mailchannels = new MailChannels('your-api-key')
2457
- * const { success, error } = await mailchannels.lists.deleteListEntry({
2458
- * listName: 'safelist',
2459
- * item: 'name@domain.com'
2460
- * })
2461
- * ```
2462
- */
2463
1930
  async deleteListEntry(options) {
2464
1931
  const { listName, item } = options;
2465
1932
  let error = null;
@@ -2488,18 +1955,6 @@ var Users = class {
2488
1955
  constructor(mailchannels) {
2489
1956
  this.mailchannels = mailchannels;
2490
1957
  }
2491
- /**
2492
- * Create a recipient user.
2493
- * @param email - The email address of the user to create.
2494
- * @param options - The options for the user to create.
2495
- * @example
2496
- * ```ts
2497
- * const mailchannels = new MailChannels('your-api-key')
2498
- * const { data, error } = await mailchannels.users.create("name@example.com", {
2499
- * admin: true
2500
- * })
2501
- * ```
2502
- */
2503
1958
  async create(email, options) {
2504
1959
  const { admin, filter, listEntries } = options || {};
2505
1960
  let error = null;
@@ -2542,19 +1997,6 @@ var Users = class {
2542
1997
  error: null
2543
1998
  };
2544
1999
  }
2545
- /**
2546
- * Add item to recipient user list
2547
- * @param email - The email address of the recipient whose list will be modified.
2548
- * @param options - The options for the list entry to add.
2549
- * @example
2550
- * ```ts
2551
- * const mailchannels = new MailChannels('your-api-key')
2552
- * const { data, error } = await mailchannels.users.addListEntry('name@example.com', {
2553
- * listName: 'safelist',
2554
- * item: 'name@domain.com'
2555
- * })
2556
- * ```
2557
- */
2558
2000
  async addListEntry(email, options) {
2559
2001
  const { listName, item } = options;
2560
2002
  let error = null;
@@ -2597,16 +2039,6 @@ var Users = class {
2597
2039
  error: null
2598
2040
  };
2599
2041
  }
2600
- /**
2601
- * Get recipient list entries.
2602
- * @param email - The email address of the recipient whose list will be fetched.
2603
- * @param listName - The name of the list to fetch. This can be a `blocklist`, `safelist`, `blacklist`, or `whitelist`.
2604
- * @example
2605
- * ```ts
2606
- * const mailchannels = new MailChannels('your-api-key')
2607
- * const { data, error } = await mailchannels.users.listEntries('name@example.com', 'safelist')
2608
- * ```
2609
- */
2610
2042
  async listEntries(email, listName) {
2611
2043
  let error = null;
2612
2044
  if (!email) {
@@ -2645,19 +2077,6 @@ var Users = class {
2645
2077
  error: null
2646
2078
  };
2647
2079
  }
2648
- /**
2649
- * Delete item from recipient list.
2650
- * @param email - The email address of the recipient whose list will be modified.
2651
- * @param options - The options for the list entry to delete.
2652
- * @example
2653
- * ```ts
2654
- * const mailchannels = new MailChannels('your-api-key')
2655
- * const { success, error } = await mailchannels.users.deleteListEntry('name@example.com', {
2656
- * listName: 'safelist',
2657
- * item: 'name@domain.com'
2658
- * })
2659
- * ```
2660
- */
2661
2080
  async deleteListEntry(email, options) {
2662
2081
  const { listName, item } = options;
2663
2082
  let error = null;
@@ -2696,14 +2115,6 @@ var Service = class {
2696
2115
  constructor(mailchannels) {
2697
2116
  this.mailchannels = mailchannels;
2698
2117
  }
2699
- /**
2700
- * Retrieve the condition of the service
2701
- * @example
2702
- * ```ts
2703
- * const mailchannels = new MailChannels('your-api-key')
2704
- * const { success, error } = await mailchannels.service.status()
2705
- * ```
2706
- */
2707
2118
  async status() {
2708
2119
  let error = null;
2709
2120
  await this.mailchannels.get("/inbound/v1/status", { onResponseError: async ({ response }) => {
@@ -2716,14 +2127,6 @@ var Service = class {
2716
2127
  error
2717
2128
  };
2718
2129
  }
2719
- /**
2720
- * Get a list of your subscriptions to MailChannels Inbound
2721
- * @example
2722
- * ```ts
2723
- * const mailchannels = new MailChannels('your-api-key')
2724
- * const { data, error } = await mailchannels.service.subscriptions()
2725
- * ```
2726
- */
2727
2130
  async subscriptions() {
2728
2131
  let error = null;
2729
2132
  const response = await this.mailchannels.get("/inbound/v1/subscriptions", { onResponseError: async ({ response }) => {
@@ -2741,17 +2144,6 @@ var Service = class {
2741
2144
  error: null
2742
2145
  };
2743
2146
  }
2744
- /**
2745
- * Submit a false negative or false positive report.
2746
- * @param options - The report options
2747
- * @example
2748
- * ```ts
2749
- * const mailchannels = new MailChannels('your-api-key')
2750
- * const { success, error } = await mailchannels.service.report({
2751
- * // ...
2752
- * })
2753
- * ```
2754
- */
2755
2147
  async report(options) {
2756
2148
  let error = null;
2757
2149
  const { type, ...payload } = options;