@braze/service-worker 4.8.3 → 4.10.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 (2) hide show
  1. package/package.json +1 -1
  2. package/service-worker.js +399 -376
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braze/service-worker",
3
- "version": "4.8.3",
3
+ "version": "4.10.0",
4
4
  "description": "Braze service worker to be used with the Braze Web SDK.",
5
5
  "main": "service-worker.js",
6
6
  "scripts": {
package/service-worker.js CHANGED
@@ -1,110 +1,104 @@
1
1
  /*
2
- * Braze Web SDK v4.8.3
2
+ * Braze Web SDK v4.10.0
3
3
  * (c) Braze, Inc. 2023 - http://braze.com
4
4
  * License available at https://github.com/braze-inc/braze-web-sdk/blob/master/LICENSE
5
- * Compiled on 2023-07-11
5
+ * Compiled on 2023-10-03
6
6
  */
7
- const k = {
8
- P: function(a) {
9
- var b = "=".repeat((4 - (a.length % 4)) % 4);
10
- a = (a + b).replace(/\-/g, "+").replace(/_/g, "/");
11
- a = atob(a);
12
- b = new Uint8Array(a.length);
13
- for (let c = 0; c < a.length; ++c) b[c] = a.charCodeAt(c);
14
- return b;
15
- }
16
- };
17
- const l = {
18
- H: () => {
19
- const a = b => {
20
- const c = (Math.random().toString(16) + "000000000").substr(2, 8);
21
- return b ? "-" + c.substr(0, 4) + "-" + c.substr(4, 4) : c;
22
- };
23
- return a() + a(!0) + a(!0) + a();
24
- }
25
- };
26
- function q(a) {
27
- if ("indexedDB" in a.G) return a.G.indexedDB;
7
+ function k(a) {
8
+ if ("indexedDB" in a.parent) return a.parent.indexedDB;
28
9
  }
29
- function r(a) {
10
+ function l(a) {
11
+ var b;
30
12
  try {
31
- if (null == q(a)) return !1;
32
- const b = q(a).open("Braze IndexedDB Support Test");
33
- b.onupgradeneeded = () => b.result.close();
34
- b.onsuccess = () => b.result.close();
13
+ if (null == k(a)) return !1;
14
+ const c =
15
+ null === (b = k(a)) || void 0 === b
16
+ ? void 0
17
+ : b.open("Braze IndexedDB Support Test");
18
+ c &&
19
+ ((c.onupgradeneeded = () => c.result.close()),
20
+ (c.onsuccess = () => c.result.close()));
35
21
  if ("undefined" !== typeof window) {
36
- const c = window.ra || window.qa || window.ta;
37
- if (c && c.O && c.O.id)
22
+ b = window;
23
+ const f = b.ra || b.qa || b.ta;
24
+ if (f && f.N && f.N.id)
38
25
  return (
39
26
  a.j.info(
40
- "Not using IndexedDB for storage because we are running inside an extension"
27
+ "Not using IndexedDB for storage because we are running inside an extension",
41
28
  ),
42
29
  !1
43
30
  );
44
31
  }
45
32
  return !0;
46
- } catch (b) {
33
+ } catch (c) {
47
34
  return (
48
- a.j.info("Not using IndexedDB for storage due to following error: " + b),
35
+ a.j.info("Not using IndexedDB for storage due to following error: " + c),
49
36
  !1
50
37
  );
51
38
  }
52
39
  }
53
- function t(a, b, c) {
54
- const f = q(a).open(a.h.l, a.h.VERSION);
55
- if (null == f) return "function" === typeof c && c(), !1;
56
- f.onupgradeneeded = e => {
40
+ function q(a, b, c) {
41
+ var f;
42
+ const g =
43
+ null === (f = k(a)) || void 0 === f ? void 0 : f.open(a.h.l, a.h.VERSION);
44
+ if (null == g) return "function" === typeof c && c(), !1;
45
+ g.onupgradeneeded = (e) => {
46
+ var d;
57
47
  a.j.info("Upgrading indexedDB " + a.h.l + " to v" + a.h.VERSION + "...");
58
- e = e.target.result;
59
- for (const d in a.h.g)
60
- a.h.g.hasOwnProperty(d) &&
61
- !e.objectStoreNames.contains(a.h.g[d]) &&
62
- e.createObjectStore(a.h.g[d]);
48
+ e = null === (d = e.target) || void 0 === d ? void 0 : d.result;
49
+ for (const h in a.h.g)
50
+ (d = h),
51
+ a.h.g.hasOwnProperty(h) &&
52
+ !e.objectStoreNames.contains(a.h.g[d]) &&
53
+ e.createObjectStore(a.h.g[d]);
63
54
  };
64
- f.onsuccess = e => {
65
- const d = e.target.result;
66
- d.onversionchange = () => {
67
- d.close();
55
+ g.onsuccess = (e) => {
56
+ var d;
57
+ const h = null === (d = e.target) || void 0 === d ? void 0 : d.result;
58
+ h.onversionchange = () => {
59
+ h.close();
68
60
  "function" === typeof c && c();
69
61
  a.j.error(
70
- "Needed to close the database unexpectedly because of an upgrade in another tab"
62
+ "Needed to close the database unexpectedly because of an upgrade in another tab",
71
63
  );
72
64
  };
73
- b(d);
65
+ b(h);
74
66
  };
75
- f.onerror = e => {
67
+ g.onerror = (e) => {
68
+ var d;
76
69
  a.j.info(
77
70
  "Could not open indexedDB " +
78
71
  a.h.l +
79
72
  " v" +
80
73
  a.h.VERSION +
81
74
  ": " +
82
- e.target.errorCode
75
+ (null === (d = e.target) || void 0 === d ? void 0 : d.errorCode),
83
76
  );
84
77
  "function" === typeof c && c();
85
78
  return !0;
86
79
  };
87
80
  return !0;
88
81
  }
89
- function w(a, b, c, f) {
90
- r(a)
91
- ? t(
82
+ function r(a, b, c, f) {
83
+ l(a)
84
+ ? q(
92
85
  a,
93
- e => {
94
- if (e.objectStoreNames.contains(b)) {
95
- var d = e.transaction([b], "readonly");
96
- d.oncomplete = () => e.close();
97
- d = d.objectStore(b).openCursor(null, "prev");
98
- d.onerror = () => {
86
+ (g) => {
87
+ if (g.objectStoreNames.contains(b)) {
88
+ var e = g.transaction([b], "readonly");
89
+ e.oncomplete = () => g.close();
90
+ e = e.objectStore(b).openCursor(null, "prev");
91
+ e.onerror = () => {
99
92
  a.j.error(
100
- "Could not open cursor for " + b + " on indexedDB " + a.h.l
93
+ "Could not open cursor for " + b + " on indexedDB " + a.h.l,
101
94
  );
102
95
  "function" === typeof f && f();
103
96
  };
104
- d.onsuccess = g => {
105
- g = g.target.result;
106
- null != g && null != g.value && null != g.key
107
- ? c(g.key, g.value)
97
+ e.onsuccess = (d) => {
98
+ var h;
99
+ d = null === (h = d.target) || void 0 === h ? void 0 : h.result;
100
+ null != d && null != d.value && null != d.key
101
+ ? c(d.key, d.value)
108
102
  : "function" === typeof f && f();
109
103
  };
110
104
  } else
@@ -115,84 +109,87 @@ function w(a, b, c, f) {
115
109
  a.h.l +
116
110
  " - " +
117
111
  b +
118
- " is not a valid objectStore"
112
+ " is not a valid objectStore",
119
113
  ),
120
114
  "function" === typeof f && f(),
121
- e.close();
115
+ g.close();
122
116
  },
123
- f
117
+ f,
124
118
  )
125
119
  : "function" === typeof f && f();
126
120
  }
127
- class x {
121
+ class t {
128
122
  constructor(a, b) {
129
- this.G = "undefined" === typeof window ? self : window;
123
+ this.h = a;
124
+ this.j = b;
125
+ this.parent = "undefined" === typeof window ? self : window;
130
126
  this.h = a;
131
127
  this.j = b;
132
128
  }
133
- setItem(a, b, c, f, e) {
134
- if (!r(this)) return "function" === typeof e && e(), !1;
135
- const d = this;
136
- return t(
129
+ setItem(a, b, c, f, g) {
130
+ if (!l(this)) return "function" === typeof g && g(), !1;
131
+ const e = this;
132
+ return q(
137
133
  this,
138
- g => {
139
- if (g.objectStoreNames.contains(a)) {
140
- var h = g.transaction([a], "readwrite");
141
- h.oncomplete = () => g.close();
134
+ (d) => {
135
+ if (d.objectStoreNames.contains(a)) {
136
+ var h = d.transaction([a], "readwrite");
137
+ h.oncomplete = () => d.close();
142
138
  h = h.objectStore(a).put(c, b);
143
139
  h.onerror = () => {
144
- d.j.error(
140
+ e.j.error(
145
141
  "Could not store object " +
146
142
  b +
147
143
  " in " +
148
144
  a +
149
145
  " on indexedDB " +
150
- d.h.l
146
+ e.h.l,
151
147
  );
152
- "function" === typeof e && e();
148
+ "function" === typeof g && g();
153
149
  };
154
150
  h.onsuccess = () => {
155
151
  "function" === typeof f && f();
156
152
  };
157
153
  } else
158
- d.j.error(
154
+ e.j.error(
159
155
  "Could not store object " +
160
156
  b +
161
157
  " in " +
162
158
  a +
163
159
  " on indexedDB " +
164
- d.h.l +
160
+ e.h.l +
165
161
  " - " +
166
162
  a +
167
- " is not a valid objectStore"
163
+ " is not a valid objectStore",
168
164
  ),
169
- "function" === typeof e && e(),
170
- g.close();
165
+ "function" === typeof g && g(),
166
+ d.close();
171
167
  },
172
- e
168
+ g,
173
169
  );
174
170
  }
175
171
  getItem(a, b, c) {
176
- if (!r(this)) return !1;
172
+ if (!l(this)) return !1;
177
173
  const f = this;
178
- return t(this, e => {
179
- if (e.objectStoreNames.contains(a)) {
180
- var d = e.transaction([a], "readonly");
181
- d.oncomplete = () => e.close();
182
- d = d.objectStore(a).get(b);
183
- d.onerror = () => {
174
+ return q(this, (g) => {
175
+ if (g.objectStoreNames.contains(a)) {
176
+ var e = g.transaction([a], "readonly");
177
+ e.oncomplete = () => g.close();
178
+ e = e.objectStore(a).get(b);
179
+ e.onerror = () => {
184
180
  f.j.error(
185
181
  "Could not retrieve object " +
186
182
  b +
187
183
  " in " +
188
184
  a +
189
185
  " on indexedDB " +
190
- f.h.l
186
+ f.h.l,
191
187
  );
192
188
  };
193
- d.onsuccess = g => {
194
- g = g.target.result;
195
- null != g && c(g);
189
+ e.onsuccess = (d) => {
190
+ var h;
191
+ d = null === (h = d.target) || void 0 === h ? void 0 : h.result;
192
+ null != d && c(d);
196
193
  };
197
194
  } else
198
195
  f.j.error(
@@ -204,213 +201,236 @@ class x {
204
201
  f.h.l +
205
202
  " - " +
206
203
  a +
207
- " is not a valid objectStore"
204
+ " is not a valid objectStore",
208
205
  ),
209
- e.close();
206
+ g.close();
210
207
  });
211
208
  }
212
209
  clearData() {
213
- if (!r(this)) return !1;
210
+ if (!l(this)) return !1;
214
211
  const a = [];
215
- for (const c in this.h.g)
212
+ for (const c in this.h.g) {
213
+ const f = c;
216
214
  this.h.g.hasOwnProperty(c) &&
217
- this.h.g[c] !== this.h.g.C &&
218
- a.push(this.h.g[c]);
215
+ this.h.g[f] !== this.h.g.C &&
216
+ a.push(this.h.g[f]);
217
+ }
219
218
  const b = this;
220
- return t(this, function(c) {
219
+ return q(this, function (c) {
221
220
  const f = c.transaction(a, "readwrite");
222
221
  f.oncomplete = () => c.close();
223
- for (let e = 0; e < a.length; e++)
224
- f.objectStore(a[e]).clear().onerror = function() {
222
+ for (let g = 0; g < a.length; g++)
223
+ f.objectStore(a[g]).clear().onerror = function () {
225
224
  b.j.error(
226
- "Could not clear " + this.source.name + " on indexedDB " + b.h.l
225
+ "Could not clear " + this.source.name + " on indexedDB " + b.h.l,
227
226
  );
228
227
  };
229
- f.onerror = function() {
228
+ f.onerror = function () {
230
229
  b.j.error("Could not clear object stores on indexedDB " + b.h.l);
231
230
  };
232
231
  });
233
232
  }
234
233
  }
235
- const y = {
236
- B: function(a) {
237
- if (void 0 !== a || void 0 === y.o) y.o = !!a;
238
- y.F || (y.F = !0);
234
+ const w = {
235
+ B: function (a) {
236
+ if (void 0 !== a || void 0 === w.o) w.o = !!a;
237
+ w.G || (w.G = !0);
239
238
  },
240
- sa: function() {
241
- y.F = !1;
242
- y.o = void 0;
243
- y.j = void 0;
239
+ sa: function () {
240
+ w.G = !1;
241
+ w.o = void 0;
242
+ w.j = void 0;
244
243
  },
245
- ua: function(a) {
244
+ ua: function (a) {
246
245
  "function" !== typeof a
247
- ? y.info("Ignoring setLogger call since logger is not a function")
248
- : (y.B(), (y.j = a));
246
+ ? w.info("Ignoring setLogger call since logger is not a function")
247
+ : (w.B(), (w.j = a));
249
248
  },
250
- va: function() {
251
- y.B();
252
- y.o
253
- ? (console.log("Disabling Braze logging"), (y.o = !1))
254
- : (console.log("Enabled Braze logging"), (y.o = !0));
249
+ va: function () {
250
+ w.B();
251
+ w.o
252
+ ? (console.log("Disabling Braze logging"), (w.o = !1))
253
+ : (console.log("Enabled Braze logging"), (w.o = !0));
255
254
  },
256
- info: function(a) {
257
- y.o && ((a = "Braze: " + a), null != y.j ? y.j(a) : console.log(a));
255
+ info: function (a) {
256
+ w.o && ((a = "Braze: " + a), null != w.j ? w.j(a) : console.log(a));
258
257
  },
259
- warn: function(a) {
260
- y.o &&
261
- ((a = "Braze SDK Warning: " + a + " (v4.8.3)"),
262
- null != y.j ? y.j(a) : console.warn(a));
258
+ warn: function (a) {
259
+ w.o &&
260
+ ((a = "Braze SDK Warning: " + a + " (v4.10.0)"),
261
+ null != w.j ? w.j(a) : console.warn(a));
262
+ },
263
+ error: function (a) {
264
+ w.o &&
265
+ ((a = "Braze SDK Error: " + a + " (v4.10.0)"),
266
+ null != w.j ? w.j(a) : console.error(a));
263
267
  },
264
- error: function(a) {
265
- y.o &&
266
- ((a = "Braze SDK Error: " + a + " (v4.8.3)"),
267
- null != y.j ? y.j(a) : console.error(a));
268
- }
269
268
  };
270
- var z = {
269
+ var x = {
270
+ O: function (a) {
271
+ var b = "=".repeat((4 - (a.length % 4)) % 4);
272
+ a = (a + b).replace(/\-/g, "+").replace(/_/g, "/");
273
+ a = atob(a);
274
+ b = new Uint8Array(a.length);
275
+ for (let c = 0; c < a.length; ++c) b[c] = a.charCodeAt(c);
276
+ return b;
277
+ },
278
+ },
279
+ y = {
271
280
  CustomEvent: "ce",
272
281
  ga: "p",
273
- M: "pc",
274
- L: "ca",
282
+ L: "pc",
283
+ K: "ca",
275
284
  ia: "i",
276
285
  ha: "ie",
277
- W: "cci",
278
- X: "ccic",
279
- U: "ccc",
280
- V: "ccd",
286
+ V: "cci",
287
+ W: "ccic",
288
+ T: "ccc",
289
+ U: "ccd",
281
290
  oa: "ss",
282
291
  na: "se",
283
292
  fa: "si",
284
293
  da: "sc",
285
294
  ca: "sbc",
286
295
  ea: "sfe",
287
- Y: "iec",
296
+ X: "iec",
288
297
  la: "lr",
289
- R: "uae",
290
- T: "ci",
291
- S: "cc",
298
+ P: "uae",
299
+ S: "ci",
300
+ R: "cc",
292
301
  ja: "lcaa",
293
302
  ka: "lcar",
294
- $: "inc",
295
- Z: "add",
296
- aa: "rem",
297
- ba: "set",
303
+ Z: "inc",
304
+ Y: "add",
305
+ $: "rem",
306
+ aa: "set",
298
307
  ma: "ncam",
299
- pa: "sgu"
308
+ pa: "sgu",
309
+ ba: "ffi",
300
310
  },
301
- A = x,
311
+ z = {
312
+ F: function () {
313
+ const a = (b = !1) => {
314
+ const c = (Math.random().toString(16) + "000000000").substr(2, 8);
315
+ return b ? "-" + c.substr(0, 4) + "-" + c.substr(4, 4) : c;
316
+ };
317
+ return a() + a(!0) + a(!0) + a();
318
+ },
319
+ },
320
+ A = t,
302
321
  B = {
303
322
  m: {
304
323
  l: "AppboyServiceWorkerAsyncStorage",
305
324
  VERSION: 6,
306
325
  g: {
307
326
  s: "data",
308
- K: "pushClicks",
327
+ J: "pushClicks",
309
328
  D: "pushSubscribed",
310
329
  A: "fallbackDevice",
311
- I: "cardUpdates",
330
+ H: "cardUpdates",
312
331
  C: "optOut",
313
- J: "pendingData",
314
- N: "sdkAuthenticationSignature"
332
+ I: "pendingData",
333
+ M: "sdkAuthenticationSignature",
315
334
  },
316
- v: 1
317
- }
335
+ v: 1,
336
+ },
318
337
  },
319
- E = y;
338
+ E = w;
320
339
  function F() {
321
- return new Promise(function(a, b) {
340
+ return new Promise(function (a, b) {
322
341
  const c = B.m;
323
- w(new A(c, E), c.g.C, b, a);
342
+ r(new A(c, E), c.g.C, b, a);
324
343
  });
325
344
  }
326
345
  function G() {
327
- return new Promise(a => {
346
+ return new Promise((a) => {
328
347
  const b = B.m;
329
- w(
348
+ r(
330
349
  new A(b, E),
331
- b.g.N,
350
+ b.g.M,
332
351
  (c, f) => {
333
352
  a(f);
334
353
  },
335
354
  () => {
336
355
  a(null);
337
- }
356
+ },
338
357
  );
339
358
  });
340
359
  }
341
360
  function H(a, b, c) {
342
361
  E.info(
343
- `${b} due to SDK Authentication failure with error code ${c.error_code}. The data will be logged on the user's next session start.`
362
+ `${b} due to SDK Authentication failure with error code ${c.error_code}. The data will be logged on the user's next session start.`,
344
363
  );
345
364
  b = B.m;
346
- new A(b, E).setItem(b.g.J, l.H(), a);
365
+ new A(b, E).setItem(b.g.I, z.F(), a);
347
366
  }
348
367
  function I(a, b, c) {
349
- return new Promise(function(f, e) {
350
- const d = {};
351
- d.time = Math.floor(new Date().valueOf() / 1e3);
352
- d.device_id = c;
353
- d.api_key = a;
354
- d.sdk_version = "4.8.3";
355
- d.sdk_flavor = "amp";
356
- d.respond_with = { config: { config_time: 0 } };
368
+ return new Promise(function (f, g) {
369
+ const e = {};
370
+ e.time = Math.floor(new Date().valueOf() / 1e3);
371
+ e.device_id = c;
372
+ e.api_key = a;
373
+ e.sdk_version = "4.10.0";
374
+ e.sdk_flavor = "amp";
375
+ e.respond_with = { config: { config_time: 0 } };
357
376
  fetch(b + "/data/", {
358
377
  method: "POST",
359
378
  headers: {
360
379
  "Content-type": "application/json",
361
380
  "X-Braze-Api-Key": a,
362
- "X-Braze-Last-Req-Ms-Ago": 72e5
381
+ "X-Braze-Last-Req-Ms-Ago": 72e5,
382
+ "X-Braze-Req-Attempt": 1,
363
383
  },
364
- body: JSON.stringify(d)
384
+ body: JSON.stringify(e),
365
385
  })
366
- .then(function(g) {
367
- g.ok || E.error("Unable to get config: " + g.status);
368
- return g.json();
386
+ .then(function (d) {
387
+ d.ok || E.error("Unable to get config: " + d.status);
388
+ return d.json();
369
389
  })
370
- .then(function(g) {
371
- g.error && (E.error("Unable to get config: " + g.error), e());
372
- g.auth_error &&
390
+ .then(function (d) {
391
+ d.error && (E.error("Unable to get config: " + d.error), g());
392
+ d.auth_error &&
373
393
  (E.error(
374
- "Unable to get config due to authentication error. SDK Authentication does not support AMP pages."
394
+ "Unable to get config due to authentication error. SDK Authentication does not support AMP pages.",
375
395
  ),
376
- e());
377
- g.error ||
378
- g.auth_error ||
379
- ((g = {
396
+ g());
397
+ d.error ||
398
+ d.auth_error ||
399
+ ((d = {
380
400
  userVisibleOnly: !0,
381
- applicationServerKey: k.P(g.config.vapid_public_key)
401
+ applicationServerKey: x.O(d.config.vapid_public_key),
382
402
  }),
383
- f(g));
403
+ f(d));
384
404
  })
385
- .catch(function(g) {
386
- E.error("Unable to get config: " + g);
387
- e();
405
+ .catch(function (d) {
406
+ E.error("Unable to get config: " + d);
407
+ g();
388
408
  });
389
409
  });
390
410
  }
391
- function J(a, b, c, f, e, d, g, h, m) {
411
+ function J(a, b, c, f, g, e, d, h, m) {
392
412
  return G().then(
393
- n =>
394
- new Promise(function(C, D) {
413
+ (n) =>
414
+ new Promise(function (C, D) {
395
415
  const u = {};
396
416
  u.device_id = c;
397
417
  u.api_key = a;
398
- u.sdk_version = "4.8.3";
399
- null != d && (u.sdk_flavor = d);
418
+ u.sdk_version = "4.10.0";
419
+ null != e && (u.sdk_flavor = e);
400
420
  var v = null;
401
421
  let K = null,
402
422
  L = null;
403
- e &&
404
- ((L = e.endpoint),
405
- e.getKey &&
423
+ g &&
424
+ ((L = g.endpoint),
425
+ g.getKey &&
406
426
  ((v = btoa(
407
427
  String.fromCharCode.apply(
408
428
  null,
409
- new Uint8Array(e.getKey("p256dh"))
410
- )
429
+ new Uint8Array(g.getKey("p256dh")),
430
+ ),
411
431
  )),
412
432
  (K = btoa(
413
- String.fromCharCode.apply(null, new Uint8Array(e.getKey("auth")))
433
+ String.fromCharCode.apply(null, new Uint8Array(g.getKey("auth"))),
414
434
  ))));
415
435
  u.time = Math.floor(new Date().valueOf() / 1e3);
416
436
  u.attributes = [
@@ -418,81 +438,83 @@ function J(a, b, c, f, e, d, g, h, m) {
418
438
  user_id: f,
419
439
  push_token: L,
420
440
  custom_push_public_key: v,
421
- custom_push_user_auth: K
422
- }
441
+ custom_push_user_auth: K,
442
+ },
423
443
  ];
424
444
  v = {
425
445
  "Content-type": "application/json",
426
446
  "X-Braze-Api-Key": u.api_key,
427
- "X-Braze-Last-Req-Ms-Ago": 72e5
447
+ "X-Braze-Last-Req-Ms-Ago": 72e5,
448
+ "X-Braze-Req-Attempt": 1,
428
449
  };
429
450
  n && m && (v["X-Braze-Auth-Signature"] = n);
430
451
  fetch(b + "/data/", {
431
452
  method: "POST",
432
453
  headers: v,
433
- body: JSON.stringify(u)
454
+ body: JSON.stringify(u),
434
455
  })
435
- .then(function(p) {
456
+ .then(function (p) {
436
457
  p.ok || E.error(h + " " + p.status);
437
458
  return p.json();
438
459
  })
439
- .then(function(p) {
460
+ .then(function (p) {
440
461
  p.error && (E.error(h + " " + p.error), D());
441
462
  p.auth_error && (H(u, h, p.auth_error), D());
442
- p.error || p.auth_error || (E.info(g), C());
463
+ p.error || p.auth_error || (E.info(d), C());
443
464
  })
444
- .catch(function(p) {
465
+ .catch(function (p) {
445
466
  E.error(h + " " + p);
446
467
  D();
447
468
  });
448
- })
469
+ }),
449
470
  );
450
471
  }
451
472
  function M(a, b) {
452
473
  return F()
453
- .then(function() {
474
+ .then(function () {
454
475
  return G();
455
476
  })
456
- .then(function(c) {
477
+ .then(function (c) {
457
478
  const f = B.m;
458
- w(new A(f, E), f.g.s, function(e, d) {
459
- e = Math.floor(new Date().valueOf() / 1e3);
460
- const g = d.data;
461
- g.time = e;
462
- a.time = e;
463
- a.user_id = d.userId;
464
- g.events = [a];
465
- g.sdk_version = "4.8.3";
466
- e = {
479
+ r(new A(f, E), f.g.s, function (g, e) {
480
+ g = Math.floor(new Date().valueOf() / 1e3);
481
+ const d = e.data;
482
+ d.time = g;
483
+ a.time = g;
484
+ a.user_id = e.userId;
485
+ d.events = [a];
486
+ d.sdk_version = "4.10.0";
487
+ g = {
467
488
  "Content-Type": "application/json",
468
- "X-Braze-Api-Key": g.api_key,
469
- "X-Braze-Last-Req-Ms-Ago": 72e5
489
+ "X-Braze-Api-Key": d.api_key,
490
+ "X-Braze-Last-Req-Ms-Ago": 72e5,
491
+ "X-Braze-Req-Attempt": 1,
470
492
  };
471
- c && d.sdkAuthEnabled && (e["X-Braze-Auth-Signature"] = c);
472
- fetch(d.baseUrl + "/data/", {
493
+ c && e.sdkAuthEnabled && (g["X-Braze-Auth-Signature"] = c);
494
+ fetch(e.baseUrl + "/data/", {
473
495
  method: "POST",
474
- headers: e,
475
- body: JSON.stringify(g)
496
+ headers: g,
497
+ body: JSON.stringify(d),
476
498
  })
477
- .then(function(h) {
499
+ .then(function (h) {
478
500
  h.ok || E.error("Unable to log " + b + ": " + h.status);
479
501
  return h.json();
480
502
  })
481
- .then(function(h) {
503
+ .then(function (h) {
482
504
  h.error && E.error("Unable to log " + b + ":", h.error);
483
- h.auth_error && H(g, "Unable to log " + b, h.auth_error);
505
+ h.auth_error && H(d, "Unable to log " + b, h.auth_error);
484
506
  h.error || h.auth_error || E.info("Successfully logged " + b);
485
507
  return Promise.resolve();
486
508
  })
487
- .catch(function(h) {
509
+ .catch(function (h) {
488
510
  E.error("Unable to log " + b + ":", h);
489
511
  return Promise.resolve();
490
512
  });
491
513
  });
492
514
  })
493
- .catch(function() {
515
+ .catch(function () {
494
516
  return Promise.reject(
495
- "Not sending data to Braze backend due to opt-out."
517
+ "Not sending data to Braze backend due to opt-out.",
496
518
  );
497
519
  });
498
520
  }
@@ -509,31 +531,31 @@ function O() {
509
531
  return null;
510
532
  }
511
533
  function P(a, b) {
512
- self.clients.matchAll().then(function(c) {
534
+ self.clients.matchAll().then(function (c) {
513
535
  for (let f = 0; f < c.length; f++)
514
536
  c[f].postMessage({ command: a, payload: b });
515
537
  });
516
538
  }
517
- function Q(a, b, c, f, e) {
539
+ function Q(a, b, c, f, g) {
518
540
  return I(a, b, c)
519
- .then(function(d) {
520
- return self.registration.pushManager.subscribe(d);
541
+ .then(function (e) {
542
+ return self.registration.pushManager.subscribe(e);
521
543
  })
522
- .then(function(d) {
544
+ .then(function (e) {
523
545
  P("amp-web-push-subscribe", null);
524
546
  return J(
525
547
  a,
526
548
  b,
527
549
  c,
528
550
  f,
529
- d,
551
+ e,
530
552
  "amp",
531
553
  "Successfully sent AMP push subscription to Braze backend.",
532
554
  "Unable to send AMP push subscription to Braze backend.",
533
- e
555
+ g,
534
556
  );
535
557
  })
536
- .catch(function() {
558
+ .catch(function () {
537
559
  E.error("Failed to subscribe for AMP push.");
538
560
  return Promise.reject();
539
561
  });
@@ -541,72 +563,72 @@ function Q(a, b, c, f, e) {
541
563
  function R() {
542
564
  self.registration.pushManager
543
565
  .getSubscription()
544
- .then(function(a) {
566
+ .then(function (a) {
545
567
  return a
546
568
  ? self.registration.pushManager.permissionState(a.options)
547
569
  : null;
548
570
  })
549
- .then(function(a) {
571
+ .then(function (a) {
550
572
  P("amp-web-push-subscription-state", "granted" === a);
551
573
  });
552
574
  }
553
575
  function S() {
554
576
  const a = B.m,
555
577
  b = new A(a, E);
556
- return new Promise(function(c, f) {
557
- w(
578
+ return new Promise(function (c, f) {
579
+ r(
558
580
  b,
559
581
  a.g.s,
560
- function(e, d) {
582
+ function (g, e) {
561
583
  Q(
562
- d.data.api_key,
563
- d.baseUrl,
564
- d.data.device_id,
565
- d.userId,
566
- d.sdkAuthEnabled
584
+ e.data.api_key,
585
+ e.baseUrl,
586
+ e.data.device_id,
587
+ e.userId,
588
+ e.sdkAuthEnabled,
567
589
  )
568
- .then(function() {
590
+ .then(function () {
569
591
  c();
570
592
  })
571
- .catch(function() {
593
+ .catch(function () {
572
594
  f();
573
595
  });
574
596
  },
575
- function() {
576
- const e = N(),
577
- d = O();
578
- w(
597
+ function () {
598
+ const g = N(),
599
+ e = O();
600
+ r(
579
601
  b,
580
602
  a.g.A,
581
- function(g, h) {
582
- Q(e, d, h, null)
583
- .then(function() {
603
+ function (d, h) {
604
+ Q(g, e, h, null)
605
+ .then(function () {
584
606
  c();
585
607
  })
586
- .catch(function() {
608
+ .catch(function () {
587
609
  f();
588
610
  });
589
611
  },
590
- function() {
591
- const g = l.H();
592
- new Promise(function(h, m) {
593
- b.setItem(a.g.A, a.v, g, h, m);
612
+ function () {
613
+ const d = z.F();
614
+ new Promise(function (h, m) {
615
+ b.setItem(a.g.A, a.v, d, h, m);
594
616
  })
595
- .then(function() {
596
- return Q(e, d, g, null);
617
+ .then(function () {
618
+ return Q(g, e, d, null);
597
619
  })
598
- .then(function() {
620
+ .then(function () {
599
621
  c();
600
622
  })
601
- .catch(function() {
623
+ .catch(function () {
602
624
  f();
603
625
  });
604
- }
626
+ },
605
627
  );
606
- }
628
+ },
607
629
  );
608
- }).then(function() {
609
- return new Promise(function(c, f) {
630
+ }).then(function () {
631
+ return new Promise(function (c, f) {
610
632
  b.setItem(a.g.D, a.v, !0, c, f);
611
633
  });
612
634
  });
@@ -614,107 +636,107 @@ function S() {
614
636
  function T() {
615
637
  return self.registration.pushManager
616
638
  .getSubscription()
617
- .then(function(a) {
639
+ .then(function (a) {
618
640
  return a.unsubscribe();
619
641
  })
620
- .then(function() {
642
+ .then(function () {
621
643
  P("amp-web-push-unsubscribe", null);
622
644
  const a = B.m,
623
645
  b = new A(a, E);
624
- return new Promise(function(c, f) {
625
- w(
646
+ return new Promise(function (c, f) {
647
+ r(
626
648
  b,
627
649
  a.g.s,
628
- function(e, d) {
650
+ function (g, e) {
629
651
  J(
630
- d.data.api_key,
631
- d.baseUrl,
632
- d.data.device_id,
633
- d.userId,
652
+ e.data.api_key,
653
+ e.baseUrl,
654
+ e.data.device_id,
655
+ e.userId,
634
656
  null,
635
657
  "amp",
636
658
  "Successfully sent AMP push unsubscription to Braze backend.",
637
659
  "Unable to send AMP push unsubscription to Braze backend.",
638
- d.sdkAuthEnabled
660
+ e.sdkAuthEnabled,
639
661
  )
640
- .then(function() {
662
+ .then(function () {
641
663
  c();
642
664
  })
643
- .catch(function() {
665
+ .catch(function () {
644
666
  f();
645
667
  });
646
668
  },
647
- function() {
648
- w(
669
+ function () {
670
+ r(
649
671
  b,
650
672
  a.g.A,
651
- function(e, d) {
652
- e = N();
653
- const g = O();
673
+ function (g, e) {
674
+ g = N();
675
+ const d = O();
654
676
  J(
655
- e,
656
677
  g,
657
678
  d,
679
+ e,
658
680
  null,
659
681
  null,
660
682
  "amp",
661
683
  "Successfully sent AMP push unsubscription to Braze backend.",
662
684
  "Unable to send AMP push unsubscription to Braze backend.",
663
- null
685
+ null,
664
686
  )
665
- .then(function() {
687
+ .then(function () {
666
688
  c();
667
689
  })
668
- .catch(function() {
690
+ .catch(function () {
669
691
  f();
670
692
  });
671
693
  },
672
- function() {
694
+ function () {
673
695
  E.error("No device found during unsubscription.");
674
696
  f();
675
- }
697
+ },
676
698
  );
677
- }
699
+ },
678
700
  );
679
- }).then(function() {
680
- return new Promise(function(c, f) {
701
+ }).then(function () {
702
+ return new Promise(function (c, f) {
681
703
  b.setItem(a.g.D, a.v, !1, c, f);
682
704
  });
683
705
  });
684
706
  })
685
- .catch(function() {
707
+ .catch(function () {
686
708
  E.error("Failed to unsubscribe for AMP push.");
687
709
  return Promise.reject();
688
710
  });
689
711
  }
690
712
  function U(a, b) {
691
713
  a.waitUntil(
692
- b.catch(function(c) {
714
+ b.catch(function (c) {
693
715
  c && E.info(c);
694
- })
716
+ }),
695
717
  );
696
718
  }
697
719
  E.B(!0);
698
720
  function V(a) {
699
721
  if (null == a || 0 === Object.keys(a).length)
700
722
  return Promise.reject(
701
- "Server has no pending push message for this registration. Ignoring push event."
723
+ "Server has no pending push message for this registration. Ignoring push event.",
702
724
  );
703
725
  const b = a.t,
704
726
  c = a.a,
705
727
  f = a.i,
706
- e = a.img,
707
- d = { url: a.u, ab_ids: { cid: a.cid }, extra: a.e },
708
- g = a.ri;
728
+ g = a.img,
729
+ e = { url: a.u, ab_ids: { cid: a.cid }, extra: a.e },
730
+ d = a.ri;
709
731
  a.ab_push_fetch_test_triggers_key &&
710
- (E.info("Service worker 4.8.3 found trigger fetch key in push payload."),
711
- (d.fetchTriggers = !0));
732
+ (E.info("Service worker 4.10.0 found trigger fetch key in push payload."),
733
+ (e.fetchTriggers = !0));
712
734
  var h = a.ab_cd;
713
735
  if (null != h) {
714
736
  var m = B.m;
715
- new A(m, E).setItem(m.g.I, new Date().valueOf(), {
737
+ new A(m, E).setItem(m.g.H, new Date().valueOf(), {
716
738
  userId: a.ab_cd_uid,
717
- card: h
739
+ card: h,
718
740
  });
719
741
  }
720
742
  a = a.pab || [];
@@ -731,71 +753,72 @@ function V(a) {
731
753
  }
732
754
  h[a[m].action] = n;
733
755
  }
734
- d.actionTargets = h;
756
+ e.actionTargets = h;
735
757
  E.info("Displaying push notification!");
736
758
  return self.registration
737
759
  .showNotification(b, {
738
760
  body: c,
739
761
  icon: f,
740
- image: e,
741
- data: d,
762
+ image: g,
763
+ data: e,
742
764
  actions: a,
743
- requireInteraction: g
765
+ requireInteraction: d,
744
766
  })
745
- .catch(function(n) {
767
+ .catch(function (n) {
746
768
  E.info(n);
747
769
  });
748
770
  }
749
- self.addEventListener("install", function(a) {
771
+ self.addEventListener("install", function (a) {
750
772
  a.waitUntil(self.skipWaiting());
751
773
  });
752
- self.addEventListener("activate", function() {
774
+ self.addEventListener("activate", function () {
753
775
  return self.clients.claim();
754
776
  });
755
- self.addEventListener("push", function(a) {
756
- E.info("Service worker 4.8.3 received push");
777
+ self.addEventListener("push", function (a) {
778
+ E.info("Service worker 4.10.0 received push");
757
779
  null != a.data && null != a.data.json
758
780
  ? U(a, V(a.data.json()))
759
781
  : U(
760
782
  a,
761
- new Promise(function(b, c) {
783
+ new Promise(function (b, c) {
762
784
  const f = B.m;
763
- w(new A(f, E), f.g.s, function(e, d) {
764
- const g = d.data;
785
+ r(new A(f, E), f.g.s, function (g, e) {
786
+ const d = e.data;
765
787
  F()
766
- .then(function() {
767
- return fetch(d.baseUrl + "/web_push/", {
788
+ .then(function () {
789
+ return fetch(e.baseUrl + "/web_push/", {
768
790
  method: "POST",
769
791
  headers: {
770
792
  "Content-type": "application/json",
771
- "X-Braze-Api-Key": g.api_key
793
+ "X-Braze-Api-Key": d.api_key,
772
794
  },
773
- body: JSON.stringify(g)
795
+ body: JSON.stringify(d),
774
796
  });
775
797
  })
776
- .then(function(h) {
798
+ .then(function (h) {
777
799
  return h.ok
778
800
  ? h.json()
779
801
  : (E.error(
780
- "Unable to retrieve push payload from server: " + h.status
802
+ "Unable to retrieve push payload from server: " +
803
+ h.status,
781
804
  ),
782
805
  Promise.reject());
783
806
  })
784
- .then(function(h) {
807
+ .then(function (h) {
785
808
  E.info("Retrieved push payload from server");
786
809
  b(V(h));
787
810
  })
788
- .catch(function(h) {
811
+ .catch(function (h) {
789
812
  c(
790
813
  "Unable to retrieve push payload from server or user has opt-out: " +
791
- h
814
+ h,
792
815
  );
793
816
  });
794
817
  });
795
- })
818
+ }),
796
819
  );
797
820
  });
798
- self.addEventListener("notificationclick", function(a) {
821
+ self.addEventListener("notificationclick", function (a) {
799
822
  if (
800
823
  a &&
801
824
  a.notification &&
@@ -809,91 +832,91 @@ self.addEventListener("notificationclick", function(a) {
809
832
  var c = b
810
833
  ? M(
811
834
  {
812
- name: z.L,
813
- data: { cid: a.notification.data.ab_ids.cid, a: a.action }
835
+ name: y.K,
836
+ data: { cid: a.notification.data.ab_ids.cid, a: a.action },
814
837
  },
815
- "push button click"
838
+ "push button click",
816
839
  )
817
840
  : M(
818
- { name: z.M, data: { cid: a.notification.data.ab_ids.cid } },
819
- "push click"
841
+ { name: y.L, data: { cid: a.notification.data.ab_ids.cid } },
842
+ "push click",
820
843
  );
821
844
  if (!b) {
822
- const g = {
845
+ const d = {
823
846
  lastClick: new Date().valueOf(),
824
- trackingString: a.notification.data.ab_ids.cid
847
+ trackingString: a.notification.data.ab_ids.cid,
825
848
  };
826
- a.notification.data.fetchTriggers && (g.fetchTriggers = !0);
849
+ a.notification.data.fetchTriggers && (d.fetchTriggers = !0);
827
850
  const h = B.m,
828
851
  m = new A(h, E);
829
852
  var f = c
830
- .then(function() {
831
- return new Promise(function(n, C) {
832
- m.setItem(h.g.K, h.v, g, n, C);
853
+ .then(function () {
854
+ return new Promise(function (n, C) {
855
+ m.setItem(h.g.J, h.v, d, n, C);
833
856
  });
834
857
  })
835
- .catch(function() {
858
+ .catch(function () {
836
859
  E.info("Not storing push click due to no click event being created.");
837
860
  return Promise.resolve();
838
861
  });
839
862
  }
840
- if (b) var e = a.notification.data.actionTargets[a.action];
841
- else if (((e = a.notification.data.url), null == e || "" === e)) e = "/";
842
- var d;
843
- null != e &&
844
- "" !== e &&
845
- (d = clients.matchAll({ type: "window" }).then(function() {
846
- if (clients.openWindow) return clients.openWindow(e);
863
+ if (b) var g = a.notification.data.actionTargets[a.action];
864
+ else if (((g = a.notification.data.url), null == g || "" === g)) g = "/";
865
+ var e;
866
+ null != g &&
867
+ "" !== g &&
868
+ (e = clients.matchAll({ type: "window" }).then(function () {
869
+ if (clients.openWindow) return clients.openWindow(g);
847
870
  }));
848
- U(a, Promise.all([d, f]));
871
+ U(a, Promise.all([e, f]));
849
872
  }
850
873
  });
851
- self.addEventListener("pushsubscriptionchange", function(a) {
874
+ self.addEventListener("pushsubscriptionchange", function (a) {
852
875
  U(
853
876
  a,
854
877
  F()
855
- .then(function() {
878
+ .then(function () {
856
879
  let b = { userVisibleOnly: !0 };
857
880
  null != a.oldSubscription && (b = a.oldSubscription.options);
858
881
  return self.registration.pushManager.subscribe(b);
859
882
  })
860
- .then(function(b) {
883
+ .then(function (b) {
861
884
  const c = B.m;
862
- return new Promise(function(f, e) {
863
- w(new A(c, E), c.g.s, function(d, g) {
885
+ return new Promise(function (f, g) {
886
+ r(new A(c, E), c.g.s, function (e, d) {
864
887
  J(
865
- g.data.api_key,
866
- g.baseUrl,
867
- g.data.device_id,
868
- g.userId,
888
+ d.data.api_key,
889
+ d.baseUrl,
890
+ d.data.device_id,
891
+ d.userId,
869
892
  b,
870
893
  null,
871
894
  "Successfully resubscribed user after expiration",
872
895
  "Unable to resubscribe user",
873
- g.sdkAuthEnabled
896
+ d.sdkAuthEnabled,
874
897
  )
875
- .then(function() {
898
+ .then(function () {
876
899
  f();
877
900
  })
878
- .catch(function() {
879
- e();
901
+ .catch(function () {
902
+ g();
880
903
  });
881
904
  });
882
905
  });
883
906
  })
884
- .catch(function() {
907
+ .catch(function () {
885
908
  return Promise.reject(
886
- "Not resubscribing user for push due to opt-out."
909
+ "Not resubscribing user for push due to opt-out.",
887
910
  );
888
- })
911
+ }),
889
912
  );
890
913
  });
891
- self.addEventListener("message", function(a) {
914
+ self.addEventListener("message", function (a) {
892
915
  a.waitUntil &&
893
916
  a.data.command &&
894
917
  a.waitUntil(
895
918
  F()
896
- .then(function() {
919
+ .then(function () {
897
920
  switch (a.data.command) {
898
921
  case "amp-web-push-subscription-state":
899
922
  return R(), Promise.resolve();
@@ -905,9 +928,9 @@ self.addEventListener("message", function(a) {
905
928
  return Promise.resolve();
906
929
  }
907
930
  })
908
- .catch(function() {
931
+ .catch(function () {
909
932
  E.info("Ignoring message from amp-web-push due to opt-out.");
910
933
  return Promise.resolve();
911
- })
934
+ }),
912
935
  );
913
936
  });