@ubnt/store.core 11.29.0-custom-tax.0 → 11.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/CHANGELOG.md +0 -8
  2. package/lib/_virtual/_virtual_multi-entry.js +98 -100
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +98 -100
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/ai-dslr.jpg +0 -0
  7. package/lib/assets/ai-dslr2.jpg +0 -0
  8. package/lib/assets/ai-lpr.jpg +0 -0
  9. package/lib/assets/ai-lpr2.jpg +0 -0
  10. package/lib/assets/ai-theta.jpg +0 -0
  11. package/lib/assets/ai-theta2.jpg +0 -0
  12. package/lib/assets/compact.svg +1 -1
  13. package/lib/assets/compact2.svg +1 -1
  14. package/lib/assets/compact22.svg +1 -0
  15. package/lib/assets/floodlight.svg +1 -1
  16. package/lib/assets/floodlight2.svg +1 -1
  17. package/lib/assets/g3-reader-flex.jpg +0 -0
  18. package/lib/assets/g3-reader-flex2.jpg +0 -0
  19. package/lib/assets/g3-reader-pro.jpg +0 -0
  20. package/lib/assets/g3-reader-pro2.jpg +0 -0
  21. package/lib/assets/g3-starter-kit-pro.jpg +0 -0
  22. package/lib/assets/g3-starter-kit-pro2.jpg +0 -0
  23. package/lib/assets/g4-instant.jpg +0 -0
  24. package/lib/assets/g4-instant2.jpg +0 -0
  25. package/lib/assets/g4-ptz.jpg +0 -0
  26. package/lib/assets/g4-ptz2.jpg +0 -0
  27. package/lib/assets/g5-bullet.jpg +0 -0
  28. package/lib/assets/g5-bullet2.jpg +0 -0
  29. package/lib/assets/g5-dome-ultra.jpg +0 -0
  30. package/lib/assets/g5-dome-ultra2.jpg +0 -0
  31. package/lib/assets/globe.svg +1 -1
  32. package/lib/assets/globe2.svg +1 -1
  33. package/lib/assets/intercom.jpg +0 -0
  34. package/lib/assets/intercom2.jpg +0 -0
  35. package/lib/assets/minus4.svg +1 -1
  36. package/lib/assets/minus5.svg +1 -1
  37. package/lib/assets/plus4.svg +1 -1
  38. package/lib/assets/plus5.svg +1 -1
  39. package/lib/assets/power.svg +1 -1
  40. package/lib/assets/power2.svg +1 -1
  41. package/lib/assets/rack.svg +1 -1
  42. package/lib/assets/rack2.svg +1 -1
  43. package/lib/assets/udr2.jpg +0 -0
  44. package/lib/assets/udr3.jpg +0 -0
  45. package/lib/assets/video-recorders.png +0 -0
  46. package/lib/components/Header/Header.js +1 -1
  47. package/lib/components/Header/Header.mjs +1 -1
  48. package/lib/components/Header/ProHeader/ProHeader.js +1 -1
  49. package/lib/components/Header/ProHeader/ProHeader.mjs +1 -1
  50. package/lib/components/MicrositeHeader/components/HeaderContent/HeaderContent.js +1 -1
  51. package/lib/components/MicrositeHeader/components/HeaderContent/HeaderContent.mjs +1 -1
  52. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  53. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  54. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  55. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  56. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  57. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  58. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  59. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  60. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  61. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  62. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  63. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  64. package/lib/components/index.d.ts +3 -4
  65. package/lib/components/index.js +82 -84
  66. package/lib/components/index.js.map +1 -1
  67. package/lib/components/index.mjs +82 -84
  68. package/lib/components/index.mjs.map +1 -1
  69. package/lib/constants/icons/header/globe.svg.js +1 -1
  70. package/lib/constants/icons/header/globe.svg.mjs +2 -2
  71. package/lib/constants/icons/header/index.js +1 -1
  72. package/lib/constants/icons/header/index.mjs +1 -1
  73. package/lib/constants/icons/menu/floodlight.svg.js +5 -5
  74. package/lib/constants/icons/menu/floodlight.svg.mjs +2 -2
  75. package/lib/constants/icons/menu/index.js +9 -9
  76. package/lib/constants/icons/menu/index.mjs +3 -3
  77. package/lib/constants/icons/menu/power.svg.js +5 -5
  78. package/lib/constants/icons/menu/power.svg.mjs +2 -2
  79. package/lib/constants/icons/menu/rack.svg.js +5 -5
  80. package/lib/constants/icons/menu/rack.svg.mjs +2 -2
  81. package/lib/constants/modelCompareData/assets/Bullet/ai-dslr.jpg.js +1 -1
  82. package/lib/constants/modelCompareData/assets/Bullet/ai-dslr.jpg.mjs +2 -2
  83. package/lib/constants/modelCompareData/assets/Bullet/ai-lpr.jpg.js +1 -1
  84. package/lib/constants/modelCompareData/assets/Bullet/ai-lpr.jpg.mjs +2 -2
  85. package/lib/constants/modelCompareData/assets/Bullet/g5-bullet.jpg.js +1 -1
  86. package/lib/constants/modelCompareData/assets/Bullet/g5-bullet.jpg.mjs +2 -2
  87. package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.js +1 -1
  88. package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.mjs +2 -2
  89. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.js +5 -5
  90. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
  91. package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.js +1 -1
  92. package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.mjs +2 -2
  93. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome-ultra.jpg.js +1 -1
  94. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome-ultra.jpg.mjs +2 -2
  95. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.js +1 -1
  96. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.mjs +2 -2
  97. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.js +1 -1
  98. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.mjs +2 -2
  99. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.js +1 -1
  100. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs +2 -2
  101. package/lib/constants/modelCompareData/assets/DoorAccess/intercom.jpg.js +1 -1
  102. package/lib/constants/modelCompareData/assets/DoorAccess/intercom.jpg.mjs +2 -2
  103. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.js +1 -1
  104. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.mjs +2 -2
  105. package/lib/constants/modelCompareData/assets/PTZ/g4-ptz.jpg.js +1 -1
  106. package/lib/constants/modelCompareData/assets/PTZ/g4-ptz.jpg.mjs +2 -2
  107. package/lib/constants/modelCompareData/assets/compact.svg.js +1 -1
  108. package/lib/constants/modelCompareData/assets/compact.svg.mjs +2 -2
  109. package/lib/constants/modelCompareData/assets/floodlight.svg.js +1 -1
  110. package/lib/constants/modelCompareData/assets/floodlight.svg.mjs +2 -2
  111. package/lib/constants/modelCompareData/assets/globe.svg.js +1 -1
  112. package/lib/constants/modelCompareData/assets/globe.svg.mjs +2 -2
  113. package/lib/constants/modelCompareData/assets/power.svg.js +1 -1
  114. package/lib/constants/modelCompareData/assets/power.svg.mjs +2 -2
  115. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-dslr.jpg.js +1 -1
  116. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-dslr.jpg.mjs +2 -2
  117. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-lpr.jpg.js +1 -1
  118. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-lpr.jpg.mjs +2 -2
  119. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/g5-bullet.jpg.js +1 -1
  120. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/g5-bullet.jpg.mjs +2 -2
  121. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.js +1 -1
  122. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.mjs +2 -2
  123. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome-ultra.jpg.js +1 -1
  124. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome-ultra.jpg.mjs +2 -2
  125. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.js +1 -1
  126. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.mjs +2 -2
  127. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.js +1 -1
  128. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.mjs +2 -2
  129. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.js +1 -1
  130. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.mjs +2 -2
  131. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/intercom.jpg.js +1 -1
  132. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/intercom.jpg.mjs +2 -2
  133. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.js +1 -1
  134. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.mjs +2 -2
  135. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g4-ptz.jpg.js +1 -1
  136. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g4-ptz.jpg.mjs +2 -2
  137. package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.js +1 -1
  138. package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.mjs +2 -2
  139. package/lib/constants/modelCompareData/assets/product-list-assets/compact2.svg.js +1 -1
  140. package/lib/constants/modelCompareData/assets/product-list-assets/compact2.svg.mjs +2 -2
  141. package/lib/constants/modelCompareData/assets/rack.svg.js +1 -1
  142. package/lib/constants/modelCompareData/assets/rack.svg.mjs +2 -2
  143. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.js +3 -3
  144. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.mjs +2 -2
  145. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.js +1 -1
  146. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.mjs +1 -1
  147. package/lib/constants/modelCompareData/data/product-list-groups/compact.js +1 -1
  148. package/lib/constants/modelCompareData/data/product-list-groups/compact.mjs +1 -1
  149. package/lib/constants/modelCompareData/data/product-list-groups/productListSwitchingCompact.js +1 -1
  150. package/lib/constants/modelCompareData/data/product-list-groups/productListSwitchingCompact.mjs +1 -1
  151. package/lib/constants/modelCompareData/data/products/aiDslr.js +2 -2
  152. package/lib/constants/modelCompareData/data/products/aiDslr.mjs +2 -2
  153. package/lib/constants/modelCompareData/data/products/aiLpr.js +2 -2
  154. package/lib/constants/modelCompareData/data/products/aiLpr.mjs +2 -2
  155. package/lib/constants/modelCompareData/data/products/g3ReaderFlex.js +2 -2
  156. package/lib/constants/modelCompareData/data/products/g3ReaderFlex.mjs +2 -2
  157. package/lib/constants/modelCompareData/data/products/g3ReaderPro.js +2 -2
  158. package/lib/constants/modelCompareData/data/products/g3ReaderPro.mjs +2 -2
  159. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.js +2 -2
  160. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.mjs +2 -2
  161. package/lib/constants/modelCompareData/data/products/g4Instant.js +2 -2
  162. package/lib/constants/modelCompareData/data/products/g4Instant.mjs +2 -2
  163. package/lib/constants/modelCompareData/data/products/g4Ptz.js +2 -2
  164. package/lib/constants/modelCompareData/data/products/g4Ptz.mjs +2 -2
  165. package/lib/constants/modelCompareData/data/products/g5Bullet.js +2 -2
  166. package/lib/constants/modelCompareData/data/products/g5Bullet.mjs +2 -2
  167. package/lib/constants/modelCompareData/data/products/g5DomeUltra.js +2 -2
  168. package/lib/constants/modelCompareData/data/products/g5DomeUltra.mjs +2 -2
  169. package/lib/constants/modelCompareData/data/products/intercom.js +2 -2
  170. package/lib/constants/modelCompareData/data/products/intercom.mjs +2 -2
  171. package/lib/constants/modelCompareData/data/products/theta.js +2 -2
  172. package/lib/constants/modelCompareData/data/products/theta.mjs +2 -2
  173. package/lib/constants/modelCompareData/data/products/udr.js +1 -1
  174. package/lib/constants/modelCompareData/data/products/udr.mjs +1 -1
  175. package/lib/constants/modelCompareData/data/properties/accessPowerMethod.js +1 -1
  176. package/lib/constants/modelCompareData/data/properties/accessPowerMethod.mjs +1 -1
  177. package/lib/constants/modelCompareData/data/properties/availability.js +1 -1
  178. package/lib/constants/modelCompareData/data/properties/availability.mjs +1 -1
  179. package/lib/constants/modelCompareData/data/properties/builtInFloodlight.js +1 -1
  180. package/lib/constants/modelCompareData/data/properties/builtInFloodlight.mjs +1 -1
  181. package/lib/constants/modelCompareData/data/properties/dcPowerOutput.js +1 -1
  182. package/lib/constants/modelCompareData/data/properties/dcPowerOutput.mjs +1 -1
  183. package/lib/constants/modelCompareData/data/properties/mounting.js +1 -1
  184. package/lib/constants/modelCompareData/data/properties/mounting.mjs +1 -1
  185. package/lib/constants/modelCompareData/data/properties/unasPowerMethod.js +1 -1
  186. package/lib/constants/modelCompareData/data/properties/unasPowerMethod.mjs +1 -1
  187. package/lib/constants/modelCompareData/data/properties/webMode.js +1 -1
  188. package/lib/constants/modelCompareData/data/properties/webMode.mjs +1 -1
  189. package/lib/contexts/MenuContext/mapping.js +3 -3
  190. package/lib/contexts/MenuContext/mapping.mjs +2 -2
  191. package/lib/contexts/MicrositeMenuContext/mapping.js +3 -3
  192. package/lib/contexts/MicrositeMenuContext/mapping.mjs +2 -2
  193. package/lib/contexts/MicrositeMenuContext/translations/ar.json.js +1 -1
  194. package/lib/contexts/MicrositeMenuContext/translations/ar.json.mjs +1 -1
  195. package/lib/contexts/MicrositeMenuContext/translations/ca.json.js +1 -1
  196. package/lib/contexts/MicrositeMenuContext/translations/ca.json.mjs +1 -1
  197. package/lib/contexts/MicrositeMenuContext/translations/cs.json.js +1 -1
  198. package/lib/contexts/MicrositeMenuContext/translations/cs.json.mjs +1 -1
  199. package/lib/contexts/MicrositeMenuContext/translations/da.json.js +1 -1
  200. package/lib/contexts/MicrositeMenuContext/translations/da.json.mjs +1 -1
  201. package/lib/contexts/MicrositeMenuContext/translations/de.json.js +1 -1
  202. package/lib/contexts/MicrositeMenuContext/translations/de.json.mjs +1 -1
  203. package/lib/contexts/MicrositeMenuContext/translations/el.json.js +1 -1
  204. package/lib/contexts/MicrositeMenuContext/translations/el.json.mjs +1 -1
  205. package/lib/contexts/MicrositeMenuContext/translations/en.json.js +1 -1
  206. package/lib/contexts/MicrositeMenuContext/translations/en.json.mjs +1 -1
  207. package/lib/contexts/MicrositeMenuContext/translations/es-ES.json.js +1 -1
  208. package/lib/contexts/MicrositeMenuContext/translations/es-ES.json.mjs +1 -1
  209. package/lib/contexts/MicrositeMenuContext/translations/es-MX.json.js +1 -1
  210. package/lib/contexts/MicrositeMenuContext/translations/es-MX.json.mjs +1 -1
  211. package/lib/contexts/MicrositeMenuContext/translations/fr.json.js +1 -1
  212. package/lib/contexts/MicrositeMenuContext/translations/fr.json.mjs +1 -1
  213. package/lib/contexts/MicrositeMenuContext/translations/it.json.js +1 -1
  214. package/lib/contexts/MicrositeMenuContext/translations/it.json.mjs +1 -1
  215. package/lib/contexts/MicrositeMenuContext/translations/ja.json.js +1 -1
  216. package/lib/contexts/MicrositeMenuContext/translations/ja.json.mjs +1 -1
  217. package/lib/contexts/MicrositeMenuContext/translations/ko.json.js +1 -1
  218. package/lib/contexts/MicrositeMenuContext/translations/ko.json.mjs +1 -1
  219. package/lib/contexts/MicrositeMenuContext/translations/nl.json.js +1 -1
  220. package/lib/contexts/MicrositeMenuContext/translations/nl.json.mjs +1 -1
  221. package/lib/contexts/MicrositeMenuContext/translations/no.json.js +1 -1
  222. package/lib/contexts/MicrositeMenuContext/translations/no.json.mjs +1 -1
  223. package/lib/contexts/MicrositeMenuContext/translations/pl.json.js +1 -1
  224. package/lib/contexts/MicrositeMenuContext/translations/pl.json.mjs +1 -1
  225. package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.js +1 -1
  226. package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.mjs +1 -1
  227. package/lib/contexts/MicrositeMenuContext/translations/pt-PT.json.js +1 -1
  228. package/lib/contexts/MicrositeMenuContext/translations/pt-PT.json.mjs +1 -1
  229. package/lib/contexts/MicrositeMenuContext/translations/ru.json.js +1 -1
  230. package/lib/contexts/MicrositeMenuContext/translations/ru.json.mjs +1 -1
  231. package/lib/contexts/MicrositeMenuContext/translations/sv.json.js +1 -1
  232. package/lib/contexts/MicrositeMenuContext/translations/sv.json.mjs +1 -1
  233. package/lib/contexts/MicrositeMenuContext/translations/tr.json.js +1 -1
  234. package/lib/contexts/MicrositeMenuContext/translations/tr.json.mjs +1 -1
  235. package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.js +1 -1
  236. package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.mjs +1 -1
  237. package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.js +1 -1
  238. package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.mjs +1 -1
  239. package/lib/utils/money/index.d.ts +0 -1
  240. package/lib/utils/money/index.js +0 -2
  241. package/lib/utils/money/index.js.map +1 -1
  242. package/lib/utils/money/index.mjs +0 -1
  243. package/lib/utils/money/index.mjs.map +1 -1
  244. package/lib/utils/money/tax.d.ts +3 -6
  245. package/lib/utils/money/tax.js +10 -3
  246. package/lib/utils/money/tax.js.map +1 -1
  247. package/lib/utils/money/tax.mjs +13 -6
  248. package/lib/utils/money/tax.mjs.map +1 -1
  249. package/lib/utils/money/tax.private.d.ts +2 -7
  250. package/lib/utils/money/tax.private.js +6 -21
  251. package/lib/utils/money/tax.private.js.map +1 -1
  252. package/lib/utils/money/tax.private.mjs +8 -22
  253. package/lib/utils/money/tax.private.mjs.map +1 -1
  254. package/package.json +1 -1
  255. package/lib/assets/compact3.svg +0 -1
  256. package/lib/components/Checkbox/Checkbox.js +0 -39
  257. package/lib/components/Checkbox/Checkbox.js.map +0 -1
  258. package/lib/components/Checkbox/Checkbox.mjs +0 -37
  259. package/lib/components/Checkbox/Checkbox.mjs.map +0 -1
  260. package/lib/components/Checkbox/Checkbox.styles.js +0 -48
  261. package/lib/components/Checkbox/Checkbox.styles.js.map +0 -1
  262. package/lib/components/Checkbox/Checkbox.styles.mjs +0 -44
  263. package/lib/components/Checkbox/Checkbox.styles.mjs.map +0 -1
  264. package/lib/components/Checkbox/index.js +0 -6
  265. package/lib/components/Checkbox/index.js.map +0 -1
  266. package/lib/components/Checkbox/index.mjs +0 -3
  267. package/lib/components/Checkbox/index.mjs.map +0 -1
  268. package/lib/utils/money/allocators/totalAmount.d.ts +0 -17
  269. package/lib/utils/money/allocators/totalAmount.js +0 -40
  270. package/lib/utils/money/allocators/totalAmount.js.map +0 -1
  271. package/lib/utils/money/allocators/totalAmount.mjs +0 -38
  272. package/lib/utils/money/allocators/totalAmount.mjs.map +0 -1
  273. package/lib/utils/money/allocators/totalAmount.test.d.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tax.js","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n dinero,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n subtract,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n getTaxFromFinalAmount,\n} from \"./tax.private\";\nimport type { Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n options,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n options: { storeId: StoreId; hasTaxIncludedPrice: boolean };\n}): Dino => {\n return storesWithPerItemTaxRate.has(options.storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate, options)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate, options);\n};\n\nexport const removeTaxAmount = (amountWithTax: Dino, taxRate: TaxRate): Dino =>\n subtract(amountWithTax, getTaxFromFinalAmount(amountWithTax, taxRate));\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","options","storesWithPerItemTaxRate","has","storeId","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","amountWithTax","subtract","getTaxFromFinalAmount","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","dinero","amount","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert"],"mappings":";;;;;;;;AA0BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAAA,KAIY;EACV,OAAOC,SAAAA,CAAAA,wBAAA,CAAyBC,GAAA,CAAIF,OAAA,CAAQG,OAAO,CAAA,GAC/CC,WAAAA,CAAAA,0BAAA,CAA2BN,WAAA,EAAaC,OAAA,EAASC,OAAO,CAAA,GACxDK,WAAAA,CAAAA,4BAAA,CAA6BP,WAAA,EAAaC,SAASC,OAAO,CAAA;AAChE,CAAA;AAEO,MAAMM,eAAA,GAAkBA,CAACC,aAAA,EAAqBR,OAAA,KACnDS,SAAAA,CAAAA,SAASD,aAAA,EAAeE,WAAAA,CAAAA,qBAAA,CAAsBF,aAAA,EAAeR,OAAO,CAAC,CAAA;AAWhE,MAAMW,iCAAA,GACXX,OAAA,IACW;EACX,MAAMY,SAAA,GAAYC,uBAAuBb,OAAO,CAAA;EAChD,MAAMc,CAAA,GAAIC,SAAAA,CAAAA,QAAA,CAASH,SAAA,EAAW,GAAG,CAAA;EACjC,OAAOI,SAAAA,CAAAA,OAAOF,CAAA,EAAG;IACfG,QAAQC,SAAAA,CAAAA,wBAAA,CAAyBC,QAAA;IACjCC,KAAA,EAAOC,SAAAA,CAAAA;EAAA,CACR,CAAA;AACH,CAAA;AAEO,MAAMR,sBAAA,GAA0Bb,OAAA,IAAmC;EACxE,MAAMsB,eACJ,OAAOtB,OAAA,KAAY,WAAWA,OAAA,GAAUuB,MAAA,CAAOC,WAAWxB,OAAO,CAAA;EACnEyB,MAAAA,CAAAA,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAA,CAAOI,QAAA,CAAA,CAE3BL,YAAA,GACAM,KAAKC,GAAA,CAAIX,SAAAA,CAAAA,wBAAA,CAAyBY,MAAMZ,kCAAA,CAAyBC,QAAQ,CAAA,EACzEY,OAAA,CAAQ,CAAC,CAAA,CACb;EACA,OAAOC,gBAAA,CAAO;IACZC,MAAA,EAAQP,eAAA;IACRQ,QAAA,EAAUhB,SAAAA,CAAAA;EAAA,CACX,CAAA;AACH,CAAA;AAWO,MAAMiB,oBAAA,GACXnC,OAAA,IACiB;EACjB,OAAO,GAAGW,iCAAA,CAAkCX,OAAO,CAAC,GAAA;AACtD,CAAA;AAEO,MAAMoC,oBAAA,GAAwBC,IAAA,IACnCC,MAAAA,CAAAA,WAAA,CAAY,CAACD,IAAA,EAAMnB,SAAAA,CAAAA,wBAAA,CAAyBC,UAAU,IAAI,CAAA;AAMrD,MAAMoB,qBAAA,GAAyBC,KAAA,IAA4B;EAChE,MAAMC,OAAA,GAAUD,MAAME,MAAA,CAAO,CAACC,KAAKN,IAAA,KAASM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAA,GAASN,MAAAA,CAAAA,WAAA,CAAYG,OAAA,EAASvB,SAAAA,CAAAA,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EAC3E0B,aAAA,CAAOD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EAC/CC,aAAA,CAAOD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EACjD,OAAOA,MAAA;AACT,CAAA;;;;;;;"}
1
+ {"version":3,"file":"tax.js","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n dinero,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n toSnapshot,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n Round,\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n} from \"./tax.private\";\nimport type { Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n storeId,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n storeId: StoreId;\n}) => {\n return storesWithPerItemTaxRate.has(storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate);\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dino,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n\n // Calculate the tax amount and apply rounding on it so that behavior for reverse process is consistent\n const taxAmount = Round.Financial(\n snapshot.amount - snapshot.amount / (1 + taxRate),\n );\n\n return dinero({\n ...snapshot,\n amount: snapshot.amount - taxAmount,\n });\n};\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","storeId","storesWithPerItemTaxRate","has","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","taxAmount","Round","Financial","amount","dinero","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert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YAAA,GACAM,KAAKC,GAAA,CAAIX,SAAAA,CAAAA,wBAAA,CAAyBY,MAAMZ,kCAAA,CAAyBC,QAAQ,CAAA,EACzEY,OAAA,CAAQ,CAAC,CAAA,CACb;EACA,OAAOrB,gBAAA,CAAO;IACZD,MAAA,EAAQiB,eAAA;IACRM,QAAA,EAAUd,SAAAA,CAAAA;EAAA,CACX,CAAA;AACH,CAAA;AAWO,MAAMe,oBAAA,GACXrC,OAAA,IACiB;EACjB,OAAO,GAAGe,iCAAA,CAAkCf,OAAO,CAAC,GAAA;AACtD,CAAA;AAEO,MAAMsC,oBAAA,GAAwBC,IAAA,IACnCC,MAAAA,CAAAA,WAAA,CAAY,CAACD,IAAA,EAAMjB,SAAAA,CAAAA,wBAAA,CAAyBC,UAAU,IAAI,CAAA;AAMrD,MAAMkB,qBAAA,GAAyBC,KAAA,IAA4B;EAChE,MAAMC,OAAA,GAAUD,MAAME,MAAA,CAAO,CAACC,KAAKN,IAAA,KAASM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAA,GAASN,MAAAA,CAAAA,WAAA,CAAYG,OAAA,EAASrB,SAAAA,CAAAA,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EAC3EwB,aAAA,CAAOD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EAC/CC,aAAA,CAAOD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EACjD,OAAOA,MAAA;AACT,CAAA;;;;;;;"}
@@ -1,17 +1,24 @@
1
- import { subtract, multiply, toUnit, halfEven, dinero } from 'dinero.js';
1
+ import { toSnapshot, dinero, multiply, toUnit, halfEven } from 'dinero.js';
2
2
  import { assert } from '../errors.mjs';
3
3
  import { isFloat, toFixedRate } from '../number.mjs';
4
- import { storesWithPerItemTaxRate, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
5
- import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, getTaxFromFinalAmount } from './tax.private.mjs';
4
+ import { storesWithPerItemTaxRate, Round, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
5
+ import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax } from './tax.private.mjs';
6
6
  "use strict";
7
7
  const calculateLineItemTax = ({
8
8
  itemSummary,
9
9
  taxRate,
10
- options
10
+ storeId
11
11
  }) => {
12
- return storesWithPerItemTaxRate.has(options.storeId) ? calculatePerQtyLineItemTax(itemSummary, taxRate, options) : calculateWholeQtyLineItemTax(itemSummary, taxRate, options);
12
+ return storesWithPerItemTaxRate.has(storeId) ? calculatePerQtyLineItemTax(itemSummary, taxRate) : calculateWholeQtyLineItemTax(itemSummary, taxRate);
13
+ };
14
+ const removeTaxAmount = (baseAmountWithTaxObj, taxRate) => {
15
+ const snapshot = toSnapshot(baseAmountWithTaxObj);
16
+ const taxAmount = Round.Financial(snapshot.amount - snapshot.amount / (1 + taxRate));
17
+ return dinero({
18
+ ...snapshot,
19
+ amount: snapshot.amount - taxAmount
20
+ });
13
21
  };
14
- const removeTaxAmount = (amountWithTax, taxRate) => subtract(amountWithTax, getTaxFromFinalAmount(amountWithTax, taxRate));
15
22
  const convertDecimalTaxRateToPercentage = taxRate => {
16
23
  const dineroObj = decimalTaxRateToDinero(taxRate);
17
24
  const t = multiply(dineroObj, 100);
@@ -1 +1 @@
1
- {"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n dinero,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n subtract,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n getTaxFromFinalAmount,\n} from \"./tax.private\";\nimport type { Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n options,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n options: { storeId: StoreId; hasTaxIncludedPrice: boolean };\n}): Dino => {\n return storesWithPerItemTaxRate.has(options.storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate, options)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate, options);\n};\n\nexport const removeTaxAmount = (amountWithTax: Dino, taxRate: TaxRate): Dino =>\n subtract(amountWithTax, getTaxFromFinalAmount(amountWithTax, taxRate));\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","options","storesWithPerItemTaxRate","has","storeId","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","amountWithTax","subtract","getTaxFromFinalAmount","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","dinero","amount","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert"],"mappings":";;;;;;AA0BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAAA,KAIY;EACV,OAAOC,wBAAA,CAAyBC,GAAA,CAAIF,OAAA,CAAQG,OAAO,CAAA,GAC/CC,0BAAA,CAA2BN,WAAA,EAAaC,OAAA,EAASC,OAAO,CAAA,GACxDK,4BAAA,CAA6BP,WAAA,EAAaC,SAASC,OAAO,CAAA;AAChE,CAAA;AAEO,MAAMM,eAAA,GAAkBA,CAAC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CAAyBC,UAAU,IAAI,CAAA;EAC3E0B,MAAA,CAAOD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EAC/CC,MAAA,CAAOD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EACjD,OAAOA,MAAA;AACT,CAAA;"}
1
+ {"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n dinero,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n toSnapshot,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n Round,\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n} from \"./tax.private\";\nimport type { Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n storeId,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n storeId: StoreId;\n}) => {\n return storesWithPerItemTaxRate.has(storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate);\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dino,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n\n // Calculate the tax amount and apply rounding on it so that behavior for reverse process is consistent\n const taxAmount = Round.Financial(\n snapshot.amount - snapshot.amount / (1 + taxRate),\n );\n\n return dinero({\n ...snapshot,\n amount: snapshot.amount - taxAmount,\n });\n};\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","storeId","storesWithPerItemTaxRate","has","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","taxAmount","Round","Financial","amount","dinero","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert"],"mappings":";;;;;;AA0BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAAA,KAIM;EACJ,OAAOC,wBAAA,CAAyBC,GAAA,CAAIF,OAAO,CAAA,GACvCG,0BAAA,CAA2BL,aAAaC,OAAO,CAAA,GAC/CK,4BAAA,CAA6BN,WAAA,EAAaC,OAAO,CAAA;AACvD,CAAA;AAEO,MAAMM,eAAA,GAAkBA,CAC7BC,oBAAA,EACAP,OAAA,KACG;EACH,MAAMQ,QAAA,GAAWC,WAAWF,oBAAoB,CAAA;EAGhD,MAAMG,YAAYC,KAAA,CAAMC,SAAA,CACtBJ,QAAA,CAASK,MAAA,GAASL,QAAA,CAASK,MAAA,IAAU,CAAA,GAAIb,OAAA,CAAA,CAC3C;EAEA,OAAOc,MAAA,CAAO;IACZ,GAAGN,QAAA;IACHK,MAAA,EAAQL,SAASK,MAAA,GAASH;EAAA,CAC3B,CAAA;AACH,CAAA;AAWO,MAAMK,iCAAA,GACXf,OAAA,IACW;EACX,MAAMgB,SAAA,GAAYC,uBAAuBjB,OAAO,CAAA;EAChD,MAAMkB,CAAA,GAAIC,QAAA,CAASH,SAAA,EAAW,GAAG,CAAA;EACjC,OAAOI,OAAOF,CAAA,EAAG;IACfG,QAAQC,wBAAA,CAAyBC,QAAA;IACjCC,KAAA,EAAOC;EAAA,CACR,CAAA;AACH,CAAA;AAEO,MAAMR,sBAAA,GAA0BjB,OAAA,IAAmC;EACxE,MAAM0B,eACJ,OAAO1B,OAAA,KAAY,WAAWA,OAAA,GAAU2B,MAAA,CAAOC,WAAW5B,OAAO,CAAA;EACnE6B,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAA,CAAOI,QAAA,CAAA,CAE3BL,YAAA,GACAM,KAAKC,GAAA,CAAIX,wBAAA,CAAyBY,MAAMZ,wBAAA,CAAyBC,QAAQ,CAAA,EACzEY,OAAA,CAAQ,CAAC,CAAA,CACb;EACA,OAAOrB,MAAA,CAAO;IACZD,MAAA,EAAQiB,eAAA;IACRM,QAAA,EAAUd;EAAA,CACX,CAAA;AACH,CAAA;AAWO,MAAMe,oBAAA,GACXrC,OAAA,IACiB;EACjB,OAAO,GAAGe,iCAAA,CAAkCf,OAAO,CAAC,GAAA;AACtD,CAAA;AAEO,MAAMsC,oBAAA,GAAwBC,IAAA,IACnCC,WAAA,CAAY,CAACD,IAAA,EAAMjB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;AAMrD,MAAMkB,qBAAA,GAAyBC,KAAA,IAA4B;EAChE,MAAMC,OAAA,GAAUD,MAAME,MAAA,CAAO,CAACC,KAAKN,IAAA,KAASM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAA,GAASN,WAAA,CAAYG,OAAA,EAASrB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EAC3EwB,MAAA,CAAOD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EAC/CC,MAAA,CAAOD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EACjD,OAAOA,MAAA;AACT,CAAA;"}
@@ -4,10 +4,5 @@ import type { Dino, LineItemSummary, SingleLineItemSummary, TaxRate } from "./ty
4
4
  * rate calculations
5
5
  */
6
6
  export declare const allocatePerItemTaxableAmount: (itemSummary: LineItemSummary) => SingleLineItemSummary[];
7
- export declare const getTaxFromFinalAmount: (amountWithTax: Dino, taxRate: TaxRate) => import("dinero.js").Dinero<number>;
8
- export declare const calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate, options: {
9
- hasTaxIncludedPrice: boolean;
10
- }) => Dino;
11
- export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate, options: {
12
- hasTaxIncludedPrice: boolean;
13
- }) => Dino;
7
+ export declare const calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dino;
8
+ export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dino;
@@ -29,37 +29,23 @@ const allocatePerItemTaxableAmount = itemSummary => {
29
29
  };
30
30
  });
31
31
  };
32
- const calculateTaxOnTaxableAmount = (itemSummary, taxRate) => {
32
+ const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
33
+ if (taxRate === 0) {
34
+ return misc.getDinero(0, itemSummary.currency);
35
+ }
33
36
  return dinero_js.dinero({
34
37
  amount: constants.Round.Financial(itemSummary.taxableAmount * taxRate),
35
38
  currency: misc.getDineroCurrency(itemSummary.currency)
36
39
  });
37
40
  };
38
- const getTaxFromFinalAmount = (amountWithTax, taxRate) => {
39
- const snapshot = dinero_js.toSnapshot(amountWithTax);
40
- const taxAmount = constants.Round.Financial(snapshot.amount - snapshot.amount / (1 + taxRate));
41
- return dinero_js.dinero({
42
- ...snapshot,
43
- amount: taxAmount
44
- });
45
- };
46
- const calculateTaxFromTaxIncludedPrice = (itemSummary, taxRate) => {
47
- return getTaxFromFinalAmount(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRate);
48
- };
49
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate, options) => {
50
- if (taxRate === 0) {
51
- return misc.getDinero(0, itemSummary.currency);
52
- }
53
- return options.hasTaxIncludedPrice ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate) : calculateTaxOnTaxableAmount(itemSummary, taxRate);
54
- };
55
- const calculatePerQtyLineItemTax = (itemSummary, taxRate, options) => {
41
+ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
56
42
  if (taxRate === 0) {
57
43
  return misc.getDinero(0, itemSummary.currency);
58
44
  }
59
45
  const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
60
46
  let totalTaxAmount = misc.getDinero(0, itemSummary.currency);
61
47
  singleItemSummaries.forEach(itemSummary2 => {
62
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate, options);
48
+ const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
63
49
  totalTaxAmount = dinero_js.add(totalTaxAmount, taxAmount);
64
50
  });
65
51
  return totalTaxAmount;
@@ -67,5 +53,4 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate, options) => {
67
53
  exports.allocatePerItemTaxableAmount = allocatePerItemTaxableAmount;
68
54
  exports.calculatePerQtyLineItemTax = calculatePerQtyLineItemTax;
69
55
  exports.calculateWholeQtyLineItemTax = calculateWholeQtyLineItemTax;
70
- exports.getTaxFromFinalAmount = getTaxFromFinalAmount;
71
56
  //# sourceMappingURL=tax.private.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport { add, dinero, subtract, toSnapshot } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Dino,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nconst calculateTaxOnTaxableAmount = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n) => {\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const getTaxFromFinalAmount = (\n amountWithTax: Dino,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(amountWithTax);\n\n // Calculate the tax amount and apply rounding on it so that behavior for reverse process is consistent\n const taxAmount = Round.Financial(\n snapshot.amount - snapshot.amount / (1 + taxRate),\n );\n\n return dinero({ ...snapshot, amount: taxAmount });\n};\n\nconst calculateTaxFromTaxIncludedPrice = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n) => {\n return getTaxFromFinalAmount(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRate,\n );\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n options: { hasTaxIncludedPrice: boolean },\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n return options.hasTaxIncludedPrice\n ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate)\n : calculateTaxOnTaxableAmount(itemSummary, taxRate);\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n options: { hasTaxIncludedPrice: boolean },\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(\n itemSummary,\n taxRate,\n options,\n );\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateTaxOnTaxableAmount","taxRate","dinero","Round","Financial","getDineroCurrency","getTaxFromFinalAmount","amountWithTax","snapshot","toSnapshot","taxAmount","calculateTaxFromTaxIncludedPrice","calculateWholeQtyLineItemTax","options","hasTaxIncludedPrice","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;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AA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtD8B,mBAAA,CAAoBE,OAAA,CAAStC,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYE,4BAAA,CAChBhC,YAAAA,EACAqB,OAAA,EACAY,OAAA,CACF;IACAI,cAAA,GAAiBlC,SAAAA,CAAAA,GAAA,CAAIkC,gBAAgBP,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOO,cAAA;AACT,CAAA;;;;"}
1
+ {"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport { add, dinero, subtract } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Dino,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxRate","dinero","Round","Financial","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount"],"mappings":";;;;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,I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EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAMA,OAAOgB,gBAAA,CAAO;IACZV,MAAA,EAAQW,SAAAA,CAAAA,KAAA,CAAMC,SAAA,CAAUxB,WAAA,CAAYK,gBAAgBgB,OAAO,CAAA;IAC3Df,QAAA,EAAUmB,IAAAA,CAAAA,iBAAA,CAAkBzB,WAAA,CAAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEO,MAAMoB,0BAAA,GAA6BA,CACxC1B,WAAA,EACAqB,OAAA,KACS;EAET,IAAIA,YAAY,CAAA,EAAG;IACjB,OAAOjB,cAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGA,MAAMqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAA,GAAiBxB,IAAAA,CAAAA,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtDqB,mBAAA,CAAoBE,OAAA,CAAS7B,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYV,4BAAA,CAA6BpB,YAAAA,EAAaqB,OAAO,CAAA;IACnEO,cAAA,GAAiBzB,SAAAA,CAAAA,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOF,cAAA;AACT,CAAA;;;"}
@@ -1,4 +1,4 @@
1
- import { add, subtract, dinero, toSnapshot } from 'dinero.js';
1
+ import { add, subtract, dinero } from 'dinero.js';
2
2
  import { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
3
3
  import { Round } from './constants.mjs';
4
4
  import { getDinero, amount, getDineroCurrency } from './misc.mjs';
@@ -27,40 +27,26 @@ const allocatePerItemTaxableAmount = itemSummary => {
27
27
  };
28
28
  });
29
29
  };
30
- const calculateTaxOnTaxableAmount = (itemSummary, taxRate) => {
30
+ const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
31
+ if (taxRate === 0) {
32
+ return getDinero(0, itemSummary.currency);
33
+ }
31
34
  return dinero({
32
35
  amount: Round.Financial(itemSummary.taxableAmount * taxRate),
33
36
  currency: getDineroCurrency(itemSummary.currency)
34
37
  });
35
38
  };
36
- const getTaxFromFinalAmount = (amountWithTax, taxRate) => {
37
- const snapshot = toSnapshot(amountWithTax);
38
- const taxAmount = Round.Financial(snapshot.amount - snapshot.amount / (1 + taxRate));
39
- return dinero({
40
- ...snapshot,
41
- amount: taxAmount
42
- });
43
- };
44
- const calculateTaxFromTaxIncludedPrice = (itemSummary, taxRate) => {
45
- return getTaxFromFinalAmount(getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRate);
46
- };
47
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate, options) => {
48
- if (taxRate === 0) {
49
- return getDinero(0, itemSummary.currency);
50
- }
51
- return options.hasTaxIncludedPrice ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate) : calculateTaxOnTaxableAmount(itemSummary, taxRate);
52
- };
53
- const calculatePerQtyLineItemTax = (itemSummary, taxRate, options) => {
39
+ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
54
40
  if (taxRate === 0) {
55
41
  return getDinero(0, itemSummary.currency);
56
42
  }
57
43
  const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
58
44
  let totalTaxAmount = getDinero(0, itemSummary.currency);
59
45
  singleItemSummaries.forEach(itemSummary2 => {
60
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate, options);
46
+ const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
61
47
  totalTaxAmount = add(totalTaxAmount, taxAmount);
62
48
  });
63
49
  return totalTaxAmount;
64
50
  };
65
- export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, getTaxFromFinalAmount };
51
+ export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax };
66
52
  //# sourceMappingURL=tax.private.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport { add, dinero, subtract, toSnapshot } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Dino,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nconst calculateTaxOnTaxableAmount = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n) => {\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const getTaxFromFinalAmount = (\n amountWithTax: Dino,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(amountWithTax);\n\n // Calculate the tax amount and apply rounding on it so that behavior for reverse process is consistent\n const taxAmount = Round.Financial(\n snapshot.amount - snapshot.amount / (1 + taxRate),\n );\n\n return dinero({ ...snapshot, amount: taxAmount });\n};\n\nconst calculateTaxFromTaxIncludedPrice = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n) => {\n return getTaxFromFinalAmount(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRate,\n );\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n options: { hasTaxIncludedPrice: boolean },\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n return options.hasTaxIncludedPrice\n ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate)\n : calculateTaxOnTaxableAmount(itemSummary, taxRate);\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n options: { hasTaxIncludedPrice: boolean },\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(\n itemSummary,\n taxRate,\n options,\n );\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateTaxOnTaxableAmount","taxRate","dinero","Round","Financial","getDineroCurrency","getTaxFromFinalAmount","amountWithTax","snapshot","toSnapshot","taxAmount","calculateTaxFromTaxIncludedPrice","calculateWholeQtyLineItemTax","options","hasTaxIncludedPrice","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAA,GAAoBC,GAAA,CACxBC,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,SAAA,CAAUJ,WAAA,CAAYO,cAAA,EAAgBP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEA,MAAME,SAAA,GAAY,IAAIC,oBAAA,CAAqB;IACzCC,uBAAuBV,WAAA,CAAYO,cAAA;IACnCI,kBAAA,EAAoBC,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAA,CAAYM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAA,CAAK;IAAEC,QAAQf,WAAA,CAAYC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAA,CAAUS,QAAA,CACxCjB,WAAA,CAAYkB,SAAA,EACZlB,WAAA,CAAYM,QAAA,CACd;IAEA,MAAMD,aAAA,GAAgBc,QAAA,CACpBf,SAAA,CAAUJ,WAAA,CAAYkB,SAAA,EAAWlB,WAAA,CAAYM,QAAQ,CAAA,EACrDU,uBAAA,CACF;IAEA,OAAO;MACLE,WAAWlB,WAAA,CAAYkB,SAAA;MACvBb,aAAA,EAAeO,OAAOP,aAAa,C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AMc,0BAAA,GAA6BA,CACxCnC,WAAA,EACAqB,OAAA,EACAY,OAAA,KACS;EAET,IAAIZ,YAAY,CAAA,EAAG;IACjB,OAAOjB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGA,MAAM8B,mBAAA,GAAsBrC,6BAA6BC,WAAW,CAAA;EAGpE,IAAIqC,cAAA,GAAiBjC,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtD8B,mBAAA,CAAoBE,OAAA,CAAStC,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYE,4BAAA,CAChBhC,YAAAA,EACAqB,OAAA,EACAY,OAAA,CACF;IACAI,cAAA,GAAiBlC,GAAA,CAAIkC,gBAAgBP,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOO,cAAA;AACT,CAAA;"}
1
+ {"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport { add, dinero, subtract } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Dino,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxRate","dinero","Round","Financial","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount"],"mappings":";;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAA,GAAoBC,GAAA,CACxBC,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,SAAA,CAAUJ,WAAA,CAAYO,cAAA,EAAgBP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEA,MAAME,SAAA,GAAY,IAAIC,oBAAA,CAAqB;IACzCC,uBAAuBV,WAAA,CAAYO,cAAA;IACnCI,kBAAA,EAAoBC,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAA,CAAYM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAA,CAAK;IAAEC,QAAQf,WAAA,CAAYC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAA,CAAUS,QAAA,CACxCjB,WAAA,CAAYkB,SAAA,EACZlB,WAAA,CAAYM,QAAA,CACd;IAEA,MAAMD,aAAA,GAAgBc,QAAA,CACpBf,SAAA,CAAUJ,WAAA,CAAYkB,SAAA,EAAWlB,WAAA,CAAYM,QAAQ,CAAA,EACrDU,uBAAA,CACF;IAEA,OAAO;MACLE,WAAWlB,WAAA,CAAYkB,SAAA;MACvBb,aAAA,EAAeO,OAAOP,aAAa,CAAA;MACnCE,cAAA,EAAgBK,OAAOI,uBAAuB,CAAA;MAC9CV,UAAUN,WAAA,CAAYM,QAAA;MACtBL,QAAA,EAAU;IAAA,CACZ;EACF,CAAC,CAAA;AACH,CAAA;AAEO,MAAMmB,4BAAA,GAA+BA,CAC1CpB,WAAA,EACAqB,OAAA,KACS;EAET,IAAIA,YAAY,CAAA,EAAG;IACjB,OAAOjB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAMA,OAAOgB,MAAA,CAAO;IACZV,MAAA,EAAQW,KAAA,CAAMC,SAAA,CAAUxB,WAAA,CAAYK,gBAAgBgB,OAAO,CAAA;IAC3Df,QAAA,EAAUmB,iBAAA,CAAkBzB,WAAA,CAAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEO,MAAMoB,0BAAA,GAA6BA,CACxC1B,WAAA,EACAqB,OAAA,KACS;EAET,IAAIA,YAAY,CAAA,EAAG;IACjB,OAAOjB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGA,MAAMqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAA,GAAiBxB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtDqB,mBAAA,CAAoBE,OAAA,CAAS7B,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYV,4BAAA,CAA6BpB,YAAAA,EAAaqB,OAAO,CAAA;IACnEO,cAAA,GAAiBzB,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOF,cAAA;AACT,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "11.29.0-custom-tax.0",
3
+ "version": "11.29.0",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="48" height="38" fill="none" viewBox="0 0 48 38"><path fill="#8e8e8e" fill-rule="evenodd" d="M16.685 0a8.48 8.48 0 0 0-8.482 8.482v18.766c.226.012.513.025.874.038 1.318.047 3.627.094 7.584.094 2.66 0 4.576-.02 5.946-.049v-7.013c0-2.34.983-4.444 2.56-5.95V8.482A8.48 8.48 0 0 0 16.686 0m-.024 27.684c2.658 0 4.573-.022 5.946-.05v4.764c0 2.096.993 3.952 2.534 5.158-.219.06-1.863.444-8.456.444-7.157 0-8.482-.452-8.482-.452V27.55a51 51 0 0 0 .863.037c.842.03 2.084.06 3.895.079a364 364 0 0 0 3.7.017m.016-26.331A6.986 6.986 0 0 0 9.69 8.339v2.248a6.16 6.16 0 0 0 6.158 6.158h1.658a6.157 6.157 0 0 0 6.157-6.158V8.34a6.987 6.987 0 0 0-6.986-6.986m3.627 7.759a3.627 3.627 0 1 1-7.254 0 3.627 3.627 0 0 1 7.254 0m-1.924 0a1.703 1.703 0 1 1-3.406 0 1.703 1.703 0 0 1 3.406 0m-1.55 4.633a.216.216 0 0 1-.37-.155.217.217 0 1 1 .37.155m-.153-8.832a.216.216 0 0 0 .197-.307.217.217 0 1 0-.197.307m6.93 15.405c0-4.042 3.358-7.318 7.5-7.318s7.5 3.276 7.5 7.318v12.08c0 3.094-2.57 5.602-5.742 5.602H29.35c-3.171 0-5.742-2.508-5.742-5.602zm3.167.166c0-2.335 1.94-4.228 4.333-4.228s4.333 1.893 4.333 4.228v3.94c0 2.334-1.94 4.227-4.333 4.227s-4.333-1.893-4.333-4.228zm4.333 11.844a.284.284 0 0 0-.287.28v2.153c0 .155.128.28.287.28a.284.284 0 0 0 .287-.28v-2.153a.284.284 0 0 0-.287-.28m2.673-11.852c0 1.44-1.197 2.608-2.673 2.608-1.477 0-2.674-1.168-2.674-2.608s1.197-2.609 2.674-2.609 2.673 1.168 2.673 2.609" clip-rule="evenodd"/></svg>
@@ -1,39 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var React = require('react');
5
- var Checkbox_styles = require('./Checkbox.styles.js');
6
- "use strict";
7
- const Checkbox = function Checkbox2({
8
- radio,
9
- ...props
10
- }) {
11
- const [isSsr, setIsSsr] = React.useState(true);
12
- React.useEffect(() => {
13
- setIsSsr(false);
14
- }, []);
15
- const onRadioClick = React.useCallback(e => {
16
- const checked = Boolean(props.checked);
17
- if (checked) {
18
- props.onChange?.(
19
- // HACK ui-components sends input change event, although the click event type-wise says it's a div
20
- e);
21
- }
22
- }, [props]);
23
- if (isSsr) {
24
- return /* @__PURE__ */jsxRuntime.jsx(Checkbox_styles.PlaceholderCheckbox, {});
25
- }
26
- return radio ? /* @__PURE__ */jsxRuntime.jsx(Checkbox_styles.StyledRadio, {
27
- variant: "primary",
28
- ...props,
29
- checked: typeof props.checked === "boolean" ? props.checked : void 0,
30
- value: typeof props.value === "string" || typeof props.value === "number" ? props.value : void 0,
31
- id: props.name,
32
- onClick: onRadioClick
33
- }) : /* @__PURE__ */jsxRuntime.jsx(Checkbox_styles.StyledCheckbox, {
34
- ...props,
35
- id: props.name
36
- });
37
- };
38
- exports.Checkbox = Checkbox;
39
- //# sourceMappingURL=Checkbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Checkbox.js","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import type { ChangeEvent, MouseEvent } from \"react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport * as S from \"./Checkbox.styles\";\nimport type { CheckboxProps } from \"./Checkbox.types\";\n\nexport const Checkbox = function Checkbox({ radio, ...props }: CheckboxProps) {\n // #############################################################################\n // SSR first render handling\n // #############################################################################\n const [isSsr, setIsSsr] = useState(true);\n\n useEffect(() => {\n setIsSsr(false);\n }, []);\n\n // #############################################################################\n // Radio handling\n // #############################################################################\n const onRadioClick = useCallback(\n (e: MouseEvent<HTMLDivElement>) => {\n const checked = Boolean(props.checked);\n\n if (checked) {\n // Send the change event\n props.onChange?.(\n // HACK ui-components sends input change event, although the click event type-wise says it's a div\n e as unknown as ChangeEvent<HTMLInputElement>,\n );\n }\n },\n [props],\n );\n\n // #############################################################################\n // Render\n // #############################################################################\n if (isSsr) {\n return <S.PlaceholderCheckbox />;\n }\n\n return radio ? (\n <S.StyledRadio\n variant=\"primary\"\n {...props}\n // Radio button does not have \"mixed\" state\n checked={typeof props.checked === \"boolean\" ? props.checked : undefined}\n // Radio button does not support \"readonly string[]\" value\n value={\n typeof props.value === \"string\" || typeof props.value === \"number\"\n ? props.value\n : undefined\n }\n id={props.name}\n onClick={onRadioClick}\n />\n ) : (\n <S.StyledCheckbox {...props} id={props.name} />\n );\n};\n"],"names":["Checkbox","radio","props","isSsr","setIsSsr","useState","useEffect","onRadioClick","useCallback","e","checked","Boolean","onChange","jsx","S.PlaceholderCheckbox","S.StyledRadio","variant","value","id","name","onClick","S.StyledCheckbox"],"mappings":";;;;;;AAMO,MAAMA,WAAW,SAASA,SAAAA,CAAS;EAAEC,KAAA;EAAO,GAAGC;CAAM,EAAkB;EAI5E,MAAM,CAACC,KAAA,EAAOC,QAAQ,CAAA,GAAIC,KAAAA,CAAAA,SAAS,IAAI,CAAA;EAEvCC,KAAAA,CAAAA,SAAA,CAAU,MAAM;IACdF,QAAA,CAAS,KAAK,CAAA;EAChB,CAAA,EAAG,EAAE,CAAA;EAKL,MAAMG,YAAA,GAAeC,KAAAA,CAAAA,WAAA,CAClBC,CAAA,IAAkC;IACjC,MAAMC,OAAA,GAAUC,OAAA,CAAQT,KAAA,CAAMQ,OAAO,CAAA;IAErC,IAAIA,OAAA,EAAS;MAEXR,KAAA,CAAMU,QAAA;MAAA;MAEJH,CAAA,CACF;IACF;EACF,CAAA,EACA,CAACP,KAAK,CAAA,CACR;EAKA,IAAIC,KAAA,EAAO;IACT,sBAAOU,UAAAA,CAAAA,GAAA,CAACC,eAAAA,CAAAA,mBAAE,EAAF,EAAsB,CAAA;EAChC;EAEA,OAAOb,KAAA,GAAA,eACLY,UAAAA,CAAAA,GAAA,CAACE,eAAAA,CAAAA,WAAE,EAAF;IACCC,OAAA,EAAQ,SAAA;IACP,GAAGd,KAAA;IAEJQ,SAAS,OAAOR,KAAA,CAAMQ,OAAA,KAAY,SAAA,GAAYR,MAAMQ,OAAA,GAAU,KAAA,CAAA;IAE9DO,KAAA,EACE,OAAOf,KAAA,CAAMe,KAAA,KAAU,QAAA,IAAY,OAAOf,KAAA,CAAMe,KAAA,KAAU,QAAA,GACtDf,KAAA,CAAMe,KAAA,GACN,KAAA,CAAA;IAENC,IAAIhB,KAAA,CAAMiB,IAAA;IACVC,OAAA,EAASb;EAAA,CAAA,CACX,GAAA,8BAECc,eAAAA,CAAAA,cAAE,EAAF;IAAkB,GAAGnB,KAAA;IAAOgB,EAAA,EAAIhB,KAAA,CAAMiB;GAAM,CAAA;AAEjD,CAAA;"}
@@ -1,37 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useState, useEffect, useCallback } from 'react';
3
- import { PlaceholderCheckbox, StyledRadio, StyledCheckbox } from './Checkbox.styles.mjs';
4
- "use strict";
5
- const Checkbox = function Checkbox2({
6
- radio,
7
- ...props
8
- }) {
9
- const [isSsr, setIsSsr] = useState(true);
10
- useEffect(() => {
11
- setIsSsr(false);
12
- }, []);
13
- const onRadioClick = useCallback(e => {
14
- const checked = Boolean(props.checked);
15
- if (checked) {
16
- props.onChange?.(
17
- // HACK ui-components sends input change event, although the click event type-wise says it's a div
18
- e);
19
- }
20
- }, [props]);
21
- if (isSsr) {
22
- return /* @__PURE__ */jsx(PlaceholderCheckbox, {});
23
- }
24
- return radio ? /* @__PURE__ */jsx(StyledRadio, {
25
- variant: "primary",
26
- ...props,
27
- checked: typeof props.checked === "boolean" ? props.checked : void 0,
28
- value: typeof props.value === "string" || typeof props.value === "number" ? props.value : void 0,
29
- id: props.name,
30
- onClick: onRadioClick
31
- }) : /* @__PURE__ */jsx(StyledCheckbox, {
32
- ...props,
33
- id: props.name
34
- });
35
- };
36
- export { Checkbox };
37
- //# sourceMappingURL=Checkbox.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Checkbox.mjs","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import type { ChangeEvent, MouseEvent } from \"react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport * as S from \"./Checkbox.styles\";\nimport type { CheckboxProps } from \"./Checkbox.types\";\n\nexport const Checkbox = function Checkbox({ radio, ...props }: CheckboxProps) {\n // #############################################################################\n // SSR first render handling\n // #############################################################################\n const [isSsr, setIsSsr] = useState(true);\n\n useEffect(() => {\n setIsSsr(false);\n }, []);\n\n // #############################################################################\n // Radio handling\n // #############################################################################\n const onRadioClick = useCallback(\n (e: MouseEvent<HTMLDivElement>) => {\n const checked = Boolean(props.checked);\n\n if (checked) {\n // Send the change event\n props.onChange?.(\n // HACK ui-components sends input change event, although the click event type-wise says it's a div\n e as unknown as ChangeEvent<HTMLInputElement>,\n );\n }\n },\n [props],\n );\n\n // #############################################################################\n // Render\n // #############################################################################\n if (isSsr) {\n return <S.PlaceholderCheckbox />;\n }\n\n return radio ? (\n <S.StyledRadio\n variant=\"primary\"\n {...props}\n // Radio button does not have \"mixed\" state\n checked={typeof props.checked === \"boolean\" ? props.checked : undefined}\n // Radio button does not support \"readonly string[]\" value\n value={\n typeof props.value === \"string\" || typeof props.value === \"number\"\n ? props.value\n : undefined\n }\n id={props.name}\n onClick={onRadioClick}\n />\n ) : (\n <S.StyledCheckbox {...props} id={props.name} />\n );\n};\n"],"names":["Checkbox","radio","props","isSsr","setIsSsr","useState","useEffect","onRadioClick","useCallback","e","checked","Boolean","onChange","jsx","S.PlaceholderCheckbox","S.StyledRadio","variant","value","id","name","onClick","S.StyledCheckbox"],"mappings":";;;;AAMO,MAAMA,WAAW,SAASA,SAAAA,CAAS;EAAEC,KAAA;EAAO,GAAGC;CAAM,EAAkB;EAI5E,MAAM,CAACC,KAAA,EAAOC,QAAQ,CAAA,GAAIC,SAAS,IAAI,CAAA;EAEvCC,SAAA,CAAU,MAAM;IACdF,QAAA,CAAS,KAAK,CAAA;EAChB,CAAA,EAAG,EAAE,CAAA;EAKL,MAAMG,YAAA,GAAeC,WAAA,CAClBC,CAAA,IAAkC;IACjC,MAAMC,OAAA,GAAUC,OAAA,CAAQT,KAAA,CAAMQ,OAAO,CAAA;IAErC,IAAIA,OAAA,EAAS;MAEXR,KAAA,CAAMU,QAAA;MAAA;MAEJH,CAAA,CACF;IACF;EACF,CAAA,EACA,CAACP,KAAK,CAAA,CACR;EAKA,IAAIC,KAAA,EAAO;IACT,sBAAOU,GAAA,CAACC,mBAAE,EAAF,EAAsB,CAAA;EAChC;EAEA,OAAOb,KAAA,GAAA,eACLY,GAAA,CAACE,WAAE,EAAF;IACCC,OAAA,EAAQ,SAAA;IACP,GAAGd,KAAA;IAEJQ,SAAS,OAAOR,KAAA,CAAMQ,OAAA,KAAY,SAAA,GAAYR,MAAMQ,OAAA,GAAU,KAAA,CAAA;IAE9DO,KAAA,EACE,OAAOf,KAAA,CAAMe,KAAA,KAAU,QAAA,IAAY,OAAOf,KAAA,CAAMe,KAAA,KAAU,QAAA,GACtDf,KAAA,CAAMe,KAAA,GACN,KAAA,CAAA;IAENC,IAAIhB,KAAA,CAAMiB,IAAA;IACVC,OAAA,EAASb;EAAA,CAAA,CACX,GAAA,mBAECc,cAAE,EAAF;IAAkB,GAAGnB,KAAA;IAAOgB,EAAA,EAAIhB,KAAA,CAAMiB;GAAM,CAAA;AAEjD,CAAA;"}
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- var Checkbox = require('@ubnt/ui-components/Checkbox');
4
- var Radio = require('@ubnt/ui-components/Radio');
5
- var styledComponents = require('styled-components');
6
- "use strict";
7
- const PlaceholderCheckbox = styledComponents.styled.div`
8
- width: 16px;
9
- height: 16px;
10
- border-radius: 4px;
11
- border: 1px solid #dbdce1;
12
- `;
13
- const StyledRadio = styledComponents.styled(Radio.Radio)`
14
- * {
15
- margin: 0 !important;
16
- }
17
-
18
- input {
19
- ${({
20
- disabled,
21
- checked
22
- }) => checked ? styledComponents.css`
23
- border: 1px solid ${disabled ? "#cce2ff" : "#006fff"} !important;
24
- ` : styledComponents.css`
25
- border: 1px solid #b6b9c4 !important;
26
- `}
27
- }
28
- `;
29
- const StyledCheckbox = styledComponents.styled(Checkbox.Checkbox)`
30
- * {
31
- margin: 0 !important;
32
- }
33
-
34
- input {
35
- ${({
36
- disabled,
37
- checked
38
- }) => checked ? styledComponents.css`
39
- border: none !important;
40
- ` : styledComponents.css`
41
- border-color: ${disabled ? "#DBDCE1" : "#B6B9C4"} !important;
42
- `};
43
- }
44
- `;
45
- exports.PlaceholderCheckbox = PlaceholderCheckbox;
46
- exports.StyledCheckbox = StyledCheckbox;
47
- exports.StyledRadio = StyledRadio;
48
- //# sourceMappingURL=Checkbox.styles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Checkbox.styles.js","sources":["../../../src/components/Checkbox/Checkbox.styles.ts"],"sourcesContent":["import { Checkbox } from \"@ubnt/ui-components/Checkbox\";\nimport { Radio } from \"@ubnt/ui-components/Radio\";\nimport { css, styled } from \"styled-components\";\n\nexport const PlaceholderCheckbox = styled.div`\n width: 16px;\n height: 16px;\n border-radius: 4px;\n border: 1px solid #dbdce1;\n`;\n\nexport const StyledRadio = styled(Radio)`\n * {\n margin: 0 !important;\n }\n\n input {\n ${({ disabled, checked }) =>\n checked\n ? css`\n border: 1px solid ${disabled ? \"#cce2ff\" : \"#006fff\"} !important;\n `\n : css`\n border: 1px solid #b6b9c4 !important;\n `}\n }\n`;\n\nexport const StyledCheckbox = styled(Checkbox)`\n * {\n margin: 0 !important;\n }\n\n input {\n ${({ disabled, checked }) =>\n checked\n ? css`\n border: none !important;\n `\n : css`\n border-color: ${disabled ? \"#DBDCE1\" : \"#B6B9C4\"} !important;\n `};\n }\n`;\n"],"names":["PlaceholderCheckbox","styled","div","StyledRadio","Radio","disabled","checked","css","StyledCheckbox","Checkbox"],"mappings":";;;;;;AAIO,MAAMA,sBAAsBC,gBAAAA,CAAAA,MAAA,CAAOC,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AAOnC,MAAMC,WAAA,GAAcF,gBAAAA,CAAAA,OAAOG,WAAK,CAAA;AAAA;AAAA;AAAA;;AAAA;AAAA,MAMjC,CAAC;EAAEC,QAAA;EAAUC;AAAA,MACbA,OAAA,GACIC,gBAAAA,CAAAA,GAAA;AAAA,gCACsBF,QAAA,GAAW,YAAY,SAAS;AAAA,WAAA,GAEtDE,gBAAAA,CAAAA,GAAA;AAAA;AAAA,WAEC;AAAA;AAAA,CAAA;AAIJ,MAAMC,cAAA,GAAiBP,gBAAAA,CAAAA,OAAOQ,iBAAQ,CAAA;AAAA;AAAA;AAAA;;AAAA;AAAA,MAMvC,CAAC;EAAEJ,QAAA;EAAUC;AAAA,MACbA,OAAA,GACIC,gBAAAA,CAAAA,GAAA;AAAA;AAAA,WAAA,GAGAA,gBAAAA,CAAAA,GAAA;AAAA,4BACkBF,QAAA,GAAW,YAAY,SAAS;AAAA,WACjD;AAAA;AAAA,CAAA;;;"}
@@ -1,44 +0,0 @@
1
- import { Checkbox } from '@ubnt/ui-components/Checkbox';
2
- import { Radio } from '@ubnt/ui-components/Radio';
3
- import { styled, css } from 'styled-components';
4
- "use strict";
5
- const PlaceholderCheckbox = styled.div`
6
- width: 16px;
7
- height: 16px;
8
- border-radius: 4px;
9
- border: 1px solid #dbdce1;
10
- `;
11
- const StyledRadio = styled(Radio)`
12
- * {
13
- margin: 0 !important;
14
- }
15
-
16
- input {
17
- ${({
18
- disabled,
19
- checked
20
- }) => checked ? css`
21
- border: 1px solid ${disabled ? "#cce2ff" : "#006fff"} !important;
22
- ` : css`
23
- border: 1px solid #b6b9c4 !important;
24
- `}
25
- }
26
- `;
27
- const StyledCheckbox = styled(Checkbox)`
28
- * {
29
- margin: 0 !important;
30
- }
31
-
32
- input {
33
- ${({
34
- disabled,
35
- checked
36
- }) => checked ? css`
37
- border: none !important;
38
- ` : css`
39
- border-color: ${disabled ? "#DBDCE1" : "#B6B9C4"} !important;
40
- `};
41
- }
42
- `;
43
- export { PlaceholderCheckbox, StyledCheckbox, StyledRadio };
44
- //# sourceMappingURL=Checkbox.styles.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Checkbox.styles.mjs","sources":["../../../src/components/Checkbox/Checkbox.styles.ts"],"sourcesContent":["import { Checkbox } from \"@ubnt/ui-components/Checkbox\";\nimport { Radio } from \"@ubnt/ui-components/Radio\";\nimport { css, styled } from \"styled-components\";\n\nexport const PlaceholderCheckbox = styled.div`\n width: 16px;\n height: 16px;\n border-radius: 4px;\n border: 1px solid #dbdce1;\n`;\n\nexport const StyledRadio = styled(Radio)`\n * {\n margin: 0 !important;\n }\n\n input {\n ${({ disabled, checked }) =>\n checked\n ? css`\n border: 1px solid ${disabled ? \"#cce2ff\" : \"#006fff\"} !important;\n `\n : css`\n border: 1px solid #b6b9c4 !important;\n `}\n }\n`;\n\nexport const StyledCheckbox = styled(Checkbox)`\n * {\n margin: 0 !important;\n }\n\n input {\n ${({ disabled, checked }) =>\n checked\n ? css`\n border: none !important;\n `\n : css`\n border-color: ${disabled ? \"#DBDCE1\" : \"#B6B9C4\"} !important;\n `};\n }\n`;\n"],"names":["PlaceholderCheckbox","styled","div","StyledRadio","Radio","disabled","checked","css","StyledCheckbox","Checkbox"],"mappings":";;;;AAIO,MAAMA,sBAAsBC,MAAA,CAAOC,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AAOnC,MAAMC,WAAA,GAAcF,OAAOG,KAAK,CAAA;AAAA;AAAA;AAAA;;AAAA;AAAA,MAMjC,CAAC;EAAEC,QAAA;EAAUC;AAAA,MACbA,OAAA,GACIC,GAAA;AAAA,gCACsBF,QAAA,GAAW,YAAY,SAAS;AAAA,WAAA,GAEtDE,GAAA;AAAA;AAAA,WAEC;AAAA;AAAA,CAAA;AAIJ,MAAMC,cAAA,GAAiBP,OAAOQ,QAAQ,CAAA;AAAA;AAAA;AAAA;;AAAA;AAAA,MAMvC,CAAC;EAAEJ,QAAA;EAAUC;AAAA,MACbA,OAAA,GACIC,GAAA;AAAA;AAAA,WAAA,GAGAA,GAAA;AAAA,4BACkBF,QAAA,GAAW,YAAY,SAAS;AAAA,WACjD;AAAA;AAAA,CAAA;"}
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var Checkbox = require('./Checkbox.js');
4
- "use strict";
5
- exports.Checkbox = Checkbox.Checkbox;
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,3 +0,0 @@
1
- export { Checkbox } from './Checkbox.mjs';
2
- "use strict";
3
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,17 +0,0 @@
1
- import type { Currency } from "../../../types";
2
- import type { Cents, Dino } from "../types";
3
- /**
4
- * Helper class to distribute a total amount across a quantity of items.
5
- */
6
- export declare class TotalAmountAllocator {
7
- #private;
8
- constructor({ amount, quantity, currency, }: {
9
- quantity: number;
10
- amount: Cents;
11
- currency: Currency;
12
- });
13
- allocate(quantity: number): {
14
- qtyAllocated: number;
15
- amount: Dino;
16
- };
17
- }
@@ -1,40 +0,0 @@
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 TotalAmountAllocator {
8
- #remainingAmount;
9
- #remainingQuantity;
10
- #currency;
11
- constructor({
12
- amount,
13
- quantity,
14
- currency
15
- }) {
16
- this.#remainingAmount = misc.getDinero(amount, currency);
17
- this.#remainingQuantity = quantity;
18
- this.#currency = currency;
19
- }
20
- allocate(quantity) {
21
- const quantityToAllocate = Math.min(quantity, this.#remainingQuantity);
22
- if (quantityToAllocate === 0) {
23
- return {
24
- qtyAllocated: 0,
25
- amount: misc.getDinero(0, this.#currency)
26
- };
27
- }
28
- const [allocated, newRemainingAmount] = dinero_js.allocate(this.#remainingAmount, [quantityToAllocate, this.#remainingQuantity - quantityToAllocate]);
29
- errors.assert(!!allocated, "Couldn't allocate amount");
30
- errors.assert(!!newRemainingAmount, "Couldn't retrieve remaining amount");
31
- this.#remainingAmount = newRemainingAmount;
32
- this.#remainingQuantity -= quantityToAllocate;
33
- return {
34
- qtyAllocated: quantityToAllocate,
35
- amount: allocated
36
- };
37
- }
38
- }
39
- exports.TotalAmountAllocator = TotalAmountAllocator;
40
- //# sourceMappingURL=totalAmount.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"totalAmount.js","sources":["../../../../src/utils/money/allocators/totalAmount.ts"],"sourcesContent":["import { allocate } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { getDinero } from \"../misc\";\nimport type { Cents, Dino } from \"../types\";\n\n/**\n * Helper class to distribute a total amount across a quantity of items.\n */\nexport class TotalAmountAllocator {\n #remainingAmount: Dino;\n #remainingQuantity: number;\n #currency: Currency;\n\n constructor({\n amount,\n quantity,\n currency,\n }: {\n quantity: number;\n amount: Cents;\n currency: Currency;\n }) {\n this.#remainingAmount = getDinero(amount, currency);\n this.#remainingQuantity = quantity;\n this.#currency = currency;\n }\n\n allocate(quantity: number): { qtyAllocated: number; amount: Dino } {\n // Normalize quantity to not exceed remaining\n const quantityToAllocate = Math.min(quantity, this.#remainingQuantity);\n\n if (quantityToAllocate === 0) {\n return { qtyAllocated: 0, amount: getDinero(0, this.#currency) };\n }\n\n const [allocated, newRemainingAmount] = allocate(this.#remainingAmount, [\n quantityToAllocate,\n this.#remainingQuantity - quantityToAllocate,\n ]);\n\n assert(!!allocated, \"Couldn't allocate amount\");\n assert(!!newRemainingAmount, \"Couldn't retrieve remaining amount\");\n\n // Update remaining amounts\n this.#remainingAmount = newRemainingAmount;\n this.#remainingQuantity -= quantityToAllocate;\n\n return { qtyAllocated: quantityToAllocate, amount: allocated };\n }\n}\n"],"names":["TotalAmountAllocator","remainingAmount","remainingQuantity","currency","constructor","amount","quantity","getDinero","allocate","quantityToAllocate","Math","min","qtyAllocated","allocated","newRemainingAmount","assert"],"mappings":";;;;;;AAUO,MAAMA,oBAAA,CAAqB;EAChC,CAAAC,eAAA;EACA,CAAAC,iBAAA;EACA,CAAAC,QAAA;EAEAC,WAAAA,CAAY;IACVC,MAAA;IACAC,QAAA;IACAH;EAAA,CACF,EAIG;IACD,IAAA,CAAK,CAAAF,eAAA,GAAmBM,cAAA,CAAUF,MAAA,EAAQF,QAAQ,CAAA;IAClD,IAAA,CAAK,CAAAD,iBAAA,GAAqBI,QAAA;IAC1B,IAAA,CAAK,CAAAH,QAAA,GAAYA,QAAA;EACnB;EAEAK,SAASF,QAAA,EAA0D;IAEjE,MAAMG,kBAAA,GAAqBC,IAAA,CAAKC,GAAA,CAAIL,QAAA,EAAU,KAAK,CAAAJ,iBAAkB,CAAA;IAErE,IAAIO,uBAAuB,CAAA,EAAG;MAC5B,OAAO;QAAEG,cAAc,CAAA;QAAGP,MAAA,EAAQE,IAAAA,CAAAA,UAAU,CAAA,EAAG,IAAA,CAAK,CAAAJ,QAAS;MAAA,CAAE;IACjE;IAEA,MAAM,CAACU,SAAA,EAAWC,kBAAkB,CAAA,GAAIN,SAAAA,CAAAA,QAAA,CAAS,KAAK,CAAAP,eAAA,EAAkB,CACtEQ,kBAAA,EACA,KAAK,CAAAP,iBAAA,GAAqBO,kBAAA,CAC3B,CAAA;IAEDM,aAAA,CAAO,CAAC,CAACF,SAAA,EAAW,0BAA0B,CAAA;IAC9CE,aAAA,CAAO,CAAC,CAACD,kBAAA,EAAoB,oCAAoC,CAAA;IAGjE,IAAA,CAAK,CAAAb,eAAA,GAAmBa,kBAAA;IACxB,IAAA,CAAK,CAAAZ,iBAAA,IAAsBO,kBAAA;IAE3B,OAAO;MAAEG,YAAA,EAAcH,kBAAA;MAAoBJ,MAAA,EAAQQ;IAAA,CAAU;EAC/D;AACF;"}