mailchannels-sdk 0.7.5 → 0.7.7

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.
@@ -2,10 +2,12 @@ import { $fetch } from "ofetch";
2
2
  import { subtle } from "node:crypto";
3
3
  import { Buffer } from "node:buffer";
4
4
  var MailChannelsClient = class MailChannelsClient {
5
- static BASE_URL = "https://api.mailchannels.net";
5
+ static DEFAULT_BASE_URL = "https://api.mailchannels.net";
6
+ #baseUrl;
6
7
  #headers;
7
- constructor(key) {
8
+ constructor(key, options = {}) {
8
9
  if (!key) throw new Error("Missing MailChannels API key.");
10
+ this.#baseUrl = options.baseUrl || MailChannelsClient.DEFAULT_BASE_URL;
9
11
  this.#headers = {
10
12
  "X-API-Key": key,
11
13
  "Accept": "application/json",
@@ -14,7 +16,7 @@ var MailChannelsClient = class MailChannelsClient {
14
16
  }
15
17
  async _fetch(path, options) {
16
18
  return $fetch(path, {
17
- baseURL: MailChannelsClient.BASE_URL,
19
+ baseURL: this.#baseUrl,
18
20
  ...options,
19
21
  headers: {
20
22
  ...this.#headers,
@@ -87,15 +89,9 @@ const validatePagination = (pagination = {}) => {
87
89
  if (typeof offset === "number" && offset < 0) return createError("Offset must be greater than or equal to 0.");
88
90
  return null;
89
91
  };
90
- /**
91
- * Validates if a string is a valid email address
92
- */
93
92
  const isValidEmail = (email) => {
94
93
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
95
94
  };
96
- /**
97
- * Parses name-address pair string to MailChannels format
98
- */
99
95
  const parseRecipientString = (input) => {
100
96
  const trimmed = input.trim();
101
97
  const match = trimmed.match(/^([^<]*)<([^>]*)>$/);
@@ -110,9 +106,6 @@ const parseRecipientString = (input) => {
110
106
  if (!isValidEmail(trimmed)) return void 0;
111
107
  return { email: trimmed };
112
108
  };
113
- /**
114
- * Parses any recipient format to MailChannels format
115
- */
116
109
  const parseRecipient = (recipient) => {
117
110
  if (typeof recipient === "string") return parseRecipientString(recipient);
118
111
  if (!recipient?.email || !isValidEmail(recipient.email)) return void 0;
@@ -121,20 +114,12 @@ const parseRecipient = (recipient) => {
121
114
  name: recipient.name
122
115
  };
123
116
  };
124
- /**
125
- * Parses any array of recipients format to MailChannels format
126
- */
127
117
  const parseArrayRecipients = (recipients) => {
128
118
  if (!recipients) return void 0;
129
119
  const filtered = (typeof recipients === "string" ? [parseRecipientString(recipients)] : Array.isArray(recipients) ? recipients.map(parseRecipient) : [recipients]).filter((recipient) => Boolean(recipient));
130
120
  return filtered.length > 0 ? filtered : void 0;
131
121
  };
132
122
  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
123
  const clean = (data) => {
139
124
  if (Array.isArray(data)) {
140
125
  const result = [];
@@ -163,75 +148,175 @@ const mapBuckets = (arr) => {
163
148
  periodStart: period_start
164
149
  }));
165
150
  };
151
+ const RESERVED_HEADER_NAMES = new Set([
152
+ "authentication-results",
153
+ "bcc",
154
+ "cc",
155
+ "content-transfer-encoding",
156
+ "content-type",
157
+ "dkim-signature",
158
+ "from",
159
+ "message-id",
160
+ "received",
161
+ "reply-to",
162
+ "subject",
163
+ "to"
164
+ ]);
165
+ const getRecipientCount = (recipients) => recipients?.length || 0;
166
+ const validateHeaderMap = (headers, label) => {
167
+ if (!headers) return null;
168
+ const seenHeaders = /* @__PURE__ */ new Set();
169
+ for (const [headerName, headerValue] of Object.entries(headers)) {
170
+ if (typeof headerValue !== "string") return `${label} header '${headerName}' must have a string value.`;
171
+ const normalizedHeaderName = headerName.toLowerCase();
172
+ if (seenHeaders.has(normalizedHeaderName)) return `${label} headers must be unique when compared case-insensitively.`;
173
+ if (RESERVED_HEADER_NAMES.has(normalizedHeaderName)) return `${label} headers cannot include the reserved header '${headerName}'.`;
174
+ seenHeaders.add(normalizedHeaderName);
175
+ }
176
+ return null;
177
+ };
178
+ const validateSendDkim = (dkim, label) => {
179
+ if (!dkim) return null;
180
+ if (dkim.domain && !dkim.selector) return `${label} DKIM domain requires a selector.`;
181
+ if (dkim.privateKey && (!dkim.domain || !dkim.selector)) return `${label} DKIM privateKey requires both a domain and selector.`;
182
+ return null;
183
+ };
184
+ const mapDkimKey = (key) => ({
185
+ algorithm: key.algorithm,
186
+ createdAt: key.created_at,
187
+ dnsRecords: key.dkim_dns_records,
188
+ domain: key.domain,
189
+ gracePeriodExpiresAt: key.gracePeriodExpiresAt,
190
+ length: key.key_length,
191
+ publicKey: key.public_key,
192
+ retiresAt: key.retiresAt,
193
+ selector: key.selector,
194
+ status: key.status,
195
+ statusModifiedAt: key.status_modified_at
196
+ });
197
+ const mapDkim = (dkim) => ({
198
+ dkim_domain: dkim?.domain,
199
+ dkim_private_key: dkim?.privateKey ? stripPemHeaders(dkim.privateKey) : void 0,
200
+ dkim_selector: dkim?.selector
201
+ });
202
+ const mapPersonalization = (personalization, index) => {
203
+ const to = parseArrayRecipients(personalization.to);
204
+ if (!to || !to.length) return `Personalization at index ${index} must include at least one recipient in the \`to\` field.`;
205
+ if (to.length > 1e3) return `Personalization at index ${index} cannot include more than 1000 \`to\` recipients.`;
206
+ const cc = parseArrayRecipients(personalization.cc);
207
+ if (cc && cc.length > 1e3) return `Personalization at index ${index} cannot include more than 1000 \`cc\` recipients.`;
208
+ const bcc = parseArrayRecipients(personalization.bcc);
209
+ if (bcc && bcc.length > 1e3) return `Personalization at index ${index} cannot include more than 1000 \`bcc\` recipients.`;
210
+ const headerError = validateHeaderMap(personalization.headers, `Personalization at index ${index}`);
211
+ if (headerError) return headerError;
212
+ const dkimError = validateSendDkim(personalization.dkim, `Personalization at index ${index}`);
213
+ if (dkimError) return dkimError;
214
+ return {
215
+ bcc,
216
+ cc,
217
+ ...mapDkim(personalization.dkim),
218
+ dynamic_template_data: personalization.mustaches,
219
+ envelope_from: parseRecipient(personalization.envelopeFrom),
220
+ from: parseRecipient(personalization.from),
221
+ headers: personalization.headers,
222
+ reply_to: parseRecipient(personalization.replyTo),
223
+ subject: personalization.subject,
224
+ to
225
+ };
226
+ };
227
+ const buildSendPayload = (options) => {
228
+ const { from, html, text } = options;
229
+ const parsedFrom = parseRecipient(from);
230
+ if (!parsedFrom || !parsedFrom.email) return "No sender provided. Use the `from` option to specify a sender";
231
+ if (!text && !html) return "No email content provided";
232
+ if (options.attachments && options.attachments.length > 1e3) return "The maximum number of attachments is 1000.";
233
+ if (options.campaignId && (options.campaignId.length > 48 || /\s/.test(options.campaignId))) return "campaignId must be 48 characters or fewer and must not contain spaces.";
234
+ const rootHeaderError = validateHeaderMap(options.headers, "Root");
235
+ if (rootHeaderError) return rootHeaderError;
236
+ const rootDkimError = validateSendDkim(options.dkim, "Root");
237
+ if (rootDkimError) return rootDkimError;
238
+ let personalizations;
239
+ if (options.personalizations) {
240
+ if (!options.personalizations.length) return "At least one personalization must be provided.";
241
+ if (options.personalizations.length > 1e3) return "The maximum number of personalizations is 1000.";
242
+ const mapped = options.personalizations.map(mapPersonalization);
243
+ const error = mapped.find((item) => typeof item === "string");
244
+ if (error) return error;
245
+ personalizations = mapped;
246
+ } else {
247
+ const parsedTo = parseArrayRecipients(options.to);
248
+ if (!parsedTo || !parsedTo.length) return "No recipients provided. Use the `to` option to specify at least one recipient";
249
+ if (parsedTo.length > 1e3) return "The maximum number of `to` recipients is 1000.";
250
+ const parsedCc = parseArrayRecipients(options.cc);
251
+ if (parsedCc && parsedCc.length > 1e3) return "The maximum number of `cc` recipients is 1000.";
252
+ const parsedBcc = parseArrayRecipients(options.bcc);
253
+ if (parsedBcc && parsedBcc.length > 1e3) return "The maximum number of `bcc` recipients is 1000.";
254
+ personalizations = [{
255
+ bcc: parsedBcc,
256
+ cc: parsedCc,
257
+ dynamic_template_data: options.mustaches,
258
+ to: parsedTo
259
+ }];
260
+ }
261
+ if (options.transactional === false) {
262
+ if (!personalizations.every((personalization) => {
263
+ const personalizationDkim = personalization.dkim_selector;
264
+ const rootDkim = options.dkim?.selector;
265
+ return Boolean(personalizationDkim || rootDkim);
266
+ })) return "Non-transactional messages must be DKIM signed.";
267
+ if (personalizations.some((personalization) => {
268
+ return getRecipientCount(personalization.to) + getRecipientCount(personalization.cc) + getRecipientCount(personalization.bcc) !== 1;
269
+ })) return "Non-transactional messages must have exactly one recipient per personalization.";
270
+ }
271
+ const content = [];
272
+ const template_type = Boolean(options.mustaches) || Boolean(options.personalizations?.some((personalization) => personalization.mustaches)) ? "mustache" : void 0;
273
+ if (text) content.push({
274
+ type: "text/plain",
275
+ value: text,
276
+ template_type
277
+ });
278
+ if (html) content.push({
279
+ type: "text/html",
280
+ value: html,
281
+ template_type
282
+ });
283
+ return {
284
+ attachments: options.attachments,
285
+ campaign_id: options.campaignId,
286
+ ...mapDkim(options.dkim),
287
+ envelope_from: parseRecipient(options.envelopeFrom),
288
+ personalizations,
289
+ headers: options.headers,
290
+ reply_to: parseRecipient(options.replyTo),
291
+ from: parsedFrom,
292
+ subject: options.subject,
293
+ content,
294
+ tracking_settings: options.tracking ? {
295
+ click_tracking: typeof options.tracking.click === "boolean" ? { enable: options.tracking.click } : void 0,
296
+ open_tracking: typeof options.tracking.open === "boolean" ? { enable: options.tracking.open } : void 0
297
+ } : void 0,
298
+ transactional: options.transactional
299
+ };
300
+ };
166
301
  var Emails = class {
167
302
  constructor(mailchannels) {
168
303
  this.mailchannels = mailchannels;
169
304
  }
170
305
  async _sendEmail(options, flags) {
171
306
  let error = null;
172
- const { cc, bcc, from, to, html, text, mustaches, dkim } = options;
173
- const parsedFrom = parseRecipient(from);
174
- if (!parsedFrom || !parsedFrom.email) {
175
- error = createError("No sender provided. Use the `from` option to specify a sender");
176
- return {
177
- success: false,
178
- data: null,
179
- error
180
- };
181
- }
182
- const parsedTo = parseArrayRecipients(to);
183
- if (!parsedTo || !parsedTo.length) {
184
- error = createError("No recipients provided. Use the `to` option to specify at least one recipient");
185
- return {
186
- success: false,
307
+ const payload = buildSendPayload(options);
308
+ if (typeof payload === "string") {
309
+ error = createError(payload);
310
+ if (flags.async) return {
187
311
  data: null,
188
312
  error
189
313
  };
190
- }
191
- if (!text && !html) {
192
- error = createError("No email content provided");
193
314
  return {
194
315
  success: false,
195
316
  data: null,
196
317
  error
197
318
  };
198
319
  }
199
- const content = [];
200
- const template_type = mustaches ? "mustache" : void 0;
201
- if (text) content.push({
202
- type: "text/plain",
203
- value: text,
204
- template_type
205
- });
206
- if (html) content.push({
207
- type: "text/html",
208
- value: html,
209
- template_type
210
- });
211
- const payload = {
212
- attachments: options.attachments,
213
- campaign_id: options.campaignId,
214
- personalizations: [{
215
- bcc: parseArrayRecipients(bcc),
216
- cc: parseArrayRecipients(cc),
217
- to: parsedTo,
218
- dkim_domain: dkim?.domain || void 0,
219
- dkim_private_key: dkim?.privateKey ? stripPemHeaders(dkim.privateKey) : void 0,
220
- dkim_selector: dkim?.selector || void 0,
221
- dynamic_template_data: options.mustaches
222
- }],
223
- headers: options.headers,
224
- reply_to: parseRecipient(options.replyTo),
225
- envelope_from: parseRecipient(options.envelopeFrom),
226
- from: parsedFrom,
227
- subject: options.subject,
228
- content,
229
- tracking_settings: options.tracking ? {
230
- click_tracking: options.tracking.click ? { enable: options.tracking.click } : void 0,
231
- open_tracking: options.tracking.open ? { enable: options.tracking.open } : void 0
232
- } : void 0,
233
- transactional: options.transactional
234
- };
235
320
  const endpoint = flags.async ? "/tx/v1/send-async" : "/tx/v1/send";
236
321
  const response = await this.mailchannels.post(endpoint, {
237
322
  query: { "dry-run": flags.dryRun },
@@ -279,67 +364,32 @@ var Emails = class {
279
364
  error: null
280
365
  };
281
366
  }
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
367
  async send(options, dryRun = false) {
298
368
  return this._sendEmail(options, { dryRun });
299
369
  }
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
370
  async sendAsync(options) {
319
371
  return this._sendEmail(options, { async: true });
320
372
  }
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
373
  async checkDomain(options) {
339
374
  let error = null;
340
375
  const { dkim, domain, senderId } = options;
376
+ const dkimOptions = dkim ? Array.isArray(dkim) ? dkim : [dkim] : void 0;
377
+ if (dkimOptions && dkimOptions.length > 10) {
378
+ error = createError("A maximum of 10 DKIM settings can be provided.");
379
+ return {
380
+ data: null,
381
+ error
382
+ };
383
+ }
384
+ if (dkimOptions?.find(({ privateKey, selector }) => privateKey && !selector)) {
385
+ error = createError("DKIM settings with a privateKey must also include a selector.");
386
+ return {
387
+ data: null,
388
+ error
389
+ };
390
+ }
341
391
  const payload = {
342
- dkim_settings: (dkim ? Array.isArray(dkim) ? dkim : [dkim] : void 0)?.map(({ domain, privateKey, selector }) => ({
392
+ dkim_settings: dkimOptions?.map(({ domain, privateKey, selector }) => ({
343
393
  dkim_domain: domain,
344
394
  dkim_private_key: privateKey ? stripPemHeaders(privateKey) : void 0,
345
395
  dkim_selector: selector
@@ -380,18 +430,6 @@ var Emails = class {
380
430
  error: null
381
431
  };
382
432
  }
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
433
  async createDkimKey(domain, options) {
396
434
  let error = null;
397
435
  if (!options.selector || options.selector.length > 63) {
@@ -423,34 +461,10 @@ var Emails = class {
423
461
  error
424
462
  };
425
463
  return {
426
- data: clean({
427
- algorithm: response.algorithm,
428
- createdAt: response.created_at,
429
- dnsRecords: response.dkim_dns_records,
430
- domain: response.domain,
431
- gracePeriodExpiresAt: response.gracePeriodExpiresAt,
432
- length: response.key_length,
433
- publicKey: response.public_key,
434
- retiresAt: response.retiresAt,
435
- selector: response.selector,
436
- status: response.status,
437
- statusModifiedAt: response.status_modified_at
438
- }),
464
+ data: clean(mapDkimKey(response)),
439
465
  error: null
440
466
  };
441
467
  }
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
468
  async getDkimKeys(domain, options) {
455
469
  let error = null;
456
470
  if (options?.selector && options.selector.length > 63) {
@@ -489,34 +503,10 @@ var Emails = class {
489
503
  error
490
504
  };
491
505
  return {
492
- data: clean(response.keys.map((key) => ({
493
- algorithm: key.algorithm,
494
- createdAt: key.created_at,
495
- dnsRecords: key.dkim_dns_records,
496
- domain: key.domain,
497
- gracePeriodExpiresAt: key.gracePeriodExpiresAt,
498
- length: key.key_length,
499
- publicKey: key.public_key,
500
- retiresAt: key.retiresAt,
501
- selector: key.selector,
502
- status: key.status,
503
- statusModifiedAt: key.status_modified_at
504
- }))),
506
+ data: clean(response.keys.map(mapDkimKey)),
505
507
  error: null
506
508
  };
507
509
  }
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
510
  async updateDkimKey(domain, options) {
521
511
  let error = null;
522
512
  if (!options.selector || options.selector.length > 63) {
@@ -543,22 +533,6 @@ var Emails = class {
543
533
  error
544
534
  };
545
535
  }
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
536
  async rotateDkimKey(domain, selector, options) {
563
537
  let error = null;
564
538
  if (!selector || selector.length > 63) {
@@ -595,32 +569,8 @@ var Emails = class {
595
569
  };
596
570
  return {
597
571
  data: clean({
598
- new: {
599
- algorithm: response.new_key.algorithm,
600
- createdAt: response.new_key.created_at,
601
- dnsRecords: response.new_key.dkim_dns_records,
602
- domain: response.new_key.domain,
603
- gracePeriodExpiresAt: response.new_key.gracePeriodExpiresAt,
604
- length: response.new_key.key_length,
605
- publicKey: response.new_key.public_key,
606
- retiresAt: response.new_key.retiresAt,
607
- selector: response.new_key.selector,
608
- status: response.new_key.status,
609
- statusModifiedAt: response.new_key.status_modified_at
610
- },
611
- rotated: {
612
- algorithm: response.rotated_key.algorithm,
613
- createdAt: response.rotated_key.created_at,
614
- dnsRecords: response.rotated_key.dkim_dns_records,
615
- domain: response.rotated_key.domain,
616
- gracePeriodExpiresAt: response.rotated_key.gracePeriodExpiresAt,
617
- length: response.rotated_key.key_length,
618
- publicKey: response.rotated_key.public_key,
619
- retiresAt: response.rotated_key.retiresAt,
620
- selector: response.rotated_key.selector,
621
- status: response.rotated_key.status,
622
- statusModifiedAt: response.rotated_key.status_modified_at
623
- }
572
+ new: mapDkimKey(response.new_key),
573
+ rotated: mapDkimKey(response.rotated_key)
624
574
  }),
625
575
  error: null
626
576
  };
@@ -635,7 +585,6 @@ const ED25519 = {
635
585
  namedCurve: "Ed25519"
636
586
  };
637
587
  const encoder = new TextEncoder();
638
- const DEFAULT_TOLERANCE = 300;
639
588
  const HEADER_CONTENT_DIGEST = "content-digest";
640
589
  const HEADER_SIGNATURE = "signature";
641
590
  const HEADER_SIGNATURE_INPUT = "signature-input";
@@ -673,7 +622,7 @@ async function isValidWebhook(options) {
673
622
  if (!signature) return false;
674
623
  const values = extractInputValues(signatureInput);
675
624
  if (!values) return false;
676
- if (Math.floor(Date.now() / 1e3) - values.timestamp > DEFAULT_TOLERANCE) return false;
625
+ if (Math.floor(Date.now() / 1e3) - values.timestamp > 300) return false;
677
626
  const signingString = `"content-digest": ${contentDigest}
678
627
  "@signature-params": ("content-digest");created=${values.timestamp};alg="${values.algorithm}";keyid="${values.keyId}"`;
679
628
  let publicKey = options.publicKey;
@@ -697,15 +646,6 @@ var Webhooks = class Webhooks {
697
646
  constructor(mailchannels) {
698
647
  this.mailchannels = mailchannels;
699
648
  }
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
649
  async enroll(endpoint) {
710
650
  let error = null;
711
651
  if (!endpoint) {
@@ -735,14 +675,6 @@ var Webhooks = class Webhooks {
735
675
  error
736
676
  };
737
677
  }
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
678
  async list() {
747
679
  let error = null;
748
680
  const response = await this.mailchannels.get("/tx/v1/webhook", { onResponseError: async ({ response }) => {
@@ -760,14 +692,6 @@ var Webhooks = class Webhooks {
760
692
  error: null
761
693
  };
762
694
  }
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
695
  async delete() {
772
696
  let error = null;
773
697
  await this.mailchannels.delete("/tx/v1/webhook", { onResponseError: async ({ response }) => {
@@ -780,15 +704,6 @@ var Webhooks = class Webhooks {
780
704
  error
781
705
  };
782
706
  }
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
707
  async getSigningKey(id) {
793
708
  let error = null;
794
709
  const response = await this.mailchannels.get("/tx/v1/webhook/public-key", {
@@ -815,15 +730,6 @@ var Webhooks = class Webhooks {
815
730
  error: null
816
731
  };
817
732
  }
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
733
  async validate(requestId) {
828
734
  let error = null;
829
735
  if (requestId && requestId.length > 28) {
@@ -857,29 +763,85 @@ var Webhooks = class Webhooks {
857
763
  error: null
858
764
  };
859
765
  }
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
766
  static async verify(options) {
869
767
  return isValidWebhook(options).catch(() => false);
870
768
  }
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
769
  async verify(options) {
881
770
  return Webhooks.verify(options);
882
771
  }
772
+ async batches(options) {
773
+ let error = null;
774
+ error = validatePagination({
775
+ ...options,
776
+ max: 500
777
+ });
778
+ if (error) return {
779
+ data: null,
780
+ error
781
+ };
782
+ if (options?.statuses && options.statuses.length > 6) return {
783
+ data: null,
784
+ error: createError("A maximum of 6 status filters can be provided.")
785
+ };
786
+ if (options?.statuses && new Set(options.statuses).size !== options.statuses.length) return {
787
+ data: null,
788
+ error: createError("Status filters must be unique.")
789
+ };
790
+ if (options?.createdAfter && Number.isNaN(Date.parse(options.createdAfter))) return {
791
+ data: null,
792
+ error: createError("createdAfter must be a valid date string.")
793
+ };
794
+ if (options?.createdBefore && Number.isNaN(Date.parse(options.createdBefore))) return {
795
+ data: null,
796
+ error: createError("createdBefore must be a valid date string.")
797
+ };
798
+ if (options?.createdAfter && options?.createdBefore) {
799
+ const createdAfter = Date.parse(options.createdAfter);
800
+ const createdBefore = Date.parse(options.createdBefore);
801
+ const maxRangeMs = 744 * 60 * 60 * 1e3;
802
+ if (createdBefore <= createdAfter) return {
803
+ data: null,
804
+ error: createError("createdBefore must be later than createdAfter.")
805
+ };
806
+ if (createdBefore - createdAfter > maxRangeMs) return {
807
+ data: null,
808
+ error: createError("The time range between createdAfter and createdBefore must not exceed 31 days.")
809
+ };
810
+ }
811
+ const response = await this.mailchannels.get("/tx/v1/webhook-batch", {
812
+ query: {
813
+ created_after: options?.createdAfter,
814
+ created_before: options?.createdBefore,
815
+ statuses: options?.statuses,
816
+ webhook: options?.webhook,
817
+ limit: options?.limit,
818
+ offset: options?.offset
819
+ },
820
+ onResponseError: async ({ response }) => {
821
+ error = getStatusError(response, { [ErrorCode.BadRequest]: "Bad Request." });
822
+ }
823
+ }).catch((e) => {
824
+ error ||= getResultError(e, "Failed to fetch webhook batches.");
825
+ return null;
826
+ });
827
+ if (!response) return {
828
+ data: null,
829
+ error
830
+ };
831
+ return {
832
+ data: clean(response.webhook_batches.map((batch) => ({
833
+ batchId: batch.batch_id,
834
+ createdAt: batch.created_at,
835
+ customerHandle: batch.customer_handle,
836
+ duration: batch.duration,
837
+ eventCount: batch.event_count,
838
+ status: batch.status,
839
+ statusCode: batch.status_code,
840
+ webhook: batch.webhook
841
+ }))),
842
+ error: null
843
+ };
844
+ }
883
845
  };
884
846
  var SubAccounts = class SubAccounts {
885
847
  static COMPANY_PATTERN = /^.{3,128}$/;
@@ -887,16 +849,6 @@ var SubAccounts = class SubAccounts {
887
849
  constructor(mailchannels) {
888
850
  this.mailchannels = mailchannels;
889
851
  }
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
852
  async create(companyName, handle) {
901
853
  let error = null;
902
854
  if (!SubAccounts.COMPANY_PATTERN.test(companyName)) {
@@ -943,15 +895,6 @@ var SubAccounts = class SubAccounts {
943
895
  error: null
944
896
  };
945
897
  }
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
898
  async list(options) {
956
899
  let error = null;
957
900
  error = validatePagination({
@@ -984,15 +927,6 @@ var SubAccounts = class SubAccounts {
984
927
  error: null
985
928
  };
986
929
  }
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
930
  async delete(handle) {
997
931
  let error = null;
998
932
  if (!handle) {
@@ -1012,15 +946,6 @@ var SubAccounts = class SubAccounts {
1012
946
  error
1013
947
  };
1014
948
  }
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
949
  async suspend(handle) {
1025
950
  let error = null;
1026
951
  if (!handle) {
@@ -1040,15 +965,6 @@ var SubAccounts = class SubAccounts {
1040
965
  error
1041
966
  };
1042
967
  }
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
968
  async activate(handle) {
1053
969
  let error = null;
1054
970
  if (!handle) {
@@ -1071,15 +987,6 @@ var SubAccounts = class SubAccounts {
1071
987
  error
1072
988
  };
1073
989
  }
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
990
  async createApiKey(handle) {
1084
991
  let error = null;
1085
992
  if (!handle) {
@@ -1111,16 +1018,6 @@ var SubAccounts = class SubAccounts {
1111
1018
  error: null
1112
1019
  };
1113
1020
  }
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
1021
  async listApiKeys(handle, options) {
1125
1022
  let error = null;
1126
1023
  if (!handle) {
@@ -1156,16 +1053,6 @@ var SubAccounts = class SubAccounts {
1156
1053
  error: null
1157
1054
  };
1158
1055
  }
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
1056
  async deleteApiKey(handle, id) {
1170
1057
  let error = null;
1171
1058
  if (!handle) {
@@ -1185,15 +1072,6 @@ var SubAccounts = class SubAccounts {
1185
1072
  error
1186
1073
  };
1187
1074
  }
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
1075
  async createSmtpPassword(handle) {
1198
1076
  let error = null;
1199
1077
  if (!handle) {
@@ -1226,15 +1104,6 @@ var SubAccounts = class SubAccounts {
1226
1104
  error: null
1227
1105
  };
1228
1106
  }
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
1107
  async listSmtpPasswords(handle) {
1239
1108
  let error = null;
1240
1109
  if (!handle) {
@@ -1263,16 +1132,6 @@ var SubAccounts = class SubAccounts {
1263
1132
  error: null
1264
1133
  };
1265
1134
  }
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
1135
  async deleteSmtpPassword(handle, id) {
1277
1136
  let error = null;
1278
1137
  if (!handle) {
@@ -1292,15 +1151,6 @@ var SubAccounts = class SubAccounts {
1292
1151
  error
1293
1152
  };
1294
1153
  }
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
1154
  async getLimit(handle) {
1305
1155
  let error = null;
1306
1156
  if (!handle) {
@@ -1325,16 +1175,6 @@ var SubAccounts = class SubAccounts {
1325
1175
  error: null
1326
1176
  };
1327
1177
  }
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
1178
  async setLimit(handle, limit) {
1339
1179
  let error = null;
1340
1180
  if (!handle) {
@@ -1360,15 +1200,6 @@ var SubAccounts = class SubAccounts {
1360
1200
  error
1361
1201
  };
1362
1202
  }
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
1203
  async deleteLimit(handle) {
1373
1204
  let error = null;
1374
1205
  if (!handle) {
@@ -1388,15 +1219,6 @@ var SubAccounts = class SubAccounts {
1388
1219
  error
1389
1220
  };
1390
1221
  }
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
1222
  async getUsage(handle) {
1401
1223
  let error = null;
1402
1224
  if (!handle) {
@@ -1430,15 +1252,6 @@ var Metrics = class {
1430
1252
  constructor(mailchannels) {
1431
1253
  this.mailchannels = mailchannels;
1432
1254
  }
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
1255
  async engagement(options) {
1443
1256
  let error = null;
1444
1257
  const response = await this.mailchannels.get("/tx/v1/metrics/engagement", {
@@ -1477,15 +1290,6 @@ var Metrics = class {
1477
1290
  error: null
1478
1291
  };
1479
1292
  }
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
1293
  async performance(options) {
1490
1294
  let error = null;
1491
1295
  const response = await this.mailchannels.get("/tx/v1/metrics/performance", {
@@ -1522,15 +1326,6 @@ var Metrics = class {
1522
1326
  error: null
1523
1327
  };
1524
1328
  }
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
1329
  async recipientBehaviour(options) {
1535
1330
  let error = null;
1536
1331
  const response = await this.mailchannels.get("/tx/v1/metrics/recipient-behaviour", {
@@ -1565,15 +1360,6 @@ var Metrics = class {
1565
1360
  error: null
1566
1361
  };
1567
1362
  }
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
1363
  async volume(options) {
1578
1364
  let error = null;
1579
1365
  const response = await this.mailchannels.get("/tx/v1/metrics/volume", {
@@ -1610,14 +1396,6 @@ var Metrics = class {
1610
1396
  error: null
1611
1397
  };
1612
1398
  }
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
1399
  async usage() {
1622
1400
  let error = null;
1623
1401
  const response = await this.mailchannels.get("/tx/v1/usage", { onResponseError: async ({ response }) => {
@@ -1639,16 +1417,6 @@ var Metrics = class {
1639
1417
  error: null
1640
1418
  };
1641
1419
  }
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
1420
  async senders(type, options) {
1653
1421
  let error = null;
1654
1422
  error = validatePagination({
@@ -1695,16 +1463,6 @@ var Suppressions = class {
1695
1463
  constructor(mailchannels) {
1696
1464
  this.mailchannels = mailchannels;
1697
1465
  }
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
1466
  async create(options) {
1709
1467
  let error = null;
1710
1468
  const { addToSubAccounts, entries } = options;
@@ -1733,16 +1491,6 @@ var Suppressions = class {
1733
1491
  error
1734
1492
  };
1735
1493
  }
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
1494
  async delete(recipient, source) {
1747
1495
  let error = null;
1748
1496
  await this.mailchannels.delete(`/tx/v1/suppression-list/recipients/${recipient}`, {
@@ -1758,15 +1506,6 @@ var Suppressions = class {
1758
1506
  error
1759
1507
  };
1760
1508
  }
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
1509
  async list(options) {
1771
1510
  let error = null;
1772
1511
  error = validatePagination({
@@ -1815,18 +1554,6 @@ var Domains = class {
1815
1554
  constructor(mailchannels) {
1816
1555
  this.mailchannels = mailchannels;
1817
1556
  }
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
1557
  async provision(options) {
1831
1558
  let error = null;
1832
1559
  const { associateKey, overwrite, ...payload } = options;
@@ -1856,26 +1583,6 @@ var Domains = class {
1856
1583
  error: null
1857
1584
  };
1858
1585
  }
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
1586
  async bulkProvision(options, domains) {
1880
1587
  let error = null;
1881
1588
  const { associateKey, overwrite, subscriptionHandle } = options;
@@ -1919,15 +1626,6 @@ var Domains = class {
1919
1626
  error: null
1920
1627
  };
1921
1628
  }
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
1629
  async list(options) {
1932
1630
  let error = null;
1933
1631
  error = validatePagination({
@@ -1959,15 +1657,6 @@ var Domains = class {
1959
1657
  error: null
1960
1658
  };
1961
1659
  }
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
1660
  async delete(domain) {
1972
1661
  let error = null;
1973
1662
  if (!domain) {
@@ -1990,19 +1679,6 @@ var Domains = class {
1990
1679
  error
1991
1680
  };
1992
1681
  }
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
1682
  async addListEntry(domain, options) {
2007
1683
  const { listName, item } = options;
2008
1684
  let error = null;
@@ -2045,16 +1721,6 @@ var Domains = class {
2045
1721
  error: null
2046
1722
  };
2047
1723
  }
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
1724
  async listEntries(domain, listName) {
2059
1725
  let error = null;
2060
1726
  if (!domain) {
@@ -2093,19 +1759,6 @@ var Domains = class {
2093
1759
  error: null
2094
1760
  };
2095
1761
  }
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
1762
  async deleteListEntry(domain, options) {
2110
1763
  const { listName, item } = options;
2111
1764
  let error = null;
@@ -2139,15 +1792,6 @@ var Domains = class {
2139
1792
  error
2140
1793
  };
2141
1794
  }
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
1795
  async createLoginLink(domain) {
2152
1796
  let error = null;
2153
1797
  if (!domain) {
@@ -2176,23 +1820,6 @@ var Domains = class {
2176
1820
  error: null
2177
1821
  };
2178
1822
  }
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
1823
  async setDownstreamAddress(domain, records) {
2197
1824
  let error = null;
2198
1825
  if (!domain) {
@@ -2232,16 +1859,6 @@ var Domains = class {
2232
1859
  error
2233
1860
  };
2234
1861
  }
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
1862
  async listDownstreamAddresses(domain, options) {
2246
1863
  let error = null;
2247
1864
  if (!domain) {
@@ -2277,16 +1894,6 @@ var Domains = class {
2277
1894
  error: null
2278
1895
  };
2279
1896
  }
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
1897
  async updateApiKey(domain, key) {
2291
1898
  let error = null;
2292
1899
  if (!domain) {
@@ -2319,15 +1926,6 @@ var Domains = class {
2319
1926
  error
2320
1927
  };
2321
1928
  }
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
1929
  async bulkCreateLoginLinks(domains) {
2332
1930
  let error = null;
2333
1931
  if (!domains || !domains.length) {
@@ -2367,18 +1965,6 @@ var Lists = class {
2367
1965
  constructor(mailchannels) {
2368
1966
  this.mailchannels = mailchannels;
2369
1967
  }
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
1968
  async addListEntry(options) {
2383
1969
  let error = null;
2384
1970
  const { listName, item } = options;
@@ -2411,15 +1997,6 @@ var Lists = class {
2411
1997
  error: null
2412
1998
  };
2413
1999
  }
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
2000
  async listEntries(listName) {
2424
2001
  let error = null;
2425
2002
  if (!listName) {
@@ -2448,18 +2025,6 @@ var Lists = class {
2448
2025
  error: null
2449
2026
  };
2450
2027
  }
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
2028
  async deleteListEntry(options) {
2464
2029
  const { listName, item } = options;
2465
2030
  let error = null;
@@ -2488,18 +2053,6 @@ var Users = class {
2488
2053
  constructor(mailchannels) {
2489
2054
  this.mailchannels = mailchannels;
2490
2055
  }
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
2056
  async create(email, options) {
2504
2057
  const { admin, filter, listEntries } = options || {};
2505
2058
  let error = null;
@@ -2542,19 +2095,6 @@ var Users = class {
2542
2095
  error: null
2543
2096
  };
2544
2097
  }
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
2098
  async addListEntry(email, options) {
2559
2099
  const { listName, item } = options;
2560
2100
  let error = null;
@@ -2597,16 +2137,6 @@ var Users = class {
2597
2137
  error: null
2598
2138
  };
2599
2139
  }
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
2140
  async listEntries(email, listName) {
2611
2141
  let error = null;
2612
2142
  if (!email) {
@@ -2645,19 +2175,6 @@ var Users = class {
2645
2175
  error: null
2646
2176
  };
2647
2177
  }
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
2178
  async deleteListEntry(email, options) {
2662
2179
  const { listName, item } = options;
2663
2180
  let error = null;
@@ -2696,14 +2213,6 @@ var Service = class {
2696
2213
  constructor(mailchannels) {
2697
2214
  this.mailchannels = mailchannels;
2698
2215
  }
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
2216
  async status() {
2708
2217
  let error = null;
2709
2218
  await this.mailchannels.get("/inbound/v1/status", { onResponseError: async ({ response }) => {
@@ -2716,14 +2225,6 @@ var Service = class {
2716
2225
  error
2717
2226
  };
2718
2227
  }
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
2228
  async subscriptions() {
2728
2229
  let error = null;
2729
2230
  const response = await this.mailchannels.get("/inbound/v1/subscriptions", { onResponseError: async ({ response }) => {
@@ -2741,17 +2242,6 @@ var Service = class {
2741
2242
  error: null
2742
2243
  };
2743
2244
  }
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
2245
  async report(options) {
2756
2246
  let error = null;
2757
2247
  const { type, ...payload } = options;
@@ -2780,8 +2270,8 @@ var MailChannels = class extends MailChannelsClient {
2780
2270
  lists = new Lists(this);
2781
2271
  users = new Users(this);
2782
2272
  service = new Service(this);
2783
- constructor(key) {
2784
- super(key);
2273
+ constructor(key, options) {
2274
+ super(key, options);
2785
2275
  }
2786
2276
  };
2787
2277
  export { Domains, Emails, Lists, MailChannels, MailChannelsClient, Metrics, Service, SubAccounts, Suppressions, Users, Webhooks };