@zonos/elements 1.3.140 → 1.3.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs.js +36 -7
- package/dist/collection/scripts/_zonosBase.js +29 -0
- package/dist/esm/index.js +36 -7
- package/dist/esm-es5/index.js +1 -1
- package/dist/scripts/index.d.ts +1 -0
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/types/scripts/_zonosBase.d.ts +1 -0
- package/dist/zonos-elements/assets/RemoveIcon.svg +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/p-f8e8b50e.system.js +1 -0
- package/package.json +1 -1
- package/dist/zonos-elements/p-26b24d0b.system.js +0 -1
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -127,7 +127,7 @@ const getZonosQaUrl = () => {
|
|
|
127
127
|
return null;
|
|
128
128
|
}
|
|
129
129
|
const qaUrl = extractZonosQaUrl(window.location.href);
|
|
130
|
-
const cdnUrl = "https://v1.3.
|
|
130
|
+
const cdnUrl = "https://v1.3.141.js.zonos.com";
|
|
131
131
|
// when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
|
|
132
132
|
if (!qaUrl &&
|
|
133
133
|
(cdnUrl.includes('test.') ||
|
|
@@ -311,10 +311,10 @@ const zonosLoadUrl = (() => {
|
|
|
311
311
|
}
|
|
312
312
|
return null;
|
|
313
313
|
})();
|
|
314
|
-
const ZONOS_URL = "https://v1.3.
|
|
315
|
-
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.
|
|
316
|
-
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.
|
|
317
|
-
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.
|
|
314
|
+
const ZONOS_URL = "https://v1.3.141.js.zonos.com";
|
|
315
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.141";
|
|
316
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.141";
|
|
317
|
+
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.141";
|
|
318
318
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
319
319
|
const GOOGLE_FONT_REGEX = /^https:\/\/fonts\.googleapis\.com/;
|
|
320
320
|
class Zonos {
|
|
@@ -328,7 +328,7 @@ Zonos.zonosConversionTest = typeof window !== 'undefined' &&
|
|
|
328
328
|
!!window.location.search.match(/\?.*(&*)zonosConversionTest/);
|
|
329
329
|
Zonos._paypalMockResponse = null;
|
|
330
330
|
Zonos.isBigCommerce = false;
|
|
331
|
-
Zonos.releaseDate = "
|
|
331
|
+
Zonos.releaseDate = "1734130586435";
|
|
332
332
|
Zonos.isLegacyCheckout = false;
|
|
333
333
|
Zonos.domain = typeof window !== 'undefined'
|
|
334
334
|
? // domain that embeds the iframe
|
|
@@ -344,7 +344,7 @@ Zonos.showBaseForeign = typeof window !== 'undefined' &&
|
|
|
344
344
|
Zonos.isNpm = true;
|
|
345
345
|
Zonos.zonosQaUrl = null;
|
|
346
346
|
Zonos.zonosQaUrlApi = null;
|
|
347
|
-
Zonos.version = `v${"1.3.
|
|
347
|
+
Zonos.version = `v${"1.3.141"}`;
|
|
348
348
|
Zonos.modeAlerted = false;
|
|
349
349
|
Zonos.cartData = null;
|
|
350
350
|
Zonos.paypal = null;
|
|
@@ -421,6 +421,8 @@ Zonos.init = async (params) => {
|
|
|
421
421
|
document.body.appendChild(hiddenButton);
|
|
422
422
|
}
|
|
423
423
|
handleFetch.log('init zonos');
|
|
424
|
+
// inject custom script for hosted checkout if can find it in metadata
|
|
425
|
+
_a.injectCustomScriptForHostedCheckout();
|
|
424
426
|
// inject zonos cdn
|
|
425
427
|
_a.injectZonosCdn();
|
|
426
428
|
// inject css for zonos elements
|
|
@@ -440,6 +442,33 @@ Zonos.init = async (params) => {
|
|
|
440
442
|
});
|
|
441
443
|
_a.doneInit = true;
|
|
442
444
|
};
|
|
445
|
+
Zonos.injectCustomScriptForHostedCheckout = () => {
|
|
446
|
+
const cartData = _a.cartData;
|
|
447
|
+
const metadata = (cartData === null || cartData === void 0 ? void 0 : cartData.metadata) || [];
|
|
448
|
+
const headerScript = metadata.find(meta => meta.key === 'customHeaderScript');
|
|
449
|
+
const footerScript = metadata.find(meta => meta.key === 'customFooterScript');
|
|
450
|
+
// Only inject the script if checkout is on Zonos hosted checkout and custom script is available
|
|
451
|
+
if (!window.Zonos.isLegacyCheckout || (!headerScript && !footerScript)) {
|
|
452
|
+
handleFetch.log('Skip injecting custom script for hosted checkout', 'info', {
|
|
453
|
+
footerScript,
|
|
454
|
+
headerScript,
|
|
455
|
+
isLegacyCheckout: window.Zonos.isLegacyCheckout,
|
|
456
|
+
});
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (headerScript) {
|
|
460
|
+
handleFetch.log('Injecting custom header script');
|
|
461
|
+
const script = document.createElement('script');
|
|
462
|
+
script.textContent = headerScript.value;
|
|
463
|
+
document.head.appendChild(script);
|
|
464
|
+
}
|
|
465
|
+
if (footerScript) {
|
|
466
|
+
handleFetch.log('Injecting custom footer script');
|
|
467
|
+
const script = document.createElement('script');
|
|
468
|
+
script.textContent = footerScript.value;
|
|
469
|
+
document.body.appendChild(script);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
443
472
|
Zonos.displayCurrency = () => {
|
|
444
473
|
const zonosHello = document.querySelector('zonos-hello');
|
|
445
474
|
if (zonosHello) {
|
|
@@ -135,6 +135,8 @@ Zonos.init = async (params) => {
|
|
|
135
135
|
document.body.appendChild(hiddenButton);
|
|
136
136
|
}
|
|
137
137
|
log('init zonos');
|
|
138
|
+
// inject custom script for hosted checkout if can find it in metadata
|
|
139
|
+
_a.injectCustomScriptForHostedCheckout();
|
|
138
140
|
// inject zonos cdn
|
|
139
141
|
_a.injectZonosCdn();
|
|
140
142
|
// inject css for zonos elements
|
|
@@ -154,6 +156,33 @@ Zonos.init = async (params) => {
|
|
|
154
156
|
});
|
|
155
157
|
_a.doneInit = true;
|
|
156
158
|
};
|
|
159
|
+
Zonos.injectCustomScriptForHostedCheckout = () => {
|
|
160
|
+
const cartData = _a.cartData;
|
|
161
|
+
const metadata = (cartData === null || cartData === void 0 ? void 0 : cartData.metadata) || [];
|
|
162
|
+
const headerScript = metadata.find(meta => meta.key === 'customHeaderScript');
|
|
163
|
+
const footerScript = metadata.find(meta => meta.key === 'customFooterScript');
|
|
164
|
+
// Only inject the script if checkout is on Zonos hosted checkout and custom script is available
|
|
165
|
+
if (!window.Zonos.isLegacyCheckout || (!headerScript && !footerScript)) {
|
|
166
|
+
log('Skip injecting custom script for hosted checkout', 'info', {
|
|
167
|
+
footerScript,
|
|
168
|
+
headerScript,
|
|
169
|
+
isLegacyCheckout: window.Zonos.isLegacyCheckout,
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (headerScript) {
|
|
174
|
+
log('Injecting custom header script');
|
|
175
|
+
const script = document.createElement('script');
|
|
176
|
+
script.textContent = headerScript.value;
|
|
177
|
+
document.head.appendChild(script);
|
|
178
|
+
}
|
|
179
|
+
if (footerScript) {
|
|
180
|
+
log('Injecting custom footer script');
|
|
181
|
+
const script = document.createElement('script');
|
|
182
|
+
script.textContent = footerScript.value;
|
|
183
|
+
document.body.appendChild(script);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
157
186
|
Zonos.displayCurrency = () => {
|
|
158
187
|
const zonosHello = document.querySelector('zonos-hello');
|
|
159
188
|
if (zonosHello) {
|
package/dist/esm/index.js
CHANGED
|
@@ -124,7 +124,7 @@ const getZonosQaUrl = () => {
|
|
|
124
124
|
return null;
|
|
125
125
|
}
|
|
126
126
|
const qaUrl = extractZonosQaUrl(window.location.href);
|
|
127
|
-
const cdnUrl = "https://v1.3.
|
|
127
|
+
const cdnUrl = "https://v1.3.141.js.zonos.com";
|
|
128
128
|
// when the qaUrl is not set and the built URL is from the test domain, use the test domain for testing
|
|
129
129
|
if (!qaUrl &&
|
|
130
130
|
(cdnUrl.includes('test.') ||
|
|
@@ -308,10 +308,10 @@ const zonosLoadUrl = (() => {
|
|
|
308
308
|
}
|
|
309
309
|
return null;
|
|
310
310
|
})();
|
|
311
|
-
const ZONOS_URL = "https://v1.3.
|
|
312
|
-
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.
|
|
313
|
-
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.
|
|
314
|
-
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.
|
|
311
|
+
const ZONOS_URL = "https://v1.3.141.js.zonos.com";
|
|
312
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.141";
|
|
313
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.141";
|
|
314
|
+
const CDNJS_ZONOS_URL = "https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.141";
|
|
315
315
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
316
316
|
const GOOGLE_FONT_REGEX = /^https:\/\/fonts\.googleapis\.com/;
|
|
317
317
|
class Zonos {
|
|
@@ -325,7 +325,7 @@ Zonos.zonosConversionTest = typeof window !== 'undefined' &&
|
|
|
325
325
|
!!window.location.search.match(/\?.*(&*)zonosConversionTest/);
|
|
326
326
|
Zonos._paypalMockResponse = null;
|
|
327
327
|
Zonos.isBigCommerce = false;
|
|
328
|
-
Zonos.releaseDate = "
|
|
328
|
+
Zonos.releaseDate = "1734130586435";
|
|
329
329
|
Zonos.isLegacyCheckout = false;
|
|
330
330
|
Zonos.domain = typeof window !== 'undefined'
|
|
331
331
|
? // domain that embeds the iframe
|
|
@@ -341,7 +341,7 @@ Zonos.showBaseForeign = typeof window !== 'undefined' &&
|
|
|
341
341
|
Zonos.isNpm = true;
|
|
342
342
|
Zonos.zonosQaUrl = null;
|
|
343
343
|
Zonos.zonosQaUrlApi = null;
|
|
344
|
-
Zonos.version = `v${"1.3.
|
|
344
|
+
Zonos.version = `v${"1.3.141"}`;
|
|
345
345
|
Zonos.modeAlerted = false;
|
|
346
346
|
Zonos.cartData = null;
|
|
347
347
|
Zonos.paypal = null;
|
|
@@ -418,6 +418,8 @@ Zonos.init = async (params) => {
|
|
|
418
418
|
document.body.appendChild(hiddenButton);
|
|
419
419
|
}
|
|
420
420
|
log('init zonos');
|
|
421
|
+
// inject custom script for hosted checkout if can find it in metadata
|
|
422
|
+
_a.injectCustomScriptForHostedCheckout();
|
|
421
423
|
// inject zonos cdn
|
|
422
424
|
_a.injectZonosCdn();
|
|
423
425
|
// inject css for zonos elements
|
|
@@ -437,6 +439,33 @@ Zonos.init = async (params) => {
|
|
|
437
439
|
});
|
|
438
440
|
_a.doneInit = true;
|
|
439
441
|
};
|
|
442
|
+
Zonos.injectCustomScriptForHostedCheckout = () => {
|
|
443
|
+
const cartData = _a.cartData;
|
|
444
|
+
const metadata = (cartData === null || cartData === void 0 ? void 0 : cartData.metadata) || [];
|
|
445
|
+
const headerScript = metadata.find(meta => meta.key === 'customHeaderScript');
|
|
446
|
+
const footerScript = metadata.find(meta => meta.key === 'customFooterScript');
|
|
447
|
+
// Only inject the script if checkout is on Zonos hosted checkout and custom script is available
|
|
448
|
+
if (!window.Zonos.isLegacyCheckout || (!headerScript && !footerScript)) {
|
|
449
|
+
log('Skip injecting custom script for hosted checkout', 'info', {
|
|
450
|
+
footerScript,
|
|
451
|
+
headerScript,
|
|
452
|
+
isLegacyCheckout: window.Zonos.isLegacyCheckout,
|
|
453
|
+
});
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (headerScript) {
|
|
457
|
+
log('Injecting custom header script');
|
|
458
|
+
const script = document.createElement('script');
|
|
459
|
+
script.textContent = headerScript.value;
|
|
460
|
+
document.head.appendChild(script);
|
|
461
|
+
}
|
|
462
|
+
if (footerScript) {
|
|
463
|
+
log('Injecting custom footer script');
|
|
464
|
+
const script = document.createElement('script');
|
|
465
|
+
script.textContent = footerScript.value;
|
|
466
|
+
document.body.appendChild(script);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
440
469
|
Zonos.displayCurrency = () => {
|
|
441
470
|
const zonosHello = document.querySelector('zonos-hello');
|
|
442
471
|
if (zonosHello) {
|
package/dist/esm-es5/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(n,e,o,t){function r(n){return n instanceof o?n:new o((function(e){e(n)}))}return new(o||(o=Promise))((function(o,i){function a(n){try{u(t.next(n))}catch(n){i(n)}}function s(n){try{u(t["throw"](n))}catch(n){i(n)}}function u(n){n.done?o(n.value):r(n.value).then(a,s)}u((t=t.apply(n,e||[])).next())}))};var __generator=this&&this.__generator||function(n,e){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},t,r,i,a;return a={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function s(n){return function(e){return u([n,e])}}function u(s){if(t)throw new TypeError("Generator is already executing.");while(a&&(a=0,s[0]&&(o=0)),o)try{if(t=1,r&&(i=s[0]&2?r["return"]:s[0]?r["throw"]||((i=r["return"])&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;if(r=0,i)s=[s[0]&2,i.value];switch(s[0]){case 0:case 1:i=s;break;case 4:o.label++;return{value:s[1],done:false};case 5:o.label++;r=s[1];s=[0];continue;case 7:s=o.ops.pop();o.trys.pop();continue;default:if(!(i=o.trys,i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){o=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(s[0]===6&&o.label<i[1]){o.label=i[1];i=s;break}if(i&&o.label<i[2]){o.label=i[2];o.ops.push(s);break}if(i[2])o.ops.pop();o.trys.pop();continue}s=e.call(n,o)}catch(n){s=[6,n];r=0}finally{t=i=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};import{l as log,h as handleFetch,a as logError}from"./handleFetch-22cb914b.js";import{s as setupCartData,c as checkoutHiddenBtnSelector}from"./CheckoutConfig-930107d4.js";export{c as checkoutHiddenBtnSelector,d as domesticRedirectedBtnSelector}from"./CheckoutConfig-930107d4.js";var checkIfLoadVersionDomain=function(n){var e=n.loadScriptSrc;if(!e){return{currentLoadScriptUrl:"",isForceLoadVersionDomain:false,isWhiteListed:false}}var o=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"];var t=["qa.js.zonos.com"];var r=new URL(e).origin;var i=o.some((function(n){return r.includes(n)}));var a=t.some((function(n){return r.includes(n)}));return{currentLoadScriptUrl:r,isForceLoadVersionDomain:a,isWhiteListed:i}};var fallbackList=["jsdelivr","cdnjs","unpkg","vercel"];var MAIN_LOAD_CDN_TYPE="jsdelivr";var getNextFallbackUrl=function(n){var e=fallbackList.indexOf(n);var o=fallbackList[e+1];return o||null};var getWithTestPublicCredential=function(){return __awaiter(void 0,void 0,void 0,(function(){var n,e,o,t,r;return __generator(this,(function(i){switch(i.label){case 0:n=window.location.search.includes("zonosTestMode=1");if(!n||!window.Zonos.zonosApiKey){return[2,null]}log("[ZONOS - loadZonos] Attempt test public credential","info");if(!!window.Zonos.zonosApiKey.includes("credential_test")){log("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info");return[2,null]}return[4,handleFetch("/api/get-test-public-credential")];case 1:e=i.sent(),o=e.errors,t=e.json;if(o.length||!t){logError("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",o);return[2,null]}r=t.publicCredential;if(!r){logError("[ZONOS - loadZonos] No test public key credential. Keep using production key");return[2,null]}log("[ZONOS - loadZonos] Retrieve new test public token ".concat(r),"info");return[2,r]}}))}))};var extractZonosQaUrl=function(n){if(!n){return null}var e=new URL(n).searchParams;var o=e.get("zonosQaUrl");if(!o){return null}var t=/[^a-zA-Z0-9-_]+/.test(o);if(!!t){return null}return o};var getZonosQaUrl=function(){var n=window&&window.location.href.includes("forceLoadCdn");if(typeof window==="undefined"||n){return null}var e=extractZonosQaUrl(window.location.href);var o="https://v1.3.140.js.zonos.com";if(!e&&(o.includes("test.")||o.includes("test-"))){return o}if(!e&&["dev.demo.elements.zonos.com"].includes(window.location.hostname)){return"https://dev.elements.zonos.com"}if(!e){return null}if(e==="dev-elements"){return"https://dev.elements.zonos.com"}var t="preview.js.zonos.com";var r="https://".concat(e,".").concat(t);log("[ZONOS-WARNING] using '".concat(r,"' for loading elements script"),"warn");void fetch(r).then((function(){window.sessionStorage.removeItem("zonos--checkout-session-id");window.sessionStorage.removeItem("zonos--client-secret")})).catch((function(){alert("[ZONOS-WARNING] '".concat(r,"' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE"));var n=new URLSearchParams(window.location.search);n.delete("zonosQaUrl");var e=window.location.pathname;var o="".concat(e,"?").concat(n.toString());window.history.replaceState(window.history.state,"",o);window.location.reload();return null}));return r};var V3_URL="https://js.stripe.com/v3";var V3_URL_REGEX=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;var EXISTING_SCRIPT_MESSAGE="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";var zonosStripeFindScript=function(){var n=document.querySelectorAll('script[src^="'.concat(V3_URL,'"]'));for(var e=0;e<n.length;e++){var o=n[e];if(!o){continue}if(!V3_URL_REGEX.test(o.src)){continue}return o}return null};var stripePromise$1=null;var injectScript=function(n){var e=n&&!n.advancedFraudSignals?"?advancedFraudSignals=false":"";var o=document.createElement("script");o.src="".concat(V3_URL).concat(e);var t=document.head||document.body;if(!t){logError("Expected document.body not to be null. Stripe.js requires a <body> element.");return null}t.appendChild(o);return o};var zonosStripeLoadScript=function(n){if(stripePromise$1!==null){return stripePromise$1}stripePromise$1=new Promise((function(e,o){if(typeof window==="undefined"||typeof document==="undefined"){e(null);return}if(window.Stripe&&n){console.warn(EXISTING_SCRIPT_MESSAGE)}if(window.Stripe){e(window.Stripe);return}try{var t=zonosStripeFindScript();if(t&&n){console.warn(EXISTING_SCRIPT_MESSAGE)}else if(!t){t=injectScript(n)}t===null||t===void 0?void 0:t.addEventListener("load",(function(){if(window.Stripe){e(window.Stripe)}else{o(new Error("Stripe.js not available"))}}));t===null||t===void 0?void 0:t.addEventListener("error",(function(){o(new Error("Failed to load Stripe.js"))}))}catch(n){o(n);return}}));return stripePromise$1};var registerWrapper=function(n,e){if(!n||!n._registerWrapper){return}n._registerWrapper({name:"stripe-js",startTime:e})};var initStripe=function(n,e,o){if(n===null){return null}var t=n.apply(undefined,e);registerWrapper(t,o);return t};var stripePromise=Promise.resolve().then((function(){return zonosStripeLoadScript(null)}));var loadCalled=false;stripePromise.catch((function(n){if(!loadCalled){console.warn(n)}}));var zonosLoadStripe=function(){var n=[];for(var e=0;e<arguments.length;e++){n[e]=arguments[e]}return __awaiter(void 0,void 0,void 0,(function(){var e;return __generator(this,(function(o){loadCalled=true;e=Date.now();return[2,stripePromise.then((function(o){return initStripe(o,n,e)}))]}))}))};var TEMP_CART_ID_QUERY_PARAM="tempCartUUID";var getCartIdFromQueryParam=function(){var n=new URLSearchParams(window.location.search);var e=n.get(TEMP_CART_ID_QUERY_PARAM);return e};var _a;var zonosLoadUrl=function(){if(typeof document==="undefined"){return null}var n=document.querySelector('script[src*="/zonos.js"]');var e=checkIfLoadVersionDomain({loadScriptSrc:n===null||n===void 0?void 0:n.src}),o=e.currentLoadScriptUrl,t=e.isWhiteListed;if(t){return o}return null}();var ZONOS_URL="https://v1.3.140.js.zonos.com";var JS_DELIVR_ZONOS_URL=zonosLoadUrl||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.140";var UNPKG_ZONOS_URL="https://unpkg.com/@zonos/elements@1.3.140";var CDNJS_ZONOS_URL="https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.140";var GOOGLE_FONT_URL="https://fonts.googleapis.com";var GOOGLE_FONT_REGEX=/^https:\/\/fonts\.googleapis\.com/;var Zonos=function(){function n(){}return n}();_a=Zonos;Zonos.doneInit=false;Zonos.debug=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/);Zonos.zonosConversionTest=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/);Zonos._paypalMockResponse=null;Zonos.isBigCommerce=false;Zonos.releaseDate="1734113749964";Zonos.isLegacyCheckout=false;Zonos.domain=typeof window!=="undefined"?window.location!=window.parent.location&&document.referrer||document.location.hostname:"";Zonos.showBaseForeign=typeof window!=="undefined"&&window.location.search.includes("zonosShowBaseForeign");Zonos.isNpm=true;Zonos.zonosQaUrl=null;Zonos.zonosQaUrlApi=null;Zonos.version="v".concat("1.3.140");Zonos.modeAlerted=false;Zonos.cartData=null;Zonos.paypal=null;Zonos.getCurrentTimestamp=function(){return(new Date).getTime()};Zonos.zonosController=null;Zonos.init=function(n){return __awaiter(void 0,void 0,void 0,(function(){var e,o,t,r,i,a,s,u,c,l,d,f,v,_,m;return __generator(this,(function(p){switch(p.label){case 0:e=n.appearance,o=n.checkoutSettings,t=n.currencyConverter,r=n.helloSettings,i=n.onCountryChange,a=n.overrideCurrencyFormat,s=n.storeId,u=n.zonosApiKey;_a.cartId=getCartIdFromQueryParam();if(_a.doneInit){return[2]}log("====== ZONOS DEBUG MODE: on (".concat(_a.version,") ======"));_a.zonosApiKey=u;_a.storeId=s;if(!_a.isNpm)return[3,4];log("====== ZONOS LOADING FROM NPM ======");c=getZonosQaUrl();if(c&&!window.isZonosPreview){log('====== RE-INJECT "zonos.js" FROM PRVIEW: '.concat(c," ======"),"info");l=document.createElement("script");l.src="".concat(c,"/dist/scripts/zonos.js");document.head.appendChild(l);l.addEventListener("load",(function(){window.Zonos.isNpm=_a.isNpm;window.Zonos.isBigCommerce=_a.isBigCommerce;window.Zonos.isLegacyCheckout=_a.isLegacyCheckout;void window.Zonos.init(n)}));l.addEventListener("error",(function(){alert('[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: '.concat(c))}));window.isZonosPreview=true;return[2]}if(!u&&!_a.cartId){logError("Zonos API key is required unless `tempCartUUID` is provided in url query params.");return[2]}if(!(!_a.cartData&&_a.cartId))return[3,2];log("Initialize cart data");return[4,setupCartData(_a.cartId)];case 1:d=p.sent();if(!d){logError("Failed to get cart data");return[2]}_a.cartData=d.cartData;_a.zonosApiKey=d.zonosApiKey;p.label=2;case 2:return[4,getWithTestPublicCredential()];case 3:f=p.sent();if(f){_a.zonosApiKey=f}p.label=4;case 4:v=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");_=_a.cartId&&_a.cartData||!!v;if(_){log("Cart data or stripe client secret is available, inject hidden button and trigger checkout");m=document.createElement("button");m.style.display="none";m.id="".concat(checkoutHiddenBtnSelector);document.body.appendChild(m)}log("init zonos");_a.injectZonosCdn();_a.injectZonosCss();_a.injectFonts();_a.injectController({config:{appearance:e,checkoutSettings:o,currencyConverter:t,helloSettings:r,onCountryChange:i,overrideCurrencyFormat:a}});_a.doneInit=true;return[2]}}))}))};Zonos.displayCurrency=function(){var n=document.querySelector("zonos-hello");if(n){void n.displayCurrency()}};Zonos.openHelloDialog=function(n){var e=document.querySelector("zonos-hello");if(e){void e.openHelloDialog(n!==null&&n!==void 0?n:true)}};Zonos.showNotification=function(n){var e;void((e=_a.zonosController)===null||e===void 0?void 0:e.showNotification(n))};Zonos.updateOrganizationName=function(n){var e;void((e=_a.zonosController)===null||e===void 0?void 0:e.updateOrganizationName(n))};Zonos.disablePlaceOrderButtons=function(n){var e=n.autoEnable,o=e===void 0?true:e,t=n.config,r=n.disable,i=n.placeOrderButtonSelector;var a;if((a=t.checkoutSettings)===null||a===void 0?void 0:a.disablePlaceOrderButtonActivation){return}if(i){var s=document.querySelectorAll(i);var u=function(n){var e=n.target;if(e.getAttribute("disabled")){n.preventDefault();n.stopPropagation()}};s.forEach((function(n){var e=n.getAttribute("data-zonos-checkout-attached");if(e){return}if(r){n.setAttribute("disabled","true");n.addEventListener("click",u)}else{n.removeAttribute("disabled");n.removeEventListener("click",u)}}));if(o&&r){setTimeout((function(){s.forEach((function(n){n.removeAttribute("disabled");n.removeEventListener("click",u)}))}),5e3)}}};Zonos.injectController=function(n){var e=n.config;var o;if(document.querySelector("zonos-controller")){return}if((o=e.checkoutSettings)===null||o===void 0?void 0:o.placeOrderButtonSelector){var t=e.checkoutSettings.placeOrderButtonSelector;_a.disablePlaceOrderButtons({config:e,disable:true,placeOrderButtonSelector:t});var r=new MutationObserver((function(){_a.disablePlaceOrderButtons({config:e,disable:true,placeOrderButtonSelector:t})}));r.observe(document.body,{childList:true,subtree:true})}var i=document.createElement("zonos-controller");i.config=e;i.zonosApiKey=_a.zonosApiKey||"";i.addEventListener("stripeInitEvent",(function(n){return __awaiter(void 0,void 0,void 0,(function(){var e,o;return __generator(this,(function(t){switch(t.label){case 0:e=n.detail;log("loading Stripe");return[4,zonosLoadStripe(e.publishableKey)];case 1:o=t.sent();if(!o){logError("API seems to be invalid or missing. Failed to load Stripe");return[2]}window.Zonos.stripe=o;void i.initCheckoutElement(o);return[2]}}))}))}));document.body.appendChild(i);_a.zonosController=i;log("Zonos controller injected!")};Zonos.injectScript=function(n){var e=n.cdnType,o=n.isModule,t=n.theRestUrl;var r=_a.getZonosUrl(e);var i="".concat(r,"/").concat(t);var a=function(){var n=document.querySelector('script[src="'.concat(i,'"]'));return!!n};if(a()){log('Zonos script "'.concat(i,'" already exists in the document'),"warn");return}var s=document.head||document.body;var u=document.createElement("script");if(!!o){u.type="module"}else{u.noModule=true}u.src=i;u.crossOrigin="anonymous";u.onerror=function(){logError("Failed to load ".concat(u.src));var n=getNextFallbackUrl(e);if(!n){return}_a.injectScript({cdnType:n,isModule:o,theRestUrl:t})};s.appendChild(u)};Zonos.getZonosUrl=function(n){var e=function(){switch(n){case"jsdelivr":return JS_DELIVR_ZONOS_URL;case"unpkg":return UNPKG_ZONOS_URL;case"cdnjs":return CDNJS_ZONOS_URL;case"vercel":return ZONOS_URL}};if(_a.isNpm){var o=getZonosQaUrl();return o||e()}return e()};Zonos.injectZonosCdn=function(){_a.injectScript({cdnType:MAIN_LOAD_CDN_TYPE,isModule:true,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"});_a.injectScript({cdnType:MAIN_LOAD_CDN_TYPE,isModule:false,theRestUrl:"dist/zonos-elements/zonos-elements.js"});log("Zonos cdn script injected!")};Zonos.injectStylesheet=function(n){var e=n.cdnType,o=n.theRestUrl;var t=_a.getZonosUrl(e);var r=document.head||document.body;var i=document.createElement("link");i.rel="preconnect";i.href="".concat(ZONOS_URL,"/");r.appendChild(i);var a=document.createElement("link");a.rel="stylesheet";a.href="".concat(t,"/").concat(o);a.onerror=function(){logError("Failed to load ".concat(a.href));var n=getNextFallbackUrl(e);if(!n){return}_a.injectStylesheet({cdnType:n,theRestUrl:o})};r.appendChild(a)};Zonos.injectZonosCss=function(){var n=function(){return!!document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')};if(n()){log("Zonos style links already injected","warn");return}_a.injectStylesheet({cdnType:MAIN_LOAD_CDN_TYPE,theRestUrl:"dist/zonos-elements/zonos-elements.css"});log("Zonos style css injected!")};Zonos.injectFonts=function(){var n=function(){var n=document.querySelectorAll('link[rel="stylesheet"][href^="'.concat(GOOGLE_FONT_URL,'"]'));for(var e=0;e<n.length;e++){var o=n[e];if(!o){continue}if(GOOGLE_FONT_REGEX.test(o.href)){continue}return o}return null};if(n()){log("Inter font already injected","warn");return}var e=document.head||document.body;var o=document.createElement("link");o.rel="preconnect";o.href=GOOGLE_FONT_URL;e.appendChild(o);var t=document.createElement("link");t.rel="stylesheet";t.href="".concat(GOOGLE_FONT_URL,"/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");e.appendChild(t);log("Zonos font injected!")};Zonos.setupGoogleFont=function(n){var e;void((e=_a.zonosController)===null||e===void 0?void 0:e.setupGoogleFont(n))};Zonos.injectSupportGoogleFont=function(n){var e;log("[FONT] injecting ".concat(n));var o=(e=n.match(/family=(.*?):/))===null||e===void 0?void 0:e[1];var t=document.head||document.body;if(!document.querySelector('link[rel="preconnect"][href^="'.concat(GOOGLE_FONT_URL,'"]'))){var r=document.createElement("link");r.rel="preconnect";r.href=GOOGLE_FONT_URL;t.appendChild(r)}if(document.querySelector('link[rel="stylesheet"][href="'.concat(n,'"]'))){log("[FONT] ".concat(o," font already injected"),"warn");return}var i=document.createElement("link");i.rel="stylesheet";i.href=n;t.appendChild(i);log("[FONT] ".concat(o," font injected!"))};export{Zonos};
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(n,e,o,t){function r(n){return n instanceof o?n:new o((function(e){e(n)}))}return new(o||(o=Promise))((function(o,i){function a(n){try{c(t.next(n))}catch(n){i(n)}}function s(n){try{c(t["throw"](n))}catch(n){i(n)}}function c(n){n.done?o(n.value):r(n.value).then(a,s)}c((t=t.apply(n,e||[])).next())}))};var __generator=this&&this.__generator||function(n,e){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},t,r,i,a;return a={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function s(n){return function(e){return c([n,e])}}function c(s){if(t)throw new TypeError("Generator is already executing.");while(a&&(a=0,s[0]&&(o=0)),o)try{if(t=1,r&&(i=s[0]&2?r["return"]:s[0]?r["throw"]||((i=r["return"])&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;if(r=0,i)s=[s[0]&2,i.value];switch(s[0]){case 0:case 1:i=s;break;case 4:o.label++;return{value:s[1],done:false};case 5:o.label++;r=s[1];s=[0];continue;case 7:s=o.ops.pop();o.trys.pop();continue;default:if(!(i=o.trys,i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){o=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(s[0]===6&&o.label<i[1]){o.label=i[1];i=s;break}if(i&&o.label<i[2]){o.label=i[2];o.ops.push(s);break}if(i[2])o.ops.pop();o.trys.pop();continue}s=e.call(n,o)}catch(n){s=[6,n];r=0}finally{t=i=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};import{l as log,h as handleFetch,a as logError}from"./handleFetch-22cb914b.js";import{s as setupCartData,c as checkoutHiddenBtnSelector}from"./CheckoutConfig-930107d4.js";export{c as checkoutHiddenBtnSelector,d as domesticRedirectedBtnSelector}from"./CheckoutConfig-930107d4.js";var checkIfLoadVersionDomain=function(n){var e=n.loadScriptSrc;if(!e){return{currentLoadScriptUrl:"",isForceLoadVersionDomain:false,isWhiteListed:false}}var o=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"];var t=["qa.js.zonos.com"];var r=new URL(e).origin;var i=o.some((function(n){return r.includes(n)}));var a=t.some((function(n){return r.includes(n)}));return{currentLoadScriptUrl:r,isForceLoadVersionDomain:a,isWhiteListed:i}};var fallbackList=["jsdelivr","cdnjs","unpkg","vercel"];var MAIN_LOAD_CDN_TYPE="jsdelivr";var getNextFallbackUrl=function(n){var e=fallbackList.indexOf(n);var o=fallbackList[e+1];return o||null};var getWithTestPublicCredential=function(){return __awaiter(void 0,void 0,void 0,(function(){var n,e,o,t,r;return __generator(this,(function(i){switch(i.label){case 0:n=window.location.search.includes("zonosTestMode=1");if(!n||!window.Zonos.zonosApiKey){return[2,null]}log("[ZONOS - loadZonos] Attempt test public credential","info");if(!!window.Zonos.zonosApiKey.includes("credential_test")){log("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info");return[2,null]}return[4,handleFetch("/api/get-test-public-credential")];case 1:e=i.sent(),o=e.errors,t=e.json;if(o.length||!t){logError("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",o);return[2,null]}r=t.publicCredential;if(!r){logError("[ZONOS - loadZonos] No test public key credential. Keep using production key");return[2,null]}log("[ZONOS - loadZonos] Retrieve new test public token ".concat(r),"info");return[2,r]}}))}))};var extractZonosQaUrl=function(n){if(!n){return null}var e=new URL(n).searchParams;var o=e.get("zonosQaUrl");if(!o){return null}var t=/[^a-zA-Z0-9-_]+/.test(o);if(!!t){return null}return o};var getZonosQaUrl=function(){var n=window&&window.location.href.includes("forceLoadCdn");if(typeof window==="undefined"||n){return null}var e=extractZonosQaUrl(window.location.href);var o="https://v1.3.141.js.zonos.com";if(!e&&(o.includes("test.")||o.includes("test-"))){return o}if(!e&&["dev.demo.elements.zonos.com"].includes(window.location.hostname)){return"https://dev.elements.zonos.com"}if(!e){return null}if(e==="dev-elements"){return"https://dev.elements.zonos.com"}var t="preview.js.zonos.com";var r="https://".concat(e,".").concat(t);log("[ZONOS-WARNING] using '".concat(r,"' for loading elements script"),"warn");void fetch(r).then((function(){window.sessionStorage.removeItem("zonos--checkout-session-id");window.sessionStorage.removeItem("zonos--client-secret")})).catch((function(){alert("[ZONOS-WARNING] '".concat(r,"' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE"));var n=new URLSearchParams(window.location.search);n.delete("zonosQaUrl");var e=window.location.pathname;var o="".concat(e,"?").concat(n.toString());window.history.replaceState(window.history.state,"",o);window.location.reload();return null}));return r};var V3_URL="https://js.stripe.com/v3";var V3_URL_REGEX=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;var EXISTING_SCRIPT_MESSAGE="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";var zonosStripeFindScript=function(){var n=document.querySelectorAll('script[src^="'.concat(V3_URL,'"]'));for(var e=0;e<n.length;e++){var o=n[e];if(!o){continue}if(!V3_URL_REGEX.test(o.src)){continue}return o}return null};var stripePromise$1=null;var injectScript=function(n){var e=n&&!n.advancedFraudSignals?"?advancedFraudSignals=false":"";var o=document.createElement("script");o.src="".concat(V3_URL).concat(e);var t=document.head||document.body;if(!t){logError("Expected document.body not to be null. Stripe.js requires a <body> element.");return null}t.appendChild(o);return o};var zonosStripeLoadScript=function(n){if(stripePromise$1!==null){return stripePromise$1}stripePromise$1=new Promise((function(e,o){if(typeof window==="undefined"||typeof document==="undefined"){e(null);return}if(window.Stripe&&n){console.warn(EXISTING_SCRIPT_MESSAGE)}if(window.Stripe){e(window.Stripe);return}try{var t=zonosStripeFindScript();if(t&&n){console.warn(EXISTING_SCRIPT_MESSAGE)}else if(!t){t=injectScript(n)}t===null||t===void 0?void 0:t.addEventListener("load",(function(){if(window.Stripe){e(window.Stripe)}else{o(new Error("Stripe.js not available"))}}));t===null||t===void 0?void 0:t.addEventListener("error",(function(){o(new Error("Failed to load Stripe.js"))}))}catch(n){o(n);return}}));return stripePromise$1};var registerWrapper=function(n,e){if(!n||!n._registerWrapper){return}n._registerWrapper({name:"stripe-js",startTime:e})};var initStripe=function(n,e,o){if(n===null){return null}var t=n.apply(undefined,e);registerWrapper(t,o);return t};var stripePromise=Promise.resolve().then((function(){return zonosStripeLoadScript(null)}));var loadCalled=false;stripePromise.catch((function(n){if(!loadCalled){console.warn(n)}}));var zonosLoadStripe=function(){var n=[];for(var e=0;e<arguments.length;e++){n[e]=arguments[e]}return __awaiter(void 0,void 0,void 0,(function(){var e;return __generator(this,(function(o){loadCalled=true;e=Date.now();return[2,stripePromise.then((function(o){return initStripe(o,n,e)}))]}))}))};var TEMP_CART_ID_QUERY_PARAM="tempCartUUID";var getCartIdFromQueryParam=function(){var n=new URLSearchParams(window.location.search);var e=n.get(TEMP_CART_ID_QUERY_PARAM);return e};var _a;var zonosLoadUrl=function(){if(typeof document==="undefined"){return null}var n=document.querySelector('script[src*="/zonos.js"]');var e=checkIfLoadVersionDomain({loadScriptSrc:n===null||n===void 0?void 0:n.src}),o=e.currentLoadScriptUrl,t=e.isWhiteListed;if(t){return o}return null}();var ZONOS_URL="https://v1.3.141.js.zonos.com";var JS_DELIVR_ZONOS_URL=zonosLoadUrl||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.141";var UNPKG_ZONOS_URL="https://unpkg.com/@zonos/elements@1.3.141";var CDNJS_ZONOS_URL="https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.141";var GOOGLE_FONT_URL="https://fonts.googleapis.com";var GOOGLE_FONT_REGEX=/^https:\/\/fonts\.googleapis\.com/;var Zonos=function(){function n(){}return n}();_a=Zonos;Zonos.doneInit=false;Zonos.debug=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/);Zonos.zonosConversionTest=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/);Zonos._paypalMockResponse=null;Zonos.isBigCommerce=false;Zonos.releaseDate="1734130586435";Zonos.isLegacyCheckout=false;Zonos.domain=typeof window!=="undefined"?window.location!=window.parent.location&&document.referrer||document.location.hostname:"";Zonos.showBaseForeign=typeof window!=="undefined"&&window.location.search.includes("zonosShowBaseForeign");Zonos.isNpm=true;Zonos.zonosQaUrl=null;Zonos.zonosQaUrlApi=null;Zonos.version="v".concat("1.3.141");Zonos.modeAlerted=false;Zonos.cartData=null;Zonos.paypal=null;Zonos.getCurrentTimestamp=function(){return(new Date).getTime()};Zonos.zonosController=null;Zonos.init=function(n){return __awaiter(void 0,void 0,void 0,(function(){var e,o,t,r,i,a,s,c,u,l,d,f,v,m,p;return __generator(this,(function(_){switch(_.label){case 0:e=n.appearance,o=n.checkoutSettings,t=n.currencyConverter,r=n.helloSettings,i=n.onCountryChange,a=n.overrideCurrencyFormat,s=n.storeId,c=n.zonosApiKey;_a.cartId=getCartIdFromQueryParam();if(_a.doneInit){return[2]}log("====== ZONOS DEBUG MODE: on (".concat(_a.version,") ======"));_a.zonosApiKey=c;_a.storeId=s;if(!_a.isNpm)return[3,4];log("====== ZONOS LOADING FROM NPM ======");u=getZonosQaUrl();if(u&&!window.isZonosPreview){log('====== RE-INJECT "zonos.js" FROM PRVIEW: '.concat(u," ======"),"info");l=document.createElement("script");l.src="".concat(u,"/dist/scripts/zonos.js");document.head.appendChild(l);l.addEventListener("load",(function(){window.Zonos.isNpm=_a.isNpm;window.Zonos.isBigCommerce=_a.isBigCommerce;window.Zonos.isLegacyCheckout=_a.isLegacyCheckout;void window.Zonos.init(n)}));l.addEventListener("error",(function(){alert('[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: '.concat(u))}));window.isZonosPreview=true;return[2]}if(!c&&!_a.cartId){logError("Zonos API key is required unless `tempCartUUID` is provided in url query params.");return[2]}if(!(!_a.cartData&&_a.cartId))return[3,2];log("Initialize cart data");return[4,setupCartData(_a.cartId)];case 1:d=_.sent();if(!d){logError("Failed to get cart data");return[2]}_a.cartData=d.cartData;_a.zonosApiKey=d.zonosApiKey;_.label=2;case 2:return[4,getWithTestPublicCredential()];case 3:f=_.sent();if(f){_a.zonosApiKey=f}_.label=4;case 4:v=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");m=_a.cartId&&_a.cartData||!!v;if(m){log("Cart data or stripe client secret is available, inject hidden button and trigger checkout");p=document.createElement("button");p.style.display="none";p.id="".concat(checkoutHiddenBtnSelector);document.body.appendChild(p)}log("init zonos");_a.injectCustomScriptForHostedCheckout();_a.injectZonosCdn();_a.injectZonosCss();_a.injectFonts();_a.injectController({config:{appearance:e,checkoutSettings:o,currencyConverter:t,helloSettings:r,onCountryChange:i,overrideCurrencyFormat:a}});_a.doneInit=true;return[2]}}))}))};Zonos.injectCustomScriptForHostedCheckout=function(){var n=_a.cartData;var e=(n===null||n===void 0?void 0:n.metadata)||[];var o=e.find((function(n){return n.key==="customHeaderScript"}));var t=e.find((function(n){return n.key==="customFooterScript"}));if(!window.Zonos.isLegacyCheckout||!o&&!t){log("Skip injecting custom script for hosted checkout","info",{footerScript:t,headerScript:o,isLegacyCheckout:window.Zonos.isLegacyCheckout});return}if(o){log("Injecting custom header script");var r=document.createElement("script");r.textContent=o.value;document.head.appendChild(r)}if(t){log("Injecting custom footer script");var r=document.createElement("script");r.textContent=t.value;document.body.appendChild(r)}};Zonos.displayCurrency=function(){var n=document.querySelector("zonos-hello");if(n){void n.displayCurrency()}};Zonos.openHelloDialog=function(n){var e=document.querySelector("zonos-hello");if(e){void e.openHelloDialog(n!==null&&n!==void 0?n:true)}};Zonos.showNotification=function(n){var e;void((e=_a.zonosController)===null||e===void 0?void 0:e.showNotification(n))};Zonos.updateOrganizationName=function(n){var e;void((e=_a.zonosController)===null||e===void 0?void 0:e.updateOrganizationName(n))};Zonos.disablePlaceOrderButtons=function(n){var e=n.autoEnable,o=e===void 0?true:e,t=n.config,r=n.disable,i=n.placeOrderButtonSelector;var a;if((a=t.checkoutSettings)===null||a===void 0?void 0:a.disablePlaceOrderButtonActivation){return}if(i){var s=document.querySelectorAll(i);var c=function(n){var e=n.target;if(e.getAttribute("disabled")){n.preventDefault();n.stopPropagation()}};s.forEach((function(n){var e=n.getAttribute("data-zonos-checkout-attached");if(e){return}if(r){n.setAttribute("disabled","true");n.addEventListener("click",c)}else{n.removeAttribute("disabled");n.removeEventListener("click",c)}}));if(o&&r){setTimeout((function(){s.forEach((function(n){n.removeAttribute("disabled");n.removeEventListener("click",c)}))}),5e3)}}};Zonos.injectController=function(n){var e=n.config;var o;if(document.querySelector("zonos-controller")){return}if((o=e.checkoutSettings)===null||o===void 0?void 0:o.placeOrderButtonSelector){var t=e.checkoutSettings.placeOrderButtonSelector;_a.disablePlaceOrderButtons({config:e,disable:true,placeOrderButtonSelector:t});var r=new MutationObserver((function(){_a.disablePlaceOrderButtons({config:e,disable:true,placeOrderButtonSelector:t})}));r.observe(document.body,{childList:true,subtree:true})}var i=document.createElement("zonos-controller");i.config=e;i.zonosApiKey=_a.zonosApiKey||"";i.addEventListener("stripeInitEvent",(function(n){return __awaiter(void 0,void 0,void 0,(function(){var e,o;return __generator(this,(function(t){switch(t.label){case 0:e=n.detail;log("loading Stripe");return[4,zonosLoadStripe(e.publishableKey)];case 1:o=t.sent();if(!o){logError("API seems to be invalid or missing. Failed to load Stripe");return[2]}window.Zonos.stripe=o;void i.initCheckoutElement(o);return[2]}}))}))}));document.body.appendChild(i);_a.zonosController=i;log("Zonos controller injected!")};Zonos.injectScript=function(n){var e=n.cdnType,o=n.isModule,t=n.theRestUrl;var r=_a.getZonosUrl(e);var i="".concat(r,"/").concat(t);var a=function(){var n=document.querySelector('script[src="'.concat(i,'"]'));return!!n};if(a()){log('Zonos script "'.concat(i,'" already exists in the document'),"warn");return}var s=document.head||document.body;var c=document.createElement("script");if(!!o){c.type="module"}else{c.noModule=true}c.src=i;c.crossOrigin="anonymous";c.onerror=function(){logError("Failed to load ".concat(c.src));var n=getNextFallbackUrl(e);if(!n){return}_a.injectScript({cdnType:n,isModule:o,theRestUrl:t})};s.appendChild(c)};Zonos.getZonosUrl=function(n){var e=function(){switch(n){case"jsdelivr":return JS_DELIVR_ZONOS_URL;case"unpkg":return UNPKG_ZONOS_URL;case"cdnjs":return CDNJS_ZONOS_URL;case"vercel":return ZONOS_URL}};if(_a.isNpm){var o=getZonosQaUrl();return o||e()}return e()};Zonos.injectZonosCdn=function(){_a.injectScript({cdnType:MAIN_LOAD_CDN_TYPE,isModule:true,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"});_a.injectScript({cdnType:MAIN_LOAD_CDN_TYPE,isModule:false,theRestUrl:"dist/zonos-elements/zonos-elements.js"});log("Zonos cdn script injected!")};Zonos.injectStylesheet=function(n){var e=n.cdnType,o=n.theRestUrl;var t=_a.getZonosUrl(e);var r=document.head||document.body;var i=document.createElement("link");i.rel="preconnect";i.href="".concat(ZONOS_URL,"/");r.appendChild(i);var a=document.createElement("link");a.rel="stylesheet";a.href="".concat(t,"/").concat(o);a.onerror=function(){logError("Failed to load ".concat(a.href));var n=getNextFallbackUrl(e);if(!n){return}_a.injectStylesheet({cdnType:n,theRestUrl:o})};r.appendChild(a)};Zonos.injectZonosCss=function(){var n=function(){return!!document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')};if(n()){log("Zonos style links already injected","warn");return}_a.injectStylesheet({cdnType:MAIN_LOAD_CDN_TYPE,theRestUrl:"dist/zonos-elements/zonos-elements.css"});log("Zonos style css injected!")};Zonos.injectFonts=function(){var n=function(){var n=document.querySelectorAll('link[rel="stylesheet"][href^="'.concat(GOOGLE_FONT_URL,'"]'));for(var e=0;e<n.length;e++){var o=n[e];if(!o){continue}if(GOOGLE_FONT_REGEX.test(o.href)){continue}return o}return null};if(n()){log("Inter font already injected","warn");return}var e=document.head||document.body;var o=document.createElement("link");o.rel="preconnect";o.href=GOOGLE_FONT_URL;e.appendChild(o);var t=document.createElement("link");t.rel="stylesheet";t.href="".concat(GOOGLE_FONT_URL,"/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");e.appendChild(t);log("Zonos font injected!")};Zonos.setupGoogleFont=function(n){var e;void((e=_a.zonosController)===null||e===void 0?void 0:e.setupGoogleFont(n))};Zonos.injectSupportGoogleFont=function(n){var e;log("[FONT] injecting ".concat(n));var o=(e=n.match(/family=(.*?):/))===null||e===void 0?void 0:e[1];var t=document.head||document.body;if(!document.querySelector('link[rel="preconnect"][href^="'.concat(GOOGLE_FONT_URL,'"]'))){var r=document.createElement("link");r.rel="preconnect";r.href=GOOGLE_FONT_URL;t.appendChild(r)}if(document.querySelector('link[rel="stylesheet"][href="'.concat(n,'"]'))){log("[FONT] ".concat(o," font already injected"),"warn");return}var i=document.createElement("link");i.rel="stylesheet";i.href=n;t.appendChild(i);log("[FONT] ".concat(o," font injected!"))};export{Zonos};
|
package/dist/scripts/index.d.ts
CHANGED
|
@@ -4625,6 +4625,7 @@ declare abstract class Zonos {
|
|
|
4625
4625
|
static cartId: string | null;
|
|
4626
4626
|
private static zonosController;
|
|
4627
4627
|
static init: (params: LoadZonosParams) => Promise<void>;
|
|
4628
|
+
private static injectCustomScriptForHostedCheckout;
|
|
4628
4629
|
static displayCurrency: () => void;
|
|
4629
4630
|
static openHelloDialog: (value?: boolean) => void;
|
|
4630
4631
|
static showNotification: (notification: NotificationInit) => void;
|
package/dist/scripts/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";const e=performance.now(),o=e=>{if("string"==typeof e)return e;try{return JSON.stringify(e)}catch(o){if(e&&"function"==typeof e.toString){return e.toString()}return"Unable to stringify info"}},t=(t,n,...r)=>{var s,i;const{elapsedTimePretty:a}=(()=>{const o=performance.now()-e,t=o>1e3?`${(o/1e3).toFixed(2)}s`:`${o.toFixed(2)}ms`;return{elapsedTime:o,elapsedTimePretty:t}})(),l=[`(${a})`,...r];l.map(o).join(" ");if(!(!!(null===(s=window.Zonos)||void 0===s?void 0:s.debug)||!!window.location.search.match(/\?.*(&*)zonosDebug=1/)))return void("error"===n&&console.error(t,...l));let c=document.querySelector("iframe#zonos---debug-logging-iframe");c||(c=document.createElement("iframe"),c.id="zonos---debug-logging-iframe",c.style.display="none",c.style.opacity="0",c.style.position="absolute",c.style.top="-9999px",c.style.left="-9999px",c.style.width="1px",c.style.height="1px",c.style.border="none",c.style.overflow="hidden",c.style.visibility="hidden",document.body.appendChild(c));const d=(null===(i=c.contentWindow)||void 0===i?void 0:i.window.console)||window.console;switch(n){case"warn":d.warn(t,...l);break;case"info":d.info(t,...l);break;case"error":d.error(t,...l);break;default:d.groupCollapsed(t,...l),d.trace(),d.groupEnd()}},n=(e,...o)=>{t(e,"error",...o)},r=["jsdelivr","cdnjs","unpkg","vercel"],s="jsdelivr",i=e=>{const o=r.indexOf(e);return r[o+1]||null};function a(e,o){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&o.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)o.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(t[n[r]]=e[n[r]])}return t}"function"==typeof SuppressedError&&SuppressedError;const l=["cloudflare","vercel"],c=l[0],d={cloudflare:"https://route.elements.zonos.com",vercel:"https://route.js.zonos.com"},u=d[c],p=(e=c)=>{const o=l.indexOf(e),t=l[o+1];return t||null},m=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){return null}return null},w=async({response:e,shouldLog:o=!0,shouldThrow:t=!1})=>{try{const o=await e.text(),t=m(o);if(!t)throw new Error(`Failed to parse content: ${o}`);return t}catch(e){if(t)throw e;return o&&console.error(e),null}},h=async({basePathType:e,options:o,path:t})=>{let n;const r=window.Zonos.zonosQaUrlApi||d[e]||c,s=new URL(r+t),i=window.Zonos.cartId?`${window.location.hostname}-${window.Zonos.cartId}`:window.location.hostname;s.searchParams.set("zToken",(e=>{try{return btoa(e).replace(/=/g,"")}catch(o){return e.replace(/[^A-Za-z0-9]/g,"").split("").reverse().join("")}})(i));try{n=await fetch(s.toString(),o)}catch(e){if(e instanceof Error)return{baseUrl:r,errors:[{message:e.message,type:"unknown"}],json:null,response:null,zonosMode:null};return{baseUrl:r,errors:[{message:"Failed to fetch",type:"unknown"}],json:null,response:null,zonosMode:null}}const a=n.headers.get("Zonos-Mode"),l=window.Zonos.zonosQaUrl;if(!window.Zonos.modeAlerted&&a&&l&&(window.Zonos.modeAlerted=!0),n.ok){return{baseUrl:r,errors:[],json:await w({response:n}),response:n,zonosMode:a}}const u=n.status.toString();try{const e=await w({response:n,shouldThrow:!0});return{baseUrl:r,errors:[{message:JSON.stringify(e),type:u}],json:null,response:n,zonosMode:a}}catch(e){return{baseUrl:r,errors:[{message:`${u}: ${"Unknown error"}`,type:u}],json:null,response:null,zonosMode:a}}},y=async({basePathType:e,options:o,path:n})=>{var r,s;const i=n.startsWith("/api/bigcommerce")?"vercel":e,l=await h({basePathType:i,options:o,path:n}),{errors:c,response:w}=l,g=a(l,["errors","response"]),f=p(i),v=!!c.find((({type:e})=>"unknown"===e))||404===(null==w?void 0:w.status),b=f&&v;return v&&(async({endpoint:e,errors:o,metadata:n,shouldPostReleaseErrorReporting:r})=>{if(t("sendErrorLog","warn",e,n,o),r){const e=Number(window.Zonos.releaseDate);if((new Date).getTime()-e>36e5)return}const s="userAgentData"in window.navigator?window.navigator.userAgentData:null,i={endpoint:e,errors:o,href:window.location.href,metadata:Object.assign({appVersion:window.Zonos.version,domain:window.Zonos.domain,publicCredential:window.Zonos.zonosApiKey,userAgent:s&&s.brands.length>0?s:window.navigator.userAgent},n)};try{fetch(`${u}/api/zonos-elements/log-error`,{body:JSON.stringify(i),headers:{"Zonos-Referer":window.location.hostname},method:"POST"})}catch(e){const o=p();if(!o)return;fetch(`${d[o]}/api/zonos-elements/log-error`,{body:JSON.stringify(i),method:"POST"})}})({endpoint:d[i]+n,errors:c.map((({message:e})=>`API: ${e}`)),metadata:{currentBasePath:i,nextFallbackApiType:f,requestHeaders:null==o?void 0:o.headers,requestPayload:m(null===(r=null==o?void 0:o.body)||void 0===r?void 0:r.toString())||(null===(s=null==o?void 0:o.body)||void 0===s?void 0:s.toString()),status:null==w?void 0:w.status,statusText:null==w?void 0:w.statusText},shouldPostReleaseErrorReporting:!0}),b?(t(`=== "${n}" failed to fetch, trying next fallback ${f}`),y({basePathType:f,options:o,path:n})):Object.assign({errors:c,response:w},g)},g=async(e,o)=>{const n=a(o||{},[]),r=n.body?JSON.stringify(n.body):void 0,s=n.method||"GET",i=Object.assign({"Content-Type":"application/json","Zonos-Is-BigCommerce":window.Zonos.isBigCommerce.toString(),"Zonos-Referer":window.location.hostname,"Zonos-Version":window.Zonos.version,credentialtoken:window.Zonos.zonosApiKey||"Empty credential token from zonos-elements"},n.headers),l=Object.assign(Object.assign({},n),{body:"GET"===s?void 0:r,headers:i,method:s}),d=new URLSearchParams(window.location.search).get("useFallbackApi");return t(e,"info"),y({basePathType:d||c,options:l,path:e})},f=()=>{const e=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||e)return null;const o=(e=>{if(!e)return null;const o=new URL(e).searchParams.get("zonosQaUrl");return o?/[^a-zA-Z0-9-_]+/.test(o)?null:o:null})(window.location.href),n="https://v1.3.140.js.zonos.com";if(!o&&(n.includes("test.")||n.includes("test-")))return n;if(!o&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!o)return null;if("dev-elements"===o)return"https://dev.elements.zonos.com";const r=`https://${o}.preview.js.zonos.com`;return t(`[ZONOS-WARNING] using '${r}' for loading elements script`,"warn"),fetch(r).then((()=>{window.sessionStorage.removeItem("zonos--checkout-session-id"),window.sessionStorage.removeItem("zonos--client-secret")})).catch((()=>{alert(`[ZONOS-WARNING] '${r}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);const e=new URLSearchParams(window.location.search);e.delete("zonosQaUrl");const{pathname:o}=window.location,t=`${o}?${e.toString()}`;return window.history.replaceState(window.history.state,"",t),window.location.reload(),null})),r},v="https://js.stripe.com/v3",b=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,S="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";let z=null;const O=e=>(null!==z||(z=new Promise(((o,t)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&e&&console.warn(S),window.Stripe)o(window.Stripe);else try{let r=(()=>{const e=document.querySelectorAll(`script[src^="${v}"]`);for(let o=0;o<e.length;o++){const t=e[o];if(t&&b.test(t.src))return t}return null})();r&&e?console.warn(S):r||(r=(e=>{const o=document.createElement("script");o.src=`${v}`;const t=document.head||document.body;return t?(t.appendChild(o),o):(n("Expected document.body not to be null. Stripe.js requires a <body> element."),null)})()),null==r||r.addEventListener("load",(()=>{window.Stripe?o(window.Stripe):t(new Error("Stripe.js not available"))})),null==r||r.addEventListener("error",(()=>{t(new Error("Failed to load Stripe.js"))}))}catch(e){return void t(e)}else o(null)}))),z),j=Promise.resolve().then((()=>O(null)));let Z=!1;j.catch((e=>{Z||console.warn(e)}));const C=async({cartId:e,retries:o})=>{const n="1"===new URLSearchParams(window.location.search).get("zonosTestMode"),{errors:r,json:s}=await g("/api/zonos-elements/get-temp-cart",{body:{isTestMode:n,tempCartUUID:e},headers:{"Content-Type":"application/json"},method:"POST"}),i=!s||r.length;return i&&o?(t("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:o}),await new Promise((e=>setTimeout(e,500))),C({cartId:e,retries:o-1})):i?null:s},k=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,E=new RegExp(`^${k.source}$`),I=new RegExp(`^cart_${k.source}$`),A=async e=>{const{isDgsCartId:o,isLegacyCartId:r}=(e=>e?I.test(e)?{isDgsCartId:!0,isLegacyCartId:!1}:E.test(e)?{isDgsCartId:!1,isLegacyCartId:!0}:{isDgsCartId:!1,isLegacyCartId:!1}:{isDgsCartId:!1,isLegacyCartId:!1})(e);if(!r&&!o)return n("[ZONOS - loadZonos] invalid cart id"),null;const s=await C({cartId:e,retries:5});return t("[ZONOS - loadZonos] getting temp cart data","info",s),s?(window.Zonos.storeId=s.cartData.storeId,window.Zonos.zonosApiKey=s.cartData.credentialToken,{cartData:s.cartData,storeFavicon:s.storeFaviconUrl,storeId:s.cartData.storeId,storeLogo:s.storeLogoUrl,zonosApiKey:s.cartData.credentialToken}):(n("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process."),null)};var T;const N=(()=>{if("undefined"==typeof document)return null;const e=document.querySelector('script[src*="/zonos.js"]'),{currentLoadScriptUrl:o,isWhiteListed:t}=(({loadScriptSrc:e})=>{if(!e)return{currentLoadScriptUrl:"",isForceLoadVersionDomain:!1,isWhiteListed:!1};const o=new URL(e).origin,t=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"].some((e=>o.includes(e))),n=["qa.js.zonos.com"].some((e=>o.includes(e)));return{currentLoadScriptUrl:o,isForceLoadVersionDomain:n,isWhiteListed:t}})({loadScriptSrc:null==e?void 0:e.src});return t?o:null})(),$="https://v1.3.140.js.zonos.com",U=N||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.140",L="https://fonts.googleapis.com",P=/^https:\/\/fonts\.googleapis\.com/;class D{}T=D,D.doneInit=!1,D.debug="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/),D.zonosConversionTest="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/),D._paypalMockResponse=null,D.isBigCommerce=!1,D.releaseDate="1734113795652",D.isLegacyCheckout=!1,D.domain="undefined"!=typeof window?window.location!=window.parent.location&&document.referrer||document.location.hostname:"",D.showBaseForeign="undefined"!=typeof window&&window.location.search.includes("zonosShowBaseForeign"),D.isNpm=!0,D.zonosQaUrl=null,D.zonosQaUrlApi=null,D.version="v1.3.140",D.modeAlerted=!1,D.cartData=null,D.paypal=null,D.getCurrentTimestamp=()=>(new Date).getTime(),D.zonosController=null,D.init=async e=>{const{appearance:o,checkoutSettings:r,currencyConverter:s,helloSettings:i,onCountryChange:a,overrideCurrencyFormat:l,storeId:c,zonosApiKey:d}=e;if(T.cartId=new URLSearchParams(window.location.search).get("tempCartUUID"),T.doneInit)return;if(t(`====== ZONOS DEBUG MODE: on (${T.version}) ======`),T.zonosApiKey=d,T.storeId=c,T.isNpm){t("====== ZONOS LOADING FROM NPM ======");const o=f();if(o&&!window.isZonosPreview){t(`====== RE-INJECT "zonos.js" FROM PRVIEW: ${o} ======`,"info");const n=document.createElement("script");return n.src=`${o}/dist/scripts/zonos.js`,document.head.appendChild(n),n.addEventListener("load",(()=>{window.Zonos.isNpm=T.isNpm,window.Zonos.isBigCommerce=T.isBigCommerce,window.Zonos.isLegacyCheckout=T.isLegacyCheckout,window.Zonos.init(e)})),n.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${o}`)})),void(window.isZonosPreview=!0)}if(!d&&!T.cartId)return void n("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(!T.cartData&&T.cartId){t("Initialize cart data");const e=await A(T.cartId);if(!e)return void n("Failed to get cart data");T.cartData=e.cartData,T.zonosApiKey=e.zonosApiKey}const r=await(async()=>{if(!window.location.search.includes("zonosTestMode=1")||!window.Zonos.zonosApiKey)return null;if(t("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return t("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:e,json:o}=await g("/api/get-test-public-credential");if(e.length||!o)return n("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",e),null;const r=o.publicCredential;return r?(t(`[ZONOS - loadZonos] Retrieve new test public token ${r}`,"info"),r):(n("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();r&&(T.zonosApiKey=r)}const u=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");if(T.cartId&&T.cartData||!!u){t("Cart data or stripe client secret is available, inject hidden button and trigger checkout");const e=document.createElement("button");e.style.display="none",e.id="zonos--checkout-hidden-button",document.body.appendChild(e)}t("init zonos"),T.injectZonosCdn(),T.injectZonosCss(),T.injectFonts(),T.injectController({config:{appearance:o,checkoutSettings:r,currencyConverter:s,helloSettings:i,onCountryChange:a,overrideCurrencyFormat:l}}),T.doneInit=!0},D.displayCurrency=()=>{const e=document.querySelector("zonos-hello");e&&e.displayCurrency()},D.openHelloDialog=e=>{const o=document.querySelector("zonos-hello");o&&o.openHelloDialog(null==e||e)},D.showNotification=e=>{var o;null===(o=T.zonosController)||void 0===o||o.showNotification(e)},D.updateOrganizationName=e=>{var o;null===(o=T.zonosController)||void 0===o||o.updateOrganizationName(e)},D.disablePlaceOrderButtons=({autoEnable:e=!0,config:o,disable:t,placeOrderButtonSelector:n})=>{var r;if(!(null===(r=o.checkoutSettings)||void 0===r?void 0:r.disablePlaceOrderButtonActivation)&&n){const o=document.querySelectorAll(n),r=e=>{e.target.getAttribute("disabled")&&(e.preventDefault(),e.stopPropagation())};o.forEach((e=>{e.getAttribute("data-zonos-checkout-attached")||(t?(e.setAttribute("disabled","true"),e.addEventListener("click",r)):(e.removeAttribute("disabled"),e.removeEventListener("click",r)))})),e&&t&&setTimeout((()=>{o.forEach((e=>{e.removeAttribute("disabled"),e.removeEventListener("click",r)}))}),5e3)}},D.injectController=({config:e})=>{var o;if(document.querySelector("zonos-controller"))return;if(null===(o=e.checkoutSettings)||void 0===o?void 0:o.placeOrderButtonSelector){const o=e.checkoutSettings.placeOrderButtonSelector;T.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:o});new MutationObserver((()=>{T.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:o})})).observe(document.body,{childList:!0,subtree:!0})}const r=document.createElement("zonos-controller");r.config=e,r.zonosApiKey=T.zonosApiKey||"",r.addEventListener("stripeInitEvent",(async e=>{const{detail:o}=e;t("loading Stripe");const s=await(async(...e)=>{Z=!0;const o=Date.now();return j.then((t=>((e,o,t)=>{if(null===e)return null;const n=e.apply(void 0,o);return((e,o)=>{e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",startTime:o})})(n,t),n})(t,e,o)))})(o.publishableKey);s?(window.Zonos.stripe=s,r.initCheckoutElement(s)):n("API seems to be invalid or missing. Failed to load Stripe")})),document.body.appendChild(r),T.zonosController=r,t("Zonos controller injected!")},D.injectScript=({cdnType:e,isModule:o,theRestUrl:r})=>{const s=`${T.getZonosUrl(e)}/${r}`;if(document.querySelector(`script[src="${s}"]`))return void t(`Zonos script "${s}" already exists in the document`,"warn");const a=document.head||document.body,l=document.createElement("script");o?l.type="module":l.noModule=!0,l.src=s,l.crossOrigin="anonymous",l.onerror=()=>{n(`Failed to load ${l.src}`);const t=i(e);t&&T.injectScript({cdnType:t,isModule:o,theRestUrl:r})},a.appendChild(l)},D.getZonosUrl=e=>{const o=()=>{switch(e){case"jsdelivr":return U;case"unpkg":return"https://unpkg.com/@zonos/elements@1.3.140";case"cdnjs":return"https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.140";case"vercel":return $}};if(T.isNpm){return f()||o()}return o()},D.injectZonosCdn=()=>{T.injectScript({cdnType:s,isModule:!0,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"}),T.injectScript({cdnType:s,isModule:!1,theRestUrl:"dist/zonos-elements/zonos-elements.js"}),t("Zonos cdn script injected!")},D.injectStylesheet=({cdnType:e,theRestUrl:o})=>{const t=T.getZonosUrl(e),r=document.head||document.body,s=document.createElement("link");s.rel="preconnect",s.href=`${$}/`,r.appendChild(s);const a=document.createElement("link");a.rel="stylesheet",a.href=`${t}/${o}`,a.onerror=()=>{n(`Failed to load ${a.href}`);const t=i(e);t&&T.injectStylesheet({cdnType:t,theRestUrl:o})},r.appendChild(a)},D.injectZonosCss=()=>{document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')?t("Zonos style links already injected","warn"):(T.injectStylesheet({cdnType:s,theRestUrl:"dist/zonos-elements/zonos-elements.css"}),t("Zonos style css injected!"))},D.injectFonts=()=>{if((()=>{const e=document.querySelectorAll(`link[rel="stylesheet"][href^="${L}"]`);for(let o=0;o<e.length;o++){const t=e[o];if(t&&!P.test(t.href))return t}return null})())return void t("Inter font already injected","warn");const e=document.head||document.body,o=document.createElement("link");o.rel="preconnect",o.href=L,e.appendChild(o);const n=document.createElement("link");n.rel="stylesheet",n.href=`${L}/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap`,e.appendChild(n),t("Zonos font injected!")},D.setupGoogleFont=e=>{var o;null===(o=T.zonosController)||void 0===o||o.setupGoogleFont(e)},D.injectSupportGoogleFont=e=>{var o;t(`[FONT] injecting ${e}`);const n=null===(o=e.match(/family=(.*?):/))||void 0===o?void 0:o[1],r=document.head||document.body;if(!document.querySelector(`link[rel="preconnect"][href^="${L}"]`)){const e=document.createElement("link");e.rel="preconnect",e.href=L,r.appendChild(e)}if(document.querySelector(`link[rel="stylesheet"][href="${e}"]`))return void t(`[FONT] ${n} font already injected`,"warn");const s=document.createElement("link");s.rel="stylesheet",s.href=e,r.appendChild(s),t(`[FONT] ${n} font injected!`)},exports.Zonos=D})();
|
|
1
|
+
(function(){"use strict";const e=performance.now(),o=e=>{if("string"==typeof e)return e;try{return JSON.stringify(e)}catch(o){if(e&&"function"==typeof e.toString){return e.toString()}return"Unable to stringify info"}},t=(t,n,...r)=>{var s,i;const{elapsedTimePretty:a}=(()=>{const o=performance.now()-e,t=o>1e3?`${(o/1e3).toFixed(2)}s`:`${o.toFixed(2)}ms`;return{elapsedTime:o,elapsedTimePretty:t}})(),c=[`(${a})`,...r];c.map(o).join(" ");if(!(!!(null===(s=window.Zonos)||void 0===s?void 0:s.debug)||!!window.location.search.match(/\?.*(&*)zonosDebug=1/)))return void("error"===n&&console.error(t,...c));let l=document.querySelector("iframe#zonos---debug-logging-iframe");l||(l=document.createElement("iframe"),l.id="zonos---debug-logging-iframe",l.style.display="none",l.style.opacity="0",l.style.position="absolute",l.style.top="-9999px",l.style.left="-9999px",l.style.width="1px",l.style.height="1px",l.style.border="none",l.style.overflow="hidden",l.style.visibility="hidden",document.body.appendChild(l));const d=(null===(i=l.contentWindow)||void 0===i?void 0:i.window.console)||window.console;switch(n){case"warn":d.warn(t,...c);break;case"info":d.info(t,...c);break;case"error":d.error(t,...c);break;default:d.groupCollapsed(t,...c),d.trace(),d.groupEnd()}},n=(e,...o)=>{t(e,"error",...o)},r=["jsdelivr","cdnjs","unpkg","vercel"],s="jsdelivr",i=e=>{const o=r.indexOf(e);return r[o+1]||null};function a(e,o){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&o.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)o.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(t[n[r]]=e[n[r]])}return t}"function"==typeof SuppressedError&&SuppressedError;const c=["cloudflare","vercel"],l=c[0],d={cloudflare:"https://route.elements.zonos.com",vercel:"https://route.js.zonos.com"},u=d[l],p=(e=l)=>{const o=c.indexOf(e),t=c[o+1];return t||null},m=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){return null}return null},w=async({response:e,shouldLog:o=!0,shouldThrow:t=!1})=>{try{const o=await e.text(),t=m(o);if(!t)throw new Error(`Failed to parse content: ${o}`);return t}catch(e){if(t)throw e;return o&&console.error(e),null}},h=async({basePathType:e,options:o,path:t})=>{let n;const r=window.Zonos.zonosQaUrlApi||d[e]||l,s=new URL(r+t),i=window.Zonos.cartId?`${window.location.hostname}-${window.Zonos.cartId}`:window.location.hostname;s.searchParams.set("zToken",(e=>{try{return btoa(e).replace(/=/g,"")}catch(o){return e.replace(/[^A-Za-z0-9]/g,"").split("").reverse().join("")}})(i));try{n=await fetch(s.toString(),o)}catch(e){if(e instanceof Error)return{baseUrl:r,errors:[{message:e.message,type:"unknown"}],json:null,response:null,zonosMode:null};return{baseUrl:r,errors:[{message:"Failed to fetch",type:"unknown"}],json:null,response:null,zonosMode:null}}const a=n.headers.get("Zonos-Mode"),c=window.Zonos.zonosQaUrl;if(!window.Zonos.modeAlerted&&a&&c&&(window.Zonos.modeAlerted=!0),n.ok){return{baseUrl:r,errors:[],json:await w({response:n}),response:n,zonosMode:a}}const u=n.status.toString();try{const e=await w({response:n,shouldThrow:!0});return{baseUrl:r,errors:[{message:JSON.stringify(e),type:u}],json:null,response:n,zonosMode:a}}catch(e){return{baseUrl:r,errors:[{message:`${u}: ${"Unknown error"}`,type:u}],json:null,response:null,zonosMode:a}}},y=async({basePathType:e,options:o,path:n})=>{var r,s;const i=n.startsWith("/api/bigcommerce")?"vercel":e,c=await h({basePathType:i,options:o,path:n}),{errors:l,response:w}=c,f=a(c,["errors","response"]),g=p(i),v=!!l.find((({type:e})=>"unknown"===e))||404===(null==w?void 0:w.status),b=g&&v;return v&&(async({endpoint:e,errors:o,metadata:n,shouldPostReleaseErrorReporting:r})=>{if(t("sendErrorLog","warn",e,n,o),r){const e=Number(window.Zonos.releaseDate);if((new Date).getTime()-e>36e5)return}const s="userAgentData"in window.navigator?window.navigator.userAgentData:null,i={endpoint:e,errors:o,href:window.location.href,metadata:Object.assign({appVersion:window.Zonos.version,domain:window.Zonos.domain,publicCredential:window.Zonos.zonosApiKey,userAgent:s&&s.brands.length>0?s:window.navigator.userAgent},n)};try{fetch(`${u}/api/zonos-elements/log-error`,{body:JSON.stringify(i),headers:{"Zonos-Referer":window.location.hostname},method:"POST"})}catch(e){const o=p();if(!o)return;fetch(`${d[o]}/api/zonos-elements/log-error`,{body:JSON.stringify(i),method:"POST"})}})({endpoint:d[i]+n,errors:l.map((({message:e})=>`API: ${e}`)),metadata:{currentBasePath:i,nextFallbackApiType:g,requestHeaders:null==o?void 0:o.headers,requestPayload:m(null===(r=null==o?void 0:o.body)||void 0===r?void 0:r.toString())||(null===(s=null==o?void 0:o.body)||void 0===s?void 0:s.toString()),status:null==w?void 0:w.status,statusText:null==w?void 0:w.statusText},shouldPostReleaseErrorReporting:!0}),b?(t(`=== "${n}" failed to fetch, trying next fallback ${g}`),y({basePathType:g,options:o,path:n})):Object.assign({errors:l,response:w},f)},f=async(e,o)=>{const n=a(o||{},[]),r=n.body?JSON.stringify(n.body):void 0,s=n.method||"GET",i=Object.assign({"Content-Type":"application/json","Zonos-Is-BigCommerce":window.Zonos.isBigCommerce.toString(),"Zonos-Referer":window.location.hostname,"Zonos-Version":window.Zonos.version,credentialtoken:window.Zonos.zonosApiKey||"Empty credential token from zonos-elements"},n.headers),c=Object.assign(Object.assign({},n),{body:"GET"===s?void 0:r,headers:i,method:s}),d=new URLSearchParams(window.location.search).get("useFallbackApi");return t(e,"info"),y({basePathType:d||l,options:c,path:e})},g=()=>{const e=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||e)return null;const o=(e=>{if(!e)return null;const o=new URL(e).searchParams.get("zonosQaUrl");return o?/[^a-zA-Z0-9-_]+/.test(o)?null:o:null})(window.location.href),n="https://v1.3.141.js.zonos.com";if(!o&&(n.includes("test.")||n.includes("test-")))return n;if(!o&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!o)return null;if("dev-elements"===o)return"https://dev.elements.zonos.com";const r=`https://${o}.preview.js.zonos.com`;return t(`[ZONOS-WARNING] using '${r}' for loading elements script`,"warn"),fetch(r).then((()=>{window.sessionStorage.removeItem("zonos--checkout-session-id"),window.sessionStorage.removeItem("zonos--client-secret")})).catch((()=>{alert(`[ZONOS-WARNING] '${r}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);const e=new URLSearchParams(window.location.search);e.delete("zonosQaUrl");const{pathname:o}=window.location,t=`${o}?${e.toString()}`;return window.history.replaceState(window.history.state,"",t),window.location.reload(),null})),r},v="https://js.stripe.com/v3",b=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,S="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";let z=null;const j=e=>(null!==z||(z=new Promise(((o,t)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&e&&console.warn(S),window.Stripe)o(window.Stripe);else try{let r=(()=>{const e=document.querySelectorAll(`script[src^="${v}"]`);for(let o=0;o<e.length;o++){const t=e[o];if(t&&b.test(t.src))return t}return null})();r&&e?console.warn(S):r||(r=(e=>{const o=document.createElement("script");o.src=`${v}`;const t=document.head||document.body;return t?(t.appendChild(o),o):(n("Expected document.body not to be null. Stripe.js requires a <body> element."),null)})()),null==r||r.addEventListener("load",(()=>{window.Stripe?o(window.Stripe):t(new Error("Stripe.js not available"))})),null==r||r.addEventListener("error",(()=>{t(new Error("Failed to load Stripe.js"))}))}catch(e){return void t(e)}else o(null)}))),z),C=Promise.resolve().then((()=>j(null)));let O=!1;C.catch((e=>{O||console.warn(e)}));const Z=async({cartId:e,retries:o})=>{const n="1"===new URLSearchParams(window.location.search).get("zonosTestMode"),{errors:r,json:s}=await f("/api/zonos-elements/get-temp-cart",{body:{isTestMode:n,tempCartUUID:e},headers:{"Content-Type":"application/json"},method:"POST"}),i=!s||r.length;return i&&o?(t("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:o}),await new Promise((e=>setTimeout(e,500))),Z({cartId:e,retries:o-1})):i?null:s},k=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,E=new RegExp(`^${k.source}$`),I=new RegExp(`^cart_${k.source}$`),A=async e=>{const{isDgsCartId:o,isLegacyCartId:r}=(e=>e?I.test(e)?{isDgsCartId:!0,isLegacyCartId:!1}:E.test(e)?{isDgsCartId:!1,isLegacyCartId:!0}:{isDgsCartId:!1,isLegacyCartId:!1}:{isDgsCartId:!1,isLegacyCartId:!1})(e);if(!r&&!o)return n("[ZONOS - loadZonos] invalid cart id"),null;const s=await Z({cartId:e,retries:5});return t("[ZONOS - loadZonos] getting temp cart data","info",s),s?(window.Zonos.storeId=s.cartData.storeId,window.Zonos.zonosApiKey=s.cartData.credentialToken,{cartData:s.cartData,storeFavicon:s.storeFaviconUrl,storeId:s.cartData.storeId,storeLogo:s.storeLogoUrl,zonosApiKey:s.cartData.credentialToken}):(n("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process."),null)};var L;const T=(()=>{if("undefined"==typeof document)return null;const e=document.querySelector('script[src*="/zonos.js"]'),{currentLoadScriptUrl:o,isWhiteListed:t}=(({loadScriptSrc:e})=>{if(!e)return{currentLoadScriptUrl:"",isForceLoadVersionDomain:!1,isWhiteListed:!1};const o=new URL(e).origin,t=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"].some((e=>o.includes(e))),n=["qa.js.zonos.com"].some((e=>o.includes(e)));return{currentLoadScriptUrl:o,isForceLoadVersionDomain:n,isWhiteListed:t}})({loadScriptSrc:null==e?void 0:e.src});return t?o:null})(),N="https://v1.3.141.js.zonos.com",$=T||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.141",U="https://fonts.googleapis.com",P=/^https:\/\/fonts\.googleapis\.com/;class D{}L=D,D.doneInit=!1,D.debug="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/),D.zonosConversionTest="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/),D._paypalMockResponse=null,D.isBigCommerce=!1,D.releaseDate="1734130633682",D.isLegacyCheckout=!1,D.domain="undefined"!=typeof window?window.location!=window.parent.location&&document.referrer||document.location.hostname:"",D.showBaseForeign="undefined"!=typeof window&&window.location.search.includes("zonosShowBaseForeign"),D.isNpm=!0,D.zonosQaUrl=null,D.zonosQaUrlApi=null,D.version="v1.3.141",D.modeAlerted=!1,D.cartData=null,D.paypal=null,D.getCurrentTimestamp=()=>(new Date).getTime(),D.zonosController=null,D.init=async e=>{const{appearance:o,checkoutSettings:r,currencyConverter:s,helloSettings:i,onCountryChange:a,overrideCurrencyFormat:c,storeId:l,zonosApiKey:d}=e;if(L.cartId=new URLSearchParams(window.location.search).get("tempCartUUID"),L.doneInit)return;if(t(`====== ZONOS DEBUG MODE: on (${L.version}) ======`),L.zonosApiKey=d,L.storeId=l,L.isNpm){t("====== ZONOS LOADING FROM NPM ======");const o=g();if(o&&!window.isZonosPreview){t(`====== RE-INJECT "zonos.js" FROM PRVIEW: ${o} ======`,"info");const n=document.createElement("script");return n.src=`${o}/dist/scripts/zonos.js`,document.head.appendChild(n),n.addEventListener("load",(()=>{window.Zonos.isNpm=L.isNpm,window.Zonos.isBigCommerce=L.isBigCommerce,window.Zonos.isLegacyCheckout=L.isLegacyCheckout,window.Zonos.init(e)})),n.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${o}`)})),void(window.isZonosPreview=!0)}if(!d&&!L.cartId)return void n("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(!L.cartData&&L.cartId){t("Initialize cart data");const e=await A(L.cartId);if(!e)return void n("Failed to get cart data");L.cartData=e.cartData,L.zonosApiKey=e.zonosApiKey}const r=await(async()=>{if(!window.location.search.includes("zonosTestMode=1")||!window.Zonos.zonosApiKey)return null;if(t("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return t("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:e,json:o}=await f("/api/get-test-public-credential");if(e.length||!o)return n("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",e),null;const r=o.publicCredential;return r?(t(`[ZONOS - loadZonos] Retrieve new test public token ${r}`,"info"),r):(n("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();r&&(L.zonosApiKey=r)}const u=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");if(L.cartId&&L.cartData||!!u){t("Cart data or stripe client secret is available, inject hidden button and trigger checkout");const e=document.createElement("button");e.style.display="none",e.id="zonos--checkout-hidden-button",document.body.appendChild(e)}t("init zonos"),L.injectCustomScriptForHostedCheckout(),L.injectZonosCdn(),L.injectZonosCss(),L.injectFonts(),L.injectController({config:{appearance:o,checkoutSettings:r,currencyConverter:s,helloSettings:i,onCountryChange:a,overrideCurrencyFormat:c}}),L.doneInit=!0},D.injectCustomScriptForHostedCheckout=()=>{const e=L.cartData,o=(null==e?void 0:e.metadata)||[],n=o.find((e=>"customHeaderScript"===e.key)),r=o.find((e=>"customFooterScript"===e.key));if(window.Zonos.isLegacyCheckout&&(n||r)){if(n){t("Injecting custom header script");const e=document.createElement("script");e.textContent=n.value,document.head.appendChild(e)}if(r){t("Injecting custom footer script");const e=document.createElement("script");e.textContent=r.value,document.body.appendChild(e)}}else t("Skip injecting custom script for hosted checkout","info",{footerScript:r,headerScript:n,isLegacyCheckout:window.Zonos.isLegacyCheckout})},D.displayCurrency=()=>{const e=document.querySelector("zonos-hello");e&&e.displayCurrency()},D.openHelloDialog=e=>{const o=document.querySelector("zonos-hello");o&&o.openHelloDialog(null==e||e)},D.showNotification=e=>{var o;null===(o=L.zonosController)||void 0===o||o.showNotification(e)},D.updateOrganizationName=e=>{var o;null===(o=L.zonosController)||void 0===o||o.updateOrganizationName(e)},D.disablePlaceOrderButtons=({autoEnable:e=!0,config:o,disable:t,placeOrderButtonSelector:n})=>{var r;if(!(null===(r=o.checkoutSettings)||void 0===r?void 0:r.disablePlaceOrderButtonActivation)&&n){const o=document.querySelectorAll(n),r=e=>{e.target.getAttribute("disabled")&&(e.preventDefault(),e.stopPropagation())};o.forEach((e=>{e.getAttribute("data-zonos-checkout-attached")||(t?(e.setAttribute("disabled","true"),e.addEventListener("click",r)):(e.removeAttribute("disabled"),e.removeEventListener("click",r)))})),e&&t&&setTimeout((()=>{o.forEach((e=>{e.removeAttribute("disabled"),e.removeEventListener("click",r)}))}),5e3)}},D.injectController=({config:e})=>{var o;if(document.querySelector("zonos-controller"))return;if(null===(o=e.checkoutSettings)||void 0===o?void 0:o.placeOrderButtonSelector){const o=e.checkoutSettings.placeOrderButtonSelector;L.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:o});new MutationObserver((()=>{L.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:o})})).observe(document.body,{childList:!0,subtree:!0})}const r=document.createElement("zonos-controller");r.config=e,r.zonosApiKey=L.zonosApiKey||"",r.addEventListener("stripeInitEvent",(async e=>{const{detail:o}=e;t("loading Stripe");const s=await(async(...e)=>{O=!0;const o=Date.now();return C.then((t=>((e,o,t)=>{if(null===e)return null;const n=e.apply(void 0,o);return((e,o)=>{e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",startTime:o})})(n,t),n})(t,e,o)))})(o.publishableKey);s?(window.Zonos.stripe=s,r.initCheckoutElement(s)):n("API seems to be invalid or missing. Failed to load Stripe")})),document.body.appendChild(r),L.zonosController=r,t("Zonos controller injected!")},D.injectScript=({cdnType:e,isModule:o,theRestUrl:r})=>{const s=`${L.getZonosUrl(e)}/${r}`;if(document.querySelector(`script[src="${s}"]`))return void t(`Zonos script "${s}" already exists in the document`,"warn");const a=document.head||document.body,c=document.createElement("script");o?c.type="module":c.noModule=!0,c.src=s,c.crossOrigin="anonymous",c.onerror=()=>{n(`Failed to load ${c.src}`);const t=i(e);t&&L.injectScript({cdnType:t,isModule:o,theRestUrl:r})},a.appendChild(c)},D.getZonosUrl=e=>{const o=()=>{switch(e){case"jsdelivr":return $;case"unpkg":return"https://unpkg.com/@zonos/elements@1.3.141";case"cdnjs":return"https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.141";case"vercel":return N}};if(L.isNpm){return g()||o()}return o()},D.injectZonosCdn=()=>{L.injectScript({cdnType:s,isModule:!0,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"}),L.injectScript({cdnType:s,isModule:!1,theRestUrl:"dist/zonos-elements/zonos-elements.js"}),t("Zonos cdn script injected!")},D.injectStylesheet=({cdnType:e,theRestUrl:o})=>{const t=L.getZonosUrl(e),r=document.head||document.body,s=document.createElement("link");s.rel="preconnect",s.href=`${N}/`,r.appendChild(s);const a=document.createElement("link");a.rel="stylesheet",a.href=`${t}/${o}`,a.onerror=()=>{n(`Failed to load ${a.href}`);const t=i(e);t&&L.injectStylesheet({cdnType:t,theRestUrl:o})},r.appendChild(a)},D.injectZonosCss=()=>{document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')?t("Zonos style links already injected","warn"):(L.injectStylesheet({cdnType:s,theRestUrl:"dist/zonos-elements/zonos-elements.css"}),t("Zonos style css injected!"))},D.injectFonts=()=>{if((()=>{const e=document.querySelectorAll(`link[rel="stylesheet"][href^="${U}"]`);for(let o=0;o<e.length;o++){const t=e[o];if(t&&!P.test(t.href))return t}return null})())return void t("Inter font already injected","warn");const e=document.head||document.body,o=document.createElement("link");o.rel="preconnect",o.href=U,e.appendChild(o);const n=document.createElement("link");n.rel="stylesheet",n.href=`${U}/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap`,e.appendChild(n),t("Zonos font injected!")},D.setupGoogleFont=e=>{var o;null===(o=L.zonosController)||void 0===o||o.setupGoogleFont(e)},D.injectSupportGoogleFont=e=>{var o;t(`[FONT] injecting ${e}`);const n=null===(o=e.match(/family=(.*?):/))||void 0===o?void 0:o[1],r=document.head||document.body;if(!document.querySelector(`link[rel="preconnect"][href^="${U}"]`)){const e=document.createElement("link");e.rel="preconnect",e.href=U,r.appendChild(e)}if(document.querySelector(`link[rel="stylesheet"][href="${e}"]`))return void t(`[FONT] ${n} font already injected`,"warn");const s=document.createElement("link");s.rel="stylesheet",s.href=e,r.appendChild(s),t(`[FONT] ${n} font injected!`)},exports.Zonos=D})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function o(o,e){var n={};for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&e.indexOf(t)<0&&(n[t]=o[t]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(t=Object.getOwnPropertySymbols(o);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(o,t[r])&&(n[t[r]]=o[t[r]])}return n}"function"==typeof SuppressedError&&SuppressedError;const e=["cloudflare","vercel"],n=e[0],t={cloudflare:"https://route.elements.zonos.com",vercel:"https://route.js.zonos.com"},r=t[n],s=(o=n)=>{const t=e.indexOf(o),r=e[t+1];return r||null},i=o=>{if("string"==typeof o)try{return JSON.parse(o)}catch(o){return null}return null},a=performance.now(),c=o=>{if("string"==typeof o)return o;try{return JSON.stringify(o)}catch(e){if(o&&"function"==typeof o.toString){return o.toString()}return"Unable to stringify info"}},d=(o,e,...n)=>{var t,r;const{elapsedTimePretty:s}=(()=>{const o=performance.now()-a,e=o>1e3?`${(o/1e3).toFixed(2)}s`:`${o.toFixed(2)}ms`;return{elapsedTime:o,elapsedTimePretty:e}})(),i=[`(${s})`,...n];i.map(c).join(" ");if(!(!!(null===(t=window.Zonos)||void 0===t?void 0:t.debug)||!!window.location.search.match(/\?.*(&*)zonosDebug=1/)))return void("error"===e&&console.error(o,...i));let d=document.querySelector("iframe#zonos---debug-logging-iframe");d||(d=document.createElement("iframe"),d.id="zonos---debug-logging-iframe",d.style.display="none",d.style.opacity="0",d.style.position="absolute",d.style.top="-9999px",d.style.left="-9999px",d.style.width="1px",d.style.height="1px",d.style.border="none",d.style.overflow="hidden",d.style.visibility="hidden",document.body.appendChild(d));const l=(null===(r=d.contentWindow)||void 0===r?void 0:r.window.console)||window.console;switch(e){case"warn":l.warn(o,...i);break;case"info":l.info(o,...i);break;case"error":l.error(o,...i);break;default:l.groupCollapsed(o,...i),l.trace(),l.groupEnd()}},l=async({endpoint:o,errors:e,metadata:n,shouldPostReleaseErrorReporting:i})=>{if(d("sendErrorLog","warn",o,n,e),i){const o=Number(window.Zonos.releaseDate);if((new Date).getTime()-o>36e5)return}const a="userAgentData"in window.navigator?window.navigator.userAgentData:null,c={endpoint:o,errors:e,href:window.location.href,metadata:Object.assign({appVersion:window.Zonos.version,domain:window.Zonos.domain,publicCredential:window.Zonos.zonosApiKey,userAgent:a&&a.brands.length>0?a:window.navigator.userAgent},n)};try{fetch(`${r}/api/zonos-elements/log-error`,{body:JSON.stringify(c),headers:{"Zonos-Referer":window.location.hostname},method:"POST"})}catch(o){const e=s();if(!e)return;fetch(`${t[e]}/api/zonos-elements/log-error`,{body:JSON.stringify(c),method:"POST"})}},p=async({response:o,shouldLog:e=!0,shouldThrow:n=!1})=>{try{const e=await o.text(),n=i(e);if(!n)throw new Error(`Failed to parse content: ${e}`);return n}catch(o){if(n)throw o;return e&&console.error(o),null}},u=async({basePathType:o,options:e,path:r})=>{let s;const i=window.Zonos.zonosQaUrlApi||t[o]||n,a=new URL(i+r),c=window.Zonos.cartId?`${window.location.hostname}-${window.Zonos.cartId}`:window.location.hostname;a.searchParams.set("zToken",(o=>{try{return btoa(o).replace(/=/g,"")}catch(e){return o.replace(/[^A-Za-z0-9]/g,"").split("").reverse().join("")}})(c));try{s=await fetch(a.toString(),e)}catch(o){if(o instanceof Error)return{baseUrl:i,errors:[{message:o.message,type:"unknown"}],json:null,response:null,zonosMode:null};return{baseUrl:i,errors:[{message:"Failed to fetch",type:"unknown"}],json:null,response:null,zonosMode:null}}const d=s.headers.get("Zonos-Mode"),l=window.Zonos.zonosQaUrl;if(!window.Zonos.modeAlerted&&d&&l&&(window.Zonos.modeAlerted=!0),s.ok){return{baseUrl:i,errors:[],json:await p({response:s}),response:s,zonosMode:d}}const u=s.status.toString();try{const o=await p({response:s,shouldThrow:!0});return{baseUrl:i,errors:[{message:JSON.stringify(o),type:u}],json:null,response:s,zonosMode:d}}catch(o){return{baseUrl:i,errors:[{message:`${u}: ${"Unknown error"}`,type:u}],json:null,response:null,zonosMode:d}}},m=async({basePathType:e,options:n,path:r})=>{var a,c;const p=r.startsWith("/api/bigcommerce")?"vercel":e,w=await u({basePathType:p,options:n,path:r}),{errors:g,response:f}=w,y=o(w,["errors","response"]),h=s(p),v=!!g.find((({type:o})=>"unknown"===o))||404===(null==f?void 0:f.status),Z=h&&v;return v&&l({endpoint:t[p]+r,errors:g.map((({message:o})=>`API: ${o}`)),metadata:{currentBasePath:p,nextFallbackApiType:h,requestHeaders:null==n?void 0:n.headers,requestPayload:i(null===(a=null==n?void 0:n.body)||void 0===a?void 0:a.toString())||(null===(c=null==n?void 0:n.body)||void 0===c?void 0:c.toString()),status:null==f?void 0:f.status,statusText:null==f?void 0:f.statusText},shouldPostReleaseErrorReporting:!0}),Z?(d(`=== "${r}" failed to fetch, trying next fallback ${h}`),m({basePathType:h,options:n,path:r})):Object.assign({errors:g,response:f},y)},w=async(e,t)=>{const r=o(t||{},[]),s=r.body?JSON.stringify(r.body):void 0,i=r.method||"GET",a=Object.assign({"Content-Type":"application/json","Zonos-Is-BigCommerce":window.Zonos.isBigCommerce.toString(),"Zonos-Referer":window.location.hostname,"Zonos-Version":window.Zonos.version,credentialtoken:window.Zonos.zonosApiKey||"Empty credential token from zonos-elements"},r.headers),c=Object.assign(Object.assign({},r),{body:"GET"===i?void 0:s,headers:a,method:i}),l=new URLSearchParams(window.location.search).get("useFallbackApi");return d(e,"info"),m({basePathType:l||n,options:c,path:e})},g=(o,...e)=>{d(o,"error",...e)},f=["jsdelivr","cdnjs","unpkg","vercel"],y=o=>{if(!o)return null;const e=new URL(o).searchParams.get("zonosQaUrl");if(!e)return null;return/[^a-zA-Z0-9-_]+/.test(e)?null:e},h=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,v=new RegExp(`^${h.source}$`),Z=new RegExp(`^cart_${h.source}$`),S=o=>o?Z.test(o)?{isDgsCartId:!0,isLegacyCartId:!1}:v.test(o)?{isDgsCartId:!1,isLegacyCartId:!0}:{isDgsCartId:!1,isLegacyCartId:!1}:{isDgsCartId:!1,isLegacyCartId:!1},O=async({cartId:o,retries:e})=>{const n="1"===new URLSearchParams(window.location.search).get("zonosTestMode"),{errors:t,json:r}=await w("/api/zonos-elements/get-temp-cart",{body:{isTestMode:n,tempCartUUID:o},headers:{"Content-Type":"application/json"},method:"POST"}),s=!r||t.length;return s&&e?(d("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:e}),await new Promise((o=>setTimeout(o,500))),O({cartId:o,retries:e-1})):s?null:r};var z;const L=(()=>{const o=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||o)return null;const e=y(window.location.href),n="https://v1.3.140.js.zonos.com";if(!e&&(n.includes("test.")||n.includes("test-")))return n;if(!e&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!e)return null;if("dev-elements"===e)return"https://dev.elements.zonos.com";const t=`https://${e}.preview.js.zonos.com`;return d(`[ZONOS-WARNING] using '${t}' for loading elements script`,"warn"),fetch(t).then((()=>{window.sessionStorage.removeItem("zonos--checkout-session-id"),window.sessionStorage.removeItem("zonos--client-secret")})).catch((()=>{alert(`[ZONOS-WARNING] '${t}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);const o=new URLSearchParams(window.location.search);o.delete("zonosQaUrl");const{pathname:e}=window.location,n=`${e}?${o.toString()}`;return window.history.replaceState(window.history.state,"",n),window.location.reload(),null})),t})(),b=(()=>{const o=(o=>{if(!o)return null;const e=new URL(o).searchParams.get("zonosQaUrlApi");return e?/[^a-zA-Z0-9-_]+/.test(e)?null:e:null})(window.location.href),e=y(window.location.href),n=o||e;if(!n&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.demo.elements.zonos.com";if(!n)return null;if("dev-elements"===n)return"https://dev.demo.elements.zonos.com";if(!o)return null;const t=`https://${o}.route.js.zonos.com`;return d(`[ZONOS-WARNING] using '${t}' for serverless API`,"warn"),t})();class U{}z=U,U.isNpm=!1,U.isBigCommerce=!1,U.requested=!1,U.cartData=null,U.domain=window.location!=window.parent.location?document.referrer:document.location.hostname,U.version="v1.3.140",U.isLegacyCheckout=!1,U.legacyStoreLogo=null,U.legacyStoreFavicon=null,U.parallelLoadTimes=[],U.parallelLoadState="off",U.releaseDate="1734113795652",U.loadScriptLogHandler=async({cdnLoadTime:o,fallbackLoadTime:e,isError:n,metadata:t,scriptLoadUrl:r,storeId:s,type:i})=>{try{const o=window.performance.getEntriesByType("resource").find((o=>{const e=o;return e.name.includes(r)&&"script"===e.initiatorType}));null==o||o.transferSize;(async o=>{})((o&&(null==o?void 0:o.duration)>0?parseFloat(o.duration.toFixed(2)):parseFloat(e.toFixed(2)),Object.assign({decodedBodySize:null==o?void 0:o.decodedBodySize,encodedBodySize:null==o?void 0:o.encodedBodySize,fallbackLoadTime:e,isError:!!n},t)))}catch(o){}},U.loadScriptLogParallelHandler=async o=>{try{if(z.parallelLoadTimes.push(o),2===z.parallelLoadTimes.length){const o=z.parallelLoadTimes.find((o=>"vercel"===o.type)),e=z.parallelLoadTimes.find((o=>"jsdelivr"===o.type));if(!o||!e)return;if(o.isError&&e.isError)return void l({endpoint:`<${o.scriptLoadUrl}> <${e.scriptLoadUrl}>`,errors:["Failed to fetch both Vercel and jsdelivr CDN. Perhaps network issue on customer site."],metadata:{cdnLoadTime:e.fallbackLoadTime,cdnType:e.type,vercelLoadTime:o.fallbackLoadTime}});z.loadScriptLogHandler({cdnLoadTime:e.fallbackLoadTime,fallbackLoadTime:o.fallbackLoadTime,isError:o.isError,metadata:{cdnScriptFallbackTime:e.fallbackLoadTime,cdnScriptIsError:!!e.isError,cdnScriptLoadUrl:e.scriptLoadUrl,cdnScriptType:e.type},scriptLoadUrl:o.scriptLoadUrl,storeId:o.storeId,type:o.type})}}catch(o){}},U.legacyCheckoutErrorHandler=({message:o,metadata:e})=>{g(`[ZONOS - loadZonos] ${o}`),l({endpoint:"LegacyCheckoutInit",errors:[o],metadata:Object.assign(Object.assign({},e),{tempCartUUID:z.cartId})}),document.dispatchEvent(new CustomEvent("legacyCheckoutError",{detail:o}))},U.getGithubCdn=({type:o,version:e})=>{let n="https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.140";"cdnjs"===o?n="https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.140":"unpkg"===o&&(n="https://unpkg.com/@zonos/elements@1.3.140");return e&&"alpha"!==e?n.replace(/@zonos\/elements@(.+)/,`@zonos/elements@${e}`).replace(/\/zonos-elements\/(.+)/,`/zonos-elements/${e}`):n},U.injectZonos=({cdnType:o="jsdelivr",initConfig:e,parallelLoaded:n,vercelUrl:t,version:r})=>{var s;e=Object.assign(Object.assign({},e),{zonosApiKey:z.zonosApiKey}),r&&(window.Zonos.version=`v${r}`);const i="vercel"===o?t:z.getGithubCdn({type:o,version:r}),a=L||i,c=a.replace("https://","").replace("http://",""),p=document.createElement("script"),u=r&&r<"1.2.5"?"loadZonos.js":"zonos.js";p.src=`https://${c}/dist/scripts/${u}`,d(`[ZONOS - loadZonos] Injecting "${u}" from "${c}"`,"info");const m="4g"===(null===(s=(()=>{const o="connection"in window.navigator?window.navigator.connection:null,e="mozConnection"in window.navigator?window.navigator.mozConnection:null,n="webkitConnection"in window.navigator?window.navigator.webkitConnection:null;return o||e||n})())||void 0===s?void 0:s.effectiveType),w=["dev.elements.zonos.com","zonos.com"].some((o=>window.location.href.includes(o))),g=f[0]===o,y=f[1],h="on"===z.parallelLoadState&&m&&g&&y&&!w;h&&z.injectZonos({cdnType:y,initConfig:e,parallelLoaded:!0,vercelUrl:t,version:r});const v=performance.now();p.addEventListener("load",(()=>{var t;if(h||n?z.loadScriptLogParallelHandler({fallbackLoadTime:performance.now()-v,scriptLoadUrl:p.src,storeId:z.storeId,type:o}):z.loadScriptLogHandler({fallbackLoadTime:performance.now()-v,scriptLoadUrl:p.src,storeId:z.storeId,type:o}),z.isBigCommerce||(z.isBigCommerce=!!window.stencilBootstrap||!!window.bcConfig||!!document.querySelector('script[src*="bigcommerce.com"]')),window.Zonos.isNpm=!1,window.Zonos.zonosQaUrl=L,window.Zonos.zonosQaUrlApi=b,window.Zonos.isBigCommerce=z.isBigCommerce,z.cartId){if(!z.zonosApiKey)throw z.legacyCheckoutErrorHandler({message:"zonosApiKey is missing to initiate checkout"}),new Error("zonosApiKey is required for legacy checkout");if(!z.cartData)throw z.legacyCheckoutErrorHandler({message:"cartData is missing to initiate legacy checkout"}),new Error("cartData is required for legacy checkout");if(z.legacyStoreFavicon&&z.isLegacyCheckout){const o=document.createElement("link");o.rel="shortcut icon",o.type="image/x-icon",o.href=z.legacyStoreFavicon,document.head.appendChild(o)}window.Zonos.cartData=z.cartData,window.Zonos.isLegacyCheckout=z.isLegacyCheckout;const o=z.isLegacyCheckout&&"CLOSE_MODAL"===(null===(t=e.checkoutSettings)||void 0===t?void 0:t.successBehavior),n=Object.assign(Object.assign({},e),{appearance:Object.assign(Object.assign({},e.appearance),{logoUrl:z.legacyStoreLogo||""}),checkoutSettings:Object.assign(Object.assign({},e.checkoutSettings),{successBehavior:o?"ZONOS_SUCCESS_PAGE":void 0,successRedirectUrl:o?z.cartData.storeBaseUrl:void 0}),zonosApiKey:z.zonosApiKey});e=n}window.Zonos.version&&(d(`[ZONOS - loadZonos] Execute "Zonos.init" from "${u}" from "${c}"`,"info"),window.Zonos.init(e))})),p.addEventListener("error",(async()=>{const s=(o=>{const e=f.indexOf(o);return f[e+1]||null})(o);if(!h&&!n){if(!s)return;z.injectZonos({cdnType:s,initConfig:e,vercelUrl:t,version:r})}if(["localhost",".zonos.com"].some((o=>window.location.href.includes(o)))||L)return;if(h||n)return void z.loadScriptLogParallelHandler({fallbackLoadTime:performance.now()-v,isError:!0,scriptLoadUrl:p.src,storeId:z.storeId,type:o});["unpkg","cdnjs","vercel"].includes(o)?l({endpoint:p.src,errors:[`zonos.js - Failed to fetch ${o} CDN.`],metadata:{cdnLoadTime:performance.now()-v,cdnType:o,loadUrl:a,version:r},shouldPostReleaseErrorReporting:!!s}):l({endpoint:p.src,errors:["[Info] Using alternative CDN. Failed to fetch script"],metadata:{cdnType:o,vercelLoadTime:performance.now()-v}})})),document.head.appendChild(p)},U.init=async o=>{var e;if(d("=== Init zonos script release date","info",z.releaseDate),L&&!window.isZonosPreview){d(`[ZONOS - loadZonos] Re-inject "loadZonos.js" from zonosQaUrl: ${L}`,"info");const e=document.createElement("script");return e.src=`${L}/dist/scripts/loadZonos.js?timestamp=${Date.now()}`,document.head.appendChild(e),e.addEventListener("load",(()=>{window.Zonos.isNpm=!1,window.Zonos.isBigCommerce=z.isBigCommerce,window.Zonos.isLegacyCheckout=z.isLegacyCheckout,window.Zonos.init(o)})),e.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${L}`)})),void(window.isZonosPreview=!0)}const n=new URLSearchParams(window.location.search).get("tempCartUUID"),{isDgsCartId:t,isLegacyCartId:r}=S(n);if(n&&!r&&!t)return void z.legacyCheckoutErrorHandler({message:`[ZONOS - loadZonos] invalid &tempCartUUID=${n}`,metadata:{invalidCartId:!0}});z.cartId=n;const s="https://v1.3.140.js.zonos.com",i=document.querySelector('script[src*="/zonos.js"]'),a=null===(e=document.querySelector("script[src*='/loadZonos.js']"))||void 0===e?void 0:e.src;d(`[ZONOS - init] first load script src: ${a}`,"info"),window.Zonos.zonosQaUrl=L,window.Zonos.zonosQaUrlApi=b,window.Zonos.zonosQaUrl&&d(`[ZONOS - init] using zonosQaUrl: ${window.Zonos.zonosQaUrl}`,"info"),window.Zonos.zonosQaUrlApi&&d(`[ZONOS - init] using zonosQaUrlApi: ${window.Zonos.zonosQaUrlApi}`,"info");const c=null==a?void 0:a.includes("timestamp=");if(!(z.isNpm||a&&c))return void g("[ZONOS - loadZonos] A timestamp is required as a query parameter in the loadZonos.js script source. This timestamp ensures that you are loading the most recent version of the script, avoiding any cached versions.");if(i||!a||z.requested)return void d("[ZONOS - loadZonos] script is already loaded or requested","info");if(!o.zonosApiKey&&!z.cartId)return z.legacyCheckoutErrorHandler({message:"Zonos API key is required unless `tempCartUUID` is provided in url query params."}),void g("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(z.requested=!0,z.zonosApiKey=o.zonosApiKey,z.storeId=o.storeId,z.cartId){const o=await(async o=>{const{isDgsCartId:e,isLegacyCartId:n}=S(o);if(!n&&!e)return g("[ZONOS - loadZonos] invalid cart id"),null;const t=await O({cartId:o,retries:5});return d("[ZONOS - loadZonos] getting temp cart data","info",t),t?(window.Zonos.storeId=t.cartData.storeId,window.Zonos.zonosApiKey=t.cartData.credentialToken,{cartData:t.cartData,storeFavicon:t.storeFaviconUrl,storeId:t.cartData.storeId,storeLogo:t.storeLogoUrl,zonosApiKey:t.cartData.credentialToken}):(g("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process."),null)})(z.cartId);if(!o)throw z.legacyCheckoutErrorHandler({message:"Error getting cart data"}),new Error("Error getting cart data");z.cartData=o.cartData,z.legacyStoreLogo=o.storeLogo,z.legacyStoreFavicon=o.storeFavicon,z.storeId=o.storeId,z.zonosApiKey=o.zonosApiKey}if(!z.zonosApiKey)return void g('"zonosApiKey" is required to initialize Zonos');const l=await(async()=>{if(!window.location.search.includes("zonosTestMode=1")||!window.Zonos.zonosApiKey)return null;if(d("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return d("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:o,json:e}=await w("/api/get-test-public-credential");if(o.length||!e)return g("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",o),null;const n=e.publicCredential;return n?(d(`[ZONOS - loadZonos] Retrieve new test public token ${n}`,"info"),n):(g("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();if(l&&(d(`[ZONOS - loadZonos] Using test API key: ${l} for test mode`,"info"),z.zonosApiKey=l),!z.storeId)return d("[ZONOS - loadZonos] loading latest script since storeId is not provided."),void z.injectZonos({initConfig:o,vercelUrl:s,version:null});const p=z.storeId||o.storeId;d(`[ZONOS - loadZonos] Store ID: ${p}`,"info");const u=new URLSearchParams;u.set("storeId",p.toString()),window.location.search.includes("_enableStoreVersionPinned=1")&&u.set("_enableStoreVersionPinned","1");const{errors:m,json:f}=await w(`/api/get-store-version?${u.toString()}`);if(m.length||!f)return d("[ZONOS - loadZonos] Error getting store version, loading the latest version.","error"),void z.injectZonos({initConfig:o,vercelUrl:s,version:null});const{isDifferent:y,source:h,version:v}=f;if(d(`[ZONOS - loadZonos] Store version: ${v}, source: ${h}`,"info"),y){d(`[ZONOS - loadZonos] Updating saved store version to ${v}`,"info");const o={storeId:p,version:v};w(`/api/set-store-version?${u.toString()}`,{body:o,method:"POST"}).catch((o=>g("Unable to save store's vesrion",o)))}if(!i){const{currentLoadScriptUrl:e,isForceLoadVersionDomain:n,isWhiteListed:t}=(({loadScriptSrc:o})=>{if(!o)return{currentLoadScriptUrl:"",isForceLoadVersionDomain:!1,isWhiteListed:!1};const e=new URL(o).origin,n=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"].some((o=>e.includes(o))),t=["qa.js.zonos.com"].some((o=>e.includes(o)));return{currentLoadScriptUrl:e,isForceLoadVersionDomain:t,isWhiteListed:n}})({loadScriptSrc:a}),r=t&&!n?e:`${"alpha"===v?"alpha":`v${v}`}.js.zonos.com`,s=t&&!n?null:v;d("[ZONOS - loadZonos] injecting zonos script","info",{currentLoadScriptUrl:e,isForceLoadVersionDomain:n,isWhiteListed:t,loadUrl:r,loadVersion:s,version:v}),z.injectZonos({initConfig:o,vercelUrl:r,version:s})}},(void 0===window.Zonos||window.isZonosPreview)&&(window.Zonos=U)})();
|
|
1
|
+
(function(){"use strict";function o(o,e){var n={};for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&e.indexOf(t)<0&&(n[t]=o[t]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(t=Object.getOwnPropertySymbols(o);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(o,t[r])&&(n[t[r]]=o[t[r]])}return n}"function"==typeof SuppressedError&&SuppressedError;const e=["cloudflare","vercel"],n=e[0],t={cloudflare:"https://route.elements.zonos.com",vercel:"https://route.js.zonos.com"},r=t[n],s=(o=n)=>{const t=e.indexOf(o),r=e[t+1];return r||null},i=o=>{if("string"==typeof o)try{return JSON.parse(o)}catch(o){return null}return null},a=performance.now(),c=o=>{if("string"==typeof o)return o;try{return JSON.stringify(o)}catch(e){if(o&&"function"==typeof o.toString){return o.toString()}return"Unable to stringify info"}},d=(o,e,...n)=>{var t,r;const{elapsedTimePretty:s}=(()=>{const o=performance.now()-a,e=o>1e3?`${(o/1e3).toFixed(2)}s`:`${o.toFixed(2)}ms`;return{elapsedTime:o,elapsedTimePretty:e}})(),i=[`(${s})`,...n];i.map(c).join(" ");if(!(!!(null===(t=window.Zonos)||void 0===t?void 0:t.debug)||!!window.location.search.match(/\?.*(&*)zonosDebug=1/)))return void("error"===e&&console.error(o,...i));let d=document.querySelector("iframe#zonos---debug-logging-iframe");d||(d=document.createElement("iframe"),d.id="zonos---debug-logging-iframe",d.style.display="none",d.style.opacity="0",d.style.position="absolute",d.style.top="-9999px",d.style.left="-9999px",d.style.width="1px",d.style.height="1px",d.style.border="none",d.style.overflow="hidden",d.style.visibility="hidden",document.body.appendChild(d));const l=(null===(r=d.contentWindow)||void 0===r?void 0:r.window.console)||window.console;switch(e){case"warn":l.warn(o,...i);break;case"info":l.info(o,...i);break;case"error":l.error(o,...i);break;default:l.groupCollapsed(o,...i),l.trace(),l.groupEnd()}},l=async({endpoint:o,errors:e,metadata:n,shouldPostReleaseErrorReporting:i})=>{if(d("sendErrorLog","warn",o,n,e),i){const o=Number(window.Zonos.releaseDate);if((new Date).getTime()-o>36e5)return}const a="userAgentData"in window.navigator?window.navigator.userAgentData:null,c={endpoint:o,errors:e,href:window.location.href,metadata:Object.assign({appVersion:window.Zonos.version,domain:window.Zonos.domain,publicCredential:window.Zonos.zonosApiKey,userAgent:a&&a.brands.length>0?a:window.navigator.userAgent},n)};try{fetch(`${r}/api/zonos-elements/log-error`,{body:JSON.stringify(c),headers:{"Zonos-Referer":window.location.hostname},method:"POST"})}catch(o){const e=s();if(!e)return;fetch(`${t[e]}/api/zonos-elements/log-error`,{body:JSON.stringify(c),method:"POST"})}},p=async({response:o,shouldLog:e=!0,shouldThrow:n=!1})=>{try{const e=await o.text(),n=i(e);if(!n)throw new Error(`Failed to parse content: ${e}`);return n}catch(o){if(n)throw o;return e&&console.error(o),null}},u=async({basePathType:o,options:e,path:r})=>{let s;const i=window.Zonos.zonosQaUrlApi||t[o]||n,a=new URL(i+r),c=window.Zonos.cartId?`${window.location.hostname}-${window.Zonos.cartId}`:window.location.hostname;a.searchParams.set("zToken",(o=>{try{return btoa(o).replace(/=/g,"")}catch(e){return o.replace(/[^A-Za-z0-9]/g,"").split("").reverse().join("")}})(c));try{s=await fetch(a.toString(),e)}catch(o){if(o instanceof Error)return{baseUrl:i,errors:[{message:o.message,type:"unknown"}],json:null,response:null,zonosMode:null};return{baseUrl:i,errors:[{message:"Failed to fetch",type:"unknown"}],json:null,response:null,zonosMode:null}}const d=s.headers.get("Zonos-Mode"),l=window.Zonos.zonosQaUrl;if(!window.Zonos.modeAlerted&&d&&l&&(window.Zonos.modeAlerted=!0),s.ok){return{baseUrl:i,errors:[],json:await p({response:s}),response:s,zonosMode:d}}const u=s.status.toString();try{const o=await p({response:s,shouldThrow:!0});return{baseUrl:i,errors:[{message:JSON.stringify(o),type:u}],json:null,response:s,zonosMode:d}}catch(o){return{baseUrl:i,errors:[{message:`${u}: ${"Unknown error"}`,type:u}],json:null,response:null,zonosMode:d}}},m=async({basePathType:e,options:n,path:r})=>{var a,c;const p=r.startsWith("/api/bigcommerce")?"vercel":e,w=await u({basePathType:p,options:n,path:r}),{errors:g,response:f}=w,y=o(w,["errors","response"]),h=s(p),v=!!g.find((({type:o})=>"unknown"===o))||404===(null==f?void 0:f.status),Z=h&&v;return v&&l({endpoint:t[p]+r,errors:g.map((({message:o})=>`API: ${o}`)),metadata:{currentBasePath:p,nextFallbackApiType:h,requestHeaders:null==n?void 0:n.headers,requestPayload:i(null===(a=null==n?void 0:n.body)||void 0===a?void 0:a.toString())||(null===(c=null==n?void 0:n.body)||void 0===c?void 0:c.toString()),status:null==f?void 0:f.status,statusText:null==f?void 0:f.statusText},shouldPostReleaseErrorReporting:!0}),Z?(d(`=== "${r}" failed to fetch, trying next fallback ${h}`),m({basePathType:h,options:n,path:r})):Object.assign({errors:g,response:f},y)},w=async(e,t)=>{const r=o(t||{},[]),s=r.body?JSON.stringify(r.body):void 0,i=r.method||"GET",a=Object.assign({"Content-Type":"application/json","Zonos-Is-BigCommerce":window.Zonos.isBigCommerce.toString(),"Zonos-Referer":window.location.hostname,"Zonos-Version":window.Zonos.version,credentialtoken:window.Zonos.zonosApiKey||"Empty credential token from zonos-elements"},r.headers),c=Object.assign(Object.assign({},r),{body:"GET"===i?void 0:s,headers:a,method:i}),l=new URLSearchParams(window.location.search).get("useFallbackApi");return d(e,"info"),m({basePathType:l||n,options:c,path:e})},g=(o,...e)=>{d(o,"error",...e)},f=["jsdelivr","cdnjs","unpkg","vercel"],y=o=>{if(!o)return null;const e=new URL(o).searchParams.get("zonosQaUrl");if(!e)return null;return/[^a-zA-Z0-9-_]+/.test(e)?null:e},h=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,v=new RegExp(`^${h.source}$`),Z=new RegExp(`^cart_${h.source}$`),S=o=>o?Z.test(o)?{isDgsCartId:!0,isLegacyCartId:!1}:v.test(o)?{isDgsCartId:!1,isLegacyCartId:!0}:{isDgsCartId:!1,isLegacyCartId:!1}:{isDgsCartId:!1,isLegacyCartId:!1},O=async({cartId:o,retries:e})=>{const n="1"===new URLSearchParams(window.location.search).get("zonosTestMode"),{errors:t,json:r}=await w("/api/zonos-elements/get-temp-cart",{body:{isTestMode:n,tempCartUUID:o},headers:{"Content-Type":"application/json"},method:"POST"}),s=!r||t.length;return s&&e?(d("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:e}),await new Promise((o=>setTimeout(o,500))),O({cartId:o,retries:e-1})):s?null:r};var z;const L=(()=>{const o=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||o)return null;const e=y(window.location.href),n="https://v1.3.141.js.zonos.com";if(!e&&(n.includes("test.")||n.includes("test-")))return n;if(!e&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!e)return null;if("dev-elements"===e)return"https://dev.elements.zonos.com";const t=`https://${e}.preview.js.zonos.com`;return d(`[ZONOS-WARNING] using '${t}' for loading elements script`,"warn"),fetch(t).then((()=>{window.sessionStorage.removeItem("zonos--checkout-session-id"),window.sessionStorage.removeItem("zonos--client-secret")})).catch((()=>{alert(`[ZONOS-WARNING] '${t}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);const o=new URLSearchParams(window.location.search);o.delete("zonosQaUrl");const{pathname:e}=window.location,n=`${e}?${o.toString()}`;return window.history.replaceState(window.history.state,"",n),window.location.reload(),null})),t})(),b=(()=>{const o=(o=>{if(!o)return null;const e=new URL(o).searchParams.get("zonosQaUrlApi");return e?/[^a-zA-Z0-9-_]+/.test(e)?null:e:null})(window.location.href),e=y(window.location.href),n=o||e;if(!n&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.demo.elements.zonos.com";if(!n)return null;if("dev-elements"===n)return"https://dev.demo.elements.zonos.com";if(!o)return null;const t=`https://${o}.route.js.zonos.com`;return d(`[ZONOS-WARNING] using '${t}' for serverless API`,"warn"),t})();class U{}z=U,U.isNpm=!1,U.isBigCommerce=!1,U.requested=!1,U.cartData=null,U.domain=window.location!=window.parent.location?document.referrer:document.location.hostname,U.version="v1.3.141",U.isLegacyCheckout=!1,U.legacyStoreLogo=null,U.legacyStoreFavicon=null,U.parallelLoadTimes=[],U.parallelLoadState="off",U.releaseDate="1734130633682",U.loadScriptLogHandler=async({cdnLoadTime:o,fallbackLoadTime:e,isError:n,metadata:t,scriptLoadUrl:r,storeId:s,type:i})=>{try{const o=window.performance.getEntriesByType("resource").find((o=>{const e=o;return e.name.includes(r)&&"script"===e.initiatorType}));null==o||o.transferSize;(async o=>{})((o&&(null==o?void 0:o.duration)>0?parseFloat(o.duration.toFixed(2)):parseFloat(e.toFixed(2)),Object.assign({decodedBodySize:null==o?void 0:o.decodedBodySize,encodedBodySize:null==o?void 0:o.encodedBodySize,fallbackLoadTime:e,isError:!!n},t)))}catch(o){}},U.loadScriptLogParallelHandler=async o=>{try{if(z.parallelLoadTimes.push(o),2===z.parallelLoadTimes.length){const o=z.parallelLoadTimes.find((o=>"vercel"===o.type)),e=z.parallelLoadTimes.find((o=>"jsdelivr"===o.type));if(!o||!e)return;if(o.isError&&e.isError)return void l({endpoint:`<${o.scriptLoadUrl}> <${e.scriptLoadUrl}>`,errors:["Failed to fetch both Vercel and jsdelivr CDN. Perhaps network issue on customer site."],metadata:{cdnLoadTime:e.fallbackLoadTime,cdnType:e.type,vercelLoadTime:o.fallbackLoadTime}});z.loadScriptLogHandler({cdnLoadTime:e.fallbackLoadTime,fallbackLoadTime:o.fallbackLoadTime,isError:o.isError,metadata:{cdnScriptFallbackTime:e.fallbackLoadTime,cdnScriptIsError:!!e.isError,cdnScriptLoadUrl:e.scriptLoadUrl,cdnScriptType:e.type},scriptLoadUrl:o.scriptLoadUrl,storeId:o.storeId,type:o.type})}}catch(o){}},U.legacyCheckoutErrorHandler=({message:o,metadata:e})=>{g(`[ZONOS - loadZonos] ${o}`),l({endpoint:"LegacyCheckoutInit",errors:[o],metadata:Object.assign(Object.assign({},e),{tempCartUUID:z.cartId})}),document.dispatchEvent(new CustomEvent("legacyCheckoutError",{detail:o}))},U.getGithubCdn=({type:o,version:e})=>{let n="https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.141";"cdnjs"===o?n="https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.141":"unpkg"===o&&(n="https://unpkg.com/@zonos/elements@1.3.141");return e&&"alpha"!==e?n.replace(/@zonos\/elements@(.+)/,`@zonos/elements@${e}`).replace(/\/zonos-elements\/(.+)/,`/zonos-elements/${e}`):n},U.injectZonos=({cdnType:o="jsdelivr",initConfig:e,parallelLoaded:n,vercelUrl:t,version:r})=>{var s;e=Object.assign(Object.assign({},e),{zonosApiKey:z.zonosApiKey}),r&&(window.Zonos.version=`v${r}`);const i="vercel"===o?t:z.getGithubCdn({type:o,version:r}),a=L||i,c=a.replace("https://","").replace("http://",""),p=document.createElement("script"),u=r&&r<"1.2.5"?"loadZonos.js":"zonos.js";p.src=`https://${c}/dist/scripts/${u}?timestamp=${Date.now()}`,d(`[ZONOS - loadZonos] Injecting "${u}" from "${c}"`,"info");const m="4g"===(null===(s=(()=>{const o="connection"in window.navigator?window.navigator.connection:null,e="mozConnection"in window.navigator?window.navigator.mozConnection:null,n="webkitConnection"in window.navigator?window.navigator.webkitConnection:null;return o||e||n})())||void 0===s?void 0:s.effectiveType),w=["dev.elements.zonos.com","zonos.com"].some((o=>window.location.href.includes(o))),g=f[0]===o,y=f[1],h="on"===z.parallelLoadState&&m&&g&&y&&!w;h&&z.injectZonos({cdnType:y,initConfig:e,parallelLoaded:!0,vercelUrl:t,version:r});const v=performance.now();p.addEventListener("load",(()=>{var t;if(h||n?z.loadScriptLogParallelHandler({fallbackLoadTime:performance.now()-v,scriptLoadUrl:p.src,storeId:z.storeId,type:o}):z.loadScriptLogHandler({fallbackLoadTime:performance.now()-v,scriptLoadUrl:p.src,storeId:z.storeId,type:o}),z.isBigCommerce||(z.isBigCommerce=!!window.stencilBootstrap||!!window.bcConfig||!!document.querySelector('script[src*="bigcommerce.com"]')),window.Zonos.isNpm=!1,window.Zonos.zonosQaUrl=L,window.Zonos.zonosQaUrlApi=b,window.Zonos.isBigCommerce=z.isBigCommerce,z.cartId){if(!z.zonosApiKey)throw z.legacyCheckoutErrorHandler({message:"zonosApiKey is missing to initiate checkout"}),new Error("zonosApiKey is required for legacy checkout");if(!z.cartData)throw z.legacyCheckoutErrorHandler({message:"cartData is missing to initiate legacy checkout"}),new Error("cartData is required for legacy checkout");if(z.legacyStoreFavicon&&z.isLegacyCheckout){const o=document.createElement("link");o.rel="shortcut icon",o.type="image/x-icon",o.href=z.legacyStoreFavicon,document.head.appendChild(o)}window.Zonos.cartData=z.cartData,window.Zonos.isLegacyCheckout=z.isLegacyCheckout;const o=z.isLegacyCheckout&&"CLOSE_MODAL"===(null===(t=e.checkoutSettings)||void 0===t?void 0:t.successBehavior),n=Object.assign(Object.assign({},e),{appearance:Object.assign(Object.assign({},e.appearance),{logoUrl:z.legacyStoreLogo||""}),checkoutSettings:Object.assign(Object.assign({},e.checkoutSettings),{successBehavior:o?"ZONOS_SUCCESS_PAGE":void 0,successRedirectUrl:o?z.cartData.storeBaseUrl:void 0}),zonosApiKey:z.zonosApiKey});e=n}window.Zonos.version&&(d(`[ZONOS - loadZonos] Execute "Zonos.init" from "${u}" from "${c}"`,"info"),window.Zonos.init(e))})),p.addEventListener("error",(async()=>{const s=(o=>{const e=f.indexOf(o);return f[e+1]||null})(o);if(!h&&!n){if(!s)return;z.injectZonos({cdnType:s,initConfig:e,vercelUrl:t,version:r})}if(["localhost",".zonos.com"].some((o=>window.location.href.includes(o)))||L)return;if(h||n)return void z.loadScriptLogParallelHandler({fallbackLoadTime:performance.now()-v,isError:!0,scriptLoadUrl:p.src,storeId:z.storeId,type:o});["unpkg","cdnjs","vercel"].includes(o)?l({endpoint:p.src,errors:[`zonos.js - Failed to fetch ${o} CDN.`],metadata:{cdnLoadTime:performance.now()-v,cdnType:o,loadUrl:a,version:r},shouldPostReleaseErrorReporting:!!s}):l({endpoint:p.src,errors:["[Info] Using alternative CDN. Failed to fetch script"],metadata:{cdnType:o,vercelLoadTime:performance.now()-v}})})),document.head.appendChild(p)},U.init=async o=>{var e;if(d("=== Init zonos script release date","info",z.releaseDate),L&&!window.isZonosPreview){d(`[ZONOS - loadZonos] Re-inject "loadZonos.js" from zonosQaUrl: ${L}`,"info");const e=document.createElement("script");return e.src=`${L}/dist/scripts/loadZonos.js?timestamp=${Date.now()}`,document.head.appendChild(e),e.addEventListener("load",(()=>{window.Zonos.isNpm=!1,window.Zonos.isBigCommerce=z.isBigCommerce,window.Zonos.isLegacyCheckout=z.isLegacyCheckout,window.Zonos.init(o)})),e.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${L}`)})),void(window.isZonosPreview=!0)}const n=new URLSearchParams(window.location.search).get("tempCartUUID"),{isDgsCartId:t,isLegacyCartId:r}=S(n);if(n&&!r&&!t)return void z.legacyCheckoutErrorHandler({message:`[ZONOS - loadZonos] invalid &tempCartUUID=${n}`,metadata:{invalidCartId:!0}});z.cartId=n;const s="https://v1.3.141.js.zonos.com",i=document.querySelector('script[src*="/zonos.js"]'),a=null===(e=document.querySelector("script[src*='/loadZonos.js']"))||void 0===e?void 0:e.src;d(`[ZONOS - init] first load script src: ${a}`,"info"),window.Zonos.zonosQaUrl=L,window.Zonos.zonosQaUrlApi=b,window.Zonos.zonosQaUrl&&d(`[ZONOS - init] using zonosQaUrl: ${window.Zonos.zonosQaUrl}`,"info"),window.Zonos.zonosQaUrlApi&&d(`[ZONOS - init] using zonosQaUrlApi: ${window.Zonos.zonosQaUrlApi}`,"info");const c=null==a?void 0:a.includes("timestamp=");if(!(z.isNpm||a&&c))return void g("[ZONOS - loadZonos] A timestamp is required as a query parameter in the loadZonos.js script source. This timestamp ensures that you are loading the most recent version of the script, avoiding any cached versions.");if(i||!a||z.requested)return void d("[ZONOS - loadZonos] script is already loaded or requested","info");if(!o.zonosApiKey&&!z.cartId)return z.legacyCheckoutErrorHandler({message:"Zonos API key is required unless `tempCartUUID` is provided in url query params."}),void g("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(z.requested=!0,z.zonosApiKey=o.zonosApiKey,z.storeId=o.storeId,z.cartId){const o=await(async o=>{const{isDgsCartId:e,isLegacyCartId:n}=S(o);if(!n&&!e)return g("[ZONOS - loadZonos] invalid cart id"),null;const t=await O({cartId:o,retries:5});return d("[ZONOS - loadZonos] getting temp cart data","info",t),t?(window.Zonos.storeId=t.cartData.storeId,window.Zonos.zonosApiKey=t.cartData.credentialToken,{cartData:t.cartData,storeFavicon:t.storeFaviconUrl,storeId:t.cartData.storeId,storeLogo:t.storeLogoUrl,zonosApiKey:t.cartData.credentialToken}):(g("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process."),null)})(z.cartId);if(!o)throw z.legacyCheckoutErrorHandler({message:"Error getting cart data"}),new Error("Error getting cart data");z.cartData=o.cartData,z.legacyStoreLogo=o.storeLogo,z.legacyStoreFavicon=o.storeFavicon,z.storeId=o.storeId,z.zonosApiKey=o.zonosApiKey}if(!z.zonosApiKey)return void g('"zonosApiKey" is required to initialize Zonos');const l=await(async()=>{if(!window.location.search.includes("zonosTestMode=1")||!window.Zonos.zonosApiKey)return null;if(d("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return d("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:o,json:e}=await w("/api/get-test-public-credential");if(o.length||!e)return g("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",o),null;const n=e.publicCredential;return n?(d(`[ZONOS - loadZonos] Retrieve new test public token ${n}`,"info"),n):(g("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();if(l&&(d(`[ZONOS - loadZonos] Using test API key: ${l} for test mode`,"info"),z.zonosApiKey=l),!z.storeId)return d("[ZONOS - loadZonos] loading latest script since storeId is not provided."),void z.injectZonos({initConfig:o,vercelUrl:s,version:null});const p=z.storeId||o.storeId;d(`[ZONOS - loadZonos] Store ID: ${p}`,"info");const u=new URLSearchParams;u.set("storeId",p.toString()),window.location.search.includes("_enableStoreVersionPinned=1")&&u.set("_enableStoreVersionPinned","1");const{errors:m,json:f}=await w(`/api/get-store-version?${u.toString()}`);if(m.length||!f)return d("[ZONOS - loadZonos] Error getting store version, loading the latest version.","error"),void z.injectZonos({initConfig:o,vercelUrl:s,version:null});const{isDifferent:y,source:h,version:v}=f;if(d(`[ZONOS - loadZonos] Store version: ${v}, source: ${h}`,"info"),y){d(`[ZONOS - loadZonos] Updating saved store version to ${v}`,"info");const o={storeId:p,version:v};w(`/api/set-store-version?${u.toString()}`,{body:o,method:"POST"}).catch((o=>g("Unable to save store's vesrion",o)))}if(!i){const{currentLoadScriptUrl:e,isForceLoadVersionDomain:n,isWhiteListed:t}=(({loadScriptSrc:o})=>{if(!o)return{currentLoadScriptUrl:"",isForceLoadVersionDomain:!1,isWhiteListed:!1};const e=new URL(o).origin,n=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"].some((o=>e.includes(o))),t=["qa.js.zonos.com"].some((o=>e.includes(o)));return{currentLoadScriptUrl:e,isForceLoadVersionDomain:t,isWhiteListed:n}})({loadScriptSrc:a}),r=t&&!n?e:`${"alpha"===v?"alpha":`v${v}`}.js.zonos.com`,s=t&&!n?null:v;d("[ZONOS - loadZonos] injecting zonos script","info",{currentLoadScriptUrl:e,isForceLoadVersionDomain:n,isWhiteListed:t,loadUrl:r,loadVersion:s,version:v}),z.injectZonos({initConfig:o,vercelUrl:r,version:s})}},(void 0===window.Zonos||window.isZonosPreview)&&(window.Zonos=U)})();
|
package/dist/scripts/zonos.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";const e=performance.now(),o=e=>{if("string"==typeof e)return e;try{return JSON.stringify(e)}catch(o){if(e&&"function"==typeof e.toString){return e.toString()}return"Unable to stringify info"}},t=(t,n,...r)=>{var s,i;const{elapsedTimePretty:a}=(()=>{const o=performance.now()-e,t=o>1e3?`${(o/1e3).toFixed(2)}s`:`${o.toFixed(2)}ms`;return{elapsedTime:o,elapsedTimePretty:t}})(),l=[`(${a})`,...r];l.map(o).join(" ");if(!(!!(null===(s=window.Zonos)||void 0===s?void 0:s.debug)||!!window.location.search.match(/\?.*(&*)zonosDebug=1/)))return void("error"===n&&console.error(t,...l));let c=document.querySelector("iframe#zonos---debug-logging-iframe");c||(c=document.createElement("iframe"),c.id="zonos---debug-logging-iframe",c.style.display="none",c.style.opacity="0",c.style.position="absolute",c.style.top="-9999px",c.style.left="-9999px",c.style.width="1px",c.style.height="1px",c.style.border="none",c.style.overflow="hidden",c.style.visibility="hidden",document.body.appendChild(c));const d=(null===(i=c.contentWindow)||void 0===i?void 0:i.window.console)||window.console;switch(n){case"warn":d.warn(t,...l);break;case"info":d.info(t,...l);break;case"error":d.error(t,...l);break;default:d.groupCollapsed(t,...l),d.trace(),d.groupEnd()}},n=(e,...o)=>{t(e,"error",...o)},r=["jsdelivr","cdnjs","unpkg","vercel"],s="jsdelivr",i=e=>{const o=r.indexOf(e);return r[o+1]||null};function a(e,o){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&o.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)o.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(t[n[r]]=e[n[r]])}return t}"function"==typeof SuppressedError&&SuppressedError;const l=["cloudflare","vercel"],c=l[0],d={cloudflare:"https://route.elements.zonos.com",vercel:"https://route.js.zonos.com"},u=d[c],p=(e=c)=>{const o=l.indexOf(e),t=l[o+1];return t||null},m=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){return null}return null},w=async({response:e,shouldLog:o=!0,shouldThrow:t=!1})=>{try{const o=await e.text(),t=m(o);if(!t)throw new Error(`Failed to parse content: ${o}`);return t}catch(e){if(t)throw e;return o&&console.error(e),null}},h=async({basePathType:e,options:o,path:t})=>{let n;const r=window.Zonos.zonosQaUrlApi||d[e]||c,s=new URL(r+t),i=window.Zonos.cartId?`${window.location.hostname}-${window.Zonos.cartId}`:window.location.hostname;s.searchParams.set("zToken",(e=>{try{return btoa(e).replace(/=/g,"")}catch(o){return e.replace(/[^A-Za-z0-9]/g,"").split("").reverse().join("")}})(i));try{n=await fetch(s.toString(),o)}catch(e){if(e instanceof Error)return{baseUrl:r,errors:[{message:e.message,type:"unknown"}],json:null,response:null,zonosMode:null};return{baseUrl:r,errors:[{message:"Failed to fetch",type:"unknown"}],json:null,response:null,zonosMode:null}}const a=n.headers.get("Zonos-Mode"),l=window.Zonos.zonosQaUrl;if(!window.Zonos.modeAlerted&&a&&l&&(window.Zonos.modeAlerted=!0),n.ok){return{baseUrl:r,errors:[],json:await w({response:n}),response:n,zonosMode:a}}const u=n.status.toString();try{const e=await w({response:n,shouldThrow:!0});return{baseUrl:r,errors:[{message:JSON.stringify(e),type:u}],json:null,response:n,zonosMode:a}}catch(e){return{baseUrl:r,errors:[{message:`${u}: ${"Unknown error"}`,type:u}],json:null,response:null,zonosMode:a}}},y=async({basePathType:e,options:o,path:n})=>{var r,s;const i=n.startsWith("/api/bigcommerce")?"vercel":e,l=await h({basePathType:i,options:o,path:n}),{errors:c,response:w}=l,g=a(l,["errors","response"]),f=p(i),v=!!c.find((({type:e})=>"unknown"===e))||404===(null==w?void 0:w.status),b=f&&v;return v&&(async({endpoint:e,errors:o,metadata:n,shouldPostReleaseErrorReporting:r})=>{if(t("sendErrorLog","warn",e,n,o),r){const e=Number(window.Zonos.releaseDate);if((new Date).getTime()-e>36e5)return}const s="userAgentData"in window.navigator?window.navigator.userAgentData:null,i={endpoint:e,errors:o,href:window.location.href,metadata:Object.assign({appVersion:window.Zonos.version,domain:window.Zonos.domain,publicCredential:window.Zonos.zonosApiKey,userAgent:s&&s.brands.length>0?s:window.navigator.userAgent},n)};try{fetch(`${u}/api/zonos-elements/log-error`,{body:JSON.stringify(i),headers:{"Zonos-Referer":window.location.hostname},method:"POST"})}catch(e){const o=p();if(!o)return;fetch(`${d[o]}/api/zonos-elements/log-error`,{body:JSON.stringify(i),method:"POST"})}})({endpoint:d[i]+n,errors:c.map((({message:e})=>`API: ${e}`)),metadata:{currentBasePath:i,nextFallbackApiType:f,requestHeaders:null==o?void 0:o.headers,requestPayload:m(null===(r=null==o?void 0:o.body)||void 0===r?void 0:r.toString())||(null===(s=null==o?void 0:o.body)||void 0===s?void 0:s.toString()),status:null==w?void 0:w.status,statusText:null==w?void 0:w.statusText},shouldPostReleaseErrorReporting:!0}),b?(t(`=== "${n}" failed to fetch, trying next fallback ${f}`),y({basePathType:f,options:o,path:n})):Object.assign({errors:c,response:w},g)},g=async(e,o)=>{const n=a(o||{},[]),r=n.body?JSON.stringify(n.body):void 0,s=n.method||"GET",i=Object.assign({"Content-Type":"application/json","Zonos-Is-BigCommerce":window.Zonos.isBigCommerce.toString(),"Zonos-Referer":window.location.hostname,"Zonos-Version":window.Zonos.version,credentialtoken:window.Zonos.zonosApiKey||"Empty credential token from zonos-elements"},n.headers),l=Object.assign(Object.assign({},n),{body:"GET"===s?void 0:r,headers:i,method:s}),d=new URLSearchParams(window.location.search).get("useFallbackApi");return t(e,"info"),y({basePathType:d||c,options:l,path:e})},f=()=>{const e=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||e)return null;const o=(e=>{if(!e)return null;const o=new URL(e).searchParams.get("zonosQaUrl");return o?/[^a-zA-Z0-9-_]+/.test(o)?null:o:null})(window.location.href),n="https://v1.3.140.js.zonos.com";if(!o&&(n.includes("test.")||n.includes("test-")))return n;if(!o&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!o)return null;if("dev-elements"===o)return"https://dev.elements.zonos.com";const r=`https://${o}.preview.js.zonos.com`;return t(`[ZONOS-WARNING] using '${r}' for loading elements script`,"warn"),fetch(r).then((()=>{window.sessionStorage.removeItem("zonos--checkout-session-id"),window.sessionStorage.removeItem("zonos--client-secret")})).catch((()=>{alert(`[ZONOS-WARNING] '${r}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);const e=new URLSearchParams(window.location.search);e.delete("zonosQaUrl");const{pathname:o}=window.location,t=`${o}?${e.toString()}`;return window.history.replaceState(window.history.state,"",t),window.location.reload(),null})),r},v="https://js.stripe.com/v3",b=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,S="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";let z=null;const O=e=>(null!==z||(z=new Promise(((o,t)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&e&&console.warn(S),window.Stripe)o(window.Stripe);else try{let r=(()=>{const e=document.querySelectorAll(`script[src^="${v}"]`);for(let o=0;o<e.length;o++){const t=e[o];if(t&&b.test(t.src))return t}return null})();r&&e?console.warn(S):r||(r=(e=>{const o=document.createElement("script");o.src=`${v}`;const t=document.head||document.body;return t?(t.appendChild(o),o):(n("Expected document.body not to be null. Stripe.js requires a <body> element."),null)})()),null==r||r.addEventListener("load",(()=>{window.Stripe?o(window.Stripe):t(new Error("Stripe.js not available"))})),null==r||r.addEventListener("error",(()=>{t(new Error("Failed to load Stripe.js"))}))}catch(e){return void t(e)}else o(null)}))),z),Z=Promise.resolve().then((()=>O(null)));let j=!1;Z.catch((e=>{j||console.warn(e)}));const C=async({cartId:e,retries:o})=>{const n="1"===new URLSearchParams(window.location.search).get("zonosTestMode"),{errors:r,json:s}=await g("/api/zonos-elements/get-temp-cart",{body:{isTestMode:n,tempCartUUID:e},headers:{"Content-Type":"application/json"},method:"POST"}),i=!s||r.length;return i&&o?(t("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:o}),await new Promise((e=>setTimeout(e,500))),C({cartId:e,retries:o-1})):i?null:s},k=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,I=new RegExp(`^${k.source}$`),E=new RegExp(`^cart_${k.source}$`),A=async e=>{const{isDgsCartId:o,isLegacyCartId:r}=(e=>e?E.test(e)?{isDgsCartId:!0,isLegacyCartId:!1}:I.test(e)?{isDgsCartId:!1,isLegacyCartId:!0}:{isDgsCartId:!1,isLegacyCartId:!1}:{isDgsCartId:!1,isLegacyCartId:!1})(e);if(!r&&!o)return n("[ZONOS - loadZonos] invalid cart id"),null;const s=await C({cartId:e,retries:5});return t("[ZONOS - loadZonos] getting temp cart data","info",s),s?(window.Zonos.storeId=s.cartData.storeId,window.Zonos.zonosApiKey=s.cartData.credentialToken,{cartData:s.cartData,storeFavicon:s.storeFaviconUrl,storeId:s.cartData.storeId,storeLogo:s.storeLogoUrl,zonosApiKey:s.cartData.credentialToken}):(n("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process."),null)};var T;const N=(()=>{if("undefined"==typeof document)return null;const e=document.querySelector('script[src*="/zonos.js"]'),{currentLoadScriptUrl:o,isWhiteListed:t}=(({loadScriptSrc:e})=>{if(!e)return{currentLoadScriptUrl:"",isForceLoadVersionDomain:!1,isWhiteListed:!1};const o=new URL(e).origin,t=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"].some((e=>o.includes(e))),n=["qa.js.zonos.com"].some((e=>o.includes(e)));return{currentLoadScriptUrl:o,isForceLoadVersionDomain:n,isWhiteListed:t}})({loadScriptSrc:null==e?void 0:e.src});return t?o:null})(),$="https://v1.3.140.js.zonos.com",U=N||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.140",L="https://fonts.googleapis.com",P=/^https:\/\/fonts\.googleapis\.com/;class D{}T=D,D.doneInit=!1,D.debug="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/),D.zonosConversionTest="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/),D._paypalMockResponse=null,D.isBigCommerce=!1,D.releaseDate="1734113795652",D.isLegacyCheckout=!1,D.domain="undefined"!=typeof window?window.location!=window.parent.location&&document.referrer||document.location.hostname:"",D.showBaseForeign="undefined"!=typeof window&&window.location.search.includes("zonosShowBaseForeign"),D.isNpm=!0,D.zonosQaUrl=null,D.zonosQaUrlApi=null,D.version="v1.3.140",D.modeAlerted=!1,D.cartData=null,D.paypal=null,D.getCurrentTimestamp=()=>(new Date).getTime(),D.zonosController=null,D.init=async e=>{const{appearance:o,checkoutSettings:r,currencyConverter:s,helloSettings:i,onCountryChange:a,overrideCurrencyFormat:l,storeId:c,zonosApiKey:d}=e;if(T.cartId=new URLSearchParams(window.location.search).get("tempCartUUID"),T.doneInit)return;if(t(`====== ZONOS DEBUG MODE: on (${T.version}) ======`),T.zonosApiKey=d,T.storeId=c,T.isNpm){t("====== ZONOS LOADING FROM NPM ======");const o=f();if(o&&!window.isZonosPreview){t(`====== RE-INJECT "zonos.js" FROM PRVIEW: ${o} ======`,"info");const n=document.createElement("script");return n.src=`${o}/dist/scripts/zonos.js`,document.head.appendChild(n),n.addEventListener("load",(()=>{window.Zonos.isNpm=T.isNpm,window.Zonos.isBigCommerce=T.isBigCommerce,window.Zonos.isLegacyCheckout=T.isLegacyCheckout,window.Zonos.init(e)})),n.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${o}`)})),void(window.isZonosPreview=!0)}if(!d&&!T.cartId)return void n("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(!T.cartData&&T.cartId){t("Initialize cart data");const e=await A(T.cartId);if(!e)return void n("Failed to get cart data");T.cartData=e.cartData,T.zonosApiKey=e.zonosApiKey}const r=await(async()=>{if(!window.location.search.includes("zonosTestMode=1")||!window.Zonos.zonosApiKey)return null;if(t("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return t("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:e,json:o}=await g("/api/get-test-public-credential");if(e.length||!o)return n("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",e),null;const r=o.publicCredential;return r?(t(`[ZONOS - loadZonos] Retrieve new test public token ${r}`,"info"),r):(n("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();r&&(T.zonosApiKey=r)}const u=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");if(T.cartId&&T.cartData||!!u){t("Cart data or stripe client secret is available, inject hidden button and trigger checkout");const e=document.createElement("button");e.style.display="none",e.id="zonos--checkout-hidden-button",document.body.appendChild(e)}t("init zonos"),T.injectZonosCdn(),T.injectZonosCss(),T.injectFonts(),T.injectController({config:{appearance:o,checkoutSettings:r,currencyConverter:s,helloSettings:i,onCountryChange:a,overrideCurrencyFormat:l}}),T.doneInit=!0},D.displayCurrency=()=>{const e=document.querySelector("zonos-hello");e&&e.displayCurrency()},D.openHelloDialog=e=>{const o=document.querySelector("zonos-hello");o&&o.openHelloDialog(null==e||e)},D.showNotification=e=>{var o;null===(o=T.zonosController)||void 0===o||o.showNotification(e)},D.updateOrganizationName=e=>{var o;null===(o=T.zonosController)||void 0===o||o.updateOrganizationName(e)},D.disablePlaceOrderButtons=({autoEnable:e=!0,config:o,disable:t,placeOrderButtonSelector:n})=>{var r;if(!(null===(r=o.checkoutSettings)||void 0===r?void 0:r.disablePlaceOrderButtonActivation)&&n){const o=document.querySelectorAll(n),r=e=>{e.target.getAttribute("disabled")&&(e.preventDefault(),e.stopPropagation())};o.forEach((e=>{e.getAttribute("data-zonos-checkout-attached")||(t?(e.setAttribute("disabled","true"),e.addEventListener("click",r)):(e.removeAttribute("disabled"),e.removeEventListener("click",r)))})),e&&t&&setTimeout((()=>{o.forEach((e=>{e.removeAttribute("disabled"),e.removeEventListener("click",r)}))}),5e3)}},D.injectController=({config:e})=>{var o;if(document.querySelector("zonos-controller"))return;if(null===(o=e.checkoutSettings)||void 0===o?void 0:o.placeOrderButtonSelector){const o=e.checkoutSettings.placeOrderButtonSelector;T.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:o});new MutationObserver((()=>{T.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:o})})).observe(document.body,{childList:!0,subtree:!0})}const r=document.createElement("zonos-controller");r.config=e,r.zonosApiKey=T.zonosApiKey||"",r.addEventListener("stripeInitEvent",(async e=>{const{detail:o}=e;t("loading Stripe");const s=await(async(...e)=>{j=!0;const o=Date.now();return Z.then((t=>((e,o,t)=>{if(null===e)return null;const n=e.apply(void 0,o);return((e,o)=>{e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",startTime:o})})(n,t),n})(t,e,o)))})(o.publishableKey);s?(window.Zonos.stripe=s,r.initCheckoutElement(s)):n("API seems to be invalid or missing. Failed to load Stripe")})),document.body.appendChild(r),T.zonosController=r,t("Zonos controller injected!")},D.injectScript=({cdnType:e,isModule:o,theRestUrl:r})=>{const s=`${T.getZonosUrl(e)}/${r}`;if(document.querySelector(`script[src="${s}"]`))return void t(`Zonos script "${s}" already exists in the document`,"warn");const a=document.head||document.body,l=document.createElement("script");o?l.type="module":l.noModule=!0,l.src=s,l.crossOrigin="anonymous",l.onerror=()=>{n(`Failed to load ${l.src}`);const t=i(e);t&&T.injectScript({cdnType:t,isModule:o,theRestUrl:r})},a.appendChild(l)},D.getZonosUrl=e=>{const o=()=>{switch(e){case"jsdelivr":return U;case"unpkg":return"https://unpkg.com/@zonos/elements@1.3.140";case"cdnjs":return"https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.140";case"vercel":return $}};if(T.isNpm){return f()||o()}return o()},D.injectZonosCdn=()=>{T.injectScript({cdnType:s,isModule:!0,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"}),T.injectScript({cdnType:s,isModule:!1,theRestUrl:"dist/zonos-elements/zonos-elements.js"}),t("Zonos cdn script injected!")},D.injectStylesheet=({cdnType:e,theRestUrl:o})=>{const t=T.getZonosUrl(e),r=document.head||document.body,s=document.createElement("link");s.rel="preconnect",s.href=`${$}/`,r.appendChild(s);const a=document.createElement("link");a.rel="stylesheet",a.href=`${t}/${o}`,a.onerror=()=>{n(`Failed to load ${a.href}`);const t=i(e);t&&T.injectStylesheet({cdnType:t,theRestUrl:o})},r.appendChild(a)},D.injectZonosCss=()=>{document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')?t("Zonos style links already injected","warn"):(T.injectStylesheet({cdnType:s,theRestUrl:"dist/zonos-elements/zonos-elements.css"}),t("Zonos style css injected!"))},D.injectFonts=()=>{if((()=>{const e=document.querySelectorAll(`link[rel="stylesheet"][href^="${L}"]`);for(let o=0;o<e.length;o++){const t=e[o];if(t&&!P.test(t.href))return t}return null})())return void t("Inter font already injected","warn");const e=document.head||document.body,o=document.createElement("link");o.rel="preconnect",o.href=L,e.appendChild(o);const n=document.createElement("link");n.rel="stylesheet",n.href=`${L}/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap`,e.appendChild(n),t("Zonos font injected!")},D.setupGoogleFont=e=>{var o;null===(o=T.zonosController)||void 0===o||o.setupGoogleFont(e)},D.injectSupportGoogleFont=e=>{var o;t(`[FONT] injecting ${e}`);const n=null===(o=e.match(/family=(.*?):/))||void 0===o?void 0:o[1],r=document.head||document.body;if(!document.querySelector(`link[rel="preconnect"][href^="${L}"]`)){const e=document.createElement("link");e.rel="preconnect",e.href=L,r.appendChild(e)}if(document.querySelector(`link[rel="stylesheet"][href="${e}"]`))return void t(`[FONT] ${n} font already injected`,"warn");const s=document.createElement("link");s.rel="stylesheet",s.href=e,r.appendChild(s),t(`[FONT] ${n} font injected!`)},window.Zonos&&window.Zonos.doneInit||(window.Zonos=D)})();
|
|
1
|
+
(function(){"use strict";const e=performance.now(),o=e=>{if("string"==typeof e)return e;try{return JSON.stringify(e)}catch(o){if(e&&"function"==typeof e.toString){return e.toString()}return"Unable to stringify info"}},t=(t,n,...r)=>{var s,i;const{elapsedTimePretty:a}=(()=>{const o=performance.now()-e,t=o>1e3?`${(o/1e3).toFixed(2)}s`:`${o.toFixed(2)}ms`;return{elapsedTime:o,elapsedTimePretty:t}})(),c=[`(${a})`,...r];c.map(o).join(" ");if(!(!!(null===(s=window.Zonos)||void 0===s?void 0:s.debug)||!!window.location.search.match(/\?.*(&*)zonosDebug=1/)))return void("error"===n&&console.error(t,...c));let l=document.querySelector("iframe#zonos---debug-logging-iframe");l||(l=document.createElement("iframe"),l.id="zonos---debug-logging-iframe",l.style.display="none",l.style.opacity="0",l.style.position="absolute",l.style.top="-9999px",l.style.left="-9999px",l.style.width="1px",l.style.height="1px",l.style.border="none",l.style.overflow="hidden",l.style.visibility="hidden",document.body.appendChild(l));const d=(null===(i=l.contentWindow)||void 0===i?void 0:i.window.console)||window.console;switch(n){case"warn":d.warn(t,...c);break;case"info":d.info(t,...c);break;case"error":d.error(t,...c);break;default:d.groupCollapsed(t,...c),d.trace(),d.groupEnd()}},n=(e,...o)=>{t(e,"error",...o)},r=["jsdelivr","cdnjs","unpkg","vercel"],s="jsdelivr",i=e=>{const o=r.indexOf(e);return r[o+1]||null};function a(e,o){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&o.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)o.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(t[n[r]]=e[n[r]])}return t}"function"==typeof SuppressedError&&SuppressedError;const c=["cloudflare","vercel"],l=c[0],d={cloudflare:"https://route.elements.zonos.com",vercel:"https://route.js.zonos.com"},u=d[l],p=(e=l)=>{const o=c.indexOf(e),t=c[o+1];return t||null},m=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){return null}return null},w=async({response:e,shouldLog:o=!0,shouldThrow:t=!1})=>{try{const o=await e.text(),t=m(o);if(!t)throw new Error(`Failed to parse content: ${o}`);return t}catch(e){if(t)throw e;return o&&console.error(e),null}},h=async({basePathType:e,options:o,path:t})=>{let n;const r=window.Zonos.zonosQaUrlApi||d[e]||l,s=new URL(r+t),i=window.Zonos.cartId?`${window.location.hostname}-${window.Zonos.cartId}`:window.location.hostname;s.searchParams.set("zToken",(e=>{try{return btoa(e).replace(/=/g,"")}catch(o){return e.replace(/[^A-Za-z0-9]/g,"").split("").reverse().join("")}})(i));try{n=await fetch(s.toString(),o)}catch(e){if(e instanceof Error)return{baseUrl:r,errors:[{message:e.message,type:"unknown"}],json:null,response:null,zonosMode:null};return{baseUrl:r,errors:[{message:"Failed to fetch",type:"unknown"}],json:null,response:null,zonosMode:null}}const a=n.headers.get("Zonos-Mode"),c=window.Zonos.zonosQaUrl;if(!window.Zonos.modeAlerted&&a&&c&&(window.Zonos.modeAlerted=!0),n.ok){return{baseUrl:r,errors:[],json:await w({response:n}),response:n,zonosMode:a}}const u=n.status.toString();try{const e=await w({response:n,shouldThrow:!0});return{baseUrl:r,errors:[{message:JSON.stringify(e),type:u}],json:null,response:n,zonosMode:a}}catch(e){return{baseUrl:r,errors:[{message:`${u}: ${"Unknown error"}`,type:u}],json:null,response:null,zonosMode:a}}},y=async({basePathType:e,options:o,path:n})=>{var r,s;const i=n.startsWith("/api/bigcommerce")?"vercel":e,c=await h({basePathType:i,options:o,path:n}),{errors:l,response:w}=c,f=a(c,["errors","response"]),g=p(i),v=!!l.find((({type:e})=>"unknown"===e))||404===(null==w?void 0:w.status),b=g&&v;return v&&(async({endpoint:e,errors:o,metadata:n,shouldPostReleaseErrorReporting:r})=>{if(t("sendErrorLog","warn",e,n,o),r){const e=Number(window.Zonos.releaseDate);if((new Date).getTime()-e>36e5)return}const s="userAgentData"in window.navigator?window.navigator.userAgentData:null,i={endpoint:e,errors:o,href:window.location.href,metadata:Object.assign({appVersion:window.Zonos.version,domain:window.Zonos.domain,publicCredential:window.Zonos.zonosApiKey,userAgent:s&&s.brands.length>0?s:window.navigator.userAgent},n)};try{fetch(`${u}/api/zonos-elements/log-error`,{body:JSON.stringify(i),headers:{"Zonos-Referer":window.location.hostname},method:"POST"})}catch(e){const o=p();if(!o)return;fetch(`${d[o]}/api/zonos-elements/log-error`,{body:JSON.stringify(i),method:"POST"})}})({endpoint:d[i]+n,errors:l.map((({message:e})=>`API: ${e}`)),metadata:{currentBasePath:i,nextFallbackApiType:g,requestHeaders:null==o?void 0:o.headers,requestPayload:m(null===(r=null==o?void 0:o.body)||void 0===r?void 0:r.toString())||(null===(s=null==o?void 0:o.body)||void 0===s?void 0:s.toString()),status:null==w?void 0:w.status,statusText:null==w?void 0:w.statusText},shouldPostReleaseErrorReporting:!0}),b?(t(`=== "${n}" failed to fetch, trying next fallback ${g}`),y({basePathType:g,options:o,path:n})):Object.assign({errors:l,response:w},f)},f=async(e,o)=>{const n=a(o||{},[]),r=n.body?JSON.stringify(n.body):void 0,s=n.method||"GET",i=Object.assign({"Content-Type":"application/json","Zonos-Is-BigCommerce":window.Zonos.isBigCommerce.toString(),"Zonos-Referer":window.location.hostname,"Zonos-Version":window.Zonos.version,credentialtoken:window.Zonos.zonosApiKey||"Empty credential token from zonos-elements"},n.headers),c=Object.assign(Object.assign({},n),{body:"GET"===s?void 0:r,headers:i,method:s}),d=new URLSearchParams(window.location.search).get("useFallbackApi");return t(e,"info"),y({basePathType:d||l,options:c,path:e})},g=()=>{const e=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||e)return null;const o=(e=>{if(!e)return null;const o=new URL(e).searchParams.get("zonosQaUrl");return o?/[^a-zA-Z0-9-_]+/.test(o)?null:o:null})(window.location.href),n="https://v1.3.141.js.zonos.com";if(!o&&(n.includes("test.")||n.includes("test-")))return n;if(!o&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!o)return null;if("dev-elements"===o)return"https://dev.elements.zonos.com";const r=`https://${o}.preview.js.zonos.com`;return t(`[ZONOS-WARNING] using '${r}' for loading elements script`,"warn"),fetch(r).then((()=>{window.sessionStorage.removeItem("zonos--checkout-session-id"),window.sessionStorage.removeItem("zonos--client-secret")})).catch((()=>{alert(`[ZONOS-WARNING] '${r}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);const e=new URLSearchParams(window.location.search);e.delete("zonosQaUrl");const{pathname:o}=window.location,t=`${o}?${e.toString()}`;return window.history.replaceState(window.history.state,"",t),window.location.reload(),null})),r},v="https://js.stripe.com/v3",b=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,S="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";let z=null;const j=e=>(null!==z||(z=new Promise(((o,t)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&e&&console.warn(S),window.Stripe)o(window.Stripe);else try{let r=(()=>{const e=document.querySelectorAll(`script[src^="${v}"]`);for(let o=0;o<e.length;o++){const t=e[o];if(t&&b.test(t.src))return t}return null})();r&&e?console.warn(S):r||(r=(e=>{const o=document.createElement("script");o.src=`${v}`;const t=document.head||document.body;return t?(t.appendChild(o),o):(n("Expected document.body not to be null. Stripe.js requires a <body> element."),null)})()),null==r||r.addEventListener("load",(()=>{window.Stripe?o(window.Stripe):t(new Error("Stripe.js not available"))})),null==r||r.addEventListener("error",(()=>{t(new Error("Failed to load Stripe.js"))}))}catch(e){return void t(e)}else o(null)}))),z),C=Promise.resolve().then((()=>j(null)));let O=!1;C.catch((e=>{O||console.warn(e)}));const Z=async({cartId:e,retries:o})=>{const n="1"===new URLSearchParams(window.location.search).get("zonosTestMode"),{errors:r,json:s}=await f("/api/zonos-elements/get-temp-cart",{body:{isTestMode:n,tempCartUUID:e},headers:{"Content-Type":"application/json"},method:"POST"}),i=!s||r.length;return i&&o?(t("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:o}),await new Promise((e=>setTimeout(e,500))),Z({cartId:e,retries:o-1})):i?null:s},k=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,I=new RegExp(`^${k.source}$`),E=new RegExp(`^cart_${k.source}$`),A=async e=>{const{isDgsCartId:o,isLegacyCartId:r}=(e=>e?E.test(e)?{isDgsCartId:!0,isLegacyCartId:!1}:I.test(e)?{isDgsCartId:!1,isLegacyCartId:!0}:{isDgsCartId:!1,isLegacyCartId:!1}:{isDgsCartId:!1,isLegacyCartId:!1})(e);if(!r&&!o)return n("[ZONOS - loadZonos] invalid cart id"),null;const s=await Z({cartId:e,retries:5});return t("[ZONOS - loadZonos] getting temp cart data","info",s),s?(window.Zonos.storeId=s.cartData.storeId,window.Zonos.zonosApiKey=s.cartData.credentialToken,{cartData:s.cartData,storeFavicon:s.storeFaviconUrl,storeId:s.cartData.storeId,storeLogo:s.storeLogoUrl,zonosApiKey:s.cartData.credentialToken}):(n("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process."),null)};var L;const T=(()=>{if("undefined"==typeof document)return null;const e=document.querySelector('script[src*="/zonos.js"]'),{currentLoadScriptUrl:o,isWhiteListed:t}=(({loadScriptSrc:e})=>{if(!e)return{currentLoadScriptUrl:"",isForceLoadVersionDomain:!1,isWhiteListed:!1};const o=new URL(e).origin,t=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"].some((e=>o.includes(e))),n=["qa.js.zonos.com"].some((e=>o.includes(e)));return{currentLoadScriptUrl:o,isForceLoadVersionDomain:n,isWhiteListed:t}})({loadScriptSrc:null==e?void 0:e.src});return t?o:null})(),N="https://v1.3.141.js.zonos.com",$=T||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.141",U="https://fonts.googleapis.com",P=/^https:\/\/fonts\.googleapis\.com/;class D{}L=D,D.doneInit=!1,D.debug="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/),D.zonosConversionTest="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/),D._paypalMockResponse=null,D.isBigCommerce=!1,D.releaseDate="1734130633682",D.isLegacyCheckout=!1,D.domain="undefined"!=typeof window?window.location!=window.parent.location&&document.referrer||document.location.hostname:"",D.showBaseForeign="undefined"!=typeof window&&window.location.search.includes("zonosShowBaseForeign"),D.isNpm=!0,D.zonosQaUrl=null,D.zonosQaUrlApi=null,D.version="v1.3.141",D.modeAlerted=!1,D.cartData=null,D.paypal=null,D.getCurrentTimestamp=()=>(new Date).getTime(),D.zonosController=null,D.init=async e=>{const{appearance:o,checkoutSettings:r,currencyConverter:s,helloSettings:i,onCountryChange:a,overrideCurrencyFormat:c,storeId:l,zonosApiKey:d}=e;if(L.cartId=new URLSearchParams(window.location.search).get("tempCartUUID"),L.doneInit)return;if(t(`====== ZONOS DEBUG MODE: on (${L.version}) ======`),L.zonosApiKey=d,L.storeId=l,L.isNpm){t("====== ZONOS LOADING FROM NPM ======");const o=g();if(o&&!window.isZonosPreview){t(`====== RE-INJECT "zonos.js" FROM PRVIEW: ${o} ======`,"info");const n=document.createElement("script");return n.src=`${o}/dist/scripts/zonos.js`,document.head.appendChild(n),n.addEventListener("load",(()=>{window.Zonos.isNpm=L.isNpm,window.Zonos.isBigCommerce=L.isBigCommerce,window.Zonos.isLegacyCheckout=L.isLegacyCheckout,window.Zonos.init(e)})),n.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${o}`)})),void(window.isZonosPreview=!0)}if(!d&&!L.cartId)return void n("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(!L.cartData&&L.cartId){t("Initialize cart data");const e=await A(L.cartId);if(!e)return void n("Failed to get cart data");L.cartData=e.cartData,L.zonosApiKey=e.zonosApiKey}const r=await(async()=>{if(!window.location.search.includes("zonosTestMode=1")||!window.Zonos.zonosApiKey)return null;if(t("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return t("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:e,json:o}=await f("/api/get-test-public-credential");if(e.length||!o)return n("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",e),null;const r=o.publicCredential;return r?(t(`[ZONOS - loadZonos] Retrieve new test public token ${r}`,"info"),r):(n("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();r&&(L.zonosApiKey=r)}const u=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");if(L.cartId&&L.cartData||!!u){t("Cart data or stripe client secret is available, inject hidden button and trigger checkout");const e=document.createElement("button");e.style.display="none",e.id="zonos--checkout-hidden-button",document.body.appendChild(e)}t("init zonos"),L.injectCustomScriptForHostedCheckout(),L.injectZonosCdn(),L.injectZonosCss(),L.injectFonts(),L.injectController({config:{appearance:o,checkoutSettings:r,currencyConverter:s,helloSettings:i,onCountryChange:a,overrideCurrencyFormat:c}}),L.doneInit=!0},D.injectCustomScriptForHostedCheckout=()=>{const e=L.cartData,o=(null==e?void 0:e.metadata)||[],n=o.find((e=>"customHeaderScript"===e.key)),r=o.find((e=>"customFooterScript"===e.key));if(window.Zonos.isLegacyCheckout&&(n||r)){if(n){t("Injecting custom header script");const e=document.createElement("script");e.textContent=n.value,document.head.appendChild(e)}if(r){t("Injecting custom footer script");const e=document.createElement("script");e.textContent=r.value,document.body.appendChild(e)}}else t("Skip injecting custom script for hosted checkout","info",{footerScript:r,headerScript:n,isLegacyCheckout:window.Zonos.isLegacyCheckout})},D.displayCurrency=()=>{const e=document.querySelector("zonos-hello");e&&e.displayCurrency()},D.openHelloDialog=e=>{const o=document.querySelector("zonos-hello");o&&o.openHelloDialog(null==e||e)},D.showNotification=e=>{var o;null===(o=L.zonosController)||void 0===o||o.showNotification(e)},D.updateOrganizationName=e=>{var o;null===(o=L.zonosController)||void 0===o||o.updateOrganizationName(e)},D.disablePlaceOrderButtons=({autoEnable:e=!0,config:o,disable:t,placeOrderButtonSelector:n})=>{var r;if(!(null===(r=o.checkoutSettings)||void 0===r?void 0:r.disablePlaceOrderButtonActivation)&&n){const o=document.querySelectorAll(n),r=e=>{e.target.getAttribute("disabled")&&(e.preventDefault(),e.stopPropagation())};o.forEach((e=>{e.getAttribute("data-zonos-checkout-attached")||(t?(e.setAttribute("disabled","true"),e.addEventListener("click",r)):(e.removeAttribute("disabled"),e.removeEventListener("click",r)))})),e&&t&&setTimeout((()=>{o.forEach((e=>{e.removeAttribute("disabled"),e.removeEventListener("click",r)}))}),5e3)}},D.injectController=({config:e})=>{var o;if(document.querySelector("zonos-controller"))return;if(null===(o=e.checkoutSettings)||void 0===o?void 0:o.placeOrderButtonSelector){const o=e.checkoutSettings.placeOrderButtonSelector;L.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:o});new MutationObserver((()=>{L.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:o})})).observe(document.body,{childList:!0,subtree:!0})}const r=document.createElement("zonos-controller");r.config=e,r.zonosApiKey=L.zonosApiKey||"",r.addEventListener("stripeInitEvent",(async e=>{const{detail:o}=e;t("loading Stripe");const s=await(async(...e)=>{O=!0;const o=Date.now();return C.then((t=>((e,o,t)=>{if(null===e)return null;const n=e.apply(void 0,o);return((e,o)=>{e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",startTime:o})})(n,t),n})(t,e,o)))})(o.publishableKey);s?(window.Zonos.stripe=s,r.initCheckoutElement(s)):n("API seems to be invalid or missing. Failed to load Stripe")})),document.body.appendChild(r),L.zonosController=r,t("Zonos controller injected!")},D.injectScript=({cdnType:e,isModule:o,theRestUrl:r})=>{const s=`${L.getZonosUrl(e)}/${r}`;if(document.querySelector(`script[src="${s}"]`))return void t(`Zonos script "${s}" already exists in the document`,"warn");const a=document.head||document.body,c=document.createElement("script");o?c.type="module":c.noModule=!0,c.src=s,c.crossOrigin="anonymous",c.onerror=()=>{n(`Failed to load ${c.src}`);const t=i(e);t&&L.injectScript({cdnType:t,isModule:o,theRestUrl:r})},a.appendChild(c)},D.getZonosUrl=e=>{const o=()=>{switch(e){case"jsdelivr":return $;case"unpkg":return"https://unpkg.com/@zonos/elements@1.3.141";case"cdnjs":return"https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.141";case"vercel":return N}};if(L.isNpm){return g()||o()}return o()},D.injectZonosCdn=()=>{L.injectScript({cdnType:s,isModule:!0,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"}),L.injectScript({cdnType:s,isModule:!1,theRestUrl:"dist/zonos-elements/zonos-elements.js"}),t("Zonos cdn script injected!")},D.injectStylesheet=({cdnType:e,theRestUrl:o})=>{const t=L.getZonosUrl(e),r=document.head||document.body,s=document.createElement("link");s.rel="preconnect",s.href=`${N}/`,r.appendChild(s);const a=document.createElement("link");a.rel="stylesheet",a.href=`${t}/${o}`,a.onerror=()=>{n(`Failed to load ${a.href}`);const t=i(e);t&&L.injectStylesheet({cdnType:t,theRestUrl:o})},r.appendChild(a)},D.injectZonosCss=()=>{document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')?t("Zonos style links already injected","warn"):(L.injectStylesheet({cdnType:s,theRestUrl:"dist/zonos-elements/zonos-elements.css"}),t("Zonos style css injected!"))},D.injectFonts=()=>{if((()=>{const e=document.querySelectorAll(`link[rel="stylesheet"][href^="${U}"]`);for(let o=0;o<e.length;o++){const t=e[o];if(t&&!P.test(t.href))return t}return null})())return void t("Inter font already injected","warn");const e=document.head||document.body,o=document.createElement("link");o.rel="preconnect",o.href=U,e.appendChild(o);const n=document.createElement("link");n.rel="stylesheet",n.href=`${U}/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap`,e.appendChild(n),t("Zonos font injected!")},D.setupGoogleFont=e=>{var o;null===(o=L.zonosController)||void 0===o||o.setupGoogleFont(e)},D.injectSupportGoogleFont=e=>{var o;t(`[FONT] injecting ${e}`);const n=null===(o=e.match(/family=(.*?):/))||void 0===o?void 0:o[1],r=document.head||document.body;if(!document.querySelector(`link[rel="preconnect"][href^="${U}"]`)){const e=document.createElement("link");e.rel="preconnect",e.href=U,r.appendChild(e)}if(document.querySelector(`link[rel="stylesheet"][href="${e}"]`))return void t(`[FONT] ${n} font already injected`,"warn");const s=document.createElement("link");s.rel="stylesheet",s.href=e,r.appendChild(s),t(`[FONT] ${n} font injected!`)},window.Zonos&&window.Zonos.doneInit||(window.Zonos=D)})();
|
|
@@ -255,6 +255,7 @@ export declare abstract class Zonos {
|
|
|
255
255
|
static cartId: string | null;
|
|
256
256
|
private static zonosController;
|
|
257
257
|
static init: (params: LoadZonosParams) => Promise<void>;
|
|
258
|
+
private static injectCustomScriptForHostedCheckout;
|
|
258
259
|
static displayCurrency: () => void;
|
|
259
260
|
static openHelloDialog: (value?: boolean) => void;
|
|
260
261
|
static showNotification: (notification: NotificationInit) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg color="var(--zonos-elements-
|
|
1
|
+
<svg color="var(--zonos-elements-gray-800)" fill="none" height="24" viewBox="0 0 24 24" width="24" xmlns="https://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10Z" data-is-secondary-color="true" fill="var(--zonos-elements-gray-200)" fill-rule="evenodd"></path><path clip-rule="evenodd" d="M8.293 8.293a1 1 0 0 1 1.414 0L12 10.586l2.293-2.293a1 1 0 1 1 1.414 1.414L13.414 12l2.293 2.293a1 1 0 0 1-1.414 1.414L12 13.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L10.586 12 8.293 9.707a1 1 0 0 1 0-1.414Z" fill="currentColor" fill-rule="evenodd"></path></svg>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{l as e,h as n,a as o}from"./p-860e46ab.js";import{s as t,c as s}from"./p-b7307c61.js";export{c as checkoutHiddenBtnSelector,d as domesticRedirectedBtnSelector}from"./p-b7307c61.js";const r=["jsdelivr","cdnjs","unpkg","vercel"],i="jsdelivr",l=e=>{const n=r.indexOf(e);return r[n+1]||null},a=()=>{const n=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||n)return null;const o=(e=>{if(!e)return null;const n=new URL(e).searchParams.get("zonosQaUrl");return n?/[^a-zA-Z0-9-_]+/.test(n)?null:n:null})(window.location.href),t="https://v1.3.140.js.zonos.com";if(!o&&(t.includes("test.")||t.includes("test-")))return t;if(!o&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!o)return null;if("dev-elements"===o)return"https://dev.elements.zonos.com";const s=`https://${o}.preview.js.zonos.com`;return e(`[ZONOS-WARNING] using '${s}' for loading elements script`,"warn"),fetch(s).then((()=>{window.sessionStorage.removeItem("zonos--checkout-session-id"),window.sessionStorage.removeItem("zonos--client-secret")})).catch((()=>{alert(`[ZONOS-WARNING] '${s}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);const e=new URLSearchParams(window.location.search);e.delete("zonosQaUrl");const{pathname:n}=window.location,o=`${n}?${e.toString()}`;return window.history.replaceState(window.history.state,"",o),window.location.reload(),null})),s},u="https://js.stripe.com/v3",m=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,w="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";let p=null;const f=Promise.resolve().then((()=>{return e=null,null!==p||(p=new Promise(((n,t)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&e&&console.warn(w),window.Stripe)n(window.Stripe);else try{let s=(()=>{const e=document.querySelectorAll(`script[src^="${u}"]`);for(let n=0;n<e.length;n++){const o=e[n];if(o&&m.test(o.src))return o}return null})();s&&e?console.warn(w):s||(s=(e=>{const n=e&&!e.advancedFraudSignals?"?advancedFraudSignals=false":"",t=document.createElement("script");t.src=`${u}${n}`;const s=document.head||document.body;return s?(s.appendChild(t),t):(o("Expected document.body not to be null. Stripe.js requires a <body> element."),null)})(e)),null==s||s.addEventListener("load",(()=>{window.Stripe?n(window.Stripe):t(new Error("Stripe.js not available"))})),null==s||s.addEventListener("error",(()=>{t(new Error("Failed to load Stripe.js"))}))}catch(e){return void t(e)}else n(null)}))),p;var e}));let h=!1;var v;f.catch((e=>{h||console.warn(e)}));const y=(()=>{if("undefined"==typeof document)return null;const e=document.querySelector('script[src*="/zonos.js"]'),{currentLoadScriptUrl:n,isWhiteListed:o}=(({loadScriptSrc:e})=>{if(!e)return{currentLoadScriptUrl:"",isForceLoadVersionDomain:!1,isWhiteListed:!1};const n=new URL(e).origin,o=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"].some((e=>n.includes(e))),t=["qa.js.zonos.com"].some((e=>n.includes(e)));return{currentLoadScriptUrl:n,isForceLoadVersionDomain:t,isWhiteListed:o}})({loadScriptSrc:null==e?void 0:e.src});return o?n:null})(),z="https://v1.3.140.js.zonos.com",j=y||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.140",g="https://fonts.googleapis.com",S=/^https:\/\/fonts\.googleapis\.com/;class O{}v=O,O.doneInit=!1,O.debug="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/),O.zonosConversionTest="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/),O._paypalMockResponse=null,O.isBigCommerce=!1,O.releaseDate="1734113749964",O.isLegacyCheckout=!1,O.domain="undefined"!=typeof window?window.location!=window.parent.location&&document.referrer||document.location.hostname:"",O.showBaseForeign="undefined"!=typeof window&&window.location.search.includes("zonosShowBaseForeign"),O.isNpm=!0,O.zonosQaUrl=null,O.zonosQaUrlApi=null,O.version="v1.3.140",O.modeAlerted=!1,O.cartData=null,O.paypal=null,O.getCurrentTimestamp=()=>(new Date).getTime(),O.zonosController=null,O.init=async r=>{const{appearance:i,checkoutSettings:c,currencyConverter:l,helloSettings:d,onCountryChange:u,overrideCurrencyFormat:m,storeId:w,zonosApiKey:p}=r;if(v.cartId=new URLSearchParams(window.location.search).get("tempCartUUID"),v.doneInit)return;if(e(`====== ZONOS DEBUG MODE: on (${v.version}) ======`),v.zonosApiKey=p,v.storeId=w,v.isNpm){e("====== ZONOS LOADING FROM NPM ======");const s=a();if(s&&!window.isZonosPreview){e(`====== RE-INJECT "zonos.js" FROM PRVIEW: ${s} ======`,"info");const n=document.createElement("script");return n.src=`${s}/dist/scripts/zonos.js`,document.head.appendChild(n),n.addEventListener("load",(()=>{window.Zonos.isNpm=v.isNpm,window.Zonos.isBigCommerce=v.isBigCommerce,window.Zonos.isLegacyCheckout=v.isLegacyCheckout,window.Zonos.init(r)})),n.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${s}`)})),void(window.isZonosPreview=!0)}if(!p&&!v.cartId)return void o("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(!v.cartData&&v.cartId){e("Initialize cart data");const n=await t(v.cartId);if(!n)return void o("Failed to get cart data");v.cartData=n.cartData,v.zonosApiKey=n.zonosApiKey}const i=await(async()=>{if(!window.location.search.includes("zonosTestMode=1")||!window.Zonos.zonosApiKey)return null;if(e("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return e("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:t,json:s}=await n("/api/get-test-public-credential");if(t.length||!s)return o("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",t),null;const r=s.publicCredential;return r?(e(`[ZONOS - loadZonos] Retrieve new test public token ${r}`,"info"),r):(o("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();i&&(v.zonosApiKey=i)}const f=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");if(v.cartId&&v.cartData||f){e("Cart data or stripe client secret is available, inject hidden button and trigger checkout");const n=document.createElement("button");n.style.display="none",n.id=`${s}`,document.body.appendChild(n)}e("init zonos"),v.injectZonosCdn(),v.injectZonosCss(),v.injectFonts(),v.injectController({config:{appearance:i,checkoutSettings:c,currencyConverter:l,helloSettings:d,onCountryChange:u,overrideCurrencyFormat:m}}),v.doneInit=!0},O.displayCurrency=()=>{const e=document.querySelector("zonos-hello");e&&e.displayCurrency()},O.openHelloDialog=e=>{const n=document.querySelector("zonos-hello");n&&n.openHelloDialog(null==e||e)},O.showNotification=e=>{var n;null===(n=v.zonosController)||void 0===n||n.showNotification(e)},O.updateOrganizationName=e=>{var n;null===(n=v.zonosController)||void 0===n||n.updateOrganizationName(e)},O.disablePlaceOrderButtons=({autoEnable:e=!0,config:n,disable:o,placeOrderButtonSelector:t})=>{var s;if(!(null===(s=n.checkoutSettings)||void 0===s?void 0:s.disablePlaceOrderButtonActivation)&&t){const n=document.querySelectorAll(t),s=e=>{e.target.getAttribute("disabled")&&(e.preventDefault(),e.stopPropagation())};n.forEach((e=>{e.getAttribute("data-zonos-checkout-attached")||(o?(e.setAttribute("disabled","true"),e.addEventListener("click",s)):(e.removeAttribute("disabled"),e.removeEventListener("click",s)))})),e&&o&&setTimeout((()=>{n.forEach((e=>{e.removeAttribute("disabled"),e.removeEventListener("click",s)}))}),5e3)}},O.injectController=({config:n})=>{var t;if(document.querySelector("zonos-controller"))return;if(null===(t=n.checkoutSettings)||void 0===t?void 0:t.placeOrderButtonSelector){const e=n.checkoutSettings.placeOrderButtonSelector;v.disablePlaceOrderButtons({config:n,disable:!0,placeOrderButtonSelector:e}),new MutationObserver((()=>{v.disablePlaceOrderButtons({config:n,disable:!0,placeOrderButtonSelector:e})})).observe(document.body,{childList:!0,subtree:!0})}const s=document.createElement("zonos-controller");s.config=n,s.zonosApiKey=v.zonosApiKey||"",s.addEventListener("stripeInitEvent",(async n=>{const{detail:t}=n;e("loading Stripe");const r=await(async(...e)=>{h=!0;const n=Date.now();return f.then((o=>((e,n,o)=>{if(null===e)return null;const t=e.apply(void 0,n);return((e,n)=>{e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",startTime:n})})(t,o),t})(o,e,n)))})(t.publishableKey);r?(window.Zonos.stripe=r,s.initCheckoutElement(r)):o("API seems to be invalid or missing. Failed to load Stripe")})),document.body.appendChild(s),v.zonosController=s,e("Zonos controller injected!")},O.injectScript=({cdnType:n,isModule:t,theRestUrl:s})=>{const r=`${v.getZonosUrl(n)}/${s}`;if(document.querySelector(`script[src="${r}"]`))return void e(`Zonos script "${r}" already exists in the document`,"warn");const i=document.head||document.body,c=document.createElement("script");t?c.type="module":c.noModule=!0,c.src=r,c.crossOrigin="anonymous",c.onerror=()=>{o(`Failed to load ${c.src}`);const e=l(n);e&&v.injectScript({cdnType:e,isModule:t,theRestUrl:s})},i.appendChild(c)},O.getZonosUrl=e=>{const n=()=>{switch(e){case"jsdelivr":return j;case"unpkg":return"https://unpkg.com/@zonos/elements@1.3.140";case"cdnjs":return"https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.140";case"vercel":return z}};return v.isNpm&&a()||n()},O.injectZonosCdn=()=>{v.injectScript({cdnType:i,isModule:!0,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"}),v.injectScript({cdnType:i,isModule:!1,theRestUrl:"dist/zonos-elements/zonos-elements.js"}),e("Zonos cdn script injected!")},O.injectStylesheet=({cdnType:e,theRestUrl:n})=>{const t=v.getZonosUrl(e),s=document.head||document.body,r=document.createElement("link");r.rel="preconnect",r.href=`${z}/`,s.appendChild(r);const i=document.createElement("link");i.rel="stylesheet",i.href=`${t}/${n}`,i.onerror=()=>{o(`Failed to load ${i.href}`);const t=l(e);t&&v.injectStylesheet({cdnType:t,theRestUrl:n})},s.appendChild(i)},O.injectZonosCss=()=>{document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')?e("Zonos style links already injected","warn"):(v.injectStylesheet({cdnType:i,theRestUrl:"dist/zonos-elements/zonos-elements.css"}),e("Zonos style css injected!"))},O.injectFonts=()=>{if((()=>{const e=document.querySelectorAll(`link[rel="stylesheet"][href^="${g}"]`);for(let n=0;n<e.length;n++){const o=e[n];if(o&&!S.test(o.href))return o}return null})())return void e("Inter font already injected","warn");const n=document.head||document.body,o=document.createElement("link");o.rel="preconnect",o.href=g,n.appendChild(o);const t=document.createElement("link");t.rel="stylesheet",t.href=`${g}/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap`,n.appendChild(t),e("Zonos font injected!")},O.setupGoogleFont=e=>{var n;null===(n=v.zonosController)||void 0===n||n.setupGoogleFont(e)},O.injectSupportGoogleFont=n=>{var o;e(`[FONT] injecting ${n}`);const t=null===(o=n.match(/family=(.*?):/))||void 0===o?void 0:o[1],s=document.head||document.body;if(!document.querySelector(`link[rel="preconnect"][href^="${g}"]`)){const e=document.createElement("link");e.rel="preconnect",e.href=g,s.appendChild(e)}if(document.querySelector(`link[rel="stylesheet"][href="${n}"]`))return void e(`[FONT] ${t} font already injected`,"warn");const r=document.createElement("link");r.rel="stylesheet",r.href=n,s.appendChild(r),e(`[FONT] ${t} font injected!`)};export{O as Zonos}
|
|
1
|
+
import{l as e,h as n,a as t}from"./p-860e46ab.js";import{s as o,c as s}from"./p-b7307c61.js";export{c as checkoutHiddenBtnSelector,d as domesticRedirectedBtnSelector}from"./p-b7307c61.js";const i=["jsdelivr","cdnjs","unpkg","vercel"],r="jsdelivr",l=e=>{const n=i.indexOf(e);return i[n+1]||null},u=()=>{const n=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||n)return null;const t=(e=>{if(!e)return null;const n=new URL(e).searchParams.get("zonosQaUrl");return n?/[^a-zA-Z0-9-_]+/.test(n)?null:n:null})(window.location.href),o="https://v1.3.141.js.zonos.com";if(!t&&(o.includes("test.")||o.includes("test-")))return o;if(!t&&["dev.demo.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!t)return null;if("dev-elements"===t)return"https://dev.elements.zonos.com";const s=`https://${t}.preview.js.zonos.com`;return e(`[ZONOS-WARNING] using '${s}' for loading elements script`,"warn"),fetch(s).then((()=>{window.sessionStorage.removeItem("zonos--checkout-session-id"),window.sessionStorage.removeItem("zonos--client-secret")})).catch((()=>{alert(`[ZONOS-WARNING] '${s}' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE`);const e=new URLSearchParams(window.location.search);e.delete("zonosQaUrl");const{pathname:n}=window.location,t=`${n}?${e.toString()}`;return window.history.replaceState(window.history.state,"",t),window.location.reload(),null})),s},a="https://js.stripe.com/v3",m=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,p="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";let w=null;const f=Promise.resolve().then((()=>{return e=null,null!==w||(w=new Promise(((n,o)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&e&&console.warn(p),window.Stripe)n(window.Stripe);else try{let s=(()=>{const e=document.querySelectorAll(`script[src^="${a}"]`);for(let n=0;n<e.length;n++){const t=e[n];if(t&&m.test(t.src))return t}return null})();s&&e?console.warn(p):s||(s=(e=>{const n=e&&!e.advancedFraudSignals?"?advancedFraudSignals=false":"",o=document.createElement("script");o.src=`${a}${n}`;const s=document.head||document.body;return s?(s.appendChild(o),o):(t("Expected document.body not to be null. Stripe.js requires a <body> element."),null)})(e)),null==s||s.addEventListener("load",(()=>{window.Stripe?n(window.Stripe):o(new Error("Stripe.js not available"))})),null==s||s.addEventListener("error",(()=>{o(new Error("Failed to load Stripe.js"))}))}catch(e){return void o(e)}else n(null)}))),w;var e}));let h=!1;var v;f.catch((e=>{h||console.warn(e)}));const y=(()=>{if("undefined"==typeof document)return null;const e=document.querySelector('script[src*="/zonos.js"]'),{currentLoadScriptUrl:n,isWhiteListed:t}=(({loadScriptSrc:e})=>{if(!e)return{currentLoadScriptUrl:"",isForceLoadVersionDomain:!1,isWhiteListed:!1};const n=new URL(e).origin,t=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"].some((e=>n.includes(e))),o=["qa.js.zonos.com"].some((e=>n.includes(e)));return{currentLoadScriptUrl:n,isForceLoadVersionDomain:o,isWhiteListed:t}})({loadScriptSrc:null==e?void 0:e.src});return t?n:null})(),z="https://v1.3.141.js.zonos.com",S=y||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.141",g="https://fonts.googleapis.com",j=/^https:\/\/fonts\.googleapis\.com/;class O{}v=O,O.doneInit=!1,O.debug="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/),O.zonosConversionTest="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/),O._paypalMockResponse=null,O.isBigCommerce=!1,O.releaseDate="1734130586435",O.isLegacyCheckout=!1,O.domain="undefined"!=typeof window?window.location!=window.parent.location&&document.referrer||document.location.hostname:"",O.showBaseForeign="undefined"!=typeof window&&window.location.search.includes("zonosShowBaseForeign"),O.isNpm=!0,O.zonosQaUrl=null,O.zonosQaUrlApi=null,O.version="v1.3.141",O.modeAlerted=!1,O.cartData=null,O.paypal=null,O.getCurrentTimestamp=()=>(new Date).getTime(),O.zonosController=null,O.init=async i=>{const{appearance:r,checkoutSettings:c,currencyConverter:d,helloSettings:l,onCountryChange:a,overrideCurrencyFormat:m,storeId:p,zonosApiKey:w}=i;if(v.cartId=new URLSearchParams(window.location.search).get("tempCartUUID"),v.doneInit)return;if(e(`====== ZONOS DEBUG MODE: on (${v.version}) ======`),v.zonosApiKey=w,v.storeId=p,v.isNpm){e("====== ZONOS LOADING FROM NPM ======");const s=u();if(s&&!window.isZonosPreview){e(`====== RE-INJECT "zonos.js" FROM PRVIEW: ${s} ======`,"info");const n=document.createElement("script");return n.src=`${s}/dist/scripts/zonos.js`,document.head.appendChild(n),n.addEventListener("load",(()=>{window.Zonos.isNpm=v.isNpm,window.Zonos.isBigCommerce=v.isBigCommerce,window.Zonos.isLegacyCheckout=v.isLegacyCheckout,window.Zonos.init(i)})),n.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${s}`)})),void(window.isZonosPreview=!0)}if(!w&&!v.cartId)return void t("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(!v.cartData&&v.cartId){e("Initialize cart data");const n=await o(v.cartId);if(!n)return void t("Failed to get cart data");v.cartData=n.cartData,v.zonosApiKey=n.zonosApiKey}const r=await(async()=>{if(!window.location.search.includes("zonosTestMode=1")||!window.Zonos.zonosApiKey)return null;if(e("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return e("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:o,json:s}=await n("/api/get-test-public-credential");if(o.length||!s)return t("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",o),null;const i=s.publicCredential;return i?(e(`[ZONOS - loadZonos] Retrieve new test public token ${i}`,"info"),i):(t("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();r&&(v.zonosApiKey=r)}const f=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");if(v.cartId&&v.cartData||f){e("Cart data or stripe client secret is available, inject hidden button and trigger checkout");const n=document.createElement("button");n.style.display="none",n.id=`${s}`,document.body.appendChild(n)}e("init zonos"),v.injectCustomScriptForHostedCheckout(),v.injectZonosCdn(),v.injectZonosCss(),v.injectFonts(),v.injectController({config:{appearance:r,checkoutSettings:c,currencyConverter:d,helloSettings:l,onCountryChange:a,overrideCurrencyFormat:m}}),v.doneInit=!0},O.injectCustomScriptForHostedCheckout=()=>{const n=v.cartData,t=(null==n?void 0:n.metadata)||[],o=t.find((e=>"customHeaderScript"===e.key)),s=t.find((e=>"customFooterScript"===e.key));if(window.Zonos.isLegacyCheckout&&(o||s)){if(o){e("Injecting custom header script");const n=document.createElement("script");n.textContent=o.value,document.head.appendChild(n)}if(s){e("Injecting custom footer script");const n=document.createElement("script");n.textContent=s.value,document.body.appendChild(n)}}else e("Skip injecting custom script for hosted checkout","info",{footerScript:s,headerScript:o,isLegacyCheckout:window.Zonos.isLegacyCheckout})},O.displayCurrency=()=>{const e=document.querySelector("zonos-hello");e&&e.displayCurrency()},O.openHelloDialog=e=>{const n=document.querySelector("zonos-hello");n&&n.openHelloDialog(null==e||e)},O.showNotification=e=>{var n;null===(n=v.zonosController)||void 0===n||n.showNotification(e)},O.updateOrganizationName=e=>{var n;null===(n=v.zonosController)||void 0===n||n.updateOrganizationName(e)},O.disablePlaceOrderButtons=({autoEnable:e=!0,config:n,disable:t,placeOrderButtonSelector:o})=>{var s;if(!(null===(s=n.checkoutSettings)||void 0===s?void 0:s.disablePlaceOrderButtonActivation)&&o){const n=document.querySelectorAll(o),s=e=>{e.target.getAttribute("disabled")&&(e.preventDefault(),e.stopPropagation())};n.forEach((e=>{e.getAttribute("data-zonos-checkout-attached")||(t?(e.setAttribute("disabled","true"),e.addEventListener("click",s)):(e.removeAttribute("disabled"),e.removeEventListener("click",s)))})),e&&t&&setTimeout((()=>{n.forEach((e=>{e.removeAttribute("disabled"),e.removeEventListener("click",s)}))}),5e3)}},O.injectController=({config:n})=>{var o;if(document.querySelector("zonos-controller"))return;if(null===(o=n.checkoutSettings)||void 0===o?void 0:o.placeOrderButtonSelector){const e=n.checkoutSettings.placeOrderButtonSelector;v.disablePlaceOrderButtons({config:n,disable:!0,placeOrderButtonSelector:e}),new MutationObserver((()=>{v.disablePlaceOrderButtons({config:n,disable:!0,placeOrderButtonSelector:e})})).observe(document.body,{childList:!0,subtree:!0})}const s=document.createElement("zonos-controller");s.config=n,s.zonosApiKey=v.zonosApiKey||"",s.addEventListener("stripeInitEvent",(async n=>{const{detail:o}=n;e("loading Stripe");const i=await(async(...e)=>{h=!0;const n=Date.now();return f.then((t=>((e,n,t)=>{if(null===e)return null;const o=e.apply(void 0,n);return((e,n)=>{e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",startTime:n})})(o,t),o})(t,e,n)))})(o.publishableKey);i?(window.Zonos.stripe=i,s.initCheckoutElement(i)):t("API seems to be invalid or missing. Failed to load Stripe")})),document.body.appendChild(s),v.zonosController=s,e("Zonos controller injected!")},O.injectScript=({cdnType:n,isModule:o,theRestUrl:s})=>{const i=`${v.getZonosUrl(n)}/${s}`;if(document.querySelector(`script[src="${i}"]`))return void e(`Zonos script "${i}" already exists in the document`,"warn");const r=document.head||document.body,c=document.createElement("script");o?c.type="module":c.noModule=!0,c.src=i,c.crossOrigin="anonymous",c.onerror=()=>{t(`Failed to load ${c.src}`);const e=l(n);e&&v.injectScript({cdnType:e,isModule:o,theRestUrl:s})},r.appendChild(c)},O.getZonosUrl=e=>{const n=()=>{switch(e){case"jsdelivr":return S;case"unpkg":return"https://unpkg.com/@zonos/elements@1.3.141";case"cdnjs":return"https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.141";case"vercel":return z}};return v.isNpm&&u()||n()},O.injectZonosCdn=()=>{v.injectScript({cdnType:r,isModule:!0,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"}),v.injectScript({cdnType:r,isModule:!1,theRestUrl:"dist/zonos-elements/zonos-elements.js"}),e("Zonos cdn script injected!")},O.injectStylesheet=({cdnType:e,theRestUrl:n})=>{const o=v.getZonosUrl(e),s=document.head||document.body,i=document.createElement("link");i.rel="preconnect",i.href=`${z}/`,s.appendChild(i);const r=document.createElement("link");r.rel="stylesheet",r.href=`${o}/${n}`,r.onerror=()=>{t(`Failed to load ${r.href}`);const o=l(e);o&&v.injectStylesheet({cdnType:o,theRestUrl:n})},s.appendChild(r)},O.injectZonosCss=()=>{document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')?e("Zonos style links already injected","warn"):(v.injectStylesheet({cdnType:r,theRestUrl:"dist/zonos-elements/zonos-elements.css"}),e("Zonos style css injected!"))},O.injectFonts=()=>{if((()=>{const e=document.querySelectorAll(`link[rel="stylesheet"][href^="${g}"]`);for(let n=0;n<e.length;n++){const t=e[n];if(t&&!j.test(t.href))return t}return null})())return void e("Inter font already injected","warn");const n=document.head||document.body,t=document.createElement("link");t.rel="preconnect",t.href=g,n.appendChild(t);const o=document.createElement("link");o.rel="stylesheet",o.href=`${g}/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap`,n.appendChild(o),e("Zonos font injected!")},O.setupGoogleFont=e=>{var n;null===(n=v.zonosController)||void 0===n||n.setupGoogleFont(e)},O.injectSupportGoogleFont=n=>{var t;e(`[FONT] injecting ${n}`);const o=null===(t=n.match(/family=(.*?):/))||void 0===t?void 0:t[1],s=document.head||document.body;if(!document.querySelector(`link[rel="preconnect"][href^="${g}"]`)){const e=document.createElement("link");e.rel="preconnect",e.href=g,s.appendChild(e)}if(document.querySelector(`link[rel="stylesheet"][href="${n}"]`))return void e(`[FONT] ${o} font already injected`,"warn");const i=document.createElement("link");i.rel="stylesheet",i.href=n,s.appendChild(i),e(`[FONT] ${o} font injected!`)};export{O as Zonos}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(n,e,t,r){function o(n){return n instanceof t?n:new t((function(e){e(n)}))}return new(t||(t=Promise))((function(t,i){function u(n){try{c(r.next(n))}catch(n){i(n)}}function s(n){try{c(r["throw"](n))}catch(n){i(n)}}function c(n){n.done?t(n.value):o(n.value).then(u,s)}c((r=r.apply(n,e||[])).next())}))};var __generator=this&&this.__generator||function(n,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,o,i,u;return u={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function s(n){return function(e){return c([n,e])}}function c(s){if(r)throw new TypeError("Generator is already executing.");while(u&&(u=0,s[0]&&(t=0)),t)try{if(r=1,o&&(i=s[0]&2?o["return"]:s[0]?o["throw"]||((i=o["return"])&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;if(o=0,i)s=[s[0]&2,i.value];switch(s[0]){case 0:case 1:i=s;break;case 4:t.label++;return{value:s[1],done:false};case 5:t.label++;o=s[1];s=[0];continue;case 7:s=t.ops.pop();t.trys.pop();continue;default:if(!(i=t.trys,i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){t=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){t.label=s[1];break}if(s[0]===6&&t.label<i[1]){t.label=i[1];i=s;break}if(i&&t.label<i[2]){t.label=i[2];t.ops.push(s);break}if(i[2])t.ops.pop();t.trys.pop();continue}s=e.call(n,t)}catch(n){s=[6,n];o=0}finally{r=i=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};System.register(["./p-febc72e7.system.js","./p-bb418544.system.js"],(function(n){"use strict";var e,t,r,o,i;return{setters:[function(n){e=n.l;t=n.h;r=n.a},function(e){o=e.s;i=e.c;var t={};t.checkoutHiddenBtnSelector=e.c;t.domesticRedirectedBtnSelector=e.d;n(t)}],execute:function(){var u=this;var s=function(n){var e=n.loadScriptSrc;if(!e){return{currentLoadScriptUrl:"",isForceLoadVersionDomain:false,isWhiteListed:false}}var t=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"];var r=["qa.js.zonos.com"];var o=new URL(e).origin;var i=t.some((function(n){return o.includes(n)}));var u=r.some((function(n){return o.includes(n)}));return{currentLoadScriptUrl:o,isForceLoadVersionDomain:u,isWhiteListed:i}};var c=["jsdelivr","cdnjs","unpkg","vercel"];var a="jsdelivr";var d=function(n){var e=c.indexOf(n);var t=c[e+1];return t||null};var l=function(){return __awaiter(u,void 0,void 0,(function(){var n,o,i,u,s;return __generator(this,(function(c){switch(c.label){case 0:n=window.location.search.includes("zonosTestMode=1");if(!n||!window.Zonos.zonosApiKey){return[2,null]}e("[ZONOS - loadZonos] Attempt test public credential","info");if(!!window.Zonos.zonosApiKey.includes("credential_test")){e("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info");return[2,null]}return[4,t("/api/get-test-public-credential")];case 1:o=c.sent(),i=o.errors,u=o.json;if(i.length||!u){r("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",i);return[2,null]}s=u.publicCredential;if(!s){r("[ZONOS - loadZonos] No test public key credential. Keep using production key");return[2,null]}e("[ZONOS - loadZonos] Retrieve new test public token ".concat(s),"info");return[2,s]}}))}))};var f=function(n){if(!n){return null}var e=new URL(n).searchParams;var t=e.get("zonosQaUrl");if(!t){return null}var r=/[^a-zA-Z0-9-_]+/.test(t);if(!!r){return null}return t};var v=function(){var n=window&&window.location.href.includes("forceLoadCdn");if(typeof window==="undefined"||n){return null}var t=f(window.location.href);var r="https://v1.3.141.js.zonos.com";if(!t&&(r.includes("test.")||r.includes("test-"))){return r}if(!t&&["dev.demo.elements.zonos.com"].includes(window.location.hostname)){return"https://dev.elements.zonos.com"}if(!t){return null}if(t==="dev-elements"){return"https://dev.elements.zonos.com"}var o="preview.js.zonos.com";var i="https://".concat(t,".").concat(o);e("[ZONOS-WARNING] using '".concat(i,"' for loading elements script"),"warn");void fetch(i).then((function(){window.sessionStorage.removeItem("zonos--checkout-session-id");window.sessionStorage.removeItem("zonos--client-secret")})).catch((function(){alert("[ZONOS-WARNING] '".concat(i,"' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE"));var n=new URLSearchParams(window.location.search);n.delete("zonosQaUrl");var e=window.location.pathname;var t="".concat(e,"?").concat(n.toString());window.history.replaceState(window.history.state,"",t);window.location.reload();return null}));return i};var m="https://js.stripe.com/v3";var w=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;var p="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";var h=function(){var n=document.querySelectorAll('script[src^="'.concat(m,'"]'));for(var e=0;e<n.length;e++){var t=n[e];if(!t){continue}if(!w.test(t.src)){continue}return t}return null};var y=null;var z=function(n){var e=n&&!n.advancedFraudSignals?"?advancedFraudSignals=false":"";var t=document.createElement("script");t.src="".concat(m).concat(e);var o=document.head||document.body;if(!o){r("Expected document.body not to be null. Stripe.js requires a <body> element.");return null}o.appendChild(t);return t};var g=function(n){if(y!==null){return y}y=new Promise((function(e,t){if(typeof window==="undefined"||typeof document==="undefined"){e(null);return}if(window.Stripe&&n){console.warn(p)}if(window.Stripe){e(window.Stripe);return}try{var r=h();if(r&&n){console.warn(p)}else if(!r){r=z(n)}r===null||r===void 0?void 0:r.addEventListener("load",(function(){if(window.Stripe){e(window.Stripe)}else{t(new Error("Stripe.js not available"))}}));r===null||r===void 0?void 0:r.addEventListener("error",(function(){t(new Error("Failed to load Stripe.js"))}))}catch(n){t(n);return}}));return y};var j=function(n,e){if(!n||!n._registerWrapper){return}n._registerWrapper({name:"stripe-js",startTime:e})};var S=function(n,e,t){if(n===null){return null}var r=n.apply(undefined,e);j(r,t);return r};var b=Promise.resolve().then((function(){return g(null)}));var k=false;b.catch((function(n){if(!k){console.warn(n)}}));var O=function(){var n=[];for(var e=0;e<arguments.length;e++){n[e]=arguments[e]}return __awaiter(u,void 0,void 0,(function(){var e;return __generator(this,(function(t){k=true;e=Date.now();return[2,b.then((function(t){return S(t,n,e)}))]}))}))};var N="tempCartUUID";var Z=function(){var n=new URLSearchParams(window.location.search);var e=n.get(N);return e};var _;var R=function(){if(typeof document==="undefined"){return null}var n=document.querySelector('script[src*="/zonos.js"]');var e=s({loadScriptSrc:n===null||n===void 0?void 0:n.src}),t=e.currentLoadScriptUrl,r=e.isWhiteListed;if(r){return t}return null}();var U="https://v1.3.141.js.zonos.com";var I=R||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.141";var L="https://unpkg.com/@zonos/elements@1.3.141";var F="https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.141";var A="https://fonts.googleapis.com";var E=/^https:\/\/fonts\.googleapis\.com/;var T=function(){function n(){}return n}();n("Zonos",T);_=T;T.doneInit=false;T.debug=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/);T.zonosConversionTest=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/);T._paypalMockResponse=null;T.isBigCommerce=false;T.releaseDate="1734130586435";T.isLegacyCheckout=false;T.domain=typeof window!=="undefined"?window.location!=window.parent.location&&document.referrer||document.location.hostname:"";T.showBaseForeign=typeof window!=="undefined"&&window.location.search.includes("zonosShowBaseForeign");T.isNpm=true;T.zonosQaUrl=null;T.zonosQaUrlApi=null;T.version="v".concat("1.3.141");T.modeAlerted=false;T.cartData=null;T.paypal=null;T.getCurrentTimestamp=function(){return(new Date).getTime()};T.zonosController=null;T.init=function(n){return __awaiter(u,void 0,void 0,(function(){var t,u,s,c,a,d,f,m,w,p,h,y,z,g,j;return __generator(this,(function(S){switch(S.label){case 0:t=n.appearance,u=n.checkoutSettings,s=n.currencyConverter,c=n.helloSettings,a=n.onCountryChange,d=n.overrideCurrencyFormat,f=n.storeId,m=n.zonosApiKey;_.cartId=Z();if(_.doneInit){return[2]}e("====== ZONOS DEBUG MODE: on (".concat(_.version,") ======"));_.zonosApiKey=m;_.storeId=f;if(!_.isNpm)return[3,4];e("====== ZONOS LOADING FROM NPM ======");w=v();if(w&&!window.isZonosPreview){e('====== RE-INJECT "zonos.js" FROM PRVIEW: '.concat(w," ======"),"info");p=document.createElement("script");p.src="".concat(w,"/dist/scripts/zonos.js");document.head.appendChild(p);p.addEventListener("load",(function(){window.Zonos.isNpm=_.isNpm;window.Zonos.isBigCommerce=_.isBigCommerce;window.Zonos.isLegacyCheckout=_.isLegacyCheckout;void window.Zonos.init(n)}));p.addEventListener("error",(function(){alert('[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: '.concat(w))}));window.isZonosPreview=true;return[2]}if(!m&&!_.cartId){r("Zonos API key is required unless `tempCartUUID` is provided in url query params.");return[2]}if(!(!_.cartData&&_.cartId))return[3,2];e("Initialize cart data");return[4,o(_.cartId)];case 1:h=S.sent();if(!h){r("Failed to get cart data");return[2]}_.cartData=h.cartData;_.zonosApiKey=h.zonosApiKey;S.label=2;case 2:return[4,l()];case 3:y=S.sent();if(y){_.zonosApiKey=y}S.label=4;case 4:z=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");g=_.cartId&&_.cartData||!!z;if(g){e("Cart data or stripe client secret is available, inject hidden button and trigger checkout");j=document.createElement("button");j.style.display="none";j.id="".concat(i);document.body.appendChild(j)}e("init zonos");_.injectCustomScriptForHostedCheckout();_.injectZonosCdn();_.injectZonosCss();_.injectFonts();_.injectController({config:{appearance:t,checkoutSettings:u,currencyConverter:s,helloSettings:c,onCountryChange:a,overrideCurrencyFormat:d}});_.doneInit=true;return[2]}}))}))};T.injectCustomScriptForHostedCheckout=function(){var n=_.cartData;var t=(n===null||n===void 0?void 0:n.metadata)||[];var r=t.find((function(n){return n.key==="customHeaderScript"}));var o=t.find((function(n){return n.key==="customFooterScript"}));if(!window.Zonos.isLegacyCheckout||!r&&!o){e("Skip injecting custom script for hosted checkout","info",{footerScript:o,headerScript:r,isLegacyCheckout:window.Zonos.isLegacyCheckout});return}if(r){e("Injecting custom header script");var i=document.createElement("script");i.textContent=r.value;document.head.appendChild(i)}if(o){e("Injecting custom footer script");var i=document.createElement("script");i.textContent=o.value;document.body.appendChild(i)}};T.displayCurrency=function(){var n=document.querySelector("zonos-hello");if(n){void n.displayCurrency()}};T.openHelloDialog=function(n){var e=document.querySelector("zonos-hello");if(e){void e.openHelloDialog(n!==null&&n!==void 0?n:true)}};T.showNotification=function(n){var e;void((e=_.zonosController)===null||e===void 0?void 0:e.showNotification(n))};T.updateOrganizationName=function(n){var e;void((e=_.zonosController)===null||e===void 0?void 0:e.updateOrganizationName(n))};T.disablePlaceOrderButtons=function(n){var e=n.autoEnable,t=e===void 0?true:e,r=n.config,o=n.disable,i=n.placeOrderButtonSelector;var u;if((u=r.checkoutSettings)===null||u===void 0?void 0:u.disablePlaceOrderButtonActivation){return}if(i){var s=document.querySelectorAll(i);var c=function(n){var e=n.target;if(e.getAttribute("disabled")){n.preventDefault();n.stopPropagation()}};s.forEach((function(n){var e=n.getAttribute("data-zonos-checkout-attached");if(e){return}if(o){n.setAttribute("disabled","true");n.addEventListener("click",c)}else{n.removeAttribute("disabled");n.removeEventListener("click",c)}}));if(t&&o){setTimeout((function(){s.forEach((function(n){n.removeAttribute("disabled");n.removeEventListener("click",c)}))}),5e3)}}};T.injectController=function(n){var t=n.config;var o;if(document.querySelector("zonos-controller")){return}if((o=t.checkoutSettings)===null||o===void 0?void 0:o.placeOrderButtonSelector){var i=t.checkoutSettings.placeOrderButtonSelector;_.disablePlaceOrderButtons({config:t,disable:true,placeOrderButtonSelector:i});var s=new MutationObserver((function(){_.disablePlaceOrderButtons({config:t,disable:true,placeOrderButtonSelector:i})}));s.observe(document.body,{childList:true,subtree:true})}var c=document.createElement("zonos-controller");c.config=t;c.zonosApiKey=_.zonosApiKey||"";c.addEventListener("stripeInitEvent",(function(n){return __awaiter(u,void 0,void 0,(function(){var t,o;return __generator(this,(function(i){switch(i.label){case 0:t=n.detail;e("loading Stripe");return[4,O(t.publishableKey)];case 1:o=i.sent();if(!o){r("API seems to be invalid or missing. Failed to load Stripe");return[2]}window.Zonos.stripe=o;void c.initCheckoutElement(o);return[2]}}))}))}));document.body.appendChild(c);_.zonosController=c;e("Zonos controller injected!")};T.injectScript=function(n){var t=n.cdnType,o=n.isModule,i=n.theRestUrl;var u=_.getZonosUrl(t);var s="".concat(u,"/").concat(i);var c=function(){var n=document.querySelector('script[src="'.concat(s,'"]'));return!!n};if(c()){e('Zonos script "'.concat(s,'" already exists in the document'),"warn");return}var a=document.head||document.body;var l=document.createElement("script");if(!!o){l.type="module"}else{l.noModule=true}l.src=s;l.crossOrigin="anonymous";l.onerror=function(){r("Failed to load ".concat(l.src));var n=d(t);if(!n){return}_.injectScript({cdnType:n,isModule:o,theRestUrl:i})};a.appendChild(l)};T.getZonosUrl=function(n){var e=function(){switch(n){case"jsdelivr":return I;case"unpkg":return L;case"cdnjs":return F;case"vercel":return U}};if(_.isNpm){var t=v();return t||e()}return e()};T.injectZonosCdn=function(){_.injectScript({cdnType:a,isModule:true,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"});_.injectScript({cdnType:a,isModule:false,theRestUrl:"dist/zonos-elements/zonos-elements.js"});e("Zonos cdn script injected!")};T.injectStylesheet=function(n){var e=n.cdnType,t=n.theRestUrl;var o=_.getZonosUrl(e);var i=document.head||document.body;var u=document.createElement("link");u.rel="preconnect";u.href="".concat(U,"/");i.appendChild(u);var s=document.createElement("link");s.rel="stylesheet";s.href="".concat(o,"/").concat(t);s.onerror=function(){r("Failed to load ".concat(s.href));var n=d(e);if(!n){return}_.injectStylesheet({cdnType:n,theRestUrl:t})};i.appendChild(s)};T.injectZonosCss=function(){var n=function(){return!!document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')};if(n()){e("Zonos style links already injected","warn");return}_.injectStylesheet({cdnType:a,theRestUrl:"dist/zonos-elements/zonos-elements.css"});e("Zonos style css injected!")};T.injectFonts=function(){var n=function(){var n=document.querySelectorAll('link[rel="stylesheet"][href^="'.concat(A,'"]'));for(var e=0;e<n.length;e++){var t=n[e];if(!t){continue}if(E.test(t.href)){continue}return t}return null};if(n()){e("Inter font already injected","warn");return}var t=document.head||document.body;var r=document.createElement("link");r.rel="preconnect";r.href=A;t.appendChild(r);var o=document.createElement("link");o.rel="stylesheet";o.href="".concat(A,"/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");t.appendChild(o);e("Zonos font injected!")};T.setupGoogleFont=function(n){var e;void((e=_.zonosController)===null||e===void 0?void 0:e.setupGoogleFont(n))};T.injectSupportGoogleFont=function(n){var t;e("[FONT] injecting ".concat(n));var r=(t=n.match(/family=(.*?):/))===null||t===void 0?void 0:t[1];var o=document.head||document.body;if(!document.querySelector('link[rel="preconnect"][href^="'.concat(A,'"]'))){var i=document.createElement("link");i.rel="preconnect";i.href=A;o.appendChild(i)}if(document.querySelector('link[rel="stylesheet"][href="'.concat(n,'"]'))){e("[FONT] ".concat(r," font already injected"),"warn");return}var u=document.createElement("link");u.rel="stylesheet";u.href=n;o.appendChild(u);e("[FONT] ".concat(r," font injected!"))}}}}));
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(n,e,t,r){function o(n){return n instanceof t?n:new t((function(e){e(n)}))}return new(t||(t=Promise))((function(t,i){function u(n){try{a(r.next(n))}catch(n){i(n)}}function s(n){try{a(r["throw"](n))}catch(n){i(n)}}function a(n){n.done?t(n.value):o(n.value).then(u,s)}a((r=r.apply(n,e||[])).next())}))};var __generator=this&&this.__generator||function(n,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,o,i,u;return u={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function s(n){return function(e){return a([n,e])}}function a(s){if(r)throw new TypeError("Generator is already executing.");while(u&&(u=0,s[0]&&(t=0)),t)try{if(r=1,o&&(i=s[0]&2?o["return"]:s[0]?o["throw"]||((i=o["return"])&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;if(o=0,i)s=[s[0]&2,i.value];switch(s[0]){case 0:case 1:i=s;break;case 4:t.label++;return{value:s[1],done:false};case 5:t.label++;o=s[1];s=[0];continue;case 7:s=t.ops.pop();t.trys.pop();continue;default:if(!(i=t.trys,i=i.length>0&&i[i.length-1])&&(s[0]===6||s[0]===2)){t=0;continue}if(s[0]===3&&(!i||s[1]>i[0]&&s[1]<i[3])){t.label=s[1];break}if(s[0]===6&&t.label<i[1]){t.label=i[1];i=s;break}if(i&&t.label<i[2]){t.label=i[2];t.ops.push(s);break}if(i[2])t.ops.pop();t.trys.pop();continue}s=e.call(n,t)}catch(n){s=[6,n];o=0}finally{r=i=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};System.register(["./p-febc72e7.system.js","./p-bb418544.system.js"],(function(n){"use strict";var e,t,r,o,i;return{setters:[function(n){e=n.l;t=n.h;r=n.a},function(e){o=e.s;i=e.c;var t={};t.checkoutHiddenBtnSelector=e.c;t.domesticRedirectedBtnSelector=e.d;n(t)}],execute:function(){var u=this;var s=function(n){var e=n.loadScriptSrc;if(!e){return{currentLoadScriptUrl:"",isForceLoadVersionDomain:false,isWhiteListed:false}}var t=["dev.elements.zonos.com","dev.assets-checkout.zonos.com",".js.zonos.com","zonos-elements-test-git","zonos-elements-git"];var r=["qa.js.zonos.com"];var o=new URL(e).origin;var i=t.some((function(n){return o.includes(n)}));var u=r.some((function(n){return o.includes(n)}));return{currentLoadScriptUrl:o,isForceLoadVersionDomain:u,isWhiteListed:i}};var a=["jsdelivr","cdnjs","unpkg","vercel"];var c="jsdelivr";var d=function(n){var e=a.indexOf(n);var t=a[e+1];return t||null};var l=function(){return __awaiter(u,void 0,void 0,(function(){var n,o,i,u,s;return __generator(this,(function(a){switch(a.label){case 0:n=window.location.search.includes("zonosTestMode=1");if(!n||!window.Zonos.zonosApiKey){return[2,null]}e("[ZONOS - loadZonos] Attempt test public credential","info");if(!!window.Zonos.zonosApiKey.includes("credential_test")){e("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info");return[2,null]}return[4,t("/api/get-test-public-credential")];case 1:o=a.sent(),i=o.errors,u=o.json;if(i.length||!u){r("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",i);return[2,null]}s=u.publicCredential;if(!s){r("[ZONOS - loadZonos] No test public key credential. Keep using production key");return[2,null]}e("[ZONOS - loadZonos] Retrieve new test public token ".concat(s),"info");return[2,s]}}))}))};var f=function(n){if(!n){return null}var e=new URL(n).searchParams;var t=e.get("zonosQaUrl");if(!t){return null}var r=/[^a-zA-Z0-9-_]+/.test(t);if(!!r){return null}return t};var v=function(){var n=window&&window.location.href.includes("forceLoadCdn");if(typeof window==="undefined"||n){return null}var t=f(window.location.href);var r="https://v1.3.140.js.zonos.com";if(!t&&(r.includes("test.")||r.includes("test-"))){return r}if(!t&&["dev.demo.elements.zonos.com"].includes(window.location.hostname)){return"https://dev.elements.zonos.com"}if(!t){return null}if(t==="dev-elements"){return"https://dev.elements.zonos.com"}var o="preview.js.zonos.com";var i="https://".concat(t,".").concat(o);e("[ZONOS-WARNING] using '".concat(i,"' for loading elements script"),"warn");void fetch(i).then((function(){window.sessionStorage.removeItem("zonos--checkout-session-id");window.sessionStorage.removeItem("zonos--client-secret")})).catch((function(){alert("[ZONOS-WARNING] '".concat(i,"' IS NO LONGER AVAILABLE. REMOVING zonosQaUrl PARAM AND RELOADING THE PAGE"));var n=new URLSearchParams(window.location.search);n.delete("zonosQaUrl");var e=window.location.pathname;var t="".concat(e,"?").concat(n.toString());window.history.replaceState(window.history.state,"",t);window.location.reload();return null}));return i};var w="https://js.stripe.com/v3";var m=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;var p="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used";var h=function(){var n=document.querySelectorAll('script[src^="'.concat(w,'"]'));for(var e=0;e<n.length;e++){var t=n[e];if(!t){continue}if(!m.test(t.src)){continue}return t}return null};var y=null;var z=function(n){var e=n&&!n.advancedFraudSignals?"?advancedFraudSignals=false":"";var t=document.createElement("script");t.src="".concat(w).concat(e);var o=document.head||document.body;if(!o){r("Expected document.body not to be null. Stripe.js requires a <body> element.");return null}o.appendChild(t);return t};var g=function(n){if(y!==null){return y}y=new Promise((function(e,t){if(typeof window==="undefined"||typeof document==="undefined"){e(null);return}if(window.Stripe&&n){console.warn(p)}if(window.Stripe){e(window.Stripe);return}try{var r=h();if(r&&n){console.warn(p)}else if(!r){r=z(n)}r===null||r===void 0?void 0:r.addEventListener("load",(function(){if(window.Stripe){e(window.Stripe)}else{t(new Error("Stripe.js not available"))}}));r===null||r===void 0?void 0:r.addEventListener("error",(function(){t(new Error("Failed to load Stripe.js"))}))}catch(n){t(n);return}}));return y};var j=function(n,e){if(!n||!n._registerWrapper){return}n._registerWrapper({name:"stripe-js",startTime:e})};var b=function(n,e,t){if(n===null){return null}var r=n.apply(undefined,e);j(r,t);return r};var O=Promise.resolve().then((function(){return g(null)}));var S=false;O.catch((function(n){if(!S){console.warn(n)}}));var k=function(){var n=[];for(var e=0;e<arguments.length;e++){n[e]=arguments[e]}return __awaiter(u,void 0,void 0,(function(){var e;return __generator(this,(function(t){S=true;e=Date.now();return[2,O.then((function(t){return b(t,n,e)}))]}))}))};var N="tempCartUUID";var Z=function(){var n=new URLSearchParams(window.location.search);var e=n.get(N);return e};var _;var R=function(){if(typeof document==="undefined"){return null}var n=document.querySelector('script[src*="/zonos.js"]');var e=s({loadScriptSrc:n===null||n===void 0?void 0:n.src}),t=e.currentLoadScriptUrl,r=e.isWhiteListed;if(r){return t}return null}();var U="https://v1.3.140.js.zonos.com";var L=R||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.140";var I="https://unpkg.com/@zonos/elements@1.3.140";var F="https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.140";var A="https://fonts.googleapis.com";var E=/^https:\/\/fonts\.googleapis\.com/;var T=function(){function n(){}return n}();n("Zonos",T);_=T;T.doneInit=false;T.debug=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/);T.zonosConversionTest=typeof window!=="undefined"&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/);T._paypalMockResponse=null;T.isBigCommerce=false;T.releaseDate="1734113749964";T.isLegacyCheckout=false;T.domain=typeof window!=="undefined"?window.location!=window.parent.location&&document.referrer||document.location.hostname:"";T.showBaseForeign=typeof window!=="undefined"&&window.location.search.includes("zonosShowBaseForeign");T.isNpm=true;T.zonosQaUrl=null;T.zonosQaUrlApi=null;T.version="v".concat("1.3.140");T.modeAlerted=false;T.cartData=null;T.paypal=null;T.getCurrentTimestamp=function(){return(new Date).getTime()};T.zonosController=null;T.init=function(n){return __awaiter(u,void 0,void 0,(function(){var t,u,s,a,c,d,f,w,m,p,h,y,z,g,j;return __generator(this,(function(b){switch(b.label){case 0:t=n.appearance,u=n.checkoutSettings,s=n.currencyConverter,a=n.helloSettings,c=n.onCountryChange,d=n.overrideCurrencyFormat,f=n.storeId,w=n.zonosApiKey;_.cartId=Z();if(_.doneInit){return[2]}e("====== ZONOS DEBUG MODE: on (".concat(_.version,") ======"));_.zonosApiKey=w;_.storeId=f;if(!_.isNpm)return[3,4];e("====== ZONOS LOADING FROM NPM ======");m=v();if(m&&!window.isZonosPreview){e('====== RE-INJECT "zonos.js" FROM PRVIEW: '.concat(m," ======"),"info");p=document.createElement("script");p.src="".concat(m,"/dist/scripts/zonos.js");document.head.appendChild(p);p.addEventListener("load",(function(){window.Zonos.isNpm=_.isNpm;window.Zonos.isBigCommerce=_.isBigCommerce;window.Zonos.isLegacyCheckout=_.isLegacyCheckout;void window.Zonos.init(n)}));p.addEventListener("error",(function(){alert('[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: '.concat(m))}));window.isZonosPreview=true;return[2]}if(!w&&!_.cartId){r("Zonos API key is required unless `tempCartUUID` is provided in url query params.");return[2]}if(!(!_.cartData&&_.cartId))return[3,2];e("Initialize cart data");return[4,o(_.cartId)];case 1:h=b.sent();if(!h){r("Failed to get cart data");return[2]}_.cartData=h.cartData;_.zonosApiKey=h.zonosApiKey;b.label=2;case 2:return[4,l()];case 3:y=b.sent();if(y){_.zonosApiKey=y}b.label=4;case 4:z=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");g=_.cartId&&_.cartData||!!z;if(g){e("Cart data or stripe client secret is available, inject hidden button and trigger checkout");j=document.createElement("button");j.style.display="none";j.id="".concat(i);document.body.appendChild(j)}e("init zonos");_.injectZonosCdn();_.injectZonosCss();_.injectFonts();_.injectController({config:{appearance:t,checkoutSettings:u,currencyConverter:s,helloSettings:a,onCountryChange:c,overrideCurrencyFormat:d}});_.doneInit=true;return[2]}}))}))};T.displayCurrency=function(){var n=document.querySelector("zonos-hello");if(n){void n.displayCurrency()}};T.openHelloDialog=function(n){var e=document.querySelector("zonos-hello");if(e){void e.openHelloDialog(n!==null&&n!==void 0?n:true)}};T.showNotification=function(n){var e;void((e=_.zonosController)===null||e===void 0?void 0:e.showNotification(n))};T.updateOrganizationName=function(n){var e;void((e=_.zonosController)===null||e===void 0?void 0:e.updateOrganizationName(n))};T.disablePlaceOrderButtons=function(n){var e=n.autoEnable,t=e===void 0?true:e,r=n.config,o=n.disable,i=n.placeOrderButtonSelector;var u;if((u=r.checkoutSettings)===null||u===void 0?void 0:u.disablePlaceOrderButtonActivation){return}if(i){var s=document.querySelectorAll(i);var a=function(n){var e=n.target;if(e.getAttribute("disabled")){n.preventDefault();n.stopPropagation()}};s.forEach((function(n){var e=n.getAttribute("data-zonos-checkout-attached");if(e){return}if(o){n.setAttribute("disabled","true");n.addEventListener("click",a)}else{n.removeAttribute("disabled");n.removeEventListener("click",a)}}));if(t&&o){setTimeout((function(){s.forEach((function(n){n.removeAttribute("disabled");n.removeEventListener("click",a)}))}),5e3)}}};T.injectController=function(n){var t=n.config;var o;if(document.querySelector("zonos-controller")){return}if((o=t.checkoutSettings)===null||o===void 0?void 0:o.placeOrderButtonSelector){var i=t.checkoutSettings.placeOrderButtonSelector;_.disablePlaceOrderButtons({config:t,disable:true,placeOrderButtonSelector:i});var s=new MutationObserver((function(){_.disablePlaceOrderButtons({config:t,disable:true,placeOrderButtonSelector:i})}));s.observe(document.body,{childList:true,subtree:true})}var a=document.createElement("zonos-controller");a.config=t;a.zonosApiKey=_.zonosApiKey||"";a.addEventListener("stripeInitEvent",(function(n){return __awaiter(u,void 0,void 0,(function(){var t,o;return __generator(this,(function(i){switch(i.label){case 0:t=n.detail;e("loading Stripe");return[4,k(t.publishableKey)];case 1:o=i.sent();if(!o){r("API seems to be invalid or missing. Failed to load Stripe");return[2]}window.Zonos.stripe=o;void a.initCheckoutElement(o);return[2]}}))}))}));document.body.appendChild(a);_.zonosController=a;e("Zonos controller injected!")};T.injectScript=function(n){var t=n.cdnType,o=n.isModule,i=n.theRestUrl;var u=_.getZonosUrl(t);var s="".concat(u,"/").concat(i);var a=function(){var n=document.querySelector('script[src="'.concat(s,'"]'));return!!n};if(a()){e('Zonos script "'.concat(s,'" already exists in the document'),"warn");return}var c=document.head||document.body;var l=document.createElement("script");if(!!o){l.type="module"}else{l.noModule=true}l.src=s;l.crossOrigin="anonymous";l.onerror=function(){r("Failed to load ".concat(l.src));var n=d(t);if(!n){return}_.injectScript({cdnType:n,isModule:o,theRestUrl:i})};c.appendChild(l)};T.getZonosUrl=function(n){var e=function(){switch(n){case"jsdelivr":return L;case"unpkg":return I;case"cdnjs":return F;case"vercel":return U}};if(_.isNpm){var t=v();return t||e()}return e()};T.injectZonosCdn=function(){_.injectScript({cdnType:c,isModule:true,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"});_.injectScript({cdnType:c,isModule:false,theRestUrl:"dist/zonos-elements/zonos-elements.js"});e("Zonos cdn script injected!")};T.injectStylesheet=function(n){var e=n.cdnType,t=n.theRestUrl;var o=_.getZonosUrl(e);var i=document.head||document.body;var u=document.createElement("link");u.rel="preconnect";u.href="".concat(U,"/");i.appendChild(u);var s=document.createElement("link");s.rel="stylesheet";s.href="".concat(o,"/").concat(t);s.onerror=function(){r("Failed to load ".concat(s.href));var n=d(e);if(!n){return}_.injectStylesheet({cdnType:n,theRestUrl:t})};i.appendChild(s)};T.injectZonosCss=function(){var n=function(){return!!document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')};if(n()){e("Zonos style links already injected","warn");return}_.injectStylesheet({cdnType:c,theRestUrl:"dist/zonos-elements/zonos-elements.css"});e("Zonos style css injected!")};T.injectFonts=function(){var n=function(){var n=document.querySelectorAll('link[rel="stylesheet"][href^="'.concat(A,'"]'));for(var e=0;e<n.length;e++){var t=n[e];if(!t){continue}if(E.test(t.href)){continue}return t}return null};if(n()){e("Inter font already injected","warn");return}var t=document.head||document.body;var r=document.createElement("link");r.rel="preconnect";r.href=A;t.appendChild(r);var o=document.createElement("link");o.rel="stylesheet";o.href="".concat(A,"/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");t.appendChild(o);e("Zonos font injected!")};T.setupGoogleFont=function(n){var e;void((e=_.zonosController)===null||e===void 0?void 0:e.setupGoogleFont(n))};T.injectSupportGoogleFont=function(n){var t;e("[FONT] injecting ".concat(n));var r=(t=n.match(/family=(.*?):/))===null||t===void 0?void 0:t[1];var o=document.head||document.body;if(!document.querySelector('link[rel="preconnect"][href^="'.concat(A,'"]'))){var i=document.createElement("link");i.rel="preconnect";i.href=A;o.appendChild(i)}if(document.querySelector('link[rel="stylesheet"][href="'.concat(n,'"]'))){e("[FONT] ".concat(r," font already injected"),"warn");return}var u=document.createElement("link");u.rel="stylesheet";u.href=n;o.appendChild(u);e("[FONT] ".concat(r," font injected!"))}}}}));
|