@ubnt/store.core 9.20.0 → 9.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/lib/assets/close.svg +1 -4
  3. package/lib/assets/close2.svg +4 -1
  4. package/lib/assets/minus4.svg +8 -8
  5. package/lib/assets/minus5.svg +8 -8
  6. package/lib/assets/plus5.svg +9 -9
  7. package/lib/assets/plus6.svg +9 -9
  8. package/lib/assets/ucgMax.jpg +0 -0
  9. package/lib/assets/ucgMax2.jpg +0 -0
  10. package/lib/assets/ucgUltra.jpg +0 -0
  11. package/lib/assets/ucgUltra2.jpg +0 -0
  12. package/lib/components/CustomImage/CustomImage.js +1 -1
  13. package/lib/components/CustomImage/CustomImage.mjs +1 -1
  14. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  15. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  16. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  17. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  18. package/lib/components/GridGallery/GridModal/GridModal.js +1 -1
  19. package/lib/components/GridGallery/GridModal/GridModal.mjs +1 -1
  20. package/lib/components/Header/CartModalV2/CartModal.js +1 -1
  21. package/lib/components/Header/CartModalV2/CartModal.mjs +1 -1
  22. package/lib/components/Header/Header.js +1 -1
  23. package/lib/components/Header/Header.mjs +1 -1
  24. package/lib/components/LandingPagePro/LandingPagePro.d.ts +3 -0
  25. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  26. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  27. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  28. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  29. package/lib/components/LandingPageSidebar/LandingPageSidebar.js +1 -1
  30. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs +1 -1
  31. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  32. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  33. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  34. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  35. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  36. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  37. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  38. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  39. package/lib/components/ModelCompareV3/data/CloudGateways.js +6 -6
  40. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +4 -4
  41. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  42. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  43. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  44. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  45. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  46. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  47. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  48. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  49. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  50. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  51. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  52. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  53. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  54. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  55. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  56. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  57. package/lib/components/Search/Input/Input.js +1 -1
  58. package/lib/components/Search/Input/Input.mjs +1 -1
  59. package/lib/constants/icons/generic/close.svg.js +1 -1
  60. package/lib/constants/icons/generic/close.svg.mjs +2 -2
  61. package/lib/constants/icons/generic/index.js +1 -1
  62. package/lib/constants/icons/generic/index.mjs +1 -1
  63. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  64. package/lib/constants/icons/options/colors/index.js +3 -3
  65. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  66. package/lib/constants/icons/options/styles/index.js +3 -3
  67. package/lib/constants/optionIcons.js +6 -6
  68. package/lib/constants/optionIcons.mjs +4 -4
  69. package/lib/utils/money/allocators/fixedAmount.d.ts +26 -0
  70. package/lib/utils/money/allocators/fixedAmount.js +52 -0
  71. package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
  72. package/lib/utils/money/allocators/fixedAmount.mjs +50 -0
  73. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
  74. package/lib/utils/money/allocators/productAmount.d.ts +13 -0
  75. package/lib/utils/money/allocators/productAmount.js +98 -0
  76. package/lib/utils/money/allocators/productAmount.js.map +1 -0
  77. package/lib/utils/money/allocators/productAmount.mjs +96 -0
  78. package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
  79. package/lib/utils/money/constants.d.ts +60 -22
  80. package/lib/utils/money/constants.js +71 -7
  81. package/lib/utils/money/constants.js.map +1 -1
  82. package/lib/utils/money/constants.mjs +68 -6
  83. package/lib/utils/money/constants.mjs.map +1 -1
  84. package/lib/utils/money/exchangeRate.d.ts +31 -0
  85. package/lib/utils/money/exchangeRate.js +27 -0
  86. package/lib/utils/money/exchangeRate.js.map +1 -0
  87. package/lib/utils/money/exchangeRate.mjs +23 -0
  88. package/lib/utils/money/exchangeRate.mjs.map +1 -0
  89. package/lib/utils/money/format.d.ts +10 -5
  90. package/lib/utils/money/format.js +22 -14
  91. package/lib/utils/money/format.js.map +1 -1
  92. package/lib/utils/money/format.mjs +23 -16
  93. package/lib/utils/money/format.mjs.map +1 -1
  94. package/lib/utils/money/index.d.ts +5 -1
  95. package/lib/utils/money/index.js +28 -8
  96. package/lib/utils/money/index.js.map +1 -1
  97. package/lib/utils/money/index.mjs +8 -4
  98. package/lib/utils/money/index.mjs.map +1 -1
  99. package/lib/utils/money/misc.d.ts +68 -28
  100. package/lib/utils/money/misc.js +35 -64
  101. package/lib/utils/money/misc.js.map +1 -1
  102. package/lib/utils/money/misc.mjs +32 -43
  103. package/lib/utils/money/misc.mjs.map +1 -1
  104. package/lib/utils/money/misc.private.d.ts +23 -0
  105. package/lib/utils/money/misc.private.js +46 -0
  106. package/lib/utils/money/misc.private.js.map +1 -0
  107. package/lib/utils/money/misc.private.mjs +21 -0
  108. package/lib/utils/money/misc.private.mjs.map +1 -0
  109. package/lib/utils/money/shipping.d.ts +5 -0
  110. package/lib/utils/money/shipping.js +8 -0
  111. package/lib/utils/money/shipping.js.map +1 -0
  112. package/lib/utils/money/shipping.mjs +6 -0
  113. package/lib/utils/money/shipping.mjs.map +1 -0
  114. package/lib/utils/money/tax.d.ts +38 -2
  115. package/lib/utils/money/tax.js +46 -10
  116. package/lib/utils/money/tax.js.map +1 -1
  117. package/lib/utils/money/tax.mjs +42 -11
  118. package/lib/utils/money/tax.mjs.map +1 -1
  119. package/lib/utils/money/tax.private.d.ts +17 -0
  120. package/lib/utils/money/tax.private.js +65 -0
  121. package/lib/utils/money/tax.private.js.map +1 -0
  122. package/lib/utils/money/tax.private.mjs +60 -0
  123. package/lib/utils/money/tax.private.mjs.map +1 -0
  124. package/lib/utils/money/types.d.ts +78 -3
  125. package/lib/utils/number.d.ts +1 -1
  126. package/lib/utils/number.js +1 -1
  127. package/lib/utils/number.js.map +1 -1
  128. package/lib/utils/number.mjs +1 -1
  129. package/lib/utils/number.mjs.map +1 -1
  130. package/package.json +1 -1
  131. package/lib/utils/validations.d.ts +0 -15
  132. package/lib/utils/validations.js +0 -23
  133. package/lib/utils/validations.js.map +0 -1
  134. package/lib/utils/validations.mjs +0 -21
  135. package/lib/utils/validations.mjs.map +0 -1
@@ -6,7 +6,7 @@ require('./darkGrey.svg.js');
6
6
  require('./grey.svg.js');
7
7
  require('./lightGrey.svg.js');
8
8
  require('./white.svg.js');
9
- var _externalAssets_NxsKXHyJ = require("../../../../assets/black.svg");
9
+ var _externalAssets_WKvVtlSv = require("../../../../assets/black.svg");
10
10
  var _externalAssets_DTFMFQ51 = require("../../../../assets/blue.svg");
11
11
  var _externalAssets_B1Gj17va = require("../../../../assets/darkGrey.svg");
12
12
  var _externalAssets_So87DWAv = require("../../../../assets/grey.svg");
@@ -17,7 +17,7 @@ function _interopDefault(e) {
17
17
  default: e
18
18
  };
19
19
  }
20
- var _externalAssets_NxsKXHyJ__default = /*#__PURE__*/_interopDefault(_externalAssets_NxsKXHyJ);
20
+ var _externalAssets_WKvVtlSv__default = /*#__PURE__*/_interopDefault(_externalAssets_WKvVtlSv);
21
21
  var _externalAssets_DTFMFQ51__default = /*#__PURE__*/_interopDefault(_externalAssets_DTFMFQ51);
22
22
  var _externalAssets_B1Gj17va__default = /*#__PURE__*/_interopDefault(_externalAssets_B1Gj17va);
23
23
  var _externalAssets_So87DWAv__default = /*#__PURE__*/_interopDefault(_externalAssets_So87DWAv);
@@ -27,7 +27,7 @@ var _externalAssets_Dh1AHi98__default = /*#__PURE__*/_interopDefault(_externalAs
27
27
  Object.defineProperty(exports, "black", {
28
28
  enumerable: true,
29
29
  get: function () {
30
- return _externalAssets_NxsKXHyJ__default["default"];
30
+ return _externalAssets_WKvVtlSv__default["default"];
31
31
  }
32
32
  });
33
33
  Object.defineProperty(exports, "blue", {
@@ -3,24 +3,24 @@
3
3
  Object.defineProperty(exports, '__esModule', {
4
4
  value: true
5
5
  });
6
- var _externalAssets_WKvVtlSv = require("../../../../assets/black.svg");
6
+ var _externalAssets_NxsKXHyJ = require("../../../../assets/black.svg");
7
7
  function _interopDefault(e) {
8
8
  return e && e.__esModule ? e : {
9
9
  default: e
10
10
  };
11
11
  }
12
- var _externalAssets_WKvVtlSv__default = /*#__PURE__*/_interopDefault(_externalAssets_WKvVtlSv);
12
+ var _externalAssets_NxsKXHyJ__default = /*#__PURE__*/_interopDefault(_externalAssets_NxsKXHyJ);
13
13
  Object.defineProperty(exports, "default", {
14
14
  enumerable: true,
15
15
  get: function () {
16
- return _externalAssets_WKvVtlSv__default["default"];
16
+ return _externalAssets_NxsKXHyJ__default["default"];
17
17
  }
18
18
  });
19
- Object.keys(_externalAssets_WKvVtlSv).forEach(function (k) {
19
+ Object.keys(_externalAssets_NxsKXHyJ).forEach(function (k) {
20
20
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
21
21
  enumerable: true,
22
22
  get: function () {
23
- return _externalAssets_WKvVtlSv[k];
23
+ return _externalAssets_NxsKXHyJ[k];
24
24
  }
25
25
  });
26
26
  });
@@ -6,7 +6,7 @@ require('./camo.png.js');
6
6
  require('./concrete.png.js');
7
7
  require('./marble.png.js');
8
8
  require('./wood.png.js');
9
- var _externalAssets_WKvVtlSv = require("../../../../assets/black.svg");
9
+ var _externalAssets_NxsKXHyJ = require("../../../../assets/black.svg");
10
10
  var _externalAssets_DxR_vr6$ = require("../../../../assets/blackFabric.png");
11
11
  var _externalAssets_D_2KPJKL = require("../../../../assets/camo.png");
12
12
  var _externalAssets_AeQRmq$G = require("../../../../assets/concrete.png");
@@ -17,7 +17,7 @@ function _interopDefault(e) {
17
17
  default: e
18
18
  };
19
19
  }
20
- var _externalAssets_WKvVtlSv__default = /*#__PURE__*/_interopDefault(_externalAssets_WKvVtlSv);
20
+ var _externalAssets_NxsKXHyJ__default = /*#__PURE__*/_interopDefault(_externalAssets_NxsKXHyJ);
21
21
  var _externalAssets_DxR_vr6$__default = /*#__PURE__*/_interopDefault(_externalAssets_DxR_vr6$);
22
22
  var _externalAssets_D_2KPJKL__default = /*#__PURE__*/_interopDefault(_externalAssets_D_2KPJKL);
23
23
  var _externalAssets_AeQRmq$G__default = /*#__PURE__*/_interopDefault(_externalAssets_AeQRmq$G);
@@ -27,7 +27,7 @@ var _externalAssets_kQL$tT0V__default = /*#__PURE__*/_interopDefault(_externalAs
27
27
  Object.defineProperty(exports, "black", {
28
28
  enumerable: true,
29
29
  get: function () {
30
- return _externalAssets_WKvVtlSv__default["default"];
30
+ return _externalAssets_NxsKXHyJ__default["default"];
31
31
  }
32
32
  });
33
33
  Object.defineProperty(exports, "blackFabric", {
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  require('./icons/index.js');
4
- var _externalAssets_WKvVtlSv = require("../assets/black.svg");
4
+ var _externalAssets_NxsKXHyJ = require("../assets/black.svg");
5
5
  var _externalAssets_DxR_vr6$ = require("../assets/blackFabric.png");
6
6
  var _externalAssets_D_2KPJKL = require("../assets/camo.png");
7
7
  var _externalAssets_AeQRmq$G = require("../assets/concrete.png");
8
8
  var _externalAssets_CoJwwvt7 = require("../assets/marble.png");
9
9
  var _externalAssets_kQL$tT0V = require("../assets/wood.png");
10
- var _externalAssets_NxsKXHyJ = require("../assets/black.svg");
10
+ var _externalAssets_WKvVtlSv = require("../assets/black.svg");
11
11
  var _externalAssets_DTFMFQ51 = require("../assets/blue.svg");
12
12
  var _externalAssets_Dh1AHi98 = require("../assets/white.svg");
13
13
  var _externalAssets_B1Gj17va = require("../assets/darkGrey.svg");
@@ -18,13 +18,13 @@ function _interopDefault(e) {
18
18
  default: e
19
19
  };
20
20
  }
21
- var _externalAssets_WKvVtlSv__default = /*#__PURE__*/_interopDefault(_externalAssets_WKvVtlSv);
21
+ var _externalAssets_NxsKXHyJ__default = /*#__PURE__*/_interopDefault(_externalAssets_NxsKXHyJ);
22
22
  var _externalAssets_DxR_vr6$__default = /*#__PURE__*/_interopDefault(_externalAssets_DxR_vr6$);
23
23
  var _externalAssets_D_2KPJKL__default = /*#__PURE__*/_interopDefault(_externalAssets_D_2KPJKL);
24
24
  var _externalAssets_AeQRmq$G__default = /*#__PURE__*/_interopDefault(_externalAssets_AeQRmq$G);
25
25
  var _externalAssets_CoJwwvt7__default = /*#__PURE__*/_interopDefault(_externalAssets_CoJwwvt7);
26
26
  var _externalAssets_kQL$tT0V__default = /*#__PURE__*/_interopDefault(_externalAssets_kQL$tT0V);
27
- var _externalAssets_NxsKXHyJ__default = /*#__PURE__*/_interopDefault(_externalAssets_NxsKXHyJ);
27
+ var _externalAssets_WKvVtlSv__default = /*#__PURE__*/_interopDefault(_externalAssets_WKvVtlSv);
28
28
  var _externalAssets_DTFMFQ51__default = /*#__PURE__*/_interopDefault(_externalAssets_DTFMFQ51);
29
29
  var _externalAssets_Dh1AHi98__default = /*#__PURE__*/_interopDefault(_externalAssets_Dh1AHi98);
30
30
  var _externalAssets_B1Gj17va__default = /*#__PURE__*/_interopDefault(_externalAssets_B1Gj17va);
@@ -53,7 +53,7 @@ var OptionColors = /* @__PURE__ */(OptionColors2 => {
53
53
  return OptionColors2;
54
54
  })(OptionColors || {});
55
55
  const optionStyle = {
56
- ["black" /* black */]: _externalAssets_WKvVtlSv__default["default"],
56
+ ["black" /* black */]: _externalAssets_NxsKXHyJ__default["default"],
57
57
  ["black-fabric" /* blackFabric */]: _externalAssets_DxR_vr6$__default["default"],
58
58
  ["camo" /* camo */]: _externalAssets_D_2KPJKL__default["default"],
59
59
  ["concrete" /* concrete */]: _externalAssets_AeQRmq$G__default["default"],
@@ -62,7 +62,7 @@ const optionStyle = {
62
62
  };
63
63
  const optionColors = {
64
64
  // Common
65
- ["black" /* black */]: _externalAssets_NxsKXHyJ__default["default"],
65
+ ["black" /* black */]: _externalAssets_WKvVtlSv__default["default"],
66
66
  ["blue" /* blue */]: _externalAssets_DTFMFQ51__default["default"],
67
67
  ["white" /* white */]: _externalAssets_Dh1AHi98__default["default"],
68
68
  // US English
@@ -1,11 +1,11 @@
1
1
  import './icons/index.mjs';
2
- import _externalAssets_WKvVtlSv__default from "../assets/black.svg";
2
+ import _externalAssets_NxsKXHyJ__default from "../assets/black.svg";
3
3
  import _externalAssets_DxR_vr6$__default from "../assets/blackFabric.png";
4
4
  import _externalAssets_D_2KPJKL__default from "../assets/camo.png";
5
5
  import _externalAssets_AeQRmq$G__default from "../assets/concrete.png";
6
6
  import _externalAssets_CoJwwvt7__default from "../assets/marble.png";
7
7
  import _externalAssets_kQL$tT0V__default from "../assets/wood.png";
8
- import _externalAssets_NxsKXHyJ__default from "../assets/black.svg";
8
+ import _externalAssets_WKvVtlSv__default from "../assets/black.svg";
9
9
  import _externalAssets_DTFMFQ51__default from "../assets/blue.svg";
10
10
  import _externalAssets_Dh1AHi98__default from "../assets/white.svg";
11
11
  import _externalAssets_B1Gj17va__default from "../assets/darkGrey.svg";
@@ -34,7 +34,7 @@ var OptionColors = /* @__PURE__ */(OptionColors2 => {
34
34
  return OptionColors2;
35
35
  })(OptionColors || {});
36
36
  const optionStyle = {
37
- ["black" /* black */]: _externalAssets_WKvVtlSv__default,
37
+ ["black" /* black */]: _externalAssets_NxsKXHyJ__default,
38
38
  ["black-fabric" /* blackFabric */]: _externalAssets_DxR_vr6$__default,
39
39
  ["camo" /* camo */]: _externalAssets_D_2KPJKL__default,
40
40
  ["concrete" /* concrete */]: _externalAssets_AeQRmq$G__default,
@@ -43,7 +43,7 @@ const optionStyle = {
43
43
  };
44
44
  const optionColors = {
45
45
  // Common
46
- ["black" /* black */]: _externalAssets_NxsKXHyJ__default,
46
+ ["black" /* black */]: _externalAssets_WKvVtlSv__default,
47
47
  ["blue" /* blue */]: _externalAssets_DTFMFQ51__default,
48
48
  ["white" /* white */]: _externalAssets_Dh1AHi98__default,
49
49
  // US English
@@ -0,0 +1,26 @@
1
+ import type { Currency } from "../../../types";
2
+ import type { Cents, Dino, DinoCurrency } from "../types";
3
+ /**
4
+ * Helper class to distribute a fixed amount (e.g. discount) between multiple items.
5
+ * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible
6
+ */
7
+ export declare class FixedAmountAllocator {
8
+ /**
9
+ * How much we have left to allocate for given allocation from the remaining total
10
+ */
11
+ remainingAllocationAmount: Dino;
12
+ /**
13
+ * How much we have left to allocate in total
14
+ */
15
+ remainingTotalAmount: Dino;
16
+ currency: DinoCurrency;
17
+ constructor({ initialAllocateAmount, initialTotalAmount, currency, }: {
18
+ initialAllocateAmount: Cents;
19
+ initialTotalAmount: Cents;
20
+ currency: Currency;
21
+ });
22
+ /**
23
+ * We always allocate biggest share to first item
24
+ */
25
+ allocate(lineItemTotal: Cents, currency: Currency): Dino;
26
+ }
@@ -0,0 +1,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;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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;AAAA;IAAOA,aAAA,CAAA,IAAA,EAAA,sBAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAWA,IAAA,CAAAC,yBAAA,GAA4BC,SAAU,CAAAL,qBAAA,EAAuBE,QAAQ,CAAA;IACrE,IAAA,CAAAI,oBAAA,GAAuBD,SAAU,CAAAJ,kBAAA,EAAoBC,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,kBAAkBL,QAAQ,CAAA;EAC5C;EAAA;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACQ,+BAAAA,QAAiB,SAAA,IAAA,CAAKA,SAASS,IAAI,EAAA,CACpE;IACM,MAAAC,mBAAA,GAAsBP,SAAU,CAAAI,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IACT;IAEM,MAAA,CAACC,gBAAkB,EAAAT,yBAAyB,CAAI,GAAAI,QAAA,CACpD,IAAK,CAAAJ,yBAAA,EACL,CACEK,aAAA,EACAK,KAAKC,GAAI,CAAAC,MAAA,CAAO,KAAKV,oBAAoB,CAAA,GAAIG,eAAe,CAAC,CAAA,CAC/D,CACF;IAEOC,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CACE,CAAC,CAACN,yBAAA,EACF,wCAAA,CACF;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKE,oBAAuB,GAAAW,QAAA,CAC1B,IAAK,CAAAX,oBAAA,EACLM,mBAAA,CACF;IAMA,OAAOM,WAAY,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EACN;AACF;"}
@@ -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,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AAA,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;"}
@@ -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;EAo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