@braze/web-sdk 4.5.1 → 4.6.1

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 (84) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +65 -9
  3. package/package.json +1 -1
  4. package/shared-lib/braze-shared-lib.js +7 -7
  5. package/shared-lib/encoding-utils.js +3 -3
  6. package/shared-lib/event-types.js +14 -14
  7. package/shared-lib/guid.js +2 -2
  8. package/shared-lib/indexed-db-adapter.js +3 -3
  9. package/shared-lib/logger.js +18 -18
  10. package/shared-lib/supported-options.js +15 -15
  11. package/src/Card/index.js +1 -0
  12. package/src/Card/log-content-card-click.js +4 -0
  13. package/src/FeatureFlags/feature-flag-factory.js +13 -5
  14. package/src/FeatureFlags/feature-flag.js +36 -8
  15. package/src/FeatureFlags/feature-flags-provider.js +58 -33
  16. package/src/FeatureFlags/get-all-feature-flags.js +3 -3
  17. package/src/FeatureFlags/get-feature-flag.js +5 -5
  18. package/src/FeatureFlags/index.js +1 -0
  19. package/src/Feed/feed-provider-factory.js +8 -8
  20. package/src/Feed/feed-provider.js +3 -3
  21. package/src/Feed/get-cached-feed.js +2 -2
  22. package/src/Feed/log-feed-displayed.js +1 -1
  23. package/src/Feed/request-feed-refresh.js +2 -2
  24. package/src/Feed/subscribe-to-feed-updates.js +2 -2
  25. package/src/Feed/ui/show-feed.js +2 -2
  26. package/src/InAppMessage/display/html-message-to-html.js +3 -3
  27. package/src/InAppMessage/display/in-app-message-to-html.js +101 -86
  28. package/src/InAppMessage/display/modal-utils.js +9 -9
  29. package/src/InAppMessage/in-app-message-factory.js +1 -1
  30. package/src/InAppMessage/in-app-message-manager-factory.js +3 -3
  31. package/src/InAppMessage/in-app-message-manager.js +52 -52
  32. package/src/InAppMessage/log-in-app-message-button-click.js +2 -2
  33. package/src/InAppMessage/log-in-app-message-click.js +2 -2
  34. package/src/InAppMessage/log-in-app-message-html-click.js +3 -3
  35. package/src/InAppMessage/log-in-app-message-impression.js +1 -1
  36. package/src/InAppMessage/models/full-screen-message.js +1 -1
  37. package/src/InAppMessage/models/in-app-message-button.js +4 -4
  38. package/src/InAppMessage/models/in-app-message.js +68 -68
  39. package/src/InAppMessage/models/modal-message.js +2 -2
  40. package/src/InAppMessage/models/slide-up-message.js +8 -8
  41. package/src/InAppMessage/models/templated-in-app-message.js +4 -4
  42. package/src/InAppMessage/subscribe-to-in-app-message.js +1 -1
  43. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +3 -3
  44. package/src/InAppMessage/ui/show-in-app-message.js +24 -21
  45. package/src/Push/push-manager.js +54 -54
  46. package/src/Push/utils/push-utils.js +4 -4
  47. package/src/User/user-manager.js +4 -4
  48. package/src/User/user.js +13 -13
  49. package/src/common/base-feed.js +1 -1
  50. package/src/common/feed-display.js +22 -22
  51. package/src/l10n/l10n-manager-factory.js +7 -7
  52. package/src/managers/auth-manager.js +23 -23
  53. package/src/managers/braze-instance.js +93 -93
  54. package/src/managers/device-manager.js +2 -2
  55. package/src/managers/network-manager.js +42 -42
  56. package/src/managers/server-config-manager.js +9 -9
  57. package/src/managers/session-manager.js +27 -27
  58. package/src/managers/storage-manager-factory.js +1 -1
  59. package/src/managers/storage-manager.js +61 -61
  60. package/src/managers/subscription-manager.js +6 -6
  61. package/src/models/backend-errors.js +5 -5
  62. package/src/models/braze-event.js +2 -2
  63. package/src/models/device.js +1 -1
  64. package/src/models/identifier.js +6 -6
  65. package/src/models/push-token.js +3 -3
  66. package/src/models/server-config.js +3 -3
  67. package/src/request-controller.js +52 -52
  68. package/src/triggers/models/filter-set.js +2 -2
  69. package/src/triggers/models/filter.js +34 -34
  70. package/src/triggers/models/in-app-message-click-data.js +6 -6
  71. package/src/triggers/models/push-click-data.js +1 -1
  72. package/src/triggers/models/trigger-condition.js +8 -8
  73. package/src/triggers/models/trigger-events.js +1 -1
  74. package/src/triggers/models/trigger.js +30 -30
  75. package/src/triggers/triggers-provider-factory.js +2 -2
  76. package/src/triggers/triggers-provider.js +37 -37
  77. package/src/ui/js/attach-css.js +1 -1
  78. package/src/ui/js/load-font-awesome.js +1 -1
  79. package/src/util/braze-actions.js +4 -4
  80. package/src/util/browser-detector.js +2 -2
  81. package/src/util/dom-utils.js +8 -8
  82. package/src/util/key-codes.js +1 -1
  83. package/src/util/net.js +3 -3
  84. package/src/util/window-utils.js +1 -1
package/README.md CHANGED
@@ -8,5 +8,5 @@ Note: The Braze Web SDK is meant to be used client-side in a web application and
8
8
 
9
9
  See the [Public Github Repo](https://github.com/braze-inc/braze-web-sdk#readme) for getting started instructions or [our documentation pages](https://www.braze.com/docs/developer_guide/platform_integration_guides/web/initial_sdk_setup/) for use-case based documentation.
10
10
 
11
- (c) Braze, Inc. 2022 - http://braze.com
11
+ (c) Braze, Inc. 2023 - http://braze.com
12
12
  License available at https://github.com/braze-inc/braze-web-sdk/blob/master/LICENSE
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
- * Type definitions for @braze/web-sdk v4.5.1
2
+ * Type definitions for @braze/web-sdk v4.6.1
3
3
  * Project: https://github.com/braze-inc/braze-web-sdk
4
- * (c) Braze, Inc. 2022 - http://braze.com
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
 
@@ -1496,15 +1496,60 @@
1496
1496
  subscribeToClickedEvent(subscriber: () => void): string;
1497
1497
  }
1498
1498
 
1499
- export interface FeatureFlag {
1499
+ export interface FeatureFlagStringProperty {
1500
+ type: "string";
1501
+ value: string;
1502
+ }
1503
+
1504
+ export interface FeatureFlagNumberProperty {
1505
+ type: "number";
1506
+ value: number;
1507
+ }
1508
+
1509
+ export interface FeatureFlagBooleanProperty {
1510
+ type: "boolean";
1511
+ value: boolean;
1512
+ }
1513
+
1514
+ export class FeatureFlag {
1500
1515
  /** Indicates whether or not this feature flag is enabled. */
1501
1516
  enabled: boolean;
1502
1517
 
1503
1518
  /** Properties of this feature flag, listed as key-value pairs. */
1504
- properties: object;
1519
+ properties: Partial<Record<string, FeatureFlagStringProperty | FeatureFlagNumberProperty | FeatureFlagBooleanProperty>>;
1505
1520
 
1506
1521
  /** The ID for this feature flag. */
1507
1522
  id: string;
1523
+
1524
+ /**
1525
+ * Get value of a feature flag property of type string.
1526
+ *
1527
+ * @param key - The key of the property.
1528
+ *
1529
+ * @returns The value of the property if the key is found and is of type string.
1530
+ * If the key is not found or if there is a type mismatch, this method will return a null.
1531
+ */
1532
+ getStringProperty(key: string): string | null;
1533
+
1534
+ /**
1535
+ * Get value of a feature flag property of type number.
1536
+ *
1537
+ * @param key - The key of the property.
1538
+ *
1539
+ * @returns The value of the property if the key is found and is of type number.
1540
+ * If the key is not found or if there is a type mismatch, this method will return a null.
1541
+ */
1542
+ getNumberProperty(key: string): number | null;
1543
+
1544
+ /**
1545
+ * Get value of a feature flag property of type boolean.
1546
+ *
1547
+ * @param key - The key of the property.
1548
+ *
1549
+ * @returns The value of the property if the key is found and is of type boolean.
1550
+ * If the key is not found or if there is a type mismatch, this method will return a null.
1551
+ */
1552
+ getBooleanProperty(key: string): boolean | null;
1508
1553
  }
1509
1554
 
1510
1555
  /**
@@ -1802,9 +1847,20 @@
1802
1847
  *
1803
1848
  * @returns Whether or not the event was successfully logged (to be flushed later).
1804
1849
  */
1805
- export function logContentCardImpressions(
1806
- contentCards: Card[],
1807
- ): boolean;
1850
+ export function logContentCardImpressions(contentCards: Card[]): boolean;
1851
+
1852
+ /**
1853
+ * A convenient method to log when user clicks on a Content Card. This method is equivalent to
1854
+ * calling [`logCardClick` method with `forContentCards` param set to true.
1855
+ * This is done automatically when you use Braze's display module and should only be called
1856
+ * if you're bypassing that and manually building the DOM for displaying content cards in
1857
+ * your own code.
1858
+ *
1859
+ * @param contentCard - the `Card` object that received a click
1860
+ *
1861
+ * @returns Whether or not the event was successfully logged (to be flushed later).
1862
+ */
1863
+ export function logContentCardClick(contentCard: Card): boolean;
1808
1864
 
1809
1865
  /**
1810
1866
  * @deprecated This method has been deprecated and is currently a no-op.
@@ -1944,7 +2000,7 @@
1944
2000
  * - Create a `service-worker.js` file with the content below and place it in the root directory of your website:
1945
2001
  *
1946
2002
  * ```
1947
- * self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.5/service-worker.js');
2003
+ * self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.6/service-worker.js');
1948
2004
  * ```
1949
2005
  *
1950
2006
  * For more details, see [Our Product Documentation](https://www.braze.com/docs/developer_guide/platform_integration_guides/web/push_notifications/integration).
@@ -2297,7 +2353,7 @@
2297
2353
  * lifecycle of, set this option to true and the Braze SDK will not register or unregister a service worker. If you set this
2298
2354
  * option to true, in order for push to function correctly you must register the service worker yourself BEFORE calling
2299
2355
  * `requestPushPermission`, and ensure that it contains Braze's service worker code, either with
2300
- * `self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.5/service-worker.js');` or by including the content
2356
+ * `self.importScripts('https://js.appboycdn.com/web-sdk-develop/4.6/service-worker.js');` or by including the content
2301
2357
  * of that file directly. When this option is true, the `serviceWorkerLocation` option is irrelevant and is ignored.
2302
2358
  */
2303
2359
  manageServiceWorkerExternally?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braze/web-sdk",
3
- "version": "4.5.1",
3
+ "version": "4.6.1",
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 ve from "./encoding-utils.js";
2
- import { EventTypes as De, InternalEventTypes as Be } from "./event-types.js";
3
- import Ae from "./guid.js";
4
- import Ge from "./indexed-db-adapter.js";
5
- import Oe from "./logger.js";
6
- import Ue from "./supported-options.js";
7
- const r = { kn: ve, A: De, qr: Be, it: Ae, qt: Ge, xt: Ge.ep, D: Oe, Vo: Ue };
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 = { Dn: je, A: ve, Ar: De, it: Be, qt: Ae, xt: Ae.ep, D: Ge, Go: Oe };
8
8
  export default r;
@@ -1,5 +1,5 @@
1
- const ve = {
2
- vn: function(t) {
1
+ const je = {
2
+ Pn: function(t) {
3
3
  const r = (t + "=".repeat((4 - (t.length % 4)) % 4))
4
4
  .replace(/\-/g, "+")
5
5
  .replace(/_/g, "/"),
@@ -9,4 +9,4 @@ const ve = {
9
9
  return o;
10
10
  }
11
11
  };
12
- export default ve;
12
+ export default je;
@@ -1,20 +1,20 @@
1
- const De = {
1
+ const ve = {
2
2
  CustomEvent: "ce",
3
3
  Pr: "p",
4
4
  xl: "pc",
5
5
  cc: "ca",
6
- za: "i",
6
+ Ba: "i",
7
7
  qs: "ie",
8
8
  T: "cci",
9
9
  W: "ccic",
10
10
  _: "ccc",
11
11
  L: "ccd",
12
- Ch: "ss",
13
- dh: "se",
14
- gi: "si",
15
- pi: "sc",
16
- mi: "sbc",
17
- ui: "sfe",
12
+ _h: "ss",
13
+ gh: "se",
14
+ bi: "si",
15
+ yi: "sc",
16
+ ji: "sbc",
17
+ vi: "sfe",
18
18
  ro: "iec",
19
19
  Ul: "lr",
20
20
  Ol: "uae",
@@ -22,11 +22,11 @@ const De = {
22
22
  F: "cc",
23
23
  Bl: "lcaa",
24
24
  Wl: "lcar",
25
- Fn: "inc",
26
- Un: "add",
27
- En: "rem",
28
- An: "set",
25
+ Tn: "inc",
26
+ En: "add",
27
+ Fn: "rem",
28
+ Un: "set",
29
29
  Gl: "sgu"
30
30
  },
31
- Be = { Fr: "feed_displayed", dc: "content_cards_displayed" };
32
- export { De as EventTypes, Be as InternalEventTypes };
31
+ De = { qr: "feed_displayed", dc: "content_cards_displayed" };
32
+ export { ve as EventTypes, De as InternalEventTypes };
@@ -1,4 +1,4 @@
1
- const Ae = {
1
+ const Be = {
2
2
  nt: () => {
3
3
  const t = t => {
4
4
  const e = (Math.random().toString(16) + "000000000").substr(2, 8);
@@ -7,4 +7,4 @@ const Ae = {
7
7
  return t() + t(!0) + t(!0) + t();
8
8
  }
9
9
  };
10
- export default Ae;
10
+ export default Be;
@@ -1,4 +1,4 @@
1
- export default class Ge {
1
+ export default class Ae {
2
2
  constructor(t, e) {
3
3
  (this.td = "undefined" == typeof window ? self : window),
4
4
  (this.ed = t),
@@ -296,7 +296,7 @@ export default class Ge {
296
296
  });
297
297
  }
298
298
  }
299
- Ge.ep = {
299
+ Ae.ep = {
300
300
  Ft: {
301
301
  dd: "AppboyServiceWorkerAsyncStorage",
302
302
  VERSION: 6,
@@ -308,7 +308,7 @@ Ge.ep = {
308
308
  Mt: "cardUpdates",
309
309
  oe: "optOut",
310
310
  $r: "pendingData",
311
- On: "sdkAuthenticationSignature"
311
+ Vn: "sdkAuthenticationSignature"
312
312
  },
313
313
  se: 1
314
314
  }
@@ -1,38 +1,38 @@
1
- const Oe = {
1
+ const Ge = {
2
2
  init: function(n) {
3
- (void 0 === n && void 0 !== Oe.zg) || (Oe.zg = !!n), Oe.Eg || (Oe.Eg = !0);
3
+ (void 0 === n && void 0 !== Ge.zg) || (Ge.zg = !!n), Ge.Eg || (Ge.Eg = !0);
4
4
  },
5
5
  destroy: function() {
6
- (Oe.Eg = !1), (Oe.zg = void 0), (Oe.nd = void 0);
6
+ (Ge.Eg = !1), (Ge.zg = void 0), (Ge.nd = void 0);
7
7
  },
8
8
  setLogger: function(n) {
9
9
  "function" == typeof n
10
- ? (Oe.init(), (Oe.nd = n))
11
- : Oe.info("Ignoring setLogger call since logger is not a function");
10
+ ? (Ge.init(), (Ge.nd = n))
11
+ : Ge.info("Ignoring setLogger call since logger is not a function");
12
12
  },
13
13
  toggleLogging: function() {
14
- Oe.init(),
15
- Oe.zg
16
- ? (console.log("Disabling Braze logging"), (Oe.zg = !1))
17
- : (console.log("Enabled Braze logging"), (Oe.zg = !0));
14
+ Ge.init(),
15
+ Ge.zg
16
+ ? (console.log("Disabling Braze logging"), (Ge.zg = !1))
17
+ : (console.log("Enabled Braze logging"), (Ge.zg = !0));
18
18
  },
19
19
  info: function(n) {
20
- if (Oe.zg) {
20
+ if (Ge.zg) {
21
21
  const o = "Braze: " + n;
22
- null != Oe.nd ? Oe.nd(o) : console.log(o);
22
+ null != Ge.nd ? Ge.nd(o) : console.log(o);
23
23
  }
24
24
  },
25
25
  warn: function(n) {
26
- if (Oe.zg) {
27
- const o = "Braze SDK Warning: " + n + " (v4.5.1)";
28
- null != Oe.nd ? Oe.nd(o) : console.warn(o);
26
+ if (Ge.zg) {
27
+ const o = "Braze SDK Warning: " + n + " (v4.6.1)";
28
+ null != Ge.nd ? Ge.nd(o) : console.warn(o);
29
29
  }
30
30
  },
31
31
  error: function(n) {
32
- if (Oe.zg) {
33
- const o = "Braze SDK Error: " + n + " (v4.5.1)";
34
- null != Oe.nd ? Oe.nd(o) : console.error(o);
32
+ if (Ge.zg) {
33
+ const o = "Braze SDK Error: " + n + " (v4.6.1)";
34
+ null != Ge.nd ? Ge.nd(o) : console.error(o);
35
35
  }
36
36
  }
37
37
  };
38
- export default Oe;
38
+ export default Ge;
@@ -1,26 +1,26 @@
1
1
  export default {
2
- Zn: "allowCrawlerActivity",
3
- ho: "baseUrl",
4
- po: "noCookies",
5
- Eo: "devicePropertyAllowlist",
2
+ ho: "allowCrawlerActivity",
3
+ po: "baseUrl",
4
+ Eo: "noCookies",
5
+ _o: "devicePropertyAllowlist",
6
6
  ta: "disablePushTokenMaintenance",
7
- _o: "enableLogging",
8
- Io: "enableSdkAuthentication",
7
+ Io: "enableLogging",
8
+ Ao: "enableSdkAuthentication",
9
9
  ia: "manageServiceWorkerExternally",
10
- Ao: "minimumIntervalBetweenTriggerActionsInSeconds",
11
- So: "sessionTimeoutInSeconds",
12
- No: "appVersion",
10
+ So: "minimumIntervalBetweenTriggerActionsInSeconds",
11
+ No: "sessionTimeoutInSeconds",
12
+ wo: "appVersion",
13
13
  na: "serviceWorkerLocation",
14
14
  ra: "safariWebsitePushId",
15
- jn: "localization",
15
+ zn: "localization",
16
16
  ao: "contentSecurityNonce",
17
- wo: "enableHtmlInAppMessages",
18
- To: "allowUserSuppliedJavascript",
17
+ To: "enableHtmlInAppMessages",
18
+ Oo: "allowUserSuppliedJavascript",
19
19
  no: "inAppMessageZIndex",
20
20
  lo: "openInAppMessagesInNewTab",
21
21
  en: "openNewsFeedCardsInNewTab",
22
- qi: "requireExplicitInAppMessageDismissal",
23
- Oo: "doNotLoadFontAwesome",
24
- vo: "sdkFlavor",
22
+ eh: "requireExplicitInAppMessageDismissal",
23
+ vo: "doNotLoadFontAwesome",
24
+ Co: "sdkFlavor",
25
25
  tn: "openCardsInNewTab"
26
26
  };
package/src/Card/index.js CHANGED
@@ -3,3 +3,4 @@ export { logCardClick } from "./log-card-click.js";
3
3
  export { logCardDismissal } from "./log-card-dismissal.js";
4
4
  export { logCardImpressions } from "./log-card-impressions.js";
5
5
  export { logContentCardImpressions } from "./log-content-card-impressions.js";
6
+ export { logContentCardClick } from "./log-content-card-click.js";
@@ -0,0 +1,4 @@
1
+ import { logCardClick } from "./log-card-click.js";
2
+ export function logContentCardClick(o) {
3
+ return logCardClick(o, !0);
4
+ }
@@ -1,13 +1,21 @@
1
1
  import r from "../../shared-lib/braze-shared-lib.js";
2
- import ee from "./feature-flag.js";
2
+ import FeatureFlag from "./feature-flag.js";
3
3
  export function newFeatureFlagFromJson(e) {
4
- if (e[ee.At.ns] && "boolean" == typeof e[ee.At.Fe])
5
- return new ee(e[ee.At.ns], e[ee.At.Fe], e[ee.At.we]);
4
+ if (e[FeatureFlag.At.ns] && "boolean" == typeof e[FeatureFlag.At.Fe])
5
+ return new FeatureFlag(
6
+ e[FeatureFlag.At.ns],
7
+ e[FeatureFlag.At.Fe],
8
+ e[FeatureFlag.At.we]
9
+ );
6
10
  r.D.info(`Unable to create feature flag from ${JSON.stringify(e, null, 2)}`);
7
11
  }
8
12
  export function newFeatureFlagFromSerializedValue(e) {
9
- if (e[ee.hs.ns] && "boolean" == typeof e[ee.hs.Fe])
10
- return new ee(e[ee.hs.ns], e[ee.hs.Fe], e[ee.hs.we]);
13
+ if (e[FeatureFlag.hs.ns] && "boolean" == typeof e[FeatureFlag.hs.Fe])
14
+ return new FeatureFlag(
15
+ e[FeatureFlag.hs.ns],
16
+ e[FeatureFlag.hs.Fe],
17
+ e[FeatureFlag.hs.we]
18
+ );
11
19
  r.D.info(
12
20
  `Unable to deserialize feature flag from ${JSON.stringify(e, null, 2)}`
13
21
  );
@@ -1,16 +1,44 @@
1
- export default class ee {
2
- constructor(t, s = !1, i = {}) {
3
- (this.id = t), (this.enabled = s), (this.properties = i);
1
+ import r from "../../shared-lib/braze-shared-lib.js";
2
+ export default class FeatureFlag {
3
+ constructor(t, r = !1, e = {}) {
4
+ (this.id = t), (this.enabled = r), (this.properties = e);
5
+ }
6
+ getStringProperty(t) {
7
+ if (!this.yr(t)) return null;
8
+ const r = this.properties[t];
9
+ return this.Er(r, "string") ? r.value : null;
10
+ }
11
+ getNumberProperty(t) {
12
+ if (!this.yr(t)) return null;
13
+ const r = this.properties[t];
14
+ return this.Er(r, "number") ? r.value : null;
15
+ }
16
+ getBooleanProperty(t) {
17
+ if (!this.yr(t)) return null;
18
+ const r = this.properties[t];
19
+ return this.Er(r, "boolean") ? r.value : null;
4
20
  }
5
21
  ss() {
6
22
  const t = {};
7
23
  return (
8
- (t[ee.hs.ns] = this.id),
9
- (t[ee.hs.Fe] = this.enabled),
10
- (t[ee.hs.we] = this.properties),
24
+ (t[FeatureFlag.hs.ns] = this.id),
25
+ (t[FeatureFlag.hs.Fe] = this.enabled),
26
+ (t[FeatureFlag.hs.we] = this.properties),
11
27
  t
12
28
  );
13
29
  }
30
+ yr(t) {
31
+ return (
32
+ !(!this.properties || !this.properties[t]) ||
33
+ (r.D.info(`${t} not found in feature flag properties.`), !1)
34
+ );
35
+ }
36
+ Er(t, e) {
37
+ return (
38
+ (t.type === e && typeof t.value === e) ||
39
+ (r.D.info(`Property is not of type ${e}.`), !1)
40
+ );
41
+ }
14
42
  }
15
- (ee.hs = { ns: "id", Fe: "e", we: "pr" }),
16
- (ee.At = { ns: "id", Fe: "enabled", we: "properties" });
43
+ (FeatureFlag.hs = { ns: "id", Fe: "e", we: "pr" }),
44
+ (FeatureFlag.At = { ns: "id", Fe: "enabled", we: "properties" });
@@ -3,76 +3,101 @@ import y from "../common/base-provider.js";
3
3
  import e from "../managers/braze-instance.js";
4
4
  import { STORAGE_KEYS as o } from "../managers/storage-manager.js";
5
5
  import u from "../managers/subscription-manager.js";
6
+ import { randomInclusive as tt } from "../util/math.js";
6
7
  import b from "../util/net.js";
7
8
  import {
8
- newFeatureFlagFromJson as tt,
9
- newFeatureFlagFromSerializedValue as et
9
+ newFeatureFlagFromJson as et,
10
+ newFeatureFlagFromSerializedValue as st
10
11
  } from "./feature-flag-factory.js";
11
12
  export default class er extends y {
12
- constructor(t, s, r) {
13
+ constructor(t, s, i) {
13
14
  super(),
14
15
  (this.gt = t),
15
16
  (this.vt = s),
16
- (this.h = r),
17
+ (this.h = i),
17
18
  (this.he = new u()),
19
+ (this.ye = 10),
20
+ (this.Te = null),
18
21
  e.jt(this.he);
19
22
  }
20
23
  Rs(t) {
21
- if (this.gt.ye() && null != t && t.feature_flags) {
22
- this.De = [];
24
+ if (this.gt._e() && null != t && t.feature_flags) {
25
+ this.Re = [];
23
26
  for (const e of t.feature_flags) {
24
- let t = tt(e);
25
- t && this.De.push(t);
27
+ let t = et(e);
28
+ t && this.Re.push(t);
26
29
  }
27
- (this.Ne = new Date().getTime()), this._e(), this.he.St(this.De);
30
+ (this.De = new Date().getTime()), this.Ne(), this.he.St(this.Re);
28
31
  }
29
32
  }
30
33
  xe() {
31
34
  const t = this.h.I(o.q.ze) || {};
32
35
  let e = {};
33
36
  for (let s in t) {
34
- let r = et(t[s]);
35
- r && (e[r.id] = r);
37
+ let i = st(t[s]);
38
+ i && (e[i.id] = i);
36
39
  }
37
40
  return e;
38
41
  }
39
42
  Ws(t) {
40
43
  return this.he.ut(t);
41
44
  }
42
- refreshFeatureFlags(t, e, s) {
43
- if (!this.Re(s))
44
- return void (
45
- this.Se ||
46
- (this.Se = this.gt.Te(() => {
47
- this.refreshFeatureFlags(t, e);
48
- }))
45
+ refreshFeatureFlags(t, e, s, i) {
46
+ if (!this.Se(s))
47
+ return (
48
+ this.$e ||
49
+ (this.$e = this.gt.qe(() => {
50
+ this.refreshFeatureFlags(t, e);
51
+ })),
52
+ void ("function" == typeof e && e())
49
53
  );
54
+ null == i && (i = !0), i && this.Me();
50
55
  const r = this.vt.Ps({}, !0),
51
- i = this.vt.Bs(r, !1, !0);
56
+ a = this.vt.Bs(r, !1, !0);
57
+ let h = !1;
52
58
  this.vt.Gs(r, () => {
53
59
  b.Hs({
54
60
  url: `${this.vt.Ks()}/feature_flags/sync`,
55
- headers: i,
61
+ headers: a,
56
62
  data: r,
57
63
  S: s => {
58
- this.vt.Os(r, s)
59
- ? (this.vt.Qs(), this.Rs(s), "function" == typeof t && t())
60
- : "function" == typeof e && e();
64
+ if (!this.vt.Os(r, s))
65
+ return (h = !0), void ("function" == typeof e && e());
66
+ this.vt.Qs(), this.Rs(s), "function" == typeof t && t();
61
67
  },
62
68
  error: t => {
63
69
  this.vt.Vs(t, "retrieving feature flags"),
70
+ (h = !0),
64
71
  "function" == typeof e && e();
72
+ },
73
+ Ue: () => {
74
+ if (i && h && !this.ke) {
75
+ let i = this.Te;
76
+ (null == i || i < 1e3 * this.ye) && (i = 1e3 * this.ye),
77
+ this.Ae(Math.min(3e5, tt(1e3 * this.ye, 3 * i)), t, e, s);
78
+ }
65
79
  }
66
80
  });
67
81
  });
68
82
  }
69
- Re(t) {
83
+ Me() {
84
+ null != this.ke && (clearTimeout(this.ke), (this.ke = null));
85
+ }
86
+ Ae(t, e, s, i) {
87
+ null == t && (t = 1e3 * this.ye),
88
+ this.Me(),
89
+ (this.ke = setTimeout(() => {
90
+ this.refreshFeatureFlags(e, s, i);
91
+ }, t)),
92
+ (this.Te = t);
93
+ }
94
+ Se(t) {
70
95
  if (!t) {
71
- const t = parseFloat(this.gt.$e());
96
+ const t = parseFloat(this.gt.Be());
72
97
  let e = !1;
73
98
  if (!isNaN(t)) {
74
99
  if (-1 === t) return r.D.info("Feature flag refreshes not allowed"), !1;
75
- e = new Date().getTime() >= (this.Ne || 0) + 1e3 * t;
100
+ e = new Date().getTime() >= (this.De || 0) + 1e3 * t;
76
101
  }
77
102
  if (!e)
78
103
  return (
@@ -80,15 +105,15 @@ export default class er extends y {
80
105
  !1
81
106
  );
82
107
  }
83
- return this.gt.ye();
108
+ return this.gt._e();
84
109
  }
85
- _e() {
110
+ Ne() {
86
111
  const t = {};
87
- for (let e = 0; e < this.De.length; e++) {
88
- let s = this.De[e],
89
- r = s.ss();
90
- t[s.id] = r;
112
+ for (let e = 0; e < this.Re.length; e++) {
113
+ let s = this.Re[e],
114
+ i = s.ss();
115
+ t[s.id] = i;
91
116
  }
92
- this.h.B(o.q.ze, t), this.h.B(o.q.qe, this.Ne);
117
+ this.h.B(o.q.ze, t), this.h.B(o.q.Ce, this.De);
93
118
  }
94
119
  }
@@ -1,12 +1,12 @@
1
1
  import r from "../../shared-lib/braze-shared-lib.js";
2
2
  import e from "../managers/braze-instance.js";
3
- import { newFeatureFlagFromJson as tt } from "./feature-flag-factory.js";
3
+ import { newFeatureFlagFromJson as et } from "./feature-flag-factory.js";
4
4
  import ir from "./feature-flags-provider-factory.js";
5
5
  export function getAllFeatureFlags() {
6
6
  if (!e.rr()) return;
7
7
  let t = [];
8
- if (!e.ir().ye()) return r.D.info("Feature flags are not enabled."), t;
8
+ if (!e.ir()._e()) return r.D.info("Feature flags are not enabled."), t;
9
9
  const a = ir.er().xe();
10
- for (let r in a) t.push(tt(a[r]));
10
+ for (let r in a) t.push(et(a[r]));
11
11
  return t;
12
12
  }
@@ -1,12 +1,12 @@
1
1
  import r from "../../shared-lib/braze-shared-lib.js";
2
2
  import e from "../managers/braze-instance.js";
3
- import { newFeatureFlagFromJson as tt } from "./feature-flag-factory.js";
4
- import ee from "./feature-flag.js";
3
+ import { newFeatureFlagFromJson as et } from "./feature-flag-factory.js";
4
+ import FeatureFlag from "./feature-flag.js";
5
5
  import ir from "./feature-flags-provider-factory.js";
6
6
  export function getFeatureFlag(a) {
7
7
  if (!e.rr()) return;
8
- if (!e.ir().ye())
9
- return r.D.info("Feature flags are not enabled."), new ee(a);
8
+ if (!e.ir()._e())
9
+ return r.D.info("Feature flags are not enabled."), new FeatureFlag(a);
10
10
  const t = ir.er().xe();
11
- return t[a] ? tt(t[a]) : new ee(a);
11
+ return t[a] ? et(t[a]) : new FeatureFlag(a);
12
12
  }
@@ -1,3 +1,4 @@
1
+ export { default as FeatureFlag } from "./feature-flag.js";
1
2
  export { refreshFeatureFlags } from "./refresh-feature-flags.js";
2
3
  export { getFeatureFlag } from "./get-feature-flag.js";
3
4
  export { subscribeToFeatureFlagsUpdates } from "./subscribe-to-feature-flags-updates.js";
@@ -1,18 +1,18 @@
1
1
  import e from "../managers/braze-instance.js";
2
- import re from "./feed-provider.js";
3
- const ie = {
2
+ import ee from "./feed-provider.js";
3
+ const re = {
4
4
  t: !1,
5
5
  provider: null,
6
6
  er: () => (
7
- ie.o(),
8
- ie.provider || ((ie.provider = new re(e.l(), e.mr())), e.ar(ie.provider)),
9
- ie.provider
7
+ re.o(),
8
+ re.provider || ((re.provider = new ee(e.l(), e.mr())), e.ar(re.provider)),
9
+ re.provider
10
10
  ),
11
11
  o: () => {
12
- ie.t || (e.u(ie), (ie.t = !0));
12
+ re.t || (e.u(re), (re.t = !0));
13
13
  },
14
14
  destroy: () => {
15
- (ie.provider = null), (ie.t = !1);
15
+ (re.provider = null), (re.t = !1);
16
16
  }
17
17
  };
18
- export default ie;
18
+ export default re;