@ubnt/store.core 11.26.0-custom-tax.0 → 11.26.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 (299) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/lib/_virtual/_virtual_multi-entry.js +0 -2
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +0 -2
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/ai-360.jpg +0 -0
  7. package/lib/assets/ai-3602.jpg +0 -0
  8. package/lib/assets/ai-theta.jpg +0 -0
  9. package/lib/assets/ai-theta2.jpg +0 -0
  10. package/lib/assets/attention.svg +1 -1
  11. package/lib/assets/attention2.svg +1 -1
  12. package/lib/assets/bullet2.svg +1 -1
  13. package/lib/assets/bullet3.svg +1 -1
  14. package/lib/assets/door-hub.jpg +0 -0
  15. package/lib/assets/door-hub2.jpg +0 -0
  16. package/lib/assets/floodlight.svg +1 -1
  17. package/lib/assets/floodlight2.svg +1 -1
  18. package/lib/assets/g2-reader.jpg +0 -0
  19. package/lib/assets/g2-reader2.jpg +0 -0
  20. package/lib/assets/g3-reader-pro.jpg +0 -0
  21. package/lib/assets/g3-reader-pro2.jpg +0 -0
  22. package/lib/assets/g3-starter-kit-pro.jpg +0 -0
  23. package/lib/assets/g3-starter-kit-pro2.jpg +0 -0
  24. package/lib/assets/g3-starter-kit.jpg +0 -0
  25. package/lib/assets/g3-starter-kit2.jpg +0 -0
  26. package/lib/assets/g4-instant.jpg +0 -0
  27. package/lib/assets/g4-instant2.jpg +0 -0
  28. package/lib/assets/g4-ptz.jpg +0 -0
  29. package/lib/assets/g4-ptz2.jpg +0 -0
  30. package/lib/assets/g5-dome-ultra.jpg +0 -0
  31. package/lib/assets/g5-dome-ultra2.jpg +0 -0
  32. package/lib/assets/g5-ptz.jpg +0 -0
  33. package/lib/assets/g5-ptz2.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/udr.jpg +0 -0
  53. package/lib/assets/udr2.jpg +0 -0
  54. package/lib/assets/udr3.jpg +0 -0
  55. package/lib/assets/udw.jpg +0 -0
  56. package/lib/assets/udw2.jpg +0 -0
  57. package/lib/assets/umr.jpg +0 -0
  58. package/lib/assets/umr2.jpg +0 -0
  59. package/lib/components/Explore/ExploreData.js +3 -3
  60. package/lib/components/Explore/ExploreData.mjs +3 -3
  61. package/lib/components/Explore/assets/udr.jpg.js +1 -1
  62. package/lib/components/Explore/assets/udr.jpg.mjs +2 -2
  63. package/lib/components/Explore/assets/udw.jpg.js +1 -1
  64. package/lib/components/Explore/assets/udw.jpg.mjs +2 -2
  65. package/lib/components/Explore/assets/umr.jpg.js +1 -1
  66. package/lib/components/Explore/assets/umr.jpg.mjs +2 -2
  67. package/lib/components/Header/Header.js +1 -1
  68. package/lib/components/Header/Header.mjs +1 -1
  69. package/lib/components/Header/LanguageFrame/LanguageFrame.js +1 -1
  70. package/lib/components/Header/LanguageFrame/LanguageFrame.js.map +1 -1
  71. package/lib/components/Header/LanguageFrame/LanguageFrame.mjs +1 -1
  72. package/lib/components/Header/LanguageFrame/LanguageFrame.mjs.map +1 -1
  73. package/lib/components/Header/ProHeader/ProHeader.js +1 -1
  74. package/lib/components/Header/ProHeader/ProHeader.mjs +1 -1
  75. package/lib/components/MicrositeHeader/components/HeaderContent/HeaderContent.js +1 -1
  76. package/lib/components/MicrositeHeader/components/HeaderContent/HeaderContent.mjs +1 -1
  77. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  78. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  79. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  80. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  81. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  82. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  83. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  84. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  85. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  86. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  87. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  88. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  89. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  90. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  91. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  92. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  93. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  94. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  95. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  96. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  97. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  98. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  99. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  100. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  101. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  102. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  103. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  104. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  105. package/lib/constants/icons/header/globe.svg.js +1 -1
  106. package/lib/constants/icons/header/globe.svg.mjs +2 -2
  107. package/lib/constants/icons/header/index.js +1 -1
  108. package/lib/constants/icons/header/index.mjs +1 -1
  109. package/lib/constants/icons/menu/floodlight.svg.js +5 -5
  110. package/lib/constants/icons/menu/floodlight.svg.mjs +2 -2
  111. package/lib/constants/icons/menu/index.js +9 -9
  112. package/lib/constants/icons/menu/index.mjs +3 -3
  113. package/lib/constants/icons/menu/power.svg.js +5 -5
  114. package/lib/constants/icons/menu/power.svg.mjs +2 -2
  115. package/lib/constants/icons/menu/rack.svg.js +5 -5
  116. package/lib/constants/icons/menu/rack.svg.mjs +2 -2
  117. package/lib/constants/modelCompareData/assets/Bullet/bullet.svg.js +1 -1
  118. package/lib/constants/modelCompareData/assets/Bullet/bullet.svg.mjs +2 -2
  119. package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.js +1 -1
  120. package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.mjs +2 -2
  121. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.js +5 -5
  122. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
  123. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udw.jpg.js +1 -1
  124. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udw.jpg.mjs +2 -2
  125. package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.js +1 -1
  126. package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.mjs +2 -2
  127. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.js +1 -1
  128. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.mjs +2 -2
  129. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome-ultra.jpg.js +1 -1
  130. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome-ultra.jpg.mjs +2 -2
  131. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.js +1 -1
  132. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.mjs +2 -2
  133. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.js +1 -1
  134. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.mjs +2 -2
  135. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.js +1 -1
  136. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.mjs +2 -2
  137. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.js +1 -1
  138. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs +2 -2
  139. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit.jpg.js +1 -1
  140. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit.jpg.mjs +2 -2
  141. package/lib/constants/modelCompareData/assets/DoorAccess/intercom.jpg.js +1 -1
  142. package/lib/constants/modelCompareData/assets/DoorAccess/intercom.jpg.mjs +2 -2
  143. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.js +1 -1
  144. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.mjs +2 -2
  145. package/lib/constants/modelCompareData/assets/MobileRouters/umr.jpg.js +1 -1
  146. package/lib/constants/modelCompareData/assets/MobileRouters/umr.jpg.mjs +2 -2
  147. package/lib/constants/modelCompareData/assets/PTZ/g4-ptz.jpg.js +1 -1
  148. package/lib/constants/modelCompareData/assets/PTZ/g4-ptz.jpg.mjs +2 -2
  149. package/lib/constants/modelCompareData/assets/PTZ/g5-ptz.jpg.js +1 -1
  150. package/lib/constants/modelCompareData/assets/PTZ/g5-ptz.jpg.mjs +2 -2
  151. package/lib/constants/modelCompareData/assets/floodlight.svg.js +1 -1
  152. package/lib/constants/modelCompareData/assets/floodlight.svg.mjs +2 -2
  153. package/lib/constants/modelCompareData/assets/globe.svg.js +1 -1
  154. package/lib/constants/modelCompareData/assets/globe.svg.mjs +2 -2
  155. package/lib/constants/modelCompareData/assets/interior-design.svg.js +1 -1
  156. package/lib/constants/modelCompareData/assets/interior-design.svg.mjs +2 -2
  157. package/lib/constants/modelCompareData/assets/power.svg.js +1 -1
  158. package/lib/constants/modelCompareData/assets/power.svg.mjs +2 -2
  159. package/lib/constants/modelCompareData/assets/product-list-assets/bullet.svg.js +1 -1
  160. package/lib/constants/modelCompareData/assets/product-list-assets/bullet.svg.mjs +2 -2
  161. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.js +1 -1
  162. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.mjs +2 -2
  163. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.js +1 -1
  164. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.mjs +2 -2
  165. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome-ultra.jpg.js +1 -1
  166. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome-ultra.jpg.mjs +2 -2
  167. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.js +1 -1
  168. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.mjs +2 -2
  169. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.js +1 -1
  170. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.mjs +2 -2
  171. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.js +1 -1
  172. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.mjs +2 -2
  173. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.js +1 -1
  174. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.mjs +2 -2
  175. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit.jpg.js +1 -1
  176. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit.jpg.mjs +2 -2
  177. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/intercom.jpg.js +1 -1
  178. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/intercom.jpg.mjs +2 -2
  179. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.js +1 -1
  180. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.mjs +2 -2
  181. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g4-ptz.jpg.js +1 -1
  182. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g4-ptz.jpg.mjs +2 -2
  183. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g5-ptz.jpg.js +1 -1
  184. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g5-ptz.jpg.mjs +2 -2
  185. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.js +1 -1
  186. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.mjs +2 -2
  187. package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.js +1 -1
  188. package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.mjs +2 -2
  189. package/lib/constants/modelCompareData/assets/ptz.svg.js +1 -1
  190. package/lib/constants/modelCompareData/assets/ptz.svg.mjs +2 -2
  191. package/lib/constants/modelCompareData/assets/rack.svg.js +1 -1
  192. package/lib/constants/modelCompareData/assets/rack.svg.mjs +2 -2
  193. package/lib/constants/modelCompareData/data/CloudGateways.js +1 -1
  194. package/lib/constants/modelCompareData/data/CloudGateways.mjs +1 -1
  195. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.js +4 -4
  196. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.mjs +3 -3
  197. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Bullet.js +1 -1
  198. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Bullet.mjs +1 -1
  199. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.js +1 -1
  200. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.mjs +1 -1
  201. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.js +1 -1
  202. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.mjs +1 -1
  203. package/lib/constants/modelCompareData/data/product-list-groups/bullet.js +1 -1
  204. package/lib/constants/modelCompareData/data/product-list-groups/bullet.mjs +1 -1
  205. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.js +1 -1
  206. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.mjs +1 -1
  207. package/lib/constants/modelCompareData/data/product-list-groups/ptz.js +1 -1
  208. package/lib/constants/modelCompareData/data/product-list-groups/ptz.mjs +1 -1
  209. package/lib/constants/modelCompareData/data/products/ai360.js +2 -2
  210. package/lib/constants/modelCompareData/data/products/ai360.mjs +2 -2
  211. package/lib/constants/modelCompareData/data/products/doorHub.js +2 -2
  212. package/lib/constants/modelCompareData/data/products/doorHub.mjs +2 -2
  213. package/lib/constants/modelCompareData/data/products/g2Reader.js +2 -2
  214. package/lib/constants/modelCompareData/data/products/g2Reader.mjs +2 -2
  215. package/lib/constants/modelCompareData/data/products/g3ReaderPro.js +2 -2
  216. package/lib/constants/modelCompareData/data/products/g3ReaderPro.mjs +2 -2
  217. package/lib/constants/modelCompareData/data/products/g3StarterKit.js +2 -2
  218. package/lib/constants/modelCompareData/data/products/g3StarterKit.mjs +2 -2
  219. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.js +2 -2
  220. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.mjs +2 -2
  221. package/lib/constants/modelCompareData/data/products/g4Instant.js +2 -2
  222. package/lib/constants/modelCompareData/data/products/g4Instant.mjs +2 -2
  223. package/lib/constants/modelCompareData/data/products/g4Ptz.js +2 -2
  224. package/lib/constants/modelCompareData/data/products/g4Ptz.mjs +2 -2
  225. package/lib/constants/modelCompareData/data/products/g5DomeUltra.js +2 -2
  226. package/lib/constants/modelCompareData/data/products/g5DomeUltra.mjs +2 -2
  227. package/lib/constants/modelCompareData/data/products/g5Ptz.js +2 -2
  228. package/lib/constants/modelCompareData/data/products/g5Ptz.mjs +2 -2
  229. package/lib/constants/modelCompareData/data/products/intercom.js +2 -2
  230. package/lib/constants/modelCompareData/data/products/intercom.mjs +2 -2
  231. package/lib/constants/modelCompareData/data/products/theta.js +2 -2
  232. package/lib/constants/modelCompareData/data/products/theta.mjs +2 -2
  233. package/lib/constants/modelCompareData/data/products/udr.js +1 -1
  234. package/lib/constants/modelCompareData/data/products/udr.mjs +1 -1
  235. package/lib/constants/modelCompareData/data/products/udw.js +1 -1
  236. package/lib/constants/modelCompareData/data/products/udw.mjs +1 -1
  237. package/lib/constants/modelCompareData/data/products/umr.js +1 -1
  238. package/lib/constants/modelCompareData/data/products/umr.mjs +1 -1
  239. package/lib/constants/modelCompareData/data/properties/accessPowerMethod.js +1 -1
  240. package/lib/constants/modelCompareData/data/properties/accessPowerMethod.mjs +1 -1
  241. package/lib/constants/modelCompareData/data/properties/availability.js +1 -1
  242. package/lib/constants/modelCompareData/data/properties/availability.mjs +1 -1
  243. package/lib/constants/modelCompareData/data/properties/builtInFloodlight.js +1 -1
  244. package/lib/constants/modelCompareData/data/properties/builtInFloodlight.mjs +1 -1
  245. package/lib/constants/modelCompareData/data/properties/dcPowerOutput.js +1 -1
  246. package/lib/constants/modelCompareData/data/properties/dcPowerOutput.mjs +1 -1
  247. package/lib/constants/modelCompareData/data/properties/mounting.js +1 -1
  248. package/lib/constants/modelCompareData/data/properties/mounting.mjs +1 -1
  249. package/lib/constants/modelCompareData/data/properties/unasPowerMethod.js +1 -1
  250. package/lib/constants/modelCompareData/data/properties/unasPowerMethod.mjs +1 -1
  251. package/lib/constants/modelCompareData/data/properties/webMode.js +1 -1
  252. package/lib/constants/modelCompareData/data/properties/webMode.mjs +1 -1
  253. package/lib/contexts/MenuContext/mapping.js +3 -3
  254. package/lib/contexts/MenuContext/mapping.mjs +2 -2
  255. package/lib/contexts/MicrositeMenuContext/mapping.js +3 -3
  256. package/lib/contexts/MicrositeMenuContext/mapping.mjs +2 -2
  257. package/lib/utils/address.d.ts +67 -1
  258. package/lib/utils/address.js +2 -1
  259. package/lib/utils/address.js.map +1 -1
  260. package/lib/utils/address.mjs +2 -1
  261. package/lib/utils/address.mjs.map +1 -1
  262. package/lib/utils/array.d.ts +0 -6
  263. package/lib/utils/array.js +0 -9
  264. package/lib/utils/array.js.map +1 -1
  265. package/lib/utils/array.mjs +1 -9
  266. package/lib/utils/array.mjs.map +1 -1
  267. package/lib/utils/index.d.ts +0 -1
  268. package/lib/utils/index.js +0 -2
  269. package/lib/utils/index.js.map +1 -1
  270. package/lib/utils/index.mjs +0 -2
  271. package/lib/utils/index.mjs.map +1 -1
  272. package/lib/utils/money/index.d.ts +0 -1
  273. package/lib/utils/money/index.js +0 -2
  274. package/lib/utils/money/index.js.map +1 -1
  275. package/lib/utils/money/index.mjs +0 -1
  276. package/lib/utils/money/index.mjs.map +1 -1
  277. package/lib/utils/money/tax.d.ts +3 -6
  278. package/lib/utils/money/tax.js +10 -3
  279. package/lib/utils/money/tax.js.map +1 -1
  280. package/lib/utils/money/tax.mjs +13 -6
  281. package/lib/utils/money/tax.mjs.map +1 -1
  282. package/lib/utils/money/tax.private.d.ts +2 -7
  283. package/lib/utils/money/tax.private.js +6 -21
  284. package/lib/utils/money/tax.private.js.map +1 -1
  285. package/lib/utils/money/tax.private.mjs +8 -22
  286. package/lib/utils/money/tax.private.mjs.map +1 -1
  287. package/package.json +1 -1
  288. package/lib/utils/map.d.ts +0 -51
  289. package/lib/utils/map.js +0 -97
  290. package/lib/utils/map.js.map +0 -1
  291. package/lib/utils/map.mjs +0 -95
  292. package/lib/utils/map.mjs.map +0 -1
  293. package/lib/utils/map.test.d.ts +0 -1
  294. package/lib/utils/money/allocators/totalAmount.d.ts +0 -14
  295. package/lib/utils/money/allocators/totalAmount.js +0 -35
  296. package/lib/utils/money/allocators/totalAmount.js.map +0 -1
  297. package/lib/utils/money/allocators/totalAmount.mjs +0 -33
  298. package/lib/utils/money/allocators/totalAmount.mjs.map +0 -1
  299. package/lib/utils/money/allocators/totalAmount.test.d.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"address.mjs","sources":["../../src/utils/address.ts"],"sourcesContent":["import type { ZodErrorMap } from \"zod\";\nimport { z } from \"zod\";\n\nimport { AddressType, AddressUsageType, CountryCode } from \"../types\";\nimport type { Country } from \"./countriesAndZones\";\nimport { address2SuperRefinement } from \"./validations/address2SuperRefinement\";\nimport { businessNameSuperRefinement } from \"./validations/businessNameSuperRefinement\";\nimport { neighborhoodSuperRefinement } from \"./validations/neighborhoodSuperRefinement\";\nimport { phoneNumberSuperRefinement } from \"./validations/phoneNumberSuperRefinement\";\nimport { postalCodeSuperRefinement } from \"./validations/postalCodeSuperRefinement\";\nimport { getProvinceSuperRefinement } from \"./validations/provinceSuperRefinement\";\nimport { createStateRegistrationNumberSuperRefinement } from \"./validations/stateRegistrationNumberSuperRefinement\";\nimport { createTaxIdSuperRefinement } from \"./validations/taxIdSuperRefinement\";\nimport type { ValidateTaxIdExternally } from \"./validations/taxIdSuperRefinement\";\n\nexport type BaseAddressSchemaArgs = {\n countries: Country[];\n errorMap?: ZodErrorMap;\n addressUsageType?: AddressUsageType;\n};\n\nexport type AddressSchemaArgs = BaseAddressSchemaArgs & {\n validateTaxIdExternally?: ValidateTaxIdExternally;\n};\n\nconst COUNTRIES_WITH_SEPARATED_STREET_AND_HOUSE_NUMBER = new Set([\n CountryCode.Br,\n]);\n\nconst COUNTRY_SPECIFIC_ADDRESS_FIELDS_BY_COUNTRY_CODE = new Map<\n CountryCode,\n Array<keyof z.infer<ReturnType<typeof getAddressSchema>>>\n>([\n [\n CountryCode.Br,\n [\"stateRegistrationNumber\", \"neighborhood\", \"additionalInfo\"],\n ],\n]);\n\n/**\n * If it returns `true`, the `address1` field will be used for the street name\n * and `address2` field will be used for the house/apartment number.\n */\nexport const shouldAddressHaveSeparatedStreetAndHouseNumber = (\n country: CountryCode,\n) => COUNTRIES_WITH_SEPARATED_STREET_AND_HOUSE_NUMBER.has(country);\n\n/**\n * Returns address form field paths for country-specific fields.\n */\nexport const getCountrySpecificAddressFormFields = <TPathPrefix extends string>(\n country: CountryCode,\n { pathPrefix }: { pathPrefix: TPathPrefix },\n) => {\n const fields = COUNTRY_SPECIFIC_ADDRESS_FIELDS_BY_COUNTRY_CODE.get(country);\n\n if (!fields) {\n return [];\n }\n\n return fields.map((field) => `${pathPrefix}${field}` as const);\n};\n\nconst DEFAULT_ADDRESS_VALIDATION_USAGE_TYPE = AddressUsageType.Shipping;\n// #############################################################################\n// Base Address Schema\n// #############################################################################\nexport const getBaseAddressSchema = ({\n countries,\n errorMap,\n addressUsageType = DEFAULT_ADDRESS_VALIDATION_USAGE_TYPE,\n}: BaseAddressSchemaArgs) => {\n const schema = z;\n\n if (errorMap) {\n schema.setErrorMap(errorMap);\n }\n\n return schema\n .object({\n address1:\n addressUsageType === AddressUsageType.ReturnShipping\n ? z.string().trim().min(1).max(35)\n : z.string().trim().min(1).max(255),\n address2:\n addressUsageType === AddressUsageType.ReturnShipping\n ? z.string().trim().max(35).nullish()\n : z.string().trim().max(255).nullish(),\n city: z.string().trim().min(1).max(255),\n province: z.string().trim().nullish(),\n country: z.nativeEnum(CountryCode),\n postalCode: z.string().trim().max(255).nullish(),\n neighborhood: z.string().trim().max(255).nullish(),\n })\n .superRefine(getProvinceSuperRefinement(countries))\n .superRefine(postalCodeSuperRefinement)\n .superRefine(neighborhoodSuperRefinement)\n .superRefine(address2SuperRefinement);\n};\n\n// #############################################################################\n// Address Schema\n// #############################################################################\nexport const getAddressSchema = ({\n countries,\n validateTaxIdExternally,\n errorMap,\n addressUsageType = DEFAULT_ADDRESS_VALIDATION_USAGE_TYPE,\n}: AddressSchemaArgs) => {\n return z\n .object({\n type: z.nativeEnum(AddressType),\n businessName: z.string().trim().max(255).nullish(),\n taxId: z.string().trim().max(255).nullish(),\n firstName: z.string().trim().min(1).max(255),\n lastName: z.string().trim().min(1).max(255),\n phoneNumber: z.string().trim().min(1).max(255),\n stateRegistrationNumber: z.string().trim().max(255).nullish(),\n additionalInfo: z.string().trim().max(255).nullish(),\n })\n .and(getBaseAddressSchema({ countries, errorMap, addressUsageType }))\n .superRefine(phoneNumberSuperRefinement)\n .superRefine(businessNameSuperRefinement)\n .superRefine(\n createTaxIdSuperRefinement({ addressUsageType, validateTaxIdExternally }),\n )\n .superRefine(\n createStateRegistrationNumberSuperRefinement({ addressUsageType }),\n );\n};\n\n// #############################################################################\n// Create Customer Address Schema\n// #############################################################################\nexport const getCreateCustomerAddressSchema = (args: AddressSchemaArgs) => {\n return z\n .object({\n isDefault: z.boolean().nullish(),\n })\n .and(getAddressSchema(args));\n};\n\n// #############################################################################\n// Update Customer Address Schema\n// #############################################################################\nexport const getUpdateCustomerAddressSchema = (args: AddressSchemaArgs) => {\n return z\n .object({\n id: z.string().trim().uuid().nullish(),\n })\n .and(getCreateCustomerAddressSchema(args));\n};\n\n// #############################################################################\n// Update Order Address Schema\n// #############################################################################\nexport const getUpdateOrderAddressSchema = (args: AddressSchemaArgs) => {\n return z\n .object({\n customerAddressId: z.string().trim().uuid().nullish(),\n saveForFutureUse: z.boolean().nullish(),\n })\n .and(getAddressSchema(args));\n};\n\n// #############################################################################\n// Address Fields uniform validation\n// #############################################################################\n/**\n * Need to use this schema for uniform validation of address fields in SF\n */\nexport const getAddressFieldsSchema = (args: AddressSchemaArgs) => {\n return getUpdateCustomerAddressSchema(args).and(\n getUpdateOrderAddressSchema(args),\n );\n};\n\n// #############################################################################\n// Email and Accepts marketing validation\n// #############################################################################\n/**\n * Stored as a separate schema because of schema differences in BE and SF.\n * @param {boolean} nullish !!! Use with caution since it is only meant for BE where fields can be optional\n * @see https://github.com/colinhacks/zod/issues/2281#issuecomment-1492082268\n */\n\nexport const getEmailAndMarketingSchema = <Nullish extends boolean = false>(\n {\n errorMap,\n nullish,\n }: {\n errorMap?: ZodErrorMap;\n nullish?: Nullish;\n } = {\n nullish: false as Nullish,\n },\n) => {\n const schema = z;\n\n if (errorMap) {\n schema.setErrorMap(errorMap);\n }\n\n const email = (\n nullish ? z.string().email().nullish() : z.string().email()\n ) as Nullish extends true\n ? z.ZodOptional<z.ZodNullable<z.ZodString>>\n : z.ZodString;\n\n const acceptsMarketing = (\n nullish ? z.boolean().optional() : z.boolean()\n ) as Nullish extends true ? z.ZodOptional<z.ZodBoolean> : z.ZodBoolean;\n\n return schema.object({\n email,\n acceptsMarketing,\n });\n};\n"],"names":["COUNTRIES_WITH_SEPARATED_STREET_AND_HOUSE_NUMBER","Set","CountryCode","Br","COUNTRY_SPECIFIC_ADDRESS_FIELDS_BY_COUNTRY_CODE","Map","shouldAddressHaveSeparatedStreetAndHouseNumber","country","has","getCountrySpecificAddressFormFields","pathPrefix","fields","get","map","field","DEFAULT_ADDRESS_VALIDATION_USAGE_TYPE","AddressUsageType","Shipping","getBaseAddressSchema","countries","errorMap","addressUsageType","schema","z","setErrorMap","object","address1","ReturnShipping","string","trim","min","max","address2","nullish","city","province","nativeEnum","postalCode","neighborhood","superRefine","getProvinceSuperRefinement","postalCodeSuperRefinement","neighborhoodSuperRefinement","address2SuperRefinement","getAddressSchema","validateTaxIdExternally","type","AddressType","businessName","taxId","firstName","lastName","phoneNumber","stateRegistrationNumber","additionalInfo","and","phoneNumberSuperRefinement","businessNameSuperRefinement","createTaxIdSuperRefinement","createStateRegistrationNumberSuperRefinement","getCreateCustomerAddressSchema","args","isDefault","boolean","getUpdateCustomerAddressSchema","id","uuid","getUpdateOrderAddressSchema","customerAddressId","saveForFutureUse","getAddressFieldsSchema","getEmailAndMarketingSchema","email","acceptsMarketing","optional"],"mappings":";;;;;;;;;;;;;AAyBA,MAAMA,gDAAA,GAAA,mBAAuDC,GAAA,CAAI,CAC/DC,WAAA,CAAYC,EAAA,CACb,CAAA;AAED,MAAMC,+CAAA,GAAA,mBAAsDC,GAAA,CAG1D,CACA,CACEH,WAAA,CAAYC,EAAA,EACZ,CAAC,yBAAA,EAA2B,cAAA,EAAgB,gBAAgB,CAAA,CAAA,CAE/D,CAAA;AAMM,MAAMG,8CAAA,GACXC,OAAA,IACGP,gDAAA,CAAiDQ,IAAID,OAAO,CAAA;AAK1D,MAAME,mCAAA,GAAsCA,CACjDF,OAAA,EACA;EAAEG;CAAW,KACV;EACH,MAAMC,MAAA,GAASP,+CAAA,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C,iBAAA,EAAmB7C,EAAEK,MAAA,CAAA,CAAO,CAAEC,MAAK,CAAEqC,IAAA,CAAA,EAAOjC,OAAA,CAAA,CAAQ;IACpDoC,gBAAA,EAAkB9C,CAAA,CAAEwC,OAAA,CAAA,CAAQ,CAAE9B,OAAA,CAAA;EAAQ,CACvC,CAAA,CACAsB,GAAA,CAAIX,gBAAA,CAAiBiB,IAAI,CAAC,CAAA;AAC/B,CAAA;AAQO,MAAMS,sBAAA,GAA0BT,IAAA,IAA4B;EACjE,OAAOG,8BAAA,CAA+BH,IAAI,CAAA,CAAEN,GAAA,CAC1CY,4BAA4BN,IAAI,CAAA,CAClC;AACF,CAAA;AAWO,MAAMU,6BAA6BA,CACxC;EACEnD,QAAA;EACAa;AACF,CAAA,GAGI;EACFA,OAAA,EAAS;AACX,CAAA,KACG;EACH,MAAMX,MAAA,GAASC,CAAA;EAEf,IAAIH,QAAA,EAAU;IACZE,MAAA,CAAOE,YAAYJ,QAAQ,CAAA;EAC7B;EAEA,MAAMoD,KAAA,GACJvC,OAAA,GAAUV,CAAA,CAAEK,MAAA,CAAA,CAAO,CAAE4C,KAAA,EAAM,CAAEvC,OAAA,EAAQ,GAAIV,CAAA,CAAEK,MAAA,CAAA,CAAO,CAAE4C,KAAA,CAAA,CAAM;EAK5D,MAAMC,gBAAA,GACJxC,UAAUV,CAAA,CAAEwC,OAAA,CAAA,EAAUW,QAAA,CAAA,CAAS,GAAInD,EAAEwC,OAAA,CAAA,CAAQ;EAG/C,OAAOzC,OAAOG,MAAA,CAAO;IACnB+C,KAAA;IACAC;EAAA,CACD,CAAA;AACH,CAAA;"}
1
+ {"version":3,"file":"address.mjs","sources":["../../src/utils/address.ts"],"sourcesContent":["import type { ZodErrorMap } from \"zod\";\nimport { z } from \"zod\";\n\nimport { AddressType, AddressUsageType, CountryCode } from \"../types\";\nimport type { Country } from \"./countriesAndZones\";\nimport { address2SuperRefinement } from \"./validations/address2SuperRefinement\";\nimport { businessNameSuperRefinement } from \"./validations/businessNameSuperRefinement\";\nimport { neighborhoodSuperRefinement } from \"./validations/neighborhoodSuperRefinement\";\nimport { phoneNumberSuperRefinement } from \"./validations/phoneNumberSuperRefinement\";\nimport { postalCodeSuperRefinement } from \"./validations/postalCodeSuperRefinement\";\nimport { getProvinceSuperRefinement } from \"./validations/provinceSuperRefinement\";\nimport { createStateRegistrationNumberSuperRefinement } from \"./validations/stateRegistrationNumberSuperRefinement\";\nimport { createTaxIdSuperRefinement } from \"./validations/taxIdSuperRefinement\";\nimport type { ValidateTaxIdExternally } from \"./validations/taxIdSuperRefinement\";\n\nexport type BaseAddressSchemaArgs = {\n countries: Country[];\n errorMap?: ZodErrorMap;\n addressUsageType?: AddressUsageType;\n};\n\nexport type AddressSchemaArgs = BaseAddressSchemaArgs & {\n validateTaxIdExternally?: ValidateTaxIdExternally;\n};\n\nconst COUNTRIES_WITH_SEPARATED_STREET_AND_HOUSE_NUMBER = new Set([\n CountryCode.Br,\n]);\n\nconst COUNTRY_SPECIFIC_ADDRESS_FIELDS_BY_COUNTRY_CODE = new Map<\n CountryCode,\n Array<keyof z.infer<ReturnType<typeof getAddressSchema>>>\n>([\n [\n CountryCode.Br,\n [\"stateRegistrationNumber\", \"neighborhood\", \"additionalInfo\"],\n ],\n]);\n\n/**\n * If it returns `true`, the `address1` field will be used for the street name\n * and `address2` field will be used for the house/apartment number.\n */\nexport const shouldAddressHaveSeparatedStreetAndHouseNumber = (\n country: CountryCode,\n) => COUNTRIES_WITH_SEPARATED_STREET_AND_HOUSE_NUMBER.has(country);\n\n/**\n * Returns address form field paths for country-specific fields.\n */\nexport const getCountrySpecificAddressFormFields = <TPathPrefix extends string>(\n country: CountryCode,\n { pathPrefix }: { pathPrefix: TPathPrefix },\n) => {\n const fields = COUNTRY_SPECIFIC_ADDRESS_FIELDS_BY_COUNTRY_CODE.get(country);\n\n if (!fields) {\n return [];\n }\n\n return fields.map((field) => `${pathPrefix}${field}` as const);\n};\n\nconst DEFAULT_ADDRESS_VALIDATION_USAGE_TYPE = AddressUsageType.Shipping;\n// #############################################################################\n// Base Address Schema\n// #############################################################################\nexport const getBaseAddressSchema = ({\n countries,\n errorMap,\n addressUsageType = DEFAULT_ADDRESS_VALIDATION_USAGE_TYPE,\n}: BaseAddressSchemaArgs) => {\n const schema = z;\n\n if (errorMap) {\n schema.setErrorMap(errorMap);\n }\n\n return schema\n .object({\n address1:\n addressUsageType === AddressUsageType.ReturnShipping\n ? z.string().trim().min(1).max(35)\n : z.string().trim().min(1).max(255),\n address2:\n addressUsageType === AddressUsageType.ReturnShipping\n ? z.string().trim().max(35).nullish()\n : z.string().trim().max(255).nullish(),\n city: z.string().trim().min(1).max(255),\n province: z.string().trim().nullish(),\n country: z.nativeEnum(CountryCode),\n postalCode: z.string().trim().max(255).nullish(),\n neighborhood: z.string().trim().max(255).nullish(),\n })\n .superRefine(getProvinceSuperRefinement(countries))\n .superRefine(postalCodeSuperRefinement)\n .superRefine(neighborhoodSuperRefinement)\n .superRefine(address2SuperRefinement);\n};\n\n// #############################################################################\n// Address Schema\n// #############################################################################\nexport const getAddressSchema = ({\n countries,\n validateTaxIdExternally,\n errorMap,\n addressUsageType = DEFAULT_ADDRESS_VALIDATION_USAGE_TYPE,\n}: AddressSchemaArgs) => {\n return z\n .object({\n type: z.nativeEnum(AddressType),\n businessName: z.string().trim().max(255).nullish(),\n taxId: z.string().trim().max(255).nullish(),\n firstName: z.string().trim().min(1).max(255),\n lastName: z.string().trim().min(1).max(255),\n phoneNumber: z.string().trim().min(1).max(255),\n stateRegistrationNumber: z.string().trim().max(255).nullish(),\n additionalInfo: z.string().trim().max(255).nullish(),\n referenceNumber: z.string().trim().max(20).nullish(),\n })\n .and(getBaseAddressSchema({ countries, errorMap, addressUsageType }))\n .superRefine(phoneNumberSuperRefinement)\n .superRefine(businessNameSuperRefinement)\n .superRefine(\n createTaxIdSuperRefinement({ addressUsageType, validateTaxIdExternally }),\n )\n .superRefine(\n createStateRegistrationNumberSuperRefinement({ addressUsageType }),\n );\n};\n\n// #############################################################################\n// Create Customer Address Schema\n// #############################################################################\nexport const getCreateCustomerAddressSchema = (args: AddressSchemaArgs) => {\n return z\n .object({\n isDefault: z.boolean().nullish(),\n })\n .and(getAddressSchema(args));\n};\n\n// #############################################################################\n// Update Customer Address Schema\n// #############################################################################\nexport const getUpdateCustomerAddressSchema = (args: AddressSchemaArgs) => {\n return z\n .object({\n id: z.string().trim().uuid().nullish(),\n })\n .and(getCreateCustomerAddressSchema(args));\n};\n\n// #############################################################################\n// Update Order Address Schema\n// #############################################################################\nexport const getUpdateOrderAddressSchema = (args: AddressSchemaArgs) => {\n return z\n .object({\n customerAddressId: z.string().trim().uuid().nullish(),\n saveForFutureUse: z.boolean().nullish(),\n })\n .and(getAddressSchema(args));\n};\n\n// #############################################################################\n// Address Fields uniform validation\n// #############################################################################\n/**\n * Need to use this schema for uniform validation of address fields in SF\n */\nexport const getAddressFieldsSchema = (args: AddressSchemaArgs) => {\n return getUpdateCustomerAddressSchema(args).and(\n getUpdateOrderAddressSchema(args),\n );\n};\n\n// #############################################################################\n// Email and Accepts marketing validation\n// #############################################################################\n/**\n * Stored as a separate schema because of schema differences in BE and SF.\n * @param {boolean} nullish !!! Use with caution since it is only meant for BE where fields can be optional\n * @see https://github.com/colinhacks/zod/issues/2281#issuecomment-1492082268\n */\n\nexport const getEmailAndMarketingSchema = <Nullish extends boolean = false>(\n {\n errorMap,\n nullish,\n }: {\n errorMap?: ZodErrorMap;\n nullish?: Nullish;\n } = {\n nullish: false as Nullish,\n },\n) => {\n const schema = z;\n\n if (errorMap) {\n schema.setErrorMap(errorMap);\n }\n\n const email = (\n nullish ? z.string().email().nullish() : z.string().email()\n ) as Nullish extends true\n ? z.ZodOptional<z.ZodNullable<z.ZodString>>\n : z.ZodString;\n\n const acceptsMarketing = (\n nullish ? z.boolean().optional() : z.boolean()\n ) as Nullish extends true ? z.ZodOptional<z.ZodBoolean> : z.ZodBoolean;\n\n return schema.object({\n email,\n acceptsMarketing,\n });\n};\n"],"names":["COUNTRIES_WITH_SEPARATED_STREET_AND_HOUSE_NUMBER","Set","CountryCode","Br","COUNTRY_SPECIFIC_ADDRESS_FIELDS_BY_COUNTRY_CODE","Map","shouldAddressHaveSeparatedStreetAndHouseNumber","country","has","getCountrySpecificAddressFormFields","pathPrefix","fields","get","map","field","DEFAULT_ADDRESS_VALIDATION_USAGE_TYPE","AddressUsageType","Shipping","getBaseAddressSchema","countries","errorMap","addressUsageType","schema","z","setErrorMap","object","address1","ReturnShipping","string","trim","min","max","address2","nullish","city","province","nativeEnum","postalCode","neighborhood","superRefine","getProvinceSuperRefinement","postalCodeSuperRefinement","neighborhoodSuperRefinement","address2SuperRefinement","getAddressSchema","validateTaxIdExternally","type","AddressType","businessName","taxId","firstName","lastName","phoneNumber","stateRegistrationNumber","additionalInfo","referenceNumber","and","phoneNumberSuperRefinement","businessNameSuperRefinement","createTaxIdSuperRefinement","createStateRegistrationNumberSuperRefinement","getCreateCustomerAddressSchema","args","isDefault","boolean","getUpdateCustomerAddressSchema","id","uuid","getUpdateOrderAddressSchema","customerAddressId","saveForFutureUse","getAddressFieldsSchema","getEmailAndMarketingSchema","email","acceptsMarketing","optional"],"mappings":";;;;;;;;;;;;;AAyBA,MAAMA,gDAAA,GAAA,mBAAuDC,GAAA,CAAI,CAC/DC,WAAA,CAAYC,EAAA,CACb,CAAA;AAED,MAAMC,+CAAA,GAAA,mBAAsDC,GAAA,CAG1D,CACA,CACEH,WAAA,CAAYC,EAAA,EACZ,CAAC,yBAAA,EAA2B,cAAA,EAAgB,gBAAgB,CAAA,CAAA,CAE/D,CAAA;AAMM,MAAMG,8CAAA,GACXC,OAAA,IACGP,gDAAA,CAAiDQ,IAAID,OAAO,CAAA;AAK1D,MAAME,mCAAA,GAAsCA,CACjDF,OAAA,EACA;EAAEG;CAAW,KACV;EACH,MAAMC,MAAA,GAASP,+CAAA,CAAgDQ,GAAA,CAAIL,OAAO,CAAA;EAE1E,IAAI,CAACI,MAAA,EA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N,IAAA,IAA4B;EACtE,OAAOvC,EACJE,MAAA,CAAO;IACN4C,iBAAA,EAAmB9C,EAAEK,MAAA,CAAA,CAAO,CAAEC,MAAK,CAAEsC,IAAA,CAAA,EAAOlC,OAAA,CAAA,CAAQ;IACpDqC,gBAAA,EAAkB/C,CAAA,CAAEyC,OAAA,CAAA,CAAQ,CAAE/B,OAAA,CAAA;EAAQ,CACvC,CAAA,CACAuB,GAAA,CAAIZ,gBAAA,CAAiBkB,IAAI,CAAC,CAAA;AAC/B,CAAA;AAQO,MAAMS,sBAAA,GAA0BT,IAAA,IAA4B;EACjE,OAAOG,8BAAA,CAA+BH,IAAI,CAAA,CAAEN,GAAA,CAC1CY,4BAA4BN,IAAI,CAAA,CAClC;AACF,CAAA;AAWO,MAAMU,6BAA6BA,CACxC;EACEpD,QAAA;EACAa;AACF,CAAA,GAGI;EACFA,OAAA,EAAS;AACX,CAAA,KACG;EACH,MAAMX,MAAA,GAASC,CAAA;EAEf,IAAIH,QAAA,EAAU;IACZE,MAAA,CAAOE,YAAYJ,QAAQ,CAAA;EAC7B;EAEA,MAAMqD,KAAA,GACJxC,OAAA,GAAUV,CAAA,CAAEK,MAAA,CAAA,CAAO,CAAE6C,KAAA,EAAM,CAAExC,OAAA,EAAQ,GAAIV,CAAA,CAAEK,MAAA,CAAA,CAAO,CAAE6C,KAAA,CAAA,CAAM;EAK5D,MAAMC,gBAAA,GACJzC,UAAUV,CAAA,CAAEyC,OAAA,CAAA,EAAUW,QAAA,CAAA,CAAS,GAAIpD,EAAEyC,OAAA,CAAA,CAAQ;EAG/C,OAAO1C,OAAOG,MAAA,CAAO;IACnBgD,KAAA;IACAC;EAAA,CACD,CAAA;AACH,CAAA;"}
@@ -28,9 +28,3 @@ export declare const arraySafeIndexFind: <T>(array: T[], index: number) => T | u
28
28
  * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts
29
29
  */
30
30
  export declare const normalizeSortResult: (sortResult: number) => number;
31
- /**
32
- * Returns an array of keys from an interface where the value is true
33
- *
34
- * @example createArrayFromInterfaceKeys<{a: string, b: number, c: Date}>({ a: true, b: false, c: true }) => ['a', 'c']
35
- */
36
- export declare function createArrayFromInterfaceKeys<T extends object>(keyRecord: Record<keyof T, boolean>): (keyof T)[];
@@ -24,18 +24,9 @@ const arraySafeIndexFind = (array, index) => {
24
24
  return array[safeIndex];
25
25
  };
26
26
  const normalizeSortResult = sortResult => number.clamp(sortResult, -1, 1);
27
- function createArrayFromInterfaceKeys(keyRecord) {
28
- return Object.entries(keyRecord).reduce((acc, [key, include]) => {
29
- if (include) {
30
- acc.push(key);
31
- }
32
- return acc;
33
- }, []);
34
- }
35
27
  exports.areEqualArrays = areEqualArrays;
36
28
  exports.arraySafeIndex = arraySafeIndex;
37
29
  exports.arraySafeIndexFind = arraySafeIndexFind;
38
- exports.createArrayFromInterfaceKeys = createArrayFromInterfaceKeys;
39
30
  exports.dedupe = dedupe;
40
31
  exports.ensureArray = ensureArray;
41
32
  exports.normalizeSortResult = normalizeSortResult;
@@ -1 +1 @@
1
- {"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Returns an array of keys from an interface where the value is true\n *\n * @example createArrayFromInterfaceKeys<{a: string, b: number, c: Date}>({ a: true, b: false, c: true }) => ['a', 'c']\n */\nexport function createArrayFromInterfaceKeys<T extends object>(\n keyRecord: Record<keyof T, boolean>,\n) {\n return Object.entries(keyRecord).reduce(\n (acc: (keyof T)[], [key, include]) => {\n if (include) {\n acc.push(key);\n }\n return acc;\n },\n [],\n );\n}\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","createArrayFromInterfaceKeys","keyRecord","Object","entries","reduce","acc","key","include","push"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAA,EAAqB;EAClD,OAAOC,MAAMC,OAAA,CAAQF,KAAK,CAAA,GAAIA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOO,MAAMG,MAAA,GAAaC,GAAA,IAAa,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAShD,MAAME,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAA,KAAyB;EACnE,IAAID,CAAA,CAAEE,MAAA,KAAWD,CAAA,CAAEC,MAAA,EAAQ;IACzB,OAAO,KAAA;EACT;EACA,IAAI,CAACF,EAAEG,KAAA,CAAOC,MAAOH,CAAA,CAAEI,QAAA,CAASD,EAAE,CAAC,CAAA,EAAG;IACpC,OAAO,KAAA;EACT;EACA,OAAO,CAACH,CAAA,CAAEE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAA,CAASD,EAAE,CAAC,CAAA,GAAI,KAAA,GAAQ,IAAA;AACpD,CAAA;AAOO,MAAME,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAAA,KAA0B;EACtE,MAAMC,YAAYF,KAAA,CAAML,MAAA;EAExB,OAAA,CAASM,KAAA,GAAQC,YAAaA,SAAA,IAAaA,SAAA;AAC7C,CAAA;AAEO,MAAMC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KAAA,KACkB;EAClB,MAAMG,SAAA,GAAYL,cAAA,CAAeC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAA,CAAMD,UAAA,EAAY,IAAI,CAAC,CAAA;AAOlB,SAASE,6BACdC,SAAA,EACA;EACA,OAAOC,MAAA,CAAOC,OAAA,CAAQF,SAAS,CAAA,CAAEG,MAAA,CAC/B,CAACC,GAAA,EAAkB,CAACC,GAAA,EAAKC,OAAO,CAAA,KAAM;IACpC,IAAIA,OAAA,EAAS;MACXF,GAAA,CAAIG,KAAKF,GAAG,CAAA;IACd;IACA,OAAOD,GAAA;EACT,CAAA,EACA,EAAC,CACH;AACF;;;;;;;"}
1
+ {"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAA,EAAqB;EAClD,OAAOC,MAAMC,OAAA,CAAQF,KAAK,CAAA,GAAIA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOO,MAAMG,MAAA,GAAaC,GAAA,IAAa,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAShD,MAAME,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAA,KAAyB;EACnE,IAAID,CAAA,CAAEE,MAAA,KAAWD,CAAA,CAAEC,MAAA,EAAQ;IACzB,OAAO,KAAA;EACT;EACA,IAAI,CAACF,EAAEG,KAAA,CAAOC,MAAOH,CAAA,CAAEI,QAAA,CAASD,EAAE,CAAC,CAAA,EAAG;IACpC,OAAO,KAAA;EACT;EACA,OAAO,CAACH,CAAA,CAAEE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAA,CAASD,EAAE,CAAC,CAAA,GAAI,KAAA,GAAQ,IAAA;AACpD,CAAA;AAOO,MAAME,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAAA,KAA0B;EACtE,MAAMC,YAAYF,KAAA,CAAML,MAAA;EAExB,OAAA,CAASM,KAAA,GAAQC,YAAaA,SAAA,IAAaA,SAAA;AAC7C,CAAA;AAEO,MAAMC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KAAA,KACkB;EAClB,MAAMG,SAAA,GAAYL,cAAA,CAAeC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAA,CAAMD,UAAA,EAAY,IAAI,CAAC,CAAA;;;;;;"}
@@ -22,13 +22,5 @@ const arraySafeIndexFind = (array, index) => {
22
22
  return array[safeIndex];
23
23
  };
24
24
  const normalizeSortResult = sortResult => clamp(sortResult, -1, 1);
25
- function createArrayFromInterfaceKeys(keyRecord) {
26
- return Object.entries(keyRecord).reduce((acc, [key, include]) => {
27
- if (include) {
28
- acc.push(key);
29
- }
30
- return acc;
31
- }, []);
32
- }
33
- export { areEqualArrays, arraySafeIndex, arraySafeIndexFind, createArrayFromInterfaceKeys, dedupe, ensureArray, normalizeSortResult };
25
+ export { areEqualArrays, arraySafeIndex, arraySafeIndexFind, dedupe, ensureArray, normalizeSortResult };
34
26
  //# sourceMappingURL=array.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Returns an array of keys from an interface where the value is true\n *\n * @example createArrayFromInterfaceKeys<{a: string, b: number, c: Date}>({ a: true, b: false, c: true }) => ['a', 'c']\n */\nexport function createArrayFromInterfaceKeys<T extends object>(\n keyRecord: Record<keyof T, boolean>,\n) {\n return Object.entries(keyRecord).reduce(\n (acc: (keyof T)[], [key, include]) => {\n if (include) {\n acc.push(key);\n }\n return acc;\n },\n [],\n );\n}\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","createArrayFromInterfaceKeys","keyRecord","Object","entries","reduce","acc","key","include","push"],"mappings":";;AAMO,SAASA,YAAeC,KAAA,EAAqB;EA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GAAA;EACT,CAAA,EACA,EAAC,CACH;AACF;"}
1
+ {"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;AAMO,SAASA,YAAeC,KAAA,EAAqB;EAClD,OAAOC,MAAMC,OAAA,CAAQF,KAAK,CAAA,GAAIA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOO,MAAMG,MAAA,GAAaC,GAAA,IAAa,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAShD,MAAME,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAA,KAAyB;EACnE,IAAID,CAAA,CAAEE,MAAA,KAAWD,CAAA,CAAEC,MAAA,EAAQ;IACzB,OAAO,KAAA;EACT;EACA,IAAI,CAACF,EAAEG,KAAA,CAAOC,MAAOH,CAAA,CAAEI,QAAA,CAASD,EAAE,CAAC,CAAA,EAAG;IACpC,OAAO,KAAA;EACT;EACA,OAAO,CAACH,CAAA,CAAEE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAA,CAASD,EAAE,CAAC,CAAA,GAAI,KAAA,GAAQ,IAAA;AACpD,CAAA;AAOO,MAAME,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAAA,KAA0B;EACtE,MAAMC,YAAYF,KAAA,CAAML,MAAA;EAExB,OAAA,CAASM,KAAA,GAAQC,YAAaA,SAAA,IAAaA,SAAA;AAC7C,CAAA;AAEO,MAAMC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KAAA,KACkB;EAClB,MAAMG,SAAA,GAAYL,cAAA,CAAeC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAA,CAAMD,UAAA,EAAY,IAAI,CAAC,CAAA;"}
@@ -20,4 +20,3 @@ export * as styles from "./styles";
20
20
  export * as storeId from "./storeId";
21
21
  export * as blackFriday from "./blackFriday";
22
22
  export * as sales from "./sales";
23
- export * as map from "./map";
@@ -22,7 +22,6 @@ var styles$1 = require('./styles.js');
22
22
  var storeId$1 = require('./storeId.js');
23
23
  var blackFriday$1 = require('./blackFriday.js');
24
24
  var sales$1 = require('./sales.js');
25
- var map$1 = require('./map.js');
26
25
  "use strict";
27
26
  exports.url = url$1;
28
27
  exports.money = index;
@@ -46,5 +45,4 @@ exports.styles = styles$1;
46
45
  exports.storeId = storeId$1;
47
46
  exports.blackFriday = blackFriday$1;
48
47
  exports.sales = sales$1;
49
- exports.map = map$1;
50
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -42,7 +42,5 @@ import * as blackFriday$1 from './blackFriday.mjs';
42
42
  export { blackFriday$1 as blackFriday };
43
43
  import * as sales$1 from './sales.mjs';
44
44
  export { sales$1 as sales };
45
- import * as map$1 from './map.mjs';
46
- export { map$1 as map };
47
45
  "use strict";
48
46
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,5 @@
1
1
  export * from "./allocators/fixedAmount";
2
2
  export * from "./allocators/productAmount";
3
- export * from "./allocators/totalAmount";
4
3
  export * from "./constants";
5
4
  export * from "./exchangeRate";
6
5
  export * from "./format";
@@ -2,7 +2,6 @@
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');
6
5
  var constants = require('./constants.js');
7
6
  var exchangeRate = require('./exchangeRate.js');
8
7
  var format = require('./format.js');
@@ -13,7 +12,6 @@ require('./types.js');
13
12
  "use strict";
14
13
  exports.FixedAmountAllocator = fixedAmount.FixedAmountAllocator;
15
14
  exports.ProductAmountAllocator = productAmount.ProductAmountAllocator;
16
- exports.TotalAmountAllocator = totalAmount.TotalAmountAllocator;
17
15
  exports.EXCHANGE_RATE_DINERO_CURRENCY = constants.EXCHANGE_RATE_DINERO_CURRENCY;
18
16
  exports.Round = constants.Round;
19
17
  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,6 +1,5 @@
1
1
  export { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
2
2
  export { ProductAmountAllocator } from './allocators/productAmount.mjs';
3
- export { TotalAmountAllocator } from './allocators/totalAmount.mjs';
4
3
  export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, roundToNearestDecimalCent, roundToNearestFull059, roundToNearestHalfUnitCent, roundToNearestValidUiCarePrice, smallestSubunitLookup, storesWithPerItemTaxRate } from './constants.mjs';
5
4
  export { invertExchangeRate, toFixedExchangeRate, toSnapshotExchangeRate } from './exchangeRate.mjs';
6
5
  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,15 +3,12 @@ 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, options, }: {
6
+ export declare const calculateLineItemTax: ({ itemSummary, taxRate, storeId, }: {
7
7
  itemSummary: LineItemSummary;
8
8
  taxRate: TaxRate;
9
- options: {
10
- storeId: StoreId;
11
- hasTaxIncludedPrice: boolean;
12
- };
9
+ storeId: StoreId;
13
10
  }) => Dino;
14
- export declare const removeTaxAmount: (amountWithTax: Dino, taxRate: TaxRate) => Dino;
11
+ export declare const removeTaxAmount: (baseAmountWithTaxObj: Dino, taxRate: TaxRate) => import("dinero.js").Dinero<number>;
15
12
  /**
16
13
  * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)
17
14
  *
@@ -9,11 +9,18 @@ var tax_private = require('./tax.private.js');
9
9
  const calculateLineItemTax = ({
10
10
  itemSummary,
11
11
  taxRate,
12
- options
12
+ storeId
13
13
  }) => {
14
- return constants.storesWithPerItemTaxRate.has(options.storeId) ? tax_private.calculatePerQtyLineItemTax(itemSummary, taxRate, options) : tax_private.calculateWholeQtyLineItemTax(itemSummary, taxRate, options);
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
+ });
15
23
  };
16
- const removeTaxAmount = (amountWithTax, taxRate) => dinero_js.subtract(amountWithTax, tax_private.getTaxFromFinalAmount(amountWithTax, taxRate));
17
24
  const convertDecimalTaxRateToPercentage = taxRate => {
18
25
  const dineroObj = decimalTaxRateToDinero(taxRate);
19
26
  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 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"],"mappings":";;;;;;;;AA0BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAAA,KAIM;EACJ,OAAOC,kCAAA,CAAyBC,GAAA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A,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,CAACC,aAAA,EAAqBR,OAAA,KACnDS,SAASD,aAAA,EAAeE,qBAAA,CAAsBF,aAAA,EAAeR,OAAO,CAAC,CAAA;AAWhE,MAAMW,iCAAA,GACXX,OAAA,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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;EAGA,MAAME,iBAAA,GAAoBC,SAAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ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E,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,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAA,GAAoBC,SAAAA,CAA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,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,CAAA;MACnCE,cAAA,EAAgBK,OAAOI,uBAAuB,CAAA;MAC9CV,UAAUN,WAAA,CAAYM,QAAA;MACtBL,QAAA,EAAU;IAAA,CACZ;EACF,CAAC,CAAA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AAGJ,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","get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