@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
@@ -5,38 +5,39 @@ import { STORAGE_KEYS as i } from "../managers/storage-manager.js";
5
5
  import { User } from "../User/index.js";
6
6
  import { WindowUtils as Z } from "../util/window-utils.js";
7
7
  import yt from "./utils/push-utils.js";
8
+ import { getErrorMessage as ei } from "../util/error-utils.js";
8
9
  export default class na {
9
10
  constructor(i, t, e, s, r, n, o, u, h, a) {
10
- (this.Wr = i),
11
- (this.Yr = t),
12
- (this.Xr = e),
13
- (this.Zr = r),
14
- (this.sn = n),
11
+ (this.Yr = i),
12
+ (this.Xr = t),
13
+ (this.Zr = e),
14
+ (this.sn = r),
15
+ (this.rn = n),
15
16
  (this.wt = o),
16
- (this.rn = u),
17
- (this.on = h),
17
+ (this.on = u),
18
+ (this.un = h),
18
19
  (this.u = a),
19
- (this.Wr = i),
20
- (this.Yr = t),
21
- (this.Xr = e),
22
- (this.un = s + "/safari/" + t),
23
- (this.Zr = r || "/service-worker.js"),
24
- (this.sn = n),
20
+ (this.Yr = i),
21
+ (this.Xr = t),
22
+ (this.Zr = e),
23
+ (this.hn = s + "/safari/" + t),
24
+ (this.sn = r || "/service-worker.js"),
25
+ (this.rn = n),
25
26
  (this.wt = o),
26
- (this.rn = u || !1),
27
- (this.on = h || !1),
27
+ (this.on = u || !1),
28
+ (this.un = h || !1),
28
29
  (this.u = a),
29
- (this.hn = yt.an()),
30
- (this.cn = yt.fn());
30
+ (this.an = yt.cn()),
31
+ (this.fn = yt.ln());
31
32
  }
32
- ln() {
33
- return this.on;
33
+ dn() {
34
+ return this.un;
34
35
  }
35
- dn(i, t, e, s, n) {
36
+ pn(i, t, e, s, n) {
36
37
  i.unsubscribe()
37
38
  .then(i => {
38
39
  i
39
- ? this.pn(t, e, s, n)
40
+ ? this.bn(t, e, s, n)
40
41
  : (r.j.error("Failed to unsubscribe device from push."),
41
42
  "function" == typeof n && n(!1));
42
43
  })
@@ -45,7 +46,7 @@ export default class na {
45
46
  "function" == typeof n && n(!1);
46
47
  });
47
48
  }
48
- bn(i, t, e) {
49
+ mn(i, t, e) {
49
50
  const s = (i => {
50
51
  if ("string" == typeof i) return i;
51
52
  if (0 !== i.endpoint.indexOf("https://android.googleapis.com/gcm/send"))
@@ -53,9 +54,9 @@ export default class na {
53
54
  let t = i.endpoint;
54
55
  const e = i;
55
56
  return (
56
- e.mn &&
57
- -1 === i.endpoint.indexOf(e.mn) &&
58
- (t = i.endpoint + "/" + e.mn),
57
+ e.yn &&
58
+ -1 === i.endpoint.indexOf(e.yn) &&
59
+ (t = i.endpoint + "/" + e.yn),
59
60
  t
60
61
  );
61
62
  })(i);
@@ -68,7 +69,7 @@ export default class na {
68
69
  (r = btoa(String.fromCharCode.apply(null, t))),
69
70
  (n = btoa(String.fromCharCode.apply(null, e)));
70
71
  } catch (i) {
71
- if (i instanceof Error && "invalid arguments" !== i.message) throw i;
72
+ if ("invalid arguments" !== ei(i)) throw i;
72
73
  }
73
74
  const o = (i => {
74
75
  let t;
@@ -81,49 +82,49 @@ export default class na {
81
82
  .replace(/\//g, "_")
82
83
  : null;
83
84
  })(i);
84
- this.Wr && this.Wr.yn(s, t, r, n, o),
85
+ this.Yr && this.Yr.gn(s, t, r, n, o),
85
86
  s && "function" == typeof e && e(s, r, n);
86
87
  }
87
- gn() {
88
- this.Wr && this.Wr.wn(!0);
88
+ wn() {
89
+ this.Yr && this.Yr.vn(!0);
89
90
  }
90
- vn(i, t) {
91
- this.Wr && this.Wr.wn(!1), r.j.info(i), "function" == typeof t && t(!1);
91
+ kn(i, t) {
92
+ this.Yr && this.Yr.vn(!1), r.j.info(i), "function" == typeof t && t(!1);
92
93
  }
93
- kn(i, t, e, s) {
94
+ Pn(i, t, e, s) {
94
95
  var n;
95
96
  if ("default" === t.permission)
96
97
  try {
97
98
  window.safari.pushNotification.requestPermission(
98
- this.un,
99
+ this.hn,
99
100
  i,
100
101
  {
101
- api_key: this.Yr,
102
+ api_key: this.Xr,
102
103
  device_id:
103
- (null === (n = this.Xr) || void 0 === n ? void 0 : n.te().id) ||
104
+ (null === (n = this.Zr) || void 0 === n ? void 0 : n.te().id) ||
104
105
  ""
105
106
  },
106
107
  t => {
107
108
  "granted" === t.permission &&
108
- this.Wr &&
109
- this.Wr.setPushNotificationSubscriptionType(
109
+ this.Yr &&
110
+ this.Yr.setPushNotificationSubscriptionType(
110
111
  User.NotificationSubscriptionTypes.OPTED_IN
111
112
  ),
112
- this.kn(i, t, e, s);
113
+ this.Pn(i, t, e, s);
113
114
  }
114
115
  );
115
116
  } catch (i) {
116
- this.vn("Could not request permission for push: " + i, s);
117
+ this.kn("Could not request permission for push: " + i, s);
117
118
  }
118
119
  else
119
120
  "denied" === t.permission
120
- ? this.vn(
121
+ ? this.kn(
121
122
  "The user has blocked notifications from this site, or Safari push is not configured in the Braze dashboard.",
122
123
  s
123
124
  )
124
125
  : "granted" === t.permission &&
125
126
  (r.j.info("Device successfully subscribed to push."),
126
- this.bn(t.deviceToken, new Date(), e));
127
+ this.mn(t.deviceToken, new Date(), e));
127
128
  }
128
129
  requestPermission(i, t, e) {
129
130
  const s = s => {
@@ -148,14 +149,14 @@ export default class na {
148
149
  })
149
150
  : (n = !0);
150
151
  }
151
- pn(i, t, e, s) {
152
+ bn(i, t, e, s) {
152
153
  const n = { userVisibleOnly: !0 };
153
154
  null != t && (n.applicationServerKey = t),
154
155
  i.pushManager
155
156
  .subscribe(n)
156
157
  .then(i => {
157
158
  r.j.info("Device successfully subscribed to push."),
158
- this.bn(i, new Date(), e);
159
+ this.mn(i, new Date(), e);
159
160
  })
160
161
  .catch(i => {
161
162
  yt.isPushBlocked()
@@ -165,10 +166,10 @@ export default class na {
165
166
  "function" == typeof s && s(!0));
166
167
  });
167
168
  }
168
- Pn() {
169
- return this.rn
169
+ Dn() {
170
+ return this.on
170
171
  ? navigator.serviceWorker.getRegistration()
171
- : navigator.serviceWorker.register(this.Zr).then(() =>
172
+ : navigator.serviceWorker.register(this.sn).then(() =>
172
173
  navigator.serviceWorker.ready.then(
173
174
  i => (
174
175
  i &&
@@ -181,22 +182,22 @@ export default class na {
181
182
  )
182
183
  );
183
184
  }
184
- Dn(i) {
185
- this.rn ||
185
+ Sn(i) {
186
+ this.on ||
186
187
  (i.unregister(), r.j.info("Service worker successfully unregistered."));
187
188
  }
188
189
  subscribe(t, e) {
189
190
  if (!yt.isPushSupported())
190
- return r.j.info(na.Sn), void ("function" == typeof e && e(!1));
191
- if (this.hn) {
192
- if (!this.rn && null != window.location) {
193
- let i = this.Zr;
191
+ return r.j.info(na.An), void ("function" == typeof e && e(!1));
192
+ if (this.an) {
193
+ if (!this.on && null != window.location) {
194
+ let i = this.sn;
194
195
  -1 === i.indexOf(window.location.host) &&
195
196
  (i = window.location.host + i),
196
197
  -1 === i.indexOf(window.location.protocol) &&
197
198
  (i = window.location.protocol + "//" + i);
198
199
  const t = i.substr(0, i.lastIndexOf("/") + 1);
199
- if (0 !== Z.An().indexOf(t))
200
+ if (0 !== Z.jn().indexOf(t))
200
201
  return (
201
202
  r.j.error(
202
203
  "Cannot subscribe to push from a path higher than the service worker location (tried to subscribe from " +
@@ -209,16 +210,16 @@ export default class na {
209
210
  );
210
211
  }
211
212
  if (yt.isPushBlocked())
212
- return void this.vn(
213
+ return void this.kn(
213
214
  "Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",
214
215
  e
215
216
  );
216
- if (this.wt && !this.wt.jn() && 0 === this.wt.oi())
217
+ if (this.wt && !this.wt.Un() && 0 === this.wt.oi())
217
218
  return (
218
219
  r.j.info(
219
220
  "Waiting for VAPID key from server config before subscribing to push."
220
221
  ),
221
- void this.wt.Un(() => {
222
+ void this.wt.Wn(() => {
222
223
  this.subscribe(t, e);
223
224
  })
224
225
  );
@@ -237,11 +238,11 @@ export default class na {
237
238
  o = yt.isPushPermissionGranted(),
238
239
  u = () => {
239
240
  !o &&
240
- this.Wr &&
241
- this.Wr.setPushNotificationSubscriptionType(
241
+ this.Yr &&
242
+ this.Yr.setPushNotificationSubscriptionType(
242
243
  User.NotificationSubscriptionTypes.OPTED_IN
243
244
  ),
244
- this.Pn()
245
+ this.Dn()
245
246
  .then(s => {
246
247
  if (null == s)
247
248
  return (
@@ -256,17 +257,17 @@ export default class na {
256
257
  let o = null;
257
258
  if (
258
259
  (this.wt &&
259
- null != this.wt.jn() &&
260
- (o = r._n.Wn(this.wt.jn())),
260
+ null != this.wt.Un() &&
261
+ (o = r.xn._n(this.wt.Un())),
261
262
  n)
262
263
  ) {
263
264
  let u,
264
265
  h = null,
265
266
  a = null;
266
- if ((this.u && (u = this.u.v(i.k.xn)), u && !p(u))) {
267
+ if ((this.u && (u = this.u.v(i.k.Nn)), u && !p(u))) {
267
268
  let i;
268
269
  try {
269
- i = ti.Tn(u).Nn;
270
+ i = ti.zn(u).Tn;
270
271
  } catch (t) {
271
272
  i = null;
272
273
  }
@@ -290,31 +291,31 @@ export default class na {
290
291
  : r.j.info(
291
292
  "Attempting to upgrade a gcm_sender_id-based push registration to VAPID - depending on the browser this may or may not result in the same gcm_sender_id-based subscription."
292
293
  ),
293
- this.dn(n, s, o, t, e))
294
+ this.pn(n, s, o, t, e))
294
295
  : n.expirationTime &&
295
296
  new Date(n.expirationTime).valueOf() <=
296
297
  new Date().valueOf()
297
298
  ? (r.j.info(
298
299
  "Push subscription is expired, creating new subscription."
299
300
  ),
300
- this.dn(n, s, o, t, e))
301
+ this.pn(n, s, o, t, e))
301
302
  : u && p(u)
302
- ? this.dn(n, s, o, t, e)
303
+ ? this.pn(n, s, o, t, e)
303
304
  : null == a
304
305
  ? (r.j.info(
305
306
  "No push subscription creation date found, creating new subscription."
306
307
  ),
307
- this.dn(n, s, o, t, e))
308
+ this.pn(n, s, o, t, e))
308
309
  : a.valueOf() <= new Date().valueOf()
309
310
  ? (r.j.info(
310
311
  "Push subscription older than 6 months, creating new subscription."
311
312
  ),
312
- this.dn(n, s, o, t, e))
313
+ this.pn(n, s, o, t, e))
313
314
  : (r.j.info(
314
315
  "Device already subscribed to push, sending existing subscription to backend."
315
316
  ),
316
- this.bn(n, h, t));
317
- } else this.pn(s, o, t, e);
317
+ this.mn(n, h, t));
318
+ } else this.bn(s, o, t, e);
318
319
  })
319
320
  .catch(i => {
320
321
  r.j.error(
@@ -327,29 +328,29 @@ export default class na {
327
328
  });
328
329
  };
329
330
  this.requestPermission(u, n, s);
330
- } else if (this.cn) {
331
- if (null == this.sn || "" === this.sn)
331
+ } else if (this.fn) {
332
+ if (null == this.rn || "" === this.rn)
332
333
  return (
333
334
  r.j.error(
334
335
  "You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari"
335
336
  ),
336
337
  void ("function" == typeof e && e(!0))
337
338
  );
338
- const i = window.safari.pushNotification.permission(this.sn);
339
- this.kn(this.sn, i, t, e);
339
+ const i = window.safari.pushNotification.permission(this.rn);
340
+ this.Pn(this.rn, i, t, e);
340
341
  }
341
342
  }
342
343
  unsubscribe(i, t) {
343
344
  if (!yt.isPushSupported())
344
- return r.j.info(na.Sn), void ("function" == typeof t && t());
345
- this.hn
345
+ return r.j.info(na.An), void ("function" == typeof t && t());
346
+ this.an
346
347
  ? navigator.serviceWorker.getRegistration().then(e => {
347
348
  e
348
349
  ? e.pushManager
349
350
  .getSubscription()
350
351
  .then(s => {
351
352
  s &&
352
- (this.gn(),
353
+ (this.wn(),
353
354
  s
354
355
  .unsubscribe()
355
356
  .then(s => {
@@ -362,7 +363,7 @@ export default class na {
362
363
  "Failed to unsubscribe device from push."
363
364
  ),
364
365
  "function" == typeof t && t()),
365
- this.Dn(e);
366
+ this.Sn(e);
366
367
  })
367
368
  .catch(i => {
368
369
  r.j.error("Push unsubscription error: " + i),
@@ -376,10 +377,10 @@ export default class na {
376
377
  : (r.j.info("Device already unsubscribed from push."),
377
378
  "function" == typeof i && i());
378
379
  })
379
- : this.cn &&
380
- (this.gn(),
380
+ : this.fn &&
381
+ (this.wn(),
381
382
  r.j.info("Device unsubscribed from push."),
382
383
  "function" == typeof i && i());
383
384
  }
384
385
  }
385
- na.Sn = "Push notifications are not supported in this browser.";
386
+ na.An = "Push notifications are not supported in this browser.";
@@ -1,15 +1,15 @@
1
1
  const yt = {
2
- an: () =>
2
+ cn: () =>
3
3
  "serviceWorker" in navigator &&
4
4
  "undefined" != typeof ServiceWorkerRegistration &&
5
5
  "showNotification" in ServiceWorkerRegistration.prototype &&
6
6
  "PushManager" in window,
7
- fn: () =>
7
+ ln: () =>
8
8
  "safari" in window &&
9
9
  "pushNotification" in window.safari &&
10
10
  "function" == typeof window.safari.pushNotification.permission &&
11
11
  "function" == typeof window.safari.pushNotification.requestPermission,
12
- isPushSupported: () => yt.an() || yt.fn(),
12
+ isPushSupported: () => yt.cn() || yt.ln(),
13
13
  isPushBlocked: () => {
14
14
  const i =
15
15
  yt.isPushSupported() &&
@@ -28,7 +28,7 @@ const yt = {
28
28
  null != window.Notification &&
29
29
  null != window.Notification.permission &&
30
30
  "granted" === window.Notification.permission,
31
- Ki: () =>
31
+ Li: () =>
32
32
  !yt.isPushBlocked() && yt.isPushSupported() && !yt.isPushPermissionGranted()
33
33
  };
34
34
  export default yt;
@@ -47,7 +47,7 @@ export default class bt {
47
47
  u
48
48
  );
49
49
  }
50
- yn(t, s, e, u, o) {
50
+ gn(t, s, e, u, o) {
51
51
  this.nu("push_token", t, !1, !0),
52
52
  this.nu("custom_push_public_key", e, !1, !0),
53
53
  this.nu("custom_push_user_auth", u, !1, !0),
@@ -55,9 +55,9 @@ export default class bt {
55
55
  const h = r.zt.Ft,
56
56
  n = new r.xt(h, r.j),
57
57
  l = new ti(t, s, e, u, o);
58
- this.u.D(i.k.xn, l.ss()), n.setItem(h.Jt.cu, h.se, !0);
58
+ this.u.D(i.k.Nn, l.ss()), n.setItem(h.Jt.cu, h.se, !0);
59
59
  }
60
- wn(t) {
60
+ vn(t) {
61
61
  if (
62
62
  (this.nu("push_token", null, !1, !0),
63
63
  this.nu("custom_push_public_key", null, !1, !0),
@@ -67,7 +67,7 @@ export default class bt {
67
67
  ) {
68
68
  const t = r.zt.Ft,
69
69
  s = new r.xt(t, r.j);
70
- this.u.D(i.k.xn, !1), s.setItem(t.Jt.cu, t.se, !1);
70
+ this.u.D(i.k.Nn, !1), s.setItem(t.Jt.cu, t.se, !1);
71
71
  }
72
72
  }
73
73
  }
package/src/User/user.js CHANGED
@@ -274,11 +274,11 @@ export default class User {
274
274
  !1)
275
275
  : this.Ci.Gn(t, User.qn.UNSUBSCRIBED).O;
276
276
  }
277
- yn(t, e, r, s, i) {
278
- this.ft.yn(t, e, r, s, i), this.Ci.zn();
277
+ gn(t, e, r, s, i) {
278
+ this.ft.gn(t, e, r, s, i), this.Ci.Hn();
279
279
  }
280
- wn(t) {
281
- this.ft.wn(t);
280
+ vn(t) {
281
+ this.ft.vn(t);
282
282
  }
283
283
  }
284
284
  (User.Genders = {
@@ -296,6 +296,6 @@ export default class User {
296
296
  }),
297
297
  (User.In = /^[0-9 .\\(\\)\\+\\-]+$/),
298
298
  (User.qn = { SUBSCRIBED: "subscribed", UNSUBSCRIBED: "unsubscribed" }),
299
- (User.Hn = "user_id"),
299
+ (User.Kn = "user_id"),
300
300
  (User.lu = "custom"),
301
301
  (User.lr = 997);