@messagebird/sdk 0.37.2 → 0.38.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.mjs CHANGED
@@ -1654,6 +1654,112 @@ const updateContact = (options) => (options.client ?? client).patch({
1654
1654
  }
1655
1655
  });
1656
1656
  /**
1657
+ * List a contact's preferences
1658
+ *
1659
+ * Returns the preferences on record for the contact's current handles: rows keyed to their email address on the email channel, and to their phone number on SMS and WhatsApp. A contact with no handles, or with no statements on record, returns an empty page.
1660
+ *
1661
+ * Rows are keyed by handle, not by contact: changing a contact's email address or phone number changes which rows this returns, and the old handle's rows remain in force for anything still sent to it.
1662
+ *
1663
+ */
1664
+ const listContactPreferences = (options) => (options.client ?? client).get({
1665
+ security: [{
1666
+ scheme: "bearer",
1667
+ type: "http"
1668
+ }, {
1669
+ in: "cookie",
1670
+ name: "bird_session",
1671
+ type: "apiKey"
1672
+ }],
1673
+ url: "/v1/contacts/{contact_id}/preferences",
1674
+ ...options
1675
+ });
1676
+ /**
1677
+ * List preferences
1678
+ *
1679
+ * Returns the workspace's recorded preferences, most recently created first. Pass `channel` to narrow to one channel, and `handle` with it to look up everything on record for one address or number.
1680
+ *
1681
+ * Each row is a key's current statement. A person can hold several rows on one channel (a channel-wide opt-out next to sender-scoped ones), and the most restrictive statement is what decides whether a message goes out.
1682
+ *
1683
+ */
1684
+ const listPreferences = (options) => (options?.client ?? client).get({
1685
+ security: [{
1686
+ scheme: "bearer",
1687
+ type: "http"
1688
+ }, {
1689
+ in: "cookie",
1690
+ name: "bird_session",
1691
+ type: "apiKey"
1692
+ }],
1693
+ url: "/v1/preferences",
1694
+ ...options
1695
+ });
1696
+ /**
1697
+ * Record a preference
1698
+ *
1699
+ * Records one statement, a grant or an opt-out, for a handle on one channel. Writing is an upsert: the key is the channel, handle, and optional sender scope, and a new statement replaces the key's current one.
1700
+ *
1701
+ * Statements are ordered by when they were made, not when they arrive. A statement older than the key's current one is refused and returned with `applied: false` alongside the statement that survived; refusals are recorded on the key's history. Granting over a stored opt-out needs `consented_at` later than the opt-out, and a person's own opt-out (an unsubscribe, a stop keyword) cannot be overridden by a grant asserted on their behalf.
1702
+ *
1703
+ * A `201` means this key had no record and one was created; a `200` returns the key's surviving record, whether this statement replaced it, repeated it, or was refused.
1704
+ *
1705
+ */
1706
+ const createPreference = (options) => (options.client ?? client).post({
1707
+ security: [{
1708
+ scheme: "bearer",
1709
+ type: "http"
1710
+ }, {
1711
+ in: "cookie",
1712
+ name: "bird_session",
1713
+ type: "apiKey"
1714
+ }],
1715
+ url: "/v1/preferences",
1716
+ ...options,
1717
+ headers: {
1718
+ "Content-Type": "application/json",
1719
+ ...options.headers
1720
+ }
1721
+ });
1722
+ /**
1723
+ * Delete a preference
1724
+ *
1725
+ * Deletes a preference, returning its key to having no record, as if nothing had ever been stated. The deletion itself is kept on the key's history, so a later statement is still ordered against what was deleted.
1726
+ *
1727
+ * **A statement the person made themselves cannot be deleted.** An unsubscribe or a stop keyword is their statement to reverse: it ends when they opt back in, and attempts to delete it return `422`. To restore messaging with the person's consent, record a `granted` statement with `consented_at` evidence instead; that records the change of mind rather than erasing the opt-out.
1728
+ *
1729
+ * A delete is ordered like any statement, using the time it is received: if the record carries a statement made after that moment, the delete is refused and returned with `applied: false` alongside the surviving record. An ID that does not exist in the workspace returns `404`.
1730
+ *
1731
+ */
1732
+ const deletePreference = (options) => (options.client ?? client).delete({
1733
+ security: [{
1734
+ scheme: "bearer",
1735
+ type: "http"
1736
+ }, {
1737
+ in: "cookie",
1738
+ name: "bird_session",
1739
+ type: "apiKey"
1740
+ }],
1741
+ url: "/v1/preferences/{preference_id}",
1742
+ ...options
1743
+ });
1744
+ /**
1745
+ * Get a preference
1746
+ *
1747
+ * Returns one preference: the key it is about, the current statement on it, and the statement's provenance. An ID that does not exist in the workspace returns `404`, including after a delete, which removes the record its ID pointed at.
1748
+ *
1749
+ */
1750
+ const getPreference = (options) => (options.client ?? client).get({
1751
+ security: [{
1752
+ scheme: "bearer",
1753
+ type: "http"
1754
+ }, {
1755
+ in: "cookie",
1756
+ name: "bird_session",
1757
+ type: "apiKey"
1758
+ }],
1759
+ url: "/v1/preferences/{preference_id}",
1760
+ ...options
1761
+ });
1762
+ /**
1657
1763
  * List contact properties
1658
1764
  *
1659
1765
  * Returns a paginated list of the workspace's contact properties, newest first. Archived properties are included; check each entry's `archived` flag.
@@ -5417,7 +5523,7 @@ var ContactPropertiesResource = class extends Resource {
5417
5523
  };
5418
5524
  //#endregion
5419
5525
  //#region src/resources/contacts.gen.ts
5420
- var ContactsResource = class extends Resource {
5526
+ var ContactsResourceBase = class extends Resource {
5421
5527
  /**
5422
5528
  * List the workspace's contacts as a cursor page, newest first. Look one up by exact email, phone_number, or external_id, repeating phone_number to resolve up to 50 numbers in one call (raise limit to match), or search by email, name, or phone substring. Pass include_total for a total count.
5423
5529
  *
@@ -5524,6 +5630,138 @@ var ContactsResource = class extends Resource {
5524
5630
  }
5525
5631
  };
5526
5632
  //#endregion
5633
+ //#region src/resources/contactsPreferences.gen.ts
5634
+ var ContactsPreferencesResource = class extends Resource {
5635
+ /**
5636
+ * List the recorded messaging preferences for a contact's own handles (their email address and phone number) across every channel, as a cursor page.
5637
+ *
5638
+ * @example List a contact's own preferences
5639
+ * for await (const preference of bird.contacts.preferences.list(
5640
+ * "con_01krdgeqcxet5s7t44vh8rt9mg",
5641
+ * )) {
5642
+ * console.log(preference.channel, preference.status);
5643
+ * }
5644
+ */
5645
+ list(contactId, query, options) {
5646
+ return this.paginated("GET", options, ({ signal, headers }, cursor) => listContactPreferences({
5647
+ client: this.client,
5648
+ path: { contact_id: contactId },
5649
+ query: {
5650
+ ...query,
5651
+ starting_after: cursor ?? query?.starting_after
5652
+ },
5653
+ headers,
5654
+ signal
5655
+ }));
5656
+ }
5657
+ };
5658
+ //#endregion
5659
+ //#region src/resources/contacts.ts
5660
+ var ContactsResource = class extends ContactsResourceBase {
5661
+ /** A contact's own preferences across every channel — `bird.contacts.preferences.list(contactId)`. */
5662
+ preferences;
5663
+ constructor(core, client) {
5664
+ super(core, client);
5665
+ this.preferences = new ContactsPreferencesResource(core, client);
5666
+ }
5667
+ };
5668
+ //#endregion
5669
+ //#region src/resources/preferences.gen.ts
5670
+ var PreferencesResourceBase = class extends Resource {
5671
+ /**
5672
+ * List the workspace's stated messaging preferences (consent grants and opt-outs) as a cursor page. Filter by channel, and by handle within a channel, to look up one person before messaging them.
5673
+ *
5674
+ * @example List stated preferences for a channel
5675
+ * for await (const preference of bird.preferences.list({ channel: "sms" })) {
5676
+ * console.log(preference.handle, preference.status);
5677
+ * }
5678
+ */
5679
+ list(query, options) {
5680
+ return this.paginated("GET", options, ({ signal, headers }, cursor) => listPreferences({
5681
+ client: this.client,
5682
+ query: {
5683
+ ...query,
5684
+ starting_after: cursor ?? query?.starting_after
5685
+ },
5686
+ headers,
5687
+ signal
5688
+ }));
5689
+ }
5690
+ /**
5691
+ * Read one recorded preference by ID: the channel and handle it is about, whether it grants or revokes, how much traffic it covers, and where the statement came from.
5692
+ *
5693
+ * @example Read one preference
5694
+ * const preference = await bird.preferences.get(
5695
+ * "prf_01krdgeqcxet5s7t44vh8rt9mg",
5696
+ * );
5697
+ * console.log(preference.status, preference.coverage);
5698
+ */
5699
+ get(preferenceId, options) {
5700
+ return this.call("GET", options, ({ signal, headers }) => getPreference({
5701
+ client: this.client,
5702
+ path: { preference_id: preferenceId },
5703
+ headers,
5704
+ signal
5705
+ }));
5706
+ }
5707
+ };
5708
+ //#endregion
5709
+ //#region src/resources/preferences.ts
5710
+ var PreferencesResource = class extends PreferencesResourceBase {
5711
+ /**
5712
+ * Record one preference statement — a grant or an opt-out — for a handle on
5713
+ * one channel. Writing is an upsert by key (channel, handle, and optional
5714
+ * sender scope): statements are causally ordered, so one dated older than
5715
+ * the key's current statement is refused and returned with `applied:
5716
+ * false` rather than applied out of order. A `201` (the key had no record)
5717
+ * and a `200` (the key already had one) return the same shape either way.
5718
+ *
5719
+ * @example Record a stated opt-out
5720
+ * const result = await bird.preferences.create({
5721
+ * channel: "sms",
5722
+ * handle: "+15550001234",
5723
+ * status: "revoked",
5724
+ * });
5725
+ * console.log(result.applied, result.preference?.id);
5726
+ */
5727
+ create(params, options) {
5728
+ const { consented_at, ...rest } = params;
5729
+ const body = consented_at === void 0 ? rest : {
5730
+ ...rest,
5731
+ consented_at: consented_at instanceof Date ? consented_at.toISOString() : consented_at
5732
+ };
5733
+ return this.call("POST", options, ({ signal, headers }) => createPreference({
5734
+ client: this.client,
5735
+ body,
5736
+ headers,
5737
+ signal
5738
+ }));
5739
+ }
5740
+ /**
5741
+ * Delete a preference, returning its key to having no record. Never void:
5742
+ * the delete is ordered like any statement, so a `200` with `applied:
5743
+ * false` means a newer statement survived and is returned in `preference`
5744
+ * rather than deleted. A statement the person made themselves — an
5745
+ * unsubscribe link, a stop keyword — cannot be deleted this way; record a
5746
+ * `granted` statement with `consented_at` evidence to restore messaging
5747
+ * instead.
5748
+ *
5749
+ * @example Delete a preference
5750
+ * const result = await bird.preferences.delete("prf_01krdgeqcxet5s7t44vh8rt9mg");
5751
+ * if (!result.applied) {
5752
+ * console.log("refused — a newer statement survived:", result.preference?.status);
5753
+ * }
5754
+ */
5755
+ delete(preferenceId, options) {
5756
+ return this.call("DELETE", options, ({ signal, headers }) => deletePreference({
5757
+ client: this.client,
5758
+ path: { preference_id: preferenceId },
5759
+ headers,
5760
+ signal
5761
+ }));
5762
+ }
5763
+ };
5764
+ //#endregion
5527
5765
  //#region src/resources/sms.gen.ts
5528
5766
  var SmsResourceBase = class extends Resource {
5529
5767
  /**
@@ -7111,6 +7349,8 @@ var BirdClient = class {
7111
7349
  verify;
7112
7350
  /** Contacts: `bird.contacts.create(...)`, `.list(...)`, `.get(...)`, `.batch(...)`, … */
7113
7351
  contacts;
7352
+ /** Preferences: `bird.preferences.list(...)`, `.get(...)`, `.create(...)`, `.delete(...)`. */
7353
+ preferences;
7114
7354
  /** Audiences: `bird.audiences.create(...)`, `.list(...)`, `.addContacts(...)`, … */
7115
7355
  audiences;
7116
7356
  /** Contact properties: `bird.contactProperties.create(...)`, `.list(...)`, `.archive(...)`, … */
@@ -7132,9 +7372,9 @@ var BirdClient = class {
7132
7372
  this.#headers = {
7133
7373
  ...opts.defaultHeaders,
7134
7374
  Authorization: `Bearer ${opts.apiKey}`,
7135
- "User-Agent": `bird-sdk-js/0.37.2`,
7375
+ "User-Agent": `bird-sdk-js/0.38.0`,
7136
7376
  "Bird-Surface": "sdk-js",
7137
- "Bird-Version": "0.37.2"
7377
+ "Bird-Version": "0.38.0"
7138
7378
  };
7139
7379
  const caller = detectCaller();
7140
7380
  if (caller) this.#headers["Bird-Caller"] = caller;
@@ -7168,6 +7408,7 @@ var BirdClient = class {
7168
7408
  this.voice = new VoiceResource(this.core, this.#client);
7169
7409
  this.verify = new VerifyResource(this.core, this.#client);
7170
7410
  this.contacts = new ContactsResource(this.core, this.#client);
7411
+ this.preferences = new PreferencesResource(this.core, this.#client);
7171
7412
  this.audiences = new AudiencesResource(this.core, this.#client);
7172
7413
  this.contactProperties = new ContactPropertiesResource(this.core, this.#client);
7173
7414
  this.domains = new DomainsResource(this.core, this.#client);
@@ -7258,6 +7499,9 @@ const WebhookEventType = {
7258
7499
  EmailScheduled: "email.scheduled",
7259
7500
  EmailSuppressionCreated: "email_suppression.created",
7260
7501
  EmailUnsubscribed: "email.unsubscribed",
7502
+ PreferenceDeleted: "preference.deleted",
7503
+ PreferenceGranted: "preference.granted",
7504
+ PreferenceRevoked: "preference.revoked",
7261
7505
  SmsAccepted: "sms.accepted",
7262
7506
  SmsDelivered: "sms.delivered",
7263
7507
  SmsExpired: "sms.expired",
@@ -7282,7 +7526,8 @@ const WebhookEventType = {
7282
7526
  WhatsappRead: "whatsapp.read",
7283
7527
  WhatsappReceived: "whatsapp.received",
7284
7528
  WhatsappRejected: "whatsapp.rejected",
7285
- WhatsappSent: "whatsapp.sent"
7529
+ WhatsappSent: "whatsapp.sent",
7530
+ WhatsappSuppressionCreated: "whatsapp_suppression.created"
7286
7531
  };
7287
7532
  //#endregion
7288
7533
  //#region src/open-enums.gen.ts
@@ -7391,6 +7636,30 @@ const NumbersOrderStatus = {
7391
7636
  Pending: "pending"
7392
7637
  };
7393
7638
  /**
7639
+ * Values of PreferenceChannel known at this SDK version. The wire value is an open
7640
+ * string: a value added by a newer server deserializes unchanged, so switch on
7641
+ * these with a `default` branch rather than treating the set as closed.
7642
+ */
7643
+ const PreferenceChannel = {
7644
+ Email: "email",
7645
+ Sms: "sms",
7646
+ Whatsapp: "whatsapp"
7647
+ };
7648
+ /**
7649
+ * Values of PreferenceOrigin known at this SDK version. The wire value is an open
7650
+ * string: a value added by a newer server deserializes unchanged, so switch on
7651
+ * these with a `default` branch rather than treating the set as closed.
7652
+ */
7653
+ const PreferenceOrigin = {
7654
+ ApiKey: "api_key",
7655
+ Import: "import",
7656
+ Keyword: "keyword",
7657
+ PreferencePage: "preference_page",
7658
+ UnsubscribeEvent: "unsubscribe_event",
7659
+ UnsubscribeLink: "unsubscribe_link",
7660
+ User: "user"
7661
+ };
7662
+ /**
7394
7663
  * Values of SMSErrorCode known at this SDK version. The wire value is an open
7395
7664
  * string: a value added by a newer server deserializes unchanged, so switch on
7396
7665
  * these with a `default` branch rather than treating the set as closed.
@@ -7573,6 +7842,6 @@ const WhatsAppTemplateParameterType = {
7573
7842
  Video: "video"
7574
7843
  };
7575
7844
  //#endregion
7576
- export { BirdAPIError, BirdAuthError, BirdBadRequestError, BirdBillingError, BirdClient, BirdConflictError, BirdConnectionError, BirdError, BirdInternalError, BirdMisdirectedError, BirdNotFoundError, BirdNotImplementedError, BirdPayloadTooLargeError, BirdPermissionError, BirdPreconditionError, BirdRateLimitError, BirdServiceUnavailableError, BirdTimeoutError, BirdValidationError, BirdWebhookVerificationError, EmailEventType, EmailLookupFlag, EmailLookupReason, EmailLookupResult, LookupFlag, LookupPropertyStatus, NumberCapability, NumberType, NumbersOrderStatus, SMSErrorCode, SMSKeywordOperation, SMSSuppressionCoverage, SMSSuppressionEndReason, SMSSuppressionOrigin, SMSSuppressionReason, TemplateLanguageStatus, TemplateStatus, VerificationAttemptFailureReason, VerificationChannel, VerificationTerminalReason, WebhookEventType, WhatsAppErrorCode, WhatsAppEventType, WhatsAppTemplateCategory, WhatsAppTemplateParameterType, baseUrlForRegion, regionFromApiKey };
7845
+ export { BirdAPIError, BirdAuthError, BirdBadRequestError, BirdBillingError, BirdClient, BirdConflictError, BirdConnectionError, BirdError, BirdInternalError, BirdMisdirectedError, BirdNotFoundError, BirdNotImplementedError, BirdPayloadTooLargeError, BirdPermissionError, BirdPreconditionError, BirdRateLimitError, BirdServiceUnavailableError, BirdTimeoutError, BirdValidationError, BirdWebhookVerificationError, EmailEventType, EmailLookupFlag, EmailLookupReason, EmailLookupResult, LookupFlag, LookupPropertyStatus, NumberCapability, NumberType, NumbersOrderStatus, PreferenceChannel, PreferenceOrigin, SMSErrorCode, SMSKeywordOperation, SMSSuppressionCoverage, SMSSuppressionEndReason, SMSSuppressionOrigin, SMSSuppressionReason, TemplateLanguageStatus, TemplateStatus, VerificationAttemptFailureReason, VerificationChannel, VerificationTerminalReason, WebhookEventType, WhatsAppErrorCode, WhatsAppEventType, WhatsAppTemplateCategory, WhatsAppTemplateParameterType, baseUrlForRegion, regionFromApiKey };
7577
7846
 
7578
7847
  //# sourceMappingURL=index.mjs.map