@ubnt/store.core 10.0.0-pre-alpha.0 → 10.0.0-pre-alpha.2
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/lib/_virtual/_virtual_multi-entry.js +10 -14
- package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
- package/lib/_virtual/_virtual_multi-entry.mjs +10 -14
- package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
- package/lib/assets/attention.svg +5 -5
- package/lib/assets/attention2.svg +5 -5
- package/lib/assets/express7.jpg +0 -0
- package/lib/assets/express72.jpg +0 -0
- package/lib/assets/minus4.svg +8 -8
- package/lib/assets/minus5.svg +8 -8
- package/lib/assets/plus3.svg +9 -9
- package/lib/assets/plus4.svg +9 -9
- 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/udmPro.jpg +0 -0
- package/lib/assets/udmPro2.jpg +0 -0
- package/lib/assets/udmProMax.jpg +0 -0
- package/lib/assets/udmProMax2.jpg +0 -0
- package/lib/assets/udmProSpecial.jpg +0 -0
- package/lib/assets/udmProSpecial2.jpg +0 -0
- package/lib/assets/udr2.jpg +0 -0
- package/lib/assets/udr3.jpg +0 -0
- package/lib/assets/udr7.jpg +0 -0
- package/lib/assets/udr72.jpg +0 -0
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/express7.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/express7.jpg.mjs +2 -2
- 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/udmPro.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr7.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr7.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/express7.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/express7.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/Consoles/udmPro.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udr.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udr.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udr7.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udr7.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/data/CloudGateways.js +21 -21
- package/lib/components/ModelCompareV3/data/CloudGateways.mjs +14 -14
- package/lib/components/ModelCompareV3/data/products/express7.js +1 -1
- package/lib/components/ModelCompareV3/data/products/express7.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/udmPro.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.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/udr7.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udr7.mjs +1 -1
- 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/utils/index.d.ts +1 -3
- package/lib/utils/index.js +6 -10
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/index.mjs +6 -10
- package/lib/utils/index.mjs.map +1 -1
- package/lib/utils/money/allocators/fixedAmount.js +44 -0
- package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
- package/lib/utils/money/allocators/fixedAmount.mjs +42 -0
- package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
- package/lib/utils/money/allocators/productAmount.js +75 -0
- package/lib/utils/money/allocators/productAmount.js.map +1 -0
- package/lib/utils/money/allocators/productAmount.mjs +73 -0
- package/lib/utils/money/allocators/productAmount.mjs.map +1 -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.js +101 -0
- package/lib/utils/money/format.js.map +1 -0
- package/lib/utils/money/format.mjs +96 -0
- package/lib/utils/money/format.mjs.map +1 -0
- package/lib/utils/money/index.js +56 -0
- package/lib/utils/money/index.js.map +1 -0
- package/lib/utils/money/index.mjs +11 -0
- package/lib/utils/money/index.mjs.map +1 -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.js +59 -0
- package/lib/utils/money/tax.js.map +1 -0
- package/lib/utils/money/tax.mjs +51 -0
- package/lib/utils/money/tax.mjs.map +1 -0
- package/lib/utils/money/tax.private.js +56 -0
- package/lib/utils/money/tax.private.js.map +1 -0
- package/lib/utils/money/tax.private.mjs +52 -0
- package/lib/utils/money/tax.private.mjs.map +1 -0
- package/lib/utils/money/types.js +3 -0
- package/lib/utils/money/types.js.map +1 -0
- package/lib/utils/money/types.mjs +2 -0
- package/lib/utils/money/types.mjs.map +1 -0
- package/package.json +1 -1
- package/lib/utils/collectionSlug.d.ts +0 -5
- package/lib/utils/collectionSlug.js +0 -13
- package/lib/utils/collectionSlug.js.map +0 -1
- package/lib/utils/collectionSlug.mjs +0 -12
- package/lib/utils/collectionSlug.mjs.map +0 -1
- package/lib/utils/collectionSlug.test.d.ts +0 -1
- package/lib/utils/variant.d.ts +0 -8
- package/lib/utils/variant.test.d.ts +0 -1
- package/lib/utils/wattage.d.ts +0 -11
- package/lib/utils/wattage.js +0 -20
- package/lib/utils/wattage.js.map +0 -1
- package/lib/utils/wattage.mjs +0 -18
- package/lib/utils/wattage.mjs.map +0 -1
- package/lib/utils/wattage.test.d.ts +0 -1
|
@@ -6,7 +6,7 @@ var asset = require('../../../../../utils/asset.js');
|
|
|
6
6
|
require('./assets/attention.svg.js');
|
|
7
7
|
var Part = require('./Part.js');
|
|
8
8
|
var ProgressBarChart_styles = require('./ProgressBarChart.styles.js');
|
|
9
|
-
var attentionIcon = require("../../../../../assets/
|
|
9
|
+
var attentionIcon = require("../../../../../assets/attention2.svg");
|
|
10
10
|
function _interopDefault(e) {
|
|
11
11
|
return e && e.__esModule ? e : {
|
|
12
12
|
default: e
|
|
@@ -4,7 +4,7 @@ import { imageSrc } from '../../../../../utils/asset.mjs';
|
|
|
4
4
|
import './assets/attention.svg.mjs';
|
|
5
5
|
import { PART_GAP_PX, PART_WIDTH_PX, Part } from './Part.mjs';
|
|
6
6
|
import { ProgressBarChartContainer, ProgressBarChartHeader, ProgressBarChartTitle, ProgressBarWrapper, ProgressBarPartsContainer, ProgressBarAttentionLabel, ProgressBarAttentionLabelIcon } from './ProgressBarChart.styles.mjs';
|
|
7
|
-
import attentionIcon__default from "../../../../../assets/
|
|
7
|
+
import attentionIcon__default from "../../../../../assets/attention2.svg";
|
|
8
8
|
"use strict";
|
|
9
9
|
const ProgressBarChart = ({
|
|
10
10
|
title,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var attentionIcon = require("../../../../../../assets/
|
|
6
|
+
var attentionIcon = require("../../../../../../assets/attention2.svg");
|
|
7
7
|
function _interopDefault(e) {
|
|
8
8
|
return e && e.__esModule ? e : {
|
|
9
9
|
default: e
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "../../../../../../assets/
|
|
2
|
-
export { default } from "../../../../../../assets/
|
|
1
|
+
export * from "../../../../../../assets/attention2.svg";
|
|
2
|
+
export { default } from "../../../../../../assets/attention2.svg";
|
|
3
3
|
//# sourceMappingURL=attention.svg.mjs.map
|
|
@@ -19,8 +19,8 @@ var ComputeResourceCalculator_types = require('../../../../ComputeResourceCalcul
|
|
|
19
19
|
var CustomImage = require('../../../../../CustomImage/CustomImage.js');
|
|
20
20
|
var SearchIcon = require("../../../../../../assets/search2.svg");
|
|
21
21
|
var StyleableSvgImage = require('../../../../../StyleableSvgImage/StyleableSvgImage.js');
|
|
22
|
-
var MinusIcon = require("../../../../../../assets/
|
|
23
|
-
var PlusIcon = require("../../../../../../assets/
|
|
22
|
+
var MinusIcon = require("../../../../../../assets/minus5.svg");
|
|
23
|
+
var PlusIcon = require("../../../../../../assets/plus4.svg");
|
|
24
24
|
function _interopDefault(e) {
|
|
25
25
|
return e && e.__esModule ? e : {
|
|
26
26
|
default: e
|
|
@@ -17,8 +17,8 @@ import { isMessageFormatted } from '../../../../ComputeResourceCalculator/Comput
|
|
|
17
17
|
import { CustomImage } from '../../../../../CustomImage/CustomImage.mjs';
|
|
18
18
|
import SearchIcon__default from "../../../../../../assets/search2.svg";
|
|
19
19
|
import { StyleableSvgImage } from '../../../../../StyleableSvgImage/StyleableSvgImage.mjs';
|
|
20
|
-
import MinusIcon__default from "../../../../../../assets/
|
|
21
|
-
import PlusIcon__default from "../../../../../../assets/
|
|
20
|
+
import MinusIcon__default from "../../../../../../assets/minus5.svg";
|
|
21
|
+
import PlusIcon__default from "../../../../../../assets/plus4.svg";
|
|
22
22
|
"use strict";
|
|
23
23
|
const NoopPlaceholder = () => /* @__PURE__ */jsx(Fragment, {});
|
|
24
24
|
const PoeConsumerSelectModal = ({
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var MinusIcon = require("../../../../../../assets/
|
|
6
|
+
var MinusIcon = require("../../../../../../assets/minus5.svg");
|
|
7
7
|
function _interopDefault(e) {
|
|
8
8
|
return e && e.__esModule ? e : {
|
|
9
9
|
default: e
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "../../../../../../assets/
|
|
2
|
-
export { default } from "../../../../../../assets/
|
|
1
|
+
export * from "../../../../../../assets/minus5.svg";
|
|
2
|
+
export { default } from "../../../../../../assets/minus5.svg";
|
|
3
3
|
//# sourceMappingURL=minus.svg.mjs.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var PlusIcon = require("../../../../../../assets/
|
|
6
|
+
var PlusIcon = require("../../../../../../assets/plus4.svg");
|
|
7
7
|
function _interopDefault(e) {
|
|
8
8
|
return e && e.__esModule ? e : {
|
|
9
9
|
default: e
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "../../../../../../assets/
|
|
2
|
-
export { default } from "../../../../../../assets/
|
|
1
|
+
export * from "../../../../../../assets/plus4.svg";
|
|
2
|
+
export { default } from "../../../../../../assets/plus4.svg";
|
|
3
3
|
//# sourceMappingURL=plus.svg.mjs.map
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * as url from "./url";
|
|
2
|
-
export * as money from "./money
|
|
2
|
+
export * as money from "./money";
|
|
3
3
|
export * as number from "./number";
|
|
4
4
|
export * as string from "./string";
|
|
5
5
|
export * as array from "./array";
|
|
@@ -9,12 +9,10 @@ export * as countryAndZones from "./countriesAndZones";
|
|
|
9
9
|
export * as address from "./address";
|
|
10
10
|
export * as tax from "./tax";
|
|
11
11
|
export * as zod from "./zod";
|
|
12
|
-
export * as collectionSlug from "./collectionSlug";
|
|
13
12
|
export * as shipping from "./shipping";
|
|
14
13
|
export * as measures from "./measures";
|
|
15
14
|
export * as errors from "./errors";
|
|
16
15
|
export * as tags from "./tags";
|
|
17
|
-
export * as wattage from "./wattage";
|
|
18
16
|
export * as product from "./product";
|
|
19
17
|
export * as asset from "./asset";
|
|
20
18
|
export * as imageOptimizer from "./imageOptimizer";
|
package/lib/utils/index.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var url$1 = require('./url.js');
|
|
4
|
-
var
|
|
4
|
+
var index = require('./money/index.js');
|
|
5
5
|
var number$1 = require('./number.js');
|
|
6
6
|
var string$1 = require('./string.js');
|
|
7
7
|
var array$1 = require('./array.js');
|
|
8
|
-
var index = require('./nextjs/index.js');
|
|
8
|
+
var index$1 = require('./nextjs/index.js');
|
|
9
9
|
var country$1 = require('./country.js');
|
|
10
10
|
var countriesAndZones = require('./countriesAndZones.js');
|
|
11
11
|
var address$1 = require('./address.js');
|
|
12
|
-
var index$
|
|
12
|
+
var index$2 = require('./tax/index.js');
|
|
13
13
|
var zod$1 = require('./zod.js');
|
|
14
|
-
var collectionSlug$1 = require('./collectionSlug.js');
|
|
15
14
|
var shipping$1 = require('./shipping.js');
|
|
16
15
|
var measures$1 = require('./measures.js');
|
|
17
16
|
var errors$1 = require('./errors.js');
|
|
18
17
|
var tags$1 = require('./tags.js');
|
|
19
|
-
var wattage$1 = require('./wattage.js');
|
|
20
18
|
var product$1 = require('./product.js');
|
|
21
19
|
var asset$1 = require('./asset.js');
|
|
22
20
|
var imageOptimizer$1 = require('./imageOptimizer.js');
|
|
@@ -26,22 +24,20 @@ var blackFriday$1 = require('./blackFriday.js');
|
|
|
26
24
|
var sales$1 = require('./sales.js');
|
|
27
25
|
"use strict";
|
|
28
26
|
exports.url = url$1;
|
|
29
|
-
exports.money =
|
|
27
|
+
exports.money = index;
|
|
30
28
|
exports.number = number$1;
|
|
31
29
|
exports.string = string$1;
|
|
32
30
|
exports.array = array$1;
|
|
33
|
-
exports.nextjs = index;
|
|
31
|
+
exports.nextjs = index$1;
|
|
34
32
|
exports.country = country$1;
|
|
35
33
|
exports.countryAndZones = countriesAndZones;
|
|
36
34
|
exports.address = address$1;
|
|
37
|
-
exports.tax = index$
|
|
35
|
+
exports.tax = index$2;
|
|
38
36
|
exports.zod = zod$1;
|
|
39
|
-
exports.collectionSlug = collectionSlug$1;
|
|
40
37
|
exports.shipping = shipping$1;
|
|
41
38
|
exports.measures = measures$1;
|
|
42
39
|
exports.errors = errors$1;
|
|
43
40
|
exports.tags = tags$1;
|
|
44
|
-
exports.wattage = wattage$1;
|
|
45
41
|
exports.product = product$1;
|
|
46
42
|
exports.asset = asset$1;
|
|
47
43
|
exports.imageOptimizer = imageOptimizer$1;
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/utils/index.mjs
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import * as url$1 from './url.mjs';
|
|
2
2
|
export { url$1 as url };
|
|
3
|
-
import * as
|
|
4
|
-
export {
|
|
3
|
+
import * as index from './money/index.mjs';
|
|
4
|
+
export { index as money };
|
|
5
5
|
import * as number$1 from './number.mjs';
|
|
6
6
|
export { number$1 as number };
|
|
7
7
|
import * as string$1 from './string.mjs';
|
|
8
8
|
export { string$1 as string };
|
|
9
9
|
import * as array$1 from './array.mjs';
|
|
10
10
|
export { array$1 as array };
|
|
11
|
-
import * as index from './nextjs/index.mjs';
|
|
12
|
-
export { index as nextjs };
|
|
11
|
+
import * as index$1 from './nextjs/index.mjs';
|
|
12
|
+
export { index$1 as nextjs };
|
|
13
13
|
import * as country$1 from './country.mjs';
|
|
14
14
|
export { country$1 as country };
|
|
15
15
|
import * as countriesAndZones from './countriesAndZones.mjs';
|
|
16
16
|
export { countriesAndZones as countryAndZones };
|
|
17
17
|
import * as address$1 from './address.mjs';
|
|
18
18
|
export { address$1 as address };
|
|
19
|
-
import * as index$
|
|
20
|
-
export { index$
|
|
19
|
+
import * as index$2 from './tax/index.mjs';
|
|
20
|
+
export { index$2 as tax };
|
|
21
21
|
import * as zod$1 from './zod.mjs';
|
|
22
22
|
export { zod$1 as zod };
|
|
23
|
-
import * as collectionSlug$1 from './collectionSlug.mjs';
|
|
24
|
-
export { collectionSlug$1 as collectionSlug };
|
|
25
23
|
import * as shipping$1 from './shipping.mjs';
|
|
26
24
|
export { shipping$1 as shipping };
|
|
27
25
|
import * as measures$1 from './measures.mjs';
|
|
@@ -30,8 +28,6 @@ import * as errors$1 from './errors.mjs';
|
|
|
30
28
|
export { errors$1 as errors };
|
|
31
29
|
import * as tags$1 from './tags.mjs';
|
|
32
30
|
export { tags$1 as tags };
|
|
33
|
-
import * as wattage$1 from './wattage.mjs';
|
|
34
|
-
export { wattage$1 as wattage };
|
|
35
31
|
import * as product$1 from './product.mjs';
|
|
36
32
|
export { product$1 as product };
|
|
37
33
|
import * as asset$1 from './asset.mjs';
|
package/lib/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
class FixedAmountAllocator {
|
|
8
|
+
/**
|
|
9
|
+
* How much we have left to allocate for given allocation from the remaining total
|
|
10
|
+
*/
|
|
11
|
+
remainingAllocationAmount;
|
|
12
|
+
/**
|
|
13
|
+
* How much we have left to allocate in total
|
|
14
|
+
*/
|
|
15
|
+
remainingTotalAmount;
|
|
16
|
+
currency;
|
|
17
|
+
constructor({
|
|
18
|
+
initialAllocateAmount,
|
|
19
|
+
initialTotalAmount,
|
|
20
|
+
currency
|
|
21
|
+
}) {
|
|
22
|
+
this.remainingAllocationAmount = misc.getDinero(initialAllocateAmount, currency);
|
|
23
|
+
this.remainingTotalAmount = misc.getDinero(initialTotalAmount, currency);
|
|
24
|
+
this.currency = misc.getDineroCurrency(currency);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* We always allocate biggest share to first item
|
|
28
|
+
*/
|
|
29
|
+
allocate(lineItemTotal, currency) {
|
|
30
|
+
errors.assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
|
|
31
|
+
const lineItemTotalDinero = misc.getDinero(lineItemTotal, currency);
|
|
32
|
+
if (lineItemTotal === 0) {
|
|
33
|
+
return lineItemTotalDinero;
|
|
34
|
+
}
|
|
35
|
+
const [allocationAmount, remainingAllocationAmount] = dinero_js.allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(misc.amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
|
|
36
|
+
errors.assert(!!allocationAmount, "Allocation amount is zero");
|
|
37
|
+
errors.assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
|
|
38
|
+
this.remainingAllocationAmount = remainingAllocationAmount;
|
|
39
|
+
this.remainingTotalAmount = dinero_js.subtract(this.remainingTotalAmount, lineItemTotalDinero);
|
|
40
|
+
return dinero_js.greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.FixedAmountAllocator = FixedAmountAllocator;
|
|
44
|
+
//# 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","remainingAllocationAmount","remainingTotalAmount","currency","constructor","initialAllocateAmount","initialTotalAmount","getDinero","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;AAWO,MAAMA,oBAAqB,CAAA;EAAA;AAAA;AAAA;EAIzBC,yBAAA;EAAA;AAAA;AAAA;EAIAC,oBAAA;EACAC,QAAA;EAEPC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAH;EAAA,CAKC,EAAA;IACI,IAAA,CAAAF,yBAAA,GAA4BM,cAAU,CAAAF,qBAAA,EAAuBF,QAAQ,CAAA;IACrE,IAAA,CAAAD,oBAAA,GAAuBK,cAAU,CAAAD,kBAAA,EAAoBH,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,uBAAkBL,QAAQ,CAAA;EAAA;EAC5C;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CAAAA,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACvB,+BAA+BA,QAAQ,SAAS,IAAA,CAAKA,SAASS,IAAI,EACpE,CAAA;IACM,MAAAC,mBAAA,GAAsBN,IAAAA,CAAAA,SAAU,CAAAG,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IAAA;IAGH,MAAA,CAACC,gBAAkB,EAAAb,yBAAyB,CAAI,GAAAQ,SAAA,CAAAA,QAAA,CACpD,IAAK,CAAAR,yBAAA,EACL,CACES,aAAA,EACAK,KAAKC,GAAI,CAAAC,IAAA,CAAAA,MAAA,CAAO,KAAKf,oBAAoB,CAAA,GAAIQ,eAAe,CAAC,CAAA,CAEjE,CAAA;IAEOC,aAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CAAAA,MAAA,CACE,CAAC,CAACV,yBAAA,EACF,wCACF,CAAA;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKC,oBAAuB,GAAAgB,SAAA,CAAAA,QAAA,CAC1B,IAAK,CAAAhB,oBAAA,EACLW,mBACF,CAAA;IAMA,OAAOM,SAAY,CAAAA,WAAA,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EAAA;AAER;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
class FixedAmountAllocator {
|
|
6
|
+
/**
|
|
7
|
+
* How much we have left to allocate for given allocation from the remaining total
|
|
8
|
+
*/
|
|
9
|
+
remainingAllocationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* How much we have left to allocate in total
|
|
12
|
+
*/
|
|
13
|
+
remainingTotalAmount;
|
|
14
|
+
currency;
|
|
15
|
+
constructor({
|
|
16
|
+
initialAllocateAmount,
|
|
17
|
+
initialTotalAmount,
|
|
18
|
+
currency
|
|
19
|
+
}) {
|
|
20
|
+
this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);
|
|
21
|
+
this.remainingTotalAmount = getDinero(initialTotalAmount, currency);
|
|
22
|
+
this.currency = getDineroCurrency(currency);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* We always allocate biggest share to first item
|
|
26
|
+
*/
|
|
27
|
+
allocate(lineItemTotal, currency) {
|
|
28
|
+
assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
|
|
29
|
+
const lineItemTotalDinero = getDinero(lineItemTotal, currency);
|
|
30
|
+
if (lineItemTotal === 0) {
|
|
31
|
+
return lineItemTotalDinero;
|
|
32
|
+
}
|
|
33
|
+
const [allocationAmount, remainingAllocationAmount] = allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
|
|
34
|
+
assert(!!allocationAmount, "Allocation amount is zero");
|
|
35
|
+
assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
|
|
36
|
+
this.remainingAllocationAmount = remainingAllocationAmount;
|
|
37
|
+
this.remainingTotalAmount = subtract(this.remainingTotalAmount, lineItemTotalDinero);
|
|
38
|
+
return greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export { FixedAmountAllocator };
|
|
42
|
+
//# 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","remainingAllocationAmount","remainingTotalAmount","currency","constructor","initialAllocateAmount","initialTotalAmount","getDinero","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;AAWO,MAAMA,oBAAqB,CAAA;EAAA;AAAA;AAAA;EAIzBC,yBAAA;EAAA;AAAA;AAAA;EAIAC,oBAAA;EACAC,QAAA;EAEPC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAH;EAAA,CAKC,EAAA;IACI,IAAA,CAAAF,yBAAA,GAA4BM,SAAU,CAAAF,qBAAA,EAAuBF,QAAQ,CAAA;IACrE,IAAA,CAAAD,oBAAA,GAAuBK,SAAU,CAAAD,kBAAA,EAAoBH,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,kBAAkBL,QAAQ,CAAA;EAAA;EAC5C;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACvB,+BAA+BA,QAAQ,SAAS,IAAA,CAAKA,SAASS,IAAI,EACpE,CAAA;IACM,MAAAC,mBAAA,GAAsBN,SAAU,CAAAG,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IAAA;IAGH,MAAA,CAACC,gBAAkB,EAAAb,yBAAyB,CAAI,GAAAQ,QAAA,CACpD,IAAK,CAAAR,yBAAA,EACL,CACES,aAAA,EACAK,KAAKC,GAAI,CAAAC,MAAA,CAAO,KAAKf,oBAAoB,CAAA,GAAIQ,eAAe,CAAC,CAAA,CAEjE,CAAA;IAEOC,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CACE,CAAC,CAACV,yBAAA,EACF,wCACF,CAAA;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKC,oBAAuB,GAAAgB,QAAA,CAC1B,IAAK,CAAAhB,oBAAA,EACLW,mBACF,CAAA;IAMA,OAAOM,WAAY,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EAAA;AAER;"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var misc = require('../misc.js');
|
|
4
|
+
var fixedAmount = require('./fixedAmount.js');
|
|
5
|
+
"use strict";
|
|
6
|
+
class ProductAmountAllocator {
|
|
7
|
+
// #############################################################################
|
|
8
|
+
// Fixed values
|
|
9
|
+
// #############################################################################
|
|
10
|
+
#itemPrice;
|
|
11
|
+
#currency;
|
|
12
|
+
// #############################################################################
|
|
13
|
+
/**
|
|
14
|
+
* Remaining quantity to allocate
|
|
15
|
+
*/
|
|
16
|
+
quantity;
|
|
17
|
+
// #############################################################################
|
|
18
|
+
// Specific amount allocators
|
|
19
|
+
// #############################################################################
|
|
20
|
+
#subtotal;
|
|
21
|
+
#discountAmount;
|
|
22
|
+
#taxableAmount;
|
|
23
|
+
#tax;
|
|
24
|
+
#total;
|
|
25
|
+
constructor(productSummary) {
|
|
26
|
+
const currency = productSummary.currency;
|
|
27
|
+
const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
|
|
28
|
+
this.#itemPrice = productSummary.itemPrice;
|
|
29
|
+
this.#currency = currency;
|
|
30
|
+
this.quantity = productSummary.quantity;
|
|
31
|
+
this.#subtotal = new fixedAmount.FixedAmountAllocator({
|
|
32
|
+
initialAllocateAmount: productSummary.subtotal,
|
|
33
|
+
initialTotalAmount: priceForAllocation,
|
|
34
|
+
currency
|
|
35
|
+
});
|
|
36
|
+
this.#discountAmount = new fixedAmount.FixedAmountAllocator({
|
|
37
|
+
initialAllocateAmount: productSummary.discountAmount,
|
|
38
|
+
initialTotalAmount: priceForAllocation,
|
|
39
|
+
currency
|
|
40
|
+
});
|
|
41
|
+
this.#taxableAmount = new fixedAmount.FixedAmountAllocator({
|
|
42
|
+
initialAllocateAmount: productSummary.taxableAmount,
|
|
43
|
+
initialTotalAmount: priceForAllocation,
|
|
44
|
+
currency
|
|
45
|
+
});
|
|
46
|
+
this.#tax = new fixedAmount.FixedAmountAllocator({
|
|
47
|
+
initialAllocateAmount: productSummary.tax,
|
|
48
|
+
initialTotalAmount: priceForAllocation,
|
|
49
|
+
currency
|
|
50
|
+
});
|
|
51
|
+
this.#total = new fixedAmount.FixedAmountAllocator({
|
|
52
|
+
initialAllocateAmount: productSummary.total,
|
|
53
|
+
initialTotalAmount: priceForAllocation,
|
|
54
|
+
currency
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
allocateQty(quantity) {
|
|
58
|
+
let quantityNormalized = Math.max(quantity, 0);
|
|
59
|
+
quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : this.quantity;
|
|
60
|
+
this.quantity = Math.max(this.quantity - quantityNormalized, 0);
|
|
61
|
+
const itemQuantityPrice = this.#itemPrice * quantityNormalized;
|
|
62
|
+
return {
|
|
63
|
+
itemPrice: this.#itemPrice,
|
|
64
|
+
currency: this.#currency,
|
|
65
|
+
quantity: quantityNormalized,
|
|
66
|
+
subtotal: misc.amount(this.#subtotal.allocate(itemQuantityPrice, this.#currency)),
|
|
67
|
+
discountAmount: misc.amount(this.#discountAmount.allocate(itemQuantityPrice, this.#currency)),
|
|
68
|
+
taxableAmount: misc.amount(this.#taxableAmount.allocate(itemQuantityPrice, this.#currency)),
|
|
69
|
+
tax: misc.amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),
|
|
70
|
+
total: misc.amount(this.#total.allocate(itemQuantityPrice, this.#currency))
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ProductAmountAllocator = ProductAmountAllocator;
|
|
75
|
+
//# 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\n ? quantityNormalized\n : this.quantity;\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":["ProductAmountAllocator","itemPrice","currency","quantity","subtotal","discountAmount","taxableAmount","tax","total","constructor","productSummary","priceForAllocation","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","amount","allocate"],"mappings":";;;;;AAQO,MAAMA,sBAAuB,CAAA;EAAA;EAAA;EAAA;EAIzB,CAAAC,SAAA;EACA,CAAAC,QAAA;EAAA;EAAA;AAAA;AAAA;EAKTC,QAAA;EAAA;EAAA;EAAA;EAIA,CAAAC,QAAA;EACA,CAAAC,cAAA;EACA,CAAAC,aAAA;EACA,CAAAC,GAAA;EACA,CAAAC,KAAA;EAEAC,YAAYC,cAAqC,EAAA;IAC/C,MAAMR,WAAWQ,cAAe,CAAAR,QAAA;IAK1B,MAAAS,kBAAA,GACJD,cAAe,CAAAT,SAAA,GAAYS,cAAe,CAAAP,QAAA;IAE5C,IAAA,CAAK,CAAAF,YAAaS,cAAe,CAAAT,SAAA;IACjC,IAAA,CAAK,CAAYC,QAAA,GAAAA,QAAA;IACjB,IAAA,CAAKC,WAAWO,cAAe,CAAAP,QAAA;IAC1B,IAAA,CAAA,CAAAC,QAAA,GAAY,IAAIQ,gCAAqB,CAAA;MACxCC,uBAAuBH,cAAe,CAAAN,QAAA;MACtCU,kBAAoB,EAAAH,kBAAA;MACpBT;IAAA,CACD,CAAA;IACI,IAAA,CAAA,CAAAG,cAAA,GAAkB,IAAIO,gCAAqB,CAAA;MAC9CC,uBAAuBH,cAAe,CAAAL,cAAA;MACtCS,kBAAoB,EAAAH,kBAAA;MACpBT;IAAA,CACD,CAAA;IACI,IAAA,CAAA,CAAAI,aAAA,GAAiB,IAAIM,gCAAqB,CAAA;MAC7CC,uBAAuBH,cAAe,CAAAJ,aAAA;MACtCQ,kBAAoB,EAAAH,kBAAA;MACpBT;IAAA,CACD,CAAA;IACI,IAAA,CAAA,CAAAK,GAAA,GAAO,IAAIK,gCAAqB,CAAA;MACnCC,uBAAuBH,cAAe,CAAAH,GAAA;MACtCO,kBAAoB,EAAAH,kBAAA;MACpBT;IAAA,CACD,CAAA;IACI,IAAA,CAAA,CAAAM,KAAA,GAAS,IAAII,gCAAqB,CAAA;MACrCC,uBAAuBH,cAAe,CAAAF,KAAA;MACtCM,kBAAoB,EAAAH,kBAAA;MACpBT;IAAA,CACD,CAAA;EAAA;EAGHa,YAAYZ,QAAuC,EAAA;IAEjD,IAAIa,kBAAqB,GAAAC,IAAA,CAAKC,GAAI,CAAAf,QAAA,EAAU,CAAC,CAAA;IAC7Ca,kBAAA,GACE,IAAK,CAAAb,QAAA,GAAWa,kBAAsB,IAAA,CAAA,GAClCA,qBACA,IAAK,CAAAb,QAAA;IAGX,IAAA,CAAKA,WAAWc,IAAK,CAAAC,GAAA,CAAI,IAAK,CAAAf,QAAA,GAAWa,oBAAoB,CAAC,CAAA;IAGxD,MAAAG,iBAAA,GAAoB,KAAK,CAAAlB,SAAa,GAAAe,kBAAA;IAErC,OAAA;MACLf,WAAW,IAAK,CAAA,CAAAA,SAAA;MAChBC,UAAU,IAAK,CAAA,CAAAA,QAAA;MACfC,QAAU,EAAAa,kBAAA;MACVZ,QAAU,EAAAgB,IAAA,CAAAA,MAAA,CACR,IAAK,CAAA,CAAAhB,QAAA,CAAUiB,QAAS,CAAAF,iBAAA,EAAmB,KAAK,CAASjB,QAAA,CAC3D,CAAA;MACAG,cAAgB,EAAAe,IAAA,CAAAA,MAAA,CACd,IAAK,CAAA,CAAAf,cAAA,CAAgBgB,QAAS,CAAAF,iBAAA,EAAmB,KAAK,CAASjB,QAAA,CACjE,CAAA;MACAI,aAAe,EAAAc,IAAA,CAAAA,MAAA,CACb,IAAK,CAAA,CAAAd,aAAA,CAAee,QAAS,CAAAF,iBAAA,EAAmB,KAAK,CAASjB,QAAA,CAChE,CAAA;MACAK,GAAA,EAAKa,IAAAA,CAAAA,OAAO,IAAK,CAAA,CAAAb,GAAA,CAAKc,SAASF,iBAAmB,EAAA,IAAA,CAAK,CAAAjB,QAAS,CAAC,CAAA;MACjEM,KAAA,EAAOY,YAAO,IAAK,CAAA,CAAAZ,KAAA,CAAOa,SAASF,iBAAmB,EAAA,IAAA,CAAK,SAAS,CAAC;IACvE,CAAA;EAAA;AAEJ;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { amount } from '../misc.mjs';
|
|
2
|
+
import { FixedAmountAllocator } from './fixedAmount.mjs';
|
|
3
|
+
"use strict";
|
|
4
|
+
class ProductAmountAllocator {
|
|
5
|
+
// #############################################################################
|
|
6
|
+
// Fixed values
|
|
7
|
+
// #############################################################################
|
|
8
|
+
#itemPrice;
|
|
9
|
+
#currency;
|
|
10
|
+
// #############################################################################
|
|
11
|
+
/**
|
|
12
|
+
* Remaining quantity to allocate
|
|
13
|
+
*/
|
|
14
|
+
quantity;
|
|
15
|
+
// #############################################################################
|
|
16
|
+
// Specific amount allocators
|
|
17
|
+
// #############################################################################
|
|
18
|
+
#subtotal;
|
|
19
|
+
#discountAmount;
|
|
20
|
+
#taxableAmount;
|
|
21
|
+
#tax;
|
|
22
|
+
#total;
|
|
23
|
+
constructor(productSummary) {
|
|
24
|
+
const currency = productSummary.currency;
|
|
25
|
+
const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
|
|
26
|
+
this.#itemPrice = productSummary.itemPrice;
|
|
27
|
+
this.#currency = currency;
|
|
28
|
+
this.quantity = productSummary.quantity;
|
|
29
|
+
this.#subtotal = new FixedAmountAllocator({
|
|
30
|
+
initialAllocateAmount: productSummary.subtotal,
|
|
31
|
+
initialTotalAmount: priceForAllocation,
|
|
32
|
+
currency
|
|
33
|
+
});
|
|
34
|
+
this.#discountAmount = new FixedAmountAllocator({
|
|
35
|
+
initialAllocateAmount: productSummary.discountAmount,
|
|
36
|
+
initialTotalAmount: priceForAllocation,
|
|
37
|
+
currency
|
|
38
|
+
});
|
|
39
|
+
this.#taxableAmount = new FixedAmountAllocator({
|
|
40
|
+
initialAllocateAmount: productSummary.taxableAmount,
|
|
41
|
+
initialTotalAmount: priceForAllocation,
|
|
42
|
+
currency
|
|
43
|
+
});
|
|
44
|
+
this.#tax = new FixedAmountAllocator({
|
|
45
|
+
initialAllocateAmount: productSummary.tax,
|
|
46
|
+
initialTotalAmount: priceForAllocation,
|
|
47
|
+
currency
|
|
48
|
+
});
|
|
49
|
+
this.#total = new FixedAmountAllocator({
|
|
50
|
+
initialAllocateAmount: productSummary.total,
|
|
51
|
+
initialTotalAmount: priceForAllocation,
|
|
52
|
+
currency
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
allocateQty(quantity) {
|
|
56
|
+
let quantityNormalized = Math.max(quantity, 0);
|
|
57
|
+
quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : this.quantity;
|
|
58
|
+
this.quantity = Math.max(this.quantity - quantityNormalized, 0);
|
|
59
|
+
const itemQuantityPrice = this.#itemPrice * quantityNormalized;
|
|
60
|
+
return {
|
|
61
|
+
itemPrice: this.#itemPrice,
|
|
62
|
+
currency: this.#currency,
|
|
63
|
+
quantity: quantityNormalized,
|
|
64
|
+
subtotal: amount(this.#subtotal.allocate(itemQuantityPrice, this.#currency)),
|
|
65
|
+
discountAmount: amount(this.#discountAmount.allocate(itemQuantityPrice, this.#currency)),
|
|
66
|
+
taxableAmount: amount(this.#taxableAmount.allocate(itemQuantityPrice, this.#currency)),
|
|
67
|
+
tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),
|
|
68
|
+
total: amount(this.#total.allocate(itemQuantityPrice, this.#currency))
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export { ProductAmountAllocator };
|
|
73
|
+
//# 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\n ? quantityNormalized\n : this.quantity;\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":["ProductAmountAllocator","itemPrice","currency","quantity","subtotal","discountAmount","taxableAmount","tax","total","constructor","productSummary","priceForAllocation","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","amount","allocate"],"mappings":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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) {
|
|
21
|
+
const exchangeRate = toFixedExchangeRate(rate, true);
|
|
22
|
+
return toFixedExchangeRate(1 / exchangeRate, false);
|
|
23
|
+
}
|
|
24
|
+
exports.invertExchangeRate = invertExchangeRate;
|
|
25
|
+
exports.toFixedExchangeRate = toFixedExchangeRate;
|
|
26
|
+
exports.toSnapshotExchangeRate = toSnapshotExchangeRate;
|
|
27
|
+
//# sourceMappingURL=exchangeRate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\";\nimport type { Cents, TaxRate } from \"./types\";\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: TaxRate,\n): {\n amount: Cents;\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?: 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) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,MAAA,CAAAA,OAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,aAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,YAAA,CAAAA,UAAA,CACdJ,YAAA,EACAK,SAAAA,CAAAA,6BAA8B,CAAAC,IAAA,EAC9BD,uCAA8B,CAAAE,QAChC,CAAA;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,SAAAA,CAAAA,6BAA8B,CAAAE;EACvC,CAAA;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,QACF,CAAA;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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) {
|
|
19
|
+
const exchangeRate = toFixedExchangeRate(rate, true);
|
|
20
|
+
return toFixedExchangeRate(1 / exchangeRate, false);
|
|
21
|
+
}
|
|
22
|
+
export { invertExchangeRate, toFixedExchangeRate, toSnapshotExchangeRate };
|
|
23
|
+
//# sourceMappingURL=exchangeRate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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\";\nimport type { Cents, TaxRate } from \"./types\";\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: TaxRate,\n): {\n amount: Cents;\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?: 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) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;AAea,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,QAChC,CAAA;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,6BAA8B,CAAAE;EACvC,CAAA;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,QACF,CAAA;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;"}
|