UNPKG

@wandelbots/wandelbots-js-react-components

Version:

React UI toolkit for building applications on top of the Wandelbots platform

915 lines • 51.8 kB
function I(r, e) { var t = {}; for (var i in r) Object.prototype.hasOwnProperty.call(r, i) && e.indexOf(i) < 0 && (t[i] = r[i]); if (r != null && typeof Object.getOwnPropertySymbols == "function") { var o = 0; for (i = Object.getOwnPropertySymbols(r); o < i.length; o++) e.indexOf(i[o]) < 0 && Object.prototype.propertyIsEnumerable.call(r, i[o]) && (t[i[o]] = r[i[o]]); } return t; } var C = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function J(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } function F(r, e) { return r(e = { exports: {} }, e.exports), e.exports; } var j = F(function(r, e) { Object.defineProperty(e, "__esModule", { value: !0 }); var t = function() { function i() { var o = this; this.locked = /* @__PURE__ */ new Map(), this.addToLocked = function(n, u) { var d = o.locked.get(n); d === void 0 ? u === void 0 ? o.locked.set(n, []) : o.locked.set(n, [u]) : u !== void 0 && (d.unshift(u), o.locked.set(n, d)); }, this.isLocked = function(n) { return o.locked.has(n); }, this.lock = function(n) { return new Promise(function(u, d) { o.isLocked(n) ? o.addToLocked(n, u) : (o.addToLocked(n), u()); }); }, this.unlock = function(n) { var u = o.locked.get(n); if (u !== void 0 && u.length !== 0) { var d = u.pop(); o.locked.set(n, u), d !== void 0 && setTimeout(d, 0); } else o.locked.delete(n); }; } return i.getInstance = function() { return i.instance === void 0 && (i.instance = new i()), i.instance; }, i; }(); e.default = function() { return t.getInstance(); }; }); J(j); var ce = J(F(function(r, e) { var t = C && C.__awaiter || function(a, s, c, l) { return new (c || (c = Promise))(function(h, w) { function g(y) { try { v(l.next(y)); } catch (m) { w(m); } } function k(y) { try { v(l.throw(y)); } catch (m) { w(m); } } function v(y) { y.done ? h(y.value) : new c(function(m) { m(y.value); }).then(g, k); } v((l = l.apply(a, s || [])).next()); }); }, i = C && C.__generator || function(a, s) { var c, l, h, w, g = { label: 0, sent: function() { if (1 & h[0]) throw h[1]; return h[1]; }, trys: [], ops: [] }; return w = { next: k(0), throw: k(1), return: k(2) }, typeof Symbol == "function" && (w[Symbol.iterator] = function() { return this; }), w; function k(v) { return function(y) { return function(m) { if (c) throw new TypeError("Generator is already executing."); for (; g; ) try { if (c = 1, l && (h = 2 & m[0] ? l.return : m[0] ? l.throw || ((h = l.return) && h.call(l), 0) : l.next) && !(h = h.call(l, m[1])).done) return h; switch (l = 0, h && (m = [2 & m[0], h.value]), m[0]) { case 0: case 1: h = m; break; case 4: return g.label++, { value: m[1], done: !1 }; case 5: g.label++, l = m[1], m = [0]; continue; case 7: m = g.ops.pop(), g.trys.pop(); continue; default: if (h = g.trys, !((h = h.length > 0 && h[h.length - 1]) || m[0] !== 6 && m[0] !== 2)) { g = 0; continue; } if (m[0] === 3 && (!h || m[1] > h[0] && m[1] < h[3])) { g.label = m[1]; break; } if (m[0] === 6 && g.label < h[1]) { g.label = h[1], h = m; break; } if (h && g.label < h[2]) { g.label = h[2], g.ops.push(m); break; } h[2] && g.ops.pop(), g.trys.pop(); continue; } m = s.call(a, g); } catch (_) { m = [6, _], l = 0; } finally { c = h = 0; } if (5 & m[0]) throw m[1]; return { value: m[0] ? m[1] : void 0, done: !0 }; }([v, y]); }; } }, o = C; Object.defineProperty(e, "__esModule", { value: !0 }); var n = "browser-tabs-lock-key", u = { key: function(a) { return t(o, void 0, void 0, function() { return i(this, function(s) { throw new Error("Unsupported"); }); }); }, getItem: function(a) { return t(o, void 0, void 0, function() { return i(this, function(s) { throw new Error("Unsupported"); }); }); }, clear: function() { return t(o, void 0, void 0, function() { return i(this, function(a) { return [2, window.localStorage.clear()]; }); }); }, removeItem: function(a) { return t(o, void 0, void 0, function() { return i(this, function(s) { throw new Error("Unsupported"); }); }); }, setItem: function(a, s) { return t(o, void 0, void 0, function() { return i(this, function(c) { throw new Error("Unsupported"); }); }); }, keySync: function(a) { return window.localStorage.key(a); }, getItemSync: function(a) { return window.localStorage.getItem(a); }, clearSync: function() { return window.localStorage.clear(); }, removeItemSync: function(a) { return window.localStorage.removeItem(a); }, setItemSync: function(a, s) { return window.localStorage.setItem(a, s); } }; function d(a) { return new Promise(function(s) { return setTimeout(s, a); }); } function p(a) { for (var s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz", c = "", l = 0; l < a; l++) c += s[Math.floor(Math.random() * s.length)]; return c; } var f = function() { function a(s) { this.acquiredIatSet = /* @__PURE__ */ new Set(), this.storageHandler = void 0, this.id = Date.now().toString() + p(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 = s, a.waiters === void 0 && (a.waiters = []); } return a.prototype.acquireLock = function(s, c) { return c === void 0 && (c = 5e3), t(this, void 0, void 0, function() { var l, h, w, g, k, v, y; return i(this, function(m) { switch (m.label) { case 0: l = Date.now() + p(4), h = Date.now() + c, w = n + "-" + s, g = this.storageHandler === void 0 ? u : this.storageHandler, m.label = 1; case 1: return Date.now() < h ? [4, d(30)] : [3, 8]; case 2: return m.sent(), g.getItemSync(w) !== null ? [3, 5] : (k = this.id + "-" + s + "-" + l, [4, d(Math.floor(25 * Math.random()))]); case 3: return m.sent(), g.setItemSync(w, JSON.stringify({ id: this.id, iat: l, timeoutKey: k, timeAcquired: Date.now(), timeRefreshed: Date.now() })), [4, d(30)]; case 4: return m.sent(), (v = g.getItemSync(w)) !== null && (y = JSON.parse(v)).id === this.id && y.iat === l ? (this.acquiredIatSet.add(l), this.refreshLockWhileAcquired(w, l), [2, !0]) : [3, 7]; case 5: return a.lockCorrector(this.storageHandler === void 0 ? u : this.storageHandler), [4, this.waitForSomethingToChange(h)]; case 6: m.sent(), m.label = 7; case 7: return l = Date.now() + p(4), [3, 1]; case 8: return [2, !1]; } }); }); }, a.prototype.refreshLockWhileAcquired = function(s, c) { return t(this, void 0, void 0, function() { var l = this; return i(this, function(h) { return setTimeout(function() { return t(l, void 0, void 0, function() { var w, g, k; return i(this, function(v) { switch (v.label) { case 0: return [4, j.default().lock(c)]; case 1: return v.sent(), this.acquiredIatSet.has(c) ? (w = this.storageHandler === void 0 ? u : this.storageHandler, (g = w.getItemSync(s)) === null ? (j.default().unlock(c), [2]) : ((k = JSON.parse(g)).timeRefreshed = Date.now(), w.setItemSync(s, JSON.stringify(k)), j.default().unlock(c), this.refreshLockWhileAcquired(s, c), [2])) : (j.default().unlock(c), [2]); } }); }); }, 1e3), [2]; }); }); }, a.prototype.waitForSomethingToChange = function(s) { return t(this, void 0, void 0, function() { return i(this, function(c) { switch (c.label) { case 0: return [4, new Promise(function(l) { var h = !1, w = Date.now(), g = !1; function k() { if (g || (window.removeEventListener("storage", k), a.removeFromWaiting(k), clearTimeout(v), g = !0), !h) { h = !0; var y = 50 - (Date.now() - w); y > 0 ? setTimeout(l, y) : l(null); } } window.addEventListener("storage", k), a.addToWaiting(k); var v = setTimeout(k, Math.max(0, s - Date.now())); })]; case 1: return c.sent(), [2]; } }); }); }, a.addToWaiting = function(s) { this.removeFromWaiting(s), a.waiters !== void 0 && a.waiters.push(s); }, a.removeFromWaiting = function(s) { a.waiters !== void 0 && (a.waiters = a.waiters.filter(function(c) { return c !== s; })); }, a.notifyWaiters = function() { a.waiters !== void 0 && a.waiters.slice().forEach(function(s) { return s(); }); }, a.prototype.releaseLock = function(s) { return t(this, void 0, void 0, function() { return i(this, function(c) { switch (c.label) { case 0: return [4, this.releaseLock__private__(s)]; case 1: return [2, c.sent()]; } }); }); }, a.prototype.releaseLock__private__ = function(s) { return t(this, void 0, void 0, function() { var c, l, h, w; return i(this, function(g) { switch (g.label) { case 0: return c = this.storageHandler === void 0 ? u : this.storageHandler, l = n + "-" + s, (h = c.getItemSync(l)) === null ? [2] : (w = JSON.parse(h)).id !== this.id ? [3, 2] : [4, j.default().lock(w.iat)]; case 1: g.sent(), this.acquiredIatSet.delete(w.iat), c.removeItemSync(l), j.default().unlock(w.iat), a.notifyWaiters(), g.label = 2; case 2: return [2]; } }); }); }, a.lockCorrector = function(s) { for (var c = Date.now() - 5e3, l = s, h = [], w = 0; ; ) { var g = l.keySync(w); if (g === null) break; h.push(g), w++; } for (var k = !1, v = 0; v < h.length; v++) { var y = h[v]; if (y.includes(n)) { var m = l.getItemSync(y); if (m !== null) { var _ = JSON.parse(m); (_.timeRefreshed === void 0 && _.timeAcquired < c || _.timeRefreshed !== void 0 && _.timeRefreshed < c) && (l.removeItemSync(y), k = !0); } } } k && a.notifyWaiters(); }, a.waiters = void 0, a; }(); e.default = f; })); const ue = { timeoutInSeconds: 60 }, ie = { name: "auth0-spa-js", version: "2.1.3" }, oe = () => Date.now(); class b extends Error { constructor(e, t) { super(t), this.error = e, this.error_description = t, Object.setPrototypeOf(this, b.prototype); } static fromPayload({ error: e, error_description: t }) { return new b(e, t); } } class H extends b { constructor(e, t, i, o = null) { super(e, t), this.state = i, this.appState = o, Object.setPrototypeOf(this, H.prototype); } } class Z extends b { constructor() { super("timeout", "Timeout"), Object.setPrototypeOf(this, Z.prototype); } } class G extends Z { constructor(e) { super(), this.popup = e, Object.setPrototypeOf(this, G.prototype); } } class Y extends b { constructor(e) { super("cancelled", "Popup closed"), this.popup = e, Object.setPrototypeOf(this, Y.prototype); } } class M extends b { constructor(e, t, i) { super(e, t), this.mfa_token = i, Object.setPrototypeOf(this, M.prototype); } } class R extends b { constructor(e, t) { super("missing_refresh_token", `Missing Refresh Token (audience: '${V(e, ["default"])}', scope: '${V(t)}')`), this.audience = e, this.scope = t, Object.setPrototypeOf(this, R.prototype); } } function V(r, e = []) { return r && !e.includes(r) ? r : ""; } const W = () => window.crypto, U = () => { const r = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~."; let e = ""; return Array.from(W().getRandomValues(new Uint8Array(43))).forEach((t) => e += r[t % r.length]), e; }, A = (r) => btoa(r), N = (r) => { var { clientId: e } = r, t = I(r, ["clientId"]); return new URLSearchParams(((i) => Object.keys(i).filter((o) => i[o] !== void 0).reduce((o, n) => Object.assign(Object.assign({}, o), { [n]: i[n] }), {}))(Object.assign({ client_id: e }, t))).toString(); }, B = (r) => ((e) => decodeURIComponent(atob(e).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")))(r.replace(/_/g, "/").replace(/-/g, "+")), de = async (r, e) => { const t = await fetch(r, e); return { ok: t.ok, json: await t.json() }; }, le = async (r, e, t) => { const i = new AbortController(); let o; return e.signal = i.signal, Promise.race([de(r, e), new Promise((n, u) => { o = setTimeout(() => { i.abort(), u(new Error("Timeout when executing 'fetch'")); }, t); })]).finally(() => { clearTimeout(o); }); }, he = async (r, e, t, i, o, n, u) => { return d = { auth: { audience: e, scope: t }, timeout: o, fetchUrl: r, fetchOptions: i, useFormData: u }, p = n, new Promise(function(f, a) { const s = new MessageChannel(); s.port1.onmessage = function(c) { c.data.error ? a(new Error(c.data.error)) : f(c.data), s.port1.close(); }, p.postMessage(d, [s.port2]); }); var d, p; }, pe = async (r, e, t, i, o, n, u = 1e4) => o ? he(r, e, t, i, u, o, n) : le(r, i, u); async function me(r, e) { var { baseUrl: t, timeout: i, audience: o, scope: n, auth0Client: u, useFormData: d } = r, p = I(r, ["baseUrl", "timeout", "audience", "scope", "auth0Client", "useFormData"]); const f = d ? N(p) : JSON.stringify(p); return await async function(a, s, c, l, h, w, g) { let k, v = null; for (let O = 0; O < 3; O++) try { k = await pe(a, c, l, h, w, g, s), v = null; break; } catch (se) { v = se; } if (v) throw v; const y = k.json, { error: m, error_description: _ } = y, E = I(y, ["error", "error_description"]), { ok: T } = k; if (!T) { const O = _ || `HTTP error. Unable to fetch ${a}`; throw m === "mfa_required" ? new M(m, O, E.mfa_token) : m === "missing_refresh_token" ? new R(c, l) : new b(m || "request_error", O); } return E; }(`${t}/oauth/token`, i, o || "default", n, { method: "POST", body: f, headers: { "Content-Type": d ? "application/x-www-form-urlencoded" : "application/json", "Auth0-Client": btoa(JSON.stringify(u || ie)) } }, e, d); } const K = (...r) => { return (e = r.filter(Boolean).join(" ").trim().split(/\s+/), Array.from(new Set(e))).join(" "); var e; }; class S { constructor(e, t = "@@auth0spajs@@", i) { this.prefix = t, this.suffix = i, this.clientId = e.clientId, this.scope = e.scope, this.audience = e.audience; } toKey() { return [this.prefix, this.clientId, this.audience, this.scope, this.suffix].filter(Boolean).join("::"); } static fromKey(e) { const [t, i, o, n] = e.split("::"); return new S({ clientId: i, scope: n, audience: o }, t); } static fromCacheEntry(e) { const { scope: t, audience: i, client_id: o } = e; return new S({ scope: t, audience: i, clientId: o }); } } class fe { set(e, t) { localStorage.setItem(e, JSON.stringify(t)); } get(e) { const t = window.localStorage.getItem(e); if (t) try { return JSON.parse(t); } catch { return; } } remove(e) { localStorage.removeItem(e); } allKeys() { return Object.keys(window.localStorage).filter((e) => e.startsWith("@@auth0spajs@@")); } } class ne { constructor() { this.enclosedCache = /* @__PURE__ */ function() { let e = {}; return { set(t, i) { e[t] = i; }, get(t) { const i = e[t]; if (i) return i; }, remove(t) { delete e[t]; }, allKeys: () => Object.keys(e) }; }(); } } class ge { constructor(e, t, i) { this.cache = e, this.keyManifest = t, this.nowProvider = i || oe; } async setIdToken(e, t, i) { var o; const n = this.getIdTokenCacheKey(e); await this.cache.set(n, { id_token: t, decodedToken: i }), await ((o = this.keyManifest) === null || o === void 0 ? void 0 : o.add(n)); } async getIdToken(e) { const t = await this.cache.get(this.getIdTokenCacheKey(e.clientId)); if (!t && e.scope && e.audience) { const i = await this.get(e); return !i || !i.id_token || !i.decodedToken ? void 0 : { id_token: i.id_token, decodedToken: i.decodedToken }; } if (t) return { id_token: t.id_token, decodedToken: t.decodedToken }; } async get(e, t = 0) { var i; let o = await this.cache.get(e.toKey()); if (!o) { const d = await this.getCacheKeys(); if (!d) return; const p = this.matchExistingCacheKey(e, d); p && (o = await this.cache.get(p)); } if (!o) return; const n = await this.nowProvider(), u = Math.floor(n / 1e3); return o.expiresAt - t < u ? o.body.refresh_token ? (o.body = { refresh_token: o.body.refresh_token }, await this.cache.set(e.toKey(), o), o.body) : (await this.cache.remove(e.toKey()), void await ((i = this.keyManifest) === null || i === void 0 ? void 0 : i.remove(e.toKey()))) : o.body; } async set(e) { var t; const i = new S({ clientId: e.client_id, scope: e.scope, audience: e.audience }), o = await this.wrapCacheEntry(e); await this.cache.set(i.toKey(), o), await ((t = this.keyManifest) === null || t === void 0 ? void 0 : t.add(i.toKey())); } async clear(e) { var t; const i = await this.getCacheKeys(); i && (await i.filter((o) => !e || o.includes(e)).reduce(async (o, n) => { await o, await this.cache.remove(n); }, Promise.resolve()), await ((t = this.keyManifest) === null || t === void 0 ? void 0 : t.clear())); } async wrapCacheEntry(e) { const t = await this.nowProvider(); return { body: e, expiresAt: Math.floor(t / 1e3) + e.expires_in }; } async getCacheKeys() { var e; return this.keyManifest ? (e = await this.keyManifest.get()) === null || e === void 0 ? void 0 : e.keys : this.cache.allKeys ? this.cache.allKeys() : void 0; } getIdTokenCacheKey(e) { return new S({ clientId: e }, "@@auth0spajs@@", "@@user@@").toKey(); } matchExistingCacheKey(e, t) { return t.filter((i) => { var o; const n = S.fromKey(i), u = new Set(n.scope && n.scope.split(" ")), d = ((o = e.scope) === null || o === void 0 ? void 0 : o.split(" ")) || [], p = n.scope && d.reduce((f, a) => f && u.has(a), !0); return n.prefix === "@@auth0spajs@@" && n.clientId === e.clientId && n.audience === e.audience && p; })[0]; } } class we { constructor(e, t, i) { this.storage = e, this.clientId = t, this.cookieDomain = i, this.storageKey = `a0.spajs.txs.${this.clientId}`; } create(e) { this.storage.save(this.storageKey, e, { daysUntilExpire: 1, cookieDomain: this.cookieDomain }); } get() { return this.storage.get(this.storageKey); } remove() { this.storage.remove(this.storageKey, { cookieDomain: this.cookieDomain }); } } const x = (r) => typeof r == "number", ye = ["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"], ke = (r) => { if (!r.id_token) throw new Error("ID token is required but missing"); const e = ((n) => { const u = n.split("."), [d, p, f] = u; if (u.length !== 3 || !d || !p || !f) throw new Error("ID token could not be decoded"); const a = JSON.parse(B(p)), s = { __raw: n }, c = {}; return Object.keys(a).forEach((l) => { s[l] = a[l], ye.includes(l) || (c[l] = a[l]); }), { encoded: { header: d, payload: p, signature: f }, header: JSON.parse(B(d)), claims: s, user: c }; })(r.id_token); if (!e.claims.iss) throw new Error("Issuer (iss) claim must be a string present in the ID token"); if (e.claims.iss !== r.iss) throw new Error(`Issuer (iss) claim mismatch in the ID token; expected "${r.iss}", found "${e.claims.iss}"`); if (!e.user.sub) throw new Error("Subject (sub) claim must be a string present in the ID token"); if (e.header.alg !== "RS256") throw new Error(`Signature algorithm of "${e.header.alg}" is not supported. Expected the ID token to be signed with "RS256".`); if (!e.claims.aud || typeof e.claims.aud != "string" && !Array.isArray(e.claims.aud)) throw new Error("Audience (aud) claim must be a string or array of strings present in the ID token"); if (Array.isArray(e.claims.aud)) { if (!e.claims.aud.includes(r.aud)) throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${r.aud}" but was not one of "${e.claims.aud.join(", ")}"`); if (e.claims.aud.length > 1) { if (!e.claims.azp) throw new Error("Authorized Party (azp) claim must be a string present in the ID token when Audience (aud) claim has multiple values"); if (e.claims.azp !== r.aud) throw new Error(`Authorized Party (azp) claim mismatch in the ID token; expected "${r.aud}", found "${e.claims.azp}"`); } } else if (e.claims.aud !== r.aud) throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${r.aud}" but found "${e.claims.aud}"`); if (r.nonce) { if (!e.claims.nonce) throw new Error("Nonce (nonce) claim must be a string present in the ID token"); if (e.claims.nonce !== r.nonce) throw new Error(`Nonce (nonce) claim mismatch in the ID token; expected "${r.nonce}", found "${e.claims.nonce}"`); } if (r.max_age && !x(e.claims.auth_time)) throw new Error("Authentication Time (auth_time) claim must be a number present in the ID token when Max Age (max_age) is specified"); if (e.claims.exp == null || !x(e.claims.exp)) throw new Error("Expiration Time (exp) claim must be a number present in the ID token"); if (!x(e.claims.iat)) throw new Error("Issued At (iat) claim must be a number present in the ID token"); const t = r.leeway || 60, i = new Date(r.now || Date.now()), o = /* @__PURE__ */ new Date(0); if (o.setUTCSeconds(e.claims.exp + t), i > o) throw new Error(`Expiration Time (exp) claim error in the ID token; current time (${i}) is after expiration time (${o})`); if (e.claims.nbf != null && x(e.claims.nbf)) { const n = /* @__PURE__ */ new Date(0); if (n.setUTCSeconds(e.claims.nbf - t), i < n) throw new Error(`Not Before time (nbf) claim in the ID token indicates that this token can't be used just yet. Current time (${i}) is before ${n}`); } if (e.claims.auth_time != null && x(e.claims.auth_time)) { const n = /* @__PURE__ */ new Date(0); if (n.setUTCSeconds(parseInt(e.claims.auth_time) + r.max_age + t), i > n) 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 (${i}) is after last auth at ${n}`); } if (r.organization) { const n = r.organization.trim(); if (n.startsWith("org_")) { const u = n; if (!e.claims.org_id) throw new Error("Organization ID (org_id) claim must be a string present in the ID token"); if (u !== e.claims.org_id) throw new Error(`Organization ID (org_id) claim mismatch in the ID token; expected "${u}", found "${e.claims.org_id}"`); } else { const u = n.toLowerCase(); if (!e.claims.org_name) throw new Error("Organization Name (org_name) claim must be a string present in the ID token"); if (u !== e.claims.org_name) throw new Error(`Organization Name (org_name) claim mismatch in the ID token; expected "${u}", found "${e.claims.org_name}"`); } } return e; }; var z = F(function(r, e) { var t = C && C.__assign || function() { return t = Object.assign || function(p) { for (var f, a = 1, s = arguments.length; a < s; a++) for (var c in f = arguments[a]) Object.prototype.hasOwnProperty.call(f, c) && (p[c] = f[c]); return p; }, t.apply(this, arguments); }; function i(p, f) { if (!f) return ""; var a = "; " + p; return f === !0 ? a : a + "=" + f; } function o(p, f, a) { return encodeURIComponent(p).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/\(/g, "%28").replace(/\)/g, "%29") + "=" + encodeURIComponent(f).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent) + function(s) { if (typeof s.expires == "number") { var c = /* @__PURE__ */ new Date(); c.setMilliseconds(c.getMilliseconds() + 864e5 * s.expires), s.expires = c; } return i("Expires", s.expires ? s.expires.toUTCString() : "") + i("Domain", s.domain) + i("Path", s.path) + i("Secure", s.secure) + i("SameSite", s.sameSite); }(a); } function n(p) { for (var f = {}, a = p ? p.split("; ") : [], s = /(%[\dA-F]{2})+/gi, c = 0; c < a.length; c++) { var l = a[c].split("="), h = l.slice(1).join("="); h.charAt(0) === '"' && (h = h.slice(1, -1)); try { f[l[0].replace(s, decodeURIComponent)] = h.replace(s, decodeURIComponent); } catch { } } return f; } function u() { return n(document.cookie); } function d(p, f, a) { document.cookie = o(p, f, t({ path: "/" }, a)); } e.__esModule = !0, e.encode = o, e.parse = n, e.getAll = u, e.get = function(p) { return u()[p]; }, e.set = d, e.remove = function(p, f) { d(p, "", t(t({}, f), { expires: -1 })); }; }); J(z), z.encode, z.parse, z.getAll; var ve = z.get, re = z.set, ae = z.remove; const P = { get(r) { const e = ve(r); if (e !== void 0) return JSON.parse(e); }, save(r, e, t) { let i = {}; window.location.protocol === "https:" && (i = { secure: !0, sameSite: "none" }), t != null && t.daysUntilExpire && (i.expires = t.daysUntilExpire), t != null && t.cookieDomain && (i.domain = t.cookieDomain), re(r, JSON.stringify(e), i); }, remove(r, e) { let t = {}; e != null && e.cookieDomain && (t.domain = e.cookieDomain), ae(r, t); } }, be = { get(r) { return P.get(r) || P.get(`_legacy_${r}`); }, save(r, e, t) { let i = {}; window.location.protocol === "https:" && (i = { secure: !0 }), t != null && t.daysUntilExpire && (i.expires = t.daysUntilExpire), t != null && t.cookieDomain && (i.domain = t.cookieDomain), re(`_legacy_${r}`, JSON.stringify(e), i), P.save(r, e, t); }, remove(r, e) { let t = {}; e != null && e.cookieDomain && (t.domain = e.cookieDomain), ae(r, t), P.remove(r, e), P.remove(`_legacy_${r}`, e); } }, _e = { get(r) { if (typeof sessionStorage > "u") return; const e = sessionStorage.getItem(r); return e != null ? JSON.parse(e) : void 0; }, save(r, e) { sessionStorage.setItem(r, JSON.stringify(e)); }, remove(r) { sessionStorage.removeItem(r); } }; function Ie(r, e, t) { var i = e === void 0 ? null : e, o = function(p, f) { var a = atob(p); if (f) { for (var s = new Uint8Array(a.length), c = 0, l = a.length; c < l; ++c) s[c] = a.charCodeAt(c); return String.fromCharCode.apply(null, new Uint16Array(s.buffer)); } return a; }(r, t !== void 0 && t), n = o.indexOf(` `, 10) + 1, u = o.substring(n) + (i ? "//# sourceMappingURL=" + i : ""), d = new Blob([u], { type: "application/javascript" }); return URL.createObjectURL(d); } var $, q, Q, L, Se = ($ = "Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZSBleHRlbmRzIEVycm9ye2NvbnN0cnVjdG9yKHQscil7c3VwZXIociksdGhpcy5lcnJvcj10LHRoaXMuZXJyb3JfZGVzY3JpcHRpb249cixPYmplY3Quc2V0UHJvdG90eXBlT2YodGhpcyxlLnByb3RvdHlwZSl9c3RhdGljIGZyb21QYXlsb2FkKHtlcnJvcjp0LGVycm9yX2Rlc2NyaXB0aW9uOnJ9KXtyZXR1cm4gbmV3IGUodCxyKX19Y2xhc3MgdCBleHRlbmRzIGV7Y29uc3RydWN0b3IoZSxzKXtzdXBlcigibWlzc2luZ19yZWZyZXNoX3Rva2VuIixgTWlzc2luZyBSZWZyZXNoIFRva2VuIChhdWRpZW5jZTogJyR7cihlLFsiZGVmYXVsdCJdKX0nLCBzY29wZTogJyR7cihzKX0nKWApLHRoaXMuYXVkaWVuY2U9ZSx0aGlzLnNjb3BlPXMsT2JqZWN0LnNldFByb3RvdHlwZU9mKHRoaXMsdC5wcm90b3R5cGUpfX1mdW5jdGlvbiByKGUsdD1bXSl7cmV0dXJuIGUmJiF0LmluY2x1ZGVzKGUpP2U6IiJ9ImZ1bmN0aW9uIj09dHlwZW9mIFN1cHByZXNzZWRFcnJvciYmU3VwcHJlc3NlZEVycm9yO2NvbnN0IHM9ZT0+e3ZhcntjbGllbnRJZDp0fT1lLHI9ZnVuY3Rpb24oZSx0KXt2YXIgcj17fTtmb3IodmFyIHMgaW4gZSlPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwoZSxzKSYmdC5pbmRleE9mKHMpPDAmJihyW3NdPWVbc10pO2lmKG51bGwhPWUmJiJmdW5jdGlvbiI9PXR5cGVvZiBPYmplY3QuZ2V0T3duUHJvcGVydHlTeW1ib2xzKXt2YXIgbz0wO2ZvcihzPU9iamVjdC5nZXRPd25Qcm9wZXJ0eVN5bWJvbHMoZSk7bzxzLmxlbmd0aDtvKyspdC5pbmRleE9mKHNbb10pPDAmJk9iamVjdC5wcm90b3R5cGUucHJvcGVydHlJc0VudW1lcmFibGUuY2FsbChlLHNbb10pJiYocltzW29dXT1lW3Nbb11dKX1yZXR1cm4gcn0oZSxbImNsaWVudElkIl0pO3JldHVybiBuZXcgVVJMU2VhcmNoUGFyYW1zKChlPT5PYmplY3Qua2V5cyhlKS5maWx0ZXIoKHQ9PnZvaWQgMCE9PWVbdF0pKS5yZWR1Y2UoKCh0LHIpPT5PYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30sdCkse1tyXTplW3JdfSkpLHt9KSkoT2JqZWN0LmFzc2lnbih7Y2xpZW50X2lkOnR9LHIpKSkudG9TdHJpbmcoKX07bGV0IG89e307Y29uc3Qgbj0oZSx0KT0+YCR7ZX18JHt0fWA7YWRkRXZlbnRMaXN0ZW5lcigibWVzc2FnZSIsKGFzeW5jKHtkYXRhOnt0aW1lb3V0OmUsYXV0aDpyLGZldGNoVXJsOmksZmV0Y2hPcHRpb25zOmMsdXNlRm9ybURhdGE6YX0scG9ydHM6W3BdfSk9PntsZXQgZjtjb25zdHthdWRpZW5jZTp1LHNjb3BlOmx9PXJ8fHt9O3RyeXtjb25zdCByPWE/KGU9Pntjb25zdCB0PW5ldyBVUkxTZWFyY2hQYXJhbXMoZSkscj17fTtyZXR1cm4gdC5mb3JFYWNoKCgoZSx0KT0+e3JbdF09ZX0pKSxyfSkoYy5ib2R5KTpKU09OLnBhcnNlKGMuYm9keSk7aWYoIXIucmVmcmVzaF90b2tlbiYmInJlZnJlc2hfdG9rZW4iPT09ci5ncmFudF90eXBlKXtjb25zdCBlPSgoZSx0KT0+b1tuKGUsdCldKSh1LGwpO2lmKCFlKXRocm93IG5ldyB0KHUsbCk7Yy5ib2R5PWE/cyhPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30scikse3JlZnJlc2hfdG9rZW46ZX0pKTpKU09OLnN0cmluZ2lmeShPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30scikse3JlZnJlc2hfdG9rZW46ZX0pKX1sZXQgaCxnOyJmdW5jdGlvbiI9PXR5cGVvZiBBYm9ydENvbnRyb2xsZXImJihoPW5ldyBBYm9ydENvbnRyb2xsZXIsYy5zaWduYWw9aC5zaWduYWwpO3RyeXtnPWF3YWl0IFByb21pc2UucmFjZShbKGQ9ZSxuZXcgUHJvbWlzZSgoZT0+c2V0VGltZW91dChlLGQpKSkpLGZldGNoKGksT2JqZWN0LmFzc2lnbih7fSxjKSldKX1jYXRjaChlKXtyZXR1cm4gdm9pZCBwLnBvc3RNZXNzYWdlKHtlcnJvcjplLm1lc3NhZ2V9KX1pZighZylyZXR1cm4gaCYmaC5hYm9ydCgpLHZvaWQgcC5wb3N0TWVzc2FnZSh7ZXJyb3I6IlRpbWVvdXQgd2hlbiBleGVjdXRpbmcgJ2ZldGNoJyJ9KTtmPWF3YWl0IGcuanNvbigpLGYucmVmcmVzaF90b2tlbj8oKChlLHQscik9PntvW24odCxyKV09ZX0pKGYucmVmcmVzaF90b2tlbix1LGwpLGRlbGV0ZSBmLnJlZnJlc2hfdG9rZW4pOigoZSx0KT0+e2RlbGV0ZSBvW24oZSx0KV19KSh1LGwpLHAucG9zdE1lc3NhZ2Uoe29rOmcub2ssanNvbjpmfSl9Y2F0Y2goZSl7cC5wb3N0TWVzc2FnZSh7b2s6ITEsanNvbjp7ZXJyb3I6ZS5lcnJvcixlcnJvcl9kZXNjcmlwdGlvbjplLm1lc3NhZ2V9fSl9dmFyIGR9KSl9KCk7Cgo=", q = null, Q = !1, function(r) { return L = L || Ie($, q, Q), new Worker(L, r); }); const D = {}; class Te { constructor(e, t) { this.cache = e, this.clientId = t, this.manifestKey = this.createManifestKeyFrom(this.clientId); } async add(e) { var t; const i = new Set(((t = await this.cache.get(this.manifestKey)) === null || t === void 0 ? void 0 : t.keys) || []); i.add(e), await this.cache.set(this.manifestKey, { keys: [...i] }); } async remove(e) { const t = await this.cache.get(this.manifestKey); if (t) { const i = new Set(t.keys); return i.delete(e), i.size > 0 ? await this.cache.set(this.manifestKey, { keys: [...i] }) : await this.cache.remove(this.manifestKey); } } get() { return this.cache.get(this.manifestKey); } clear() { return this.cache.remove(this.manifestKey); } createManifestKeyFrom(e) { return `@@auth0spajs@@::${e}`; } } const Oe = { memory: () => new ne().enclosedCache, localstorage: () => new fe() }, ee = (r) => Oe[r], te = (r) => { const { openUrl: e, onRedirect: t } = r, i = I(r, ["openUrl", "onRedirect"]); return Object.assign(Object.assign({}, i), { openUrl: e === !1 || e ? e : t }); }, X = new ce(); class je { constructor(e) { let t, i; if (this.userCache = new ne().enclosedCache, this.defaultOptions = { authorizationParams: { scope: "openid profile email" }, useRefreshTokensFallback: !1, useFormData: !0 }, this._releaseLockOnPageHide = async () => { await X.releaseLock("auth0.lock.getTokenSilently"), window.removeEventListener("pagehide", this._releaseLockOnPageHide); }, this.options = Object.assign(Object.assign(Object.assign({}, this.defaultOptions), e), { authorizationParams: Object.assign(Object.assign({}, this.defaultOptions.authorizationParams), e.authorizationParams) }), typeof window < "u" && (() => { if (!W()) throw new Error("For security reasons, `window.crypto` is required to run `auth0-spa-js`."); if (W().subtle === void 0) throw new Error(` 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. `); })(), 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) i = e.cache; else { if (t = e.cacheLocation || "memory", !ee(t)) throw new Error(`Invalid cache location "${t}"`); i = ee(t)(); } this.httpTimeoutMs = e.httpTimeoutInSeconds ? 1e3 * e.httpTimeoutInSeconds : 1e4, this.cookieStorage = e.legacySameSiteCookie === !1 ? P : be, this.orgHintCookieName = `auth0.${this.options.clientId}.organization_hint`, this.isAuthenticatedCookieName = ((u) => `auth0.${u}.is.authenticated`)(this.options.clientId), this.sessionCheckExpiryDays = e.sessionCheckExpiryDays || 1; const o = e.useCookiesForTransactions ? this.cookieStorage : _e; var n; this.scope = K("openid", this.options.authorizationParams.scope, this.options.useRefreshTokens ? "offline_access" : ""), this.transactionManager = new we(o, this.options.clientId, this.options.cookieDomain), this.nowProvider = this.options.nowProvider || oe, this.cacheManager = new ge(i, i.allKeys ? void 0 : new Te(i, this.options.clientId), this.nowProvider), this.domainUrl = (n = this.options.domain, /^https?:\/\//.test(n) ? n : `https://${n}`), this.tokenIssuer = ((u, d) => u ? u.startsWith("https://") ? u : `https://${u}/` : `${d}/`)(this.options.issuer, this.domainUrl), typeof window < "u" && window.Worker && this.options.useRefreshTokens && t === "memory" && (this.options.workerUrl ? this.worker = new Worker(this.options.workerUrl) : this.worker = new Se()); } _url(e) { const t = encodeURIComponent(btoa(JSON.stringify(this.options.auth0Client || ie))); return `${this.domainUrl}${e}&auth0Client=${t}`; } _authorizeUrl(e) { return this._url(`/authorize?${N(e)}`); } async _verifyIdToken(e, t, i) { const o = await this.nowProvider(); return ke({ iss: this.tokenIssuer, aud: this.options.clientId, id_token: e, nonce: t, organization: i, leeway: this.options.leeway, max_age: (n = this.options.authorizationParams.max_age, typeof n != "string" ? n : parseInt(n, 10) || void 0), now: o }); var n; } _processOrgHint(e) { e ? this.cookieStorage.save(this.orgHintCookieName, e, { daysUntilExpire: this.sessionCheckExpiryDays, cookieDomain: this.options.cookieDomain }) : this.cookieStorage.remove(this.orgHintCookieName, { cookieDomain: this.options.cookieDomain }); } async _prepareAuthorizeUrl(e, t, i) { const o = A(U()), n = A(U()), u = U(), d = ((a) => { const s = new Uint8Array(a); return ((c) => { const l = { "+": "-", "/": "_", "=": "" }; return c.replace(/[+/=]/g, (h) => l[h]); })(window.btoa(String.fromCharCode(...Array.from(s)))); })(await (async (a) => await W().subtle.digest({ name: "SHA-256" }, new TextEncoder().encode(a)))(u)), p = ((a, s, c, l, h, w, g, k) => Object.assign(Object.assign(Object.assign({ client_id: a.clientId }, a.authorizationParams), c), { scope: K(s, c.scope), response_type: "code", response_mode: k || "query", state: l, nonce: h, redirect_uri: g || a.authorizationParams.redirect_uri, code_challenge: w, code_challenge_method: "S256" }))(this.options, this.scope, e, o, n, d, e.redirect_uri || this.options.authorizationParams.redirect_uri || i, t == null ? void 0 : t.response_mode), f = this._authorizeUrl(p); return { nonce: n, code_verifier: u, scope: p.scope, audience: p.audience || "default", redirect_uri: p.redirect_uri, state: o, url: f }; } async loginWithPopup(e, t) { var i; if (e = e || {}, !(t = t || {}).popup && (t.popup = ((d) => { const p = window.screenX + (window.innerWidth - 400) / 2, f = window.screenY + (window.innerHeight - 600) / 2; return window.open(d, "auth0:authorize:popup", `left=${p},top=${f},width=400,height=600,resizable,scrollbars=yes,status=1`); })(""), !t.popup)) throw new Error("Unable to open a popup for loginWithPopup - window.open returned `null`"); const o = await this._prepareAuthorizeUrl(e.authorizationParams || {}, { response_mode: "web_message" }, window.location.origin); t.popup.location.href = o.url; const n = await ((d) => new Promise((p, f) => { let a; const s = setInterval(() => { d.popup && d.popup.closed && (clearInterval(s), clearTimeout(c), window.removeEventListener("message", a, !1), f(new Y(d.popup))); }, 1e3), c = setTimeout(() => { clearInterval(s), f(new G(d.popup)), window.removeEventListener("message", a, !1); }, 1e3 * (d.timeoutInSeconds || 60)); a = function(l) { if (l.data && l.data.type === "authorization_response") { if (clearTimeout(c), clearInterval(s), window.removeEventListener("message", a, !1), d.popup.close(), l.data.response.error) return f(b.fromPayload(l.data.response)); p(l.data.response); } }, window.addEventListener("message", a); }))(Object.assign(Object.assign({}, t), { timeoutInSeconds: t.timeoutInSeconds || this.options.authorizeTimeoutInSeconds || 60 })); if (o.state !== n.state) throw new b("state_mismatch", "Invalid state"); const u = ((i = e.authorizationParams) === null || i === void 0 ? void 0 : i.organization) || this.options.authorizationParams.organization; await this._requestToken({ audience: o.audience, scope: o.scope, code_verifier: o.code_verifier, grant_type: "authorization_code", code: n.code, redirect_uri: o.redirect_uri }, { nonceIn: o.nonce, organization: u }); } async getUser() { var e; const t = await this._getIdTokenFromCache(); return (e = t == null ? void 0 : t.decodedToken) === null || e === void 0 ? void 0 : e.user; } async getIdTokenClaims() { var e; const t = await this._getIdTokenFromCache(); return (e = t == null ? void 0 : t.decodedToken) === null || e === void 0 ? void 0 : e.claims; } async loginWithRedirect(e = {}) { var t; const i = te(e), { openUrl: o, fragment: n, appState: u } = i, d = I(i, ["openUrl", "fragment", "appState"]), p = ((t = d.authorizationParams) === null || t === void 0 ? void 0 : t.organization) || this.options.authorizationParams.organization, f = await this._prepareAuthorizeUrl(d.authorizationParams || {}), { url: a } = f, s = I(f, ["url"]); this.transactionManager.create(Object.assign(Object.assign(Object.assign({}, s), { appState: u }), p && { organization: p })); const c = n ? `${a}#${n}` : a; o ? await o(c) : window.location.assign(c); } async handleRedirectCallback(e = window.location.href) { const t = e.split("?").slice(1); if (t.length === 0) throw new Error("There are no query params available for parsing."); const { state: i, code: o, error: n, error_description: u } = ((s) => { s.indexOf("#") > -1 && (s = s.substring(0, s.indexOf("#"))); const c = new URLSearchParams(s); return { state: c.get("state"), code: c.get("code") || void 0, error: c.get("error") || void 0, error_description: c.get("error_description") || void 0 }; })(t.join("")), d = this.transactionManager.get(); if (!d) throw new b("missing_transaction", "Invalid state"); if (this.transactionManager.remove(), n) throw new H(n, u || n, i, d.appState); if (!d.code_verifier || d.state && d.state !== i) throw new b("state_mismatch", "Invalid state"); const p = d.organization, f = d.nonce, a = d.redirect_uri; return await this._requestToken(Object.assign({ audience: d.audience, scope: d.scope, code_verifier: d.code_verifier, grant_type: "authorization_code", code: o }, a ? { redirect_uri: a } : {}), { nonceIn: f, organization: p }), { appState: d.appState }; } async checkSession(e) { if (!this.cookieStorage.get(this.isAuthenticatedCookieName)) { if (!this.cookieStorage.get("auth0.is.authenticated")) return; this.cookieStorage.save(this.isAuthenticatedCookieName, !0, { daysUntilExpire: this.sessionCheckExpiryDays, cookieDomain: this.options.cookieDomain }), this.cookieStorage.remove("auth0.is.authenticated"); } try { await this.getTokenSilently(e); } catch { } } async getTokenSilently(e = {}) { var t; const i = Object.assign(Object.assign({ cacheMode: "on" }, e), { authorizationParams: Object.assign(Object.assign(Object.assign({}, this.options.authorizationParams), e.authorizationParams), { scope: K(this.scope, (t = e.authorizationParams) === null || t === void 0 ? void 0 : t.scope) }) }), o = await ((n, u) => { let d = D[u]; return d || (d = n().finally(() => { delete D[u], d = null; }), D[u] = d), d; })(() => this._getTokenSilently(i), `${this.options.clientId}::${i.authorizationParams.audience}::${i.authorizationParams.scope}`); return e.detailedResponse ? o : o == null ? void 0 : o.access_token; } async _getTokenSilently(e) { const { cacheMode: t } = e, i = I(e, ["cacheMode"]); if (t !== "off") { const o = await this._getEntryFromCache({ scope: i.authorizationParams.scope, audience: i.authorizationParams.audience || "default", clientId: this.options.clientId }); if (o) return o; } if (t !== "cache-only") { if (!await (async (o, n = 3) => { for (let u = 0; u < n; u++) if (await o()) return !0; return !1; })(() => X.acquireLock("auth0.lock.getTokenSilently", 5e3), 10)) throw new Z(); try { if (window.addEventListener("pagehide", this._releaseLockOnPageHide), t !== "off") { const f = await this._getEntryFromCache({ scope: i.authorizationParams.scope, audience: i.authorizationParams.audience || "default", clientId: this.options.clientId }); if (f) return f; } const o = this.options.useRefreshTokens ? await this._getTokenUsingRefreshToken(i) : await this._getTokenFromIFrame(i), { id_token: n, access_token: u, oauthTokenScope: d, expires_in: p } = o; return Object.assign(Object.assign({ id_token: n, access_token: u }, d ? { scope: d } : null), { expires_in: p }); } finally { await X.releaseLock("auth0.lock.getTokenSilently"), window.removeEventListener("pagehide", this._releaseLockOnPageHide); } } } async getTokenWithPopup(e = {}, t = {}) { var i; const o = Object.assign(Object.assign({}, e), { authorizationParams: Object.assign(Object.assign(Object.assign({}, this.options.authorizationParams), e.authorizationParams), { scope: K(this.scope, (i = e.authorizationParams) === null || i === void 0 ? void 0 : i.scope) }) }); return t = Object.assign(Object.assign({}, ue), t), await this.loginWithPopup(o, t), (await this.cacheManager.get(new S({ scope: o.authorizationParams.scope, audience: o.authorizationParams.audience || "default", clientId: this.options.clientId }))).access_token; } async isAuthenticated() { return !!await this.getUser(); } _buildLogoutUrl(e) { e.clientId !== null ? e.clientId = e.clientId || this.options.clientId : delete e.clientId; const t = e.logoutParams || {}, { federated: i } = t, o = I(t, ["federated"]), n = i ? "&federated" : ""; return this._url(`/v2/logout?${N(Object.assign({ clientId: e.clientId }, o))}`) + n; } async logout(e = {}) { const t = te(e), { openUrl: i } = t, o = I(t, ["openUrl"]); 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@@"); const n = this._buildLogoutUrl(o); i ? await i(n) : i !== !1 && window.location.assign(n); } async _getTokenFromIFrame(e) { const t = Object.assign(Object.assign({}, e.authorizationParams), { prompt: "none" }), i = this.cookieStorage.get(this.orgHintCookieName); i && !t.organization && (t.organization = i); const { url: o, state: n, nonce: u, code_verifier: d, redirect_uri: p, scope: f, audience: a } = await this._prepareAuthorizeUrl(t, { response_mode: "web_message" }, window.location.origin); try { if (window.crossOriginIsolated) throw new b("login_required", "The application is running in a Cross-Origin Isolated context, silently retrieving a token without refresh token is not possible."); const s = e.timeoutInSeconds || this.options.authorizeTimeoutInSeconds, c = await ((h, w, g = 60) => new Promise((k, v) => { const y = window.document.createElement("iframe"); y.setAttribute("width", "0"), y.setAttribute("height", "0"), y.style.display = "none"; const m = () => { window.document.body.contains(y) && (window.document.body.removeChild(y), window.removeEventListener("message", _, !1)); }; let _; const E = setTimeout(() => { v(new Z()), m(); }, 1e3 * g); _ = function(T) { if (T.origin != w || !T.data || T.data.type !== "authorization_response") return; const O = T.source; O && O.close(), T.data.response.error ? v(b.fromPayload(T.data.response)) : k(T.data.response), clearTimeout(E), window.removeEventListener("message", _, !1), setTimeout(m, 2e3); }, window.addEventListener("message", _, !1), window.document.body.appendChild(y), y.setAttribute("src", h); }))(o, this.domainUrl, s); if (n !== c.state) throw new b("state_mismatch", "Invalid state"); const l = await this._requestToken(Object.assign(Object.assign({}, e.authorizationParams), { code_verifier: d, code: c.code, grant_type: "authorization_code", redirect_uri: p, timeout: e.authorizationParams.timeout || this.httpTimeoutMs }), { nonceIn: u, organization: t.organization }); return Object.assign(Object.assign({}, l), { scope: f, oauthTokenScope: l.scope, audience: a }); } catch (s) { throw s.error === "login_required" && this.logout({ openUrl: !1 }), s; } } async _getTokenUsingRefreshToken(e) { const t = await this.cacheManager.get(new S({ scope: e.authorizationParams.scope, audience: e.authorizationParams.audience || "default", clientId: this.options.clientId })); if (!(t && t.refresh_token || this.worker)) { if (this.options.useRefreshTokensFallback) return await this._getTokenFromIFrame(e); throw new R(e.authorizationParams.audience || "default", e.authorizationParams.scope); } const i = e.authorizationParams.redirect_uri || this.options.authorizationParams.redirect_uri || window.location.origin, o = typeof e.timeoutInSeconds == "number" ? 1e3 * e.timeoutInSeconds : null; try { const n = await this._requestToken(Object.assign(Object.assign(Object.assign({}, e.authorizationParams), { grant_type: "refresh_token", refresh_token: t && t.refresh_token, redirect_uri: i }), o && { timeout: o })); return Object.assign(Object.assign({}, n), { scope: e.authorizationParams.scope, oauthTokenScope: n.scope, audience: e.authorizationParams.audience || "default" }); } catch (n) { if ((n.message.indexOf("Missing Refresh Token") > -1 || n.message && n.message.indexOf("invalid refresh token") > -1) && this.options.useRefreshTokensFallback) return await this._getTokenFromIFrame(e); throw n; } } async _saveEntryInCache(e) { const { id_token: t, decodedToken: i } = e, o = I(e, ["id_token", "decodedToken"]); this.userCache.set("@@user@@", { id_token: t, decodedToken: i }), await this.cacheManager.setIdToken(this.options.clientId, e.id_token, e.decodedToken), await this.cacheManager.set(o); } async _getIdTokenFromCache() { const e = this.options.authorizationParams.audience || "default", t = await this.cacheManager.getIdToken(new S({ clientId: this.options.clientId, audience: e, scope: this.scope })), i = this.userCache.get("@@user@@"); return t && t.id_token === (i == null ? void 0 : i.id_token) ? i : (this.userCache.set("@@user@@", t),