@ubnt/store.core 9.10.1 → 9.11.0-alpha.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 (164) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/lib/assets/minus4.svg +8 -8
  3. package/lib/assets/minus5.svg +8 -8
  4. package/lib/components/Header/ProHeader/ProHeader.js +19 -2
  5. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  6. package/lib/components/Header/ProHeader/ProHeader.mjs +19 -2
  7. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  8. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +1 -0
  9. package/lib/components/Header/ProHeader/ProHeader.styles.js +6 -0
  10. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  11. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +6 -0
  12. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  13. package/lib/components/LandingPagePro/LandingPagePro.d.ts +3 -0
  14. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  15. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  16. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  17. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  18. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +6 -1
  19. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  20. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +6 -1
  21. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  22. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  23. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  24. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  25. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  26. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +2 -0
  27. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  28. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +2 -0
  29. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  30. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +1 -1
  31. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +1 -1
  32. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  33. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  34. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +1 -1
  35. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +1 -1
  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/Tooltip/Tooltip.d.ts +2 -0
  39. package/lib/components/Tooltip/Tooltip.js +45 -0
  40. package/lib/components/Tooltip/Tooltip.js.map +1 -0
  41. package/lib/components/Tooltip/Tooltip.mjs +43 -0
  42. package/lib/components/Tooltip/Tooltip.mjs.map +1 -0
  43. package/lib/components/Tooltip/Tooltip.styles.d.ts +32 -0
  44. package/lib/components/Tooltip/Tooltip.styles.js +44 -0
  45. package/lib/components/Tooltip/Tooltip.styles.js.map +1 -0
  46. package/lib/components/Tooltip/Tooltip.styles.mjs +34 -0
  47. package/lib/components/Tooltip/Tooltip.styles.mjs.map +1 -0
  48. package/lib/components/Tooltip/index.d.ts +1 -0
  49. package/lib/components/Tooltip/index.js +6 -0
  50. package/lib/components/Tooltip/index.js.map +1 -0
  51. package/lib/components/Tooltip/index.mjs +3 -0
  52. package/lib/components/Tooltip/index.mjs.map +1 -0
  53. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  54. package/lib/constants/icons/options/colors/index.js +3 -3
  55. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  56. package/lib/constants/icons/options/styles/index.js +3 -3
  57. package/lib/constants/optionIcons.js +6 -6
  58. package/lib/constants/optionIcons.mjs +4 -4
  59. package/lib/constants/proStoreCategories/mapping/index.d.ts +3 -0
  60. package/lib/constants/proStoreCategories/mapping/index.js +20 -10
  61. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  62. package/lib/constants/proStoreCategories/mapping/index.mjs +20 -10
  63. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  64. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +3 -1
  65. package/lib/constants/proStoreCategories/mapping/unifi.js +2 -0
  66. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  67. package/lib/constants/proStoreCategories/mapping/unifi.mjs +2 -0
  68. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  69. package/lib/constants/proStoreCategories/translations/ar.json.js +1 -1
  70. package/lib/constants/proStoreCategories/translations/ar.json.mjs +1 -1
  71. package/lib/constants/proStoreCategories/translations/de.json.js +1 -1
  72. package/lib/constants/proStoreCategories/translations/de.json.mjs +1 -1
  73. package/lib/constants/proStoreCategories/translations/el.json.js +1 -1
  74. package/lib/constants/proStoreCategories/translations/el.json.mjs +1 -1
  75. package/lib/constants/proStoreCategories/translations/en.json.js +5 -0
  76. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  77. package/lib/constants/proStoreCategories/translations/en.json.mjs +5 -1
  78. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  79. package/lib/constants/proStoreCategories/translations/es.json.js +1 -1
  80. package/lib/constants/proStoreCategories/translations/es.json.mjs +1 -1
  81. package/lib/constants/proStoreCategories/translations/fr.json.js +2 -2
  82. package/lib/constants/proStoreCategories/translations/fr.json.mjs +2 -2
  83. package/lib/constants/proStoreCategories/translations/it.json.js +1 -1
  84. package/lib/constants/proStoreCategories/translations/it.json.mjs +1 -1
  85. package/lib/constants/proStoreCategories/translations/ja.json.js +1 -1
  86. package/lib/constants/proStoreCategories/translations/ja.json.mjs +1 -1
  87. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +1 -1
  88. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +1 -1
  89. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +2 -2
  90. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +2 -2
  91. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +2 -2
  92. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +2 -2
  93. package/lib/utils/money/allocators/fixedAmount.d.ts +26 -0
  94. package/lib/utils/money/allocators/fixedAmount.js +55 -0
  95. package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
  96. package/lib/utils/money/allocators/fixedAmount.mjs +53 -0
  97. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
  98. package/lib/utils/money/allocators/index.d.ts +2 -0
  99. package/lib/utils/money/allocators/index.js +8 -0
  100. package/lib/utils/money/allocators/index.js.map +1 -0
  101. package/lib/utils/money/allocators/index.mjs +4 -0
  102. package/lib/utils/money/allocators/index.mjs.map +1 -0
  103. package/lib/utils/money/allocators/productAmount.d.ts +13 -0
  104. package/lib/utils/money/allocators/productAmount.js +110 -0
  105. package/lib/utils/money/allocators/productAmount.js.map +1 -0
  106. package/lib/utils/money/allocators/productAmount.mjs +108 -0
  107. package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
  108. package/lib/utils/money/constants.d.ts +56 -25
  109. package/lib/utils/money/constants.js +72 -7
  110. package/lib/utils/money/constants.js.map +1 -1
  111. package/lib/utils/money/constants.mjs +70 -7
  112. package/lib/utils/money/constants.mjs.map +1 -1
  113. package/lib/utils/money/exchangeRate.d.ts +31 -0
  114. package/lib/utils/money/exchangeRate.js +27 -0
  115. package/lib/utils/money/exchangeRate.js.map +1 -0
  116. package/lib/utils/money/exchangeRate.mjs +23 -0
  117. package/lib/utils/money/exchangeRate.mjs.map +1 -0
  118. package/lib/utils/money/format.d.ts +10 -5
  119. package/lib/utils/money/format.js +22 -14
  120. package/lib/utils/money/format.js.map +1 -1
  121. package/lib/utils/money/format.mjs +23 -16
  122. package/lib/utils/money/format.mjs.map +1 -1
  123. package/lib/utils/money/index.d.ts +4 -1
  124. package/lib/utils/money/index.js +26 -8
  125. package/lib/utils/money/index.js.map +1 -1
  126. package/lib/utils/money/index.mjs +8 -4
  127. package/lib/utils/money/index.mjs.map +1 -1
  128. package/lib/utils/money/misc.d.ts +68 -28
  129. package/lib/utils/money/misc.js +35 -64
  130. package/lib/utils/money/misc.js.map +1 -1
  131. package/lib/utils/money/misc.mjs +32 -43
  132. package/lib/utils/money/misc.mjs.map +1 -1
  133. package/lib/utils/money/misc.private.d.ts +23 -0
  134. package/lib/utils/money/misc.private.js +46 -0
  135. package/lib/utils/money/misc.private.js.map +1 -0
  136. package/lib/utils/money/misc.private.mjs +21 -0
  137. package/lib/utils/money/misc.private.mjs.map +1 -0
  138. package/lib/utils/money/shipping.d.ts +5 -0
  139. package/lib/utils/money/shipping.js +8 -0
  140. package/lib/utils/money/shipping.js.map +1 -0
  141. package/lib/utils/money/shipping.mjs +6 -0
  142. package/lib/utils/money/shipping.mjs.map +1 -0
  143. package/lib/utils/money/tax.d.ts +38 -2
  144. package/lib/utils/money/tax.js +46 -10
  145. package/lib/utils/money/tax.js.map +1 -1
  146. package/lib/utils/money/tax.mjs +42 -11
  147. package/lib/utils/money/tax.mjs.map +1 -1
  148. package/lib/utils/money/tax.private.d.ts +17 -0
  149. package/lib/utils/money/tax.private.js +65 -0
  150. package/lib/utils/money/tax.private.js.map +1 -0
  151. package/lib/utils/money/tax.private.mjs +60 -0
  152. package/lib/utils/money/tax.private.mjs.map +1 -0
  153. package/lib/utils/money/types.d.ts +78 -3
  154. package/lib/utils/number.d.ts +1 -1
  155. package/lib/utils/number.js +1 -1
  156. package/lib/utils/number.js.map +1 -1
  157. package/lib/utils/number.mjs +1 -1
  158. package/lib/utils/number.mjs.map +1 -1
  159. package/package.json +1 -1
  160. package/lib/utils/validations.d.ts +0 -15
  161. package/lib/utils/validations.js +0 -23
  162. package/lib/utils/validations.js.map +0 -1
  163. package/lib/utils/validations.mjs +0 -21
  164. package/lib/utils/validations.mjs.map +0 -1
@@ -22,7 +22,7 @@ var Installations = "Installations";
22
22
  var Intercoms = "Interphones";
23
23
  var Kits = "Kits";
24
24
  var Mounting = "Montage";
25
- var NAS = "Réseau de stockage en réseau";
25
+ var NAS = "NAS";
26
26
  var Other = "Autre";
27
27
  var Outdoor = "En plein air";
28
28
  var PTZ = "PTZ";
@@ -107,7 +107,7 @@ var fr = {
107
107
  "Professional A/V": "Professionnel A/V",
108
108
  "Professional Max": "Professional Max",
109
109
  "RF Shielding": "Blindage RF",
110
- "RJ45 & Copper": "RJ45 & Cuivre",
110
+ "RJ45 & Copper": "RJ45 & Copper",
111
111
  "Rack Mount": "Montage en Rack",
112
112
  "Radio Module": "Module Radio",
113
113
  Readers: Readers,
@@ -112,7 +112,7 @@ var it = {
112
112
  "Professional A/V": "Professionale A/V",
113
113
  "Professional Max": "Professional Max",
114
114
  "RF Shielding": "Schermatura RF",
115
- "RJ45 & Copper": "RJ45 & Rame",
115
+ "RJ45 & Copper": "RJ45 & Copper",
116
116
  "Rack Mount": "Montaggio a Rack",
117
117
  "Radio Module": "Modulo Radio",
118
118
  Readers: Readers,
@@ -107,7 +107,7 @@ var it = {
107
107
  "Professional A/V": "Professionale A/V",
108
108
  "Professional Max": "Professional Max",
109
109
  "RF Shielding": "Schermatura RF",
110
- "RJ45 & Copper": "RJ45 & Rame",
110
+ "RJ45 & Copper": "RJ45 & Copper",
111
111
  "Rack Mount": "Montaggio a Rack",
112
112
  "Radio Module": "Modulo Radio",
113
113
  Readers: Readers,
@@ -112,7 +112,7 @@ var ja = {
112
112
  "Professional A/V": "プロフェッショナル A/V",
113
113
  "Professional Max": "プロフェッショナルマックス",
114
114
  "RF Shielding": "RFシールディング",
115
- "RJ45 & Copper": "RJ45&銅",
115
+ "RJ45 & Copper": "RJ45 & Copper",
116
116
  "Rack Mount": "ラックマウント",
117
117
  "Radio Module": "ラジオモジュール",
118
118
  Readers: Readers,
@@ -107,7 +107,7 @@ var ja = {
107
107
  "Professional A/V": "プロフェッショナル A/V",
108
108
  "Professional Max": "プロフェッショナルマックス",
109
109
  "RF Shielding": "RFシールディング",
110
- "RJ45 & Copper": "RJ45&銅",
110
+ "RJ45 & Copper": "RJ45 & Copper",
111
111
  "Rack Mount": "ラックマウント",
112
112
  "Radio Module": "ラジオモジュール",
113
113
  Readers: Readers,
@@ -112,7 +112,7 @@ var ptBR = {
112
112
  "Professional A/V": "Profissional A/V",
113
113
  "Professional Max": "Professional Max",
114
114
  "RF Shielding": "Blindagem RF",
115
- "RJ45 & Copper": "RJ45 & Cobre",
115
+ "RJ45 & Copper": "RJ45 & Copper",
116
116
  "Rack Mount": "Montagem em Rack",
117
117
  "Radio Module": "Módulo de Rádio",
118
118
  Readers: Readers,
@@ -107,7 +107,7 @@ var ptBR = {
107
107
  "Professional A/V": "Profissional A/V",
108
108
  "Professional Max": "Professional Max",
109
109
  "RF Shielding": "Blindagem RF",
110
- "RJ45 & Copper": "RJ45 & Cobre",
110
+ "RJ45 & Copper": "RJ45 & Copper",
111
111
  "Rack Mount": "Montagem em Rack",
112
112
  "Radio Module": "Módulo de Rádio",
113
113
  Readers: Readers,
@@ -27,7 +27,7 @@ var Installations = "安装";
27
27
  var Intercoms = "对讲机";
28
28
  var Kits = "套件";
29
29
  var Mounting = "安装方式";
30
- var NAS = "网络附加存储";
30
+ var NAS = "NAS";
31
31
  var Other = "其他";
32
32
  var Outdoor = "室外";
33
33
  var PTZ = "PTZ";
@@ -112,7 +112,7 @@ var zhHans = {
112
112
  "Professional A/V": "专业A/V",
113
113
  "Professional Max": "Professional Max",
114
114
  "RF Shielding": "射频屏蔽",
115
- "RJ45 & Copper": "RJ45 &铜",
115
+ "RJ45 & Copper": "RJ45 & Copper",
116
116
  "Rack Mount": "安装机柜",
117
117
  "Radio Module": "无线电模块",
118
118
  Readers: Readers,
@@ -22,7 +22,7 @@ var Installations = "安装";
22
22
  var Intercoms = "对讲机";
23
23
  var Kits = "套件";
24
24
  var Mounting = "安装方式";
25
- var NAS = "网络附加存储";
25
+ var NAS = "NAS";
26
26
  var Other = "其他";
27
27
  var Outdoor = "室外";
28
28
  var PTZ = "PTZ";
@@ -107,7 +107,7 @@ var zhHans = {
107
107
  "Professional A/V": "专业A/V",
108
108
  "Professional Max": "Professional Max",
109
109
  "RF Shielding": "射频屏蔽",
110
- "RJ45 & Copper": "RJ45 &铜",
110
+ "RJ45 & Copper": "RJ45 & Copper",
111
111
  "Rack Mount": "安装机柜",
112
112
  "Radio Module": "无线电模块",
113
113
  Readers: Readers,
@@ -27,7 +27,7 @@ var Installations = "安裝配件";
27
27
  var Intercoms = "對講機";
28
28
  var Kits = "套組";
29
29
  var Mounting = "安裝配件";
30
- var NAS = "網路附加儲存";
30
+ var NAS = "NAS";
31
31
  var Other = "其他";
32
32
  var Outdoor = "戶外適用";
33
33
  var PTZ = "PTZ";
@@ -112,7 +112,7 @@ var zhHantTW = {
112
112
  "Professional A/V": "Professional A/V",
113
113
  "Professional Max": "Professional Max",
114
114
  "RF Shielding": "射頻屏蔽",
115
- "RJ45 & Copper": "RJ45 &銅",
115
+ "RJ45 & Copper": "RJ45 & Copper",
116
116
  "Rack Mount": "機架配件",
117
117
  "Radio Module": "無線模組",
118
118
  Readers: Readers,
@@ -22,7 +22,7 @@ var Installations = "安裝配件";
22
22
  var Intercoms = "對講機";
23
23
  var Kits = "套組";
24
24
  var Mounting = "安裝配件";
25
- var NAS = "網路附加儲存";
25
+ var NAS = "NAS";
26
26
  var Other = "其他";
27
27
  var Outdoor = "戶外適用";
28
28
  var PTZ = "PTZ";
@@ -107,7 +107,7 @@ var zhHantTW = {
107
107
  "Professional A/V": "Professional A/V",
108
108
  "Professional Max": "Professional Max",
109
109
  "RF Shielding": "射頻屏蔽",
110
- "RJ45 & Copper": "RJ45 &銅",
110
+ "RJ45 & Copper": "RJ45 & Copper",
111
111
  "Rack Mount": "機架配件",
112
112
  "Radio Module": "無線模組",
113
113
  Readers: Readers,
@@ -0,0 +1,26 @@
1
+ import type { Currency } from "../../../types";
2
+ import type { Cents, Dino, DinoCurrency } from "../types";
3
+ /**
4
+ * Helper class to distribute a fixed amount (e.g. discount) between multiple items.
5
+ * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible
6
+ */
7
+ export declare class FixedAmountAllocator {
8
+ /**
9
+ * How much we have left to allocate for given allocation from the remaining total
10
+ */
11
+ remainingAllocationAmount: Dino;
12
+ /**
13
+ * How much we have left to allocate in total
14
+ */
15
+ remainingTotalAmount: Dino;
16
+ currency: DinoCurrency;
17
+ constructor({ initialAllocateAmount, initialTotalAmount, currency, }: {
18
+ initialAllocateAmount: Cents;
19
+ initialTotalAmount: Cents;
20
+ currency: Currency;
21
+ });
22
+ /**
23
+ * We always allocate biggest share to first item
24
+ */
25
+ allocate(lineItemTotal: Cents, currency: Currency): Dino;
26
+ }
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ var dinero_js = require('dinero.js');
4
+ var errors = require('../../errors.js');
5
+ var misc = require('../misc.js');
6
+ "use strict";
7
+ var __defProp = Object.defineProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value
13
+ }) : obj[key] = value;
14
+ var __publicField = (obj, key, value) => {
15
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
16
+ return value;
17
+ };
18
+ class FixedAmountAllocator {
19
+ constructor({
20
+ initialAllocateAmount,
21
+ initialTotalAmount,
22
+ currency
23
+ }) {
24
+ /**
25
+ * How much we have left to allocate for given allocation from the remaining total
26
+ */
27
+ __publicField(this, "remainingAllocationAmount");
28
+ /**
29
+ * How much we have left to allocate in total
30
+ */
31
+ __publicField(this, "remainingTotalAmount");
32
+ __publicField(this, "currency");
33
+ this.remainingAllocationAmount = misc.getDinero(initialAllocateAmount, currency);
34
+ this.remainingTotalAmount = misc.getDinero(initialTotalAmount, currency);
35
+ this.currency = misc.getDineroCurrency(currency);
36
+ }
37
+ /**
38
+ * We always allocate biggest share to first item
39
+ */
40
+ allocate(lineItemTotal, currency) {
41
+ errors.assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
42
+ const lineItemTotalDinero = misc.getDinero(lineItemTotal, currency);
43
+ if (lineItemTotal === 0) {
44
+ return lineItemTotalDinero;
45
+ }
46
+ const [allocationAmount, remainingAllocationAmount] = dinero_js.allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(misc.amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
47
+ errors.assert(!!allocationAmount, "Allocation amount is zero");
48
+ errors.assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
49
+ this.remainingAllocationAmount = remainingAllocationAmount;
50
+ this.remainingTotalAmount = dinero_js.subtract(this.remainingTotalAmount, lineItemTotalDinero);
51
+ return dinero_js.greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
52
+ }
53
+ }
54
+ exports.FixedAmountAllocator = FixedAmountAllocator;
55
+ //# sourceMappingURL=fixedAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedAmount.js","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","constructor","initialAllocateAmount","initialTotalAmount","currency","__publicField","remainingAllocationAmount","getDinero","remainingTotalAmount","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;;;;;;;;;;;;AAWO,MAAMA,oBAAqB,CAAA;EAWhCC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAC;EAAA,CAKC,EAAA;IAfH;AAAA;AAAA;IAAOC,aAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;IAIP;AAAA;AAAA;IAAOA,aAAA,CAAA,IAAA,EAAA,sBAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAWA,IAAA,CAAAC,yBAAA,GAA4BC,IAAAA,CAAAA,SAAU,CAAAL,qBAAA,EAAuBE,QAAQ,CAAA;IACrE,IAAA,CAAAI,oBAAA,GAAuBD,IAAAA,CAAAA,SAAU,CAAAJ,kBAAA,EAAoBC,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,uBAAkBL,QAAQ,CAAA;EAC5C;EAAA;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CAAAA,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACQ,+BAAAA,QAAiB,SAAA,IAAA,CAAKA,SAASS,IAAI,EAAA,CACpE;IACM,MAAAC,mBAAA,GAAsBP,IAAAA,CAAAA,SAAU,CAAAI,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IACT;IAEM,MAAA,CAACC,gBAAkB,EAAAT,yBAAyB,CAAI,GAAAI,SAAA,CAAAA,QAAA,CACpD,IAAK,CAAAJ,yBAAA,EACL,CACEK,aAAA,EACAK,KAAKC,GAAI,CAAAC,WAAA,CAAO,KAAKV,oBAAoB,CAAA,GAAIG,eAAe,CAAC,CAAA,CAC/D,CACF;IAEOC,MAAAA,CAAAA,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CAAAA,MAAA,CACE,CAAC,CAACN,yBAAA,EACF,wCAAA,CACF;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKE,oBAAuB,GAAAW,SAAA,CAAAA,QAAA,CAC1B,IAAK,CAAAX,oBAAA,EACLM,mBAAA,CACF;IAMA,OAAOM,SAAY,CAAAA,WAAA,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EACN;AACF;"}
@@ -0,0 +1,53 @@
1
+ import { allocate, subtract, greaterThan } from 'dinero.js';
2
+ import { assert } from '../../errors.mjs';
3
+ import { getDinero, getDineroCurrency, amount } from '../misc.mjs';
4
+ "use strict";
5
+ var __defProp = Object.defineProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value
11
+ }) : obj[key] = value;
12
+ var __publicField = (obj, key, value) => {
13
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
+ return value;
15
+ };
16
+ class FixedAmountAllocator {
17
+ constructor({
18
+ initialAllocateAmount,
19
+ initialTotalAmount,
20
+ currency
21
+ }) {
22
+ /**
23
+ * How much we have left to allocate for given allocation from the remaining total
24
+ */
25
+ __publicField(this, "remainingAllocationAmount");
26
+ /**
27
+ * How much we have left to allocate in total
28
+ */
29
+ __publicField(this, "remainingTotalAmount");
30
+ __publicField(this, "currency");
31
+ this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);
32
+ this.remainingTotalAmount = getDinero(initialTotalAmount, currency);
33
+ this.currency = getDineroCurrency(currency);
34
+ }
35
+ /**
36
+ * We always allocate biggest share to first item
37
+ */
38
+ allocate(lineItemTotal, currency) {
39
+ assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
40
+ const lineItemTotalDinero = getDinero(lineItemTotal, currency);
41
+ if (lineItemTotal === 0) {
42
+ return lineItemTotalDinero;
43
+ }
44
+ const [allocationAmount, remainingAllocationAmount] = allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
45
+ assert(!!allocationAmount, "Allocation amount is zero");
46
+ assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
47
+ this.remainingAllocationAmount = remainingAllocationAmount;
48
+ this.remainingTotalAmount = subtract(this.remainingTotalAmount, lineItemTotalDinero);
49
+ return greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
50
+ }
51
+ }
52
+ export { FixedAmountAllocator };
53
+ //# sourceMappingURL=fixedAmount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedAmount.mjs","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","constructor","initialAllocateAmount","initialTotalAmount","currency","__publicField","remainingAllocationAmount","getDinero","remainingTotalAmount","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;;;;;;;;;;AAWO,MAAMA,oBAAqB,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;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Amount.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,110 @@
1
+ 'use strict';
2
+
3
+ var misc = require('../misc.js');
4
+ var fixedAmount = require('./fixedAmount.js');
5
+ "use strict";
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value
12
+ }) : obj[key] = value;
13
+ var __publicField = (obj, key, value) => {
14
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ return value;
16
+ };
17
+ var __accessCheck = (obj, member, msg) => {
18
+ if (!member.has(obj)) throw TypeError("Cannot " + msg);
19
+ };
20
+ var __privateGet = (obj, member, getter) => {
21
+ __accessCheck(obj, member, "read from private field");
22
+ return getter ? getter.call(obj) : member.get(obj);
23
+ };
24
+ var __privateAdd = (obj, member, value) => {
25
+ if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
26
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
27
+ };
28
+ var __privateSet = (obj, member, value, setter) => {
29
+ __accessCheck(obj, member, "write to private field");
30
+ setter ? setter.call(obj, value) : member.set(obj, value);
31
+ return value;
32
+ };
33
+ var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
34
+ class ProductAmountAllocator {
35
+ constructor(productSummary) {
36
+ // #############################################################################
37
+ // Fixed values
38
+ // #############################################################################
39
+ __privateAdd(this, _itemPrice, void 0);
40
+ __privateAdd(this, _currency, void 0);
41
+ // #############################################################################
42
+ /**
43
+ * Remaining quantity to allocate
44
+ */
45
+ __publicField(this, "quantity");
46
+ // #############################################################################
47
+ // Specific amount allocators
48
+ // #############################################################################
49
+ __privateAdd(this, _subtotal, void 0);
50
+ __privateAdd(this, _discountAmount, void 0);
51
+ __privateAdd(this, _taxableAmount, void 0);
52
+ __privateAdd(this, _tax, void 0);
53
+ __privateAdd(this, _total, void 0);
54
+ const currency = productSummary.currency;
55
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
56
+ __privateSet(this, _itemPrice, productSummary.itemPrice);
57
+ __privateSet(this, _currency, currency);
58
+ this.quantity = productSummary.quantity;
59
+ __privateSet(this, _subtotal, new fixedAmount.FixedAmountAllocator({
60
+ initialAllocateAmount: productSummary.subtotal,
61
+ initialTotalAmount: priceForAllocation,
62
+ currency
63
+ }));
64
+ __privateSet(this, _discountAmount, new fixedAmount.FixedAmountAllocator({
65
+ initialAllocateAmount: productSummary.discountAmount,
66
+ initialTotalAmount: priceForAllocation,
67
+ currency
68
+ }));
69
+ __privateSet(this, _taxableAmount, new fixedAmount.FixedAmountAllocator({
70
+ initialAllocateAmount: productSummary.taxableAmount,
71
+ initialTotalAmount: priceForAllocation,
72
+ currency
73
+ }));
74
+ __privateSet(this, _tax, new fixedAmount.FixedAmountAllocator({
75
+ initialAllocateAmount: productSummary.tax,
76
+ initialTotalAmount: priceForAllocation,
77
+ currency
78
+ }));
79
+ __privateSet(this, _total, new fixedAmount.FixedAmountAllocator({
80
+ initialAllocateAmount: productSummary.total,
81
+ initialTotalAmount: priceForAllocation,
82
+ currency
83
+ }));
84
+ }
85
+ allocateQty(quantity) {
86
+ let quantityNormalized = Math.max(quantity, 0);
87
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;
88
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
89
+ const itemQuantityPrice = __privateGet(this, _itemPrice) * quantityNormalized;
90
+ return {
91
+ itemPrice: __privateGet(this, _itemPrice),
92
+ currency: __privateGet(this, _currency),
93
+ quantity: quantityNormalized,
94
+ subtotal: misc.amount(__privateGet(this, _subtotal).allocate(itemQuantityPrice, __privateGet(this, _currency))),
95
+ discountAmount: misc.amount(__privateGet(this, _discountAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
96
+ taxableAmount: misc.amount(__privateGet(this, _taxableAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
97
+ tax: misc.amount(__privateGet(this, _tax).allocate(itemQuantityPrice, __privateGet(this, _currency))),
98
+ total: misc.amount(__privateGet(this, _total).allocate(itemQuantityPrice, __privateGet(this, _currency)))
99
+ };
100
+ }
101
+ }
102
+ _itemPrice = new WeakMap();
103
+ _currency = new WeakMap();
104
+ _subtotal = new WeakMap();
105
+ _discountAmount = new WeakMap();
106
+ _taxableAmount = new WeakMap();
107
+ _tax = new WeakMap();
108
+ _total = new WeakMap();
109
+ exports.ProductAmountAllocator = ProductAmountAllocator;
110
+ //# sourceMappingURL=productAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productAmount.js","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAAAC,YAAA,CAAA,IAAA,EAASV,UAAT,EAAA,KAAA,CAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAST,SAAT,EAAA,KAAA,CAAA,CAAA;IAKA;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAIA;IAAA;IAAA;IAAAD,YAAA,CAAA,IAAA,EAAAR,SAAA,EAAA,KAAA,CAAA,CAAA;IACAQ,YAAA,CAAA,IAAA,EAAAP,eAAA,EAAA,KAAA,CAAA,CAAA;IACAO,YAAA,CAAA,IAAA,EAAAN,cAAA,EAAA,KAAA,CAAA,CAAA;IACAM,YAAA,CAAA,IAAA,EAAAL,IAAA,EAAA,KAAA,CAAA,CAAA;IACAK,YAAA,CAAA,IAAA,EAAAJ,MAAA,EAAA,KAAA,CAAA,CAAA;IAGE,MAAMM,WAAWH,c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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,108 @@
1
+ import { amount } from '../misc.mjs';
2
+ import { FixedAmountAllocator } from './fixedAmount.mjs';
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value
10
+ }) : obj[key] = value;
11
+ var __publicField = (obj, key, value) => {
12
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
+ return value;
14
+ };
15
+ var __accessCheck = (obj, member, msg) => {
16
+ if (!member.has(obj)) throw TypeError("Cannot " + msg);
17
+ };
18
+ var __privateGet = (obj, member, getter) => {
19
+ __accessCheck(obj, member, "read from private field");
20
+ return getter ? getter.call(obj) : member.get(obj);
21
+ };
22
+ var __privateAdd = (obj, member, value) => {
23
+ if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
24
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ };
26
+ var __privateSet = (obj, member, value, setter) => {
27
+ __accessCheck(obj, member, "write to private field");
28
+ setter ? setter.call(obj, value) : member.set(obj, value);
29
+ return value;
30
+ };
31
+ var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
32
+ class ProductAmountAllocator {
33
+ constructor(productSummary) {
34
+ // #############################################################################
35
+ // Fixed values
36
+ // #############################################################################
37
+ __privateAdd(this, _itemPrice, void 0);
38
+ __privateAdd(this, _currency, void 0);
39
+ // #############################################################################
40
+ /**
41
+ * Remaining quantity to allocate
42
+ */
43
+ __publicField(this, "quantity");
44
+ // #############################################################################
45
+ // Specific amount allocators
46
+ // #############################################################################
47
+ __privateAdd(this, _subtotal, void 0);
48
+ __privateAdd(this, _discountAmount, void 0);
49
+ __privateAdd(this, _taxableAmount, void 0);
50
+ __privateAdd(this, _tax, void 0);
51
+ __privateAdd(this, _total, void 0);
52
+ const currency = productSummary.currency;
53
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
54
+ __privateSet(this, _itemPrice, productSummary.itemPrice);
55
+ __privateSet(this, _currency, currency);
56
+ this.quantity = productSummary.quantity;
57
+ __privateSet(this, _subtotal, new FixedAmountAllocator({
58
+ initialAllocateAmount: productSummary.subtotal,
59
+ initialTotalAmount: priceForAllocation,
60
+ currency
61
+ }));
62
+ __privateSet(this, _discountAmount, new FixedAmountAllocator({
63
+ initialAllocateAmount: productSummary.discountAmount,
64
+ initialTotalAmount: priceForAllocation,
65
+ currency
66
+ }));
67
+ __privateSet(this, _taxableAmount, new FixedAmountAllocator({
68
+ initialAllocateAmount: productSummary.taxableAmount,
69
+ initialTotalAmount: priceForAllocation,
70
+ currency
71
+ }));
72
+ __privateSet(this, _tax, new FixedAmountAllocator({
73
+ initialAllocateAmount: productSummary.tax,
74
+ initialTotalAmount: priceForAllocation,
75
+ currency
76
+ }));
77
+ __privateSet(this, _total, new FixedAmountAllocator({
78
+ initialAllocateAmount: productSummary.total,
79
+ initialTotalAmount: priceForAllocation,
80
+ currency
81
+ }));
82
+ }
83
+ allocateQty(quantity) {
84
+ let quantityNormalized = Math.max(quantity, 0);
85
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;
86
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
87
+ const itemQuantityPrice = __privateGet(this, _itemPrice) * quantityNormalized;
88
+ return {
89
+ itemPrice: __privateGet(this, _itemPrice),
90
+ currency: __privateGet(this, _currency),
91
+ quantity: quantityNormalized,
92
+ subtotal: amount(__privateGet(this, _subtotal).allocate(itemQuantityPrice, __privateGet(this, _currency))),
93
+ discountAmount: amount(__privateGet(this, _discountAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
94
+ taxableAmount: amount(__privateGet(this, _taxableAmount).allocate(itemQuantityPrice, __privateGet(this, _currency))),
95
+ tax: amount(__privateGet(this, _tax).allocate(itemQuantityPrice, __privateGet(this, _currency))),
96
+ total: amount(__privateGet(this, _total).allocate(itemQuantityPrice, __privateGet(this, _currency)))
97
+ };
98
+ }
99
+ }
100
+ _itemPrice = new WeakMap();
101
+ _currency = new WeakMap();
102
+ _subtotal = new WeakMap();
103
+ _discountAmount = new WeakMap();
104
+ _taxableAmount = new WeakMap();
105
+ _tax = new WeakMap();
106
+ _total = new WeakMap();
107
+ export { ProductAmountAllocator };
108
+ //# sourceMappingURL=productAmount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productAmount.mjs","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAA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