@zonos/elements 1.3.227 → 1.3.229
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/{cart-af017ac3.js → cart-ad82a680.js} +2 -2
- package/dist/cjs/index.cjs.js +7 -7
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{localization-21030292.js → localization-31e3dfe3.js} +1 -1
- package/dist/cjs/{paypal-2b22f0f5.js → paypal-88b5e878.js} +3 -3
- package/dist/cjs/{placeTestOrder-9cde1ca4.js → placeTestOrder-6aefbf9c.js} +2 -2
- package/dist/cjs/{renderFallback-9300dbaf.js → renderFallback-87c908ad.js} +2 -2
- package/dist/cjs/{translationStore-ce2c700d.js → translationStore-b8b25e9d.js} +240 -0
- package/dist/cjs/zonos-address_11.cjs.entry.js +3 -3
- package/dist/cjs/{zonos-cart-items_12.cjs.entry.js → zonos-cart-items_13.cjs.entry.js} +23 -5
- package/dist/cjs/zonos-checkout.cjs.entry.js +27 -15
- package/dist/cjs/zonos-collect-cart-items_3.cjs.entry.js +3 -3
- package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +6 -6
- package/dist/cjs/zonos-collect.cjs.entry.js +5 -5
- package/dist/cjs/zonos-confirm-dialog_2.cjs.entry.js +1 -1
- package/dist/cjs/zonos-controller.cjs.entry.js +3 -3
- package/dist/cjs/zonos-country-flag.cjs.entry.js +2 -2
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +2 -2
- package/dist/cjs/zonos-elements.cjs.js +1 -1
- package/dist/cjs/zonos-empty-state-payment_4.cjs.entry.js +4 -4
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +2 -2
- package/dist/cjs/zonos-hello.cjs.entry.js +2 -2
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +2 -2
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +26 -13
- package/dist/collection/components/store/translationStore/strings.arabic.js +12 -0
- package/dist/collection/components/store/translationStore/strings.base.js +12 -0
- package/dist/collection/components/store/translationStore/strings.chinese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.danish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.dutch.js +12 -0
- package/dist/collection/components/store/translationStore/strings.french.js +12 -0
- package/dist/collection/components/store/translationStore/strings.german.js +12 -0
- package/dist/collection/components/store/translationStore/strings.hebrew.js +12 -0
- package/dist/collection/components/store/translationStore/strings.indonesian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.italian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.japanese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.korean.js +12 -0
- package/dist/collection/components/store/translationStore/strings.norwegian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.polish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.portuguese.js +12 -0
- package/dist/collection/components/store/translationStore/strings.russian.js +12 -0
- package/dist/collection/components/store/translationStore/strings.spanish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.swedish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.turkish.js +12 -0
- package/dist/collection/components/store/translationStore/strings.vietnamese.js +12 -0
- package/dist/esm/{cart-11b87221.js → cart-c74f9aaa.js} +3 -3
- package/dist/esm/index.js +7 -7
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{localization-9320a65d.js → localization-106476cb.js} +1 -1
- package/dist/esm/{paypal-338a4350.js → paypal-bf3a2bdd.js} +3 -3
- package/dist/esm/{placeTestOrder-d28f33c2.js → placeTestOrder-891295e8.js} +2 -2
- package/dist/esm/{renderFallback-28ef3364.js → renderFallback-ce0e238a.js} +2 -2
- package/dist/esm/{translationStore-7eebaa41.js → translationStore-766b7521.js} +240 -0
- package/dist/esm/zonos-address_11.entry.js +3 -3
- package/dist/esm/{zonos-cart-items_12.entry.js → zonos-cart-items_13.entry.js} +23 -6
- package/dist/esm/zonos-checkout.entry.js +28 -16
- package/dist/esm/zonos-collect-cart-items_3.entry.js +3 -3
- package/dist/esm/zonos-collect-finish_6.entry.js +6 -6
- package/dist/esm/zonos-collect.entry.js +5 -5
- package/dist/esm/zonos-confirm-dialog_2.entry.js +1 -1
- package/dist/esm/zonos-controller.entry.js +3 -3
- package/dist/esm/zonos-country-flag.entry.js +2 -2
- package/dist/esm/zonos-country-select_4.entry.js +2 -2
- package/dist/esm/zonos-elements.js +1 -1
- package/dist/esm/zonos-empty-state-payment_4.entry.js +4 -4
- package/dist/esm/zonos-hello-dialog.entry.js +2 -2
- package/dist/esm/zonos-hello.entry.js +2 -2
- package/dist/esm/zonos-language-select_2.entry.js +2 -2
- package/dist/esm-es5/{cart-11b87221.js → cart-c74f9aaa.js} +1 -1
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/{localization-9320a65d.js → localization-106476cb.js} +1 -1
- package/dist/esm-es5/{paypal-338a4350.js → paypal-bf3a2bdd.js} +1 -1
- package/dist/esm-es5/placeTestOrder-891295e8.js +1 -0
- package/dist/esm-es5/{renderFallback-28ef3364.js → renderFallback-ce0e238a.js} +1 -1
- package/dist/esm-es5/translationStore-766b7521.js +1 -0
- package/dist/esm-es5/zonos-address_11.entry.js +1 -1
- package/dist/esm-es5/{zonos-cart-items_12.entry.js → zonos-cart-items_13.entry.js} +1 -1
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-cart-items_3.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-confirm-dialog_2.entry.js +1 -1
- package/dist/esm-es5/zonos-controller.entry.js +1 -1
- package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
- package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
- package/dist/esm-es5/zonos-elements.js +1 -1
- package/dist/esm-es5/zonos-empty-state-payment_4.entry.js +1 -1
- package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
- package/dist/esm-es5/zonos-hello.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/scripts/index.d.ts +10 -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/components/checkout/zonos-checkout/zonos-checkout.d.ts +5 -4
- package/dist/types/components/store/translationStore/strings.arabic.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.base.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.chinese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.danish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.dutch.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.french.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.german.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.hebrew.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.indonesian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.italian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.japanese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.korean.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.norwegian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.polish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.portuguese.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.russian.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.spanish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.swedish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.turkish.d.ts +12 -0
- package/dist/types/components/store/translationStore/strings.vietnamese.d.ts +12 -0
- package/dist/types/types/generated/graphql.internal.types.d.ts +21 -0
- package/dist/types/types/generated/graphql.internal.types.ts +7 -0
- package/dist/types/types/utils/ZonosSettings.d.ts +4 -0
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-19305aa8.entry.js → p-053a042e.entry.js} +1 -1
- package/dist/zonos-elements/p-0d3767ec.entry.js +1 -0
- package/dist/zonos-elements/{p-4ce3489a.entry.js → p-10894d36.entry.js} +1 -1
- package/dist/zonos-elements/{p-1c5ba523.js → p-1d15662c.js} +1 -1
- package/dist/zonos-elements/{p-0260fd13.js → p-203c7fda.js} +1 -1
- package/dist/zonos-elements/{p-e00e5d64.system.entry.js → p-21b251f0.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-2657f099.system.entry.js → p-225a61c4.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-4004c838.system.entry.js → p-236e0144.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-9e03a145.system.entry.js → p-23f6a2fb.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-bfc0fc85.system.entry.js → p-288f5a5b.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-1ef793d0.entry.js → p-2b84039a.entry.js} +1 -1
- package/dist/zonos-elements/{p-04c1dc63.system.entry.js → p-2db90c99.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-ba334962.system.entry.js → p-3d2925c5.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-ae3e4f2b.entry.js → p-462f8857.entry.js} +1 -1
- package/dist/zonos-elements/{p-1868a283.entry.js → p-5608ac9d.entry.js} +1 -1
- package/dist/zonos-elements/{p-0b6a3a09.system.entry.js → p-57ee34aa.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-d531b524.system.js → p-595668d7.system.js} +1 -1
- package/dist/zonos-elements/{p-67787bd4.entry.js → p-62803534.entry.js} +1 -1
- package/dist/zonos-elements/p-6497ce22.entry.js +1 -0
- package/dist/zonos-elements/{p-6092af05.entry.js → p-65db3219.entry.js} +1 -1
- package/dist/zonos-elements/{p-7cee0e68.system.entry.js → p-6c8e4f01.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-1b9cc0e2.system.entry.js → p-6f1024de.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-0a92e3fd.entry.js → p-76f924b3.entry.js} +1 -1
- package/dist/zonos-elements/{p-375994d1.system.entry.js → p-7a97e1cf.system.entry.js} +1 -1
- package/dist/zonos-elements/p-81b357f7.system.js +1 -1
- package/dist/zonos-elements/p-94853366.system.entry.js +1 -0
- package/dist/zonos-elements/{p-4dfe97ad.js → p-964a4d85.js} +2 -2
- package/dist/zonos-elements/{p-2616ba72.entry.js → p-9972941a.entry.js} +1 -1
- package/dist/zonos-elements/{p-290715a7.system.js → p-9c728733.system.js} +1 -1
- package/dist/zonos-elements/{p-bcf11c99.system.entry.js → p-ad7be556.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-cb0e6468.entry.js → p-b0a75761.entry.js} +1 -1
- package/dist/zonos-elements/p-b4fe3604.system.js +1 -0
- package/dist/zonos-elements/p-b8293509.js +1 -0
- package/dist/zonos-elements/{p-873b6185.system.entry.js → p-bd373de0.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-7eb8e2d4.js → p-c3c3cd98.js} +1 -1
- package/dist/zonos-elements/{p-0ec82d78.system.js → p-c89e9d56.system.js} +1 -1
- package/dist/zonos-elements/{p-725605f6.system.js → p-cdaf52f4.system.js} +1 -1
- package/dist/zonos-elements/{p-b5b3f908.system.js → p-cef1e888.system.js} +1 -1
- package/dist/zonos-elements/{p-e60b988c.entry.js → p-cf56b990.entry.js} +1 -1
- package/dist/zonos-elements/{p-112c6453.system.js → p-de984173.system.js} +1 -1
- package/dist/zonos-elements/p-eea0d8af.js +1 -0
- package/dist/zonos-elements/{p-252fa1da.entry.js → p-f4085c23.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/zonos-link.cjs.entry.js +0 -24
- package/dist/esm/zonos-link.entry.js +0 -20
- package/dist/esm-es5/placeTestOrder-d28f33c2.js +0 -1
- package/dist/esm-es5/translationStore-7eebaa41.js +0 -1
- package/dist/esm-es5/zonos-link.entry.js +0 -1
- package/dist/zonos-elements/p-02667a58.entry.js +0 -1
- package/dist/zonos-elements/p-0d82e1fd.entry.js +0 -1
- package/dist/zonos-elements/p-182da73f.system.js +0 -1
- package/dist/zonos-elements/p-5c43ecdf.system.entry.js +0 -1
- package/dist/zonos-elements/p-820ad058.js +0 -1
- package/dist/zonos-elements/p-a800965d.system.entry.js +0 -1
- package/dist/zonos-elements/p-cc599cd9.entry.js +0 -1
- package/dist/zonos-elements/p-d42b5113.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,r,t,o){function n(e){return e instanceof t?e:new t((function(r){r(e)}))}return new(t||(t=Promise))((function(t,a){function i(e){try{u(o.next(e))}catch(e){a(e)}}function l(e){try{u(o["throw"](e))}catch(e){a(e)}}function u(e){e.done?t(e.value):n(e.value).then(i,l)}u((o=o.apply(e,r||[])).next())}))};var __generator=this&&this.__generator||function(e,r){var t={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},o,n,a,i;return i={next:l(0),throw:l(1),return:l(2)},typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function l(e){return function(r){return u([e,r])}}function u(l){if(o)throw new TypeError("Generator is already executing.");while(i&&(i=0,l[0]&&(t=0)),t)try{if(o=1,n&&(a=l[0]&2?n["return"]:l[0]?n["throw"]||((a=n["return"])&&a.call(n),0):n.next)&&!(a=a.call(n,l[1])).done)return a;if(n=0,a)l=[l[0]&2,a.value];switch(l[0]){case 0:case 1:a=l;break;case 4:t.label++;return{value:l[1],done:false};case 5:t.label++;n=l[1];l=[0];continue;case 7:l=t.ops.pop();t.trys.pop();continue;default:if(!(a=t.trys,a=a.length>0&&a[a.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!a||l[1]>a[0]&&l[1]<a[3])){t.label=l[1];break}if(l[0]===6&&t.label<a[1]){t.label=a[1];a=l;break}if(a&&t.label<a[2]){t.label=a[2];t.ops.push(l);break}if(a[2])t.ops.pop();t.trys.pop();continue}l=r.call(e,t)}catch(e){l=[6,e];n=0}finally{o=a=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:true}}};import{c as createStore,z as zonosStore}from"./zonosStore-e3d0493a.js";import{j as jsonParse,h as handleFetch,l as logError}from"./handleFetch-a844cac1.js";import{a as availableTestKeys,l as log}from"./VarianceTest-572cecf5.js";import{a as translationStoreUpdateLanguage}from"./translationStore-7eebaa41.js";var hasAtLeastOneAvailableTestKey=function(e){var r=!!e.find((function(e){return e.testKey in availableTestKeys}));if(!r){log("No available test key found in response","info",{response:e})}return!!e.find((function(e){return e.testKey in availableTestKeys}))};var filterValidTests=function(e){if(!hasAtLeastOneAvailableTestKey(e)){return[]}return e.filter((function(e){var r;var t=availableTestKeys[e.testKey]&&!e.selectedVariantKey;var o=e.selectedVariantKey&&!!((r=availableTestKeys[e.testKey])===null||r===void 0?void 0:r["availableVariants"].includes(e.selectedVariantKey));return t||o})).map((function(e){return Object.assign(Object.assign({},e),{expiresAt:e.expiresAt||Date.now()+VARIANT_TEST_KEY_EXPIRATION,selectedVariantKey:e.selectedVariantKey||null})}))};var VARIANT_TEST_KEY_EXPIRATION=60*60*24*1e3;var _d=createStore({checkoutSessionId:sessionStorage.getItem("zonos--checkout-session-id"),enabledVariantTestKeys:jsonParse(localStorage.getItem("zonos--enabled-variant-test-keys"))}),storageStoreOnChange=_d.onChange,storageStore=_d.state;storageStoreOnChange("enabledVariantTestKeys",(function(){var e;if(!((e=storageStore.enabledVariantTestKeys)===null||e===void 0?void 0:e.length)){localStorage.removeItem("zonos--enabled-variant-test-keys");return}localStorage.setItem("zonos--enabled-variant-test-keys",JSON.stringify(storageStore.enabledVariantTestKeys))}));storageStoreOnChange("checkoutSessionId",(function(){if(!storageStore.checkoutSessionId){sessionStorage.removeItem("zonos--checkout-session-id");return}sessionStorage.setItem("zonos--checkout-session-id",storageStore.checkoutSessionId)}));var storageStoreSetEnabledVariantTestKeys=function(e){storageStore.enabledVariantTestKeys=filterValidTests(e)};var getCountries=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o;return __generator(this,(function(n){switch(n.label){case 0:n.trys.push([0,2,,3]);return[4,handleFetch("/api/zonos-elements/get-countries",{method:"GET"})];case 1:e=n.sent(),r=e.errors,t=e.json;if(r.length||!t){return[2,null]}return[2,t];case 2:o=n.sent();return[2,null];case 3:return[2]}}))}))};var getCountryLandedCost=function(e){return __awaiter(void 0,void 0,void 0,(function(){var r,t,o,n,a;return __generator(this,(function(i){switch(i.label){case 0:if(!e){return[2,null]}t="/api/zonos-elements/country-landed-cost/".concat(e);return[4,handleFetch(t)];case 1:o=i.sent(),n=o.errors,a=o.json;if(n.length||!a){logError("Error fetching country landed cost: ".concat((r=n.find(Boolean))===null||r===void 0?void 0:r.message));return[2,null]}return[2,a||null]}}))}))};var defaultUsExchangeRate={exchangeRate:{rate:1,targetFormat:{currencyCode:"USD",decimalDelimiter:".",scale:2,symbol:"$",symbolLocation:"before",thousandsDelimiter:","}},maxAge:null};var getExchangeRate=function(e){return __awaiter(void 0,[e],void 0,(function(e){var r,t,o,n,a,i,l,u,c,s;var d=e.country,v=e.isGuaranteed,f=e.sourceCurrency,g=e.targetCurrency;return __generator(this,(function(e){switch(e.label){case 0:if(f===g&&!v){return[2,defaultUsExchangeRate]}t=new URLSearchParams;t.set("sourceCurrency",f);t.set("targetCurrency",g);t.set("isGuaranteed",String(v));t.set("country",d||"");return[4,handleFetch("/api/zonos-elements/exchange-rates?".concat(t.toString()))];case 1:o=e.sent(),n=o.errors,a=o.json;if(n.length||!a){logError("Error fetching country landed cost: ".concat((r=n.find(Boolean))===null||r===void 0?void 0:r.message));return[2,defaultUsExchangeRate]}i=a.exchangeRateCreate,l=i.rate,u=i.targetFormat;c=a.maxAge;if(l){sessionStorage.setItem(d+"_rate",JSON.stringify(l));s={rate:l,targetFormat:u};return[2,{exchangeRate:s,maxAge:c}]}return[2,defaultUsExchangeRate]}}))}))};var getInclusivePricing=function(e){return __awaiter(void 0,void 0,void 0,(function(){var r,t,o,n;return __generator(this,(function(a){switch(a.label){case 0:if(!e){return[2,null]}return[4,handleFetch("/api/zonos-elements/inclusive-prices/".concat(e))];case 1:t=a.sent(),o=t.errors,n=t.json;if(o.length||!n){logError("Error fetching country inclusive price setting: ".concat((r=o.find(Boolean))===null||r===void 0?void 0:r.message));return[2,null]}return[2,n||null]}}))}))};var getLocaleMessages=function(e){return __awaiter(void 0,[e],void 0,(function(e){var r,t,o,n,a;var i=e.countryCode,l=e.localeTo,u=e.storeId;return __generator(this,(function(e){switch(e.label){case 0:t=new URLSearchParams;t.set("countryCode",i);t.set("storeId",u.toString());if(l){t.set("localeTo",l)}return[4,handleFetch("/api/zonos-elements/locale-messages?".concat(t.toString()))];case 1:o=e.sent(),n=o.errors,a=o.json;if(n.length||!a){logError("Error fetching exchange rate",(r=n.find(Boolean))===null||r===void 0?void 0:r.message);return[2,[]]}return[2,a.locale_countryCodesPage]}}))}))};var validateCountryCode=function(e){if(e&&/^[A-Z]{2}$/.test(e)){return e}return null};var getZCountryUrlParam=function(e){var r=new URLSearchParams(e||window.location.search);var t=function(e){var t=r.get(e);return validateCountryCode(t)};var o=t("zCountry");var n=t("country");var a=t("customerCountry");return o||n||a};var getLocalization=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o,n,a,i,l;return __generator(this,(function(u){switch(u.label){case 0:u.trys.push([0,2,,3]);e=new URL(window.location.href);r=window.sessionStorage.getItem("zonos--country");t=getZCountryUrlParam(e.searchParams)||r;o=new URLSearchParams;if(t){o.set("zCountry",t)}return[4,handleFetch("/api/zonos-elements/localization?".concat(o.toString()))];case 1:n=u.sent(),a=n.errors,i=n.json;if(a.length||!i){return[2,{country:null,locale:null}]}return[2,{country:i.country,locale:i.locale}];case 2:l=u.sent();return[2,{country:null,locale:null}];case 3:return[2]}}))}))};var getShippingZones=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o,n,a,i;return __generator(this,(function(l){switch(l.label){case 0:if((e=window.Zonos.cartSettings)===null||e===void 0?void 0:e.shippingZones){return[2,window.Zonos.cartSettings.shippingZones.flatMap((function(e){return e===null||e===void 0?void 0:e.countryCodes})).filter(Boolean)]}return[4,handleFetch("/api/zonos-elements/shipping-zones")];case 1:o=l.sent(),n=o.errors,a=o.json;if(n.length||!a){logError("Error fetching shipping zones: ".concat((r=n.find(Boolean))===null||r===void 0?void 0:r.message));return[2,null]}i=(t=a===null||a===void 0?void 0:a.shippingZones)===null||t===void 0?void 0:t.flatMap((function(e){return e===null||e===void 0?void 0:e.countryCodes})).filter(Boolean);return[2,i||null]}}))}))};var currencyConvert=function(e){var r=localizationStore.exchangeRate;if(!r||!e||isNaN(e)){return e}var t=(r===null||r===void 0?void 0:r.targetFormat.scale)||2;var o=e*r.rate;var n=o.toFixed(t);return Number(n)};var numberFormat=function(e){var r=e.amount,t=e.currency,o=e.targetFormat;var n=t||localizationStore.targetCurrency;var a=(o===null||o===void 0?void 0:o.scale)||2;var i=window.navigator.userAgent.indexOf("MSIE ")!==-1;var l=typeof Intl==="object"&&Intl&&typeof Intl.NumberFormat==="function";if(i||!l){var u=Number(r).toFixed(a).replace(".","|dec|").replace(",",(o===null||o===void 0?void 0:o.thousandsDelimiter)||"").replace("|dec|",(o===null||o===void 0?void 0:o.decimalDelimiter)||"");return u}var c=new Intl.NumberFormat(window.navigator.language,{currency:n,currencyDisplay:"code",minimumFractionDigits:a,style:"currency"}).format(r);return c.replace(new RegExp("".concat(n,"\\s+")),"")};var currencyFormat=function(e){var r=e.amount,t=e.currency;if(isNaN(r)||r!==0&&!r){return""}var o=zonosStore.overrideCurrencyFormat;var n=localizationStore.exchangeRate;var a=t||localizationStore.targetCurrency;if(typeof o==="function"){return o({amount:r,currencyCode:a,numberFormat:function(e){var r=e.amount;return numberFormat({amount:r,currency:a,targetFormat:(n===null||n===void 0?void 0:n.targetFormat)||null})}})}var i=(n||{}).targetFormat;if(!i||!n){return"".concat(r.toFixed(2)," ").concat(a)}var l=i.scale||2;var u=window.navigator.userAgent.indexOf("MSIE ")!==-1;var c=typeof Intl==="object"&&Intl&&typeof Intl.NumberFormat==="function";if(u||!c){var s=Number(r).toFixed(l).replace(".","|dec|").replace(",",i.thousandsDelimiter||"").replace("|dec|",i.decimalDelimiter||"");var d="".concat(s).concat(i.currencyCode!=="USD"?" ".concat(i.currencyCode):"");return d}var v=(o===null||o===void 0?void 0:o.currencyDisplay)||"symbol";var f=new Intl.NumberFormat(window.navigator.language,{currency:a,currencyDisplay:v,minimumFractionDigits:l,style:"currency"}).format(r);var g=v==="code"?"".concat(f.replace(new RegExp("".concat(a,"\\s+")),"")," ").concat(a):f;return g};var currencyConvertAndFormat=function(e){var r=currencyConvert(e);var t=currencyFormat({amount:r});return t};var isValidSelector=function(e){try{document.createDocumentFragment().querySelector(e)}catch(e){return false}return true};var getCurrencyElements=function(e){var r=e||".money";if(!isValidSelector(r)){logError('Currency element selector "'.concat(r,'" is not valid.'));return null}var t=document.querySelectorAll(r);if(!t.length){log('No currency elements found with selector "'.concat(r,'"'),"warn");return null}return Array.from(t)};var getInitialElementAmount=function(e){var r;var t=e.getAttribute("data-domestic");var o=e.getAttribute("data-zintl");var n=(r=e.textContent)===null||r===void 0?void 0:r.replace(/[^\d.-]/g,"");if(!n){return null}if(!t||e.textContent!==o&&o){e.setAttribute("data-domestic",n);return parseFloat(n)}return parseFloat(t)};var BLUR_CURRENCY_DURATION=7e3;var BLUR_CURRENCY_CLASSNAME="z--blur";var removeBlurCurrency=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r;return __generator(this,(function(t){switch(t.label){case 0:e=window.zonosBlurCurrencyOnInitIntervalId;if(!e){return[2]}return[4,new Promise((function(e){return setTimeout(e,500)}))];case 1:t.sent();clearInterval(e);r=document.querySelectorAll(".".concat(BLUR_CURRENCY_CLASSNAME));r.forEach((function(e){e.classList.remove(BLUR_CURRENCY_CLASSNAME)}));window.zonosBlurCurrencyOnInitIntervalId=undefined;return[2]}}))}))};var blurCurrencyElements=function(e){var r=e.currencySelector;if(!r){return}var t=document.querySelectorAll([r].filter(Boolean).join(","));t.forEach((function(e){e.classList.add(BLUR_CURRENCY_CLASSNAME)}))};var performBlurCurrency=function(){if(typeof window==="undefined"){return}if(window.zonosBlurCurrencyOnInitIntervalId){return}blurCurrencyElements({currencySelector:window.zonosBlurCurrencyOnInitCurrencySelector});var e=setInterval((function(){blurCurrencyElements({currencySelector:window.zonosBlurCurrencyOnInitCurrencySelector})}),10);window.zonosBlurCurrencyOnInitIntervalId=e;setTimeout((function(){void removeBlurCurrency()}),BLUR_CURRENCY_DURATION)};var convertCurrency=function(e){var r;var t=getInitialElementAmount(e);if(!t||isNaN(t)){return}var o=e.getAttribute("data-zintl");var n=parseFloat(e.getAttribute("data-zrate")||"1");var a=e.getAttribute("data-zcountry-code");var i=localizationStore.exchangeRate&&localizationStore.targetCurrency===localizationStore.exchangeRate.targetFormat.currencyCode;var l=((r=localizationStore.exchangeRate)===null||r===void 0?void 0:r.rate)||1;if(i&&(e.textContent!==o||l!==n||a!==localizationStore.selectedCountryCode)){performBlurCurrency();var u=typeof zonosStore.currencyConverter==="function"&&zonosStore.currencyConverter({convert:currencyConvert,convertAndFormat:currencyConvertAndFormat,currencyCode:localizationStore.targetCurrency,format:function(e){return currencyFormat({amount:e})},originalAmount:t,selector:e});var c=u||currencyConvertAndFormat(t);if(c!==e.textContent){e.textContent=c}e.setAttribute("data-zrate",l.toString());e.setAttribute("data-zintl",c);e.setAttribute("data-zcountry-code",localizationStore.selectedCountryCode||"")}void removeBlurCurrency()};var defaultCurrencyConverter=function(){var e=zonosStore.helloSettings.currencyElementSelector;var r=getCurrencyElements(e);if(!(r===null||r===void 0?void 0:r.length)){return}if(!localizationStore.exchangeRate){logError("Could not display currency. Exchange rate and format data is not available.");return}r.forEach((function(e){convertCurrency(e)}))};var currencyDisplay=function(){if(zonosStore.helloSettings.currencyBehavior==="DISABLED"||window.Zonos.isLegacyCheckout){void removeBlurCurrency();return}defaultCurrencyConverter()};var getCurrencyCode=function(e){var r;var t=(r=localizationStore.shippingZoneCountries)===null||r===void 0?void 0:r[e];if(t){return t.currencyCode}return null};var setZCountryUrlParam=function(e){if(!e){return}var r=new URLSearchParams(window.location.search);var t=r.has("zCountry")||zonosStore.helloSettings.countryOverrideBehavior==="URL_PARAM";if(t){r.set("zCountry",e);var o="".concat(window.location.pathname,"?").concat(r.toString());window.history.replaceState(window.history.state,document.title,o)}};var _e=createStore({countryLandedCost:null,customMessages:[],exchangeRate:null,helloCountryList:null,inclusivePricing:null,isDisabledCountry:true,isShippableCountry:false,localizationLoaded:false,selectedCountryCode:null,selectedLocale:"en",shippingZoneCountries:null,targetCurrency:"USD"}),localizationDispose=_e.dispose,localizationStoreOnChange=_e.onChange,localizationStore=_e.state;var triggerGetExchangeRate=function(e){return __awaiter(void 0,void 0,void 0,(function(){var r,t,o;return __generator(this,(function(n){switch(n.label){case 0:return[4,getExchangeRate({country:localizationStore.selectedCountryCode,isGuaranteed:e,sourceCurrency:zonosStore.sourceCurrency,targetCurrency:localizationStore.targetCurrency})];case 1:r=n.sent(),t=r.exchangeRate,o=r.maxAge;if(t){localizationStore.exchangeRate=t;currencyDisplay()}return[2,{maxAge:o}]}}))}))};var DEFAULT_COUNTRY_CODE_LEGACY_CHECKOUT="CA";var getFallbackDefaultCountryCode=function(e){if(localizationStore.selectedCountryCode&&e.includes(localizationStore.selectedCountryCode)){return localizationStore.selectedCountryCode}return DEFAULT_COUNTRY_CODE_LEGACY_CHECKOUT};var startExchangeRateTimeout=function(e){var r=e.isGuaranteed,t=e.maxAge;if(localizationStore.exchangeRateTimeout){clearTimeout(localizationStore.exchangeRateTimeout)}var o=5*60;var n=t||o;localizationStore.exchangeRateTimeout=setTimeout((function(){return __awaiter(void 0,void 0,void 0,(function(){var e;return __generator(this,(function(t){switch(t.label){case 0:return[4,triggerGetExchangeRate(r)];case 1:e=t.sent().maxAge;startExchangeRateTimeout({isGuaranteed:r,maxAge:e});return[2]}}))}))}),n*1e3)};var getNewLocalization=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o,n,a,i,l;return __generator(this,(function(u){switch(u.label){case 0:log("get new localization store");r=localizationStore.isDisabledCountry,t=localizationStore.isShippableCountry,o=localizationStore.selectedCountryCode;if(zonosStore.helloSettings.currencyBehavior==="DISABLED"||!t||r||!o){return[2]}n=zonosStore.checkoutSettings.visibilityStatus==="ENABLED";performBlurCurrency();return[4,triggerGetExchangeRate(n)];case 1:a=u.sent().maxAge;startExchangeRateTimeout({isGuaranteed:n,maxAge:a});if(!!window.Zonos.isLegacyCheckout)return[3,4];i=localizationStore;return[4,getCountryLandedCost(localizationStore.selectedCountryCode)];case 2:i.countryLandedCost=u.sent();l=localizationStore;return[4,getInclusivePricing(o)];case 3:l.inclusivePricing=((e=u.sent())===null||e===void 0?void 0:e.setting)||null;if(localizationStore.inclusivePricing){log("Inclusive price setting found for this country (".concat(o,") ").concat(JSON.stringify(localizationStore.inclusivePricing,null,2)))}return[3,5];case 4:log("Skipping country landed cost and inclusive pricing requests, because this is a legacy checkout");u.label=5;case 5:return[2]}}))}))};var getCustomMessages=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r;return __generator(this,(function(t){switch(t.label){case 0:log("Getting custom messages for ".concat(localizationStore.selectedCountryCode));if(!localizationStore.selectedCountryCode||!zonosStore.storeId){return[2]}return[4,getLocaleMessages({countryCode:localizationStore.selectedCountryCode,localeTo:localizationStore.selectedLocale,storeId:zonosStore.storeId})];case 1:e=t.sent();r=e.flatMap((function(e){var r;return{countryCode:localizationStore.selectedCountryCode,message:(r=e.countryCodesPageMessageLinks.find(Boolean))===null||r===void 0?void 0:r.message.textTo,pageName:e.pageName}}));localizationStore.customMessages=r;return[2]}}))}))};var getOverrideLocale=function(){var e=new URL(window.location.href);var r=e.searchParams.get("zonosLocale");return r};var addInternationalHideClass=function(){if(localizationStore.isShippableCountry){document.body.classList.add("z-intl")}else{document.body.classList.remove("z-intl")}};var getValidCountryCode=function(e){if(e==="UK"){return"GB"}return e};var localizationStoreUpdateSelectedCountryCode=function(e){var r,t;log("Updating selected country code to ".concat(e));var o=!localizationStore.selectedCountryCode;localizationStore.selectedCountryCode=getValidCountryCode(e);var n=localizationStore.selectedCountryCode,a=localizationStore.shippingZoneCountries;var i=!!a&&!!n&&!!a[n]&&!zonosStore.disabledCountries.includes(n);localizationStore.isShippableCountry=i;log("".concat(localizationStore.selectedCountryCode," is a shippable country: ").concat(localizationStore.isShippableCountry));var l=!!n&&zonosStore.disabledCountries.includes(n);localizationStore.isDisabledCountry=l;log("".concat(localizationStore.selectedCountryCode," is a disabled country: ").concat(localizationStore.isDisabledCountry));addInternationalHideClass();if(!n){return}var u=getCurrencyCode(n);if(!o){(r=zonosStore.onCountryChange)===null||r===void 0?void 0:r.call(zonosStore,{countryCode:n,currencyCode:u,isShippableCountry:i})}if(!u){return}localizationStore.targetCurrency=u;void getNewLocalization();window.sessionStorage.setItem("zonos--country",n);setZCountryUrlParam(n);(t=document.querySelector("zonos-hello"))===null||t===void 0?void 0:t.setAttribute("z-country",n)};var initHelloCountryList=function(e){var r=zonosStore.helloSettings.showCountryList;var t=localizationStore.shippingZoneCountries;if(!r||r==="ONLY_SHIPPABLE"){localizationStore.helloCountryList=t;return}if(r==="ALL"){localizationStore.helloCountryList=e;return}localizationStore.helloCountryList=r.reduce((function(r,t){var o;var n=e===null||e===void 0?void 0:e[t];return n?Object.assign(Object.assign({},r),(o={},o[t]=n,o)):r}),{})};var updateCheckoutSessionLanguage=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t;return __generator(this,(function(o){switch(o.label){case 0:if(!storageStore.checkoutSessionId){return[2,null]}return[4,handleFetch("/api/zonos-elements/update-checkout-session-metadata",{body:{id:storageStore.checkoutSessionId,metadata:[{key:"language",value:localizationStore.selectedLocale}]},method:"POST"})];case 1:e=o.sent(),r=e.errors,t=e.json;if(r.length||!t){logError("Error occurs when updating checkout session",JSON.stringify(r,null,2));return[2,{errors:r,json:t}]}return[2,{errors:[],json:t}]}}))}))};var localizationStoreUpdateSelectedLocale=function(e){localizationStore.selectedLocale=e;translationStoreUpdateLanguage(e);void updateCheckoutSessionLanguage();void getCustomMessages()};var initLocalizationStore=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o,n,a,i,l,u;return __generator(this,(function(c){switch(c.label){case 0:return[4,Promise.all([getCountries(),getShippingZones(),getLocalization()])];case 1:e=c.sent(),r=e[0],t=e[1],o=e[2];n=t===null||t===void 0?void 0:t.reduce((function(e,t){var o;var n=r===null||r===void 0?void 0:r[t];return n?Object.assign(Object.assign({},e),(o={},o[t]=n,o)):e}),{});localizationStore.shippingZoneCountries=n||null;initHelloCountryList(r||{});a=o.country,i=o.locale;log("Country code from localization: ".concat(a));log("Locale from localization: ".concat(i));localizationStoreUpdateSelectedCountryCode(a);l=getOverrideLocale();localizationStoreUpdateSelectedLocale(l||i||"en");u=["dev.storybook.elements","dev.elements","dev.demo.elements","dev.dashboard"];if(!localizationStore.selectedCountryCode&&u.some((function(e){return window.location.origin.includes(e)}))){localizationStoreUpdateSelectedCountryCode("CA")}localizationStore.localizationLoaded=true;return[2]}}))}))};export{VARIANT_TEST_KEY_EXPIRATION as V,localizationStoreUpdateSelectedCountryCode as a,storageStoreSetEnabledVariantTestKeys as b,localizationStoreOnChange as c,currencyFormat as d,initLocalizationStore as e,filterValidTests as f,getZCountryUrlParam as g,setZCountryUrlParam as h,isValidSelector as i,currencyDisplay as j,currencyConvertAndFormat as k,localizationStore as l,currencyConvert as m,getFallbackDefaultCountryCode as n,storageStoreOnChange as o,localizationStoreUpdateSelectedLocale as p,storageStore as s};
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,r,t,o){function n(e){return e instanceof t?e:new t((function(r){r(e)}))}return new(t||(t=Promise))((function(t,a){function i(e){try{u(o.next(e))}catch(e){a(e)}}function l(e){try{u(o["throw"](e))}catch(e){a(e)}}function u(e){e.done?t(e.value):n(e.value).then(i,l)}u((o=o.apply(e,r||[])).next())}))};var __generator=this&&this.__generator||function(e,r){var t={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},o,n,a,i;return i={next:l(0),throw:l(1),return:l(2)},typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function l(e){return function(r){return u([e,r])}}function u(l){if(o)throw new TypeError("Generator is already executing.");while(i&&(i=0,l[0]&&(t=0)),t)try{if(o=1,n&&(a=l[0]&2?n["return"]:l[0]?n["throw"]||((a=n["return"])&&a.call(n),0):n.next)&&!(a=a.call(n,l[1])).done)return a;if(n=0,a)l=[l[0]&2,a.value];switch(l[0]){case 0:case 1:a=l;break;case 4:t.label++;return{value:l[1],done:false};case 5:t.label++;n=l[1];l=[0];continue;case 7:l=t.ops.pop();t.trys.pop();continue;default:if(!(a=t.trys,a=a.length>0&&a[a.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!a||l[1]>a[0]&&l[1]<a[3])){t.label=l[1];break}if(l[0]===6&&t.label<a[1]){t.label=a[1];a=l;break}if(a&&t.label<a[2]){t.label=a[2];t.ops.push(l);break}if(a[2])t.ops.pop();t.trys.pop();continue}l=r.call(e,t)}catch(e){l=[6,e];n=0}finally{o=a=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:true}}};import{c as createStore,z as zonosStore}from"./zonosStore-e3d0493a.js";import{j as jsonParse,h as handleFetch,l as logError}from"./handleFetch-a844cac1.js";import{a as availableTestKeys,l as log}from"./VarianceTest-572cecf5.js";import{a as translationStoreUpdateLanguage}from"./translationStore-766b7521.js";var hasAtLeastOneAvailableTestKey=function(e){var r=!!e.find((function(e){return e.testKey in availableTestKeys}));if(!r){log("No available test key found in response","info",{response:e})}return!!e.find((function(e){return e.testKey in availableTestKeys}))};var filterValidTests=function(e){if(!hasAtLeastOneAvailableTestKey(e)){return[]}return e.filter((function(e){var r;var t=availableTestKeys[e.testKey]&&!e.selectedVariantKey;var o=e.selectedVariantKey&&!!((r=availableTestKeys[e.testKey])===null||r===void 0?void 0:r["availableVariants"].includes(e.selectedVariantKey));return t||o})).map((function(e){return Object.assign(Object.assign({},e),{expiresAt:e.expiresAt||Date.now()+VARIANT_TEST_KEY_EXPIRATION,selectedVariantKey:e.selectedVariantKey||null})}))};var VARIANT_TEST_KEY_EXPIRATION=60*60*24*1e3;var _d=createStore({checkoutSessionId:sessionStorage.getItem("zonos--checkout-session-id"),enabledVariantTestKeys:jsonParse(localStorage.getItem("zonos--enabled-variant-test-keys"))}),storageStoreOnChange=_d.onChange,storageStore=_d.state;storageStoreOnChange("enabledVariantTestKeys",(function(){var e;if(!((e=storageStore.enabledVariantTestKeys)===null||e===void 0?void 0:e.length)){localStorage.removeItem("zonos--enabled-variant-test-keys");return}localStorage.setItem("zonos--enabled-variant-test-keys",JSON.stringify(storageStore.enabledVariantTestKeys))}));storageStoreOnChange("checkoutSessionId",(function(){if(!storageStore.checkoutSessionId){sessionStorage.removeItem("zonos--checkout-session-id");return}sessionStorage.setItem("zonos--checkout-session-id",storageStore.checkoutSessionId)}));var storageStoreSetEnabledVariantTestKeys=function(e){storageStore.enabledVariantTestKeys=filterValidTests(e)};var getCountries=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o;return __generator(this,(function(n){switch(n.label){case 0:n.trys.push([0,2,,3]);return[4,handleFetch("/api/zonos-elements/get-countries",{method:"GET"})];case 1:e=n.sent(),r=e.errors,t=e.json;if(r.length||!t){return[2,null]}return[2,t];case 2:o=n.sent();return[2,null];case 3:return[2]}}))}))};var getCountryLandedCost=function(e){return __awaiter(void 0,void 0,void 0,(function(){var r,t,o,n,a;return __generator(this,(function(i){switch(i.label){case 0:if(!e){return[2,null]}t="/api/zonos-elements/country-landed-cost/".concat(e);return[4,handleFetch(t)];case 1:o=i.sent(),n=o.errors,a=o.json;if(n.length||!a){logError("Error fetching country landed cost: ".concat((r=n.find(Boolean))===null||r===void 0?void 0:r.message));return[2,null]}return[2,a||null]}}))}))};var defaultUsExchangeRate={exchangeRate:{rate:1,targetFormat:{currencyCode:"USD",decimalDelimiter:".",scale:2,symbol:"$",symbolLocation:"before",thousandsDelimiter:","}},maxAge:null};var getExchangeRate=function(e){return __awaiter(void 0,[e],void 0,(function(e){var r,t,o,n,a,i,l,u,c,s;var d=e.country,v=e.isGuaranteed,f=e.sourceCurrency,g=e.targetCurrency;return __generator(this,(function(e){switch(e.label){case 0:if(f===g&&!v){return[2,defaultUsExchangeRate]}t=new URLSearchParams;t.set("sourceCurrency",f);t.set("targetCurrency",g);t.set("isGuaranteed",String(v));t.set("country",d||"");return[4,handleFetch("/api/zonos-elements/exchange-rates?".concat(t.toString()))];case 1:o=e.sent(),n=o.errors,a=o.json;if(n.length||!a){logError("Error fetching country landed cost: ".concat((r=n.find(Boolean))===null||r===void 0?void 0:r.message));return[2,defaultUsExchangeRate]}i=a.exchangeRateCreate,l=i.rate,u=i.targetFormat;c=a.maxAge;if(l){sessionStorage.setItem(d+"_rate",JSON.stringify(l));s={rate:l,targetFormat:u};return[2,{exchangeRate:s,maxAge:c}]}return[2,defaultUsExchangeRate]}}))}))};var getInclusivePricing=function(e){return __awaiter(void 0,void 0,void 0,(function(){var r,t,o,n;return __generator(this,(function(a){switch(a.label){case 0:if(!e){return[2,null]}return[4,handleFetch("/api/zonos-elements/inclusive-prices/".concat(e))];case 1:t=a.sent(),o=t.errors,n=t.json;if(o.length||!n){logError("Error fetching country inclusive price setting: ".concat((r=o.find(Boolean))===null||r===void 0?void 0:r.message));return[2,null]}return[2,n||null]}}))}))};var getLocaleMessages=function(e){return __awaiter(void 0,[e],void 0,(function(e){var r,t,o,n,a;var i=e.countryCode,l=e.localeTo,u=e.storeId;return __generator(this,(function(e){switch(e.label){case 0:t=new URLSearchParams;t.set("countryCode",i);t.set("storeId",u.toString());if(l){t.set("localeTo",l)}return[4,handleFetch("/api/zonos-elements/locale-messages?".concat(t.toString()))];case 1:o=e.sent(),n=o.errors,a=o.json;if(n.length||!a){logError("Error fetching exchange rate",(r=n.find(Boolean))===null||r===void 0?void 0:r.message);return[2,[]]}return[2,a.locale_countryCodesPage]}}))}))};var validateCountryCode=function(e){if(e&&/^[A-Z]{2}$/.test(e)){return e}return null};var getZCountryUrlParam=function(e){var r=new URLSearchParams(e||window.location.search);var t=function(e){var t=r.get(e);return validateCountryCode(t)};var o=t("zCountry");var n=t("country");var a=t("customerCountry");return o||n||a};var getLocalization=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o,n,a,i,l;return __generator(this,(function(u){switch(u.label){case 0:u.trys.push([0,2,,3]);e=new URL(window.location.href);r=window.sessionStorage.getItem("zonos--country");t=getZCountryUrlParam(e.searchParams)||r;o=new URLSearchParams;if(t){o.set("zCountry",t)}return[4,handleFetch("/api/zonos-elements/localization?".concat(o.toString()))];case 1:n=u.sent(),a=n.errors,i=n.json;if(a.length||!i){return[2,{country:null,locale:null}]}return[2,{country:i.country,locale:i.locale}];case 2:l=u.sent();return[2,{country:null,locale:null}];case 3:return[2]}}))}))};var getShippingZones=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o,n,a,i;return __generator(this,(function(l){switch(l.label){case 0:if((e=window.Zonos.cartSettings)===null||e===void 0?void 0:e.shippingZones){return[2,window.Zonos.cartSettings.shippingZones.flatMap((function(e){return e===null||e===void 0?void 0:e.countryCodes})).filter(Boolean)]}return[4,handleFetch("/api/zonos-elements/shipping-zones")];case 1:o=l.sent(),n=o.errors,a=o.json;if(n.length||!a){logError("Error fetching shipping zones: ".concat((r=n.find(Boolean))===null||r===void 0?void 0:r.message));return[2,null]}i=(t=a===null||a===void 0?void 0:a.shippingZones)===null||t===void 0?void 0:t.flatMap((function(e){return e===null||e===void 0?void 0:e.countryCodes})).filter(Boolean);return[2,i||null]}}))}))};var currencyConvert=function(e){var r=localizationStore.exchangeRate;if(!r||!e||isNaN(e)){return e}var t=(r===null||r===void 0?void 0:r.targetFormat.scale)||2;var o=e*r.rate;var n=o.toFixed(t);return Number(n)};var numberFormat=function(e){var r=e.amount,t=e.currency,o=e.targetFormat;var n=t||localizationStore.targetCurrency;var a=(o===null||o===void 0?void 0:o.scale)||2;var i=window.navigator.userAgent.indexOf("MSIE ")!==-1;var l=typeof Intl==="object"&&Intl&&typeof Intl.NumberFormat==="function";if(i||!l){var u=Number(r).toFixed(a).replace(".","|dec|").replace(",",(o===null||o===void 0?void 0:o.thousandsDelimiter)||"").replace("|dec|",(o===null||o===void 0?void 0:o.decimalDelimiter)||"");return u}var c=new Intl.NumberFormat(window.navigator.language,{currency:n,currencyDisplay:"code",minimumFractionDigits:a,style:"currency"}).format(r);return c.replace(new RegExp("".concat(n,"\\s+")),"")};var currencyFormat=function(e){var r=e.amount,t=e.currency;if(isNaN(r)||r!==0&&!r){return""}var o=zonosStore.overrideCurrencyFormat;var n=localizationStore.exchangeRate;var a=t||localizationStore.targetCurrency;if(typeof o==="function"){return o({amount:r,currencyCode:a,numberFormat:function(e){var r=e.amount;return numberFormat({amount:r,currency:a,targetFormat:(n===null||n===void 0?void 0:n.targetFormat)||null})}})}var i=(n||{}).targetFormat;if(!i||!n){return"".concat(r.toFixed(2)," ").concat(a)}var l=i.scale||2;var u=window.navigator.userAgent.indexOf("MSIE ")!==-1;var c=typeof Intl==="object"&&Intl&&typeof Intl.NumberFormat==="function";if(u||!c){var s=Number(r).toFixed(l).replace(".","|dec|").replace(",",i.thousandsDelimiter||"").replace("|dec|",i.decimalDelimiter||"");var d="".concat(s).concat(i.currencyCode!=="USD"?" ".concat(i.currencyCode):"");return d}var v=(o===null||o===void 0?void 0:o.currencyDisplay)||"symbol";var f=new Intl.NumberFormat(window.navigator.language,{currency:a,currencyDisplay:v,minimumFractionDigits:l,style:"currency"}).format(r);var g=v==="code"?"".concat(f.replace(new RegExp("".concat(a,"\\s+")),"")," ").concat(a):f;return g};var currencyConvertAndFormat=function(e){var r=currencyConvert(e);var t=currencyFormat({amount:r});return t};var isValidSelector=function(e){try{document.createDocumentFragment().querySelector(e)}catch(e){return false}return true};var getCurrencyElements=function(e){var r=e||".money";if(!isValidSelector(r)){logError('Currency element selector "'.concat(r,'" is not valid.'));return null}var t=document.querySelectorAll(r);if(!t.length){log('No currency elements found with selector "'.concat(r,'"'),"warn");return null}return Array.from(t)};var getInitialElementAmount=function(e){var r;var t=e.getAttribute("data-domestic");var o=e.getAttribute("data-zintl");var n=(r=e.textContent)===null||r===void 0?void 0:r.replace(/[^\d.-]/g,"");if(!n){return null}if(!t||e.textContent!==o&&o){e.setAttribute("data-domestic",n);return parseFloat(n)}return parseFloat(t)};var BLUR_CURRENCY_DURATION=7e3;var BLUR_CURRENCY_CLASSNAME="z--blur";var removeBlurCurrency=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r;return __generator(this,(function(t){switch(t.label){case 0:e=window.zonosBlurCurrencyOnInitIntervalId;if(!e){return[2]}return[4,new Promise((function(e){return setTimeout(e,500)}))];case 1:t.sent();clearInterval(e);r=document.querySelectorAll(".".concat(BLUR_CURRENCY_CLASSNAME));r.forEach((function(e){e.classList.remove(BLUR_CURRENCY_CLASSNAME)}));window.zonosBlurCurrencyOnInitIntervalId=undefined;return[2]}}))}))};var blurCurrencyElements=function(e){var r=e.currencySelector;if(!r){return}var t=document.querySelectorAll([r].filter(Boolean).join(","));t.forEach((function(e){e.classList.add(BLUR_CURRENCY_CLASSNAME)}))};var performBlurCurrency=function(){if(typeof window==="undefined"){return}if(window.zonosBlurCurrencyOnInitIntervalId){return}blurCurrencyElements({currencySelector:window.zonosBlurCurrencyOnInitCurrencySelector});var e=setInterval((function(){blurCurrencyElements({currencySelector:window.zonosBlurCurrencyOnInitCurrencySelector})}),10);window.zonosBlurCurrencyOnInitIntervalId=e;setTimeout((function(){void removeBlurCurrency()}),BLUR_CURRENCY_DURATION)};var convertCurrency=function(e){var r;var t=getInitialElementAmount(e);if(!t||isNaN(t)){return}var o=e.getAttribute("data-zintl");var n=parseFloat(e.getAttribute("data-zrate")||"1");var a=e.getAttribute("data-zcountry-code");var i=localizationStore.exchangeRate&&localizationStore.targetCurrency===localizationStore.exchangeRate.targetFormat.currencyCode;var l=((r=localizationStore.exchangeRate)===null||r===void 0?void 0:r.rate)||1;if(i&&(e.textContent!==o||l!==n||a!==localizationStore.selectedCountryCode)){performBlurCurrency();var u=typeof zonosStore.currencyConverter==="function"&&zonosStore.currencyConverter({convert:currencyConvert,convertAndFormat:currencyConvertAndFormat,currencyCode:localizationStore.targetCurrency,format:function(e){return currencyFormat({amount:e})},originalAmount:t,selector:e});var c=u||currencyConvertAndFormat(t);if(c!==e.textContent){e.textContent=c}e.setAttribute("data-zrate",l.toString());e.setAttribute("data-zintl",c);e.setAttribute("data-zcountry-code",localizationStore.selectedCountryCode||"")}void removeBlurCurrency()};var defaultCurrencyConverter=function(){var e=zonosStore.helloSettings.currencyElementSelector;var r=getCurrencyElements(e);if(!(r===null||r===void 0?void 0:r.length)){return}if(!localizationStore.exchangeRate){logError("Could not display currency. Exchange rate and format data is not available.");return}r.forEach((function(e){convertCurrency(e)}))};var currencyDisplay=function(){if(zonosStore.helloSettings.currencyBehavior==="DISABLED"||window.Zonos.isLegacyCheckout){void removeBlurCurrency();return}defaultCurrencyConverter()};var getCurrencyCode=function(e){var r;var t=(r=localizationStore.shippingZoneCountries)===null||r===void 0?void 0:r[e];if(t){return t.currencyCode}return null};var setZCountryUrlParam=function(e){if(!e){return}var r=new URLSearchParams(window.location.search);var t=r.has("zCountry")||zonosStore.helloSettings.countryOverrideBehavior==="URL_PARAM";if(t){r.set("zCountry",e);var o="".concat(window.location.pathname,"?").concat(r.toString());window.history.replaceState(window.history.state,document.title,o)}};var _e=createStore({countryLandedCost:null,customMessages:[],exchangeRate:null,helloCountryList:null,inclusivePricing:null,isDisabledCountry:true,isShippableCountry:false,localizationLoaded:false,selectedCountryCode:null,selectedLocale:"en",shippingZoneCountries:null,targetCurrency:"USD"}),localizationDispose=_e.dispose,localizationStoreOnChange=_e.onChange,localizationStore=_e.state;var triggerGetExchangeRate=function(e){return __awaiter(void 0,void 0,void 0,(function(){var r,t,o;return __generator(this,(function(n){switch(n.label){case 0:return[4,getExchangeRate({country:localizationStore.selectedCountryCode,isGuaranteed:e,sourceCurrency:zonosStore.sourceCurrency,targetCurrency:localizationStore.targetCurrency})];case 1:r=n.sent(),t=r.exchangeRate,o=r.maxAge;if(t){localizationStore.exchangeRate=t;currencyDisplay()}return[2,{maxAge:o}]}}))}))};var DEFAULT_COUNTRY_CODE_LEGACY_CHECKOUT="CA";var getFallbackDefaultCountryCode=function(e){if(localizationStore.selectedCountryCode&&e.includes(localizationStore.selectedCountryCode)){return localizationStore.selectedCountryCode}return DEFAULT_COUNTRY_CODE_LEGACY_CHECKOUT};var startExchangeRateTimeout=function(e){var r=e.isGuaranteed,t=e.maxAge;if(localizationStore.exchangeRateTimeout){clearTimeout(localizationStore.exchangeRateTimeout)}var o=5*60;var n=t||o;localizationStore.exchangeRateTimeout=setTimeout((function(){return __awaiter(void 0,void 0,void 0,(function(){var e;return __generator(this,(function(t){switch(t.label){case 0:return[4,triggerGetExchangeRate(r)];case 1:e=t.sent().maxAge;startExchangeRateTimeout({isGuaranteed:r,maxAge:e});return[2]}}))}))}),n*1e3)};var getNewLocalization=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o,n,a,i,l;return __generator(this,(function(u){switch(u.label){case 0:log("get new localization store");r=localizationStore.isDisabledCountry,t=localizationStore.isShippableCountry,o=localizationStore.selectedCountryCode;if(zonosStore.helloSettings.currencyBehavior==="DISABLED"||!t||r||!o){return[2]}n=zonosStore.checkoutSettings.visibilityStatus==="ENABLED";performBlurCurrency();return[4,triggerGetExchangeRate(n)];case 1:a=u.sent().maxAge;startExchangeRateTimeout({isGuaranteed:n,maxAge:a});if(!!window.Zonos.isLegacyCheckout)return[3,4];i=localizationStore;return[4,getCountryLandedCost(localizationStore.selectedCountryCode)];case 2:i.countryLandedCost=u.sent();l=localizationStore;return[4,getInclusivePricing(o)];case 3:l.inclusivePricing=((e=u.sent())===null||e===void 0?void 0:e.setting)||null;if(localizationStore.inclusivePricing){log("Inclusive price setting found for this country (".concat(o,") ").concat(JSON.stringify(localizationStore.inclusivePricing,null,2)))}return[3,5];case 4:log("Skipping country landed cost and inclusive pricing requests, because this is a legacy checkout");u.label=5;case 5:return[2]}}))}))};var getCustomMessages=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r;return __generator(this,(function(t){switch(t.label){case 0:log("Getting custom messages for ".concat(localizationStore.selectedCountryCode));if(!localizationStore.selectedCountryCode||!zonosStore.storeId){return[2]}return[4,getLocaleMessages({countryCode:localizationStore.selectedCountryCode,localeTo:localizationStore.selectedLocale,storeId:zonosStore.storeId})];case 1:e=t.sent();r=e.flatMap((function(e){var r;return{countryCode:localizationStore.selectedCountryCode,message:(r=e.countryCodesPageMessageLinks.find(Boolean))===null||r===void 0?void 0:r.message.textTo,pageName:e.pageName}}));localizationStore.customMessages=r;return[2]}}))}))};var getOverrideLocale=function(){var e=new URL(window.location.href);var r=e.searchParams.get("zonosLocale");return r};var addInternationalHideClass=function(){if(localizationStore.isShippableCountry){document.body.classList.add("z-intl")}else{document.body.classList.remove("z-intl")}};var getValidCountryCode=function(e){if(e==="UK"){return"GB"}return e};var localizationStoreUpdateSelectedCountryCode=function(e){var r,t;log("Updating selected country code to ".concat(e));var o=!localizationStore.selectedCountryCode;localizationStore.selectedCountryCode=getValidCountryCode(e);var n=localizationStore.selectedCountryCode,a=localizationStore.shippingZoneCountries;var i=!!a&&!!n&&!!a[n]&&!zonosStore.disabledCountries.includes(n);localizationStore.isShippableCountry=i;log("".concat(localizationStore.selectedCountryCode," is a shippable country: ").concat(localizationStore.isShippableCountry));var l=!!n&&zonosStore.disabledCountries.includes(n);localizationStore.isDisabledCountry=l;log("".concat(localizationStore.selectedCountryCode," is a disabled country: ").concat(localizationStore.isDisabledCountry));addInternationalHideClass();if(!n){return}var u=getCurrencyCode(n);if(!o){(r=zonosStore.onCountryChange)===null||r===void 0?void 0:r.call(zonosStore,{countryCode:n,currencyCode:u,isShippableCountry:i})}if(!u){return}localizationStore.targetCurrency=u;void getNewLocalization();window.sessionStorage.setItem("zonos--country",n);setZCountryUrlParam(n);(t=document.querySelector("zonos-hello"))===null||t===void 0?void 0:t.setAttribute("z-country",n)};var initHelloCountryList=function(e){var r=zonosStore.helloSettings.showCountryList;var t=localizationStore.shippingZoneCountries;if(!r||r==="ONLY_SHIPPABLE"){localizationStore.helloCountryList=t;return}if(r==="ALL"){localizationStore.helloCountryList=e;return}localizationStore.helloCountryList=r.reduce((function(r,t){var o;var n=e===null||e===void 0?void 0:e[t];return n?Object.assign(Object.assign({},r),(o={},o[t]=n,o)):r}),{})};var updateCheckoutSessionLanguage=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t;return __generator(this,(function(o){switch(o.label){case 0:if(!storageStore.checkoutSessionId){return[2,null]}return[4,handleFetch("/api/zonos-elements/update-checkout-session-metadata",{body:{id:storageStore.checkoutSessionId,metadata:[{key:"language",value:localizationStore.selectedLocale}]},method:"POST"})];case 1:e=o.sent(),r=e.errors,t=e.json;if(r.length||!t){logError("Error occurs when updating checkout session",JSON.stringify(r,null,2));return[2,{errors:r,json:t}]}return[2,{errors:[],json:t}]}}))}))};var localizationStoreUpdateSelectedLocale=function(e){localizationStore.selectedLocale=e;translationStoreUpdateLanguage(e);void updateCheckoutSessionLanguage();void getCustomMessages()};var initLocalizationStore=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,r,t,o,n,a,i,l,u;return __generator(this,(function(c){switch(c.label){case 0:return[4,Promise.all([getCountries(),getShippingZones(),getLocalization()])];case 1:e=c.sent(),r=e[0],t=e[1],o=e[2];n=t===null||t===void 0?void 0:t.reduce((function(e,t){var o;var n=r===null||r===void 0?void 0:r[t];return n?Object.assign(Object.assign({},e),(o={},o[t]=n,o)):e}),{});localizationStore.shippingZoneCountries=n||null;initHelloCountryList(r||{});a=o.country,i=o.locale;log("Country code from localization: ".concat(a));log("Locale from localization: ".concat(i));localizationStoreUpdateSelectedCountryCode(a);l=getOverrideLocale();localizationStoreUpdateSelectedLocale(l||i||"en");u=["dev.storybook.elements","dev.elements","dev.demo.elements","dev.dashboard"];if(!localizationStore.selectedCountryCode&&u.some((function(e){return window.location.origin.includes(e)}))){localizationStoreUpdateSelectedCountryCode("CA")}localizationStore.localizationLoaded=true;return[2]}}))}))};export{VARIANT_TEST_KEY_EXPIRATION as V,localizationStoreUpdateSelectedCountryCode as a,storageStoreSetEnabledVariantTestKeys as b,localizationStoreOnChange as c,currencyFormat as d,initLocalizationStore as e,filterValidTests as f,getZCountryUrlParam as g,setZCountryUrlParam as h,isValidSelector as i,currencyDisplay as j,currencyConvertAndFormat as k,localizationStore as l,currencyConvert as m,getFallbackDefaultCountryCode as n,storageStoreOnChange as o,localizationStoreUpdateSelectedLocale as p,storageStore as s};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(r,e,t,o){function n(r){return r instanceof t?r:new t((function(e){e(r)}))}return new(t||(t=Promise))((function(t,a){function i(r){try{c(o.next(r))}catch(r){a(r)}}function u(r){try{c(o["throw"](r))}catch(r){a(r)}}function c(r){r.done?t(r.value):n(r.value).then(i,u)}c((o=o.apply(r,e||[])).next())}))};var __generator=this&&this.__generator||function(r,e){var t={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},o,n,a,i;return i={next:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function u(r){return function(e){return c([r,e])}}function c(u){if(o)throw new TypeError("Generator is already executing.");while(i&&(i=0,u[0]&&(t=0)),t)try{if(o=1,n&&(a=u[0]&2?n["return"]:u[0]?n["throw"]||((a=n["return"])&&a.call(n),0):n.next)&&!(a=a.call(n,u[1])).done)return a;if(n=0,a)u=[u[0]&2,a.value];switch(u[0]){case 0:case 1:a=u;break;case 4:t.label++;return{value:u[1],done:false};case 5:t.label++;n=u[1];u=[0];continue;case 7:u=t.ops.pop();t.trys.pop();continue;default:if(!(a=t.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){t=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){t.label=u[1];break}if(u[0]===6&&t.label<a[1]){t.label=a[1];a=u;break}if(a&&t.label<a[2]){t.label=a[2];t.ops.push(u);break}if(a[2])t.ops.pop();t.trys.pop();continue}u=e.call(r,t)}catch(r){u=[6,r];n=0}finally{o=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:true}}};import{z as zonosStore,c as createStore}from"./zonosStore-e3d0493a.js";import{t as trackConversionEvent,
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(r,e,t,o){function n(r){return r instanceof t?r:new t((function(e){e(r)}))}return new(t||(t=Promise))((function(t,a){function i(r){try{c(o.next(r))}catch(r){a(r)}}function u(r){try{c(o["throw"](r))}catch(r){a(r)}}function c(r){r.done?t(r.value):n(r.value).then(i,u)}c((o=o.apply(r,e||[])).next())}))};var __generator=this&&this.__generator||function(r,e){var t={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},o,n,a,i;return i={next:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function u(r){return function(e){return c([r,e])}}function c(u){if(o)throw new TypeError("Generator is already executing.");while(i&&(i=0,u[0]&&(t=0)),t)try{if(o=1,n&&(a=u[0]&2?n["return"]:u[0]?n["throw"]||((a=n["return"])&&a.call(n),0):n.next)&&!(a=a.call(n,u[1])).done)return a;if(n=0,a)u=[u[0]&2,a.value];switch(u[0]){case 0:case 1:a=u;break;case 4:t.label++;return{value:u[1],done:false};case 5:t.label++;n=u[1];u=[0];continue;case 7:u=t.ops.pop();t.trys.pop();continue;default:if(!(a=t.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){t=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){t.label=u[1];break}if(u[0]===6&&t.label<a[1]){t.label=a[1];a=u;break}if(a&&t.label<a[2]){t.label=a[2];t.ops.push(u);break}if(a[2])t.ops.pop();t.trys.pop();continue}u=e.call(r,t)}catch(r){u=[6,r];n=0}finally{o=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:true}}};import{z as zonosStore,c as createStore}from"./zonosStore-e3d0493a.js";import{t as trackConversionEvent,A as validateCheckoutSession,c as stripeStore,e as cartStore,v as stripeStoreHandleInventoryCheck,r as cartStoreNextStep,j as cartStoreClearCheckoutInterval}from"./cart-c74f9aaa.js";import{s as storageStore}from"./localization-106476cb.js";import{t as translate}from"./translationStore-766b7521.js";import{h as handleFetch,l as logError,j as jsonParse}from"./handleFetch-a844cac1.js";import{t as tinycolor}from"./isDarkColor-83e0c27e.js";import{l as log}from"./VarianceTest-572cecf5.js";
|
|
2
2
|
/*!
|
|
3
3
|
* paypal-js v8.1.0 (2024-06-07T16:55:00.122Z)
|
|
4
4
|
* Copyright 2020-present, PayPal, Inc. All rights reserved.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(r,t,e,n){function o(r){return r instanceof e?r:new e((function(t){t(r)}))}return new(e||(e=Promise))((function(e,a){function c(r){try{u(n.next(r))}catch(r){a(r)}}function i(r){try{u(n["throw"](r))}catch(r){a(r)}}function u(r){r.done?e(r.value):o(r.value).then(c,i)}u((n=n.apply(r,t||[])).next())}))};var __generator=this&&this.__generator||function(r,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},n,o,a,c;return c={next:i(0),throw:i(1),return:i(2)},typeof Symbol==="function"&&(c[Symbol.iterator]=function(){return this}),c;function i(r){return function(t){return u([r,t])}}function u(i){if(n)throw new TypeError("Generator is already executing.");while(c&&(c=0,i[0]&&(e=0)),e)try{if(n=1,o&&(a=i[0]&2?o["return"]:i[0]?o["throw"]||((a=o["return"])&&a.call(o),0):o.next)&&!(a=a.call(o,i[1])).done)return a;if(o=0,a)i=[i[0]&2,a.value];switch(i[0]){case 0:case 1:a=i;break;case 4:e.label++;return{value:i[1],done:false};case 5:e.label++;o=i[1];i=[0];continue;case 7:i=e.ops.pop();e.trys.pop();continue;default:if(!(a=e.trys,a=a.length>0&&a[a.length-1])&&(i[0]===6||i[0]===2)){e=0;continue}if(i[0]===3&&(!a||i[1]>a[0]&&i[1]<a[3])){e.label=i[1];break}if(i[0]===6&&e.label<a[1]){e.label=a[1];a=i;break}if(a&&e.label<a[2]){e.label=a[2];e.ops.push(i);break}if(a[2])e.ops.pop();e.trys.pop();continue}i=t.call(r,e)}catch(r){i=[6,r];o=0}finally{n=a=0}if(i[0]&5)throw i[1];return{value:i[0]?i[1]:void 0,done:true}}};import{e as cartStore}from"./cart-c74f9aaa.js";import{d as currencyFormat,s as storageStore}from"./localization-106476cb.js";import{l as logError,h as handleFetch}from"./handleFetch-a844cac1.js";var getDisplayCurrency=function(){var r,t;var e=cartStore.displayBaseCurrency;var n=e&&((r=cartStore.exchangeRate)===null||r===void 0?void 0:r.sourceCurrencyCode)?(t=cartStore.exchangeRate)===null||t===void 0?void 0:t.sourceCurrencyCode:cartStore.currency;return n};var renderCheckoutCurrency=function(r){var t=r.amount,e=r.isForeign;var n,o;var a=((n=cartStore.exchangeRate)===null||n===void 0?void 0:n.rate)||1;var c=cartStore.currency;var i=(o=cartStore.items[0])===null||o===void 0?void 0:o.currencyCode;if(i===c){return currencyFormat({amount:t,currency:c})}var u=cartStore.displayBaseCurrency;var s=getDisplayCurrency();if(e){var l=u?t/a:t;return currencyFormat({amount:l,currency:s})}var f=u?t:t*a;return currencyFormat({amount:f,currency:s})};var placeTestOrder=function(){return __awaiter(void 0,void 0,void 0,(function(){var r,t,e,n,o,a,c,i,u;return __generator(this,(function(s){switch(s.label){case 0:e=(r=cartStore.partiesData.find((function(r){return r.type==="DESTINATION"})))===null||r===void 0?void 0:r.id;n=(t=cartStore.partiesData.find((function(r){return r.type==="PAYOR"})))===null||t===void 0?void 0:t.id;o=storageStore.checkoutSessionId;if(!o||!n||!e){logError("Missing required data",{billToPartyId:n,checkoutSessionId:o,shipToPartyId:e});return[2,{errors:["Missing required data"],json:null}]}a={billToPartyId:n,checkoutSessionId:o,shipToPartyId:e};return[4,handleFetch("/api/zonos-elements/place-test-order",{body:a,method:"POST"})];case 1:c=s.sent(),i=c.errors,u=c.json;if(i.length||!u){logError("Error occurs when placing test order",i);return[2,{errors:i.map((function(r){return r.message})),json:null}]}return[2,{errors:[],json:u}]}}))}))};export{placeTestOrder as p,renderCheckoutCurrency as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,t,o,r){function n(e){return e instanceof o?e:new o((function(t){t(e)}))}return new(o||(o=Promise))((function(o,i){function l(e){try{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r["throw"](e))}catch(e){i(e)}}function s(e){e.done?o(e.value):n(e.value).then(l,a)}s((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,n,i,l;return l={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(l[Symbol.iterator]=function(){return this}),l;function a(e){return function(t){return s([e,t])}}function s(a){if(r)throw new TypeError("Generator is already executing.");while(l&&(l=0,a[0]&&(o=0)),o)try{if(r=1,n&&(i=a[0]&2?n["return"]:a[0]?n["throw"]||((i=n["return"])&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;if(n=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:o.label++;return{value:a[1],done:false};case 5:o.label++;n=a[1];a=[0];continue;case 7:a=o.ops.pop();o.trys.pop();continue;default:if(!(i=o.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1];i=a;break}if(i&&o.label<i[2]){o.label=i[2];o.ops.push(a);break}if(i[2])o.ops.pop();o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e];n=0}finally{r=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};import{c as createStore,z as zonosStore}from"./zonosStore-e3d0493a.js";import{c as stripeStore,
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,t,o,r){function n(e){return e instanceof o?e:new o((function(t){t(e)}))}return new(o||(o=Promise))((function(o,i){function l(e){try{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r["throw"](e))}catch(e){i(e)}}function s(e){e.done?o(e.value):n(e.value).then(l,a)}s((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,n,i,l;return l={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(l[Symbol.iterator]=function(){return this}),l;function a(e){return function(t){return s([e,t])}}function s(a){if(r)throw new TypeError("Generator is already executing.");while(l&&(l=0,a[0]&&(o=0)),o)try{if(r=1,n&&(i=a[0]&2?n["return"]:a[0]?n["throw"]||((i=n["return"])&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;if(n=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:o.label++;return{value:a[1],done:false};case 5:o.label++;n=a[1];a=[0];continue;case 7:a=o.ops.pop();o.trys.pop();continue;default:if(!(i=o.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(a[0]===6&&o.label<i[1]){o.label=i[1];i=a;break}if(i&&o.label<i[2]){o.label=i[2];o.ops.push(a);break}if(i[2])o.ops.pop();o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e];n=0}finally{r=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};import{c as createStore,z as zonosStore}from"./zonosStore-e3d0493a.js";import{c as stripeStore,C as stripeStoreBuildAddressForPartyCreate,e as cartStore,D as cartStoreUpdateSelectedShippingOption}from"./cart-c74f9aaa.js";import{s as storageStore}from"./localization-106476cb.js";import{h as handleFetch,s as sendErrorLog,l as logError}from"./handleFetch-a844cac1.js";import{b as allLogs}from"./VarianceTest-572cecf5.js";import{h}from"./index-55a03023.js";var _k=createStore((function(){return{amountDutyTaxFeeTotal:null,amountTotalPaid:null,isFetchingShippingInfo:true,landedCostShortId:null,originCompanyName:null,partyBillingId:null,shippingAddress:null}})),collectStoreReset=_k.reset,collectStore=_k.state;var collectStoreInitShippingInfo=function(e){return __awaiter(void 0,[e],void 0,(function(e){var t,o,r,n,i,l,a,s,c,d,u,p,S;var f=e.landedCostId,v=e.retries,h=v===void 0?5:v;return __generator(this,(function(e){switch(e.label){case 0:collectStore.isFetchingShippingInfo=true;return[4,handleFetch("/api/zonos-elements/collect/get-shipping-info-by-lc-id",{body:{landedCostId:f},method:"POST"})];case 1:d=e.sent();if(!d.errors.length)return[3,4];if(!(h>0))return[3,3];return[4,new Promise((function(e){return setTimeout(e,1e3)}))];case 2:e.sent();return[2,collectStoreInitShippingInfo({landedCostId:f,retries:h-1})];case 3:return[2,null];case 4:collectStore.landedCostShortId=((t=d.json)===null||t===void 0?void 0:t.landedCostShortId)||null;collectStore.isFetchingShippingInfo=false;collectStore.shippingAddress=((o=d.json)===null||o===void 0?void 0:o.shipping)||null;u=(r=cartStore.checkoutSession)===null||r===void 0?void 0:r.landedCost;p=(n=cartStore.checkoutSession)===null||n===void 0?void 0:n.subtotals;S=(((i=u===null||u===void 0?void 0:u.amountSubtotals)===null||i===void 0?void 0:i.shipping)||0)+(((l=u===null||u===void 0?void 0:u.amountSubtotals)===null||l===void 0?void 0:l.items)||0);collectStore.amountTotalPaid=S*(((a=p===null||p===void 0?void 0:p.exchangeRate)===null||a===void 0?void 0:a.rate)||1);collectStore.amountDutyTaxFeeTotal=((p===null||p===void 0?void 0:p.duties)||0)+((p===null||p===void 0?void 0:p.taxes)||0)+((p===null||p===void 0?void 0:p.fees)||0);collectStore.originCompanyName=((c=(s=d.json)===null||s===void 0?void 0:s.origin)===null||c===void 0?void 0:c.companyName)||null;if(collectStore.amountTotalPaid===0){void sendErrorLog({endpoint:"COLLECT_NO_TOTAL_PAID",errors:[],metadata:{landedCostId:f,organizationId:zonosStore.organizationId}})}return[2]}}))}))};var collectStoreAsyncAddressUpdate=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,t,o,r,n,i,l,a,s,c;return __generator(this,(function(d){switch(d.label){case 0:if(!((e=stripeStore.stripeBillingAddressEventData)===null||e===void 0?void 0:e.complete)){return[2,{partiesCreated:false}]}n=(o=(t=cartStore.checkoutSession)===null||t===void 0?void 0:t.landedCost)===null||o===void 0?void 0:o.rootId;if(!n){void sendErrorLog({endpoint:"PF_NO_SELECTED_LANDED_COST",errors:["No selected landed cost"],metadata:{allLogs:allLogs,cartId:window.Zonos.cartId,checkoutSessionId:storageStore.checkoutSessionId}});return[2,{partiesCreated:false}]}if(!storageStore.checkoutSessionId){void sendErrorLog({endpoint:"COLLECT_NO_CHECKOUT_SESSION_ID",errors:["No checkout session id"],metadata:{allLogs:allLogs,cartId:window.Zonos.cartId,landedCostRootId:n}});return[2,{partiesCreated:false}]}i=stripeStoreBuildAddressForPartyCreate({address:stripeStore.stripeBillingAddressEventData.value.address,firstName:stripeStore.stripeBillingAddressEventData.value.firstName,lastName:stripeStore.stripeBillingAddressEventData.value.lastName,name:stripeStore.stripeBillingAddressEventData.value.name,phone:stripeStore.stripeBillingAddressEventData.value.phone});l=new URLSearchParams(window.location.search).get("zonosE2ETest")==="1";return[4,handleFetch("/api/zonos-elements/create-billing-party",{body:{billingAddress:i,checkoutSessionId:storageStore.checkoutSessionId,companyName:stripeStore.companyName,email:((r=stripeStore.stripeLinkEventData)===null||r===void 0?void 0:r.value.email)||"",isTest:l,rootId:n},method:"POST"})];case 1:a=d.sent(),s=a.errors,c=a.json;if(s.length||!c){logError("Error occurs when creating billing party",JSON.stringify(s,null,2));void sendErrorLog({endpoint:"COLLECT_BILLING_PARTY_CREATE_FAILED",errors:["[COLLECT] Failed to create billing party"],metadata:{allLogs:allLogs,cartId:window.Zonos.cartId,checkoutSessionId:storageStore.checkoutSessionId,errors:s,json:c}});return[2,{partiesCreated:false}]}collectStore.partyBillingId=c.billToPartyId;return[2,{partiesCreated:true}]}}))}))};var collectStoreUpdateSelectedShippingOption=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t;return __generator(this,(function(o){t=e.landedCost;if(!t){return[2,false]}cartStore.landedCostData=[Object.assign(Object.assign({},e),{landedCost:Object.assign({},t),landedCostId:t.id})];return[2,cartStoreUpdateSelectedShippingOption({applySubtotalsOnly:true,landedCostId:t.id,selectedShippingOption:t.shipmentRating})]}))}))};var collectTabletBreakpoint=1024;var collectMobileBreakpoint=768;var isCollectTablet=function(e){return e||window.innerWidth<collectTabletBreakpoint&&window.innerWidth>=collectMobileBreakpoint};var isCollectMobile=function(e){return e||window.innerWidth<collectMobileBreakpoint};var renderFallback=function(e){var t=e.content,o=e.isLoading,r=e.skeletonHeight,n=e.skeletonWidth;if(o){return h("zonos-skeleton",{skeletonHeight:r,skeletonWidth:n})}return t};export{isCollectTablet as a,collectStoreInitShippingInfo as b,collectStoreUpdateSelectedShippingOption as c,collectStoreAsyncAddressUpdate as d,collectStore as e,isCollectMobile as i,renderFallback as r};
|