@ubnt/store.core 9.17.0-alpha.4 → 9.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -154
- package/lib/_virtual/_virtual_multi-entry.js +12 -27
- package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
- package/lib/_virtual/_virtual_multi-entry.mjs +10 -14
- package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
- package/lib/apis/smartcat.js +1 -4
- package/lib/apis/smartcat.js.map +1 -1
- package/lib/apis/smartcat.mjs +1 -4
- package/lib/apis/smartcat.mjs.map +1 -1
- package/lib/{components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js → assets/icons/menu/icon-globe.svg.js} +6 -6
- package/lib/assets/icons/menu/icon-globe.svg.js.map +1 -0
- package/lib/assets/icons/menu/icon-globe.svg.mjs +3 -0
- package/lib/assets/icons/menu/icon-globe.svg.mjs.map +1 -0
- package/lib/components/CategoryTabs/CategoryTabs.styles.d.ts +1 -1
- package/lib/components/CategoryTabs/CategoryTabs.types.d.ts +1 -1
- package/lib/components/CloserLookSection/CloserLookSection.js.map +1 -1
- package/lib/components/CloserLookSection/CloserLookSection.mjs.map +1 -1
- package/lib/components/Compare/Compare.styles.d.ts +5 -5
- package/lib/components/Container/Container.d.ts +1 -1
- package/lib/components/Container/Container.js +3 -4
- package/lib/components/Container/Container.js.map +1 -1
- package/lib/components/Container/Container.mjs +4 -5
- package/lib/components/Container/Container.mjs.map +1 -1
- package/lib/components/CustomImage/CustomImage.js.map +1 -1
- package/lib/components/CustomImage/CustomImage.mjs.map +1 -1
- package/lib/components/FeaturesSection_deprecated/FeaturesSection.js.map +1 -1
- package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs.map +1 -1
- package/lib/components/Footer/hooks/useFooterContent.d.ts +3 -1
- package/lib/components/Footer/hooks/useFooterContent.js +8 -1
- package/lib/components/Footer/hooks/useFooterContent.js.map +1 -1
- package/lib/components/Footer/hooks/useFooterContent.mjs +8 -1
- package/lib/components/Footer/hooks/useFooterContent.mjs.map +1 -1
- package/lib/components/Footer/translations/ar.json.js +1 -1
- package/lib/components/Footer/translations/ar.json.mjs +1 -1
- package/lib/components/Footer/translations/de.json.js +1 -1
- package/lib/components/Footer/translations/de.json.mjs +1 -1
- package/lib/components/Footer/translations/el.json.js +1 -1
- package/lib/components/Footer/translations/el.json.mjs +1 -1
- package/lib/components/Footer/translations/en.json.js +1 -0
- package/lib/components/Footer/translations/en.json.js.map +1 -1
- package/lib/components/Footer/translations/en.json.mjs +1 -0
- package/lib/components/Footer/translations/en.json.mjs.map +1 -1
- package/lib/components/Footer/translations/es.json.js +1 -1
- package/lib/components/Footer/translations/es.json.mjs +1 -1
- package/lib/components/Footer/translations/fr.json.js +4 -4
- package/lib/components/Footer/translations/fr.json.mjs +4 -4
- package/lib/components/Footer/translations/it.json.js +1 -1
- package/lib/components/Footer/translations/it.json.mjs +1 -1
- package/lib/components/Footer/translations/ja.json.js +2 -2
- package/lib/components/Footer/translations/ja.json.mjs +2 -2
- package/lib/components/Footer/translations/pt-BR.json.js +1 -1
- package/lib/components/Footer/translations/pt-BR.json.mjs +1 -1
- package/lib/components/Footer/translations/zh-Hans.json.js +4 -4
- package/lib/components/Footer/translations/zh-Hans.json.mjs +4 -4
- package/lib/components/Footer/translations/zh-Hant-TW.json.js +1 -1
- package/lib/components/Footer/translations/zh-Hant-TW.json.mjs +1 -1
- package/lib/components/GridGallery/GridGallery.js.map +1 -1
- package/lib/components/GridGallery/GridGallery.mjs.map +1 -1
- package/lib/components/Header/AccountMenu/AccountMenu.js +12 -20
- package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
- package/lib/components/Header/AccountMenu/AccountMenu.mjs +14 -22
- package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
- package/lib/components/Header/AccountMenu/megaphone.http.service.js +1 -4
- package/lib/components/Header/AccountMenu/megaphone.http.service.js.map +1 -1
- package/lib/components/Header/AccountMenu/megaphone.http.service.mjs +1 -4
- package/lib/components/Header/AccountMenu/megaphone.http.service.mjs.map +1 -1
- package/lib/components/Header/CartModalV2/CartModal.js.map +1 -1
- package/lib/components/Header/CartModalV2/CartModal.mjs.map +1 -1
- package/lib/components/Header/Header.js.map +1 -1
- package/lib/components/Header/Header.mjs.map +1 -1
- package/lib/components/Header/Header.styles.d.ts +2 -2
- package/lib/components/Header/Header.types.d.ts +4 -8
- package/lib/components/Header/Header.types.js +1 -2
- package/lib/components/Header/Header.types.js.map +1 -1
- package/lib/components/Header/Header.types.mjs +1 -2
- package/lib/components/Header/Header.types.mjs.map +1 -1
- package/lib/components/Header/LanguageFrame/LanguageFrame.js.map +1 -1
- package/lib/components/Header/LanguageFrame/LanguageFrame.mjs.map +1 -1
- package/lib/components/Header/LanguageFrame/Mobile/Mobile.js.map +1 -1
- package/lib/components/Header/LanguageFrame/Mobile/Mobile.mjs.map +1 -1
- package/lib/components/Header/MenuItem/MenuItem.styles.d.ts +1 -1
- package/lib/components/Header/MenuItem/MenuItem.styles.js +1 -1
- package/lib/components/Header/MenuItem/MenuItem.styles.js.map +1 -1
- package/lib/components/Header/MenuItem/MenuItem.styles.mjs +1 -1
- package/lib/components/Header/MenuItem/MenuItem.styles.mjs.map +1 -1
- package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.d.ts +1 -1
- package/lib/components/Header/Navigation/MobileMenu/MobileMenu.styles.d.ts +1 -1
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.d.ts +1 -1
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +63 -85
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +64 -86
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs.map +1 -1
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.d.ts +0 -6
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js +1 -11
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js.map +1 -1
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs +2 -10
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs.map +1 -1
- package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.types.d.ts +1 -5
- package/lib/components/Header/Overlay/Overlay.js.map +1 -1
- package/lib/components/Header/Overlay/Overlay.mjs.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.d.ts +4 -2
- package/lib/components/Header/ProHeader/ProHeader.js +36 -145
- package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.mjs +39 -146
- package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +1 -4
- package/lib/components/Header/ProHeader/ProHeader.styles.js +18 -20
- package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.styles.mjs +19 -18
- package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
- package/lib/components/Header/translations/en.json.js +1 -4
- package/lib/components/Header/translations/en.json.js.map +1 -1
- package/lib/components/Header/translations/en.json.mjs +2 -4
- package/lib/components/Header/translations/en.json.mjs.map +1 -1
- package/lib/components/Hero/Hero.styles.d.ts +2 -2
- package/lib/components/HeroFadeGallery/HeroFadeGallery.styles.d.ts +1 -1
- package/lib/components/HowToUseSection/HowToUseSection.styles.d.ts +2 -2
- package/lib/components/ImageSequence/ImageSequence.js.map +1 -1
- package/lib/components/ImageSequence/ImageSequence.mjs.map +1 -1
- package/lib/components/LandingPage/Cards/Card/Card.js.map +1 -1
- package/lib/components/LandingPage/Cards/Card/Card.mjs.map +1 -1
- package/lib/components/LandingPage/Cards/Cards.js.map +1 -1
- package/lib/components/LandingPage/Cards/Cards.mjs.map +1 -1
- package/lib/components/LandingPagePro/LandingPagePro.d.ts +0 -3
- package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
- package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
- package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
- package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
- package/lib/components/LandingPagePro/LandingPagePro.styles.d.ts +1 -1
- package/lib/components/LayoutRenderer/LayoutRenderer.styles.d.ts +1 -1
- package/lib/components/LayoutRendererV1/LayoutRenderer.styles.d.ts +3 -3
- package/lib/components/LayoutRendererV2/LayoutRenderer.styles.d.ts +3 -3
- package/lib/components/MicrositeIntroductionBlock/MicrositeIntroductionBlock.js.map +1 -1
- package/lib/components/MicrositeIntroductionBlock/MicrositeIntroductionBlock.mjs.map +1 -1
- package/lib/components/MicrositeMediaGrid/MicrositeMediaGrid.js.map +1 -1
- package/lib/components/MicrositeMediaGrid/MicrositeMediaGrid.mjs.map +1 -1
- package/lib/components/MicrositeProductGrid/MicrositeProductGrid.js.map +1 -1
- package/lib/components/MicrositeProductGrid/MicrositeProductGrid.mjs.map +1 -1
- package/lib/components/MicrositeSectionWrap/MicrositeSectionWrap.styles.d.ts +1 -1
- package/lib/components/Microsites/MicrositeProductPage.js +39 -0
- package/lib/components/Microsites/MicrositeProductPage.js.map +1 -1
- package/lib/components/Microsites/MicrositeProductPage.mjs +39 -0
- package/lib/components/Microsites/MicrositeProductPage.mjs.map +1 -1
- package/lib/components/ModelCompareV3/StickyGrid/StickyGridHeader.js.map +1 -1
- package/lib/components/ModelCompareV3/StickyGrid/StickyGridHeader.mjs.map +1 -1
- package/lib/components/ProductCompare/ProductCompare.js.map +1 -1
- package/lib/components/ProductCompare/ProductCompare.mjs.map +1 -1
- package/lib/components/ProductSectionNavigation/ProductSectionNavigation.styles.d.ts +1 -1
- package/lib/components/ProductSectionNavigationV2/ProductSectionNavigation.styles.d.ts +1 -1
- package/lib/components/ProductTechSpecs/ProductTechSpecs.styles.d.ts +1 -1
- package/lib/components/QuantityControls/QuantityControls.js.map +1 -1
- package/lib/components/QuantityControls/QuantityControls.mjs.map +1 -1
- package/lib/components/RelatedProducts/RelatedProducts.js.map +1 -1
- package/lib/components/RelatedProducts/RelatedProducts.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +17 -313
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +17 -311
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +2 -3
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +0 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +0 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js +34 -120
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs +34 -120
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.d.ts +2 -16
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js +12 -54
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs +11 -50
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowLeftPrimary.svg.js +5 -5
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowRightPrimary.svg.js +5 -5
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +0 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +0 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ResourceCalculator.js +2 -1
- package/lib/components/ResourceCalculatorV1/ResourceCalculator.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs +2 -1
- package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs.map +1 -1
- package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.d.ts +1 -1
- package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.js +1 -3
- package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +1 -0
- package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.mjs +1 -3
- package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +1 -0
- package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.d.ts +0 -1
- package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.js +7 -10
- package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +1 -0
- package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.mjs +7 -10
- package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +1 -0
- package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.types.d.ts +0 -1
- package/lib/components/ResourceCalculatorV1/components/index.d.ts +1 -0
- package/lib/components/ResourceCalculatorV1/components/index.js +5 -0
- package/lib/components/{Header/Navigation/ProMenu → ResourceCalculatorV1/components}/index.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/components/index.mjs +3 -0
- package/lib/components/ResourceCalculatorV1/translations/en.json.js +4 -6
- package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +4 -6
- package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
- package/lib/components/ReverseLoopingVideo/ReverseLoopingVideo.js.map +1 -1
- package/lib/components/ReverseLoopingVideo/ReverseLoopingVideo.mjs.map +1 -1
- package/lib/components/ScrollWrapper/ScrollWrapper.js.map +1 -1
- package/lib/components/ScrollWrapper/ScrollWrapper.mjs.map +1 -1
- package/lib/components/StorageSliders/Slider/Slider.js.map +1 -1
- package/lib/components/StorageSliders/Slider/Slider.mjs.map +1 -1
- package/lib/components/StorageSliders/StorageSliders.context.js.map +1 -1
- package/lib/components/StorageSliders/StorageSliders.context.mjs.map +1 -1
- package/lib/components/VariantSelector/Variant/Compatibility/Compatibility.js.map +1 -1
- package/lib/components/VariantSelector/Variant/Compatibility/Compatibility.mjs.map +1 -1
- package/lib/components/VariantSelector/Variant/Variant.js.map +1 -1
- package/lib/components/VariantSelector/Variant/Variant.mjs.map +1 -1
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -2
- package/lib/components/index.js.map +1 -1
- package/lib/components/index.mjs +0 -2
- package/lib/components/index.mjs.map +1 -1
- package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -1
- package/lib/constants/proStoreCategories/mapping/index.js +10 -15
- package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
- package/lib/constants/proStoreCategories/mapping/index.mjs +10 -15
- package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
- package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -2
- package/lib/constants/proStoreCategories/mapping/unifi.js +0 -1
- package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
- package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -1
- package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/en.json.js +0 -3
- package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -3
- package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/fr.json.js +1 -1
- package/lib/constants/proStoreCategories/translations/fr.json.mjs +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +1 -1
- package/lib/constants/url.d.ts +2 -1
- package/lib/constants/url.js +1 -0
- package/lib/constants/url.js.map +1 -1
- package/lib/constants/url.mjs +1 -0
- package/lib/constants/url.mjs.map +1 -1
- package/lib/contexts/MenuContext/context.js +1 -1
- package/lib/contexts/MenuContext/context.js.map +1 -1
- package/lib/contexts/MenuContext/context.mjs +1 -1
- package/lib/contexts/MenuContext/context.mjs.map +1 -1
- package/lib/contexts/MenuContext/utils.js +1 -0
- package/lib/contexts/MenuContext/utils.js.map +1 -1
- package/lib/contexts/MenuContext/utils.mjs +1 -0
- package/lib/contexts/MenuContext/utils.mjs.map +1 -1
- package/lib/helpers/index.d.ts +0 -1
- package/lib/helpers/index.js +0 -11
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/index.mjs +0 -1
- package/lib/helpers/index.mjs.map +1 -1
- package/lib/helpers/ux.d.ts +1 -9
- package/lib/helpers/ux.js +0 -15
- package/lib/helpers/ux.js.map +1 -1
- package/lib/helpers/ux.mjs +1 -15
- package/lib/helpers/ux.mjs.map +1 -1
- package/lib/hooks/useHasTouch.js.map +1 -1
- package/lib/hooks/useHasTouch.mjs.map +1 -1
- package/lib/hooks/useHorizontalScroll.js.map +1 -1
- package/lib/hooks/useHorizontalScroll.mjs.map +1 -1
- package/lib/types/index.d.ts +0 -1
- package/lib/types/index.js +0 -2
- package/lib/types/index.js.map +1 -1
- package/lib/types/index.mjs +0 -1
- package/lib/types/index.mjs.map +1 -1
- package/lib/utils/array.d.ts +0 -4
- package/lib/utils/array.js +0 -10
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/array.mjs +1 -10
- package/lib/utils/array.mjs.map +1 -1
- package/lib/utils/money/constants.d.ts +25 -56
- package/lib/utils/money/constants.js +7 -72
- package/lib/utils/money/constants.js.map +1 -1
- package/lib/utils/money/constants.mjs +7 -70
- package/lib/utils/money/constants.mjs.map +1 -1
- package/lib/utils/money/format.d.ts +5 -10
- package/lib/utils/money/format.js +14 -22
- package/lib/utils/money/format.js.map +1 -1
- package/lib/utils/money/format.mjs +16 -23
- package/lib/utils/money/format.mjs.map +1 -1
- package/lib/utils/money/index.d.ts +1 -4
- package/lib/utils/money/index.js +8 -26
- package/lib/utils/money/index.js.map +1 -1
- package/lib/utils/money/index.mjs +4 -8
- package/lib/utils/money/index.mjs.map +1 -1
- package/lib/utils/money/misc.d.ts +28 -68
- package/lib/utils/money/misc.js +64 -35
- package/lib/utils/money/misc.js.map +1 -1
- package/lib/utils/money/misc.mjs +43 -32
- package/lib/utils/money/misc.mjs.map +1 -1
- package/lib/utils/money/tax.d.ts +2 -38
- package/lib/utils/money/tax.js +10 -46
- package/lib/utils/money/tax.js.map +1 -1
- package/lib/utils/money/tax.mjs +11 -42
- package/lib/utils/money/tax.mjs.map +1 -1
- package/lib/utils/money/types.d.ts +3 -78
- package/lib/utils/number.d.ts +1 -1
- package/lib/utils/number.js +1 -1
- package/lib/utils/number.js.map +1 -1
- package/lib/utils/number.mjs +1 -1
- package/lib/utils/number.mjs.map +1 -1
- package/lib/utils/validations/postalCodeSuperRefinement.js +3 -0
- package/lib/utils/validations/postalCodeSuperRefinement.js.map +1 -1
- package/lib/utils/validations/postalCodeSuperRefinement.mjs +3 -0
- package/lib/utils/validations/postalCodeSuperRefinement.mjs.map +1 -1
- package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js +2 -0
- package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js.map +1 -1
- package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs +2 -0
- package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs.map +1 -1
- package/lib/utils/validations/taxIdSuperRefinement.js +2 -0
- package/lib/utils/validations/taxIdSuperRefinement.js.map +1 -1
- package/lib/utils/validations/taxIdSuperRefinement.mjs +2 -0
- package/lib/utils/validations/taxIdSuperRefinement.mjs.map +1 -1
- package/lib/utils/validations.d.ts +15 -0
- package/lib/utils/validations.js +23 -0
- package/lib/utils/validations.js.map +1 -0
- package/lib/utils/validations.mjs +21 -0
- package/lib/utils/validations.mjs.map +1 -0
- package/lib/utils/variant.js.map +1 -1
- package/lib/utils/variant.mjs.map +1 -1
- package/lib/utils/wattage.js.map +1 -1
- package/lib/utils/wattage.mjs.map +1 -1
- package/package.json +1 -1
- package/lib/assets/efg.png +0 -0
- package/lib/assets/icon-location-pin.svg +0 -5
- package/lib/assets/icons/menu/icon-location-pin.svg.js +0 -27
- package/lib/assets/icons/menu/icon-location-pin.svg.js.map +0 -1
- package/lib/assets/icons/menu/icon-location-pin.svg.mjs +0 -3
- package/lib/assets/icons/menu/icon-location-pin.svg.mjs.map +0 -1
- package/lib/assets/ucg-max.png +0 -0
- package/lib/components/Header/Navigation/ProMenu/ProMenu.d.ts +0 -2
- package/lib/components/Header/Navigation/ProMenu/ProMenu.js +0 -109
- package/lib/components/Header/Navigation/ProMenu/ProMenu.js.map +0 -1
- package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs +0 -87
- package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs.map +0 -1
- package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.d.ts +0 -24
- package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js +0 -154
- package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js.map +0 -1
- package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs +0 -138
- package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs.map +0 -1
- package/lib/components/Header/Navigation/ProMenu/ProMenu.types.d.ts +0 -13
- package/lib/components/Header/Navigation/ProMenu/index.d.ts +0 -1
- package/lib/components/Header/Navigation/ProMenu/index.js +0 -6
- package/lib/components/Header/Navigation/ProMenu/index.mjs +0 -3
- package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +0 -1
- package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +0 -1
- package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +0 -1
- package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +0 -1
- package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js +0 -27
- package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +0 -1
- package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +0 -3
- package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +0 -1
- package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +0 -1
- package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +0 -3
- package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +0 -1
- package/lib/helpers/product.d.ts +0 -87
- package/lib/helpers/product.js +0 -346
- package/lib/helpers/product.js.map +0 -1
- package/lib/helpers/product.mjs +0 -335
- package/lib/helpers/product.mjs.map +0 -1
- package/lib/types/product.d.ts +0 -87
- package/lib/types/product.js +0 -14
- package/lib/types/product.js.map +0 -1
- package/lib/types/product.mjs +0 -13
- package/lib/types/product.mjs.map +0 -1
- package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
- package/lib/utils/money/allocators/fixedAmount.js +0 -55
- package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
- package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
- package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
- package/lib/utils/money/allocators/index.d.ts +0 -2
- package/lib/utils/money/allocators/index.js +0 -8
- package/lib/utils/money/allocators/index.js.map +0 -1
- package/lib/utils/money/allocators/index.mjs +0 -4
- package/lib/utils/money/allocators/index.mjs.map +0 -1
- package/lib/utils/money/allocators/productAmount.d.ts +0 -13
- package/lib/utils/money/allocators/productAmount.js +0 -110
- package/lib/utils/money/allocators/productAmount.js.map +0 -1
- package/lib/utils/money/allocators/productAmount.mjs +0 -108
- package/lib/utils/money/allocators/productAmount.mjs.map +0 -1
- package/lib/utils/money/exchangeRate.d.ts +0 -31
- package/lib/utils/money/exchangeRate.js +0 -27
- package/lib/utils/money/exchangeRate.js.map +0 -1
- package/lib/utils/money/exchangeRate.mjs +0 -23
- package/lib/utils/money/exchangeRate.mjs.map +0 -1
- package/lib/utils/money/misc.private.d.ts +0 -23
- package/lib/utils/money/misc.private.js +0 -46
- package/lib/utils/money/misc.private.js.map +0 -1
- package/lib/utils/money/misc.private.mjs +0 -21
- package/lib/utils/money/misc.private.mjs.map +0 -1
- package/lib/utils/money/shipping.d.ts +0 -5
- package/lib/utils/money/shipping.js +0 -8
- package/lib/utils/money/shipping.js.map +0 -1
- package/lib/utils/money/shipping.mjs +0 -6
- package/lib/utils/money/shipping.mjs.map +0 -1
- package/lib/utils/money/tax.private.d.ts +0 -17
- package/lib/utils/money/tax.private.js +0 -65
- package/lib/utils/money/tax.private.js.map +0 -1
- package/lib/utils/money/tax.private.mjs +0 -60
- package/lib/utils/money/tax.private.mjs.map +0 -1
- package/lib/utils/productSort.d.ts +0 -41
- package/lib/utils/productSort.js +0 -66
- package/lib/utils/productSort.js.map +0 -1
- package/lib/utils/productSort.mjs +0 -59
- package/lib/utils/productSort.mjs.map +0 -1
- /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.d.ts +0 -0
- /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js +0 -0
- /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js.map +0 -0
- /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs +0 -0
- /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs.map +0 -0
- /package/lib/components/{Header/Navigation/ProMenu → ResourceCalculatorV1/components}/index.mjs.map +0 -0
package/lib/utils/money/tax.js
CHANGED
|
@@ -1,58 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var dinero_js = require('dinero.js');
|
|
4
|
-
var errors = require('../errors.js');
|
|
5
|
-
var number = require('../number.js');
|
|
6
|
-
var constants = require('./constants.js');
|
|
7
|
-
var tax_private = require('./tax.private.js');
|
|
8
4
|
"use strict";
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
5
|
+
const allocateTaxAmount = (baseAmountObj, floatRate) => {
|
|
6
|
+
const rateScale = String(floatRate).split(".")[1]?.length;
|
|
7
|
+
if (rateScale === void 0) {
|
|
8
|
+
throw new Error(`rateScale is unsupported ${floatRate}`);
|
|
9
|
+
}
|
|
10
|
+
const rateInt = Math.round(floatRate * Math.pow(10, rateScale));
|
|
11
|
+
return dinero_js.allocate(baseAmountObj, [rateInt, Math.pow(10, rateScale) - rateInt])[0];
|
|
15
12
|
};
|
|
16
|
-
const removeTaxAmount = (baseAmountWithTaxObj,
|
|
13
|
+
const removeTaxAmount = (baseAmountWithTaxObj, floatRate) => {
|
|
17
14
|
const snapshot = dinero_js.toSnapshot(baseAmountWithTaxObj);
|
|
18
15
|
return dinero_js.dinero({
|
|
19
16
|
...snapshot,
|
|
20
|
-
amount: dinero_js.down(snapshot.amount / (1 +
|
|
17
|
+
amount: dinero_js.down(snapshot.amount / (1 + floatRate))
|
|
21
18
|
});
|
|
22
19
|
};
|
|
23
|
-
|
|
24
|
-
const dineroObj = decimalTaxRateToDinero(taxRate);
|
|
25
|
-
const t = dinero_js.multiply(dineroObj, 100);
|
|
26
|
-
return dinero_js.toUnit(t, {
|
|
27
|
-
digits: constants.TAX_RATE_DINERO_CURRENCY.exponent,
|
|
28
|
-
round: dinero_js.halfEven
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
const decimalTaxRateToDinero = taxRate => {
|
|
32
|
-
const parsedNumber = typeof taxRate === "number" ? taxRate : Number.parseFloat(taxRate);
|
|
33
|
-
number.isFloat(parsedNumber);
|
|
34
|
-
const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(constants.TAX_RATE_DINERO_CURRENCY.base, constants.TAX_RATE_DINERO_CURRENCY.exponent)).toFixed(0));
|
|
35
|
-
return dinero_js.dinero({
|
|
36
|
-
amount: parsedNumberInt,
|
|
37
|
-
currency: constants.TAX_RATE_DINERO_CURRENCY
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
const formatDecimalTaxRate = taxRate => {
|
|
41
|
-
return `${convertDecimalTaxRateToPercentage(taxRate)}%`;
|
|
42
|
-
};
|
|
43
|
-
const stringTaxRateToFloat = rate => number.toFixedRate(+rate, constants.TAX_RATE_DINERO_CURRENCY.exponent, true);
|
|
44
|
-
const calculateTotalTaxRate = rates => {
|
|
45
|
-
const rateSum = rates.reduce((sum, rate) => sum + rate, 0);
|
|
46
|
-
const result = number.toFixedRate(rateSum, constants.TAX_RATE_DINERO_CURRENCY.exponent, true);
|
|
47
|
-
errors.assert(result >= 0, "Tax rate must be positive");
|
|
48
|
-
errors.assert(result < 1, "Tax rate must be less than 1");
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
exports.calculateLineItemTax = calculateLineItemTax;
|
|
52
|
-
exports.calculateTotalTaxRate = calculateTotalTaxRate;
|
|
53
|
-
exports.convertDecimalTaxRateToPercentage = convertDecimalTaxRateToPercentage;
|
|
54
|
-
exports.decimalTaxRateToDinero = decimalTaxRateToDinero;
|
|
55
|
-
exports.formatDecimalTaxRate = formatDecimalTaxRate;
|
|
20
|
+
exports.allocateTaxAmount = allocateTaxAmount;
|
|
56
21
|
exports.removeTaxAmount = removeTaxAmount;
|
|
57
|
-
exports.stringTaxRateToFloat = stringTaxRateToFloat;
|
|
58
22
|
//# sourceMappingURL=tax.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tax.js","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"tax.js","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import { allocate, type Dinero, dinero, down, toSnapshot } from \"dinero.js\";\n\nexport const allocateTaxAmount = (\n baseAmountObj: Dinero<number>,\n floatRate: number,\n) => {\n // FIXME: currently the API returns rate as a floating number, but the dinero lib expects be a integer number with some\n // scale so for now we attempt calculate the scale from the float rate\n // @see https://v2.dinerojs.com/docs/api/mutations/allocate\n const rateScale = String(floatRate).split(\".\")[1]?.length;\n if (rateScale === undefined) {\n throw new Error(`rateScale is unsupported ${floatRate}`);\n }\n const rateInt = Math.round(floatRate * Math.pow(10, rateScale));\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allocate(baseAmountObj, [\n rateInt,\n Math.pow(10, rateScale) - rateInt,\n ])[0]!;\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<number>,\n floatRate: number,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + floatRate)),\n });\n};\n"],"names":["allocateTaxAmount","baseAmountObj","floatRate","rateScale","String","split","length","Error","rateInt","Math","round","pow","allocate","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down"],"mappings":";;;;AAEa,MAAAA,iBAAA,GAAoBA,CAC/BC,aAAA,EACAC,SACG,KAAA;EAIG,MAAAC,SAAA,GAAYC,OAAOF,SAAS,CAAA,CAAEG,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EACnD,IAAIH,cAAc,KAAW,CAAA,EAAA;IAC3B,MAAM,IAAII,KAAA,CAAkC,4BAAAL,SAAW,EAAA,CAAA;EACzD;EACM,MAAAM,OAAA,GAAUC,KAAKC,KAAM,CAAAR,SAAA,GAAYO,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAE9D,OAAOS,SAAAA,CAAAA,SAASX,aAAe,EAAA,CAC7BO,OAAA,EACAC,IAAK,CAAAE,GAAA,CAAI,EAAI,EAAAR,SAAS,CAAI,GAAAK,OAAA,CAC3B,EAAE,CAAC,CAAA;AACN,CAAA;AAEa,MAAAK,eAAA,GAAkBA,CAC7BC,oBAAA,EACAZ,SACG,KAAA;EACG,MAAAa,QAAA,GAAWC,qBAAWF,oBAAoB,CAAA;EAChD,OAAOG,gBAAO,CAAA;IACZ,GAAGF,QAAA;IACHG,MAAQ,EAAAC,SAAA,CAAAA,IAAA,CAAKJ,QAAS,CAAAG,MAAA,IAAU,IAAIhB,SAAU,CAAA;EAAA,CAC/C,CAAA;AACH,CAAA;;"}
|
package/lib/utils/money/tax.mjs
CHANGED
|
@@ -1,50 +1,19 @@
|
|
|
1
|
-
import { toSnapshot, dinero, down
|
|
2
|
-
import { assert } from '../errors.mjs';
|
|
3
|
-
import { isFloat, toFixedRate } from '../number.mjs';
|
|
4
|
-
import { storesWithPerItemTaxRate, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
|
|
5
|
-
import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax } from './tax.private.mjs';
|
|
1
|
+
import { allocate, toSnapshot, dinero, down } from 'dinero.js';
|
|
6
2
|
"use strict";
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
3
|
+
const allocateTaxAmount = (baseAmountObj, floatRate) => {
|
|
4
|
+
const rateScale = String(floatRate).split(".")[1]?.length;
|
|
5
|
+
if (rateScale === void 0) {
|
|
6
|
+
throw new Error(`rateScale is unsupported ${floatRate}`);
|
|
7
|
+
}
|
|
8
|
+
const rateInt = Math.round(floatRate * Math.pow(10, rateScale));
|
|
9
|
+
return allocate(baseAmountObj, [rateInt, Math.pow(10, rateScale) - rateInt])[0];
|
|
13
10
|
};
|
|
14
|
-
const removeTaxAmount = (baseAmountWithTaxObj,
|
|
11
|
+
const removeTaxAmount = (baseAmountWithTaxObj, floatRate) => {
|
|
15
12
|
const snapshot = toSnapshot(baseAmountWithTaxObj);
|
|
16
13
|
return dinero({
|
|
17
14
|
...snapshot,
|
|
18
|
-
amount: down(snapshot.amount / (1 +
|
|
15
|
+
amount: down(snapshot.amount / (1 + floatRate))
|
|
19
16
|
});
|
|
20
17
|
};
|
|
21
|
-
|
|
22
|
-
const dineroObj = decimalTaxRateToDinero(taxRate);
|
|
23
|
-
const t = multiply(dineroObj, 100);
|
|
24
|
-
return toUnit(t, {
|
|
25
|
-
digits: TAX_RATE_DINERO_CURRENCY.exponent,
|
|
26
|
-
round: halfEven
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
const decimalTaxRateToDinero = taxRate => {
|
|
30
|
-
const parsedNumber = typeof taxRate === "number" ? taxRate : Number.parseFloat(taxRate);
|
|
31
|
-
isFloat(parsedNumber);
|
|
32
|
-
const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)).toFixed(0));
|
|
33
|
-
return dinero({
|
|
34
|
-
amount: parsedNumberInt,
|
|
35
|
-
currency: TAX_RATE_DINERO_CURRENCY
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
const formatDecimalTaxRate = taxRate => {
|
|
39
|
-
return `${convertDecimalTaxRateToPercentage(taxRate)}%`;
|
|
40
|
-
};
|
|
41
|
-
const stringTaxRateToFloat = rate => toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);
|
|
42
|
-
const calculateTotalTaxRate = rates => {
|
|
43
|
-
const rateSum = rates.reduce((sum, rate) => sum + rate, 0);
|
|
44
|
-
const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);
|
|
45
|
-
assert(result >= 0, "Tax rate must be positive");
|
|
46
|
-
assert(result < 1, "Tax rate must be less than 1");
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
export { calculateLineItemTax, calculateTotalTaxRate, convertDecimalTaxRateToPercentage, decimalTaxRateToDinero, formatDecimalTaxRate, removeTaxAmount, stringTaxRateToFloat };
|
|
18
|
+
export { allocateTaxAmount, removeTaxAmount };
|
|
50
19
|
//# sourceMappingURL=tax.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import { allocate, type Dinero, dinero, down, toSnapshot } from \"dinero.js\";\n\nexport const allocateTaxAmount = (\n baseAmountObj: Dinero<number>,\n floatRate: number,\n) => {\n // FIXME: currently the API returns rate as a floating number, but the dinero lib expects be a integer number with some\n // scale so for now we attempt calculate the scale from the float rate\n // @see https://v2.dinerojs.com/docs/api/mutations/allocate\n const rateScale = String(floatRate).split(\".\")[1]?.length;\n if (rateScale === undefined) {\n throw new Error(`rateScale is unsupported ${floatRate}`);\n }\n const rateInt = Math.round(floatRate * Math.pow(10, rateScale));\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allocate(baseAmountObj, [\n rateInt,\n Math.pow(10, rateScale) - rateInt,\n ])[0]!;\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<number>,\n floatRate: number,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + floatRate)),\n });\n};\n"],"names":["allocateTaxAmount","baseAmountObj","floatRate","rateScale","String","split","length","Error","rateInt","Math","round","pow","allocate","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down"],"mappings":";;AAEa,MAAAA,iBAAA,GAAoBA,CAC/BC,aAAA,EACAC,SACG,KAAA;EAIG,MAAAC,SAAA,GAAYC,OAAOF,SAAS,CAAA,CAAEG,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EACnD,IAAIH,cAAc,KAAW,CAAA,EAAA;IAC3B,MAAM,IAAII,KAAA,CAAkC,4BAAAL,SAAW,EAAA,CAAA;EACzD;EACM,MAAAM,OAAA,GAAUC,KAAKC,KAAM,CAAAR,SAAA,GAAYO,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAE9D,OAAOS,SAASX,aAAe,EAAA,CAC7BO,OAAA,EACAC,IAAK,CAAAE,GAAA,CAAI,EAAI,EAAAR,SAAS,CAAI,GAAAK,OAAA,CAC3B,EAAE,CAAC,CAAA;AACN,CAAA;AAEa,MAAAK,eAAA,GAAkBA,CAC7BC,oBAAA,EACAZ,SACG,KAAA;EACG,MAAAa,QAAA,GAAWC,WAAWF,oBAAoB,CAAA;EAChD,OAAOG,MAAO,CAAA;IACZ,GAAGF,QAAA;IACHG,MAAQ,EAAAC,IAAA,CAAKJ,QAAS,CAAAG,MAAA,IAAU,IAAIhB,SAAU,CAAA;EAAA,CAC/C,CAAA;AACH,CAAA;"}
|
|
@@ -1,85 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Currency } from "../../types";
|
|
3
|
-
/**
|
|
4
|
-
* Floating point number of item tax rate
|
|
5
|
-
* Number in range of 0>rate<1 (non-inclusive boundaries)
|
|
6
|
-
* @example
|
|
7
|
-
* 0.09 // 9%
|
|
8
|
-
*/
|
|
9
|
-
export type TaxRate = number;
|
|
10
|
-
/**
|
|
11
|
-
* Shorthand for Dinero.js instance with number as the amount
|
|
12
|
-
*/
|
|
13
|
-
export type Dino = Dinero<number>;
|
|
14
|
-
/**
|
|
15
|
-
* Shorthand for Dinero.js currency instance representing either a currency or custom currency such as tax-rate or shipping
|
|
16
|
-
*/
|
|
17
|
-
export type DinoCurrency = DineroCurrency<number>;
|
|
18
|
-
/**
|
|
19
|
-
* Cents representation of specific currency
|
|
20
|
-
* As a helper to easily understand the code, we use `Cents` as a type alias for `number` as historically we have had
|
|
21
|
-
* mistakes by the team where we have used as dollar instead of `Cents` and vice versa.
|
|
22
|
-
* @example
|
|
23
|
-
* 100 // in USD this is $1.00
|
|
24
|
-
* 100 // in YEN this is ¥100
|
|
25
|
-
*/
|
|
26
|
-
export type Cents = number;
|
|
27
|
-
/**
|
|
28
|
-
* Type definition for a rounding function that can be used to round fractions
|
|
29
|
-
*/
|
|
30
|
-
export type RoundingFn = (float: number) => Cents;
|
|
31
|
-
/**
|
|
32
|
-
* Convenient way to represent a money on the API level
|
|
33
|
-
* When working with dinero you typically will convert this to a Dinero instance
|
|
34
|
-
*/
|
|
35
|
-
export interface Money {
|
|
36
|
-
amount: Cents;
|
|
37
|
-
currency: Currency;
|
|
38
|
-
}
|
|
1
|
+
import type { Currency as DineroCurrency } from "dinero.js";
|
|
39
2
|
/**
|
|
40
3
|
* Attempt to type out some locales `language-TERRITORY` which "we" as store care about
|
|
41
4
|
* @see https://unicode-org.github.io/cldr-staging/charts/38/supplemental/territory_language_information.html
|
|
42
5
|
*/
|
|
43
6
|
export type Locale = "ar-AE" | "ar-SA" | "bg-BG" | "bn-BD" | "bn-IN" | "cs-CZ" | "da-DK" | "de-AT" | "de-CH" | "de-DE" | "el-GR" | "en-AU" | "en-BR" | "en-CA" | "en-GB" | "en-IE" | "en-IN" | "en-JP" | "en-NZ" | "en-SG" | "en-US" | "en-ZA" | "es-AR" | "es-CL" | "es-CO" | "es-ES" | "es-MX" | "es-US" | "fi-FI" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "he-IL" | "hi-IN" | "hr-HR" | "hu-HU" | "id-ID" | "it-CH" | "it-IT" | "ja-JP" | "ko-KR" | "nl-BE" | "nl-NL" | "no-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sv-SE" | "ta-IN" | "ta-LK" | "th-TH" | "tr-TR" | "zh-CN" | "zh-HK" | "zh-TW" | string;
|
|
44
|
-
export type
|
|
45
|
-
currency:
|
|
7
|
+
export type CurrencyObj = {
|
|
8
|
+
currency: DineroCurrency<number>;
|
|
46
9
|
locale: Locale;
|
|
47
10
|
};
|
|
48
|
-
export interface LineItemSummary {
|
|
49
|
-
itemPrice: Cents;
|
|
50
|
-
/**
|
|
51
|
-
* Item quantity that is always bigger than zero!
|
|
52
|
-
*/
|
|
53
|
-
quantity: number;
|
|
54
|
-
currency: Currency;
|
|
55
|
-
/**
|
|
56
|
-
* Total discount amount (only) applied for the given item quantity.
|
|
57
|
-
* No taxes are included. Calculated by `total_raw_price * <discount-allocation-percentage>`
|
|
58
|
-
*/
|
|
59
|
-
discountAmount: Cents;
|
|
60
|
-
/**
|
|
61
|
-
* subtotal - discountAmount
|
|
62
|
-
*/
|
|
63
|
-
taxableAmount: Cents;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Pretty much the same as PreTaxItemSummary but with quantity always set to 1 (for clearer type hinting and reasoning
|
|
67
|
-
* around the topic)
|
|
68
|
-
*/
|
|
69
|
-
export interface SingleLineItemSummary extends LineItemSummary {
|
|
70
|
-
quantity: 1;
|
|
71
|
-
}
|
|
72
|
-
export interface FullLineItemSummary extends LineItemSummary {
|
|
73
|
-
/**
|
|
74
|
-
* Total price for the given item quantity. Calculated by `(itemPrice * quantity)`
|
|
75
|
-
*/
|
|
76
|
-
subtotal: Cents;
|
|
77
|
-
/**
|
|
78
|
-
* Total tax amount for the given item quantity.
|
|
79
|
-
*/
|
|
80
|
-
tax: Cents;
|
|
81
|
-
/**
|
|
82
|
-
* Total price for the given item quantity. Calculated by `subtotal - discountAmount + tax`
|
|
83
|
-
*/
|
|
84
|
-
total: Cents;
|
|
85
|
-
}
|
package/lib/utils/number.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare function isFloat(value: unknown, entity?: string, ErrorClass?: ne
|
|
|
31
31
|
* toFixed(1.2345, 0) // => "1"
|
|
32
32
|
* toFixed(1.23, 4) // => "1.2300"
|
|
33
33
|
*/
|
|
34
|
-
export declare function toFixedRate(rate: number, scale: number
|
|
34
|
+
export declare function toFixedRate(rate: number, scale: number): string;
|
|
35
35
|
export declare function toFixedRate(rate: number, scale: number, asNumber: true): number;
|
|
36
36
|
/**
|
|
37
37
|
* Util to convert a float number to a string. Using this rather than simple template string to have a consistent way of
|
package/lib/utils/number.js
CHANGED
|
@@ -21,7 +21,7 @@ function isInt(value, entity = "Value", ErrorClass = TypeError) {
|
|
|
21
21
|
function isFloat(value, entity = "Value", ErrorClass = TypeError) {
|
|
22
22
|
isFiniteNumber(value, entity, ErrorClass);
|
|
23
23
|
}
|
|
24
|
-
function toFixedRate(rate, scale, asNumber) {
|
|
24
|
+
function toFixedRate(rate, scale = 0, asNumber = false) {
|
|
25
25
|
isFloat(rate, "Rate");
|
|
26
26
|
const fixedRate = rate.toFixed(scale);
|
|
27
27
|
return asNumber ? +fixedRate : fixedRate;
|
package/lib/utils/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sources":["../../src/utils/number.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n\n/**\n * Custom isFloat validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.parseFloat would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L34-L38\n * @throws If given input is not a valid float\n */\nexport function isFloat(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n}\n\n/**\n * Returns a string representing a number in fixed-point notation.\n * Overload: Returns the rate parsed as a number\n * @example\n * toFixed(1.2345, 2) // => \"1.23\"\n * toFixed(1.2345, 0) // => \"1\"\n * toFixed(1.23, 4) // => \"1.2300\"\n */\nexport function toFixedRate(
|
|
1
|
+
{"version":3,"file":"number.js","sources":["../../src/utils/number.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n\n/**\n * Custom isFloat validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.parseFloat would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L34-L38\n * @throws If given input is not a valid float\n */\nexport function isFloat(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n}\n\n/**\n * Returns a string representing a number in fixed-point notation.\n * Overload: Returns the rate parsed as a number\n * @example\n * toFixed(1.2345, 2) // => \"1.23\"\n * toFixed(1.2345, 0) // => \"1\"\n * toFixed(1.23, 4) // => \"1.2300\"\n */\nexport function toFixedRate(rate: number, scale: number): string;\nexport function toFixedRate(\n rate: number,\n scale: number,\n asNumber: true,\n): number;\nexport function toFixedRate(rate: number, scale = 0, asNumber = false) {\n // Verify rate\n isFloat(rate, \"Rate\");\n\n const fixedRate = rate.toFixed(scale);\n\n return asNumber ? +fixedRate : fixedRate;\n}\n\n/**\n * Util to convert a float number to a string. Using this rather than simple template string to have a consistent way of\n * doing it. Removes any redundant trailing zeros.\n * @example\n * numberToString(1.23) // => \"1.23\"\n * numberToString(10.00) // => \"10\"\n * @throws If given input is not a valid number\n */\nexport const numberToString = (num: number): string => {\n isFloat(num);\n return num.toString(10);\n};\n\n/**\n * @see https://stackoverflow.com/a/35000557\n */\nexport const findClosestNumber = <T extends number>(\n haystack: T[],\n needle: number,\n): T => {\n return haystack.reduce((prev, curr) =>\n Math.abs(curr - needle) < Math.abs(prev - needle) ? curr : prev,\n );\n};\n\n/**\n * Splits number into array by max value provided.\n * E.g. splitNumberBy(100, 30) => [30, 30, 30, 10]\n */\nexport const splitNumberBy = (value: number, by: number) => {\n const chunks = new Array(Math.floor(value / by)).fill(by);\n const remainder = value % by;\n\n if (remainder > 0) {\n chunks.push(remainder);\n }\n\n return chunks;\n};\n\n/**\n * Clamp value to a given range\n */\nexport const clamp = (val: number, min: number, max: number) => {\n const trueMin = Math.min(min, max);\n const trueMax = Math.max(min, max);\n\n return Math.min(trueMax, Math.max(trueMin, val));\n};\n\n/**\n * Interpolate a number to a new range\n *\n * @example\n * linearInterpolate(5, [0, 10], [0, 100]); // 50\n */\nexport const linearInterpolate = (\n inputY: number,\n [fromMin, fromMax]: [number, number],\n [toMin, toMax]: [number, number],\n clampResult = true,\n) => {\n const percent = (inputY - fromMin) / (fromMax - fromMin);\n const outputX = percent * (toMax - toMin) + toMin;\n\n return clampResult ? clamp(outputX, toMin, toMax) : outputX;\n};\n\n/**\n * Increase value and start over once the range is overflown\n */\nexport const incrementLoopValue = (\n value: number,\n [min, max]: [number, number],\n) => {\n if (value === max) {\n return min;\n }\n return value + 1;\n};\n"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger","isFloat","toFixedRate","rate","scale","asNumber","fixedRate","toFixed","numberToString","num","toString","findClosestNumber","haystack","needle","reduce","prev","curr","Math","abs","splitNumberBy","by","chunks","Array","floor","fill","remainder","push","clamp","val","min","max","trueMin","trueMax","linearInterpolate","inputY","fromMin","fromMax","toMin","toMax","clampResult","percent","outputX","incrementLoopValue"],"mappings":"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"}
|
package/lib/utils/number.mjs
CHANGED
|
@@ -20,7 +20,7 @@ function isInt(value, entity = "Value", ErrorClass = TypeError) {
|
|
|
20
20
|
function isFloat(value, entity = "Value", ErrorClass = TypeError) {
|
|
21
21
|
isFiniteNumber(value, entity, ErrorClass);
|
|
22
22
|
}
|
|
23
|
-
function toFixedRate(rate, scale, asNumber) {
|
|
23
|
+
function toFixedRate(rate, scale = 0, asNumber = false) {
|
|
24
24
|
isFloat(rate, "Rate");
|
|
25
25
|
const fixedRate = rate.toFixed(scale);
|
|
26
26
|
return asNumber ? +fixedRate : fixedRate;
|
package/lib/utils/number.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.mjs","sources":["../../src/utils/number.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n\n/**\n * Custom isFloat validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.parseFloat would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L34-L38\n * @throws If given input is not a valid float\n */\nexport function isFloat(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n}\n\n/**\n * Returns a string representing a number in fixed-point notation.\n * Overload: Returns the rate parsed as a number\n * @example\n * toFixed(1.2345, 2) // => \"1.23\"\n * toFixed(1.2345, 0) // => \"1\"\n * toFixed(1.23, 4) // => \"1.2300\"\n */\nexport function toFixedRate(
|
|
1
|
+
{"version":3,"file":"number.mjs","sources":["../../src/utils/number.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n\n/**\n * Custom isFloat validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.parseFloat would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L34-L38\n * @throws If given input is not a valid float\n */\nexport function isFloat(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n}\n\n/**\n * Returns a string representing a number in fixed-point notation.\n * Overload: Returns the rate parsed as a number\n * @example\n * toFixed(1.2345, 2) // => \"1.23\"\n * toFixed(1.2345, 0) // => \"1\"\n * toFixed(1.23, 4) // => \"1.2300\"\n */\nexport function toFixedRate(rate: number, scale: number): string;\nexport function toFixedRate(\n rate: number,\n scale: number,\n asNumber: true,\n): number;\nexport function toFixedRate(rate: number, scale = 0, asNumber = false) {\n // Verify rate\n isFloat(rate, \"Rate\");\n\n const fixedRate = rate.toFixed(scale);\n\n return asNumber ? +fixedRate : fixedRate;\n}\n\n/**\n * Util to convert a float number to a string. Using this rather than simple template string to have a consistent way of\n * doing it. Removes any redundant trailing zeros.\n * @example\n * numberToString(1.23) // => \"1.23\"\n * numberToString(10.00) // => \"10\"\n * @throws If given input is not a valid number\n */\nexport const numberToString = (num: number): string => {\n isFloat(num);\n return num.toString(10);\n};\n\n/**\n * @see https://stackoverflow.com/a/35000557\n */\nexport const findClosestNumber = <T extends number>(\n haystack: T[],\n needle: number,\n): T => {\n return haystack.reduce((prev, curr) =>\n Math.abs(curr - needle) < Math.abs(prev - needle) ? curr : prev,\n );\n};\n\n/**\n * Splits number into array by max value provided.\n * E.g. splitNumberBy(100, 30) => [30, 30, 30, 10]\n */\nexport const splitNumberBy = (value: number, by: number) => {\n const chunks = new Array(Math.floor(value / by)).fill(by);\n const remainder = value % by;\n\n if (remainder > 0) {\n chunks.push(remainder);\n }\n\n return chunks;\n};\n\n/**\n * Clamp value to a given range\n */\nexport const clamp = (val: number, min: number, max: number) => {\n const trueMin = Math.min(min, max);\n const trueMax = Math.max(min, max);\n\n return Math.min(trueMax, Math.max(trueMin, val));\n};\n\n/**\n * Interpolate a number to a new range\n *\n * @example\n * linearInterpolate(5, [0, 10], [0, 100]); // 50\n */\nexport const linearInterpolate = (\n inputY: number,\n [fromMin, fromMax]: [number, number],\n [toMin, toMax]: [number, number],\n clampResult = true,\n) => {\n const percent = (inputY - fromMin) / (fromMax - fromMin);\n const outputX = percent * (toMax - toMin) + toMin;\n\n return clampResult ? clamp(outputX, toMin, toMax) : outputX;\n};\n\n/**\n * Increase value and start over once the range is overflown\n */\nexport const incrementLoopValue = (\n value: number,\n [min, max]: [number, number],\n) => {\n if (value === max) {\n return min;\n }\n return value + 1;\n};\n"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger","isFloat","toFixedRate","rate","scale","asNumber","fixedRate","toFixed","numberToString","num","toString","findClosestNumber","haystack","needle","reduce","prev","curr","Math","abs","splitNumberBy","by","chunks","Array","floor","fill","remainder","push","clamp","val","min","max","trueMin","trueMax","linearInterpolate","inputY","fromMin","fromMax","toMin","toMax","clampResult","percent","outputX","incrementLoopValue"],"mappings":"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"}
|
|
@@ -29,6 +29,9 @@ const postalCodeSuperRefinement = ({
|
|
|
29
29
|
return zod$1.addCustomZodIssue(ctx, "postalCode", zod$1.CustomZodIssueCode.PostalCode);
|
|
30
30
|
}
|
|
31
31
|
switch (country$1) {
|
|
32
|
+
/**
|
|
33
|
+
* We additionally validate that the postal code matches the selected province
|
|
34
|
+
*/
|
|
32
35
|
case generated.CountryCode.Ca:
|
|
33
36
|
{
|
|
34
37
|
if (province && postalCode$1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postalCodeSuperRefinement.js","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAAC,OAAA,EAAEA;cAASC,YAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,OAAAA,CAAAA,oBAAqB,CAAAJ,SAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,YAAA,IAAc,CAACA,YAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,UAAAA,CAAAA,wBAAyB,CAAAf,SAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,YAAU,CAAG,EAAA;IACtE,OAAOiB,KAAkB,CAAAA,iBAAA,CAAAf,GAAA,EAAK,YAAc,EAAAgB,KAAA,CAAAA,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,SAAS;IAIf,KAAKqB,SAAAA,CAAAA,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,YAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,aAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,UAAA,CAAAA,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
|
|
1
|
+
{"version":3,"file":"postalCodeSuperRefinement.js","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAAC,OAAA,EAAEA;cAASC,YAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,OAAAA,CAAAA,oBAAqB,CAAAJ,SAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,YAAA,IAAc,CAACA,YAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,UAAAA,CAAAA,wBAAyB,CAAAf,SAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,YAAU,CAAG,EAAA;IACtE,OAAOiB,KAAkB,CAAAA,iBAAA,CAAAf,GAAA,EAAK,YAAc,EAAAgB,KAAA,CAAAA,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,SAAS;IAAA;AAAA;AAAA;IAIf,KAAKqB,SAAAA,CAAAA,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,YAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,aAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,UAAA,CAAAA,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
|
|
@@ -27,6 +27,9 @@ const postalCodeSuperRefinement = ({
|
|
|
27
27
|
return addCustomZodIssue(ctx, "postalCode", CustomZodIssueCode.PostalCode);
|
|
28
28
|
}
|
|
29
29
|
switch (country) {
|
|
30
|
+
/**
|
|
31
|
+
* We additionally validate that the postal code matches the selected province
|
|
32
|
+
*/
|
|
30
33
|
case CountryCode.Ca:
|
|
31
34
|
{
|
|
32
35
|
if (province && postalCode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postalCodeSuperRefinement.mjs","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAEC;EAASC,UAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,oBAAqB,CAAAJ,OAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,UAAA,IAAc,CAACA,UAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,YAAa,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,wBAAyB,CAAAf,OAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,UAAU,CAAG,EAAA;IACtE,OAAOiB,iBAAkB,CAAAf,GAAA,EAAK,YAAc,EAAAgB,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,OAAS;IAIf,KAAKqB,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,UAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,WAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
|
|
1
|
+
{"version":3,"file":"postalCodeSuperRefinement.mjs","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAEC;EAASC,UAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,oBAAqB,CAAAJ,OAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,UAAA,IAAc,CAACA,UAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,YAAa,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,wBAAyB,CAAAf,OAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,UAAU,CAAG,EAAA;IACtE,OAAOiB,iBAAkB,CAAAf,GAAA,EAAK,YAAc,EAAAgB,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,OAAS;IAAA;AAAA;AAAA;IAIf,KAAKqB,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,UAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,WAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
|
|
@@ -17,8 +17,10 @@ const createStateRegistrationNumberSuperRefinement = ({
|
|
|
17
17
|
type
|
|
18
18
|
}, ctx) => {
|
|
19
19
|
switch (addressUsageType) {
|
|
20
|
+
// Exit early because state registration number is generally not needed for billing addresses.
|
|
20
21
|
case constants.AddressUsageType.Billing:
|
|
21
22
|
return;
|
|
23
|
+
// Don't do anything and proceed with the validation logic below.
|
|
22
24
|
case constants.AddressUsageType.ReturnShipping:
|
|
23
25
|
case constants.AddressUsageType.Shipping:
|
|
24
26
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateRegistrationNumberSuperRefinement.js","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAExB,KAAKK,SAAiB,CAAAA,gBAAA,CAAAC,OAAA;MACpB;IAEF,KAAKD,SAAAA,CAAAA,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,SAAiB,CAAAA,gBAAA,CAAAG,QAAA;MACpB;IACF;MACEC,MAAA,CAAAA,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,qBAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,SAAAA,CAAAA,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,KAAA,CAAAA,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;;"}
|
|
1
|
+
{"version":3,"file":"stateRegistrationNumberSuperRefinement.js","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAAA;IAExB,KAAKK,SAAiB,CAAAA,gBAAA,CAAAC,OAAA;MACpB;IAAA;IAEF,KAAKD,SAAAA,CAAAA,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,SAAiB,CAAAA,gBAAA,CAAAG,QAAA;MACpB;IACF;MACEC,MAAA,CAAAA,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,qBAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,SAAAA,CAAAA,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,KAAA,CAAAA,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;;"}
|
|
@@ -15,8 +15,10 @@ const createStateRegistrationNumberSuperRefinement = ({
|
|
|
15
15
|
type
|
|
16
16
|
}, ctx) => {
|
|
17
17
|
switch (addressUsageType) {
|
|
18
|
+
// Exit early because state registration number is generally not needed for billing addresses.
|
|
18
19
|
case AddressUsageType.Billing:
|
|
19
20
|
return;
|
|
21
|
+
// Don't do anything and proceed with the validation logic below.
|
|
20
22
|
case AddressUsageType.ReturnShipping:
|
|
21
23
|
case AddressUsageType.Shipping:
|
|
22
24
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateRegistrationNumberSuperRefinement.mjs","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAExB,KAAKK,gBAAiB,CAAAC,OAAA;MACpB;IAEF,KAAKD,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,gBAAiB,CAAAG,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,WAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,YAAa,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;"}
|
|
1
|
+
{"version":3,"file":"stateRegistrationNumberSuperRefinement.mjs","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAAA;IAExB,KAAKK,gBAAiB,CAAAC,OAAA;MACpB;IAAA;IAEF,KAAKD,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,gBAAiB,CAAAG,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,WAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,YAAa,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;"}
|
|
@@ -19,8 +19,10 @@ const createTaxIdSuperRefinement = ({
|
|
|
19
19
|
taxId
|
|
20
20
|
}, ctx) => {
|
|
21
21
|
switch (addressUsageType) {
|
|
22
|
+
// Exit early because tax ID is generally not needed for billing addresses.
|
|
22
23
|
case constants.AddressUsageType.Billing:
|
|
23
24
|
return;
|
|
25
|
+
// Don't do anything and proceed with the validation logic below.
|
|
24
26
|
case constants.AddressUsageType.ReturnShipping:
|
|
25
27
|
case constants.AddressUsageType.Shipping:
|
|
26
28
|
break;
|