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