@zonos/elements 1.3.218 → 1.3.219
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/buildCartItemsByTempCart-309fcebf.js +28 -0
- package/dist/cjs/{cart-c54d05ce.js → cart-9a2b32e4.js} +90 -47
- package/dist/cjs/cleanHtmlMarkdown-577d0a77.js +999 -0
- package/dist/cjs/index.cjs.js +19 -9
- package/dist/cjs/isCollectMobileTablet-7e57fd90.js +172 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/localization-b12edb2a.js +738 -0
- package/dist/cjs/{paypal-d36b5dd1.js → paypal-e80871d0.js} +12 -8
- package/dist/cjs/placeTestOrder-8222fe95.js +93 -0
- package/dist/cjs/{localization-ab7e1902.js → translationStore-20a6d8bf.js} +963 -734
- package/dist/cjs/zonos-address_11.cjs.entry.js +102 -72
- package/dist/cjs/zonos-badge.cjs.entry.js +3 -3
- package/dist/cjs/{zonos-banner.cjs.entry.js → zonos-banner_2.cjs.entry.js} +40 -0
- package/dist/cjs/zonos-button_3.cjs.entry.js +3 -3
- package/dist/cjs/{zonos-cart-items_14.cjs.entry.js → zonos-cart-items_12.cjs.entry.js} +73 -1292
- package/dist/cjs/zonos-checkout.cjs.entry.js +25 -48
- package/dist/cjs/zonos-collapse.cjs.entry.js +2 -2
- package/dist/cjs/zonos-collect-cart-items_3.cjs.entry.js +92 -0
- package/dist/cjs/zonos-collect-finish_6.cjs.entry.js +810 -0
- package/dist/cjs/zonos-collect.cjs.entry.js +468 -0
- package/dist/cjs/zonos-component.cjs.entry.js +1 -1
- package/dist/cjs/zonos-confirm-dialog_2.cjs.entry.js +168 -0
- package/dist/cjs/zonos-controller.cjs.entry.js +84 -28
- package/dist/cjs/zonos-country-flag.cjs.entry.js +2 -1
- package/dist/cjs/zonos-country-select_4.cjs.entry.js +11 -10
- package/dist/cjs/zonos-elements.cjs.js +1 -1
- package/dist/cjs/zonos-empty-state-payment_4.cjs.entry.js +15 -5
- package/dist/cjs/zonos-hello-dialog.cjs.entry.js +34 -33
- package/dist/cjs/zonos-hello.cjs.entry.js +8 -7
- package/dist/cjs/zonos-input.cjs.entry.js +4 -4
- package/dist/cjs/zonos-language-select_2.cjs.entry.js +6 -5
- package/dist/cjs/zonos-link.cjs.entry.js +1 -1
- package/dist/cjs/zonos-logo.cjs.entry.js +2 -2
- package/dist/cjs/zonos-stripe-input.cjs.entry.js +8 -5
- package/dist/cjs/zonos-text.cjs.entry.js +1 -1
- package/dist/cjs/zonos-toggle.cjs.entry.js +2 -2
- package/dist/cjs/zonos-tooltip.cjs.entry.js +2 -2
- package/dist/cjs/zonos-v-stack.cjs.entry.js +2 -2
- package/dist/collection/collection-manifest.json +10 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-payment/zonos-checkout-payment.js +3 -0
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout.js +2 -2
- package/dist/collection/components/checkout/zonos-checkout/zonos-shipping/zonos-shipping.js +5 -1
- package/dist/collection/components/checkout/zonos-collect/assets/ChevronDownIcon.svg +1 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-cart-items/assets/empty-item.jpeg +0 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-cart-items/zonos-collect-cart-items.css +60 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-cart-items/zonos-collect-cart-items.js +39 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-finish/assets/RemoveIcon.svg +1 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-finish/assets/SuccessIcon.svg +1 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-finish/zonos-collect-finish.css +84 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-finish/zonos-collect-finish.js +403 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-footer/assets/chevronDownIcon.svg +1 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-footer/assets/globe.svg +3 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-footer/assets/zonosIconDark.svg +10 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-footer/assets/zonosIconLight.svg +10 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-footer/assets/zonosWordmark.svg +7 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-footer/zonos-collect-footer.css +152 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-footer/zonos-collect-footer.js +164 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-order-details/assets/ChevronDownIcon.svg +1 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-order-details/assets/ChevronUpIcon.svg +1 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-order-details/zonos-collect-order-details.css +109 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-order-details/zonos-collect-order-details.js +194 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-payment/assets/CheckmarkLineIcon.svg +1 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-payment/assets/RemoveLineIcon.svg +1 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-payment/zonos-collect-payment.css +98 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-payment/zonos-collect-payment.js +369 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-review/zonos-collect-review.css +68 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-review/zonos-collect-review.js +151 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-subtotal/zonos-collect-subtotal.css +78 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect-subtotal/zonos-collect-subtotal.js +115 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect.css +349 -0
- package/dist/collection/components/checkout/zonos-collect/zonos-collect.js +547 -0
- package/dist/collection/components/common/zonos-badge/zonos-badge.js +3 -3
- package/dist/collection/components/common/zonos-button/zonos-button.js +3 -3
- package/dist/collection/components/common/zonos-card/zonos-card.js +4 -4
- package/dist/collection/components/common/zonos-checkbox/zonos-checkbox.js +3 -3
- package/dist/collection/components/common/zonos-checkout-progress-tabs/zonos-checkout-progress-tabs.js +3 -3
- package/dist/collection/components/common/zonos-collapse/zonos-collapse.js +2 -2
- package/dist/collection/components/common/zonos-confirm-dialog/zonos-confirm-dialog.js +3 -3
- package/dist/collection/components/common/zonos-country-select/zonos-country-select.js +3 -3
- package/dist/collection/components/common/zonos-custom-message/zonos-custom-message.js +2 -2
- package/dist/collection/components/common/zonos-dialog/zonos-dialog.js +3 -3
- package/dist/collection/components/common/zonos-h-stack/zonos-h-stack.css +38 -0
- package/dist/collection/components/common/zonos-h-stack/zonos-h-stack.js +63 -0
- package/dist/collection/components/common/zonos-input/zonos-input.js +4 -4
- package/dist/collection/components/common/zonos-language-select/zonos-language-select.js +2 -2
- package/dist/collection/components/common/zonos-link/zonos-link.js +1 -1
- package/dist/collection/components/common/zonos-loading-overlay/zonos-loading-overlay.js +1 -1
- package/dist/collection/components/common/zonos-logo/zonos-logo.js +2 -2
- package/dist/collection/components/common/zonos-rest-state/zonos-rest-state.js +3 -3
- package/dist/collection/components/common/zonos-select-dialog-header/zonos-select-dialog-header.js +2 -2
- package/dist/collection/components/common/zonos-skeleton/assets/RemoveLineIcon.svg +3 -0
- package/dist/collection/components/common/zonos-skeleton/zonos-skeleton.css +40 -0
- package/dist/collection/components/common/zonos-skeleton/zonos-skeleton.js +102 -0
- package/dist/collection/components/common/zonos-stripe-input/zonos-stripe-input.js +8 -5
- package/dist/collection/components/common/zonos-stripe-phone-input/zonos-stripe-phone-input.js +5 -5
- package/dist/collection/components/common/zonos-stripe-select/zonos-stripe-select.js +5 -5
- package/dist/collection/components/common/zonos-text/zonos-text.css +1 -0
- package/dist/collection/components/common/zonos-toggle/zonos-toggle.js +2 -2
- package/dist/collection/components/common/zonos-tooltip/zonos-tooltip.js +2 -2
- package/dist/collection/components/common/zonos-v-stack/zonos-v-stack.js +2 -2
- package/dist/collection/components/common/zonos-virtual-scroll/zonos-virtual-scroll.js +2 -2
- package/dist/collection/components/component-template/zonos-component/zonos-component.js +1 -1
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog-footer/zonos-hello-dialog-footer.js +2 -2
- package/dist/collection/components/hello/zonos-hello-dialog/zonos-hello-dialog.js +4 -4
- package/dist/collection/components/main/zonos-controller.js +91 -25
- package/dist/collection/components/paypal/zonos-paypal-payment.js +13 -2
- package/dist/collection/components/store/checkout/cart.js +36 -15
- package/dist/collection/components/store/checkout/collect.js +157 -0
- package/dist/collection/components/store/checkout/paypal.js +4 -2
- package/dist/collection/components/store/checkout/stripe.js +31 -12
- package/dist/collection/components/store/translationStore/strings.arabic.js +48 -0
- package/dist/collection/components/store/translationStore/strings.base.js +48 -0
- package/dist/collection/components/store/translationStore/strings.chinese.js +48 -0
- package/dist/collection/components/store/translationStore/strings.danish.js +48 -0
- package/dist/collection/components/store/translationStore/strings.dutch.js +48 -0
- package/dist/collection/components/store/translationStore/strings.french.js +48 -0
- package/dist/collection/components/store/translationStore/strings.german.js +48 -0
- package/dist/collection/components/store/translationStore/strings.hebrew.js +48 -0
- package/dist/collection/components/store/translationStore/strings.indonesian.js +48 -0
- package/dist/collection/components/store/translationStore/strings.italian.js +48 -0
- package/dist/collection/components/store/translationStore/strings.japanese.js +48 -0
- package/dist/collection/components/store/translationStore/strings.korean.js +48 -0
- package/dist/collection/components/store/translationStore/strings.norwegian.js +48 -0
- package/dist/collection/components/store/translationStore/strings.polish.js +48 -0
- package/dist/collection/components/store/translationStore/strings.portuguese.js +48 -0
- package/dist/collection/components/store/translationStore/strings.russian.js +48 -0
- package/dist/collection/components/store/translationStore/strings.spanish.js +48 -0
- package/dist/collection/components/store/translationStore/strings.swedish.js +48 -0
- package/dist/collection/components/store/translationStore/strings.turkish.js +48 -0
- package/dist/collection/components/store/translationStore/strings.vietnamese.js +48 -0
- package/dist/collection/components/store/translationStore.js +2 -1
- package/dist/collection/components/stripe/zonos-address/zonos-address.js +35 -18
- package/dist/collection/components/stripe/zonos-custom-address/zonos-address-suggestions/zonos-address-suggestions.js +2 -2
- package/dist/collection/components/stripe/zonos-custom-address/zonos-custom-address.js +2 -2
- package/dist/collection/components/stripe/zonos-link-authentication/zonos-link-authentication.js +15 -2
- package/dist/collection/components/stripe/zonos-payment/zonos-payment.js +1 -1
- package/dist/collection/components/utils/checkout/initCollect.js +15 -0
- package/dist/collection/components/utils/checkout/isCollectMobileTablet.js +10 -0
- package/dist/collection/components/utils/checkout/renderCheckoutCurrency.js +10 -1
- package/dist/collection/components/utils/renderFallback.js +7 -0
- package/dist/collection/scripts/_getZonosQaUrl.js +5 -1
- package/dist/collection/scripts/_zonosBase.js +7 -1
- package/dist/collection/types/checkout/api/PartyInfo.js +1 -0
- package/dist/collection/types/generated/graphql.internal.types.js +103 -0
- package/dist/collection/types/index.js +1 -0
- package/dist/esm/buildCartItemsByTempCart-c4488f73.js +26 -0
- package/dist/esm/{cart-bb0ee971.js → cart-acf4ebf5.js} +68 -27
- package/dist/esm/cleanHtmlMarkdown-b5b18743.js +997 -0
- package/dist/esm/index.js +19 -9
- package/dist/esm/isCollectMobileTablet-b72b81c5.js +165 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/localization-8646f526.js +719 -0
- package/dist/esm/{paypal-bd4520eb.js → paypal-2fa930eb.js} +7 -4
- package/dist/esm/placeTestOrder-d1ad9cf6.js +90 -0
- package/dist/esm/{localization-d8326254.js → translationStore-c9743292.js} +963 -718
- package/dist/esm/zonos-address_11.entry.js +71 -41
- package/dist/esm/zonos-badge.entry.js +3 -3
- package/dist/esm/{zonos-banner.entry.js → zonos-banner_2.entry.js} +40 -1
- package/dist/esm/zonos-button_3.entry.js +3 -3
- package/dist/esm/{zonos-cart-items_14.entry.js → zonos-cart-items_12.entry.js} +23 -1240
- package/dist/esm/zonos-checkout.entry.js +6 -29
- package/dist/esm/zonos-collapse.entry.js +2 -2
- package/dist/esm/zonos-collect-cart-items_3.entry.js +86 -0
- package/dist/esm/zonos-collect-finish_6.entry.js +801 -0
- package/dist/esm/zonos-collect.entry.js +464 -0
- package/dist/esm/zonos-component.entry.js +1 -1
- package/dist/esm/zonos-confirm-dialog_2.entry.js +163 -0
- package/dist/esm/zonos-controller.entry.js +84 -28
- package/dist/esm/zonos-country-flag.entry.js +2 -1
- package/dist/esm/zonos-country-select_4.entry.js +11 -10
- package/dist/esm/zonos-elements.js +1 -1
- package/dist/esm/zonos-empty-state-payment_4.entry.js +15 -5
- package/dist/esm/zonos-hello-dialog.entry.js +6 -5
- package/dist/esm/zonos-hello.entry.js +2 -1
- package/dist/esm/zonos-input.entry.js +4 -4
- package/dist/esm/zonos-language-select_2.entry.js +6 -5
- package/dist/esm/zonos-link.entry.js +1 -1
- package/dist/esm/zonos-logo.entry.js +2 -2
- package/dist/esm/zonos-stripe-input.entry.js +9 -6
- package/dist/esm/zonos-text.entry.js +1 -1
- package/dist/esm/zonos-toggle.entry.js +2 -2
- package/dist/esm/zonos-tooltip.entry.js +2 -2
- package/dist/esm/zonos-v-stack.entry.js +2 -2
- package/dist/esm-es5/buildCartItemsByTempCart-c4488f73.js +1 -0
- package/dist/esm-es5/cart-acf4ebf5.js +1 -0
- package/dist/esm-es5/cleanHtmlMarkdown-b5b18743.js +1 -0
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/isCollectMobileTablet-b72b81c5.js +1 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/localization-8646f526.js +1 -0
- package/dist/esm-es5/paypal-2fa930eb.js +17 -0
- package/dist/esm-es5/placeTestOrder-d1ad9cf6.js +1 -0
- package/dist/esm-es5/translationStore-c9743292.js +1 -0
- package/dist/esm-es5/zonos-address_11.entry.js +1 -1
- package/dist/esm-es5/zonos-badge.entry.js +1 -1
- package/dist/esm-es5/zonos-banner_2.entry.js +1 -0
- package/dist/esm-es5/zonos-button_3.entry.js +1 -1
- package/dist/esm-es5/zonos-cart-items_12.entry.js +1 -0
- package/dist/esm-es5/zonos-checkout.entry.js +1 -1
- package/dist/esm-es5/zonos-collapse.entry.js +1 -1
- package/dist/esm-es5/zonos-collect-cart-items_3.entry.js +1 -0
- package/dist/esm-es5/zonos-collect-finish_6.entry.js +1 -0
- package/dist/esm-es5/zonos-collect.entry.js +1 -0
- package/dist/esm-es5/zonos-component.entry.js +1 -1
- package/dist/esm-es5/zonos-confirm-dialog_2.entry.js +1 -0
- 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-input.entry.js +1 -1
- package/dist/esm-es5/zonos-language-select_2.entry.js +1 -1
- package/dist/esm-es5/zonos-link.entry.js +1 -1
- package/dist/esm-es5/zonos-logo.entry.js +1 -1
- package/dist/esm-es5/zonos-stripe-input.entry.js +1 -1
- package/dist/esm-es5/zonos-text.entry.js +1 -1
- package/dist/esm-es5/zonos-toggle.entry.js +1 -1
- package/dist/esm-es5/zonos-tooltip.entry.js +1 -1
- package/dist/esm-es5/zonos-v-stack.entry.js +1 -1
- package/dist/scripts/index.d.ts +470 -3
- 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-collect/zonos-collect-cart-items/zonos-collect-cart-items.d.ts +4 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect-finish/zonos-collect-finish.d.ts +49 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect-footer/zonos-collect-footer.d.ts +25 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect-order-details/zonos-collect-order-details.d.ts +29 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect-payment/zonos-collect-payment.d.ts +62 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect-review/zonos-collect-review.d.ts +22 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect-subtotal/zonos-collect-subtotal.d.ts +10 -0
- package/dist/types/components/checkout/zonos-collect/zonos-collect.d.ts +86 -0
- package/dist/types/components/common/zonos-h-stack/zonos-h-stack.d.ts +9 -0
- package/dist/types/components/common/zonos-skeleton/zonos-skeleton.d.ts +17 -0
- package/dist/types/components/main/zonos-controller.d.ts +5 -0
- package/dist/types/components/paypal/zonos-paypal-payment.d.ts +3 -0
- package/dist/types/components/store/checkout/cart.d.ts +23 -3
- package/dist/types/components/store/checkout/collect.d.ts +21 -0
- package/dist/types/components/store/checkout/paypal.d.ts +4 -3
- package/dist/types/components/store/checkout/stripe.d.ts +6 -2
- package/dist/types/components/store/translationStore/strings.arabic.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.base.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.chinese.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.danish.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.dutch.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.french.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.german.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.hebrew.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.indonesian.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.italian.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.japanese.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.korean.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.norwegian.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.polish.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.portuguese.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.russian.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.spanish.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.swedish.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.turkish.d.ts +48 -0
- package/dist/types/components/store/translationStore/strings.vietnamese.d.ts +48 -0
- package/dist/types/components/store/translationStore.d.ts +2 -1
- package/dist/types/components/stripe/zonos-address/zonos-address.d.ts +1 -2
- package/dist/types/components/stripe/zonos-link-authentication/zonos-link-authentication.d.ts +2 -0
- package/dist/types/components/utils/api/getLocaleMessages.d.ts +1 -1
- package/dist/types/components/utils/checkout/initCollect.d.ts +1 -0
- package/dist/types/components/utils/checkout/isCollectMobileTablet.d.ts +4 -0
- package/dist/types/components/utils/renderFallback.d.ts +6 -0
- package/dist/types/components.d.ts +401 -2
- package/dist/types/scripts/_zonosBase.d.ts +5 -0
- package/dist/types/scripts/cart/_setupCartDataWithSettings.d.ts +5 -0
- package/dist/types/types/checkout/api/CheckoutSession.d.ts +9 -1
- package/dist/types/types/checkout/api/CreateParty.d.ts +24 -0
- package/dist/types/types/checkout/api/NormalizedTempCart.d.ts +6 -1
- package/dist/types/types/checkout/api/PartyInfo.d.ts +24 -0
- package/dist/types/types/generated/graphql.frontend.types.d.ts +1 -1
- package/dist/types/types/generated/graphql.frontend.types.ts +1 -1
- package/dist/types/types/generated/graphql.internal.types.d.ts +431 -9
- package/dist/types/types/generated/graphql.internal.types.ts +428 -10
- package/dist/types/types/index.d.ts +1 -0
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/{p-288761b1.system.entry.js → p-009c3ac5.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-c7d5d45d.entry.js → p-03980f76.entry.js} +1 -1
- package/dist/zonos-elements/p-07bea979.system.js +1 -0
- package/dist/zonos-elements/p-0cec2dd2.system.entry.js +1 -0
- package/dist/zonos-elements/p-0d6c6a38.entry.js +1 -0
- package/dist/zonos-elements/p-0ef2a242.js +1 -0
- package/dist/zonos-elements/p-106ae0f1.entry.js +1 -0
- package/dist/zonos-elements/p-10797d2b.system.entry.js +1 -0
- package/dist/zonos-elements/p-195b33b6.system.entry.js +1 -0
- package/dist/zonos-elements/p-1fe5d4da.system.entry.js +1 -0
- package/dist/zonos-elements/{p-da4c01da.system.entry.js → p-2323ff0f.system.entry.js} +1 -1
- package/dist/zonos-elements/p-23293a0b.entry.js +1 -0
- package/dist/zonos-elements/{p-62813488.entry.js → p-23735db6.entry.js} +1 -1
- package/dist/zonos-elements/{p-ebaaaee9.entry.js → p-26573347.entry.js} +1 -1
- package/dist/zonos-elements/{p-e640e8b8.entry.js → p-29499a5f.entry.js} +1 -1
- package/dist/zonos-elements/p-29c80a34.js +1 -0
- package/dist/zonos-elements/{p-edc77ea1.entry.js → p-2a9681b4.entry.js} +1 -1
- package/dist/zonos-elements/{p-3f31901f.entry.js → p-2c9381be.entry.js} +1 -1
- package/dist/zonos-elements/p-2cc031b3.js +17 -0
- package/dist/zonos-elements/{p-7ab62a26.system.entry.js → p-34a37ce7.system.entry.js} +1 -1
- package/dist/zonos-elements/p-3c9714a8.system.entry.js +1 -0
- package/dist/zonos-elements/p-485416ec.js +1 -0
- package/dist/zonos-elements/p-56ee6d4b.system.entry.js +1 -0
- package/dist/zonos-elements/p-58afbe2b.entry.js +1 -0
- package/dist/zonos-elements/p-5e372fb9.entry.js +1 -0
- package/dist/zonos-elements/p-5ff4f9df.system.js +1 -0
- package/dist/zonos-elements/{p-92cc26b7.system.entry.js → p-60c61982.system.entry.js} +1 -1
- package/dist/zonos-elements/p-61c2c336.entry.js +1 -0
- package/dist/zonos-elements/p-6696617a.system.entry.js +1 -0
- package/dist/zonos-elements/p-6761091e.entry.js +1 -0
- package/dist/zonos-elements/p-6761286d.js +1 -0
- package/dist/zonos-elements/p-69451a50.system.js +1 -0
- package/dist/zonos-elements/p-69fd1b88.js +1 -0
- package/dist/zonos-elements/p-6dd63754.system.js +1 -0
- package/dist/zonos-elements/p-6e8aae27.system.entry.js +1 -0
- package/dist/zonos-elements/{p-1c45cd15.entry.js → p-70b81bbc.entry.js} +1 -1
- package/dist/zonos-elements/{p-eeb01de6.system.entry.js → p-750b7f32.system.entry.js} +1 -1
- package/dist/zonos-elements/p-772ac0b7.js +1 -0
- package/dist/zonos-elements/p-81b357f7.system.js +1 -1
- package/dist/zonos-elements/p-81e23f30.system.js +1 -0
- package/dist/zonos-elements/p-873b698a.entry.js +1 -0
- package/dist/zonos-elements/p-87e2a777.entry.js +1 -0
- package/dist/zonos-elements/p-8ca25e6c.entry.js +1 -0
- package/dist/zonos-elements/p-909d36bf.entry.js +1 -0
- package/dist/zonos-elements/p-95461a1b.system.entry.js +1 -0
- package/dist/zonos-elements/p-986ebccc.js +1 -0
- package/dist/zonos-elements/p-9c0b78bf.system.entry.js +1 -0
- package/dist/zonos-elements/p-a61a9b65.system.entry.js +1 -0
- package/dist/zonos-elements/p-a7204d41.entry.js +1 -0
- package/dist/zonos-elements/p-aca272ea.entry.js +1 -0
- package/dist/zonos-elements/p-b12ec9f2.system.entry.js +1 -0
- package/dist/zonos-elements/p-b1bd9fe7.system.entry.js +1 -0
- package/dist/zonos-elements/p-b2ae8eb7.system.js +1 -0
- package/dist/zonos-elements/{p-77666360.entry.js → p-b5406d26.entry.js} +1 -1
- package/dist/zonos-elements/p-bfbc081f.entry.js +1 -0
- package/dist/zonos-elements/p-c0a54cf6.system.js +1 -0
- package/dist/zonos-elements/p-c3c9b089.entry.js +1 -0
- package/dist/zonos-elements/p-c8784a01.system.entry.js +1 -0
- package/dist/zonos-elements/{p-7b5de646.entry.js → p-d045e2e5.entry.js} +1 -1
- package/dist/zonos-elements/p-d26cffba.entry.js +1 -0
- package/dist/zonos-elements/{p-544c173a.system.entry.js → p-d351ece6.system.entry.js} +1 -1
- package/dist/zonos-elements/p-d63696ac.system.js +17 -0
- package/dist/zonos-elements/p-ddb29c2a.system.entry.js +1 -0
- package/dist/zonos-elements/{p-d6fa2dc2.entry.js → p-dfb92907.entry.js} +1 -1
- package/dist/zonos-elements/{p-714c28b1.system.entry.js → p-e2a45188.system.entry.js} +1 -1
- package/dist/zonos-elements/{p-1ac8bfbb.system.entry.js → p-e455f060.system.entry.js} +1 -1
- package/dist/zonos-elements/p-eb54ece4.system.entry.js +1 -0
- package/dist/zonos-elements/{p-a98b1e8d.entry.js → p-efa6203f.entry.js} +1 -1
- package/dist/zonos-elements/{p-59eaebe3.system.entry.js → p-f0be0ca9.system.entry.js} +1 -1
- package/dist/zonos-elements/p-f129a83b.system.entry.js +1 -0
- package/dist/zonos-elements/p-f17fde5f.system.js +1 -0
- package/dist/zonos-elements/{p-47ffacd8.system.entry.js → p-f74a6b78.system.entry.js} +1 -1
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/zonos-card.cjs.entry.js +0 -49
- package/dist/esm/zonos-card.entry.js +0 -45
- package/dist/esm-es5/cart-bb0ee971.js +0 -1
- package/dist/esm-es5/localization-d8326254.js +0 -1
- package/dist/esm-es5/paypal-bd4520eb.js +0 -17
- package/dist/esm-es5/zonos-banner.entry.js +0 -1
- package/dist/esm-es5/zonos-card.entry.js +0 -1
- package/dist/esm-es5/zonos-cart-items_14.entry.js +0 -1
- package/dist/zonos-elements/p-043f57e8.system.entry.js +0 -1
- package/dist/zonos-elements/p-0631d2b9.js +0 -1
- package/dist/zonos-elements/p-0a6ac265.system.js +0 -1
- package/dist/zonos-elements/p-0f041dc5.system.entry.js +0 -1
- package/dist/zonos-elements/p-1432a217.system.entry.js +0 -1
- package/dist/zonos-elements/p-1b51b738.system.entry.js +0 -1
- package/dist/zonos-elements/p-3a1513ae.system.entry.js +0 -1
- package/dist/zonos-elements/p-3b8d11dd.entry.js +0 -1
- package/dist/zonos-elements/p-4333afcb.entry.js +0 -1
- package/dist/zonos-elements/p-4d0d89da.system.entry.js +0 -1
- package/dist/zonos-elements/p-5dd9cb44.system.entry.js +0 -1
- package/dist/zonos-elements/p-605a21ac.entry.js +0 -1
- package/dist/zonos-elements/p-674981ad.system.js +0 -1
- package/dist/zonos-elements/p-6d090b53.entry.js +0 -1
- package/dist/zonos-elements/p-73c8c551.system.entry.js +0 -1
- package/dist/zonos-elements/p-795d223d.entry.js +0 -1
- package/dist/zonos-elements/p-8218ff62.system.entry.js +0 -1
- package/dist/zonos-elements/p-82f80c8a.entry.js +0 -1
- package/dist/zonos-elements/p-88f7256d.js +0 -1
- package/dist/zonos-elements/p-8b083884.entry.js +0 -1
- package/dist/zonos-elements/p-a449940d.entry.js +0 -1
- package/dist/zonos-elements/p-a5a4ad2f.entry.js +0 -1
- package/dist/zonos-elements/p-a5d45585.system.entry.js +0 -1
- package/dist/zonos-elements/p-a751e819.system.entry.js +0 -1
- package/dist/zonos-elements/p-ad556be6.entry.js +0 -1
- package/dist/zonos-elements/p-b4792af0.entry.js +0 -1
- package/dist/zonos-elements/p-b9ff6458.entry.js +0 -1
- package/dist/zonos-elements/p-d3dbae8c.system.js +0 -1
- package/dist/zonos-elements/p-d55aec11.system.entry.js +0 -1
- package/dist/zonos-elements/p-ebb9b902.system.js +0 -17
- package/dist/zonos-elements/p-ef1ce617.system.entry.js +0 -1
- package/dist/zonos-elements/p-ef75da6f.js +0 -17
- package/dist/zonos-elements/p-f3dbe934.entry.js +0 -1
- package/dist/zonos-elements/p-f741407e.system.entry.js +0 -1
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const zonosStore = require('./zonosStore-f8ee56aa.js');
|
|
4
|
+
const handleFetch = require('./handleFetch-45f35cac.js');
|
|
5
|
+
const VarianceTest = require('./VarianceTest-0cb1e118.js');
|
|
6
|
+
const translationStore = require('./translationStore-20a6d8bf.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if the response contains at least one available test key that we support
|
|
10
|
+
*/
|
|
11
|
+
const hasAtLeastOneAvailableTestKey = (rawResponse) => {
|
|
12
|
+
const hasAvailableTestKey = !!rawResponse.find(item => item.testKey in VarianceTest.availableTestKeys);
|
|
13
|
+
if (!hasAvailableTestKey) {
|
|
14
|
+
handleFetch.log('No available test key found in response', 'info', {
|
|
15
|
+
response: rawResponse,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return !!rawResponse.find(item => item.testKey in VarianceTest.availableTestKeys);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Filter the response to only include test keys and variants key that we support
|
|
23
|
+
*/
|
|
24
|
+
const filterValidTests = (testKeys) => {
|
|
25
|
+
// Type guard the response to ensure it matches the expected structure
|
|
26
|
+
if (!hasAtLeastOneAvailableTestKey(testKeys)) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
// Filter the response to only include test keys that we support
|
|
30
|
+
return testKeys
|
|
31
|
+
.filter(item => {
|
|
32
|
+
var _a;
|
|
33
|
+
const isTestKeyValidButNoSelectedVariantKey = VarianceTest.availableTestKeys[item.testKey] && !item.selectedVariantKey;
|
|
34
|
+
const validTestKeyWithSelectedVariantKey = item.selectedVariantKey &&
|
|
35
|
+
!!((_a = VarianceTest.availableTestKeys[item.testKey]) === null || _a === void 0 ? void 0 : _a['availableVariants'].includes(item.selectedVariantKey));
|
|
36
|
+
return (isTestKeyValidButNoSelectedVariantKey ||
|
|
37
|
+
validTestKeyWithSelectedVariantKey);
|
|
38
|
+
})
|
|
39
|
+
.map(item => (Object.assign(Object.assign({}, item), { expiresAt: item.expiresAt || Date.now() + VARIANT_TEST_KEY_EXPIRATION, selectedVariantKey: item.selectedVariantKey || null })));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Expiration time for variant test keys in milliseconds
|
|
44
|
+
* @default 1 day
|
|
45
|
+
*/
|
|
46
|
+
const VARIANT_TEST_KEY_EXPIRATION = 60 * 60 * 24 * 1000;
|
|
47
|
+
const { onChange: storageStoreOnChange, state: storageStore } = zonosStore.createStore({
|
|
48
|
+
checkoutSessionId: sessionStorage.getItem('zonos--checkout-session-id'),
|
|
49
|
+
enabledVariantTestKeys: handleFetch.jsonParse(localStorage.getItem('zonos--enabled-variant-test-keys')),
|
|
50
|
+
});
|
|
51
|
+
storageStoreOnChange('enabledVariantTestKeys', () => {
|
|
52
|
+
var _a;
|
|
53
|
+
// This should be set in localStorage so we don't have multiple tests for the same user in short period of time
|
|
54
|
+
if (!((_a = storageStore.enabledVariantTestKeys) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
55
|
+
localStorage.removeItem('zonos--enabled-variant-test-keys');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
localStorage.setItem('zonos--enabled-variant-test-keys', JSON.stringify(storageStore.enabledVariantTestKeys));
|
|
59
|
+
});
|
|
60
|
+
storageStoreOnChange('checkoutSessionId', () => {
|
|
61
|
+
if (!storageStore.checkoutSessionId) {
|
|
62
|
+
sessionStorage.removeItem('zonos--checkout-session-id');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
sessionStorage.setItem('zonos--checkout-session-id', storageStore.checkoutSessionId);
|
|
66
|
+
});
|
|
67
|
+
const storageStoreSetEnabledVariantTestKeys = (testKeys) => {
|
|
68
|
+
storageStore.enabledVariantTestKeys = filterValidTests(testKeys);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getCountries = async () => {
|
|
72
|
+
try {
|
|
73
|
+
const { errors, json } = await handleFetch.handleFetch('/api/zonos-elements/get-countries', {
|
|
74
|
+
method: 'GET',
|
|
75
|
+
});
|
|
76
|
+
if (errors.length || !json) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return json;
|
|
80
|
+
}
|
|
81
|
+
catch (_a) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const getCountryLandedCost = async (countryCode) => {
|
|
87
|
+
var _a;
|
|
88
|
+
if (!countryCode) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const url = `/api/zonos-elements/country-landed-cost/${countryCode}`;
|
|
92
|
+
const { errors, json } = await handleFetch.handleFetch(url);
|
|
93
|
+
if (errors.length || !json) {
|
|
94
|
+
handleFetch.logError(`Error fetching country landed cost: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return json || null;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const defaultUsExchangeRate = {
|
|
101
|
+
exchangeRate: {
|
|
102
|
+
rate: 1,
|
|
103
|
+
targetFormat: {
|
|
104
|
+
currencyCode: 'USD',
|
|
105
|
+
decimalDelimiter: '.',
|
|
106
|
+
scale: 2,
|
|
107
|
+
symbol: '$',
|
|
108
|
+
symbolLocation: 'before',
|
|
109
|
+
thousandsDelimiter: ',',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
maxAge: null,
|
|
113
|
+
};
|
|
114
|
+
const getExchangeRate = async ({ country, isGuaranteed, sourceCurrency, targetCurrency, }) => {
|
|
115
|
+
var _a;
|
|
116
|
+
// If source currency matches target currency (US -> US) and is not a guaranteed rate, return default exchange rate so we still format properly.
|
|
117
|
+
if (sourceCurrency === targetCurrency && !isGuaranteed) {
|
|
118
|
+
return defaultUsExchangeRate;
|
|
119
|
+
}
|
|
120
|
+
const searchParams = new URLSearchParams();
|
|
121
|
+
searchParams.set('sourceCurrency', sourceCurrency);
|
|
122
|
+
searchParams.set('targetCurrency', targetCurrency);
|
|
123
|
+
searchParams.set('isGuaranteed', String(isGuaranteed));
|
|
124
|
+
searchParams.set('country', country || '');
|
|
125
|
+
const { errors, json } = await handleFetch.handleFetch(`/api/zonos-elements/exchange-rates?${searchParams.toString()}`);
|
|
126
|
+
if (errors.length || !json) {
|
|
127
|
+
handleFetch.logError(`Error fetching country landed cost: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
128
|
+
return defaultUsExchangeRate;
|
|
129
|
+
}
|
|
130
|
+
const { rate, targetFormat } = json.exchangeRateCreate;
|
|
131
|
+
const maxAge = json.maxAge;
|
|
132
|
+
if (rate) {
|
|
133
|
+
sessionStorage.setItem(country + '_rate', JSON.stringify(rate));
|
|
134
|
+
const exchangeRate = { rate, targetFormat };
|
|
135
|
+
return { exchangeRate, maxAge };
|
|
136
|
+
}
|
|
137
|
+
return defaultUsExchangeRate;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const getInclusivePricing = async (countryCode) => {
|
|
141
|
+
var _a;
|
|
142
|
+
if (!countryCode) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
const { errors, json } = await handleFetch.handleFetch(`/api/zonos-elements/inclusive-prices/${countryCode}`);
|
|
146
|
+
if (errors.length || !json) {
|
|
147
|
+
handleFetch.logError(`Error fetching country inclusive price setting: ${(_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message}`);
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return json || null;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const getLocaleMessages = async ({ countryCode, localeTo, storeId, }) => {
|
|
154
|
+
var _a;
|
|
155
|
+
const searchParams = new URLSearchParams();
|
|
156
|
+
searchParams.set('countryCode', countryCode);
|
|
157
|
+
searchParams.set('storeId', storeId.toString());
|
|
158
|
+
if (localeTo) {
|
|
159
|
+
searchParams.set('localeTo', localeTo);
|
|
160
|
+
}
|
|
161
|
+
const { errors, json } = await handleFetch.handleFetch(`/api/zonos-elements/locale-messages?${searchParams.toString()}`);
|
|
162
|
+
if (errors.length || !json) {
|
|
163
|
+
handleFetch.logError('Error fetching exchange rate', (_a = errors.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message);
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
return json.locale_countryCodesPage;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const validateCountryCode = (countryCode) => {
|
|
170
|
+
// Check that the country is two characters and is upper case
|
|
171
|
+
if (countryCode && /^[A-Z]{2}$/.test(countryCode)) {
|
|
172
|
+
return countryCode;
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
};
|
|
176
|
+
const getZCountryUrlParam = (urlParams) => {
|
|
177
|
+
const urlSearchParams = new URLSearchParams(urlParams || window.location.search);
|
|
178
|
+
const getCountryParam = (param) => {
|
|
179
|
+
const country = urlSearchParams.get(param);
|
|
180
|
+
// Check that the country is two characters and is upper case
|
|
181
|
+
return validateCountryCode(country);
|
|
182
|
+
};
|
|
183
|
+
const zCountry = getCountryParam('zCountry');
|
|
184
|
+
// Fallback to legacy 'country'
|
|
185
|
+
const fallback = getCountryParam('country');
|
|
186
|
+
// Fallback to customerCountry
|
|
187
|
+
const secondFallback = getCountryParam('customerCountry');
|
|
188
|
+
return zCountry || fallback || secondFallback;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const getLocalization = async () => {
|
|
192
|
+
try {
|
|
193
|
+
const currentUrl = new URL(window.location.href);
|
|
194
|
+
// load and use country from session storage when zCountry query param is not present
|
|
195
|
+
const countryLoadedSession = window.sessionStorage.getItem('zonos--country');
|
|
196
|
+
const zCountry = getZCountryUrlParam(currentUrl.searchParams) || countryLoadedSession;
|
|
197
|
+
const searchParams = new URLSearchParams();
|
|
198
|
+
if (zCountry) {
|
|
199
|
+
searchParams.set('zCountry', zCountry);
|
|
200
|
+
}
|
|
201
|
+
const { errors, json } = await handleFetch.handleFetch(`/api/zonos-elements/localization?${searchParams.toString()}`);
|
|
202
|
+
if (errors.length || !json) {
|
|
203
|
+
return { country: null, locale: null };
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
country: json.country,
|
|
207
|
+
locale: json.locale,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
catch (_a) {
|
|
211
|
+
return { country: null, locale: null };
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const getShippingZones = async () => {
|
|
216
|
+
var _a, _b, _c;
|
|
217
|
+
if ((_a = window.Zonos.cartSettings) === null || _a === void 0 ? void 0 : _a.shippingZones) {
|
|
218
|
+
return window.Zonos.cartSettings.shippingZones
|
|
219
|
+
.flatMap(zone => zone === null || zone === void 0 ? void 0 : zone.countryCodes)
|
|
220
|
+
.filter(Boolean);
|
|
221
|
+
}
|
|
222
|
+
const { errors, json } = await handleFetch.handleFetch('/api/zonos-elements/shipping-zones');
|
|
223
|
+
if (errors.length || !json) {
|
|
224
|
+
handleFetch.logError(`Error fetching shipping zones: ${(_b = errors.find(Boolean)) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
const shippingZones = (_c = json === null || json === void 0 ? void 0 : json.shippingZones) === null || _c === void 0 ? void 0 : _c.flatMap(zone => zone === null || zone === void 0 ? void 0 : zone.countryCodes).filter(Boolean);
|
|
228
|
+
return shippingZones || null;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const currencyConvert = (value) => {
|
|
232
|
+
// TODO(potentially): Bring over the code for vanity checks
|
|
233
|
+
const { exchangeRate } = localizationStore;
|
|
234
|
+
if (!exchangeRate || !value || isNaN(value)) {
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
const minimumFractionDigits = (exchangeRate === null || exchangeRate === void 0 ? void 0 : exchangeRate.targetFormat.scale) || 2;
|
|
238
|
+
const convertedValue = value * exchangeRate.rate;
|
|
239
|
+
const fixedValue = convertedValue.toFixed(minimumFractionDigits);
|
|
240
|
+
return Number(fixedValue);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* This function only to format the number in
|
|
245
|
+
* @returns
|
|
246
|
+
*/
|
|
247
|
+
const numberFormat = ({ amount, currency, targetFormat, }) => {
|
|
248
|
+
const targetCurrency = currency || localizationStore.targetCurrency;
|
|
249
|
+
const minimumFractionDigits = (targetFormat === null || targetFormat === void 0 ? void 0 : targetFormat.scale) || 2;
|
|
250
|
+
const isIE = window.navigator.userAgent.indexOf('MSIE ') !== -1;
|
|
251
|
+
const numberFormatExists = typeof Intl === 'object' && Intl && typeof Intl.NumberFormat === 'function';
|
|
252
|
+
if (isIE || !numberFormatExists) {
|
|
253
|
+
// use native number formatting if it's IE.
|
|
254
|
+
const formattedNumber = Number(amount)
|
|
255
|
+
.toFixed(minimumFractionDigits)
|
|
256
|
+
.replace('.', '|dec|')
|
|
257
|
+
.replace(',', (targetFormat === null || targetFormat === void 0 ? void 0 : targetFormat.thousandsDelimiter) || '')
|
|
258
|
+
.replace('|dec|', (targetFormat === null || targetFormat === void 0 ? void 0 : targetFormat.decimalDelimiter) || '');
|
|
259
|
+
return formattedNumber;
|
|
260
|
+
}
|
|
261
|
+
const formatedNumber = new Intl.NumberFormat(window.navigator.language, {
|
|
262
|
+
currency: targetCurrency,
|
|
263
|
+
currencyDisplay: 'code',
|
|
264
|
+
minimumFractionDigits: minimumFractionDigits,
|
|
265
|
+
style: 'currency',
|
|
266
|
+
}).format(amount);
|
|
267
|
+
return formatedNumber.replace(new RegExp(`${targetCurrency}\\s+`), '');
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const currencyFormat = ({ amount, currency, }) => {
|
|
271
|
+
if (isNaN(amount) || (amount !== 0 && !amount)) {
|
|
272
|
+
return '';
|
|
273
|
+
}
|
|
274
|
+
const overrideCurrencyFormat = zonosStore.zonosStore.overrideCurrencyFormat;
|
|
275
|
+
const { exchangeRate } = localizationStore;
|
|
276
|
+
const targetCurrency = currency || localizationStore.targetCurrency;
|
|
277
|
+
// Use user-defined currency format
|
|
278
|
+
if (typeof overrideCurrencyFormat === 'function') {
|
|
279
|
+
return overrideCurrencyFormat({
|
|
280
|
+
amount: amount,
|
|
281
|
+
currencyCode: targetCurrency,
|
|
282
|
+
numberFormat: ({ amount: _amount }) => numberFormat({
|
|
283
|
+
amount: _amount,
|
|
284
|
+
currency: targetCurrency,
|
|
285
|
+
targetFormat: (exchangeRate === null || exchangeRate === void 0 ? void 0 : exchangeRate.targetFormat) || null,
|
|
286
|
+
}),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
const { targetFormat } = exchangeRate || {};
|
|
290
|
+
if (!targetFormat || !exchangeRate) {
|
|
291
|
+
// Return the amount as a string if no exchange rate is available
|
|
292
|
+
return `${amount.toFixed(2)} ${targetCurrency}`;
|
|
293
|
+
}
|
|
294
|
+
const minimumFractionDigits = targetFormat.scale || 2;
|
|
295
|
+
const isIE = window.navigator.userAgent.indexOf('MSIE ') !== -1;
|
|
296
|
+
const numberFormatExists = typeof Intl === 'object' && Intl && typeof Intl.NumberFormat === 'function';
|
|
297
|
+
if (isIE || !numberFormatExists) {
|
|
298
|
+
// use native number formatting if it's IE.
|
|
299
|
+
const formattedNumber = Number(amount)
|
|
300
|
+
.toFixed(minimumFractionDigits)
|
|
301
|
+
.replace('.', '|dec|')
|
|
302
|
+
.replace(',', targetFormat.thousandsDelimiter || '')
|
|
303
|
+
.replace('|dec|', targetFormat.decimalDelimiter || '');
|
|
304
|
+
const result = `${formattedNumber}${targetFormat.currencyCode !== 'USD' ? ` ${targetFormat.currencyCode}` : ''}`;
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
const currencyDisplay = (overrideCurrencyFormat === null || overrideCurrencyFormat === void 0 ? void 0 : overrideCurrencyFormat.currencyDisplay) || 'symbol';
|
|
308
|
+
const formattedNumber = new Intl.NumberFormat(window.navigator.language, {
|
|
309
|
+
currency: targetCurrency,
|
|
310
|
+
currencyDisplay,
|
|
311
|
+
minimumFractionDigits: minimumFractionDigits,
|
|
312
|
+
style: 'currency',
|
|
313
|
+
}).format(amount);
|
|
314
|
+
// Move currency code to the end of the string if currencyDisplay is 'code'
|
|
315
|
+
const result = currencyDisplay === 'code'
|
|
316
|
+
? `${formattedNumber.replace(new RegExp(`${targetCurrency}\\s+`), '')} ${targetCurrency}`
|
|
317
|
+
: formattedNumber;
|
|
318
|
+
return result;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const currencyConvertAndFormat = (value) => {
|
|
322
|
+
const convertedValue = currencyConvert(value);
|
|
323
|
+
const formattedValue = currencyFormat({ amount: convertedValue });
|
|
324
|
+
return formattedValue;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Check if selector user pass is valid
|
|
329
|
+
* @example
|
|
330
|
+
* isValidSelector('div') // true
|
|
331
|
+
* isValidSelector('div + >>> span') // false
|
|
332
|
+
*/
|
|
333
|
+
const isValidSelector = (selector) => {
|
|
334
|
+
try {
|
|
335
|
+
// this will error out if the selector is invalid in the DOM
|
|
336
|
+
document.createDocumentFragment().querySelector(selector);
|
|
337
|
+
}
|
|
338
|
+
catch (_a) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
return true;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const getCurrencyElements = (selector) => {
|
|
345
|
+
const currencySelector = selector || '.money';
|
|
346
|
+
if (!isValidSelector(currencySelector)) {
|
|
347
|
+
handleFetch.logError(`Currency element selector "${currencySelector}" is not valid.`);
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
const currencyElements = document.querySelectorAll(currencySelector);
|
|
351
|
+
if (!currencyElements.length) {
|
|
352
|
+
handleFetch.log(`No currency elements found with selector "${currencySelector}"`, 'warn');
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
// return array of currency elements instead of a NodeList
|
|
356
|
+
return Array.from(currencyElements);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const getInitialElementAmount = (element) => {
|
|
360
|
+
var _a;
|
|
361
|
+
const domesticValue = element.getAttribute('data-domestic');
|
|
362
|
+
const intlValue = element.getAttribute('data-zintl');
|
|
363
|
+
// Only keep numbers, decimal, and hyphens
|
|
364
|
+
const cleanedText = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.replace(/[^\d.-]/g, '');
|
|
365
|
+
if (!cleanedText) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
// If the element has no data-domestic attribute, or the text content is different from the data-zintl attribute, set the data-domestic attribute
|
|
369
|
+
if (!domesticValue || (element.textContent !== intlValue && intlValue)) {
|
|
370
|
+
// Store the original value on the element once, and international on every new conversion
|
|
371
|
+
element.setAttribute('data-domestic', cleanedText);
|
|
372
|
+
return parseFloat(cleanedText);
|
|
373
|
+
}
|
|
374
|
+
return parseFloat(domesticValue);
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const convertCurrency = (element) => {
|
|
378
|
+
var _a;
|
|
379
|
+
const amount = getInitialElementAmount(element);
|
|
380
|
+
if (!amount || isNaN(amount)) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const currentIntlValue = element.getAttribute('data-zintl');
|
|
384
|
+
// get rate
|
|
385
|
+
const currentIntlRateValue = parseFloat(element.getAttribute('data-zrate') || '1');
|
|
386
|
+
const currentCountryValue = element.getAttribute('data-zcountry-code');
|
|
387
|
+
// do nothing if the target currency is the same
|
|
388
|
+
const isExchangeRateReady = localizationStore.exchangeRate &&
|
|
389
|
+
localizationStore.targetCurrency ===
|
|
390
|
+
localizationStore.exchangeRate.targetFormat.currencyCode;
|
|
391
|
+
const rate = ((_a = localizationStore.exchangeRate) === null || _a === void 0 ? void 0 : _a.rate) || 1;
|
|
392
|
+
// if the current value on the element is different from the current intl value, update the data-zintl attribute
|
|
393
|
+
if (isExchangeRateReady &&
|
|
394
|
+
// Update currency if the value is not yet formatted
|
|
395
|
+
(element.textContent !== currentIntlValue ||
|
|
396
|
+
// Update rate when new rate is available
|
|
397
|
+
rate !== currentIntlRateValue ||
|
|
398
|
+
// Update currency when the country code changes
|
|
399
|
+
currentCountryValue !== localizationStore.selectedCountryCode)) {
|
|
400
|
+
const customizedCurrencyFormat = typeof zonosStore.zonosStore.currencyConverter === 'function' &&
|
|
401
|
+
zonosStore.zonosStore.currencyConverter({
|
|
402
|
+
convert: currencyConvert,
|
|
403
|
+
convertAndFormat: currencyConvertAndFormat,
|
|
404
|
+
currencyCode: localizationStore.targetCurrency,
|
|
405
|
+
format: (value) => currencyFormat({ amount: value }),
|
|
406
|
+
originalAmount: amount,
|
|
407
|
+
selector: element,
|
|
408
|
+
});
|
|
409
|
+
// default to the currencyConvertAndFormat if the currencyConverter function does not return a value, or invalid value. This is to make sure we don't break the merchant's price.
|
|
410
|
+
const observedFormattedValue = customizedCurrencyFormat || currencyConvertAndFormat(amount);
|
|
411
|
+
if (observedFormattedValue !== element.textContent) {
|
|
412
|
+
// Only set textContent if the value has changed, this is to prevent it redrawing the element if the value is the same
|
|
413
|
+
element.textContent = observedFormattedValue;
|
|
414
|
+
}
|
|
415
|
+
// save the new rate to the data-zrate attribute
|
|
416
|
+
element.setAttribute('data-zrate', rate.toString());
|
|
417
|
+
// save the new value to the data-zintl attribute
|
|
418
|
+
element.setAttribute('data-zintl', observedFormattedValue);
|
|
419
|
+
element.setAttribute('data-zcountry-code', localizationStore.selectedCountryCode || '');
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
const defaultCurrencyConverter = () => {
|
|
423
|
+
const { currencyElementSelector } = zonosStore.zonosStore.helloSettings;
|
|
424
|
+
const currencyElements = getCurrencyElements(currencyElementSelector);
|
|
425
|
+
// do nothing if none of the currency elements are found
|
|
426
|
+
if (!(currencyElements === null || currencyElements === void 0 ? void 0 : currencyElements.length)) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (!localizationStore.exchangeRate) {
|
|
430
|
+
handleFetch.logError('Could not display currency. Exchange rate and format data is not available.');
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
currencyElements.forEach(element => {
|
|
434
|
+
// convert the currency and save the formatted value to the data-zintl attribute
|
|
435
|
+
convertCurrency(element);
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const currencyDisplay = () => {
|
|
440
|
+
if (zonosStore.zonosStore.helloSettings.currencyBehavior === 'DISABLED' ||
|
|
441
|
+
window.Zonos.isLegacyCheckout) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
defaultCurrencyConverter();
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
const getCurrencyCode = (code) => {
|
|
448
|
+
var _a;
|
|
449
|
+
const countryInShippingZone = (_a = localizationStore.shippingZoneCountries) === null || _a === void 0 ? void 0 : _a[code];
|
|
450
|
+
if (countryInShippingZone) {
|
|
451
|
+
return countryInShippingZone.currencyCode;
|
|
452
|
+
}
|
|
453
|
+
return null;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const setZCountryUrlParam = (selectedCountryCode) => {
|
|
457
|
+
if (!selectedCountryCode) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
461
|
+
// Only append zCountry if it's already in the URL or the countryOverrideBehavior is URL_PARAM
|
|
462
|
+
const shouldAppendParam = urlSearchParams.has('zCountry') ||
|
|
463
|
+
zonosStore.zonosStore.helloSettings.countryOverrideBehavior === 'URL_PARAM';
|
|
464
|
+
if (shouldAppendParam) {
|
|
465
|
+
// Only append zCountry if it's not already in the URL
|
|
466
|
+
urlSearchParams.set('zCountry', selectedCountryCode);
|
|
467
|
+
const newUrl = `${window.location.pathname}?${urlSearchParams.toString()}`;
|
|
468
|
+
/**
|
|
469
|
+
* Setting the state to null in window.history.replaceState can cause issues with rendering when using next/link and pressing the back button.
|
|
470
|
+
* @ref https://github.com/vercel/next.js/issues/33233#issuecomment-1052349396
|
|
471
|
+
**/
|
|
472
|
+
window.history.replaceState(window.history.state, document.title, newUrl);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
const { dispose: localizationDispose, onChange: localizationStoreOnChange, state: localizationStore, } = zonosStore.createStore({
|
|
477
|
+
countryLandedCost: null,
|
|
478
|
+
customMessages: [],
|
|
479
|
+
exchangeRate: null,
|
|
480
|
+
helloCountryList: null,
|
|
481
|
+
inclusivePricing: null,
|
|
482
|
+
isDisabledCountry: true,
|
|
483
|
+
isShippableCountry: false,
|
|
484
|
+
localizationLoaded: false,
|
|
485
|
+
selectedCountryCode: null,
|
|
486
|
+
selectedLocale: 'en',
|
|
487
|
+
shippingZoneCountries: null,
|
|
488
|
+
targetCurrency: 'USD',
|
|
489
|
+
});
|
|
490
|
+
const triggerGetExchangeRate = async (isGuaranteed) => {
|
|
491
|
+
const { exchangeRate, maxAge } = await getExchangeRate({
|
|
492
|
+
country: localizationStore.selectedCountryCode,
|
|
493
|
+
isGuaranteed,
|
|
494
|
+
sourceCurrency: zonosStore.zonosStore.sourceCurrency,
|
|
495
|
+
targetCurrency: localizationStore.targetCurrency,
|
|
496
|
+
});
|
|
497
|
+
if (exchangeRate) {
|
|
498
|
+
localizationStore.exchangeRate = exchangeRate;
|
|
499
|
+
currencyDisplay();
|
|
500
|
+
}
|
|
501
|
+
return { maxAge };
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* CHORE: This is mostly for legacy checkout as the country param is not guaranteed.
|
|
505
|
+
*/
|
|
506
|
+
const DEFAULT_COUNTRY_CODE_LEGACY_CHECKOUT = 'CA';
|
|
507
|
+
const getFallbackDefaultCountryCode = (allowedCountries) => {
|
|
508
|
+
if (localizationStore.selectedCountryCode &&
|
|
509
|
+
allowedCountries.includes(localizationStore.selectedCountryCode)) {
|
|
510
|
+
return localizationStore.selectedCountryCode;
|
|
511
|
+
}
|
|
512
|
+
// Don't check if it is allowed. If it is not allowed it will fallback to Albania (first option).
|
|
513
|
+
return DEFAULT_COUNTRY_CODE_LEGACY_CHECKOUT;
|
|
514
|
+
};
|
|
515
|
+
// This recursive function is for users who step away from their computer and come back needing a new exchange rate
|
|
516
|
+
const startExchangeRateTimeout = ({ isGuaranteed, maxAge, }) => {
|
|
517
|
+
if (localizationStore.exchangeRateTimeout) {
|
|
518
|
+
clearTimeout(localizationStore.exchangeRateTimeout);
|
|
519
|
+
}
|
|
520
|
+
// maxAge comes in seconds, convert to milliseconds
|
|
521
|
+
const defaultMaxAge = 5 * 60;
|
|
522
|
+
const maxAgeToUse = maxAge || defaultMaxAge;
|
|
523
|
+
// Recursively set timeouts to get new exchange rates when the current one expires
|
|
524
|
+
localizationStore.exchangeRateTimeout = setTimeout(async () => {
|
|
525
|
+
const { maxAge: newMaxAge } = await triggerGetExchangeRate(isGuaranteed);
|
|
526
|
+
startExchangeRateTimeout({ isGuaranteed, maxAge: newMaxAge });
|
|
527
|
+
}, maxAgeToUse * 1000);
|
|
528
|
+
};
|
|
529
|
+
const getNewLocalization = async () => {
|
|
530
|
+
var _a;
|
|
531
|
+
handleFetch.log('get new localization store');
|
|
532
|
+
const { isDisabledCountry, isShippableCountry, selectedCountryCode } = localizationStore;
|
|
533
|
+
if (!window.Zonos.isLegacyCheckout) {
|
|
534
|
+
// These requests are only needed for Hello, so we can skip them for legacy checkout
|
|
535
|
+
localizationStore.countryLandedCost = await getCountryLandedCost(localizationStore.selectedCountryCode);
|
|
536
|
+
localizationStore.inclusivePricing =
|
|
537
|
+
((_a = (await getInclusivePricing(selectedCountryCode))) === null || _a === void 0 ? void 0 : _a.setting) || null;
|
|
538
|
+
if (localizationStore.inclusivePricing) {
|
|
539
|
+
handleFetch.log(`Inclusive price setting found for this country (${selectedCountryCode}) ${JSON.stringify(localizationStore.inclusivePricing, null, 2)}`);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
handleFetch.log('Skipping country landed cost and inclusive pricing requests, because this is a legacy checkout');
|
|
544
|
+
}
|
|
545
|
+
if (zonosStore.zonosStore.helloSettings.currencyBehavior === 'DISABLED' ||
|
|
546
|
+
!isShippableCountry ||
|
|
547
|
+
isDisabledCountry ||
|
|
548
|
+
!selectedCountryCode) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const isGuaranteed = zonosStore.zonosStore.checkoutSettings.visibilityStatus === 'ENABLED';
|
|
552
|
+
const { maxAge } = await triggerGetExchangeRate(isGuaranteed);
|
|
553
|
+
startExchangeRateTimeout({ isGuaranteed, maxAge });
|
|
554
|
+
};
|
|
555
|
+
const getCustomMessages = async () => {
|
|
556
|
+
handleFetch.log(`Getting custom messages for ${localizationStore.selectedCountryCode}`);
|
|
557
|
+
if (!localizationStore.selectedCountryCode || !zonosStore.zonosStore.storeId) {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const localeMessages = await getLocaleMessages({
|
|
561
|
+
countryCode: localizationStore.selectedCountryCode,
|
|
562
|
+
localeTo: localizationStore.selectedLocale,
|
|
563
|
+
storeId: zonosStore.zonosStore.storeId,
|
|
564
|
+
});
|
|
565
|
+
const allMessages = localeMessages.flatMap(x => {
|
|
566
|
+
var _a;
|
|
567
|
+
return {
|
|
568
|
+
countryCode: localizationStore.selectedCountryCode,
|
|
569
|
+
message: (_a = x.countryCodesPageMessageLinks.find(Boolean)) === null || _a === void 0 ? void 0 : _a.message.textTo,
|
|
570
|
+
pageName: x.pageName,
|
|
571
|
+
};
|
|
572
|
+
});
|
|
573
|
+
localizationStore.customMessages = allMessages;
|
|
574
|
+
};
|
|
575
|
+
const getOverrideLocale = () => {
|
|
576
|
+
const currentUrl = new URL(window.location.href);
|
|
577
|
+
const zonosLocale = currentUrl.searchParams.get('zonosLocale');
|
|
578
|
+
return zonosLocale;
|
|
579
|
+
};
|
|
580
|
+
const addInternationalHideClass = () => {
|
|
581
|
+
if (localizationStore.isShippableCountry) {
|
|
582
|
+
document.body.classList.add('z-intl');
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
document.body.classList.remove('z-intl');
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
const getValidCountryCode = (countryCode) => {
|
|
589
|
+
if (countryCode === 'UK') {
|
|
590
|
+
return 'GB';
|
|
591
|
+
}
|
|
592
|
+
return countryCode;
|
|
593
|
+
};
|
|
594
|
+
const localizationStoreUpdateSelectedCountryCode = (newSelectedCountryCode) => {
|
|
595
|
+
var _a, _b;
|
|
596
|
+
handleFetch.log(`Updating selected country code to ${newSelectedCountryCode}`);
|
|
597
|
+
const isFirstTime = !localizationStore.selectedCountryCode;
|
|
598
|
+
localizationStore.selectedCountryCode = getValidCountryCode(newSelectedCountryCode);
|
|
599
|
+
const { selectedCountryCode, shippingZoneCountries } = localizationStore;
|
|
600
|
+
const isShippableCountry = !!shippingZoneCountries &&
|
|
601
|
+
!!selectedCountryCode &&
|
|
602
|
+
!!shippingZoneCountries[selectedCountryCode] &&
|
|
603
|
+
// Make sure the country is not in the disabled countries list
|
|
604
|
+
!zonosStore.zonosStore.disabledCountries.includes(selectedCountryCode);
|
|
605
|
+
// update shippable country
|
|
606
|
+
localizationStore.isShippableCountry = isShippableCountry;
|
|
607
|
+
handleFetch.log(`${localizationStore.selectedCountryCode} is a shippable country: ${localizationStore.isShippableCountry}`);
|
|
608
|
+
const isDisabledCountry = !!selectedCountryCode &&
|
|
609
|
+
zonosStore.zonosStore.disabledCountries.includes(selectedCountryCode);
|
|
610
|
+
localizationStore.isDisabledCountry = isDisabledCountry;
|
|
611
|
+
handleFetch.log(`${localizationStore.selectedCountryCode} is a disabled country: ${localizationStore.isDisabledCountry}`);
|
|
612
|
+
addInternationalHideClass();
|
|
613
|
+
if (!selectedCountryCode) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const currencyCode = getCurrencyCode(selectedCountryCode);
|
|
617
|
+
// Only trigger callback onCountryChange if the country code has been set before
|
|
618
|
+
if (!isFirstTime) {
|
|
619
|
+
// Trigger callback onCountryChange
|
|
620
|
+
(_a = zonosStore.zonosStore.onCountryChange) === null || _a === void 0 ? void 0 : _a.call(zonosStore.zonosStore, {
|
|
621
|
+
countryCode: selectedCountryCode,
|
|
622
|
+
currencyCode,
|
|
623
|
+
isShippableCountry: isShippableCountry,
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
if (!currencyCode) {
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
localizationStore.targetCurrency = currencyCode;
|
|
630
|
+
void getNewLocalization();
|
|
631
|
+
// Save the country code to session storage for later use
|
|
632
|
+
window.sessionStorage.setItem('zonos--country', selectedCountryCode);
|
|
633
|
+
// Update the URL query param with the new country code
|
|
634
|
+
setZCountryUrlParam(selectedCountryCode);
|
|
635
|
+
(_b = document
|
|
636
|
+
.querySelector('zonos-hello')) === null || _b === void 0 ? void 0 : _b.setAttribute('z-country', selectedCountryCode);
|
|
637
|
+
};
|
|
638
|
+
const initHelloCountryList = (allCountries) => {
|
|
639
|
+
const showCountryList = zonosStore.zonosStore.helloSettings.showCountryList;
|
|
640
|
+
const hellCountryList = localizationStore.shippingZoneCountries;
|
|
641
|
+
if (!showCountryList || showCountryList === 'ONLY_SHIPPABLE') {
|
|
642
|
+
// just use the shipping zone countries
|
|
643
|
+
localizationStore.helloCountryList = hellCountryList;
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (showCountryList === 'ALL') {
|
|
647
|
+
localizationStore.helloCountryList = allCountries;
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
// get all active countries in the showCountryList
|
|
651
|
+
localizationStore.helloCountryList = showCountryList.reduce((acc, countryCode) => {
|
|
652
|
+
const countryInfo = allCountries === null || allCountries === void 0 ? void 0 : allCountries[countryCode];
|
|
653
|
+
return countryInfo
|
|
654
|
+
? Object.assign(Object.assign({}, acc), { [countryCode]: countryInfo }) : acc;
|
|
655
|
+
}, {});
|
|
656
|
+
};
|
|
657
|
+
const updateCheckoutSessionLanguage = async () => {
|
|
658
|
+
if (!storageStore.checkoutSessionId) {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
const { errors, json } = await handleFetch.handleFetch('/api/zonos-elements/update-checkout-session-metadata', {
|
|
662
|
+
body: {
|
|
663
|
+
id: storageStore.checkoutSessionId,
|
|
664
|
+
metadata: [
|
|
665
|
+
// This is being used from the backend to determine the language of the checkout session
|
|
666
|
+
{
|
|
667
|
+
key: 'language',
|
|
668
|
+
value: localizationStore.selectedLocale,
|
|
669
|
+
},
|
|
670
|
+
],
|
|
671
|
+
},
|
|
672
|
+
method: 'POST',
|
|
673
|
+
});
|
|
674
|
+
if (errors.length || !json) {
|
|
675
|
+
handleFetch.logError('Error occurs when updating checkout session', JSON.stringify(errors, null, 2));
|
|
676
|
+
return { errors, json };
|
|
677
|
+
}
|
|
678
|
+
return { errors: [], json };
|
|
679
|
+
};
|
|
680
|
+
const localizationStoreUpdateSelectedLocale = (newSelectedLocale) => {
|
|
681
|
+
localizationStore.selectedLocale = newSelectedLocale;
|
|
682
|
+
translationStore.translationStoreUpdateLanguage(newSelectedLocale);
|
|
683
|
+
void updateCheckoutSessionLanguage();
|
|
684
|
+
void getCustomMessages();
|
|
685
|
+
};
|
|
686
|
+
const initLocalizationStore = async () => {
|
|
687
|
+
// all countries from countries.json, shipping zone and localization
|
|
688
|
+
const [allCountries, shippingZoneCountries, localization] = await Promise.all([getCountries(), getShippingZones(), getLocalization()]);
|
|
689
|
+
// Filter countries to only include countries in the shipping zone
|
|
690
|
+
const filteredCountries = shippingZoneCountries === null || shippingZoneCountries === void 0 ? void 0 : shippingZoneCountries.reduce((acc, countryCode) => {
|
|
691
|
+
const countryInfo = allCountries === null || allCountries === void 0 ? void 0 : allCountries[countryCode];
|
|
692
|
+
return countryInfo
|
|
693
|
+
? Object.assign(Object.assign({}, acc), { [countryCode]: countryInfo }) : acc;
|
|
694
|
+
}, {});
|
|
695
|
+
localizationStore.shippingZoneCountries = filteredCountries || null;
|
|
696
|
+
// Initialize the country list for the hello widget
|
|
697
|
+
initHelloCountryList(allCountries || {});
|
|
698
|
+
const { country, locale } = localization;
|
|
699
|
+
handleFetch.log(`Country code from localization: ${country}`);
|
|
700
|
+
handleFetch.log(`Locale from localization: ${locale}`);
|
|
701
|
+
// update selected country code in store
|
|
702
|
+
localizationStoreUpdateSelectedCountryCode(country);
|
|
703
|
+
// use locale from params if it exists, otherwise use locale from localization
|
|
704
|
+
const overrideLocale = getOverrideLocale();
|
|
705
|
+
localizationStoreUpdateSelectedLocale(overrideLocale || locale || 'en');
|
|
706
|
+
const devSites = [
|
|
707
|
+
'dev.storybook.elements',
|
|
708
|
+
'dev.elements',
|
|
709
|
+
'dev.demo.elements',
|
|
710
|
+
'dev.dashboard',
|
|
711
|
+
];
|
|
712
|
+
// If the country code is not set, set it to the US for development (vercel can't get geo country in dev)
|
|
713
|
+
if (!localizationStore.selectedCountryCode &&
|
|
714
|
+
devSites.some(site => window.location.origin.includes(site))) {
|
|
715
|
+
// update selected country code in store
|
|
716
|
+
localizationStoreUpdateSelectedCountryCode('CA');
|
|
717
|
+
}
|
|
718
|
+
localizationStore.localizationLoaded = true;
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
exports.VARIANT_TEST_KEY_EXPIRATION = VARIANT_TEST_KEY_EXPIRATION;
|
|
722
|
+
exports.currencyConvert = currencyConvert;
|
|
723
|
+
exports.currencyConvertAndFormat = currencyConvertAndFormat;
|
|
724
|
+
exports.currencyDisplay = currencyDisplay;
|
|
725
|
+
exports.currencyFormat = currencyFormat;
|
|
726
|
+
exports.filterValidTests = filterValidTests;
|
|
727
|
+
exports.getFallbackDefaultCountryCode = getFallbackDefaultCountryCode;
|
|
728
|
+
exports.getZCountryUrlParam = getZCountryUrlParam;
|
|
729
|
+
exports.initLocalizationStore = initLocalizationStore;
|
|
730
|
+
exports.isValidSelector = isValidSelector;
|
|
731
|
+
exports.localizationStore = localizationStore;
|
|
732
|
+
exports.localizationStoreOnChange = localizationStoreOnChange;
|
|
733
|
+
exports.localizationStoreUpdateSelectedCountryCode = localizationStoreUpdateSelectedCountryCode;
|
|
734
|
+
exports.localizationStoreUpdateSelectedLocale = localizationStoreUpdateSelectedLocale;
|
|
735
|
+
exports.setZCountryUrlParam = setZCountryUrlParam;
|
|
736
|
+
exports.storageStore = storageStore;
|
|
737
|
+
exports.storageStoreOnChange = storageStoreOnChange;
|
|
738
|
+
exports.storageStoreSetEnabledVariantTestKeys = storageStoreSetEnabledVariantTestKeys;
|