@messagebird/sdk 0.49.0 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1057,16 +1057,21 @@ type EmailMessageSendRequest = {
1057
1057
  */
1058
1058
  attachments?: Array<EmailAttachment>;
1059
1059
  /**
1060
- * Schedule the message to send at a future time instead of immediately. Must be at least 30 seconds and at most 30 days ahead. Outside that range the request is rejected with `422`. The message returns with status `accepted` and shows as `scheduled` on reads until it sends. Cancel it before then with the message cancel endpoint. Scheduled sends count against your plan's monthly scheduled-email allowance. Exceeding it is rejected with a `422`. A scheduled message has inline content: `scheduled_at` and `template` are mutually exclusive, and combining them is rejected with a `422`. This field is accepted only on a single send. Batch items reject it.
1060
+ * Schedule the message to send at a future time instead of immediately. Must be at least 30 seconds and at most 30 days ahead. Outside that range the request is rejected with `422`. The message returns with status `accepted` and shows as `scheduled` on reads until it sends. Cancel it before then with the message cancel endpoint. Scheduled sends count against your plan's monthly scheduled-email allowance. Exceeding it is rejected with a `422`. A scheduled message has inline content: `scheduled_at` and `template` are mutually exclusive, and combining them is rejected with a `422`. Batch items take this field too, so one batch can mix scheduled and immediate messages.
1061
1061
  *
1062
1062
  */
1063
1063
  scheduled_at?: string;
1064
1064
  };
1065
1065
  /**
1066
- * Batch of email message send requests. All items are validated before any are queued. Attachments are allowed on individual messages. Each message must stay within the 20 MB estimated generated message-size cap. The serialized JSON request body for the batch has a hard 20 MB cap.
1067
- *
1066
+ * Batch of email message send requests.
1068
1067
  */
1069
- type EmailMessageBatchRequest = Array<EmailMessageSendRequest>;
1068
+ type EmailMessageBatchRequest = {
1069
+ /**
1070
+ * Email message send requests, up to 100. All items are validated before any are queued. Attachments are allowed on individual messages. Each message must stay within the 20 MB estimated generated message-size cap. The serialized JSON request body for the batch has a hard 20 MB cap.
1071
+ *
1072
+ */
1073
+ messages: Array<EmailMessageSendRequest>;
1074
+ };
1070
1075
  type EmailMessageBatchItem = {
1071
1076
  /**
1072
1077
  * Message ID assigned to this batch item.
@@ -1885,9 +1890,14 @@ type SmsMessageSendRequest = unknown & {
1885
1890
  };
1886
1891
  };
1887
1892
  /**
1888
- * Batch of SMS message send requests. All items are validated before any are queued.
1893
+ * Batch of SMS message send requests.
1889
1894
  */
1890
- type SmsMessageBatchRequest = Array<SmsMessageSendRequest>;
1895
+ type SmsMessageBatchRequest = {
1896
+ /**
1897
+ * SMS message send requests, up to 100. Each is an independent send; all are validated before any is queued.
1898
+ */
1899
+ messages: Array<SmsMessageSendRequest>;
1900
+ };
1891
1901
  /**
1892
1902
  * Aggregate result for an SMS batch.
1893
1903
  */
@@ -13061,8 +13071,10 @@ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
13061
13071
  type DefaultedKeys<D> = D extends object ? Extract<keyof D, keyof EmailMessageSendRequest> : never;
13062
13072
  /** `send` params with defaulted fields made optional. */
13063
13073
  type EmailSend<D> = PartialBy<EmailMessageSendRequest, DefaultedKeys<D>>;
13064
- /** `sendBatch` params — every item relaxed the same way `send` is. */
13065
- type EmailSendBatch<D> = Array<EmailSend<D>>;
13074
+ /** `sendBatch` params — every item under `messages` relaxed the same way `send` is. */
13075
+ type EmailSendBatch<D> = {
13076
+ messages: Array<EmailSend<D>>;
13077
+ };
13066
13078
  //#endregion
13067
13079
  //#region src/resources/emailStats.gen.d.ts
13068
13080
  type EmailStatsSummaryQuery = NonNullable<GetEmailStatsSummaryData["query"]>;
@@ -13615,24 +13627,29 @@ declare class EmailResource<D extends EmailChannelDefaults | undefined = undefin
13615
13627
  * is accepted (the API's 202). Channel defaults are applied per item, so a
13616
13628
  * field set as a default may be omitted from every item (per-item value wins).
13617
13629
  *
13630
+ * Passing a bare array of sends is deprecated — wrap them in
13631
+ * `{ messages: [...] }`.
13632
+ *
13618
13633
  * @example Send a batch of messages
13619
- * const batch = await bird.email.sendBatch([
13620
- * {
13621
- * from: { email: "onboarding@messagebird.dev", name: "Bird" },
13622
- * to: ["alice@example.com"],
13623
- * subject: "Your receipt",
13624
- * html: "<p>Thanks, Alice.</p>",
13625
- * },
13626
- * {
13627
- * from: { email: "onboarding@messagebird.dev", name: "Bird" },
13628
- * to: ["bob@example.com"],
13629
- * subject: "Your receipt",
13630
- * html: "<p>Thanks, Bob.</p>",
13631
- * },
13632
- * ]);
13634
+ * const batch = await bird.email.sendBatch({
13635
+ * messages: [
13636
+ * {
13637
+ * from: { email: "onboarding@messagebird.dev", name: "Bird" },
13638
+ * to: ["alice@example.com"],
13639
+ * subject: "Your receipt",
13640
+ * html: "<p>Thanks, Alice.</p>",
13641
+ * },
13642
+ * {
13643
+ * from: { email: "onboarding@messagebird.dev", name: "Bird" },
13644
+ * to: ["bob@example.com"],
13645
+ * subject: "Your receipt",
13646
+ * html: "<p>Thanks, Bob.</p>",
13647
+ * },
13648
+ * ],
13649
+ * });
13633
13650
  * for (const item of batch.data) console.log(item.id, item.status);
13634
13651
  */
13635
- sendBatch(params: EmailSendBatch<D>, options?: RequestOptions): APIPromise<EmailSendBatchResult>;
13652
+ sendBatch(params: EmailSendBatch<D> | Array<EmailSend<D>>, options?: RequestOptions): APIPromise<EmailSendBatchResult>;
13636
13653
  }
13637
13654
  //#endregion
13638
13655
  //#region src/resources/audiences.gen.d.ts
@@ -14284,26 +14301,32 @@ declare class SmsResource extends SmsResourceBase {
14284
14301
  */
14285
14302
  send(params: SmsSendParams, options?: RequestOptions): APIPromise<SmsMessage>;
14286
14303
  /**
14287
- * Send up to 100 independent SMS messages in one call. Each item is a full send
14288
- * (free text or template); all items are validated before any are queued.
14304
+ * Send up to 100 independent SMS messages in one call. Each item under
14305
+ * `messages` is a full send (free text or template); all items are validated
14306
+ * before any are queued.
14307
+ *
14308
+ * Passing a bare array of sends is deprecated — wrap them in
14309
+ * `{ messages: [...] }`.
14289
14310
  *
14290
14311
  * @example
14291
- * const result = await bird.sms.sendBatch([
14292
- * {
14293
- * from: "+15557654321",
14294
- * to: "+15551111111",
14295
- * text: "Hi Alice!",
14296
- * category: "marketing",
14297
- * },
14298
- * {
14299
- * from: "+15557654321",
14300
- * to: "+15552222222",
14301
- * text: "Hi Bob!",
14302
- * category: "marketing",
14303
- * },
14304
- * ]);
14312
+ * const result = await bird.sms.sendBatch({
14313
+ * messages: [
14314
+ * {
14315
+ * from: "+15557654321",
14316
+ * to: "+15551111111",
14317
+ * text: "Hi Alice!",
14318
+ * category: "marketing",
14319
+ * },
14320
+ * {
14321
+ * from: "+15557654321",
14322
+ * to: "+15552222222",
14323
+ * text: "Hi Bob!",
14324
+ * category: "marketing",
14325
+ * },
14326
+ * ],
14327
+ * });
14305
14328
  */
14306
- sendBatch(params: SmsSendBatchParams, options?: RequestOptions): APIPromise<SmsSendBatchResult>;
14329
+ sendBatch(params: SmsSendBatchParams | SmsSendParams[], options?: RequestOptions): APIPromise<SmsSendBatchResult>;
14307
14330
  }
14308
14331
  //#endregion
14309
14332
  //#region src/resources/smsKeywordRules.gen.d.ts
package/dist/index.mjs CHANGED
@@ -1502,7 +1502,7 @@ const createEmailMessage = (options) => (options.client ?? client).post({
1502
1502
  /**
1503
1503
  * Create a batch of email messages
1504
1504
  *
1505
- * Accepts up to 100 independent email messages and queues them for delivery. All items are validated before any are queued: if one fails validation, the entire batch is rejected. Field-level validation failures and business-rule failures, such as sending from a domain that is not verified, both return `422`. None of the items can set `scheduled_at`; schedule a single message with [Create an email message](/docs/api/reference/create-email-message) instead. Suppression is evaluated per recipient after acceptance, never as a synchronous error. The `202` response returns one entry per message in submission order, each with its own `id` you can use to fetch that message or match it against webhook events. Attachments are allowed per message. Each message must stay within the 20 MB estimated generated message-size cap, and the serialized JSON request body for the whole batch has a hard 20 MB cap.
1505
+ * Accepts up to 100 independent email messages and queues them for delivery. All items are validated before any are queued: if one fails validation, the entire batch is rejected. Field-level validation failures and business-rule failures, such as sending from a domain that is not verified, both return `422`. An item can set `scheduled_at` to send it later, on the same terms as a single scheduled send, and one batch can mix scheduled and immediate messages. Cancel a scheduled item before it sends with [Cancel an email message](/docs/api/reference/cancel-email-message). Suppression is evaluated per recipient after acceptance, never as a synchronous error. The `202` response returns one entry per message in submission order, each with its own `id` you can use to fetch that message or match it against webhook events. Attachments are allowed per message. Each message must stay within the 20 MB estimated generated message-size cap, and the serialized JSON request body for the whole batch has a hard 20 MB cap.
1506
1506
  *
1507
1507
  */
1508
1508
  const createEmailMessageBatch = (options) => (options.client ?? client).post({
@@ -5427,25 +5427,30 @@ var EmailResource = class extends EmailResourceBase {
5427
5427
  * is accepted (the API's 202). Channel defaults are applied per item, so a
5428
5428
  * field set as a default may be omitted from every item (per-item value wins).
5429
5429
  *
5430
+ * Passing a bare array of sends is deprecated — wrap them in
5431
+ * `{ messages: [...] }`.
5432
+ *
5430
5433
  * @example Send a batch of messages
5431
- * const batch = await bird.email.sendBatch([
5432
- * {
5433
- * from: { email: "onboarding@messagebird.dev", name: "Bird" },
5434
- * to: ["alice@example.com"],
5435
- * subject: "Your receipt",
5436
- * html: "<p>Thanks, Alice.</p>",
5437
- * },
5438
- * {
5439
- * from: { email: "onboarding@messagebird.dev", name: "Bird" },
5440
- * to: ["bob@example.com"],
5441
- * subject: "Your receipt",
5442
- * html: "<p>Thanks, Bob.</p>",
5443
- * },
5444
- * ]);
5434
+ * const batch = await bird.email.sendBatch({
5435
+ * messages: [
5436
+ * {
5437
+ * from: { email: "onboarding@messagebird.dev", name: "Bird" },
5438
+ * to: ["alice@example.com"],
5439
+ * subject: "Your receipt",
5440
+ * html: "<p>Thanks, Alice.</p>",
5441
+ * },
5442
+ * {
5443
+ * from: { email: "onboarding@messagebird.dev", name: "Bird" },
5444
+ * to: ["bob@example.com"],
5445
+ * subject: "Your receipt",
5446
+ * html: "<p>Thanks, Bob.</p>",
5447
+ * },
5448
+ * ],
5449
+ * });
5445
5450
  * for (const item of batch.data) console.log(item.id, item.status);
5446
5451
  */
5447
5452
  sendBatch(params, options) {
5448
- const body = params.map((item) => withDefaults(this.#defaults, item));
5453
+ const body = { messages: (Array.isArray(params) ? params : params.messages).map((item) => withDefaults(this.#defaults, item)) };
5449
5454
  return this.call("POST", options, ({ signal, headers }) => createEmailMessageBatch({
5450
5455
  client: this.client,
5451
5456
  body,
@@ -6465,29 +6470,36 @@ var SmsResource = class extends SmsResourceBase {
6465
6470
  }));
6466
6471
  }
6467
6472
  /**
6468
- * Send up to 100 independent SMS messages in one call. Each item is a full send
6469
- * (free text or template); all items are validated before any are queued.
6473
+ * Send up to 100 independent SMS messages in one call. Each item under
6474
+ * `messages` is a full send (free text or template); all items are validated
6475
+ * before any are queued.
6476
+ *
6477
+ * Passing a bare array of sends is deprecated — wrap them in
6478
+ * `{ messages: [...] }`.
6470
6479
  *
6471
6480
  * @example
6472
- * const result = await bird.sms.sendBatch([
6473
- * {
6474
- * from: "+15557654321",
6475
- * to: "+15551111111",
6476
- * text: "Hi Alice!",
6477
- * category: "marketing",
6478
- * },
6479
- * {
6480
- * from: "+15557654321",
6481
- * to: "+15552222222",
6482
- * text: "Hi Bob!",
6483
- * category: "marketing",
6484
- * },
6485
- * ]);
6481
+ * const result = await bird.sms.sendBatch({
6482
+ * messages: [
6483
+ * {
6484
+ * from: "+15557654321",
6485
+ * to: "+15551111111",
6486
+ * text: "Hi Alice!",
6487
+ * category: "marketing",
6488
+ * },
6489
+ * {
6490
+ * from: "+15557654321",
6491
+ * to: "+15552222222",
6492
+ * text: "Hi Bob!",
6493
+ * category: "marketing",
6494
+ * },
6495
+ * ],
6496
+ * });
6486
6497
  */
6487
6498
  sendBatch(params, options) {
6499
+ const body = Array.isArray(params) ? { messages: params } : params;
6488
6500
  return this.call("POST", options, ({ signal, headers }) => createSmsMessageBatch({
6489
6501
  client: this.client,
6490
- body: params,
6502
+ body,
6491
6503
  headers,
6492
6504
  signal
6493
6505
  }));
@@ -7927,9 +7939,9 @@ var BirdClient = class {
7927
7939
  this.#headers = {
7928
7940
  ...opts.defaultHeaders,
7929
7941
  ...opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {},
7930
- "User-Agent": `bird-sdk-js/0.49.0`,
7942
+ "User-Agent": `bird-sdk-js/0.51.0`,
7931
7943
  "Bird-Surface": "sdk-js",
7932
- "Bird-Version": "0.49.0"
7944
+ "Bird-Version": "0.51.0"
7933
7945
  };
7934
7946
  const caller = detectCaller();
7935
7947
  if (caller) this.#headers["Bird-Caller"] = caller;