@ubnt/store.core 9.20.0 → 9.21.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.
Files changed (127) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/lib/assets/close.svg +1 -4
  3. package/lib/assets/close2.svg +3 -1
  4. package/lib/assets/close3.svg +3 -2
  5. package/lib/assets/minus4.svg +8 -8
  6. package/lib/assets/minus5.svg +8 -8
  7. package/lib/assets/plus5.svg +9 -9
  8. package/lib/assets/plus6.svg +9 -9
  9. package/lib/components/CustomImage/CustomImage.js +1 -1
  10. package/lib/components/CustomImage/CustomImage.mjs +1 -1
  11. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  12. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  13. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  14. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  15. package/lib/components/GridGallery/GridModal/GridModal.js +1 -1
  16. package/lib/components/GridGallery/GridModal/GridModal.mjs +1 -1
  17. package/lib/components/Header/CartModalV2/CartModal.js +1 -1
  18. package/lib/components/Header/CartModalV2/CartModal.mjs +1 -1
  19. package/lib/components/Header/Header.js +1 -1
  20. package/lib/components/Header/Header.mjs +1 -1
  21. package/lib/components/LandingPagePro/LandingPagePro.d.ts +3 -0
  22. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  23. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  24. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  25. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  26. package/lib/components/LandingPageSidebar/LandingPageSidebar.js +1 -1
  27. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs +1 -1
  28. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  29. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  30. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  31. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  32. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  33. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  34. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  35. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  36. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  37. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  38. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  39. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  40. package/lib/components/Search/Input/Input.js +1 -1
  41. package/lib/components/Search/Input/Input.mjs +1 -1
  42. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  43. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  44. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  45. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  46. package/lib/constants/icons/generic/close.svg.js +1 -1
  47. package/lib/constants/icons/generic/close.svg.mjs +2 -2
  48. package/lib/constants/icons/generic/index.js +1 -1
  49. package/lib/constants/icons/generic/index.mjs +1 -1
  50. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  51. package/lib/constants/icons/options/colors/index.js +3 -3
  52. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  53. package/lib/constants/icons/options/styles/index.js +3 -3
  54. package/lib/constants/optionIcons.js +6 -6
  55. package/lib/constants/optionIcons.mjs +4 -4
  56. package/lib/utils/money/allocators/fixedAmount.d.ts +26 -0
  57. package/lib/utils/money/allocators/fixedAmount.js +52 -0
  58. package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
  59. package/lib/utils/money/allocators/fixedAmount.mjs +50 -0
  60. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
  61. package/lib/utils/money/allocators/index.d.ts +2 -0
  62. package/lib/utils/money/allocators/index.js +8 -0
  63. package/lib/utils/money/allocators/index.js.map +1 -0
  64. package/lib/utils/money/allocators/index.mjs +4 -0
  65. package/lib/utils/money/allocators/index.mjs.map +1 -0
  66. package/lib/utils/money/allocators/productAmount.d.ts +13 -0
  67. package/lib/utils/money/allocators/productAmount.js +98 -0
  68. package/lib/utils/money/allocators/productAmount.js.map +1 -0
  69. package/lib/utils/money/allocators/productAmount.mjs +96 -0
  70. package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
  71. package/lib/utils/money/constants.d.ts +60 -22
  72. package/lib/utils/money/constants.js +71 -7
  73. package/lib/utils/money/constants.js.map +1 -1
  74. package/lib/utils/money/constants.mjs +68 -6
  75. package/lib/utils/money/constants.mjs.map +1 -1
  76. package/lib/utils/money/exchangeRate.d.ts +31 -0
  77. package/lib/utils/money/exchangeRate.js +27 -0
  78. package/lib/utils/money/exchangeRate.js.map +1 -0
  79. package/lib/utils/money/exchangeRate.mjs +23 -0
  80. package/lib/utils/money/exchangeRate.mjs.map +1 -0
  81. package/lib/utils/money/format.d.ts +10 -5
  82. package/lib/utils/money/format.js +22 -14
  83. package/lib/utils/money/format.js.map +1 -1
  84. package/lib/utils/money/format.mjs +23 -16
  85. package/lib/utils/money/format.mjs.map +1 -1
  86. package/lib/utils/money/index.d.ts +4 -1
  87. package/lib/utils/money/index.js +25 -8
  88. package/lib/utils/money/index.js.map +1 -1
  89. package/lib/utils/money/index.mjs +7 -4
  90. package/lib/utils/money/index.mjs.map +1 -1
  91. package/lib/utils/money/misc.d.ts +68 -28
  92. package/lib/utils/money/misc.js +35 -64
  93. package/lib/utils/money/misc.js.map +1 -1
  94. package/lib/utils/money/misc.mjs +32 -43
  95. package/lib/utils/money/misc.mjs.map +1 -1
  96. package/lib/utils/money/misc.private.d.ts +23 -0
  97. package/lib/utils/money/misc.private.js +46 -0
  98. package/lib/utils/money/misc.private.js.map +1 -0
  99. package/lib/utils/money/misc.private.mjs +21 -0
  100. package/lib/utils/money/misc.private.mjs.map +1 -0
  101. package/lib/utils/money/shipping.d.ts +5 -0
  102. package/lib/utils/money/shipping.js +8 -0
  103. package/lib/utils/money/shipping.js.map +1 -0
  104. package/lib/utils/money/shipping.mjs +6 -0
  105. package/lib/utils/money/shipping.mjs.map +1 -0
  106. package/lib/utils/money/tax.d.ts +38 -2
  107. package/lib/utils/money/tax.js +46 -10
  108. package/lib/utils/money/tax.js.map +1 -1
  109. package/lib/utils/money/tax.mjs +42 -11
  110. package/lib/utils/money/tax.mjs.map +1 -1
  111. package/lib/utils/money/tax.private.d.ts +17 -0
  112. package/lib/utils/money/tax.private.js +65 -0
  113. package/lib/utils/money/tax.private.js.map +1 -0
  114. package/lib/utils/money/tax.private.mjs +60 -0
  115. package/lib/utils/money/tax.private.mjs.map +1 -0
  116. package/lib/utils/money/types.d.ts +78 -3
  117. package/lib/utils/number.d.ts +1 -1
  118. package/lib/utils/number.js +1 -1
  119. package/lib/utils/number.js.map +1 -1
  120. package/lib/utils/number.mjs +1 -1
  121. package/lib/utils/number.mjs.map +1 -1
  122. package/package.json +1 -1
  123. package/lib/utils/validations.d.ts +0 -15
  124. package/lib/utils/validations.js +0 -23
  125. package/lib/utils/validations.js.map +0 -1
  126. package/lib/utils/validations.mjs +0 -21
  127. package/lib/utils/validations.mjs.map +0 -1
@@ -0,0 +1,52 @@
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ class FixedAmountAllocator {
16
+ constructor({
17
+ initialAllocateAmount,
18
+ initialTotalAmount,
19
+ currency
20
+ }) {
21
+ /**
22
+ * How much we have left to allocate for given allocation from the remaining total
23
+ */
24
+ __publicField(this, "remainingAllocationAmount");
25
+ /**
26
+ * How much we have left to allocate in total
27
+ */
28
+ __publicField(this, "remainingTotalAmount");
29
+ __publicField(this, "currency");
30
+ this.remainingAllocationAmount = misc.getDinero(initialAllocateAmount, currency);
31
+ this.remainingTotalAmount = misc.getDinero(initialTotalAmount, currency);
32
+ this.currency = misc.getDineroCurrency(currency);
33
+ }
34
+ /**
35
+ * We always allocate biggest share to first item
36
+ */
37
+ allocate(lineItemTotal, currency) {
38
+ errors.assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
39
+ const lineItemTotalDinero = misc.getDinero(lineItemTotal, currency);
40
+ if (lineItemTotal === 0) {
41
+ return lineItemTotalDinero;
42
+ }
43
+ const [allocationAmount, remainingAllocationAmount] = dinero_js.allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(misc.amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
44
+ errors.assert(!!allocationAmount, "Allocation amount is zero");
45
+ errors.assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
46
+ this.remainingAllocationAmount = remainingAllocationAmount;
47
+ this.remainingTotalAmount = dinero_js.subtract(this.remainingTotalAmount, lineItemTotalDinero);
48
+ return dinero_js.greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
49
+ }
50
+ }
51
+ exports.FixedAmountAllocator = FixedAmountAllocator;
52
+ //# sourceMappingURL=fixedAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedAmount.js","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","constructor","initialAllocateAmount","initialTotalAmount","currency","__publicField","remainingAllocationAmount","getDinero","remainingTotalAmount","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;;;;;;;;;AAWO,MAAMA,oBAAqB,CAAA;EAWhCC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAC;EAAA,CAKC,EAAA;IAfH;AAAA;AAAA;IAAOC,aAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;IAIP;AAAA;AAAA;IAAOA,aAAA,CAAA,IAAA,EAAA,sBAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAWA,IAAA,CAAAC,yBAAA,GAA4BC,IAAAA,CAAAA,SAAU,CAAAL,qBAAA,EAAuBE,QAAQ,CAAA;IACrE,IAAA,CAAAI,oBAAA,GAAuBD,IAAAA,CAAAA,SAAU,CAAAJ,kBAAA,EAAoBC,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,uBAAkBL,QAAQ,CAAA;EAC5C;EAAA;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CAAAA,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACQ,+BAAAA,QAAiB,SAAA,IAAA,CAAKA,SAASS,IAAI,EAAA,CACpE;IACM,MAAAC,mBAAA,GAAsBP,IAAAA,CAAAA,SAAU,CAAAI,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IACT;IAEM,MAAA,CAACC,gBAAkB,EAAAT,yBAAyB,CAAI,GAAAI,SAAA,CAAAA,QAAA,CACpD,IAAK,CAAAJ,yBAAA,EACL,CACEK,aAAA,EACAK,KAAKC,GAAI,CAAAC,WAAA,CAAO,KAAKV,oBAAoB,CAAA,GAAIG,eAAe,CAAC,CAAA,CAC/D,CACF;IAEOC,MAAAA,CAAAA,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CAAAA,MAAA,CACE,CAAC,CAACN,yBAAA,EACF,wCAAA,CACF;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKE,oBAAuB,GAAAW,SAAA,CAAAA,QAAA,CAC1B,IAAK,CAAAX,oBAAA,EACLM,mBAAA,CACF;IAMA,OAAOM,SAAY,CAAAA,WAAA,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EACN;AACF;"}
@@ -0,0 +1,50 @@
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
+ class FixedAmountAllocator {
14
+ constructor({
15
+ initialAllocateAmount,
16
+ initialTotalAmount,
17
+ currency
18
+ }) {
19
+ /**
20
+ * How much we have left to allocate for given allocation from the remaining total
21
+ */
22
+ __publicField(this, "remainingAllocationAmount");
23
+ /**
24
+ * How much we have left to allocate in total
25
+ */
26
+ __publicField(this, "remainingTotalAmount");
27
+ __publicField(this, "currency");
28
+ this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);
29
+ this.remainingTotalAmount = getDinero(initialTotalAmount, currency);
30
+ this.currency = getDineroCurrency(currency);
31
+ }
32
+ /**
33
+ * We always allocate biggest share to first item
34
+ */
35
+ allocate(lineItemTotal, currency) {
36
+ assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
37
+ const lineItemTotalDinero = getDinero(lineItemTotal, currency);
38
+ if (lineItemTotal === 0) {
39
+ return lineItemTotalDinero;
40
+ }
41
+ const [allocationAmount, remainingAllocationAmount] = allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
42
+ assert(!!allocationAmount, "Allocation amount is zero");
43
+ assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
44
+ this.remainingAllocationAmount = remainingAllocationAmount;
45
+ this.remainingTotalAmount = subtract(this.remainingTotalAmount, lineItemTotalDinero);
46
+ return greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
47
+ }
48
+ }
49
+ export { FixedAmountAllocator };
50
+ //# sourceMappingURL=fixedAmount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedAmount.mjs","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","constructor","initialAllocateAmount","initialTotalAmount","currency","__publicField","remainingAllocationAmount","getDinero","remainingTotalAmount","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;;;;;;;AAWO,MAAMA,oBAAqB,CAAA;EAWhCC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAC;EAAA,CAKC,EAAA;IAfH;AAAA;AAAA;IAAOC,aAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;IAIP;AAAA;AA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1,8 @@
1
+ 'use strict';
2
+
3
+ var fixedAmount = require('./fixedAmount.js');
4
+ var productAmount = require('./productAmount.js');
5
+ "use strict";
6
+ exports.FixedAmountAllocator = fixedAmount.FixedAmountAllocator;
7
+ exports.ProductAmountAllocator = productAmount.ProductAmountAllocator;
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,4 @@
1
+ export { FixedAmountAllocator } from './fixedAmount.mjs';
2
+ export { ProductAmountAllocator } from './productAmount.mjs';
3
+ "use strict";
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,13 @@
1
+ import type { FullLineItemSummary } from "../types";
2
+ /**
3
+ * Helper class to distribute a total amount for a product
4
+ */
5
+ export declare class ProductAmountAllocator {
6
+ #private;
7
+ /**
8
+ * Remaining quantity to allocate
9
+ */
10
+ quantity: number;
11
+ constructor(productSummary: FullLineItemSummary);
12
+ allocateQty(quantity: number): FullLineItemSummary;
13
+ }
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ var misc = require('../misc.js');
4
+ var fixedAmount = require('./fixedAmount.js');
5
+ "use strict";
6
+ var __defProp = Object.defineProperty;
7
+ var __typeError = msg => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value
15
+ }) : obj[key] = value;
16
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
17
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
18
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
19
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
21
+ var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
22
+ class ProductAmountAllocator {
23
+ constructor(productSummary) {
24
+ // #############################################################################
25
+ // Fixed values
26
+ // #############################################################################
27
+ __privateAdd(this, _itemPrice);
28
+ __privateAdd(this, _currency);
29
+ // #############################################################################
30
+ /**
31
+ * Remaining quantity to allocate
32
+ */
33
+ __publicField(this, "quantity");
34
+ // #############################################################################
35
+ // Specific amount allocators
36
+ // #############################################################################
37
+ __privateAdd(this, _subtotal);
38
+ __privateAdd(this, _discountAmount);
39
+ __privateAdd(this, _taxableAmount);
40
+ __privateAdd(this, _tax);
41
+ __privateAdd(this, _total);
42
+ const currency = productSummary.currency;
43
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
44
+ __privateSet(this, _itemPrice, productSummary.itemPrice);
45
+ __privateSet(this, _currency, currency);
46
+ this.quantity = productSummary.quantity;
47
+ __privateSet(this, _subtotal, new fixedAmount.FixedAmountAllocator({
48
+ initialAllocateAmount: productSummary.subtotal,
49
+ initialTotalAmount: priceForAllocation,
50
+ currency
51
+ }));
52
+ __privateSet(this, _discountAmount, new fixedAmount.FixedAmountAllocator({
53
+ initialAllocateAmount: productSummary.discountAmount,
54
+ initialTotalAmount: priceForAllocation,
55
+ currency
56
+ }));
57
+ __privateSet(this, _taxableAmount, new fixedAmount.FixedAmountAllocator({
58
+ initialAllocateAmount: productSummary.taxableAmount,
59
+ initialTotalAmount: priceForAllocation,
60
+ currency
61
+ }));
62
+ __privateSet(this, _tax, new fixedAmount.FixedAmountAllocator({
63
+ initialAllocateAmount: productSummary.tax,
64
+ initialTotalAmount: priceForAllocation,
65
+ currency
66
+ }));
67
+ __privateSet(this, _total, new fixedAmount.FixedAmountAllocator({
68
+ initialAllocateAmount: productSummary.total,
69
+ initialTotalAmount: priceForAllocation,
70
+ currency
71
+ }));
72
+ }
73
+ allocateQty(quantity) {
74
+ let quantityNormalized = Math.max(quantity, 0);
75
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : this.quantity;
76
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
77
+ const itemQuantityPrice = __privateGet(this, _itemPrice) * quantityNormalized;
78
+ return {
79
+ itemPrice: __privateGet(this, _itemPrice),
80
+ currency: __privateGet(this, _currency),
81
+ quantity: quantityNormalized,
82
+ subtotal: misc.amount(__privateGet(this, _subtotal).allocate(itemQuantityPrice, __privateGet(this, _currency))),
83
+ discountAmount: misc.amount(__privateGet(this, _discountAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
84
+ taxableAmount: misc.amount(__privateGet(this, _taxableAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
85
+ tax: misc.amount(__privateGet(this, _tax).allocate(itemQuantityPrice, __privateGet(this, _currency))),
86
+ total: misc.amount(__privateGet(this, _total).allocate(itemQuantityPrice, __privateGet(this, _currency)))
87
+ };
88
+ }
89
+ }
90
+ _itemPrice = new WeakMap();
91
+ _currency = new WeakMap();
92
+ _subtotal = new WeakMap();
93
+ _discountAmount = new WeakMap();
94
+ _taxableAmount = new WeakMap();
95
+ _tax = new WeakMap();
96
+ _total = new WeakMap();
97
+ exports.ProductAmountAllocator = ProductAmountAllocator;
98
+ //# 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":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAASC,YAAA,CAAA,IAAA,EAAAV,UAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAAT,SAAA,CAAA;IAKT;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAIA;IAAA;IAAA;IAAAD,YAAA,CAAA,IAAA,EAAAR,SAAA,CAAA;IACAQ,YAAA,CAAA,IAAA,EAAAP,eAAA,CAAA;IACAO,YAAA,CAAA,IAAA,EAAAN,cAAA,CAAA;IACAM,YAAA,CAAA,IAAA,EAAAL,IAAA,CAAA;IACAK,YAAA,CAAA,IAAA,EAAAJ,MAAA,CAAA;IAGE,MAAMM,WAAWH,cAAe,CAAAG,QAAA;IAK1B,MAAAC,kBAAA,GACJJ,cAAe,CAAAK,SAAA,GAAYL,cAAe,CAAAM,QAAA;IAE5CC,YAAA,CAAA,IAAA,EAAKhB,YAAaS,cAAe,CAAAK,SAAA,CAAA;IACjCE,YAAA,CAAA,IAA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3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
@@ -0,0 +1,96 @@
1
+ import { amount } from '../misc.mjs';
2
+ import { FixedAmountAllocator } from './fixedAmount.mjs';
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __typeError = msg => {
6
+ throw TypeError(msg);
7
+ };
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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
16
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
17
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
18
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
19
+ var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
20
+ class ProductAmountAllocator {
21
+ constructor(productSummary) {
22
+ // #############################################################################
23
+ // Fixed values
24
+ // #############################################################################
25
+ __privateAdd(this, _itemPrice);
26
+ __privateAdd(this, _currency);
27
+ // #############################################################################
28
+ /**
29
+ * Remaining quantity to allocate
30
+ */
31
+ __publicField(this, "quantity");
32
+ // #############################################################################
33
+ // Specific amount allocators
34
+ // #############################################################################
35
+ __privateAdd(this, _subtotal);
36
+ __privateAdd(this, _discountAmount);
37
+ __privateAdd(this, _taxableAmount);
38
+ __privateAdd(this, _tax);
39
+ __privateAdd(this, _total);
40
+ const currency = productSummary.currency;
41
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
42
+ __privateSet(this, _itemPrice, productSummary.itemPrice);
43
+ __privateSet(this, _currency, currency);
44
+ this.quantity = productSummary.quantity;
45
+ __privateSet(this, _subtotal, new FixedAmountAllocator({
46
+ initialAllocateAmount: productSummary.subtotal,
47
+ initialTotalAmount: priceForAllocation,
48
+ currency
49
+ }));
50
+ __privateSet(this, _discountAmount, new FixedAmountAllocator({
51
+ initialAllocateAmount: productSummary.discountAmount,
52
+ initialTotalAmount: priceForAllocation,
53
+ currency
54
+ }));
55
+ __privateSet(this, _taxableAmount, new FixedAmountAllocator({
56
+ initialAllocateAmount: productSummary.taxableAmount,
57
+ initialTotalAmount: priceForAllocation,
58
+ currency
59
+ }));
60
+ __privateSet(this, _tax, new FixedAmountAllocator({
61
+ initialAllocateAmount: productSummary.tax,
62
+ initialTotalAmount: priceForAllocation,
63
+ currency
64
+ }));
65
+ __privateSet(this, _total, new FixedAmountAllocator({
66
+ initialAllocateAmount: productSummary.total,
67
+ initialTotalAmount: priceForAllocation,
68
+ currency
69
+ }));
70
+ }
71
+ allocateQty(quantity) {
72
+ let quantityNormalized = Math.max(quantity, 0);
73
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : this.quantity;
74
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
75
+ const itemQuantityPrice = __privateGet(this, _itemPrice) * quantityNormalized;
76
+ return {
77
+ itemPrice: __privateGet(this, _itemPrice),
78
+ currency: __privateGet(this, _currency),
79
+ quantity: quantityNormalized,
80
+ subtotal: amount(__privateGet(this, _subtotal).allocate(itemQuantityPrice, __privateGet(this, _currency))),
81
+ discountAmount: amount(__privateGet(this, _discountAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
82
+ taxableAmount: amount(__privateGet(this, _taxableAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
83
+ tax: amount(__privateGet(this, _tax).allocate(itemQuantityPrice, __privateGet(this, _currency))),
84
+ total: amount(__privateGet(this, _total).allocate(itemQuantityPrice, __privateGet(this, _currency)))
85
+ };
86
+ }
87
+ }
88
+ _itemPrice = new WeakMap();
89
+ _currency = new WeakMap();
90
+ _subtotal = new WeakMap();
91
+ _discountAmount = new WeakMap();
92
+ _taxableAmount = new WeakMap();
93
+ _tax = new WeakMap();
94
+ _total = new WeakMap();
95
+ export { ProductAmountAllocator };
96
+ //# 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":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAASC,YAAA,CAAA,IAAA,EAAAV,UAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAAT,SAAA,CAAA;IAKT;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,I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AA,EAAOO,OAAOD,YAAK,CAAA,IAAA,EAAAxB,MAAA,CAAA,CAAO0B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC;IAAA,CACvE;EACF;AACF;AAtFWD,UAAA,GAAA,IAAAiC,OAAA,CAAA,CAAA;AACAhC,SAAA,GAAA,IAAAgC,OAAA,CAAA,CAAA;AAST/B,SAAA,GAAA,IAAA+B,OAAA,CAAA,CAAA;AACA9B,eAAA,GAAA,IAAA8B,OAAA,CAAA,CAAA;AACA7B,cAAA,GAAA,IAAA6B,OAAA,CAAA,CAAA;AACA5B,IAAA,GAAA,IAAA4B,OAAA,CAAA,CAAA;AACA3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
@@ -1,37 +1,75 @@
1
+ import type { StoreId } from "../../types";
1
2
  import { Currency } from "../../types";
2
- import type { CurrencyObj } from "./types";
3
+ import type { LocalizedCurrency, RoundingFn } from "./types";
4
+ export declare const Round: {
5
+ /**
6
+ * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
7
+ * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
8
+ * normalise the values so we use this method.
9
+ *
10
+ * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
11
+ * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
12
+ * @see
13
+ *
14
+ * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
15
+ * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
16
+ * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
17
+ * https://youtu.be/yuRdYlZvs1E
18
+ *
19
+ * If you really want to get knee-deep in the rounding subject, you can read the following:
20
+ * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
21
+ */
22
+ Financial: import("@dinero.js/core").RoundingMode;
23
+ Shipping: import("@dinero.js/core").RoundingMode;
24
+ Prettify: import("@dinero.js/core").RoundingMode;
25
+ Subunit: import("@dinero.js/core").RoundingMode;
26
+ };
3
27
  /**
4
28
  * Mapping of how prices should be rounded down to "whole numbers" after certain threshold
5
29
  */
6
30
  export declare const prettifyPriceLookup: Map<string, number>;
7
31
  /**
8
- * Map of currencycode to subunit digit count.
32
+ * Map of dinero code to subunit digit count.
9
33
  */
10
- export declare const smallestSubunitLookup: Map<string, [number, (value: number) => number]>;
34
+ export declare const smallestSubunitLookup: Map<string, [number, RoundingFn]>;
11
35
  /**
12
- * Mapping of maximum price filter
13
- * TODO: Add all possible currencies
36
+ * Precompiled list for faster currency and locale lookups
14
37
  */
15
- export declare const maximumPriceFilterLookup: Map<string, number>;
38
+ export declare const localizedCurrencyLookup: Map<Currency, LocalizedCurrency>;
16
39
  /**
17
- * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
18
- * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
19
- * normalise the values so we use this method.
20
- *
21
- * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
22
- * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
23
- * @see
40
+ * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a
41
+ * single line. Rest of the stores inherit default behavior that tax calculated on whole line item
24
42
  *
25
- * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
26
- * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
27
- * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
28
- * https://youtu.be/yuRdYlZvs1E
43
+ * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change
29
44
  *
30
- * If you really want to get knee-deep in the rounding subject, you can read the following:
31
- * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
45
+ * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires
46
+ * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for
47
+ * different tax calculations is there just need to enable on the share side and test if it works
32
48
  */
33
- export declare const financialRound: import("@dinero.js/core").RoundingMode;
49
+ export declare const storesWithPerItemTaxRate: Set<StoreId>;
34
50
  /**
35
- * Precompiled list for faster currency and locale lookups
51
+ * Dinero currency option block for working with tax rates within dinero
36
52
  */
37
- export declare const currencyObjLookup: Map<Currency, CurrencyObj>;
53
+ export declare const TAX_RATE_DINERO_CURRENCY: {
54
+ base: number;
55
+ /**
56
+ * We expect the tax rate to be in the range of 0..1
57
+ * 0 --> 0%
58
+ * 1 --> 100%
59
+ * 0.21 --> 21%
60
+ * 0.2169 --> 21.69%
61
+ * 0.12345678 --> 12.345678%
62
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
63
+ */
64
+ exponent: number;
65
+ code: string;
66
+ };
67
+ export declare const EXCHANGE_RATE_DINERO_CURRENCY: {
68
+ base: number;
69
+ /**
70
+ * We support having certain decimal places for exchange rates
71
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
72
+ */
73
+ exponent: number;
74
+ code: string;
75
+ };
@@ -5,6 +5,33 @@ var dinero_js = require('dinero.js');
5
5
  require('../../types/index.js');
6
6
  var generated = require('../../types/generated.js');
7
7
  "use strict";
8
+ const Round = {
9
+ /**
10
+ * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
11
+ * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
12
+ * normalise the values so we use this method.
13
+ *
14
+ * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
15
+ * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
16
+ * @see
17
+ *
18
+ * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
19
+ * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
20
+ * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
21
+ * https://youtu.be/yuRdYlZvs1E
22
+ *
23
+ * If you really want to get knee-deep in the rounding subject, you can read the following:
24
+ * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
25
+ */
26
+ Financial: dinero_js.halfEven,
27
+ // TODO: maybe we should have separate rounding functions depending on the input value?
28
+ // Reading from wiki "Round half toward zero" is better if the value is already "normalized to cents"
29
+ // But the "Round half to even" seems better for when working with float like values
30
+ // financialRound = Math.round;
31
+ Shipping: dinero_js.down,
32
+ Prettify: dinero_js.down,
33
+ Subunit: dinero_js.halfUp
34
+ };
8
35
  const prettifyPriceLookup = /* @__PURE__ */new Map([[currencies.USD.code, 20], [currencies.CAD.code, 20], [currencies.EUR.code, 20], [currencies.GBP.code, 20], [currencies.AED.code, 50],
9
36
  // Approximately every price above ~1.1 usd will be rounded in ZAR
10
37
  [currencies.ZAR.code, 20]]);
@@ -12,10 +39,8 @@ const smallestSubunitLookup = /* @__PURE__ */new Map([
12
39
  /**
13
40
  * TWD does not use subunits at all in day to day transactions.
14
41
  */
15
- [currencies.TWD.code, [0, dinero_js.halfUp]]]);
16
- const maximumPriceFilterLookup = /* @__PURE__ */new Map([[currencies.CAD.code, 7e4], [currencies.EUR.code, 7e4], [currencies.AED.code, 7e4]]);
17
- const financialRound = dinero_js.halfEven;
18
- const currencyObjLookup = /* @__PURE__ */new Map([[generated.Currency.Aed, {
42
+ [currencies.TWD.code, [0, Round.Subunit]]]);
43
+ const localizedCurrencyLookup = /* @__PURE__ */new Map([[generated.Currency.Aed, {
19
44
  currency: currencies.AED,
20
45
  locale: "ar-AE"
21
46
  }], [generated.Currency.Bgn, {
@@ -86,9 +111,48 @@ const currencyObjLookup = /* @__PURE__ */new Map([[generated.Currency.Aed, {
86
111
  currency: currencies.MXN,
87
112
  locale: "es-MX"
88
113
  }]]);
89
- exports.currencyObjLookup = currencyObjLookup;
90
- exports.financialRound = financialRound;
91
- exports.maximumPriceFilterLookup = maximumPriceFilterLookup;
114
+ const storesWithPerItemTaxRate = /* @__PURE__ */new Set([
115
+ // #############################################################################
116
+ // Stores with custom tax rates
117
+ // #############################################################################
118
+ // StoreId.Br,
119
+ // StoreId.Tw,
120
+ // #############################################################################
121
+ // Stores with Avalara, but will have custom company codes to handle per-item tax rate
122
+ // #############################################################################
123
+ // StoreId.Jp,
124
+ // StoreId.Sg,
125
+ ]);
126
+ const TAX_RATE_DINERO_CURRENCY = {
127
+ base: 10,
128
+ /**
129
+ * We expect the tax rate to be in the range of 0..1
130
+ * 0 --> 0%
131
+ * 1 --> 100%
132
+ * 0.21 --> 21%
133
+ * 0.2169 --> 21.69%
134
+ * 0.12345678 --> 12.345678%
135
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
136
+ */
137
+ exponent: 8,
138
+ code: ""
139
+ // Not important
140
+ };
141
+ const EXCHANGE_RATE_DINERO_CURRENCY = {
142
+ base: 10,
143
+ /**
144
+ * We support having certain decimal places for exchange rates
145
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
146
+ */
147
+ exponent: 6,
148
+ code: ""
149
+ // Not important
150
+ };
151
+ exports.EXCHANGE_RATE_DINERO_CURRENCY = EXCHANGE_RATE_DINERO_CURRENCY;
152
+ exports.Round = Round;
153
+ exports.TAX_RATE_DINERO_CURRENCY = TAX_RATE_DINERO_CURRENCY;
154
+ exports.localizedCurrencyLookup = localizedCurrencyLookup;
92
155
  exports.prettifyPriceLookup = prettifyPriceLookup;
93
156
  exports.smallestSubunitLookup = smallestSubunitLookup;
157
+ exports.storesWithPerItemTaxRate = storesWithPerItemTaxRate;
94
158
  //# sourceMappingURL=constants.js.map