@solidgate/client-sdk-loader
Version:
Solidgate client sdk loader
61 lines (60 loc) • 3.52 kB
JavaScript
;
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _a, _SdkLoader_CloudfrontSrc, _SdkLoader_loadAttempt, _SdkLoader_previousAttemptUrl;
Object.defineProperty(exports, "__esModule", { value: true });
class SdkLoader {
static load(sdkUrl) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
// Resolve to null when imported server side. This makes the module
// safe to import in an isomorphic code base.
return Promise.resolve(null);
}
const isPreviousCallWithoutUrl = __classPrivateFieldGet(this, _a, "f", _SdkLoader_previousAttemptUrl) === __classPrivateFieldGet(this, _a, "f", _SdkLoader_CloudfrontSrc);
if (sdkUrl && isPreviousCallWithoutUrl) {
console.error(`SDK Initialization Error: A URL was provided for SDK initialization after a previous attempt without one.
The SDK will proceed using the initial configuration without a URL.`);
}
if (window.PaymentFormSdk) {
return Promise.resolve(window.PaymentFormSdk);
}
if (__classPrivateFieldGet(this, _a, "f", _SdkLoader_loadAttempt)) {
return __classPrivateFieldGet(this, _a, "f", _SdkLoader_loadAttempt);
}
__classPrivateFieldSet(this, _a, sdkUrl || __classPrivateFieldGet(this, _a, "f", _SdkLoader_CloudfrontSrc), "f", _SdkLoader_previousAttemptUrl);
const script = document.createElement('script');
script.async = true;
script.src = sdkUrl || __classPrivateFieldGet(this, _a, "f", _SdkLoader_CloudfrontSrc);
script.id = 'solid-payment-form-source';
document.head.appendChild(script);
__classPrivateFieldSet(this, _a, new Promise((resolve, reject) => {
try {
script.onerror = (e) => {
__classPrivateFieldSet(this, _a, null, "f", _SdkLoader_loadAttempt);
reject(e);
};
script.onload = () => {
resolve(window.PaymentFormSdk);
};
}
catch (e) {
reject(e);
}
}), "f", _SdkLoader_loadAttempt);
return __classPrivateFieldGet(this, _a, "f", _SdkLoader_loadAttempt);
}
}
exports.default = SdkLoader;
_a = SdkLoader;
_SdkLoader_CloudfrontSrc = { value: 'https://cdn.solidgate.com/js/solid-form.js' };
_SdkLoader_loadAttempt = { value: null };
_SdkLoader_previousAttemptUrl = { value: null };