@ubnt/store.core 11.27.4 → 11.28.0-custom-tax.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 (308) hide show
  1. package/CHANGELOG.md +0 -16
  2. package/lib/_virtual/_virtual_multi-entry.js +2 -0
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +2 -0
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/ai-dome.jpg +0 -0
  7. package/lib/assets/ai-dome2.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/close.svg +1 -1
  13. package/lib/assets/close2.svg +1 -1
  14. package/lib/assets/compact.svg +1 -1
  15. package/lib/assets/compact2.svg +1 -1
  16. package/lib/assets/door-hub-mini.jpg +0 -0
  17. package/lib/assets/door-hub-mini2.jpg +0 -0
  18. package/lib/assets/door-hub.jpg +0 -0
  19. package/lib/assets/door-hub2.jpg +0 -0
  20. package/lib/assets/floodlight.svg +1 -1
  21. package/lib/assets/floodlight2.svg +1 -1
  22. package/lib/assets/g2-reader-pro.jpg +0 -0
  23. package/lib/assets/g2-reader-pro2.jpg +0 -0
  24. package/lib/assets/g2-reader.jpg +0 -0
  25. package/lib/assets/g2-reader2.jpg +0 -0
  26. package/lib/assets/g3-starter-kit-pro.jpg +0 -0
  27. package/lib/assets/g3-starter-kit-pro2.jpg +0 -0
  28. package/lib/assets/g4-instant.jpg +0 -0
  29. package/lib/assets/g4-instant2.jpg +0 -0
  30. package/lib/assets/g5-dome.jpg +0 -0
  31. package/lib/assets/g5-dome2.jpg +0 -0
  32. package/lib/assets/g5-turret-ultra.jpg +0 -0
  33. package/lib/assets/g5-turret-ultra2.jpg +0 -0
  34. package/lib/assets/globe.svg +1 -1
  35. package/lib/assets/globe2.svg +1 -1
  36. package/lib/assets/intercom.jpg +0 -0
  37. package/lib/assets/intercom2.jpg +0 -0
  38. package/lib/assets/interior-design.svg +1 -1
  39. package/lib/assets/interior-design2.svg +1 -1
  40. package/lib/assets/minus4.svg +1 -1
  41. package/lib/assets/minus5.svg +1 -1
  42. package/lib/assets/pause.svg +1 -1
  43. package/lib/assets/pause2.svg +1 -1
  44. package/lib/assets/plus4.svg +1 -1
  45. package/lib/assets/plus5.svg +1 -1
  46. package/lib/assets/power.svg +1 -1
  47. package/lib/assets/power2.svg +1 -1
  48. package/lib/assets/ptz2.svg +1 -1
  49. package/lib/assets/ptz3.svg +1 -1
  50. package/lib/assets/rack.svg +1 -1
  51. package/lib/assets/rack2.svg +1 -1
  52. package/lib/assets/ucgFiber.jpg +0 -0
  53. package/lib/assets/ucgFiber2.jpg +0 -0
  54. package/lib/components/CustomImage/CustomImage.js +1 -1
  55. package/lib/components/CustomImage/CustomImage.mjs +1 -1
  56. package/lib/components/GridGallery/GridModal/GridModal.js +1 -1
  57. package/lib/components/GridGallery/GridModal/GridModal.mjs +1 -1
  58. package/lib/components/Header/AccountMenu/AccountMenu.d.ts +1 -1
  59. package/lib/components/Header/AccountMenu/AccountMenu.js +3 -5
  60. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  61. package/lib/components/Header/AccountMenu/AccountMenu.mjs +4 -6
  62. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  63. package/lib/components/Header/AccountMenu/AccountMenu.stories.d.ts +1 -1
  64. package/lib/components/Header/AccountMenu/AccountMenu.types.d.ts +0 -5
  65. package/lib/components/Header/CartModalV2/CartModal.js +1 -1
  66. package/lib/components/Header/CartModalV2/CartModal.mjs +1 -1
  67. package/lib/components/Header/Header.js +35 -13
  68. package/lib/components/Header/Header.js.map +1 -1
  69. package/lib/components/Header/Header.mjs +33 -11
  70. package/lib/components/Header/Header.mjs.map +1 -1
  71. package/lib/components/Header/Header.styles.d.ts +1 -1
  72. package/lib/components/Header/Header.styles.js +1 -1
  73. package/lib/components/Header/Header.styles.js.map +1 -1
  74. package/lib/components/Header/Header.styles.mjs +1 -1
  75. package/lib/components/Header/Header.styles.mjs.map +1 -1
  76. package/lib/components/Header/IsolatedHeader.js +1 -2
  77. package/lib/components/Header/IsolatedHeader.js.map +1 -1
  78. package/lib/components/Header/IsolatedHeader.mjs +1 -2
  79. package/lib/components/Header/IsolatedHeader.mjs.map +1 -1
  80. package/lib/components/Header/LanguageFrame/LanguageFrame.js +1 -1
  81. package/lib/components/Header/LanguageFrame/LanguageFrame.mjs +1 -1
  82. package/lib/components/Header/LogoIcon/LogoIcon.d.ts +1 -6
  83. package/lib/components/Header/LogoIcon/LogoIcon.js +7 -26
  84. package/lib/components/Header/LogoIcon/LogoIcon.js.map +1 -1
  85. package/lib/components/Header/LogoIcon/LogoIcon.mjs +9 -27
  86. package/lib/components/Header/LogoIcon/LogoIcon.mjs.map +1 -1
  87. package/lib/components/Header/LogoIcon/index.js +0 -1
  88. package/lib/components/Header/LogoIcon/index.js.map +1 -1
  89. package/lib/components/Header/LogoIcon/index.mjs +1 -1
  90. package/lib/components/Header/ProHeader/ProHeader.js +27 -28
  91. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  92. package/lib/components/Header/ProHeader/ProHeader.mjs +4 -5
  93. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  94. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +0 -1
  95. package/lib/components/Header/ProHeader/ProHeader.styles.js +0 -2
  96. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  97. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +1 -2
  98. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  99. package/lib/components/MicrositeHeader/components/HeaderContent/HeaderContent.js +1 -1
  100. package/lib/components/MicrositeHeader/components/HeaderContent/HeaderContent.mjs +1 -1
  101. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  102. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  103. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  104. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  105. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  106. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  107. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  108. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  109. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  110. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  111. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  112. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  113. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  114. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  115. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  116. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  117. package/lib/components/Search/Input/Input.js +1 -1
  118. package/lib/components/Search/Input/Input.mjs +1 -1
  119. package/lib/components/VideoPlayerNew/VideoPlayer.js +2 -2
  120. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +2 -2
  121. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  122. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  123. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  124. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  125. package/lib/constants/icons/generic/close.svg.js +1 -1
  126. package/lib/constants/icons/generic/close.svg.mjs +2 -2
  127. package/lib/constants/icons/generic/index.js +1 -1
  128. package/lib/constants/icons/generic/index.mjs +1 -1
  129. package/lib/constants/icons/header/globe.svg.js +1 -1
  130. package/lib/constants/icons/header/globe.svg.mjs +2 -2
  131. package/lib/constants/icons/header/index.js +1 -1
  132. package/lib/constants/icons/header/index.mjs +1 -1
  133. package/lib/constants/icons/menu/floodlight.svg.js +5 -5
  134. package/lib/constants/icons/menu/floodlight.svg.mjs +2 -2
  135. package/lib/constants/icons/menu/index.js +9 -9
  136. package/lib/constants/icons/menu/index.mjs +3 -3
  137. package/lib/constants/icons/menu/power.svg.js +5 -5
  138. package/lib/constants/icons/menu/power.svg.mjs +2 -2
  139. package/lib/constants/icons/menu/rack.svg.js +5 -5
  140. package/lib/constants/icons/menu/rack.svg.mjs +2 -2
  141. package/lib/constants/modelCompareData/assets/Bullet/ai-lpr.jpg.js +1 -1
  142. package/lib/constants/modelCompareData/assets/Bullet/ai-lpr.jpg.mjs +2 -2
  143. package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.js +1 -1
  144. package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.mjs +2 -2
  145. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/ucgFiber.jpg.js +5 -5
  146. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/ucgFiber.jpg.mjs +2 -2
  147. package/lib/constants/modelCompareData/assets/Consoles/ucgFiber.jpg.js +1 -1
  148. package/lib/constants/modelCompareData/assets/Consoles/ucgFiber.jpg.mjs +2 -2
  149. package/lib/constants/modelCompareData/assets/DomeTurret/ai-dome.jpg.js +1 -1
  150. package/lib/constants/modelCompareData/assets/DomeTurret/ai-dome.jpg.mjs +2 -2
  151. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.js +1 -1
  152. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.mjs +2 -2
  153. package/lib/constants/modelCompareData/assets/DomeTurret/g5-turret-ultra.jpg.js +1 -1
  154. package/lib/constants/modelCompareData/assets/DomeTurret/g5-turret-ultra.jpg.mjs +2 -2
  155. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.js +1 -1
  156. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.mjs +2 -2
  157. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.js +1 -1
  158. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.mjs +2 -2
  159. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader-pro.jpg.js +1 -1
  160. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader-pro.jpg.mjs +2 -2
  161. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.js +1 -1
  162. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.mjs +2 -2
  163. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.js +1 -1
  164. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs +2 -2
  165. package/lib/constants/modelCompareData/assets/DoorAccess/intercom.jpg.js +1 -1
  166. package/lib/constants/modelCompareData/assets/DoorAccess/intercom.jpg.mjs +2 -2
  167. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.js +1 -1
  168. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.mjs +2 -2
  169. package/lib/constants/modelCompareData/assets/compact.svg.js +1 -1
  170. package/lib/constants/modelCompareData/assets/compact.svg.mjs +2 -2
  171. package/lib/constants/modelCompareData/assets/floodlight.svg.js +1 -1
  172. package/lib/constants/modelCompareData/assets/floodlight.svg.mjs +2 -2
  173. package/lib/constants/modelCompareData/assets/globe.svg.js +1 -1
  174. package/lib/constants/modelCompareData/assets/globe.svg.mjs +2 -2
  175. package/lib/constants/modelCompareData/assets/interior-design.svg.js +1 -1
  176. package/lib/constants/modelCompareData/assets/interior-design.svg.mjs +2 -2
  177. package/lib/constants/modelCompareData/assets/power.svg.js +1 -1
  178. package/lib/constants/modelCompareData/assets/power.svg.mjs +2 -2
  179. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-lpr.jpg.js +1 -1
  180. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-lpr.jpg.mjs +2 -2
  181. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.js +1 -1
  182. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.mjs +2 -2
  183. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-dome.jpg.js +1 -1
  184. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-dome.jpg.mjs +2 -2
  185. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.js +1 -1
  186. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.mjs +2 -2
  187. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-turret-ultra.jpg.js +1 -1
  188. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-turret-ultra.jpg.mjs +2 -2
  189. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.js +1 -1
  190. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.mjs +2 -2
  191. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.js +1 -1
  192. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.mjs +2 -2
  193. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader-pro.jpg.js +1 -1
  194. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader-pro.jpg.mjs +2 -2
  195. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.js +1 -1
  196. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.mjs +2 -2
  197. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.js +1 -1
  198. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.mjs +2 -2
  199. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/intercom.jpg.js +1 -1
  200. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/intercom.jpg.mjs +2 -2
  201. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.js +1 -1
  202. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.mjs +2 -2
  203. package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.js +1 -1
  204. package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.mjs +2 -2
  205. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.js +1 -1
  206. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.mjs +2 -2
  207. package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.js +1 -1
  208. package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.mjs +2 -2
  209. package/lib/constants/modelCompareData/assets/ptz.svg.js +1 -1
  210. package/lib/constants/modelCompareData/assets/ptz.svg.mjs +2 -2
  211. package/lib/constants/modelCompareData/assets/rack.svg.js +1 -1
  212. package/lib/constants/modelCompareData/assets/rack.svg.mjs +2 -2
  213. package/lib/constants/modelCompareData/data/CloudGateways.js +3 -3
  214. package/lib/constants/modelCompareData/data/CloudGateways.mjs +2 -2
  215. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.js +1 -1
  216. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.mjs +1 -1
  217. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.js +1 -1
  218. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.mjs +1 -1
  219. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.js +1 -1
  220. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.mjs +1 -1
  221. package/lib/constants/modelCompareData/data/product-list-groups/compact.js +1 -1
  222. package/lib/constants/modelCompareData/data/product-list-groups/compact.mjs +1 -1
  223. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.js +1 -1
  224. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.mjs +1 -1
  225. package/lib/constants/modelCompareData/data/product-list-groups/ptz.js +1 -1
  226. package/lib/constants/modelCompareData/data/product-list-groups/ptz.mjs +1 -1
  227. package/lib/constants/modelCompareData/data/products/aiDome.js +2 -2
  228. package/lib/constants/modelCompareData/data/products/aiDome.mjs +2 -2
  229. package/lib/constants/modelCompareData/data/products/aiLpr.js +2 -2
  230. package/lib/constants/modelCompareData/data/products/aiLpr.mjs +2 -2
  231. package/lib/constants/modelCompareData/data/products/doorHub.js +2 -2
  232. package/lib/constants/modelCompareData/data/products/doorHub.mjs +2 -2
  233. package/lib/constants/modelCompareData/data/products/doorHubMini.js +2 -2
  234. package/lib/constants/modelCompareData/data/products/doorHubMini.mjs +2 -2
  235. package/lib/constants/modelCompareData/data/products/g2Reader.js +2 -2
  236. package/lib/constants/modelCompareData/data/products/g2Reader.mjs +2 -2
  237. package/lib/constants/modelCompareData/data/products/g2ReaderPro.js +2 -2
  238. package/lib/constants/modelCompareData/data/products/g2ReaderPro.mjs +2 -2
  239. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.js +2 -2
  240. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.mjs +2 -2
  241. package/lib/constants/modelCompareData/data/products/g4Instant.js +2 -2
  242. package/lib/constants/modelCompareData/data/products/g4Instant.mjs +2 -2
  243. package/lib/constants/modelCompareData/data/products/g5Dome.js +2 -2
  244. package/lib/constants/modelCompareData/data/products/g5Dome.mjs +2 -2
  245. package/lib/constants/modelCompareData/data/products/g5TurretUltra.js +2 -2
  246. package/lib/constants/modelCompareData/data/products/g5TurretUltra.mjs +2 -2
  247. package/lib/constants/modelCompareData/data/products/intercom.js +2 -2
  248. package/lib/constants/modelCompareData/data/products/intercom.mjs +2 -2
  249. package/lib/constants/modelCompareData/data/products/theta.js +2 -2
  250. package/lib/constants/modelCompareData/data/products/theta.mjs +2 -2
  251. package/lib/constants/modelCompareData/data/products/ucgFiber.js +1 -1
  252. package/lib/constants/modelCompareData/data/products/ucgFiber.mjs +1 -1
  253. package/lib/constants/modelCompareData/data/properties/accessPowerMethod.js +1 -1
  254. package/lib/constants/modelCompareData/data/properties/accessPowerMethod.mjs +1 -1
  255. package/lib/constants/modelCompareData/data/properties/availability.js +1 -1
  256. package/lib/constants/modelCompareData/data/properties/availability.mjs +1 -1
  257. package/lib/constants/modelCompareData/data/properties/builtInFloodlight.js +1 -1
  258. package/lib/constants/modelCompareData/data/properties/builtInFloodlight.mjs +1 -1
  259. package/lib/constants/modelCompareData/data/properties/dcPowerOutput.js +1 -1
  260. package/lib/constants/modelCompareData/data/properties/dcPowerOutput.mjs +1 -1
  261. package/lib/constants/modelCompareData/data/properties/mounting.js +1 -1
  262. package/lib/constants/modelCompareData/data/properties/mounting.mjs +1 -1
  263. package/lib/constants/modelCompareData/data/properties/unasPowerMethod.js +1 -1
  264. package/lib/constants/modelCompareData/data/properties/unasPowerMethod.mjs +1 -1
  265. package/lib/constants/modelCompareData/data/properties/webMode.js +1 -1
  266. package/lib/constants/modelCompareData/data/properties/webMode.mjs +1 -1
  267. package/lib/contexts/MenuContext/mapping.js +3 -3
  268. package/lib/contexts/MenuContext/mapping.mjs +2 -2
  269. package/lib/contexts/MicrositeMenuContext/mapping.js +3 -3
  270. package/lib/contexts/MicrositeMenuContext/mapping.mjs +2 -2
  271. package/lib/utils/array.d.ts +6 -0
  272. package/lib/utils/array.js +9 -0
  273. package/lib/utils/array.js.map +1 -1
  274. package/lib/utils/array.mjs +9 -1
  275. package/lib/utils/array.mjs.map +1 -1
  276. package/lib/utils/index.d.ts +1 -0
  277. package/lib/utils/index.js +2 -0
  278. package/lib/utils/index.js.map +1 -1
  279. package/lib/utils/index.mjs +2 -0
  280. package/lib/utils/index.mjs.map +1 -1
  281. package/lib/utils/map.d.ts +51 -0
  282. package/lib/utils/map.js +97 -0
  283. package/lib/utils/map.js.map +1 -0
  284. package/lib/utils/map.mjs +95 -0
  285. package/lib/utils/map.mjs.map +1 -0
  286. package/lib/utils/map.test.d.ts +1 -0
  287. package/lib/utils/money/allocators/totalAmount.d.ts +17 -0
  288. package/lib/utils/money/allocators/totalAmount.js +40 -0
  289. package/lib/utils/money/allocators/totalAmount.js.map +1 -0
  290. package/lib/utils/money/allocators/totalAmount.mjs +38 -0
  291. package/lib/utils/money/allocators/totalAmount.mjs.map +1 -0
  292. package/lib/utils/money/allocators/totalAmount.test.d.ts +1 -0
  293. package/lib/utils/money/index.d.ts +1 -0
  294. package/lib/utils/money/index.js +2 -0
  295. package/lib/utils/money/index.js.map +1 -1
  296. package/lib/utils/money/index.mjs +1 -0
  297. package/lib/utils/money/index.mjs.map +1 -1
  298. package/lib/utils/money/tax.d.ts +6 -3
  299. package/lib/utils/money/tax.js +3 -10
  300. package/lib/utils/money/tax.js.map +1 -1
  301. package/lib/utils/money/tax.mjs +6 -13
  302. package/lib/utils/money/tax.mjs.map +1 -1
  303. package/lib/utils/money/tax.private.d.ts +7 -2
  304. package/lib/utils/money/tax.private.js +21 -6
  305. package/lib/utils/money/tax.private.js.map +1 -1
  306. package/lib/utils/money/tax.private.mjs +22 -8
  307. package/lib/utils/money/tax.private.mjs.map +1 -1
  308. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
1
  export * from "./allocators/fixedAmount";
2
2
  export * from "./allocators/productAmount";
3
+ export * from "./allocators/totalAmount";
3
4
  export * from "./constants";
4
5
  export * from "./exchangeRate";
5
6
  export * from "./format";
@@ -2,6 +2,7 @@
2
2
 
3
3
  var fixedAmount = require('./allocators/fixedAmount.js');
4
4
  var productAmount = require('./allocators/productAmount.js');
5
+ var totalAmount = require('./allocators/totalAmount.js');
5
6
  var constants = require('./constants.js');
6
7
  var exchangeRate = require('./exchangeRate.js');
7
8
  var format = require('./format.js');
@@ -12,6 +13,7 @@ require('./types.js');
12
13
  "use strict";
13
14
  exports.FixedAmountAllocator = fixedAmount.FixedAmountAllocator;
14
15
  exports.ProductAmountAllocator = productAmount.ProductAmountAllocator;
16
+ exports.TotalAmountAllocator = totalAmount.TotalAmountAllocator;
15
17
  exports.EXCHANGE_RATE_DINERO_CURRENCY = constants.EXCHANGE_RATE_DINERO_CURRENCY;
16
18
  exports.Round = constants.Round;
17
19
  exports.TAX_RATE_DINERO_CURRENCY = constants.TAX_RATE_DINERO_CURRENCY;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,6 @@
1
1
  export { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
2
2
  export { ProductAmountAllocator } from './allocators/productAmount.mjs';
3
+ export { TotalAmountAllocator } from './allocators/totalAmount.mjs';
3
4
  export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, roundToNearestDecimalCent, roundToNearestFull059, roundToNearestHalfUnitCent, roundToNearestValidUiCarePrice, smallestSubunitLookup, storesWithPerItemTaxRate } from './constants.mjs';
4
5
  export { invertExchangeRate, toFixedExchangeRate, toSnapshotExchangeRate } from './exchangeRate.mjs';
5
6
  export { formatPrice, formatPriceRaw, getLocalizedCurrency, prettifyTotal } from './format.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -3,12 +3,15 @@ import type { Dino, LineItemSummary, TaxRate } from "./types";
3
3
  /**
4
4
  * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy
5
5
  */
6
- export declare const calculateLineItemTax: ({ itemSummary, taxRate, storeId, }: {
6
+ export declare const calculateLineItemTax: ({ itemSummary, taxRate, options, }: {
7
7
  itemSummary: LineItemSummary;
8
8
  taxRate: TaxRate;
9
- storeId: StoreId;
9
+ options: {
10
+ storeId: StoreId;
11
+ hasTaxIncludedPrice: boolean;
12
+ };
10
13
  }) => Dino;
11
- export declare const removeTaxAmount: (baseAmountWithTaxObj: Dino, taxRate: TaxRate) => import("dinero.js").Dinero<number>;
14
+ export declare const removeTaxAmount: (amountWithTax: Dino, taxRate: TaxRate) => Dino;
12
15
  /**
13
16
  * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)
14
17
  *
@@ -9,18 +9,11 @@ var tax_private = require('./tax.private.js');
9
9
  const calculateLineItemTax = ({
10
10
  itemSummary,
11
11
  taxRate,
12
- storeId
12
+ options
13
13
  }) => {
14
- return constants.storesWithPerItemTaxRate.has(storeId) ? tax_private.calculatePerQtyLineItemTax(itemSummary, taxRate) : tax_private.calculateWholeQtyLineItemTax(itemSummary, taxRate);
15
- };
16
- const removeTaxAmount = (baseAmountWithTaxObj, taxRate) => {
17
- const snapshot = dinero_js.toSnapshot(baseAmountWithTaxObj);
18
- const taxAmount = constants.Round.Financial(snapshot.amount - snapshot.amount / (1 + taxRate));
19
- return dinero_js.dinero({
20
- ...snapshot,
21
- amount: snapshot.amount - taxAmount
22
- });
14
+ return constants.storesWithPerItemTaxRate.has(options.storeId) ? tax_private.calculatePerQtyLineItemTax(itemSummary, taxRate, options) : tax_private.calculateWholeQtyLineItemTax(itemSummary, taxRate, options);
23
15
  };
16
+ const removeTaxAmount = (amountWithTax, taxRate) => dinero_js.subtract(amountWithTax, tax_private.getTaxFromFinalAmount(amountWithTax, taxRate));
24
17
  const convertDecimalTaxRateToPercentage = taxRate => {
25
18
  const dineroObj = decimalTaxRateToDinero(taxRate);
26
19
  const t = dinero_js.multiply(dineroObj, 100);
@@ -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 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,kCAAA,CAAyBC,GAAA,CAAIF,OAAO,CAAA,GACvCG,WAAAA,CAAAA,0BAAA,CAA2BL,aAAaC,OAAO,CAAA,GAC/CK,WAAAA,CAAAA,4BAAA,CAA6BN,WAAA,EAAaC,OAAO,CAAA;AACvD,CAAA;AAEO,MAAMM,eAAA,GAAkBA,CAC7BC,oBAAA,EACAP,OAAA,KACG;EACH,MAAMQ,QAAA,GAAWC,SAAAA,CAAAA,WAAWF,oBAAoB,CAAA;EAGhD,MAAMG,YAAYC,SAAAA,CAAAA,KAAA,CAAMC,SAAA,CACtBJ,QAAA,CAASK,MAAA,GAASL,QAAA,CAASK,MAAA,IAAU,CAAA,GAAIb,OAAA,CAAA,CAC3C;EAEA,OAA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AAUD,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
+ {"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,S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iply, toUnit, halfEven } from 'dinero.js';
1
+ import { subtract, multiply, toUnit, halfEven, dinero } from 'dinero.js';
2
2
  import { assert } from '../errors.mjs';
3
3
  import { isFloat, toFixedRate } from '../number.mjs';
4
- import { storesWithPerItemTaxRate, Round, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
5
- import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax } from './tax.private.mjs';
4
+ import { storesWithPerItemTaxRate, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
5
+ import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, getTaxFromFinalAmount } from './tax.private.mjs';
6
6
  "use strict";
7
7
  const calculateLineItemTax = ({
8
8
  itemSummary,
9
9
  taxRate,
10
- storeId
10
+ options
11
11
  }) => {
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
- });
12
+ return storesWithPerItemTaxRate.has(options.storeId) ? calculatePerQtyLineItemTax(itemSummary, taxRate, options) : calculateWholeQtyLineItemTax(itemSummary, taxRate, options);
21
13
  };
14
+ const removeTaxAmount = (amountWithTax, taxRate) => subtract(amountWithTax, getTaxFromFinalAmount(amountWithTax, taxRate));
22
15
  const convertDecimalTaxRateToPercentage = taxRate => {
23
16
  const dineroObj = decimalTaxRateToDinero(taxRate);
24
17
  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 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;"}
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,CAACC,aAAA,EAAqBR,OAAA,KACnDS,SAAS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B,MAAA,CAAOD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EAC/CC,MAAA,CAAOD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EACjD,OAAOA,MAAA;AACT,CAAA;"}
@@ -4,5 +4,10 @@ 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 calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dino;
8
- export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dino;
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;
@@ -29,23 +29,37 @@ const allocatePerItemTaxableAmount = itemSummary => {
29
29
  };
30
30
  });
31
31
  };
32
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
33
- if (taxRate === 0) {
34
- return misc.getDinero(0, itemSummary.currency);
35
- }
32
+ const calculateTaxOnTaxableAmount = (itemSummary, taxRate) => {
36
33
  return dinero_js.dinero({
37
34
  amount: constants.Round.Financial(itemSummary.taxableAmount * taxRate),
38
35
  currency: misc.getDineroCurrency(itemSummary.currency)
39
36
  });
40
37
  };
41
- const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
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) => {
42
56
  if (taxRate === 0) {
43
57
  return misc.getDinero(0, itemSummary.currency);
44
58
  }
45
59
  const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
46
60
  let totalTaxAmount = misc.getDinero(0, itemSummary.currency);
47
61
  singleItemSummaries.forEach(itemSummary2 => {
48
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
62
+ const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate, options);
49
63
  totalTaxAmount = dinero_js.add(totalTaxAmount, taxAmount);
50
64
  });
51
65
  return totalTaxAmount;
@@ -53,4 +67,5 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
53
67
  exports.allocatePerItemTaxableAmount = allocatePerItemTaxableAmount;
54
68
  exports.calculatePerQtyLineItemTax = calculatePerQtyLineItemTax;
55
69
  exports.calculateWholeQtyLineItemTax = calculateWholeQtyLineItemTax;
70
+ exports.getTaxFromFinalAmount = getTaxFromFinalAmount;
56
71
  //# 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 } 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,SAAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYO,cAAA,EAAgBP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEA,MAAME,SAAA,GAAY,IAAIC,gCAAA,CAAqB;IACzCC,uBAAuBV,WAAA,CAAYO,cAAA;IACnCI,kBAAA,EAAoBC,IAAAA,CAAAA,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAA,CAAYM;EA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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
+ {"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;EAGA,MAAME,iBAAA,GAAoBC,SAAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYO,cAAA,EAAgBP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEA,MAAME,SAAA,GAAY,IAAIC,gCAAA,CAAqB;IACzCC,uBAAuBV,WAAA,CAAYO,cAAA;IACnCI,kBAAA,EAAoBC,IAAAA,CAAAA,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAA,CA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
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,26 +27,40 @@ const allocatePerItemTaxableAmount = itemSummary => {
27
27
  };
28
28
  });
29
29
  };
30
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
31
- if (taxRate === 0) {
32
- return getDinero(0, itemSummary.currency);
33
- }
30
+ const calculateTaxOnTaxableAmount = (itemSummary, taxRate) => {
34
31
  return dinero({
35
32
  amount: Round.Financial(itemSummary.taxableAmount * taxRate),
36
33
  currency: getDineroCurrency(itemSummary.currency)
37
34
  });
38
35
  };
39
- const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
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) => {
40
54
  if (taxRate === 0) {
41
55
  return getDinero(0, itemSummary.currency);
42
56
  }
43
57
  const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
44
58
  let totalTaxAmount = getDinero(0, itemSummary.currency);
45
59
  singleItemSummaries.forEach(itemSummary2 => {
46
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
60
+ const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate, options);
47
61
  totalTaxAmount = add(totalTaxAmount, taxAmount);
48
62
  });
49
63
  return totalTaxAmount;
50
64
  };
51
- export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax };
65
+ export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, getTaxFromFinalAmount };
52
66
  //# 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 } 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;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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;"}
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,WA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ANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "11.27.4",
3
+ "version": "11.28.0-custom-tax.0",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {