@zonos/elements 1.3.292 → 1.4.0
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/{collect-Oeo5tjN5.js → collect-DnrvaXUI.js} +24 -4
- package/dist/cjs/index.cjs.js +30 -8
- package/dist/cjs/zonos-address-completion-dialog_7.cjs.entry.js +1 -1
- package/dist/cjs/zonos-airwallex-payment.cjs.entry.js +1 -1
- package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +1 -1
- package/dist/cjs/zonos-collect.cjs.entry.js +1 -1
- package/dist/cjs/zonos-controller.cjs.entry.js +9 -0
- package/dist/collection/components/utils/checkout/injectDomesticElementHideStyle.js +9 -0
- package/dist/collection/environment.js +7 -2
- package/dist/collection/scripts/_stripe.js +23 -1
- package/dist/collection/utils/formattedCloudflareApiUrl.js +32 -14
- package/dist/collection/utils/generateCloudflareDeployUrl.js +2 -3
- package/dist/collection/utils/generateCloudflareWorkerPreviewUrl.js +51 -0
- package/dist/collection/utils/resolveCloudflareRuntime.js +15 -0
- package/dist/esm/{collect-CdrR5OBy.js → collect-Eo4gtyql.js} +24 -4
- package/dist/esm/index.js +30 -8
- package/dist/esm/zonos-address-completion-dialog_7.entry.js +1 -1
- package/dist/esm/zonos-airwallex-payment.entry.js +1 -1
- package/dist/esm/zonos-collect-finish_6.entry.js +1 -1
- package/dist/esm/zonos-collect.entry.js +1 -1
- package/dist/esm/zonos-controller.entry.js +9 -0
- package/dist/esm-es5/{collect-CdrR5OBy.js → collect-Eo4gtyql.js} +4 -2
- package/dist/esm-es5/index.js +6 -6
- package/dist/esm-es5/zonos-address-completion-dialog_7.entry.js +1 -1
- package/dist/esm-es5/zonos-airwallex-payment.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-finish_6.entry.js +1 -1
- package/dist/esm-es5/zonos-collect.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +6 -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/utils/formattedCloudflareApiUrl.d.ts +17 -11
- package/dist/types/utils/generateCloudflareDeployUrl.d.ts +2 -3
- package/dist/types/utils/generateCloudflareWorkerPreviewUrl.d.ts +17 -0
- package/dist/types/utils/resolveCloudflareRuntime.d.ts +11 -0
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-e0e9cff5.system.entry.js → p-06030d3b.system.entry.js} +6 -0
- package/dist/zonos-elements/{p-DzLNk-Pf.js → p-0mGRBGcf.js} +1 -1
- package/dist/zonos-elements/{p-552fbde1.system.entry.js → p-155ed3d3.system.entry.js} +6 -6
- package/dist/zonos-elements/{p-04bded81.system.entry.js → p-31043c2e.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-938fc1e4.entry.js → p-3a2da031.entry.js} +1 -1
- package/dist/zonos-elements/{p-b2dd7f02.system.entry.js → p-5967a1c1.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-c5bab786.entry.js → p-725e29bb.entry.js} +1 -1
- package/dist/zonos-elements/{p-c3646ae6.system.entry.js → p-7bd99479.system.entry.js} +3 -3
- package/dist/zonos-elements/{p-y7PFdTUN.system.js → p-BiR2fYOJ.system.js} +52 -52
- package/dist/zonos-elements/p-Bu9WCfUC.system.js +1 -1
- package/dist/zonos-elements/{p-DNc279vN.system.js → p-CZD8WvyY.system.js} +33 -31
- package/dist/zonos-elements/{p-6e296228.entry.js → p-ad9ff14c.entry.js} +1 -1
- package/dist/zonos-elements/p-c9d5d8f1.entry.js +1 -0
- package/dist/zonos-elements/{p-550d4eea.entry.js → p-d8b312e5.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +6 -4
- package/dist/zonos-elements/p-82595838.entry.js +0 -1
|
@@ -1,18 +1,24 @@
|
|
|
1
|
+
export type ICloudflareDeployTarget = 'pages' | 'worker';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
* Pages when Cloudflare Pages sets `CF_PAGES=1`.
|
|
4
|
+
* Otherwise a Cloudflare build is the worker. Every other build stays on the Pages preview path.
|
|
5
|
+
* `USE_OPENNEXT` is not an input.
|
|
6
|
+
*/
|
|
7
|
+
export declare const resolveCloudflareDeployTarget: ({ buildEnv, cfPages, }: {
|
|
8
|
+
buildEnv: string | undefined;
|
|
9
|
+
cfPages: string | undefined;
|
|
10
|
+
}) => ICloudflareDeployTarget;
|
|
11
|
+
/**
|
|
12
|
+
* Cloudflare API address inlined into the storefront script.
|
|
9
13
|
* @returns
|
|
10
|
-
* - `https://<
|
|
11
|
-
*
|
|
12
|
-
* - `https
|
|
14
|
+
* - `https://<label>.robert-152.workers.dev` for a non-production Worker preview
|
|
15
|
+
* - `https://zonos-elements-serverless-test.robert-152.workers.dev` for the test Worker production host
|
|
16
|
+
* - `https://<branch_name>.<project_name>.pages.dev` for a non-production Pages preview
|
|
17
|
+
* - the configured host for production, local, and GitHub Actions
|
|
13
18
|
*/
|
|
14
|
-
export declare const formattedCloudflareApiUrl: ({ branchName, inCI: _inCI, inGithubAction, inVercel: _inVercel, isVercelPreview: _isVercelPreview, url, }: {
|
|
19
|
+
export declare const formattedCloudflareApiUrl: ({ branchName, cloudflareTarget, inCI: _inCI, inGithubAction, inVercel: _inVercel, isVercelPreview: _isVercelPreview, url, }: {
|
|
15
20
|
branchName?: string;
|
|
21
|
+
cloudflareTarget: ICloudflareDeployTarget;
|
|
16
22
|
inCI: boolean;
|
|
17
23
|
inGithubAction: boolean;
|
|
18
24
|
inVercel: boolean;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate a Cloudflare Pages-style deploy URL based on the branch name and project name.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* until a matching Workers alias exists.
|
|
3
|
+
* Worker preview hosts are built separately by `generateCloudflareWorkerPreviewUrl`.
|
|
4
|
+
* This helper only builds Cloudflare Pages aliases (`<branch>.<project>.pages.dev`).
|
|
6
5
|
* @note not including https://
|
|
7
6
|
* @return {url} string
|
|
8
7
|
* @urlExample build-cloudflare-2.zonos-elements.pages.dev
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker host without a scheme.
|
|
3
|
+
* Production is `{workerName}.robert-152.workers.dev`.
|
|
4
|
+
* Preview is `{prefix}-{workerName}.robert-152.workers.dev`.
|
|
5
|
+
* A branch longer than the prefix budget becomes `{prefix}-{hash}-{workerName}`.
|
|
6
|
+
* `{workerName}` is `zonos-elements-serverless`, or `zonos-elements-serverless-test` for the test project.
|
|
7
|
+
* The label is at most 63 characters.
|
|
8
|
+
* @example feat-checkout-zonos-elements-serverless.robert-152.workers.dev
|
|
9
|
+
* @example zonos-elements-serverless-test.robert-152.workers.dev
|
|
10
|
+
*/
|
|
11
|
+
export declare const generateCloudflareWorkerPreviewUrl: ({ branchName, workerName, }: {
|
|
12
|
+
branchName: string;
|
|
13
|
+
workerName?: string;
|
|
14
|
+
}) => string;
|
|
15
|
+
export declare const cloudflareWorkerName: (isTest: boolean) => "zonos-elements-serverless" | "zonos-elements-serverless-test";
|
|
16
|
+
/** `{workerName}.robert-152.workers.dev` with no branch prefix. */
|
|
17
|
+
export declare const cloudflareWorkerHost: (workerName: string) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ICloudflareRuntime = 'other' | 'pages' | 'worker';
|
|
2
|
+
/**
|
|
3
|
+
* Pages when Cloudflare Pages sets `CF_PAGES=1`.
|
|
4
|
+
* A Cloudflare build that is not Pages is the worker.
|
|
5
|
+
* Every other build is neither.
|
|
6
|
+
* `USE_OPENNEXT` is not an input.
|
|
7
|
+
*/
|
|
8
|
+
export declare const resolveCloudflareRuntime: ({ buildEnv, cfPages, }: {
|
|
9
|
+
buildEnv: string | undefined;
|
|
10
|
+
cfPages: string | undefined;
|
|
11
|
+
}) => ICloudflareRuntime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as n}from"./p-XQfWgQLB.js";import{g as o,I as t}from"./p-HeAZDwVW.js";import{l as r}from"./p-BJmZPrZl.js";export{a as availableTestKeys}from"./p-BJmZPrZl.js";import{g as i,a as l,h as u,l as m}from"./p-DE4a-QD5.js";import{g as p,_ as w,c as f,a as v}from"./p-D5SpFsQJ.js";export{d as domesticRedirectedBtnSelector}from"./p-D5SpFsQJ.js";export{c as countryRequireShortAddressCode}from"./p-nJ6oI8-n.js";export{c as countryRequireTaxId,e as euCountryCodes,s as shipToTaxIdLabels}from"./p-Cye-evFK.js";const y=["jsdelivr","cdnjs","unpkg","vercel"],h="jsdelivr",O=e=>{const n=y.indexOf(e);return y[n+1]||null},S=()=>{const e=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||e)return null;const n=(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.292.js.zonos.com";if(!n&&(o.includes("test.")||o.includes("test-")))return o;if(!n&&["dev.demo.elements.zonos.com","dev.checkout.elements.zonos.com","dev.storybook.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!n)return null;if("dev-elements"===n)return"https://dev.elements.zonos.com";const t=`https://${n}.preview.js.zonos.com`;return r(`[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 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})),t},g="https://js.stripe.com/v3",j=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;let z=null;const b=e=>(null!==z||(z=new Promise(((n,o)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe)n(window.Stripe);else try{let t=(()=>{const e=document.querySelectorAll(`script[src^="${g}"]`);for(let n=0;n<e.length;n++){const o=e[n];if(o&&j.test(o.src))return o}return null})();t&&e?console.warn("loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used"):t||(t=(()=>{const e=document.createElement("script");e.src=`${g}`;const n=document.head||document.body;return n?(n.appendChild(e),e):(m("Expected document.body not to be null. Stripe.js requires a <body> element."),null)})()),null==t||t.addEventListener("load",(()=>{window.Stripe?n(window.Stripe):o(new Error("Stripe.js not available"))})),null==t||t.addEventListener("error",(()=>{o(new Error("Failed to load Stripe.js"))}))}catch(e){return void o(e)}else n(null)}))),z),N=Promise.resolve().then((()=>(()=>{var e,n;return"undefined"!=typeof window&&("function"==typeof(null===(e=window.Zonos)||void 0===e?void 0:e.createCartId)||"function"==typeof(null===(n=window.Zonos)||void 0===n?void 0:n.buildCartDetail))})()?b(null):null));let I=!1;N.catch((e=>{I||console.warn(e)}));const Z=async({cartId:e,retries:n})=>{const t=i(),s=o(),c=p()||void 0,d=new URLSearchParams;s.overrideShouldEnabledCustomAddress&&d.set("overrideShouldEnabledCustomAddress",s.overrideShouldEnabledCustomAddress);const{errors:l,json:a,zonosMode:m}=await u(`/api/zonos-elements/get-cart?${d.toString()}`,{body:{isTestMode:t,renewCartExpirationToken:c,tempCartUUID:e},headers:{"Content-Type":"application/json"},method:"POST"}),w=!a||l.length;return w&&n?(r("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:n}),await new Promise((e=>setTimeout(e,500))),Z({cartId:e,retries:n-1})):w?null:Object.assign(Object.assign({},a),{zonosMode:m})};var k;const R=(()=>{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})(),T=Date.now(),$="https://v1.3.292.js.zonos.com",A=R||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.292",L="https://fonts.googleapis.com",C=/^https:\/\/fonts\.googleapis\.com/;class U{}k=U,U.doneInit=!1,U.cartSettings=null,U.debug="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/),U.zonosConversionTest="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/),U._paypalMockResponse=null,U.iframeLogType="undefined"!=typeof window?new URLSearchParams(window.location.search).get("iframeLogType"):null,U.isBigCommerce=!1,U.releaseDate="1791222618677",U.isLegacyCheckout=!1,U.googleAnalyticId=null,U.googleAnalyticReady=!1,U.facebookPixelId=null,U.facebookPixelReady=!1,U.startLoadTime=T,U.domain="undefined"!=typeof window?window.location!=window.parent.location&&document.referrer||document.location.hostname:"",U.showBaseForeign="undefined"!=typeof window&&window.location.search.includes("zonosShowBaseForeign"),U.overrideUseCustomAddressForm=!1,U.isCollect=!1,U.isInvoice=!1,U.isNpm=!0,U.zonosQaUrl=null,U.zonosQaUrlApi=null,U.trackEventLogs=[],U.version="v1.3.292",U.modeAlerted=!1,U.cartData=null,U.paypal=null,U.zonosMode=null,U.IframeService=t,U.getCurrentTimestamp=()=>(new Date).getTime(),U.zonosController=null,U.loadTimeApiInfoList=[],U.logIntervalId=null,U.init=async e=>{const{appearance:n,checkoutSettings:o,currencyConverter:t,helloSettings:s,onCountryChange:c,overrideCurrencyFormat:d,storeId:a,zonosApiKey:p}=e;if(k.cartId=new URLSearchParams(window.location.search).get("tempCartUUID"),k.createCartId=null==o?void 0:o.createCartId,k.buildCartDetail=null==o?void 0:o.buildCartDetail,k.doneInit)return;if(r(`====== ZONOS DEBUG MODE: on (${k.version}) ======`),k.zonosApiKey=p,k.storeId=a,"undefined"!=typeof window&&window.parent===window&&(k.googleAnalyticReady=!0,k.facebookPixelReady=!0),k.isNpm){r("====== ZONOS LOADING FROM NPM ======");const n=S();if(n&&!window.isZonosPreview){r(`====== RE-INJECT "zonos.js" FROM PRVIEW: ${n} ======`,"info");const o=document.createElement("script");return o.src=`${n}/dist/scripts/zonos.js`,document.head.appendChild(o),o.addEventListener("load",(()=>{window.Zonos.isNpm=k.isNpm,window.Zonos.isBigCommerce=k.isBigCommerce,window.Zonos.isLegacyCheckout=k.isLegacyCheckout,window.Zonos.zonosMode=k.zonosMode,window.Zonos.init(e)})),o.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${n}`)})),void(window.isZonosPreview=!0)}if(!p&&!k.cartId)return void m("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(!k.cartData&&k.cartId){r("Initialize cart data");const e=await(async e=>{const{isDgsCartId:n,isLegacyCartId:o}=w(e);if(!o&&!n)return m("[ZONOS - loadZonos] invalid cart id"),null;const t=await Z({cartId:e,retries:5});return r("[ZONOS - loadZonos] getting temp cart data","info",t),t?(window.Zonos.storeId=t.cartData.storeId,window.Zonos.zonosApiKey=t.cartData.credentialToken,window.Zonos.zonosMode=t.zonosMode,{cartData:t.cartData,settings:t.settings,storeFavicon:t.storeFaviconUrl,storeId:t.cartData.storeId,storeLogo:t.storeLogoUrl,zonosApiKey:t.cartData.credentialToken}):(m("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process."),null)})(k.cartId);if(!e)return void m("Failed to get cart data");k.cartData=e.cartData,k.zonosApiKey=e.zonosApiKey,k.cartSettings=e.settings}const o=await(async()=>{const e=i(),n=l();if(!e&&!n||!window.Zonos.zonosApiKey)return null;if(r("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return r("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:o,json:t}=await u("/api/get-test-public-credential");if(o.length||!t)return m("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",o),null;const s=t.publicCredential;return s?(r(`[ZONOS - loadZonos] Retrieve new test public token ${s}`,"info"),s):(m("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();o&&(k.zonosApiKey=o)}const v=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");if(k.cartId&&k.cartData||v){r("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=`${f}`,document.body.appendChild(e)}r("init zonos"),k.restoreNativeBrowserFunctions(),k.injectCustomScriptForHostedCheckout(),k.injectZonosCdn(),k.injectZonosCss(),k.injectFonts(),k.injectCheckoutInternationalButton(),k.injectController({config:{appearance:n,checkoutSettings:o,currencyConverter:t,helloSettings:s,onCountryChange:c,overrideCurrencyFormat:d}}),k.doneInit=!0},U.injectCheckoutInternationalButton=()=>{if(!document.querySelector(`#${v}`)){const e=document.createElement("button");e.id=v,e.style.display="none",document.body.appendChild(e)}},U.injectCustomScriptForHostedCheckout=()=>{const e=k.cartData,n=(null==e?void 0:e.metadata)||[],o=n.find((e=>"customHeaderScript"===e.key)),t=n.find((e=>"customFooterScript"===e.key));if(window.Zonos.isLegacyCheckout&&(o||t)){if(o){r("Injecting custom header script");const e=document.createElement("script");e.textContent=o.value,document.head.appendChild(e)}if(t){r("Injecting custom footer script");const e=document.createElement("script");e.textContent=t.value,document.body.appendChild(e)}}else r("Skip injecting custom script for hosted checkout","info",{footerScript:t,headerScript:o,isLegacyCheckout:window.Zonos.isLegacyCheckout})},U.displayCurrency=()=>{const e=document.querySelector("zonos-hello");e&&e.displayCurrency()},U.triggerCheckoutInternational=async()=>{const e=document.querySelector(`#${v}`);setTimeout((()=>{e&&e.dispatchEvent(n("click"))}),10)},U.openHelloDialog=e=>{const n=document.querySelector("zonos-hello");n&&n.openHelloDialog(null==e||e)},U.showNotification=e=>{var n;null===(n=k.zonosController)||void 0===n||n.showNotification(e)},U.updateOrganizationName=e=>{var n;null===(n=k.zonosController)||void 0===n||n.updateOrganizationName(e)},U.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)}},U.restoreNativeBrowserFunctions=()=>{var e;if("1"===new URL(window.location.href).searchParams.get("useMerchantPolyfill"))return;const n="zonos---native-browser";let o=document.querySelector(`iframe#${n}`);o||(o=document.createElement("iframe"),o.id=n,o.style.display="none",o.style.opacity="0",o.style.position="absolute",o.style.top="-9999px",o.style.left="-9999px",o.style.width="1px",o.style.height="1px",o.style.border="none",o.style.overflow="hidden",o.style.visibility="hidden",document.body.appendChild(o));const t=(null===(e=o.contentWindow)||void 0===e?void 0:e.window.Array.from)||Array.from;Array.from=t,document.body.removeChild(o)},U.injectController=({config:e})=>{var n,o;if(document.querySelector("zonos-controller"))return;if(null===(n=e.checkoutSettings)||void 0===n?void 0:n.placeOrderButtonSelector){const n=e.checkoutSettings.placeOrderButtonSelector;k.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:n}),new MutationObserver((()=>{k.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:n})})).observe(document.body,{childList:!0,subtree:!0})}if(null===(o=e.checkoutSettings)||void 0===o?void 0:o.alwaysTriggerInternationalCheckoutSelector){const n=e.checkoutSettings.alwaysTriggerInternationalCheckoutSelector;k.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:n}),new MutationObserver((()=>{k.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:n})})).observe(document.body,{childList:!0,subtree:!0})}const t=document.createElement("zonos-controller");t.config=e,t.zonosApiKey=k.zonosApiKey||"",t.addEventListener("stripeInitEvent",(async e=>{const{detail:n}=e;r("loading Stripe");const o=await(async(...e)=>{var n;I=!0;const o=Date.now();return((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})(null!==(n=await N)&&void 0!==n?n:await b(null),e,o)})(n.publishableKey);o?(window.Zonos.stripe=o,window.Zonos.isCollect?t.initCollectElement(o):window.Zonos.isInvoice?t.initInvoiceElement(o):t.initCheckoutElement(o)):m("API seems to be invalid or missing. Failed to load Stripe")})),document.body.appendChild(t),k.zonosController=t,r("Zonos controller injected!")},U.injectScript=({cdnType:e,isModule:n,theRestUrl:o})=>{const t=`${k.getZonosUrl(e)}/${o}`;if(document.querySelector(`script[src="${t}"]`))return void r(`Zonos script "${t}" already exists in the document`,"warn");const s=document.head||document.body,i=document.createElement("script");n?i.type="module":i.noModule=!0,i.src=t,i.crossOrigin="anonymous",i.onerror=()=>{m(`Failed to load ${i.src}`);const t=O(e);t&&k.injectScript({cdnType:t,isModule:n,theRestUrl:o})},s.appendChild(i)},U.getZonosUrl=e=>{const n=()=>{switch(e){case"jsdelivr":return A;case"unpkg":return"https://unpkg.com/@zonos/elements@1.3.292";case"cdnjs":return"https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.3.292";case"vercel":return $}};return k.isNpm&&S()||n()},U.injectZonosCdn=()=>{k.injectScript({cdnType:h,isModule:!0,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"}),k.injectScript({cdnType:h,isModule:!1,theRestUrl:"dist/zonos-elements/zonos-elements.js"}),r("Zonos cdn script injected!")},U.injectStylesheet=({cdnType:e,theRestUrl:n})=>{const o=k.getZonosUrl(e),t=document.head||document.body,s=document.createElement("link");s.rel="preconnect",s.href=`${$}/`,t.appendChild(s);const r=document.createElement("link");r.rel="stylesheet",r.href=`${o}/${n}`,r.onerror=()=>{m(`Failed to load ${r.href}`);const o=O(e);o&&k.injectStylesheet({cdnType:o,theRestUrl:n})},t.appendChild(r)},U.injectZonosCss=()=>{document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')?r("Zonos style links already injected","warn"):(k.injectStylesheet({cdnType:h,theRestUrl:"dist/zonos-elements/zonos-elements.css"}),r("Zonos style css injected!"))},U.injectFonts=()=>{if((()=>{if(document.fonts.check("1em Inter"))return void r("Inter font already loaded","warn");const e=document.querySelectorAll(`link[rel="stylesheet"][href^="${L}"]`);for(let n=0;n<e.length;n++){const o=e[n];if(o&&!C.test(o.href))return o}return null})())return void r("Inter font already injected","warn");const e=document.head||document.body,n=document.createElement("link");n.rel="preconnect",n.href=L,e.appendChild(n);const o=document.createElement("link");o.rel="stylesheet",o.href=`${L}/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap`,e.appendChild(o),r("Zonos font injected!")},U.setupGoogleFont=e=>{var n;null===(n=k.zonosController)||void 0===n||n.setupGoogleFont(e)},U.injectSupportGoogleFont=e=>{var n;r(`[FONT] injecting ${e}`);const o=null===(n=e.match(/family=(.*?):/))||void 0===n?void 0:n[1],t=document.head||document.body;if(!document.querySelector(`link[rel="preconnect"][href^="${L}"]`)){const e=document.createElement("link");e.rel="preconnect",e.href=L,t.appendChild(e)}if(document.querySelector(`link[rel="stylesheet"][href="${e}"]`))return void r(`[FONT] ${o} font already injected`,"warn");const s=document.createElement("link");s.rel="stylesheet",s.href=e,t.appendChild(s),r(`[FONT] ${o} font injected!`)};const E=["ZONOS_FORM_TYPE_USING","APP_VERSION","APP_VERSION_NPM_INTEGRATION","LEGACY_CHECKOUT_FACADE"],D=["ORDER_DUPLICATION_CONSENT","WITH_ABANDONED_CART_TOKEN"],P=[...E,...D];export{U as Zonos,f as checkoutHiddenBtnSelector,v as checkoutHiddenInternationalBtnSelector,P as checkoutSessionAttributeKeys,D as checkoutSessionImmutableAttributeKeys,E as checkoutSessionMutableAttributeKeys}
|
|
1
|
+
import{c as n}from"./p-XQfWgQLB.js";import{g as o,I as t}from"./p-HeAZDwVW.js";import{l as r}from"./p-BJmZPrZl.js";export{a as availableTestKeys}from"./p-BJmZPrZl.js";import{g as i,a as l,h as u,l as m}from"./p-DE4a-QD5.js";import{g as p,_ as w,c as f,a as y}from"./p-D5SpFsQJ.js";export{d as domesticRedirectedBtnSelector}from"./p-D5SpFsQJ.js";export{c as countryRequireShortAddressCode}from"./p-nJ6oI8-n.js";export{c as countryRequireTaxId,e as euCountryCodes,s as shipToTaxIdLabels}from"./p-Cye-evFK.js";const v=["jsdelivr","cdnjs","unpkg","vercel"],h="jsdelivr",O=e=>{const n=v.indexOf(e);return v[n+1]||null},g=()=>{const e=window&&window.location.href.includes("forceLoadCdn");if("undefined"==typeof window||e)return null;const n=(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.4.0.js.zonos.com";if(!n&&(o.includes("test.")||o.includes("test-")))return o;if(!n&&["dev.demo.elements.zonos.com","dev.checkout.elements.zonos.com","dev.storybook.elements.zonos.com"].includes(window.location.hostname))return"https://dev.elements.zonos.com";if(!n)return null;if("dev-elements"===n)return"https://dev.elements.zonos.com";const t=`https://${n}.preview.js.zonos.com`;return r(`[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 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})),t},S="https://js.stripe.com/v3",j=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;let z=null;const b=e=>(null!==z||(z=new Promise(((n,o)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe)n(window.Stripe);else try{let t=(()=>{const e=document.querySelectorAll(`script[src^="${S}"]`);for(let n=0;n<e.length;n++){const o=e[n];if(o&&j.test(o.src))return o}return null})();t&&e?console.warn("loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used"):t||(t=(()=>{const e=document.createElement("script");e.src=`${S}`;const n=document.head||document.body;return n?(n.appendChild(e),e):(m("Expected document.body not to be null. Stripe.js requires a <body> element."),null)})()),null==t||t.addEventListener("load",(()=>{window.Stripe?n(window.Stripe):o(new Error("Stripe.js not available"))})),null==t||t.addEventListener("error",(()=>{o(new Error("Failed to load Stripe.js"))}))}catch(e){return void o(e)}else n(null)}))),z),N=Promise.resolve().then((()=>(()=>{var e,n;return"undefined"!=typeof window&&("function"==typeof(null===(e=window.Zonos)||void 0===e?void 0:e.createCartId)||"function"==typeof(null===(n=window.Zonos)||void 0===n?void 0:n.buildCartDetail))})()?b(null):null));let I=!1;N.catch((e=>{I||console.warn(e)}));const Z=async({cartId:e,retries:n})=>{const t=i(),s=o(),c=p()||void 0,d=new URLSearchParams;s.overrideShouldEnabledCustomAddress&&d.set("overrideShouldEnabledCustomAddress",s.overrideShouldEnabledCustomAddress);const{errors:l,json:a,zonosMode:m}=await u(`/api/zonos-elements/get-cart?${d.toString()}`,{body:{isTestMode:t,renewCartExpirationToken:c,tempCartUUID:e},headers:{"Content-Type":"application/json"},method:"POST"}),w=!a||l.length;return w&&n?(r("[ZONOS - loadZonos] temp cart not ready, retrying in 1 second","info",{retries:n}),await new Promise((e=>setTimeout(e,500))),Z({cartId:e,retries:n-1})):w?null:Object.assign(Object.assign({},a),{zonosMode:m})};var k;const R=(()=>{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})(),T=Date.now(),$="https://v1.4.0.js.zonos.com",A=R||"https://cdn.jsdelivr.net/npm/@zonos/elements@1.4.0",L="https://fonts.googleapis.com",C=/^https:\/\/fonts\.googleapis\.com/;class U{}k=U,U.doneInit=!1,U.cartSettings=null,U.debug="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosDebug=1/),U.zonosConversionTest="undefined"!=typeof window&&!!window.location.search.match(/\?.*(&*)zonosConversionTest/),U._paypalMockResponse=null,U.iframeLogType="undefined"!=typeof window?new URLSearchParams(window.location.search).get("iframeLogType"):null,U.isBigCommerce=!1,U.releaseDate="1792186375498",U.isLegacyCheckout=!1,U.googleAnalyticId=null,U.googleAnalyticReady=!1,U.facebookPixelId=null,U.facebookPixelReady=!1,U.startLoadTime=T,U.domain="undefined"!=typeof window?window.location!=window.parent.location&&document.referrer||document.location.hostname:"",U.showBaseForeign="undefined"!=typeof window&&window.location.search.includes("zonosShowBaseForeign"),U.overrideUseCustomAddressForm=!1,U.isCollect=!1,U.isInvoice=!1,U.isNpm=!0,U.zonosQaUrl=null,U.zonosQaUrlApi=null,U.trackEventLogs=[],U.version="v1.4.0",U.modeAlerted=!1,U.cartData=null,U.paypal=null,U.zonosMode=null,U.IframeService=t,U.getCurrentTimestamp=()=>(new Date).getTime(),U.zonosController=null,U.loadTimeApiInfoList=[],U.logIntervalId=null,U.init=async e=>{const{appearance:n,checkoutSettings:o,currencyConverter:t,helloSettings:s,onCountryChange:c,overrideCurrencyFormat:d,storeId:a,zonosApiKey:p}=e;if(k.cartId=new URLSearchParams(window.location.search).get("tempCartUUID"),k.createCartId=null==o?void 0:o.createCartId,k.buildCartDetail=null==o?void 0:o.buildCartDetail,k.doneInit)return;if(r(`====== ZONOS DEBUG MODE: on (${k.version}) ======`),k.zonosApiKey=p,k.storeId=a,"undefined"!=typeof window&&window.parent===window&&(k.googleAnalyticReady=!0,k.facebookPixelReady=!0),k.isNpm){r("====== ZONOS LOADING FROM NPM ======");const n=g();if(n&&!window.isZonosPreview){r(`====== RE-INJECT "zonos.js" FROM PRVIEW: ${n} ======`,"info");const o=document.createElement("script");return o.src=`${n}/dist/scripts/zonos.js`,document.head.appendChild(o),o.addEventListener("load",(()=>{window.Zonos.isNpm=k.isNpm,window.Zonos.isBigCommerce=k.isBigCommerce,window.Zonos.isLegacyCheckout=k.isLegacyCheckout,window.Zonos.zonosMode=k.zonosMode,window.Zonos.init(e)})),o.addEventListener("error",(()=>{alert(`[ZONOS - loadZonos] Failed to load "loadZonos.js" from zonosQaUrl: ${n}`)})),void(window.isZonosPreview=!0)}if(!p&&!k.cartId)return void m("Zonos API key is required unless `tempCartUUID` is provided in url query params.");if(!k.cartData&&k.cartId){r("Initialize cart data");const e=await(async e=>{const{isDgsCartId:n,isLegacyCartId:o}=w(e);if(!o&&!n)return m("[ZONOS - loadZonos] invalid cart id"),null;const t=await Z({cartId:e,retries:5});return r("[ZONOS - loadZonos] getting temp cart data","info",t),t?(window.Zonos.storeId=t.cartData.storeId,window.Zonos.zonosApiKey=t.cartData.credentialToken,window.Zonos.zonosMode=t.zonosMode,{cartData:t.cartData,settings:t.settings,storeFavicon:t.storeFaviconUrl,storeId:t.cartData.storeId,storeLogo:t.storeLogoUrl,zonosApiKey:t.cartData.credentialToken}):(m("[ZONOS - loadZonos] Error getting temp cart data, stop checkout process."),null)})(k.cartId);if(!e)return void m("Failed to get cart data");k.cartData=e.cartData,k.zonosApiKey=e.zonosApiKey,k.cartSettings=e.settings}const o=await(async()=>{const e=i(),n=l();if(!e&&!n||!window.Zonos.zonosApiKey)return null;if(r("[ZONOS - loadZonos] Attempt test public credential","info"),window.Zonos.zonosApiKey.includes("credential_test"))return r("[ZONOS - loadZonos] Test mode is enabled but the API key is already a test key","info"),null;const{errors:o,json:t}=await u("/api/get-test-public-credential");if(o.length||!t)return m("[ZONOS - loadZonos] Failed to get test public credential. Keep using production key",o),null;const s=t.publicCredential;return s?(r(`[ZONOS - loadZonos] Retrieve new test public token ${s}`,"info"),s):(m("[ZONOS - loadZonos] No test public key credential. Keep using production key"),null)})();o&&(k.zonosApiKey=o)}const y=new URL(window.location.href).searchParams.get("payment_intent_client_secret")||sessionStorage.getItem("zonos--client-secret");if(k.cartId&&k.cartData||y){r("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=`${f}`,document.body.appendChild(e)}r("init zonos"),k.restoreNativeBrowserFunctions(),k.injectCustomScriptForHostedCheckout(),k.injectZonosCdn(),k.injectZonosCss(),k.injectFonts(),k.injectCheckoutInternationalButton(),k.injectController({config:{appearance:n,checkoutSettings:o,currencyConverter:t,helloSettings:s,onCountryChange:c,overrideCurrencyFormat:d}}),k.doneInit=!0},U.injectCheckoutInternationalButton=()=>{if(!document.querySelector(`#${y}`)){const e=document.createElement("button");e.id=y,e.style.display="none",document.body.appendChild(e)}},U.injectCustomScriptForHostedCheckout=()=>{const e=k.cartData,n=(null==e?void 0:e.metadata)||[],o=n.find((e=>"customHeaderScript"===e.key)),t=n.find((e=>"customFooterScript"===e.key));if(window.Zonos.isLegacyCheckout&&(o||t)){if(o){r("Injecting custom header script");const e=document.createElement("script");e.textContent=o.value,document.head.appendChild(e)}if(t){r("Injecting custom footer script");const e=document.createElement("script");e.textContent=t.value,document.body.appendChild(e)}}else r("Skip injecting custom script for hosted checkout","info",{footerScript:t,headerScript:o,isLegacyCheckout:window.Zonos.isLegacyCheckout})},U.displayCurrency=()=>{const e=document.querySelector("zonos-hello");e&&e.displayCurrency()},U.triggerCheckoutInternational=async()=>{const e=document.querySelector(`#${y}`);setTimeout((()=>{e&&e.dispatchEvent(n("click"))}),10)},U.openHelloDialog=e=>{const n=document.querySelector("zonos-hello");n&&n.openHelloDialog(null==e||e)},U.showNotification=e=>{var n;null===(n=k.zonosController)||void 0===n||n.showNotification(e)},U.updateOrganizationName=e=>{var n;null===(n=k.zonosController)||void 0===n||n.updateOrganizationName(e)},U.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)}},U.restoreNativeBrowserFunctions=()=>{var e;if("1"===new URL(window.location.href).searchParams.get("useMerchantPolyfill"))return;const n="zonos---native-browser";let o=document.querySelector(`iframe#${n}`);o||(o=document.createElement("iframe"),o.id=n,o.style.display="none",o.style.opacity="0",o.style.position="absolute",o.style.top="-9999px",o.style.left="-9999px",o.style.width="1px",o.style.height="1px",o.style.border="none",o.style.overflow="hidden",o.style.visibility="hidden",document.body.appendChild(o));const t=(null===(e=o.contentWindow)||void 0===e?void 0:e.window.Array.from)||Array.from;Array.from=t,document.body.removeChild(o)},U.injectController=({config:e})=>{var n,o;if(document.querySelector("zonos-controller"))return;if(null===(n=e.checkoutSettings)||void 0===n?void 0:n.placeOrderButtonSelector){const n=e.checkoutSettings.placeOrderButtonSelector;k.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:n}),new MutationObserver((()=>{k.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:n})})).observe(document.body,{childList:!0,subtree:!0})}if(null===(o=e.checkoutSettings)||void 0===o?void 0:o.alwaysTriggerInternationalCheckoutSelector){const n=e.checkoutSettings.alwaysTriggerInternationalCheckoutSelector;k.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:n}),new MutationObserver((()=>{k.disablePlaceOrderButtons({config:e,disable:!0,placeOrderButtonSelector:n})})).observe(document.body,{childList:!0,subtree:!0})}const t=document.createElement("zonos-controller");t.config=e,t.zonosApiKey=k.zonosApiKey||"",t.addEventListener("stripeInitEvent",(async e=>{const{detail:n}=e;r("loading Stripe");const o=await(async(...e)=>{var n;I=!0;const o=Date.now();return((e,n,o)=>{if(null===e)return null;const[t,s]=n,r=Object.assign({},s),i=(e=>{if(!("version"in e))return;const{version:n}=e;return"number"==typeof n||"string"==typeof n?n:void 0})(e);"string"==typeof i&&i!==3..toString()?delete r.apiVersion:r.apiVersion="2025-02-24.acacia";const c=e(t,r);return((e,n)=>{e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",startTime:n})})(c,o),c})(null!==(n=await N)&&void 0!==n?n:await b(null),e,o)})(n.publishableKey);o?(window.Zonos.stripe=o,window.Zonos.isCollect?t.initCollectElement(o):window.Zonos.isInvoice?t.initInvoiceElement(o):t.initCheckoutElement(o)):m("API seems to be invalid or missing. Failed to load Stripe")})),document.body.appendChild(t),k.zonosController=t,r("Zonos controller injected!")},U.injectScript=({cdnType:e,isModule:n,theRestUrl:o})=>{const t=`${k.getZonosUrl(e)}/${o}`;if(document.querySelector(`script[src="${t}"]`))return void r(`Zonos script "${t}" already exists in the document`,"warn");const s=document.head||document.body,i=document.createElement("script");n?i.type="module":i.noModule=!0,i.src=t,i.crossOrigin="anonymous",i.onerror=()=>{m(`Failed to load ${i.src}`);const t=O(e);t&&k.injectScript({cdnType:t,isModule:n,theRestUrl:o})},s.appendChild(i)},U.getZonosUrl=e=>{const n=()=>{switch(e){case"jsdelivr":return A;case"unpkg":return"https://unpkg.com/@zonos/elements@1.4.0";case"cdnjs":return"https://cdnjs.cloudflare.com/ajax/libs/zonos-elements/1.4.0";case"vercel":return $}};return k.isNpm&&g()||n()},U.injectZonosCdn=()=>{k.injectScript({cdnType:h,isModule:!0,theRestUrl:"dist/zonos-elements/zonos-elements.esm.js"}),k.injectScript({cdnType:h,isModule:!1,theRestUrl:"dist/zonos-elements/zonos-elements.js"}),r("Zonos cdn script injected!")},U.injectStylesheet=({cdnType:e,theRestUrl:n})=>{const o=k.getZonosUrl(e),t=document.head||document.body,s=document.createElement("link");s.rel="preconnect",s.href=`${$}/`,t.appendChild(s);const r=document.createElement("link");r.rel="stylesheet",r.href=`${o}/${n}`,r.onerror=()=>{m(`Failed to load ${r.href}`);const o=O(e);o&&k.injectStylesheet({cdnType:o,theRestUrl:n})},t.appendChild(r)},U.injectZonosCss=()=>{document.querySelector('link[rel="stylesheet"][href*="/dist/zonos-elements/zonos-elements.css"]')?r("Zonos style links already injected","warn"):(k.injectStylesheet({cdnType:h,theRestUrl:"dist/zonos-elements/zonos-elements.css"}),r("Zonos style css injected!"))},U.injectFonts=()=>{if((()=>{if(document.fonts.check("1em Inter"))return void r("Inter font already loaded","warn");const e=document.querySelectorAll(`link[rel="stylesheet"][href^="${L}"]`);for(let n=0;n<e.length;n++){const o=e[n];if(o&&!C.test(o.href))return o}return null})())return void r("Inter font already injected","warn");const e=document.head||document.body,n=document.createElement("link");n.rel="preconnect",n.href=L,e.appendChild(n);const o=document.createElement("link");o.rel="stylesheet",o.href=`${L}/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap`,e.appendChild(o),r("Zonos font injected!")},U.setupGoogleFont=e=>{var n;null===(n=k.zonosController)||void 0===n||n.setupGoogleFont(e)},U.injectSupportGoogleFont=e=>{var n;r(`[FONT] injecting ${e}`);const o=null===(n=e.match(/family=(.*?):/))||void 0===n?void 0:n[1],t=document.head||document.body;if(!document.querySelector(`link[rel="preconnect"][href^="${L}"]`)){const e=document.createElement("link");e.rel="preconnect",e.href=L,t.appendChild(e)}if(document.querySelector(`link[rel="stylesheet"][href="${e}"]`))return void r(`[FONT] ${o} font already injected`,"warn");const s=document.createElement("link");s.rel="stylesheet",s.href=e,t.appendChild(s),r(`[FONT] ${o} font injected!`)};const E=["ZONOS_FORM_TYPE_USING","APP_VERSION","APP_VERSION_NPM_INTEGRATION","LEGACY_CHECKOUT_FACADE"],D=["ORDER_DUPLICATION_CONSENT","WITH_ABANDONED_CART_TOKEN"],P=[...E,...D];export{U as Zonos,f as checkoutHiddenBtnSelector,y as checkoutHiddenInternationalBtnSelector,P as checkoutSessionAttributeKeys,D as checkoutSessionImmutableAttributeKeys,E as checkoutSessionMutableAttributeKeys}
|
|
@@ -47,6 +47,12 @@ return T(n).map((function(t){return"body.z-intl ".concat(t)})).join(", ")};
|
|
|
47
47
|
* also the selector we validate — see [[buildDomesticHideSelector]] for the
|
|
48
48
|
* `:is()`-support branching.
|
|
49
49
|
*/var L=function(t){if(typeof document==="undefined"||!t){return}var n=P({merchantSelector:t,supportsIs:E});
|
|
50
|
+
// A raw `<` is never a valid CSS selector character, and it is the
|
|
51
|
+
// character that would close a `<style>` tag if this string were ever
|
|
52
|
+
// assigned as HTML. Some parsers (current jsdom) do not throw on it, so
|
|
53
|
+
// reject it before `querySelector`. `>` stays allowed: it is the child
|
|
54
|
+
// combinator.
|
|
55
|
+
if(n.includes("<")){_('Skip domesticElementSelector injection: "'.concat(t,'" contains "<"'),"warn");return}
|
|
50
56
|
// The browser's own parser is the source of truth — `document.querySelector`
|
|
51
57
|
// throws `DOMException(SyntaxError)` for syntactically invalid selectors.
|
|
52
58
|
// Validating the exact string we're about to emit catches both malformed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as n,z as e}from"./p-W82paT5F.js";import{t,l as r,s as i}from"./p-clDfq9AL.js";import{l as o,h as a,s}from"./p-DE4a-QD5.js";import{l as u,b as c}from"./p-BJmZPrZl.js";import{d as l,Y as d,b as f,a0 as v}from"./p-FRWZayxL.js";function m(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function p(n,e,t,r,i,o,a){try{var s=n[o](a),u=s.value}catch(n){return void t(n)}s.done?e(u):Promise.resolve(u).then(r,i)}function h(n){return function(){var e=this,t=arguments;return new Promise((function(r,i){var o=n.apply(e,t);function a(n){p(o,r,i,a,s,"next",n)}function s(n){p(o,r,i,a,s,"throw",n)}a(void 0)}))}}function y(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}function w(n,e){return e&&function(n,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}(n.prototype,e),n}function g(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function b(n,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](n):n instanceof e}function k(n){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter((function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})))),r.forEach((function(e){g(n,e,t[e])}))}return n}function x(n,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):function(n){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(n);e.push.apply(e,t)}return e}(Object(e)).forEach((function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(e,t))})),n}function E(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var t=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=t){var r,i,o=[],a=!0,s=!1;try{for(t=t.call(n);!(a=(r=t.next()).done)&&(o.push(r.value),o.length!==e);a=!0);}catch(n){s=!0,i=n}finally{try{a||null==t.return||t.return()}finally{if(s)throw i}}return o}}(n,e)||N(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(n){return function(n){if(Array.isArray(n))return m(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||N(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(n){return n&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n}function N(n,e){if(n){if("string"==typeof n)return m(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?m(n,e):void 0}}function C(n,e){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(n,a)}catch(n){o=[6,n],r=0}finally{t=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var T,D,P,R,O,j=function(n){return n.production="prod",n.demo="demo",n.staging="staging",n}(j||{}),_="airTracker_unknown",A={appName:_,appVersion:_,env:"staging",isWebappContainer:!1,delay:2e3,errorRepeatTime:3,enableErrorMonitoring:!1,assetSpeedMonitoringWhiteList:[],enableDetectPageChange:!1,enableRecordPageRetention:!1,hideSearchParams:!1,useSessionStorageForSessionId:!1,assetSpeedMonitoringWhiteListByMFE:{}},L={appName:_,env:"staging",sessionId:_,deviceId:_},U=function(){var n=new WeakSet;return function(e,t){if(b(t,Error))return"Error.message: ".concat(t.message," \n Error.stack: ").concat(t.stack);if("object"===(void 0===t?"undefined":S(t))&&null!==t){if(n.has(t))return"[Circular ".concat(e||"root","]");n.add(t)}return"function"==typeof t?"function":"symbol"===(void 0===t?"undefined":S(t))?"symbol":void 0===t?null:t}},F=function(n){if("string"==typeof n)return n;try{return b(n,Error)?(JSON.stringify(n,U())||"undefined").replace(/"/gim,""):JSON.stringify(n,U())}catch(n){return'{"error":"error happen when airTracker stringify"}'}},M=function(n){var e=n.method,t=void 0===e?"post":e,r=n.url,i=n.data,o=n.success,a=n.fail;if((s=i)&&!/^\s*$/.test(s)&&(s=(s=(s=s.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@")).replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]")).replace(/(?:^|:|,)(?:\s*\[)+/g,""),/^[\],:{}\s]*$/.test(s))){var s,u=new XMLHttpRequest;u.addEventListener("readystatechange",(function(){4===u.readyState&&(u.status>=400||0===u.status?null==a||a(u.response):null==o||o(u.response))})),u.open(t,r),u.setRequestHeader("Content-Type","application/json"),u.send(i)}},K="onCommonUpdated",q="AIR_ANALYTICS_DEVICE_ID",H="AIR_ANALYTICS_SESSION_ID",z=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(n){var e=16*Math.random()|0;return("x"===n?e:3&e|8).toString(16)}))},B=function(n){var e,t,r;return n.config.getMFEName?n.config.getMFEName():(null===(r=location)||void 0===r||null===(t=r.pathname)||void 0===t||null===(e=t.split("/"))||void 0===e?void 0:e[2])||"unknown"},W=function(n){return"string"==typeof n?n.split("?")[1]||"":n},X=function(n){return"string"==typeof n&&n.startsWith("//")?"undefined"!=typeof location&&"https:"===location.protocol:/^https/.test(n)},V=function(n){return"number"==typeof n||"string"==typeof n?n:-1},G=function(n,e){var t,r=!1;if(!e.config.isWebappContainer)return J(n,e.config.assetSpeedMonitoringWhiteList);var i=B(e);return r||J(n,null===(t=e.config.assetSpeedMonitoringWhiteListByMFE)||void 0===t?void 0:t[i])},J=function(n,e){if(!(null==e?void 0:e.length))return!1;for(var t=0;t<e.length;t++){var r=e[t];if(b(r,RegExp)&&r.test(n))return!0;if("string"==typeof r&&n.includes(r))return!0}return!1},$=function(n,e){return Math.round(100*(n-e))/100},Q=function(n){return function(e){var t,r,i=B(n),o=n.config.isWebappContainer?k({},n.commonData||{},(null===(t=n.MFECommonDataMap)||void 0===t?void 0:t[i])||{}):n.commonData,a=Array.isArray(e)?e:[e];if(0!==a.length){var s,u=F({commonData:o,data:a}),c={method:"post",url:(s=n.commonData.env,"prod"==s?"https://o11y.airwallex.com/airtracker/logs":"demo"==s?"https://o11y-demo.airwallex.com/airtracker/logs":"https://o11y-staging.airwallex.com/airtracker/logs"),data:u};"function"==typeof(null===(r=navigator)||void 0===r?void 0:r.sendBeacon)&&navigator.sendBeacon(c.url,u)||M(c)}}},Y=function(n){return function(e){var t,r,i,o=B(n),a={commonData:n.config.isWebappContainer?k({},n.commonData||{},(null===(t=n.MFECommonDataMap)||void 0===t?void 0:t[o])||{}):n.commonData,data:Array.isArray(e)?e:[e]},s=F(a),u={method:"post",url:(i=n.commonData.env,"prod"==i?"https://o11y.airwallex.com/airtracker/metrics":"demo"==i?"https://o11y-demo.airwallex.com/airtracker/metrics":"https://o11y-staging.airwallex.com/airtracker/metrics"),data:s};"function"==typeof(null===(r=navigator)||void 0===r?void 0:r.sendBeacon)&&navigator.sendBeacon(u.url,s)||M(u)}},Z=function(n,e){var t,r=[],i=n.config;return window.addEventListener("beforeunload",(function(){r.length>0&&(n.immediateSendPipe(r.splice(0,r.length)),t&&clearTimeout(t))})),function(o,a){if(r.push(o),n.lifeCycle.on(K,(function(){r.length>0&&(null==a||a(r.splice(0,r.length)),n.lifeCycle.remove(K),t&&clearTimeout(t))})),r.length>=e)return null==a||a(r.splice(0,r.length)),void(t&&clearTimeout(t));t&&clearTimeout(t),t=setTimeout((function(){t=null,r.length>0&&(null==a||a(r.splice(0,r.length)),n.lifeCycle.remove(K))}),i.delay)}},nn=function(){},en=function(n){if(!n||!n.reduce||!n.length)throw new TypeError("createPipeline need at least one function param");return 1===n.length?function(e,t){n[0](e,t||nn)}:n.reduce((function(n,e){return function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nn;return n(t,(function(n){return null==e?void 0:e(n,r)}))}}))},tn=function(){function n(){var e=this;y(this,n),this.emit=function(n,t){if(e){var r,i=e.eventsList[n];if(null==i?void 0:i.length){i=i.slice();for(var o=0;o<i.length;o++){r=i[o];try{var a=r.callback.apply(e,[t]);if(1===r.type&&e.remove(n,r.callback),!1===a)break}catch(n){throw n}}}return e}},this.eventsList={}}return w(n,[{key:"indexOf",value:function(n,e){for(var t=0;t<n.length;t++)if(n[t].callback===e)return t;return-1}},{key:"on",value:function(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(this){var r=this.eventsList[n];return r||(this.eventsList[n]=[],r=this.eventsList[n]),-1===this.indexOf(r,e)?(r.push({name:n,type:t||0,callback:e}),this):this}}},{key:"one",value:function(n,e){this.on(n,e,1)}},{key:"remove",value:function(n,e){if(this){var t=this.eventsList[n];if(!t)return null;if(!e){try{delete this.eventsList[n]}catch(n){}return null}if(t.length){var r=this.indexOf(t,e);t.splice(r,1)}return this}}},{key:"clear",value:function(){this.eventsList={}}}]),n}(),rn=function(){function n(e){y(this,n),this.name="",this.isInit=!1,this.name=e.name,this.option=e}return w(n,[{key:"patch",value:function(n){var e,t;this.isInit||(this.isInit=!0,null===(t=this.option)||void 0===t||null===(e=t.setUp)||void 0===e||e.call(this.option,n))}},{key:"uninstall",value:function(){var n,e;null===(e=this.option)||void 0===e||null===(n=e.destroy)||void 0===n||n.apply(this),this.isInit=!1}}]),n}(),on=function(n){var e="".concat(F(n.message)||""," @ (").concat(F(n.filename)||"",":").concat(n.lineno||0,":").concat(n.colno||0,")\n").concat(F(n.error||""));T.normalLogPipeLine({severity:"autoDetectError",eventName:"windowOnError",extraInfo:{error:e}})},an=function(n){var e=n&&F(n.reason);T.normalLogPipeLine({severity:"autoDetectError",eventName:"promiseError",extraInfo:{error:e}})},sn=function(n){var e=(null==n?void 0:n.target)||(null==n?void 0:n.srcElement);if(e){var t=(null==e?void 0:e.src)||(null==e?void 0:e.href),r=e.tagName,i="unknown";if("string"==typeof t&&r){if(window.location.href.indexOf(t)>-1)return;if(/\.js$/.test(t))i="script";else if(/\.css$/.test(t))i="css";else switch(r.toLowerCase()){case"script":i="script";break;case"link":i="css";break;case"img":i="image";break;case"audio":case"video":i="media";break;default:return}T.normalLogPipeLine({severity:"autoDetectError",eventName:"staticFileLoadError",extraInfo:{staticFileType:i,error:"".concat(r," load fail: ").concat(t)}})}}},un=new rn({name:"errorDetectionPlugin",setUp:function(n){T=n,window.addEventListener("error",on),window.addEventListener("unhandledrejection",an),window.document.addEventListener("error",sn,!0)},destroy:function(){window.removeEventListener("unhandledrejection",an),window.document.removeEventListener("error",sn,!0),window.removeEventListener("error",on)}}),cn=["img","css","script","link","audio","video","iframe"],ln="resource",dn=function(n){var e,t=n.name;return{url:(e=t,"string"==typeof e?(e.split("?")[0]||"").slice(0,200):e),method:"get",duration:Number(n.duration.toFixed(2)),type:"static",isHttps:X(t),urlQuery:W(t),domainLookup:V(n.domainLookupEnd-n.domainLookupStart),connectTime:V(n.connectEnd-n.connectStart)}},fn=function(n,e){for(var t=0,r=n.length;t<r;t++){var i=n[t];-1!==cn.indexOf(i.initiatorType)&&G(i.name,e)&&e.normalLogPipeLine({severity:"performance",eventName:"assets_speed",extraInfo:{log:dn(i)}})}},vn=new rn({name:"assetsSpeedPlugin",setUp:function(n){if(void 0!==window.performance&&"function"==typeof window.performance.clearResourceTimings&&"function"==typeof window.performance.getEntriesByType&&"function"==typeof window.performance.now){var e=0;window.performance.onresourcetimingbufferfull=function(){e=0,window.performance.clearResourceTimings()},"function"==typeof window.PerformanceObserver?(fn(window.performance.getEntriesByType(ln),n),(P=new window.PerformanceObserver((function(e){fn(e.getEntries(),n)}))).observe({entryTypes:[ln]})):D=setInterval((function(){var t=window.performance.getEntriesByType(ln),r=t.slice(e);e=t.length,fn(r,n)}),3e3)}},destroy:function(){null==P||P.disconnect(),D&&clearInterval(D)}}),mn=new rn({name:"onPageChangePlugin",setUp:function(){var n=h((function(n){var e,t,r,i;return C(this,(function(){return t=null===(e=location)||void 0===e?void 0:e.href,r=document.querySelector("body"),i=function(e){var t,r,i,o,a;n.normalLogPipeLine({severity:"autoDetectEvent",eventName:"onPageChange",extraInfo:{prevHref:e.prevHref,href:(null===(t=location)||void 0===t?void 0:t.href)||"",hostname:null===(r=location)||void 0===r?void 0:r.hostname,pathName:null===(i=location)||void 0===i?void 0:i.pathname,protocol:null===(o=location)||void 0===o?void 0:o.protocol,search:null===(a=location)||void 0===a?void 0:a.search}})},i({prevHref:""}),(R=new MutationObserver((function(){if(location.href!==t){var n=t;t=location.href,i({prevHref:n})}}))).observe(r||document,{subtree:!0,childList:!0}),[2]}))}));return function(e){return n.apply(this,arguments)}}(),destroy:function(){null==R||R.disconnect()}}),pn=new rn({name:"onPageRetentionPlugin",setUp:function(){var n=h((function(n){var e,t,r,i,o,a;return C(this,(function(){return void 0===document.visibilityState||(t=null===(e=location)||void 0===e?void 0:e.href,r=document.querySelector("body"),(o=function(){i=Date.now()})(),document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState?a({href:location.href,leftReason:"visibilityChange"}):"visible"===document.visibilityState&&o()})),window.addEventListener("beforeunload",(function(){a({href:location.href,sendImmediate:!0,leftReason:"pageClose"})})),a=function(e){var t=e.href,r=e.sendImmediate,o=e.leftReason;if(i){var a=Date.now()-i;if(0!==a){i=void 0;var s={severity:"autoDetectEvent",eventName:"onPageRetention",extraInfo:{href:t,duration:a,leftReason:o}};r?n.ImmediatePipeline(s):n.normalLogPipeLine(s)}}},(O=new MutationObserver((function(){if(location.href!==t){var n=t;t=location.href,a({href:n,leftReason:"nextPage"}),o()}}))).observe(r||document,{subtree:!0,childList:!0})),[2]}))}));return function(e){return n.apply(this,arguments)}}(),destroy:function(){null==O||O.disconnect()}}),hn=function(){return Date.now().toString(36)+Math.random().toString(36).substring(2,15)},yn=function(n,e){return![/authenticate\/heartbeat/,/papluginlogs\/.*/,/airtracker\/.*/,/o11y(-staging|-demo)?\.airwallex\.com/,/\.(png|jpe?g|gif|svg|ico|webp|avif|css|js|json|woff2?|ttf|eot|map|txt|csv|xml)(\?.*)?(#.*)?$/i].some((function(e){return e.test(n)}))&&J(n,e||[/^https?:\/\/[^\/]*\.airwallex\.com($|\/)/])},wn=function(n){return Math.round(100*n)/100},gn=function(n,e){var t,r,i,o,a,s,u,c,l,d,f,v,m,p,h,y,w,g,b,E=n.url,I=n.method,S=n.errorType,N=n.errorDetail,C=function(n){var e=n.startTime,t=n.endTime,r=n.entries;if(0!==r.length){if(1===r.length)return r[0];var i=r.filter((function(n){return n.startTime>=e&&t&&n.responseEnd<=t})).sort((function(n,e){return n.startTime-e.startTime}));return null==i?void 0:i[0]}}(n),T=new URL(E,window.location.href),D=T.href,P=T.protocol,R=C?(i=(t=C).duration,o=t.responseStart,a=t.connectEnd,s=t.connectStart,u=t.domainLookupEnd,c=t.domainLookupStart,l=t.requestStart,d=t.secureConnectionStart,f=t.redirectEnd,v=t.redirectStart,m=t.responseStatus,p=t.responseEnd,h=t.encodedBodySize,y=t.decodedBodySize,w=t.transferSize,g=t.deliveryType,b=t.initiatorType,{startTime:wn(r=t.startTime),totalDuration:wn(i),timeToFirstByte:$(o,r),tcpDuration:$(a,s),dnsDuration:$(u,c),tlsDuration:$(l,d),redirectDuration:$(f,v),responseDuration:$(p,o),encodeResponseSize:h,decodeResponseSize:y,transferSize:w,deliveryType:g,statusCode:m,initiatorType:b}):{};return{severity:"autoDetectEvent",eventName:"httpClientMetrics",extraInfo:k(x(k({httpUrl:D,method:I,scheme:P},S&&{errorType:S},N&&{errorDetail:N},R),{statusCode:(null==R?void 0:R.statusCode)||(null==n?void 0:n.responseStatus),startTime:(null==R?void 0:R.startTime)||(null==n?void 0:n.startTime),initiatorType:(null==R?void 0:R.initiatorType)||(null==n?void 0:n.initiatorType)}),e)}},bn=function(n){return n&&"object"===(void 0===n?"undefined":S(n))&&"errors"in n&&Array.isArray(n.errors)&&n.errors.every((function(n){return n&&"object"===(void 0===n?"undefined":S(n))&&"message"in n}))},kn="awx_airtracker_api_performance_queue",xn="awx_airtracker_api_performance_plugin_loaded",En="undefined"!=typeof window?window:"undefined"!=typeof global?global:{};En[kn]=En[kn]||[];var In=function(n,e,t){setTimeout((function(){var r=gn(n,t);e.observerPipeline(r),En[kn]=En[kn].filter((function(e){return e.id!==n.id}))}),300)},Sn=function(n,e){setTimeout((function(){var t=En[kn].find((function(e){return e.id===n}));if(t){var r=gn(t,{exceptionType:"timeout-without-response"});e.observerPipeline(r),En[kn]=En[kn].filter((function(e){return e.id!==n}))}}),1e4)},Nn=new rn({name:"apiPerformancePlugin",setUp:function(){var n=h((function(n){var e,t;return C(this,(function(){return En[xn]||(null===(e=n.config)||void 0===e?void 0:e.enableRecordAPIPerformance)&&Math.random()<((null===(t=n.config)||void 0===t?void 0:t.enableRecordAPIPerformancePercentage)||0)&&(En[xn]=!0,function(n){var e;(function(n){var e=XMLHttpRequest.prototype.open,t=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(t,r,i,o,a){try{var s,u=hn();this.__requestId=u;var c=b(r,URL)?r.href:new URL(r,window.location.href).href;if(!yn(c,null===(s=n.config)||void 0===s?void 0:s.enableRecordAPIPerformanceWhitelist))return e.call(this,t,r,null==i||i,o,a);var l={id:u,startTime:performance.now(),method:t,url:c,entries:[],initiatorType:"xmlhttprequest"};return En[kn].push(l),Sn(u,n),e.call(this,t,r,null==i||i,o,a)}catch(s){return n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"Inject XHR open error",error:s}}),e.call(this,t,r,null==i||i,o,a)}},XMLHttpRequest.prototype.send=function(){for(var e=this,r=arguments.length,i=new Array(r),o=0;o<r;o++)i[o]=arguments[o];try{var a=En[kn].find((function(n){return n.id===e.__requestId}));if(!a)return t.apply(this,i);var s=this;return this.addEventListener("loadend",h((function(){var e,t,r,i,o,u,c;return C(this,(function(l){switch(l.label){case 0:if(e=performance.now(),t=e-a.startTime,0===(r=s.status))return[2];a.endTime=e,a.duration=t,a.responseStatus=r,l.label=1;case 1:return l.trys.push([1,6,,7]),""!==s.responseType&&"text"!==s.responseType?[3,2]:(i=s.responseText,[3,5]);case 2:return"json"!==s.responseType?[3,3]:(i=s.response,[3,5]);case 3:return"blob"!==s.responseType||"application/json"!==(null==(o=s.response)?void 0:o.type)?[3,5]:[4,o.text()];case 4:i=l.sent(),l.label=5;case 5:return(u=i&&"string"==typeof i?JSON.parse(i):i)&&bn(u)&&(a.errorType="graphqlError",a.errorDetail=u.errors),[3,7];case 6:return c=l.sent(),n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"Parse response body error in XHR",url:null==a?void 0:a.url,error:c}}),[3,7];case 7:return In(a,n),[2]}}))}))),this.addEventListener("error",(function(){In(a,n,{exceptionType:"network-error"})})),this.addEventListener("abort",(function(){In(a,n,{exceptionType:"abort-error"})})),this.addEventListener("timeout",(function(){In(a,n,{exceptionType:"timeout-error"})})),t.apply(this,i)}catch(e){throw n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"InjectXHR send error",error:e}}),e}}})(n),function(n){var e=window.fetch;window.fetch=h((function(){var t,r,i,o,a,s,u,c,l,d,f,v,m,p,h,y,w=arguments;return C(this,(function(g){switch(g.label){case 0:for(t=w.length,r=new Array(t),i=0;i<t;i++)r[i]=w[i];return s=new URL(b(r[0],Request)?r[0].url:String(r[0]),window.location.href).href,yn(s,null===(o=n.config)||void 0===o?void 0:o.enableRecordAPIPerformanceWhitelist)?[3,2]:[4,e.apply(this,r)];case 1:return[2,g.sent()];case 2:return g.trys.push([2,9,,10]),c=performance.now(),l=hn(),a={id:l,startTime:c,method:(null===(u=b(r[0],Request)?r[0]:r[1])||void 0===u?void 0:u.method)||"GET",url:s,entries:[],initiatorType:"fetch"},En[kn].push(a),Sn(l,n),[4,e.apply(this,r)];case 3:d=g.sent(),f=performance.now(),a.endTime=f,a.duration=f-c,a.responseStatus=d.status,v=d.clone(),g.label=4;case 4:return g.trys.push([4,7,,8]),v.ok?[4,v.json()]:[3,6];case 5:(m=g.sent())&&bn(m)&&(a.errorType="graphqlError",a.errorDetail=m.errors),g.label=6;case 6:return[3,8];case 7:return p=g.sent(),n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"Parse response body error in fetch",url:null==a?void 0:a.url,error:p}}),[3,8];case 8:return In(a,n),[2,d];case 9:throw h=g.sent(),a&&a.id&&En[kn].find((function(n){return n.id===(null==a?void 0:a.id)}))?(y="fetch-error",b(h,TypeError)?y="network-error":b(h,DOMException)&&"AbortError"===h.name&&(y="abort-error"),In(a,n,{exceptionType:y})):n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"Inject fetch error",error:h}}),h;case 10:return[2]}}))}))}(n),(null===(e=window)||void 0===e?void 0:e.PerformanceObserver)?new window.PerformanceObserver((function(n){n.getEntries().forEach((function(n){var e=n;"fetch"!==e.initiatorType&&"xmlhttprequest"!==e.initiatorType||En[kn].filter((function(n){return n.url===e.name})).forEach((function(n){n.entries.push(e)}))}))})).observe({entryTypes:["resource"],buffered:!0}):n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{error:"PerformanceObserver Not Supported"}})}(n)),[2]}))}));return function(e){return n.apply(this,arguments)}}()}),Cn=function(){function n(e){var t,r,i=this,o=e.config,a=e.plugins,s=void 0===a?[]:a;y(this,n),this.config=A,this.lifeCycle=new tn,this.plugins=[],this._commonData=L,this._MFECommonDataMap={},this.timeMap={},this.packedDataConvert=function(n){var e,t,r=n.extraInfo,o=k({severity:n.severity,eventName:n.eventName,currentHref:i.config.hideSearchParams?((null===(e=location)||void 0===e?void 0:e.href)||"").split("?")[0]||"":(null===(t=location)||void 0===t?void 0:t.href)||""},r);return i.config.isWebappContainer&&(o.MFEName=B(i)),o},this.normalPipelineObj=en([Z(this,8),(t=this,r={},function(n,e){var i="number"==typeof t.config.errorRepeatTime?t.config.errorRepeatTime:5;if(0===i)return null==e?void 0:e(n);null==e||e(n.filter((function(n){return"autoDetectError"!=n.severity||(r[n.error]=r[n.error]||0,r[n.error]+=1,!(r[n.error]>i))})))}),Q(this)]),this.observerPipelineObj=en([Z(this,8),Y(this)]),this.immediateSendPipe=Q(this),this.observerPipeline=function(n){var e=i.packedDataConvert({severity:n.severity,eventName:n.eventName,extraInfo:n.extraInfo});return i.observerPipelineObj(e)},this.normalLogPipeLine=function(n){var e=i.packedDataConvert({severity:n.severity,eventName:n.eventName,extraInfo:n.extraInfo});return i.config.disableThrottle?i.immediateSendPipe(e):i.normalPipelineObj(e)},this.ImmediatePipeline=function(n){var e=i.packedDataConvert({severity:n.severity,eventName:n.eventName,extraInfo:n.extraInfo});return i.immediateSendPipe(e)},this.plugins=I(s),this.setConfig(o),this.initCommonData(o),this.lifeCycle.emit("onInit"),o.enableErrorMonitoring&&this.plugins.push(un),((null==o?void 0:o.assetSpeedMonitoringWhiteList)&&o.assetSpeedMonitoringWhiteList.length>0||o.isWebappContainer)&&this.plugins.push(vn),(null==o?void 0:o.enableDetectPageChange)&&this.plugins.push(mn),(null==o?void 0:o.enableRecordPageRetention)&&this.plugins.push(pn),(null==o?void 0:o.enableRecordAPIPerformance)&&(null==o?void 0:o.enableRecordAPIPerformancePercentage)&&o.enableRecordAPIPerformancePercentage>0&&o.enableRecordAPIPerformancePercentage<=1&&this.plugins.push(Nn),this.installPlugins()}return w(n,[{key:"installPlugins",value:function(){var n=this;this.plugins.forEach((function(e){e.patch(n)}))}},{key:"commonData",get:function(){return this._commonData}},{key:"MFECommonDataMap",get:function(){return this._MFECommonDataMap}},{key:"initCommonData",value:function(n){this._commonData.sessionId=n.useSessionStorageForSessionId?function(){try{var n=window.sessionStorage.getItem(H);return n||(n=z(),window.sessionStorage.setItem(H,n)),n}catch(n){return z()}}():z(),this._commonData.deviceId=function(){try{var n=window.localStorage.getItem(q);return n||(n=z(),window.localStorage.setItem(q,n)),n}catch(n){}}()||_,this._commonData.riskDeviceId=function(){try{return window.localStorage.getItem("AWX_RISK_ID")||void 0}catch(n){}}(),this._commonData.networkType=function(){var n,e,t="",r=navigator.userAgent.match(/NetType\/(\w+)/);if(r)t=E(r,2)[1];else if(null===(n=navigator)||void 0===n?void 0:n.connection){var i,o,a,s;t=(null===(o=navigator)||void 0===o||null===(i=o.connection)||void 0===i?void 0:i.effectiveType)||(null===(s=navigator)||void 0===s||null===(a=s.connection)||void 0===a?void 0:a.type)}return t||(t="unknown"),e=t,(e=String(e).toLowerCase()).indexOf("4g")>=0?"net4g":e.indexOf("wifi")>=0?"wifi":e.indexOf("5g")>=0?"net5g":e.indexOf("3g")>=0?"net3g":e.indexOf("2g")>=0?"net2g":"unknown"}()||"unknown",this._commonData.env=n.env||this._commonData.env,this._commonData.accountId=n.accountId||_,this._commonData.appVersion=n.appVersion,this._commonData.appName=n.appName,this._commonData.sdkVersion="3.1.0",this.lifeCycle.emit("onCommonDataInit",this.commonData)}},{key:"updateCommonDataBasedOnConfig",value:function(n){this.lifeCycle.emit(K,this._commonData),this._commonData.env=n.env||this._commonData.env,this._commonData.appName=n.appName||this._commonData.appName,this._commonData.env=n.env||this._commonData.env,this._commonData.accountId=n.accountId||this._commonData.accountId,this._commonData.appVersion=n.appVersion||this._commonData.appVersion}},{key:"updateCommonData",value:function(n){this.lifeCycle.emit(K,this._commonData),this._commonData=k({},this._commonData,n)}},{key:"removeCommonDataByKey",value:function(n){var e=this;this.lifeCycle.emit(K,this._commonData),setTimeout((function(){n.forEach((function(n){delete e._commonData[n]}))}),1e3)}},{key:"addToMFECommonData",value:function(n){var e,t=n.MFEName,r=n.MFECommonData;this.config.isWebappContainer&&t&&r&&(this._MFECommonDataMap=x(k({},this._MFECommonDataMap||{}),g({},t,k({},(null===(e=this._MFECommonDataMap)||void 0===e?void 0:e[t])||{},r))))}},{key:"setConfig",value:function(n){var e=this;this.config.isWebappContainer||(Object.entries(n).forEach((function(n){var t=E(n,2),r=t[0],i=t[1];void 0!==(void 0===i?"undefined":S(i))&&function(n,t){e.config[n]=t}(r,i)})),this.lifeCycle.emit("onConfigInit",this.config),this.updateCommonDataBasedOnConfig(n))}},{key:"verbose",value:function(n,e){this.normalLogPipeLine({severity:"verbose",eventName:n,extraInfo:e})}},{key:"httpLog",value:function(n,e){this.normalLogPipeLine({severity:"http",eventName:n,extraInfo:e})}},{key:"info",value:function(n,e){this.normalLogPipeLine({severity:"info",eventName:n,extraInfo:e})}},{key:"warn",value:function(n,e){this.normalLogPipeLine({severity:"warn",eventName:n,extraInfo:e})}},{key:"error",value:function(n,e){console.error("error",n),this.normalLogPipeLine({severity:"error",eventName:n,extraInfo:e})}},{key:"businessLog",value:function(n,e){this.normalLogPipeLine({severity:"info",eventName:n,extraInfo:x(k({},e),{isBusinessLog:!0})})}},{key:"reportDuration",value:function(n,e,t){"string"==typeof n?"number"==typeof e?e<0||e>6e4?console.warn("reportDuration: duration (second param) must between 0 and 60000"):this.normalLogPipeLine({severity:"speed",eventName:n,extraInfo:k({duration:e},t)}):console.warn("reportDuration: duration (second param) must be number"):console.warn("reportDuration: eventName (first param) must be a string")}},{key:"getTimerKey",value:function(n){var e=B(this);return this.config.isWebappContainer?"".concat(e,"_").concat(n):n}},{key:"timeStart",value:function(n){"string"==typeof n?(this.timeMap[this.getTimerKey(n)]&&console.warn("Timer ".concat(n," already exists")),this.timeMap[this.getTimerKey(n)]=Date.now()):console.warn("time: first param must be a string")}},{key:"timeEnd",value:function(n,e){if("string"==typeof n)if(this.timeMap[this.getTimerKey(n)]){var t=Date.now()-this.timeMap[this.getTimerKey(n)]+(e||0);this.normalLogPipeLine({severity:"speed",eventName:n,extraInfo:{duration:t}}),delete this.timeMap[this.getTimerKey(n)]}else console.warn("Timer key :".concat(n," does not exist"));else console.warn("timeEnd: first param must be a string")}},{key:"addToAssetSpeedWhiteListByMFE",value:function(n){var e,t,r,i,o=n.MFEName,a=n.whiteList;this.config.isWebappContainer&&o&&(null==a?void 0:a.length)&&(this.config.assetSpeedMonitoringWhiteListByMFE||(this.config.assetSpeedMonitoringWhiteListByMFE={}),(null===(e=this.config.assetSpeedMonitoringWhiteListByMFE)||void 0===e?void 0:e[o])?null===(i=this.config.assetSpeedMonitoringWhiteListByMFE)||void 0===i||null===(r=i[o])||void 0===r||(t=r).push.apply(t,I(a)):this.config.assetSpeedMonitoringWhiteListByMFE=x(k({},this.config.assetSpeedMonitoringWhiteListByMFE),g({},o,a)))}},{key:"destroy",value:function(){this.config.isWebappContainer||this.plugins.forEach((function(n){n.uninstall()}))}}]),n}(),Tn=Cn,Dn=function(n,e){return Dn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,e){n.__proto__=e}||function(n,e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t])},Dn(n,e)};function Pn(n,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function t(){this.constructor=n}Dn(n,e),n.prototype=null===e?Object.create(e):(t.prototype=e.prototype,new t)}var Rn=function(){return Rn=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n},Rn.apply(this,arguments)};function On(n,e,t,r){return new(t||(t=Promise))((function(e,i){function o(n){try{s(r.next(n))}catch(n){i(n)}}function a(n){try{s(r.throw(n))}catch(n){i(n)}}function s(n){var r;n.done?e(n.value):(r=n.value,r instanceof t?r:new t((function(n){n(r)}))).then(o,a)}s((r=r.apply(n,[])).next())}))}function jn(n,e){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(u){return function(s){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(t=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(n,a)}catch(n){s=[6,n],r=0}finally{t=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function _n(n,e){for(var t,r=0,i=e.length;r<i;r++)!t&&r in e||(t||(t=Array.prototype.slice.call(e,0,r)),t[r]=e[r]);return n.concat(t||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var An,Ln,Un,Fn={dev:j.staging,staging:j.staging,demo:j.demo,prod:j.production},Mn=function(n){if("object"!=typeof n)return n;try{var e=JSON.parse(JSON.stringify(n));return Object.keys(e).forEach((function(n){"string"==typeof n&&["auth","code"].some((function(e){return n.includes(e)}))&&(e[n]="***")})),e}catch(e){return n}},Kn=function(n,e){var t,r;null===(r=null===(t=window._AirwallexSDKs)||void 0===t?void 0:t.airTracker)||void 0===r||r.error(n,Rn(Rn({},e),{context:"components-sdk"}))},qn=function(n,e){var t;null===(t=window._AirwallexSDKs.airTracker)||void 0===t||t.info(n,Rn(Rn({},e),{context:"components-sdk"}))},Hn=function(n){function e(e){var t=n.call(this,e)||this;return t.code="LOAD_SCRIPT_ERROR",t}return Pn(e,n),e}(Error);!function(n){n.dev="dev",n.staging="staging",n.demo="demo",n.prod="prod",n.sandbox="sandbox"}(Un||(Un={}));var zn,Bn=((An={})[Un.dev]="https://checkout-staging.airwallex.com",An[Un.staging]="https://checkout-staging.airwallex.com",An[Un.demo]="https://checkout-demo.airwallex.com",An[Un.prod]="https://checkout.airwallex.com",An[Un.sandbox]="https://checkout.sandbox.airwallex.com",An),Wn=((Ln={})[Un.dev]="https://static-staging.airwallex.com",Ln[Un.staging]="https://static-staging.airwallex.com",Ln[Un.demo]="https://static-demo.airwallex.com",Ln[Un.prod]="https://static.airwallex.com",Ln[Un.sandbox]="https://static.sandbox.airwallex.com",Ln),Xn="sdkController",Vn="payments",Gn={kyc:"/widgets/kyc/sdk/v1/index.js",rfi:"/widgets/kycRfi/sdk/v1/index.js",paymentsKyb:"/widgets/paymentsKyb/sdk/v1/index.js",sdkController:"/widgets/sdk-controller/sdk/v1/index.js",payouts:"/widgets/payouts/sdk/v1/index.js",payments:"/assets/elements.bundle.min.js",sca:"/hosted-sca/sdk/v1/index.js",taxForm:"/widgets/taxForm/sdk/v1/index.js",billing:"/widgets/checkout/sdk/v1/index.js"},Jn={kyc:"kyc",paymentsKyb:"paymentsKyb",kycRfi:"rfi",transactionRfi:"rfi",paymentEnablementRfi:"rfi",lendingRfi:"rfi",mrmRfi:"rfi",payoutForm:"payouts",beneficiaryForm:"payouts",hpp:"payments",cvc:"payments",card:"payments",expiry:"payments",dropIn:"payments",cardNumber:"payments",applePayButton:"payments",googlePayButton:"payments",krCardNumber:"payments",krCardIdentifier:"payments",krCardExpiry:"payments",krCardPswFirstTwo:"payments",scaSetup:"sca",scaVerify:"sca",scaManagement:"sca",taxForm:"taxForm",embeddedCheckout:"billing"},$n={payments:["hpp","cvc","card","expiry","dropIn","cardNumber","applePayButton","googlePayButton","krCardNumber","krCardIdentifier","krCardExpiry","krCardPswFirstTwo"],payouts:["payoutForm","beneficiaryForm"],onboarding:["kyc","paymentsKyb"],risk:["scaSetup","scaVerify","scaManagement","transactionRfi","kycRfi","paymentEnablementRfi","lendingRfi","mrmRfi"],billing:["embeddedCheckout"]},Qn={billing:["payments"]},Yn=["payments","sca","billing"],Zn=function(n){function e(e){var t=n.call(this,e)||this;return t.code="INVALID_STATIC_RESOURCE_ERROR",t}return Pn(e,n),e}(Error),ne=Date.now(),ee=function(n){return Jn[n]},te=function(n){var e=n.reduce((function(n,e){return n.concat((t=e,Object.keys($n).includes(t)?$n[e]:e));var t}),[]);return Array.from(new Set(e)).map((function(n){return{elementName:n,sdkName:ee(n)}}))},re=function(n){return"payments"===n?"payment":n},ie=function(n){var e=n.name,t=n.env,r=function(n,e){var t=n===Vn?Bn:Wn;return t[e]||t.prod}(e,void 0===t?Un.prod:t),i=Gn[e];if(!i)throw Kn("[components-sdk] Element static resource not found",{sdkName:e}),new Zn("Element ".concat(e," static resource URL is invalid."));return"".concat(r).concat(i,"?ts=").concat(ne)},oe=function(){return Math.floor(performance.now())},ae=function(n){function e(e){var t=n.call(this,e)||this;return t.code="INSTANCE_NOT_FOUND_ERROR",t}return Pn(e,n),e}(Error),se=new Map,ue=function(n){var e=n.scriptName,t=ie({name:e,env:n.env}),r=se.get(e);if(r)return r;var i=function(n){return On(void 0,0,void 0,(function(){var e,t;return jn(this,(function(r){switch(r.label){case 0:if("undefined"==typeof window)throw new Error("Please load script in browser environment");e=0,t=function(){return On(void 0,0,void 0,(function(){var t,r,i;return jn(this,(function(){return t=oe(),e>0&&n.includes("?ts=")&&((r=new URL(n,window.location.href)).searchParams.set("ts","".concat(Date.now())),n=r.toString()),i=function(n){var e=document.createElement("script");return e.src=n,e.type="module",(document.head||document.body).appendChild(e),e}(n),[2,new Promise((function(r,o){i.addEventListener("load",(function(){var i=oe();qn("[components-sdk] SDK script loaded",{scriptUrl:n,start:t,latency:i-t,end:i,retryCount:e}),r(!0)})),i.addEventListener("error",(function(r){i.remove(),console.error(r);var a=oe();Kn("[components-sdk] Failed to load script",{scriptUrl:n,error:r,start:t,latency:a-t,end:a,retryCount:e}),o(new Hn("Failed to load Airwallex SDK scripts: ".concat(n)))}))}))]}))}))},r.label=1;case 1:if(!(e<3))return[3,7];r.label=2;case 2:return r.trys.push([2,4,,6]),[4,t()];case 3:return[2,r.sent()];case 4:return r.sent(),e++,[4,(void 0===i&&(i=500),new Promise((function(n){return window.setTimeout(n,i)})))];case 5:return r.sent(),[3,6];case 6:return[3,1];case 7:throw Kn("[components-sdk] Failed to load script after retry",{scriptUrl:n,retryCount:e}),new Hn("Failed to load Airwallex SDK scripts: ".concat(n))}var i}))}))}(t);return se.set(e,i),i},ce=function(n){var e=n.env,t=n.scriptName;return On(void 0,0,void 0,(function(){var n;return jn(this,(function(r){switch(r.label){case 0:return(n=Qn[t]||[]).length>0?[4,Promise.all(n.map((function(n){return ue({env:e,scriptName:n})})))]:[3,2];case 1:r.sent(),r.label=2;case 2:return[2,ue({env:e,scriptName:t})]}}))}))},le=function(n){return On(void 0,0,void 0,(function(){return jn(this,(function(){if("undefined"==typeof window)throw new Error("Please call the `init()` function in a browser environment.");var e,t;return t=n.clientId,void 0===(e=n.env)&&(e=j.production),window._AirwallexSDKs.airTracker||(window._AirwallexSDKs.airTracker=new Tn({config:{appName:"components-sdk",appVersion:"1.35.0",env:Fn[e]||j.production}}),window._AirwallexSDKs.airTracker.updateCommonData({clientId:t})),window,qn("[components-sdk] SDK init start",{options:Mn(n),start:oe()}),zn=new Promise((function(e,t){var r,i=Rn(Rn({},n),{env:n.env&&Un[n.env]?n.env:Un.prod});window.AirwallexComponentsSDK.__env__=i.env;var o=ue({env:i.env,scriptName:Xn}).then((function(){return window._AirwallexSDKs.__controller__.init(i)})),a=null!==(r=n.enabledElements)&&void 0!==r?r:[],s=function(n){return Array.from(new Set(te(n).map((function(n){return n.sdkName})).filter((function(n){return Yn.includes(n)}))))}(a),u=s.map((function(n){return ce({env:i.env,scriptName:n}).then((function(){return o})).then((function(){var e=window._AirwallexSDKs[re(n)];if(!e)throw Kn("[components-sdk] SDK instance not found",{functionsNamespace:n,windowSDKInstanceName:re(n)}),new ae("SDK instance not found");return window._AirwallexSDKs.__controller__.registerFunctions({functionsNamespace:n,instance:e})}))})),c=te(a).map((function(n){var e=n.sdkName,t=n.elementName;return ce({scriptName:e,env:i.env}).then((function(){return o})).then((function(){var n=window._AirwallexSDKs[re(e)];if(!n)throw Kn("[components-sdk] SDK instance not found",{sdkName:e,windowSDKInstanceName:re(e)}),new ae("SDK instance not found");return window._AirwallexSDKs.__controller__.registerElement({sdkName:e,elementName:t,instance:n})}))}));Promise.all(_n(_n([o],u),c)).then((function(){qn("[components-sdk] SDK initialized",{options:Mn(n),start:oe()}),e(Yn.reduce((function(n,e){var t;return Rn(Rn({},n),((t={})[e]=window._AirwallexSDKs.__controller__.internalSDKs[e],t))}),{}))})).catch((function(n){n.code||Kn("[components-sdk] Unexpected errors when init",{error:n}),t(n)}))})),[2,zn]}))}))},de=function(n,e){return On(void 0,0,void 0,(function(){var t,r,i,o,a;return jn(this,(function(s){switch(s.label){case 0:if(!n)throw new Error("Element type is missing. Please specify a valid element.");if(qn("[components-sdk] SDK createElement start",{elementName:n,options:Mn(e),timestamp:oe()}),!zn)throw function(){var n;null===(n=window._AirwallexSDKs.airTracker)||void 0===n||n.warn("[components-sdk] Did not call init before createElement",Rn(Rn({},void 0),{context:"components-sdk"}))}(),new Error("Please initialize the Element before creating it.");return[4,zn];case 1:if(s.sent(),!(t=ee(n)))throw new Error("`createElement()` with type `".concat(n,"` is not supported. Please specify a valid Element type."));r=oe(),s.label=2;case 2:return s.trys.push([2,6,,7]),[4,ce({scriptName:t,env:window.AirwallexComponentsSDK.__env__||Un.prod})];case 3:return s.sent(),[4,window._AirwallexSDKs.__controller__.registerElement({sdkName:t,elementName:n,instance:window._AirwallexSDKs[re(t)]})];case 4:return s.sent(),[4,window._AirwallexSDKs.__controller__.createElement(n,e)];case 5:return i=s.sent(),o=oe(),qn("[components-sdk] SDK createElement being called",{elementName:n,options:Mn(e),start:r,latency:o-r,end:o}),[3,7];case 6:if((a=s.sent()).code)throw a;return Kn("[components-sdk] Unexpected errors when createElement",{error:a}),[3,7];case 7:return[2,i]}}))}))},fe=[Xn,Vn],ve=function(){fe.forEach((function(n){var e=ie({name:n,env:Un.prod}),t=document.createElement("link");t.href=e,t.rel="modulepreload",t.as="script",(document.head||document.body).appendChild(t)}))};"undefined"==typeof document||"undefined"==typeof window||("loading"===document.readyState?document.addEventListener("DOMContentLoaded",ve):ve()),"undefined"!=typeof window&&(window.AirwallexComponentsSDK||Object.defineProperties(window,{AirwallexComponentsSDK:{value:{},writable:!1},_AirwallexSDKs:{value:{},writable:!1}}),window.AirwallexComponentsSDK.init=le,window.AirwallexComponentsSDK.createElement=de);const{onChange:me,reset:pe,state:he}=n((()=>({clientSecret:null,currency:null,hasPaymentError:!1,isReady:!1,paymentConfirmed:!1,paymentIntentId:null}))),ye=n=>"AIRWALLEX"===n.paymentProcessor&&(n.clientSecret&&(he.clientSecret=n.clientSecret),n.paymentIntentId&&(he.paymentIntentId=n.paymentIntentId),!!he.clientSecret||(o("Airwallex checkout session is missing the client secret"),!1)),we={ar:"ar",da:"da",de:"de",en:"en",es:"es",fr:"fr",id:"id",it:"it",ja:"ja",ko:"ko",nl:"nl",pl:"pl",pt:"pt",ru:"ru",sv:"sv",zh:"zh"},ge=n=>we[n]||"en";let be=null;const ke=async()=>!!he.isReady||(be||(be=le({enabledElements:["payments"],env:e.zonosMode&&"production"!==e.zonosMode||"LIVE"!==e.checkoutSettings.mode?"demo":"prod",locale:ge(r.selectedLocale)}).then((()=>(he.isReady=!0,u("Airwallex SDK initialized"),!0))).catch((n=>(o(n),be=null,!1)))),be),xe=["SUCCEEDED","REQUIRES_CAPTURE","PENDING_REVIEW","PENDING"],Ee=n=>!!n&&xe.includes(n),Ie=n=>{switch(n){case"SUCCEEDED":return{isError:!1,messages:[t("Thank you for submitting your payment. We appreciate your prompt attention."),"",t("A confirmation email with your payment details has been sent for your records. If you have any questions or need support, our team is here to help.")]};case"PENDING":case"PENDING_REVIEW":case"REQUIRES_CAPTURE":return{isError:!1,messages:[t("Payment processing. We'll update you when payment is received.")]};case"REQUIRES_CUSTOMER_ACTION":return{isError:!1,messages:[t("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.")]};case"CANCELLED":case"REQUIRES_PAYMENT_METHOD":return{isError:!0,messages:[t("Payment failed. Please reload the page and try another payment method.")]};default:return{isError:!0,messages:[t("Something went wrong.")]}}},Se=async n=>{const{errors:e,json:t}=await a("/api/zonos-elements/collect/airwallex-payment-intent",{body:{paymentIntentId:n},method:"POST"});return e.length||!t?(o("Failed to retrieve Airwallex payment intent",e),{status:null}):{status:t.airwallexPaymentIntent.status}},{state:Ne}=n((()=>({amountDutyTaxFeeTotal:null,amountTotalPaid:null,collectLogoUrl:null,isFetchingShippingInfo:!0,landedCostShortId:null,originCompanyName:null,partyBillingId:null,paymentProcessor:null,shippingAddress:null}))),Ce=async({landedCostId:n,retries:t=5})=>{var r,i,o,u,c,d,f,v,m,p;Ne.isFetchingShippingInfo=!0;const h=await a("/api/zonos-elements/collect/get-shipping-info-by-lc-id",{body:{landedCostId:n},method:"POST"});if(h.errors.length)return t>0?(await new Promise((n=>setTimeout(n,1e3))),Ce({landedCostId:n,retries:t-1})):null;Ne.landedCostShortId=(null===(r=h.json)||void 0===r?void 0:r.landedCostShortId)||null,Ne.isFetchingShippingInfo=!1,Ne.shippingAddress=(null===(i=h.json)||void 0===i?void 0:i.shipping)||null;const y=null===(o=l.checkoutSession)||void 0===o?void 0:o.landedCost,w=null===(u=l.checkoutSession)||void 0===u?void 0:u.subtotals,g=((null===(c=null==y?void 0:y.amountSubtotals)||void 0===c?void 0:c.shipping)||0)+((null===(d=null==y?void 0:y.amountSubtotals)||void 0===d?void 0:d.items)||0);Ne.amountTotalPaid=g*((null===(f=null==w?void 0:w.exchangeRate)||void 0===f?void 0:f.rate)||1),Ne.amountDutyTaxFeeTotal=((null==w?void 0:w.duties)||0)+((null==w?void 0:w.taxes)||0)+((null==w?void 0:w.fees)||0),Ne.originCompanyName=(null===(m=null===(v=h.json)||void 0===v?void 0:v.origin)||void 0===m?void 0:m.companyName)||null,Ne.collectLogoUrl=(null===(p=h.json)||void 0===p?void 0:p.collectLogoUrl)||null,0===Ne.amountTotalPaid&&s({endpoint:"COLLECT_NO_TOTAL_PAID",errors:[],metadata:{landedCostId:n,organizationId:e.organizationId}})},Te=async()=>{var n,e,t,r;if(!(null===(n=f.stripeBillingAddressEventData)||void 0===n?void 0:n.complete))return{partiesCreated:!1};const u=null===(t=null===(e=l.checkoutSession)||void 0===e?void 0:e.landedCost)||void 0===t?void 0:t.rootId;if(!u)return s({endpoint:"PF_NO_SELECTED_LANDED_COST",errors:["No selected landed cost"],metadata:{allLogs:c,cartId:window.Zonos.cartId,checkoutSessionId:i.checkoutSessionId}}),{partiesCreated:!1};if(!i.checkoutSessionId)return s({endpoint:"COLLECT_NO_CHECKOUT_SESSION_ID",errors:["No checkout session id"],metadata:{allLogs:c,cartId:window.Zonos.cartId,landedCostRootId:u}}),{partiesCreated:!1};const d=v({address:f.stripeBillingAddressEventData.value.address,firstName:f.stripeBillingAddressEventData.value.firstName,lastName:f.stripeBillingAddressEventData.value.lastName,name:f.stripeBillingAddressEventData.value.name,phone:f.stripeBillingAddressEventData.value.phone}),m="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:p,json:h}=await a("/api/zonos-elements/create-billing-party",{body:{billingAddress:d,checkoutSessionId:i.checkoutSessionId,companyName:f.companyName,email:(null===(r=f.stripeLinkEventData)||void 0===r?void 0:r.value.email)||"",isTest:m,rootId:u},method:"POST"});return p.length||!h?(o("Error occurs when creating billing party",JSON.stringify(p,null,2)),s({endpoint:"COLLECT_BILLING_PARTY_CREATE_FAILED",errors:["[COLLECT] Failed to create billing party"],metadata:{allLogs:c,cartId:window.Zonos.cartId,checkoutSessionId:i.checkoutSessionId,errors:p,json:h}}),{partiesCreated:!1}):(Ne.partyBillingId=h.billToPartyId,{partiesCreated:!0})},De=async n=>{const e=n.landedCost;return!!e&&(l.landedCostData=[Object.assign(Object.assign({},n),{landedCost:Object.assign({},e),landedCostId:e.id})],d({applySubtotalsOnly:!0,landedCostId:e.id,selectedShippingOption:e.shipmentRating}))};export{ye as a,he as b,Ne as c,Se as d,Ee as e,ke as f,De as g,Ce as h,Te as i,Ie as j,pe as k,de as l,ge as m,me as n}
|
|
1
|
+
import{c as n,z as e}from"./p-W82paT5F.js";import{t,l as r,s as i}from"./p-clDfq9AL.js";import{l as o,h as a,s}from"./p-DE4a-QD5.js";import{l as u,b as c}from"./p-BJmZPrZl.js";import{d as l,Y as d,b as f,a0 as v}from"./p-FRWZayxL.js";function m(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function p(n,e,t,r,i,o,a){try{var s=n[o](a),u=s.value}catch(n){return void t(n)}s.done?e(u):Promise.resolve(u).then(r,i)}function h(n){return function(){var e=this,t=arguments;return new Promise((function(r,i){var o=n.apply(e,t);function a(n){p(o,r,i,a,s,"next",n)}function s(n){p(o,r,i,a,s,"throw",n)}a(void 0)}))}}function y(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}function w(n,e){return e&&function(n,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}(n.prototype,e),n}function b(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function g(n,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](n):n instanceof e}function k(n){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter((function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})))),r.forEach((function(e){b(n,e,t[e])}))}return n}function x(n,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):function(n){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(n);e.push.apply(e,t)}return e}(Object(e)).forEach((function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(e,t))})),n}function E(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var t=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=t){var r,i,o=[],a=!0,s=!1;try{for(t=t.call(n);!(a=(r=t.next()).done)&&(o.push(r.value),o.length!==e);a=!0);}catch(n){s=!0,i=n}finally{try{a||null==t.return||t.return()}finally{if(s)throw i}}return o}}(n,e)||N(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(n){return function(n){if(Array.isArray(n))return m(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||N(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(n){return n&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n}function N(n,e){if(n){if("string"==typeof n)return m(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?m(n,e):void 0}}function C(n,e){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(n,a)}catch(n){o=[6,n],r=0}finally{t=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var D,T,P,R,O,j=function(n){return n.production="prod",n.demo="demo",n.staging="staging",n}(j||{}),A="airTracker_unknown",_={appName:A,appVersion:A,env:"staging",isWebappContainer:!1,delay:2e3,errorRepeatTime:3,enableErrorMonitoring:!1,assetSpeedMonitoringWhiteList:[],enableDetectPageChange:!1,enableRecordPageRetention:!1,hideSearchParams:!1,useSessionStorageForSessionId:!1,assetSpeedMonitoringWhiteListByMFE:{}},L={appName:A,env:"staging",sessionId:A,deviceId:A},U=function(){var n=new WeakSet;return function(e,t){if(g(t,Error))return"Error.message: ".concat(t.message," \n Error.stack: ").concat(t.stack);if("object"===(void 0===t?"undefined":S(t))&&null!==t){if(n.has(t))return"[Circular ".concat(e||"root","]");n.add(t)}return"function"==typeof t?"function":"symbol"===(void 0===t?"undefined":S(t))?"symbol":void 0===t?null:t}},F=function(n){if("string"==typeof n)return n;try{return g(n,Error)?(JSON.stringify(n,U())||"undefined").replace(/"/gim,""):JSON.stringify(n,U())}catch(n){return'{"error":"error happen when airTracker stringify"}'}},M=function(n){var e=n.method,t=void 0===e?"post":e,r=n.url,i=n.data,o=n.success,a=n.fail;if((s=i)&&!/^\s*$/.test(s)&&(s=(s=(s=s.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@")).replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]")).replace(/(?:^|:|,)(?:\s*\[)+/g,""),/^[\],:{}\s]*$/.test(s))){var s,u=new XMLHttpRequest;u.addEventListener("readystatechange",(function(){4===u.readyState&&(u.status>=400||0===u.status?null==a||a(u.response):null==o||o(u.response))})),u.open(t,r),u.setRequestHeader("Content-Type","application/json"),u.send(i)}},K="onCommonUpdated",H="AIR_ANALYTICS_DEVICE_ID",q="AIR_ANALYTICS_SESSION_ID",z=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(n){var e=16*Math.random()|0;return("x"===n?e:3&e|8).toString(16)}))},B=function(n){var e,t,r;return n.config.getMFEName?n.config.getMFEName():(null===(r=location)||void 0===r||null===(t=r.pathname)||void 0===t||null===(e=t.split("/"))||void 0===e?void 0:e[2])||"unknown"},W=function(n){return"string"==typeof n?n.split("?")[1]||"":n},X=function(n){return"string"==typeof n&&n.startsWith("//")?"undefined"!=typeof location&&"https:"===location.protocol:/^https/.test(n)},V=function(n){return"number"==typeof n||"string"==typeof n?n:-1},G=function(n,e){var t,r=!1;if(!e.config.isWebappContainer)return J(n,e.config.assetSpeedMonitoringWhiteList);var i=B(e);return r||J(n,null===(t=e.config.assetSpeedMonitoringWhiteListByMFE)||void 0===t?void 0:t[i])},J=function(n,e){if(!(null==e?void 0:e.length))return!1;for(var t=0;t<e.length;t++){var r=e[t];if(g(r,RegExp)&&r.test(n))return!0;if("string"==typeof r&&n.includes(r))return!0}return!1},$=function(n,e){return Math.round(100*(n-e))/100},Q=function(n){return function(e){var t,r,i=B(n),o=n.config.isWebappContainer?k({},n.commonData||{},(null===(t=n.MFECommonDataMap)||void 0===t?void 0:t[i])||{}):n.commonData,a=Array.isArray(e)?e:[e];if(0!==a.length){var s,u=F({commonData:o,data:a}),c={method:"post",url:(s=n.commonData.env,"prod"==s?"https://o11y.airwallex.com/airtracker/logs":"demo"==s?"https://o11y-demo.airwallex.com/airtracker/logs":"https://o11y-staging.airwallex.com/airtracker/logs"),data:u};"function"==typeof(null===(r=navigator)||void 0===r?void 0:r.sendBeacon)&&navigator.sendBeacon(c.url,u)||M(c)}}},Y=function(n){return function(e){var t,r,i,o=B(n),a={commonData:n.config.isWebappContainer?k({},n.commonData||{},(null===(t=n.MFECommonDataMap)||void 0===t?void 0:t[o])||{}):n.commonData,data:Array.isArray(e)?e:[e]},s=F(a),u={method:"post",url:(i=n.commonData.env,"prod"==i?"https://o11y.airwallex.com/airtracker/metrics":"demo"==i?"https://o11y-demo.airwallex.com/airtracker/metrics":"https://o11y-staging.airwallex.com/airtracker/metrics"),data:s};"function"==typeof(null===(r=navigator)||void 0===r?void 0:r.sendBeacon)&&navigator.sendBeacon(u.url,s)||M(u)}},Z=function(n,e){var t,r=[],i=n.config;return window.addEventListener("beforeunload",(function(){r.length>0&&(n.immediateSendPipe(r.splice(0,r.length)),t&&clearTimeout(t))})),function(o,a){if(r.push(o),n.lifeCycle.on(K,(function(){r.length>0&&(null==a||a(r.splice(0,r.length)),n.lifeCycle.remove(K),t&&clearTimeout(t))})),r.length>=e)return null==a||a(r.splice(0,r.length)),void(t&&clearTimeout(t));t&&clearTimeout(t),t=setTimeout((function(){t=null,r.length>0&&(null==a||a(r.splice(0,r.length)),n.lifeCycle.remove(K))}),i.delay)}},nn=function(){},en=function(n){if(!n||!n.reduce||!n.length)throw new TypeError("createPipeline need at least one function param");return 1===n.length?function(e,t){n[0](e,t||nn)}:n.reduce((function(n,e){return function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nn;return n(t,(function(n){return null==e?void 0:e(n,r)}))}}))},tn=function(){function n(){var e=this;y(this,n),this.emit=function(n,t){if(e){var r,i=e.eventsList[n];if(null==i?void 0:i.length){i=i.slice();for(var o=0;o<i.length;o++){r=i[o];try{var a=r.callback.apply(e,[t]);if(1===r.type&&e.remove(n,r.callback),!1===a)break}catch(n){throw n}}}return e}},this.eventsList={}}return w(n,[{key:"indexOf",value:function(n,e){for(var t=0;t<n.length;t++)if(n[t].callback===e)return t;return-1}},{key:"on",value:function(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(this){var r=this.eventsList[n];return r||(this.eventsList[n]=[],r=this.eventsList[n]),-1===this.indexOf(r,e)?(r.push({name:n,type:t||0,callback:e}),this):this}}},{key:"one",value:function(n,e){this.on(n,e,1)}},{key:"remove",value:function(n,e){if(this){var t=this.eventsList[n];if(!t)return null;if(!e){try{delete this.eventsList[n]}catch(n){}return null}if(t.length){var r=this.indexOf(t,e);t.splice(r,1)}return this}}},{key:"clear",value:function(){this.eventsList={}}}]),n}(),rn=function(){function n(e){y(this,n),this.name="",this.isInit=!1,this.name=e.name,this.option=e}return w(n,[{key:"patch",value:function(n){var e,t;this.isInit||(this.isInit=!0,null===(t=this.option)||void 0===t||null===(e=t.setUp)||void 0===e||e.call(this.option,n))}},{key:"uninstall",value:function(){var n,e;null===(e=this.option)||void 0===e||null===(n=e.destroy)||void 0===n||n.apply(this),this.isInit=!1}}]),n}(),on=function(n){var e="".concat(F(n.message)||""," @ (").concat(F(n.filename)||"",":").concat(n.lineno||0,":").concat(n.colno||0,")\n").concat(F(n.error||""));D.normalLogPipeLine({severity:"autoDetectError",eventName:"windowOnError",extraInfo:{error:e}})},an=function(n){var e=n&&F(n.reason);D.normalLogPipeLine({severity:"autoDetectError",eventName:"promiseError",extraInfo:{error:e}})},sn=function(n){var e=(null==n?void 0:n.target)||(null==n?void 0:n.srcElement);if(e){var t=(null==e?void 0:e.src)||(null==e?void 0:e.href),r=e.tagName,i="unknown";if("string"==typeof t&&r){if(window.location.href.indexOf(t)>-1)return;if(/\.js$/.test(t))i="script";else if(/\.css$/.test(t))i="css";else switch(r.toLowerCase()){case"script":i="script";break;case"link":i="css";break;case"img":i="image";break;case"audio":case"video":i="media";break;default:return}D.normalLogPipeLine({severity:"autoDetectError",eventName:"staticFileLoadError",extraInfo:{staticFileType:i,error:"".concat(r," load fail: ").concat(t)}})}}},un=new rn({name:"errorDetectionPlugin",setUp:function(n){D=n,window.addEventListener("error",on),window.addEventListener("unhandledrejection",an),window.document.addEventListener("error",sn,!0)},destroy:function(){window.removeEventListener("unhandledrejection",an),window.document.removeEventListener("error",sn,!0),window.removeEventListener("error",on)}}),cn=["img","css","script","link","audio","video","iframe"],ln="resource",dn=function(n){var e,t=n.name;return{url:(e=t,"string"==typeof e?(e.split("?")[0]||"").slice(0,200):e),method:"get",duration:Number(n.duration.toFixed(2)),type:"static",isHttps:X(t),urlQuery:W(t),domainLookup:V(n.domainLookupEnd-n.domainLookupStart),connectTime:V(n.connectEnd-n.connectStart)}},fn=function(n,e){for(var t=0,r=n.length;t<r;t++){var i=n[t];-1!==cn.indexOf(i.initiatorType)&&G(i.name,e)&&e.normalLogPipeLine({severity:"performance",eventName:"assets_speed",extraInfo:{log:dn(i)}})}},vn=new rn({name:"assetsSpeedPlugin",setUp:function(n){if(void 0!==window.performance&&"function"==typeof window.performance.clearResourceTimings&&"function"==typeof window.performance.getEntriesByType&&"function"==typeof window.performance.now){var e=0;window.performance.onresourcetimingbufferfull=function(){e=0,window.performance.clearResourceTimings()},"function"==typeof window.PerformanceObserver?(fn(window.performance.getEntriesByType(ln),n),(P=new window.PerformanceObserver((function(e){fn(e.getEntries(),n)}))).observe({entryTypes:[ln]})):T=setInterval((function(){var t=window.performance.getEntriesByType(ln),r=t.slice(e);e=t.length,fn(r,n)}),3e3)}},destroy:function(){null==P||P.disconnect(),T&&clearInterval(T)}}),mn=new rn({name:"onPageChangePlugin",setUp:function(){var n=h((function(n){var e,t,r,i;return C(this,(function(){return t=null===(e=location)||void 0===e?void 0:e.href,r=document.querySelector("body"),i=function(e){var t,r,i,o,a;n.normalLogPipeLine({severity:"autoDetectEvent",eventName:"onPageChange",extraInfo:{prevHref:e.prevHref,href:(null===(t=location)||void 0===t?void 0:t.href)||"",hostname:null===(r=location)||void 0===r?void 0:r.hostname,pathName:null===(i=location)||void 0===i?void 0:i.pathname,protocol:null===(o=location)||void 0===o?void 0:o.protocol,search:null===(a=location)||void 0===a?void 0:a.search}})},i({prevHref:""}),(R=new MutationObserver((function(){if(location.href!==t){var n=t;t=location.href,i({prevHref:n})}}))).observe(r||document,{subtree:!0,childList:!0}),[2]}))}));return function(e){return n.apply(this,arguments)}}(),destroy:function(){null==R||R.disconnect()}}),pn=new rn({name:"onPageRetentionPlugin",setUp:function(){var n=h((function(n){var e,t,r,i,o,a;return C(this,(function(){return void 0===document.visibilityState||(t=null===(e=location)||void 0===e?void 0:e.href,r=document.querySelector("body"),(o=function(){i=Date.now()})(),document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState?a({href:location.href,leftReason:"visibilityChange"}):"visible"===document.visibilityState&&o()})),window.addEventListener("beforeunload",(function(){a({href:location.href,sendImmediate:!0,leftReason:"pageClose"})})),a=function(e){var t=e.href,r=e.sendImmediate,o=e.leftReason;if(i){var a=Date.now()-i;if(0!==a){i=void 0;var s={severity:"autoDetectEvent",eventName:"onPageRetention",extraInfo:{href:t,duration:a,leftReason:o}};r?n.ImmediatePipeline(s):n.normalLogPipeLine(s)}}},(O=new MutationObserver((function(){if(location.href!==t){var n=t;t=location.href,a({href:n,leftReason:"nextPage"}),o()}}))).observe(r||document,{subtree:!0,childList:!0})),[2]}))}));return function(e){return n.apply(this,arguments)}}(),destroy:function(){null==O||O.disconnect()}}),hn=function(){return Date.now().toString(36)+Math.random().toString(36).substring(2,15)},yn=function(n,e){return![/authenticate\/heartbeat/,/papluginlogs\/.*/,/airtracker\/.*/,/o11y(-staging|-demo)?\.airwallex\.com/,/\.(png|jpe?g|gif|svg|ico|webp|avif|css|js|json|woff2?|ttf|eot|map|txt|csv|xml)(\?.*)?(#.*)?$/i].some((function(e){return e.test(n)}))&&J(n,e||[/^https?:\/\/[^\/]*\.airwallex\.com($|\/)/])},wn=function(n){return Math.round(100*n)/100},bn=function(n,e){var t,r,i,o,a,s,u,c,l,d,f,v,m,p,h,y,w,b,g,E=n.url,I=n.method,S=n.errorType,N=n.errorDetail,C=function(n){var e=n.startTime,t=n.endTime,r=n.entries;if(0!==r.length){if(1===r.length)return r[0];var i=r.filter((function(n){return n.startTime>=e&&t&&n.responseEnd<=t})).sort((function(n,e){return n.startTime-e.startTime}));return null==i?void 0:i[0]}}(n),D=new URL(E,window.location.href),T=D.href,P=D.protocol,R=C?(i=(t=C).duration,o=t.responseStart,a=t.connectEnd,s=t.connectStart,u=t.domainLookupEnd,c=t.domainLookupStart,l=t.requestStart,d=t.secureConnectionStart,f=t.redirectEnd,v=t.redirectStart,m=t.responseStatus,p=t.responseEnd,h=t.encodedBodySize,y=t.decodedBodySize,w=t.transferSize,b=t.deliveryType,g=t.initiatorType,{startTime:wn(r=t.startTime),totalDuration:wn(i),timeToFirstByte:$(o,r),tcpDuration:$(a,s),dnsDuration:$(u,c),tlsDuration:$(l,d),redirectDuration:$(f,v),responseDuration:$(p,o),encodeResponseSize:h,decodeResponseSize:y,transferSize:w,deliveryType:b,statusCode:m,initiatorType:g}):{};return{severity:"autoDetectEvent",eventName:"httpClientMetrics",extraInfo:k(x(k({httpUrl:T,method:I,scheme:P},S&&{errorType:S},N&&{errorDetail:N},R),{statusCode:(null==R?void 0:R.statusCode)||(null==n?void 0:n.responseStatus),startTime:(null==R?void 0:R.startTime)||(null==n?void 0:n.startTime),initiatorType:(null==R?void 0:R.initiatorType)||(null==n?void 0:n.initiatorType)}),e)}},gn=function(n){return n&&"object"===(void 0===n?"undefined":S(n))&&"errors"in n&&Array.isArray(n.errors)&&n.errors.every((function(n){return n&&"object"===(void 0===n?"undefined":S(n))&&"message"in n}))},kn="awx_airtracker_api_performance_queue",xn="awx_airtracker_api_performance_plugin_loaded",En="undefined"!=typeof window?window:"undefined"!=typeof global?global:{};En[kn]=En[kn]||[];var In=function(n,e,t){setTimeout((function(){var r=bn(n,t);e.observerPipeline(r),En[kn]=En[kn].filter((function(e){return e.id!==n.id}))}),300)},Sn=function(n,e){setTimeout((function(){var t=En[kn].find((function(e){return e.id===n}));if(t){var r=bn(t,{exceptionType:"timeout-without-response"});e.observerPipeline(r),En[kn]=En[kn].filter((function(e){return e.id!==n}))}}),1e4)},Nn=new rn({name:"apiPerformancePlugin",setUp:function(){var n=h((function(n){var e,t;return C(this,(function(){return En[xn]||(null===(e=n.config)||void 0===e?void 0:e.enableRecordAPIPerformance)&&Math.random()<((null===(t=n.config)||void 0===t?void 0:t.enableRecordAPIPerformancePercentage)||0)&&(En[xn]=!0,function(n){var e;(function(n){var e=XMLHttpRequest.prototype.open,t=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(t,r,i,o,a){try{var s,u=hn();this.__requestId=u;var c=g(r,URL)?r.href:new URL(r,window.location.href).href;if(!yn(c,null===(s=n.config)||void 0===s?void 0:s.enableRecordAPIPerformanceWhitelist))return e.call(this,t,r,null==i||i,o,a);var l={id:u,startTime:performance.now(),method:t,url:c,entries:[],initiatorType:"xmlhttprequest"};return En[kn].push(l),Sn(u,n),e.call(this,t,r,null==i||i,o,a)}catch(s){return n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"Inject XHR open error",error:s}}),e.call(this,t,r,null==i||i,o,a)}},XMLHttpRequest.prototype.send=function(){for(var e=this,r=arguments.length,i=new Array(r),o=0;o<r;o++)i[o]=arguments[o];try{var a=En[kn].find((function(n){return n.id===e.__requestId}));if(!a)return t.apply(this,i);var s=this;return this.addEventListener("loadend",h((function(){var e,t,r,i,o,u,c;return C(this,(function(l){switch(l.label){case 0:if(e=performance.now(),t=e-a.startTime,0===(r=s.status))return[2];a.endTime=e,a.duration=t,a.responseStatus=r,l.label=1;case 1:return l.trys.push([1,6,,7]),""!==s.responseType&&"text"!==s.responseType?[3,2]:(i=s.responseText,[3,5]);case 2:return"json"!==s.responseType?[3,3]:(i=s.response,[3,5]);case 3:return"blob"!==s.responseType||"application/json"!==(null==(o=s.response)?void 0:o.type)?[3,5]:[4,o.text()];case 4:i=l.sent(),l.label=5;case 5:return(u=i&&"string"==typeof i?JSON.parse(i):i)&&gn(u)&&(a.errorType="graphqlError",a.errorDetail=u.errors),[3,7];case 6:return c=l.sent(),n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"Parse response body error in XHR",url:null==a?void 0:a.url,error:c}}),[3,7];case 7:return In(a,n),[2]}}))}))),this.addEventListener("error",(function(){In(a,n,{exceptionType:"network-error"})})),this.addEventListener("abort",(function(){In(a,n,{exceptionType:"abort-error"})})),this.addEventListener("timeout",(function(){In(a,n,{exceptionType:"timeout-error"})})),t.apply(this,i)}catch(e){throw n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"InjectXHR send error",error:e}}),e}}})(n),function(n){var e=window.fetch;window.fetch=h((function(){var t,r,i,o,a,s,u,c,l,d,f,v,m,p,h,y,w=arguments;return C(this,(function(b){switch(b.label){case 0:for(t=w.length,r=new Array(t),i=0;i<t;i++)r[i]=w[i];return s=new URL(g(r[0],Request)?r[0].url:String(r[0]),window.location.href).href,yn(s,null===(o=n.config)||void 0===o?void 0:o.enableRecordAPIPerformanceWhitelist)?[3,2]:[4,e.apply(this,r)];case 1:return[2,b.sent()];case 2:return b.trys.push([2,9,,10]),c=performance.now(),l=hn(),a={id:l,startTime:c,method:(null===(u=g(r[0],Request)?r[0]:r[1])||void 0===u?void 0:u.method)||"GET",url:s,entries:[],initiatorType:"fetch"},En[kn].push(a),Sn(l,n),[4,e.apply(this,r)];case 3:d=b.sent(),f=performance.now(),a.endTime=f,a.duration=f-c,a.responseStatus=d.status,v=d.clone(),b.label=4;case 4:return b.trys.push([4,7,,8]),v.ok?[4,v.json()]:[3,6];case 5:(m=b.sent())&&gn(m)&&(a.errorType="graphqlError",a.errorDetail=m.errors),b.label=6;case 6:return[3,8];case 7:return p=b.sent(),n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"Parse response body error in fetch",url:null==a?void 0:a.url,error:p}}),[3,8];case 8:return In(a,n),[2,d];case 9:throw h=b.sent(),a&&a.id&&En[kn].find((function(n){return n.id===(null==a?void 0:a.id)}))?(y="fetch-error",g(h,TypeError)?y="network-error":g(h,DOMException)&&"AbortError"===h.name&&(y="abort-error"),In(a,n,{exceptionType:y})):n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{message:"Inject fetch error",error:h}}),h;case 10:return[2]}}))}))}(n),(null===(e=window)||void 0===e?void 0:e.PerformanceObserver)?new window.PerformanceObserver((function(n){n.getEntries().forEach((function(n){var e=n;"fetch"!==e.initiatorType&&"xmlhttprequest"!==e.initiatorType||En[kn].filter((function(n){return n.url===e.name})).forEach((function(n){n.entries.push(e)}))}))})).observe({entryTypes:["resource"],buffered:!0}):n.normalLogPipeLine({severity:"warn",eventName:"apiPerformancePluginError",extraInfo:{error:"PerformanceObserver Not Supported"}})}(n)),[2]}))}));return function(e){return n.apply(this,arguments)}}()}),Cn=function(){function n(e){var t,r,i=this,o=e.config,a=e.plugins,s=void 0===a?[]:a;y(this,n),this.config=_,this.lifeCycle=new tn,this.plugins=[],this._commonData=L,this._MFECommonDataMap={},this.timeMap={},this.packedDataConvert=function(n){var e,t,r=n.extraInfo,o=k({severity:n.severity,eventName:n.eventName,currentHref:i.config.hideSearchParams?((null===(e=location)||void 0===e?void 0:e.href)||"").split("?")[0]||"":(null===(t=location)||void 0===t?void 0:t.href)||""},r);return i.config.isWebappContainer&&(o.MFEName=B(i)),o},this.normalPipelineObj=en([Z(this,8),(t=this,r={},function(n,e){var i="number"==typeof t.config.errorRepeatTime?t.config.errorRepeatTime:5;if(0===i)return null==e?void 0:e(n);null==e||e(n.filter((function(n){return"autoDetectError"!=n.severity||(r[n.error]=r[n.error]||0,r[n.error]+=1,!(r[n.error]>i))})))}),Q(this)]),this.observerPipelineObj=en([Z(this,8),Y(this)]),this.immediateSendPipe=Q(this),this.observerPipeline=function(n){var e=i.packedDataConvert({severity:n.severity,eventName:n.eventName,extraInfo:n.extraInfo});return i.observerPipelineObj(e)},this.normalLogPipeLine=function(n){var e=i.packedDataConvert({severity:n.severity,eventName:n.eventName,extraInfo:n.extraInfo});return i.config.disableThrottle?i.immediateSendPipe(e):i.normalPipelineObj(e)},this.ImmediatePipeline=function(n){var e=i.packedDataConvert({severity:n.severity,eventName:n.eventName,extraInfo:n.extraInfo});return i.immediateSendPipe(e)},this.plugins=I(s),this.setConfig(o),this.initCommonData(o),this.lifeCycle.emit("onInit"),o.enableErrorMonitoring&&this.plugins.push(un),((null==o?void 0:o.assetSpeedMonitoringWhiteList)&&o.assetSpeedMonitoringWhiteList.length>0||o.isWebappContainer)&&this.plugins.push(vn),(null==o?void 0:o.enableDetectPageChange)&&this.plugins.push(mn),(null==o?void 0:o.enableRecordPageRetention)&&this.plugins.push(pn),(null==o?void 0:o.enableRecordAPIPerformance)&&(null==o?void 0:o.enableRecordAPIPerformancePercentage)&&o.enableRecordAPIPerformancePercentage>0&&o.enableRecordAPIPerformancePercentage<=1&&this.plugins.push(Nn),this.installPlugins()}return w(n,[{key:"installPlugins",value:function(){var n=this;this.plugins.forEach((function(e){e.patch(n)}))}},{key:"commonData",get:function(){return this._commonData}},{key:"MFECommonDataMap",get:function(){return this._MFECommonDataMap}},{key:"initCommonData",value:function(n){this._commonData.sessionId=n.useSessionStorageForSessionId?function(){try{var n=window.sessionStorage.getItem(q);return n||(n=z(),window.sessionStorage.setItem(q,n)),n}catch(n){return z()}}():z(),this._commonData.deviceId=function(){try{var n=window.localStorage.getItem(H);return n||(n=z(),window.localStorage.setItem(H,n)),n}catch(n){}}()||A,this._commonData.riskDeviceId=function(){try{return window.localStorage.getItem("AWX_RISK_ID")||void 0}catch(n){}}(),this._commonData.networkType=function(){var n,e,t="",r=navigator.userAgent.match(/NetType\/(\w+)/);if(r)t=E(r,2)[1];else if(null===(n=navigator)||void 0===n?void 0:n.connection){var i,o,a,s;t=(null===(o=navigator)||void 0===o||null===(i=o.connection)||void 0===i?void 0:i.effectiveType)||(null===(s=navigator)||void 0===s||null===(a=s.connection)||void 0===a?void 0:a.type)}return t||(t="unknown"),e=t,(e=String(e).toLowerCase()).indexOf("4g")>=0?"net4g":e.indexOf("wifi")>=0?"wifi":e.indexOf("5g")>=0?"net5g":e.indexOf("3g")>=0?"net3g":e.indexOf("2g")>=0?"net2g":"unknown"}()||"unknown",this._commonData.env=n.env||this._commonData.env,this._commonData.accountId=n.accountId||A,this._commonData.appVersion=n.appVersion,this._commonData.appName=n.appName,this._commonData.sdkVersion="3.1.0",this.lifeCycle.emit("onCommonDataInit",this.commonData)}},{key:"updateCommonDataBasedOnConfig",value:function(n){this.lifeCycle.emit(K,this._commonData),this._commonData.env=n.env||this._commonData.env,this._commonData.appName=n.appName||this._commonData.appName,this._commonData.env=n.env||this._commonData.env,this._commonData.accountId=n.accountId||this._commonData.accountId,this._commonData.appVersion=n.appVersion||this._commonData.appVersion}},{key:"updateCommonData",value:function(n){this.lifeCycle.emit(K,this._commonData),this._commonData=k({},this._commonData,n)}},{key:"removeCommonDataByKey",value:function(n){var e=this;this.lifeCycle.emit(K,this._commonData),setTimeout((function(){n.forEach((function(n){delete e._commonData[n]}))}),1e3)}},{key:"addToMFECommonData",value:function(n){var e,t=n.MFEName,r=n.MFECommonData;this.config.isWebappContainer&&t&&r&&(this._MFECommonDataMap=x(k({},this._MFECommonDataMap||{}),b({},t,k({},(null===(e=this._MFECommonDataMap)||void 0===e?void 0:e[t])||{},r))))}},{key:"setConfig",value:function(n){var e=this;this.config.isWebappContainer||(Object.entries(n).forEach((function(n){var t=E(n,2),r=t[0],i=t[1];void 0!==(void 0===i?"undefined":S(i))&&function(n,t){e.config[n]=t}(r,i)})),this.lifeCycle.emit("onConfigInit",this.config),this.updateCommonDataBasedOnConfig(n))}},{key:"verbose",value:function(n,e){this.normalLogPipeLine({severity:"verbose",eventName:n,extraInfo:e})}},{key:"httpLog",value:function(n,e){this.normalLogPipeLine({severity:"http",eventName:n,extraInfo:e})}},{key:"info",value:function(n,e){this.normalLogPipeLine({severity:"info",eventName:n,extraInfo:e})}},{key:"warn",value:function(n,e){this.normalLogPipeLine({severity:"warn",eventName:n,extraInfo:e})}},{key:"error",value:function(n,e){console.error("error",n),this.normalLogPipeLine({severity:"error",eventName:n,extraInfo:e})}},{key:"businessLog",value:function(n,e){this.normalLogPipeLine({severity:"info",eventName:n,extraInfo:x(k({},e),{isBusinessLog:!0})})}},{key:"reportDuration",value:function(n,e,t){"string"==typeof n?"number"==typeof e?e<0||e>6e4?console.warn("reportDuration: duration (second param) must between 0 and 60000"):this.normalLogPipeLine({severity:"speed",eventName:n,extraInfo:k({duration:e},t)}):console.warn("reportDuration: duration (second param) must be number"):console.warn("reportDuration: eventName (first param) must be a string")}},{key:"getTimerKey",value:function(n){var e=B(this);return this.config.isWebappContainer?"".concat(e,"_").concat(n):n}},{key:"timeStart",value:function(n){"string"==typeof n?(this.timeMap[this.getTimerKey(n)]&&console.warn("Timer ".concat(n," already exists")),this.timeMap[this.getTimerKey(n)]=Date.now()):console.warn("time: first param must be a string")}},{key:"timeEnd",value:function(n,e){if("string"==typeof n)if(this.timeMap[this.getTimerKey(n)]){var t=Date.now()-this.timeMap[this.getTimerKey(n)]+(e||0);this.normalLogPipeLine({severity:"speed",eventName:n,extraInfo:{duration:t}}),delete this.timeMap[this.getTimerKey(n)]}else console.warn("Timer key :".concat(n," does not exist"));else console.warn("timeEnd: first param must be a string")}},{key:"addToAssetSpeedWhiteListByMFE",value:function(n){var e,t,r,i,o=n.MFEName,a=n.whiteList;this.config.isWebappContainer&&o&&(null==a?void 0:a.length)&&(this.config.assetSpeedMonitoringWhiteListByMFE||(this.config.assetSpeedMonitoringWhiteListByMFE={}),(null===(e=this.config.assetSpeedMonitoringWhiteListByMFE)||void 0===e?void 0:e[o])?null===(i=this.config.assetSpeedMonitoringWhiteListByMFE)||void 0===i||null===(r=i[o])||void 0===r||(t=r).push.apply(t,I(a)):this.config.assetSpeedMonitoringWhiteListByMFE=x(k({},this.config.assetSpeedMonitoringWhiteListByMFE),b({},o,a)))}},{key:"destroy",value:function(){this.config.isWebappContainer||this.plugins.forEach((function(n){n.uninstall()}))}}]),n}(),Dn=Cn,Tn=function(n,e){return Tn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,e){n.__proto__=e}||function(n,e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t])},Tn(n,e)};function Pn(n,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function t(){this.constructor=n}Tn(n,e),n.prototype=null===e?Object.create(e):(t.prototype=e.prototype,new t)}var Rn=function(){return Rn=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n},Rn.apply(this,arguments)};function On(n,e,t,r){return new(t||(t=Promise))((function(e,i){function o(n){try{s(r.next(n))}catch(n){i(n)}}function a(n){try{s(r.throw(n))}catch(n){i(n)}}function s(n){var r;n.done?e(n.value):(r=n.value,r instanceof t?r:new t((function(n){n(r)}))).then(o,a)}s((r=r.apply(n,[])).next())}))}function jn(n,e){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(u){return function(s){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(t=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(n,a)}catch(n){s=[6,n],r=0}finally{t=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function An(n,e){for(var t,r=0,i=e.length;r<i;r++)!t&&r in e||(t||(t=Array.prototype.slice.call(e,0,r)),t[r]=e[r]);return n.concat(t||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var _n,Ln,Un,Fn={dev:j.staging,staging:j.staging,demo:j.demo,prod:j.production},Mn=function(n){if("object"!=typeof n)return n;try{var e=JSON.parse(JSON.stringify(n));return Object.keys(e).forEach((function(n){"string"==typeof n&&["auth","code"].some((function(e){return n.includes(e)}))&&(e[n]="***")})),e}catch(e){return n}},Kn=function(n,e){var t,r;null===(r=null===(t=window._AirwallexSDKs)||void 0===t?void 0:t.airTracker)||void 0===r||r.error(n,Rn(Rn({},e),{context:"components-sdk"}))},Hn=function(n,e){var t;null===(t=window._AirwallexSDKs.airTracker)||void 0===t||t.info(n,Rn(Rn({},e),{context:"components-sdk"}))},qn=function(n){function e(e){var t=n.call(this,e)||this;return t.code="LOAD_SCRIPT_ERROR",t}return Pn(e,n),e}(Error);!function(n){n.dev="dev",n.staging="staging",n.demo="demo",n.prod="prod",n.sandbox="sandbox"}(Un||(Un={}));var zn,Bn=((_n={})[Un.dev]="https://checkout-staging.airwallex.com",_n[Un.staging]="https://checkout-staging.airwallex.com",_n[Un.demo]="https://checkout-demo.airwallex.com",_n[Un.prod]="https://checkout.airwallex.com",_n[Un.sandbox]="https://checkout.sandbox.airwallex.com",_n),Wn=((Ln={})[Un.dev]="https://static-staging.airwallex.com",Ln[Un.staging]="https://static-staging.airwallex.com",Ln[Un.demo]="https://static-demo.airwallex.com",Ln[Un.prod]="https://static.airwallex.com",Ln[Un.sandbox]="https://static.sandbox.airwallex.com",Ln),Xn="sdkController",Vn="payments",Gn={kyc:"/widgets/kyc/sdk/v1/index.js",rfi:"/widgets/kycRfi/sdk/v1/index.js",paymentsKyb:"/widgets/paymentsKyb/sdk/v1/index.js",sdkController:"/widgets/sdk-controller/sdk/v1/index.js",payouts:"/widgets/payouts/sdk/v1/index.js",payments:"/assets/elements.bundle.min.js",sca:"/hosted-sca/sdk/v1/index.js",taxForm:"/widgets/taxForm/sdk/v1/index.js",billing:"/widgets/checkout/sdk/v1/index.js",balance:"/widgets/embedded-balance/sdk/v1/index.js"},Jn={kyc:"kyc",paymentsKyb:"paymentsKyb",kycRfi:"rfi",transactionRfi:"rfi",paymentEnablementRfi:"rfi",lendingRfi:"rfi",mrmRfi:"rfi",payoutForm:"payouts",beneficiaryForm:"payouts",hpp:"payments",cvc:"payments",card:"payments",expiry:"payments",dropIn:"payments",cardNumber:"payments",applePayButton:"payments",googlePayButton:"payments",krCardNumber:"payments",krCardIdentifier:"payments",krCardExpiry:"payments",krCardPswFirstTwo:"payments",scaSetup:"sca",scaVerify:"sca",scaManagement:"sca",taxForm:"taxForm",embeddedCheckout:"billing",balanceOverview:"balance",balanceDetail:"balance",balanceActivities:"balance",balanceActivityDetails:"balance",balanceHistoryChart:"balance",balanceInfo:"balance",balanceScheduledTransactions:"balance",balanceList:"balance"},$n={payments:["hpp","cvc","card","expiry","dropIn","cardNumber","applePayButton","googlePayButton","krCardNumber","krCardIdentifier","krCardExpiry","krCardPswFirstTwo"],payouts:["payoutForm","beneficiaryForm"],onboarding:["kyc","paymentsKyb"],risk:["scaSetup","scaVerify","scaManagement","transactionRfi","kycRfi","paymentEnablementRfi","lendingRfi","mrmRfi"],billing:["embeddedCheckout"],balance:["balanceOverview","balanceDetail","balanceActivities","balanceHistoryChart","balanceInfo","balanceScheduledTransactions","balanceList","balanceActivityDetails"]},Qn={billing:["payments"]},Yn=["payments","sca","billing"],Zn=function(n){function e(e){var t=n.call(this,e)||this;return t.code="INVALID_STATIC_RESOURCE_ERROR",t}return Pn(e,n),e}(Error),ne=Date.now(),ee=function(n){return Jn[n]},te=function(n){var e=n.reduce((function(n,e){return n.concat((t=e,Object.keys($n).includes(t)?$n[e]:e));var t}),[]);return Array.from(new Set(e)).map((function(n){return{elementName:n,sdkName:ee(n)}}))},re=function(n){return"payments"===n?"payment":n},ie=function(n){var e=n.name,t=n.env,r=function(n,e){var t=n===Vn?Bn:Wn;return t[e]||t.prod}(e,void 0===t?Un.prod:t),i=Gn[e];if(!i)throw Kn("[components-sdk] Element static resource not found",{sdkName:e}),new Zn("Element ".concat(e," static resource URL is invalid."));return"".concat(r).concat(i,"?ts=").concat(ne)},oe=function(){return Math.floor(performance.now())},ae=function(n){function e(e){var t=n.call(this,e)||this;return t.code="INSTANCE_NOT_FOUND_ERROR",t}return Pn(e,n),e}(Error),se=new Map,ue=function(n){var e=n.scriptName,t=ie({name:e,env:n.env}),r=se.get(e);if(r)return r;var i=function(n){return On(void 0,0,void 0,(function(){var e,t;return jn(this,(function(r){switch(r.label){case 0:if("undefined"==typeof window)throw new Error("Please load script in browser environment");e=0,t=function(){return On(void 0,0,void 0,(function(){var t,r,i;return jn(this,(function(){return t=oe(),e>0&&n.includes("?ts=")&&((r=new URL(n,window.location.href)).searchParams.set("ts","".concat(Date.now())),n=r.toString()),i=function(n){var e=document.createElement("script");return e.src=n,e.type="module",(document.head||document.body).appendChild(e),e}(n),[2,new Promise((function(r,o){i.addEventListener("load",(function(){var i=oe();Hn("[components-sdk] SDK script loaded",{scriptUrl:n,start:t,latency:i-t,end:i,retryCount:e}),r(!0)})),i.addEventListener("error",(function(r){i.remove(),console.error(r);var a=oe();Kn("[components-sdk] Failed to load script",{scriptUrl:n,error:r,start:t,latency:a-t,end:a,retryCount:e}),o(new qn("Failed to load Airwallex SDK scripts: ".concat(n)))}))}))]}))}))},r.label=1;case 1:if(!(e<3))return[3,7];r.label=2;case 2:return r.trys.push([2,4,,6]),[4,t()];case 3:return[2,r.sent()];case 4:return r.sent(),e++,[4,(void 0===i&&(i=500),new Promise((function(n){return window.setTimeout(n,i)})))];case 5:return r.sent(),[3,6];case 6:return[3,1];case 7:throw Kn("[components-sdk] Failed to load script after retry",{scriptUrl:n,retryCount:e}),new qn("Failed to load Airwallex SDK scripts: ".concat(n))}var i}))}))}(t);return se.set(e,i),i},ce=function(n){var e=n.env,t=n.scriptName;return On(void 0,0,void 0,(function(){var n;return jn(this,(function(r){switch(r.label){case 0:return(n=Qn[t]||[]).length>0?[4,Promise.all(n.map((function(n){return ue({env:e,scriptName:n})})))]:[3,2];case 1:r.sent(),r.label=2;case 2:return[2,ue({env:e,scriptName:t})]}}))}))},le=function(n){return On(void 0,0,void 0,(function(){return jn(this,(function(){if("undefined"==typeof window)throw new Error("Please call the `init()` function in a browser environment.");var e,t;return t=n.clientId,void 0===(e=n.env)&&(e=j.production),window._AirwallexSDKs.airTracker||(window._AirwallexSDKs.airTracker=new Dn({config:{appName:"components-sdk",appVersion:"1.35.1",env:Fn[e]||j.production}}),window._AirwallexSDKs.airTracker.updateCommonData({clientId:t})),window,Hn("[components-sdk] SDK init start",{options:Mn(n),start:oe()}),zn=new Promise((function(e,t){var r,i=Rn(Rn({},n),{env:n.env&&Un[n.env]?n.env:Un.prod});window.AirwallexComponentsSDK.__env__=i.env;var o=ue({env:i.env,scriptName:Xn}).then((function(){return window._AirwallexSDKs.__controller__.init(i)})),a=null!==(r=n.enabledElements)&&void 0!==r?r:[],s=function(n){return Array.from(new Set(te(n).map((function(n){return n.sdkName})).filter((function(n){return Yn.includes(n)}))))}(a),u=s.map((function(n){return ce({env:i.env,scriptName:n}).then((function(){return o})).then((function(){var e=window._AirwallexSDKs[re(n)];if(!e)throw Kn("[components-sdk] SDK instance not found",{functionsNamespace:n,windowSDKInstanceName:re(n)}),new ae("SDK instance not found");return window._AirwallexSDKs.__controller__.registerFunctions({functionsNamespace:n,instance:e})}))})),c=te(a).map((function(n){var e=n.sdkName,t=n.elementName;return ce({scriptName:e,env:i.env}).then((function(){return o})).then((function(){var n=window._AirwallexSDKs[re(e)];if(!n)throw Kn("[components-sdk] SDK instance not found",{sdkName:e,windowSDKInstanceName:re(e)}),new ae("SDK instance not found");return window._AirwallexSDKs.__controller__.registerElement({sdkName:e,elementName:t,instance:n})}))}));Promise.all(An(An([o],u),c)).then((function(){Hn("[components-sdk] SDK initialized",{options:Mn(n),start:oe()}),e(Yn.reduce((function(n,e){var t;return Rn(Rn({},n),((t={})[e]=window._AirwallexSDKs.__controller__.internalSDKs[e],t))}),{}))})).catch((function(n){n.code||Kn("[components-sdk] Unexpected errors when init",{error:n}),t(n)}))})),[2,zn]}))}))},de=function(n,e){return On(void 0,0,void 0,(function(){var t,r,i,o,a;return jn(this,(function(s){switch(s.label){case 0:if(!n)throw new Error("Element type is missing. Please specify a valid element.");if(Hn("[components-sdk] SDK createElement start",{elementName:n,options:Mn(e),timestamp:oe()}),!zn)throw function(){var n;null===(n=window._AirwallexSDKs.airTracker)||void 0===n||n.warn("[components-sdk] Did not call init before createElement",Rn(Rn({},void 0),{context:"components-sdk"}))}(),new Error("Please initialize the Element before creating it.");return[4,zn];case 1:if(s.sent(),!(t=ee(n)))throw new Error("`createElement()` with type `".concat(n,"` is not supported. Please specify a valid Element type."));r=oe(),s.label=2;case 2:return s.trys.push([2,6,,7]),[4,ce({scriptName:t,env:window.AirwallexComponentsSDK.__env__||Un.prod})];case 3:return s.sent(),[4,window._AirwallexSDKs.__controller__.registerElement({sdkName:t,elementName:n,instance:window._AirwallexSDKs[re(t)]})];case 4:return s.sent(),[4,window._AirwallexSDKs.__controller__.createElement(n,e)];case 5:return i=s.sent(),o=oe(),Hn("[components-sdk] SDK createElement being called",{elementName:n,options:Mn(e),start:r,latency:o-r,end:o}),[3,7];case 6:if((a=s.sent()).code)throw a;return Kn("[components-sdk] Unexpected errors when createElement",{error:a}),[3,7];case 7:return[2,i]}}))}))},fe=[Xn,Vn],ve=function(){fe.forEach((function(n){var e=ie({name:n,env:Un.prod}),t=document.createElement("link");t.href=e,t.rel="modulepreload",t.as="script",(document.head||document.body).appendChild(t)}))};"undefined"==typeof document||"undefined"==typeof window||("loading"===document.readyState?document.addEventListener("DOMContentLoaded",ve):ve()),"undefined"!=typeof window&&(window.AirwallexComponentsSDK||Object.defineProperties(window,{AirwallexComponentsSDK:{value:{},writable:!1},_AirwallexSDKs:{value:{},writable:!1}}),window.AirwallexComponentsSDK.init=le,window.AirwallexComponentsSDK.createElement=de);const{onChange:me,reset:pe,state:he}=n((()=>({clientSecret:null,currency:null,hasPaymentError:!1,isReady:!1,paymentConfirmed:!1,paymentIntentId:null}))),ye=n=>"AIRWALLEX"===n.paymentProcessor&&(n.clientSecret&&(he.clientSecret=n.clientSecret),n.paymentIntentId&&(he.paymentIntentId=n.paymentIntentId),!!he.clientSecret||(o("Airwallex checkout session is missing the client secret"),!1)),we={ar:"ar",da:"da",de:"de",en:"en",es:"es",fr:"fr",id:"id",it:"it",ja:"ja",ko:"ko",nl:"nl",pl:"pl",pt:"pt",ru:"ru",sv:"sv",zh:"zh"},be=n=>we[n]||"en";let ge=null;const ke=async()=>!!he.isReady||(ge||(ge=le({enabledElements:["payments"],env:e.zonosMode&&"production"!==e.zonosMode||"LIVE"!==e.checkoutSettings.mode?"demo":"prod",locale:be(r.selectedLocale)}).then((()=>(he.isReady=!0,u("Airwallex SDK initialized"),!0))).catch((n=>(o(n),ge=null,!1)))),ge),xe=["SUCCEEDED","REQUIRES_CAPTURE","PENDING_REVIEW","PENDING"],Ee=n=>!!n&&xe.includes(n),Ie=n=>{switch(n){case"SUCCEEDED":return{isError:!1,messages:[t("Thank you for submitting your payment. We appreciate your prompt attention."),"",t("A confirmation email with your payment details has been sent for your records. If you have any questions or need support, our team is here to help.")]};case"PENDING":case"PENDING_REVIEW":case"REQUIRES_CAPTURE":return{isError:!1,messages:[t("Payment processing. We'll update you when payment is received.")]};case"REQUIRES_CUSTOMER_ACTION":return{isError:!1,messages:[t("Your selected payment method requires additional verification. Please follow the instructions provided by your payment provider to complete the transaction.")]};case"CANCELLED":case"REQUIRES_PAYMENT_METHOD":return{isError:!0,messages:[t("Payment failed. Please reload the page and try another payment method.")]};default:return{isError:!0,messages:[t("Something went wrong.")]}}},Se=async n=>{const{errors:e,json:t}=await a("/api/zonos-elements/collect/airwallex-payment-intent",{body:{paymentIntentId:n},method:"POST"});return e.length||!t?(o("Failed to retrieve Airwallex payment intent",e),{status:null}):{status:t.airwallexPaymentIntent.status}},{state:Ne}=n((()=>({amountDutyTaxFeeTotal:null,amountTotalPaid:null,collectLogoUrl:null,isFetchingShippingInfo:!0,landedCostShortId:null,originCompanyName:null,partyBillingId:null,paymentProcessor:null,shippingAddress:null}))),Ce=async({landedCostId:n,retries:t=5})=>{var r,i,o,u,c,d,f,v,m,p;Ne.isFetchingShippingInfo=!0;const h=await a("/api/zonos-elements/collect/get-shipping-info-by-lc-id",{body:{landedCostId:n},method:"POST"});if(h.errors.length)return t>0?(await new Promise((n=>setTimeout(n,1e3))),Ce({landedCostId:n,retries:t-1})):null;Ne.landedCostShortId=(null===(r=h.json)||void 0===r?void 0:r.landedCostShortId)||null,Ne.isFetchingShippingInfo=!1,Ne.shippingAddress=(null===(i=h.json)||void 0===i?void 0:i.shipping)||null;const y=null===(o=l.checkoutSession)||void 0===o?void 0:o.landedCost,w=null===(u=l.checkoutSession)||void 0===u?void 0:u.subtotals,b=((null===(c=null==y?void 0:y.amountSubtotals)||void 0===c?void 0:c.shipping)||0)+((null===(d=null==y?void 0:y.amountSubtotals)||void 0===d?void 0:d.items)||0);Ne.amountTotalPaid=b*((null===(f=null==w?void 0:w.exchangeRate)||void 0===f?void 0:f.rate)||1),Ne.amountDutyTaxFeeTotal=((null==w?void 0:w.duties)||0)+((null==w?void 0:w.taxes)||0)+((null==w?void 0:w.fees)||0),Ne.originCompanyName=(null===(m=null===(v=h.json)||void 0===v?void 0:v.origin)||void 0===m?void 0:m.companyName)||null,Ne.collectLogoUrl=(null===(p=h.json)||void 0===p?void 0:p.collectLogoUrl)||null,0===Ne.amountTotalPaid&&s({endpoint:"COLLECT_NO_TOTAL_PAID",errors:[],metadata:{landedCostId:n,organizationId:e.organizationId}})},De=async()=>{var n,e,t,r;if(!(null===(n=f.stripeBillingAddressEventData)||void 0===n?void 0:n.complete))return{partiesCreated:!1};const u=null===(t=null===(e=l.checkoutSession)||void 0===e?void 0:e.landedCost)||void 0===t?void 0:t.rootId;if(!u)return s({endpoint:"PF_NO_SELECTED_LANDED_COST",errors:["No selected landed cost"],metadata:{allLogs:c,cartId:window.Zonos.cartId,checkoutSessionId:i.checkoutSessionId}}),{partiesCreated:!1};if(!i.checkoutSessionId)return s({endpoint:"COLLECT_NO_CHECKOUT_SESSION_ID",errors:["No checkout session id"],metadata:{allLogs:c,cartId:window.Zonos.cartId,landedCostRootId:u}}),{partiesCreated:!1};const d=v({address:f.stripeBillingAddressEventData.value.address,firstName:f.stripeBillingAddressEventData.value.firstName,lastName:f.stripeBillingAddressEventData.value.lastName,name:f.stripeBillingAddressEventData.value.name,phone:f.stripeBillingAddressEventData.value.phone}),m="1"===new URLSearchParams(window.location.search).get("zonosE2ETest"),{errors:p,json:h}=await a("/api/zonos-elements/create-billing-party",{body:{billingAddress:d,checkoutSessionId:i.checkoutSessionId,companyName:f.companyName,email:(null===(r=f.stripeLinkEventData)||void 0===r?void 0:r.value.email)||"",isTest:m,rootId:u},method:"POST"});return p.length||!h?(o("Error occurs when creating billing party",JSON.stringify(p,null,2)),s({endpoint:"COLLECT_BILLING_PARTY_CREATE_FAILED",errors:["[COLLECT] Failed to create billing party"],metadata:{allLogs:c,cartId:window.Zonos.cartId,checkoutSessionId:i.checkoutSessionId,errors:p,json:h}}),{partiesCreated:!1}):(Ne.partyBillingId=h.billToPartyId,{partiesCreated:!0})},Te=async n=>{const e=n.landedCost;return!!e&&(l.landedCostData=[Object.assign(Object.assign({},n),{landedCost:Object.assign({},e),landedCostId:e.id})],d({applySubtotalsOnly:!0,landedCostId:e.id,selectedShippingOption:e.shipmentRating}))};export{ye as a,he as b,Ne as c,Se as d,Ee as e,ke as f,Te as g,Ce as h,De as i,Ie as j,pe as k,de as l,be as m,me as n}
|