@braze/service-worker 5.0.1 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/service-worker.js +468 -523
package/service-worker.js
CHANGED
|
@@ -1,27 +1,69 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Braze Web SDK v5.
|
|
3
|
-
* (c) Braze, Inc.
|
|
2
|
+
* Braze Web SDK v5.1.1
|
|
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
|
|
5
|
+
* Compiled on 2024-02-13
|
|
6
6
|
*/
|
|
7
|
-
|
|
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.1)"),
|
|
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.1)"),
|
|
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
|
|
11
|
-
var
|
|
52
|
+
function r(a) {
|
|
53
|
+
var c;
|
|
12
54
|
try {
|
|
13
|
-
if (null ==
|
|
14
|
-
const
|
|
15
|
-
null === (
|
|
55
|
+
if (null == q(a)) return !1;
|
|
56
|
+
const e =
|
|
57
|
+
null === (c = q(a)) || void 0 === c
|
|
16
58
|
? void 0
|
|
17
|
-
:
|
|
18
|
-
|
|
19
|
-
((
|
|
20
|
-
(
|
|
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
|
-
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
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 (
|
|
75
|
+
} catch (e) {
|
|
34
76
|
return (
|
|
35
|
-
a.j.info("Not using IndexedDB for storage due to following error: " +
|
|
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
|
|
41
|
-
var
|
|
42
|
-
const
|
|
43
|
-
null === (
|
|
44
|
-
if (null ==
|
|
45
|
-
|
|
46
|
-
var
|
|
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
|
-
|
|
49
|
-
for (const
|
|
50
|
-
(
|
|
51
|
-
a.h.g.hasOwnProperty(
|
|
52
|
-
!
|
|
53
|
-
|
|
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
|
-
|
|
56
|
-
var
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"function" === typeof
|
|
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
|
-
|
|
107
|
+
c(k);
|
|
66
108
|
};
|
|
67
|
-
|
|
68
|
-
var
|
|
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 === (
|
|
117
|
+
(null === (b = f.target) || void 0 === b ? void 0 : b.errorCode),
|
|
76
118
|
);
|
|
77
|
-
"function" === typeof
|
|
119
|
+
"function" === typeof e && e();
|
|
78
120
|
return !0;
|
|
79
121
|
};
|
|
80
122
|
return !0;
|
|
81
123
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
?
|
|
124
|
+
function w(a, c, e, g) {
|
|
125
|
+
r(a)
|
|
126
|
+
? v(
|
|
85
127
|
a,
|
|
86
|
-
(
|
|
87
|
-
if (
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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 " +
|
|
135
|
+
"Could not open cursor for " + c + " on indexedDB " + a.h.l,
|
|
94
136
|
);
|
|
95
|
-
"function" === typeof
|
|
137
|
+
"function" === typeof g && g();
|
|
96
138
|
};
|
|
97
|
-
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
null !=
|
|
101
|
-
?
|
|
102
|
-
: "function" === typeof
|
|
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
|
-
|
|
149
|
+
c +
|
|
108
150
|
" on indexedDB " +
|
|
109
151
|
a.h.l +
|
|
110
152
|
" - " +
|
|
111
|
-
|
|
153
|
+
c +
|
|
112
154
|
" is not a valid objectStore",
|
|
113
155
|
),
|
|
114
|
-
"function" === typeof
|
|
115
|
-
|
|
156
|
+
"function" === typeof g && g(),
|
|
157
|
+
d.close();
|
|
116
158
|
},
|
|
117
|
-
|
|
159
|
+
g,
|
|
118
160
|
)
|
|
119
|
-
: "function" === typeof
|
|
161
|
+
: "function" === typeof g && g();
|
|
120
162
|
}
|
|
121
|
-
class
|
|
122
|
-
constructor(
|
|
163
|
+
class x {
|
|
164
|
+
constructor() {
|
|
165
|
+
var a = y,
|
|
166
|
+
c = h;
|
|
123
167
|
this.h = a;
|
|
124
|
-
this.j =
|
|
168
|
+
this.j = c;
|
|
125
169
|
this.parent = "undefined" === typeof window ? self : window;
|
|
126
170
|
this.h = a;
|
|
127
|
-
this.j =
|
|
171
|
+
this.j = c;
|
|
128
172
|
}
|
|
129
|
-
setItem(a,
|
|
130
|
-
if (!
|
|
131
|
-
const
|
|
132
|
-
return
|
|
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
|
-
(
|
|
135
|
-
if (
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
186
|
+
c +
|
|
143
187
|
" in " +
|
|
144
188
|
a +
|
|
145
189
|
" on indexedDB " +
|
|
146
|
-
|
|
190
|
+
f.h.l,
|
|
147
191
|
);
|
|
148
|
-
"function" === typeof
|
|
192
|
+
"function" === typeof d && d();
|
|
149
193
|
};
|
|
150
|
-
|
|
151
|
-
"function" === typeof
|
|
194
|
+
k.onsuccess = () => {
|
|
195
|
+
"function" === typeof g && g();
|
|
152
196
|
};
|
|
153
197
|
} else
|
|
154
|
-
|
|
198
|
+
f.j.error(
|
|
155
199
|
"Could not store object " +
|
|
156
|
-
|
|
200
|
+
c +
|
|
157
201
|
" in " +
|
|
158
202
|
a +
|
|
159
203
|
" on indexedDB " +
|
|
160
|
-
|
|
204
|
+
f.h.l +
|
|
161
205
|
" - " +
|
|
162
206
|
a +
|
|
163
207
|
" is not a valid objectStore",
|
|
164
208
|
),
|
|
165
|
-
"function" === typeof
|
|
166
|
-
|
|
209
|
+
"function" === typeof d && d(),
|
|
210
|
+
b.close();
|
|
167
211
|
},
|
|
168
|
-
|
|
212
|
+
d,
|
|
169
213
|
);
|
|
170
214
|
}
|
|
171
|
-
getItem(a,
|
|
172
|
-
if (!
|
|
173
|
-
const
|
|
174
|
-
return
|
|
175
|
-
if (
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
226
|
+
c +
|
|
183
227
|
" in " +
|
|
184
228
|
a +
|
|
185
229
|
" on indexedDB " +
|
|
186
|
-
|
|
230
|
+
g.h.l,
|
|
187
231
|
);
|
|
188
232
|
};
|
|
189
|
-
|
|
190
|
-
var
|
|
191
|
-
|
|
192
|
-
null !=
|
|
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
|
-
|
|
239
|
+
g.j.error(
|
|
196
240
|
"Could not retrieve object " +
|
|
197
|
-
|
|
241
|
+
c +
|
|
198
242
|
" in " +
|
|
199
243
|
a +
|
|
200
244
|
" on indexedDB " +
|
|
201
|
-
|
|
245
|
+
g.h.l +
|
|
202
246
|
" - " +
|
|
203
247
|
a +
|
|
204
248
|
" is not a valid objectStore",
|
|
205
249
|
),
|
|
206
|
-
|
|
250
|
+
d.close();
|
|
207
251
|
});
|
|
208
252
|
}
|
|
209
253
|
clearData() {
|
|
210
|
-
if (!
|
|
254
|
+
if (!r(this)) return !1;
|
|
211
255
|
const a = [];
|
|
212
|
-
for (const
|
|
213
|
-
const
|
|
214
|
-
this.h.g.hasOwnProperty(
|
|
215
|
-
this.h.g[
|
|
216
|
-
a.push(this.h.g[
|
|
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
|
|
219
|
-
return
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
for (let
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
"Could not clear " + this.source.name + " on indexedDB " +
|
|
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
|
-
|
|
229
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
"
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
|
298
|
+
function A() {
|
|
346
299
|
return new Promise((a) => {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
|
361
|
-
|
|
362
|
-
`${
|
|
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
|
-
|
|
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
|
|
368
|
-
return new Promise(function (
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
fetch(
|
|
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.1";
|
|
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(
|
|
335
|
+
body: JSON.stringify(f),
|
|
385
336
|
})
|
|
386
|
-
.then(function (
|
|
387
|
-
|
|
388
|
-
return
|
|
337
|
+
.then(function (b) {
|
|
338
|
+
b.ok || h.error("Unable to get config: " + b.status);
|
|
339
|
+
return b.json();
|
|
389
340
|
})
|
|
390
|
-
.then(function (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
(
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
((
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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 (
|
|
406
|
-
|
|
407
|
-
|
|
358
|
+
.catch(function (b) {
|
|
359
|
+
h.error("Unable to get config: " + b);
|
|
360
|
+
d();
|
|
408
361
|
});
|
|
409
362
|
});
|
|
410
363
|
}
|
|
411
|
-
function
|
|
412
|
-
return
|
|
413
|
-
(
|
|
414
|
-
new Promise(function (
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
null !=
|
|
420
|
-
var
|
|
421
|
-
let
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
((
|
|
425
|
-
|
|
426
|
-
((
|
|
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.1";
|
|
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(
|
|
382
|
+
new Uint8Array(d.getKey("p256dh")),
|
|
430
383
|
),
|
|
431
384
|
)),
|
|
432
|
-
(
|
|
433
|
-
String.fromCharCode.apply(null, new Uint8Array(
|
|
385
|
+
(H = btoa(
|
|
386
|
+
String.fromCharCode.apply(null, new Uint8Array(d.getKey("auth"))),
|
|
434
387
|
))));
|
|
435
|
-
|
|
436
|
-
|
|
388
|
+
t.time = Math.floor(new Date().valueOf() / 1e3);
|
|
389
|
+
t.attributes = [
|
|
437
390
|
{
|
|
438
|
-
user_id:
|
|
439
|
-
push_token:
|
|
440
|
-
custom_push_public_key:
|
|
441
|
-
custom_push_user_auth:
|
|
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
|
-
|
|
397
|
+
u = {
|
|
445
398
|
"Content-type": "application/json",
|
|
446
|
-
"X-Braze-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
|
-
|
|
451
|
-
fetch(
|
|
403
|
+
p && m && (u["X-Braze-Auth-Signature"] = p);
|
|
404
|
+
fetch(c + "/data/", {
|
|
452
405
|
method: "POST",
|
|
453
|
-
headers:
|
|
454
|
-
body: JSON.stringify(
|
|
406
|
+
headers: u,
|
|
407
|
+
body: JSON.stringify(t),
|
|
455
408
|
})
|
|
456
|
-
.then(function (
|
|
457
|
-
|
|
458
|
-
return
|
|
409
|
+
.then(function (n) {
|
|
410
|
+
n.ok || h.error(k + " " + n.status);
|
|
411
|
+
return n.json();
|
|
459
412
|
})
|
|
460
|
-
.then(function (
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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 (
|
|
466
|
-
|
|
467
|
-
|
|
418
|
+
.catch(function (n) {
|
|
419
|
+
h.error(k + " " + n);
|
|
420
|
+
B();
|
|
468
421
|
});
|
|
469
422
|
}),
|
|
470
423
|
);
|
|
471
424
|
}
|
|
472
|
-
function
|
|
473
|
-
return
|
|
425
|
+
function F(a, c) {
|
|
426
|
+
return z()
|
|
474
427
|
.then(function () {
|
|
475
|
-
return
|
|
428
|
+
return A();
|
|
476
429
|
})
|
|
477
|
-
.then(function (
|
|
478
|
-
|
|
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
|
|
482
|
-
|
|
433
|
+
const f = d.data;
|
|
434
|
+
f.time = g;
|
|
483
435
|
a.time = g;
|
|
484
|
-
a.user_id =
|
|
485
|
-
|
|
486
|
-
|
|
436
|
+
a.user_id = d.userId;
|
|
437
|
+
f.events = [a];
|
|
438
|
+
f.sdk_version = "5.1.1";
|
|
487
439
|
g = {
|
|
488
440
|
"Content-Type": "application/json",
|
|
489
|
-
"X-Braze-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
|
-
|
|
494
|
-
fetch(
|
|
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(
|
|
449
|
+
body: JSON.stringify(f),
|
|
498
450
|
})
|
|
499
|
-
.then(function (
|
|
500
|
-
|
|
501
|
-
return
|
|
451
|
+
.then(function (b) {
|
|
452
|
+
b.ok || h.error("Unable to log " + c + ": " + b.status);
|
|
453
|
+
return b.json();
|
|
502
454
|
})
|
|
503
|
-
.then(function (
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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 (
|
|
510
|
-
|
|
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
|
|
473
|
+
function G() {
|
|
522
474
|
const a = self.location.search.match(/apiKey=([^&]+)/i);
|
|
523
475
|
if (a) return a[1];
|
|
524
|
-
|
|
476
|
+
h.error("Missing API key in query params.");
|
|
525
477
|
return null;
|
|
526
478
|
}
|
|
527
|
-
function
|
|
479
|
+
function J() {
|
|
528
480
|
const a = self.location.search.match(/baseUrl=([^&]+)/i);
|
|
529
481
|
if (a) return a[1];
|
|
530
|
-
|
|
482
|
+
h.error("Missing base URL in query params.");
|
|
531
483
|
return null;
|
|
532
484
|
}
|
|
533
|
-
function
|
|
534
|
-
self.clients.matchAll().then(function (
|
|
535
|
-
for (let
|
|
536
|
-
|
|
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
|
|
540
|
-
return
|
|
541
|
-
.then(function (
|
|
542
|
-
return self.registration.pushManager.subscribe(
|
|
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 (
|
|
545
|
-
|
|
546
|
-
return
|
|
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
|
-
|
|
507
|
+
d,
|
|
556
508
|
);
|
|
557
509
|
})
|
|
558
510
|
.catch(function () {
|
|
559
|
-
|
|
511
|
+
h.error("Failed to subscribe for AMP push.");
|
|
560
512
|
return Promise.reject();
|
|
561
513
|
});
|
|
562
514
|
}
|
|
563
|
-
function
|
|
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
|
-
|
|
524
|
+
K("amp-web-push-subscription-state", "granted" === a);
|
|
573
525
|
});
|
|
574
526
|
}
|
|
575
|
-
function
|
|
576
|
-
const a =
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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
|
-
|
|
545
|
+
e();
|
|
595
546
|
});
|
|
596
547
|
},
|
|
597
548
|
function () {
|
|
598
|
-
const g =
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
function (
|
|
604
|
-
|
|
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
|
-
|
|
560
|
+
e();
|
|
610
561
|
});
|
|
611
562
|
},
|
|
612
563
|
function () {
|
|
613
|
-
const
|
|
614
|
-
new Promise(function (
|
|
615
|
-
|
|
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
|
|
569
|
+
return L(g, d, f, null);
|
|
619
570
|
})
|
|
620
571
|
.then(function () {
|
|
621
572
|
c();
|
|
622
573
|
})
|
|
623
574
|
.catch(function () {
|
|
624
|
-
|
|
575
|
+
e();
|
|
625
576
|
});
|
|
626
577
|
},
|
|
627
578
|
);
|
|
628
579
|
},
|
|
629
580
|
);
|
|
630
581
|
}).then(function () {
|
|
631
|
-
return new Promise(function (c,
|
|
632
|
-
|
|
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
|
|
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
|
-
|
|
644
|
-
const a =
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
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
|
-
|
|
610
|
+
d.sdkAuthEnabled,
|
|
661
611
|
)
|
|
662
612
|
.then(function () {
|
|
663
613
|
c();
|
|
664
614
|
})
|
|
665
615
|
.catch(function () {
|
|
666
|
-
|
|
616
|
+
e();
|
|
667
617
|
});
|
|
668
618
|
},
|
|
669
619
|
function () {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
function (g,
|
|
674
|
-
g =
|
|
675
|
-
const
|
|
676
|
-
|
|
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
|
-
|
|
641
|
+
e();
|
|
692
642
|
});
|
|
693
643
|
},
|
|
694
644
|
function () {
|
|
695
|
-
|
|
696
|
-
|
|
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,
|
|
703
|
-
|
|
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
|
-
|
|
658
|
+
h.error("Failed to unsubscribe for AMP push.");
|
|
709
659
|
return Promise.reject();
|
|
710
660
|
});
|
|
711
661
|
}
|
|
712
|
-
function
|
|
662
|
+
function Q(a, c) {
|
|
713
663
|
a.waitUntil(
|
|
714
|
-
|
|
715
|
-
|
|
664
|
+
c.catch(function (e) {
|
|
665
|
+
e && h.info(e);
|
|
716
666
|
}),
|
|
717
667
|
);
|
|
718
668
|
}
|
|
719
|
-
|
|
720
|
-
function
|
|
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
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
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
|
-
(
|
|
733
|
-
(
|
|
734
|
-
var
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
new A(m, E).setItem(m.g.H, new Date().valueOf(), {
|
|
682
|
+
(h.info("Service worker 5.1.1 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:
|
|
688
|
+
card: k,
|
|
740
689
|
});
|
|
741
|
-
}
|
|
742
690
|
a = a.pab || [];
|
|
743
|
-
|
|
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
|
|
694
|
+
let p;
|
|
747
695
|
switch (a[m].a) {
|
|
748
696
|
case "ab_none":
|
|
749
|
-
|
|
697
|
+
p = null;
|
|
750
698
|
break;
|
|
751
699
|
case "ab_uri":
|
|
752
|
-
if (((
|
|
700
|
+
if (((p = a[m].u), null == p || "" === p)) p = "/";
|
|
753
701
|
}
|
|
754
|
-
|
|
702
|
+
k[a[m].action] = p;
|
|
755
703
|
}
|
|
756
|
-
|
|
757
|
-
|
|
704
|
+
f.actionTargets = k;
|
|
705
|
+
h.info("Displaying push notification!");
|
|
758
706
|
return self.registration
|
|
759
|
-
.showNotification(
|
|
760
|
-
body:
|
|
761
|
-
icon:
|
|
762
|
-
image:
|
|
763
|
-
data:
|
|
707
|
+
.showNotification(c, {
|
|
708
|
+
body: e,
|
|
709
|
+
icon: g,
|
|
710
|
+
image: d,
|
|
711
|
+
data: f,
|
|
764
712
|
actions: a,
|
|
765
|
-
requireInteraction:
|
|
713
|
+
requireInteraction: b,
|
|
766
714
|
})
|
|
767
|
-
.catch(function (
|
|
768
|
-
|
|
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
|
-
|
|
726
|
+
h.info("Service worker 5.1.1 received push");
|
|
779
727
|
null != a.data && null != a.data.json
|
|
780
|
-
?
|
|
781
|
-
:
|
|
728
|
+
? Q(a, R(a.data.json()))
|
|
729
|
+
: Q(
|
|
782
730
|
a,
|
|
783
|
-
new Promise(function (
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
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(
|
|
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":
|
|
740
|
+
"X-Braze-Api-Key": f.api_key,
|
|
794
741
|
},
|
|
795
|
-
body: JSON.stringify(
|
|
742
|
+
body: JSON.stringify(f),
|
|
796
743
|
});
|
|
797
744
|
})
|
|
798
|
-
.then(function (
|
|
799
|
-
return
|
|
800
|
-
?
|
|
801
|
-
: (
|
|
745
|
+
.then(function (b) {
|
|
746
|
+
return b.ok
|
|
747
|
+
? b.json()
|
|
748
|
+
: (h.error(
|
|
802
749
|
"Unable to retrieve push payload from server: " +
|
|
803
|
-
|
|
750
|
+
b.status,
|
|
804
751
|
),
|
|
805
752
|
Promise.reject());
|
|
806
753
|
})
|
|
807
|
-
.then(function (
|
|
808
|
-
|
|
809
|
-
|
|
754
|
+
.then(function (b) {
|
|
755
|
+
h.info("Retrieved push payload from server");
|
|
756
|
+
c(R(b));
|
|
810
757
|
})
|
|
811
|
-
.catch(function (
|
|
812
|
-
|
|
758
|
+
.catch(function (b) {
|
|
759
|
+
e(
|
|
813
760
|
"Unable to retrieve push payload from server or user has opt-out: " +
|
|
814
|
-
|
|
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
|
|
832
|
-
var
|
|
833
|
-
?
|
|
778
|
+
var c = null != a.action && "" !== a.action;
|
|
779
|
+
var e = c
|
|
780
|
+
? F(
|
|
834
781
|
{
|
|
835
|
-
name:
|
|
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
|
-
:
|
|
841
|
-
{ name:
|
|
787
|
+
: F(
|
|
788
|
+
{ name: "pc", data: { cid: a.notification.data.ab_ids.cid } },
|
|
842
789
|
"push click",
|
|
843
790
|
);
|
|
844
|
-
if (!
|
|
845
|
-
const
|
|
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 && (
|
|
850
|
-
const
|
|
851
|
-
|
|
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 (
|
|
855
|
-
|
|
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
|
-
|
|
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 (
|
|
864
|
-
else if (((
|
|
865
|
-
var
|
|
866
|
-
null !=
|
|
867
|
-
"" !==
|
|
868
|
-
(
|
|
869
|
-
if (clients.openWindow) return clients.openWindow(
|
|
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
|
-
|
|
817
|
+
Q(a, Promise.all([f, g]));
|
|
872
818
|
}
|
|
873
819
|
});
|
|
874
820
|
self.addEventListener("pushsubscriptionchange", function (a) {
|
|
875
|
-
|
|
821
|
+
Q(
|
|
876
822
|
a,
|
|
877
|
-
|
|
823
|
+
z()
|
|
878
824
|
.then(function () {
|
|
879
|
-
let
|
|
880
|
-
null != a.oldSubscription && (
|
|
881
|
-
return self.registration.pushManager.subscribe(
|
|
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 (
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
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
|
-
|
|
841
|
+
f.sdkAuthEnabled,
|
|
897
842
|
)
|
|
898
843
|
.then(function () {
|
|
899
|
-
|
|
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
|
-
|
|
863
|
+
z()
|
|
919
864
|
.then(function () {
|
|
920
865
|
switch (a.data.command) {
|
|
921
866
|
case "amp-web-push-subscription-state":
|
|
922
|
-
return
|
|
867
|
+
return M(), Promise.resolve();
|
|
923
868
|
case "amp-web-push-subscribe":
|
|
924
|
-
return
|
|
869
|
+
return N();
|
|
925
870
|
case "amp-web-push-unsubscribe":
|
|
926
|
-
return
|
|
871
|
+
return P();
|
|
927
872
|
default:
|
|
928
873
|
return Promise.resolve();
|
|
929
874
|
}
|
|
930
875
|
})
|
|
931
876
|
.catch(function () {
|
|
932
|
-
|
|
877
|
+
h.info("Ignoring message from amp-web-push due to opt-out.");
|
|
933
878
|
return Promise.resolve();
|
|
934
879
|
}),
|
|
935
880
|
);
|