@braze/web-sdk 4.8.3 → 4.9.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.
Files changed (154) hide show
  1. package/index.d.ts +121 -6
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +7 -7
  4. package/shared-lib/encoding-utils.js +4 -4
  5. package/shared-lib/event-types.js +22 -21
  6. package/shared-lib/guid.js +7 -7
  7. package/shared-lib/indexed-db-adapter.js +172 -135
  8. package/shared-lib/logger.js +26 -26
  9. package/shared-lib/supported-options.js +15 -15
  10. package/shared-lib/types.js +1 -0
  11. package/src/Card/card-manager-factory.js +1 -1
  12. package/src/Card/card-manager.js +2 -2
  13. package/src/Card/display/card-display.js +5 -4
  14. package/src/Card/models/banner.js +10 -10
  15. package/src/Card/models/captioned-image.js +7 -7
  16. package/src/Card/models/card.js +37 -36
  17. package/src/Card/models/classic-card.js +7 -7
  18. package/src/Card/models/control-card.js +3 -3
  19. package/src/Card/models/image-only.js +32 -0
  20. package/src/Card/models/index.js +1 -0
  21. package/src/Card/util/card-factory.js +16 -16
  22. package/src/ContentCards/content-cards-provider-factory.js +1 -1
  23. package/src/ContentCards/content-cards-provider.js +102 -102
  24. package/src/ContentCards/get-cached-content-cards.js +1 -1
  25. package/src/ContentCards/request-content-cards-refresh.js +1 -1
  26. package/src/ContentCards/subscribe-to-content-cards-updates.js +4 -4
  27. package/src/ContentCards/ui/show-content-cards.js +15 -12
  28. package/src/Core/add-sdk-metadata.js +2 -2
  29. package/src/Core/braze-sdk-metadata.js +1 -1
  30. package/src/Core/change-user.js +1 -1
  31. package/src/Core/device-properties.js +1 -1
  32. package/src/Core/disable-sdk.js +10 -7
  33. package/src/Core/enable-sdk.js +5 -2
  34. package/src/Core/get-device-id.js +3 -3
  35. package/src/Core/get-user.js +1 -1
  36. package/src/Core/handle-braze-action.js +14 -14
  37. package/src/Core/is-disabled.js +1 -1
  38. package/src/Core/log-custom-event.js +4 -4
  39. package/src/Core/log-purchase.js +9 -9
  40. package/src/Core/open-session.js +10 -10
  41. package/src/FeatureFlags/feature-flag-factory.js +5 -3
  42. package/src/FeatureFlags/feature-flag.js +17 -14
  43. package/src/FeatureFlags/feature-flags-provider-factory.js +1 -1
  44. package/src/FeatureFlags/feature-flags-provider.js +56 -43
  45. package/src/FeatureFlags/get-all-feature-flags.js +2 -2
  46. package/src/FeatureFlags/get-feature-flag.js +2 -2
  47. package/src/FeatureFlags/index.js +1 -0
  48. package/src/FeatureFlags/log-feature-flag-impression.js +23 -0
  49. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
  50. package/src/Feed/feed-provider-factory.js +1 -1
  51. package/src/Feed/feed-provider.js +20 -20
  52. package/src/Feed/get-cached-feed.js +1 -1
  53. package/src/Feed/log-feed-displayed.js +1 -1
  54. package/src/Feed/request-feed-refresh.js +1 -1
  55. package/src/Feed/subscribe-to-feed-updates.js +1 -1
  56. package/src/Feed/ui/show-feed.js +13 -10
  57. package/src/InAppMessage/defer-in-app-message.js +13 -0
  58. package/src/InAppMessage/display/get-animation-effect.js +1 -1
  59. package/src/InAppMessage/display/html-message-to-html.js +47 -47
  60. package/src/InAppMessage/display/in-app-message-to-html.js +92 -91
  61. package/src/InAppMessage/display/modal-utils.js +16 -16
  62. package/src/InAppMessage/get-deferred-in-app-message.js +5 -0
  63. package/src/InAppMessage/in-app-message-factory.js +77 -57
  64. package/src/InAppMessage/in-app-message-manager-factory.js +6 -6
  65. package/src/InAppMessage/in-app-message-manager.js +121 -82
  66. package/src/InAppMessage/index.js +2 -0
  67. package/src/InAppMessage/log-in-app-message-button-click.js +17 -9
  68. package/src/InAppMessage/log-in-app-message-click.js +4 -4
  69. package/src/InAppMessage/log-in-app-message-html-click.js +6 -6
  70. package/src/InAppMessage/log-in-app-message-impression.js +3 -3
  71. package/src/InAppMessage/models/full-screen-message.js +65 -29
  72. package/src/InAppMessage/models/html-message.js +32 -13
  73. package/src/InAppMessage/models/in-app-message-button.js +7 -7
  74. package/src/InAppMessage/models/in-app-message.js +203 -134
  75. package/src/InAppMessage/models/modal-message.js +64 -29
  76. package/src/InAppMessage/models/slide-up-message.js +52 -24
  77. package/src/InAppMessage/models/templated-in-app-message.js +8 -8
  78. package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
  79. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +6 -6
  80. package/src/InAppMessage/ui/show-in-app-message.js +49 -47
  81. package/src/InAppMessage/utils/in-app-message-utils.js +1 -1
  82. package/src/Push/is-push-blocked.js +2 -2
  83. package/src/Push/is-push-permission-granted.js +2 -2
  84. package/src/Push/is-push-supported.js +2 -2
  85. package/src/Push/push-manager-factory.js +19 -19
  86. package/src/Push/push-manager.js +131 -131
  87. package/src/Push/request-push-permission.js +2 -2
  88. package/src/Push/unregister-push.js +2 -2
  89. package/src/Push/utils/push-utils.js +12 -10
  90. package/src/User/user-manager.js +4 -4
  91. package/src/User/user.js +57 -57
  92. package/src/common/base-feed.js +1 -1
  93. package/src/common/constants.js +1 -0
  94. package/src/common/event-logger.js +6 -6
  95. package/src/common/feed-display.js +34 -34
  96. package/src/common/translations.js +33 -33
  97. package/src/l10n/l10n-manager-factory.js +8 -8
  98. package/src/l10n/l10n-manager.js +6 -2
  99. package/src/l10n/types.js +1 -0
  100. package/src/managers/auth-manager.js +29 -29
  101. package/src/managers/braze-instance.js +125 -125
  102. package/src/managers/device-manager.js +20 -20
  103. package/src/managers/network-manager.js +100 -98
  104. package/src/managers/server-config-manager.js +23 -23
  105. package/src/managers/session-manager.js +5 -5
  106. package/src/managers/storage-manager-factory.js +9 -9
  107. package/src/managers/storage-manager.js +132 -129
  108. package/src/managers/subscription-manager.js +8 -8
  109. package/src/models/backend-errors.js +6 -6
  110. package/src/models/braze-event.js +11 -11
  111. package/src/models/braze-sdk-metadata.js +1 -1
  112. package/src/models/device.js +2 -2
  113. package/src/models/identifier.js +1 -1
  114. package/src/models/push-token.js +5 -5
  115. package/src/models/server-config.js +7 -7
  116. package/src/request-controller.js +191 -178
  117. package/src/triggers/models/custom-event-data.js +4 -4
  118. package/src/triggers/models/custom-event-property-data.js +7 -7
  119. package/src/triggers/models/filter-set.js +5 -5
  120. package/src/triggers/models/filter.js +64 -60
  121. package/src/triggers/models/in-app-message-click-data.js +9 -9
  122. package/src/triggers/models/purchase-data.js +4 -4
  123. package/src/triggers/models/purchase-property-data.js +6 -6
  124. package/src/triggers/models/push-click-data.js +6 -6
  125. package/src/triggers/models/trigger-condition.js +55 -59
  126. package/src/triggers/models/trigger-events.js +3 -3
  127. package/src/triggers/models/trigger.js +47 -35
  128. package/src/triggers/triggers-provider-factory.js +10 -6
  129. package/src/triggers/triggers-provider.js +203 -185
  130. package/src/triggers/types.js +1 -0
  131. package/src/ui/js/attach-css.js +5 -4
  132. package/src/ui/js/feed-css.js +5 -5
  133. package/src/ui/js/iam-css.js +5 -5
  134. package/src/ui/js/load-font-awesome.js +1 -1
  135. package/src/util/base-device-parser.js +1 -1
  136. package/src/util/braze-actions.js +35 -30
  137. package/src/util/browser-detector.js +30 -31
  138. package/src/util/client-hints-parser.js +30 -24
  139. package/src/util/code-utils.js +22 -21
  140. package/src/util/color-utils.js +19 -13
  141. package/src/util/component-utils.js +4 -4
  142. package/src/util/date-utils.js +4 -3
  143. package/src/util/device-constants.js +10 -10
  144. package/src/util/dom-utils.js +32 -28
  145. package/src/util/error-utils.js +1 -1
  146. package/src/util/key-codes.js +1 -1
  147. package/src/util/net.js +53 -57
  148. package/src/util/request-header-utils.js +34 -11
  149. package/src/util/string-utils.js +14 -14
  150. package/src/util/types.js +1 -0
  151. package/src/util/url-utils.js +1 -4
  152. package/src/util/user-agent-parser.js +39 -39
  153. package/src/util/validation-utils.js +32 -32
  154. package/src/util/window-utils.js +11 -12
package/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  /*
2
- * Type definitions for @braze/web-sdk v4.8.3
2
+ * Type definitions for @braze/web-sdk v4.9.0
3
3
  * Project: https://github.com/braze-inc/braze-web-sdk
4
4
  * (c) Braze, Inc. 2023 - http://braze.com
5
5
  * License available at https://github.com/braze-inc/braze-web-sdk/blob/master/LICENSE
6
6
  */
7
7
 
8
+ /* eslint-disable no-unused-vars, no-use-before-define */
8
9
 
9
10
  /**
10
11
  * Enum to represent the accepted SDK Metadata tags. See `addSdkMetadata` for more info.
@@ -57,7 +58,7 @@
57
58
 
58
59
  /**
59
60
  * Abstract base for news feed and Content Cards cards. Use subclasses `ClassicCard`, `CaptionedImage`,
60
- * `Banner`, and `ControlCard`.
61
+ * `ImageOnly`, and `ControlCard`.
61
62
  */
62
63
  export class Card {
63
64
  /**
@@ -128,6 +129,9 @@
128
129
 
129
130
  }
130
131
 
132
+ /**
133
+ * @deprecated This class has been deprecated in favor of `ImageOnly`.
134
+ */
131
135
  export class Banner extends Card {
132
136
  /**
133
137
  * A card with only an image, which can be passed to `showFeed` or handled manually.
@@ -201,6 +205,79 @@
201
205
  clicked: boolean;
202
206
  }
203
207
 
208
+ export class ImageOnly extends Card {
209
+ /**
210
+ * A card with only an image, which can be passed to `showFeed` or handled manually.
211
+ * Subscribe to receive new cards via `subscribeToFeedUpdates`
212
+ *
213
+ * @param id - The id of the card. This will be reported back to Braze with events for analytics purposes.
214
+ * @param viewed - Whether this card has been shown to the user.
215
+ * @param imageUrl - The url for this card's image.
216
+ * @param created - When this card was created.
217
+ * @param updated - When this card was last modified.
218
+ * @param categories - Purely for organization in your custom implementation, these categories can be set in
219
+ * the dashboard composer.
220
+ * @param expiresAt - When this card expires and should stop being shown to the user.
221
+ * @param url - A url to open when this card is clicked.
222
+ * @param linkText - The display text for the url.
223
+ * @param aspectRatio - The aspect ratio for this card's image. This field is meant to serve as a hint before
224
+ * image loading completes. Note that the field may not be supplied in certain circumstances.
225
+ * @param extras - Object of string/string key/value pairs.
226
+ * @param pinned - Whether to pin this card to the top of the view.
227
+ * @param dismissible - Whether to allow the user to dismiss this card, removing it from the view.
228
+ * @param clicked - Whether this card has ever been clicked on this device.
229
+ */
230
+ constructor(
231
+ id?: string,
232
+ viewed?: boolean,
233
+ imageUrl?: string,
234
+ created?: Date,
235
+ updated?: Date,
236
+ categories?: string[],
237
+ expiresAt?: Date,
238
+ url?: string,
239
+ linkText?: string,
240
+ aspectRatio?: number,
241
+ extras?: Record<string, string>,
242
+ pinned?: boolean,
243
+ dismissible?: boolean,
244
+ clicked?: boolean
245
+ );
246
+
247
+ /** The url for this card's image. */
248
+ imageUrl?: string;
249
+
250
+ /** When this card was created. */
251
+ created: Date | null;
252
+
253
+ /**
254
+ * Purely for organization in your custom implementation, these categories can be set in
255
+ * the dashboard composer.
256
+ */
257
+ categories: string[];
258
+
259
+ /** A url to open when this card is clicked. */
260
+ url?: string;
261
+
262
+ /** The display text for the url. */
263
+ linkText?: string;
264
+
265
+ /**
266
+ * The aspect ratio for this card's image. This field is meant to serve as a hint before image loading completes.
267
+ * Note that the field may not be supplied in certain circumstances.
268
+ * */
269
+ aspectRatio: number | null;
270
+
271
+ /** Whether this card has been dismissed. */
272
+ dismissed: boolean;
273
+
274
+ /** Whether to allow the user to dismiss this card, removing it from the view. */
275
+ dismissible: boolean;
276
+
277
+ /** Whether this card has ever been clicked on this device. */
278
+ clicked: boolean;
279
+ }
280
+
204
281
  export class CaptionedImage extends Card {
205
282
  /**
206
283
  * A card with a large image and descriptive text, which can be passed to `showFeed` or handled manually.
@@ -1641,6 +1718,35 @@
1641
1718
  onDisplayCallback?: () => void
1642
1719
  ): boolean;
1643
1720
 
1721
+ /**
1722
+ * Defers the display of given in-app message for a future pageload.
1723
+ * The deferred in-app message can be retrieved by calling `getDeferredInAppMessage`,
1724
+ * and displayed using `showInAppMessage`.
1725
+ * Deferring an in-app message will overwrite any previously deferred in-app message.
1726
+ *
1727
+ * Note: Be sure to subscribe to clicked / dismissed events on this in-app message only after retrieving it using `getDeferredInAppMessage`.
1728
+ * Any subscriptions made before calling `deferInAppMessage` will not be persisted.
1729
+ * Also note that the in-app message deferred here will be cleared out when in-app message triggers have been refreshed from the Braze backend.
1730
+ *
1731
+ * @param inAppMessage - The message to defer for later display.
1732
+ *
1733
+ * @returns Whether or not the message was successfully deferred.
1734
+ * Returns undefined if the SDK has not been initialized.
1735
+ */
1736
+ export function deferInAppMessage(
1737
+ inAppMessage: InAppMessage
1738
+ ): boolean | undefined;
1739
+
1740
+ /**
1741
+ * Retrieves the in-app message that was most recently deferred for display with `deferInAppMessage`.
1742
+ *
1743
+ * Note: Retrieving the deferred in-app message here will clear it from storage.
1744
+ *
1745
+ * @returns The deferred in-app message if it exists, or returns null.
1746
+ * Returns undefined if the SDK has not been initialized.
1747
+ */
1748
+ export function getDeferredInAppMessage(): InAppMessage | null | undefined;
1749
+
1644
1750
  /**
1645
1751
  * Toggle the display of Braze content cards, showing them if they are not shown, and hiding them if they are. If you
1646
1752
  * wish to display multiple content cards feeds on a page simultaneously, you should use `showContentCards` and `hideContentCards`
@@ -1993,8 +2099,8 @@
1993
2099
  * When a new session is opened, this refreshes In-App Messages. Content Cards are refreshed automatically if
1994
2100
  * the `subscribeToContentCardsUpdates` has been registered prior to `openSession`. If the user has previously
1995
2101
  * granted the site permission to send push, automatically sends the push registration to the Braze backend.
1996
- *
1997
- * Be sure to call `openSession` at the end of your initialization code section, after any calls to `changeUser` or subscribing to Content Cards,
2102
+ *
2103
+ * Be sure to call `openSession` at the end of your initialization code section, after any calls to `changeUser` or subscribing to Content Cards,
1998
2104
  * In-App Message, and Feature Flag updates. Calling `openSession` before `changeUser` may result in a second session start event.
1999
2105
  */
2000
2106
  export function openSession(): void;
@@ -2011,7 +2117,7 @@
2011
2117
  * - Create a `service-worker.js` file with the content below and place it in the root directory of your website:
2012
2118
  *
2013
2119
  * ```
2014
- * self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.8/service-worker.js');
2120
+ * self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.9/service-worker.js');
2015
2121
  * ```
2016
2122
  *
2017
2123
  * For more details, see [Our Product Documentation](https://www.braze.com/docs/developer_guide/platform_integration_guides/web/push_notifications/integration).
@@ -2270,6 +2376,15 @@
2270
2376
  * @returns - A list of `FeatureFlag` objects.
2271
2377
  */
2272
2378
  export function getAllFeatureFlags(): FeatureFlag[];
2379
+
2380
+ /**
2381
+ * Logs impression for a given feature flag.
2382
+ *
2383
+ * @param featureFlagId - ID of the feature flag that has received the impression.
2384
+ *
2385
+ * @returns - Whether or not the impression was successfully logged. Returns undefined if the SDK has not been initialized.
2386
+ */
2387
+ export function logFeatureFlagImpression(featureFlagId: string): boolean | undefined;
2273
2388
 
2274
2389
  /**
2275
2390
  * Supported initialization options
@@ -2367,7 +2482,7 @@
2367
2482
  * lifecycle of, set this option to true and the Braze SDK will not register or unregister a service worker. If you set this
2368
2483
  * option to true, in order for push to function correctly you must register the service worker yourself BEFORE calling
2369
2484
  * `requestPushPermission`, and ensure that it contains Braze's service worker code, either with
2370
- * `self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.8/service-worker.js');` or by including the content
2485
+ * `self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.9/service-worker.js');` or by including the content
2371
2486
  * of that file directly. When this option is true, the `serviceWorkerLocation` option is irrelevant and is ignored.
2372
2487
  */
2373
2488
  manageServiceWorkerExternally?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braze/web-sdk",
3
- "version": "4.8.3",
3
+ "version": "4.9.0",
4
4
  "description": "Braze SDK for web sites and other JS platforms.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,8 +1,8 @@
1
- import je from "./encoding-utils.js";
2
- import { EventTypes as ve, InternalEventTypes as De } from "./event-types.js";
3
- import Be from "./guid.js";
4
- import Ae from "./indexed-db-adapter.js";
5
- import Ge from "./logger.js";
6
- import Oe from "./supported-options.js";
7
- const r = { xn: je, q: ve, Cr: De, Z: Be, xt: Ae, zt: Ae.ep, j: Ge, xo: Oe };
1
+ import ve from "./encoding-utils.js";
2
+ import { EventTypes as De, InternalEventTypes as Be } from "./event-types.js";
3
+ import Ge from "./guid.js";
4
+ import Oe from "./indexed-db-adapter.js";
5
+ import Ue from "./logger.js";
6
+ import ke from "./supported-options.js";
7
+ const r = { On: ve, q: De, Cr: Be, Z: Ge, xt: Oe, zt: Oe.ep, j: Ue, Jo: ke };
8
8
  export default r;
@@ -1,5 +1,5 @@
1
- const je = {
2
- _n: function(t) {
1
+ const ve = {
2
+ Fn: function (t) {
3
3
  const r = (t + "=".repeat((4 - (t.length % 4)) % 4))
4
4
  .replace(/\-/g, "+")
5
5
  .replace(/_/g, "/"),
@@ -7,6 +7,6 @@ const je = {
7
7
  o = new Uint8Array(n.length);
8
8
  for (let t = 0; t < n.length; ++t) o[t] = n.charCodeAt(t);
9
9
  return o;
10
- }
10
+ },
11
11
  };
12
- export default je;
12
+ export default ve;
@@ -1,33 +1,34 @@
1
- const ve = {
1
+ const De = {
2
2
  CustomEvent: "ce",
3
3
  Pr: "p",
4
- du: "pc",
4
+ $u: "pc",
5
5
  dc: "ca",
6
- ka: "i",
7
- Is: "ie",
6
+ Va: "i",
7
+ qs: "ie",
8
8
  P: "cci",
9
9
  T: "ccic",
10
10
  $: "ccc",
11
11
  H: "ccd",
12
12
  Wl: "ss",
13
13
  xl: "se",
14
- _i: "si",
15
- Ii: "sc",
16
- Mi: "sbc",
17
- Ze: "sfe",
18
- ro: "iec",
19
- au: "lr",
20
- Zh: "uae",
14
+ Vi: "si",
15
+ Li: "sc",
16
+ Qi: "sbc",
17
+ Ki: "sfe",
18
+ eo: "iec",
19
+ Su: "lr",
20
+ ju: "uae",
21
21
  R: "ci",
22
22
  B: "cc",
23
- gu: "lcaa",
24
- fu: "lcar",
25
- Rn: "inc",
26
- Bn: "add",
27
- Ln: "rem",
28
- Fn: "set",
29
- $n: "ncam",
30
- pu: "sgu"
23
+ Au: "lcaa",
24
+ qu: "lcar",
25
+ Xn: "inc",
26
+ Jn: "add",
27
+ Qn: "rem",
28
+ Hn: "set",
29
+ Kn: "ncam",
30
+ Cu: "sgu",
31
+ Fr: "ffi",
31
32
  },
32
- De = { Ar: "feed_displayed", Cc: "content_cards_displayed" };
33
- export { ve as EventTypes, De as InternalEventTypes };
33
+ Be = { Br: "feed_displayed", vc: "content_cards_displayed" };
34
+ export { De as EventTypes, Be as InternalEventTypes };
@@ -1,10 +1,10 @@
1
- const Be = {
2
- Y: () => {
3
- const t = t => {
4
- const e = (Math.random().toString(16) + "000000000").substr(2, 8);
5
- return t ? "-" + e.substr(0, 4) + "-" + e.substr(4, 4) : e;
1
+ const Ge = {
2
+ Y: function () {
3
+ const t = (t = !1) => {
4
+ const n = (Math.random().toString(16) + "000000000").substr(2, 8);
5
+ return t ? "-" + n.substr(0, 4) + "-" + n.substr(4, 4) : n;
6
6
  };
7
7
  return t() + t(!0) + t(!0) + t();
8
- }
8
+ },
9
9
  };
10
- export default Be;
10
+ export default Ge;