@braze/web-sdk 5.3.2 → 5.4.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 (48) hide show
  1. package/index.d.ts +20 -4
  2. package/package.json +1 -1
  3. package/shared-lib/event-types.js +7 -7
  4. package/shared-lib/indexed-db-adapter.js +1 -1
  5. package/shared-lib/logger.js +2 -2
  6. package/shared-lib/supported-options.js +9 -8
  7. package/src/Card/display/card-display.js +59 -58
  8. package/src/Core/index.js +1 -0
  9. package/src/Core/is-initialized.js +4 -0
  10. package/src/InAppMessage/display/in-app-message-to-html.js +64 -62
  11. package/src/InAppMessage/ui/show-in-app-message.js +42 -40
  12. package/src/Push/push-manager-factory.js +2 -1
  13. package/src/Push/push-manager.js +73 -85
  14. package/src/Push/utils/push-utils.js +3 -3
  15. package/src/User/user-manager.js +2 -2
  16. package/src/User/user.js +4 -4
  17. package/src/common/event-logger.js +4 -4
  18. package/src/common/feed-display.js +17 -16
  19. package/src/l10n/l10n-manager-factory.js +7 -7
  20. package/src/l10n/l10n-manager.js +15 -5
  21. package/src/managers/braze-instance.js +53 -51
  22. package/src/managers/device-manager.js +17 -17
  23. package/src/managers/network-manager.js +89 -89
  24. package/src/managers/server-config-manager.js +4 -4
  25. package/src/managers/session-manager.js +4 -4
  26. package/src/managers/storage-manager-factory.js +1 -1
  27. package/src/managers/storage-manager.js +17 -17
  28. package/src/models/backend-errors.js +5 -5
  29. package/src/models/braze-event.js +3 -3
  30. package/src/models/device.js +1 -1
  31. package/src/models/server-config.js +2 -2
  32. package/src/request-controller.js +74 -74
  33. package/src/triggers/models/filter.js +3 -3
  34. package/src/triggers/models/in-app-message-click-data.js +8 -8
  35. package/src/triggers/models/push-click-data.js +3 -3
  36. package/src/triggers/models/trigger-condition.js +1 -1
  37. package/src/triggers/triggers-provider.js +3 -3
  38. package/src/ui/js/attach-css.js +1 -1
  39. package/src/ui/js/feed-css.js +1 -1
  40. package/src/ui/js/iam-css.js +1 -1
  41. package/src/util/base-device-parser.js +7 -7
  42. package/src/util/browser-detector.js +21 -21
  43. package/src/util/client-hints-parser.js +3 -3
  44. package/src/util/component-utils.js +13 -12
  45. package/src/util/net.js +1 -1
  46. package/src/util/request-header-utils.js +7 -7
  47. package/src/util/user-agent-parser.js +3 -3
  48. package/src/util/window-utils.js +1 -1
@@ -12,7 +12,7 @@ import { Card, ControlCard } from "../Card/index.js";
12
12
  import { cardToHtml as _e } from "../Card/display/card-display.js";
13
13
  import { isArray as j } from "../util/code-utils.js";
14
14
  import { KeyCodes as mt } from "../util/key-codes.js";
15
- import je from "../l10n/l10n-manager-factory.js";
15
+ import ue from "../l10n/l10n-manager-factory.js";
16
16
  import { removeSubscription } from "../Core/remove-subscription.js";
17
17
  import { logger as r, Guid as p } from "../../shared-lib/index.js";
18
18
  import { BRAZE_ACTION_URI_REGEX as Z } from "../util/validation-utils.js";
@@ -41,11 +41,12 @@ export function destroyFeedHtml(e) {
41
41
  delete scrollListeners[o]);
42
42
  }
43
43
  export function generateFeedBody(e, t) {
44
- const o = document.createElement("div");
44
+ const o = ue.m(),
45
+ s = document.createElement("div");
45
46
  if (
46
- ((o.className = "ab-feed-body"),
47
- o.setAttribute("aria-label", "Feed"),
48
- o.setAttribute("role", "feed"),
47
+ ((s.className = "ab-feed-body"),
48
+ s.setAttribute("aria-label", "Feed"),
49
+ s.setAttribute("role", "feed"),
49
50
  null == e.lastUpdated)
50
51
  ) {
51
52
  const e = document.createElement("div");
@@ -53,27 +54,27 @@ export function generateFeedBody(e, t) {
53
54
  const t = document.createElement("i");
54
55
  (t.className = "fa fa-spinner fa-spin fa-4x ab-initial-spinner"),
55
56
  e.appendChild(t),
56
- o.appendChild(e);
57
+ s.appendChild(e);
57
58
  } else {
58
- let s = !1;
59
+ let n = !1;
59
60
  const logCardClick = (t) => e.logCardClick(t);
60
- for (const n of e.cards) {
61
- const i = n instanceof ControlCard;
62
- !i || e.dr()
63
- ? (o.appendChild(_e(n, logCardClick, t)), (s = s || !i))
61
+ for (const i of e.cards) {
62
+ const a = i instanceof ControlCard;
63
+ !a || e.dr()
64
+ ? (s.appendChild(_e(i, logCardClick, t, o.wo())), (n = n || !a))
64
65
  : r.error(
65
66
  "Received a control card for a legacy news feed. Control cards are only supported with content cards.",
66
67
  );
67
68
  }
68
- if (!s) {
69
+ if (!n) {
69
70
  const e = document.createElement("div");
70
71
  (e.className = "ab-no-cards-message"),
71
- (e.innerHTML = je.m().get("NO_CARDS_MESSAGE") || ""),
72
+ (e.innerHTML = o.get("NO_CARDS_MESSAGE") || ""),
72
73
  e.setAttribute("role", "article"),
73
- o.appendChild(e);
74
+ s.appendChild(e);
74
75
  }
75
76
  }
76
- return o;
77
+ return s;
77
78
  }
78
79
  export function detectFeedImpressions(e, t) {
79
80
  if (null != e && null != t) {
@@ -123,7 +124,7 @@ export function refreshFeed(e, t) {
123
124
  const o = t.querySelectorAll(".ab-initial-spinner")[0];
124
125
  if (null != o) {
125
126
  const e = document.createElement("span");
126
- (e.innerHTML = je.m().get("FEED_TIMEOUT_MESSAGE") || ""),
127
+ (e.innerHTML = ue.m().get("FEED_TIMEOUT_MESSAGE") || ""),
127
128
  null != o.parentNode &&
128
129
  (o.parentNode.appendChild(e), o.parentNode.removeChild(o));
129
130
  }
@@ -1,22 +1,22 @@
1
1
  import e, { OPTIONS as L } from "../managers/braze-instance.js";
2
2
  import X from "../util/browser-detector.js";
3
3
  import nr from "./l10n-manager.js";
4
- const je = {
4
+ const ue = {
5
5
  t: !1,
6
6
  i: null,
7
7
  m: () => {
8
- if ((je.o(), !je.i)) {
8
+ if ((ue.o(), !ue.i)) {
9
9
  let r = X.language,
10
10
  t = !1;
11
- e.nn(L.zn) && ((r = e.nn(L.zn)), (t = !0)), (je.i = new nr(r, t));
11
+ e.nn(L.zn) && ((r = e.nn(L.zn)), (t = !0)), (ue.i = new nr(r, t));
12
12
  }
13
- return je.i;
13
+ return ue.i;
14
14
  },
15
15
  o: () => {
16
- je.t || (e.g(je), (je.t = !0));
16
+ ue.t || (e.g(ue), (ue.t = !0));
17
17
  },
18
18
  destroy: () => {
19
- (je.i = null), (je.t = !1);
19
+ (ue.i = null), (ue.t = !1);
20
20
  },
21
21
  };
22
- export default je;
22
+ export default ue;
@@ -1,25 +1,35 @@
1
1
  import { logger as r } from "../../shared-lib/index.js";
2
2
  import xt from "../common/translations.js";
3
3
  export default class nr {
4
- constructor(t, l = !1) {
4
+ constructor(t, e = !1) {
5
5
  if (
6
6
  ((this.language = t),
7
7
  null != t && (t = t.toLowerCase()),
8
8
  null != t && null == xt[t])
9
9
  ) {
10
- const l = t.indexOf("-");
11
- l > 0 && (t = t.substring(0, l));
10
+ const e = t.indexOf("-");
11
+ e > 0 && (t = t.substring(0, e));
12
12
  }
13
13
  if (null == xt[t]) {
14
- const n =
14
+ const a =
15
15
  "Braze does not yet have a localization for language " +
16
16
  t +
17
17
  ", defaulting to English. Please contact us if you are willing and able to help us translate our SDK into this language.";
18
- l ? r.error(n) : r.info(n), (t = "en");
18
+ e ? r.error(a) : r.info(a), (t = "en");
19
19
  }
20
20
  this.language = t;
21
21
  }
22
22
  get(t) {
23
23
  return xt[this.language][t];
24
24
  }
25
+ wo() {
26
+ switch (this.language) {
27
+ case "ar":
28
+ case "he":
29
+ case "fa":
30
+ return "rtl";
31
+ default:
32
+ return "ltr";
33
+ }
34
+ }
25
35
  }
@@ -7,9 +7,9 @@ import {
7
7
  isArray as j,
8
8
  keys as to,
9
9
  validateValueIsFromEnum as J,
10
- values as Pt,
10
+ values as Rt,
11
11
  } from "../util/code-utils.js";
12
- import Rt from "./network-manager.js";
12
+ import Pt from "./network-manager.js";
13
13
  import Lt from "../request-controller.js";
14
14
  import Dt from "./server-config-manager.js";
15
15
  import Mt from "./session-manager.js";
@@ -22,23 +22,23 @@ import { User } from "../User/index.js";
22
22
  import { parseQueryStringKeyValues as ut } from "../util/url-utils.js";
23
23
  import { WindowUtils as eo } from "../util/window-utils.js";
24
24
  import { BRAZE_MUST_BE_INITIALIZED_ERROR as _ } from "../common/constants.js";
25
- import { SupportedOptions as Vt, logger as r } from "../../shared-lib/index.js";
25
+ import { SupportedOptions as zt, logger as r } from "../../shared-lib/index.js";
26
26
  import _t from "../models/identifier.js";
27
27
  const L = {
28
28
  Eo: "allowCrawlerActivity",
29
29
  _o: "baseUrl",
30
30
  Io: "noCookies",
31
- Ao: "devicePropertyAllowlist",
32
- _a: "disablePushTokenMaintenance",
33
- So: "enableLogging",
31
+ So: "devicePropertyAllowlist",
32
+ ka: "disablePushTokenMaintenance",
33
+ Ao: "enableLogging",
34
34
  No: "enableSdkAuthentication",
35
- Ma: "manageServiceWorkerExternally",
35
+ _a: "manageServiceWorkerExternally",
36
36
  Oo: "minimumIntervalBetweenTriggerActionsInSeconds",
37
- Po: "sessionTimeoutInSeconds",
38
- Ro: "appVersion",
37
+ Ro: "sessionTimeoutInSeconds",
38
+ Po: "appVersion",
39
39
  Lo: "appVersionNumber",
40
40
  wa: "serviceWorkerLocation",
41
- ya: "safariWebsitePushId",
41
+ Ma: "safariWebsitePushId",
42
42
  zn: "localization",
43
43
  bo: "contentSecurityNonce",
44
44
  Do: "allowUserSuppliedJavascript",
@@ -49,14 +49,15 @@ const L = {
49
49
  Lh: "requireExplicitInAppMessageDismissal",
50
50
  Mo: "doNotLoadFontAwesome",
51
51
  Uo: "deviceId",
52
- Bo: "sdkFlavor",
52
+ ya: "serviceWorkerScope",
53
+ Wo: "sdkFlavor",
53
54
  };
54
- class zt {
55
+ class Vt {
55
56
  constructor() {
56
57
  (this.rn = ""),
57
- (this.Wo = ""),
58
+ (this.Bo = ""),
58
59
  (this.Vo = void 0),
59
- (this.zo = null),
60
+ (this.Ko = null),
60
61
  (this.on = null),
61
62
  (this.qt = null),
62
63
  (this.zi = null),
@@ -65,7 +66,7 @@ class zt {
65
66
  (this.u = null),
66
67
  (this.wt = null),
67
68
  (this.Go = ""),
68
- (this.Ko = !1),
69
+ (this.isInitialized = !1),
69
70
  (this.$o = !1),
70
71
  (this.qo = new T()),
71
72
  (this.Jo = new T()),
@@ -73,7 +74,7 @@ class zt {
73
74
  (this.Yo = []),
74
75
  (this.Ho = []),
75
76
  (this._e = []),
76
- (this.Wo = "5.3.2");
77
+ (this.Bo = "5.4.0");
77
78
  }
78
79
  Xo(t) {
79
80
  this.qo.It(t);
@@ -85,8 +86,8 @@ class zt {
85
86
  if (this.so())
86
87
  return r.info("Braze has already been initialized with an API key."), !0;
87
88
  this.options = i || {};
88
- let s = this.nn(L.So);
89
- const e = ut(eo.Un());
89
+ let s = this.nn(L.Ao);
90
+ const e = ut(eo.Zo());
90
91
  if (
91
92
  (e && "true" === e.brazeLogging && (s = !0),
92
93
  r.init(s),
@@ -107,7 +108,7 @@ class zt {
107
108
  (n.href = h),
108
109
  "/" === n.pathname && (n = `${n}api/v3`),
109
110
  (this.Go = n.toString()),
110
- X.Zo && !this.nn(L.Eo))
111
+ X.Qo && !this.nn(L.Eo))
111
112
  )
112
113
  return (
113
114
  r.info("Ignoring activity from crawler bot " + navigator.userAgent),
@@ -116,7 +117,7 @@ class zt {
116
117
  );
117
118
  const a = this.nn(L.Io) || !1;
118
119
  if (
119
- ((this.u = Wt.Qo(t, a)), a && this.u.Wh(t), new Q.ee(null, !0).br(o.se))
120
+ ((this.u = Wt.Wh(t, a)), a && this.u.Vh(t), new Q.ee(null, !0).br(o.se))
120
121
  )
121
122
  return (
122
123
  r.info("Ignoring all activity due to previous opt out"),
@@ -124,16 +125,16 @@ class zt {
124
125
  !1
125
126
  );
126
127
  for (const t of to(this.options))
127
- -1 === Pt(Vt).indexOf(t) &&
128
+ -1 === Rt(zt).indexOf(t) &&
128
129
  r.warn(`Ignoring unknown initialization option '${t}'.`);
129
130
  const l = ["mparticle", "wordpress", "tealium"];
130
- if (null != this.nn(L.Bo)) {
131
- const t = this.nn(L.Bo);
131
+ if (null != this.nn(L.Wo)) {
132
+ const t = this.nn(L.Wo);
132
133
  -1 !== l.indexOf(t)
133
134
  ? (this.Vo = t)
134
135
  : r.error("Invalid sdk flavor passed: " + t);
135
136
  }
136
- let u = this.nn(Vt.Ao);
137
+ let u = this.nn(zt.So);
137
138
  if (null != u)
138
139
  if (j(u)) {
139
140
  const t = [];
@@ -150,31 +151,31 @@ class zt {
150
151
  "devicePropertyAllowlist must be an array. Defaulting to all properties.",
151
152
  ),
152
153
  (u = null);
153
- const f = this.nn(L.Uo);
154
- if (f) {
155
- const t = new _t(f);
154
+ const c = this.nn(L.Uo);
155
+ if (c) {
156
+ const t = new _t(c);
156
157
  this.u.uu(o.iu.Uo, t);
157
158
  }
158
159
  (this.on = new Ot(this.u, u)),
159
160
  (this.yt = new Dt(this.u)),
160
161
  (this.wt = new kt(this.yt, this.u)),
161
- (this.ri = new Mt(this.u, this.wt, this.yt, this.nn(L.Po)));
162
- const c = new T();
162
+ (this.ri = new Mt(this.u, this.wt, this.yt, this.nn(L.Ro)));
163
+ const f = new T();
163
164
  return (
164
- (this.zo = new qt(this.u, this.nn(L.No), c)),
165
- this.$t(c),
166
- (this.qt = new Rt(
165
+ (this.Ko = new qt(this.u, this.nn(L.No), f)),
166
+ this.$t(f),
167
+ (this.qt = new Pt(
167
168
  this.on,
168
169
  this.u,
169
- this.zo,
170
+ this.Ko,
170
171
  this.wt,
171
172
  this.ri,
172
173
  this.yt,
173
174
  this.rn,
174
175
  this.Go,
175
- this.Wo,
176
+ this.Bo,
176
177
  this.Vo || "",
177
- this.nn(L.Ro),
178
+ this.nn(L.Po),
178
179
  this.nn(L.Lo),
179
180
  )),
180
181
  (this.zi = new Lt(
@@ -188,11 +189,11 @@ class zt {
188
189
  (t) => {
189
190
  if (this.so()) for (const i of this.gr()) i.Ns(t);
190
191
  },
191
- this.zo,
192
+ this.Ko,
192
193
  this.qt,
193
194
  )),
194
195
  this.zi.initialize(),
195
- a || this.u.Vh(),
196
+ a || this.u.Kh(),
196
197
  r.info(
197
198
  `Initialized for the Braze backend at "${this.nn(
198
199
  L._o,
@@ -201,24 +202,25 @@ class zt {
201
202
  et.o(),
202
203
  this.yt.ji(() => {
203
204
  var t;
204
- this.Ko &&
205
+ this.isInitialized &&
205
206
  (null === (t = this.yt) || void 0 === t ? void 0 : t.ci()) &&
206
207
  import("../FeatureFlags/refresh-feature-flags.js").then((t) => {
207
- if (!this.Ko) return;
208
+ if (!this.isInitialized) return;
208
209
  (0, t.default)();
209
210
  });
210
211
  }),
211
212
  this.zi.mr(() => {
212
213
  var t;
213
- this.Ko &&
214
+ this.isInitialized &&
214
215
  (null === (t = this.yt) || void 0 === t ? void 0 : t.ci()) &&
215
216
  import("../FeatureFlags/refresh-feature-flags.js").then((t) => {
216
- if (!this.Ko) return;
217
+ if (!this.isInitialized) return;
217
218
  (0, t.default)(void 0, void 0, !0);
218
219
  });
219
220
  }),
220
221
  this.qo.Dt(this.options),
221
- (this.Ko = !0),
222
+ (this.isInitialized = !0),
223
+ window.dispatchEvent(new CustomEvent("braze.initialized")),
222
224
  !0
223
225
  );
224
226
  }
@@ -233,7 +235,7 @@ class zt {
233
235
  (this._e = []),
234
236
  null != this.zi && this.zi.destroy(),
235
237
  (this.zi = null),
236
- (this.zo = null),
238
+ (this.Ko = null),
237
239
  (this.on = null),
238
240
  (this.qt = null),
239
241
  (this.yt = null),
@@ -241,19 +243,19 @@ class zt {
241
243
  (this.wt = null),
242
244
  (this.options = {}),
243
245
  (this.Vo = void 0),
244
- (this.Ko = !1),
246
+ (this.isInitialized = !1),
245
247
  (this.$o = !1),
246
248
  t && (this.u = null);
247
249
  }
248
250
  }
249
251
  X() {
250
- return !this.Kh() && (!!this.so() || (console.warn(_), !1));
252
+ return !this.$h() && (!!this.so() || (console.warn(_), !1));
251
253
  }
252
254
  ba() {
253
255
  return this.rn;
254
256
  }
255
257
  Sr() {
256
- return this.zo;
258
+ return this.Ko;
257
259
  }
258
260
  Hs() {
259
261
  return this.Go;
@@ -314,14 +316,14 @@ class zt {
314
316
  this.$o = t;
315
317
  }
316
318
  so() {
317
- return this.Ko;
319
+ return this.isInitialized;
318
320
  }
319
- Kh() {
321
+ $h() {
320
322
  return this.$o;
321
323
  }
322
324
  Ds() {
323
- return this.Wo;
325
+ return this.Bo;
324
326
  }
325
327
  }
326
- const e = new zt();
327
- export { e as default, zt as BrazeSdkInstance, L as OPTIONS };
328
+ const e = new Vt();
329
+ export { e as default, Vt as BrazeSdkInstance, L as OPTIONS };
@@ -4,39 +4,39 @@ import DeviceProperties from "../Core/device-properties.js";
4
4
  import _t from "../models/identifier.js";
5
5
  import { logger as r, Guid as p } from "../../shared-lib/index.js";
6
6
  import { STORAGE_KEYS as o } from "../managers/storage-manager.js";
7
- import { values as Pt } from "../util/code-utils.js";
7
+ import { values as Rt } from "../util/code-utils.js";
8
8
  import { getErrorMessage as si } from "../util/error-utils.js";
9
9
  export default class Ot {
10
10
  constructor(t, e) {
11
11
  (this.u = t),
12
- (this.ka = e),
12
+ (this.Ia = e),
13
13
  (this.u = t),
14
- null == e && (e = Pt(DeviceProperties)),
15
- (this.ka = e);
14
+ null == e && (e = Rt(DeviceProperties)),
15
+ (this.Ia = e);
16
16
  }
17
17
  ce(t = !0) {
18
18
  let e = this.u.tu(o.iu.Uo);
19
19
  null == e && ((e = new _t(p.W())), t && this.u.uu(o.iu.Uo, e));
20
20
  const r = new Gt(e.eu);
21
- for (let t = 0; t < this.ka.length; t++) {
22
- switch (this.ka[t]) {
21
+ for (let t = 0; t < this.Ia.length; t++) {
22
+ switch (this.Ia[t]) {
23
23
  case DeviceProperties.BROWSER:
24
24
  r.browser = X.browser;
25
25
  break;
26
26
  case DeviceProperties.BROWSER_VERSION:
27
- r.Ia = X.version;
27
+ r.Ta = X.version;
28
28
  break;
29
29
  case DeviceProperties.OS:
30
- r.os = this.Ta();
30
+ r.os = this.Da();
31
31
  break;
32
32
  case DeviceProperties.RESOLUTION:
33
- r.Da = screen.width + "x" + screen.height;
33
+ r.Sa = screen.width + "x" + screen.height;
34
34
  break;
35
35
  case DeviceProperties.LANGUAGE:
36
36
  r.language = X.language;
37
37
  break;
38
38
  case DeviceProperties.TIME_ZONE:
39
- r.timeZone = this.Sa(new Date());
39
+ r.timeZone = this.Oa(new Date());
40
40
  break;
41
41
  case DeviceProperties.USER_AGENT:
42
42
  r.userAgent = X.userAgent;
@@ -44,12 +44,12 @@ export default class Ot {
44
44
  }
45
45
  return r;
46
46
  }
47
- Ta() {
48
- if (X.Oa()) return X.Oa();
49
- const t = this.u.j(o.C.Ca);
50
- return t && t.os_version ? t.os_version : X.Ta();
47
+ Da() {
48
+ if (X.Ca()) return X.Ca();
49
+ const t = this.u.j(o.C.Fa);
50
+ return t && t.os_version ? t.os_version : X.Da();
51
51
  }
52
- Sa(t) {
52
+ Oa(t) {
53
53
  let e = !1;
54
54
  if ("undefined" != typeof Intl && "function" == typeof Intl.DateTimeFormat)
55
55
  try {
@@ -66,9 +66,9 @@ export default class Ot {
66
66
  }
67
67
  if (e) return "";
68
68
  const s = t.getTimezoneOffset();
69
- return this.Fa(s);
69
+ return this.Ga(s);
70
70
  }
71
- Fa(t) {
71
+ Ga(t) {
72
72
  const e = Math.trunc(t / 60),
73
73
  r = Math.trunc(t % 60);
74
74
  let s = "GMT";