UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

86 lines (85 loc) 3.87 kB
var a = Object.defineProperty; var f = (i, e, t) => e in i ? a(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t; var s = (i, e, t) => f(i, typeof e != "symbol" ? e + "" : e, t); import { SetupContext as _ } from "./SetupContext.js"; import { AuthSessionSpecification as c } from "./AuthSessionSpecification.js"; import { createErrorContainer as l } from "../../../primitives/auxiliary/errorContainer/main.js"; import { SessionContext as S } from "../../../primitives/context/session/SessionContext.js"; import { createPromisor as p } from "../../../primitives/async/promisor/main.js"; import { createWatchlist as u } from "../../../primitives/reactive/watchlist/main.js"; import { EVT_SESSION_EXPIRED as C, EVT_SESSION_READY as m, ERR_SESSION_REFRESH_ABORTED as d } from "../../../primitives/context/session/constants.js"; import { boolOrTrue as x, boolOrFalse as E } from "../../../utils/value/bool.js"; import { isFunction as g } from "../../../utils/value/is.js"; class z { constructor() { s(this, "_canSkipSessionRefresh", !1); s(this, "_refreshPromisorSignal"); s(this, "_sessionIsFrozen", !1); s(this, "_errorContainer", l()); s(this, "_specification", new c()); s(this, "_sessionContext", new S(this._specification)); s(this, "_setupContext", new _(this._sessionContext)); s(this, "_refreshPromisor", p(async (e, t = !1) => { let r = !this._refreshPromisorSignal, n = this._refreshPromisorSignal === (this._refreshPromisorSignal = e); const o = E(t) && this._canSkipSessionRefresh; r && (r = !1, this._errorContainer.reset(), this._onAuthStateChanged()); try { await (o ? this._setupContext : this._sessionContext).refresh(e).finally(() => n = this._refreshPromisorSignal === e); } catch (h) { if (!n) return; !e.aborted && (o || h !== d) && this._errorContainer.set(h), r = !o; } finally { (r || o && n) && (this._refreshPromisorSignal = void 0, this._onAuthStateChanged()); } })); s(this, "_watchlist", u({ endpoints: () => this._setupContext.endpoints, extraConfig: () => this._setupContext.extraConfig, hasError: () => this._errorContainer.hasError, isExpired: () => this._sessionContext.isExpired, isFrozen: () => this._sessionIsFrozen, refreshing: () => !!this._refreshPromisorSignal })); s(this, "freeze", () => { this._sessionIsFrozen = !0, this._watchlist.on.resume = void 0, this._watchlist.cancelSubscriptions(); }); s(this, "http", this._sessionContext.http.bind(this._sessionContext, null)); s(this, "refresh", this._refresh.bind(this)); s(this, "subscribe", this._watchlist.subscribe); this._watchlist.on.resume = () => { const e = [ this._sessionContext.on(C, () => { this._canSkipSessionRefresh = !1, this._onAuthStateChanged(); }), this._sessionContext.on(m, () => { this._refresh(this._canSkipSessionRefresh = !0); }) ]; this._watchlist.on.idle = () => { this._watchlist.on.idle = void 0, e.forEach((t) => t()), e.length = 0; }, !this.context.refreshing && x(this.context.isExpired) && this._refresh(); }; } get context() { return this._watchlist.snapshot; } set loadingContext(e) { this._setupContext.loadingContext = e; } set errorHandler(e) { this._specification.errorHandler = e; } set onSessionCreate(e) { this._specification.onSessionCreate !== e && (this._specification.onSessionCreate = e, this._refreshPromisorSignal && g(this._specification.onSessionCreate) && (this._canSkipSessionRefresh = !1, this._refresh())); } _onAuthStateChanged() { this._watchlist.requestNotification(); } _refresh(e = !1) { this._refreshPromisor(e); } } export { z as AuthSession, z as default };