@braze/web-sdk 4.8.0 → 4.8.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 (72) hide show
  1. package/index.d.ts +6 -3
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +1 -1
  4. package/shared-lib/encoding-utils.js +1 -1
  5. package/shared-lib/event-types.js +11 -11
  6. package/shared-lib/indexed-db-adapter.js +67 -67
  7. package/shared-lib/logger.js +7 -7
  8. package/src/Card/card-manager.js +1 -1
  9. package/src/ContentCards/ui/show-content-cards.js +1 -1
  10. package/src/Core/disable-sdk.js +5 -4
  11. package/src/Core/enable-sdk.js +1 -1
  12. package/src/Core/is-disabled.js +1 -1
  13. package/src/FeatureFlags/feature-flags-provider.js +12 -12
  14. package/src/Feed/ui/show-feed.js +1 -1
  15. package/src/InAppMessage/in-app-message-manager.js +40 -34
  16. package/src/InAppMessage/log-in-app-message-button-click.js +2 -2
  17. package/src/InAppMessage/log-in-app-message-click.js +2 -2
  18. package/src/InAppMessage/log-in-app-message-html-click.js +1 -1
  19. package/src/InAppMessage/models/in-app-message-button.js +4 -4
  20. package/src/InAppMessage/models/in-app-message.js +13 -13
  21. package/src/InAppMessage/models/slide-up-message.js +2 -2
  22. package/src/InAppMessage/models/templated-in-app-message.js +8 -8
  23. package/src/InAppMessage/ui/show-in-app-message.js +2 -2
  24. package/src/Push/push-manager.js +82 -81
  25. package/src/Push/utils/push-utils.js +4 -4
  26. package/src/User/user-manager.js +4 -4
  27. package/src/User/user.js +5 -5
  28. package/src/common/feed-display.js +82 -72
  29. package/src/l10n/l10n-manager-factory.js +7 -7
  30. package/src/managers/auth-manager.js +18 -15
  31. package/src/managers/braze-instance.js +125 -109
  32. package/src/managers/device-manager.js +40 -35
  33. package/src/managers/network-manager.js +90 -81
  34. package/src/managers/server-config-manager.js +36 -34
  35. package/src/managers/session-manager.js +44 -37
  36. package/src/managers/storage-manager-factory.js +23 -16
  37. package/src/managers/storage-manager.js +251 -239
  38. package/src/managers/subscription-manager.js +10 -7
  39. package/src/managers/types.js +1 -0
  40. package/src/models/backend-errors.js +5 -5
  41. package/src/models/braze-event.js +10 -4
  42. package/src/models/device.js +10 -18
  43. package/src/models/identifier.js +10 -11
  44. package/src/models/push-token.js +14 -9
  45. package/src/models/request-result.js +2 -2
  46. package/src/models/server-config.js +32 -16
  47. package/src/models/types.js +1 -0
  48. package/src/request-controller.js +109 -109
  49. package/src/triggers/models/custom-event-data.js +6 -6
  50. package/src/triggers/models/custom-event-property-data.js +9 -9
  51. package/src/triggers/models/filter-set.js +9 -9
  52. package/src/triggers/models/filter.js +60 -60
  53. package/src/triggers/models/in-app-message-click-data.js +9 -9
  54. package/src/triggers/models/purchase-data.js +3 -3
  55. package/src/triggers/models/purchase-property-data.js +7 -7
  56. package/src/triggers/models/push-click-data.js +6 -6
  57. package/src/triggers/models/trigger-condition.js +46 -46
  58. package/src/triggers/models/trigger-events.js +1 -1
  59. package/src/triggers/models/trigger.js +27 -27
  60. package/src/triggers/triggers-provider.js +126 -126
  61. package/src/ui/js/attach-css.js +1 -1
  62. package/src/util/base-device-parser.js +2 -2
  63. package/src/util/braze-actions.js +4 -4
  64. package/src/util/browser-detector.js +18 -18
  65. package/src/util/client-hints-parser.js +6 -6
  66. package/src/util/device-constants.js +6 -6
  67. package/src/util/dom-utils.js +5 -5
  68. package/src/util/error-utils.js +2 -0
  69. package/src/util/net.js +1 -1
  70. package/src/util/request-header-utils.js +9 -9
  71. package/src/util/user-agent-parser.js +21 -21
  72. package/src/util/window-utils.js +1 -1
@@ -52,75 +52,89 @@ const L = {
52
52
  };
53
53
  class Wt {
54
54
  constructor() {
55
- (this.Ro = !1),
56
- (this.Mo = !1),
57
- (this.jo = new E()),
58
- (this.Do = new E()),
59
- (this.Uo = {}),
60
- (this.Bo = []),
61
- (this.Wo = []),
62
- (this.zo = []),
63
- (this.Vo = "4.8.0");
55
+ (this.Xr = ""),
56
+ (this.Ro = ""),
57
+ (this.Mo = void 0),
58
+ (this.jo = null),
59
+ (this.Zr = null),
60
+ (this.gt = null),
61
+ (this.Ci = null),
62
+ (this.wt = null),
63
+ (this._e = null),
64
+ (this.u = null),
65
+ (this.ft = null),
66
+ (this.Do = ""),
67
+ (this.Uo = !1),
68
+ (this.Bo = !1),
69
+ (this.Wo = new E()),
70
+ (this.zo = new E()),
71
+ (this.options = {}),
72
+ (this.Vo = []),
73
+ (this.Go = []),
74
+ (this.Se = []),
75
+ (this.Ro = "4.8.1");
64
76
  }
65
- Go(t) {
66
- this.jo.lt(t);
77
+ Ko(t) {
78
+ this.Wo.lt(t);
67
79
  }
68
80
  Nh(t) {
69
- this.Do.lt(t);
81
+ this.zo.lt(t);
70
82
  }
71
83
  initialize(t, s) {
72
84
  if (this.ue())
73
85
  return (
74
86
  r.j.info("Braze has already been initialized with an API key."), !0
75
87
  );
76
- this.Uo = s || {};
88
+ this.options = s || {};
77
89
  let e = this.nn(L.Ao);
78
- const n = ct(Z.An());
90
+ const n = ct(Z.jn());
79
91
  if (
80
92
  (n && "true" === n.brazeLogging && (e = !0),
81
93
  r.j.init(e),
82
- r.j.info(`Initialization Options: ${JSON.stringify(this.Uo, null, 2)}`),
94
+ r.j.info(
95
+ `Initialization Options: ${JSON.stringify(this.options, null, 2)}`
96
+ ),
83
97
  null == t || "" === t || "string" != typeof t)
84
98
  )
85
99
  return r.j.error("Braze requires a valid API key to be initialized."), !1;
86
- this.Ko = t;
100
+ this.Xr = t;
87
101
  let o = this.nn(L.Eo);
88
102
  if (null == o || "" === o || "string" != typeof o)
89
103
  return r.j.error("Braze requires a valid baseUrl to be initialized."), !1;
90
104
  !1 === /^https?:/.test(o) && (o = `https://${o}`);
91
- let h = o;
105
+ const h = o;
92
106
  if (
93
107
  ((o = document.createElement("a")),
94
108
  (o.href = h),
95
109
  "/" === o.pathname && (o = `${o}api/v3`),
96
- (this.Ho = o.toString()),
97
- V.$o && !this.nn(L.ho))
110
+ (this.Do = o.toString()),
111
+ V.Ho && !this.nn(L.ho))
98
112
  )
99
113
  return (
100
114
  r.j.info("Ignoring activity from crawler bot " + navigator.userAgent),
101
- (this.Mo = !0),
115
+ (this.Bo = !0),
102
116
  !1
103
117
  );
104
118
  const a = this.nn(L._o) || !1;
105
119
  if (
106
- ((this.Jn = Bt.qo(t, a)), a && this.Jn.xo(t), new O.ee(null, !0).wr(i.re))
120
+ ((this.u = Bt.$o(t, a)), a && this.u.qo(t), new O.ee(null, !0).wr(i.ne))
107
121
  )
108
122
  return (
109
123
  r.j.info("Ignoring all activity due to previous opt out"),
110
- (this.Mo = !0),
124
+ (this.Bo = !0),
111
125
  !1
112
126
  );
113
- for (const t of oo(this.Uo))
114
- -1 === Lt(r.Jo).indexOf(t) &&
127
+ for (const t of oo(this.options))
128
+ -1 === Lt(r.xo).indexOf(t) &&
115
129
  r.j.warn(`Ignoring unknown initialization option '${t}'.`);
116
130
  const l = ["mparticle", "wordpress", "tealium"];
117
131
  if (null != this.nn(L.Po)) {
118
132
  const t = this.nn(L.Po);
119
133
  -1 !== l.indexOf(t)
120
- ? (this.Yo = t)
134
+ ? (this.Mo = t)
121
135
  : r.j.error("Invalid sdk flavor passed: " + t);
122
136
  }
123
- let u = this.nn(r.Jo.Io);
137
+ let u = this.nn(r.xo.Io);
124
138
  if (null != u)
125
139
  if (p(u)) {
126
140
  const t = [];
@@ -137,46 +151,46 @@ class Wt {
137
151
  "devicePropertyAllowlist must be an array. Defaulting to all properties."
138
152
  ),
139
153
  (u = null);
140
- (this.Xo = new Ot(this.Jn, u)),
141
- (this.Zo = new Mt(this.Jn)),
142
- (this.Qo = new bt(this.Zo, this.Jn)),
143
- (this.fh = new Dt(this.Jn, this.Qo, this.Zo, this.nn(L.wo)));
154
+ (this.Zr = new Ot(this.u, u)),
155
+ (this.wt = new Mt(this.u)),
156
+ (this.ft = new bt(this.wt, this.u)),
157
+ (this._e = new Dt(this.u, this.ft, this.wt, this.nn(L.wo)));
144
158
  const f = new E();
145
159
  return (
146
- (this.gh = new jt(this.Jn, this.nn(L.So), f)),
160
+ (this.jo = new jt(this.u, this.nn(L.So), f)),
147
161
  this.jt(f),
148
- (this.wh = new Pt(
149
- this.Xo,
150
- this.Jn,
151
- this.gh,
152
- this.Qo,
153
- this.fh,
154
- this.Zo,
155
- this.Ko,
156
- this.Ho,
157
- this.Vo,
158
- this.Yo,
162
+ (this.gt = new Pt(
163
+ this.Zr,
164
+ this.u,
165
+ this.jo,
166
+ this.ft,
167
+ this._e,
168
+ this.wt,
169
+ this.Xr,
170
+ this.Do,
171
+ this.Ro,
172
+ this.Mo || "",
159
173
  this.nn(L.To)
160
174
  )),
161
- (this.Ch = new Rt(
162
- this.Ko,
163
- this.Ho,
164
- this.fh,
165
- this.Xo,
166
- this.Qo,
167
- this.Zo,
168
- this.Jn,
175
+ (this.Ci = new Rt(
176
+ this.Xr,
177
+ this.Do,
178
+ this._e,
179
+ this.Zr,
180
+ this.ft,
181
+ this.wt,
182
+ this.u,
169
183
  t => {
170
184
  if (this.ue()) for (const i of this.gr()) i.Ts(t);
171
185
  },
172
- this.gh,
173
- this.wh
186
+ this.jo,
187
+ this.gt
174
188
  )),
175
- this.Ch.initialize(),
189
+ this.Ci.initialize(),
176
190
  r.j.info(
177
191
  `Initialized for the Braze backend at "${this.nn(
178
192
  L.Eo
179
- )}" with API key "${this.Ko}".`
193
+ )}" with API key "${this.Xr}".`
180
194
  ),
181
195
  null != this.nn(L.Oo) &&
182
196
  z(
@@ -185,128 +199,130 @@ class Wt {
185
199
  "allowUserSuppliedJavascript"
186
200
  ),
187
201
  et.init(),
188
- this.Zo.Ni(() => {
189
- this.Ro &&
190
- this.Zo.bi() &&
202
+ this.wt.Ni(() => {
203
+ this.Uo &&
204
+ this.wt &&
205
+ this.wt.bi() &&
191
206
  import("../FeatureFlags/refresh-feature-flags.js").then(t => {
192
- if (!this.Ro) return;
207
+ if (!this.Uo) return;
193
208
  (0, t.default)();
194
209
  });
195
210
  }),
196
- this.Ch.pr(() => {
197
- this.Ro &&
198
- this.Zo.bi() &&
211
+ this.Ci.pr(() => {
212
+ this.Uo &&
213
+ this.wt &&
214
+ this.wt.bi() &&
199
215
  import("../FeatureFlags/refresh-feature-flags.js").then(t => {
200
- if (!this.Ro) return;
216
+ if (!this.Uo) return;
201
217
  (0, t.default)(null, null, !0);
202
218
  });
203
219
  }),
204
- this.jo.Et(this.Uo),
205
- (this.Ro = !0),
220
+ this.Wo.Et(this.options),
221
+ (this.Uo = !0),
206
222
  !0
207
223
  );
208
224
  }
209
225
  destroy(t) {
210
226
  if ((r.j.destroy(), this.ue())) {
211
- this.Do.Et(), this.Do.removeAllSubscriptions();
212
- for (const t of this.Bo) t.destroy();
213
- this.Bo = [];
214
- for (const t of this.Wo) t.clearData(!1);
215
- (this.Wo = []),
227
+ this.zo.Et(), this.zo.removeAllSubscriptions();
228
+ for (const t of this.Vo) t.destroy();
229
+ this.Vo = [];
230
+ for (const t of this.Go) t.clearData(!1);
231
+ (this.Go = []),
216
232
  this.removeAllSubscriptions(),
217
- (this.zo = []),
218
- this.Ch.destroy(),
219
- (this.Ch = null),
220
- (this.gh = null),
221
- (this.Xo = null),
222
- (this.wh = null),
223
- (this.Zo = null),
224
- (this.fh = null),
225
- (this.Qo = null),
226
- (this.Uo = {}),
227
- (this.Yo = void 0),
228
- (this.Ro = !1),
229
- (this.Mo = !1),
230
- t && (this.Jn = null);
233
+ (this.Se = []),
234
+ null != this.Ci && this.Ci.destroy(),
235
+ (this.Ci = null),
236
+ (this.jo = null),
237
+ (this.Zr = null),
238
+ (this.gt = null),
239
+ (this.wt = null),
240
+ (this._e = null),
241
+ (this.ft = null),
242
+ (this.options = {}),
243
+ (this.Mo = void 0),
244
+ (this.Uo = !1),
245
+ (this.Bo = !1),
246
+ t && (this.u = null);
231
247
  }
232
248
  }
233
249
  rr() {
234
- if (this.Ph()) return !1;
250
+ if (this.Jo()) return !1;
235
251
  if (!this.ue()) throw new Error(P);
236
252
  return !0;
237
253
  }
238
254
  ea() {
239
- return this.Ko;
255
+ return this.Xr;
240
256
  }
241
257
  Sr() {
242
- return this.gh;
258
+ return this.jo;
243
259
  }
244
260
  Zs() {
245
- return this.Ho;
261
+ return this.Do;
246
262
  }
247
263
  ie() {
248
- return this.Xo;
264
+ return this.Zr;
249
265
  }
250
266
  ar() {
251
- return this.wh;
267
+ return this.gt;
252
268
  }
253
269
  nn(t) {
254
- return this.Uo[t];
270
+ return this.options[t];
255
271
  }
256
272
  gr() {
257
- return this.Wo;
273
+ return this.Go;
258
274
  }
259
275
  cr() {
260
- return this.Ch;
276
+ return this.Ci;
261
277
  }
262
278
  tr() {
263
- return this.Zo;
279
+ return this.wt;
264
280
  }
265
281
  aa() {
266
- return this.fh;
282
+ return this._e;
267
283
  }
268
284
  l() {
269
- return this.Jn;
285
+ return this.u;
270
286
  }
271
287
  jr() {
272
- if (this.Qo && this.Ch) return new User(this.Qo, this.Ch);
288
+ if (this.ft && this.Ci) return new User(this.ft, this.Ci);
273
289
  }
274
290
  ir() {
275
- return this.Qo;
291
+ return this.ft;
276
292
  }
277
293
  nr() {
278
294
  return !0 === this.nn(L.Co) || !0 === this.nn(L.Oo);
279
295
  }
280
296
  g(t) {
281
297
  let i = !1;
282
- for (const s of this.Bo) s === t && (i = !0);
283
- i || this.Bo.push(t);
298
+ for (const s of this.Vo) s === t && (i = !0);
299
+ i || this.Vo.push(t);
284
300
  }
285
301
  dr(t) {
286
302
  let i = !1;
287
- for (const s of this.Wo) s.constructor === t.constructor && (i = !0);
288
- t instanceof y && !i && this.Wo.push(t);
303
+ for (const s of this.Go) s.constructor === t.constructor && (i = !0);
304
+ t instanceof y && !i && this.Go.push(t);
289
305
  }
290
306
  jt(t) {
291
- t instanceof E && this.zo.push(t);
307
+ t instanceof E && this.Se.push(t);
292
308
  }
293
309
  removeAllSubscriptions() {
294
- if (this.rr()) for (const t of this.zo) t.removeAllSubscriptions();
310
+ if (this.rr()) for (const t of this.Se) t.removeAllSubscriptions();
295
311
  }
296
312
  removeSubscription(t) {
297
- if (this.rr()) for (const i of this.zo) i.removeSubscription(t);
313
+ if (this.rr()) for (const i of this.Se) i.removeSubscription(t);
298
314
  }
299
315
  ae(t) {
300
- this.Mo = t;
316
+ this.Bo = t;
301
317
  }
302
318
  ue() {
303
- return this.Ro;
319
+ return this.Uo;
304
320
  }
305
- Ph() {
306
- return this.Mo;
321
+ Jo() {
322
+ return this.Bo;
307
323
  }
308
324
  Us() {
309
- return this.Vo;
325
+ return this.Ro;
310
326
  }
311
327
  }
312
328
  const e = new Wt();
@@ -1,77 +1,82 @@
1
1
  import V from "../util/browser-detector.js";
2
- import ge from "../models/device.js";
2
+ import xt from "../models/device.js";
3
3
  import DeviceProperties from "../Core/device-properties.js";
4
4
  import _t from "../models/identifier.js";
5
5
  import r from "../../shared-lib/braze-shared-lib.js";
6
6
  import { STORAGE_KEYS as i } from "../managers/storage-manager.js";
7
7
  import { values as Lt } from "../util/code-utils.js";
8
+ import { getErrorMessage as ei } from "../util/error-utils.js";
8
9
  export default class Ot {
9
- constructor(e, t) {
10
- (this.Jn = e), null == t && (t = Lt(DeviceProperties)), (this.sa = t);
10
+ constructor(t, e) {
11
+ (this.u = t),
12
+ (this.Qo = e),
13
+ (this.u = t),
14
+ null == e && (e = Lt(DeviceProperties)),
15
+ (this.Qo = e);
11
16
  }
12
17
  te() {
13
- let e = this.Jn.tu(i.eu.oa);
14
- null == e && ((e = new _t(r.Z.Y())), this.Jn.uu(i.eu.oa, e));
15
- const t = new ge(e.iu);
16
- for (let e = 0; e < this.sa.length; e++) {
17
- const r = this.sa[e];
18
- switch (r) {
18
+ let t = this.u.tu(i.eu.Xo);
19
+ null == t && ((t = new _t(r.Z.Y())), this.u.uu(i.eu.Xo, t));
20
+ const e = new xt(t.iu);
21
+ for (let t = 0; t < this.Qo.length; t++) {
22
+ switch (this.Qo[t]) {
19
23
  case DeviceProperties.BROWSER:
20
- t[r] = V.browser;
24
+ e.browser = V.browser;
21
25
  break;
22
26
  case DeviceProperties.BROWSER_VERSION:
23
- t[r] = V.version;
27
+ e.Yo = V.version;
24
28
  break;
25
29
  case DeviceProperties.OS:
26
- t[r] = this.ca();
30
+ e.os = this.Zo();
27
31
  break;
28
32
  case DeviceProperties.RESOLUTION:
29
- t[r] = screen.width + "x" + screen.height;
33
+ e.sa = screen.width + "x" + screen.height;
30
34
  break;
31
35
  case DeviceProperties.LANGUAGE:
32
- t[r] = V.language;
36
+ e.language = V.language;
33
37
  break;
34
38
  case DeviceProperties.TIME_ZONE:
35
- t[r] = this.fa(new Date());
39
+ e.timeZone = this.oa(new Date());
36
40
  break;
37
41
  case DeviceProperties.USER_AGENT:
38
- t[r] = V.userAgent;
42
+ e.userAgent = V.userAgent;
39
43
  }
40
44
  }
41
- return t;
45
+ return e;
42
46
  }
43
- ca() {
44
- if (V.la()) return V.la();
45
- const e = this.Jn.v(i.k.ma);
46
- return e && e.os_version ? e.os_version : V.ua();
47
+ Zo() {
48
+ if (V.ca()) return V.ca();
49
+ const t = this.u.v(i.k.la);
50
+ return t && t.os_version ? t.os_version : V.Zo();
47
51
  }
48
- fa(e) {
52
+ oa(t) {
53
+ let e = !1;
49
54
  if ("undefined" != typeof Intl && "function" == typeof Intl.DateTimeFormat)
50
55
  try {
51
56
  if ("function" == typeof Intl.DateTimeFormat().resolvedOptions) {
52
- const e = Intl.DateTimeFormat().resolvedOptions().timeZone;
53
- if (null != e && "" !== e) return e;
57
+ const t = Intl.DateTimeFormat().resolvedOptions().timeZone;
58
+ if (null != t && "" !== t) return t;
54
59
  }
55
60
  } catch (t) {
56
61
  r.j.info(
57
62
  "Intl.DateTimeFormat threw an error, cannot detect user's time zone:" +
58
- t.message
63
+ ei(t)
59
64
  ),
60
- (e = "");
65
+ (e = !0);
61
66
  }
62
- if (!e) return e;
63
- const t = e.getTimezoneOffset();
64
- return this.ha(t);
67
+ if (e) return "";
68
+ const s = t.getTimezoneOffset();
69
+ return this.fa(s);
65
70
  }
66
- ha(e) {
67
- const t = parseInt(e / 60),
68
- r = parseInt(e % 60);
71
+ fa(t) {
72
+ const e = Math.trunc(t / 60),
73
+ r = Math.trunc(t % 60);
69
74
  let s = "GMT";
70
75
  return (
71
- 0 !== e &&
72
- ((s += e < 0 ? "+" : "-"),
76
+ 0 !== t &&
77
+ ((s += t < 0 ? "+" : "-"),
73
78
  (s +=
74
- ("00" + Math.abs(t)).slice(-2) +
79
+ ("00" + Math.abs(e)).slice(-2) +
75
80
  ":" +
76
81
  ("00" + Math.abs(r)).slice(-2))),
77
82
  s