@ubnt/store.core 9.2.0-money.1 → 9.2.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 +15 -0
- package/lib/assets/attention.svg +5 -5
- package/lib/assets/attention2.svg +5 -5
- package/lib/assets/efg.jpg +0 -0
- package/lib/assets/efg.svg +5 -0
- package/lib/assets/efgStacked.svg +3 -0
- package/lib/assets/gatewayEnterprise.jpg +0 -0
- package/lib/assets/gatewayLite.jpg +0 -0
- package/lib/assets/gatewayMax.jpg +0 -0
- package/lib/assets/gatewayProfessional.jpg +0 -0
- package/lib/assets/minus4.svg +8 -8
- package/lib/assets/minus5.svg +8 -8
- package/lib/assets/nextAi.svg +11 -0
- package/lib/assets/plus5.svg +9 -9
- package/lib/assets/plus6.svg +9 -9
- package/lib/components/Header/ProHeader/ProHeader.styles.js +2 -0
- package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.styles.mjs +3 -1
- package/lib/components/Header/ProHeader/ProHeader.styles.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/MicrositeHero/MicrositeHero.d.ts +1 -1
- package/lib/components/MicrositeHero/MicrositeHero.js +8 -2
- package/lib/components/MicrositeHero/MicrositeHero.js.map +1 -1
- package/lib/components/MicrositeHero/MicrositeHero.mjs +9 -3
- package/lib/components/MicrositeHero/MicrositeHero.mjs.map +1 -1
- package/lib/components/MicrositeHero/MicrositeHero.styles.d.ts +1 -0
- package/lib/components/MicrositeHero/MicrositeHero.styles.js +21 -5
- package/lib/components/MicrositeHero/MicrositeHero.styles.js.map +1 -1
- package/lib/components/MicrositeHero/MicrositeHero.styles.mjs +21 -6
- package/lib/components/MicrositeHero/MicrositeHero.styles.mjs.map +1 -1
- package/lib/components/MicrositeHero/MicrositeHero.types.d.ts +2 -0
- package/lib/components/MicrositeHero/MicrositeHero.types.js.map +1 -1
- package/lib/components/MicrositeHero/MicrositeHero.types.mjs.map +1 -1
- package/lib/components/ModelCompareV3/ModelCompareV3.types.d.ts +4 -1
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/efg.jpg.js +27 -0
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/efg.jpg.js.map +1 -0
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/efg.jpg.mjs +3 -0
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/efg.jpg.mjs.map +1 -0
- package/lib/components/ModelCompareV3/assets/Gateways/gatewayEnterprise.jpg.js +27 -0
- package/lib/components/ModelCompareV3/assets/Gateways/gatewayEnterprise.jpg.js.map +1 -0
- package/lib/components/ModelCompareV3/assets/Gateways/gatewayEnterprise.jpg.mjs +3 -0
- package/lib/components/ModelCompareV3/assets/Gateways/gatewayEnterprise.jpg.mjs.map +1 -0
- package/lib/components/ModelCompareV3/assets/nextAi.svg.js +27 -0
- package/lib/components/ModelCompareV3/assets/nextAi.svg.js.map +1 -0
- package/lib/components/ModelCompareV3/assets/nextAi.svg.mjs +3 -0
- package/lib/components/ModelCompareV3/assets/nextAi.svg.mjs.map +1 -0
- package/lib/components/ModelCompareV3/data/CloudGateways.js +8 -2
- package/lib/components/ModelCompareV3/data/CloudGateways.js.map +1 -1
- package/lib/components/ModelCompareV3/data/CloudGateways.mjs +8 -2
- package/lib/components/ModelCompareV3/data/CloudGateways.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/Gateway.js +10 -7
- package/lib/components/ModelCompareV3/data/Gateway.js.map +1 -1
- package/lib/components/ModelCompareV3/data/Gateway.mjs +10 -7
- package/lib/components/ModelCompareV3/data/Gateway.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/aggregation.js +1 -1
- package/lib/components/ModelCompareV3/data/products/aggregation.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/aggregation.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/aggregation.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/efg.d.ts +2 -0
- package/lib/components/ModelCompareV3/data/products/efg.js +133 -0
- package/lib/components/ModelCompareV3/data/products/efg.js.map +1 -0
- package/lib/components/ModelCompareV3/data/products/efg.mjs +123 -0
- package/lib/components/ModelCompareV3/data/products/efg.mjs.map +1 -0
- package/lib/components/ModelCompareV3/data/products/enterprise24PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/enterprise24PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/enterprise24PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/enterprise24PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/enterprise48PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/enterprise48PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/enterprise48PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/enterprise48PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/enterpriseXG24.js +1 -1
- package/lib/components/ModelCompareV3/data/products/enterpriseXG24.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/enterpriseXG24.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/enterpriseXG24.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/express.js +8 -0
- package/lib/components/ModelCompareV3/data/products/express.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/express.mjs +8 -0
- package/lib/components/ModelCompareV3/data/products/express.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.d.ts +2 -0
- package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.js +87 -0
- package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.js.map +1 -0
- package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.mjs +79 -0
- package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.mjs.map +1 -0
- package/lib/components/ModelCompareV3/data/products/gatewayLite.js +8 -7
- package/lib/components/ModelCompareV3/data/products/gatewayLite.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/gatewayLite.mjs +8 -7
- package/lib/components/ModelCompareV3/data/products/gatewayLite.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/gatewayMax.js +5 -5
- package/lib/components/ModelCompareV3/data/products/gatewayMax.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/gatewayMax.mjs +5 -5
- package/lib/components/ModelCompareV3/data/products/gatewayMax.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/gatewayProfessional.js +12 -11
- package/lib/components/ModelCompareV3/data/products/gatewayProfessional.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/gatewayProfessional.mjs +12 -11
- package/lib/components/ModelCompareV3/data/products/gatewayProfessional.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/missionCritical.js +1 -1
- package/lib/components/ModelCompareV3/data/products/missionCritical.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/missionCritical.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/missionCritical.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professional24.js +1 -1
- package/lib/components/ModelCompareV3/data/products/professional24.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professional24.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/professional24.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professional24PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/professional24PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professional24PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/professional24PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professional48.js +1 -1
- package/lib/components/ModelCompareV3/data/products/professional48.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professional48.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/professional48.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professional48PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/professional48PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professional48PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/professional48PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax24.js +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax24.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax24.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax24.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax48.js +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax48.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax48.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax48.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard16PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/standard16PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard16PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/standard16PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard24.js +1 -1
- package/lib/components/ModelCompareV3/data/products/standard24.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard24.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/standard24.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard24PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/standard24PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard24PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/standard24PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard48.js +1 -1
- package/lib/components/ModelCompareV3/data/products/standard48.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard48.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/standard48.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard48PoE.js +1 -1
- package/lib/components/ModelCompareV3/data/products/standard48PoE.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/standard48PoE.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/standard48PoE.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesEnterprise.js +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesEnterprise.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesEnterprise.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesEnterprise.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesProfessional.js +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesProfessional.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesProfessional.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesProfessional.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.js +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesStandard.js +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesStandard.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesStandard.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/switchesStandard.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgMax.js +7 -0
- package/lib/components/ModelCompareV3/data/products/ucgMax.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +7 -0
- package/lib/components/ModelCompareV3/data/products/ucgMax.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgUltra.js +8 -0
- package/lib/components/ModelCompareV3/data/products/ucgUltra.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +8 -0
- package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udmPro.js +9 -1
- package/lib/components/ModelCompareV3/data/products/udmPro.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udmPro.mjs +9 -1
- package/lib/components/ModelCompareV3/data/products/udmPro.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProMax.js +9 -2
- package/lib/components/ModelCompareV3/data/products/udmProMax.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +9 -2
- package/lib/components/ModelCompareV3/data/products/udmProMax.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +9 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +9 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udr.js +8 -0
- package/lib/components/ModelCompareV3/data/products/udr.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udr.mjs +8 -0
- package/lib/components/ModelCompareV3/data/products/udr.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udw.js +8 -0
- package/lib/components/ModelCompareV3/data/products/udw.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/udw.mjs +8 -0
- package/lib/components/ModelCompareV3/data/products/udw.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/properties/index.d.ts +2 -0
- package/lib/components/ModelCompareV3/data/properties/index.js +4 -0
- package/lib/components/ModelCompareV3/data/properties/index.js.map +1 -1
- package/lib/components/ModelCompareV3/data/properties/index.mjs +2 -0
- package/lib/components/ModelCompareV3/data/properties/index.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/properties/nextAiInspection.d.ts +2 -0
- package/lib/components/ModelCompareV3/data/properties/nextAiInspection.js +19 -0
- package/lib/components/ModelCompareV3/data/properties/nextAiInspection.js.map +1 -0
- package/lib/components/ModelCompareV3/data/properties/nextAiInspection.mjs +11 -0
- package/lib/components/ModelCompareV3/data/properties/nextAiInspection.mjs.map +1 -0
- package/lib/components/ModelCompareV3/translations/en.json.js +21 -36
- package/lib/components/ModelCompareV3/translations/en.json.js.map +1 -1
- package/lib/components/ModelCompareV3/translations/en.json.mjs +21 -36
- package/lib/components/ModelCompareV3/translations/en.json.mjs.map +1 -1
- package/lib/components/ModelCompareV3/translations/useModelCompareTranslation.d.ts +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +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/constants/icons/menu/efg.svg.js +27 -0
- package/lib/constants/icons/menu/efg.svg.js.map +1 -0
- package/lib/constants/icons/menu/efg.svg.mjs +3 -0
- package/lib/constants/icons/menu/efg.svg.mjs.map +1 -0
- package/lib/constants/icons/menu/efgStacked.svg.js +27 -0
- package/lib/constants/icons/menu/efgStacked.svg.js.map +1 -0
- package/lib/constants/icons/menu/efgStacked.svg.mjs +3 -0
- package/lib/constants/icons/menu/efgStacked.svg.mjs.map +1 -0
- package/lib/constants/icons/menu/index.d.ts +2 -0
- package/lib/constants/icons/menu/index.js +18 -0
- package/lib/constants/icons/menu/index.js.map +1 -1
- package/lib/constants/icons/menu/index.mjs +4 -0
- package/lib/constants/icons/menu/index.mjs.map +1 -1
- package/lib/constants/icons/options/colors/black.svg.js +5 -5
- package/lib/constants/icons/options/colors/index.js +3 -3
- package/lib/constants/icons/options/styles/black.svg.js +5 -5
- package/lib/constants/icons/options/styles/index.js +3 -3
- package/lib/constants/optionIcons.js +6 -6
- package/lib/constants/optionIcons.mjs +4 -4
- package/lib/constants/proStoreCategories/mapping/index.d.ts +13 -12
- package/lib/constants/proStoreCategories/mapping/index.js +5 -0
- package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
- package/lib/constants/proStoreCategories/mapping/index.mjs +5 -0
- package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
- package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -0
- 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/ar.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/ar.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/ar.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/ar.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/de.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/de.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/de.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/de.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/el.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/el.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/el.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/el.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/en.json.js +20 -19
- package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/en.json.mjs +20 -19
- package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/es.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/es.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/es.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/es.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/fr.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/fr.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/fr.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/fr.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/it.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/it.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/it.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/it.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/ja.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/ja.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/ja.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/ja.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/pt-BR.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/pt-BR.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +29 -24
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +29 -25
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs.map +1 -1
- package/lib/contexts/MenuContext/mapping.js +14 -0
- package/lib/contexts/MenuContext/mapping.js.map +1 -1
- package/lib/contexts/MenuContext/mapping.mjs +13 -0
- package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
- package/lib/types/constants.d.ts +5 -1
- package/lib/types/constants.js +1 -0
- package/lib/types/constants.js.map +1 -1
- package/lib/types/constants.mjs +1 -0
- package/lib/types/constants.mjs.map +1 -1
- package/lib/utils/address.d.ts +2 -2
- package/lib/utils/address.js +8 -5
- package/lib/utils/address.js.map +1 -1
- package/lib/utils/address.mjs +8 -5
- package/lib/utils/address.mjs.map +1 -1
- package/lib/utils/money/constants.d.ts +25 -56
- package/lib/utils/money/constants.js +7 -68
- package/lib/utils/money/constants.js.map +1 -1
- package/lib/utils/money/constants.mjs +7 -66
- 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 -64
- 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/stateRegistrationNumberSuperRefinement.js +1 -0
- package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js.map +1 -1
- package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs +1 -0
- package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs.map +1 -1
- package/lib/utils/validations/taxIdSuperRefinement.js +1 -0
- package/lib/utils/validations/taxIdSuperRefinement.js.map +1 -1
- package/lib/utils/validations/taxIdSuperRefinement.mjs +1 -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/package.json +1 -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 -1
- package/lib/utils/money/allocators/index.js +0 -6
- package/lib/utils/money/allocators/index.js.map +0 -1
- package/lib/utils/money/allocators/index.mjs +0 -3
- package/lib/utils/money/allocators/index.mjs.map +0 -1
- package/lib/utils/money/exchangeRate.d.ts +0 -30
- 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 -59
- package/lib/utils/money/tax.private.js.map +0 -1
- package/lib/utils/money/tax.private.mjs +0 -54
- package/lib/utils/money/tax.private.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validations.js","sources":["../../src/utils/validations.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"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger"],"mappings":";;;AAIO,SAASA,cACdA,CAAAC,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACzB,IAAI,OAAOH,KAAU,KAAA,QAAA,IAAYI,MAAO,CAAAC,KAAA,CAAML,KAAK,CAAG,EAAA;IAEpD,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,qBAAqBD,KAAO,EAAA,CAAA;EAC5D;EAEA,IAAI,CAACI,MAAA,CAAOE,QAAS,CAAAN,KAAK,CAAG,EAAA;IAE3B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,4BAA4BD,KAAO,EAAA,CAAA;EACnE;AACF;AAWO,SAASO,KACdA,CAAAP,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACVJ,cAAA,CAAAC,KAAA,EAAOC,QAAQC,UAAU,CAAA;EAExC,IAAI,CAACE,MAAA,CAAOI,SAAU,CAAAR,KAAK,CAAG,EAAA;IAE5B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,uBAAuBD,KAAO,EAAA,CAAA;EAC9D;EAEA,IAAI,CAACI,MAAA,CAAOK,aAAc,CAAAT,KAAK,CAAG,EAAA;IAEhC,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,2BAA2BD,KAAO,EAAA,CAAA;EAClE;AACF;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function isFiniteNumber(value, entity = "Value", ErrorClass = TypeError) {
|
|
4
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
5
|
+
throw new ErrorClass(`${entity} is not a number: ${value}`);
|
|
6
|
+
}
|
|
7
|
+
if (!Number.isFinite(value)) {
|
|
8
|
+
throw new ErrorClass(`${entity} is not a finite number: ${value}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function isInt(value, entity = "Value", ErrorClass = TypeError) {
|
|
12
|
+
isFiniteNumber(value, entity, ErrorClass);
|
|
13
|
+
if (!Number.isInteger(value)) {
|
|
14
|
+
throw new ErrorClass(`${entity} is not an integer: ${value}`);
|
|
15
|
+
}
|
|
16
|
+
if (!Number.isSafeInteger(value)) {
|
|
17
|
+
throw new ErrorClass(`${entity} is not a safe integer: ${value}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export { isFiniteNumber, isInt };
|
|
21
|
+
//# sourceMappingURL=validations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validations.mjs","sources":["../../src/utils/validations.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"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger"],"mappings":";;AAIO,SAASA,cACdA,CAAAC,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACzB,IAAI,OAAOH,KAAU,KAAA,QAAA,IAAYI,MAAO,CAAAC,KAAA,CAAML,KAAK,CAAG,EAAA;IAEpD,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,qBAAqBD,KAAO,EAAA,CAAA;EAC5D;EAEA,IAAI,CAACI,MAAA,CAAOE,QAAS,CAAAN,KAAK,CAAG,EAAA;IAE3B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,4BAA4BD,KAAO,EAAA,CAAA;EACnE;AACF;AAWO,SAASO,KACdA,CAAAP,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACVJ,cAAA,CAAAC,KAAA,EAAOC,QAAQC,UAAU,CAAA;EAExC,IAAI,CAACE,MAAA,CAAOI,SAAU,CAAAR,KAAK,CAAG,EAAA;IAE5B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,uBAAuBD,KAAO,EAAA,CAAA;EAC9D;EAEA,IAAI,CAACI,MAAA,CAAOK,aAAc,CAAAT,KAAK,CAAG,EAAA;IAEhC,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,2BAA2BD,KAAO,EAAA,CAAA;EAClE;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;"}
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,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,SAAU,CAAAL,qBAAA,EAAuBE,QAAQ,CAAA;IACrE,IAAA,CAAAI,oBAAA,GAAuBD,SAAU,CAAAJ,kBAAA,EAAoBC,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,kBAAkBL,QAAQ,CAAA;EAC5C;EAAA;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACQ,+BAAAA,QAAiB,SAAA,IAAA,CAAKA,SAASS,IAAI,EAAA,CACpE;IACM,MAAAC,mBAAA,GAAsBP,SAAU,CAAAI,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IACT;IAEM,MAAA,CAACC,gBAAkB,EAAAT,yBAAyB,CAAI,GAAAI,QAAA,CACpD,IAAK,CAAAJ,yBAAA,EACL,CACEK,aAAA,EACAK,KAAKC,GAAI,CAAAC,MAAA,CAAO,KAAKV,oBAAoB,CAAA,GAAIG,eAAe,CAAC,CAAA,CAC/D,CACF;IAEOC,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CACE,CAAC,CAACN,yBAAA,EACF,wCAAA,CACF;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKE,oBAAuB,GAAAW,QAAA,CAC1B,IAAK,CAAAX,oBAAA,EACLM,mBAAA,CACF;IAMA,OAAOM,WAAY,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EACN;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./fixedAmount";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse exchange rate to dinero friendly amount and scale.
|
|
3
|
-
*
|
|
4
|
-
* Used to prepare exchange rate for sending over API.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}
|
|
8
|
-
*/
|
|
9
|
-
export declare const toSnapshotExchangeRate: (exchangeRate: number) => {
|
|
10
|
-
amount: number;
|
|
11
|
-
scale: number;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Converts an arbitrary exchange rate to a fixed decimal place number.
|
|
15
|
-
*
|
|
16
|
-
* Used to take in an input and convert it for storage in the database.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* toFixedExchangeRate("0.123456789") // "0.123457"
|
|
20
|
-
* toFixedExchangeRate("0.123456789", true) // 0.123457
|
|
21
|
-
*/
|
|
22
|
-
export declare function toFixedExchangeRate(rate: string | number, asNumber?: boolean): string;
|
|
23
|
-
export declare function toFixedExchangeRate(rate: string | number, asNumber?: true): number;
|
|
24
|
-
/**
|
|
25
|
-
* Invert an exchange rate by doing 1 / rate
|
|
26
|
-
* Used to fake a reverse exchange rate in case we don't have it
|
|
27
|
-
* @example
|
|
28
|
-
* invertExchangeRate("0.22") // "4.545455"
|
|
29
|
-
*/
|
|
30
|
-
export declare function invertExchangeRate(rate: string | number, asNumber?: boolean): string;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var errors = require('../errors.js');
|
|
4
|
-
var number = require('../number.js');
|
|
5
|
-
var constants = require('./constants.js');
|
|
6
|
-
var misc_private = require('./misc.private.js');
|
|
7
|
-
"use strict";
|
|
8
|
-
const toSnapshotExchangeRate = exchangeRate => {
|
|
9
|
-
number.isFloat(exchangeRate, "Exchange rate");
|
|
10
|
-
errors.assert(exchangeRate > 0, "Exchange rate must be greater than 0");
|
|
11
|
-
const rateInt = misc_private.floatToInt(exchangeRate, constants.EXCHANGE_RATE_DINERO_CURRENCY.base, constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent);
|
|
12
|
-
return {
|
|
13
|
-
amount: rateInt,
|
|
14
|
-
scale: constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
function toFixedExchangeRate(rate, asNumber) {
|
|
18
|
-
return number.toFixedRate(typeof rate === "string" ? +rate : rate, constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent, asNumber);
|
|
19
|
-
}
|
|
20
|
-
function invertExchangeRate(rate, asNumber) {
|
|
21
|
-
const exchangeRate = toFixedExchangeRate(rate, true);
|
|
22
|
-
return toFixedExchangeRate(1 / exchangeRate, asNumber);
|
|
23
|
-
}
|
|
24
|
-
exports.invertExchangeRate = invertExchangeRate;
|
|
25
|
-
exports.toFixedExchangeRate = toFixedExchangeRate;
|
|
26
|
-
exports.toSnapshotExchangeRate = toSnapshotExchangeRate;
|
|
27
|
-
//# sourceMappingURL=exchangeRate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exchangeRate.js","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: number,\n): {\n amount: number;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: NoInfer<boolean>,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number, asNumber?: boolean) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, asNumber);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;;;AAca,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,cAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAAA,CAAAA,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,YAAA,CAAAA,UAAA,CACdJ,YAAA,EACAK,SAAAA,CAAAA,6BAA8B,CAAAC,IAAA,EAC9BD,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,CAChC;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,SAA8B,CAAAA,6BAAA,CAAAE;EAAA,CACvC;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,MAAA,CAAAA,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,EAC9BK,QAAA,CACF;AACF;AAQgB,SAAAE,kBAAAA,CAAmBH,MAAuBC,QAAoB,EAAA;EACtE,MAAAZ,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAcY,QAAQ,CAAA;AACvD;;;"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { assert } from '../errors.mjs';
|
|
2
|
-
import { isFloat, toFixedRate } from '../number.mjs';
|
|
3
|
-
import { EXCHANGE_RATE_DINERO_CURRENCY } from './constants.mjs';
|
|
4
|
-
import { floatToInt } from './misc.private.mjs';
|
|
5
|
-
"use strict";
|
|
6
|
-
const toSnapshotExchangeRate = exchangeRate => {
|
|
7
|
-
isFloat(exchangeRate, "Exchange rate");
|
|
8
|
-
assert(exchangeRate > 0, "Exchange rate must be greater than 0");
|
|
9
|
-
const rateInt = floatToInt(exchangeRate, EXCHANGE_RATE_DINERO_CURRENCY.base, EXCHANGE_RATE_DINERO_CURRENCY.exponent);
|
|
10
|
-
return {
|
|
11
|
-
amount: rateInt,
|
|
12
|
-
scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
function toFixedExchangeRate(rate, asNumber) {
|
|
16
|
-
return toFixedRate(typeof rate === "string" ? +rate : rate, EXCHANGE_RATE_DINERO_CURRENCY.exponent, asNumber);
|
|
17
|
-
}
|
|
18
|
-
function invertExchangeRate(rate, asNumber) {
|
|
19
|
-
const exchangeRate = toFixedExchangeRate(rate, true);
|
|
20
|
-
return toFixedExchangeRate(1 / exchangeRate, asNumber);
|
|
21
|
-
}
|
|
22
|
-
export { invertExchangeRate, toFixedExchangeRate, toSnapshotExchangeRate };
|
|
23
|
-
//# sourceMappingURL=exchangeRate.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exchangeRate.mjs","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: number,\n): {\n amount: number;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: NoInfer<boolean>,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number, asNumber?: boolean) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, asNumber);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;AAca,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,OAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,UAAA,CACdJ,YAAA,EACAK,6BAA8B,CAAAC,IAAA,EAC9BD,6BAA8B,CAAAE,QAAA,CAChC;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,6BAA8B,CAAAE;EAAA,CACvC;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,6BAA8B,CAAAE,QAAA,EAC9BK,QAAA,CACF;AACF;AAQgB,SAAAE,kBAAAA,CAAmBH,MAAuBC,QAAoB,EAAA;EACtE,MAAAZ,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAcY,QAAQ,CAAA;AACvD;"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as currencies from "@dinero.js/currencies";
|
|
2
|
-
import type { DinoCurrency } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Fast lookup for our custom currency enum to check that given currency is valid
|
|
5
|
-
*/
|
|
6
|
-
export declare const currencyLookup: Set<string>;
|
|
7
|
-
/**
|
|
8
|
-
* Dinero currency lookup to check that given currency is valid
|
|
9
|
-
*/
|
|
10
|
-
export declare const dineroCurrenciesLookup: Map<string, currencies.Currency<number>>;
|
|
11
|
-
/**
|
|
12
|
-
* Private util to convert a float value into a int. Also applies financial rounding to the value if needed.
|
|
13
|
-
* Inspired by https://v2.dinerojs.com/docs/faq/how-can-i-create-dinero-objects-from-floats
|
|
14
|
-
* @example
|
|
15
|
-
* floatToInt(69.10, 10, 2); // 6910
|
|
16
|
-
* floatToInt(42, 10, 2); // 4200
|
|
17
|
-
* floatToInt(0.22, 10, 6); // 220000
|
|
18
|
-
*/
|
|
19
|
-
export declare const floatToInt: (floatAmount: number, base: number, exponent: number) => number;
|
|
20
|
-
/**
|
|
21
|
-
* FIXME: is it private tho?!
|
|
22
|
-
*/
|
|
23
|
-
export declare const decimalToDinero: (decimalAmount: string | number, currency: DinoCurrency) => import("dinero.js").Dinero<number>;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var currencies = require('@dinero.js/currencies');
|
|
4
|
-
var dinero_js = require('dinero.js');
|
|
5
|
-
require('../../types/index.js');
|
|
6
|
-
var number = require('../number.js');
|
|
7
|
-
var constants = require('./constants.js');
|
|
8
|
-
var generated = require('../../types/generated.js');
|
|
9
|
-
function _interopNamespace(e) {
|
|
10
|
-
if (e && e.__esModule) return e;
|
|
11
|
-
var n = Object.create(null);
|
|
12
|
-
if (e) {
|
|
13
|
-
Object.keys(e).forEach(function (k) {
|
|
14
|
-
if (k !== 'default') {
|
|
15
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return e[k];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
n["default"] = e;
|
|
26
|
-
return Object.freeze(n);
|
|
27
|
-
}
|
|
28
|
-
var currencies__namespace = /*#__PURE__*/_interopNamespace(currencies);
|
|
29
|
-
"use strict";
|
|
30
|
-
const currencyLookup = new Set(Object.keys(generated.Currency).map(el => el.toString()));
|
|
31
|
-
const dineroCurrenciesLookup = new Map(Object.values(currencies__namespace).map(currency => [currency.code, currency]));
|
|
32
|
-
const floatToInt = (floatAmount, base, exponent) => constants.Round.Financial(floatAmount * Math.pow(base, exponent));
|
|
33
|
-
const decimalToDinero = (decimalAmount, currency) => {
|
|
34
|
-
const parsedNumber = typeof decimalAmount === "number" ? decimalAmount : Number.parseFloat(decimalAmount);
|
|
35
|
-
number.isFloat(parsedNumber);
|
|
36
|
-
const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(10, currency.exponent)).toFixed(0));
|
|
37
|
-
return dinero_js.dinero({
|
|
38
|
-
amount: parsedNumberInt,
|
|
39
|
-
currency
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
exports.currencyLookup = currencyLookup;
|
|
43
|
-
exports.decimalToDinero = decimalToDinero;
|
|
44
|
-
exports.dineroCurrenciesLookup = dineroCurrenciesLookup;
|
|
45
|
-
exports.floatToInt = floatToInt;
|
|
46
|
-
//# sourceMappingURL=misc.private.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"misc.private.js","sources":["../../../src/utils/money/misc.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport * as currencies from \"@dinero.js/currencies\";\nimport { dinero } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { isFloat } from \"../number\";\nimport { Round } from \"./constants\";\nimport type { DinoCurrency } from \"./types\";\n\n/**\n * Fast lookup for our custom currency enum to check that given currency is valid\n */\nexport const currencyLookup = new Set(\n Object.keys(Currency).map((el) => el.toString()),\n);\n\n/**\n * Dinero currency lookup to check that given currency is valid\n */\nexport const dineroCurrenciesLookup = new Map(\n Object.values(currencies).map((currency) => [currency.code, currency]),\n);\n\n/**\n * Private util to convert a float value into a int. Also applies financial rounding to the value if needed.\n * Inspired by https://v2.dinerojs.com/docs/faq/how-can-i-create-dinero-objects-from-floats\n * @example\n * floatToInt(69.10, 10, 2); // 6910\n * floatToInt(42, 10, 2); // 4200\n * floatToInt(0.22, 10, 6); // 220000\n */\nexport const floatToInt = (\n floatAmount: number,\n base: number,\n exponent: number,\n // FIXME: pass in the rounding method and or use roundDinero\n): number => Round.Financial(floatAmount * Math.pow(base, exponent));\n\n/**\n * FIXME: is it private tho?!\n */\nexport const decimalToDinero = (\n decimalAmount: string | number,\n currency: DinoCurrency,\n // FIXME: rounding method?!\n) => {\n const parsedNumber =\n typeof decimalAmount === \"number\"\n ? decimalAmount\n : Number.parseFloat(decimalAmount);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (parsedNumber * Math.pow(10, currency.exponent)).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency,\n });\n};\n"],"names":["currencyLookup","Set","Object","keys","Currency","map","el","toString","dineroCurrenciesLookup","Map","values","currencies","currency","code","floatToInt","floatAmount","base","exponent","Round","Financial","Math","pow","decimalToDinero","decimalAmount","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","toFixed","dinero","amount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAMA,iBAAiB,IAAIC,GAAA,CAChCC,MAAA,CAAOC,KAAKC,SAAAA,CAAAA,QAAQ,CAAA,CAAEC,IAAKC,EAAA,IAAOA,EAAG,CAAAC,QAAA,EAAU,CACjD,CAAA;AAKO,MAAMC,yBAAyB,IAAIC,GAAA,CACxCP,MAAA,CAAOQ,MAAO,CAAAC,qBAAU,CAAE,CAAAN,GAAA,CAAKO,QAAA,IAAa,CAACA,QAAA,CAASC,IAAM,EAAAD,QAAQ,CAAC,CACvE,CAAA;AAUO,MAAME,UAAa,GAAAA,CACxBC,WACA,EAAAC,IAAA,EACAC,QAEW,KAAAC,SAAA,CAAAA,KAAA,CAAMC,SAAU,CAAAJ,WAAA,GAAcK,IAAK,CAAAC,GAAA,CAAIL,IAAM,EAAAC,QAAQ,CAAC,CAAA;AAKtD,MAAAK,eAAA,GAAkBA,CAC7BC,aAAA,EACAX,QAEG,KAAA;EACH,MAAMY,eACJ,OAAOD,aAAA,KAAkB,WACrBA,aACA,GAAAE,MAAA,CAAOC,WAAWH,aAAa,CAAA;EACrCI,MAAA,CAAAA,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAO,CAAAI,QAAA,CAC5B,CAAAL,YAAA,GAAeJ,KAAKC,GAAI,CAAA,EAAA,EAAIT,SAASK,QAAQ,CAAA,EAAGa,QAAQ,CAAC,CAAA,CAC5D;EACA,OAAOC,gBAAO,CAAA;IACZC,MAAQ,EAAAJ,eAAA;IACRhB;EAAA,CACD,CAAA;AACH,CAAA;;;;"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as currencies from '@dinero.js/currencies';
|
|
2
|
-
import { dinero } from 'dinero.js';
|
|
3
|
-
import '../../types/index.mjs';
|
|
4
|
-
import { isFloat } from '../number.mjs';
|
|
5
|
-
import { Round } from './constants.mjs';
|
|
6
|
-
import { Currency } from '../../types/generated.mjs';
|
|
7
|
-
"use strict";
|
|
8
|
-
const currencyLookup = new Set(Object.keys(Currency).map(el => el.toString()));
|
|
9
|
-
const dineroCurrenciesLookup = new Map(Object.values(currencies).map(currency => [currency.code, currency]));
|
|
10
|
-
const floatToInt = (floatAmount, base, exponent) => Round.Financial(floatAmount * Math.pow(base, exponent));
|
|
11
|
-
const decimalToDinero = (decimalAmount, currency) => {
|
|
12
|
-
const parsedNumber = typeof decimalAmount === "number" ? decimalAmount : Number.parseFloat(decimalAmount);
|
|
13
|
-
isFloat(parsedNumber);
|
|
14
|
-
const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(10, currency.exponent)).toFixed(0));
|
|
15
|
-
return dinero({
|
|
16
|
-
amount: parsedNumberInt,
|
|
17
|
-
currency
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
export { currencyLookup, decimalToDinero, dineroCurrenciesLookup, floatToInt };
|
|
21
|
-
//# sourceMappingURL=misc.private.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"misc.private.mjs","sources":["../../../src/utils/money/misc.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport * as currencies from \"@dinero.js/currencies\";\nimport { dinero } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { isFloat } from \"../number\";\nimport { Round } from \"./constants\";\nimport type { DinoCurrency } from \"./types\";\n\n/**\n * Fast lookup for our custom currency enum to check that given currency is valid\n */\nexport const currencyLookup = new Set(\n Object.keys(Currency).map((el) => el.toString()),\n);\n\n/**\n * Dinero currency lookup to check that given currency is valid\n */\nexport const dineroCurrenciesLookup = new Map(\n Object.values(currencies).map((currency) => [currency.code, currency]),\n);\n\n/**\n * Private util to convert a float value into a int. Also applies financial rounding to the value if needed.\n * Inspired by https://v2.dinerojs.com/docs/faq/how-can-i-create-dinero-objects-from-floats\n * @example\n * floatToInt(69.10, 10, 2); // 6910\n * floatToInt(42, 10, 2); // 4200\n * floatToInt(0.22, 10, 6); // 220000\n */\nexport const floatToInt = (\n floatAmount: number,\n base: number,\n exponent: number,\n // FIXME: pass in the rounding method and or use roundDinero\n): number => Round.Financial(floatAmount * Math.pow(base, exponent));\n\n/**\n * FIXME: is it private tho?!\n */\nexport const decimalToDinero = (\n decimalAmount: string | number,\n currency: DinoCurrency,\n // FIXME: rounding method?!\n) => {\n const parsedNumber =\n typeof decimalAmount === \"number\"\n ? decimalAmount\n : Number.parseFloat(decimalAmount);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (parsedNumber * Math.pow(10, currency.exponent)).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency,\n });\n};\n"],"names":["currencyLookup","Set","Object","keys","Currency","map","el","toString","dineroCurrenciesLookup","Map","values","currencies","currency","code","floatToInt","floatAmount","base","exponent","Round","Financial","Math","pow","decimalToDinero","decimalAmount","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","toFixed","dinero","amount"],"mappings":";;;;;;;AAeO,MAAMA,iBAAiB,IAAIC,GAAA,CAChCC,MAAA,CAAOC,KAAKC,QAAQ,CAAA,CAAEC,IAAKC,EAAA,IAAOA,EAAG,CAAAC,QAAA,EAAU,CACjD,CAAA;AAKO,MAAMC,yBAAyB,IAAIC,GAAA,CACxCP,MAAA,CAAOQ,MAAO,CAAAC,UAAU,CAAE,CAAAN,GAAA,CAAKO,QAAA,IAAa,CAACA,QAAA,CAASC,IAAM,EAAAD,QAAQ,CAAC,CACvE,CAAA;AAUO,MAAME,UAAa,GAAAA,CACxBC,WACA,EAAAC,IAAA,EACAC,QAEW,KAAAC,KAAA,CAAMC,SAAU,CAAAJ,WAAA,GAAcK,IAAK,CAAAC,GAAA,CAAIL,IAAM,EAAAC,QAAQ,CAAC,CAAA;AAKtD,MAAAK,eAAA,GAAkBA,CAC7BC,aAAA,EACAX,QAEG,KAAA;EACH,MAAMY,eACJ,OAAOD,aAAA,KAAkB,WACrBA,aACA,GAAAE,MAAA,CAAOC,WAAWH,aAAa,CAAA;EACrCI,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAO,CAAAI,QAAA,CAC5B,CAAAL,YAAA,GAAeJ,KAAKC,GAAI,CAAA,EAAA,EAAIT,SAASK,QAAQ,CAAA,EAAGa,QAAQ,CAAC,CAAA,CAC5D;EACA,OAAOC,MAAO,CAAA;IACZC,MAAQ,EAAAJ,eAAA;IACRhB;EAAA,CACD,CAAA;AACH,CAAA;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var constants = require('./constants.js');
|
|
4
|
-
var misc = require('./misc.js');
|
|
5
|
-
"use strict";
|
|
6
|
-
const roundShippingPrice = price => misc.roundDinero(price, constants.Round.Shipping);
|
|
7
|
-
exports.roundShippingPrice = roundShippingPrice;
|
|
8
|
-
//# sourceMappingURL=shipping.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shipping.js","sources":["../../../src/utils/money/shipping.ts"],"sourcesContent":["import { Round } from \"./constants\";\nimport { roundDinero } from \"./misc\";\nimport type { Dino } from \"./types\";\n\n/**\n * Rounding for shipping price used only after applying\n */\nexport const roundShippingPrice = (price: Dino) =>\n roundDinero(price, Round.Shipping);\n"],"names":["roundShippingPrice","price","roundDinero","Round","Shipping"],"mappings":";;;;;AAOO,MAAMA,qBAAsBC,KAAA,IACjCC,IAAY,CAAAA,WAAA,CAAAD,KAAA,EAAOE,gBAAMC,QAAQ,CAAA;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shipping.mjs","sources":["../../../src/utils/money/shipping.ts"],"sourcesContent":["import { Round } from \"./constants\";\nimport { roundDinero } from \"./misc\";\nimport type { Dino } from \"./types\";\n\n/**\n * Rounding for shipping price used only after applying\n */\nexport const roundShippingPrice = (price: Dino) =>\n roundDinero(price, Round.Shipping);\n"],"names":["roundShippingPrice","price","roundDinero","Round","Shipping"],"mappings":";;;AAOO,MAAMA,qBAAsBC,KAAA,IACjCC,WAAY,CAAAD,KAAA,EAAOE,MAAMC,QAAQ,CAAA;"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Dinero } from "dinero.js";
|
|
2
|
-
import type { Cents, LineItemSummary, SingleLineItemSummary, TaxRate } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Private helper to convert a floating number to a dinero friendly allocation integer pair
|
|
5
|
-
* @see https://v2.dinerojs.com/docs/api/mutations/allocate
|
|
6
|
-
* @example
|
|
7
|
-
* taxRateToDineroAllocation(0.1) // [1, 9]
|
|
8
|
-
* taxRateToDineroAllocation(0.5) // [5, 5]
|
|
9
|
-
*/
|
|
10
|
-
export declare const taxRateToDineroAllocation: (taxRate: TaxRate) => [number, number];
|
|
11
|
-
/**
|
|
12
|
-
* Reverse engineer the taxable amount from "whole item" taxable amount into "per item" taxable amount for custom tax
|
|
13
|
-
* rate calculations
|
|
14
|
-
*/
|
|
15
|
-
export declare const allocatePerItemTaxableAmount: (itemSummary: LineItemSummary) => SingleLineItemSummary[];
|
|
16
|
-
export declare const calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dinero<Cents>;
|
|
17
|
-
export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dinero<Cents>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var dinero_js = require('dinero.js');
|
|
4
|
-
var errors = require('../errors.js');
|
|
5
|
-
var fixedAmount = require('./allocators/fixedAmount.js');
|
|
6
|
-
var misc = require('./misc.js');
|
|
7
|
-
"use strict";
|
|
8
|
-
const taxRateToDineroAllocation = taxRate => {
|
|
9
|
-
if (taxRate <= 0 || taxRate >= 1) {
|
|
10
|
-
throw new RangeError("Unsupported rate, expected in range of 0>rate<1");
|
|
11
|
-
}
|
|
12
|
-
const rateScale = String(taxRate).split(".")[1]?.length;
|
|
13
|
-
errors.assert(rateScale !== void 0, "rateScale is undefined");
|
|
14
|
-
const rateInt = Math.round(taxRate * Math.pow(10, rateScale));
|
|
15
|
-
return [rateInt, Math.pow(10, rateScale) - rateInt];
|
|
16
|
-
};
|
|
17
|
-
const allocatePerItemTaxableAmount = itemSummary => {
|
|
18
|
-
if (itemSummary.quantity === 1) {
|
|
19
|
-
return [itemSummary];
|
|
20
|
-
}
|
|
21
|
-
const preDiscountAmount = dinero_js.add(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), misc.getDinero(itemSummary.discountAmount, itemSummary.currency));
|
|
22
|
-
const allocator = new fixedAmount.FixedAmountAllocator({
|
|
23
|
-
initialAllocateAmount: itemSummary.discountAmount,
|
|
24
|
-
initialTotalAmount: misc.amount(preDiscountAmount),
|
|
25
|
-
currency: itemSummary.currency
|
|
26
|
-
});
|
|
27
|
-
return Array.from({
|
|
28
|
-
length: itemSummary.quantity
|
|
29
|
-
}, () => {
|
|
30
|
-
const discountAllocatedAmount = allocator.allocate(itemSummary.itemPrice, itemSummary.currency);
|
|
31
|
-
const taxableAmount = dinero_js.subtract(misc.getDinero(itemSummary.itemPrice, itemSummary.currency), discountAllocatedAmount);
|
|
32
|
-
return {
|
|
33
|
-
itemPrice: itemSummary.itemPrice,
|
|
34
|
-
taxableAmount: misc.amount(taxableAmount),
|
|
35
|
-
discountAmount: misc.amount(discountAllocatedAmount),
|
|
36
|
-
currency: itemSummary.currency,
|
|
37
|
-
quantity: 1
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
|
|
42
|
-
const [taxAmount] = dinero_js.allocate(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
|
|
43
|
-
errors.assert(taxAmount !== void 0, "taxAmount is undefined");
|
|
44
|
-
return taxAmount;
|
|
45
|
-
};
|
|
46
|
-
const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
|
|
47
|
-
const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
|
|
48
|
-
let totalTaxAmount = misc.getDinero(0, itemSummary.currency);
|
|
49
|
-
singleItemSummaries.forEach(itemSummary2 => {
|
|
50
|
-
const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
|
|
51
|
-
totalTaxAmount = dinero_js.add(totalTaxAmount, taxAmount);
|
|
52
|
-
});
|
|
53
|
-
return totalTaxAmount;
|
|
54
|
-
};
|
|
55
|
-
exports.allocatePerItemTaxableAmount = allocatePerItemTaxableAmount;
|
|
56
|
-
exports.calculatePerQtyLineItemTax = calculatePerQtyLineItemTax;
|
|
57
|
-
exports.calculateWholeQtyLineItemTax = calculateWholeQtyLineItemTax;
|
|
58
|
-
exports.taxRateToDineroAllocation = taxRateToDineroAllocation;
|
|
59
|
-
//# sourceMappingURL=tax.private.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, allocate, subtract } from \"dinero.js\";\n\nimport { assert } from \"../errors\";\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { amount, getDinero } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Private helper to convert a floating number to a dinero friendly allocation integer pair\n * @see https://v2.dinerojs.com/docs/api/mutations/allocate\n * @example\n * taxRateToDineroAllocation(0.1) // [1, 9]\n * taxRateToDineroAllocation(0.5) // [5, 5]\n */\nexport const taxRateToDineroAllocation = (\n taxRate: TaxRate,\n): [number, number] => {\n if (taxRate <= 0 || taxRate >= 1) {\n throw new RangeError(\"Unsupported rate, expected in range of 0>rate<1\");\n }\n\n // Get the scale of the rate\n const rateScale = String(taxRate).split(\".\")[1]?.length;\n assert(rateScale !== undefined, \"rateScale is undefined\");\n\n // Convert to integers\n const rateInt = Math.round(taxRate * Math.pow(10, rateScale));\n return [rateInt, Math.pow(10, rateScale) - rateInt];\n};\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n /**\n * FIXME: look into approach with multiply and different scale for control over rounding, currently we just inherit\n * what dinero gives us which cause unexpected rounding issue\n */\n const [taxAmount] = allocate(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRateToDineroAllocation(taxRate),\n );\n\n assert(taxAmount !== undefined, \"taxAmount is undefined\");\n return taxAmount;\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["taxRateToDineroAllocation","taxRate","RangeError","rateScale","String","split","length","assert","rateInt","Math","round","pow","allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxAmount","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;;;AAwBa,MAAAA,yBAAA,GACXC,OACqB,IAAA;EACjB,IAAAA,OAAA,IAAW,CAAK,IAAAA,OAAA,IAAW,CAAG,EAAA;IAC1B,MAAA,IAAIC,WAAW,iDAAiD,CAAA;EACxE;EAGM,MAAAC,SAAA,GAAYC,OAAOH,OAAO,CAAA,CAAEI,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EAC1CC,MAAAA,CAAAA,MAAA,CAAAJ,SAAA,KAAc,QAAW,wBAAwB,CAAA;EAGlD,MAAAK,OAAA,GAAUC,KAAKC,KAAM,CAAAT,OAAA,GAAUQ,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAC5D,OAAO,CAACK,OAAS,EAAAC,IAAA,CAAKE,IAAI,EAAI,EAAAR,SAAS,IAAIK,OAAO,CAAA;AACpD,CAAA;AAMa,MAAAI,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAoB,GAAAC,SAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYO,cAAgB,EAAAP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEM,MAAAE,SAAA,GAAY,IAAIC,gCAAqB,CAAA;IACzCC,uBAAuBV,WAAY,CAAAO,cAAA;IACnCI,kBAAA,EAAoBC,YAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAY,CAAAM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAK,CAAA;IAAErB,QAAQO,WAAY,CAAAC;EAAA,GAAY,MAAM;IACxD,MAAMc,0BAA0BP,SAAU,CAAAQ,QAAA,CACxChB,WAAY,CAAAiB,SAAA,EACZjB,WAAY,CAAAM,QAAA,CACd;IAEA,MAAMD,aAAgB,GAAAa,SAAA,CAAAA,QAAA,CACpBd,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYiB,SAAW,EAAAjB,WAAA,CAAYM,QAAQ,CAAA,EACrDS,uBAAA,CACF;IAEO,OAAA;MACLE,WAAWjB,WAAY,CAAAiB,SAAA;MACvBZ,aAAA,EAAeO,YAAOP,aAAa,CAAA;MACnCE,cAAA,EAAgBK,YAAOG,uBAAuB,CAAA;MAC9CT,UAAUN,WAAY,CAAAM,QAAA;MACtBL,QAAU,EAAA;IAAA,CACZ;EAAA,CACD,CAAA;AACH,CAAA;AAEa,MAAAkB,4BAAA,GAA+BA,CAC1CnB,WAAA,EACAZ,OACkB,KAAA;EAKZ,MAAA,CAACgC,SAAS,CAAI,GAAAJ,SAAA,CAAAA,QAAA,CAClBZ,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDnB,0BAA0BC,OAAO,CAAA,CACnC;EAEOM,MAAAA,CAAAA,MAAA,CAAA0B,SAAA,KAAc,QAAW,wBAAwB,CAAA;EACjD,OAAAA,SAAA;AACT,CAAA;AAEa,MAAAC,0BAAA,GAA6BA,CACxCrB,WAAA,EACAZ,OACkB,KAAA;EAEZ,MAAAkC,mBAAA,GAAsBvB,6BAA6BC,WAAW,CAAA;EAGpE,IAAIuB,cAAiB,GAAAnB,IAAA,CAAAA,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCgB,mBAAA,CAAAE,OAAA,CAASxB,YAAgB,IAAA;IAGrC,MAAAoB,SAAA,GAAYD,4BAA6BnB,CAAAA,YAAAA,EAAaZ,OAAO,CAAA;IAClDmC,cAAA,GAAApB,SAAA,CAAAA,GAAA,CAAIoB,gBAAgBH,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAG,cAAA;AACT,CAAA;;;;"}
|