@ubnt/store.core 9.11.1 → 9.12.0-alpha.1
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 +59 -2
- package/lib/_virtual/_virtual_multi-entry.js +15 -2
- package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
- package/lib/_virtual/_virtual_multi-entry.mjs +2 -0
- package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
- package/lib/assets/ai360.jpg +0 -0
- package/lib/assets/attention.svg +5 -5
- package/lib/assets/attention2.svg +5 -5
- package/lib/assets/check2.svg +3 -3
- package/lib/assets/check3.svg +3 -3
- package/lib/assets/close2.svg +3 -2
- package/lib/assets/close3.svg +2 -3
- package/lib/assets/g5-ptz.jpg +0 -0
- package/lib/assets/g5Ptz.jpg +0 -0
- package/lib/assets/keyFeatures/music.svg +3 -0
- package/lib/{components/Explore/assets/ProAV.jpg.js → assets/keyFeatures/music.svg.js} +6 -6
- package/lib/assets/keyFeatures/music.svg.js.map +1 -0
- package/lib/assets/keyFeatures/music.svg.mjs +3 -0
- package/lib/assets/keyFeatures/music.svg.mjs.map +1 -0
- package/lib/assets/minus4.svg +8 -8
- package/lib/assets/minus5.svg +8 -8
- package/lib/assets/music.svg +3 -0
- package/lib/assets/pause.svg +3 -3
- package/lib/assets/pause2.svg +3 -3
- package/lib/assets/plus5.svg +9 -9
- package/lib/assets/plus6.svg +9 -9
- package/lib/assets/powerAmp.jpg +0 -0
- package/lib/assets/powerAmp.svg +3 -0
- package/lib/assets/ucgMax.jpg +0 -0
- package/lib/assets/ucgMax2.jpg +0 -0
- package/lib/assets/ucgUltra.jpg +0 -0
- package/lib/assets/ucgUltra2.jpg +0 -0
- package/lib/assets/udr.jpg +0 -0
- package/lib/assets/udr2.jpg +0 -0
- package/lib/assets/udw.jpg +0 -0
- package/lib/assets/udw2.jpg +0 -0
- package/lib/assets/umr.jpg +0 -0
- package/lib/assets/umr2.jpg +0 -0
- package/lib/assets/wideAngle.jpg +0 -0
- package/lib/components/Explore/Explore.js +2 -9
- package/lib/components/Explore/Explore.js.map +1 -1
- package/lib/components/Explore/Explore.mjs +2 -9
- package/lib/components/Explore/Explore.mjs.map +1 -1
- package/lib/components/Explore/ExploreData.d.ts +4 -7
- package/lib/components/Explore/ExploreData.js +79 -139
- package/lib/components/Explore/ExploreData.js.map +1 -1
- package/lib/components/Explore/ExploreData.mjs +71 -129
- package/lib/components/Explore/ExploreData.mjs.map +1 -1
- package/lib/components/Explore/assets/UISPConsole.jpg.js +5 -5
- package/lib/components/Explore/assets/{baseStation-mobile.jpg.js → baseStation--mobile.jpg.js} +6 -6
- package/lib/components/Explore/assets/baseStation--mobile.jpg.js.map +1 -0
- package/lib/components/Explore/assets/baseStation--mobile.jpg.mjs +3 -0
- package/lib/components/Explore/assets/baseStation--mobile.jpg.mjs.map +1 -0
- package/lib/components/Explore/assets/baseStation.jpg.js +5 -5
- package/lib/components/Explore/assets/{g4-ptz.jpg.js → g4Ptz.jpg.js} +2 -2
- package/lib/components/Explore/assets/g4Ptz.jpg.js.map +1 -0
- package/lib/components/Explore/assets/g4Ptz.jpg.mjs +3 -0
- package/lib/components/Explore/assets/g4Ptz.jpg.mjs.map +1 -0
- package/lib/components/Explore/assets/{g5-ptz.jpg.js → g5Ptz.jpg.js} +2 -2
- package/lib/components/Explore/assets/g5Ptz.jpg.js.map +1 -0
- package/lib/components/Explore/assets/g5Ptz.jpg.mjs +3 -0
- package/lib/components/Explore/assets/g5Ptz.jpg.mjs.map +1 -0
- package/lib/components/Explore/assets/{AITheta.jpg.js → powerAmp.jpg.js} +6 -6
- package/lib/components/Explore/assets/powerAmp.jpg.js.map +1 -0
- package/lib/components/Explore/assets/powerAmp.jpg.mjs +3 -0
- package/lib/components/Explore/assets/powerAmp.jpg.mjs.map +1 -0
- package/lib/components/Explore/{LensCompare/assets/ai360.jpg.js → assets/udr.jpg.js} +6 -6
- package/lib/components/Explore/assets/udr.jpg.js.map +1 -0
- package/lib/components/Explore/assets/udr.jpg.mjs +3 -0
- package/lib/components/Explore/assets/udr.jpg.mjs.map +1 -0
- package/lib/components/Explore/assets/udw.jpg.js +27 -0
- package/lib/components/Explore/assets/udw.jpg.js.map +1 -0
- package/lib/components/Explore/assets/udw.jpg.mjs +3 -0
- package/lib/components/Explore/assets/udw.jpg.mjs.map +1 -0
- package/lib/components/Explore/assets/umr.jpg.js +27 -0
- package/lib/components/Explore/assets/umr.jpg.js.map +1 -0
- package/lib/components/Explore/assets/umr.jpg.mjs +3 -0
- package/lib/components/Explore/assets/umr.jpg.mjs.map +1 -0
- package/lib/components/Explore/assets/ux.jpg.js +27 -0
- package/lib/components/Explore/assets/ux.jpg.js.map +1 -0
- package/lib/components/Explore/assets/ux.jpg.mjs +3 -0
- package/lib/components/Explore/assets/ux.jpg.mjs.map +1 -0
- package/lib/components/Explore/translations/en.json.js +8 -30
- package/lib/components/Explore/translations/en.json.js.map +1 -1
- package/lib/components/Explore/translations/en.json.mjs +9 -30
- package/lib/components/Explore/translations/en.json.mjs.map +1 -1
- package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
- package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
- package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
- package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
- package/lib/components/Header/ProHeader/ProHeader.js +19 -2
- package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.mjs +19 -2
- package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +1 -0
- package/lib/components/Header/ProHeader/ProHeader.styles.js +6 -0
- package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.styles.mjs +6 -0
- package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
- package/lib/components/LandingPagePro/LandingPagePro.d.ts +3 -0
- 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/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
- package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
- package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
- package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
- package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.js +1 -1
- package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.mjs +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udw.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udw.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Interior/ai360.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Interior/ai360.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Interior/wideAngle.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Interior/wideAngle.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/MobileRouters/umr.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/MobileRouters/umr.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/PTZ/g5-ptz.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/PTZ/g5-ptz.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/check.svg.js +1 -1
- package/lib/components/ModelCompareV3/assets/check.svg.mjs +2 -2
- package/lib/components/ModelCompareV3/data/CloudGateways.js +8 -8
- package/lib/components/ModelCompareV3/data/CloudGateways.mjs +6 -6
- package/lib/components/ModelCompareV3/data/products/g5Ptz.js +1 -1
- package/lib/components/ModelCompareV3/data/products/g5Ptz.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/theta360.js +1 -1
- package/lib/components/ModelCompareV3/data/products/theta360.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/thetaWideAngle.js +1 -1
- package/lib/components/ModelCompareV3/data/products/thetaWideAngle.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/udr.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udr.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/udw.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udw.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/umr.js +1 -1
- package/lib/components/ModelCompareV3/data/products/umr.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +6 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +6 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +2 -0
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +2 -0
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
- package/lib/components/Tooltip/Tooltip.d.ts +2 -0
- package/lib/components/Tooltip/Tooltip.js +45 -0
- package/lib/components/Tooltip/Tooltip.js.map +1 -0
- package/lib/components/Tooltip/Tooltip.mjs +43 -0
- package/lib/components/Tooltip/Tooltip.mjs.map +1 -0
- package/lib/components/Tooltip/Tooltip.styles.d.ts +32 -0
- package/lib/components/Tooltip/Tooltip.styles.js +44 -0
- package/lib/components/Tooltip/Tooltip.styles.js.map +1 -0
- package/lib/components/Tooltip/Tooltip.styles.mjs +34 -0
- package/lib/components/Tooltip/Tooltip.styles.mjs.map +1 -0
- package/lib/components/Tooltip/index.d.ts +1 -0
- package/lib/components/Tooltip/index.js +6 -0
- package/lib/components/Tooltip/index.js.map +1 -0
- package/lib/components/Tooltip/index.mjs +3 -0
- package/lib/components/Tooltip/index.mjs.map +1 -0
- package/lib/components/VariantSelector/CheckBox/CheckBox.js +1 -1
- package/lib/components/VariantSelector/CheckBox/CheckBox.mjs +1 -1
- package/lib/components/VariantSelector/CheckBox/assets/check.svg.js +1 -1
- package/lib/components/VariantSelector/CheckBox/assets/check.svg.mjs +2 -2
- package/lib/components/VideoPlayerNew/VideoPlayer.js +2 -2
- package/lib/components/VideoPlayerNew/VideoPlayer.mjs +2 -2
- package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
- package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
- package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
- package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
- package/lib/constants/icons/menu/index.d.ts +1 -0
- package/lib/constants/icons/menu/index.js +9 -0
- package/lib/constants/icons/menu/index.js.map +1 -1
- package/lib/constants/icons/menu/index.mjs +2 -0
- package/lib/constants/icons/menu/index.mjs.map +1 -1
- package/lib/{components/Explore/assets/MobileR.jpg.js → constants/icons/menu/powerAmp.svg.js} +6 -6
- package/lib/constants/icons/menu/powerAmp.svg.js.map +1 -0
- package/lib/constants/icons/menu/powerAmp.svg.mjs +3 -0
- package/lib/constants/icons/menu/powerAmp.svg.mjs.map +1 -0
- package/lib/constants/keyFeatureIcons.d.ts +1 -0
- package/lib/constants/keyFeatureIcons.js +3 -0
- package/lib/constants/keyFeatureIcons.js.map +1 -1
- package/lib/constants/keyFeatureIcons.mjs +3 -0
- package/lib/constants/keyFeatureIcons.mjs.map +1 -1
- package/lib/constants/proStoreCategories/mapping/index.d.ts +1 -0
- package/lib/constants/proStoreCategories/mapping/index.js +13 -8
- package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
- package/lib/constants/proStoreCategories/mapping/index.mjs +13 -8
- package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
- package/lib/constants/proStoreCategories/mapping/unifi.d.ts +2 -1
- package/lib/constants/proStoreCategories/mapping/unifi.js +1 -0
- package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
- package/lib/constants/proStoreCategories/mapping/unifi.mjs +1 -0
- package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/en.json.js +3 -0
- package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/en.json.mjs +3 -1
- 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/shopify/keyFeatureIcons.js +4 -0
- package/lib/constants/shopify/keyFeatureIcons.js.map +1 -1
- package/lib/constants/shopify/keyFeatureIcons.mjs +3 -0
- package/lib/constants/shopify/keyFeatureIcons.mjs.map +1 -1
- package/lib/contexts/MenuContext/mapping.js +20 -11
- package/lib/contexts/MenuContext/mapping.js.map +1 -1
- package/lib/contexts/MenuContext/mapping.mjs +19 -11
- package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
- package/lib/helpers/index.d.ts +1 -0
- package/lib/helpers/index.js +11 -0
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/index.mjs +1 -0
- package/lib/helpers/index.mjs.map +1 -1
- package/lib/helpers/product.d.ts +87 -0
- package/lib/helpers/product.js +346 -0
- package/lib/helpers/product.js.map +1 -0
- package/lib/helpers/product.mjs +335 -0
- package/lib/helpers/product.mjs.map +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +2 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/index.mjs +1 -0
- package/lib/types/index.mjs.map +1 -1
- package/lib/types/product.d.ts +87 -0
- package/lib/types/product.js +14 -0
- package/lib/types/product.js.map +1 -0
- package/lib/types/product.mjs +13 -0
- package/lib/types/product.mjs.map +1 -0
- package/lib/utils/array.d.ts +4 -0
- package/lib/utils/array.js +10 -0
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/array.mjs +10 -1
- package/lib/utils/array.mjs.map +1 -1
- package/lib/utils/money/allocators/fixedAmount.d.ts +26 -0
- package/lib/utils/money/allocators/fixedAmount.js +55 -0
- package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
- package/lib/utils/money/allocators/fixedAmount.mjs +53 -0
- package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
- package/lib/utils/money/allocators/index.d.ts +2 -0
- package/lib/utils/money/allocators/index.js +8 -0
- package/lib/utils/money/allocators/index.js.map +1 -0
- package/lib/utils/money/allocators/index.mjs +4 -0
- package/lib/utils/money/allocators/index.mjs.map +1 -0
- package/lib/utils/money/allocators/productAmount.d.ts +13 -0
- package/lib/utils/money/allocators/productAmount.js +110 -0
- package/lib/utils/money/allocators/productAmount.js.map +1 -0
- package/lib/utils/money/allocators/productAmount.mjs +108 -0
- package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
- package/lib/utils/money/constants.d.ts +56 -25
- package/lib/utils/money/constants.js +72 -7
- package/lib/utils/money/constants.js.map +1 -1
- package/lib/utils/money/constants.mjs +70 -7
- package/lib/utils/money/constants.mjs.map +1 -1
- package/lib/utils/money/exchangeRate.d.ts +31 -0
- package/lib/utils/money/exchangeRate.js +27 -0
- package/lib/utils/money/exchangeRate.js.map +1 -0
- package/lib/utils/money/exchangeRate.mjs +23 -0
- package/lib/utils/money/exchangeRate.mjs.map +1 -0
- package/lib/utils/money/format.d.ts +10 -5
- package/lib/utils/money/format.js +22 -14
- package/lib/utils/money/format.js.map +1 -1
- package/lib/utils/money/format.mjs +23 -16
- package/lib/utils/money/format.mjs.map +1 -1
- package/lib/utils/money/index.d.ts +4 -1
- package/lib/utils/money/index.js +26 -8
- package/lib/utils/money/index.js.map +1 -1
- package/lib/utils/money/index.mjs +8 -4
- package/lib/utils/money/index.mjs.map +1 -1
- package/lib/utils/money/misc.d.ts +68 -28
- package/lib/utils/money/misc.js +35 -64
- package/lib/utils/money/misc.js.map +1 -1
- package/lib/utils/money/misc.mjs +32 -43
- package/lib/utils/money/misc.mjs.map +1 -1
- package/lib/utils/money/misc.private.d.ts +23 -0
- package/lib/utils/money/misc.private.js +46 -0
- package/lib/utils/money/misc.private.js.map +1 -0
- package/lib/utils/money/misc.private.mjs +21 -0
- package/lib/utils/money/misc.private.mjs.map +1 -0
- package/lib/utils/money/shipping.d.ts +5 -0
- package/lib/utils/money/shipping.js +8 -0
- package/lib/utils/money/shipping.js.map +1 -0
- package/lib/utils/money/shipping.mjs +6 -0
- package/lib/utils/money/shipping.mjs.map +1 -0
- package/lib/utils/money/tax.d.ts +38 -2
- package/lib/utils/money/tax.js +46 -10
- package/lib/utils/money/tax.js.map +1 -1
- package/lib/utils/money/tax.mjs +42 -11
- package/lib/utils/money/tax.mjs.map +1 -1
- package/lib/utils/money/tax.private.d.ts +17 -0
- package/lib/utils/money/tax.private.js +65 -0
- package/lib/utils/money/tax.private.js.map +1 -0
- package/lib/utils/money/tax.private.mjs +60 -0
- package/lib/utils/money/tax.private.mjs.map +1 -0
- package/lib/utils/money/types.d.ts +78 -3
- 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/productSort.d.ts +41 -0
- package/lib/utils/productSort.js +66 -0
- package/lib/utils/productSort.js.map +1 -0
- package/lib/utils/productSort.mjs +59 -0
- package/lib/utils/productSort.mjs.map +1 -0
- package/package.json +53 -53
- package/lib/assets/AITheta.jpg +0 -0
- package/lib/assets/MobileR.jpg +0 -0
- package/lib/assets/ProAV.jpg +0 -0
- package/lib/assets/ai3602.jpg +0 -0
- package/lib/assets/cloudgatewayultra.jpg +0 -0
- package/lib/assets/dreamRouter.jpg +0 -0
- package/lib/assets/dreamWall.jpg +0 -0
- package/lib/assets/g5-ptz2.jpg +0 -0
- package/lib/assets/wideAngle2.jpg +0 -0
- package/lib/components/Explore/LensCompare/LensCompare.d.ts +0 -2
- package/lib/components/Explore/LensCompare/LensCompare.js +0 -111
- package/lib/components/Explore/LensCompare/LensCompare.js.map +0 -1
- package/lib/components/Explore/LensCompare/LensCompare.mjs +0 -109
- package/lib/components/Explore/LensCompare/LensCompare.mjs.map +0 -1
- package/lib/components/Explore/LensCompare/LensCompare.styles.d.ts +0 -16
- package/lib/components/Explore/LensCompare/LensCompare.styles.js +0 -153
- package/lib/components/Explore/LensCompare/LensCompare.styles.js.map +0 -1
- package/lib/components/Explore/LensCompare/LensCompare.styles.mjs +0 -132
- package/lib/components/Explore/LensCompare/LensCompare.styles.mjs.map +0 -1
- package/lib/components/Explore/LensCompare/LensCompare.types.d.ts +0 -9
- package/lib/components/Explore/LensCompare/LensCompare.utils.d.ts +0 -2
- package/lib/components/Explore/LensCompare/LensCompare.utils.js +0 -23
- package/lib/components/Explore/LensCompare/LensCompare.utils.js.map +0 -1
- package/lib/components/Explore/LensCompare/LensCompare.utils.mjs +0 -21
- package/lib/components/Explore/LensCompare/LensCompare.utils.mjs.map +0 -1
- package/lib/components/Explore/LensCompare/LensCompareData.d.ts +0 -29
- package/lib/components/Explore/LensCompare/LensCompareData.js +0 -68
- package/lib/components/Explore/LensCompare/LensCompareData.js.map +0 -1
- package/lib/components/Explore/LensCompare/LensCompareData.mjs +0 -58
- package/lib/components/Explore/LensCompare/LensCompareData.mjs.map +0 -1
- package/lib/components/Explore/LensCompare/assets/ai360.jpg.js.map +0 -1
- package/lib/components/Explore/LensCompare/assets/ai360.jpg.mjs +0 -3
- package/lib/components/Explore/LensCompare/assets/ai360.jpg.mjs.map +0 -1
- package/lib/components/Explore/LensCompare/assets/wideAngle.jpg.js +0 -27
- package/lib/components/Explore/LensCompare/assets/wideAngle.jpg.js.map +0 -1
- package/lib/components/Explore/LensCompare/assets/wideAngle.jpg.mjs +0 -3
- package/lib/components/Explore/LensCompare/assets/wideAngle.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/AITheta.jpg.js.map +0 -1
- package/lib/components/Explore/assets/AITheta.jpg.mjs +0 -3
- package/lib/components/Explore/assets/AITheta.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/MobileR.jpg.js.map +0 -1
- package/lib/components/Explore/assets/MobileR.jpg.mjs +0 -3
- package/lib/components/Explore/assets/MobileR.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/ProAV.jpg.js.map +0 -1
- package/lib/components/Explore/assets/ProAV.jpg.mjs +0 -3
- package/lib/components/Explore/assets/ProAV.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/baseStation-mobile.jpg.js.map +0 -1
- package/lib/components/Explore/assets/baseStation-mobile.jpg.mjs +0 -3
- package/lib/components/Explore/assets/baseStation-mobile.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/cloudgatewayultra.jpg.js +0 -27
- package/lib/components/Explore/assets/cloudgatewayultra.jpg.js.map +0 -1
- package/lib/components/Explore/assets/cloudgatewayultra.jpg.mjs +0 -3
- package/lib/components/Explore/assets/cloudgatewayultra.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/dreamRouter.jpg.js +0 -27
- package/lib/components/Explore/assets/dreamRouter.jpg.js.map +0 -1
- package/lib/components/Explore/assets/dreamRouter.jpg.mjs +0 -3
- package/lib/components/Explore/assets/dreamRouter.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/dreamWall.jpg.js +0 -27
- package/lib/components/Explore/assets/dreamWall.jpg.js.map +0 -1
- package/lib/components/Explore/assets/dreamWall.jpg.mjs +0 -3
- package/lib/components/Explore/assets/dreamWall.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/g4-ptz.jpg.js.map +0 -1
- package/lib/components/Explore/assets/g4-ptz.jpg.mjs +0 -3
- package/lib/components/Explore/assets/g4-ptz.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/g5-ptz.jpg.js.map +0 -1
- package/lib/components/Explore/assets/g5-ptz.jpg.mjs +0 -3
- package/lib/components/Explore/assets/g5-ptz.jpg.mjs.map +0 -1
- package/lib/components/Explore/assets/unifiExpress.jpg.js +0 -27
- package/lib/components/Explore/assets/unifiExpress.jpg.js.map +0 -1
- package/lib/components/Explore/assets/unifiExpress.jpg.mjs +0 -3
- package/lib/components/Explore/assets/unifiExpress.jpg.mjs.map +0 -1
- package/lib/utils/validations.d.ts +0 -15
- package/lib/utils/validations.js +0 -23
- package/lib/utils/validations.js.map +0 -1
- package/lib/utils/validations.mjs +0 -21
- package/lib/utils/validations.mjs.map +0 -1
- /package/lib/assets/{baseStation-mobile.jpg → baseStation--mobile.jpg} +0 -0
- /package/lib/assets/{g4-ptz.jpg → g4Ptz.jpg} +0 -0
- /package/lib/assets/{unifiExpress.jpg → ux.jpg} +0 -0
package/lib/utils/array.mjs
CHANGED
|
@@ -22,5 +22,14 @@ const arraySafeIndexFind = (array, index) => {
|
|
|
22
22
|
return array[safeIndex];
|
|
23
23
|
};
|
|
24
24
|
const normalizeSortResult = sortResult => clamp(sortResult, -1, 1);
|
|
25
|
-
|
|
25
|
+
const combineSorts = sorts => (a, b) => {
|
|
26
|
+
for (const sort of sorts) {
|
|
27
|
+
const result = sort(a, b);
|
|
28
|
+
if (result !== 0) {
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return 0;
|
|
33
|
+
};
|
|
34
|
+
export { areEqualArrays, arraySafeIndex, arraySafeIndexFind, combineSorts, dedupe, ensureArray, normalizeSortResult };
|
|
26
35
|
//# sourceMappingURL=array.mjs.map
|
package/lib/utils/array.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;"}
|
|
1
|
+
{"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Combine multiple sort functions into one\n */\nexport const combineSorts =\n <T>(sorts: ((a: T, b: T) => number)[]): ((a: T, b: T) => number) =>\n (a, b) => {\n for (const sort of sorts) {\n const result = sort(a, b);\n\n if (result !== 0) {\n return result;\n }\n }\n\n return 0;\n };\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","combineSorts","sorts","sort","result"],"mappings":";;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;AAKlB,MAAME,YACX,GAAIC,KACJ,IAAA,CAAChB,GAAGC,CAAM,KAAA;EACR,KAAA,MAAWgB,QAAQD,KAAO,EAAA;IAClB,MAAAE,MAAA,GAASD,IAAK,CAAAjB,CAAA,EAAGC,CAAC,CAAA;IAExB,IAAIiB,WAAW,CAAG,EAAA;MACT,OAAAA,MAAA;IACT;EACF;EAEO,OAAA,CAAA;AACT,CAAA;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Currency } from "../../../types";
|
|
2
|
+
import type { Cents, Dino, DinoCurrency } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Helper class to distribute a fixed amount (e.g. discount) between multiple items.
|
|
5
|
+
* For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible
|
|
6
|
+
*/
|
|
7
|
+
export declare class FixedAmountAllocator {
|
|
8
|
+
/**
|
|
9
|
+
* How much we have left to allocate for given allocation from the remaining total
|
|
10
|
+
*/
|
|
11
|
+
remainingAllocationAmount: Dino;
|
|
12
|
+
/**
|
|
13
|
+
* How much we have left to allocate in total
|
|
14
|
+
*/
|
|
15
|
+
remainingTotalAmount: Dino;
|
|
16
|
+
currency: DinoCurrency;
|
|
17
|
+
constructor({ initialAllocateAmount, initialTotalAmount, currency, }: {
|
|
18
|
+
initialAllocateAmount: Cents;
|
|
19
|
+
initialTotalAmount: Cents;
|
|
20
|
+
currency: Currency;
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* We always allocate biggest share to first item
|
|
24
|
+
*/
|
|
25
|
+
allocate(lineItemTotal: Cents, currency: Currency): Dino;
|
|
26
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dinero_js = require('dinero.js');
|
|
4
|
+
var errors = require('../../errors.js');
|
|
5
|
+
var misc = require('../misc.js');
|
|
6
|
+
"use strict";
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value
|
|
13
|
+
}) : obj[key] = value;
|
|
14
|
+
var __publicField = (obj, key, value) => {
|
|
15
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
class FixedAmountAllocator {
|
|
19
|
+
constructor({
|
|
20
|
+
initialAllocateAmount,
|
|
21
|
+
initialTotalAmount,
|
|
22
|
+
currency
|
|
23
|
+
}) {
|
|
24
|
+
/**
|
|
25
|
+
* How much we have left to allocate for given allocation from the remaining total
|
|
26
|
+
*/
|
|
27
|
+
__publicField(this, "remainingAllocationAmount");
|
|
28
|
+
/**
|
|
29
|
+
* How much we have left to allocate in total
|
|
30
|
+
*/
|
|
31
|
+
__publicField(this, "remainingTotalAmount");
|
|
32
|
+
__publicField(this, "currency");
|
|
33
|
+
this.remainingAllocationAmount = misc.getDinero(initialAllocateAmount, currency);
|
|
34
|
+
this.remainingTotalAmount = misc.getDinero(initialTotalAmount, currency);
|
|
35
|
+
this.currency = misc.getDineroCurrency(currency);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* We always allocate biggest share to first item
|
|
39
|
+
*/
|
|
40
|
+
allocate(lineItemTotal, currency) {
|
|
41
|
+
errors.assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
|
|
42
|
+
const lineItemTotalDinero = misc.getDinero(lineItemTotal, currency);
|
|
43
|
+
if (lineItemTotal === 0) {
|
|
44
|
+
return lineItemTotalDinero;
|
|
45
|
+
}
|
|
46
|
+
const [allocationAmount, remainingAllocationAmount] = dinero_js.allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(misc.amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
|
|
47
|
+
errors.assert(!!allocationAmount, "Allocation amount is zero");
|
|
48
|
+
errors.assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
|
|
49
|
+
this.remainingAllocationAmount = remainingAllocationAmount;
|
|
50
|
+
this.remainingTotalAmount = dinero_js.subtract(this.remainingTotalAmount, lineItemTotalDinero);
|
|
51
|
+
return dinero_js.greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.FixedAmountAllocator = FixedAmountAllocator;
|
|
55
|
+
//# sourceMappingURL=fixedAmount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixedAmount.js","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","constructor","initialAllocateAmount","initialTotalAmount","currency","__publicField","remainingAllocationAmount","getDinero","remainingTotalAmount","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;;;;;;;;;;;;AAWO,MAAMA,oBAAqB,CAAA;EAWhCC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAC;EAAA,CAKC,EAAA;IAfH;AAAA;AAAA;IAAOC,aAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;IAIP;AAAA;AAAA;IAAOA,aAAA,CAAA,IAAA,EAAA,sBAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAWA,IAAA,CAAAC,yBAAA,GAA4BC,IAAAA,CAAAA,SAAU,CAAAL,qBAAA,EAAuBE,QAAQ,CAAA;IACrE,IAAA,CAAAI,oBAAA,GAAuBD,IAAAA,CAAAA,SAAU,CAAAJ,kBAAA,EAAoBC,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,uBAAkBL,QAAQ,CAAA;EAC5C;EAAA;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CAAAA,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACQ,+BAAAA,QAAiB,SAAA,IAAA,CAAKA,SAASS,IAAI,EAAA,CACpE;IACM,MAAAC,mBAAA,GAAsBP,IAAAA,CAAAA,SAAU,CAAAI,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IACT;IAEM,MAAA,CAACC,gBAAkB,EAAAT,yBAAyB,CAAI,GAAAI,SAAA,CAAAA,QAAA,CACpD,IAAK,CAAAJ,yBAAA,EACL,CACEK,aAAA,EACAK,KAAKC,GAAI,CAAAC,WAAA,CAAO,KAAKV,oBAAoB,CAAA,GAAIG,eAAe,CAAC,CAAA,CAC/D,CACF;IAEOC,MAAAA,CAAAA,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CAAAA,MAAA,CACE,CAAC,CAACN,yBAAA,EACF,wCAAA,CACF;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKE,oBAAuB,GAAAW,SAAA,CAAAA,QAAA,CAC1B,IAAK,CAAAX,oBAAA,EACLM,mBAAA,CACF;IAMA,OAAOM,SAAY,CAAAA,WAAA,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EACN;AACF;"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { allocate, subtract, greaterThan } from 'dinero.js';
|
|
2
|
+
import { assert } from '../../errors.mjs';
|
|
3
|
+
import { getDinero, getDineroCurrency, amount } from '../misc.mjs';
|
|
4
|
+
"use strict";
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value
|
|
11
|
+
}) : obj[key] = value;
|
|
12
|
+
var __publicField = (obj, key, value) => {
|
|
13
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
class FixedAmountAllocator {
|
|
17
|
+
constructor({
|
|
18
|
+
initialAllocateAmount,
|
|
19
|
+
initialTotalAmount,
|
|
20
|
+
currency
|
|
21
|
+
}) {
|
|
22
|
+
/**
|
|
23
|
+
* How much we have left to allocate for given allocation from the remaining total
|
|
24
|
+
*/
|
|
25
|
+
__publicField(this, "remainingAllocationAmount");
|
|
26
|
+
/**
|
|
27
|
+
* How much we have left to allocate in total
|
|
28
|
+
*/
|
|
29
|
+
__publicField(this, "remainingTotalAmount");
|
|
30
|
+
__publicField(this, "currency");
|
|
31
|
+
this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);
|
|
32
|
+
this.remainingTotalAmount = getDinero(initialTotalAmount, currency);
|
|
33
|
+
this.currency = getDineroCurrency(currency);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* We always allocate biggest share to first item
|
|
37
|
+
*/
|
|
38
|
+
allocate(lineItemTotal, currency) {
|
|
39
|
+
assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
|
|
40
|
+
const lineItemTotalDinero = getDinero(lineItemTotal, currency);
|
|
41
|
+
if (lineItemTotal === 0) {
|
|
42
|
+
return lineItemTotalDinero;
|
|
43
|
+
}
|
|
44
|
+
const [allocationAmount, remainingAllocationAmount] = allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
|
|
45
|
+
assert(!!allocationAmount, "Allocation amount is zero");
|
|
46
|
+
assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
|
|
47
|
+
this.remainingAllocationAmount = remainingAllocationAmount;
|
|
48
|
+
this.remainingTotalAmount = subtract(this.remainingTotalAmount, lineItemTotalDinero);
|
|
49
|
+
return greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export { FixedAmountAllocator };
|
|
53
|
+
//# sourceMappingURL=fixedAmount.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixedAmount.mjs","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","constructor","initialAllocateAmount","initialTotalAmount","currency","__publicField","remainingAllocationAmount","getDinero","remainingTotalAmount","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;;;;;;;;;;AAWO,MAAMA,oBAAqB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OM,WAAY,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EACN;AACF;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fixedAmount = require('./fixedAmount.js');
|
|
4
|
+
var productAmount = require('./productAmount.js');
|
|
5
|
+
"use strict";
|
|
6
|
+
exports.FixedAmountAllocator = fixedAmount.FixedAmountAllocator;
|
|
7
|
+
exports.ProductAmountAllocator = productAmount.ProductAmountAllocator;
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FullLineItemSummary } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Helper class to distribute a total amount for a product
|
|
4
|
+
*/
|
|
5
|
+
export declare class ProductAmountAllocator {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Remaining quantity to allocate
|
|
9
|
+
*/
|
|
10
|
+
quantity: number;
|
|
11
|
+
constructor(productSummary: FullLineItemSummary);
|
|
12
|
+
allocateQty(quantity: number): FullLineItemSummary;
|
|
13
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var misc = require('../misc.js');
|
|
4
|
+
var fixedAmount = require('./fixedAmount.js');
|
|
5
|
+
"use strict";
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value
|
|
12
|
+
}) : obj[key] = value;
|
|
13
|
+
var __publicField = (obj, key, value) => {
|
|
14
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
var __accessCheck = (obj, member, msg) => {
|
|
18
|
+
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
19
|
+
};
|
|
20
|
+
var __privateGet = (obj, member, getter) => {
|
|
21
|
+
__accessCheck(obj, member, "read from private field");
|
|
22
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
23
|
+
};
|
|
24
|
+
var __privateAdd = (obj, member, value) => {
|
|
25
|
+
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
26
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
27
|
+
};
|
|
28
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
29
|
+
__accessCheck(obj, member, "write to private field");
|
|
30
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
|
|
34
|
+
class ProductAmountAllocator {
|
|
35
|
+
constructor(productSummary) {
|
|
36
|
+
// #############################################################################
|
|
37
|
+
// Fixed values
|
|
38
|
+
// #############################################################################
|
|
39
|
+
__privateAdd(this, _itemPrice, void 0);
|
|
40
|
+
__privateAdd(this, _currency, void 0);
|
|
41
|
+
// #############################################################################
|
|
42
|
+
/**
|
|
43
|
+
* Remaining quantity to allocate
|
|
44
|
+
*/
|
|
45
|
+
__publicField(this, "quantity");
|
|
46
|
+
// #############################################################################
|
|
47
|
+
// Specific amount allocators
|
|
48
|
+
// #############################################################################
|
|
49
|
+
__privateAdd(this, _subtotal, void 0);
|
|
50
|
+
__privateAdd(this, _discountAmount, void 0);
|
|
51
|
+
__privateAdd(this, _taxableAmount, void 0);
|
|
52
|
+
__privateAdd(this, _tax, void 0);
|
|
53
|
+
__privateAdd(this, _total, void 0);
|
|
54
|
+
const currency = productSummary.currency;
|
|
55
|
+
const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
|
|
56
|
+
__privateSet(this, _itemPrice, productSummary.itemPrice);
|
|
57
|
+
__privateSet(this, _currency, currency);
|
|
58
|
+
this.quantity = productSummary.quantity;
|
|
59
|
+
__privateSet(this, _subtotal, new fixedAmount.FixedAmountAllocator({
|
|
60
|
+
initialAllocateAmount: productSummary.subtotal,
|
|
61
|
+
initialTotalAmount: priceForAllocation,
|
|
62
|
+
currency
|
|
63
|
+
}));
|
|
64
|
+
__privateSet(this, _discountAmount, new fixedAmount.FixedAmountAllocator({
|
|
65
|
+
initialAllocateAmount: productSummary.discountAmount,
|
|
66
|
+
initialTotalAmount: priceForAllocation,
|
|
67
|
+
currency
|
|
68
|
+
}));
|
|
69
|
+
__privateSet(this, _taxableAmount, new fixedAmount.FixedAmountAllocator({
|
|
70
|
+
initialAllocateAmount: productSummary.taxableAmount,
|
|
71
|
+
initialTotalAmount: priceForAllocation,
|
|
72
|
+
currency
|
|
73
|
+
}));
|
|
74
|
+
__privateSet(this, _tax, new fixedAmount.FixedAmountAllocator({
|
|
75
|
+
initialAllocateAmount: productSummary.tax,
|
|
76
|
+
initialTotalAmount: priceForAllocation,
|
|
77
|
+
currency
|
|
78
|
+
}));
|
|
79
|
+
__privateSet(this, _total, new fixedAmount.FixedAmountAllocator({
|
|
80
|
+
initialAllocateAmount: productSummary.total,
|
|
81
|
+
initialTotalAmount: priceForAllocation,
|
|
82
|
+
currency
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
allocateQty(quantity) {
|
|
86
|
+
let quantityNormalized = Math.max(quantity, 0);
|
|
87
|
+
quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;
|
|
88
|
+
this.quantity = Math.max(this.quantity - quantityNormalized, 0);
|
|
89
|
+
const itemQuantityPrice = __privateGet(this, _itemPrice) * quantityNormalized;
|
|
90
|
+
return {
|
|
91
|
+
itemPrice: __privateGet(this, _itemPrice),
|
|
92
|
+
currency: __privateGet(this, _currency),
|
|
93
|
+
quantity: quantityNormalized,
|
|
94
|
+
subtotal: misc.amount(__privateGet(this, _subtotal).allocate(itemQuantityPrice, __privateGet(this, _currency))),
|
|
95
|
+
discountAmount: misc.amount(__privateGet(this, _discountAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
|
|
96
|
+
taxableAmount: misc.amount(__privateGet(this, _taxableAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
|
|
97
|
+
tax: misc.amount(__privateGet(this, _tax).allocate(itemQuantityPrice, __privateGet(this, _currency))),
|
|
98
|
+
total: misc.amount(__privateGet(this, _total).allocate(itemQuantityPrice, __privateGet(this, _currency)))
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
_itemPrice = new WeakMap();
|
|
103
|
+
_currency = new WeakMap();
|
|
104
|
+
_subtotal = new WeakMap();
|
|
105
|
+
_discountAmount = new WeakMap();
|
|
106
|
+
_taxableAmount = new WeakMap();
|
|
107
|
+
_tax = new WeakMap();
|
|
108
|
+
_total = new WeakMap();
|
|
109
|
+
exports.ProductAmountAllocator = ProductAmountAllocator;
|
|
110
|
+
//# sourceMappingURL=productAmount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"productAmount.js","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAAAC,YAAA,CAAA,IAAA,EAASV,UAAT,EAAA,KAAA,CAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAST,SAAT,EAAA,KAAA,CAAA,CAAA;IAKA;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAIA;IAAA;IAAA;IAAAD,YAAA,CAAA,IAAA,EAAAR,SAAA,EAAA,KAAA,CAAA,CAAA;IACAQ,YAAA,CAAA,IAAA,EAAAP,eAAA,EAAA,KAAA,CAAA,CAAA;IACAO,YAAA,CAAA,IAAA,EAAAN,cAAA,EAAA,KAAA,CAAA,CAAA;IACAM,YAAA,CAAA,IAAA,EAAAL,IAAA,EAAA,KAAA,CAAA,CAAA;IACAK,YAAA,CAAA,IAAA,EAAAJ,MAAA,EAAA,KAAA,CAAA,CAAA;IAGE,MAAMM,WAAWH,cAAe,CAAAG,QAAA;IAK1B,MAAAC,kBAAA,GACJJ,cAAe,CAAAK,SAAA,GAAYL,cAAe,CAAAM,QAAA;IAE5CC,YAAA,CAAA,IAAA,EAAKhB,YAAaS,cAAe,CAAAK,SAAA,CAAA;IACjCE,YAAA,CAAA,IAAA,EAAKf,SAAY,EAAAW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AA,CAAA,CAAA;"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { amount } from '../misc.mjs';
|
|
2
|
+
import { FixedAmountAllocator } from './fixedAmount.mjs';
|
|
3
|
+
"use strict";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value
|
|
10
|
+
}) : obj[key] = value;
|
|
11
|
+
var __publicField = (obj, key, value) => {
|
|
12
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
var __accessCheck = (obj, member, msg) => {
|
|
16
|
+
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
17
|
+
};
|
|
18
|
+
var __privateGet = (obj, member, getter) => {
|
|
19
|
+
__accessCheck(obj, member, "read from private field");
|
|
20
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
21
|
+
};
|
|
22
|
+
var __privateAdd = (obj, member, value) => {
|
|
23
|
+
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
24
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
};
|
|
26
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
27
|
+
__accessCheck(obj, member, "write to private field");
|
|
28
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
29
|
+
return value;
|
|
30
|
+
};
|
|
31
|
+
var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
|
|
32
|
+
class ProductAmountAllocator {
|
|
33
|
+
constructor(productSummary) {
|
|
34
|
+
// #############################################################################
|
|
35
|
+
// Fixed values
|
|
36
|
+
// #############################################################################
|
|
37
|
+
__privateAdd(this, _itemPrice, void 0);
|
|
38
|
+
__privateAdd(this, _currency, void 0);
|
|
39
|
+
// #############################################################################
|
|
40
|
+
/**
|
|
41
|
+
* Remaining quantity to allocate
|
|
42
|
+
*/
|
|
43
|
+
__publicField(this, "quantity");
|
|
44
|
+
// #############################################################################
|
|
45
|
+
// Specific amount allocators
|
|
46
|
+
// #############################################################################
|
|
47
|
+
__privateAdd(this, _subtotal, void 0);
|
|
48
|
+
__privateAdd(this, _discountAmount, void 0);
|
|
49
|
+
__privateAdd(this, _taxableAmount, void 0);
|
|
50
|
+
__privateAdd(this, _tax, void 0);
|
|
51
|
+
__privateAdd(this, _total, void 0);
|
|
52
|
+
const currency = productSummary.currency;
|
|
53
|
+
const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
|
|
54
|
+
__privateSet(this, _itemPrice, productSummary.itemPrice);
|
|
55
|
+
__privateSet(this, _currency, currency);
|
|
56
|
+
this.quantity = productSummary.quantity;
|
|
57
|
+
__privateSet(this, _subtotal, new FixedAmountAllocator({
|
|
58
|
+
initialAllocateAmount: productSummary.subtotal,
|
|
59
|
+
initialTotalAmount: priceForAllocation,
|
|
60
|
+
currency
|
|
61
|
+
}));
|
|
62
|
+
__privateSet(this, _discountAmount, new FixedAmountAllocator({
|
|
63
|
+
initialAllocateAmount: productSummary.discountAmount,
|
|
64
|
+
initialTotalAmount: priceForAllocation,
|
|
65
|
+
currency
|
|
66
|
+
}));
|
|
67
|
+
__privateSet(this, _taxableAmount, new FixedAmountAllocator({
|
|
68
|
+
initialAllocateAmount: productSummary.taxableAmount,
|
|
69
|
+
initialTotalAmount: priceForAllocation,
|
|
70
|
+
currency
|
|
71
|
+
}));
|
|
72
|
+
__privateSet(this, _tax, new FixedAmountAllocator({
|
|
73
|
+
initialAllocateAmount: productSummary.tax,
|
|
74
|
+
initialTotalAmount: priceForAllocation,
|
|
75
|
+
currency
|
|
76
|
+
}));
|
|
77
|
+
__privateSet(this, _total, new FixedAmountAllocator({
|
|
78
|
+
initialAllocateAmount: productSummary.total,
|
|
79
|
+
initialTotalAmount: priceForAllocation,
|
|
80
|
+
currency
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
allocateQty(quantity) {
|
|
84
|
+
let quantityNormalized = Math.max(quantity, 0);
|
|
85
|
+
quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;
|
|
86
|
+
this.quantity = Math.max(this.quantity - quantityNormalized, 0);
|
|
87
|
+
const itemQuantityPrice = __privateGet(this, _itemPrice) * quantityNormalized;
|
|
88
|
+
return {
|
|
89
|
+
itemPrice: __privateGet(this, _itemPrice),
|
|
90
|
+
currency: __privateGet(this, _currency),
|
|
91
|
+
quantity: quantityNormalized,
|
|
92
|
+
subtotal: amount(__privateGet(this, _subtotal).allocate(itemQuantityPrice, __privateGet(this, _currency))),
|
|
93
|
+
discountAmount: amount(__privateGet(this, _discountAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
|
|
94
|
+
taxableAmount: amount(__privateGet(this, _taxableAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
|
|
95
|
+
tax: amount(__privateGet(this, _tax).allocate(itemQuantityPrice, __privateGet(this, _currency))),
|
|
96
|
+
total: amount(__privateGet(this, _total).allocate(itemQuantityPrice, __privateGet(this, _currency)))
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
_itemPrice = new WeakMap();
|
|
101
|
+
_currency = new WeakMap();
|
|
102
|
+
_subtotal = new WeakMap();
|
|
103
|
+
_discountAmount = new WeakMap();
|
|
104
|
+
_taxableAmount = new WeakMap();
|
|
105
|
+
_tax = new WeakMap();
|
|
106
|
+
_total = new WeakMap();
|
|
107
|
+
export { ProductAmountAllocator };
|
|
108
|
+
//# sourceMappingURL=productAmount.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"productAmount.mjs","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAAAC,YAAA,CAAA,IAAA,EAASV,UAAT,EAAA,KAAA,CAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAST,SAAT,EAAA,KAAA,CAAA,CAAA;IAKA;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAIA;IAAA;IAAA;IAAAD,YAAA,CAAA,IAAA,EAAAR,SAAA,EAAA,KAAA,CAAA,CAAA;IACAQ,YAAA,CAAA,IAAA,EAAAP,eAAA,EAAA,KAAA,CAAA,CAAA;IACAO,YAAA,CAAA,IAAA,EAAAN,cAAA,EAAA,KAAA,CAAA,CAAA;IACAM,YAAA,CAAA,IAAA,EAAAL,IAAA,EAAA,KAAA,CAAA,CAAA;IACAK,YAAA,CAAA,IAAA,EA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AA,CAAA;AAST/B,SAAA,GAAA,IAAA+B,OAAA,CAAA,CAAA;AACA9B,eAAA,GAAA,IAAA8B,OAAA,CAAA,CAAA;AACA7B,cAAA,GAAA,IAAA6B,OAAA,CAAA,CAAA;AACA5B,IAAA,GAAA,IAAA4B,OAAA,CAAA,CAAA;AACA3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
|
|
@@ -1,37 +1,68 @@
|
|
|
1
|
-
import { Currency } from "../../types";
|
|
2
|
-
import type {
|
|
1
|
+
import { Currency, StoreId } from "../../types";
|
|
2
|
+
import type { LocalizedCurrency, RoundingFn } from "./types";
|
|
3
|
+
export declare const Round: {
|
|
4
|
+
/**
|
|
5
|
+
* ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
|
|
6
|
+
* deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
|
|
7
|
+
* normalise the values so we use this method.
|
|
8
|
+
*
|
|
9
|
+
* It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
|
|
10
|
+
* @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
|
|
11
|
+
* @see
|
|
12
|
+
*
|
|
13
|
+
* Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
|
|
14
|
+
* number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
|
|
15
|
+
* See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
|
|
16
|
+
* https://youtu.be/yuRdYlZvs1E
|
|
17
|
+
*
|
|
18
|
+
* If you really want to get knee-deep in the rounding subject, you can read the following:
|
|
19
|
+
* https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
|
|
20
|
+
*/
|
|
21
|
+
Financial: import("@dinero.js/core").RoundingMode;
|
|
22
|
+
Shipping: import("@dinero.js/core").RoundingMode;
|
|
23
|
+
Prettify: import("@dinero.js/core").RoundingMode;
|
|
24
|
+
Subunit: import("@dinero.js/core").RoundingMode;
|
|
25
|
+
};
|
|
3
26
|
/**
|
|
4
27
|
* Mapping of how prices should be rounded down to "whole numbers" after certain threshold
|
|
5
28
|
*/
|
|
6
29
|
export declare const prettifyPriceLookup: Map<string, number>;
|
|
7
30
|
/**
|
|
8
|
-
* Map of
|
|
31
|
+
* Map of dinero code to subunit digit count.
|
|
9
32
|
*/
|
|
10
|
-
export declare const smallestSubunitLookup: Map<string, [number,
|
|
33
|
+
export declare const smallestSubunitLookup: Map<string, [number, RoundingFn]>;
|
|
11
34
|
/**
|
|
12
|
-
*
|
|
13
|
-
* TODO: Add all possible currencies
|
|
35
|
+
* Precompiled list for faster currency and locale lookups
|
|
14
36
|
*/
|
|
15
|
-
export declare const
|
|
37
|
+
export declare const localizedCurrencyLookup: Map<Currency, LocalizedCurrency>;
|
|
16
38
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* normalise the values so we use this method.
|
|
20
|
-
*
|
|
21
|
-
* It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
|
|
22
|
-
* @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
|
|
23
|
-
* @see
|
|
24
|
-
*
|
|
25
|
-
* Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
|
|
26
|
-
* number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
|
|
27
|
-
* See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
|
|
28
|
-
* https://youtu.be/yuRdYlZvs1E
|
|
29
|
-
*
|
|
30
|
-
* If you really want to get knee-deep in the rounding subject, you can read the following:
|
|
31
|
-
* https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
|
|
39
|
+
* List of stores that require calculating per single item qty and then combining them to get the total tax amount for a
|
|
40
|
+
* single line. Rest of the stores inherit default behavior that tax calculated on whole line item
|
|
32
41
|
*/
|
|
33
|
-
export declare const
|
|
42
|
+
export declare const storesWithPerItemTaxRate: Set<StoreId>;
|
|
34
43
|
/**
|
|
35
|
-
*
|
|
44
|
+
* Dinero currency option block for working with tax rates within dinero
|
|
36
45
|
*/
|
|
37
|
-
export declare const
|
|
46
|
+
export declare const TAX_RATE_DINERO_CURRENCY: {
|
|
47
|
+
base: number;
|
|
48
|
+
/**
|
|
49
|
+
* We expect the tax rate to be in the range of 0..1
|
|
50
|
+
* 0 --> 0%
|
|
51
|
+
* 1 --> 100%
|
|
52
|
+
* 0.21 --> 21%
|
|
53
|
+
* 0.2169 --> 21.69%
|
|
54
|
+
* 0.12345678 --> 12.345678%
|
|
55
|
+
* !!! Don't change as this value is tied to store.backend DB schema !!!
|
|
56
|
+
*/
|
|
57
|
+
exponent: number;
|
|
58
|
+
code: string;
|
|
59
|
+
};
|
|
60
|
+
export declare const EXCHANGE_RATE_DINERO_CURRENCY: {
|
|
61
|
+
base: number;
|
|
62
|
+
/**
|
|
63
|
+
* We support having certain decimal places for exchange rates
|
|
64
|
+
* !!! Don't change as this value is tied to store.backend DB schema !!!
|
|
65
|
+
*/
|
|
66
|
+
exponent: number;
|
|
67
|
+
code: string;
|
|
68
|
+
};
|