@zonos/elements 1.3.220 → 1.3.222

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.
Files changed (169) hide show
  1. package/dist/cjs/{cart-9a9ae4b9.js → cart-3a2a062c.js} +2 -2
  2. package/dist/cjs/index.cjs.js +7 -7
  3. package/dist/cjs/{localization-0169b27d.js → localization-12e7e934.js} +1 -1
  4. package/dist/cjs/{paypal-9ee374a0.js → paypal-a1377508.js} +3 -3
  5. package/dist/cjs/{placeTestOrder-0dfff170.js → placeTestOrder-6fcce33e.js} +2 -2
  6. package/dist/cjs/{isCollectMobileTablet-7a9413e3.js → renderFallback-39ba034b.js} +11 -2
  7. package/dist/cjs/{translationStore-0c67178f.js → translationStore-951ed4b4.js} +100 -40
  8. package/dist/cjs/zonos-address_11.cjs.entry.js +7 -13
  9. package/dist/cjs/zonos-cart-items_12.cjs.entry.js +5 -5
  10. package/dist/cjs/zonos-checkout.cjs.entry.js +4 -4
  11. package/dist/cjs/zonos-collect-cart-items_3.cjs.entry.js +4 -4
  12. package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +35 -42
  13. package/dist/cjs/zonos-collect.cjs.entry.js +22 -15
  14. package/dist/cjs/zonos-confirm-dialog_2.cjs.entry.js +1 -1
  15. package/dist/cjs/zonos-controller.cjs.entry.js +3 -3
  16. package/dist/cjs/zonos-country-flag.cjs.entry.js +2 -2
  17. package/dist/cjs/zonos-country-select_4.cjs.entry.js +2 -2
  18. package/dist/cjs/zonos-empty-state-payment_4.cjs.entry.js +4 -4
  19. package/dist/cjs/zonos-hello-dialog.cjs.entry.js +2 -2
  20. package/dist/cjs/zonos-hello.cjs.entry.js +2 -2
  21. package/dist/cjs/zonos-language-select_2.cjs.entry.js +2 -2
  22. package/dist/collection/components/checkout/zonos-collect/zonos-collect-review/zonos-collect-review.js +1 -1
  23. package/dist/collection/components/checkout/zonos-collect/zonos-collect.css +1 -1
  24. package/dist/collection/components/checkout/zonos-collect/zonos-collect.js +11 -3
  25. package/dist/collection/components/common/zonos-skeleton/zonos-skeleton.css +2 -0
  26. package/dist/collection/components/store/translationStore/strings.arabic.js +5 -2
  27. package/dist/collection/components/store/translationStore/strings.base.js +5 -2
  28. package/dist/collection/components/store/translationStore/strings.chinese.js +5 -2
  29. package/dist/collection/components/store/translationStore/strings.danish.js +5 -2
  30. package/dist/collection/components/store/translationStore/strings.dutch.js +5 -2
  31. package/dist/collection/components/store/translationStore/strings.french.js +5 -2
  32. package/dist/collection/components/store/translationStore/strings.german.js +5 -2
  33. package/dist/collection/components/store/translationStore/strings.hebrew.js +5 -2
  34. package/dist/collection/components/store/translationStore/strings.indonesian.js +5 -2
  35. package/dist/collection/components/store/translationStore/strings.italian.js +5 -2
  36. package/dist/collection/components/store/translationStore/strings.japanese.js +5 -2
  37. package/dist/collection/components/store/translationStore/strings.korean.js +5 -2
  38. package/dist/collection/components/store/translationStore/strings.norwegian.js +5 -2
  39. package/dist/collection/components/store/translationStore/strings.polish.js +5 -2
  40. package/dist/collection/components/store/translationStore/strings.portuguese.js +5 -2
  41. package/dist/collection/components/store/translationStore/strings.russian.js +5 -2
  42. package/dist/collection/components/store/translationStore/strings.spanish.js +5 -2
  43. package/dist/collection/components/store/translationStore/strings.swedish.js +5 -2
  44. package/dist/collection/components/store/translationStore/strings.turkish.js +5 -2
  45. package/dist/collection/components/store/translationStore/strings.vietnamese.js +5 -2
  46. package/dist/collection/components/stripe/zonos-link-authentication/zonos-link-authentication.js +4 -10
  47. package/dist/esm/{cart-b2dd578c.js → cart-7f06662c.js} +2 -2
  48. package/dist/esm/index.js +7 -7
  49. package/dist/esm/{localization-d7125e4e.js → localization-192886e4.js} +1 -1
  50. package/dist/esm/{paypal-555bbf1e.js → paypal-53f1b4a1.js} +3 -3
  51. package/dist/esm/{placeTestOrder-2d67c1a9.js → placeTestOrder-95cbb623.js} +2 -2
  52. package/dist/esm/{isCollectMobileTablet-7f9a5e2b.js → renderFallback-6352363c.js} +11 -3
  53. package/dist/esm/{translationStore-13502f49.js → translationStore-fb98a08d.js} +100 -40
  54. package/dist/esm/zonos-address_11.entry.js +7 -13
  55. package/dist/esm/zonos-cart-items_12.entry.js +5 -5
  56. package/dist/esm/zonos-checkout.entry.js +4 -4
  57. package/dist/esm/zonos-collect-cart-items_3.entry.js +4 -4
  58. package/dist/esm/zonos-collect-finish_6.entry.js +7 -14
  59. package/dist/esm/zonos-collect.entry.js +16 -9
  60. package/dist/esm/zonos-confirm-dialog_2.entry.js +1 -1
  61. package/dist/esm/zonos-controller.entry.js +3 -3
  62. package/dist/esm/zonos-country-flag.entry.js +2 -2
  63. package/dist/esm/zonos-country-select_4.entry.js +2 -2
  64. package/dist/esm/zonos-empty-state-payment_4.entry.js +4 -4
  65. package/dist/esm/zonos-hello-dialog.entry.js +2 -2
  66. package/dist/esm/zonos-hello.entry.js +2 -2
  67. package/dist/esm/zonos-language-select_2.entry.js +2 -2
  68. package/dist/esm-es5/{cart-b2dd578c.js → cart-7f06662c.js} +1 -1
  69. package/dist/esm-es5/index.js +1 -1
  70. package/dist/esm-es5/{localization-d7125e4e.js → localization-192886e4.js} +1 -1
  71. package/dist/esm-es5/{paypal-555bbf1e.js → paypal-53f1b4a1.js} +1 -1
  72. package/dist/esm-es5/{placeTestOrder-2d67c1a9.js → placeTestOrder-95cbb623.js} +1 -1
  73. package/dist/esm-es5/renderFallback-6352363c.js +1 -0
  74. package/dist/esm-es5/translationStore-fb98a08d.js +1 -0
  75. package/dist/esm-es5/zonos-address_11.entry.js +1 -1
  76. package/dist/esm-es5/zonos-cart-items_12.entry.js +1 -1
  77. package/dist/esm-es5/zonos-checkout.entry.js +1 -1
  78. package/dist/esm-es5/zonos-collect-cart-items_3.entry.js +1 -1
  79. package/dist/esm-es5/zonos-collect-finish_6.entry.js +1 -1
  80. package/dist/esm-es5/zonos-collect.entry.js +1 -1
  81. package/dist/esm-es5/zonos-confirm-dialog_2.entry.js +1 -1
  82. package/dist/esm-es5/zonos-controller.entry.js +1 -1
  83. package/dist/esm-es5/zonos-country-flag.entry.js +1 -1
  84. package/dist/esm-es5/zonos-country-select_4.entry.js +1 -1
  85. package/dist/esm-es5/zonos-empty-state-payment_4.entry.js +1 -1
  86. package/dist/esm-es5/zonos-hello-dialog.entry.js +1 -1
  87. package/dist/esm-es5/zonos-hello.entry.js +1 -1
  88. package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
  89. package/dist/scripts/index.js +1 -1
  90. package/dist/scripts/loadZonos.js +1 -1
  91. package/dist/scripts/zonos.js +1 -1
  92. package/dist/types/components/store/translationStore/strings.arabic.d.ts +4 -1
  93. package/dist/types/components/store/translationStore/strings.base.d.ts +4 -1
  94. package/dist/types/components/store/translationStore/strings.chinese.d.ts +4 -1
  95. package/dist/types/components/store/translationStore/strings.danish.d.ts +4 -1
  96. package/dist/types/components/store/translationStore/strings.dutch.d.ts +4 -1
  97. package/dist/types/components/store/translationStore/strings.french.d.ts +4 -1
  98. package/dist/types/components/store/translationStore/strings.german.d.ts +4 -1
  99. package/dist/types/components/store/translationStore/strings.hebrew.d.ts +4 -1
  100. package/dist/types/components/store/translationStore/strings.indonesian.d.ts +4 -1
  101. package/dist/types/components/store/translationStore/strings.italian.d.ts +4 -1
  102. package/dist/types/components/store/translationStore/strings.japanese.d.ts +4 -1
  103. package/dist/types/components/store/translationStore/strings.korean.d.ts +4 -1
  104. package/dist/types/components/store/translationStore/strings.norwegian.d.ts +4 -1
  105. package/dist/types/components/store/translationStore/strings.polish.d.ts +4 -1
  106. package/dist/types/components/store/translationStore/strings.portuguese.d.ts +4 -1
  107. package/dist/types/components/store/translationStore/strings.russian.d.ts +4 -1
  108. package/dist/types/components/store/translationStore/strings.spanish.d.ts +4 -1
  109. package/dist/types/components/store/translationStore/strings.swedish.d.ts +4 -1
  110. package/dist/types/components/store/translationStore/strings.turkish.d.ts +4 -1
  111. package/dist/types/components/store/translationStore/strings.vietnamese.d.ts +4 -1
  112. package/dist/zonos-elements/index.esm.js +1 -1
  113. package/dist/zonos-elements/{p-82e88a33.system.js → p-00423fa0.system.js} +1 -1
  114. package/dist/zonos-elements/p-0c0fda23.js +1 -0
  115. package/dist/zonos-elements/p-19f25feb.system.entry.js +1 -0
  116. package/dist/zonos-elements/p-1cd1da90.system.js +1 -0
  117. package/dist/zonos-elements/{p-c803753e.entry.js → p-2131fa8b.entry.js} +1 -1
  118. package/dist/zonos-elements/{p-8dd47520.system.entry.js → p-245f6ad4.system.entry.js} +1 -1
  119. package/dist/zonos-elements/{p-759ef3ca.entry.js → p-366ea017.entry.js} +1 -1
  120. package/dist/zonos-elements/p-3a15f2fb.system.entry.js +1 -0
  121. package/dist/zonos-elements/{p-d291e964.system.entry.js → p-3f3c92db.system.entry.js} +1 -1
  122. package/dist/zonos-elements/{p-960e0ab1.system.entry.js → p-45d288d0.system.entry.js} +1 -1
  123. package/dist/zonos-elements/{p-637b22ee.system.entry.js → p-4637f365.system.entry.js} +1 -1
  124. package/dist/zonos-elements/{p-40a4266f.js → p-4a3abbf2.js} +1 -1
  125. package/dist/zonos-elements/p-4d9ad3b1.system.entry.js +1 -0
  126. package/dist/zonos-elements/p-4dcbbd60.js +1 -0
  127. package/dist/zonos-elements/{p-2b3c7c77.system.entry.js → p-520bd291.system.entry.js} +1 -1
  128. package/dist/zonos-elements/{p-b3d5bcf9.entry.js → p-53b46925.entry.js} +1 -1
  129. package/dist/zonos-elements/{p-b9e9b82f.system.entry.js → p-5e3d2bd2.system.entry.js} +1 -1
  130. package/dist/zonos-elements/p-62fa680d.system.js +1 -0
  131. package/dist/zonos-elements/{p-d3485a03.system.js → p-640a6898.system.js} +1 -1
  132. package/dist/zonos-elements/{p-7ecbb2cb.entry.js → p-6afbbe66.entry.js} +1 -1
  133. package/dist/zonos-elements/{p-ce15d62d.system.js → p-6f6573a5.system.js} +1 -1
  134. package/dist/zonos-elements/{p-c7b57886.js → p-7b56e345.js} +1 -1
  135. package/dist/zonos-elements/{p-e5388438.system.entry.js → p-7f7abdf2.system.entry.js} +1 -1
  136. package/dist/zonos-elements/{p-fe7e2dc4.entry.js → p-8194fcd8.entry.js} +1 -1
  137. package/dist/zonos-elements/p-81b357f7.system.js +1 -1
  138. package/dist/zonos-elements/{p-031d646e.system.js → p-81b94b8f.system.js} +1 -1
  139. package/dist/zonos-elements/{p-3462e9e4.system.entry.js → p-8350937d.system.entry.js} +1 -1
  140. package/dist/zonos-elements/p-838e448f.entry.js +1 -0
  141. package/dist/zonos-elements/{p-6b3a0874.entry.js → p-9396059b.entry.js} +1 -1
  142. package/dist/zonos-elements/{p-849b47aa.entry.js → p-9b062dfb.entry.js} +1 -1
  143. package/dist/zonos-elements/{p-52d35358.system.entry.js → p-a435931e.system.entry.js} +1 -1
  144. package/dist/zonos-elements/{p-ea8aff21.system.js → p-a7485913.system.js} +1 -1
  145. package/dist/zonos-elements/{p-3c1b1be1.system.entry.js → p-a95d2034.system.entry.js} +1 -1
  146. package/dist/zonos-elements/p-a9b3cfe1.entry.js +1 -0
  147. package/dist/zonos-elements/p-abcefd25.entry.js +1 -0
  148. package/dist/zonos-elements/{p-2a6c964d.js → p-b76db2ac.js} +1 -1
  149. package/dist/zonos-elements/{p-e77b6e42.entry.js → p-bdf183a3.entry.js} +1 -1
  150. package/dist/zonos-elements/{p-63a42823.entry.js → p-d1b415cd.entry.js} +1 -1
  151. package/dist/zonos-elements/{p-372c2fc5.entry.js → p-d2098bef.entry.js} +1 -1
  152. package/dist/zonos-elements/p-df0cbde4.js +1 -0
  153. package/dist/zonos-elements/{p-79d8c3f3.system.entry.js → p-e970f2aa.system.entry.js} +1 -1
  154. package/dist/zonos-elements/{p-a08a005d.entry.js → p-fc27467b.entry.js} +1 -1
  155. package/dist/zonos-elements/zonos-elements.esm.js +1 -1
  156. package/package.json +1 -1
  157. package/dist/esm-es5/isCollectMobileTablet-7f9a5e2b.js +0 -1
  158. package/dist/esm-es5/translationStore-13502f49.js +0 -1
  159. package/dist/zonos-elements/p-0e07e1d6.entry.js +0 -1
  160. package/dist/zonos-elements/p-126087a2.system.entry.js +0 -1
  161. package/dist/zonos-elements/p-27d9abab.js +0 -1
  162. package/dist/zonos-elements/p-2813d72e.system.js +0 -1
  163. package/dist/zonos-elements/p-2b8897d1.system.entry.js +0 -1
  164. package/dist/zonos-elements/p-5d9410da.entry.js +0 -1
  165. package/dist/zonos-elements/p-73c1e91f.js +0 -1
  166. package/dist/zonos-elements/p-932600b7.js +0 -1
  167. package/dist/zonos-elements/p-9c5b8239.system.js +0 -1
  168. package/dist/zonos-elements/p-a10de7fb.entry.js +0 -1
  169. package/dist/zonos-elements/p-a49b5e7f.system.entry.js +0 -1
@@ -1 +1 @@
1
- import{c as n,z as e}from"./p-7ce093aa.js";import{l as o,j as t,h as r,b as a}from"./p-a8a312b2.js";import{a as s}from"./p-04a01cb1.js";import{a as c}from"./p-27d9abab.js";const l=n=>{return!!(e=n).find((n=>n.testKey in s))||o("No available test key found in response","info",{response:e}),e.find((n=>n.testKey in s))?n.filter((n=>{var e;const o=s[n.testKey]&&!n.selectedVariantKey,t=n.selectedVariantKey&&!!(null===(e=s[n.testKey])||void 0===e?void 0:e.availableVariants.includes(n.selectedVariantKey));return o||t})).map((n=>Object.assign(Object.assign({},n),{expiresAt:n.expiresAt||Date.now()+i,selectedVariantKey:n.selectedVariantKey||null}))):[];var e},i=864e5,{onChange:u,state:d}=n({checkoutSessionId:sessionStorage.getItem("zonos--checkout-session-id"),enabledVariantTestKeys:t(localStorage.getItem("zonos--enabled-variant-test-keys"))});u("enabledVariantTestKeys",(()=>{var n;(null===(n=d.enabledVariantTestKeys)||void 0===n?void 0:n.length)?localStorage.setItem("zonos--enabled-variant-test-keys",JSON.stringify(d.enabledVariantTestKeys)):localStorage.removeItem("zonos--enabled-variant-test-keys")})),u("checkoutSessionId",(()=>{d.checkoutSessionId?sessionStorage.setItem("zonos--checkout-session-id",d.checkoutSessionId):sessionStorage.removeItem("zonos--checkout-session-id")}));const y=n=>{d.enabledVariantTestKeys=l(n)},m=async()=>{try{const{errors:n,json:e}=await r("/api/zonos-elements/get-countries",{method:"GET"});return n.length||!e?null:e}catch(n){return null}},v={exchangeRate:{rate:1,targetFormat:{currencyCode:"USD",decimalDelimiter:".",scale:2,symbol:"$",symbolLocation:"before",thousandsDelimiter:","}},maxAge:null},g=n=>{const e=new URLSearchParams(n||window.location.search),o=n=>{return(o=e.get(n))&&/^[A-Z]{2}$/.test(o)?o:null;var o},t=o("zCountry"),r=o("country"),a=o("customerCountry");return t||r||a},w=async()=>{try{const n=new URL(window.location.href),e=window.sessionStorage.getItem("zonos--country"),o=g(n.searchParams)||e,t=new URLSearchParams;o&&t.set("zCountry",o);const{errors:a,json:s}=await r(`/api/zonos-elements/localization?${t.toString()}`);return a.length||!s?{country:null,locale:null}:{country:s.country,locale:s.locale}}catch(n){return{country:null,locale:null}}},p=async()=>{var n,e,o;if(null===(n=window.Zonos.cartSettings)||void 0===n?void 0:n.shippingZones)return window.Zonos.cartSettings.shippingZones.flatMap((n=>null==n?void 0:n.countryCodes)).filter(Boolean);const{errors:t,json:s}=await r("/api/zonos-elements/shipping-zones");return t.length||!s?(a(`Error fetching shipping zones: ${null===(e=t.find(Boolean))||void 0===e?void 0:e.message}`),null):(null===(o=null==s?void 0:s.shippingZones)||void 0===o?void 0:o.flatMap((n=>null==n?void 0:n.countryCodes)).filter(Boolean))||null},h=n=>{const{exchangeRate:e}=j;if(!e||!n||isNaN(n))return n;const o=(n*e.rate).toFixed((null==e?void 0:e.targetFormat.scale)||2);return Number(o)},f=({amount:n,currency:o})=>{if(isNaN(n)||0!==n&&!n)return"";const t=e.overrideCurrencyFormat,{exchangeRate:r}=j,a=o||j.targetCurrency;if("function"==typeof t)return t({amount:n,currencyCode:a,numberFormat:({amount:n})=>(({amount:n,currency:e,targetFormat:o})=>{const t=e||j.targetCurrency,r=(null==o?void 0:o.scale)||2,a=-1!==window.navigator.userAgent.indexOf("MSIE "),s="object"==typeof Intl&&Intl&&"function"==typeof Intl.NumberFormat;return a||!s?Number(n).toFixed(r).replace(".","|dec|").replace(",",(null==o?void 0:o.thousandsDelimiter)||"").replace("|dec|",(null==o?void 0:o.decimalDelimiter)||""):new Intl.NumberFormat(window.navigator.language,{currency:t,currencyDisplay:"code",minimumFractionDigits:r,style:"currency"}).format(n).replace(new RegExp(`${t}\\s+`),"")})({amount:n,currency:a,targetFormat:(null==r?void 0:r.targetFormat)||null})});const{targetFormat:s}=r||{};if(!s||!r)return`${n.toFixed(2)} ${a}`;const c=s.scale||2,l=-1!==window.navigator.userAgent.indexOf("MSIE "),i="object"==typeof Intl&&Intl&&"function"==typeof Intl.NumberFormat;if(l||!i)return`${Number(n).toFixed(c).replace(".","|dec|").replace(",",s.thousandsDelimiter||"").replace("|dec|",s.decimalDelimiter||"")}${"USD"!==s.currencyCode?` ${s.currencyCode}`:""}`;const u=(null==t?void 0:t.currencyDisplay)||"symbol",d=new Intl.NumberFormat(window.navigator.language,{currency:a,currencyDisplay:u,minimumFractionDigits:c,style:"currency"}).format(n);return"code"===u?`${d.replace(new RegExp(`${a}\\s+`),"")} ${a}`:d},C=n=>{const e=h(n);return f({amount:e})},b=n=>{try{document.createDocumentFragment().querySelector(n)}catch(n){return!1}return!0},z=()=>{const{currencyElementSelector:n}=e.helloSettings,t=(n=>{const e=n||".money";if(!b(e))return a(`Currency element selector "${e}" is not valid.`),null;const t=document.querySelectorAll(e);return t.length?Array.from(t):(o(`No currency elements found with selector "${e}"`,"warn"),null)})(n);(null==t?void 0:t.length)&&(j.exchangeRate?t.forEach((n=>{(n=>{var o;const t=(n=>{var e;const o=n.getAttribute("data-domestic"),t=n.getAttribute("data-zintl"),r=null===(e=n.textContent)||void 0===e?void 0:e.replace(/[^\d.-]/g,"");return r?!o||n.textContent!==t&&t?(n.setAttribute("data-domestic",r),parseFloat(r)):parseFloat(o):null})(n);if(!t||isNaN(t))return;const r=n.getAttribute("data-zintl"),a=parseFloat(n.getAttribute("data-zrate")||"1"),s=n.getAttribute("data-zcountry-code"),c=(null===(o=j.exchangeRate)||void 0===o?void 0:o.rate)||1;if(j.exchangeRate&&j.targetCurrency===j.exchangeRate.targetFormat.currencyCode&&(n.textContent!==r||c!==a||s!==j.selectedCountryCode)){const o="function"==typeof e.currencyConverter&&e.currencyConverter({convert:h,convertAndFormat:C,currencyCode:j.targetCurrency,format:n=>f({amount:n}),originalAmount:t,selector:n})||C(t);o!==n.textContent&&(n.textContent=o),n.setAttribute("data-zrate",c.toString()),n.setAttribute("data-zintl",o),n.setAttribute("data-zcountry-code",j.selectedCountryCode||"")}})(n)})):a("Could not display currency. Exchange rate and format data is not available."))},$=()=>{"DISABLED"===e.helloSettings.currencyBehavior||window.Zonos.isLegacyCheckout||z()},S=n=>{if(!n)return;const o=new URLSearchParams(window.location.search);if(o.has("zCountry")||"URL_PARAM"===e.helloSettings.countryOverrideBehavior){o.set("zCountry",n);const e=`${window.location.pathname}?${o.toString()}`;window.history.replaceState(window.history.state,document.title,e)}},{onChange:A,state:j}=n({countryLandedCost:null,customMessages:[],exchangeRate:null,helloCountryList:null,inclusivePricing:null,isDisabledCountry:!0,isShippableCountry:!1,localizationLoaded:!1,selectedCountryCode:null,selectedLocale:"en",shippingZoneCountries:null,targetCurrency:"USD"}),x=async n=>{const{exchangeRate:o,maxAge:t}=await(async({country:n,isGuaranteed:e,sourceCurrency:o,targetCurrency:t})=>{var s;if(o===t&&!e)return v;const c=new URLSearchParams;c.set("sourceCurrency",o),c.set("targetCurrency",t),c.set("isGuaranteed",String(e)),c.set("country",n||"");const{errors:l,json:i}=await r(`/api/zonos-elements/exchange-rates?${c.toString()}`);if(l.length||!i)return a(`Error fetching country landed cost: ${null===(s=l.find(Boolean))||void 0===s?void 0:s.message}`),v;const{rate:u,targetFormat:d}=i.exchangeRateCreate,y=i.maxAge;return u?(sessionStorage.setItem(n+"_rate",JSON.stringify(u)),{exchangeRate:{rate:u,targetFormat:d},maxAge:y}):v})({country:j.selectedCountryCode,isGuaranteed:n,sourceCurrency:e.sourceCurrency,targetCurrency:j.targetCurrency});return o&&(j.exchangeRate=o,$()),{maxAge:t}},L=n=>j.selectedCountryCode&&n.includes(j.selectedCountryCode)?j.selectedCountryCode:"CA",I=({isGuaranteed:n,maxAge:e})=>{j.exchangeRateTimeout&&clearTimeout(j.exchangeRateTimeout),j.exchangeRateTimeout=setTimeout((async()=>{const{maxAge:e}=await x(n);I({isGuaranteed:n,maxAge:e})}),1e3*(e||300))},E=n=>{var t,s;o(`Updating selected country code to ${n}`);const c=!j.selectedCountryCode;var l;j.selectedCountryCode="UK"===(l=n)?"GB":l;const{selectedCountryCode:i,shippingZoneCountries:u}=j,d=!(!u||!i||!u[i]||e.disabledCountries.includes(i));j.isShippableCountry=d,o(`${j.selectedCountryCode} is a shippable country: ${j.isShippableCountry}`);const y=!!i&&e.disabledCountries.includes(i);if(j.isDisabledCountry=y,o(`${j.selectedCountryCode} is a disabled country: ${j.isDisabledCountry}`),j.isShippableCountry?document.body.classList.add("z-intl"):document.body.classList.remove("z-intl"),!i)return;const m=(n=>{var e;const o=null===(e=j.shippingZoneCountries)||void 0===e?void 0:e[n];return o?o.currencyCode:null})(i);c||null===(t=e.onCountryChange)||void 0===t||t.call(e,{countryCode:i,currencyCode:m,isShippableCountry:d}),m&&(j.targetCurrency=m,(async()=>{var n;o("get new localization store");const{isDisabledCountry:t,isShippableCountry:s,selectedCountryCode:c}=j;if(window.Zonos.isLegacyCheckout?o("Skipping country landed cost and inclusive pricing requests, because this is a legacy checkout"):(j.countryLandedCost=await(async n=>{var e;if(!n)return null;const o=`/api/zonos-elements/country-landed-cost/${n}`,{errors:t,json:s}=await r(o);return t.length||!s?(a(`Error fetching country landed cost: ${null===(e=t.find(Boolean))||void 0===e?void 0:e.message}`),null):s||null})(j.selectedCountryCode),j.inclusivePricing=(null===(n=await(async n=>{var e;if(!n)return null;const{errors:o,json:t}=await r(`/api/zonos-elements/inclusive-prices/${n}`);return o.length||!t?(a(`Error fetching country inclusive price setting: ${null===(e=o.find(Boolean))||void 0===e?void 0:e.message}`),null):t||null})(c))||void 0===n?void 0:n.setting)||null,j.inclusivePricing&&o(`Inclusive price setting found for this country (${c}) ${JSON.stringify(j.inclusivePricing,null,2)}`)),"DISABLED"===e.helloSettings.currencyBehavior||!s||t||!c)return;const l="ENABLED"===e.checkoutSettings.visibilityStatus,{maxAge:i}=await x(l);I({isGuaranteed:l,maxAge:i})})(),window.sessionStorage.setItem("zonos--country",i),S(i),null===(s=document.querySelector("zonos-hello"))||void 0===s||s.setAttribute("z-country",i))},N=n=>{j.selectedLocale=n,c(n),(async()=>{if(!d.checkoutSessionId)return null;const{errors:n,json:e}=await r("/api/zonos-elements/update-checkout-session-metadata",{body:{id:d.checkoutSessionId,metadata:[{key:"language",value:j.selectedLocale}]},method:"POST"});(n.length||!e)&&a("Error occurs when updating checkout session",JSON.stringify(n,null,2))})(),(async()=>{if(o(`Getting custom messages for ${j.selectedCountryCode}`),!j.selectedCountryCode||!e.storeId)return;const n=(await(async({countryCode:n,localeTo:e,storeId:o})=>{var t;const s=new URLSearchParams;s.set("countryCode",n),s.set("storeId",o.toString()),e&&s.set("localeTo",e);const{errors:c,json:l}=await r(`/api/zonos-elements/locale-messages?${s.toString()}`);return c.length||!l?(a("Error fetching exchange rate",null===(t=c.find(Boolean))||void 0===t?void 0:t.message),[]):l.locale_countryCodesPage})({countryCode:j.selectedCountryCode,localeTo:j.selectedLocale,storeId:e.storeId})).flatMap((n=>{var e;return{countryCode:j.selectedCountryCode,message:null===(e=n.countryCodesPageMessageLinks.find(Boolean))||void 0===e?void 0:e.message.textTo,pageName:n.pageName}}));j.customMessages=n})()},D=async()=>{const[n,t,r]=await Promise.all([m(),p(),w()]),a=null==t?void 0:t.reduce(((e,o)=>{const t=null==n?void 0:n[o];return t?Object.assign(Object.assign({},e),{[o]:t}):e}),{});j.shippingZoneCountries=a||null,(n=>{const o=e.helloSettings.showCountryList,t=j.shippingZoneCountries;j.helloCountryList=o&&"ONLY_SHIPPABLE"!==o?"ALL"!==o?o.reduce(((e,o)=>{const t=null==n?void 0:n[o];return t?Object.assign(Object.assign({},e),{[o]:t}):e}),{}):n:t})(n||{});const{country:s,locale:c}=r;o(`Country code from localization: ${s}`),o(`Locale from localization: ${c}`),E(s);const l=new URL(window.location.href).searchParams.get("zonosLocale");N(l||c||"en"),!j.selectedCountryCode&&["dev.storybook.elements","dev.elements","dev.demo.elements","dev.dashboard"].some((n=>window.location.origin.includes(n)))&&E("CA"),j.localizationLoaded=!0};export{i as V,E as a,y as b,A as c,f as d,D as e,l as f,g,S as h,b as i,$ as j,C as k,j as l,h as m,L as n,u as o,N as p,d as s}
1
+ import{c as n,z as e}from"./p-7ce093aa.js";import{l as o,j as t,h as r,b as a}from"./p-a8a312b2.js";import{a as s}from"./p-04a01cb1.js";import{a as c}from"./p-0c0fda23.js";const l=n=>{return!!(e=n).find((n=>n.testKey in s))||o("No available test key found in response","info",{response:e}),e.find((n=>n.testKey in s))?n.filter((n=>{var e;const o=s[n.testKey]&&!n.selectedVariantKey,t=n.selectedVariantKey&&!!(null===(e=s[n.testKey])||void 0===e?void 0:e.availableVariants.includes(n.selectedVariantKey));return o||t})).map((n=>Object.assign(Object.assign({},n),{expiresAt:n.expiresAt||Date.now()+i,selectedVariantKey:n.selectedVariantKey||null}))):[];var e},i=864e5,{onChange:u,state:d}=n({checkoutSessionId:sessionStorage.getItem("zonos--checkout-session-id"),enabledVariantTestKeys:t(localStorage.getItem("zonos--enabled-variant-test-keys"))});u("enabledVariantTestKeys",(()=>{var n;(null===(n=d.enabledVariantTestKeys)||void 0===n?void 0:n.length)?localStorage.setItem("zonos--enabled-variant-test-keys",JSON.stringify(d.enabledVariantTestKeys)):localStorage.removeItem("zonos--enabled-variant-test-keys")})),u("checkoutSessionId",(()=>{d.checkoutSessionId?sessionStorage.setItem("zonos--checkout-session-id",d.checkoutSessionId):sessionStorage.removeItem("zonos--checkout-session-id")}));const y=n=>{d.enabledVariantTestKeys=l(n)},m=async()=>{try{const{errors:n,json:e}=await r("/api/zonos-elements/get-countries",{method:"GET"});return n.length||!e?null:e}catch(n){return null}},v={exchangeRate:{rate:1,targetFormat:{currencyCode:"USD",decimalDelimiter:".",scale:2,symbol:"$",symbolLocation:"before",thousandsDelimiter:","}},maxAge:null},g=n=>{const e=new URLSearchParams(n||window.location.search),o=n=>{return(o=e.get(n))&&/^[A-Z]{2}$/.test(o)?o:null;var o},t=o("zCountry"),r=o("country"),a=o("customerCountry");return t||r||a},w=async()=>{try{const n=new URL(window.location.href),e=window.sessionStorage.getItem("zonos--country"),o=g(n.searchParams)||e,t=new URLSearchParams;o&&t.set("zCountry",o);const{errors:a,json:s}=await r(`/api/zonos-elements/localization?${t.toString()}`);return a.length||!s?{country:null,locale:null}:{country:s.country,locale:s.locale}}catch(n){return{country:null,locale:null}}},p=async()=>{var n,e,o;if(null===(n=window.Zonos.cartSettings)||void 0===n?void 0:n.shippingZones)return window.Zonos.cartSettings.shippingZones.flatMap((n=>null==n?void 0:n.countryCodes)).filter(Boolean);const{errors:t,json:s}=await r("/api/zonos-elements/shipping-zones");return t.length||!s?(a(`Error fetching shipping zones: ${null===(e=t.find(Boolean))||void 0===e?void 0:e.message}`),null):(null===(o=null==s?void 0:s.shippingZones)||void 0===o?void 0:o.flatMap((n=>null==n?void 0:n.countryCodes)).filter(Boolean))||null},h=n=>{const{exchangeRate:e}=j;if(!e||!n||isNaN(n))return n;const o=(n*e.rate).toFixed((null==e?void 0:e.targetFormat.scale)||2);return Number(o)},f=({amount:n,currency:o})=>{if(isNaN(n)||0!==n&&!n)return"";const t=e.overrideCurrencyFormat,{exchangeRate:r}=j,a=o||j.targetCurrency;if("function"==typeof t)return t({amount:n,currencyCode:a,numberFormat:({amount:n})=>(({amount:n,currency:e,targetFormat:o})=>{const t=e||j.targetCurrency,r=(null==o?void 0:o.scale)||2,a=-1!==window.navigator.userAgent.indexOf("MSIE "),s="object"==typeof Intl&&Intl&&"function"==typeof Intl.NumberFormat;return a||!s?Number(n).toFixed(r).replace(".","|dec|").replace(",",(null==o?void 0:o.thousandsDelimiter)||"").replace("|dec|",(null==o?void 0:o.decimalDelimiter)||""):new Intl.NumberFormat(window.navigator.language,{currency:t,currencyDisplay:"code",minimumFractionDigits:r,style:"currency"}).format(n).replace(new RegExp(`${t}\\s+`),"")})({amount:n,currency:a,targetFormat:(null==r?void 0:r.targetFormat)||null})});const{targetFormat:s}=r||{};if(!s||!r)return`${n.toFixed(2)} ${a}`;const c=s.scale||2,l=-1!==window.navigator.userAgent.indexOf("MSIE "),i="object"==typeof Intl&&Intl&&"function"==typeof Intl.NumberFormat;if(l||!i)return`${Number(n).toFixed(c).replace(".","|dec|").replace(",",s.thousandsDelimiter||"").replace("|dec|",s.decimalDelimiter||"")}${"USD"!==s.currencyCode?` ${s.currencyCode}`:""}`;const u=(null==t?void 0:t.currencyDisplay)||"symbol",d=new Intl.NumberFormat(window.navigator.language,{currency:a,currencyDisplay:u,minimumFractionDigits:c,style:"currency"}).format(n);return"code"===u?`${d.replace(new RegExp(`${a}\\s+`),"")} ${a}`:d},C=n=>{const e=h(n);return f({amount:e})},z=n=>{try{document.createDocumentFragment().querySelector(n)}catch(n){return!1}return!0},b=()=>{const{currencyElementSelector:n}=e.helloSettings,t=(n=>{const e=n||".money";if(!z(e))return a(`Currency element selector "${e}" is not valid.`),null;const t=document.querySelectorAll(e);return t.length?Array.from(t):(o(`No currency elements found with selector "${e}"`,"warn"),null)})(n);(null==t?void 0:t.length)&&(j.exchangeRate?t.forEach((n=>{(n=>{var o;const t=(n=>{var e;const o=n.getAttribute("data-domestic"),t=n.getAttribute("data-zintl"),r=null===(e=n.textContent)||void 0===e?void 0:e.replace(/[^\d.-]/g,"");return r?!o||n.textContent!==t&&t?(n.setAttribute("data-domestic",r),parseFloat(r)):parseFloat(o):null})(n);if(!t||isNaN(t))return;const r=n.getAttribute("data-zintl"),a=parseFloat(n.getAttribute("data-zrate")||"1"),s=n.getAttribute("data-zcountry-code"),c=(null===(o=j.exchangeRate)||void 0===o?void 0:o.rate)||1;if(j.exchangeRate&&j.targetCurrency===j.exchangeRate.targetFormat.currencyCode&&(n.textContent!==r||c!==a||s!==j.selectedCountryCode)){const o="function"==typeof e.currencyConverter&&e.currencyConverter({convert:h,convertAndFormat:C,currencyCode:j.targetCurrency,format:n=>f({amount:n}),originalAmount:t,selector:n})||C(t);o!==n.textContent&&(n.textContent=o),n.setAttribute("data-zrate",c.toString()),n.setAttribute("data-zintl",o),n.setAttribute("data-zcountry-code",j.selectedCountryCode||"")}})(n)})):a("Could not display currency. Exchange rate and format data is not available."))},$=()=>{"DISABLED"===e.helloSettings.currencyBehavior||window.Zonos.isLegacyCheckout||b()},S=n=>{if(!n)return;const o=new URLSearchParams(window.location.search);if(o.has("zCountry")||"URL_PARAM"===e.helloSettings.countryOverrideBehavior){o.set("zCountry",n);const e=`${window.location.pathname}?${o.toString()}`;window.history.replaceState(window.history.state,document.title,e)}},{onChange:A,state:j}=n({countryLandedCost:null,customMessages:[],exchangeRate:null,helloCountryList:null,inclusivePricing:null,isDisabledCountry:!0,isShippableCountry:!1,localizationLoaded:!1,selectedCountryCode:null,selectedLocale:"en",shippingZoneCountries:null,targetCurrency:"USD"}),x=async n=>{const{exchangeRate:o,maxAge:t}=await(async({country:n,isGuaranteed:e,sourceCurrency:o,targetCurrency:t})=>{var s;if(o===t&&!e)return v;const c=new URLSearchParams;c.set("sourceCurrency",o),c.set("targetCurrency",t),c.set("isGuaranteed",String(e)),c.set("country",n||"");const{errors:l,json:i}=await r(`/api/zonos-elements/exchange-rates?${c.toString()}`);if(l.length||!i)return a(`Error fetching country landed cost: ${null===(s=l.find(Boolean))||void 0===s?void 0:s.message}`),v;const{rate:u,targetFormat:d}=i.exchangeRateCreate,y=i.maxAge;return u?(sessionStorage.setItem(n+"_rate",JSON.stringify(u)),{exchangeRate:{rate:u,targetFormat:d},maxAge:y}):v})({country:j.selectedCountryCode,isGuaranteed:n,sourceCurrency:e.sourceCurrency,targetCurrency:j.targetCurrency});return o&&(j.exchangeRate=o,$()),{maxAge:t}},L=n=>j.selectedCountryCode&&n.includes(j.selectedCountryCode)?j.selectedCountryCode:"CA",I=({isGuaranteed:n,maxAge:e})=>{j.exchangeRateTimeout&&clearTimeout(j.exchangeRateTimeout),j.exchangeRateTimeout=setTimeout((async()=>{const{maxAge:e}=await x(n);I({isGuaranteed:n,maxAge:e})}),1e3*(e||300))},E=n=>{var t,s;o(`Updating selected country code to ${n}`);const c=!j.selectedCountryCode;var l;j.selectedCountryCode="UK"===(l=n)?"GB":l;const{selectedCountryCode:i,shippingZoneCountries:u}=j,d=!(!u||!i||!u[i]||e.disabledCountries.includes(i));j.isShippableCountry=d,o(`${j.selectedCountryCode} is a shippable country: ${j.isShippableCountry}`);const y=!!i&&e.disabledCountries.includes(i);if(j.isDisabledCountry=y,o(`${j.selectedCountryCode} is a disabled country: ${j.isDisabledCountry}`),j.isShippableCountry?document.body.classList.add("z-intl"):document.body.classList.remove("z-intl"),!i)return;const m=(n=>{var e;const o=null===(e=j.shippingZoneCountries)||void 0===e?void 0:e[n];return o?o.currencyCode:null})(i);c||null===(t=e.onCountryChange)||void 0===t||t.call(e,{countryCode:i,currencyCode:m,isShippableCountry:d}),m&&(j.targetCurrency=m,(async()=>{var n;o("get new localization store");const{isDisabledCountry:t,isShippableCountry:s,selectedCountryCode:c}=j;if(window.Zonos.isLegacyCheckout?o("Skipping country landed cost and inclusive pricing requests, because this is a legacy checkout"):(j.countryLandedCost=await(async n=>{var e;if(!n)return null;const o=`/api/zonos-elements/country-landed-cost/${n}`,{errors:t,json:s}=await r(o);return t.length||!s?(a(`Error fetching country landed cost: ${null===(e=t.find(Boolean))||void 0===e?void 0:e.message}`),null):s||null})(j.selectedCountryCode),j.inclusivePricing=(null===(n=await(async n=>{var e;if(!n)return null;const{errors:o,json:t}=await r(`/api/zonos-elements/inclusive-prices/${n}`);return o.length||!t?(a(`Error fetching country inclusive price setting: ${null===(e=o.find(Boolean))||void 0===e?void 0:e.message}`),null):t||null})(c))||void 0===n?void 0:n.setting)||null,j.inclusivePricing&&o(`Inclusive price setting found for this country (${c}) ${JSON.stringify(j.inclusivePricing,null,2)}`)),"DISABLED"===e.helloSettings.currencyBehavior||!s||t||!c)return;const l="ENABLED"===e.checkoutSettings.visibilityStatus,{maxAge:i}=await x(l);I({isGuaranteed:l,maxAge:i})})(),window.sessionStorage.setItem("zonos--country",i),S(i),null===(s=document.querySelector("zonos-hello"))||void 0===s||s.setAttribute("z-country",i))},N=n=>{j.selectedLocale=n,c(n),(async()=>{if(!d.checkoutSessionId)return null;const{errors:n,json:e}=await r("/api/zonos-elements/update-checkout-session-metadata",{body:{id:d.checkoutSessionId,metadata:[{key:"language",value:j.selectedLocale}]},method:"POST"});(n.length||!e)&&a("Error occurs when updating checkout session",JSON.stringify(n,null,2))})(),(async()=>{if(o(`Getting custom messages for ${j.selectedCountryCode}`),!j.selectedCountryCode||!e.storeId)return;const n=(await(async({countryCode:n,localeTo:e,storeId:o})=>{var t;const s=new URLSearchParams;s.set("countryCode",n),s.set("storeId",o.toString()),e&&s.set("localeTo",e);const{errors:c,json:l}=await r(`/api/zonos-elements/locale-messages?${s.toString()}`);return c.length||!l?(a("Error fetching exchange rate",null===(t=c.find(Boolean))||void 0===t?void 0:t.message),[]):l.locale_countryCodesPage})({countryCode:j.selectedCountryCode,localeTo:j.selectedLocale,storeId:e.storeId})).flatMap((n=>{var e;return{countryCode:j.selectedCountryCode,message:null===(e=n.countryCodesPageMessageLinks.find(Boolean))||void 0===e?void 0:e.message.textTo,pageName:n.pageName}}));j.customMessages=n})()},D=async()=>{const[n,t,r]=await Promise.all([m(),p(),w()]),a=null==t?void 0:t.reduce(((e,o)=>{const t=null==n?void 0:n[o];return t?Object.assign(Object.assign({},e),{[o]:t}):e}),{});j.shippingZoneCountries=a||null,(n=>{const o=e.helloSettings.showCountryList,t=j.shippingZoneCountries;j.helloCountryList=o&&"ONLY_SHIPPABLE"!==o?"ALL"!==o?o.reduce(((e,o)=>{const t=null==n?void 0:n[o];return t?Object.assign(Object.assign({},e),{[o]:t}):e}),{}):n:t})(n||{});const{country:s,locale:c}=r;o(`Country code from localization: ${s}`),o(`Locale from localization: ${c}`),E(s);const l=new URL(window.location.href).searchParams.get("zonosLocale");N(l||c||"en"),!j.selectedCountryCode&&["dev.storybook.elements","dev.elements","dev.demo.elements","dev.dashboard"].some((n=>window.location.origin.includes(n)))&&E("CA"),j.localizationLoaded=!0};export{i as V,E as a,y as b,A as c,f as d,D as e,l as f,g,S as h,z as i,$ as j,C as k,j as l,h as m,L as n,u as o,N as p,d as s}