@braze/web-sdk 6.7.1 → 6.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 (138) hide show
  1. package/index.d.ts +165 -38
  2. package/package.json +1 -1
  3. package/shared-lib/encoding-utils.js +2 -2
  4. package/shared-lib/event-types.js +16 -16
  5. package/shared-lib/indexed-db-adapter.js +65 -65
  6. package/shared-lib/logger.js +18 -18
  7. package/shared-lib/supported-options.js +1 -1
  8. package/src/Banner/banner-provider.js +67 -59
  9. package/src/Banner/banner.js +40 -19
  10. package/src/Banner/dismiss-banner.js +4 -0
  11. package/src/Banner/display/banner-to-html.js +10 -10
  12. package/src/Banner/display/destroy-banner-html.js +2 -2
  13. package/src/Banner/get-all-banners.js +6 -6
  14. package/src/Banner/get-banner.js +6 -6
  15. package/src/Banner/index.js +1 -0
  16. package/src/Banner/log-banner-click.js +7 -7
  17. package/src/Banner/log-banner-dismissal.js +7 -7
  18. package/src/Banner/log-banner-impressions.js +27 -18
  19. package/src/Banner/request-banners-refresh.js +8 -8
  20. package/src/Banner/subscribe-to-banners-updates.js +5 -5
  21. package/src/Banner/ui/insert-banner.js +8 -8
  22. package/src/Card/card-manager.js +31 -31
  23. package/src/Card/log-card-dismissal.js +2 -2
  24. package/src/Card/log-content-card-click.js +2 -2
  25. package/src/Card/log-content-card-impressions.js +4 -4
  26. package/src/Card/models/captioned-image.js +15 -15
  27. package/src/Card/models/card.js +89 -89
  28. package/src/Card/models/classic-card.js +16 -16
  29. package/src/Card/models/control-card.js +7 -7
  30. package/src/Card/models/image-only.js +13 -13
  31. package/src/Card/util/card-factory.js +32 -32
  32. package/src/ContentCards/content-cards-provider-factory.js +13 -11
  33. package/src/ContentCards/content-cards-provider.js +105 -105
  34. package/src/ContentCards/get-cached-content-cards.js +2 -2
  35. package/src/ContentCards/request-content-cards-refresh.js +2 -2
  36. package/src/ContentCards/subscribe-to-content-cards-updates.js +10 -10
  37. package/src/ContentCards/ui/show-content-cards.js +7 -7
  38. package/src/Core/add-sdk-metadata.js +2 -2
  39. package/src/Core/change-user.js +5 -5
  40. package/src/Core/destroy.js +2 -2
  41. package/src/Core/disable-sdk.js +4 -4
  42. package/src/Core/enable-sdk.js +4 -4
  43. package/src/Core/get-device-id.js +2 -2
  44. package/src/Core/handle-braze-action.js +5 -5
  45. package/src/Core/index.js +1 -0
  46. package/src/Core/log-custom-event.js +5 -5
  47. package/src/Core/log-ecommerce-event.js +29 -0
  48. package/src/Core/log-purchase.js +23 -198
  49. package/src/Core/open-session.js +10 -10
  50. package/src/Core/set-logger.js +2 -2
  51. package/src/Core/set-sdk-authentication-signature.js +1 -1
  52. package/src/Core/subscribe-to-sdk-authentication-failures.js +1 -1
  53. package/src/Core/toggle-logging.js +2 -2
  54. package/src/Core/wipe-data.js +6 -6
  55. package/src/DUST/dust-connection-core.js +1 -0
  56. package/src/DUST/dust-provider-factory.js +10 -10
  57. package/src/DUST/dust-provider.js +258 -226
  58. package/src/DUST/dust-shared-worker-code.js +1 -1
  59. package/src/DUST/dust-shared-worker-impl.js +97 -103
  60. package/src/DUST/dust-worker-bridge.js +55 -40
  61. package/src/DUST/subscribe-to-dust.js +7 -7
  62. package/src/FeatureFlags/feature-flag-factory.js +8 -8
  63. package/src/FeatureFlags/feature-flag.js +3 -3
  64. package/src/FeatureFlags/feature-flags-provider.js +21 -21
  65. package/src/FeatureFlags/log-feature-flag-impression.js +5 -5
  66. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
  67. package/src/InAppMessage/constants.js +3 -3
  68. package/src/InAppMessage/defer-in-app-message.js +3 -3
  69. package/src/InAppMessage/display/html-message-to-html.js +4 -4
  70. package/src/InAppMessage/display/in-app-message-to-html.js +32 -32
  71. package/src/InAppMessage/display/modal-utils.js +2 -2
  72. package/src/InAppMessage/in-app-message-factory.js +36 -36
  73. package/src/InAppMessage/in-app-message-manager.js +35 -35
  74. package/src/InAppMessage/log-in-app-message-button-click.js +3 -3
  75. package/src/InAppMessage/log-in-app-message-click.js +3 -3
  76. package/src/InAppMessage/log-in-app-message-html-click.js +3 -3
  77. package/src/InAppMessage/log-in-app-message-impression.js +3 -3
  78. package/src/InAppMessage/models/control-message.js +4 -4
  79. package/src/InAppMessage/models/full-screen-message.js +9 -9
  80. package/src/InAppMessage/models/html-message.js +2 -2
  81. package/src/InAppMessage/models/in-app-message-button.js +4 -4
  82. package/src/InAppMessage/models/in-app-message.js +34 -34
  83. package/src/InAppMessage/models/modal-message.js +7 -7
  84. package/src/InAppMessage/models/slide-up-message.js +8 -8
  85. package/src/InAppMessage/ui/show-in-app-message.js +20 -20
  86. package/src/Push/push-manager.js +44 -44
  87. package/src/User/user-manager.js +19 -19
  88. package/src/User/user.js +17 -17
  89. package/src/common/base-provider.js +1 -1
  90. package/src/common/constants.js +1 -0
  91. package/src/common/content-cards-display.js +6 -6
  92. package/src/common/event-logger.js +3 -3
  93. package/src/common/properties-base.js +3 -3
  94. package/src/l10n/l10n-manager.js +2 -2
  95. package/src/managers/auth-manager.js +11 -11
  96. package/src/managers/braze-instance.js +59 -59
  97. package/src/managers/device-manager.js +9 -9
  98. package/src/managers/network-manager.js +65 -63
  99. package/src/managers/server-config-manager.js +110 -93
  100. package/src/managers/session-manager.js +20 -20
  101. package/src/managers/storage-manager-factory.js +9 -9
  102. package/src/managers/storage-manager.js +137 -137
  103. package/src/managers/subscription-manager.js +2 -2
  104. package/src/managers/utils.js +1 -1
  105. package/src/models/braze-event.js +2 -2
  106. package/src/models/identifier.js +5 -5
  107. package/src/models/push-token.js +8 -8
  108. package/src/models/request-result.js +1 -1
  109. package/src/models/server-config.js +46 -28
  110. package/src/request-controller.js +124 -124
  111. package/src/triggers/models/custom-event-data.js +4 -4
  112. package/src/triggers/models/custom-event-property-data.js +5 -5
  113. package/src/triggers/models/filter-set.js +2 -2
  114. package/src/triggers/models/filter.js +1 -1
  115. package/src/triggers/models/in-app-message-click-data.js +5 -5
  116. package/src/triggers/models/purchase-data.js +1 -1
  117. package/src/triggers/models/purchase-property-data.js +2 -2
  118. package/src/triggers/models/push-click-data.js +5 -5
  119. package/src/triggers/models/trigger-condition.js +45 -45
  120. package/src/triggers/models/trigger-events.js +3 -3
  121. package/src/triggers/models/trigger.js +30 -30
  122. package/src/triggers/triggers-provider.js +63 -63
  123. package/src/types.js +5 -1
  124. package/src/ui/js/attach-css.js +1 -1
  125. package/src/util/braze-actions.js +6 -6
  126. package/src/util/browser-detector.js +13 -13
  127. package/src/util/client-hints-parser.js +5 -5
  128. package/src/util/code-utils.js +2 -2
  129. package/src/util/deprecation-utils.js +2 -2
  130. package/src/util/dom-utils.js +8 -8
  131. package/src/util/ecommerce-event-validation.js +343 -0
  132. package/src/util/html-display-utils.js +11 -11
  133. package/src/util/iso-4217-currency-codes.js +176 -0
  134. package/src/util/net.js +4 -4
  135. package/src/util/request-header-utils.js +10 -10
  136. package/src/util/string-utils.js +2 -2
  137. package/src/util/user-agent-parser.js +15 -15
  138. package/src/util/validation-utils.js +14 -14
@@ -1,5 +1,5 @@
1
- import { logger as E } from "../../shared-lib/index.js";
2
- import { getErrorMessage as ai } from "./error-utils.js";
1
+ import { logger as b } from "../../shared-lib/index.js";
2
+ import { getErrorMessage as hi } from "./error-utils.js";
3
3
  import { decodeBrazeActions as uo } from "./string-utils.js";
4
4
  import {
5
5
  BRAZE_ACTION_URI_REGEX as to,
@@ -26,7 +26,7 @@ export const BRAZE_ACTIONS = {
26
26
  };
27
27
  export const INELIGIBLE_BRAZE_ACTION_URL_ERROR_TYPES = {
28
28
  Un: "unknownBrazeAction",
29
- Zc: "noPushPrompt",
29
+ Nc: "noPushPrompt",
30
30
  };
31
31
  export const ineligibleBrazeActionURLErrorMessage = (t, o) =>
32
32
  t === INELIGIBLE_BRAZE_ACTION_URL_ERROR_TYPES.Un
@@ -38,15 +38,15 @@ export function getDecodedBrazeAction(t) {
38
38
  r = o ? o[0].length : null,
39
39
  n = r ? t.substring(r) : null;
40
40
  if (null == r || r > t.length - 1 || !n)
41
- return void E.error(
41
+ return void b.error(
42
42
  `Did not find base64 encoded brazeAction in url to process : ${t}`,
43
43
  );
44
44
  const e = uo(n);
45
45
  return e
46
46
  ? JSON.parse(e)
47
- : void E.error(`Failed to decode base64 encoded brazeAction: ${n}`);
47
+ : void b.error(`Failed to decode base64 encoded brazeAction: ${n}`);
48
48
  } catch (o) {
49
- return void E.error(`Failed to process brazeAction URL ${t} : ${ai(o)}`);
49
+ return void b.error(`Failed to process brazeAction URL ${t} : ${hi(o)}`);
50
50
  }
51
51
  }
52
52
  function po(t, o) {
@@ -1,13 +1,13 @@
1
1
  import Si from "./client-hints-parser.js";
2
- import bi from "./user-agent-parser.js";
3
- import { Browsers as vi, OperatingSystems as so } from "./device-constants.js";
4
- class yi {
2
+ import vi from "./user-agent-parser.js";
3
+ import { Browsers as yi, OperatingSystems as so } from "./device-constants.js";
4
+ class xi {
5
5
  constructor() {
6
6
  let t;
7
7
  (t =
8
- navigator.userAgent.toLowerCase().includes(vi.Sg.toLowerCase()) ||
8
+ navigator.userAgent.toLowerCase().includes(yi.Sg.toLowerCase()) ||
9
9
  !navigator.userAgentData
10
- ? bi
10
+ ? vi
11
11
  : Si),
12
12
  (this.vg = new t()),
13
13
  (this.userAgent = navigator.userAgent),
@@ -23,10 +23,10 @@ class yi {
23
23
  i.systemLanguage ||
24
24
  ""
25
25
  ).toLowerCase()),
26
- (this.il = yi.xg(this.userAgent));
26
+ (this.il = xi.xg(this.userAgent));
27
27
  }
28
- IS() {
29
- return this.browser === vi.Bg;
28
+ bS() {
29
+ return this.browser === yi.Bg;
30
30
  }
31
31
  Aa() {
32
32
  return this.OS || null;
@@ -34,14 +34,14 @@ class yi {
34
34
  Fa() {
35
35
  return this.OS
36
36
  ? Promise.resolve(this.OS)
37
- : this.vg.Fa(yi.Og).then((t) => ((this.OS = t), t));
37
+ : this.vg.Fa(xi.Og).then((t) => ((this.OS = t), t));
38
38
  }
39
39
  static xg(t) {
40
40
  t = t.toLowerCase();
41
41
  const i = [
42
42
  "bot",
43
+ "spider",
43
44
  "slurp",
44
- "baiduspider",
45
45
  "yandex",
46
46
  "facebookexternalhit",
47
47
  "sogou",
@@ -63,7 +63,7 @@ class yi {
63
63
  return !1;
64
64
  }
65
65
  }
66
- yi.Og = [
66
+ xi.Og = [
67
67
  { string: navigator.platform, cf: "Win", identity: so.kg },
68
68
  { string: navigator.platform, cf: "Mac", identity: so.Pg },
69
69
  { string: navigator.platform, cf: "BlackBerry", identity: "BlackBerry" },
@@ -91,5 +91,5 @@ yi.Og = [
91
91
  { string: navigator.userAgent, cf: ["Android"], identity: so.Dg },
92
92
  { string: navigator.platform, cf: "Linux", identity: "Linux" },
93
93
  ];
94
- const ro = new yi();
95
- export { ro as default, yi as BrowserDetector };
94
+ const ro = new xi();
95
+ export { ro as default, xi as BrowserDetector };
@@ -1,5 +1,5 @@
1
1
  import Ve from "./base-device-parser.js";
2
- import { Browsers as vi } from "./device-constants.js";
2
+ import { Browsers as yi } from "./device-constants.js";
3
3
  export default class Si extends Ve {
4
4
  constructor() {
5
5
  if (
@@ -9,7 +9,7 @@ export default class Si extends Ve {
9
9
  (this.version = null),
10
10
  this.userAgentData)
11
11
  ) {
12
- const t = this.hf();
12
+ const t = this.Bc();
13
13
  (this.browser = t.browser || "Unknown Browser"),
14
14
  (this.version = t.version || "Unknown Version");
15
15
  }
@@ -36,12 +36,12 @@ export default class Si extends Ve {
36
36
  .then((t) => (t.platform ? s(t.platform) : navigator.platform))
37
37
  .catch(() => navigator.platform);
38
38
  }
39
- hf() {
39
+ Bc() {
40
40
  const t = {},
41
41
  s = this.userAgentData.brands;
42
42
  if (s && s.length)
43
43
  for (const r of s) {
44
- const s = this.uf(vi),
44
+ const s = this.Vc(yi),
45
45
  i = r.brand.match(s);
46
46
  if (i && i.length > 0) {
47
47
  (t.browser = i[0]), (t.version = r.version);
@@ -50,7 +50,7 @@ export default class Si extends Ve {
50
50
  }
51
51
  return t;
52
52
  }
53
- uf(t) {
53
+ Vc(t) {
54
54
  const s = [];
55
55
  for (const r in t) {
56
56
  const i = r;
@@ -1,4 +1,4 @@
1
- import { logger as E } from "../../shared-lib/index.js";
1
+ import { logger as b } from "../../shared-lib/index.js";
2
2
  export function values(t) {
3
3
  const e = [];
4
4
  let r;
@@ -13,7 +13,7 @@ export function validateValueIsFromEnum(t, e, r, n) {
13
13
  const o = values(t);
14
14
  return (
15
15
  -1 !== o.indexOf(e) ||
16
- (E.error(`${r} Valid values from ${n} are "${o.join('"/"')}".`), !1)
16
+ (b.error(`${r} Valid values from ${n} are "${o.join('"/"')}".`), !1)
17
17
  );
18
18
  }
19
19
  export function isArray(t) {
@@ -1,5 +1,5 @@
1
- import { logger as E } from "../../shared-lib/index.js";
1
+ import { logger as b } from "../../shared-lib/index.js";
2
2
  export function logDeprecationWarning(e, i, n) {
3
3
  let r = `The '${e}' ${i} is deprecated.`;
4
- n && (r += ` Please use '${n}' instead.`), E.warn(r);
4
+ n && (r += ` Please use '${n}' instead.`), b.warn(r);
5
5
  }
@@ -1,5 +1,5 @@
1
- import { logger as E } from "../../shared-lib/index.js";
2
- import { getErrorMessage as ai } from "./error-utils.js";
1
+ import { logger as b } from "../../shared-lib/index.js";
2
+ import { getErrorMessage as hi } from "./error-utils.js";
3
3
  export function _isInView(t, n = !1, e = !1, s = !1) {
4
4
  if (null == t) return !1;
5
5
  (n = n || !1), (e = e || !1);
@@ -18,24 +18,24 @@ export function _isInView(t, n = !1, e = !1, s = !1) {
18
18
  !s)
19
19
  );
20
20
  }
21
- export const DOMUtils = { lp: null, td: _isInView };
21
+ export const DOMUtils = { Ic: null, td: _isInView };
22
22
  export const DIRECTIONS = { Uo: "up", Vo: "down", ie: "left", ne: "right" };
23
23
  export function supportsPassive() {
24
- if (null == DOMUtils.lp) {
25
- DOMUtils.lp = !1;
24
+ if (null == DOMUtils.Ic) {
25
+ DOMUtils.Ic = !1;
26
26
  try {
27
27
  const t = Object.defineProperty({}, "passive", {
28
28
  get: () => {
29
- DOMUtils.lp = !0;
29
+ DOMUtils.Ic = !0;
30
30
  },
31
31
  });
32
32
  window.addEventListener("testPassive", () => {}, t),
33
33
  window.removeEventListener("testPassive", () => {}, t);
34
34
  } catch (t) {
35
- E.error(ai(t));
35
+ b.error(hi(t));
36
36
  }
37
37
  }
38
- return DOMUtils.lp;
38
+ return DOMUtils.Ic;
39
39
  }
40
40
  export function addPassiveEventListener(t, n, e = () => {}) {
41
41
  t.addEventListener(n, e, !!supportsPassive() && { passive: !0 });
@@ -0,0 +1,343 @@
1
+ import { logger as b } from "../../shared-lib/index.js";
2
+ import { isValidIso4217CurrencyCode as or } from "./iso-4217-currency-codes.js";
3
+ import { CoreStrings as R } from "../common/constants.js";
4
+ import { CartUpdatedActions as un } from "../types.js";
5
+ import {
6
+ isArray as g,
7
+ isObject as Ct,
8
+ validateValueIsFromEnum as ta,
9
+ } from "./code-utils.js";
10
+ import {
11
+ validateCustomProperties as nt,
12
+ validateCustomString as mt,
13
+ } from "./validation-utils.js";
14
+ const ln = "log eCommerce event";
15
+ function dn(n, t, e) {
16
+ if (null == n) {
17
+ if (!e) return;
18
+ return b.error(`Cannot ${ln} because ${t} must be a non-empty string.`), !1;
19
+ }
20
+ return "string" != typeof n || (e && n.length <= 0)
21
+ ? (b.error(
22
+ `Cannot ${ln} because ${t} must be a string${
23
+ e ? "" : " when provided"
24
+ }.`,
25
+ ),
26
+ !1)
27
+ : n.length > 255
28
+ ? (b.error(`Cannot ${ln} because ${t} must be at most 255 characters.`), !1)
29
+ : !!mt(n, ln, t) && n;
30
+ }
31
+ function mn(n, t) {
32
+ return "number" != typeof n || isNaN(n) || !isFinite(n)
33
+ ? (b.error(`Cannot ${ln} because ${t} must be a finite number.`), !1)
34
+ : n;
35
+ }
36
+ function pn(n, t) {
37
+ const e = mn(n, t);
38
+ return (
39
+ !1 !== e &&
40
+ (e < 0 ? (b.error(`Cannot ${ln} because ${t} must be at least 0.`), !1) : e)
41
+ );
42
+ }
43
+ const bn = /^[A-Za-z0-9\-_.,:;!?@#%&*()+={}[\]|\\/'`~^<>]+$/;
44
+ function _n(n, t) {
45
+ return 0 === n.length || n.length > 255
46
+ ? (b.error(
47
+ `Cannot ${ln} because each ${t} key must be between 1 and 255 characters.`,
48
+ ),
49
+ !1)
50
+ : "$" === n.charAt(0)
51
+ ? (b.error(`Cannot ${ln} because ${t} keys cannot begin with "$".`), !1)
52
+ : !!bn.test(n) ||
53
+ (b.error(
54
+ `Cannot ${ln} because ${t} key "${n}" contains invalid characters.`,
55
+ ),
56
+ !1);
57
+ }
58
+ function $n(n, t, e) {
59
+ if (e > 50)
60
+ return b.error(`Cannot ${ln} because ${t} is nested too deeply.`), !1;
61
+ if (null == n || "object" != typeof n) return !0;
62
+ if (g(n)) {
63
+ const r = n;
64
+ for (let n = 0; n < r.length; n++) {
65
+ const u = r[n];
66
+ if ("string" == typeof u) {
67
+ if (u.length > 255)
68
+ return (
69
+ b.error(
70
+ `Cannot ${ln} because a ${t} string value exceeds 255 characters.`,
71
+ ),
72
+ !1
73
+ );
74
+ } else if (!$n(u, t, e + 1)) return !1;
75
+ }
76
+ return !0;
77
+ }
78
+ if (!Ct(n)) return !0;
79
+ const r = n;
80
+ for (const n in r) {
81
+ if (!Object.prototype.hasOwnProperty.call(r, n)) continue;
82
+ if (!_n(n, t)) return !1;
83
+ const u = r[n];
84
+ if ("string" == typeof u) {
85
+ if (u.length > 255)
86
+ return (
87
+ b.error(
88
+ `Cannot ${ln} because a ${t} string value exceeds 255 characters.`,
89
+ ),
90
+ !1
91
+ );
92
+ } else if (null != u && "object" == typeof u && !$n(u, t, e + 1)) return !1;
93
+ }
94
+ return !0;
95
+ }
96
+ function vn(n, t) {
97
+ if (!g(n))
98
+ return (
99
+ b.error(`Cannot ${ln} because ${t} must be an array of strings.`), !1
100
+ );
101
+ for (const e of n) if (!1 === dn(e, t, !0)) return !1;
102
+ return !0;
103
+ }
104
+ function yn(n, t) {
105
+ if (void 0 === n) return;
106
+ const [e, r] = nt(null != n ? n : {}, R.QE, "metadata", ln, t);
107
+ return !!e && !(null != r && !$n(r, t, 0)) && r;
108
+ }
109
+ function gn(n) {
110
+ if (null == n || "object" != typeof n || g(n))
111
+ return (
112
+ b.error(`Cannot ${ln} because each product must be an object.`), null
113
+ );
114
+ const t = n,
115
+ e = dn(t.product_id, "product_id", !0),
116
+ r = dn(t.product_name, "product_name", !0),
117
+ u = dn(t.variant_id, "variant_id", !0),
118
+ o = (function (n) {
119
+ if (!1 === mn(n, "product quantity")) return !1;
120
+ const t = parseInt(n.toString(), 10);
121
+ return t !== n
122
+ ? (b.error(`Cannot ${ln} because product quantity must be an integer.`),
123
+ !1)
124
+ : n < 0 || n > Number.MAX_SAFE_INTEGER
125
+ ? (b.error(
126
+ `Cannot ${ln} because product quantity must be between 0 and Number.MAX_SAFE_INTEGER.`,
127
+ ),
128
+ !1)
129
+ : t;
130
+ })(t.quantity),
131
+ c = pn(t.price, "product price");
132
+ if (!1 === e || !1 === r || !1 === u || !1 === o || !1 === c) return null;
133
+ const i = dn(t.image_url, "image_url", !1),
134
+ a = dn(t.product_url, "product_url", !1);
135
+ if (!1 === i || !1 === a) return null;
136
+ const s = yn(t.metadata, "eCommerce product metadata");
137
+ if (!1 === s) return null;
138
+ const l = {
139
+ product_id: e,
140
+ product_name: r,
141
+ variant_id: u,
142
+ quantity: o,
143
+ price: c,
144
+ };
145
+ return (
146
+ null != i && (l.image_url = i),
147
+ null != a && (l.product_url = a),
148
+ null != s && (l.metadata = s),
149
+ l
150
+ );
151
+ }
152
+ function Cn(n) {
153
+ if (null == n || !g(n))
154
+ return b.error(`Cannot ${ln} because products must be an array.`), null;
155
+ const t = [],
156
+ e = n;
157
+ for (const n of e) {
158
+ const e = gn(n);
159
+ if (null == e) return null;
160
+ t.push(e);
161
+ }
162
+ return t;
163
+ }
164
+ function hn(n) {
165
+ const t = (function (n) {
166
+ if (null == n || "string" != typeof n || n.length <= 0)
167
+ return (
168
+ b.error(`Cannot ${ln} because currency must be a non-empty string.`),
169
+ !1
170
+ );
171
+ const t = n.toUpperCase();
172
+ return or(t)
173
+ ? t
174
+ : (b.error(
175
+ `${R.QE} requires a valid ISO 4217 currency code, got "${n}". Ignoring event.`,
176
+ ),
177
+ !1);
178
+ })(n.currency),
179
+ e = dn(n.source, "source", !0);
180
+ return !1 === t || !1 === e ? null : { currency: t, source: e };
181
+ }
182
+ function jn(n, t) {
183
+ const e = ["subtotal_value", "tax", "shipping"];
184
+ for (const r of e)
185
+ if (null != t[r]) {
186
+ const e = pn(t[r], r);
187
+ if (!1 === e) return !1;
188
+ n[r] = e;
189
+ }
190
+ return !0;
191
+ }
192
+ function wn(n, t) {
193
+ const e = yn(t, "eCommerce event metadata");
194
+ return !1 !== e && (null != e && (n.metadata = e), !0);
195
+ }
196
+ function kn(n, t) {
197
+ const e = dn(n.cart_id, "cart_id", !0),
198
+ r =
199
+ void 0 === n.action
200
+ ? un.REPLACE
201
+ : ((u = n.action),
202
+ !!ta(
203
+ un,
204
+ u,
205
+ `Cannot ${ln} because action is invalid.`,
206
+ "CartUpdatedActions",
207
+ ) && u);
208
+ var u;
209
+ const o = Cn(n.products);
210
+ if (!1 === e || !1 === r || null == o) return null;
211
+ const c = r === un.Ld || r === un.Md,
212
+ i =
213
+ void 0 === n.total_value && c ? void 0 : pn(n.total_value, "total_value");
214
+ if (!1 === i) return null;
215
+ const a = {
216
+ cart_id: e,
217
+ action: r,
218
+ currency: t.currency,
219
+ products: o,
220
+ source: t.source,
221
+ };
222
+ return (
223
+ void 0 !== i && (a.total_value = i),
224
+ jn(a, n) && wn(a, n.metadata) ? a : null
225
+ );
226
+ }
227
+ export function sanitizeEcommerceEvent(n) {
228
+ const t = n.properties;
229
+ if (null == t || "object" != typeof t || g(t))
230
+ return b.error(`${R.QE} requires a properties object.`), null;
231
+ const e = t,
232
+ r = hn(e);
233
+ if (null == r) return null;
234
+ switch (n.name) {
235
+ case "ecommerce.product_viewed":
236
+ return (function (n, t) {
237
+ const e = n.metadata;
238
+ if (void 0 !== n.type && !vn(n.type, "type")) return null;
239
+ const r = dn(n.product_id, "product_id", !0),
240
+ u = dn(n.product_name, "product_name", !0),
241
+ o = dn(n.variant_id, "variant_id", !0),
242
+ c = pn(n.price, "price"),
243
+ i = dn(n.image_url, "image_url", !1),
244
+ a = dn(n.product_url, "product_url", !1);
245
+ if (
246
+ !1 === r ||
247
+ !1 === u ||
248
+ !1 === o ||
249
+ !1 === c ||
250
+ !1 === i ||
251
+ !1 === a
252
+ )
253
+ return null;
254
+ const s = {
255
+ product_id: r,
256
+ product_name: u,
257
+ variant_id: o,
258
+ price: c,
259
+ currency: t.currency,
260
+ source: t.source,
261
+ };
262
+ return (
263
+ null != i && (s.image_url = i),
264
+ null != a && (s.product_url = a),
265
+ void 0 !== n.type && (s.type = n.type),
266
+ wn(s, e) ? s : null
267
+ );
268
+ })(e, r);
269
+ case "ecommerce.cart_updated":
270
+ return kn(e, r);
271
+ case "ecommerce.checkout_started":
272
+ return (function (n, t) {
273
+ const e = dn(n.checkout_id, "checkout_id", !0),
274
+ r = pn(n.total_value, "total_value"),
275
+ u = Cn(n.products),
276
+ o = dn(n.cart_id, "cart_id", !1);
277
+ if (!1 === e || !1 === r || null == u || !1 === o) return null;
278
+ const c = {
279
+ checkout_id: e,
280
+ total_value: r,
281
+ currency: t.currency,
282
+ products: u,
283
+ source: t.source,
284
+ };
285
+ return (
286
+ null != o && (c.cart_id = o), jn(c, n) && wn(c, n.metadata) ? c : null
287
+ );
288
+ })(e, r);
289
+ case "ecommerce.order_placed":
290
+ return (function (n, t) {
291
+ const e = n.metadata;
292
+ if (null != e && "object" == typeof e && !g(e)) {
293
+ const n = e;
294
+ if (void 0 !== n.tags && !vn(n.tags, "metadata.tags")) return null;
295
+ if (
296
+ void 0 !== n.payment_gateway_names &&
297
+ !vn(n.payment_gateway_names, "metadata.payment_gateway_names")
298
+ )
299
+ return null;
300
+ }
301
+ const r = dn(n.order_id, "order_id", !0),
302
+ u = pn(n.total_value, "total_value"),
303
+ o = Cn(n.products),
304
+ c = dn(n.cart_id, "cart_id", !1);
305
+ if (!1 === r || !1 === u || null == o || !1 === c) return null;
306
+ const i = {
307
+ order_id: r,
308
+ total_value: u,
309
+ currency: t.currency,
310
+ products: o,
311
+ source: t.source,
312
+ };
313
+ if ((null != c && (i.cart_id = c), null != n.total_discounts)) {
314
+ const t = pn(n.total_discounts, "total_discounts");
315
+ if (!1 === t) return null;
316
+ i.total_discounts = t;
317
+ }
318
+ if (void 0 !== n.discounts) {
319
+ if (!g(n.discounts))
320
+ return (
321
+ b.error(`Cannot ${ln} because discounts must be an array.`), null
322
+ );
323
+ const [t, e] = nt(
324
+ { discounts: n.discounts },
325
+ R.QE,
326
+ "discounts",
327
+ ln,
328
+ "eCommerce order discounts",
329
+ );
330
+ if (!t || null == e) return null;
331
+ i.discounts = e.discounts;
332
+ }
333
+ return jn(i, n) && wn(i, n.metadata) ? i : null;
334
+ })(e, r);
335
+ default:
336
+ return (
337
+ b.error(
338
+ "logEcommerceEvent received an unknown event name. Ignoring event.",
339
+ ),
340
+ null
341
+ );
342
+ }
343
+ }
@@ -1,8 +1,8 @@
1
- import { logger as E } from "../../shared-lib/index.js";
1
+ import { logger as b } from "../../shared-lib/index.js";
2
2
  import { getUser as ao } from "../Core/get-user.js";
3
3
  import { CoreStrings as R } from "../common/constants.js";
4
4
  import r from "../managers/braze-instance.js";
5
- import { keys as D } from "../util/code-utils.js";
5
+ import { keys as C } from "../util/code-utils.js";
6
6
  import User from "../User/user.js";
7
7
  export const buildBrazeBridge = (t, e) => {
8
8
  const o = { display: {}, web: {} },
@@ -12,7 +12,7 @@ export const buildBrazeBridge = (t, e) => {
12
12
  import("../Push/request-push-permission.js").then((e) => {
13
13
  r.ao()
14
14
  ? e.requestPushPermission(...Array.prototype.slice.call(t))
15
- : E.error(R.ee);
15
+ : b.error(R.ee);
16
16
  });
17
17
  };
18
18
  },
@@ -23,7 +23,7 @@ export const buildBrazeBridge = (t, e) => {
23
23
  ({ requestImmediateDataFlush: requestImmediateDataFlush }) => {
24
24
  r.ao()
25
25
  ? requestImmediateDataFlush(...Array.prototype.slice.call(t))
26
- : E.error(R.ee);
26
+ : b.error(R.ee);
27
27
  },
28
28
  );
29
29
  },
@@ -31,7 +31,7 @@ export const buildBrazeBridge = (t, e) => {
31
31
  const t = arguments;
32
32
  import("../Core/log-custom-event.js").then(
33
33
  ({ logCustomEvent: logCustomEvent }) => {
34
- if (!r.ao()) return void E.error(R.ee);
34
+ if (!r.ao()) return void b.error(R.ee);
35
35
  logCustomEvent(...Array.prototype.slice.call(t));
36
36
  },
37
37
  );
@@ -40,7 +40,7 @@ export const buildBrazeBridge = (t, e) => {
40
40
  const t = arguments;
41
41
  import("../Core/log-purchase.js").then(
42
42
  ({ logPurchase: logPurchase }) => {
43
- if (!r.ao()) return void E.error(R.ee);
43
+ if (!r.ao()) return void b.error(R.ee);
44
44
  logPurchase(...Array.prototype.slice.call(t));
45
45
  },
46
46
  );
@@ -51,7 +51,7 @@ export const buildBrazeBridge = (t, e) => {
51
51
  ({ unregisterPush: unregisterPush }) => {
52
52
  r.ao()
53
53
  ? unregisterPush(...Array.prototype.slice.call(t))
54
- : E.error(R.ee);
54
+ : b.error(R.ee);
55
55
  },
56
56
  );
57
57
  },
@@ -59,7 +59,7 @@ export const buildBrazeBridge = (t, e) => {
59
59
  changeUser: function () {
60
60
  const t = arguments;
61
61
  import("../Core/change-user.js").then(({ changeUser: changeUser }) => {
62
- if (!r.ao()) return void E.error(R.ee);
62
+ if (!r.ao()) return void b.error(R.ee);
63
63
  changeUser(...Array.prototype.slice.call(t));
64
64
  });
65
65
  },
@@ -69,7 +69,7 @@ export const buildBrazeBridge = (t, e) => {
69
69
  n[t](...Array.prototype.slice.call(arguments));
70
70
  };
71
71
  };
72
- for (const t of D(n)) o[t] = s(t);
72
+ for (const t of C(n)) o[t] = s(t);
73
73
  const i = [
74
74
  "setFirstName",
75
75
  "setLastName",
@@ -115,7 +115,7 @@ export const buildBrazeBridge = (t, e) => {
115
115
  };
116
116
  },
117
117
  f = o.display;
118
- for (const t of D(a)) f[t] = m(t);
118
+ for (const t of C(a)) f[t] = m(t);
119
119
  const l = { registerAppboyPushMessages: requestPushPermission() },
120
120
  p = function (t) {
121
121
  return function () {
@@ -123,7 +123,7 @@ export const buildBrazeBridge = (t, e) => {
123
123
  };
124
124
  },
125
125
  y = o.web;
126
- for (const t of D(l)) y[t] = p(t);
126
+ for (const t of C(l)) y[t] = p(t);
127
127
  return (
128
128
  (o.NotificationSubscriptionTypes = User.NotificationSubscriptionTypes), o
129
129
  );