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

67 lines (66 loc) • 2.89 kB
JavaScript
var e = Object.defineProperty;
var r = (s, t, i) => t in s ? e(s, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[t] = i;
var o = (s, t, i) => r(s, typeof t != "symbol" ? t + "" : t, i);
import { FALLBACK_ENV as a, resolveEnvironment as h } from "./utils.js";
import { AuthSession as l } from "./ConfigContext/session/AuthSession.js";
import p from "./Localization/Localization.js";
import { EMPTY_OBJECT as c } from "../utils/value/constants.js";
class m {
// [TODO]: Change the error handling strategy.
constructor(t) {
o(this, "components", []);
o(this, "options");
o(this, "localization");
o(this, "loadingContext");
o(this, "session", new l());
o(this, "onError");
/**
* Updates global configurations, resets the internal state and remounts each element.
* @param options - props to update
* @returns this - the element instance
*/
o(this, "update", async (t = c) => (this.setOptions(t), await this.initialize(), this.components.forEach((i) => {
i.props.core === this && i.update(this.getPropsForComponent(this.options));
}), this));
/**
* Remove the reference of a component
* @param component - reference to the component to be removed
* @returns this - the element instance
*/
o(this, "remove", (t) => (this.components = this.components.filter((i) => i._id !== t._id), t.unmount(), this));
/**
* @internal
* Register components in core to be able to update them all at once
*/
o(this, "registerComponent", (t) => {
t.props.core === this && this.components.push(t);
});
/**
* @internal
* Enhances the config object passed when AdyenPlatformExperience is initialised (environment, clientKey, etc...)
* (Re)Initializes core properties & processes (i18n, etc...)
* @param options - the config object passed when AdyenPlatformExperience is initialised
* @returns this
*/
o(this, "setOptions", (t) => {
var i, n;
return this.options = { ...this.options, ...t }, this.localization.locale = (i = this.options) == null ? void 0 : i.locale, this.localization.customTranslations = (n = this.options) == null ? void 0 : n.translations, this.session.loadingContext = this.loadingContext, this.session.onSessionCreate = this.options.onSessionCreate, this;
});
this.options = { environment: a, ...t }, this.localization = new p(t.locale, t.availableTranslations), this.loadingContext = h(this.options.environment), this.setOptions(t);
}
async initialize() {
return Promise.all([this.localization.ready]).then(() => this);
}
/**
* @internal
* @param options - options that will be merged to the global Checkout props
* @returns props for a new UIElement
*/
getPropsForComponent(t) {
return { ...t };
}
}
o(m, "version", "1.5.0");
export {
m as default
};