@adyen/adyen-platform-experience-web
Version:

33 lines (32 loc) • 1.18 kB
JavaScript
import { EVT_SESSION_EXPIRED as l } from "../constants.js";
import { createPromisor as m } from "../../../async/promisor/main.js";
import { isFunction as p } from "../../../../utils/value/is.js";
import { boolOrFalse as f, falsify as h } from "../../../../utils/value/bool.js";
import { noop as i } from "../../../../utils/common.js";
import { getter as d } from "../../../../utils/struct/property.js";
import { tryResolve as _ } from "../../../../utils/async/main.js";
const y = async (t) => {
const { specification: s } = t.context, e = await _(async () => {
const o = s.autoRefresh;
return p(o) ? o.call(s, t.session) : o;
}).catch(h);
return f(e);
}, O = (t) => {
let s = t.context.emitter.on(l, () => n(!1)), e, o = m(async (r, c = !1) => {
e = r;
const u = f(c) || await y(t);
e === r && u && t.pending && !t.refreshing && t.refresh(e).catch(i);
}), n = (r = !1) => {
t.refreshing || o(r);
}, a = () => {
s(), o.abort(), o = e = s = void 0, n = a = i;
};
return Object.defineProperties((r = !1) => n(r), {
destruct: d(() => a, !1)
});
};
export {
y as _canAutofresh,
O as createSessionAutofresher,
O as default
};