@ubnt/store.core 9.6.0-alpha.6 → 9.6.0-alpha.8

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 (131) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/lib/assets/attention.svg +5 -5
  3. package/lib/assets/attention2.svg +5 -5
  4. package/lib/assets/close.svg +1 -4
  5. package/lib/assets/close2.svg +3 -1
  6. package/lib/assets/close3.svg +3 -2
  7. package/lib/assets/icons/wizard/plus.svg.js +1 -1
  8. package/lib/assets/icons/wizard/plus.svg.mjs +2 -2
  9. package/lib/assets/minus4.svg +8 -8
  10. package/lib/assets/minus5.svg +8 -8
  11. package/lib/assets/pause.svg +3 -3
  12. package/lib/assets/pause2.svg +3 -3
  13. package/lib/assets/plus.svg +22 -4
  14. package/lib/assets/plus2.svg +4 -22
  15. package/lib/assets/plus5.svg +9 -9
  16. package/lib/assets/plus6.svg +9 -9
  17. package/lib/assets/ucgMax.jpg +0 -0
  18. package/lib/assets/ucgMax2.jpg +0 -0
  19. package/lib/assets/ucgUltra.jpg +0 -0
  20. package/lib/assets/ucgUltra2.jpg +0 -0
  21. package/lib/components/CustomImage/CustomImage.js +1 -1
  22. package/lib/components/CustomImage/CustomImage.mjs +1 -1
  23. package/lib/components/FeaturesSection_deprecated/AllFeaturesButton/AllFeaturesButton.js +1 -1
  24. package/lib/components/FeaturesSection_deprecated/AllFeaturesButton/AllFeaturesButton.mjs +1 -1
  25. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  26. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  27. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  28. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  29. package/lib/components/FeaturesSection_deprecated/assets/plus.svg.js +1 -1
  30. package/lib/components/FeaturesSection_deprecated/assets/plus.svg.mjs +2 -2
  31. package/lib/components/GridGallery/GridModal/GridModal.js +1 -1
  32. package/lib/components/GridGallery/GridModal/GridModal.mjs +1 -1
  33. package/lib/components/Header/CartModalV2/CartModal.js +1 -1
  34. package/lib/components/Header/CartModalV2/CartModal.mjs +1 -1
  35. package/lib/components/Header/Header.js +1 -1
  36. package/lib/components/Header/Header.mjs +1 -1
  37. package/lib/components/Header/ProHeader/ProHeader.js +6 -8
  38. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  39. package/lib/components/Header/ProHeader/ProHeader.mjs +7 -9
  40. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  41. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +0 -32
  42. package/lib/components/Header/ProHeader/ProHeader.styles.js +0 -32
  43. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  44. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +2 -31
  45. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  46. package/lib/components/LandingPageSidebar/LandingPageSidebar.js +1 -1
  47. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs +1 -1
  48. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  49. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  50. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  51. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  52. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  53. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  54. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  55. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  56. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  57. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  58. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  59. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  60. package/lib/components/ModelCompareV3/data/CloudGateways.js +6 -6
  61. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +4 -4
  62. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  63. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  64. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  65. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  66. package/lib/components/ProductWizard/ProductWizard.js +1 -1
  67. package/lib/components/ProductWizard/ProductWizard.mjs +1 -1
  68. package/lib/components/QuantityInput/QuantityInput.js +1 -1
  69. package/lib/components/QuantityInput/QuantityInput.mjs +1 -1
  70. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  71. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  72. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  73. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  74. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  75. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  76. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  77. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  78. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  79. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  80. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  81. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  82. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  83. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  84. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  85. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  86. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  87. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  88. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  89. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  90. package/lib/components/Search/Input/Input.js +1 -1
  91. package/lib/components/Search/Input/Input.mjs +1 -1
  92. package/lib/components/Tooltip/Tooltip.d.ts +2 -0
  93. package/lib/components/Tooltip/Tooltip.js +38 -0
  94. package/lib/components/Tooltip/Tooltip.js.map +1 -0
  95. package/lib/components/Tooltip/Tooltip.mjs +36 -0
  96. package/lib/components/Tooltip/Tooltip.mjs.map +1 -0
  97. package/lib/components/Tooltip/Tooltip.styles.d.ts +32 -0
  98. package/lib/components/Tooltip/Tooltip.styles.js +44 -0
  99. package/lib/components/Tooltip/Tooltip.styles.js.map +1 -0
  100. package/lib/components/Tooltip/Tooltip.styles.mjs +34 -0
  101. package/lib/components/Tooltip/Tooltip.styles.mjs.map +1 -0
  102. package/lib/components/Tooltip/index.d.ts +1 -0
  103. package/lib/components/Tooltip/index.js +6 -0
  104. package/lib/components/Tooltip/index.js.map +1 -0
  105. package/lib/components/Tooltip/index.mjs +3 -0
  106. package/lib/components/Tooltip/index.mjs.map +1 -0
  107. package/lib/components/VideoPlayerNew/VideoPlayer.js +2 -2
  108. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +2 -2
  109. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  110. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  111. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  112. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  113. package/lib/constants/icons/generic/close.svg.js +1 -1
  114. package/lib/constants/icons/generic/close.svg.mjs +2 -2
  115. package/lib/constants/icons/generic/index.js +1 -1
  116. package/lib/constants/icons/generic/index.mjs +1 -1
  117. package/lib/utils/money/allocators/index.d.ts +1 -0
  118. package/lib/utils/money/allocators/index.js +2 -0
  119. package/lib/utils/money/allocators/index.js.map +1 -1
  120. package/lib/utils/money/allocators/index.mjs +1 -0
  121. package/lib/utils/money/allocators/index.mjs.map +1 -1
  122. package/lib/utils/money/allocators/productAmount.d.ts +17 -0
  123. package/lib/utils/money/allocators/productAmount.js +69 -0
  124. package/lib/utils/money/allocators/productAmount.js.map +1 -0
  125. package/lib/utils/money/allocators/productAmount.mjs +67 -0
  126. package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
  127. package/lib/utils/money/exchangeRate.d.ts +1 -1
  128. package/lib/utils/money/exchangeRate.js.map +1 -1
  129. package/lib/utils/money/exchangeRate.mjs.map +1 -1
  130. package/lib/utils/money/types.d.ts +15 -5
  131. package/package.json +1 -1
@@ -0,0 +1,69 @@
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
+ class ProductAmountAllocator {
18
+ constructor(productSummary) {
19
+ __publicField(this, "itemPrice");
20
+ __publicField(this, "currency");
21
+ __publicField(this, "quantity");
22
+ __publicField(this, "discountAmount");
23
+ __publicField(this, "taxableAmount");
24
+ __publicField(this, "tax");
25
+ __publicField(this, "total");
26
+ const currency = productSummary.currency;
27
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
28
+ this.itemPrice = productSummary.itemPrice;
29
+ this.currency = currency;
30
+ this.quantity = productSummary.quantity;
31
+ this.discountAmount = new fixedAmount.FixedAmountAllocator({
32
+ initialAllocateAmount: productSummary.discountAmount,
33
+ initialTotalAmount: priceForAllocation,
34
+ currency
35
+ });
36
+ this.taxableAmount = new fixedAmount.FixedAmountAllocator({
37
+ initialAllocateAmount: productSummary.taxableAmount,
38
+ initialTotalAmount: priceForAllocation,
39
+ currency
40
+ });
41
+ this.tax = new fixedAmount.FixedAmountAllocator({
42
+ initialAllocateAmount: productSummary.tax,
43
+ initialTotalAmount: priceForAllocation,
44
+ currency
45
+ });
46
+ this.total = new fixedAmount.FixedAmountAllocator({
47
+ initialAllocateAmount: productSummary.total,
48
+ initialTotalAmount: priceForAllocation,
49
+ currency
50
+ });
51
+ }
52
+ allocateQty(quantity) {
53
+ let quantityNormalized = Math.max(quantity, 0);
54
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;
55
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
56
+ const itemQuantityPrice = this.itemPrice * quantityNormalized;
57
+ return {
58
+ itemPrice: this.itemPrice,
59
+ currency: this.currency,
60
+ quantity: quantityNormalized,
61
+ discountAmount: misc.amount(this.discountAmount.allocate(itemQuantityPrice, this.currency)),
62
+ taxableAmount: misc.amount(this.taxableAmount.allocate(itemQuantityPrice, this.currency)),
63
+ tax: misc.amount(this.tax.allocate(itemQuantityPrice, this.currency)),
64
+ total: misc.amount(this.total.allocate(itemQuantityPrice, this.currency))
65
+ };
66
+ }
67
+ }
68
+ exports.ProductAmountAllocator = ProductAmountAllocator;
69
+ //# 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 itemPrice: Cents;\n currency: Currency;\n quantity: number;\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.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 discountAmount: amount(\n this.discountAmount.allocate(itemQuantityPrice, this.currency),\n ),\n taxableAmount: amount(\n this.taxableAmount.allocate(itemQuantityPrice, this.currency),\n ),\n tax: amount(this.tax.allocate(itemQuantityPrice, this.currency)),\n total: amount(this.total.allocate(itemQuantityPrice, this.currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["ProductAmountAllocator","constructor","productSummary","__publicField","currency","priceForAllocation","itemPrice","quantity","discountAmount","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","amount","allocate"],"mappings":";;;;;;;;;;;;;;;;AAQO,MAAMA,sBAAuB,CAAA;EASlCC,YAAYC,cAAqC,EAAA;IARjDC,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,KAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;IAGE,MAAMC,WAAWF,cAAe,CAAAE,QAAA;IAK1B,MAAAC,kBAAA,GACJH,cAAe,CAAAI,SAAA,GAAYJ,cAAe,CAAAK,QAAA;IAE5C,IAAA,CAAKD,YAAYJ,cAAe,CAAAI,SAAA;IAChC,IAAA,CAAKF,QAAW,GAAAA,QAAA;IAChB,IAAA,CAAKG,WAAWL,cAAe,CAAAK,QAAA;IAC1B,IAAA,CAAAC,cAAA,GAAiB,IAAIC,gCAAqB,CAAA;MAC7CC,uBAAuBR,cAAe,CAAAM,cAAA;MACtCG,kBAAoB,EAAAN,kBAAA;MACpBD;IAAA,CACD,CAAA;IACI,IAAA,CAAAQ,aAAA,GAAgB,IAAIH,gCAAqB,CAAA;MAC5CC,uBAAuBR,cAAe,CAAAU,aAAA;MACtCD,kBAAoB,EAAAN,kBAAA;MACpBD;IAAA,CACD,CAAA;IACI,IAAA,CAAAS,GAAA,GAAM,IAAIJ,gCAAqB,CAAA;MAClCC,uBAAuBR,cAAe,CAAAW,GAAA;MACtCF,kBAAoB,EAAAN,kBAAA;MACpBD;IAAA,CACD,CAAA;IACI,IAAA,CAAAU,KAAA,GAAQ,IAAIL,gCAAqB,CAAA;MACpCC,uBAAuBR,cAAe,CAAAY,KAAA;MACtCH,kBAAoB,EAAAN,kBAAA;MACpBD;IAAA,CACD,CAAA;EACH;EAEAW,YAAYR,QAAuC,EAAA;IAEjD,IAAIS,kBAAqB,GAAAC,IAAA,CAAKC,GAAI,CAAAX,QAAA,EAAU,CAAC,CAAA;IAC7CS,kBAAA,GACE,IAAK,CAAAT,QAAA,GAAWS,kBAAsB,IAAA,CAAA,GAAIA,kBAAqB,GAAA,CAAA;IAGjE,IAAA,CAAKT,WAAWU,IAAK,CAAAC,GAAA,CAAI,IAAK,CAAAX,QAAA,GAAWS,oBAAoB,CAAC,CAAA;IAGxD,MAAAG,iBAAA,GAAoB,KAAKb,SAAY,GAAAU,kBAAA;IAEpC,OAAA;MACLV,WAAW,IAAK,CAAAA,SAAA;MAChBF,UAAU,IAAK,CAAAA,QAAA;MACfG,QAAU,EAAAS,kBAAA;MACVR,cAAgB,EAAAY,IAAA,CAAAA,MAAA,CACd,IAAK,CAAAZ,cAAA,CAAea,QAAS,CAAAF,iBAAA,EAAmB,KAAKf,QAAQ,CAC/D,CAAA;MACAQ,aAAe,EAAAQ,IAAA,CAAAA,MAAA,CACb,IAAK,CAAAR,aAAA,CAAcS,QAAS,CAAAF,iBAAA,EAAmB,KAAKf,QAAQ,CAC9D,CAAA;MACAS,GAAA,EAAKO,IAAAA,CAAAA,OAAO,IAAK,CAAAP,GAAA,CAAIQ,SAASF,iBAAmB,EAAA,IAAA,CAAKf,QAAQ,CAAC,CAAA;MAC/DU,KAAA,EAAOM,IAAAA,CAAAA,OAAO,IAAK,CAAAN,KAAA,CAAMO,SAASF,iBAAmB,EAAA,IAAA,CAAKf,QAAQ,CAAC;IAAA,CACrE;EACF;AACF;"}
@@ -0,0 +1,67 @@
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
+ class ProductAmountAllocator {
16
+ constructor(productSummary) {
17
+ __publicField(this, "itemPrice");
18
+ __publicField(this, "currency");
19
+ __publicField(this, "quantity");
20
+ __publicField(this, "discountAmount");
21
+ __publicField(this, "taxableAmount");
22
+ __publicField(this, "tax");
23
+ __publicField(this, "total");
24
+ const currency = productSummary.currency;
25
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
26
+ this.itemPrice = productSummary.itemPrice;
27
+ this.currency = currency;
28
+ this.quantity = productSummary.quantity;
29
+ this.discountAmount = new FixedAmountAllocator({
30
+ initialAllocateAmount: productSummary.discountAmount,
31
+ initialTotalAmount: priceForAllocation,
32
+ currency
33
+ });
34
+ this.taxableAmount = new FixedAmountAllocator({
35
+ initialAllocateAmount: productSummary.taxableAmount,
36
+ initialTotalAmount: priceForAllocation,
37
+ currency
38
+ });
39
+ this.tax = new FixedAmountAllocator({
40
+ initialAllocateAmount: productSummary.tax,
41
+ initialTotalAmount: priceForAllocation,
42
+ currency
43
+ });
44
+ this.total = new FixedAmountAllocator({
45
+ initialAllocateAmount: productSummary.total,
46
+ initialTotalAmount: priceForAllocation,
47
+ currency
48
+ });
49
+ }
50
+ allocateQty(quantity) {
51
+ let quantityNormalized = Math.max(quantity, 0);
52
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;
53
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
54
+ const itemQuantityPrice = this.itemPrice * quantityNormalized;
55
+ return {
56
+ itemPrice: this.itemPrice,
57
+ currency: this.currency,
58
+ quantity: quantityNormalized,
59
+ discountAmount: amount(this.discountAmount.allocate(itemQuantityPrice, this.currency)),
60
+ taxableAmount: amount(this.taxableAmount.allocate(itemQuantityPrice, this.currency)),
61
+ tax: amount(this.tax.allocate(itemQuantityPrice, this.currency)),
62
+ total: amount(this.total.allocate(itemQuantityPrice, this.currency))
63
+ };
64
+ }
65
+ }
66
+ export { ProductAmountAllocator };
67
+ //# 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 itemPrice: Cents;\n currency: Currency;\n quantity: number;\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.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 discountAmount: amount(\n this.discountAmount.allocate(itemQuantityPrice, this.currency),\n ),\n taxableAmount: amount(\n this.taxableAmount.allocate(itemQuantityPrice, this.currency),\n ),\n tax: amount(this.tax.allocate(itemQuantityPrice, this.currency)),\n total: amount(this.total.allocate(itemQuantityPrice, this.currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["ProductAmountAllocator","constructor","productSummary","__publicField","currency","priceForAllocation","itemPrice","quantity","discountAmount","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","amount","allocate"],"mappings":";;;;;;;;;;;;;;AAQO,MAAMA,sBAAuB,CAAA;EASlCC,YAAYC,cAAqC,EAAA;IARjDC,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,KAAA,CAAA;IACAA,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;IAGE,MAAMC,WAAWF,cAAe,CAAAE,QAAA;IAK1B,MAAAC,kBAAA,GACJH,cAAe,CAAAI,SAAA,GAAYJ,cAAe,CAAAK,QAAA;IAE5C,IAAA,CAAKD,YAAYJ,cAAe,CAAAI,SAAA;IAChC,IAAA,CAAKF,QAAW,GAAAA,QAAA;IAChB,IAAA,CAAKG,WAAWL,cAAe,CAAAK,QAAA;IAC1B,IAAA,CAAAC,cAAA,GAAiB,IAAIC,oBAAqB,CAAA;MAC7CC,uBAAuBR,cAAe,CAAAM,cAAA;MACtCG,kBAAoB,EAAAN,kBAAA;MACpBD;IAAA,CACD,CAAA;IACI,IAAA,CAAAQ,aAAA,GAAgB,IAAIH,oBAAqB,CAAA;MAC5CC,uBAAuBR,cAAe,CAAAU,aAAA;MACtCD,kBAAoB,EAAAN,kBAAA;MACpBD;IAAA,CACD,CAAA;IACI,IAAA,CAAAS,GAAA,GAAM,IAAIJ,oBAAqB,CAAA;MAClCC,uBAAuBR,cAAe,CAAAW,GAAA;MACtCF,kBAAoB,EAAAN,kBAAA;MACpBD;IAAA,CACD,CAAA;IACI,IAAA,CAAAU,KAAA,GAAQ,IAAIL,oBAAqB,CAAA;MACpCC,uBAAuBR,cAAe,CAAAY,KAAA;MACtCH,kBAAoB,EAAAN,kBAAA;MACpBD;IAAA,CACD,CAAA;EACH;EAEAW,YAAYR,QAAuC,EAAA;IAEjD,IAAIS,kBAAqB,GAAAC,IAAA,CAAKC,GAAI,CAAAX,QAAA,EAAU,CAAC,CAAA;IAC7CS,kBAAA,GACE,IAAK,CAAAT,QAAA,GAAWS,kBAAsB,IAAA,CAAA,GAAIA,kBAAqB,GAAA,CAAA;IAGjE,IAAA,CAAKT,WAAWU,IAAK,CAAAC,GAAA,CAAI,IAAK,CAAAX,QAAA,GAAWS,oBAAoB,CAAC,CAAA;IAGxD,MAAAG,iBAAA,GAAoB,KAAKb,SAAY,GAAAU,kBAAA;IAEpC,OAAA;MACLV,WAAW,IAAK,CAAAA,SAAA;MAChBF,UAAU,IAAK,CAAAA,QAAA;MACfG,QAAU,EAAAS,kBAAA;MACVR,cAAgB,EAAAY,MAAA,CACd,IAAK,CAAAZ,cAAA,CAAea,QAAS,CAAAF,iBAAA,EAAmB,KAAKf,QAAQ,CAC/D,CAAA;MACAQ,aAAe,EAAAQ,MAAA,CACb,IAAK,CAAAR,aAAA,CAAcS,QAAS,CAAAF,iBAAA,EAAmB,KAAKf,QAAQ,CAC9D,CAAA;MACAS,GAAA,EAAKO,OAAO,IAAK,CAAAP,GAAA,CAAIQ,SAASF,iBAAmB,EAAA,IAAA,CAAKf,QAAQ,CAAC,CAAA;MAC/DU,KAAA,EAAOM,OAAO,IAAK,CAAAN,KAAA,CAAMO,SAASF,iBAAmB,EAAA,IAAA,CAAKf,QAAQ,CAAC;IAAA,CACrE;EACF;AACF;"}
@@ -21,7 +21,7 @@ export declare const toSnapshotExchangeRate: (exchangeRate: TaxRate) => {
21
21
  * toFixedExchangeRate("0.123456789", true) // 0.123457
22
22
  */
23
23
  export declare function toFixedExchangeRate(rate: string | number, asNumber?: boolean): string;
24
- export declare function toFixedExchangeRate(rate: string | number, asNumber?: true): number;
24
+ export declare function toFixedExchangeRate(rate: string | number, asNumber: true): number;
25
25
  /**
26
26
  * Invert an exchange rate by doing 1 / rate
27
27
  * Used to fake a reverse exchange rate in case we don't have it
@@ -1 +1 @@
1
- {"version":3,"file":"exchangeRate.js","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\nimport type { Cents, TaxRate } from \"./types\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: TaxRate,\n): {\n amount: Cents;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: NoInfer<boolean>,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,cAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAAA,CAAAA,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,YAAA,CAAAA,UAAA,CACdJ,YAAA,EACAK,SAAAA,CAAAA,6BAA8B,CAAAC,IAAA,EAC9BD,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,CAChC;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,SAA8B,CAAAA,6BAAA,CAAAE;EAAA,CACvC;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,MAAA,CAAAA,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,EAC9BK,QAAA,CACF;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;;;"}
1
+ {"version":3,"file":"exchangeRate.js","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\nimport type { Cents, TaxRate } from \"./types\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: TaxRate,\n): {\n amount: Cents;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,cAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAAA,CAAAA,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,YAAA,CAAAA,UAAA,CACdJ,YAAA,EACAK,SAAAA,CAAAA,6BAA8B,CAAAC,IAAA,EAC9BD,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,CAChC;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,SAA8B,CAAAA,6BAAA,CAAAE;EAAA,CACvC;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,MAAA,CAAAA,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,EAC9BK,QAAA,CACF;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"exchangeRate.mjs","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\nimport type { Cents, TaxRate } from \"./types\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: TaxRate,\n): {\n amount: Cents;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: NoInfer<boolean>,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,OAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,UAAA,CACdJ,YAAA,EACAK,6BAA8B,CAAAC,IAAA,EAC9BD,6BAA8B,CAAAE,QAAA,CAChC;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,6BAA8B,CAAAE;EAAA,CACvC;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,6BAA8B,CAAAE,QAAA,EAC9BK,QAAA,CACF;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;"}
1
+ {"version":3,"file":"exchangeRate.mjs","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\nimport type { Cents, TaxRate } from \"./types\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: TaxRate,\n): {\n amount: Cents;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,OAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,UAAA,CACdJ,YAAA,EACAK,6BAA8B,CAAAC,IAAA,EAC9BD,6BAA8B,CAAAE,QAAA,CAChC;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,6BAA8B,CAAAE;EAAA,CACvC;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,6BAA8B,CAAAE,QAAA,EAC9BK,QAAA,CACF;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;"}
@@ -48,19 +48,19 @@ export type LocalizedCurrency = {
48
48
  export interface LineItemSummary {
49
49
  itemPrice: Cents;
50
50
  /**
51
- * (itemPrice * quantity) - discountAmount
51
+ * Item quantity that is always bigger than zero!
52
52
  */
53
- taxableAmount: Cents;
53
+ quantity: number;
54
+ currency: Currency;
54
55
  /**
55
56
  * Total discount amount (only) applied for the given item quantity.
56
57
  * No taxes are included. Calculated by `total_raw_price * <discount-allocation-percentage>`
57
58
  */
58
59
  discountAmount: Cents;
59
- currency: Currency;
60
60
  /**
61
- * Item quantity that is always bigger than zero!
61
+ * (itemPrice * quantity) - discountAmount
62
62
  */
63
- quantity: number;
63
+ taxableAmount: Cents;
64
64
  }
65
65
  /**
66
66
  * Pretty much the same as PreTaxItemSummary but with quantity always set to 1 (for clearer type hinting and reasoning
@@ -69,3 +69,13 @@ export interface LineItemSummary {
69
69
  export interface SingleLineItemSummary extends LineItemSummary {
70
70
  quantity: 1;
71
71
  }
72
+ export interface FullLineItemSummary extends LineItemSummary {
73
+ /**
74
+ * Total tax amount for the given item quantity.
75
+ */
76
+ tax: Cents;
77
+ /**
78
+ * Total price for the given item quantity. Calculated by `(itemPrice * quantity) - discountAmount + tax`
79
+ */
80
+ total: Cents;
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "9.6.0-alpha.6",
3
+ "version": "9.6.0-alpha.8",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {