@arsel.sa/web-sdk 1.1.0 → 1.2.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.
- package/CHANGELOG.md +22 -1
- package/dist/arsel.js +442 -425
- package/dist/arsel.js.map +1 -1
- package/dist/arsel.umd.cjs +2 -2
- package/dist/arsel.umd.cjs.map +1 -1
- package/dist/events.d.ts +7 -2
- package/dist/install.d.ts +10 -0
- package/dist/store.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/arsel.js
CHANGED
|
@@ -3,9 +3,9 @@ const S = {
|
|
|
3
3
|
events: "events",
|
|
4
4
|
inAppBeacons: "inapp_beacons"
|
|
5
5
|
};
|
|
6
|
-
let
|
|
6
|
+
let H = null;
|
|
7
7
|
function Je() {
|
|
8
|
-
return
|
|
8
|
+
return H || (H = new Promise((e, t) => {
|
|
9
9
|
const n = indexedDB.open(Ye, 2);
|
|
10
10
|
n.onupgradeneeded = () => {
|
|
11
11
|
const i = n.result;
|
|
@@ -13,42 +13,42 @@ function Je() {
|
|
|
13
13
|
for (const r of Object.values(S))
|
|
14
14
|
i.objectStoreNames.contains(r) || i.createObjectStore(r, { keyPath: "id", autoIncrement: !0 });
|
|
15
15
|
}, n.onsuccess = () => e(n.result), n.onerror = () => t(n.error);
|
|
16
|
-
}),
|
|
16
|
+
}), H);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function P(e, t, n) {
|
|
19
19
|
return Je().then(
|
|
20
|
-
(i) => new Promise((r,
|
|
21
|
-
const
|
|
22
|
-
|
|
20
|
+
(i) => new Promise((r, s) => {
|
|
21
|
+
const a = n(i.transaction(e, t).objectStore(e));
|
|
22
|
+
a.onsuccess = () => r(a.result), a.onerror = () => s(a.error);
|
|
23
23
|
})
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
function c(e) {
|
|
27
|
-
return
|
|
27
|
+
return P("kv", "readonly", (t) => t.get(e)).then(
|
|
28
28
|
(t) => t ?? null
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
return
|
|
31
|
+
function u(e, t) {
|
|
32
|
+
return P("kv", "readwrite", (n) => n.put(t, e));
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
34
|
+
function L(e) {
|
|
35
|
+
return P("kv", "readwrite", (t) => t.delete(e));
|
|
36
36
|
}
|
|
37
37
|
function De(e, t, n = "") {
|
|
38
|
-
return
|
|
38
|
+
return P(
|
|
39
39
|
e,
|
|
40
40
|
"readwrite",
|
|
41
41
|
(i) => i.add({ body: t, idempotencyKey: n, createdAtMs: Date.now() })
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
function le(e) {
|
|
45
|
-
return
|
|
45
|
+
return P(e, "readonly", (t) => t.getAll());
|
|
46
46
|
}
|
|
47
47
|
function ue(e, t) {
|
|
48
|
-
return
|
|
48
|
+
return P(e, "readwrite", (n) => n.delete(t));
|
|
49
49
|
}
|
|
50
50
|
function Oe(e) {
|
|
51
|
-
return
|
|
51
|
+
return P(e, "readonly", (t) => t.count());
|
|
52
52
|
}
|
|
53
53
|
async function Ge(e, t) {
|
|
54
54
|
const n = await le(e);
|
|
@@ -56,7 +56,7 @@ async function Ge(e, t) {
|
|
|
56
56
|
for (const i of n.slice(0, n.length - t))
|
|
57
57
|
i.id !== void 0 && await ue(e, i.id);
|
|
58
58
|
}
|
|
59
|
-
const
|
|
59
|
+
const o = {
|
|
60
60
|
clientKey: "client_key",
|
|
61
61
|
baseUrl: "base_url",
|
|
62
62
|
anonymousId: "anonymous_id",
|
|
@@ -68,6 +68,7 @@ const a = {
|
|
|
68
68
|
vapidKeyVersion: "vapid_key_version",
|
|
69
69
|
endpoint: "endpoint",
|
|
70
70
|
subscriptionStatus: "subscription_status",
|
|
71
|
+
installReported: "install_reported",
|
|
71
72
|
sessionStartedAt: "session_started_at",
|
|
72
73
|
backgroundedAt: "backgrounded_at",
|
|
73
74
|
lastResponseCode: "last_response_code",
|
|
@@ -85,40 +86,40 @@ const a = {
|
|
|
85
86
|
inAppSession: "inapp_session"
|
|
86
87
|
};
|
|
87
88
|
async function X() {
|
|
88
|
-
const e = await c(
|
|
89
|
+
const e = await c(o.anonymousId);
|
|
89
90
|
if (e) return e;
|
|
90
91
|
const t = crypto.randomUUID();
|
|
91
|
-
return await
|
|
92
|
+
return await u(o.anonymousId, t), t;
|
|
92
93
|
}
|
|
93
94
|
async function Ze() {
|
|
94
95
|
const e = crypto.randomUUID();
|
|
95
|
-
return await
|
|
96
|
+
return await u(o.anonymousId, e), e;
|
|
96
97
|
}
|
|
97
|
-
const
|
|
98
|
+
const j = "1.2.0", Re = { "X-Arsel-SDK": `web/${j}` }, y = {
|
|
98
99
|
success: "success",
|
|
99
100
|
retryable: "retryable",
|
|
100
101
|
permanent: "permanent",
|
|
101
102
|
reauth: "reauth"
|
|
102
|
-
},
|
|
103
|
-
function
|
|
103
|
+
}, J = -1;
|
|
104
|
+
function Me(e, t) {
|
|
104
105
|
return e >= 200 && e <= 299 ? y.success : e === 408 || e === 429 || e >= 500 && e <= 599 ? y.retryable : t && (e === 401 || e === 403 || e === 404) ? y.reauth : e === 404 ? y.retryable : y.permanent;
|
|
105
106
|
}
|
|
106
|
-
async function
|
|
107
|
+
async function G(e, t) {
|
|
107
108
|
try {
|
|
108
109
|
await Promise.all([
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
u(o.lastResponseCode, t),
|
|
111
|
+
u(o.lastResponsePath, e),
|
|
112
|
+
u(o.lastResponseAtMs, Date.now())
|
|
112
113
|
]);
|
|
113
114
|
} catch {
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
|
-
async function
|
|
117
|
-
let
|
|
117
|
+
async function z(e, t, n, i = {}, r = !1) {
|
|
118
|
+
let s;
|
|
118
119
|
try {
|
|
119
|
-
|
|
120
|
+
s = await fetch(e + t, {
|
|
120
121
|
method: "POST",
|
|
121
|
-
headers: { "Content-Type": "application/json", ...
|
|
122
|
+
headers: { "Content-Type": "application/json", ...Re, ...i },
|
|
122
123
|
body: JSON.stringify(n),
|
|
123
124
|
// The SDK never relies on cookies, and sending them would attach a
|
|
124
125
|
// first-party session to a cross-origin call for no reason.
|
|
@@ -126,41 +127,41 @@ async function j(e, t, n, i = {}, r = !1) {
|
|
|
126
127
|
keepalive: !0
|
|
127
128
|
});
|
|
128
129
|
} catch {
|
|
129
|
-
return await
|
|
130
|
+
return await G(t, J), { result: y.retryable, code: J, body: null };
|
|
130
131
|
}
|
|
131
|
-
await
|
|
132
|
-
const
|
|
132
|
+
await G(t, s.status);
|
|
133
|
+
const a = Me(s.status, r);
|
|
133
134
|
let l = null;
|
|
134
135
|
try {
|
|
135
|
-
l = await
|
|
136
|
+
l = await s.json();
|
|
136
137
|
} catch {
|
|
137
138
|
}
|
|
138
|
-
return { result:
|
|
139
|
+
return { result: a, code: s.status, body: l };
|
|
139
140
|
}
|
|
140
141
|
async function de(e, t, n = {}, i = !1, r = {}) {
|
|
141
|
-
let
|
|
142
|
+
let s;
|
|
142
143
|
try {
|
|
143
|
-
|
|
144
|
+
s = await fetch(e + t, {
|
|
144
145
|
...r,
|
|
145
146
|
credentials: "omit",
|
|
146
|
-
headers: { ...
|
|
147
|
+
headers: { ...Re, ...n }
|
|
147
148
|
});
|
|
148
149
|
} catch {
|
|
149
|
-
return await
|
|
150
|
+
return await G(t, J), { result: y.retryable, code: J, body: null };
|
|
150
151
|
}
|
|
151
|
-
await
|
|
152
|
-
let
|
|
152
|
+
await G(t, s.status);
|
|
153
|
+
let a = null;
|
|
153
154
|
try {
|
|
154
|
-
|
|
155
|
+
a = await s.json();
|
|
155
156
|
} catch {
|
|
156
157
|
}
|
|
157
158
|
return {
|
|
158
|
-
result:
|
|
159
|
-
code:
|
|
160
|
-
body:
|
|
159
|
+
result: Me(s.status, i),
|
|
160
|
+
code: s.status,
|
|
161
|
+
body: a
|
|
161
162
|
};
|
|
162
163
|
}
|
|
163
|
-
const Qe = "/v1/events/send",
|
|
164
|
+
const Qe = "/v1/events/send", x = "arsel.", et = `${x}session_start`, tt = `${x}session_end`, nt = `${x}identify`, it = `${x}app_installed`, rt = `${x}screen_view`, ot = 80, st = 128, at = 255, ge = 50, ct = 8, ve = 64 * 1024;
|
|
164
165
|
function se(e, t) {
|
|
165
166
|
if (e === null) return null;
|
|
166
167
|
const n = typeof e;
|
|
@@ -169,171 +170,171 @@ function se(e, t) {
|
|
|
169
170
|
if (n === "bigint") return String(e);
|
|
170
171
|
if (e instanceof Date)
|
|
171
172
|
return Number.isNaN(e.getTime()) ? void 0 : e.toISOString();
|
|
172
|
-
if (n !== "object" || t >=
|
|
173
|
+
if (n !== "object" || t >= ct) return;
|
|
173
174
|
if (Array.isArray(e))
|
|
174
175
|
return e.map((r) => se(r, t + 1) ?? null);
|
|
175
176
|
const i = {};
|
|
176
|
-
for (const [r,
|
|
177
|
+
for (const [r, s] of Object.entries(e)) {
|
|
177
178
|
if (!r) continue;
|
|
178
|
-
const
|
|
179
|
-
|
|
179
|
+
const a = se(s, t + 1);
|
|
180
|
+
a !== void 0 && (i[r] = a);
|
|
180
181
|
}
|
|
181
182
|
return i;
|
|
182
183
|
}
|
|
183
|
-
function
|
|
184
|
+
function lt(e) {
|
|
184
185
|
const t = {};
|
|
185
186
|
let n = 2, i = !1;
|
|
186
|
-
for (const [r,
|
|
187
|
+
for (const [r, s] of Object.entries(e ?? {})) {
|
|
187
188
|
if (!r) continue;
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
190
|
-
const l = r.length + JSON.stringify(
|
|
189
|
+
const a = se(s, 0);
|
|
190
|
+
if (a === void 0) continue;
|
|
191
|
+
const l = r.length + JSON.stringify(a).length + 6;
|
|
191
192
|
if (n + l > ve) {
|
|
192
193
|
i = !0;
|
|
193
194
|
continue;
|
|
194
195
|
}
|
|
195
|
-
n += l, t[r] =
|
|
196
|
+
n += l, t[r] = a;
|
|
196
197
|
}
|
|
197
198
|
return i && console.warn(
|
|
198
199
|
`[arsel] event data exceeded ${ve} serialized bytes — oversized properties were dropped`
|
|
199
200
|
), t;
|
|
200
201
|
}
|
|
201
|
-
async function
|
|
202
|
-
const [i, r,
|
|
202
|
+
async function ut(e, t, n) {
|
|
203
|
+
const [i, r, s, a] = await Promise.all([
|
|
203
204
|
X(),
|
|
204
|
-
c(
|
|
205
|
-
c(
|
|
206
|
-
c(
|
|
205
|
+
c(o.externalId),
|
|
206
|
+
c(o.email),
|
|
207
|
+
c(o.phoneNumber)
|
|
207
208
|
]), l = {
|
|
208
|
-
event: e.slice(0,
|
|
209
|
+
event: e.slice(0, ot),
|
|
209
210
|
// Always sent, even once identified: it is what the backend merges FROM.
|
|
210
|
-
anonymous_id: i.slice(0,
|
|
211
|
-
data:
|
|
211
|
+
anonymous_id: i.slice(0, st),
|
|
212
|
+
data: lt(t),
|
|
212
213
|
timestamp: new Date(n).toISOString()
|
|
213
214
|
};
|
|
214
|
-
return r && (l.external_id = r.slice(0,
|
|
215
|
+
return r && (l.external_id = r.slice(0, at)), s && (l.email = s), a && (l.phone_number = a), JSON.stringify(l);
|
|
215
216
|
}
|
|
216
|
-
async function
|
|
217
|
-
await De(S.events, await
|
|
217
|
+
async function k(e, t, n = Date.now()) {
|
|
218
|
+
await De(S.events, await ut(e, t, n), crypto.randomUUID()), V().catch(() => {
|
|
218
219
|
});
|
|
219
220
|
}
|
|
220
221
|
let $ = null;
|
|
221
222
|
function V() {
|
|
222
|
-
return $ || ($ =
|
|
223
|
+
return $ || ($ = pt().finally(() => {
|
|
223
224
|
$ = null;
|
|
224
225
|
}), $);
|
|
225
226
|
}
|
|
226
|
-
function
|
|
227
|
+
function dt(e) {
|
|
227
228
|
const t = e[0].idempotencyKey;
|
|
228
229
|
return e.length === 1 ? t : `${t}:${e[e.length - 1].idempotencyKey}:${e.length}`;
|
|
229
230
|
}
|
|
230
|
-
function
|
|
231
|
+
function ft(e, t, n) {
|
|
231
232
|
e.some(
|
|
232
233
|
(r) => r.external_id || r.email || r.phone_number
|
|
233
234
|
) && console.error(
|
|
234
235
|
`[arsel] ${e.length} event(s) carrying identifiers were rejected permanently (HTTP ${t}) and dropped. Response: ${JSON.stringify(n)}`
|
|
235
236
|
);
|
|
236
237
|
}
|
|
237
|
-
async function
|
|
238
|
+
async function pt() {
|
|
238
239
|
const [e, t] = await Promise.all([
|
|
239
|
-
c(
|
|
240
|
-
c(
|
|
240
|
+
c(o.clientKey),
|
|
241
|
+
c(o.baseUrl)
|
|
241
242
|
]);
|
|
242
243
|
if (!(!e || !t))
|
|
243
244
|
for (; ; ) {
|
|
244
245
|
const n = await le(S.events);
|
|
245
246
|
if (n.length === 0) return;
|
|
246
|
-
for (let i = 0; i < n.length; i +=
|
|
247
|
-
const r = n.slice(i, i +
|
|
247
|
+
for (let i = 0; i < n.length; i += ge) {
|
|
248
|
+
const r = n.slice(i, i + ge), s = r.map(
|
|
248
249
|
(l) => JSON.parse(l.body)
|
|
249
|
-
),
|
|
250
|
+
), a = await z(
|
|
250
251
|
t,
|
|
251
252
|
Qe,
|
|
252
|
-
r.length === 1 ?
|
|
253
|
+
r.length === 1 ? s[0] : { events: s },
|
|
253
254
|
{
|
|
254
255
|
Authorization: `Bearer ${e}`,
|
|
255
|
-
"Idempotency-Key":
|
|
256
|
+
"Idempotency-Key": dt(r)
|
|
256
257
|
}
|
|
257
258
|
);
|
|
258
|
-
if (
|
|
259
|
-
|
|
259
|
+
if (a.result === y.retryable) return;
|
|
260
|
+
a.result !== y.success && ft(s, a.code, a.body);
|
|
260
261
|
for (const l of r)
|
|
261
262
|
l.id !== void 0 && await ue(S.events, l.id);
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
|
-
const ee = 1e3,
|
|
266
|
+
const ee = 1e3, mt = 720 * 60 * 60 * ee, yt = 500, Se = 50, bt = 86400, ht = 900, q = {
|
|
266
267
|
maxPerSession: 1,
|
|
267
268
|
maxLifetime: 3,
|
|
268
269
|
minSecondsBetween: 86400,
|
|
269
270
|
delaySeconds: 0
|
|
270
|
-
},
|
|
271
|
+
}, wt = [
|
|
271
272
|
"MODAL",
|
|
272
273
|
"BANNER_TOP",
|
|
273
274
|
"BANNER_BOTTOM",
|
|
274
275
|
"IMAGE_ONLY"
|
|
275
276
|
];
|
|
276
|
-
let fe = !1,
|
|
277
|
+
let fe = !1, d = null, h = {}, v = { startedAt: 0, counts: {} }, F = null, K = null, Be = !1, ie = null, _ = null, Ue = !1, Ae = !1;
|
|
277
278
|
function N(e) {
|
|
278
|
-
|
|
279
|
+
Ue && console.info(`[arsel] in-app: ${e}`);
|
|
279
280
|
}
|
|
280
281
|
async function gt(e) {
|
|
281
|
-
fe = !0,
|
|
282
|
+
fe = !0, Ue = e;
|
|
282
283
|
const [t, n, i] = await Promise.all([
|
|
283
|
-
c(
|
|
284
|
-
c(
|
|
285
|
-
c(
|
|
284
|
+
c(o.inAppBundle),
|
|
285
|
+
c(o.inAppState),
|
|
286
|
+
c(o.inAppSession)
|
|
286
287
|
]);
|
|
287
|
-
|
|
288
|
+
d = t, h = n ?? {}, v = i ?? { startedAt: 0, counts: {} }, await Ke(), await te();
|
|
288
289
|
}
|
|
289
|
-
function
|
|
290
|
+
function vt(e) {
|
|
290
291
|
_ = e;
|
|
291
292
|
}
|
|
292
|
-
function
|
|
293
|
-
|
|
293
|
+
function St(e) {
|
|
294
|
+
Be = e, e && ae();
|
|
294
295
|
}
|
|
295
|
-
function
|
|
296
|
+
function At() {
|
|
296
297
|
return {
|
|
297
|
-
messages: (
|
|
298
|
-
bundleVersion: (
|
|
299
|
-
fetchedAtMs: (
|
|
298
|
+
messages: (d == null ? void 0 : d.messages.length) ?? 0,
|
|
299
|
+
bundleVersion: (d == null ? void 0 : d.bundleVersion) ?? null,
|
|
300
|
+
fetchedAtMs: (d == null ? void 0 : d.fetchedAtMs) ?? null
|
|
300
301
|
};
|
|
301
302
|
}
|
|
302
|
-
function
|
|
303
|
+
function Et() {
|
|
303
304
|
return Oe(S.inAppBeacons);
|
|
304
305
|
}
|
|
305
306
|
async function Ce() {
|
|
306
|
-
|
|
307
|
+
d = null, await L(o.inAppBundle), fe && await te(!0);
|
|
307
308
|
}
|
|
308
|
-
function
|
|
309
|
+
function It() {
|
|
309
310
|
te(!0);
|
|
310
311
|
}
|
|
311
312
|
function te(e = !1) {
|
|
312
|
-
return ie ?? (ie =
|
|
313
|
+
return ie ?? (ie = _t(e).finally(() => {
|
|
313
314
|
ie = null;
|
|
314
315
|
})), ie;
|
|
315
316
|
}
|
|
316
|
-
async function
|
|
317
|
+
async function _t(e) {
|
|
317
318
|
if (!fe) return;
|
|
318
319
|
const t = Date.now();
|
|
319
|
-
if (!e &&
|
|
320
|
+
if (!e && d && t - d.fetchedAtMs < d.ttlSeconds * ee)
|
|
320
321
|
return;
|
|
321
322
|
const n = await $e();
|
|
322
323
|
if (!n) return;
|
|
323
|
-
const i =
|
|
324
|
+
const i = Nt(n.clientKey, n.installationId), r = {
|
|
324
325
|
"X-Arsel-Device-Auth": n.deviceSecret
|
|
325
|
-
},
|
|
326
|
-
|
|
327
|
-
let
|
|
328
|
-
if (
|
|
329
|
-
|
|
326
|
+
}, s = !!(d != null && d.bundleVersion);
|
|
327
|
+
s && (r["If-None-Match"] = `"${(d == null ? void 0 : d.bundleVersion) ?? ""}"`);
|
|
328
|
+
let a = await Ee(n.baseUrl, i, r);
|
|
329
|
+
if (a.code === Lt && s && Ae && (N("conditional request failed; retrying without If-None-Match"), delete r["If-None-Match"], a = await Ee(n.baseUrl, i, r)), a.code === Kt) {
|
|
330
|
+
d && (d = { ...d, fetchedAtMs: t }, await u(o.inAppBundle, d));
|
|
330
331
|
return;
|
|
331
332
|
}
|
|
332
|
-
if (
|
|
333
|
+
if (a.result !== y.success || !a.body)
|
|
333
334
|
return;
|
|
334
|
-
|
|
335
|
-
const l =
|
|
336
|
-
l && (
|
|
335
|
+
s || (Ae = !0);
|
|
336
|
+
const l = xt(a.body, t);
|
|
337
|
+
l && (d = l, await u(o.inAppBundle, d), await Ct(l, t));
|
|
337
338
|
}
|
|
338
339
|
function Ee(e, t, n) {
|
|
339
340
|
return de(e, t, n, !0, {
|
|
@@ -343,63 +344,63 @@ function Ee(e, t, n) {
|
|
|
343
344
|
cache: "no-store"
|
|
344
345
|
});
|
|
345
346
|
}
|
|
346
|
-
function
|
|
347
|
+
function Nt(e, t) {
|
|
347
348
|
const n = encodeURIComponent(e), i = encodeURIComponent(t);
|
|
348
349
|
return `/api/v1/orgs/${n}/in-app/bundle?installationId=${i}`;
|
|
349
350
|
}
|
|
350
351
|
async function $e() {
|
|
351
352
|
const [e, t, n, i] = await Promise.all([
|
|
352
|
-
c(
|
|
353
|
-
c(
|
|
354
|
-
c(
|
|
355
|
-
c(
|
|
353
|
+
c(o.clientKey),
|
|
354
|
+
c(o.baseUrl),
|
|
355
|
+
c(o.installationId),
|
|
356
|
+
c(o.deviceSecret)
|
|
356
357
|
]);
|
|
357
358
|
return !e || !t || !n || !i ? null : { clientKey: e, baseUrl: t, installationId: n, deviceSecret: i };
|
|
358
359
|
}
|
|
359
|
-
function
|
|
360
|
+
function xt(e, t) {
|
|
360
361
|
if (typeof (e == null ? void 0 : e.bundleVersion) != "string")
|
|
361
362
|
return N("response carried no bundleVersion"), null;
|
|
362
363
|
e.contractVersion !== void 0 && e.contractVersion !== 1 && N(`unknown contractVersion ${String(e.contractVersion)}; proceeding`);
|
|
363
364
|
const n = Array.isArray(e.messages) ? e.messages : [], i = [];
|
|
364
|
-
for (const
|
|
365
|
-
const
|
|
366
|
-
|
|
365
|
+
for (const s of n) {
|
|
366
|
+
const a = kt(s);
|
|
367
|
+
a && i.push(a);
|
|
367
368
|
}
|
|
368
369
|
n.length !== i.length && N(`dropped ${n.length - i.length} unrenderable message(s)`);
|
|
369
|
-
const r =
|
|
370
|
+
const r = O(e.ttlSeconds);
|
|
370
371
|
return {
|
|
371
372
|
bundleVersion: e.bundleVersion,
|
|
372
|
-
ttlSeconds: r && r > 0 ? r :
|
|
373
|
+
ttlSeconds: r && r > 0 ? r : ht,
|
|
373
374
|
fetchedAtMs: t,
|
|
374
375
|
messages: i
|
|
375
376
|
};
|
|
376
377
|
}
|
|
377
|
-
function
|
|
378
|
-
if (!
|
|
379
|
-
const t = m(e.campaignId), n = m(e.messageId), i = m(e.layout), r =
|
|
380
|
-
if (!t || !n || !i || !r || !
|
|
378
|
+
function kt(e) {
|
|
379
|
+
if (!D(e)) return null;
|
|
380
|
+
const t = m(e.campaignId), n = m(e.messageId), i = m(e.layout), r = D(e.content) ? e.content : null, s = r ? m(r.headline) : void 0;
|
|
381
|
+
if (!t || !n || !i || !r || !s)
|
|
381
382
|
return N("message missing a required field"), null;
|
|
382
|
-
if (!
|
|
383
|
+
if (!wt.includes(i))
|
|
383
384
|
return N(`layout ${i} is not renderable on web`), null;
|
|
384
|
-
const
|
|
385
|
+
const a = D(e.trigger) ? e.trigger : {}, l = D(e.displayRules) ? e.displayRules : {};
|
|
385
386
|
return {
|
|
386
387
|
campaignId: t,
|
|
387
388
|
messageId: n,
|
|
388
389
|
variantKey: m(e.variantKey) ?? "default",
|
|
389
|
-
priority:
|
|
390
|
-
expiresAtMs:
|
|
391
|
-
triggerType: m(
|
|
392
|
-
triggerEventName: m(
|
|
393
|
-
triggerProperties:
|
|
390
|
+
priority: O(e.priority) ?? 0,
|
|
391
|
+
expiresAtMs: $t(e.expiresAt),
|
|
392
|
+
triggerType: m(a.type) ?? "APP_OPEN",
|
|
393
|
+
triggerEventName: m(a.eventName) ?? null,
|
|
394
|
+
triggerProperties: D(a.properties) ? a.properties : null,
|
|
394
395
|
displayRules: {
|
|
395
|
-
maxPerSession:
|
|
396
|
-
maxLifetime:
|
|
397
|
-
minSecondsBetween:
|
|
398
|
-
delaySeconds:
|
|
396
|
+
maxPerSession: O(l.maxPerSession) ?? q.maxPerSession,
|
|
397
|
+
maxLifetime: O(l.maxLifetime) ?? q.maxLifetime,
|
|
398
|
+
minSecondsBetween: O(l.minSecondsBetween) ?? q.minSecondsBetween,
|
|
399
|
+
delaySeconds: O(l.delaySeconds) ?? q.delaySeconds
|
|
399
400
|
},
|
|
400
401
|
layout: i,
|
|
401
402
|
content: {
|
|
402
|
-
headline:
|
|
403
|
+
headline: s,
|
|
403
404
|
body: m(r.body) ?? "",
|
|
404
405
|
imageUrl: m(r.imageUrl),
|
|
405
406
|
backgroundColor: m(r.backgroundColor),
|
|
@@ -408,11 +409,11 @@ function xt(e) {
|
|
|
408
409
|
showCloseButton: r.showCloseButton !== !1
|
|
409
410
|
},
|
|
410
411
|
// `buttons` arrives as null, not [], when a campaign has none.
|
|
411
|
-
buttons: Array.isArray(e.buttons) ? e.buttons.map(
|
|
412
|
+
buttons: Array.isArray(e.buttons) ? e.buttons.map(Pt).filter((w) => w !== null) : []
|
|
412
413
|
};
|
|
413
414
|
}
|
|
414
|
-
function
|
|
415
|
-
if (!
|
|
415
|
+
function Pt(e) {
|
|
416
|
+
if (!D(e)) return null;
|
|
416
417
|
const t = m(e.buttonId), n = m(e.label), i = m(e.action);
|
|
417
418
|
return !t || !n || !i ? null : {
|
|
418
419
|
buttonId: t,
|
|
@@ -422,21 +423,21 @@ function kt(e) {
|
|
|
422
423
|
style: m(e.style) === "SECONDARY" ? "SECONDARY" : "PRIMARY"
|
|
423
424
|
};
|
|
424
425
|
}
|
|
425
|
-
function
|
|
426
|
-
if (
|
|
427
|
-
for (const r of
|
|
428
|
-
if (r.triggerType !== t || t !== "APP_OPEN" && r.triggerEventName !== n || !
|
|
429
|
-
const
|
|
426
|
+
function Tt(e, t, n, i) {
|
|
427
|
+
if (Be || F !== null || !d) return null;
|
|
428
|
+
for (const r of d.messages) {
|
|
429
|
+
if (r.triggerType !== t || t !== "APP_OPEN" && r.triggerEventName !== n || !Dt(r.triggerProperties, i)) continue;
|
|
430
|
+
const s = h[r.messageId];
|
|
430
431
|
if (r.expiresAtMs !== null && r.expiresAtMs <= e) {
|
|
431
432
|
Ut(r);
|
|
432
433
|
continue;
|
|
433
434
|
}
|
|
434
|
-
if (!(((
|
|
435
|
+
if (!(((s == null ? void 0 : s.shown) ?? 0) >= r.displayRules.maxLifetime) && !((v.counts[r.messageId] ?? 0) >= r.displayRules.maxPerSession) && !(s && e - s.lastShownAtMs < r.displayRules.minSecondsBetween * ee))
|
|
435
436
|
return r;
|
|
436
437
|
}
|
|
437
438
|
return null;
|
|
438
439
|
}
|
|
439
|
-
function
|
|
440
|
+
function Dt(e, t) {
|
|
440
441
|
if (!e) return !0;
|
|
441
442
|
const n = t;
|
|
442
443
|
for (const [i, r] of Object.entries(e))
|
|
@@ -445,37 +446,37 @@ function Tt(e, t) {
|
|
|
445
446
|
}
|
|
446
447
|
function pe(e, t, n = {}) {
|
|
447
448
|
try {
|
|
448
|
-
const i =
|
|
449
|
+
const i = Tt(Date.now(), e, t, n);
|
|
449
450
|
if (!i) return;
|
|
450
|
-
F = i.messageId,
|
|
451
|
+
F = i.messageId, Le = t;
|
|
451
452
|
const r = i.displayRules.delaySeconds * ee;
|
|
452
453
|
if (r <= 0) {
|
|
453
454
|
_ == null || _(i);
|
|
454
455
|
return;
|
|
455
456
|
}
|
|
456
|
-
|
|
457
|
-
|
|
457
|
+
K = setTimeout(() => {
|
|
458
|
+
K = null, _ == null || _(i);
|
|
458
459
|
}, r);
|
|
459
460
|
} catch (i) {
|
|
460
461
|
N(`observe failed: ${i instanceof Error ? i.message : "unknown"}`), F = null;
|
|
461
462
|
}
|
|
462
463
|
}
|
|
463
|
-
let
|
|
464
|
-
function
|
|
465
|
-
return
|
|
464
|
+
let Le = null;
|
|
465
|
+
function Ot() {
|
|
466
|
+
return Le;
|
|
466
467
|
}
|
|
467
468
|
function Ie() {
|
|
468
|
-
|
|
469
|
+
Ke().then(() => {
|
|
469
470
|
pe("APP_OPEN", null, {});
|
|
470
471
|
});
|
|
471
472
|
}
|
|
472
473
|
function ae() {
|
|
473
|
-
|
|
474
|
+
K !== null && (clearTimeout(K), K = null, F = null);
|
|
474
475
|
}
|
|
475
476
|
function _e() {
|
|
476
477
|
F = null;
|
|
477
478
|
}
|
|
478
|
-
async function
|
|
479
|
+
async function Rt(e, t) {
|
|
479
480
|
const n = Date.now(), i = h[e.messageId] ?? {
|
|
480
481
|
shown: 0,
|
|
481
482
|
lastShownAtMs: 0,
|
|
@@ -491,18 +492,18 @@ async function Ot(e, t) {
|
|
|
491
492
|
[e.messageId]: (v.counts[e.messageId] ?? 0) + 1
|
|
492
493
|
}
|
|
493
494
|
}, await Promise.all([
|
|
494
|
-
|
|
495
|
-
|
|
495
|
+
u(o.inAppState, h),
|
|
496
|
+
u(o.inAppSession, v)
|
|
496
497
|
]), await ne(e, "impression", { triggerEventName: t });
|
|
497
498
|
}
|
|
498
499
|
async function Mt(e, t) {
|
|
499
500
|
await ne(e, "clicked", { buttonId: t });
|
|
500
501
|
}
|
|
501
|
-
async function
|
|
502
|
+
async function Bt(e, t) {
|
|
502
503
|
await ne(e, "dismissed", {
|
|
503
504
|
visibleSeconds: Math.max(
|
|
504
505
|
0,
|
|
505
|
-
Math.min(
|
|
506
|
+
Math.min(bt, Math.round(t))
|
|
506
507
|
)
|
|
507
508
|
});
|
|
508
509
|
}
|
|
@@ -516,7 +517,7 @@ function Ut(e) {
|
|
|
516
517
|
lastSeenInBundleAtMs: (t == null ? void 0 : t.lastSeenInBundleAtMs) ?? Date.now(),
|
|
517
518
|
expiredReported: !0
|
|
518
519
|
}
|
|
519
|
-
},
|
|
520
|
+
}, u(o.inAppState, h), ne(e, "expired", {}));
|
|
520
521
|
}
|
|
521
522
|
async function ne(e, t, n) {
|
|
522
523
|
const i = {
|
|
@@ -528,9 +529,9 @@ async function ne(e, t, n) {
|
|
|
528
529
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
529
530
|
variantKey: e.variantKey
|
|
530
531
|
};
|
|
531
|
-
n.buttonId && (i.buttonId = n.buttonId), n.visibleSeconds !== void 0 && (i.visibleSeconds = n.visibleSeconds), n.triggerEventName && (i.triggerEventName = n.triggerEventName), await De(S.inAppBeacons, JSON.stringify(i)), await Ge(S.inAppBeacons,
|
|
532
|
+
n.buttonId && (i.buttonId = n.buttonId), n.visibleSeconds !== void 0 && (i.visibleSeconds = n.visibleSeconds), n.triggerEventName && (i.triggerEventName = n.triggerEventName), await De(S.inAppBeacons, JSON.stringify(i)), await Ge(S.inAppBeacons, yt), Y();
|
|
532
533
|
}
|
|
533
|
-
async function
|
|
534
|
+
async function Y() {
|
|
534
535
|
const e = await $e();
|
|
535
536
|
if (!e) return;
|
|
536
537
|
const t = await le(S.inAppBeacons);
|
|
@@ -538,146 +539,146 @@ async function q() {
|
|
|
538
539
|
const n = `/api/v1/orgs/${encodeURIComponent(e.clientKey)}/in-app/events`;
|
|
539
540
|
for (let i = 0; i < t.length; i += Se) {
|
|
540
541
|
const r = t.slice(i, i + Se);
|
|
541
|
-
if ((await
|
|
542
|
+
if ((await z(
|
|
542
543
|
e.baseUrl,
|
|
543
544
|
n,
|
|
544
545
|
{
|
|
545
546
|
installationId: e.installationId,
|
|
546
|
-
events: r.map((
|
|
547
|
+
events: r.map((a) => JSON.parse(a.body))
|
|
547
548
|
},
|
|
548
549
|
{ "X-Arsel-Device-Auth": e.deviceSecret },
|
|
549
550
|
!0
|
|
550
551
|
)).result === y.retryable) return;
|
|
551
|
-
for (const
|
|
552
|
-
|
|
552
|
+
for (const a of r)
|
|
553
|
+
a.id !== void 0 && await ue(S.inAppBeacons, a.id);
|
|
553
554
|
}
|
|
554
555
|
}
|
|
555
|
-
async function
|
|
556
|
+
async function Ct(e, t) {
|
|
556
557
|
const n = new Set(e.messages.map((r) => r.messageId)), i = {};
|
|
557
|
-
for (const [r,
|
|
558
|
-
const
|
|
559
|
-
t -
|
|
558
|
+
for (const [r, s] of Object.entries(h)) {
|
|
559
|
+
const a = n.has(r) ? t : s.lastSeenInBundleAtMs;
|
|
560
|
+
t - a > mt || (i[r] = { ...s, lastSeenInBundleAtMs: a });
|
|
560
561
|
}
|
|
561
|
-
h = i, await
|
|
562
|
+
h = i, await u(o.inAppState, h);
|
|
562
563
|
}
|
|
563
|
-
async function
|
|
564
|
-
const e = await c(
|
|
565
|
-
v.startedAt !== e && (v = { startedAt: e, counts: {} }, await
|
|
564
|
+
async function Ke() {
|
|
565
|
+
const e = await c(o.sessionStartedAt) ?? 0;
|
|
566
|
+
v.startedAt !== e && (v = { startedAt: e, counts: {} }, await u(o.inAppSession, v));
|
|
566
567
|
}
|
|
567
|
-
function
|
|
568
|
+
function D(e) {
|
|
568
569
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
569
570
|
}
|
|
570
571
|
function m(e) {
|
|
571
572
|
return typeof e == "string" && e.length > 0 ? e : void 0;
|
|
572
573
|
}
|
|
573
|
-
function
|
|
574
|
+
function O(e) {
|
|
574
575
|
return typeof e == "number" && Number.isFinite(e) ? e : void 0;
|
|
575
576
|
}
|
|
576
|
-
function
|
|
577
|
+
function $t(e) {
|
|
577
578
|
if (typeof e != "string") return null;
|
|
578
579
|
const t = Date.parse(e);
|
|
579
580
|
return Number.isNaN(t) ? null : t;
|
|
580
581
|
}
|
|
581
|
-
const
|
|
582
|
-
let xe = null,
|
|
583
|
-
function
|
|
584
|
-
const i = e.layout === "MODAL", r = Date.now(),
|
|
585
|
-
|
|
586
|
-
const l =
|
|
587
|
-
|
|
588
|
-
const
|
|
589
|
-
f.className = "panel", f.tabIndex = -1, i ? (f.setAttribute("role", "dialog"), f.setAttribute("aria-modal", "true"), f.setAttribute("aria-labelledby", `${
|
|
590
|
-
const A =
|
|
582
|
+
const Lt = -1, Kt = 304, Vt = 2147483e3, re = 44, Ne = /^#[0-9a-fA-F]{3,8}$/, Ft = 0.6;
|
|
583
|
+
let xe = null, Wt = 0;
|
|
584
|
+
function Xt(e, t, n) {
|
|
585
|
+
const i = e.layout === "MODAL", r = Date.now(), s = `arsel-iam-${Wt += 1}`, a = document.createElement("div");
|
|
586
|
+
a.setAttribute("data-arsel-inapp", "");
|
|
587
|
+
const l = a.attachShadow({ mode: "closed" });
|
|
588
|
+
tn(l), a.style.setProperty("z-index", String(t.zIndex || Vt)), a.style.setProperty("isolation", "isolate"), a.setAttribute("data-layout", e.layout), a.setAttribute("dir", Zt());
|
|
589
|
+
const w = document.activeElement instanceof HTMLElement ? document.activeElement : null, f = document.createElement("div");
|
|
590
|
+
f.className = "panel", f.tabIndex = -1, i ? (f.setAttribute("role", "dialog"), f.setAttribute("aria-modal", "true"), f.setAttribute("aria-labelledby", `${s}-h`), e.content.body && f.setAttribute("aria-describedby", `${s}-b`)) : (f.setAttribute("role", "status"), f.setAttribute("aria-live", "polite"));
|
|
591
|
+
const A = Qt(e);
|
|
591
592
|
A.background && f.style.setProperty("background", A.background), A.text && f.style.setProperty("color", A.text);
|
|
592
593
|
let C = !1;
|
|
593
594
|
const E = (p) => {
|
|
594
|
-
var
|
|
595
|
-
C || (C = !0, document.removeEventListener("keydown",
|
|
596
|
-
},
|
|
595
|
+
var g, we;
|
|
596
|
+
C || (C = !0, document.removeEventListener("keydown", T, !0), a.remove(), w != null && w.isConnected ? w.focus() : i && ((we = (g = document.body).focus) == null || we.call(g)), p === "dismiss" && n.onDismiss((Date.now() - r) / 1e3));
|
|
597
|
+
}, T = (p) => {
|
|
597
598
|
p.key === "Escape" && (p.stopPropagation(), E("dismiss"));
|
|
598
599
|
};
|
|
599
600
|
if (e.layout === "IMAGE_ONLY" && e.content.imageUrl)
|
|
600
|
-
f.append(
|
|
601
|
+
f.append(zt(e, () => qe(e)));
|
|
601
602
|
else {
|
|
602
|
-
e.content.imageUrl && f.append(
|
|
603
|
+
e.content.imageUrl && f.append(jt(e.content.imageUrl, e.content.headline));
|
|
603
604
|
const p = document.createElement("h2");
|
|
604
|
-
if (p.id = `${
|
|
605
|
-
const
|
|
606
|
-
|
|
605
|
+
if (p.id = `${s}-h`, p.className = "headline", p.textContent = e.content.headline, f.append(p), e.content.body) {
|
|
606
|
+
const g = document.createElement("p");
|
|
607
|
+
g.id = `${s}-b`, g.className = "body", g.textContent = e.content.body, f.append(g);
|
|
607
608
|
}
|
|
608
609
|
}
|
|
609
|
-
if (e.buttons.length > 0 && f.append(
|
|
610
|
+
if (e.buttons.length > 0 && f.append(Ht(e, n, E)), (e.content.showCloseButton || !e.buttons.some((p) => p.action === "DISMISS")) && f.append(Jt(t.closeLabel, () => E("dismiss"))), i) {
|
|
610
611
|
const p = document.createElement("div");
|
|
611
612
|
p.className = "backdrop", e.content.showCloseButton && p.addEventListener("click", () => E("dismiss")), l.append(p);
|
|
612
613
|
}
|
|
613
|
-
l.append(f), document.body.append(
|
|
614
|
-
p instanceof KeyboardEvent &&
|
|
614
|
+
l.append(f), document.body.append(a), i ? (f.focus({ preventScroll: !0 }), l.addEventListener("keydown", (p) => {
|
|
615
|
+
p instanceof KeyboardEvent && Gt(p, l);
|
|
615
616
|
})) : (f.textContent, f.setAttribute("aria-busy", "true"), requestAnimationFrame(() => {
|
|
616
617
|
f.removeAttribute("aria-busy");
|
|
617
|
-
})), document.addEventListener("keydown",
|
|
618
|
-
C || !
|
|
618
|
+
})), document.addEventListener("keydown", T, !0), requestAnimationFrame(() => {
|
|
619
|
+
C || !a.isConnected || document.visibilityState === "visible" && n.onImpression();
|
|
619
620
|
});
|
|
620
621
|
function qe(p) {
|
|
621
|
-
const
|
|
622
|
-
if (!
|
|
622
|
+
const g = p.buttons[0];
|
|
623
|
+
if (!g) {
|
|
623
624
|
E("dismiss");
|
|
624
625
|
return;
|
|
625
626
|
}
|
|
626
|
-
n.onButton(
|
|
627
|
+
n.onButton(g), E("button");
|
|
627
628
|
}
|
|
628
629
|
return { close: E, root: l };
|
|
629
630
|
}
|
|
630
|
-
function
|
|
631
|
+
function jt(e, t) {
|
|
631
632
|
const n = document.createElement("figure");
|
|
632
633
|
n.className = "figure";
|
|
633
634
|
const i = document.createElement("img");
|
|
634
635
|
return i.src = e, i.alt = t, i.loading = "eager", i.decoding = "async", i.referrerPolicy = "no-referrer", i.addEventListener("error", () => n.remove()), n.append(i), n;
|
|
635
636
|
}
|
|
636
|
-
function
|
|
637
|
+
function zt(e, t) {
|
|
637
638
|
const n = document.createElement("button");
|
|
638
639
|
n.type = "button", n.className = "image-only";
|
|
639
640
|
const i = document.createElement("img");
|
|
640
641
|
return i.src = e.content.imageUrl ?? "", i.alt = e.content.headline, i.loading = "eager", i.decoding = "async", i.referrerPolicy = "no-referrer", n.append(i), n.addEventListener("click", t), n;
|
|
641
642
|
}
|
|
642
|
-
function
|
|
643
|
+
function Ht(e, t, n) {
|
|
643
644
|
const i = document.createElement("div");
|
|
644
645
|
i.className = "buttons";
|
|
645
646
|
for (const r of e.buttons) {
|
|
646
|
-
const
|
|
647
|
-
|
|
647
|
+
const s = r.action === "URL" && r.value ? qt(r) : Yt(r);
|
|
648
|
+
s.addEventListener("click", () => {
|
|
648
649
|
r.action !== "DISMISS" && t.onButton(r), n(r.action === "DISMISS" ? "dismiss" : "button"), r.action === "DEEP_LINK" && r.value && location.assign(r.value);
|
|
649
|
-
}), i.append(
|
|
650
|
+
}), i.append(s);
|
|
650
651
|
}
|
|
651
652
|
return i;
|
|
652
653
|
}
|
|
653
|
-
function
|
|
654
|
+
function qt(e) {
|
|
654
655
|
const t = document.createElement("a");
|
|
655
656
|
return t.href = e.value ?? "#", t.target = "_blank", t.rel = "noopener noreferrer", t.className = `cta ${e.style.toLowerCase()}`, t.textContent = e.label, t;
|
|
656
657
|
}
|
|
657
|
-
function
|
|
658
|
+
function Yt(e) {
|
|
658
659
|
const t = document.createElement("button");
|
|
659
660
|
return t.type = "button", t.className = `cta ${e.style.toLowerCase()}`, t.textContent = e.label, t;
|
|
660
661
|
}
|
|
661
|
-
function
|
|
662
|
+
function Jt(e, t) {
|
|
662
663
|
const n = document.createElement("button");
|
|
663
664
|
return n.type = "button", n.className = "close", n.setAttribute("aria-label", e), n.textContent = "×", n.addEventListener("click", t), n;
|
|
664
665
|
}
|
|
665
|
-
function
|
|
666
|
+
function Gt(e, t) {
|
|
666
667
|
if (e.key !== "Tab") return;
|
|
667
668
|
const n = [
|
|
668
669
|
...t.querySelectorAll("button, a[href]")
|
|
669
|
-
].filter((
|
|
670
|
+
].filter((a) => !a.hasAttribute("disabled"));
|
|
670
671
|
if (n.length === 0) return;
|
|
671
672
|
const i = n[0], r = n[n.length - 1];
|
|
672
673
|
if (!i || !r) return;
|
|
673
|
-
const
|
|
674
|
-
if (e.shiftKey &&
|
|
674
|
+
const s = t.activeElement;
|
|
675
|
+
if (e.shiftKey && s === i) {
|
|
675
676
|
e.preventDefault(), r.focus();
|
|
676
677
|
return;
|
|
677
678
|
}
|
|
678
|
-
!e.shiftKey &&
|
|
679
|
+
!e.shiftKey && s === r && (e.preventDefault(), i.focus());
|
|
679
680
|
}
|
|
680
|
-
function
|
|
681
|
+
function Zt() {
|
|
681
682
|
const e = document.documentElement.getAttribute("dir");
|
|
682
683
|
if (e) return e;
|
|
683
684
|
try {
|
|
@@ -686,25 +687,25 @@ function Gt() {
|
|
|
686
687
|
return "ltr";
|
|
687
688
|
}
|
|
688
689
|
}
|
|
689
|
-
function Zt(e) {
|
|
690
|
-
const t = Ne.test(e.content.backgroundColor ?? "") ? e.content.backgroundColor : void 0, n = Ne.test(e.content.textColor ?? "") ? e.content.textColor : void 0;
|
|
691
|
-
return t && !n ? { background: t, text: Qt(t) > Vt ? "#101010" : "#FFFFFF" } : { background: t, text: n };
|
|
692
|
-
}
|
|
693
690
|
function Qt(e) {
|
|
694
|
-
const t =
|
|
695
|
-
return
|
|
691
|
+
const t = Ne.test(e.content.backgroundColor ?? "") ? e.content.backgroundColor : void 0, n = Ne.test(e.content.textColor ?? "") ? e.content.textColor : void 0;
|
|
692
|
+
return t && !n ? { background: t, text: en(t) > Ft ? "#101010" : "#FFFFFF" } : { background: t, text: n };
|
|
696
693
|
}
|
|
697
694
|
function en(e) {
|
|
695
|
+
const t = e.slice(1), n = t.length === 3 ? t.split("").map((a) => a + a).join("") : t.slice(0, 6), i = parseInt(n.slice(0, 2), 16) / 255, r = parseInt(n.slice(2, 4), 16) / 255, s = parseInt(n.slice(4, 6), 16) / 255;
|
|
696
|
+
return 0.2126 * i + 0.7152 * r + 0.0722 * s;
|
|
697
|
+
}
|
|
698
|
+
function tn(e) {
|
|
698
699
|
if ("adoptedStyleSheets" in Document.prototype && typeof CSSStyleSheet == "function")
|
|
699
700
|
try {
|
|
700
|
-
xe ?? (xe =
|
|
701
|
+
xe ?? (xe = nn()), e.adoptedStyleSheets = [xe];
|
|
701
702
|
return;
|
|
702
703
|
} catch {
|
|
703
704
|
}
|
|
704
705
|
const t = document.createElement("style");
|
|
705
706
|
t.textContent = Ve, e.append(t);
|
|
706
707
|
}
|
|
707
|
-
function
|
|
708
|
+
function nn() {
|
|
708
709
|
const e = new CSSStyleSheet();
|
|
709
710
|
return e.replaceSync(Ve), e;
|
|
710
711
|
}
|
|
@@ -814,13 +815,27 @@ const Ve = `
|
|
|
814
815
|
@media (prefers-reduced-motion: reduce) {
|
|
815
816
|
.panel { animation: none; transition: none; }
|
|
816
817
|
}
|
|
817
|
-
|
|
818
|
-
function
|
|
818
|
+
`;
|
|
819
|
+
async function rn(e) {
|
|
820
|
+
await c(o.installReported) || (await u(o.installReported, !0), !e && await k(it, {
|
|
821
|
+
sdk_version: j,
|
|
822
|
+
platform: "web"
|
|
823
|
+
}));
|
|
824
|
+
}
|
|
825
|
+
async function on() {
|
|
826
|
+
const [e, t] = await Promise.all([
|
|
827
|
+
c(o.anonymousId),
|
|
828
|
+
c(o.installationId)
|
|
829
|
+
]);
|
|
830
|
+
return !!e || !!t;
|
|
831
|
+
}
|
|
832
|
+
const me = "REVOKED";
|
|
833
|
+
function sn(e) {
|
|
819
834
|
const t = e.replace(/-/g, "+").replace(/_/g, "/"), n = atob(t + "=".repeat((4 - t.length % 4) % 4)), i = new Uint8Array(n.length);
|
|
820
835
|
for (let r = 0; r < n.length; r += 1) i[r] = n.charCodeAt(r);
|
|
821
836
|
return i.buffer;
|
|
822
837
|
}
|
|
823
|
-
function
|
|
838
|
+
function B() {
|
|
824
839
|
return typeof navigator < "u" && "serviceWorker" in navigator && typeof PushManager < "u" && typeof Notification < "u";
|
|
825
840
|
}
|
|
826
841
|
function Fe(e) {
|
|
@@ -830,21 +845,21 @@ function ye(e) {
|
|
|
830
845
|
return `/api/v1/orgs/${e}/push/subscriptions`;
|
|
831
846
|
}
|
|
832
847
|
const We = 1e4;
|
|
833
|
-
let
|
|
834
|
-
function
|
|
835
|
-
|
|
848
|
+
let M = "none", W = null, Z = null;
|
|
849
|
+
function an() {
|
|
850
|
+
M = "external";
|
|
836
851
|
}
|
|
837
|
-
async function
|
|
838
|
-
if (
|
|
839
|
-
|
|
852
|
+
async function cn(e) {
|
|
853
|
+
if (B()) {
|
|
854
|
+
M = "managed";
|
|
840
855
|
try {
|
|
841
|
-
W = await navigator.serviceWorker.register(e),
|
|
856
|
+
W = await navigator.serviceWorker.register(e), Z = null;
|
|
842
857
|
} catch (t) {
|
|
843
|
-
W = null,
|
|
858
|
+
W = null, Z = `service worker registration failed for '${e}': ${String(t)}. Check that the file is deployed and served with a JavaScript content type.`;
|
|
844
859
|
}
|
|
845
860
|
}
|
|
846
861
|
}
|
|
847
|
-
function
|
|
862
|
+
function ln(e, t) {
|
|
848
863
|
return e.active ? Promise.resolve(e) : new Promise((n, i) => {
|
|
849
864
|
const r = setTimeout(() => {
|
|
850
865
|
i(
|
|
@@ -852,7 +867,7 @@ function sn(e, t) {
|
|
|
852
867
|
`service worker did not activate within ${t}ms — check the worker script for load errors in DevTools → Application → Service Workers`
|
|
853
868
|
)
|
|
854
869
|
);
|
|
855
|
-
}, t),
|
|
870
|
+
}, t), s = (l) => {
|
|
856
871
|
l.addEventListener("statechange", () => {
|
|
857
872
|
l.state === "activated" ? (clearTimeout(r), n(e)) : l.state === "redundant" && (clearTimeout(r), i(
|
|
858
873
|
new Error(
|
|
@@ -860,13 +875,13 @@ function sn(e, t) {
|
|
|
860
875
|
)
|
|
861
876
|
));
|
|
862
877
|
});
|
|
863
|
-
},
|
|
864
|
-
|
|
865
|
-
e.installing &&
|
|
878
|
+
}, a = e.installing ?? e.waiting;
|
|
879
|
+
a ? s(a) : e.addEventListener("updatefound", () => {
|
|
880
|
+
e.installing && s(e.installing);
|
|
866
881
|
});
|
|
867
882
|
});
|
|
868
883
|
}
|
|
869
|
-
function
|
|
884
|
+
function un(e, t, n) {
|
|
870
885
|
return Promise.race([
|
|
871
886
|
e,
|
|
872
887
|
new Promise((i, r) => {
|
|
@@ -875,22 +890,22 @@ function an(e, t, n) {
|
|
|
875
890
|
]);
|
|
876
891
|
}
|
|
877
892
|
async function be(e = We) {
|
|
878
|
-
if (
|
|
893
|
+
if (M === "none")
|
|
879
894
|
throw new Error(
|
|
880
895
|
"push is not configured — pass serviceWorkerPath to init(), or serviceWorker: 'external' if your own service worker imports arsel-sw.js"
|
|
881
896
|
);
|
|
882
|
-
if (
|
|
883
|
-
return
|
|
897
|
+
if (M === "external")
|
|
898
|
+
return un(
|
|
884
899
|
navigator.serviceWorker.ready,
|
|
885
900
|
e,
|
|
886
901
|
`no service worker became active within ${e}ms — with serviceWorker: 'external', your own worker must be registered and must importScripts arsel-sw.js`
|
|
887
902
|
);
|
|
888
|
-
if (
|
|
903
|
+
if (Z) throw new Error(Z);
|
|
889
904
|
if (!W)
|
|
890
905
|
throw new Error("service worker registration has not completed");
|
|
891
|
-
return
|
|
906
|
+
return ln(W, e);
|
|
892
907
|
}
|
|
893
|
-
async function
|
|
908
|
+
async function dn(e = We) {
|
|
894
909
|
try {
|
|
895
910
|
return await be(e), null;
|
|
896
911
|
} catch (t) {
|
|
@@ -903,7 +918,7 @@ async function Xe(e, t) {
|
|
|
903
918
|
// Non-negotiable: the Push API only accepts a userVisibleOnly subscription
|
|
904
919
|
// in Chrome, and silent push is what the restriction exists to prevent.
|
|
905
920
|
userVisibleOnly: !0,
|
|
906
|
-
applicationServerKey:
|
|
921
|
+
applicationServerKey: sn(t)
|
|
907
922
|
});
|
|
908
923
|
} catch (n) {
|
|
909
924
|
return console.error(
|
|
@@ -911,12 +926,12 @@ async function Xe(e, t) {
|
|
|
911
926
|
), null;
|
|
912
927
|
}
|
|
913
928
|
}
|
|
914
|
-
async function
|
|
929
|
+
async function fn() {
|
|
915
930
|
const [e, t] = await Promise.all([
|
|
916
|
-
c(
|
|
917
|
-
c(
|
|
931
|
+
c(o.clientKey),
|
|
932
|
+
c(o.baseUrl)
|
|
918
933
|
]);
|
|
919
|
-
if (!e || !t || !
|
|
934
|
+
if (!e || !t || !B()) return !1;
|
|
920
935
|
const { body: n } = await de(
|
|
921
936
|
t,
|
|
922
937
|
Fe(e)
|
|
@@ -925,8 +940,8 @@ async function ln() {
|
|
|
925
940
|
let i;
|
|
926
941
|
try {
|
|
927
942
|
i = await be();
|
|
928
|
-
} catch (
|
|
929
|
-
return console.error(`[arsel] ${
|
|
943
|
+
} catch (s) {
|
|
944
|
+
return console.error(`[arsel] ${s instanceof Error ? s.message : s}`), !1;
|
|
930
945
|
}
|
|
931
946
|
const r = await Xe(i, n.vapidPublicKey);
|
|
932
947
|
return r ? je(r, n.keyVersion) : !1;
|
|
@@ -934,21 +949,21 @@ async function ln() {
|
|
|
934
949
|
async function je(e, t) {
|
|
935
950
|
var f, A;
|
|
936
951
|
const [n, i, r] = await Promise.all([
|
|
937
|
-
c(
|
|
938
|
-
c(
|
|
952
|
+
c(o.clientKey),
|
|
953
|
+
c(o.baseUrl),
|
|
939
954
|
X()
|
|
940
955
|
]);
|
|
941
956
|
if (!n || !i) return !1;
|
|
942
|
-
let
|
|
943
|
-
|
|
944
|
-
const
|
|
957
|
+
let s = await c(o.installationId);
|
|
958
|
+
s || (s = crypto.randomUUID(), await u(o.installationId, s));
|
|
959
|
+
const a = e.toJSON(), l = await z(
|
|
945
960
|
i,
|
|
946
961
|
ye(n),
|
|
947
962
|
{
|
|
948
|
-
installationId:
|
|
963
|
+
installationId: s,
|
|
949
964
|
platform: "web",
|
|
950
|
-
endpoint:
|
|
951
|
-
keys:
|
|
965
|
+
endpoint: a.endpoint,
|
|
966
|
+
keys: a.keys,
|
|
952
967
|
// The same id the events API sends — it is what binds this subscription
|
|
953
968
|
// to the contact the browser's events resolve to.
|
|
954
969
|
anonymousId: r,
|
|
@@ -958,30 +973,30 @@ async function je(e, t) {
|
|
|
958
973
|
}
|
|
959
974
|
);
|
|
960
975
|
if (l.result !== y.success) return !1;
|
|
961
|
-
(f = l.body) != null && f.deviceSecret && await
|
|
962
|
-
const
|
|
963
|
-
return await
|
|
976
|
+
(f = l.body) != null && f.deviceSecret && await u(o.deviceSecret, l.body.deviceSecret), await u(o.vapidKeyVersion, t), await u(o.endpoint, a.endpoint ?? null);
|
|
977
|
+
const w = ((A = l.body) == null ? void 0 : A.status) ?? null;
|
|
978
|
+
return await u(o.subscriptionStatus, w), w !== me;
|
|
964
979
|
}
|
|
965
|
-
async function
|
|
980
|
+
async function pn() {
|
|
966
981
|
const [e, t, n, i] = await Promise.all([
|
|
967
|
-
c(
|
|
968
|
-
c(
|
|
969
|
-
c(
|
|
970
|
-
c(
|
|
982
|
+
c(o.clientKey),
|
|
983
|
+
c(o.baseUrl),
|
|
984
|
+
c(o.installationId),
|
|
985
|
+
c(o.deviceSecret)
|
|
971
986
|
]);
|
|
972
|
-
return !e || !t || !n || !i || (await
|
|
987
|
+
return !e || !t || !n || !i || (await z(
|
|
973
988
|
t,
|
|
974
989
|
`${ye(e)}/unsubscribe`,
|
|
975
990
|
{ installationId: n },
|
|
976
991
|
{ "X-Arsel-Device-Auth": i },
|
|
977
992
|
!0
|
|
978
|
-
)).result !== y.success ? !1 : (await
|
|
993
|
+
)).result !== y.success ? !1 : (await u(o.subscriptionStatus, me), !0);
|
|
979
994
|
}
|
|
980
|
-
async function
|
|
981
|
-
if (
|
|
995
|
+
async function mn() {
|
|
996
|
+
if (M === "none" || !B() || Notification.permission !== "granted") return;
|
|
982
997
|
const [e, t] = await Promise.all([
|
|
983
|
-
c(
|
|
984
|
-
c(
|
|
998
|
+
c(o.clientKey),
|
|
999
|
+
c(o.baseUrl)
|
|
985
1000
|
]);
|
|
986
1001
|
if (!e || !t) return;
|
|
987
1002
|
const { body: n } = await de(
|
|
@@ -995,40 +1010,40 @@ async function dn() {
|
|
|
995
1010
|
} catch {
|
|
996
1011
|
return;
|
|
997
1012
|
}
|
|
998
|
-
const r = await i.pushManager.getSubscription(),
|
|
999
|
-
if (r &&
|
|
1013
|
+
const r = await i.pushManager.getSubscription(), s = await c(o.vapidKeyVersion);
|
|
1014
|
+
if (r && s === n.keyVersion) return;
|
|
1000
1015
|
r && await r.unsubscribe().catch(() => !1);
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1016
|
+
const a = await Xe(i, n.vapidPublicKey);
|
|
1017
|
+
a && await je(a, n.keyVersion);
|
|
1003
1018
|
}
|
|
1004
|
-
async function
|
|
1005
|
-
if (!
|
|
1019
|
+
async function yn() {
|
|
1020
|
+
if (!B() || await c(o.subscriptionStatus) === me)
|
|
1006
1021
|
return !1;
|
|
1007
1022
|
try {
|
|
1008
|
-
const e =
|
|
1023
|
+
const e = M === "managed" ? W : await navigator.serviceWorker.getRegistration();
|
|
1009
1024
|
return e ? await e.pushManager.getSubscription() !== null : !1;
|
|
1010
1025
|
} catch {
|
|
1011
1026
|
return !1;
|
|
1012
1027
|
}
|
|
1013
1028
|
}
|
|
1014
|
-
function
|
|
1015
|
-
return oe ?? (oe =
|
|
1029
|
+
function bn() {
|
|
1030
|
+
return oe ?? (oe = hn().finally(() => {
|
|
1016
1031
|
oe = null;
|
|
1017
1032
|
})), oe;
|
|
1018
1033
|
}
|
|
1019
1034
|
let oe = null;
|
|
1020
|
-
async function
|
|
1021
|
-
var
|
|
1035
|
+
async function hn() {
|
|
1036
|
+
var s;
|
|
1022
1037
|
const [e, t, n] = await Promise.all([
|
|
1023
|
-
c(
|
|
1024
|
-
c(
|
|
1038
|
+
c(o.clientKey),
|
|
1039
|
+
c(o.baseUrl),
|
|
1025
1040
|
X()
|
|
1026
1041
|
]);
|
|
1027
1042
|
if (!e || !t) return !1;
|
|
1028
|
-
if (await c(
|
|
1029
|
-
let i = await c(
|
|
1030
|
-
i || (i = crypto.randomUUID(), await
|
|
1031
|
-
const r = await
|
|
1043
|
+
if (await c(o.deviceSecret)) return !0;
|
|
1044
|
+
let i = await c(o.installationId);
|
|
1045
|
+
i || (i = crypto.randomUUID(), await u(o.installationId, i));
|
|
1046
|
+
const r = await z(
|
|
1032
1047
|
t,
|
|
1033
1048
|
ye(e),
|
|
1034
1049
|
{
|
|
@@ -1044,45 +1059,45 @@ async function mn() {
|
|
|
1044
1059
|
);
|
|
1045
1060
|
return r.code === 403 ? (console.error(
|
|
1046
1061
|
"[arsel] this origin is not on the organization's allowed origins list — in-app messaging is disabled"
|
|
1047
|
-
), !1) : r.result !== y.success ? !1 : ((
|
|
1062
|
+
), !1) : r.result !== y.success ? !1 : ((s = r.body) != null && s.deviceSecret && await u(o.deviceSecret, r.body.deviceSecret), !0);
|
|
1048
1063
|
}
|
|
1049
|
-
const
|
|
1064
|
+
const wn = 30 * 6e4;
|
|
1050
1065
|
async function ze(e = Date.now()) {
|
|
1051
|
-
const t = await c(
|
|
1066
|
+
const t = await c(o.sessionStartedAt) ?? 0, n = await c(o.backgroundedAt) ?? 0;
|
|
1052
1067
|
if (t !== 0) {
|
|
1053
|
-
if (n === 0 || e - n <
|
|
1054
|
-
await
|
|
1068
|
+
if (n === 0 || e - n < wn) return;
|
|
1069
|
+
await k(
|
|
1055
1070
|
tt,
|
|
1056
1071
|
{ duration_seconds: Math.round((n - t) / 1e3) },
|
|
1057
1072
|
n
|
|
1058
1073
|
);
|
|
1059
1074
|
}
|
|
1060
|
-
await
|
|
1075
|
+
await u(o.sessionStartedAt, e), await u(o.backgroundedAt, 0), await k(et, {}, e);
|
|
1061
1076
|
}
|
|
1062
1077
|
async function ke(e = Date.now()) {
|
|
1063
|
-
(await c(
|
|
1078
|
+
(await c(o.sessionStartedAt) ?? 0) !== 0 && await u(o.backgroundedAt, e);
|
|
1064
1079
|
}
|
|
1065
|
-
function
|
|
1080
|
+
function gn(e) {
|
|
1066
1081
|
typeof document > "u" || (document.addEventListener("visibilitychange", () => {
|
|
1067
1082
|
document.visibilityState === "visible" ? ze().then(() => e == null ? void 0 : e()) : ke();
|
|
1068
1083
|
}), window.addEventListener("pagehide", () => void ke()));
|
|
1069
1084
|
}
|
|
1070
|
-
let b = null, ce = !1,
|
|
1085
|
+
let b = null, ce = !1, R = null;
|
|
1071
1086
|
function I(e) {
|
|
1072
1087
|
ce && console.info(`[arsel] ${e}`);
|
|
1073
1088
|
}
|
|
1074
|
-
const
|
|
1075
|
-
let
|
|
1076
|
-
function
|
|
1089
|
+
const vn = /^\+[1-9]\d{6,14}$/, Sn = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, Pe = 100;
|
|
1090
|
+
let Q = [], Te = !1;
|
|
1091
|
+
function An() {
|
|
1077
1092
|
typeof navigator < "u" && navigator.serviceWorker && navigator.serviceWorker.addEventListener("message", (e) => {
|
|
1078
1093
|
const t = e.data;
|
|
1079
|
-
(t == null ? void 0 : t.type) === "arsel_iam_sync" &&
|
|
1094
|
+
(t == null ? void 0 : t.type) === "arsel_iam_sync" && It();
|
|
1080
1095
|
}), typeof window < "u" && (window.addEventListener("online", () => {
|
|
1081
1096
|
V().catch(() => {
|
|
1082
|
-
}),
|
|
1097
|
+
}), Y().catch(() => {
|
|
1083
1098
|
});
|
|
1084
1099
|
}), window.addEventListener("pagehide", () => {
|
|
1085
|
-
ae(),
|
|
1100
|
+
ae(), Y().catch(() => {
|
|
1086
1101
|
});
|
|
1087
1102
|
})), typeof document < "u" && document.addEventListener("visibilitychange", () => {
|
|
1088
1103
|
if (document.visibilityState === "visible") {
|
|
@@ -1091,14 +1106,14 @@ function wn() {
|
|
|
1091
1106
|
});
|
|
1092
1107
|
return;
|
|
1093
1108
|
}
|
|
1094
|
-
ae(),
|
|
1109
|
+
ae(), Y().catch(() => {
|
|
1095
1110
|
});
|
|
1096
1111
|
});
|
|
1097
1112
|
}
|
|
1098
|
-
function
|
|
1099
|
-
return
|
|
1113
|
+
function U() {
|
|
1114
|
+
return R === null;
|
|
1100
1115
|
}
|
|
1101
|
-
function
|
|
1116
|
+
function En(e) {
|
|
1102
1117
|
var n, i;
|
|
1103
1118
|
if (!((n = e.clientKey) != null && n.trim()))
|
|
1104
1119
|
return "clientKey is required (the org's publishable pub_… key)";
|
|
@@ -1116,28 +1131,30 @@ function vn(e) {
|
|
|
1116
1131
|
}
|
|
1117
1132
|
return null;
|
|
1118
1133
|
}
|
|
1119
|
-
function
|
|
1134
|
+
function In(e) {
|
|
1120
1135
|
return b || (b = (async () => {
|
|
1121
|
-
if (ce = e.debug ?? !1,
|
|
1122
|
-
console.error(`[arsel] not started — ${
|
|
1136
|
+
if (ce = e.debug ?? !1, R = En(e), R) {
|
|
1137
|
+
console.error(`[arsel] not started — ${R}`);
|
|
1123
1138
|
return;
|
|
1124
1139
|
}
|
|
1125
1140
|
const t = e.baseUrl.replace(/\/+$/, "");
|
|
1126
1141
|
await Promise.all([
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
])
|
|
1130
|
-
const n =
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
const r =
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1142
|
+
u(o.clientKey, e.clientKey),
|
|
1143
|
+
u(o.baseUrl, t)
|
|
1144
|
+
]);
|
|
1145
|
+
const n = await on();
|
|
1146
|
+
await X(), await rn(n);
|
|
1147
|
+
const i = Q;
|
|
1148
|
+
Q = [];
|
|
1149
|
+
for (const l of i)
|
|
1150
|
+
await k(l.name, l.properties, l.timestampMs);
|
|
1151
|
+
e.serviceWorker === "external" ? an() : e.serviceWorkerPath && await cn(e.serviceWorkerPath);
|
|
1152
|
+
const r = Mn(e.inApp);
|
|
1153
|
+
gn(r ? Ie : void 0), An();
|
|
1154
|
+
const s = typeof document < "u" ? document : void 0, a = (s == null ? void 0 : s.visibilityState) === "visible" && s.prerendering !== !0;
|
|
1155
|
+
a && await ze(), r && (vt(Bn(r)), await bn() && (await gt(ce), a && Ie())), V().catch(() => {
|
|
1156
|
+
}), mn().catch(() => {
|
|
1157
|
+
}), I(`initialized (sdk ${j})`);
|
|
1141
1158
|
})(), b);
|
|
1142
1159
|
}
|
|
1143
1160
|
async function He(e, t = {}) {
|
|
@@ -1146,157 +1163,157 @@ async function He(e, t = {}) {
|
|
|
1146
1163
|
I("track() called with a blank event name — ignoring");
|
|
1147
1164
|
return;
|
|
1148
1165
|
}
|
|
1149
|
-
if (n.startsWith(
|
|
1150
|
-
I(`'${
|
|
1166
|
+
if (n.startsWith(x)) {
|
|
1167
|
+
I(`'${x}' is reserved for the SDK — ignoring '${n}'`);
|
|
1151
1168
|
return;
|
|
1152
1169
|
}
|
|
1153
1170
|
if (!b) {
|
|
1154
|
-
if (
|
|
1171
|
+
if (Q.length >= Pe) {
|
|
1155
1172
|
Te || (Te = !0, console.warn(
|
|
1156
1173
|
`[arsel] more than ${Pe} events tracked before init() — dropping the rest. Call init() earlier.`
|
|
1157
1174
|
));
|
|
1158
1175
|
return;
|
|
1159
1176
|
}
|
|
1160
|
-
|
|
1177
|
+
Q.push({ name: n, properties: t, timestampMs: Date.now() });
|
|
1161
1178
|
return;
|
|
1162
1179
|
}
|
|
1163
|
-
await b,
|
|
1180
|
+
await b, U() && (await k(n, t), pe("CUSTOM_EVENT", n, t));
|
|
1164
1181
|
}
|
|
1165
|
-
async function
|
|
1182
|
+
async function _n(e, t = {}) {
|
|
1166
1183
|
const n = e == null ? void 0 : e.trim();
|
|
1167
1184
|
if (!n) {
|
|
1168
1185
|
I("screen() called with a blank name — ignoring");
|
|
1169
1186
|
return;
|
|
1170
1187
|
}
|
|
1171
|
-
await b, await
|
|
1188
|
+
await b, await k(rt, { ...t, screen_name: n }), pe("SCREEN_VIEW", n, t);
|
|
1172
1189
|
}
|
|
1173
|
-
function
|
|
1174
|
-
|
|
1190
|
+
function Nn(e) {
|
|
1191
|
+
St(e);
|
|
1175
1192
|
}
|
|
1176
|
-
async function
|
|
1177
|
-
if (await b, !
|
|
1193
|
+
async function xn(e) {
|
|
1194
|
+
if (await b, !U()) return;
|
|
1178
1195
|
let { email: t, phoneNumber: n } = e ?? {};
|
|
1179
1196
|
const i = e == null ? void 0 : e.externalId;
|
|
1180
|
-
if (t && !
|
|
1197
|
+
if (t && !Sn.test(t) && (console.error(`[arsel] identify(): '${t}' is not a valid email address — ignored`), t = void 0), n && !vn.test(n) && (console.error(
|
|
1181
1198
|
`[arsel] identify(): '${n}' is not E.164 (e.g. +966501234567) — ignored`
|
|
1182
1199
|
), n = void 0), !i && !t && !n) {
|
|
1183
1200
|
I("identify() needs at least one of externalId, email or phoneNumber");
|
|
1184
1201
|
return;
|
|
1185
1202
|
}
|
|
1186
|
-
i && await
|
|
1187
|
-
}
|
|
1188
|
-
async function
|
|
1189
|
-
await b,
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1203
|
+
i && await u(o.externalId, i), t && await u(o.email, t), n && await u(o.phoneNumber, n), await k(nt, {}), await Ce();
|
|
1204
|
+
}
|
|
1205
|
+
async function kn() {
|
|
1206
|
+
await b, U() && (await Promise.all([
|
|
1207
|
+
L(o.externalId),
|
|
1208
|
+
L(o.email),
|
|
1209
|
+
L(o.phoneNumber),
|
|
1210
|
+
L(o.sessionStartedAt)
|
|
1194
1211
|
]), await Ze(), await Ce(), I("identity reset"));
|
|
1195
1212
|
}
|
|
1196
|
-
async function
|
|
1197
|
-
if (await b, !
|
|
1198
|
-
const e = await
|
|
1213
|
+
async function Pn() {
|
|
1214
|
+
if (await b, !U()) return !1;
|
|
1215
|
+
const e = await pn();
|
|
1199
1216
|
return I(e ? "push opt-out recorded" : "push opt-out not sent — no registration to revoke"), e;
|
|
1200
1217
|
}
|
|
1201
|
-
async function
|
|
1202
|
-
if (await b, !
|
|
1203
|
-
const e = await
|
|
1218
|
+
async function Tn() {
|
|
1219
|
+
if (await b, !U() || !B()) return !1;
|
|
1220
|
+
const e = await dn();
|
|
1204
1221
|
if (e)
|
|
1205
1222
|
return console.error(`[arsel] promptForPush(): ${e}`), !1;
|
|
1206
1223
|
const t = await Notification.requestPermission();
|
|
1207
|
-
return t !== "granted" ? (I(`notification permission: ${t}`), !1) :
|
|
1224
|
+
return t !== "granted" ? (I(`notification permission: ${t}`), !1) : fn();
|
|
1208
1225
|
}
|
|
1209
|
-
async function
|
|
1226
|
+
async function Dn() {
|
|
1210
1227
|
return await b, X();
|
|
1211
1228
|
}
|
|
1212
|
-
async function
|
|
1229
|
+
async function On() {
|
|
1213
1230
|
const [
|
|
1214
1231
|
e,
|
|
1215
1232
|
t,
|
|
1216
1233
|
n,
|
|
1217
1234
|
i,
|
|
1218
1235
|
r,
|
|
1219
|
-
o,
|
|
1220
1236
|
s,
|
|
1237
|
+
a,
|
|
1221
1238
|
l,
|
|
1222
|
-
|
|
1239
|
+
w,
|
|
1223
1240
|
f,
|
|
1224
1241
|
A,
|
|
1225
1242
|
C,
|
|
1226
1243
|
E
|
|
1227
1244
|
] = await Promise.all([
|
|
1228
|
-
c(
|
|
1229
|
-
c(
|
|
1230
|
-
c(
|
|
1231
|
-
c(
|
|
1232
|
-
c(
|
|
1233
|
-
c(
|
|
1234
|
-
c(
|
|
1245
|
+
c(o.anonymousId),
|
|
1246
|
+
c(o.externalId),
|
|
1247
|
+
c(o.email),
|
|
1248
|
+
c(o.phoneNumber),
|
|
1249
|
+
c(o.installationId),
|
|
1250
|
+
c(o.deviceSecret),
|
|
1251
|
+
c(o.vapidKeyVersion),
|
|
1235
1252
|
Oe(S.events),
|
|
1236
|
-
|
|
1237
|
-
c(
|
|
1238
|
-
c(
|
|
1239
|
-
c(
|
|
1240
|
-
c(
|
|
1241
|
-
]),
|
|
1253
|
+
yn(),
|
|
1254
|
+
c(o.subscriptionStatus),
|
|
1255
|
+
c(o.lastResponseCode),
|
|
1256
|
+
c(o.lastResponsePath),
|
|
1257
|
+
c(o.lastResponseAtMs)
|
|
1258
|
+
]), T = At(), he = await Et().catch(() => 0);
|
|
1242
1259
|
return {
|
|
1243
|
-
sdkVersion:
|
|
1244
|
-
initialized: b !== null &&
|
|
1245
|
-
configError:
|
|
1246
|
-
inAppMessages:
|
|
1247
|
-
inAppBundleVersion:
|
|
1248
|
-
inAppFetchedAtMs:
|
|
1260
|
+
sdkVersion: j,
|
|
1261
|
+
initialized: b !== null && R === null,
|
|
1262
|
+
configError: R,
|
|
1263
|
+
inAppMessages: T.messages,
|
|
1264
|
+
inAppBundleVersion: T.bundleVersion,
|
|
1265
|
+
inAppFetchedAtMs: T.fetchedAtMs,
|
|
1249
1266
|
pendingInAppBeacons: he,
|
|
1250
1267
|
anonymousId: e,
|
|
1251
1268
|
hasAssertedIdentity: !!(t || n || i),
|
|
1252
1269
|
installationId: r,
|
|
1253
|
-
hasDeviceSecret: !!
|
|
1270
|
+
hasDeviceSecret: !!s,
|
|
1254
1271
|
pendingEvents: l,
|
|
1255
|
-
permission:
|
|
1256
|
-
isSubscribed:
|
|
1272
|
+
permission: B() ? Notification.permission : "unsupported",
|
|
1273
|
+
isSubscribed: w,
|
|
1257
1274
|
subscriptionStatus: f,
|
|
1258
|
-
vapidKeyVersion:
|
|
1275
|
+
vapidKeyVersion: a,
|
|
1259
1276
|
lastResponseCode: A,
|
|
1260
1277
|
lastResponsePath: C,
|
|
1261
1278
|
lastResponseAtMs: E
|
|
1262
1279
|
};
|
|
1263
1280
|
}
|
|
1264
|
-
async function
|
|
1265
|
-
await b,
|
|
1281
|
+
async function Rn() {
|
|
1282
|
+
await b, U() && await V();
|
|
1266
1283
|
}
|
|
1267
|
-
const
|
|
1268
|
-
init:
|
|
1284
|
+
const Cn = {
|
|
1285
|
+
init: In,
|
|
1269
1286
|
track: He,
|
|
1270
|
-
screen:
|
|
1271
|
-
suppressInAppMessages:
|
|
1272
|
-
identify:
|
|
1273
|
-
reset:
|
|
1274
|
-
optOut:
|
|
1275
|
-
promptForPush:
|
|
1276
|
-
getAnonymousId:
|
|
1277
|
-
diagnostics:
|
|
1278
|
-
flushNow:
|
|
1279
|
-
SDK_VERSION:
|
|
1287
|
+
screen: _n,
|
|
1288
|
+
suppressInAppMessages: Nn,
|
|
1289
|
+
identify: xn,
|
|
1290
|
+
reset: kn,
|
|
1291
|
+
optOut: Pn,
|
|
1292
|
+
promptForPush: Tn,
|
|
1293
|
+
getAnonymousId: Dn,
|
|
1294
|
+
diagnostics: On,
|
|
1295
|
+
flushNow: Rn,
|
|
1296
|
+
SDK_VERSION: j
|
|
1280
1297
|
};
|
|
1281
|
-
function
|
|
1298
|
+
function Mn(e) {
|
|
1282
1299
|
if (e === !1) return;
|
|
1283
1300
|
const t = typeof e == "object" && e !== null ? e : {};
|
|
1284
1301
|
return {
|
|
1285
|
-
zIndex: t.zIndex ??
|
|
1302
|
+
zIndex: t.zIndex ?? Un,
|
|
1286
1303
|
closeLabel: t.closeLabel ?? "Close"
|
|
1287
1304
|
};
|
|
1288
1305
|
}
|
|
1289
|
-
function
|
|
1306
|
+
function Bn(e) {
|
|
1290
1307
|
return (t) => {
|
|
1291
|
-
const n =
|
|
1308
|
+
const n = Ot();
|
|
1292
1309
|
try {
|
|
1293
|
-
|
|
1294
|
-
onImpression: () => void
|
|
1310
|
+
Xt(t, e, {
|
|
1311
|
+
onImpression: () => void Rt(t, n),
|
|
1295
1312
|
onButton: (i) => {
|
|
1296
1313
|
Mt(t, i.buttonId), i.action === "CUSTOM_EVENT" && i.value && He(i.value);
|
|
1297
1314
|
},
|
|
1298
1315
|
onDismiss: (i) => {
|
|
1299
|
-
|
|
1316
|
+
Bt(t, i), _e();
|
|
1300
1317
|
}
|
|
1301
1318
|
});
|
|
1302
1319
|
} catch (i) {
|
|
@@ -1304,21 +1321,21 @@ function On(e) {
|
|
|
1304
1321
|
}
|
|
1305
1322
|
};
|
|
1306
1323
|
}
|
|
1307
|
-
const
|
|
1324
|
+
const Un = 2147483e3;
|
|
1308
1325
|
export {
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1326
|
+
Cn as Arsel,
|
|
1327
|
+
j as SDK_VERSION,
|
|
1328
|
+
Cn as default,
|
|
1329
|
+
On as diagnostics,
|
|
1330
|
+
Rn as flushNow,
|
|
1331
|
+
Dn as getAnonymousId,
|
|
1332
|
+
xn as identify,
|
|
1333
|
+
In as init,
|
|
1334
|
+
Pn as optOut,
|
|
1335
|
+
Tn as promptForPush,
|
|
1336
|
+
kn as reset,
|
|
1337
|
+
_n as screen,
|
|
1338
|
+
Nn as suppressInAppMessages,
|
|
1322
1339
|
He as track
|
|
1323
1340
|
};
|
|
1324
1341
|
//# sourceMappingURL=arsel.js.map
|