@braze/web-sdk 6.10.2 → 6.11.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 (71) hide show
  1. package/index.d.ts +28 -4
  2. package/package.json +1 -1
  3. package/shared-lib/encoding-utils.js +3 -3
  4. package/shared-lib/event-types.js +10 -10
  5. package/shared-lib/indexed-db-adapter.js +51 -51
  6. package/shared-lib/logger.js +7 -7
  7. package/shared-lib/supported-options.js +9 -9
  8. package/src/Core/logout.js +2 -2
  9. package/src/InAppMessage/constants.js +39 -47
  10. package/src/InAppMessage/display/html-message-to-html.js +1 -1
  11. package/src/InAppMessage/display/in-app-message-to-html.js +38 -36
  12. package/src/InAppMessage/in-app-message-factory.js +4 -4
  13. package/src/InAppMessage/in-app-message-manager.js +89 -68
  14. package/src/InAppMessage/log-in-app-message-button-click.js +1 -1
  15. package/src/InAppMessage/log-in-app-message-click.js +1 -1
  16. package/src/InAppMessage/log-in-app-message-html-click.js +2 -2
  17. package/src/InAppMessage/log-in-app-message-impression.js +1 -1
  18. package/src/InAppMessage/models/full-screen-message.js +22 -22
  19. package/src/InAppMessage/models/html-message.js +13 -13
  20. package/src/InAppMessage/models/in-app-message-button.js +2 -2
  21. package/src/InAppMessage/models/in-app-message.js +68 -66
  22. package/src/InAppMessage/models/modal-message.js +20 -20
  23. package/src/InAppMessage/models/slide-up-message.js +25 -25
  24. package/src/InAppMessage/models/templated-in-app-message.js +6 -6
  25. package/src/InAppMessage/subscribe-to-in-app-message.js +1 -1
  26. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +3 -3
  27. package/src/InAppMessage/ui/show-in-app-message.js +27 -25
  28. package/src/Push/index.js +1 -0
  29. package/src/Push/push-manager-factory.js +4 -4
  30. package/src/Push/push-manager.js +222 -179
  31. package/src/Push/register-push.js +9 -0
  32. package/src/Push/unregister-push-token-on-server.js +4 -4
  33. package/src/Push/utils/push-utils.js +8 -8
  34. package/src/User/user-manager.js +19 -19
  35. package/src/User/user.js +35 -35
  36. package/src/common/constants.js +1 -1
  37. package/src/common/content-cards-display.js +5 -5
  38. package/src/l10n/l10n-manager-factory.js +1 -1
  39. package/src/l10n/l10n-manager.js +1 -1
  40. package/src/managers/braze-instance.js +42 -38
  41. package/src/managers/device-manager.js +20 -20
  42. package/src/managers/network-manager.js +122 -122
  43. package/src/managers/server-config-manager.js +76 -76
  44. package/src/managers/session-manager.js +8 -8
  45. package/src/managers/storage-manager.js +127 -127
  46. package/src/managers/utils.js +1 -1
  47. package/src/models/backend-errors.js +5 -5
  48. package/src/models/braze-event.js +2 -2
  49. package/src/models/device.js +3 -3
  50. package/src/models/identifier.js +6 -6
  51. package/src/models/push-token.js +6 -6
  52. package/src/models/server-config.js +24 -24
  53. package/src/request-controller.js +85 -85
  54. package/src/triggers/models/trigger-condition.js +27 -27
  55. package/src/triggers/models/trigger.js +2 -2
  56. package/src/triggers/triggers-provider-factory.js +1 -1
  57. package/src/triggers/triggers-provider.js +37 -29
  58. package/src/types.js +2 -2
  59. package/src/ui/js/attach-css.js +1 -1
  60. package/src/util/base-device-parser.js +1 -1
  61. package/src/util/braze-actions.js +4 -4
  62. package/src/util/browser-detector.js +5 -5
  63. package/src/util/client-hints-parser.js +1 -1
  64. package/src/util/dom-utils.js +2 -2
  65. package/src/util/ecommerce-event-validation.js +1 -1
  66. package/src/util/key-codes.js +1 -1
  67. package/src/util/net.js +3 -3
  68. package/src/util/request-header-utils.js +15 -15
  69. package/src/util/user-agent-parser.js +4 -4
  70. package/src/util/validation-utils.js +5 -5
  71. package/src/util/window-utils.js +2 -2
@@ -1,43 +1,43 @@
1
- import { isArray as g, isEqual as oi } from "../util/code-utils.js";
2
- import ui from "../models/push-token.js";
3
- import { logger as b, EncodingUtils as ai } from "../../shared-lib/index.js";
1
+ import { EncodingUtils as oi, logger as b } from "../../shared-lib/index.js";
4
2
  import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
3
+ import ui from "../models/push-token.js";
5
4
  import { User } from "../User/index.js";
5
+ import { isArray as g, isEqual as hi } from "../util/code-utils.js";
6
+ import { getErrorMessage as ai } from "../util/error-utils.js";
6
7
  import It from "./utils/push-utils.js";
7
- import { getErrorMessage as hi } from "../util/error-utils.js";
8
8
  export default class na {
9
- constructor(i, t, e, s, r, n, o, u, a, h, c) {
9
+ constructor(i, e, t, s, r, o, n, u, h, a, c) {
10
10
  (this.iu = i),
11
- (this.tu = t),
12
11
  (this.eu = e),
12
+ (this.tu = t),
13
13
  (this.su = r),
14
- (this.ru = n),
15
- (this.nu = o),
14
+ (this.ru = o),
15
+ (this.ou = n),
16
16
  (this.h = u),
17
- (this.ou = a),
18
- (this.uu = h),
17
+ (this.nu = h),
18
+ (this.uu = a),
19
19
  (this.j = c),
20
20
  (this.iu = i),
21
- (this.tu = t),
22
21
  (this.eu = e),
23
- (this.au = s + "/safari/" + t),
22
+ (this.tu = t),
23
+ (this.hu = s + "/safari/" + e),
24
24
  (this.su = r || "/service-worker.js"),
25
- (this.nu = o),
25
+ (this.ou = n),
26
26
  (this.h = u),
27
- (this.ou = a || !1),
28
- (this.uu = h || !1),
27
+ (this.nu = h || !1),
28
+ (this.uu = a || !1),
29
29
  (this.j = c),
30
- (this.hu = It.cu()),
31
- (this.fu = It.lu());
30
+ (this.au = It.cu()),
31
+ (this.fu = It.du());
32
32
  }
33
- du() {
33
+ lu() {
34
34
  return this.uu;
35
35
  }
36
- pu(i, t, e, s, r) {
36
+ pu(i, e, t, s, r) {
37
37
  i.unsubscribe()
38
38
  .then((i) => {
39
39
  i
40
- ? this.bu(t, e, s, r)
40
+ ? this.bu(e, t, s, r)
41
41
  : (b.error("Failed to unsubscribe device from push."),
42
42
  "function" == typeof r && r(!1));
43
43
  })
@@ -46,101 +46,101 @@ export default class na {
46
46
  "function" == typeof r && r(!1);
47
47
  });
48
48
  }
49
- yu(i, t, e) {
49
+ mu(i, e, t) {
50
50
  var s;
51
51
  const r = ((i) => {
52
52
  if ("string" == typeof i) return i;
53
53
  if (0 !== i.endpoint.indexOf("https://android.googleapis.com/gcm/send"))
54
54
  return i.endpoint;
55
- let t = i.endpoint;
56
- const e = i;
55
+ let e = i.endpoint;
56
+ const t = i;
57
57
  return (
58
- e.mu &&
59
- -1 === i.endpoint.indexOf(e.mu) &&
60
- (t = i.endpoint + "/" + e.mu),
61
- t
58
+ t.gu &&
59
+ -1 === i.endpoint.indexOf(t.gu) &&
60
+ (e = i.endpoint + "/" + t.gu),
61
+ e
62
62
  );
63
63
  })(i);
64
- let n = null,
65
- o = null;
64
+ let o = null,
65
+ n = null;
66
66
  const u = i;
67
67
  if (null != u.getKey)
68
68
  try {
69
69
  const i = Array.from(new Uint8Array(u.getKey("p256dh"))),
70
- t = Array.from(new Uint8Array(u.getKey("auth")));
71
- (n = btoa(String.fromCharCode.apply(null, i))),
72
- (o = btoa(String.fromCharCode.apply(null, t)));
70
+ e = Array.from(new Uint8Array(u.getKey("auth")));
71
+ (o = btoa(String.fromCharCode.apply(null, i))),
72
+ (n = btoa(String.fromCharCode.apply(null, e)));
73
73
  } catch (i) {
74
- b.error(hi(i));
74
+ b.error(ai(i));
75
75
  }
76
- const a = ((i) => {
77
- let t;
76
+ const h = ((i) => {
77
+ let e;
78
78
  return i.options &&
79
- (t = i.options.applicationServerKey) &&
80
- t.byteLength &&
81
- t.byteLength > 0
82
- ? btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(t))))
79
+ (e = i.options.applicationServerKey) &&
80
+ e.byteLength &&
81
+ e.byteLength > 0
82
+ ? btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(e))))
83
83
  .replace(/\+/g, "-")
84
84
  .replace(/\//g, "_")
85
85
  : null;
86
86
  })(u);
87
- null === (s = this.iu) || void 0 === s || s.gu(r, t, n, o, a),
88
- r && "function" == typeof e && e(r, n, o);
87
+ null === (s = this.iu) || void 0 === s || s.yu(r, e, o, n, h),
88
+ r && "function" == typeof t && t(r, o, n);
89
89
  }
90
90
  vu() {
91
91
  var i;
92
92
  null === (i = this.iu) || void 0 === i || i.wu(!0);
93
93
  }
94
- ku(i, t) {
95
- var e;
96
- null === (e = this.iu) || void 0 === e || e.wu(!1),
94
+ Pu(i, e) {
95
+ var t;
96
+ null === (t = this.iu) || void 0 === t || t.wu(!1),
97
97
  b.info(i),
98
- "function" == typeof t && t(!1);
98
+ "function" == typeof e && e(!1);
99
99
  }
100
- Pu(i, t, e, s) {
100
+ ku(i, e, t, s) {
101
101
  var r;
102
- if ("default" === t.permission)
102
+ if ("default" === e.permission)
103
103
  try {
104
104
  window.safari.pushNotification.requestPermission(
105
- this.au,
105
+ this.hu,
106
106
  i,
107
107
  {
108
- api_key: this.tu,
108
+ api_key: this.eu,
109
109
  device_id:
110
- (null === (r = this.eu) || void 0 === r ? void 0 : r.ve().id) ||
110
+ (null === (r = this.tu) || void 0 === r ? void 0 : r.ve().id) ||
111
111
  "",
112
112
  },
113
- (t) => {
114
- "granted" === t.permission &&
113
+ (e) => {
114
+ "granted" === e.permission &&
115
115
  this.iu &&
116
116
  this.iu.setPushNotificationSubscriptionType(
117
117
  User.NotificationSubscriptionTypes.OPTED_IN,
118
118
  ),
119
- this.Pu(i, t, e, s);
119
+ this.ku(i, e, t, s);
120
120
  },
121
121
  );
122
122
  } catch (i) {
123
- this.ku("Could not request permission for push: " + i, s);
123
+ this.Pu("Could not request permission for push: " + i, s);
124
124
  }
125
125
  else
126
- "denied" === t.permission
127
- ? this.ku(
126
+ "denied" === e.permission
127
+ ? this.Pu(
128
128
  "The user has blocked notifications from this site, or Safari push is not configured in the Braze dashboard.",
129
129
  s,
130
130
  )
131
- : "granted" === t.permission &&
131
+ : "granted" === e.permission &&
132
132
  (b.info("Device successfully subscribed to push."),
133
- this.yu(t.deviceToken, new Date(), e));
133
+ this.mu(e.deviceToken, new Date(), t));
134
134
  }
135
- requestPermission(i, t, e) {
135
+ requestPermission(i, e, t) {
136
136
  const s = (s) => {
137
137
  switch (s) {
138
138
  case "granted":
139
139
  return void ("function" == typeof i && i());
140
140
  case "default":
141
- return void ("function" == typeof t && t());
142
- case "denied":
143
141
  return void ("function" == typeof e && e());
142
+ case "denied":
143
+ return void ("function" == typeof t && t());
144
144
  default:
145
145
  b.error("Received unexpected permission result " + s);
146
146
  }
@@ -159,14 +159,14 @@ export default class na {
159
159
  : (r = !0);
160
160
  }
161
161
  }
162
- bu(i, t, e, s) {
162
+ bu(i, e, t, s) {
163
163
  const r = { userVisibleOnly: !0 };
164
- null != t && (r.applicationServerKey = t),
164
+ null != e && (r.applicationServerKey = e),
165
165
  i.pushManager
166
166
  .subscribe(r)
167
167
  .then((i) => {
168
168
  b.info("Device successfully subscribed to push."),
169
- this.yu(i, new Date(), e);
169
+ this.mu(i, new Date(), t);
170
170
  })
171
171
  .catch((i) => {
172
172
  It.isPushBlocked()
@@ -177,7 +177,7 @@ export default class na {
177
177
  });
178
178
  }
179
179
  Du() {
180
- if (this.ou) return navigator.serviceWorker.getRegistration(this.su);
180
+ if (this.nu) return navigator.serviceWorker.getRegistration(this.su);
181
181
  const i = this.ru ? { scope: this.ru } : void 0;
182
182
  return navigator.serviceWorker.register(this.su, i).then(() =>
183
183
  navigator.serviceWorker.ready.then(
@@ -193,14 +193,14 @@ export default class na {
193
193
  );
194
194
  }
195
195
  Su(i) {
196
- this.ou ||
196
+ this.nu ||
197
197
  (i.unregister(), b.info("Service worker successfully unregistered."));
198
198
  }
199
- subscribe(i, t) {
199
+ subscribe(i, e) {
200
200
  if (!It.isPushSupported())
201
- return b.info(na.Au), void ("function" == typeof t && t(!1));
202
- if (this.hu) {
203
- if (!this.ou && null != window.location) {
201
+ return b.info(na.Au), void ("function" == typeof e && e(!1));
202
+ if (this.au) {
203
+ if (!this.nu && null != window.location) {
204
204
  let i = this.su;
205
205
  -1 === i.indexOf(window.location.host) &&
206
206
  (i = window.location.host + i),
@@ -208,143 +208,186 @@ export default class na {
208
208
  (i = window.location.protocol + "//" + i);
209
209
  }
210
210
  if (It.isPushBlocked())
211
- return void this.ku(
211
+ return void this.Pu(
212
212
  "Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",
213
- t,
213
+ e,
214
214
  );
215
- if (this.h && !this.h.ju() && 0 === this.h.Qt())
215
+ if (this.h && !this.h.Wu() && 0 === this.h.Qt())
216
216
  return (
217
217
  b.info(
218
218
  "Waiting for VAPID key from server config before subscribing to push.",
219
219
  ),
220
- void this.h.xu(() => {
221
- this.subscribe(i, t);
220
+ void this.h.ju(() => {
221
+ this.subscribe(i, e);
222
222
  })
223
223
  );
224
- const e = () => {
224
+ const t = () => {
225
225
  b.info("Permission for push notifications was denied."),
226
- "function" == typeof t && t(!1);
226
+ "function" == typeof e && e(!1);
227
227
  },
228
- r = () => {
228
+ s = () => {
229
229
  let i = "Permission for push notifications was ignored.";
230
230
  It.isPushBlocked() &&
231
231
  (i +=
232
232
  " The browser has automatically blocked further permission requests for a period (probably 1 week)."),
233
233
  b.info(i),
234
- "function" == typeof t && t(!0);
234
+ "function" == typeof e && e(!0);
235
235
  },
236
- n = It.isPushPermissionGranted(),
236
+ r = It.isPushPermissionGranted(),
237
237
  o = () => {
238
- !n &&
238
+ !r &&
239
239
  this.iu &&
240
240
  this.iu.setPushNotificationSubscriptionType(
241
241
  User.NotificationSubscriptionTypes.OPTED_IN,
242
242
  ),
243
- this.Du()
244
- .then((e) => {
245
- if (null == e)
246
- return (
247
- b.error(
248
- "No service worker registration. Set the `manageServiceWorkerExternally` initialization option to false or ensure that your service worker is registered before calling registerPush.",
249
- ),
250
- void ("function" == typeof t && t(!0))
251
- );
252
- e.pushManager
253
- .getSubscription()
254
- .then((r) => {
255
- var n;
256
- let o = null;
257
- if (
258
- (null !=
259
- (null === (n = this.h) || void 0 === n
260
- ? void 0
261
- : n.ju()) && (o = ai.Nu(this.h.ju())),
262
- r)
263
- ) {
264
- let n,
265
- u = null,
266
- a = null;
267
- if ((this.j && (n = this.j.St(s.It.Uu)), n && !g(n))) {
268
- let i;
269
- try {
270
- i = ui._u(n).Wu;
271
- } catch (t) {
272
- i = null;
273
- }
274
- null == i ||
275
- isNaN(i.getTime()) ||
276
- 0 === i.getTime() ||
277
- ((u = i),
278
- (a = new Date(u)),
279
- a.setMonth(u.getMonth() + 6));
280
- }
281
- null != o &&
282
- r.options &&
283
- r.options.applicationServerKey &&
284
- r.options.applicationServerKey.byteLength &&
285
- r.options.applicationServerKey.byteLength > 0 &&
286
- !oi(o, new Uint8Array(r.options.applicationServerKey))
287
- ? (r.options.applicationServerKey.byteLength > 12
288
- ? b.info(
289
- "Device was already subscribed to push using a different VAPID provider, creating new subscription.",
290
- )
291
- : b.info(
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.",
293
- ),
294
- this.pu(r, e, o, i, t))
295
- : r.expirationTime &&
296
- new Date(r.expirationTime).valueOf() <=
297
- new Date().valueOf()
298
- ? (b.info(
299
- "Push subscription is expired, creating new subscription.",
300
- ),
301
- this.pu(r, e, o, i, t))
302
- : n && g(n)
303
- ? this.pu(r, e, o, i, t)
304
- : null == a
305
- ? (b.info(
306
- "No push subscription creation date found, creating new subscription.",
307
- ),
308
- this.pu(r, e, o, i, t))
309
- : a.valueOf() <= new Date().valueOf()
310
- ? (b.info(
311
- "Push subscription older than 6 months, creating new subscription.",
312
- ),
313
- this.pu(r, e, o, i, t))
314
- : (b.info(
315
- "Device already subscribed to push, sending existing subscription to backend.",
316
- ),
317
- this.yu(r, u, i));
318
- } else this.bu(e, o, i, t);
319
- })
320
- .catch((i) => {
321
- b.error("Error checking current push subscriptions: " + i);
322
- });
323
- })
324
- .catch((i) => {
325
- b.error("ServiceWorker registration failed: " + i);
326
- });
243
+ this.Nu(i, e);
327
244
  };
328
- this.requestPermission(o, r, e);
245
+ this.requestPermission(o, s, t);
329
246
  } else if (this.fu) {
330
- if (null == this.nu || "" === this.nu)
247
+ if (null == this.ou || "" === this.ou)
331
248
  return (
332
249
  b.error(
333
250
  "You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari",
334
251
  ),
335
- void ("function" == typeof t && t(!0))
252
+ void ("function" == typeof e && e(!0))
336
253
  );
337
- const e = window.safari.pushNotification.permission(this.nu);
338
- this.Pu(this.nu, e, i, t);
254
+ const t = window.safari.pushNotification.permission(this.ou);
255
+ this.ku(this.ou, t, i, e);
339
256
  }
340
257
  }
341
- unsubscribe(i, t) {
258
+ registerPush(i, e) {
259
+ if (!It.isPushSupported())
260
+ return b.info(na.Au), void ("function" == typeof e && e(!1));
261
+ if (this.au) {
262
+ if (It.isPushBlocked())
263
+ return void this.Pu(
264
+ "Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",
265
+ e,
266
+ );
267
+ if (this.h && !this.h.Wu() && 0 === this.h.Qt())
268
+ return (
269
+ b.info(
270
+ "Waiting for VAPID key from server config before registering push.",
271
+ ),
272
+ void this.h.ju(() => {
273
+ this.registerPush(i, e);
274
+ })
275
+ );
276
+ if (!It.isPushPermissionGranted())
277
+ return void b.info(
278
+ "Push permission has not been granted, so registerPush is a no-op. Call requestPushPermission to prompt the user for permission.",
279
+ );
280
+ this.Nu(i, e);
281
+ } else if (this.fu) {
282
+ if (null == this.ou || "" === this.ou)
283
+ return (
284
+ b.error(
285
+ "You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari",
286
+ ),
287
+ void ("function" == typeof e && e(!0))
288
+ );
289
+ const t = window.safari.pushNotification.permission(this.ou);
290
+ "granted" === t.permission
291
+ ? this.ku(this.ou, t, i, e)
292
+ : "denied" === t.permission
293
+ ? this.Pu(
294
+ "The user has blocked notifications from this site, or Safari push is not configured in the Braze dashboard.",
295
+ e,
296
+ )
297
+ : b.info(
298
+ "Push permission has not been granted, so registerPush is a no-op. Call requestPushPermission to prompt the user for permission.",
299
+ );
300
+ }
301
+ }
302
+ Nu(i, e) {
303
+ this.Du()
304
+ .then((t) => {
305
+ if (null == t)
306
+ return (
307
+ b.error(
308
+ "No service worker registration. Set the `manageServiceWorkerExternally` initialization option to false or ensure that your service worker is registered before calling registerPush.",
309
+ ),
310
+ void ("function" == typeof e && e(!0))
311
+ );
312
+ t.pushManager
313
+ .getSubscription()
314
+ .then((r) => {
315
+ var o;
316
+ let n = null;
317
+ if (
318
+ (null !=
319
+ (null === (o = this.h) || void 0 === o ? void 0 : o.Wu()) &&
320
+ (n = oi.Tu(this.h.Wu())),
321
+ r)
322
+ ) {
323
+ let o,
324
+ u = null,
325
+ h = null;
326
+ if ((this.j && (o = this.j.St(s.It.xu)), o && !g(o))) {
327
+ let i;
328
+ try {
329
+ i = ui._u(o).Uu;
330
+ } catch (e) {
331
+ i = null;
332
+ }
333
+ null == i ||
334
+ isNaN(i.getTime()) ||
335
+ 0 === i.getTime() ||
336
+ ((u = i), (h = new Date(u)), h.setMonth(u.getMonth() + 6));
337
+ }
338
+ null != n &&
339
+ r.options &&
340
+ r.options.applicationServerKey &&
341
+ r.options.applicationServerKey.byteLength &&
342
+ r.options.applicationServerKey.byteLength > 0 &&
343
+ !hi(n, new Uint8Array(r.options.applicationServerKey))
344
+ ? (r.options.applicationServerKey.byteLength > 12
345
+ ? b.info(
346
+ "Device was already subscribed to push using a different VAPID provider, creating new subscription.",
347
+ )
348
+ : b.info(
349
+ "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.",
350
+ ),
351
+ this.pu(r, t, n, i, e))
352
+ : r.expirationTime &&
353
+ new Date(r.expirationTime).valueOf() <= new Date().valueOf()
354
+ ? (b.info(
355
+ "Push subscription is expired, creating new subscription.",
356
+ ),
357
+ this.pu(r, t, n, i, e))
358
+ : o && g(o)
359
+ ? this.pu(r, t, n, i, e)
360
+ : null == h
361
+ ? (b.info(
362
+ "No push subscription creation date found, creating new subscription.",
363
+ ),
364
+ this.pu(r, t, n, i, e))
365
+ : h.valueOf() <= new Date().valueOf()
366
+ ? (b.info(
367
+ "Push subscription older than 6 months, creating new subscription.",
368
+ ),
369
+ this.pu(r, t, n, i, e))
370
+ : (b.info(
371
+ "Device already subscribed to push, sending existing subscription to backend.",
372
+ ),
373
+ this.mu(r, u, i));
374
+ } else this.bu(t, n, i, e);
375
+ })
376
+ .catch((i) => {
377
+ b.error("Error checking current push subscriptions: " + i);
378
+ });
379
+ })
380
+ .catch((i) => {
381
+ b.error("ServiceWorker registration failed: " + i);
382
+ });
383
+ }
384
+ unsubscribe(i, e) {
342
385
  if (!It.isPushSupported())
343
386
  return b.info(na.Au), void ("function" == typeof i && i());
344
- this.hu
345
- ? navigator.serviceWorker.getRegistration(this.su).then((e) => {
346
- e
347
- ? e.pushManager
387
+ this.au
388
+ ? navigator.serviceWorker.getRegistration(this.su).then((t) => {
389
+ t
390
+ ? t.pushManager
348
391
  .getSubscription()
349
392
  .then((s) => {
350
393
  s
@@ -360,19 +403,19 @@ export default class na {
360
403
  : (b.error(
361
404
  "Failed to unsubscribe device from push.",
362
405
  ),
363
- "function" == typeof t && t()),
364
- this.Su(e);
406
+ "function" == typeof e && e()),
407
+ this.Su(t);
365
408
  })
366
409
  .catch((i) => {
367
410
  b.error("Push unsubscription error: " + i),
368
- "function" == typeof t && t();
411
+ "function" == typeof e && e();
369
412
  }))
370
413
  : (b.info("Device already unsubscribed from push."),
371
414
  "function" == typeof i && i());
372
415
  })
373
416
  .catch((i) => {
374
417
  b.error("Error unsubscribing from push: " + i),
375
- "function" == typeof t && t();
418
+ "function" == typeof e && e();
376
419
  })
377
420
  : (b.info("Device already unsubscribed from push."),
378
421
  "function" == typeof i && i());
@@ -0,0 +1,9 @@
1
+ import r from "../managers/braze-instance.js";
2
+ import ra from "./push-manager-factory.js";
3
+ export function registerPush(t, n) {
4
+ if (r.rr())
5
+ return ra.ra().registerPush((n, o, e) => {
6
+ const s = r.nn();
7
+ s && s.requestImmediateDataFlush(), "function" == typeof t && t(n, o, e);
8
+ }, n);
9
+ }
@@ -8,18 +8,18 @@ export function unregisterPushTokenOnServer() {
8
8
  const e = r.m();
9
9
  if (!e) return;
10
10
  const t = r.p(),
11
- n = null == t ? void 0 : t.St(s.It.Uu);
11
+ n = null == t ? void 0 : t.St(s.It.xu);
12
12
  if (!n || "object" != typeof n || Array.isArray(n)) return;
13
13
  const o = ui._u(n);
14
14
  if (!o.endpoint) return;
15
15
  const i = e.Z({}, !0);
16
16
  i.push_token = o.endpoint;
17
- const a = e.tt(i, h.it.qa);
17
+ const a = e.tt(i, h.it.Ra);
18
18
  e.et(
19
19
  i,
20
20
  (n = -1) => {
21
21
  r.rr() &&
22
- (h.nt(t, h.it.qa, new Date().valueOf()),
22
+ (h.nt(t, h.it.Ra, new Date().valueOf()),
23
23
  -1 !== n && a.push(["X-Braze-Req-Tokens-Remaining", n.toString()]),
24
24
  l.ot({
25
25
  url: `${e.ht()}/push/unregister`,
@@ -30,6 +30,6 @@ export function unregisterPushTokenOnServer() {
30
30
  },
31
31
  }));
32
32
  },
33
- h.it.qa,
33
+ h.it.Ra,
34
34
  );
35
35
  }
@@ -4,12 +4,12 @@ const It = {
4
4
  "undefined" != typeof ServiceWorkerRegistration &&
5
5
  "showNotification" in ServiceWorkerRegistration.prototype &&
6
6
  "PushManager" in window,
7
- lu: () =>
7
+ du: () =>
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: () => It.cu() || It.lu(),
12
+ isPushSupported: () => It.cu() || It.du(),
13
13
  isPushBlocked: () => {
14
14
  const o =
15
15
  It.isPushSupported() &&
@@ -28,15 +28,15 @@ const It = {
28
28
  null != window.Notification &&
29
29
  null != window.Notification.permission &&
30
30
  "granted" === window.Notification.permission,
31
- Vn: () =>
31
+ Yn: () =>
32
32
  It.isPushBlocked()
33
- ? { Wn: !1, reason: "blocked" }
33
+ ? { Zn: !1, reason: "blocked" }
34
34
  : It.isPushSupported()
35
35
  ? It.isPushPermissionGranted()
36
- ? { Wn: !1, reason: "permissionGranted" }
37
- : { Wn: !0 }
38
- : { Wn: !1, reason: "unsupported" },
39
- Yn: (o, i) =>
36
+ ? { Zn: !1, reason: "permissionGranted" }
37
+ : { Zn: !0 }
38
+ : { Zn: !1, reason: "unsupported" },
39
+ _o: (o, i) =>
40
40
  "blocked" === o
41
41
  ? `${i} containing a push prompt is not being shown because the user has already declined push permission prompt.`
42
42
  : "unsupported" === o