@sesamy/sesamy-js 1.2.0 → 1.3.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.
@@ -1,3169 +0,0 @@
1
- var gr = Object.defineProperty;
2
- var yr = (t, e, n) => e in t ? gr(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var G = (t, e, n) => (yr(t, typeof e != "symbol" ? e + "" : e, n), n);
4
- (function() {
5
- const e = document.createElement("link").relList;
6
- if (e && e.supports && e.supports("modulepreload"))
7
- return;
8
- for (const i of document.querySelectorAll('link[rel="modulepreload"]'))
9
- r(i);
10
- new MutationObserver((i) => {
11
- for (const o of i)
12
- if (o.type === "childList")
13
- for (const a of o.addedNodes)
14
- a.tagName === "LINK" && a.rel === "modulepreload" && r(a);
15
- }).observe(document, { childList: !0, subtree: !0 });
16
- function n(i) {
17
- const o = {};
18
- return i.integrity && (o.integrity = i.integrity), i.referrerPolicy && (o.referrerPolicy = i.referrerPolicy), i.crossOrigin === "use-credentials" ? o.credentials = "include" : i.crossOrigin === "anonymous" ? o.credentials = "omit" : o.credentials = "same-origin", o;
19
- }
20
- function r(i) {
21
- if (i.ep)
22
- return;
23
- i.ep = !0;
24
- const o = n(i);
25
- fetch(i.href, o);
26
- }
27
- })();
28
- function rt(t, e) {
29
- const n = new CustomEvent(t, {
30
- detail: e,
31
- bubbles: !0,
32
- composed: !0
33
- });
34
- dispatchEvent(n);
35
- }
36
- function Q(t, e) {
37
- var n = {};
38
- for (var r in t)
39
- Object.prototype.hasOwnProperty.call(t, r) && e.indexOf(r) < 0 && (n[r] = t[r]);
40
- if (t != null && typeof Object.getOwnPropertySymbols == "function") {
41
- var i = 0;
42
- for (r = Object.getOwnPropertySymbols(t); i < r.length; i++)
43
- e.indexOf(r[i]) < 0 && Object.prototype.propertyIsEnumerable.call(t, r[i]) && (n[r[i]] = t[r[i]]);
44
- }
45
- return n;
46
- }
47
- var ue = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
48
- function Tt(t) {
49
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
50
- }
51
- function jt(t, e) {
52
- return t(e = { exports: {} }, e.exports), e.exports;
53
- }
54
- var se = jt(function(t, e) {
55
- Object.defineProperty(e, "__esModule", { value: !0 });
56
- var n = function() {
57
- function r() {
58
- var i = this;
59
- this.locked = /* @__PURE__ */ new Map(), this.addToLocked = function(o, a) {
60
- var s = i.locked.get(o);
61
- s === void 0 ? a === void 0 ? i.locked.set(o, []) : i.locked.set(o, [a]) : a !== void 0 && (s.unshift(a), i.locked.set(o, s));
62
- }, this.isLocked = function(o) {
63
- return i.locked.has(o);
64
- }, this.lock = function(o) {
65
- return new Promise(function(a, s) {
66
- i.isLocked(o) ? i.addToLocked(o, a) : (i.addToLocked(o), a());
67
- });
68
- }, this.unlock = function(o) {
69
- var a = i.locked.get(o);
70
- if (a !== void 0 && a.length !== 0) {
71
- var s = a.pop();
72
- i.locked.set(o, a), s !== void 0 && setTimeout(s, 0);
73
- } else
74
- i.locked.delete(o);
75
- };
76
- }
77
- return r.getInstance = function() {
78
- return r.instance === void 0 && (r.instance = new r()), r.instance;
79
- }, r;
80
- }();
81
- e.default = function() {
82
- return n.getInstance();
83
- };
84
- });
85
- Tt(se);
86
- var vr = Tt(jt(function(t, e) {
87
- var n = ue && ue.__awaiter || function(u, c, h, d) {
88
- return new (h || (h = Promise))(function(w, k) {
89
- function v(y) {
90
- try {
91
- _(d.next(y));
92
- } catch (l) {
93
- k(l);
94
- }
95
- }
96
- function I(y) {
97
- try {
98
- _(d.throw(y));
99
- } catch (l) {
100
- k(l);
101
- }
102
- }
103
- function _(y) {
104
- y.done ? w(y.value) : new h(function(l) {
105
- l(y.value);
106
- }).then(v, I);
107
- }
108
- _((d = d.apply(u, c || [])).next());
109
- });
110
- }, r = ue && ue.__generator || function(u, c) {
111
- var h, d, w, k, v = { label: 0, sent: function() {
112
- if (1 & w[0])
113
- throw w[1];
114
- return w[1];
115
- }, trys: [], ops: [] };
116
- return k = { next: I(0), throw: I(1), return: I(2) }, typeof Symbol == "function" && (k[Symbol.iterator] = function() {
117
- return this;
118
- }), k;
119
- function I(_) {
120
- return function(y) {
121
- return function(l) {
122
- if (h)
123
- throw new TypeError("Generator is already executing.");
124
- for (; v; )
125
- try {
126
- if (h = 1, d && (w = 2 & l[0] ? d.return : l[0] ? d.throw || ((w = d.return) && w.call(d), 0) : d.next) && !(w = w.call(d, l[1])).done)
127
- return w;
128
- switch (d = 0, w && (l = [2 & l[0], w.value]), l[0]) {
129
- case 0:
130
- case 1:
131
- w = l;
132
- break;
133
- case 4:
134
- return v.label++, { value: l[1], done: !1 };
135
- case 5:
136
- v.label++, d = l[1], l = [0];
137
- continue;
138
- case 7:
139
- l = v.ops.pop(), v.trys.pop();
140
- continue;
141
- default:
142
- if (w = v.trys, !((w = w.length > 0 && w[w.length - 1]) || l[0] !== 6 && l[0] !== 2)) {
143
- v = 0;
144
- continue;
145
- }
146
- if (l[0] === 3 && (!w || l[1] > w[0] && l[1] < w[3])) {
147
- v.label = l[1];
148
- break;
149
- }
150
- if (l[0] === 6 && v.label < w[1]) {
151
- v.label = w[1], w = l;
152
- break;
153
- }
154
- if (w && v.label < w[2]) {
155
- v.label = w[2], v.ops.push(l);
156
- break;
157
- }
158
- w[2] && v.ops.pop(), v.trys.pop();
159
- continue;
160
- }
161
- l = c.call(u, v);
162
- } catch (b) {
163
- l = [6, b], d = 0;
164
- } finally {
165
- h = w = 0;
166
- }
167
- if (5 & l[0])
168
- throw l[1];
169
- return { value: l[0] ? l[1] : void 0, done: !0 };
170
- }([_, y]);
171
- };
172
- }
173
- }, i = ue;
174
- Object.defineProperty(e, "__esModule", { value: !0 });
175
- var o = "browser-tabs-lock-key", a = { key: function(u) {
176
- return n(i, void 0, void 0, function() {
177
- return r(this, function(c) {
178
- throw new Error("Unsupported");
179
- });
180
- });
181
- }, getItem: function(u) {
182
- return n(i, void 0, void 0, function() {
183
- return r(this, function(c) {
184
- throw new Error("Unsupported");
185
- });
186
- });
187
- }, clear: function() {
188
- return n(i, void 0, void 0, function() {
189
- return r(this, function(u) {
190
- return [2, window.localStorage.clear()];
191
- });
192
- });
193
- }, removeItem: function(u) {
194
- return n(i, void 0, void 0, function() {
195
- return r(this, function(c) {
196
- throw new Error("Unsupported");
197
- });
198
- });
199
- }, setItem: function(u, c) {
200
- return n(i, void 0, void 0, function() {
201
- return r(this, function(h) {
202
- throw new Error("Unsupported");
203
- });
204
- });
205
- }, keySync: function(u) {
206
- return window.localStorage.key(u);
207
- }, getItemSync: function(u) {
208
- return window.localStorage.getItem(u);
209
- }, clearSync: function() {
210
- return window.localStorage.clear();
211
- }, removeItemSync: function(u) {
212
- return window.localStorage.removeItem(u);
213
- }, setItemSync: function(u, c) {
214
- return window.localStorage.setItem(u, c);
215
- } };
216
- function s(u) {
217
- return new Promise(function(c) {
218
- return setTimeout(c, u);
219
- });
220
- }
221
- function m(u) {
222
- for (var c = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz", h = "", d = 0; d < u; d++)
223
- h += c[Math.floor(Math.random() * c.length)];
224
- return h;
225
- }
226
- var p = function() {
227
- function u(c) {
228
- this.acquiredIatSet = /* @__PURE__ */ new Set(), this.storageHandler = void 0, this.id = Date.now().toString() + m(15), this.acquireLock = this.acquireLock.bind(this), this.releaseLock = this.releaseLock.bind(this), this.releaseLock__private__ = this.releaseLock__private__.bind(this), this.waitForSomethingToChange = this.waitForSomethingToChange.bind(this), this.refreshLockWhileAcquired = this.refreshLockWhileAcquired.bind(this), this.storageHandler = c, u.waiters === void 0 && (u.waiters = []);
229
- }
230
- return u.prototype.acquireLock = function(c, h) {
231
- return h === void 0 && (h = 5e3), n(this, void 0, void 0, function() {
232
- var d, w, k, v, I, _, y;
233
- return r(this, function(l) {
234
- switch (l.label) {
235
- case 0:
236
- d = Date.now() + m(4), w = Date.now() + h, k = o + "-" + c, v = this.storageHandler === void 0 ? a : this.storageHandler, l.label = 1;
237
- case 1:
238
- return Date.now() < w ? [4, s(30)] : [3, 8];
239
- case 2:
240
- return l.sent(), v.getItemSync(k) !== null ? [3, 5] : (I = this.id + "-" + c + "-" + d, [4, s(Math.floor(25 * Math.random()))]);
241
- case 3:
242
- return l.sent(), v.setItemSync(k, JSON.stringify({ id: this.id, iat: d, timeoutKey: I, timeAcquired: Date.now(), timeRefreshed: Date.now() })), [4, s(30)];
243
- case 4:
244
- return l.sent(), (_ = v.getItemSync(k)) !== null && (y = JSON.parse(_)).id === this.id && y.iat === d ? (this.acquiredIatSet.add(d), this.refreshLockWhileAcquired(k, d), [2, !0]) : [3, 7];
245
- case 5:
246
- return u.lockCorrector(this.storageHandler === void 0 ? a : this.storageHandler), [4, this.waitForSomethingToChange(w)];
247
- case 6:
248
- l.sent(), l.label = 7;
249
- case 7:
250
- return d = Date.now() + m(4), [3, 1];
251
- case 8:
252
- return [2, !1];
253
- }
254
- });
255
- });
256
- }, u.prototype.refreshLockWhileAcquired = function(c, h) {
257
- return n(this, void 0, void 0, function() {
258
- var d = this;
259
- return r(this, function(w) {
260
- return setTimeout(function() {
261
- return n(d, void 0, void 0, function() {
262
- var k, v, I;
263
- return r(this, function(_) {
264
- switch (_.label) {
265
- case 0:
266
- return [4, se.default().lock(h)];
267
- case 1:
268
- return _.sent(), this.acquiredIatSet.has(h) ? (k = this.storageHandler === void 0 ? a : this.storageHandler, (v = k.getItemSync(c)) === null ? (se.default().unlock(h), [2]) : ((I = JSON.parse(v)).timeRefreshed = Date.now(), k.setItemSync(c, JSON.stringify(I)), se.default().unlock(h), this.refreshLockWhileAcquired(c, h), [2])) : (se.default().unlock(h), [2]);
269
- }
270
- });
271
- });
272
- }, 1e3), [2];
273
- });
274
- });
275
- }, u.prototype.waitForSomethingToChange = function(c) {
276
- return n(this, void 0, void 0, function() {
277
- return r(this, function(h) {
278
- switch (h.label) {
279
- case 0:
280
- return [4, new Promise(function(d) {
281
- var w = !1, k = Date.now(), v = !1;
282
- function I() {
283
- if (v || (window.removeEventListener("storage", I), u.removeFromWaiting(I), clearTimeout(_), v = !0), !w) {
284
- w = !0;
285
- var y = 50 - (Date.now() - k);
286
- y > 0 ? setTimeout(d, y) : d(null);
287
- }
288
- }
289
- window.addEventListener("storage", I), u.addToWaiting(I);
290
- var _ = setTimeout(I, Math.max(0, c - Date.now()));
291
- })];
292
- case 1:
293
- return h.sent(), [2];
294
- }
295
- });
296
- });
297
- }, u.addToWaiting = function(c) {
298
- this.removeFromWaiting(c), u.waiters !== void 0 && u.waiters.push(c);
299
- }, u.removeFromWaiting = function(c) {
300
- u.waiters !== void 0 && (u.waiters = u.waiters.filter(function(h) {
301
- return h !== c;
302
- }));
303
- }, u.notifyWaiters = function() {
304
- u.waiters !== void 0 && u.waiters.slice().forEach(function(c) {
305
- return c();
306
- });
307
- }, u.prototype.releaseLock = function(c) {
308
- return n(this, void 0, void 0, function() {
309
- return r(this, function(h) {
310
- switch (h.label) {
311
- case 0:
312
- return [4, this.releaseLock__private__(c)];
313
- case 1:
314
- return [2, h.sent()];
315
- }
316
- });
317
- });
318
- }, u.prototype.releaseLock__private__ = function(c) {
319
- return n(this, void 0, void 0, function() {
320
- var h, d, w, k;
321
- return r(this, function(v) {
322
- switch (v.label) {
323
- case 0:
324
- return h = this.storageHandler === void 0 ? a : this.storageHandler, d = o + "-" + c, (w = h.getItemSync(d)) === null ? [2] : (k = JSON.parse(w)).id !== this.id ? [3, 2] : [4, se.default().lock(k.iat)];
325
- case 1:
326
- v.sent(), this.acquiredIatSet.delete(k.iat), h.removeItemSync(d), se.default().unlock(k.iat), u.notifyWaiters(), v.label = 2;
327
- case 2:
328
- return [2];
329
- }
330
- });
331
- });
332
- }, u.lockCorrector = function(c) {
333
- for (var h = Date.now() - 5e3, d = c, w = [], k = 0; ; ) {
334
- var v = d.keySync(k);
335
- if (v === null)
336
- break;
337
- w.push(v), k++;
338
- }
339
- for (var I = !1, _ = 0; _ < w.length; _++) {
340
- var y = w[_];
341
- if (y.includes(o)) {
342
- var l = d.getItemSync(y);
343
- if (l !== null) {
344
- var b = JSON.parse(l);
345
- (b.timeRefreshed === void 0 && b.timeAcquired < h || b.timeRefreshed !== void 0 && b.timeRefreshed < h) && (d.removeItemSync(y), I = !0);
346
- }
347
- }
348
- }
349
- I && u.notifyWaiters();
350
- }, u.waiters = void 0, u;
351
- }();
352
- e.default = p;
353
- }));
354
- const wr = { timeoutInSeconds: 60 }, En = { name: "auth0-spa-js", version: "2.1.3" }, On = () => Date.now();
355
- let V = class kt extends Error {
356
- constructor(e, n) {
357
- super(n), this.error = e, this.error_description = n, Object.setPrototypeOf(this, kt.prototype);
358
- }
359
- static fromPayload({ error: e, error_description: n }) {
360
- return new kt(e, n);
361
- }
362
- }, br = class Pn extends V {
363
- constructor(e, n, r, i = null) {
364
- super(e, n), this.state = r, this.appState = i, Object.setPrototypeOf(this, Pn.prototype);
365
- }
366
- }, It = class Tn extends V {
367
- constructor() {
368
- super("timeout", "Timeout"), Object.setPrototypeOf(this, Tn.prototype);
369
- }
370
- }, kr = class jn extends It {
371
- constructor(e) {
372
- super(), this.popup = e, Object.setPrototypeOf(this, jn.prototype);
373
- }
374
- }, Ir = class xn extends V {
375
- constructor(e) {
376
- super("cancelled", "Popup closed"), this.popup = e, Object.setPrototypeOf(this, xn.prototype);
377
- }
378
- }, _r = class Cn extends V {
379
- constructor(e, n, r) {
380
- super(e, n), this.mfa_token = r, Object.setPrototypeOf(this, Cn.prototype);
381
- }
382
- }, $n = class An extends V {
383
- constructor(e, n) {
384
- super("missing_refresh_token", `Missing Refresh Token (audience: '${Wt(e, ["default"])}', scope: '${Wt(n)}')`), this.audience = e, this.scope = n, Object.setPrototypeOf(this, An.prototype);
385
- }
386
- };
387
- function Wt(t, e = []) {
388
- return t && !e.includes(t) ? t : "";
389
- }
390
- const Be = () => window.crypto, dt = () => {
391
- const t = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.";
392
- let e = "";
393
- return Array.from(Be().getRandomValues(new Uint8Array(43))).forEach((n) => e += t[n % t.length]), e;
394
- }, Zt = (t) => btoa(t), _t = (t) => {
395
- var { clientId: e } = t, n = Q(t, ["clientId"]);
396
- return new URLSearchParams(((r) => Object.keys(r).filter((i) => r[i] !== void 0).reduce((i, o) => Object.assign(Object.assign({}, i), { [o]: r[o] }), {}))(Object.assign({ client_id: e }, n))).toString();
397
- }, Kt = (t) => ((e) => decodeURIComponent(atob(e).split("").map((n) => "%" + ("00" + n.charCodeAt(0).toString(16)).slice(-2)).join("")))(t.replace(/_/g, "/").replace(/-/g, "+")), Sr = async (t, e) => {
398
- const n = await fetch(t, e);
399
- return { ok: n.ok, json: await n.json() };
400
- }, Er = async (t, e, n) => {
401
- const r = new AbortController();
402
- let i;
403
- return e.signal = r.signal, Promise.race([Sr(t, e), new Promise((o, a) => {
404
- i = setTimeout(() => {
405
- r.abort(), a(new Error("Timeout when executing 'fetch'"));
406
- }, n);
407
- })]).finally(() => {
408
- clearTimeout(i);
409
- });
410
- }, Or = async (t, e, n, r, i, o, a) => {
411
- return s = { auth: { audience: e, scope: n }, timeout: i, fetchUrl: t, fetchOptions: r, useFormData: a }, m = o, new Promise(function(p, u) {
412
- const c = new MessageChannel();
413
- c.port1.onmessage = function(h) {
414
- h.data.error ? u(new Error(h.data.error)) : p(h.data), c.port1.close();
415
- }, m.postMessage(s, [c.port2]);
416
- });
417
- var s, m;
418
- }, Pr = async (t, e, n, r, i, o, a = 1e4) => i ? Or(t, e, n, r, a, i, o) : Er(t, r, a);
419
- async function Tr(t, e) {
420
- var { baseUrl: n, timeout: r, audience: i, scope: o, auth0Client: a, useFormData: s } = t, m = Q(t, ["baseUrl", "timeout", "audience", "scope", "auth0Client", "useFormData"]);
421
- const p = s ? _t(m) : JSON.stringify(m);
422
- return await async function(u, c, h, d, w, k, v) {
423
- let I, _ = null;
424
- for (let x = 0; x < 3; x++)
425
- try {
426
- I = await Pr(u, h, d, w, k, v, c), _ = null;
427
- break;
428
- } catch (D) {
429
- _ = D;
430
- }
431
- if (_)
432
- throw _;
433
- const y = I.json, { error: l, error_description: b } = y, T = Q(y, ["error", "error_description"]), { ok: P } = I;
434
- if (!P) {
435
- const x = b || `HTTP error. Unable to fetch ${u}`;
436
- throw l === "mfa_required" ? new _r(l, x, T.mfa_token) : l === "missing_refresh_token" ? new $n(h, d) : new V(l || "request_error", x);
437
- }
438
- return T;
439
- }(`${n}/oauth/token`, r, i || "default", o, { method: "POST", body: p, headers: { "Content-Type": s ? "application/x-www-form-urlencoded" : "application/json", "Auth0-Client": btoa(JSON.stringify(a || En)) } }, e, s);
440
- }
441
- const Xe = (...t) => {
442
- return (e = t.filter(Boolean).join(" ").trim().split(/\s+/), Array.from(new Set(e))).join(" ");
443
- var e;
444
- };
445
- let de = class St {
446
- constructor(e, n = "@@auth0spajs@@", r) {
447
- this.prefix = n, this.suffix = r, this.clientId = e.clientId, this.scope = e.scope, this.audience = e.audience;
448
- }
449
- toKey() {
450
- return [this.prefix, this.clientId, this.audience, this.scope, this.suffix].filter(Boolean).join("::");
451
- }
452
- static fromKey(e) {
453
- const [n, r, i, o] = e.split("::");
454
- return new St({ clientId: r, scope: o, audience: i }, n);
455
- }
456
- static fromCacheEntry(e) {
457
- const { scope: n, audience: r, client_id: i } = e;
458
- return new St({ scope: n, audience: r, clientId: i });
459
- }
460
- }, jr = class {
461
- set(e, n) {
462
- localStorage.setItem(e, JSON.stringify(n));
463
- }
464
- get(e) {
465
- const n = window.localStorage.getItem(e);
466
- if (n)
467
- try {
468
- return JSON.parse(n);
469
- } catch {
470
- return;
471
- }
472
- }
473
- remove(e) {
474
- localStorage.removeItem(e);
475
- }
476
- allKeys() {
477
- return Object.keys(window.localStorage).filter((e) => e.startsWith("@@auth0spajs@@"));
478
- }
479
- }, zn = class {
480
- constructor() {
481
- this.enclosedCache = /* @__PURE__ */ function() {
482
- let e = {};
483
- return { set(n, r) {
484
- e[n] = r;
485
- }, get(n) {
486
- const r = e[n];
487
- if (r)
488
- return r;
489
- }, remove(n) {
490
- delete e[n];
491
- }, allKeys: () => Object.keys(e) };
492
- }();
493
- }
494
- }, xr = class {
495
- constructor(e, n, r) {
496
- this.cache = e, this.keyManifest = n, this.nowProvider = r || On;
497
- }
498
- async setIdToken(e, n, r) {
499
- var i;
500
- const o = this.getIdTokenCacheKey(e);
501
- await this.cache.set(o, { id_token: n, decodedToken: r }), await ((i = this.keyManifest) === null || i === void 0 ? void 0 : i.add(o));
502
- }
503
- async getIdToken(e) {
504
- const n = await this.cache.get(this.getIdTokenCacheKey(e.clientId));
505
- if (!n && e.scope && e.audience) {
506
- const r = await this.get(e);
507
- return !r || !r.id_token || !r.decodedToken ? void 0 : { id_token: r.id_token, decodedToken: r.decodedToken };
508
- }
509
- if (n)
510
- return { id_token: n.id_token, decodedToken: n.decodedToken };
511
- }
512
- async get(e, n = 0) {
513
- var r;
514
- let i = await this.cache.get(e.toKey());
515
- if (!i) {
516
- const s = await this.getCacheKeys();
517
- if (!s)
518
- return;
519
- const m = this.matchExistingCacheKey(e, s);
520
- m && (i = await this.cache.get(m));
521
- }
522
- if (!i)
523
- return;
524
- const o = await this.nowProvider(), a = Math.floor(o / 1e3);
525
- return i.expiresAt - n < a ? i.body.refresh_token ? (i.body = { refresh_token: i.body.refresh_token }, await this.cache.set(e.toKey(), i), i.body) : (await this.cache.remove(e.toKey()), void await ((r = this.keyManifest) === null || r === void 0 ? void 0 : r.remove(e.toKey()))) : i.body;
526
- }
527
- async set(e) {
528
- var n;
529
- const r = new de({ clientId: e.client_id, scope: e.scope, audience: e.audience }), i = await this.wrapCacheEntry(e);
530
- await this.cache.set(r.toKey(), i), await ((n = this.keyManifest) === null || n === void 0 ? void 0 : n.add(r.toKey()));
531
- }
532
- async clear(e) {
533
- var n;
534
- const r = await this.getCacheKeys();
535
- r && (await r.filter((i) => !e || i.includes(e)).reduce(async (i, o) => {
536
- await i, await this.cache.remove(o);
537
- }, Promise.resolve()), await ((n = this.keyManifest) === null || n === void 0 ? void 0 : n.clear()));
538
- }
539
- async wrapCacheEntry(e) {
540
- const n = await this.nowProvider();
541
- return { body: e, expiresAt: Math.floor(n / 1e3) + e.expires_in };
542
- }
543
- async getCacheKeys() {
544
- var e;
545
- return this.keyManifest ? (e = await this.keyManifest.get()) === null || e === void 0 ? void 0 : e.keys : this.cache.allKeys ? this.cache.allKeys() : void 0;
546
- }
547
- getIdTokenCacheKey(e) {
548
- return new de({ clientId: e }, "@@auth0spajs@@", "@@user@@").toKey();
549
- }
550
- matchExistingCacheKey(e, n) {
551
- return n.filter((r) => {
552
- var i;
553
- const o = de.fromKey(r), a = new Set(o.scope && o.scope.split(" ")), s = ((i = e.scope) === null || i === void 0 ? void 0 : i.split(" ")) || [], m = o.scope && s.reduce((p, u) => p && a.has(u), !0);
554
- return o.prefix === "@@auth0spajs@@" && o.clientId === e.clientId && o.audience === e.audience && m;
555
- })[0];
556
- }
557
- }, Cr = class {
558
- constructor(e, n, r) {
559
- this.storage = e, this.clientId = n, this.cookieDomain = r, this.storageKey = `a0.spajs.txs.${this.clientId}`;
560
- }
561
- create(e) {
562
- this.storage.save(this.storageKey, e, { daysUntilExpire: 1, cookieDomain: this.cookieDomain });
563
- }
564
- get() {
565
- return this.storage.get(this.storageKey);
566
- }
567
- remove() {
568
- this.storage.remove(this.storageKey, { cookieDomain: this.cookieDomain });
569
- }
570
- };
571
- const ze = (t) => typeof t == "number", $r = ["iss", "aud", "exp", "nbf", "iat", "jti", "azp", "nonce", "auth_time", "at_hash", "c_hash", "acr", "amr", "sub_jwk", "cnf", "sip_from_tag", "sip_date", "sip_callid", "sip_cseq_num", "sip_via_branch", "orig", "dest", "mky", "events", "toe", "txn", "rph", "sid", "vot", "vtm"], Ar = (t) => {
572
- if (!t.id_token)
573
- throw new Error("ID token is required but missing");
574
- const e = ((o) => {
575
- const a = o.split("."), [s, m, p] = a;
576
- if (a.length !== 3 || !s || !m || !p)
577
- throw new Error("ID token could not be decoded");
578
- const u = JSON.parse(Kt(m)), c = { __raw: o }, h = {};
579
- return Object.keys(u).forEach((d) => {
580
- c[d] = u[d], $r.includes(d) || (h[d] = u[d]);
581
- }), { encoded: { header: s, payload: m, signature: p }, header: JSON.parse(Kt(s)), claims: c, user: h };
582
- })(t.id_token);
583
- if (!e.claims.iss)
584
- throw new Error("Issuer (iss) claim must be a string present in the ID token");
585
- if (e.claims.iss !== t.iss)
586
- throw new Error(`Issuer (iss) claim mismatch in the ID token; expected "${t.iss}", found "${e.claims.iss}"`);
587
- if (!e.user.sub)
588
- throw new Error("Subject (sub) claim must be a string present in the ID token");
589
- if (e.header.alg !== "RS256")
590
- throw new Error(`Signature algorithm of "${e.header.alg}" is not supported. Expected the ID token to be signed with "RS256".`);
591
- if (!e.claims.aud || typeof e.claims.aud != "string" && !Array.isArray(e.claims.aud))
592
- throw new Error("Audience (aud) claim must be a string or array of strings present in the ID token");
593
- if (Array.isArray(e.claims.aud)) {
594
- if (!e.claims.aud.includes(t.aud))
595
- throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${t.aud}" but was not one of "${e.claims.aud.join(", ")}"`);
596
- if (e.claims.aud.length > 1) {
597
- if (!e.claims.azp)
598
- throw new Error("Authorized Party (azp) claim must be a string present in the ID token when Audience (aud) claim has multiple values");
599
- if (e.claims.azp !== t.aud)
600
- throw new Error(`Authorized Party (azp) claim mismatch in the ID token; expected "${t.aud}", found "${e.claims.azp}"`);
601
- }
602
- } else if (e.claims.aud !== t.aud)
603
- throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${t.aud}" but found "${e.claims.aud}"`);
604
- if (t.nonce) {
605
- if (!e.claims.nonce)
606
- throw new Error("Nonce (nonce) claim must be a string present in the ID token");
607
- if (e.claims.nonce !== t.nonce)
608
- throw new Error(`Nonce (nonce) claim mismatch in the ID token; expected "${t.nonce}", found "${e.claims.nonce}"`);
609
- }
610
- if (t.max_age && !ze(e.claims.auth_time))
611
- throw new Error("Authentication Time (auth_time) claim must be a number present in the ID token when Max Age (max_age) is specified");
612
- if (e.claims.exp == null || !ze(e.claims.exp))
613
- throw new Error("Expiration Time (exp) claim must be a number present in the ID token");
614
- if (!ze(e.claims.iat))
615
- throw new Error("Issued At (iat) claim must be a number present in the ID token");
616
- const n = t.leeway || 60, r = new Date(t.now || Date.now()), i = /* @__PURE__ */ new Date(0);
617
- if (i.setUTCSeconds(e.claims.exp + n), r > i)
618
- throw new Error(`Expiration Time (exp) claim error in the ID token; current time (${r}) is after expiration time (${i})`);
619
- if (e.claims.nbf != null && ze(e.claims.nbf)) {
620
- const o = /* @__PURE__ */ new Date(0);
621
- if (o.setUTCSeconds(e.claims.nbf - n), r < o)
622
- throw new Error(`Not Before time (nbf) claim in the ID token indicates that this token can't be used just yet. Current time (${r}) is before ${o}`);
623
- }
624
- if (e.claims.auth_time != null && ze(e.claims.auth_time)) {
625
- const o = /* @__PURE__ */ new Date(0);
626
- if (o.setUTCSeconds(parseInt(e.claims.auth_time) + t.max_age + n), r > o)
627
- throw new Error(`Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time (${r}) is after last auth at ${o}`);
628
- }
629
- if (t.organization) {
630
- const o = t.organization.trim();
631
- if (o.startsWith("org_")) {
632
- const a = o;
633
- if (!e.claims.org_id)
634
- throw new Error("Organization ID (org_id) claim must be a string present in the ID token");
635
- if (a !== e.claims.org_id)
636
- throw new Error(`Organization ID (org_id) claim mismatch in the ID token; expected "${a}", found "${e.claims.org_id}"`);
637
- } else {
638
- const a = o.toLowerCase();
639
- if (!e.claims.org_name)
640
- throw new Error("Organization Name (org_name) claim must be a string present in the ID token");
641
- if (a !== e.claims.org_name)
642
- throw new Error(`Organization Name (org_name) claim mismatch in the ID token; expected "${a}", found "${e.claims.org_name}"`);
643
- }
644
- }
645
- return e;
646
- };
647
- var he = jt(function(t, e) {
648
- var n = ue && ue.__assign || function() {
649
- return n = Object.assign || function(m) {
650
- for (var p, u = 1, c = arguments.length; u < c; u++)
651
- for (var h in p = arguments[u])
652
- Object.prototype.hasOwnProperty.call(p, h) && (m[h] = p[h]);
653
- return m;
654
- }, n.apply(this, arguments);
655
- };
656
- function r(m, p) {
657
- if (!p)
658
- return "";
659
- var u = "; " + m;
660
- return p === !0 ? u : u + "=" + p;
661
- }
662
- function i(m, p, u) {
663
- return encodeURIComponent(m).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/\(/g, "%28").replace(/\)/g, "%29") + "=" + encodeURIComponent(p).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent) + function(c) {
664
- if (typeof c.expires == "number") {
665
- var h = /* @__PURE__ */ new Date();
666
- h.setMilliseconds(h.getMilliseconds() + 864e5 * c.expires), c.expires = h;
667
- }
668
- return r("Expires", c.expires ? c.expires.toUTCString() : "") + r("Domain", c.domain) + r("Path", c.path) + r("Secure", c.secure) + r("SameSite", c.sameSite);
669
- }(u);
670
- }
671
- function o(m) {
672
- for (var p = {}, u = m ? m.split("; ") : [], c = /(%[\dA-F]{2})+/gi, h = 0; h < u.length; h++) {
673
- var d = u[h].split("="), w = d.slice(1).join("=");
674
- w.charAt(0) === '"' && (w = w.slice(1, -1));
675
- try {
676
- p[d[0].replace(c, decodeURIComponent)] = w.replace(c, decodeURIComponent);
677
- } catch {
678
- }
679
- }
680
- return p;
681
- }
682
- function a() {
683
- return o(document.cookie);
684
- }
685
- function s(m, p, u) {
686
- document.cookie = i(m, p, n({ path: "/" }, u));
687
- }
688
- e.__esModule = !0, e.encode = i, e.parse = o, e.getAll = a, e.get = function(m) {
689
- return a()[m];
690
- }, e.set = s, e.remove = function(m, p) {
691
- s(m, "", n(n({}, p), { expires: -1 }));
692
- };
693
- });
694
- Tt(he), he.encode, he.parse, he.getAll;
695
- var zr = he.get, Nn = he.set, Ln = he.remove;
696
- const we = { get(t) {
697
- const e = zr(t);
698
- if (e !== void 0)
699
- return JSON.parse(e);
700
- }, save(t, e, n) {
701
- let r = {};
702
- window.location.protocol === "https:" && (r = { secure: !0, sameSite: "none" }), n != null && n.daysUntilExpire && (r.expires = n.daysUntilExpire), n != null && n.cookieDomain && (r.domain = n.cookieDomain), Nn(t, JSON.stringify(e), r);
703
- }, remove(t, e) {
704
- let n = {};
705
- e != null && e.cookieDomain && (n.domain = e.cookieDomain), Ln(t, n);
706
- } }, Nr = { get(t) {
707
- return we.get(t) || we.get(`_legacy_${t}`);
708
- }, save(t, e, n) {
709
- let r = {};
710
- window.location.protocol === "https:" && (r = { secure: !0 }), n != null && n.daysUntilExpire && (r.expires = n.daysUntilExpire), n != null && n.cookieDomain && (r.domain = n.cookieDomain), Nn(`_legacy_${t}`, JSON.stringify(e), r), we.save(t, e, n);
711
- }, remove(t, e) {
712
- let n = {};
713
- e != null && e.cookieDomain && (n.domain = e.cookieDomain), Ln(t, n), we.remove(t, e), we.remove(`_legacy_${t}`, e);
714
- } }, Lr = { get(t) {
715
- if (typeof sessionStorage > "u")
716
- return;
717
- const e = sessionStorage.getItem(t);
718
- return e != null ? JSON.parse(e) : void 0;
719
- }, save(t, e) {
720
- sessionStorage.setItem(t, JSON.stringify(e));
721
- }, remove(t) {
722
- sessionStorage.removeItem(t);
723
- } };
724
- function Dr(t, e, n) {
725
- var r = e === void 0 ? null : e, i = function(m, p) {
726
- var u = atob(m);
727
- if (p) {
728
- for (var c = new Uint8Array(u.length), h = 0, d = u.length; h < d; ++h)
729
- c[h] = u.charCodeAt(h);
730
- return String.fromCharCode.apply(null, new Uint16Array(c.buffer));
731
- }
732
- return u;
733
- }(t, n !== void 0 && n), o = i.indexOf(`
734
- `, 10) + 1, a = i.substring(o) + (r ? "//# sourceMappingURL=" + r : ""), s = new Blob([a], { type: "application/javascript" });
735
- return URL.createObjectURL(s);
736
- }
737
- var Mt, Xt, Ft, ht, Ur = (Mt = "Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZSBleHRlbmRzIEVycm9ye2NvbnN0cnVjdG9yKHQscil7c3VwZXIociksdGhpcy5lcnJvcj10LHRoaXMuZXJyb3JfZGVzY3JpcHRpb249cixPYmplY3Quc2V0UHJvdG90eXBlT2YodGhpcyxlLnByb3RvdHlwZSl9c3RhdGljIGZyb21QYXlsb2FkKHtlcnJvcjp0LGVycm9yX2Rlc2NyaXB0aW9uOnJ9KXtyZXR1cm4gbmV3IGUodCxyKX19Y2xhc3MgdCBleHRlbmRzIGV7Y29uc3RydWN0b3IoZSxzKXtzdXBlcigibWlzc2luZ19yZWZyZXNoX3Rva2VuIixgTWlzc2luZyBSZWZyZXNoIFRva2VuIChhdWRpZW5jZTogJyR7cihlLFsiZGVmYXVsdCJdKX0nLCBzY29wZTogJyR7cihzKX0nKWApLHRoaXMuYXVkaWVuY2U9ZSx0aGlzLnNjb3BlPXMsT2JqZWN0LnNldFByb3RvdHlwZU9mKHRoaXMsdC5wcm90b3R5cGUpfX1mdW5jdGlvbiByKGUsdD1bXSl7cmV0dXJuIGUmJiF0LmluY2x1ZGVzKGUpP2U6IiJ9ImZ1bmN0aW9uIj09dHlwZW9mIFN1cHByZXNzZWRFcnJvciYmU3VwcHJlc3NlZEVycm9yO2NvbnN0IHM9ZT0+e3ZhcntjbGllbnRJZDp0fT1lLHI9ZnVuY3Rpb24oZSx0KXt2YXIgcj17fTtmb3IodmFyIHMgaW4gZSlPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwoZSxzKSYmdC5pbmRleE9mKHMpPDAmJihyW3NdPWVbc10pO2lmKG51bGwhPWUmJiJmdW5jdGlvbiI9PXR5cGVvZiBPYmplY3QuZ2V0T3duUHJvcGVydHlTeW1ib2xzKXt2YXIgbz0wO2ZvcihzPU9iamVjdC5nZXRPd25Qcm9wZXJ0eVN5bWJvbHMoZSk7bzxzLmxlbmd0aDtvKyspdC5pbmRleE9mKHNbb10pPDAmJk9iamVjdC5wcm90b3R5cGUucHJvcGVydHlJc0VudW1lcmFibGUuY2FsbChlLHNbb10pJiYocltzW29dXT1lW3Nbb11dKX1yZXR1cm4gcn0oZSxbImNsaWVudElkIl0pO3JldHVybiBuZXcgVVJMU2VhcmNoUGFyYW1zKChlPT5PYmplY3Qua2V5cyhlKS5maWx0ZXIoKHQ9PnZvaWQgMCE9PWVbdF0pKS5yZWR1Y2UoKCh0LHIpPT5PYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30sdCkse1tyXTplW3JdfSkpLHt9KSkoT2JqZWN0LmFzc2lnbih7Y2xpZW50X2lkOnR9LHIpKSkudG9TdHJpbmcoKX07bGV0IG89e307Y29uc3Qgbj0oZSx0KT0+YCR7ZX18JHt0fWA7YWRkRXZlbnRMaXN0ZW5lcigibWVzc2FnZSIsKGFzeW5jKHtkYXRhOnt0aW1lb3V0OmUsYXV0aDpyLGZldGNoVXJsOmksZmV0Y2hPcHRpb25zOmMsdXNlRm9ybURhdGE6YX0scG9ydHM6W3BdfSk9PntsZXQgZjtjb25zdHthdWRpZW5jZTp1LHNjb3BlOmx9PXJ8fHt9O3RyeXtjb25zdCByPWE/KGU9Pntjb25zdCB0PW5ldyBVUkxTZWFyY2hQYXJhbXMoZSkscj17fTtyZXR1cm4gdC5mb3JFYWNoKCgoZSx0KT0+e3JbdF09ZX0pKSxyfSkoYy5ib2R5KTpKU09OLnBhcnNlKGMuYm9keSk7aWYoIXIucmVmcmVzaF90b2tlbiYmInJlZnJlc2hfdG9rZW4iPT09ci5ncmFudF90eXBlKXtjb25zdCBlPSgoZSx0KT0+b1tuKGUsdCldKSh1LGwpO2lmKCFlKXRocm93IG5ldyB0KHUsbCk7Yy5ib2R5PWE/cyhPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30scikse3JlZnJlc2hfdG9rZW46ZX0pKTpKU09OLnN0cmluZ2lmeShPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30scikse3JlZnJlc2hfdG9rZW46ZX0pKX1sZXQgaCxnOyJmdW5jdGlvbiI9PXR5cGVvZiBBYm9ydENvbnRyb2xsZXImJihoPW5ldyBBYm9ydENvbnRyb2xsZXIsYy5zaWduYWw9aC5zaWduYWwpO3RyeXtnPWF3YWl0IFByb21pc2UucmFjZShbKGQ9ZSxuZXcgUHJvbWlzZSgoZT0+c2V0VGltZW91dChlLGQpKSkpLGZldGNoKGksT2JqZWN0LmFzc2lnbih7fSxjKSldKX1jYXRjaChlKXtyZXR1cm4gdm9pZCBwLnBvc3RNZXNzYWdlKHtlcnJvcjplLm1lc3NhZ2V9KX1pZighZylyZXR1cm4gaCYmaC5hYm9ydCgpLHZvaWQgcC5wb3N0TWVzc2FnZSh7ZXJyb3I6IlRpbWVvdXQgd2hlbiBleGVjdXRpbmcgJ2ZldGNoJyJ9KTtmPWF3YWl0IGcuanNvbigpLGYucmVmcmVzaF90b2tlbj8oKChlLHQscik9PntvW24odCxyKV09ZX0pKGYucmVmcmVzaF90b2tlbix1LGwpLGRlbGV0ZSBmLnJlZnJlc2hfdG9rZW4pOigoZSx0KT0+e2RlbGV0ZSBvW24oZSx0KV19KSh1LGwpLHAucG9zdE1lc3NhZ2Uoe29rOmcub2ssanNvbjpmfSl9Y2F0Y2goZSl7cC5wb3N0TWVzc2FnZSh7b2s6ITEsanNvbjp7ZXJyb3I6ZS5lcnJvcixlcnJvcl9kZXNjcmlwdGlvbjplLm1lc3NhZ2V9fSl9dmFyIGR9KSl9KCk7Cgo=", Xt = null, Ft = !1, function(t) {
738
- return ht = ht || Dr(Mt, Xt, Ft), new Worker(ht, t);
739
- });
740
- const ft = {};
741
- let Rr = class {
742
- constructor(e, n) {
743
- this.cache = e, this.clientId = n, this.manifestKey = this.createManifestKeyFrom(this.clientId);
744
- }
745
- async add(e) {
746
- var n;
747
- const r = new Set(((n = await this.cache.get(this.manifestKey)) === null || n === void 0 ? void 0 : n.keys) || []);
748
- r.add(e), await this.cache.set(this.manifestKey, { keys: [...r] });
749
- }
750
- async remove(e) {
751
- const n = await this.cache.get(this.manifestKey);
752
- if (n) {
753
- const r = new Set(n.keys);
754
- return r.delete(e), r.size > 0 ? await this.cache.set(this.manifestKey, { keys: [...r] }) : await this.cache.remove(this.manifestKey);
755
- }
756
- }
757
- get() {
758
- return this.cache.get(this.manifestKey);
759
- }
760
- clear() {
761
- return this.cache.remove(this.manifestKey);
762
- }
763
- createManifestKeyFrom(e) {
764
- return `@@auth0spajs@@::${e}`;
765
- }
766
- };
767
- const Wr = { memory: () => new zn().enclosedCache, localstorage: () => new jr() }, Ht = (t) => Wr[t], Jt = (t) => {
768
- const { openUrl: e, onRedirect: n } = t, r = Q(t, ["openUrl", "onRedirect"]);
769
- return Object.assign(Object.assign({}, r), { openUrl: e === !1 || e ? e : n });
770
- }, pt = new vr();
771
- let Zr = class {
772
- constructor(e) {
773
- let n, r;
774
- if (this.userCache = new zn().enclosedCache, this.defaultOptions = { authorizationParams: { scope: "openid profile email" }, useRefreshTokensFallback: !1, useFormData: !0 }, this._releaseLockOnPageHide = async () => {
775
- await pt.releaseLock("auth0.lock.getTokenSilently"), window.removeEventListener("pagehide", this._releaseLockOnPageHide);
776
- }, this.options = Object.assign(Object.assign(Object.assign({}, this.defaultOptions), e), { authorizationParams: Object.assign(Object.assign({}, this.defaultOptions.authorizationParams), e.authorizationParams) }), typeof window < "u" && (() => {
777
- if (!Be())
778
- throw new Error("For security reasons, `window.crypto` is required to run `auth0-spa-js`.");
779
- if (Be().subtle === void 0)
780
- throw new Error(`
781
- auth0-spa-js must run on a secure origin. See https://github.com/auth0/auth0-spa-js/blob/main/FAQ.md#why-do-i-get-auth0-spa-js-must-run-on-a-secure-origin for more information.
782
- `);
783
- })(), e.cache && e.cacheLocation && console.warn("Both `cache` and `cacheLocation` options have been specified in the Auth0Client configuration; ignoring `cacheLocation` and using `cache`."), e.cache)
784
- r = e.cache;
785
- else {
786
- if (n = e.cacheLocation || "memory", !Ht(n))
787
- throw new Error(`Invalid cache location "${n}"`);
788
- r = Ht(n)();
789
- }
790
- this.httpTimeoutMs = e.httpTimeoutInSeconds ? 1e3 * e.httpTimeoutInSeconds : 1e4, this.cookieStorage = e.legacySameSiteCookie === !1 ? we : Nr, this.orgHintCookieName = `auth0.${this.options.clientId}.organization_hint`, this.isAuthenticatedCookieName = ((a) => `auth0.${a}.is.authenticated`)(this.options.clientId), this.sessionCheckExpiryDays = e.sessionCheckExpiryDays || 1;
791
- const i = e.useCookiesForTransactions ? this.cookieStorage : Lr;
792
- var o;
793
- this.scope = Xe("openid", this.options.authorizationParams.scope, this.options.useRefreshTokens ? "offline_access" : ""), this.transactionManager = new Cr(i, this.options.clientId, this.options.cookieDomain), this.nowProvider = this.options.nowProvider || On, this.cacheManager = new xr(r, r.allKeys ? void 0 : new Rr(r, this.options.clientId), this.nowProvider), this.domainUrl = (o = this.options.domain, /^https?:\/\//.test(o) ? o : `https://${o}`), this.tokenIssuer = ((a, s) => a ? a.startsWith("https://") ? a : `https://${a}/` : `${s}/`)(this.options.issuer, this.domainUrl), typeof window < "u" && window.Worker && this.options.useRefreshTokens && n === "memory" && (this.options.workerUrl ? this.worker = new Worker(this.options.workerUrl) : this.worker = new Ur());
794
- }
795
- _url(e) {
796
- const n = encodeURIComponent(btoa(JSON.stringify(this.options.auth0Client || En)));
797
- return `${this.domainUrl}${e}&auth0Client=${n}`;
798
- }
799
- _authorizeUrl(e) {
800
- return this._url(`/authorize?${_t(e)}`);
801
- }
802
- async _verifyIdToken(e, n, r) {
803
- const i = await this.nowProvider();
804
- return Ar({ iss: this.tokenIssuer, aud: this.options.clientId, id_token: e, nonce: n, organization: r, leeway: this.options.leeway, max_age: (o = this.options.authorizationParams.max_age, typeof o != "string" ? o : parseInt(o, 10) || void 0), now: i });
805
- var o;
806
- }
807
- _processOrgHint(e) {
808
- e ? this.cookieStorage.save(this.orgHintCookieName, e, { daysUntilExpire: this.sessionCheckExpiryDays, cookieDomain: this.options.cookieDomain }) : this.cookieStorage.remove(this.orgHintCookieName, { cookieDomain: this.options.cookieDomain });
809
- }
810
- async _prepareAuthorizeUrl(e, n, r) {
811
- const i = Zt(dt()), o = Zt(dt()), a = dt(), s = ((u) => {
812
- const c = new Uint8Array(u);
813
- return ((h) => {
814
- const d = { "+": "-", "/": "_", "=": "" };
815
- return h.replace(/[+/=]/g, (w) => d[w]);
816
- })(window.btoa(String.fromCharCode(...Array.from(c))));
817
- })(await (async (u) => await Be().subtle.digest({ name: "SHA-256" }, new TextEncoder().encode(u)))(a)), m = ((u, c, h, d, w, k, v, I) => Object.assign(Object.assign(Object.assign({ client_id: u.clientId }, u.authorizationParams), h), { scope: Xe(c, h.scope), response_type: "code", response_mode: I || "query", state: d, nonce: w, redirect_uri: v || u.authorizationParams.redirect_uri, code_challenge: k, code_challenge_method: "S256" }))(this.options, this.scope, e, i, o, s, e.redirect_uri || this.options.authorizationParams.redirect_uri || r, n == null ? void 0 : n.response_mode), p = this._authorizeUrl(m);
818
- return { nonce: o, code_verifier: a, scope: m.scope, audience: m.audience || "default", redirect_uri: m.redirect_uri, state: i, url: p };
819
- }
820
- async loginWithPopup(e, n) {
821
- var r;
822
- if (e = e || {}, !(n = n || {}).popup && (n.popup = ((s) => {
823
- const m = window.screenX + (window.innerWidth - 400) / 2, p = window.screenY + (window.innerHeight - 600) / 2;
824
- return window.open(s, "auth0:authorize:popup", `left=${m},top=${p},width=400,height=600,resizable,scrollbars=yes,status=1`);
825
- })(""), !n.popup))
826
- throw new Error("Unable to open a popup for loginWithPopup - window.open returned `null`");
827
- const i = await this._prepareAuthorizeUrl(e.authorizationParams || {}, { response_mode: "web_message" }, window.location.origin);
828
- n.popup.location.href = i.url;
829
- const o = await ((s) => new Promise((m, p) => {
830
- let u;
831
- const c = setInterval(() => {
832
- s.popup && s.popup.closed && (clearInterval(c), clearTimeout(h), window.removeEventListener("message", u, !1), p(new Ir(s.popup)));
833
- }, 1e3), h = setTimeout(() => {
834
- clearInterval(c), p(new kr(s.popup)), window.removeEventListener("message", u, !1);
835
- }, 1e3 * (s.timeoutInSeconds || 60));
836
- u = function(d) {
837
- if (d.data && d.data.type === "authorization_response") {
838
- if (clearTimeout(h), clearInterval(c), window.removeEventListener("message", u, !1), s.popup.close(), d.data.response.error)
839
- return p(V.fromPayload(d.data.response));
840
- m(d.data.response);
841
- }
842
- }, window.addEventListener("message", u);
843
- }))(Object.assign(Object.assign({}, n), { timeoutInSeconds: n.timeoutInSeconds || this.options.authorizeTimeoutInSeconds || 60 }));
844
- if (i.state !== o.state)
845
- throw new V("state_mismatch", "Invalid state");
846
- const a = ((r = e.authorizationParams) === null || r === void 0 ? void 0 : r.organization) || this.options.authorizationParams.organization;
847
- await this._requestToken({ audience: i.audience, scope: i.scope, code_verifier: i.code_verifier, grant_type: "authorization_code", code: o.code, redirect_uri: i.redirect_uri }, { nonceIn: i.nonce, organization: a });
848
- }
849
- async getUser() {
850
- var e;
851
- const n = await this._getIdTokenFromCache();
852
- return (e = n == null ? void 0 : n.decodedToken) === null || e === void 0 ? void 0 : e.user;
853
- }
854
- async getIdTokenClaims() {
855
- var e;
856
- const n = await this._getIdTokenFromCache();
857
- return (e = n == null ? void 0 : n.decodedToken) === null || e === void 0 ? void 0 : e.claims;
858
- }
859
- async loginWithRedirect(e = {}) {
860
- var n;
861
- const r = Jt(e), { openUrl: i, fragment: o, appState: a } = r, s = Q(r, ["openUrl", "fragment", "appState"]), m = ((n = s.authorizationParams) === null || n === void 0 ? void 0 : n.organization) || this.options.authorizationParams.organization, p = await this._prepareAuthorizeUrl(s.authorizationParams || {}), { url: u } = p, c = Q(p, ["url"]);
862
- this.transactionManager.create(Object.assign(Object.assign(Object.assign({}, c), { appState: a }), m && { organization: m }));
863
- const h = o ? `${u}#${o}` : u;
864
- i ? await i(h) : window.location.assign(h);
865
- }
866
- async handleRedirectCallback(e = window.location.href) {
867
- const n = e.split("?").slice(1);
868
- if (n.length === 0)
869
- throw new Error("There are no query params available for parsing.");
870
- const { state: r, code: i, error: o, error_description: a } = ((c) => {
871
- c.indexOf("#") > -1 && (c = c.substring(0, c.indexOf("#")));
872
- const h = new URLSearchParams(c);
873
- return { state: h.get("state"), code: h.get("code") || void 0, error: h.get("error") || void 0, error_description: h.get("error_description") || void 0 };
874
- })(n.join("")), s = this.transactionManager.get();
875
- if (!s)
876
- throw new V("missing_transaction", "Invalid state");
877
- if (this.transactionManager.remove(), o)
878
- throw new br(o, a || o, r, s.appState);
879
- if (!s.code_verifier || s.state && s.state !== r)
880
- throw new V("state_mismatch", "Invalid state");
881
- const m = s.organization, p = s.nonce, u = s.redirect_uri;
882
- return await this._requestToken(Object.assign({ audience: s.audience, scope: s.scope, code_verifier: s.code_verifier, grant_type: "authorization_code", code: i }, u ? { redirect_uri: u } : {}), { nonceIn: p, organization: m }), { appState: s.appState };
883
- }
884
- async checkSession(e) {
885
- if (!this.cookieStorage.get(this.isAuthenticatedCookieName)) {
886
- if (!this.cookieStorage.get("auth0.is.authenticated"))
887
- return;
888
- this.cookieStorage.save(this.isAuthenticatedCookieName, !0, { daysUntilExpire: this.sessionCheckExpiryDays, cookieDomain: this.options.cookieDomain }), this.cookieStorage.remove("auth0.is.authenticated");
889
- }
890
- try {
891
- await this.getTokenSilently(e);
892
- } catch {
893
- }
894
- }
895
- async getTokenSilently(e = {}) {
896
- var n;
897
- const r = Object.assign(Object.assign({ cacheMode: "on" }, e), { authorizationParams: Object.assign(Object.assign(Object.assign({}, this.options.authorizationParams), e.authorizationParams), { scope: Xe(this.scope, (n = e.authorizationParams) === null || n === void 0 ? void 0 : n.scope) }) }), i = await ((o, a) => {
898
- let s = ft[a];
899
- return s || (s = o().finally(() => {
900
- delete ft[a], s = null;
901
- }), ft[a] = s), s;
902
- })(() => this._getTokenSilently(r), `${this.options.clientId}::${r.authorizationParams.audience}::${r.authorizationParams.scope}`);
903
- return e.detailedResponse ? i : i == null ? void 0 : i.access_token;
904
- }
905
- async _getTokenSilently(e) {
906
- const { cacheMode: n } = e, r = Q(e, ["cacheMode"]);
907
- if (n !== "off") {
908
- const i = await this._getEntryFromCache({ scope: r.authorizationParams.scope, audience: r.authorizationParams.audience || "default", clientId: this.options.clientId });
909
- if (i)
910
- return i;
911
- }
912
- if (n !== "cache-only") {
913
- if (!await (async (i, o = 3) => {
914
- for (let a = 0; a < o; a++)
915
- if (await i())
916
- return !0;
917
- return !1;
918
- })(() => pt.acquireLock("auth0.lock.getTokenSilently", 5e3), 10))
919
- throw new It();
920
- try {
921
- if (window.addEventListener("pagehide", this._releaseLockOnPageHide), n !== "off") {
922
- const p = await this._getEntryFromCache({ scope: r.authorizationParams.scope, audience: r.authorizationParams.audience || "default", clientId: this.options.clientId });
923
- if (p)
924
- return p;
925
- }
926
- const i = this.options.useRefreshTokens ? await this._getTokenUsingRefreshToken(r) : await this._getTokenFromIFrame(r), { id_token: o, access_token: a, oauthTokenScope: s, expires_in: m } = i;
927
- return Object.assign(Object.assign({ id_token: o, access_token: a }, s ? { scope: s } : null), { expires_in: m });
928
- } finally {
929
- await pt.releaseLock("auth0.lock.getTokenSilently"), window.removeEventListener("pagehide", this._releaseLockOnPageHide);
930
- }
931
- }
932
- }
933
- async getTokenWithPopup(e = {}, n = {}) {
934
- var r;
935
- const i = Object.assign(Object.assign({}, e), { authorizationParams: Object.assign(Object.assign(Object.assign({}, this.options.authorizationParams), e.authorizationParams), { scope: Xe(this.scope, (r = e.authorizationParams) === null || r === void 0 ? void 0 : r.scope) }) });
936
- return n = Object.assign(Object.assign({}, wr), n), await this.loginWithPopup(i, n), (await this.cacheManager.get(new de({ scope: i.authorizationParams.scope, audience: i.authorizationParams.audience || "default", clientId: this.options.clientId }))).access_token;
937
- }
938
- async isAuthenticated() {
939
- return !!await this.getUser();
940
- }
941
- _buildLogoutUrl(e) {
942
- e.clientId !== null ? e.clientId = e.clientId || this.options.clientId : delete e.clientId;
943
- const n = e.logoutParams || {}, { federated: r } = n, i = Q(n, ["federated"]), o = r ? "&federated" : "";
944
- return this._url(`/v2/logout?${_t(Object.assign({ clientId: e.clientId }, i))}`) + o;
945
- }
946
- async logout(e = {}) {
947
- const n = Jt(e), { openUrl: r } = n, i = Q(n, ["openUrl"]);
948
- e.clientId === null ? await this.cacheManager.clear() : await this.cacheManager.clear(e.clientId || this.options.clientId), this.cookieStorage.remove(this.orgHintCookieName, { cookieDomain: this.options.cookieDomain }), this.cookieStorage.remove(this.isAuthenticatedCookieName, { cookieDomain: this.options.cookieDomain }), this.userCache.remove("@@user@@");
949
- const o = this._buildLogoutUrl(i);
950
- r ? await r(o) : r !== !1 && window.location.assign(o);
951
- }
952
- async _getTokenFromIFrame(e) {
953
- const n = Object.assign(Object.assign({}, e.authorizationParams), { prompt: "none" }), r = this.cookieStorage.get(this.orgHintCookieName);
954
- r && !n.organization && (n.organization = r);
955
- const { url: i, state: o, nonce: a, code_verifier: s, redirect_uri: m, scope: p, audience: u } = await this._prepareAuthorizeUrl(n, { response_mode: "web_message" }, window.location.origin);
956
- try {
957
- if (window.crossOriginIsolated)
958
- throw new V("login_required", "The application is running in a Cross-Origin Isolated context, silently retrieving a token without refresh token is not possible.");
959
- const c = e.timeoutInSeconds || this.options.authorizeTimeoutInSeconds, h = await ((w, k, v = 60) => new Promise((I, _) => {
960
- const y = window.document.createElement("iframe");
961
- y.setAttribute("width", "0"), y.setAttribute("height", "0"), y.style.display = "none";
962
- const l = () => {
963
- window.document.body.contains(y) && (window.document.body.removeChild(y), window.removeEventListener("message", b, !1));
964
- };
965
- let b;
966
- const T = setTimeout(() => {
967
- _(new It()), l();
968
- }, 1e3 * v);
969
- b = function(P) {
970
- if (P.origin != k || !P.data || P.data.type !== "authorization_response")
971
- return;
972
- const x = P.source;
973
- x && x.close(), P.data.response.error ? _(V.fromPayload(P.data.response)) : I(P.data.response), clearTimeout(T), window.removeEventListener("message", b, !1), setTimeout(l, 2e3);
974
- }, window.addEventListener("message", b, !1), window.document.body.appendChild(y), y.setAttribute("src", w);
975
- }))(i, this.domainUrl, c);
976
- if (o !== h.state)
977
- throw new V("state_mismatch", "Invalid state");
978
- const d = await this._requestToken(Object.assign(Object.assign({}, e.authorizationParams), { code_verifier: s, code: h.code, grant_type: "authorization_code", redirect_uri: m, timeout: e.authorizationParams.timeout || this.httpTimeoutMs }), { nonceIn: a, organization: n.organization });
979
- return Object.assign(Object.assign({}, d), { scope: p, oauthTokenScope: d.scope, audience: u });
980
- } catch (c) {
981
- throw c.error === "login_required" && this.logout({ openUrl: !1 }), c;
982
- }
983
- }
984
- async _getTokenUsingRefreshToken(e) {
985
- const n = await this.cacheManager.get(new de({ scope: e.authorizationParams.scope, audience: e.authorizationParams.audience || "default", clientId: this.options.clientId }));
986
- if (!(n && n.refresh_token || this.worker)) {
987
- if (this.options.useRefreshTokensFallback)
988
- return await this._getTokenFromIFrame(e);
989
- throw new $n(e.authorizationParams.audience || "default", e.authorizationParams.scope);
990
- }
991
- const r = e.authorizationParams.redirect_uri || this.options.authorizationParams.redirect_uri || window.location.origin, i = typeof e.timeoutInSeconds == "number" ? 1e3 * e.timeoutInSeconds : null;
992
- try {
993
- const o = await this._requestToken(Object.assign(Object.assign(Object.assign({}, e.authorizationParams), { grant_type: "refresh_token", refresh_token: n && n.refresh_token, redirect_uri: r }), i && { timeout: i }));
994
- return Object.assign(Object.assign({}, o), { scope: e.authorizationParams.scope, oauthTokenScope: o.scope, audience: e.authorizationParams.audience || "default" });
995
- } catch (o) {
996
- if ((o.message.indexOf("Missing Refresh Token") > -1 || o.message && o.message.indexOf("invalid refresh token") > -1) && this.options.useRefreshTokensFallback)
997
- return await this._getTokenFromIFrame(e);
998
- throw o;
999
- }
1000
- }
1001
- async _saveEntryInCache(e) {
1002
- const { id_token: n, decodedToken: r } = e, i = Q(e, ["id_token", "decodedToken"]);
1003
- this.userCache.set("@@user@@", { id_token: n, decodedToken: r }), await this.cacheManager.setIdToken(this.options.clientId, e.id_token, e.decodedToken), await this.cacheManager.set(i);
1004
- }
1005
- async _getIdTokenFromCache() {
1006
- const e = this.options.authorizationParams.audience || "default", n = await this.cacheManager.getIdToken(new de({ clientId: this.options.clientId, audience: e, scope: this.scope })), r = this.userCache.get("@@user@@");
1007
- return n && n.id_token === (r == null ? void 0 : r.id_token) ? r : (this.userCache.set("@@user@@", n), n);
1008
- }
1009
- async _getEntryFromCache({ scope: e, audience: n, clientId: r }) {
1010
- const i = await this.cacheManager.get(new de({ scope: e, audience: n, clientId: r }), 60);
1011
- if (i && i.access_token) {
1012
- const { access_token: o, oauthTokenScope: a, expires_in: s } = i, m = await this._getIdTokenFromCache();
1013
- return m && Object.assign(Object.assign({ id_token: m.id_token, access_token: o }, a ? { scope: a } : null), { expires_in: s });
1014
- }
1015
- }
1016
- async _requestToken(e, n) {
1017
- const { nonceIn: r, organization: i } = n || {}, o = await Tr(Object.assign({ baseUrl: this.domainUrl, client_id: this.options.clientId, auth0Client: this.options.auth0Client, useFormData: this.options.useFormData, timeout: this.httpTimeoutMs }, e), this.worker), a = await this._verifyIdToken(o.id_token, r, i);
1018
- return await this._saveEntryInCache(Object.assign(Object.assign(Object.assign(Object.assign({}, o), { decodedToken: a, scope: e.scope, audience: e.audience || "default" }), o.scope ? { oauthTokenScope: o.scope } : null), { client_id: this.options.clientId })), this.cookieStorage.save(this.isAuthenticatedCookieName, !0, { daysUntilExpire: this.sessionCheckExpiryDays, cookieDomain: this.options.cookieDomain }), this._processOrgHint(i || a.claims.org_id), Object.assign(Object.assign({}, o), { decodedToken: a });
1019
- }
1020
- };
1021
- async function Kr(t) {
1022
- const e = new Zr(t);
1023
- return await e.checkSession(), e;
1024
- }
1025
- const xt = "sesamy.com", Mr = "https://logs.sesamy.com/events";
1026
- var oe = /* @__PURE__ */ ((t) => (t.READY = "sesamyReady", t.AUTHENTICATED = "sesamyAuthenticated", t.LOGOUT = "sesamyLogout", t.SOFT_PAYWALL = "sesamySoftPaywall", t))(oe || {});
1027
- let F;
1028
- async function Xr({ clientId: t }) {
1029
- if (F = await Kr({
1030
- domain: `token.${xt}`,
1031
- clientId: t,
1032
- cacheLocation: "localstorage"
1033
- }), window.location.search.includes("code="))
1034
- try {
1035
- await F.handleRedirectCallback();
1036
- const e = await F.getUser();
1037
- rt(oe.AUTHENTICATED, e), window.history.replaceState({}, document.title, "/");
1038
- const n = await F.getTokenSilently();
1039
- localStorage.setItem("accessToken", n);
1040
- } catch {
1041
- }
1042
- }
1043
- async function Fr() {
1044
- if (!F)
1045
- throw new Error("Auth0 client not initialized");
1046
- return F.isAuthenticated();
1047
- }
1048
- async function Hr() {
1049
- if (!F)
1050
- throw new Error("Auth0 client not initialized");
1051
- return F.getUser();
1052
- }
1053
- function Jr() {
1054
- if (!F)
1055
- throw new Error("Auth0 client not initialized");
1056
- return F.loginWithRedirect({
1057
- authorizationParams: {
1058
- redirect_uri: window.location.href
1059
- }
1060
- });
1061
- }
1062
- async function Vr() {
1063
- if (!F)
1064
- throw new Error("Auth0 client not initialized");
1065
- return F.getTokenSilently();
1066
- }
1067
- async function Yr() {
1068
- if (!F)
1069
- throw new Error("Auth0 client not initialized");
1070
- return rt(oe.LOGOUT, {}), F.logout({
1071
- logoutParams: {
1072
- returnTo: window.location.href
1073
- }
1074
- });
1075
- }
1076
- const Gr = (t, e) => e.skipDedupe || e.method !== "GET", Br = (t, e) => e.method + "@" + t, qr = (t) => t.clone(), Dn = ({ skip: t = Gr, key: e = Br, resolver: n = qr } = {}) => {
1077
- const r = /* @__PURE__ */ new Map();
1078
- return (i) => (o, a) => {
1079
- if (t(o, a))
1080
- return i(o, a);
1081
- const s = e(o, a);
1082
- if (!r.has(s))
1083
- r.set(s, []);
1084
- else
1085
- return new Promise((m, p) => {
1086
- r.get(s).push([m, p]);
1087
- });
1088
- try {
1089
- return i(o, a).then((m) => (r.get(s).forEach(([p]) => p(n(m))), r.delete(s), m)).catch((m) => {
1090
- throw r.get(s).forEach(([p, u]) => u(m)), r.delete(s), m;
1091
- });
1092
- } catch (m) {
1093
- return r.delete(s), Promise.reject(m);
1094
- }
1095
- };
1096
- }, Qr = (t, e) => t * e, ei = (t) => t && t.ok, Un = ({ delayTimer: t = 500, delayRamp: e = Qr, maxAttempts: n = 10, until: r = ei, onRetry: i = null, retryOnNetworkError: o = !1, resolveWithLatestResponse: a = !1, skip: s } = {}) => (m) => (p, u) => {
1097
- let c = 0;
1098
- if (s && s(p, u))
1099
- return m(p, u);
1100
- const h = (d, w) => Promise.resolve(r(d, w)).then((k) => k ? d && a ? d : w ? Promise.reject(w) : d : (c++, !n || c <= n ? new Promise((v) => {
1101
- const I = e(t, c);
1102
- setTimeout(() => {
1103
- typeof i == "function" ? Promise.resolve(i({
1104
- response: d,
1105
- error: w,
1106
- url: p,
1107
- options: u
1108
- })).then((_ = {}) => {
1109
- var y, l;
1110
- v(m((y = _ && _.url) !== null && y !== void 0 ? y : p, (l = _ && _.options) !== null && l !== void 0 ? l : u));
1111
- }) : v(m(p, u));
1112
- }, I);
1113
- }).then(h).catch((v) => {
1114
- if (!o)
1115
- throw v;
1116
- return h(null, v);
1117
- }) : d && a ? d : Promise.reject(w || new Error("Number of attempts exceeded."))));
1118
- return m(p, u).then(h).catch((d) => {
1119
- if (!o)
1120
- throw d;
1121
- return h(null, d);
1122
- });
1123
- }, ti = "application/json", Rn = "Content-Type", ve = Symbol(), Wn = Symbol();
1124
- function Vt(t = {}) {
1125
- var e;
1126
- return (e = Object.entries(t).find(([n]) => n.toLowerCase() === Rn.toLowerCase())) === null || e === void 0 ? void 0 : e[1];
1127
- }
1128
- function Yt(t) {
1129
- return /^application\/.*json.*/.test(t);
1130
- }
1131
- const fe = function(t, e, n = !1) {
1132
- return Object.entries(e).reduce((r, [i, o]) => {
1133
- const a = t[i];
1134
- return Array.isArray(a) && Array.isArray(o) ? r[i] = n ? [...a, ...o] : o : typeof a == "object" && typeof o == "object" ? r[i] = fe(a, o, n) : r[i] = o, r;
1135
- }, { ...t });
1136
- }, Ee = {
1137
- // Default options
1138
- options: {},
1139
- // Error type
1140
- errorType: "text",
1141
- // Polyfills
1142
- polyfills: {
1143
- // fetch: null,
1144
- // FormData: null,
1145
- // URLSearchParams: null,
1146
- // performance: null,
1147
- // PerformanceObserver: null,
1148
- // AbortController: null
1149
- },
1150
- polyfill(t, e = !0, n = !1, ...r) {
1151
- const i = this.polyfills[t] || (typeof self < "u" ? self[t] : null) || (typeof global < "u" ? global[t] : null);
1152
- if (e && !i)
1153
- throw new Error(t + " is not defined");
1154
- return n && i ? new i(...r) : i;
1155
- }
1156
- };
1157
- function ni(t, e = !1) {
1158
- Ee.options = e ? t : fe(Ee.options, t);
1159
- }
1160
- function ri(t, e = !1) {
1161
- Ee.polyfills = e ? t : fe(Ee.polyfills, t);
1162
- }
1163
- function ii(t) {
1164
- Ee.errorType = t;
1165
- }
1166
- const oi = (t) => (e) => t.reduceRight((n, r) => r(n), e) || e;
1167
- class Zn extends Error {
1168
- }
1169
- const ai = (t) => {
1170
- const e = /* @__PURE__ */ Object.create(null);
1171
- t = t._addons.reduce((y, l) => l.beforeRequest && l.beforeRequest(y, t._options, e) || y, t);
1172
- const { _url: n, _options: r, _config: i, _catchers: o, _resolvers: a, _middlewares: s, _addons: m } = t, p = new Map(o), u = fe(i.options, r);
1173
- let c = n;
1174
- const h = oi(s)((y, l) => (c = y, i.polyfill("fetch")(y, l)))(n, u), d = new Error(), w = h.catch((y) => {
1175
- throw { [ve]: y };
1176
- }).then((y) => {
1177
- if (!y.ok) {
1178
- const l = new Zn();
1179
- if (l.cause = d, l.stack = l.stack + `
1180
- CAUSE: ` + d.stack, l.response = y, l.url = c, y.type === "opaque")
1181
- throw l;
1182
- return y.text().then((b) => {
1183
- var T;
1184
- if (l.message = b, i.errorType === "json" || ((T = y.headers.get("Content-Type")) === null || T === void 0 ? void 0 : T.split(";")[0]) === "application/json")
1185
- try {
1186
- l.json = JSON.parse(b);
1187
- } catch {
1188
- }
1189
- throw l.text = b, l.status = y.status, l;
1190
- });
1191
- }
1192
- return y;
1193
- }), k = (y) => y.catch((l) => {
1194
- const b = l.hasOwnProperty(ve), T = b ? l[ve] : l, P = (T == null ? void 0 : T.status) && p.get(T.status) || p.get(T == null ? void 0 : T.name) || b && p.has(ve) && p.get(ve);
1195
- if (P)
1196
- return P(T, t);
1197
- const x = p.get(Wn);
1198
- if (x)
1199
- return x(T, t);
1200
- throw T;
1201
- }), v = (y) => (l) => /* If a callback is provided, then callback with the body result otherwise return the parsed body itself. */ k(y ? w.then((b) => b && b[y]()).then((b) => l ? l(b) : b) : w.then((b) => l ? l(b) : b)), I = {
1202
- _wretchReq: t,
1203
- _fetchReq: h,
1204
- _sharedState: e,
1205
- res: v(null),
1206
- json: v("json"),
1207
- blob: v("blob"),
1208
- formData: v("formData"),
1209
- arrayBuffer: v("arrayBuffer"),
1210
- text: v("text"),
1211
- error(y, l) {
1212
- return p.set(y, l), this;
1213
- },
1214
- badRequest(y) {
1215
- return this.error(400, y);
1216
- },
1217
- unauthorized(y) {
1218
- return this.error(401, y);
1219
- },
1220
- forbidden(y) {
1221
- return this.error(403, y);
1222
- },
1223
- notFound(y) {
1224
- return this.error(404, y);
1225
- },
1226
- timeout(y) {
1227
- return this.error(408, y);
1228
- },
1229
- internalError(y) {
1230
- return this.error(500, y);
1231
- },
1232
- fetchError(y) {
1233
- return this.error(ve, y);
1234
- }
1235
- }, _ = m.reduce((y, l) => ({
1236
- ...y,
1237
- ...typeof l.resolver == "function" ? l.resolver(y) : l.resolver
1238
- }), I);
1239
- return a.reduce((y, l) => l(y, t), _);
1240
- }, si = {
1241
- _url: "",
1242
- _options: {},
1243
- _config: Ee,
1244
- _catchers: /* @__PURE__ */ new Map(),
1245
- _resolvers: [],
1246
- _deferred: [],
1247
- _middlewares: [],
1248
- _addons: [],
1249
- addon(t) {
1250
- return { ...this, _addons: [...this._addons, t], ...t.wretch };
1251
- },
1252
- errorType(t) {
1253
- return {
1254
- ...this,
1255
- _config: {
1256
- ...this._config,
1257
- errorType: t
1258
- }
1259
- };
1260
- },
1261
- polyfills(t, e = !1) {
1262
- return {
1263
- ...this,
1264
- _config: {
1265
- ...this._config,
1266
- polyfills: e ? t : fe(this._config.polyfills, t)
1267
- }
1268
- };
1269
- },
1270
- url(t, e = !1) {
1271
- if (e)
1272
- return { ...this, _url: t };
1273
- const n = this._url.split("?");
1274
- return {
1275
- ...this,
1276
- _url: n.length > 1 ? n[0] + t + "?" + n[1] : this._url + t
1277
- };
1278
- },
1279
- options(t, e = !1) {
1280
- return { ...this, _options: e ? t : fe(this._options, t) };
1281
- },
1282
- headers(t) {
1283
- const e = t ? Array.isArray(t) ? Object.fromEntries(t) : "entries" in t ? Object.fromEntries(t.entries()) : t : {};
1284
- return { ...this, _options: fe(this._options, { headers: e }) };
1285
- },
1286
- accept(t) {
1287
- return this.headers({ Accept: t });
1288
- },
1289
- content(t) {
1290
- return this.headers({ [Rn]: t });
1291
- },
1292
- auth(t) {
1293
- return this.headers({ Authorization: t });
1294
- },
1295
- catcher(t, e) {
1296
- const n = new Map(this._catchers);
1297
- return n.set(t, e), { ...this, _catchers: n };
1298
- },
1299
- catcherFallback(t) {
1300
- return this.catcher(Wn, t);
1301
- },
1302
- resolve(t, e = !1) {
1303
- return { ...this, _resolvers: e ? [t] : [...this._resolvers, t] };
1304
- },
1305
- defer(t, e = !1) {
1306
- return {
1307
- ...this,
1308
- _deferred: e ? [t] : [...this._deferred, t]
1309
- };
1310
- },
1311
- middlewares(t, e = !1) {
1312
- return {
1313
- ...this,
1314
- _middlewares: e ? t : [...this._middlewares, ...t]
1315
- };
1316
- },
1317
- fetch(t = this._options.method, e = "", n = null) {
1318
- let r = this.url(e).options({ method: t });
1319
- const i = Vt(r._options.headers), o = typeof n == "object" && (!r._options.headers || !i || Yt(i));
1320
- return r = n ? o ? r.json(n, i) : r.body(n) : r, ai(r._deferred.reduce((a, s) => s(a, a._url, a._options), r));
1321
- },
1322
- get(t = "") {
1323
- return this.fetch("GET", t);
1324
- },
1325
- delete(t = "") {
1326
- return this.fetch("DELETE", t);
1327
- },
1328
- put(t, e = "") {
1329
- return this.fetch("PUT", e, t);
1330
- },
1331
- post(t, e = "") {
1332
- return this.fetch("POST", e, t);
1333
- },
1334
- patch(t, e = "") {
1335
- return this.fetch("PATCH", e, t);
1336
- },
1337
- head(t = "") {
1338
- return this.fetch("HEAD", t);
1339
- },
1340
- opts(t = "") {
1341
- return this.fetch("OPTIONS", t);
1342
- },
1343
- body(t) {
1344
- return { ...this, _options: { ...this._options, body: t } };
1345
- },
1346
- json(t, e) {
1347
- const n = Vt(this._options.headers);
1348
- return this.content(e || Yt(n) && n || ti).body(JSON.stringify(t));
1349
- }
1350
- };
1351
- function ae(t = "", e = {}) {
1352
- return { ...si, _url: t, _options: e };
1353
- }
1354
- ae.default = ae;
1355
- ae.options = ni;
1356
- ae.errorType = ii;
1357
- ae.polyfills = ri;
1358
- ae.WretchError = Zn;
1359
- const ci = (t) => (e, n) => new Promise(async (r, i) => {
1360
- try {
1361
- const o = await Vr(), a = {
1362
- ...n,
1363
- headers: {
1364
- ...n.headers,
1365
- Authorization: `Bearer ${o}`
1366
- }
1367
- };
1368
- r(t(e, a));
1369
- } catch (o) {
1370
- console.error("Error fetching access token:", o), i(o);
1371
- }
1372
- }), ui = (t) => (e, n) => {
1373
- const r = localStorage.getItem("__anon_id"), i = btoa(`${r}:`), o = {
1374
- ...n,
1375
- headers: {
1376
- ...n.headers,
1377
- Authorization: `Basic ${i}`
1378
- }
1379
- };
1380
- return t(e, o);
1381
- }, je = ae(`https://api2.${xt}`).headers({ "Content-Type": "application/json" }).middlewares([
1382
- ci,
1383
- Dn(),
1384
- Un({
1385
- delayTimer: 1e3,
1386
- delayRamp: (t, e) => t * e,
1387
- maxAttempts: 3,
1388
- until: (t) => (t == null ? void 0 : t.ok) || !1,
1389
- retryOnNetworkError: !1
1390
- })
1391
- ]), it = ae(`https://api2.${xt}`).headers({ "Content-Type": "application/json" }).middlewares([
1392
- ui,
1393
- Dn(),
1394
- Un({
1395
- delayTimer: 1e3,
1396
- delayRamp: (t, e) => t * e,
1397
- maxAttempts: 3,
1398
- until: (t) => (t == null ? void 0 : t.ok) || !1,
1399
- retryOnNetworkError: !1
1400
- })
1401
- ]);
1402
- async function li() {
1403
- return je.get("/entitlements").json();
1404
- }
1405
- async function di(t) {
1406
- const e = await je.get("/entitlements").json();
1407
- return e == null ? void 0 : e.find((n) => n.id === t);
1408
- }
1409
- async function hi() {
1410
- return je.get("/contracts").json();
1411
- }
1412
- async function fi(t) {
1413
- const e = await je.get("/contracts").json();
1414
- return e == null ? void 0 : e.find((n) => n.id === t);
1415
- }
1416
- async function pi() {
1417
- return je.get("/bills").json();
1418
- }
1419
- async function mi(t) {
1420
- const e = await je.get("/bills").json();
1421
- return e == null ? void 0 : e.find((n) => n.id === t);
1422
- }
1423
- async function gi() {
1424
- return await it.get("/tags").json();
1425
- }
1426
- async function yi(t, e) {
1427
- return await it.url(`/tags/${t}`).put({
1428
- value: e
1429
- }).json();
1430
- }
1431
- async function vi(t, e) {
1432
- return await it.url(`/tags/${t}/push`).put({
1433
- value: e
1434
- }).json();
1435
- }
1436
- async function wi(t) {
1437
- const e = localStorage.getItem("__anon_id");
1438
- if (!e)
1439
- throw new Error("User id not found");
1440
- return it.url("/articles/access").post({
1441
- articleId: t.articleId,
1442
- userId: e
1443
- }).json();
1444
- }
1445
- async function bi(t) {
1446
- const e = await wi({ articleId: t });
1447
- return e.status !== "ok" && rt(oe.SOFT_PAYWALL, {}), e;
1448
- }
1449
- const Kn = "@sesamy/sesamy-js", Ct = "1.1.0";
1450
- function ki() {
1451
- return Ct;
1452
- }
1453
- function Ii(t = "sesamy") {
1454
- window[t] = {
1455
- auth: {
1456
- getUser: Hr,
1457
- isAuthenticated: Fr,
1458
- loginWithRedirect: Jr,
1459
- logout: Yr
1460
- },
1461
- articles: {
1462
- access: bi
1463
- },
1464
- tags: {
1465
- list: gi,
1466
- set: yi,
1467
- push: vi
1468
- },
1469
- getEntitlement: di,
1470
- getEntitlements: li,
1471
- getContract: fi,
1472
- getContracts: hi,
1473
- getBill: mi,
1474
- getBills: pi,
1475
- getVersion: ki
1476
- };
1477
- }
1478
- function Gt(t, e, n, r, i) {
1479
- for (e = e.split ? e.split(".") : e, r = 0; r < e.length; r++)
1480
- t = t ? t[e[r]] : i;
1481
- return t === i ? n : t;
1482
- }
1483
- var Fe = "undefined", Bt = "object", _i = function() {
1484
- }, Mn = "any", Xn = "*", me = "__", Qe = typeof process < "u" ? process : {};
1485
- Qe.env && Qe.env.NODE_ENV;
1486
- var Y = typeof document < "u";
1487
- Qe.versions != null && Qe.versions.node != null;
1488
- typeof Deno < "u" && Deno.core;
1489
- Y && window.name === "nodejs" || typeof navigator < "u" && navigator.userAgent !== void 0 && (navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom"));
1490
- function Fn(t, e) {
1491
- return e.charAt(0)[t]() + e.slice(1);
1492
- }
1493
- var Si = Fn.bind(null, "toUpperCase"), Ei = Fn.bind(null, "toLowerCase");
1494
- function Oi(t) {
1495
- return Hn(t) ? Si("null") : typeof t == "object" ? xi(t) : Object.prototype.toString.call(t).slice(8, -1);
1496
- }
1497
- function et(t, e) {
1498
- e === void 0 && (e = !0);
1499
- var n = Oi(t);
1500
- return e ? Ei(n) : n;
1501
- }
1502
- function Ke(t, e) {
1503
- return typeof e === t;
1504
- }
1505
- var B = Ke.bind(null, "function"), re = Ke.bind(null, "string"), be = Ke.bind(null, "undefined"), Pi = Ke.bind(null, "boolean");
1506
- Ke.bind(null, "symbol");
1507
- function Hn(t) {
1508
- return t === null;
1509
- }
1510
- function Ti(t) {
1511
- return et(t) === "number" && !isNaN(t);
1512
- }
1513
- function Jn(t) {
1514
- return et(t) === "array";
1515
- }
1516
- function X(t) {
1517
- if (!ji(t))
1518
- return !1;
1519
- for (var e = t; Object.getPrototypeOf(e) !== null; )
1520
- e = Object.getPrototypeOf(e);
1521
- return Object.getPrototypeOf(t) === e;
1522
- }
1523
- function ji(t) {
1524
- return t && (typeof t == "object" || t !== null);
1525
- }
1526
- function xi(t) {
1527
- return B(t.constructor) ? t.constructor.name : null;
1528
- }
1529
- function Ci(t) {
1530
- return t instanceof Error || re(t.message) && t.constructor && Ti(t.constructor.stackTraceLimit);
1531
- }
1532
- function Vn(t, e) {
1533
- if (typeof e != "object" || Hn(e))
1534
- return !1;
1535
- if (e instanceof t)
1536
- return !0;
1537
- var n = et(new t(""));
1538
- if (Ci(e))
1539
- for (; e; ) {
1540
- if (et(e) === n)
1541
- return !0;
1542
- e = Object.getPrototypeOf(e);
1543
- }
1544
- return !1;
1545
- }
1546
- Vn.bind(null, TypeError);
1547
- Vn.bind(null, SyntaxError);
1548
- function ot(t, e) {
1549
- var n = t instanceof Element || t instanceof HTMLDocument;
1550
- return n && e ? $i(t, e) : n;
1551
- }
1552
- function $i(t, e) {
1553
- return e === void 0 && (e = ""), t && t.nodeName === e.toUpperCase();
1554
- }
1555
- function at(t) {
1556
- var e = [].slice.call(arguments, 1);
1557
- return function() {
1558
- return t.apply(void 0, [].slice.call(arguments).concat(e));
1559
- };
1560
- }
1561
- at(ot, "form");
1562
- at(ot, "button");
1563
- at(ot, "input");
1564
- at(ot, "select");
1565
- function Ai(t) {
1566
- return t ? Jn(t) ? t : [t] : [];
1567
- }
1568
- function qt(t) {
1569
- try {
1570
- return decodeURIComponent(t.replace(/\+/g, " "));
1571
- } catch {
1572
- return null;
1573
- }
1574
- }
1575
- function zi() {
1576
- if (Y) {
1577
- var t = navigator, e = t.languages;
1578
- return t.userLanguage || (e && e.length ? e[0] : t.language);
1579
- }
1580
- }
1581
- function Ni() {
1582
- try {
1583
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
1584
- } catch {
1585
- }
1586
- }
1587
- function Li(t) {
1588
- return function(e) {
1589
- for (var n, r = /* @__PURE__ */ Object.create(null), i = /([^&=]+)=?([^&]*)/g; n = i.exec(e); ) {
1590
- var o = qt(n[1]), a = qt(n[2]);
1591
- o.substring(o.length - 2) === "[]" ? (r[o = o.substring(0, o.length - 2)] || (r[o] = [])).push(a) : r[o] = a === "" || a;
1592
- }
1593
- for (var s in r) {
1594
- var m = s.split("[");
1595
- m.length > 1 && (Di(r, m.map(function(p) {
1596
- return p.replace(/[?[\]\\ ]/g, "");
1597
- }), r[s]), delete r[s]);
1598
- }
1599
- return r;
1600
- }(function(e) {
1601
- if (e) {
1602
- var n = e.match(/\?(.*)/);
1603
- return n && n[1] ? n[1].split("#")[0] : "";
1604
- }
1605
- return Y && window.location.search.substring(1);
1606
- }(t));
1607
- }
1608
- function Di(t, e, n) {
1609
- for (var r = e.length - 1, i = 0; i < r; ++i) {
1610
- var o = e[i];
1611
- if (o === "__proto__" || o === "constructor")
1612
- break;
1613
- o in t || (t[o] = {}), t = t[o];
1614
- }
1615
- t[e[r]] = n;
1616
- }
1617
- function st() {
1618
- for (var t = "", e = 0, n = 4294967295 * Math.random() | 0; e++ < 36; ) {
1619
- var r = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"[e - 1], i = 15 & n;
1620
- t += r == "-" || r == "4" ? r : (r == "x" ? i : 3 & i | 8).toString(16), n = e % 8 == 0 ? 4294967295 * Math.random() | 0 : n >> 4;
1621
- }
1622
- return t;
1623
- }
1624
- var De = "global", Oe = me + "global" + me, Pe = typeof self === Bt && self.self === self && self || typeof global === Bt && global.global === global && global || void 0;
1625
- function ge(t) {
1626
- return Pe[Oe][t];
1627
- }
1628
- function ye(t, e) {
1629
- return Pe[Oe][t] = e;
1630
- }
1631
- function xe(t) {
1632
- delete Pe[Oe][t];
1633
- }
1634
- function Ce(t, e, n) {
1635
- var r;
1636
- try {
1637
- if ($t(t)) {
1638
- var i = window[t];
1639
- r = i[e].bind(i);
1640
- }
1641
- } catch {
1642
- }
1643
- return r || n;
1644
- }
1645
- Pe[Oe] || (Pe[Oe] = {});
1646
- var He = {};
1647
- function $t(t) {
1648
- if (typeof He[t] !== Fe)
1649
- return He[t];
1650
- try {
1651
- var e = window[t];
1652
- e.setItem(Fe, Fe), e.removeItem(Fe);
1653
- } catch {
1654
- return He[t] = !1;
1655
- }
1656
- return He[t] = !0;
1657
- }
1658
- function O() {
1659
- return O = Object.assign || function(t) {
1660
- for (var e = 1; e < arguments.length; e++) {
1661
- var n = arguments[e];
1662
- for (var r in n)
1663
- Object.prototype.hasOwnProperty.call(n, r) && (t[r] = n[r]);
1664
- }
1665
- return t;
1666
- }, O.apply(this, arguments);
1667
- }
1668
- var ne = "function", ee = "undefined", Ui = "@@redux/" + Math.random().toString(36), Qt = /* @__PURE__ */ function() {
1669
- return typeof Symbol === ne && Symbol.observable || "@@observable";
1670
- }(), Je = " != " + ne;
1671
- function Yn(t, e, n) {
1672
- var r;
1673
- if (typeof e === ne && typeof n === ee && (n = e, e = void 0), typeof n !== ee) {
1674
- if (typeof n !== ne)
1675
- throw new Error("enhancer" + Je);
1676
- return n(Yn)(t, e);
1677
- }
1678
- if (typeof t !== ne)
1679
- throw new Error("reducer" + Je);
1680
- var i = t, o = e, a = [], s = a, m = !1;
1681
- function p() {
1682
- s === a && (s = a.slice());
1683
- }
1684
- function u() {
1685
- return o;
1686
- }
1687
- function c(d) {
1688
- if (typeof d !== ne)
1689
- throw new Error("Listener" + Je);
1690
- var w = !0;
1691
- return p(), s.push(d), function() {
1692
- if (w) {
1693
- w = !1, p();
1694
- var k = s.indexOf(d);
1695
- s.splice(k, 1);
1696
- }
1697
- };
1698
- }
1699
- function h(d) {
1700
- if (!X(d))
1701
- throw new Error("Act != obj");
1702
- if (typeof d.type === ee)
1703
- throw new Error("ActType " + ee);
1704
- if (m)
1705
- throw new Error("Dispatch in reducer");
1706
- try {
1707
- m = !0, o = i(o, d);
1708
- } finally {
1709
- m = !1;
1710
- }
1711
- for (var w = a = s, k = 0; k < w.length; k++)
1712
- (0, w[k])();
1713
- return d;
1714
- }
1715
- return h({ type: "@@redux/INIT" }), (r = { dispatch: h, subscribe: c, getState: u, replaceReducer: function(d) {
1716
- if (typeof d !== ne)
1717
- throw new Error("next reducer" + Je);
1718
- i = d, h({ type: "@@redux/INIT" });
1719
- } })[Qt] = function() {
1720
- var d, w = c;
1721
- return (d = { subscribe: function(k) {
1722
- if (typeof k != "object")
1723
- throw new TypeError("Observer != obj");
1724
- function v() {
1725
- k.next && k.next(u());
1726
- }
1727
- return v(), { unsubscribe: w(v) };
1728
- } })[Qt] = function() {
1729
- return this;
1730
- }, d;
1731
- }, r;
1732
- }
1733
- function Ri(t, e) {
1734
- var n = e && e.type;
1735
- return "action " + (n && n.toString() || "?") + "reducer " + t + " returns " + ee;
1736
- }
1737
- function Te() {
1738
- var t = [].slice.call(arguments);
1739
- return t.length === 0 ? function(e) {
1740
- return e;
1741
- } : t.length === 1 ? t[0] : t.reduce(function(e, n) {
1742
- return function() {
1743
- return e(n.apply(void 0, [].slice.call(arguments)));
1744
- };
1745
- });
1746
- }
1747
- function Wi() {
1748
- var t = arguments;
1749
- return function(e) {
1750
- return function(n, r, i) {
1751
- var o, a = e(n, r, i), s = a.dispatch, m = { getState: a.getState, dispatch: function(p) {
1752
- return s(p);
1753
- } };
1754
- return o = [].slice.call(t).map(function(p) {
1755
- return p(m);
1756
- }), O({}, a, { dispatch: s = Te.apply(void 0, o)(a.dispatch) });
1757
- };
1758
- };
1759
- }
1760
- var ie = me + "anon_id", pe = me + "user_id", Ie = me + "user_traits", te = "userId", ke = "anonymousId", qe = ["bootstrap", "params", "campaign", "initializeStart", "initialize", "initializeEnd", "ready", "resetStart", "reset", "resetEnd", "pageStart", "page", "pageEnd", "pageAborted", "trackStart", "track", "trackEnd", "trackAborted", "identifyStart", "identify", "identifyEnd", "identifyAborted", "userIdChanged", "registerPlugins", "enablePlugin", "disablePlugin", "online", "offline", "setItemStart", "setItem", "setItemEnd", "setItemAborted", "removeItemStart", "removeItem", "removeItemEnd", "removeItemAborted"], Et = ["name", "EVENTS", "config", "loaded"], E = qe.reduce(function(t, e) {
1761
- return t[e] = e, t;
1762
- }, { registerPluginType: function(t) {
1763
- return "registerPlugin:" + t;
1764
- }, pluginReadyType: function(t) {
1765
- return "ready:" + t;
1766
- } }), en = /^utm_/, tn = /^an_prop_/, nn = /^an_trait_/;
1767
- function Zi(t) {
1768
- var e = t.storage.setItem;
1769
- return function(n) {
1770
- return function(r) {
1771
- return function(i) {
1772
- if (i.type === E.bootstrap) {
1773
- var o = i.params, a = i.user, s = i.persistedUser, m = i.initialUser, p = s.userId === a.userId;
1774
- s.anonymousId !== a.anonymousId && e(ie, a.anonymousId), p || e(pe, a.userId), m.traits && e(Ie, O({}, p && s.traits ? s.traits : {}, m.traits));
1775
- var u = Object.keys(i.params);
1776
- if (u.length) {
1777
- var c = o.an_uid, h = o.an_event, d = u.reduce(function(w, k) {
1778
- if (k.match(en) || k.match(/^(d|g)clid/)) {
1779
- var v = k.replace(en, "");
1780
- w.campaign[v === "campaign" ? "name" : v] = o[k];
1781
- }
1782
- return k.match(tn) && (w.props[k.replace(tn, "")] = o[k]), k.match(nn) && (w.traits[k.replace(nn, "")] = o[k]), w;
1783
- }, { campaign: {}, props: {}, traits: {} });
1784
- n.dispatch(O({ type: E.params, raw: o }, d, c ? { userId: c } : {})), c && setTimeout(function() {
1785
- return t.identify(c, d.traits);
1786
- }, 0), h && setTimeout(function() {
1787
- return t.track(h, d.props);
1788
- }, 0), Object.keys(d.campaign).length && n.dispatch({ type: E.campaign, campaign: d.campaign });
1789
- }
1790
- }
1791
- return r(i);
1792
- };
1793
- };
1794
- };
1795
- }
1796
- function Ki(t) {
1797
- return function(e, n) {
1798
- if (e === void 0 && (e = {}), n === void 0 && (n = {}), n.type === E.setItemEnd) {
1799
- if (n.key === ie)
1800
- return O({}, e, { anonymousId: n.value });
1801
- if (n.key === pe)
1802
- return O({}, e, { userId: n.value });
1803
- }
1804
- switch (n.type) {
1805
- case E.identify:
1806
- return Object.assign({}, e, { userId: n.userId, traits: O({}, e.traits, n.traits) });
1807
- case E.reset:
1808
- return [pe, ie, Ie].forEach(function(r) {
1809
- t.removeItem(r);
1810
- }), Object.assign({}, e, { userId: null, anonymousId: null, traits: {} });
1811
- default:
1812
- return e;
1813
- }
1814
- };
1815
- }
1816
- function rn(t) {
1817
- return { userId: t.getItem(pe), anonymousId: t.getItem(ie), traits: t.getItem(Ie) };
1818
- }
1819
- var Ot = function(t) {
1820
- return me + "TEMP" + me + t;
1821
- };
1822
- function Mi(t) {
1823
- var e = t.storage, n = e.setItem, r = e.removeItem, i = e.getItem;
1824
- return function(o) {
1825
- return function(a) {
1826
- return function(s) {
1827
- var m = s.userId, p = s.traits, u = s.options;
1828
- if (s.type === E.reset && ([pe, Ie, ie].forEach(function(d) {
1829
- r(d);
1830
- }), [te, ke, "traits"].forEach(function(d) {
1831
- xe(Ot(d));
1832
- })), s.type === E.identify) {
1833
- i(ie) || n(ie, st());
1834
- var c = i(pe), h = i(Ie) || {};
1835
- c && c !== m && o.dispatch({ type: E.userIdChanged, old: { userId: c, traits: h }, new: { userId: m, traits: p }, options: u }), m && n(pe, m), p && n(Ie, O({}, h, p));
1836
- }
1837
- return a(s);
1838
- };
1839
- };
1840
- };
1841
- }
1842
- var Le = {};
1843
- function on(t, e) {
1844
- Le[t] && B(Le[t]) && (Le[t](e), delete Le[t]);
1845
- }
1846
- function Gn(t, e, n) {
1847
- return new Promise(function(r, i) {
1848
- return e() ? r(t) : n < 1 ? i(O({}, t, { queue: !0 })) : new Promise(function(o) {
1849
- return setTimeout(o, 10);
1850
- }).then(function(o) {
1851
- return Gn(t, e, n - 10).then(r, i);
1852
- });
1853
- });
1854
- }
1855
- function Xi(t) {
1856
- return { abort: t };
1857
- }
1858
- function Bn(t, e, n) {
1859
- var r = {}, i = e(), o = t.getState(), a = o.plugins, s = o.queue, m = o.user;
1860
- if (!o.context.offline && s && s.actions && s.actions.length) {
1861
- var p = s.actions.reduce(function(c, h, d) {
1862
- return a[h.plugin].loaded ? (c.process.push(h), c.processIndex.push(d)) : (c.requeue.push(h), c.requeueIndex.push(d)), c;
1863
- }, { processIndex: [], process: [], requeue: [], requeueIndex: [] });
1864
- if (p.processIndex && p.processIndex.length) {
1865
- p.processIndex.forEach(function(c) {
1866
- var h = s.actions[c], d = h.plugin, w = h.payload.type, k = i[d][w];
1867
- if (k && B(k)) {
1868
- var v, I = function(l, b) {
1869
- return l === void 0 && (l = {}), b === void 0 && (b = {}), [te, ke].reduce(function(T, P) {
1870
- return l.hasOwnProperty(P) && b[P] && b[P] !== l[P] && (T[P] = b[P]), T;
1871
- }, l);
1872
- }(h.payload, m), _ = r[I.meta.rid];
1873
- if (!_ && (v = k({ payload: I, config: a[d].config, instance: n, abort: Xi })) && X(v) && v.abort)
1874
- return void (r[I.meta.rid] = !0);
1875
- if (!_) {
1876
- var y = w + ":" + d;
1877
- t.dispatch(O({}, I, { type: y, _: { called: y, from: "queueDrain" } }));
1878
- }
1879
- }
1880
- });
1881
- var u = s.actions.filter(function(c, h) {
1882
- return !~p.processIndex.indexOf(h);
1883
- });
1884
- s.actions = u;
1885
- }
1886
- }
1887
- }
1888
- var mt = function(t) {
1889
- var e = t.data, n = t.action, r = t.instance, i = t.state, o = t.allPlugins, a = t.allMatches, s = t.store, m = t.EVENTS;
1890
- try {
1891
- var p = i.plugins, u = i.context, c = n.type, h = c.match(_e), d = e.exact.map(function(v) {
1892
- return v.pluginName;
1893
- });
1894
- h && (d = a.during.map(function(v) {
1895
- return v.pluginName;
1896
- }));
1897
- var w = /* @__PURE__ */ function(v, I) {
1898
- return function(_, y, l) {
1899
- var b = y.config, T = y.name, P = T + "." + _.type;
1900
- l && (P = l.event);
1901
- var x = _.type.match(_e) ? /* @__PURE__ */ function(D, L, H, U, J) {
1902
- return function(W, j) {
1903
- var K = U ? U.name : D, M = j && Ze(j) ? j : H;
1904
- if (U && (!(M = j && Ze(j) ? j : [D]).includes(D) || M.length !== 1))
1905
- throw new Error("Method " + L + " can only abort " + D + " plugin. " + JSON.stringify(M) + " input valid");
1906
- return O({}, J, { abort: { reason: W, plugins: M, caller: L, _: K } });
1907
- };
1908
- }(T, P, I, l, _) : /* @__PURE__ */ function(D, L) {
1909
- return function() {
1910
- throw new Error(D.type + " action not cancellable. Remove abort in " + L);
1911
- };
1912
- }(_, P);
1913
- return { payload: Fi(_), instance: v, config: b || {}, abort: x };
1914
- };
1915
- }(r, d), k = e.exact.reduce(function(v, I) {
1916
- var _ = I.pluginName, y = I.methodName, l = !1;
1917
- return y.match(/^initialize/) || y.match(/^reset/) || (l = !p[_].loaded), u.offline && y.match(/^(page|track|identify)/) && (l = !0), v["" + _] = l, v;
1918
- }, {});
1919
- return Promise.resolve(e.exact.reduce(function(v, I, _) {
1920
- try {
1921
- var y = I.pluginName;
1922
- return Promise.resolve(v).then(function(l) {
1923
- function b() {
1924
- return Promise.resolve(l);
1925
- }
1926
- var T = function() {
1927
- if (e.namespaced && e.namespaced[y])
1928
- return Promise.resolve(e.namespaced[y].reduce(function(P, x, D) {
1929
- try {
1930
- return Promise.resolve(P).then(function(L) {
1931
- return x.method && B(x.method) ? (function(W, j) {
1932
- var K = hn(W);
1933
- if (K && K.name === j) {
1934
- var M = hn(K.method);
1935
- throw new Error([j + " plugin is calling method " + W, "Plugins cant call self", "Use " + K.method + " " + (M ? "or " + M.method : "") + " in " + j + " plugin insteadof " + W].join(`
1936
- `));
1937
- }
1938
- }(x.methodName, x.pluginName), Promise.resolve(x.method({ payload: L, instance: r, abort: (H = L, U = y, J = x.pluginName, function(W, j) {
1939
- return O({}, H, { abort: { reason: W, plugins: j || [U], caller: c, from: J || U } });
1940
- }), config: cn(x.pluginName, p, o), plugins: p })).then(function(W) {
1941
- var j = X(W) ? W : {};
1942
- return Promise.resolve(O({}, L, j));
1943
- })) : L;
1944
- var H, U, J;
1945
- });
1946
- } catch (L) {
1947
- return Promise.reject(L);
1948
- }
1949
- }, Promise.resolve(n))).then(function(P) {
1950
- l[y] = P;
1951
- });
1952
- l[y] = n;
1953
- }();
1954
- return T && T.then ? T.then(b) : b();
1955
- });
1956
- } catch (l) {
1957
- return Promise.reject(l);
1958
- }
1959
- }, Promise.resolve({}))).then(function(v) {
1960
- return Promise.resolve(e.exact.reduce(function(I, _, y) {
1961
- try {
1962
- var l = e.exact.length === y + 1, b = _.pluginName, T = o[b];
1963
- return Promise.resolve(I).then(function(P) {
1964
- var x = v[b] ? v[b] : {};
1965
- if (h && (x = P), yt(x, b))
1966
- return gt({ data: x, method: c, instance: r, pluginName: b, store: s }), Promise.resolve(P);
1967
- if (yt(P, b))
1968
- return l && gt({ data: P, method: c, instance: r, store: s }), Promise.resolve(P);
1969
- if (k.hasOwnProperty(b) && k[b] === !0)
1970
- return s.dispatch({ type: "queue", plugin: b, payload: x, _: { called: "queue", from: "queueMechanism" } }), Promise.resolve(P);
1971
- var D = w(v[b], o[b]);
1972
- return Promise.resolve(T[c]({ abort: D.abort, payload: x, instance: r, config: cn(b, p, o), plugins: p })).then(function(L) {
1973
- var H = X(L) ? L : {}, U = O({}, P, H), J = v[b];
1974
- if (yt(J, b))
1975
- gt({ data: J, method: c, instance: r, pluginName: b, store: s });
1976
- else {
1977
- var W = c + ":" + b;
1978
- (W.match(/:/g) || []).length < 2 && !c.match(an) && !c.match(sn) && r.dispatch(O({}, h ? U : x, { type: W, _: { called: W, from: "submethod" } }));
1979
- }
1980
- return Promise.resolve(U);
1981
- });
1982
- });
1983
- } catch (P) {
1984
- return Promise.reject(P);
1985
- }
1986
- }, Promise.resolve(n))).then(function(I) {
1987
- if (!(c.match(_e) || c.match(/^registerPlugin/) || c.match(sn) || c.match(an) || c.match(/^params/) || c.match(/^userIdChanged/))) {
1988
- if (m.plugins.includes(c), I._ && I._.originalAction === c)
1989
- return I;
1990
- var _ = O({}, I, { _: { originalAction: I.type, called: I.type, from: "engineEnd" } });
1991
- qn(I, e.exact.length) && !c.match(/End$/) && (_ = O({}, _, { type: I.type + "Aborted" })), s.dispatch(_);
1992
- }
1993
- return I;
1994
- });
1995
- });
1996
- } catch (v) {
1997
- return Promise.reject(v);
1998
- }
1999
- }, _e = /Start$/, an = /^bootstrap/, sn = /^ready/;
2000
- function gt(t) {
2001
- var e = t.pluginName, n = t.method + "Aborted" + (e ? ":" + e : "");
2002
- t.store.dispatch(O({}, t.data, { type: n, _: { called: n, from: "abort" } }));
2003
- }
2004
- function cn(t, e, n) {
2005
- var r = e[t] || n[t];
2006
- return r && r.config ? r.config : {};
2007
- }
2008
- function un(t, e) {
2009
- return e.reduce(function(n, r) {
2010
- return r[t] ? n.concat({ methodName: t, pluginName: r.name, method: r[t] }) : n;
2011
- }, []);
2012
- }
2013
- function ln(t, e) {
2014
- var n = t.replace(_e, ""), r = e ? ":" + e : "";
2015
- return ["" + t + r, "" + n + r, n + "End" + r];
2016
- }
2017
- function yt(t, e) {
2018
- var n = t.abort;
2019
- return !!n && (n === !0 || dn(n, e) || n && dn(n.plugins, e));
2020
- }
2021
- function qn(t, e) {
2022
- var n = t.abort;
2023
- if (!n)
2024
- return !1;
2025
- if (n === !0 || re(n))
2026
- return !0;
2027
- var r = n.plugins;
2028
- return Ze(n) && n.length === e || Ze(r) && r.length === e;
2029
- }
2030
- function Ze(t) {
2031
- return Array.isArray(t);
2032
- }
2033
- function dn(t, e) {
2034
- return !(!t || !Ze(t)) && t.includes(e);
2035
- }
2036
- function hn(t) {
2037
- var e = t.match(/(.*):(.*)/);
2038
- return !!e && { method: e[1], name: e[2] };
2039
- }
2040
- function Fi(t) {
2041
- return Object.keys(t).reduce(function(e, n) {
2042
- return n === "type" || (e[n] = X(t[n]) ? Object.assign({}, t[n]) : t[n]), e;
2043
- }, {});
2044
- }
2045
- function Hi(t, e, n) {
2046
- var r = {};
2047
- return function(i) {
2048
- return function(o) {
2049
- return function(a) {
2050
- try {
2051
- var s, m = function(l) {
2052
- return s ? l : o(c);
2053
- }, p = a.type, u = a.plugins, c = a;
2054
- if (a.abort)
2055
- return Promise.resolve(o(a));
2056
- if (p === E.enablePlugin && i.dispatch({ type: E.initializeStart, plugins: u, disabled: [], fromEnable: !0, meta: a.meta }), p === E.disablePlugin && setTimeout(function() {
2057
- return on(a.meta.rid, { payload: a });
2058
- }, 0), p === E.initializeEnd) {
2059
- var h = e(), d = Object.keys(h), w = d.filter(function(l) {
2060
- return u.includes(l);
2061
- }).map(function(l) {
2062
- return h[l];
2063
- }), k = [], v = [], I = a.disabled, _ = w.map(function(l) {
2064
- var b = l.loaded, T = l.name, P = l.config;
2065
- return Gn(l, function() {
2066
- return b({ config: P });
2067
- }, 1e4).then(function(x) {
2068
- return r[T] || (i.dispatch({ type: E.pluginReadyType(T), name: T, events: Object.keys(l).filter(function(D) {
2069
- return !Et.includes(D);
2070
- }) }), r[T] = !0), k = k.concat(T), l;
2071
- }).catch(function(x) {
2072
- if (x instanceof Error)
2073
- throw new Error(x);
2074
- return v = v.concat(x.name), x;
2075
- });
2076
- });
2077
- Promise.all(_).then(function(l) {
2078
- var b = { plugins: k, failed: v, disabled: I };
2079
- setTimeout(function() {
2080
- d.length === _.length + I.length && i.dispatch(O({}, { type: E.ready }, b));
2081
- }, 0);
2082
- });
2083
- }
2084
- var y = function() {
2085
- if (p !== E.bootstrap)
2086
- return /^ready:([^:]*)$/.test(p) && setTimeout(function() {
2087
- return Bn(i, e, t);
2088
- }, 0), Promise.resolve(function(l, b, T, P, x) {
2089
- try {
2090
- var D = B(b) ? b() : b, L = l.type, H = L.replace(_e, "");
2091
- if (l._ && l._.called)
2092
- return Promise.resolve(l);
2093
- var U = T.getState(), J = (K = D, (M = U.plugins) === void 0 && (M = {}), ($e = l.options) === void 0 && ($e = {}), Object.keys(K).filter(function(f) {
2094
- var g = $e.plugins || {};
2095
- return Pi(g[f]) ? g[f] : g.all !== !1 && (!M[f] || M[f].enabled !== !1);
2096
- }).map(function(f) {
2097
- return K[f];
2098
- }));
2099
- L === E.initializeStart && l.fromEnable && (J = Object.keys(U.plugins).filter(function(f) {
2100
- var g = U.plugins[f];
2101
- return l.plugins.includes(f) && !g.initialized;
2102
- }).map(function(f) {
2103
- return D[f];
2104
- }));
2105
- var W = J.map(function(f) {
2106
- return f.name;
2107
- }), j = function(f, g, S) {
2108
- var C = ln(f).map(function($) {
2109
- return un($, g);
2110
- });
2111
- return g.reduce(function($, A) {
2112
- var Z = A.name, N = ln(f, Z).map(function(Ae) {
2113
- return un(Ae, g);
2114
- }), R = N[0], z = N[1], q = N[2];
2115
- return R.length && ($.beforeNS[Z] = R), z.length && ($.duringNS[Z] = z), q.length && ($.afterNS[Z] = q), $;
2116
- }, { before: C[0], beforeNS: {}, during: C[1], duringNS: {}, after: C[2], afterNS: {} });
2117
- }(L, J);
2118
- return Promise.resolve(mt({ action: l, data: { exact: j.before, namespaced: j.beforeNS }, state: U, allPlugins: D, allMatches: j, instance: T, store: P, EVENTS: x })).then(function(f) {
2119
- function g() {
2120
- var $ = function() {
2121
- if (L.match(_e))
2122
- return Promise.resolve(mt({ action: O({}, S, { type: H + "End" }), data: { exact: j.after, namespaced: j.afterNS }, state: U, allPlugins: D, allMatches: j, instance: T, store: P, EVENTS: x })).then(function(A) {
2123
- A.meta && A.meta.hasCallback && on(A.meta.rid, { payload: A });
2124
- });
2125
- }();
2126
- return $ && $.then ? $.then(function() {
2127
- return f;
2128
- }) : f;
2129
- }
2130
- if (qn(f, W.length))
2131
- return f;
2132
- var S, C = function() {
2133
- if (L !== H)
2134
- return Promise.resolve(mt({ action: O({}, f, { type: H }), data: { exact: j.during, namespaced: j.duringNS }, state: U, allPlugins: D, allMatches: j, instance: T, store: P, EVENTS: x })).then(function($) {
2135
- S = $;
2136
- });
2137
- S = f;
2138
- }();
2139
- return C && C.then ? C.then(g) : g();
2140
- });
2141
- } catch (f) {
2142
- return Promise.reject(f);
2143
- }
2144
- var K, M, $e;
2145
- }(a, e, t, i, n)).then(function(l) {
2146
- return s = 1, o(l);
2147
- });
2148
- }();
2149
- return Promise.resolve(y && y.then ? y.then(m) : m(y));
2150
- } catch (l) {
2151
- return Promise.reject(l);
2152
- }
2153
- };
2154
- };
2155
- };
2156
- }
2157
- function Ji(t) {
2158
- return function(e) {
2159
- return function(n) {
2160
- return function(r) {
2161
- var i = r.type, o = r.key, a = r.value, s = r.options;
2162
- if (i === E.setItem || i === E.removeItem) {
2163
- if (r.abort)
2164
- return n(r);
2165
- i === E.setItem ? t.setItem(o, a, s) : t.removeItem(o, s);
2166
- }
2167
- return n(r);
2168
- };
2169
- };
2170
- };
2171
- }
2172
- var Vi = function() {
2173
- var t = this;
2174
- this.before = [], this.after = [], this.addMiddleware = function(e, n) {
2175
- t[n] = t[n].concat(e);
2176
- }, this.removeMiddleware = function(e, n) {
2177
- var r = t[n].findIndex(function(i) {
2178
- return i === e;
2179
- });
2180
- r !== -1 && (t[n] = [].concat(t[n].slice(0, r), t[n].slice(r + 1)));
2181
- }, this.dynamicMiddlewares = function(e) {
2182
- return function(n) {
2183
- return function(r) {
2184
- return function(i) {
2185
- var o = { getState: n.getState, dispatch: function(s) {
2186
- return n.dispatch(s);
2187
- } }, a = t[e].map(function(s) {
2188
- return s(o);
2189
- });
2190
- return Te.apply(void 0, a)(r)(i);
2191
- };
2192
- };
2193
- };
2194
- };
2195
- };
2196
- function Yi(t) {
2197
- return function(e, n) {
2198
- e === void 0 && (e = {});
2199
- var r = {};
2200
- if (n.type === "initialize:aborted")
2201
- return e;
2202
- if (/^registerPlugin:([^:]*)$/.test(n.type)) {
2203
- var i = fn(n.type, "registerPlugin"), o = t()[i];
2204
- if (!o || !i)
2205
- return e;
2206
- var a = n.enabled, s = o.config;
2207
- return r[i] = { enabled: a, initialized: !!a && !o.initialize, loaded: !!a && !!o.loaded({ config: s }), config: s }, O({}, e, r);
2208
- }
2209
- if (/^initialize:([^:]*)$/.test(n.type)) {
2210
- var m = fn(n.type, E.initialize), p = t()[m];
2211
- return p && m ? (r[m] = O({}, e[m], { initialized: !0, loaded: !!p.loaded({ config: p.config }) }), O({}, e, r)) : e;
2212
- }
2213
- if (/^ready:([^:]*)$/.test(n.type))
2214
- return r[n.name] = O({}, e[n.name], { loaded: !0 }), O({}, e, r);
2215
- switch (n.type) {
2216
- case E.disablePlugin:
2217
- return O({}, e, pn(n.plugins, !1, e));
2218
- case E.enablePlugin:
2219
- return O({}, e, pn(n.plugins, !0, e));
2220
- default:
2221
- return e;
2222
- }
2223
- };
2224
- }
2225
- function fn(t, e) {
2226
- return t.substring(e.length + 1, t.length);
2227
- }
2228
- function pn(t, e, n) {
2229
- return t.reduce(function(r, i) {
2230
- return r[i] = O({}, n[i], { enabled: e }), r;
2231
- }, n);
2232
- }
2233
- function Qn(t) {
2234
- try {
2235
- return JSON.parse(JSON.stringify(t));
2236
- } catch {
2237
- }
2238
- return t;
2239
- }
2240
- var Gi = { last: {}, history: [] };
2241
- function Bi(t, e) {
2242
- t === void 0 && (t = Gi);
2243
- var n = e.options, r = e.meta;
2244
- if (e.type === E.track) {
2245
- var i = Qn(O({ event: e.event, properties: e.properties }, Object.keys(n).length && { options: n }, { meta: r }));
2246
- return O({}, t, { last: i, history: t.history.concat(i) });
2247
- }
2248
- return t;
2249
- }
2250
- var qi = { actions: [] };
2251
- function Qi(t, e) {
2252
- t === void 0 && (t = qi);
2253
- var n = e.payload;
2254
- switch (e.type) {
2255
- case "queue":
2256
- var r;
2257
- return r = n && n.type && n.type === E.identify ? [e].concat(t.actions) : t.actions.concat(e), O({}, t, { actions: r });
2258
- case "dequeue":
2259
- return [];
2260
- default:
2261
- return t;
2262
- }
2263
- }
2264
- var er = /#.*$/;
2265
- function eo(t) {
2266
- var e = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g.exec(t);
2267
- return "/" + (e && e[3] ? e[3].split("?")[0].replace(er, "") : "");
2268
- }
2269
- var tr, nr, rr, ir, to = function(t) {
2270
- if (t === void 0 && (t = {}), !Y)
2271
- return t;
2272
- var e = document, n = e.title, r = e.referrer, i = window, o = i.location, a = i.innerWidth, s = i.innerHeight, m = o.hash, p = o.search, u = function(h) {
2273
- var d = function() {
2274
- if (Y) {
2275
- for (var w, k = document.getElementsByTagName("link"), v = 0; w = k[v]; v++)
2276
- if (w.getAttribute("rel") === "canonical")
2277
- return w.getAttribute("href");
2278
- }
2279
- }();
2280
- return d ? d.match(/\?/) ? d : d + h : window.location.href.replace(er, "");
2281
- }(p), c = { title: n, url: u, path: eo(u), hash: m, search: p, width: a, height: s };
2282
- return r && r !== "" && (c.referrer = r), O({}, c, t);
2283
- }, no = { last: {}, history: [] };
2284
- function ro(t, e) {
2285
- t === void 0 && (t = no);
2286
- var n = e.options;
2287
- if (e.type === E.page) {
2288
- var r = Qn(O({ properties: e.properties, meta: e.meta }, Object.keys(n).length && { options: n }));
2289
- return O({}, t, { last: r, history: t.history.concat(r) });
2290
- }
2291
- return t;
2292
- }
2293
- tr = function() {
2294
- if (!Y)
2295
- return !1;
2296
- var t = navigator.appVersion;
2297
- return ~t.indexOf("Win") ? "Windows" : ~t.indexOf("Mac") ? "MacOS" : ~t.indexOf("X11") ? "UNIX" : ~t.indexOf("Linux") ? "Linux" : "Unknown OS";
2298
- }(), nr = Y ? document.referrer : null, rr = zi(), ir = Ni();
2299
- var mn = { initialized: !1, sessionId: st(), app: null, version: null, debug: !1, offline: !!Y && !navigator.onLine, os: { name: tr }, userAgent: Y ? navigator.userAgent : "node", library: { name: "analytics", version: "0.12.7" }, timezone: ir, locale: rr, campaign: {}, referrer: nr };
2300
- function io(t, e) {
2301
- t === void 0 && (t = mn);
2302
- var n = t.initialized, r = e.campaign;
2303
- switch (e.type) {
2304
- case E.campaign:
2305
- return O({}, t, { campaign: r });
2306
- case E.offline:
2307
- return O({}, t, { offline: !0 });
2308
- case E.online:
2309
- return O({}, t, { offline: !1 });
2310
- default:
2311
- return n ? t : O({}, mn, t, { initialized: !0 });
2312
- }
2313
- }
2314
- var oo = ["plugins", "reducers", "storage"];
2315
- function ao(t, e, n) {
2316
- if (Y) {
2317
- var r = window[(n ? "add" : "remove") + "EventListener"];
2318
- t.split(" ").forEach(function(i) {
2319
- r(i, e);
2320
- });
2321
- }
2322
- }
2323
- function so(t) {
2324
- var e = ao.bind(null, "online offline", function(n) {
2325
- return Promise.resolve(!navigator.onLine).then(t);
2326
- });
2327
- return e(!0), function(n) {
2328
- return e(!1);
2329
- };
2330
- }
2331
- function or() {
2332
- return ye("analytics", []), function(t) {
2333
- return function(e, n, r) {
2334
- var i = t(e, n, r), o = i.dispatch;
2335
- return Object.assign(i, { dispatch: function(a) {
2336
- return Pe[Oe].analytics.push(a.action || a), o(a);
2337
- } });
2338
- };
2339
- };
2340
- }
2341
- function gn(t) {
2342
- return function() {
2343
- return Te(Te.apply(null, arguments), or());
2344
- };
2345
- }
2346
- function vt(t) {
2347
- return t ? Jn(t) ? t : [t] : [];
2348
- }
2349
- function yn(t, e, n) {
2350
- t === void 0 && (t = {});
2351
- var r, i, o = st();
2352
- return e && (Le[o] = (r = e, i = function(a) {
2353
- for (var s, m = a || Array.prototype.slice.call(arguments), p = 0; p < m.length; p++)
2354
- if (B(m[p])) {
2355
- s = m[p];
2356
- break;
2357
- }
2358
- return s;
2359
- }(n), function(a) {
2360
- i && i(a), r(a);
2361
- })), O({}, t, { rid: o, ts: (/* @__PURE__ */ new Date()).getTime() }, e ? { hasCallback: !0 } : {});
2362
- }
2363
- function co(t) {
2364
- t === void 0 && (t = {});
2365
- var e = t.reducers || {}, n = t.initialUser || {}, r = (t.plugins || []).reduce(function(f, g) {
2366
- if (B(g))
2367
- return f.middlewares = f.middlewares.concat(g), f;
2368
- if (g.NAMESPACE && (g.name = g.NAMESPACE), !g.name)
2369
- throw new Error("https://lytics.dev/errors/1");
2370
- g.config || (g.config = {});
2371
- var S = g.EVENTS ? Object.keys(g.EVENTS).map(function(A) {
2372
- return g.EVENTS[A];
2373
- }) : [];
2374
- f.pluginEnabled[g.name] = !(g.enabled === !1 || g.config.enabled === !1), delete g.enabled, g.methods && (f.methods[g.name] = Object.keys(g.methods).reduce(function(A, Z) {
2375
- var N;
2376
- return A[Z] = (N = g.methods[Z], function() {
2377
- for (var R = Array.prototype.slice.call(arguments), z = new Array(N.length), q = 0; q < R.length; q++)
2378
- z[q] = R[q];
2379
- return z[z.length] = b, N.apply({ instance: b }, z);
2380
- }), A;
2381
- }, {}), delete g.methods);
2382
- var C = Object.keys(g).concat(S), $ = new Set(f.events.concat(C));
2383
- if (f.events = Array.from($), f.pluginsArray = f.pluginsArray.concat(g), f.plugins[g.name])
2384
- throw new Error(g.name + "AlreadyLoaded");
2385
- return f.plugins[g.name] = g, f.plugins[g.name].loaded || (f.plugins[g.name].loaded = function() {
2386
- return !0;
2387
- }), f;
2388
- }, { plugins: {}, pluginEnabled: {}, methods: {}, pluginsArray: [], middlewares: [], events: [] }), i = t.storage ? t.storage : { getItem: ge, setItem: ye, removeItem: xe }, o = /* @__PURE__ */ function(f) {
2389
- return function(g, S, C) {
2390
- return S.getState("user")[g] || (C && X(C) && C[g] ? C[g] : rn(f)[g] || ge(Ot(g)) || null);
2391
- };
2392
- }(i), a = r.plugins, s = r.events.filter(function(f) {
2393
- return !Et.includes(f);
2394
- }).sort(), m = new Set(s.concat(qe).filter(function(f) {
2395
- return !Et.includes(f);
2396
- })), p = Array.from(m).sort(), u = function() {
2397
- return a;
2398
- }, c = new Vi(), h = c.addMiddleware, d = c.removeMiddleware, w = c.dynamicMiddlewares, k = function() {
2399
- throw new Error("Abort disabled inListener");
2400
- }, v = Li(), I = rn(i), _ = O({}, I, n, v.an_uid ? { userId: v.an_uid } : {}, v.an_aid ? { anonymousId: v.an_aid } : {});
2401
- _.anonymousId || (_.anonymousId = st());
2402
- var y = O({ enable: function(f, g) {
2403
- return new Promise(function(S) {
2404
- j.dispatch({ type: E.enablePlugin, plugins: vt(f), _: { originalAction: E.enablePlugin } }, S, [g]);
2405
- });
2406
- }, disable: function(f, g) {
2407
- return new Promise(function(S) {
2408
- j.dispatch({ type: E.disablePlugin, plugins: vt(f), _: { originalAction: E.disablePlugin } }, S, [g]);
2409
- });
2410
- } }, r.methods), l = !1, b = { identify: function(f, g, S, C) {
2411
- try {
2412
- var $ = re(f) ? f : null, A = X(f) ? f : g, Z = S || {}, N = b.user();
2413
- ye(Ot(te), $);
2414
- var R = $ || A.userId || o(te, b, A);
2415
- return Promise.resolve(new Promise(function(z) {
2416
- j.dispatch(O({ type: E.identifyStart, userId: R, traits: A || {}, options: Z, anonymousId: N.anonymousId }, N.id && N.id !== $ && { previousId: N.id }), z, [g, S, C]);
2417
- }));
2418
- } catch (z) {
2419
- return Promise.reject(z);
2420
- }
2421
- }, track: function(f, g, S, C) {
2422
- try {
2423
- var $ = X(f) ? f.event : f;
2424
- if (!$ || !re($))
2425
- throw new Error("EventMissing");
2426
- var A = X(f) ? f : g || {}, Z = X(S) ? S : {};
2427
- return Promise.resolve(new Promise(function(N) {
2428
- j.dispatch({ type: E.trackStart, event: $, properties: A, options: Z, userId: o(te, b, g), anonymousId: o(ke, b, g) }, N, [g, S, C]);
2429
- }));
2430
- } catch (N) {
2431
- return Promise.reject(N);
2432
- }
2433
- }, page: function(f, g, S) {
2434
- try {
2435
- var C = X(f) ? f : {}, $ = X(g) ? g : {};
2436
- return Promise.resolve(new Promise(function(A) {
2437
- j.dispatch({ type: E.pageStart, properties: to(C), options: $, userId: o(te, b, C), anonymousId: o(ke, b, C) }, A, [f, g, S]);
2438
- }));
2439
- } catch (A) {
2440
- return Promise.reject(A);
2441
- }
2442
- }, user: function(f) {
2443
- if (f === te || f === "id")
2444
- return o(te, b);
2445
- if (f === ke || f === "anonId")
2446
- return o(ke, b);
2447
- var g = b.getState("user");
2448
- return f ? Gt(g, f) : g;
2449
- }, reset: function(f) {
2450
- return new Promise(function(g) {
2451
- j.dispatch({ type: E.resetStart }, g, f);
2452
- });
2453
- }, ready: function(f) {
2454
- return l && f({ plugins: y, instance: b }), b.on(E.ready, function(g) {
2455
- f(g), l = !0;
2456
- });
2457
- }, on: function(f, g) {
2458
- if (!f || !B(g))
2459
- return !1;
2460
- if (f === E.bootstrap)
2461
- throw new Error(".on disabled for " + f);
2462
- var S = /Start$|Start:/;
2463
- if (f === "*") {
2464
- var C = function(N) {
2465
- return function(R) {
2466
- return function(z) {
2467
- return z.type.match(S) && g({ payload: z, instance: b, plugins: a }), R(z);
2468
- };
2469
- };
2470
- }, $ = function(N) {
2471
- return function(R) {
2472
- return function(z) {
2473
- return z.type.match(S) || g({ payload: z, instance: b, plugins: a }), R(z);
2474
- };
2475
- };
2476
- };
2477
- return h(C, Ve), h($, Ye), function() {
2478
- d(C, Ve), d($, Ye);
2479
- };
2480
- }
2481
- var A = f.match(S) ? Ve : Ye, Z = function(N) {
2482
- return function(R) {
2483
- return function(z) {
2484
- return z.type === f && g({ payload: z, instance: b, plugins: a, abort: k }), R(z);
2485
- };
2486
- };
2487
- };
2488
- return h(Z, A), function() {
2489
- return d(Z, A);
2490
- };
2491
- }, once: function(f, g) {
2492
- if (!f || !B(g))
2493
- return !1;
2494
- if (f === E.bootstrap)
2495
- throw new Error(".once disabled for " + f);
2496
- var S = b.on(f, function(C) {
2497
- g({ payload: C.payload, instance: b, plugins: a, abort: k }), S();
2498
- });
2499
- return S;
2500
- }, getState: function(f) {
2501
- var g = j.getState();
2502
- return f ? Gt(g, f) : Object.assign({}, g);
2503
- }, dispatch: function(f) {
2504
- var g = re(f) ? { type: f } : f;
2505
- if (qe.includes(g.type))
2506
- throw new Error("reserved action " + g.type);
2507
- var S = O({}, g, { _: O({ originalAction: g.type }, f._ || {}) });
2508
- j.dispatch(S);
2509
- }, enablePlugin: y.enable, disablePlugin: y.disable, plugins: y, storage: { getItem: i.getItem, setItem: function(f, g, S) {
2510
- j.dispatch({ type: E.setItemStart, key: f, value: g, options: S });
2511
- }, removeItem: function(f, g) {
2512
- j.dispatch({ type: E.removeItemStart, key: f, options: g });
2513
- } }, setAnonymousId: function(f, g) {
2514
- b.storage.setItem(ie, f, g);
2515
- }, events: { core: qe, plugins: s } }, T = r.middlewares.concat([function(f) {
2516
- return function(g) {
2517
- return function(S) {
2518
- return S.meta || (S.meta = yn()), g(S);
2519
- };
2520
- };
2521
- }, w(Ve), Hi(b, u, { all: p, plugins: s }), Ji(i), Zi(b), Mi(b), w(Ye)]), P = { context: io, user: Ki(i), page: ro, track: Bi, plugins: Yi(u), queue: Qi }, x = Te, D = Te;
2522
- if (Y && t.debug) {
2523
- var L = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
2524
- L && (x = L({ trace: !0, traceLimit: 25 })), D = function() {
2525
- return arguments.length === 0 ? or() : X(typeof arguments[0]) ? gn() : gn().apply(null, arguments);
2526
- };
2527
- }
2528
- var H, U = function(f) {
2529
- return Object.keys(f).reduce(function(g, S) {
2530
- return oo.includes(S) || (g[S] = f[S]), g;
2531
- }, {});
2532
- }(t), J = r.pluginsArray.reduce(function(f, g) {
2533
- var S = g.name, C = g.config, $ = g.loaded, A = r.pluginEnabled[S];
2534
- return f[S] = { enabled: A, initialized: !!A && !g.initialize, loaded: !!$({ config: C }), config: C }, f;
2535
- }, {}), W = { context: U, user: _, plugins: J }, j = Yn(function(f) {
2536
- for (var g = Object.keys(f), S = {}, C = 0; C < g.length; C++) {
2537
- var $ = g[C];
2538
- typeof f[$] === ne && (S[$] = f[$]);
2539
- }
2540
- var A, Z = Object.keys(S);
2541
- try {
2542
- (function(N) {
2543
- Object.keys(N).forEach(function(R) {
2544
- var z = N[R];
2545
- if (typeof z(void 0, { type: "@@redux/INIT" }) === ee || typeof z(void 0, { type: Ui }) === ee)
2546
- throw new Error("reducer " + R + " " + ee);
2547
- });
2548
- })(S);
2549
- } catch (N) {
2550
- A = N;
2551
- }
2552
- return function(N, R) {
2553
- if (N === void 0 && (N = {}), A)
2554
- throw A;
2555
- for (var z = !1, q = {}, Ae = 0; Ae < Z.length; Ae++) {
2556
- var Me = Z[Ae], Rt = N[Me], lt = (0, S[Me])(Rt, R);
2557
- if (typeof lt === ee) {
2558
- var mr = Ri(Me, R);
2559
- throw new Error(mr);
2560
- }
2561
- q[Me] = lt, z = z || lt !== Rt;
2562
- }
2563
- return z ? q : N;
2564
- };
2565
- }(O({}, P, e)), W, D(x(Wi.apply(void 0, T))));
2566
- j.dispatch = (H = j.dispatch, function(f, g, S) {
2567
- var C = O({}, f, { meta: yn(f.meta, g, vt(S)) });
2568
- return H.apply(null, [C]);
2569
- });
2570
- var K = Object.keys(a);
2571
- j.dispatch({ type: E.bootstrap, plugins: K, config: U, params: v, user: _, initialUser: n, persistedUser: I });
2572
- var M = K.filter(function(f) {
2573
- return r.pluginEnabled[f];
2574
- }), $e = K.filter(function(f) {
2575
- return !r.pluginEnabled[f];
2576
- });
2577
- return j.dispatch({ type: E.registerPlugins, plugins: K, enabled: r.pluginEnabled }), r.pluginsArray.map(function(f, g) {
2578
- var S = f.bootstrap, C = f.config, $ = f.name;
2579
- S && B(S) && S({ instance: b, config: C, payload: f }), j.dispatch({ type: E.registerPluginType($), name: $, enabled: r.pluginEnabled[$], plugin: f }), r.pluginsArray.length === g + 1 && j.dispatch({ type: E.initializeStart, plugins: M, disabled: $e });
2580
- }), so(function(f) {
2581
- j.dispatch({ type: f ? E.offline : E.online });
2582
- }), function(f, g, S) {
2583
- setInterval(function() {
2584
- return Bn(f, g, S);
2585
- }, 3e3);
2586
- }(j, u, b), b;
2587
- }
2588
- var Ve = "before", Ye = "after", Ue = "cookie", le = cr(), ar = ct, uo = ct;
2589
- function sr(t) {
2590
- return le ? ct(t, "", -1) : xe(t);
2591
- }
2592
- function cr() {
2593
- if (le !== void 0)
2594
- return le;
2595
- var t = "cookiecookie";
2596
- try {
2597
- ct(t, t), le = document.cookie.indexOf(t) !== -1, sr(t);
2598
- } catch {
2599
- le = !1;
2600
- }
2601
- return le;
2602
- }
2603
- function ct(t, e, n, r, i, o) {
2604
- if (typeof window < "u") {
2605
- var a = arguments.length > 1;
2606
- return le === !1 && (a ? ye(t, e) : ge(t)), a ? document.cookie = t + "=" + encodeURIComponent(e) + (n ? "; expires=" + new Date(+/* @__PURE__ */ new Date() + 1e3 * n).toUTCString() + (r ? "; path=" + r : "") + (i ? "; domain=" + i : "") + (o ? "; secure" : "") : "") : decodeURIComponent((("; " + document.cookie).split("; " + t + "=")[1] || "").split(";")[0]);
2607
- }
2608
- }
2609
- var Re = "localStorage", lo = $t.bind(null, "localStorage");
2610
- Ce("localStorage", "getItem", ge);
2611
- Ce("localStorage", "setItem", ye);
2612
- Ce("localStorage", "removeItem", xe);
2613
- var We = "sessionStorage", ho = $t.bind(null, "sessionStorage");
2614
- Ce("sessionStorage", "getItem", ge);
2615
- Ce("sessionStorage", "setItem", ye);
2616
- Ce("sessionStorage", "removeItem", xe);
2617
- function Se(t) {
2618
- var e = t;
2619
- try {
2620
- if ((e = JSON.parse(t)) === "true")
2621
- return !0;
2622
- if (e === "false")
2623
- return !1;
2624
- if (X(e))
2625
- return e;
2626
- parseFloat(e) === e && (e = parseFloat(e));
2627
- } catch {
2628
- }
2629
- if (e !== null && e !== "")
2630
- return e;
2631
- }
2632
- var fo = lo(), po = ho(), mo = cr();
2633
- function ur(t, e) {
2634
- if (t) {
2635
- var n = At(e), r = !Dt(n), i = zt(n) ? Se(localStorage.getItem(t)) : void 0;
2636
- if (r && !be(i))
2637
- return i;
2638
- var o = Nt(n) ? Se(ar(t)) : void 0;
2639
- if (r && o)
2640
- return o;
2641
- var a = Lt(n) ? Se(sessionStorage.getItem(t)) : void 0;
2642
- if (r && a)
2643
- return a;
2644
- var s = ge(t);
2645
- return r ? s : { localStorage: i, sessionStorage: a, cookie: o, global: s };
2646
- }
2647
- }
2648
- function go(t, e, n) {
2649
- if (t && !be(e)) {
2650
- var r = {}, i = At(n), o = JSON.stringify(e), a = !Dt(i);
2651
- return zt(i) && (r[Re] = Ge(Re, e, Se(localStorage.getItem(t))), localStorage.setItem(t, o), a) ? r[Re] : Nt(i) && (r[Ue] = Ge(Ue, e, Se(ar(t))), uo(t, o), a) ? r[Ue] : Lt(i) && (r[We] = Ge(We, e, Se(sessionStorage.getItem(t))), sessionStorage.setItem(t, o), a) ? r[We] : (r[De] = Ge(De, e, ge(t)), ye(t, e), a ? r[De] : r);
2652
- }
2653
- }
2654
- function yo(t, e) {
2655
- if (t) {
2656
- var n = At(e), r = ur(t, Xn), i = {};
2657
- return !be(r.localStorage) && zt(n) && (localStorage.removeItem(t), i[Re] = r.localStorage), !be(r.cookie) && Nt(n) && (sr(t), i[Ue] = r.cookie), !be(r.sessionStorage) && Lt(n) && (sessionStorage.removeItem(t), i[We] = r.sessionStorage), !be(r.global) && ut(n, De) && (xe(t), i[De] = r.global), i;
2658
- }
2659
- }
2660
- function At(t) {
2661
- return t ? re(t) ? t : t.storage : Mn;
2662
- }
2663
- function zt(t) {
2664
- return fo && ut(t, Re);
2665
- }
2666
- function Nt(t) {
2667
- return mo && ut(t, Ue);
2668
- }
2669
- function Lt(t) {
2670
- return po && ut(t, We);
2671
- }
2672
- function Dt(t) {
2673
- return t === Xn || t === "all";
2674
- }
2675
- function ut(t, e) {
2676
- return t === Mn || t === e || Dt(t);
2677
- }
2678
- function Ge(t, e, n) {
2679
- return { location: t, current: e, previous: n };
2680
- }
2681
- var vo = { setItem: go, getItem: ur, removeItem: yo };
2682
- function wo(t, e, n) {
2683
- return e in t ? Object.defineProperty(t, e, {
2684
- value: n,
2685
- enumerable: !0,
2686
- configurable: !0,
2687
- writable: !0
2688
- }) : t[e] = n, t;
2689
- }
2690
- function vn(t, e) {
2691
- var n = Object.keys(t);
2692
- if (Object.getOwnPropertySymbols) {
2693
- var r = Object.getOwnPropertySymbols(t);
2694
- e && (r = r.filter(function(i) {
2695
- return Object.getOwnPropertyDescriptor(t, i).enumerable;
2696
- })), n.push.apply(n, r);
2697
- }
2698
- return n;
2699
- }
2700
- function wn(t) {
2701
- for (var e = 1; e < arguments.length; e++) {
2702
- var n = arguments[e] != null ? arguments[e] : {};
2703
- e % 2 ? vn(Object(n), !0).forEach(function(r) {
2704
- wo(t, r, n[r]);
2705
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(n)) : vn(Object(n)).forEach(function(r) {
2706
- Object.defineProperty(t, r, Object.getOwnPropertyDescriptor(n, r));
2707
- });
2708
- }
2709
- return t;
2710
- }
2711
- function bo() {
2712
- var t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, e = {
2713
- storage: vo
2714
- };
2715
- return co(wn(wn({}, e), t));
2716
- }
2717
- function ko(t, e) {
2718
- e = e || {};
2719
- var n, r, i = [], o = e.max || 1 / 0;
2720
- function a() {
2721
- clearInterval(n), t(i.splice(0, o)), s();
2722
- }
2723
- function s() {
2724
- n = setInterval(a, e.interval || 1e4);
2725
- }
2726
- return s(), {
2727
- flush: a,
2728
- push: function(m) {
2729
- return r = i.push(m), r >= o && a(), r;
2730
- },
2731
- size: function() {
2732
- return i.length;
2733
- },
2734
- end: function(m) {
2735
- m && a(), clearInterval(n);
2736
- }
2737
- };
2738
- }
2739
- function Io(t) {
2740
- if (!(typeof window > "u")) {
2741
- var e = window, n = e.addEventListener, r = e.history, i = e.location, o = i.pathname;
2742
- n("popstate", function() {
2743
- return t(i.pathname);
2744
- }), ["push", "replace"].map(function(a) {
2745
- var s = "".concat(a, "State"), m = r[s];
2746
- r[s] = function() {
2747
- var p = arguments, u = So(arguments[2]);
2748
- return o !== u && (o = u, setTimeout(function() {
2749
- return t(p[2]);
2750
- }, 0)), m.apply(r, arguments);
2751
- };
2752
- });
2753
- }
2754
- }
2755
- function _o(t, e) {
2756
- var n = t.indexOf(e);
2757
- return n > -1 ? t.slice(0, n) : t;
2758
- }
2759
- function So(t) {
2760
- return ["#", "?"].forEach(function(e) {
2761
- return t = _o(t, e);
2762
- }), t;
2763
- }
2764
- function Eo() {
2765
- Io(() => {
2766
- ce.page();
2767
- });
2768
- }
2769
- var bn = "EventListener";
2770
- function Oo(t) {
2771
- return function(e, n, r, i) {
2772
- var o = r || _i, a = i || !1;
2773
- if (!Y)
2774
- return o;
2775
- var s = tt(n), m = tt(e, !0);
2776
- if (!m.length)
2777
- throw new Error("noElements");
2778
- if (!s.length)
2779
- throw new Error("noEvent");
2780
- var p = [];
2781
- return function u(c) {
2782
- c && (p = []);
2783
- for (var h = c ? "add" + bn : "remove" + bn, d = 0; d < m.length; d++) {
2784
- var w = m[d];
2785
- p[d] = c ? a && a.once ? Po(o) : o : p[d] || o;
2786
- for (var k = 0; k < s.length; k++)
2787
- w[h] ? w["on" + s[k]] = c ? p[d] : null : w[h](s[k], p[d], a);
2788
- }
2789
- return u.bind(null, !c);
2790
- }(t);
2791
- };
2792
- }
2793
- function tt(t, e) {
2794
- if (re(t))
2795
- return e ? tt(document.querySelectorAll(t)) : (n = t).split(n.indexOf(",") > -1 ? "," : " ").map(function(a) {
2796
- return a.trim();
2797
- });
2798
- var n;
2799
- if (NodeList.prototype.isPrototypeOf(t)) {
2800
- for (var r = [], i = t.length >>> 0; i--; )
2801
- r[i] = t[i];
2802
- return r;
2803
- }
2804
- var o = Ai(t);
2805
- return e ? o.map(function(a) {
2806
- return re(a) ? tt(a, !0) : a;
2807
- }).flat() : o;
2808
- }
2809
- function Po(t, e) {
2810
- var n;
2811
- return function() {
2812
- return t && (n = t.apply(e || this, arguments), t = null), n;
2813
- };
2814
- }
2815
- var wt = Oo("Event");
2816
- function lr(t, e) {
2817
- return Y && B(window[t]) ? (n = window[t], r = e, (i = window) === void 0 && (i = null), B(n) ? function() {
2818
- n.apply(i, arguments), r.apply(i, arguments);
2819
- } : r) : window[t] = e;
2820
- var n, r, i;
2821
- }
2822
- lr.bind(null, "onerror");
2823
- lr.bind(null, "onload");
2824
- var dr = typeof window > "u", kn = "hidden";
2825
- function To(t) {
2826
- if (dr)
2827
- return !1;
2828
- var e = jo(), n = "".concat(e.replace(/[H|h]idden/, ""), "visibilitychange"), r = function() {
2829
- return t(!!document[e]);
2830
- }, i = function() {
2831
- return document.addEventListener(n, r);
2832
- };
2833
- return i(), function() {
2834
- return document.removeEventListener(n, r), i;
2835
- };
2836
- }
2837
- function jo() {
2838
- var t = ["webkit", "moz", "ms", "o"];
2839
- return dr || kn in document ? kn : t.reduce(function(e, n) {
2840
- var r = n + "Hidden";
2841
- return !e && r in document ? r : e;
2842
- }, null);
2843
- }
2844
- var xo = ["mousemove", "mousedown", "touchmove", "touchstart", "touchend", "keydown"];
2845
- function Co(t, e) {
2846
- e === void 0 && (e = {});
2847
- var n = /* @__PURE__ */ function(a, s) {
2848
- var m = this, p = !1;
2849
- return function(u) {
2850
- p || (a.call(m, u), p = !0, setTimeout(function() {
2851
- return p = !1;
2852
- }, s));
2853
- };
2854
- }(t, e.throttle || 1e4), r = [];
2855
- function i() {
2856
- var a = To(function(s) {
2857
- s || n({ type: "tabVisible" });
2858
- });
2859
- return r = [a].concat(xo.map(function(s) {
2860
- return wt(document, s, n);
2861
- })).concat(wt(window, "load", n)).concat(wt(window, "scroll", n, { capture: !0, passive: !0 })), o;
2862
- }
2863
- function o() {
2864
- r.map(function(a) {
2865
- return a();
2866
- });
2867
- }
2868
- return i(), function() {
2869
- return o(), i;
2870
- };
2871
- }
2872
- function $o(t) {
2873
- var e, n, r = t.onIdle, i = t.onWakeUp, o = t.onHeartbeat, a = t.timeout, s = a === void 0 ? 1e4 : a, m = t.throttle, p = m === void 0 ? 2e3 : m, u = !1, c = !1, h = /* @__PURE__ */ new Date(), d = function() {
2874
- return clearTimeout(e);
2875
- };
2876
- function w(v) {
2877
- d(), o && !u && o(Ne(h), v), i && u && (u = !1, i(Ne(n), v), h = /* @__PURE__ */ new Date()), e = setTimeout(function() {
2878
- u = !0, r && (n = /* @__PURE__ */ new Date(), r(Ne(h), v));
2879
- }, s);
2880
- }
2881
- var k = Co(w, { throttle: p });
2882
- return { disable: function() {
2883
- c = !0, u = !1, d();
2884
- var v = k();
2885
- return function() {
2886
- return c = !1, h = /* @__PURE__ */ new Date(), w({ type: "load" }), v();
2887
- };
2888
- }, getStatus: function() {
2889
- return { isIdle: u, isDisabled: c, active: u ? 0 : Ne(h, c), idle: u ? Ne(n, c) : 0 };
2890
- } };
2891
- }
2892
- function Ne(t, e) {
2893
- return e ? 0 : Math.round((/* @__PURE__ */ new Date() - t) / 1e3);
2894
- }
2895
- const In = 5e3;
2896
- class Ao {
2897
- constructor(e) {
2898
- G(this, "element");
2899
- G(this, "isInViewport", !1);
2900
- G(this, "isAwake", !1);
2901
- G(this, "isFlushing");
2902
- G(this, "observer");
2903
- G(this, "lastEventAt", Date.now());
2904
- G(this, "registeredView", !1);
2905
- G(this, "viewCallback");
2906
- G(this, "activeDurationCallback");
2907
- G(this, "idleDurationCallback");
2908
- this.element = e.element, this.viewCallback = e.viewCallback, this.activeDurationCallback = e.activeDurationCallback, this.idleDurationCallback = e.idleDurationCallback, this.observer = new IntersectionObserver(
2909
- (n) => {
2910
- n.forEach((r) => {
2911
- this.handleInViewPort(r.isIntersecting);
2912
- });
2913
- },
2914
- {
2915
- threshold: 0
2916
- }
2917
- ), this.observer.observe(this.element), $o({
2918
- onIdle: (n) => this.handleAwake(!1, n),
2919
- onWakeUp: (n) => this.handleAwake(!0, n),
2920
- timeout: In
2921
- });
2922
- }
2923
- /**
2924
- * Flush the awake timer in case the page is unloading
2925
- */
2926
- flush() {
2927
- this.isFlushing = !0, this.handleAwake(!this.isAwake, Math.round((Date.now() - this.lastEventAt) / 1e3));
2928
- }
2929
- handleInViewPort(e) {
2930
- e ? (this.isAwake = !0, this.trackInViewport()) : this.handleAwake(!1, Math.round((Date.now() - this.lastEventAt) / 1e3)), this.isInViewport = e;
2931
- }
2932
- handleAwake(e, n) {
2933
- this.isAwake = e, this.lastEventAt = e ? Date.now() - n * In : Date.now(), this.isInViewport && this.trackAwake(e, n);
2934
- }
2935
- trackAwake(e, n) {
2936
- !e && this.activeDurationCallback && this.activeDurationCallback(n, this.isFlushing), e && this.idleDurationCallback && this.idleDurationCallback(n, this.isFlushing);
2937
- }
2938
- trackInViewport() {
2939
- this.registeredView || (this.registeredView = !0, this.viewCallback && this.viewCallback());
2940
- }
2941
- }
2942
- const _n = "sesamy_session_id";
2943
- function zo() {
2944
- let t = sessionStorage.getItem(_n);
2945
- return t || (t = Math.random().toString(36).slice(2, 9), sessionStorage.setItem(_n, t)), t;
2946
- }
2947
- let hr = !1, Pt, Sn, nt;
2948
- function No({ clientId: t, enabled: e = !0, endpoint: n = Mr }) {
2949
- if (Pt = t, Sn = e, nt = n, !Sn)
2950
- return;
2951
- Eo();
2952
- const r = new Ao({
2953
- element: document.body,
2954
- viewCallback: () => {
2955
- ce.page();
2956
- },
2957
- activeDurationCallback: (i, o) => {
2958
- ce.track("activeDuration", {
2959
- duration: i,
2960
- flushing: o
2961
- });
2962
- },
2963
- idleDurationCallback: (i, o) => {
2964
- ce.track("idleDuration", {
2965
- duration: i,
2966
- flushing: o
2967
- });
2968
- }
2969
- });
2970
- Do(document.body, () => {
2971
- r.flush();
2972
- }), window.addEventListener(oe.AUTHENTICATED, async (i) => {
2973
- const o = i;
2974
- await ce.identify(o.detail.sub);
2975
- }), window.addEventListener(oe.LOGOUT, async () => {
2976
- await ce.track("logout", {}), Ut.flush(), await ce.reset();
2977
- });
2978
- }
2979
- function fr(t) {
2980
- return JSON.stringify(
2981
- t.map((e) => ({
2982
- ...e,
2983
- clientId: Pt,
2984
- requestId: Math.random().toString(36).slice(2, 9),
2985
- sessionId: zo(),
2986
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2987
- version: Ct,
2988
- event: e.event,
2989
- context: {
2990
- page: {
2991
- url: window.location.hostname,
2992
- path: window.location.pathname,
2993
- title: document.title,
2994
- search: window.location.search,
2995
- referrer: document.referrer
2996
- },
2997
- locale: navigator.language,
2998
- library: Kn,
2999
- userAgent: navigator.userAgent,
3000
- clientId: Pt
3001
- }
3002
- }))
3003
- );
3004
- }
3005
- const Ut = ko(
3006
- async (t) => {
3007
- if (t.length > 0) {
3008
- const e = fr(t);
3009
- hr ? navigator.sendBeacon(nt, e) : (await fetch(nt, {
3010
- method: "POST",
3011
- body: e,
3012
- headers: {
3013
- "Content-Type": "text/plain"
3014
- }
3015
- })).ok;
3016
- }
3017
- },
3018
- {
3019
- max: 10,
3020
- // limit
3021
- interval: 3e3
3022
- // 3s
3023
- }
3024
- );
3025
- function bt(t) {
3026
- var e;
3027
- if (t.anonymousId)
3028
- if ((e = t.properties) != null && e.flushing) {
3029
- const n = { ...t };
3030
- delete n.properties.flushing, navigator.sendBeacon(nt, fr([n]));
3031
- } else
3032
- Ut.push(t);
3033
- }
3034
- const ce = bo({
3035
- app: Kn,
3036
- version: Ct,
3037
- plugins: [
3038
- {
3039
- name: "custom-analytics-plugin",
3040
- page: ({ payload: t }) => {
3041
- const { properties: e, anonymousId: n, userId: r, event: i } = t;
3042
- bt({
3043
- anonymousId: n,
3044
- userId: r,
3045
- properties: e,
3046
- event: i,
3047
- type: "page"
3048
- });
3049
- },
3050
- track: ({ payload: t }) => {
3051
- const { properties: e, anonymousId: n, userId: r, event: i } = t;
3052
- bt({
3053
- anonymousId: n,
3054
- userId: r,
3055
- properties: e,
3056
- event: i,
3057
- type: "track"
3058
- });
3059
- },
3060
- identify: ({ payload: t }) => {
3061
- const { properties: e, anonymousId: n, userId: r } = t;
3062
- bt({
3063
- anonymousId: n,
3064
- userId: r,
3065
- properties: e,
3066
- type: "identify"
3067
- });
3068
- }
3069
- }
3070
- ]
3071
- });
3072
- function Lo() {
3073
- return hr = !0, Ut.flush();
3074
- }
3075
- const pr = /* @__PURE__ */ new Map();
3076
- function Do(t, e) {
3077
- pr.set(t, e);
3078
- }
3079
- window.addEventListener("beforeunload", () => {
3080
- pr.forEach((t, e) => {
3081
- t.bind(e)();
3082
- }), Lo();
3083
- });
3084
- async function Uo(t) {
3085
- No({
3086
- clientId: t.clientId,
3087
- // The default client id can be overridden by the config
3088
- ...t.analytics
3089
- }), await Xr(t), Ii(t.namespace), rt(oe.READY, {});
3090
- }
3091
- if (typeof document < "u") {
3092
- const t = document.getElementById("sesamy-js");
3093
- if (t != null && t.textContent)
3094
- try {
3095
- const e = JSON.parse(t.textContent);
3096
- Uo(e);
3097
- } catch (e) {
3098
- console.error("Failed to parse config", e);
3099
- }
3100
- }
3101
- const Ro = "/sesamy.png";
3102
- class Wo extends HTMLElement {
3103
- constructor() {
3104
- super();
3105
- G(this, "user");
3106
- }
3107
- async _handleProfile() {
3108
- this.user = await window.sesamy.auth.getUser(), this.render();
3109
- }
3110
- async connectedCallback() {
3111
- if (this.setupEventListeners(), !window.sesamy) {
3112
- window.addEventListener(oe.READY, () => this._handleProfile());
3113
- return;
3114
- }
3115
- this._handleProfile();
3116
- }
3117
- render() {
3118
- this.innerHTML = `
3119
- <div>
3120
- <a href="https://docs.sesamy.com" target="_blank">
3121
- <img src="${Ro}" class="logo" alt="Vite logo" />
3122
- </a>
3123
- <h1>Sesamy JS</h1>
3124
- <p class="read-the-docs">
3125
- Click on the Sesamy logo to learn more
3126
- </p>
3127
- ${this.user ? this.renderUserProfile() : this.renderLoginButton()}
3128
- </div>
3129
- `;
3130
- }
3131
- renderLoginButton() {
3132
- return '<button part="login-btn" class="login auth-visible" id="login-btn"> Login </button>';
3133
- }
3134
- renderUserProfile() {
3135
- var n, r;
3136
- return `<div class="user" part="user">
3137
- <a href="/profile" part="user-link">
3138
- ${(n = this.user) != null && n.picture ? ` <img
3139
- class="big"
3140
- part="user-img img-big"
3141
- src=${this.user.picture}
3142
- alt=${this.user.name || "User avatar"}
3143
- />` : '<div part="avatar avatar-big" class="avatar big"> Placeholder </div>'}
3144
- <h2 class="user-name">${((r = this.user) == null ? void 0 : r.name) || "User Name"}</h2>
3145
- </a>
3146
-
3147
- <div class="logout-wrap">
3148
- <a href="#" class="logout-btn" id="logout-btn"> Logout </a>
3149
- </div>
3150
- <div>
3151
- <a href="/entitlements.html">
3152
- View Entitlements
3153
- </a>
3154
- </div>
3155
- <div>
3156
- <a href="/contracts.html">
3157
- View Contracts
3158
- </a>
3159
- </div>
3160
- </div>`;
3161
- }
3162
- setupEventListeners() {
3163
- this.addEventListener("click", (n) => {
3164
- const r = n.target, i = r.closest("#logout-btn"), o = r.closest("#login-btn");
3165
- i && window.sesamy.auth.logout(), o && window.sesamy.auth.loginWithRedirect();
3166
- });
3167
- }
3168
- }
3169
- customElements.define("sesamy-app", Wo);