@ubnt/store.core 10.0.0-pre-alpha.0 → 10.0.0-pre-alpha.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 (194) hide show
  1. package/lib/_virtual/_virtual_multi-entry.js +10 -12
  2. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  3. package/lib/_virtual/_virtual_multi-entry.mjs +10 -12
  4. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  5. package/lib/assets/clients.svg +9 -2
  6. package/lib/assets/clients2.svg +2 -9
  7. package/lib/assets/express7.jpg +0 -0
  8. package/lib/assets/express72.jpg +0 -0
  9. package/lib/assets/hdd.svg +2 -2
  10. package/lib/assets/hdd2.svg +2 -2
  11. package/lib/assets/icons/wizard/minus.svg.js +1 -1
  12. package/lib/assets/icons/wizard/minus.svg.mjs +2 -2
  13. package/lib/assets/keyFeatures/clients.svg.js +1 -1
  14. package/lib/assets/keyFeatures/clients.svg.mjs +2 -2
  15. package/lib/assets/keyFeatures/hdd.svg.js +1 -1
  16. package/lib/assets/keyFeatures/hdd.svg.mjs +2 -2
  17. package/lib/assets/keyFeatures/led.svg.js +1 -1
  18. package/lib/assets/keyFeatures/led.svg.mjs +2 -2
  19. package/lib/assets/keyFeatures/power.svg.js +1 -1
  20. package/lib/assets/keyFeatures/power.svg.mjs +2 -2
  21. package/lib/assets/keyFeatures/rack.svg.js +1 -1
  22. package/lib/assets/keyFeatures/rack.svg.mjs +2 -2
  23. package/lib/assets/keyFeatures/signal.svg.js +1 -1
  24. package/lib/assets/keyFeatures/signal.svg.mjs +2 -2
  25. package/lib/assets/keyFeatures/waterdrop.svg.js +1 -1
  26. package/lib/assets/keyFeatures/waterdrop.svg.mjs +2 -2
  27. package/lib/assets/led.svg +2 -9
  28. package/lib/assets/led2.svg +9 -2
  29. package/lib/assets/minus2.svg +13 -2
  30. package/lib/assets/minus3.svg +2 -13
  31. package/lib/assets/pause.svg +3 -3
  32. package/lib/assets/pause2.svg +3 -3
  33. package/lib/assets/power2.svg +3 -4
  34. package/lib/assets/power3.svg +4 -3
  35. package/lib/assets/rack2.svg +3 -3
  36. package/lib/assets/rack3.svg +3 -3
  37. package/lib/assets/signal.svg +2 -4
  38. package/lib/assets/signal2.svg +4 -2
  39. package/lib/assets/udmPro.jpg +0 -0
  40. package/lib/assets/udmPro2.jpg +0 -0
  41. package/lib/assets/udmProMax.jpg +0 -0
  42. package/lib/assets/udmProMax2.jpg +0 -0
  43. package/lib/assets/udmProSpecial.jpg +0 -0
  44. package/lib/assets/udmProSpecial2.jpg +0 -0
  45. package/lib/assets/udr2.jpg +0 -0
  46. package/lib/assets/udr3.jpg +0 -0
  47. package/lib/assets/udr7.jpg +0 -0
  48. package/lib/assets/udr72.jpg +0 -0
  49. package/lib/assets/waterdrop.svg +9 -2
  50. package/lib/assets/waterdrop2.svg +2 -9
  51. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  52. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  53. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  54. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  55. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.js +1 -1
  56. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.mjs +1 -1
  57. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/express7.jpg.js +5 -5
  58. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/express7.jpg.mjs +2 -2
  59. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  60. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  61. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  62. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  63. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  64. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  65. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr.jpg.js +5 -5
  66. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
  67. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr7.jpg.js +5 -5
  68. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr7.jpg.mjs +2 -2
  69. package/lib/components/ModelCompareV3/assets/Consoles/express7.jpg.js +1 -1
  70. package/lib/components/ModelCompareV3/assets/Consoles/express7.jpg.mjs +2 -2
  71. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  72. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  73. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  74. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  75. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  76. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  77. package/lib/components/ModelCompareV3/assets/Consoles/udr.jpg.js +1 -1
  78. package/lib/components/ModelCompareV3/assets/Consoles/udr.jpg.mjs +2 -2
  79. package/lib/components/ModelCompareV3/assets/Consoles/udr7.jpg.js +1 -1
  80. package/lib/components/ModelCompareV3/assets/Consoles/udr7.jpg.mjs +2 -2
  81. package/lib/components/ModelCompareV3/assets/clients.svg.js +1 -1
  82. package/lib/components/ModelCompareV3/assets/clients.svg.mjs +2 -2
  83. package/lib/components/ModelCompareV3/assets/hdd.svg.js +1 -1
  84. package/lib/components/ModelCompareV3/assets/hdd.svg.mjs +2 -2
  85. package/lib/components/ModelCompareV3/assets/led.svg.js +1 -1
  86. package/lib/components/ModelCompareV3/assets/led.svg.mjs +2 -2
  87. package/lib/components/ModelCompareV3/assets/minus.svg.js +1 -1
  88. package/lib/components/ModelCompareV3/assets/minus.svg.mjs +2 -2
  89. package/lib/components/ModelCompareV3/assets/power.svg.js +1 -1
  90. package/lib/components/ModelCompareV3/assets/power.svg.mjs +2 -2
  91. package/lib/components/ModelCompareV3/assets/rack.svg.js +1 -1
  92. package/lib/components/ModelCompareV3/assets/rack.svg.mjs +2 -2
  93. package/lib/components/ModelCompareV3/assets/signal.svg.js +1 -1
  94. package/lib/components/ModelCompareV3/assets/signal.svg.mjs +2 -2
  95. package/lib/components/ModelCompareV3/assets/waterdrop.svg.js +1 -1
  96. package/lib/components/ModelCompareV3/assets/waterdrop.svg.mjs +2 -2
  97. package/lib/components/ModelCompareV3/data/CloudGateways.js +15 -15
  98. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +10 -10
  99. package/lib/components/ModelCompareV3/data/products/express7.js +1 -1
  100. package/lib/components/ModelCompareV3/data/products/express7.mjs +1 -1
  101. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  102. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  103. package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
  104. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
  105. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  106. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  107. package/lib/components/ModelCompareV3/data/products/udr.js +1 -1
  108. package/lib/components/ModelCompareV3/data/products/udr.mjs +1 -1
  109. package/lib/components/ModelCompareV3/data/products/udr7.js +1 -1
  110. package/lib/components/ModelCompareV3/data/products/udr7.mjs +1 -1
  111. package/lib/components/ModelCompareV3/data/properties/accessPowerMethod.js +1 -1
  112. package/lib/components/ModelCompareV3/data/properties/accessPowerMethod.mjs +1 -1
  113. package/lib/components/ModelCompareV3/data/properties/cellular.js +1 -1
  114. package/lib/components/ModelCompareV3/data/properties/cellular.mjs +1 -1
  115. package/lib/components/ModelCompareV3/data/properties/clientDevices.js +1 -1
  116. package/lib/components/ModelCompareV3/data/properties/clientDevices.mjs +1 -1
  117. package/lib/components/ModelCompareV3/data/properties/connectedDevices.js +1 -1
  118. package/lib/components/ModelCompareV3/data/properties/connectedDevices.mjs +1 -1
  119. package/lib/components/ModelCompareV3/data/properties/dataPlan.js +1 -1
  120. package/lib/components/ModelCompareV3/data/properties/dataPlan.mjs +1 -1
  121. package/lib/components/ModelCompareV3/data/properties/dcPowerOutput.js +1 -1
  122. package/lib/components/ModelCompareV3/data/properties/dcPowerOutput.mjs +1 -1
  123. package/lib/components/ModelCompareV3/data/properties/etherlighting.js +1 -1
  124. package/lib/components/ModelCompareV3/data/properties/etherlighting.mjs +1 -1
  125. package/lib/components/ModelCompareV3/data/properties/mounting.js +1 -1
  126. package/lib/components/ModelCompareV3/data/properties/mounting.mjs +1 -1
  127. package/lib/components/ModelCompareV3/data/properties/nvrHdd35Bay.js +1 -1
  128. package/lib/components/ModelCompareV3/data/properties/nvrHdd35Bay.mjs +1 -1
  129. package/lib/components/ModelCompareV3/data/properties/outdoorReady.js +1 -1
  130. package/lib/components/ModelCompareV3/data/properties/outdoorReady.mjs +1 -1
  131. package/lib/components/ModelCompareV3/data/properties/storage.js +1 -1
  132. package/lib/components/ModelCompareV3/data/properties/storage.mjs +1 -1
  133. package/lib/components/ModelCompareV3/data/properties/storageCapacity.js +1 -1
  134. package/lib/components/ModelCompareV3/data/properties/storageCapacity.mjs +1 -1
  135. package/lib/components/ModelCompareV3/data/properties/weatherproofing.js +1 -1
  136. package/lib/components/ModelCompareV3/data/properties/weatherproofing.mjs +1 -1
  137. package/lib/components/QuantityInput/QuantityInput.js +1 -1
  138. package/lib/components/QuantityInput/QuantityInput.mjs +1 -1
  139. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  140. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  141. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  142. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  143. package/lib/constants/shopify/keyFeatureIcons.js +7 -7
  144. package/lib/constants/shopify/keyFeatureIcons.mjs +7 -7
  145. package/lib/utils/index.d.ts +1 -2
  146. package/lib/utils/index.js +6 -8
  147. package/lib/utils/index.js.map +1 -1
  148. package/lib/utils/index.mjs +6 -8
  149. package/lib/utils/index.mjs.map +1 -1
  150. package/lib/utils/money/allocators/fixedAmount.js +44 -0
  151. package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
  152. package/lib/utils/money/allocators/fixedAmount.mjs +42 -0
  153. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
  154. package/lib/utils/money/allocators/productAmount.js +75 -0
  155. package/lib/utils/money/allocators/productAmount.js.map +1 -0
  156. package/lib/utils/money/allocators/productAmount.mjs +73 -0
  157. package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
  158. package/lib/utils/money/exchangeRate.js +27 -0
  159. package/lib/utils/money/exchangeRate.js.map +1 -0
  160. package/lib/utils/money/exchangeRate.mjs +23 -0
  161. package/lib/utils/money/exchangeRate.mjs.map +1 -0
  162. package/lib/utils/money/format.js +101 -0
  163. package/lib/utils/money/format.js.map +1 -0
  164. package/lib/utils/money/format.mjs +96 -0
  165. package/lib/utils/money/format.mjs.map +1 -0
  166. package/lib/utils/money/index.js +56 -0
  167. package/lib/utils/money/index.js.map +1 -0
  168. package/lib/utils/money/index.mjs +11 -0
  169. package/lib/utils/money/index.mjs.map +1 -0
  170. package/lib/utils/money/shipping.js +8 -0
  171. package/lib/utils/money/shipping.js.map +1 -0
  172. package/lib/utils/money/shipping.mjs +6 -0
  173. package/lib/utils/money/shipping.mjs.map +1 -0
  174. package/lib/utils/money/tax.js +59 -0
  175. package/lib/utils/money/tax.js.map +1 -0
  176. package/lib/utils/money/tax.mjs +51 -0
  177. package/lib/utils/money/tax.mjs.map +1 -0
  178. package/lib/utils/money/tax.private.js +56 -0
  179. package/lib/utils/money/tax.private.js.map +1 -0
  180. package/lib/utils/money/tax.private.mjs +52 -0
  181. package/lib/utils/money/tax.private.mjs.map +1 -0
  182. package/lib/utils/money/types.js +3 -0
  183. package/lib/utils/money/types.js.map +1 -0
  184. package/lib/utils/money/types.mjs +2 -0
  185. package/lib/utils/money/types.mjs.map +1 -0
  186. package/package.json +1 -1
  187. package/lib/utils/variant.d.ts +0 -8
  188. package/lib/utils/variant.test.d.ts +0 -1
  189. package/lib/utils/wattage.d.ts +0 -11
  190. package/lib/utils/wattage.js +0 -20
  191. package/lib/utils/wattage.js.map +0 -1
  192. package/lib/utils/wattage.mjs +0 -18
  193. package/lib/utils/wattage.mjs.map +0 -1
  194. package/lib/utils/wattage.test.d.ts +0 -1
@@ -169,7 +169,7 @@ var wifi5 = require("../../assets/wifi5.svg");
169
169
  var wifi = require("../../assets/wifi.svg");
170
170
  var wide_angle = require("../../assets/wide_angle.svg");
171
171
  var wave = require("../../assets/wave.svg");
172
- var waterdrop = require("../../assets/waterdrop.svg");
172
+ var waterdrop = require("../../assets/waterdrop2.svg");
173
173
  var warning = require("../../assets/warning.svg");
174
174
  var video_file = require("../../assets/video_file.svg");
175
175
  var video = require("../../assets/video.svg");
@@ -194,7 +194,7 @@ var socket_eu = require("../../assets/socket_eu.svg");
194
194
  var snowflake = require("../../assets/snowflake.svg");
195
195
  var sma_connector = require("../../assets/sma_connector.svg");
196
196
  var sim_card = require("../../assets/sim_card.svg");
197
- var signal = require("../../assets/signal.svg");
197
+ var signal = require("../../assets/signal2.svg");
198
198
  var shield = require("../../assets/shield.svg");
199
199
  var sharing = require("../../assets/sharing.svg");
200
200
  var sfp = require("../../assets/sfp.svg");
@@ -211,10 +211,10 @@ var range = require("../../assets/range.svg");
211
211
  var radios = require("../../assets/radios.svg");
212
212
  var radio = require("../../assets/radio.svg");
213
213
  var rackv2 = require("../../assets/rackv2.svg");
214
- var rack = require("../../assets/rack2.svg");
214
+ var rack = require("../../assets/rack3.svg");
215
215
  var pulse = require("../../assets/pulse.svg");
216
216
  var power_support = require("../../assets/power_support.svg");
217
- var power = require("../../assets/power2.svg");
217
+ var power = require("../../assets/power3.svg");
218
218
  var poe_wifi = require("../../assets/poe_wifi.svg");
219
219
  var poe_plus_plus_plus_outlined = require("../../assets/poe_plus_plus_plus_outlined.svg");
220
220
  var poe_plus_plus_outlined = require("../../assets/poe_plus_plus_outlined.svg");
@@ -245,7 +245,7 @@ var lock = require("../../assets/lock.svg");
245
245
  var locate = require("../../assets/locate.svg");
246
246
  var license_plate = require("../../assets/license_plate.svg");
247
247
  var lens = require("../../assets/lens.svg");
248
- var led = require("../../assets/led.svg");
248
+ var led = require("../../assets/led2.svg");
249
249
  var layer3 = require("../../assets/layer3.svg");
250
250
  var layer2 = require("../../assets/layer2.svg");
251
251
  var latency = require("../../assets/latency.svg");
@@ -254,7 +254,7 @@ var human = require("../../assets/human.svg");
254
254
  var headset = require("../../assets/headset.svg");
255
255
  var hdr = require("../../assets/hdr.svg");
256
256
  var hdmi = require("../../assets/hdmi.svg");
257
- var hdd = require("../../assets/hdd.svg");
257
+ var hdd = require("../../assets/hdd2.svg");
258
258
  var hard_drive = require("../../assets/hard_drive.svg");
259
259
  var hammer = require("../../assets/hammer.svg");
260
260
  var group = require("../../assets/group.svg");
@@ -283,7 +283,7 @@ var coverage = require("../../assets/coverage.svg");
283
283
  var contract = require("../../assets/contract.svg");
284
284
  var connection = require("../../assets/connection.svg");
285
285
  var connected_devices = require("../../assets/connected_devices.svg");
286
- var clients = require("../../assets/clients.svg");
286
+ var clients = require("../../assets/clients2.svg");
287
287
  var chip = require("../../assets/chip.svg");
288
288
  var checkmark = require("../../assets/checkmark.svg");
289
289
  var card = require("../../assets/card.svg");
@@ -167,7 +167,7 @@ import wifi5__default from "../../assets/wifi5.svg";
167
167
  import wifi__default from "../../assets/wifi.svg";
168
168
  import wide_angle__default from "../../assets/wide_angle.svg";
169
169
  import wave__default from "../../assets/wave.svg";
170
- import waterdrop__default from "../../assets/waterdrop.svg";
170
+ import waterdrop__default from "../../assets/waterdrop2.svg";
171
171
  import warning__default from "../../assets/warning.svg";
172
172
  import video_file__default from "../../assets/video_file.svg";
173
173
  import video__default from "../../assets/video.svg";
@@ -192,7 +192,7 @@ import socket_eu__default from "../../assets/socket_eu.svg";
192
192
  import snowflake__default from "../../assets/snowflake.svg";
193
193
  import sma_connector__default from "../../assets/sma_connector.svg";
194
194
  import sim_card__default from "../../assets/sim_card.svg";
195
- import signal__default from "../../assets/signal.svg";
195
+ import signal__default from "../../assets/signal2.svg";
196
196
  import shield__default from "../../assets/shield.svg";
197
197
  import sharing__default from "../../assets/sharing.svg";
198
198
  import sfp__default from "../../assets/sfp.svg";
@@ -209,10 +209,10 @@ import range__default from "../../assets/range.svg";
209
209
  import radios__default from "../../assets/radios.svg";
210
210
  import radio__default from "../../assets/radio.svg";
211
211
  import rackv2__default from "../../assets/rackv2.svg";
212
- import rack__default from "../../assets/rack2.svg";
212
+ import rack__default from "../../assets/rack3.svg";
213
213
  import pulse__default from "../../assets/pulse.svg";
214
214
  import power_support__default from "../../assets/power_support.svg";
215
- import power__default from "../../assets/power2.svg";
215
+ import power__default from "../../assets/power3.svg";
216
216
  import poe_wifi__default from "../../assets/poe_wifi.svg";
217
217
  import poe_plus_plus_plus_outlined__default from "../../assets/poe_plus_plus_plus_outlined.svg";
218
218
  import poe_plus_plus_outlined__default from "../../assets/poe_plus_plus_outlined.svg";
@@ -243,7 +243,7 @@ import lock__default from "../../assets/lock.svg";
243
243
  import locate__default from "../../assets/locate.svg";
244
244
  import license_plate__default from "../../assets/license_plate.svg";
245
245
  import lens__default from "../../assets/lens.svg";
246
- import led__default from "../../assets/led.svg";
246
+ import led__default from "../../assets/led2.svg";
247
247
  import layer3__default from "../../assets/layer3.svg";
248
248
  import layer2__default from "../../assets/layer2.svg";
249
249
  import latency__default from "../../assets/latency.svg";
@@ -252,7 +252,7 @@ import human__default from "../../assets/human.svg";
252
252
  import headset__default from "../../assets/headset.svg";
253
253
  import hdr__default from "../../assets/hdr.svg";
254
254
  import hdmi__default from "../../assets/hdmi.svg";
255
- import hdd__default from "../../assets/hdd.svg";
255
+ import hdd__default from "../../assets/hdd2.svg";
256
256
  import hard_drive__default from "../../assets/hard_drive.svg";
257
257
  import hammer__default from "../../assets/hammer.svg";
258
258
  import group__default from "../../assets/group.svg";
@@ -281,7 +281,7 @@ import coverage__default from "../../assets/coverage.svg";
281
281
  import contract__default from "../../assets/contract.svg";
282
282
  import connection__default from "../../assets/connection.svg";
283
283
  import connected_devices__default from "../../assets/connected_devices.svg";
284
- import clients__default from "../../assets/clients.svg";
284
+ import clients__default from "../../assets/clients2.svg";
285
285
  import chip__default from "../../assets/chip.svg";
286
286
  import checkmark__default from "../../assets/checkmark.svg";
287
287
  import card__default from "../../assets/card.svg";
@@ -1,5 +1,5 @@
1
1
  export * as url from "./url";
2
- export * as money from "./money/misc";
2
+ export * as money from "./money";
3
3
  export * as number from "./number";
4
4
  export * as string from "./string";
5
5
  export * as array from "./array";
@@ -14,7 +14,6 @@ export * as shipping from "./shipping";
14
14
  export * as measures from "./measures";
15
15
  export * as errors from "./errors";
16
16
  export * as tags from "./tags";
17
- export * as wattage from "./wattage";
18
17
  export * as product from "./product";
19
18
  export * as asset from "./asset";
20
19
  export * as imageOptimizer from "./imageOptimizer";
@@ -1,22 +1,21 @@
1
1
  'use strict';
2
2
 
3
3
  var url$1 = require('./url.js');
4
- var misc = require('./money/misc.js');
4
+ var index = require('./money/index.js');
5
5
  var number$1 = require('./number.js');
6
6
  var string$1 = require('./string.js');
7
7
  var array$1 = require('./array.js');
8
- var index = require('./nextjs/index.js');
8
+ var index$1 = require('./nextjs/index.js');
9
9
  var country$1 = require('./country.js');
10
10
  var countriesAndZones = require('./countriesAndZones.js');
11
11
  var address$1 = require('./address.js');
12
- var index$1 = require('./tax/index.js');
12
+ var index$2 = require('./tax/index.js');
13
13
  var zod$1 = require('./zod.js');
14
14
  var collectionSlug$1 = require('./collectionSlug.js');
15
15
  var shipping$1 = require('./shipping.js');
16
16
  var measures$1 = require('./measures.js');
17
17
  var errors$1 = require('./errors.js');
18
18
  var tags$1 = require('./tags.js');
19
- var wattage$1 = require('./wattage.js');
20
19
  var product$1 = require('./product.js');
21
20
  var asset$1 = require('./asset.js');
22
21
  var imageOptimizer$1 = require('./imageOptimizer.js');
@@ -26,22 +25,21 @@ var blackFriday$1 = require('./blackFriday.js');
26
25
  var sales$1 = require('./sales.js');
27
26
  "use strict";
28
27
  exports.url = url$1;
29
- exports.money = misc;
28
+ exports.money = index;
30
29
  exports.number = number$1;
31
30
  exports.string = string$1;
32
31
  exports.array = array$1;
33
- exports.nextjs = index;
32
+ exports.nextjs = index$1;
34
33
  exports.country = country$1;
35
34
  exports.countryAndZones = countriesAndZones;
36
35
  exports.address = address$1;
37
- exports.tax = index$1;
36
+ exports.tax = index$2;
38
37
  exports.zod = zod$1;
39
38
  exports.collectionSlug = collectionSlug$1;
40
39
  exports.shipping = shipping$1;
41
40
  exports.measures = measures$1;
42
41
  exports.errors = errors$1;
43
42
  exports.tags = tags$1;
44
- exports.wattage = wattage$1;
45
43
  exports.product = product$1;
46
44
  exports.asset = asset$1;
47
45
  exports.imageOptimizer = imageOptimizer$1;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,23 +1,23 @@
1
1
  import * as url$1 from './url.mjs';
2
2
  export { url$1 as url };
3
- import * as misc from './money/misc.mjs';
4
- export { misc as money };
3
+ import * as index from './money/index.mjs';
4
+ export { index as money };
5
5
  import * as number$1 from './number.mjs';
6
6
  export { number$1 as number };
7
7
  import * as string$1 from './string.mjs';
8
8
  export { string$1 as string };
9
9
  import * as array$1 from './array.mjs';
10
10
  export { array$1 as array };
11
- import * as index from './nextjs/index.mjs';
12
- export { index as nextjs };
11
+ import * as index$1 from './nextjs/index.mjs';
12
+ export { index$1 as nextjs };
13
13
  import * as country$1 from './country.mjs';
14
14
  export { country$1 as country };
15
15
  import * as countriesAndZones from './countriesAndZones.mjs';
16
16
  export { countriesAndZones as countryAndZones };
17
17
  import * as address$1 from './address.mjs';
18
18
  export { address$1 as address };
19
- import * as index$1 from './tax/index.mjs';
20
- export { index$1 as tax };
19
+ import * as index$2 from './tax/index.mjs';
20
+ export { index$2 as tax };
21
21
  import * as zod$1 from './zod.mjs';
22
22
  export { zod$1 as zod };
23
23
  import * as collectionSlug$1 from './collectionSlug.mjs';
@@ -30,8 +30,6 @@ import * as errors$1 from './errors.mjs';
30
30
  export { errors$1 as errors };
31
31
  import * as tags$1 from './tags.mjs';
32
32
  export { tags$1 as tags };
33
- import * as wattage$1 from './wattage.mjs';
34
- export { wattage$1 as wattage };
35
33
  import * as product$1 from './product.mjs';
36
34
  export { product$1 as product };
37
35
  import * as asset$1 from './asset.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var dinero_js = require('dinero.js');
4
+ var errors = require('../../errors.js');
5
+ var misc = require('../misc.js');
6
+ "use strict";
7
+ class FixedAmountAllocator {
8
+ /**
9
+ * How much we have left to allocate for given allocation from the remaining total
10
+ */
11
+ remainingAllocationAmount;
12
+ /**
13
+ * How much we have left to allocate in total
14
+ */
15
+ remainingTotalAmount;
16
+ currency;
17
+ constructor({
18
+ initialAllocateAmount,
19
+ initialTotalAmount,
20
+ currency
21
+ }) {
22
+ this.remainingAllocationAmount = misc.getDinero(initialAllocateAmount, currency);
23
+ this.remainingTotalAmount = misc.getDinero(initialTotalAmount, currency);
24
+ this.currency = misc.getDineroCurrency(currency);
25
+ }
26
+ /**
27
+ * We always allocate biggest share to first item
28
+ */
29
+ allocate(lineItemTotal, currency) {
30
+ errors.assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
31
+ const lineItemTotalDinero = misc.getDinero(lineItemTotal, currency);
32
+ if (lineItemTotal === 0) {
33
+ return lineItemTotalDinero;
34
+ }
35
+ const [allocationAmount, remainingAllocationAmount] = dinero_js.allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(misc.amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
36
+ errors.assert(!!allocationAmount, "Allocation amount is zero");
37
+ errors.assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
38
+ this.remainingAllocationAmount = remainingAllocationAmount;
39
+ this.remainingTotalAmount = dinero_js.subtract(this.remainingTotalAmount, lineItemTotalDinero);
40
+ return dinero_js.greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
41
+ }
42
+ }
43
+ exports.FixedAmountAllocator = FixedAmountAllocator;
44
+ //# sourceMappingURL=fixedAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedAmount.js","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","remainingAllocationAmount","remainingTotalAmount","currency","constructor","initialAllocateAmount","initialTotalAmount","getDinero","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;;;AAWO,MAAMA,oBAAqB,CAAA;EAAA;AAAA;AAAA;EAIzBC,yBAAA;EAAA;AAAA;AAAA;EAIAC,oBAAA;EACAC,QAAA;EAE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AER;"}
@@ -0,0 +1,42 @@
1
+ import { allocate, subtract, greaterThan } from 'dinero.js';
2
+ import { assert } from '../../errors.mjs';
3
+ import { getDinero, getDineroCurrency, amount } from '../misc.mjs';
4
+ "use strict";
5
+ class FixedAmountAllocator {
6
+ /**
7
+ * How much we have left to allocate for given allocation from the remaining total
8
+ */
9
+ remainingAllocationAmount;
10
+ /**
11
+ * How much we have left to allocate in total
12
+ */
13
+ remainingTotalAmount;
14
+ currency;
15
+ constructor({
16
+ initialAllocateAmount,
17
+ initialTotalAmount,
18
+ currency
19
+ }) {
20
+ this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);
21
+ this.remainingTotalAmount = getDinero(initialTotalAmount, currency);
22
+ this.currency = getDineroCurrency(currency);
23
+ }
24
+ /**
25
+ * We always allocate biggest share to first item
26
+ */
27
+ allocate(lineItemTotal, currency) {
28
+ assert(this.currency.code === currency, `Currency mismatch, expected ${currency}, got ${this.currency.code}`);
29
+ const lineItemTotalDinero = getDinero(lineItemTotal, currency);
30
+ if (lineItemTotal === 0) {
31
+ return lineItemTotalDinero;
32
+ }
33
+ const [allocationAmount, remainingAllocationAmount] = allocate(this.remainingAllocationAmount, [lineItemTotal, Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0)]);
34
+ assert(!!allocationAmount, "Allocation amount is zero");
35
+ assert(!!remainingAllocationAmount, "Remaining allocation remainder is zero");
36
+ this.remainingAllocationAmount = remainingAllocationAmount;
37
+ this.remainingTotalAmount = subtract(this.remainingTotalAmount, lineItemTotalDinero);
38
+ return greaterThan(allocationAmount, lineItemTotalDinero) ? lineItemTotalDinero : allocationAmount;
39
+ }
40
+ }
41
+ export { FixedAmountAllocator };
42
+ //# sourceMappingURL=fixedAmount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixedAmount.mjs","sources":["../../../../src/utils/money/allocators/fixedAmount.ts"],"sourcesContent":["import { allocate, greaterThan, subtract } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { amount, getDinero, getDineroCurrency } from \"../misc\";\nimport type { Cents, Dino, DinoCurrency } from \"../types\";\n\n/**\n * Helper class to distribute a fixed amount (e.g. discount) between multiple items.\n * For example when trying to apply 5$ discount to 3 items, we need to distribute it evenly as possible\n */\nexport class FixedAmountAllocator {\n /**\n * How much we have left to allocate for given allocation from the remaining total\n */\n public remainingAllocationAmount: Dino;\n /**\n * How much we have left to allocate in total\n */\n public remainingTotalAmount: Dino;\n public currency: DinoCurrency;\n\n constructor({\n initialAllocateAmount,\n initialTotalAmount,\n currency,\n }: {\n initialAllocateAmount: Cents;\n initialTotalAmount: Cents;\n currency: Currency;\n }) {\n this.remainingAllocationAmount = getDinero(initialAllocateAmount, currency);\n this.remainingTotalAmount = getDinero(initialTotalAmount, currency);\n this.currency = getDineroCurrency(currency);\n }\n\n /**\n * We always allocate biggest share to first item\n */\n allocate(lineItemTotal: Cents, currency: Currency): Dino {\n assert(\n this.currency.code === currency,\n `Currency mismatch, expected ${currency}, got ${this.currency.code}`,\n );\n const lineItemTotalDinero = getDinero(lineItemTotal, currency);\n /**\n * If total price of line items is zero, it means it's free, thus no discount\n * can be calculated (it's either 0 or infinity, but let's go with 0)\n */\n if (lineItemTotal === 0) {\n return lineItemTotalDinero;\n }\n\n const [allocationAmount, remainingAllocationAmount] = allocate(\n this.remainingAllocationAmount,\n [\n lineItemTotal,\n Math.max(amount(this.remainingTotalAmount) - lineItemTotal, 0),\n ],\n );\n\n assert(!!allocationAmount, \"Allocation amount is zero\");\n assert(\n !!remainingAllocationAmount,\n \"Remaining allocation remainder is zero\",\n );\n\n this.remainingAllocationAmount = remainingAllocationAmount;\n this.remainingTotalAmount = subtract(\n this.remainingTotalAmount,\n lineItemTotalDinero,\n );\n\n /**\n * The discount amount is evenly split but can still be higher than the line item total\n * Need to ceil the price to be not more than the line item total\n */\n return greaterThan(allocationAmount, lineItemTotalDinero)\n ? lineItemTotalDinero\n : allocationAmount;\n }\n}\n"],"names":["FixedAmountAllocator","remainingAllocationAmount","remainingTotalAmount","currency","constructor","initialAllocateAmount","initialTotalAmount","getDinero","getDineroCurrency","allocate","lineItemTotal","assert","code","lineItemTotalDinero","allocationAmount","Math","max","amount","subtract","greaterThan"],"mappings":";;;;AAWO,MAAMA,oBAAqB,CAAA;EAAA;AAAA;AAAA;EAIzBC,yBAAA;EAAA;AAAA;AAAA;EAIAC,oBAAA;EACAC,QAAA;EAEPC,WAAYA,CAAA;IACVC,qBAAA;IACAC,kBAAA;IACAH;EAAA,CAKC,EAAA;IACI,IAAA,CAAAF,yBAAA,GAA4BM,SAAU,CAAAF,qBAAA,EAAuBF,QAAQ,CAAA;IACrE,IAAA,CAAAD,oBAAA,GAAuBK,SAAU,CAAAD,kBAAA,EAAoBH,QAAQ,CAAA;IAC7D,IAAA,CAAAA,QAAA,GAAWK,kBAAkBL,QAAQ,CAAA;EAAA;EAC5C;AAAA;AAAA;EAKAM,QAAAA,CAASC,eAAsBP,QAA0B,EAAA;IACvDQ,MAAA,CACE,IAAA,CAAKR,SAASS,IAAS,KAAAT,QAAA,EACvB,+BAA+BA,QAAQ,SAAS,IAAA,CAAKA,SAASS,IAAI,EACpE,CAAA;IACM,MAAAC,mBAAA,GAAsBN,SAAU,CAAAG,aAAA,EAAeP,QAAQ,CAAA;IAK7D,IAAIO,kBAAkB,CAAG,EAAA;MAChB,OAAAG,mBAAA;IAAA;IAGH,MAAA,CAACC,gBAAkB,EAAAb,yBAAyB,CAAI,GAAAQ,QAAA,CACpD,IAAK,CAAAR,yBAAA,EACL,CACES,aAAA,EACAK,KAAKC,GAAI,CAAAC,MAAA,CAAO,KAAKf,oBAAoB,CAAA,GAAIQ,eAAe,CAAC,CAAA,CAEjE,CAAA;IAEOC,MAAA,CAAA,CAAC,CAACG,gBAAA,EAAkB,2BAA2B,CAAA;IACtDH,MAAA,CACE,CAAC,CAACV,yBAAA,EACF,wCACF,CAAA;IAEA,IAAA,CAAKA,yBAA4B,GAAAA,yBAAA;IACjC,IAAA,CAAKC,oBAAuB,GAAAgB,QAAA,CAC1B,IAAK,CAAAhB,oBAAA,EACLW,mBACF,CAAA;IAMA,OAAOM,WAAY,CAAAL,gBAAA,EAAkBD,mBAAmB,CAAA,GACpDA,mBACA,GAAAC,gBAAA;EAAA;AAER;"}
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ var misc = require('../misc.js');
4
+ var fixedAmount = require('./fixedAmount.js');
5
+ "use strict";
6
+ class ProductAmountAllocator {
7
+ // #############################################################################
8
+ // Fixed values
9
+ // #############################################################################
10
+ #itemPrice;
11
+ #currency;
12
+ // #############################################################################
13
+ /**
14
+ * Remaining quantity to allocate
15
+ */
16
+ quantity;
17
+ // #############################################################################
18
+ // Specific amount allocators
19
+ // #############################################################################
20
+ #subtotal;
21
+ #discountAmount;
22
+ #taxableAmount;
23
+ #tax;
24
+ #total;
25
+ constructor(productSummary) {
26
+ const currency = productSummary.currency;
27
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
28
+ this.#itemPrice = productSummary.itemPrice;
29
+ this.#currency = currency;
30
+ this.quantity = productSummary.quantity;
31
+ this.#subtotal = new fixedAmount.FixedAmountAllocator({
32
+ initialAllocateAmount: productSummary.subtotal,
33
+ initialTotalAmount: priceForAllocation,
34
+ currency
35
+ });
36
+ this.#discountAmount = new fixedAmount.FixedAmountAllocator({
37
+ initialAllocateAmount: productSummary.discountAmount,
38
+ initialTotalAmount: priceForAllocation,
39
+ currency
40
+ });
41
+ this.#taxableAmount = new fixedAmount.FixedAmountAllocator({
42
+ initialAllocateAmount: productSummary.taxableAmount,
43
+ initialTotalAmount: priceForAllocation,
44
+ currency
45
+ });
46
+ this.#tax = new fixedAmount.FixedAmountAllocator({
47
+ initialAllocateAmount: productSummary.tax,
48
+ initialTotalAmount: priceForAllocation,
49
+ currency
50
+ });
51
+ this.#total = new fixedAmount.FixedAmountAllocator({
52
+ initialAllocateAmount: productSummary.total,
53
+ initialTotalAmount: priceForAllocation,
54
+ currency
55
+ });
56
+ }
57
+ allocateQty(quantity) {
58
+ let quantityNormalized = Math.max(quantity, 0);
59
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : this.quantity;
60
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
61
+ const itemQuantityPrice = this.#itemPrice * quantityNormalized;
62
+ return {
63
+ itemPrice: this.#itemPrice,
64
+ currency: this.#currency,
65
+ quantity: quantityNormalized,
66
+ subtotal: misc.amount(this.#subtotal.allocate(itemQuantityPrice, this.#currency)),
67
+ discountAmount: misc.amount(this.#discountAmount.allocate(itemQuantityPrice, this.#currency)),
68
+ taxableAmount: misc.amount(this.#taxableAmount.allocate(itemQuantityPrice, this.#currency)),
69
+ tax: misc.amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),
70
+ total: misc.amount(this.#total.allocate(itemQuantityPrice, this.#currency))
71
+ };
72
+ }
73
+ }
74
+ exports.ProductAmountAllocator = ProductAmountAllocator;
75
+ //# sourceMappingURL=productAmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productAmount.js","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0\n ? quantityNormalized\n : this.quantity;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["ProductAmountAllocator","itemPrice","currency","quantity","subtotal","discountAmount","taxableAmount","tax","total","constructor","productSummary","priceForAllocation","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","allocate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vE,CAAA;EAAA;AAEJ;"}
@@ -0,0 +1,73 @@
1
+ import { amount } from '../misc.mjs';
2
+ import { FixedAmountAllocator } from './fixedAmount.mjs';
3
+ "use strict";
4
+ class ProductAmountAllocator {
5
+ // #############################################################################
6
+ // Fixed values
7
+ // #############################################################################
8
+ #itemPrice;
9
+ #currency;
10
+ // #############################################################################
11
+ /**
12
+ * Remaining quantity to allocate
13
+ */
14
+ quantity;
15
+ // #############################################################################
16
+ // Specific amount allocators
17
+ // #############################################################################
18
+ #subtotal;
19
+ #discountAmount;
20
+ #taxableAmount;
21
+ #tax;
22
+ #total;
23
+ constructor(productSummary) {
24
+ const currency = productSummary.currency;
25
+ const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
26
+ this.#itemPrice = productSummary.itemPrice;
27
+ this.#currency = currency;
28
+ this.quantity = productSummary.quantity;
29
+ this.#subtotal = new FixedAmountAllocator({
30
+ initialAllocateAmount: productSummary.subtotal,
31
+ initialTotalAmount: priceForAllocation,
32
+ currency
33
+ });
34
+ this.#discountAmount = new FixedAmountAllocator({
35
+ initialAllocateAmount: productSummary.discountAmount,
36
+ initialTotalAmount: priceForAllocation,
37
+ currency
38
+ });
39
+ this.#taxableAmount = new FixedAmountAllocator({
40
+ initialAllocateAmount: productSummary.taxableAmount,
41
+ initialTotalAmount: priceForAllocation,
42
+ currency
43
+ });
44
+ this.#tax = new FixedAmountAllocator({
45
+ initialAllocateAmount: productSummary.tax,
46
+ initialTotalAmount: priceForAllocation,
47
+ currency
48
+ });
49
+ this.#total = new FixedAmountAllocator({
50
+ initialAllocateAmount: productSummary.total,
51
+ initialTotalAmount: priceForAllocation,
52
+ currency
53
+ });
54
+ }
55
+ allocateQty(quantity) {
56
+ let quantityNormalized = Math.max(quantity, 0);
57
+ quantityNormalized = this.quantity - quantityNormalized >= 0 ? quantityNormalized : this.quantity;
58
+ this.quantity = Math.max(this.quantity - quantityNormalized, 0);
59
+ const itemQuantityPrice = this.#itemPrice * quantityNormalized;
60
+ return {
61
+ itemPrice: this.#itemPrice,
62
+ currency: this.#currency,
63
+ quantity: quantityNormalized,
64
+ subtotal: amount(this.#subtotal.allocate(itemQuantityPrice, this.#currency)),
65
+ discountAmount: amount(this.#discountAmount.allocate(itemQuantityPrice, this.#currency)),
66
+ taxableAmount: amount(this.#taxableAmount.allocate(itemQuantityPrice, this.#currency)),
67
+ tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),
68
+ total: amount(this.#total.allocate(itemQuantityPrice, this.#currency))
69
+ };
70
+ }
71
+ }
72
+ export { ProductAmountAllocator };
73
+ //# sourceMappingURL=productAmount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productAmount.mjs","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0\n ? quantityNormalized\n : this.quantity;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["ProductAmountAllocator","itemPrice","currency","quantity","subtotal","discountAmount","taxableAmount","tax","total","constructor","productSummary","priceForAllocation","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","amount","allocate"],"mappings":";;;AAQO,MAAMA,sBAAuB,CAAA;EAAA;EAAA;EAAA;EAIzB,CAAAC,SAAA;EACA,CAAAC,QAAA;EAAA;EAAA;AAAA;AAAA;EAKTC,QAAA;EAAA;EAAA;EAAA;EAIA,CAAAC,QAAA;EACA,CAAAC,cAAA;EACA,CAAAC,a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,GAAWa,kBAAsB,IAAA,CAAA,GAClCA,qBACA,IAAK,CAAAb,QAAA;IAGX,IAAA,CAAKA,WAAWc,IAAK,CAAAC,GAAA,CAAI,IAAK,CAAAf,QAAA,GAAWa,oBAAoB,CAAC,CAAA;IAGxD,MAAAG,iBAAA,GAAoB,KAAK,CAAAlB,SAAa,GAAAe,kBAAA;IAErC,OAAA;MACLf,WAAW,IAAK,CAAA,CAAAA,SAAA;MAChBC,UAAU,IAAK,CAAA,CAAAA,QAAA;MACfC,QAAU,EAAAa,kBAAA;MACVZ,QAAU,EAAAgB,MAAA,CACR,IAAK,CAAA,CAAAhB,QAAA,CAAUiB,QAAS,CAAAF,iBAAA,EAAmB,KAAK,CAASjB,QAAA,CAC3D,CAAA;MACAG,cAAgB,EAAAe,MAAA,CACd,IAAK,CAAA,CAAAf,cAAA,CAAgBgB,QAAS,CAAAF,iBAAA,EAAmB,KAAK,CAASjB,QAAA,CACjE,CAAA;MACAI,aAAe,EAAAc,MAAA,CACb,IAAK,CAAA,CAAAd,aAAA,CAAee,QAAS,CAAAF,iBAAA,EAAmB,KAAK,CAASjB,QAAA,CAChE,CAAA;MACAK,GAAA,EAAKa,OAAO,IAAK,CAAA,CAAAb,GAAA,CAAKc,SAASF,iBAAmB,EAAA,IAAA,CAAK,CAAAjB,QAAS,CAAC,CAAA;MACjEM,KAAA,EAAOY,OAAO,IAAK,CAAA,CAAAZ,KAAA,CAAOa,SAASF,iBAAmB,EAAA,IAAA,CAAK,SAAS,CAAC;IACvE,CAAA;EAAA;AAEJ;"}
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var errors = require('../errors.js');
4
+ var number = require('../number.js');
5
+ var constants = require('./constants.js');
6
+ var misc_private = require('./misc.private.js');
7
+ "use strict";
8
+ const toSnapshotExchangeRate = exchangeRate => {
9
+ number.isFloat(exchangeRate, "Exchange rate");
10
+ errors.assert(exchangeRate > 0, "Exchange rate must be greater than 0");
11
+ const rateInt = misc_private.floatToInt(exchangeRate, constants.EXCHANGE_RATE_DINERO_CURRENCY.base, constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent);
12
+ return {
13
+ amount: rateInt,
14
+ scale: constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent
15
+ };
16
+ };
17
+ function toFixedExchangeRate(rate, asNumber) {
18
+ return number.toFixedRate(typeof rate === "string" ? +rate : rate, constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent, asNumber);
19
+ }
20
+ function invertExchangeRate(rate) {
21
+ const exchangeRate = toFixedExchangeRate(rate, true);
22
+ return toFixedExchangeRate(1 / exchangeRate, false);
23
+ }
24
+ exports.invertExchangeRate = invertExchangeRate;
25
+ exports.toFixedExchangeRate = toFixedExchangeRate;
26
+ exports.toSnapshotExchangeRate = toSnapshotExchangeRate;
27
+ //# sourceMappingURL=exchangeRate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchangeRate.js","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\nimport type { Cents, TaxRate } from \"./types\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: TaxRate,\n): {\n amount: Cents;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,MAAA,CAAAA,OAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,aAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,YAAA,CAAAA,UAAA,CACdJ,YAAA,EACAK,SAAAA,CAAAA,6BAA8B,CAAAC,IAAA,EAC9BD,uCAA8B,CAAAE,QAChC,CAAA;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,SAAAA,CAAAA,6BAA8B,CAAAE;EACvC,CAAA;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,MAAA,CAAAA,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,EAC9BK,QACF,CAAA;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;;;"}
@@ -0,0 +1,23 @@
1
+ import { assert } from '../errors.mjs';
2
+ import { isFloat, toFixedRate } from '../number.mjs';
3
+ import { EXCHANGE_RATE_DINERO_CURRENCY } from './constants.mjs';
4
+ import { floatToInt } from './misc.private.mjs';
5
+ "use strict";
6
+ const toSnapshotExchangeRate = exchangeRate => {
7
+ isFloat(exchangeRate, "Exchange rate");
8
+ assert(exchangeRate > 0, "Exchange rate must be greater than 0");
9
+ const rateInt = floatToInt(exchangeRate, EXCHANGE_RATE_DINERO_CURRENCY.base, EXCHANGE_RATE_DINERO_CURRENCY.exponent);
10
+ return {
11
+ amount: rateInt,
12
+ scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent
13
+ };
14
+ };
15
+ function toFixedExchangeRate(rate, asNumber) {
16
+ return toFixedRate(typeof rate === "string" ? +rate : rate, EXCHANGE_RATE_DINERO_CURRENCY.exponent, asNumber);
17
+ }
18
+ function invertExchangeRate(rate) {
19
+ const exchangeRate = toFixedExchangeRate(rate, true);
20
+ return toFixedExchangeRate(1 / exchangeRate, false);
21
+ }
22
+ export { invertExchangeRate, toFixedExchangeRate, toSnapshotExchangeRate };
23
+ //# sourceMappingURL=exchangeRate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchangeRate.mjs","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\nimport type { Cents, TaxRate } from \"./types\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: TaxRate,\n): {\n amount: Cents;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,OAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,UAAA,CACdJ,YAAA,EACAK,6BAA8B,CAAAC,IAAA,EAC9BD,6BAA8B,CAAAE,QAChC,CAAA;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,6BAA8B,CAAAE;EACvC,CAAA;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,6BAA8B,CAAAE,QAAA,EAC9BK,QACF,CAAA;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;"}