@ubnt/store.core 9.19.1 → 9.20.0-alpha.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 (425) hide show
  1. package/CHANGELOG.md +199 -3
  2. package/lib/_virtual/_virtual_multi-entry.js +27 -12
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +14 -10
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/attention.svg +5 -5
  7. package/lib/assets/attention2.svg +5 -5
  8. package/lib/assets/close2.svg +2 -3
  9. package/lib/assets/close3.svg +3 -2
  10. package/lib/assets/efg.png +0 -0
  11. package/lib/assets/icon-location-pin.svg +5 -0
  12. package/lib/assets/icons/menu/icon-location-pin.svg.js +27 -0
  13. package/lib/assets/icons/menu/icon-location-pin.svg.js.map +1 -0
  14. package/lib/assets/icons/menu/icon-location-pin.svg.mjs +3 -0
  15. package/lib/assets/icons/menu/icon-location-pin.svg.mjs.map +1 -0
  16. package/lib/assets/minus4.svg +8 -8
  17. package/lib/assets/minus5.svg +8 -8
  18. package/lib/assets/plus5.svg +9 -9
  19. package/lib/assets/plus6.svg +9 -9
  20. package/lib/assets/ucg-max.png +0 -0
  21. package/lib/assets/ucgMax.jpg +0 -0
  22. package/lib/assets/ucgMax2.jpg +0 -0
  23. package/lib/assets/ucgUltra.jpg +0 -0
  24. package/lib/assets/ucgUltra2.jpg +0 -0
  25. package/lib/assets/udmPro.jpg +0 -0
  26. package/lib/assets/udmPro2.jpg +0 -0
  27. package/lib/components/CategoryTabs/CategoryTabs.styles.d.ts +1 -1
  28. package/lib/components/CategoryTabs/CategoryTabs.styles.js +2 -3
  29. package/lib/components/CategoryTabs/CategoryTabs.styles.js.map +1 -1
  30. package/lib/components/CategoryTabs/CategoryTabs.styles.mjs +2 -3
  31. package/lib/components/CategoryTabs/CategoryTabs.styles.mjs.map +1 -1
  32. package/lib/components/Compare/Compare.styles.d.ts +5 -5
  33. package/lib/components/Container/Container.d.ts +1 -1
  34. package/lib/components/Container/Container.js +4 -3
  35. package/lib/components/Container/Container.js.map +1 -1
  36. package/lib/components/Container/Container.mjs +5 -4
  37. package/lib/components/Container/Container.mjs.map +1 -1
  38. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  39. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  40. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  41. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  42. package/lib/components/Header/AccountMenu/AccountMenu.js +11 -1
  43. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  44. package/lib/components/Header/AccountMenu/AccountMenu.mjs +13 -3
  45. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  46. package/lib/components/Header/Header.js +6 -6
  47. package/lib/components/Header/Header.js.map +1 -1
  48. package/lib/components/Header/Header.mjs +6 -6
  49. package/lib/components/Header/Header.mjs.map +1 -1
  50. package/lib/components/Header/Header.styles.d.ts +2 -2
  51. package/lib/components/Header/Header.types.d.ts +12 -4
  52. package/lib/components/Header/Header.types.js +2 -1
  53. package/lib/components/Header/Header.types.js.map +1 -1
  54. package/lib/components/Header/Header.types.mjs +2 -1
  55. package/lib/components/Header/Header.types.mjs.map +1 -1
  56. package/lib/components/Header/MenuItem/MenuItem.styles.d.ts +1 -1
  57. package/lib/components/Header/MenuItem/MenuItem.styles.js +3 -3
  58. package/lib/components/Header/MenuItem/MenuItem.styles.js.map +1 -1
  59. package/lib/components/Header/MenuItem/MenuItem.styles.mjs +3 -3
  60. package/lib/components/Header/MenuItem/MenuItem.styles.mjs.map +1 -1
  61. package/lib/components/Header/MenuItem/MenuItem.types.d.ts +1 -0
  62. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.d.ts +1 -1
  63. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.styles.d.ts +1 -1
  64. package/lib/components/Header/Navigation/ProMenu/ProMenu.d.ts +2 -0
  65. package/lib/components/Header/Navigation/ProMenu/ProMenu.js +103 -0
  66. package/lib/components/Header/Navigation/ProMenu/ProMenu.js.map +1 -0
  67. package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs +81 -0
  68. package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs.map +1 -0
  69. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.d.ts +23 -0
  70. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js +121 -0
  71. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js.map +1 -0
  72. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs +106 -0
  73. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs.map +1 -0
  74. package/lib/components/Header/Navigation/ProMenu/ProMenu.types.d.ts +12 -0
  75. package/lib/components/Header/Navigation/ProMenu/index.d.ts +1 -0
  76. package/lib/components/Header/Navigation/ProMenu/index.js +6 -0
  77. package/lib/components/{ResourceCalculatorV1/components → Header/Navigation/ProMenu}/index.js.map +1 -1
  78. package/lib/components/Header/Navigation/ProMenu/index.mjs +3 -0
  79. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.d.ts +1 -1
  80. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +92 -95
  81. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
  82. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +92 -95
  83. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs.map +1 -1
  84. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.d.ts +9 -0
  85. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js +15 -1
  86. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js.map +1 -1
  87. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs +13 -2
  88. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs.map +1 -1
  89. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.types.d.ts +10 -4
  90. package/lib/components/Header/ProHeader/ProHeader.d.ts +3 -4
  91. package/lib/components/Header/ProHeader/ProHeader.js +247 -120
  92. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  93. package/lib/components/Header/ProHeader/ProHeader.mjs +249 -124
  94. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  95. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +4 -1
  96. package/lib/components/Header/ProHeader/ProHeader.styles.js +23 -17
  97. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  98. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +21 -18
  99. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  100. package/lib/components/Header/translations/ar.json.js +4 -1
  101. package/lib/components/Header/translations/ar.json.js.map +1 -1
  102. package/lib/components/Header/translations/ar.json.mjs +4 -2
  103. package/lib/components/Header/translations/ar.json.mjs.map +1 -1
  104. package/lib/components/Header/translations/de.json.js +4 -1
  105. package/lib/components/Header/translations/de.json.js.map +1 -1
  106. package/lib/components/Header/translations/de.json.mjs +4 -2
  107. package/lib/components/Header/translations/de.json.mjs.map +1 -1
  108. package/lib/components/Header/translations/el.json.js +4 -1
  109. package/lib/components/Header/translations/el.json.js.map +1 -1
  110. package/lib/components/Header/translations/el.json.mjs +4 -2
  111. package/lib/components/Header/translations/el.json.mjs.map +1 -1
  112. package/lib/components/Header/translations/en.json.js +4 -1
  113. package/lib/components/Header/translations/en.json.js.map +1 -1
  114. package/lib/components/Header/translations/en.json.mjs +4 -2
  115. package/lib/components/Header/translations/en.json.mjs.map +1 -1
  116. package/lib/components/Header/translations/es.json.js +4 -1
  117. package/lib/components/Header/translations/es.json.js.map +1 -1
  118. package/lib/components/Header/translations/es.json.mjs +4 -2
  119. package/lib/components/Header/translations/es.json.mjs.map +1 -1
  120. package/lib/components/Header/translations/fr.json.js +4 -1
  121. package/lib/components/Header/translations/fr.json.js.map +1 -1
  122. package/lib/components/Header/translations/fr.json.mjs +4 -2
  123. package/lib/components/Header/translations/fr.json.mjs.map +1 -1
  124. package/lib/components/Header/translations/it.json.js +4 -1
  125. package/lib/components/Header/translations/it.json.js.map +1 -1
  126. package/lib/components/Header/translations/it.json.mjs +4 -2
  127. package/lib/components/Header/translations/it.json.mjs.map +1 -1
  128. package/lib/components/Header/translations/ja.json.js +4 -1
  129. package/lib/components/Header/translations/ja.json.js.map +1 -1
  130. package/lib/components/Header/translations/ja.json.mjs +4 -2
  131. package/lib/components/Header/translations/ja.json.mjs.map +1 -1
  132. package/lib/components/Header/translations/pt-BR.json.js +4 -1
  133. package/lib/components/Header/translations/pt-BR.json.js.map +1 -1
  134. package/lib/components/Header/translations/pt-BR.json.mjs +4 -2
  135. package/lib/components/Header/translations/pt-BR.json.mjs.map +1 -1
  136. package/lib/components/Header/translations/zh-Hans.json.js +4 -1
  137. package/lib/components/Header/translations/zh-Hans.json.js.map +1 -1
  138. package/lib/components/Header/translations/zh-Hans.json.mjs +4 -2
  139. package/lib/components/Header/translations/zh-Hans.json.mjs.map +1 -1
  140. package/lib/components/Header/translations/zh-Hant-TW.json.js +4 -1
  141. package/lib/components/Header/translations/zh-Hant-TW.json.js.map +1 -1
  142. package/lib/components/Header/translations/zh-Hant-TW.json.mjs +4 -2
  143. package/lib/components/Header/translations/zh-Hant-TW.json.mjs.map +1 -1
  144. package/lib/components/Hero/Hero.styles.d.ts +2 -2
  145. package/lib/components/HeroFadeGallery/HeroFadeGallery.styles.d.ts +1 -1
  146. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.d.ts +1 -1
  147. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.js +3 -1
  148. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +1 -0
  149. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.mjs +3 -1
  150. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +1 -0
  151. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.styles.d.ts +1 -0
  152. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.styles.js +10 -7
  153. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +1 -0
  154. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.styles.mjs +10 -7
  155. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +1 -0
  156. package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/HorizontalOptionSelect.types.d.ts +1 -0
  157. package/lib/components/HowToUseSection/HowToUseSection.styles.d.ts +2 -2
  158. package/lib/components/LandingPagePro/LandingPagePro.d.ts +3 -0
  159. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  160. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  161. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  162. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  163. package/lib/components/LandingPagePro/LandingPagePro.styles.d.ts +1 -1
  164. package/lib/components/LayoutRenderer/LayoutRenderer.styles.d.ts +1 -1
  165. package/lib/components/LayoutRendererV1/LayoutRenderer.styles.d.ts +3 -3
  166. package/lib/components/LayoutRendererV2/LayoutRenderer.styles.d.ts +3 -3
  167. package/lib/components/MicrositeSectionWrap/MicrositeSectionWrap.styles.d.ts +1 -1
  168. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  169. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  170. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  171. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  172. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  173. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  174. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  175. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  176. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  177. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  178. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  179. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  180. package/lib/components/ModelCompareV3/data/CloudGateways.js +9 -9
  181. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +6 -6
  182. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  183. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  184. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  185. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  186. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  187. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  188. package/lib/components/ProductSectionNavigation/ProductSectionNavigation.styles.d.ts +1 -1
  189. package/lib/components/ProductSectionNavigationV2/ProductSectionNavigation.styles.d.ts +1 -1
  190. package/lib/components/ProductTechSpecs/ProductTechSpecs.styles.d.ts +1 -1
  191. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +313 -17
  192. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  193. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +311 -17
  194. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  195. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +3 -2
  196. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +2 -0
  197. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  198. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +2 -0
  199. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  200. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js +120 -34
  201. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js.map +1 -1
  202. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs +120 -34
  203. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs.map +1 -1
  204. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.d.ts +16 -2
  205. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js +54 -12
  206. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js.map +1 -1
  207. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs +50 -11
  208. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs.map +1 -1
  209. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowLeftPrimary.svg.js +5 -5
  210. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowRightPrimary.svg.js +5 -5
  211. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +2 -2
  212. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  213. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +2 -2
  214. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  215. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +2 -0
  216. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  217. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +2 -0
  218. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  219. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  220. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  221. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  222. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  223. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  224. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  225. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  226. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  227. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  228. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  229. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  230. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  231. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
  232. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
  233. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
  234. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
  235. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +4 -4
  236. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js.map +1 -1
  237. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +4 -4
  238. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs.map +1 -1
  239. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  240. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  241. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  242. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  243. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js +1 -2
  244. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js.map +1 -1
  245. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs +1 -2
  246. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs.map +1 -1
  247. package/lib/{assets/icons/menu/icon-globe.svg.js → components/ResourceCalculatorV1/assets/consoles/efg.png.js} +6 -6
  248. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +1 -0
  249. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +3 -0
  250. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +1 -0
  251. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js +27 -0
  252. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +1 -0
  253. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +3 -0
  254. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +1 -0
  255. package/lib/components/ResourceCalculatorV1/translations/en.json.js +6 -4
  256. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  257. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +6 -4
  258. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  259. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  260. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  261. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  262. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  263. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  264. package/lib/components/index.d.ts +1 -0
  265. package/lib/components/index.js +2 -0
  266. package/lib/components/index.js.map +1 -1
  267. package/lib/components/index.mjs +2 -0
  268. package/lib/components/index.mjs.map +1 -1
  269. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  270. package/lib/constants/icons/options/colors/index.js +3 -3
  271. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  272. package/lib/constants/icons/options/styles/index.js +3 -3
  273. package/lib/constants/optionIcons.js +6 -6
  274. package/lib/constants/optionIcons.mjs +4 -4
  275. package/lib/constants/proStoreCategories/mapping/index.d.ts +1 -0
  276. package/lib/constants/proStoreCategories/mapping/index.js +54 -49
  277. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  278. package/lib/constants/proStoreCategories/mapping/index.mjs +54 -49
  279. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  280. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +2 -1
  281. package/lib/constants/proStoreCategories/mapping/unifi.js +1 -0
  282. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  283. package/lib/constants/proStoreCategories/mapping/unifi.mjs +1 -0
  284. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  285. package/lib/constants/proStoreCategories/translations/en.json.js +3 -0
  286. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  287. package/lib/constants/proStoreCategories/translations/en.json.mjs +3 -1
  288. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  289. package/lib/constants/proStoreCategories/translations/fr.json.js +1 -1
  290. package/lib/constants/proStoreCategories/translations/fr.json.mjs +1 -1
  291. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +1 -1
  292. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +1 -1
  293. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +1 -1
  294. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +1 -1
  295. package/lib/constants/theme.js +4 -0
  296. package/lib/constants/theme.js.map +1 -1
  297. package/lib/constants/theme.mjs +4 -0
  298. package/lib/constants/theme.mjs.map +1 -1
  299. package/lib/contexts/MenuContext/context.js +1 -1
  300. package/lib/contexts/MenuContext/context.js.map +1 -1
  301. package/lib/contexts/MenuContext/context.mjs +1 -1
  302. package/lib/contexts/MenuContext/context.mjs.map +1 -1
  303. package/lib/helpers/index.d.ts +1 -0
  304. package/lib/helpers/index.js +11 -0
  305. package/lib/helpers/index.js.map +1 -1
  306. package/lib/helpers/index.mjs +1 -0
  307. package/lib/helpers/index.mjs.map +1 -1
  308. package/lib/helpers/product.d.ts +87 -0
  309. package/lib/helpers/product.js +346 -0
  310. package/lib/helpers/product.js.map +1 -0
  311. package/lib/helpers/product.mjs +335 -0
  312. package/lib/helpers/product.mjs.map +1 -0
  313. package/lib/helpers/ux.d.ts +9 -1
  314. package/lib/helpers/ux.js +15 -0
  315. package/lib/helpers/ux.js.map +1 -1
  316. package/lib/helpers/ux.mjs +15 -1
  317. package/lib/helpers/ux.mjs.map +1 -1
  318. package/lib/types/index.d.ts +1 -0
  319. package/lib/types/index.js +2 -0
  320. package/lib/types/index.js.map +1 -1
  321. package/lib/types/index.mjs +1 -0
  322. package/lib/types/index.mjs.map +1 -1
  323. package/lib/types/product.d.ts +87 -0
  324. package/lib/types/product.js +14 -0
  325. package/lib/types/product.js.map +1 -0
  326. package/lib/types/product.mjs +13 -0
  327. package/lib/types/product.mjs.map +1 -0
  328. package/lib/utils/array.d.ts +4 -0
  329. package/lib/utils/array.js +10 -0
  330. package/lib/utils/array.js.map +1 -1
  331. package/lib/utils/array.mjs +10 -1
  332. package/lib/utils/array.mjs.map +1 -1
  333. package/lib/utils/money/allocators/fixedAmount.d.ts +26 -0
  334. package/lib/utils/money/allocators/fixedAmount.js +52 -0
  335. package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
  336. package/lib/utils/money/allocators/fixedAmount.mjs +50 -0
  337. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
  338. package/lib/utils/money/allocators/index.d.ts +2 -0
  339. package/lib/utils/money/allocators/index.js +8 -0
  340. package/lib/utils/money/allocators/index.js.map +1 -0
  341. package/lib/utils/money/allocators/index.mjs +4 -0
  342. package/lib/utils/money/allocators/index.mjs.map +1 -0
  343. package/lib/utils/money/allocators/productAmount.d.ts +13 -0
  344. package/lib/utils/money/allocators/productAmount.js +98 -0
  345. package/lib/utils/money/allocators/productAmount.js.map +1 -0
  346. package/lib/utils/money/allocators/productAmount.mjs +96 -0
  347. package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
  348. package/lib/utils/money/constants.d.ts +56 -25
  349. package/lib/utils/money/constants.js +72 -7
  350. package/lib/utils/money/constants.js.map +1 -1
  351. package/lib/utils/money/constants.mjs +70 -7
  352. package/lib/utils/money/constants.mjs.map +1 -1
  353. package/lib/utils/money/exchangeRate.d.ts +31 -0
  354. package/lib/utils/money/exchangeRate.js +27 -0
  355. package/lib/utils/money/exchangeRate.js.map +1 -0
  356. package/lib/utils/money/exchangeRate.mjs +23 -0
  357. package/lib/utils/money/exchangeRate.mjs.map +1 -0
  358. package/lib/utils/money/format.d.ts +10 -5
  359. package/lib/utils/money/format.js +22 -14
  360. package/lib/utils/money/format.js.map +1 -1
  361. package/lib/utils/money/format.mjs +23 -16
  362. package/lib/utils/money/format.mjs.map +1 -1
  363. package/lib/utils/money/index.d.ts +4 -1
  364. package/lib/utils/money/index.js +26 -8
  365. package/lib/utils/money/index.js.map +1 -1
  366. package/lib/utils/money/index.mjs +8 -4
  367. package/lib/utils/money/index.mjs.map +1 -1
  368. package/lib/utils/money/misc.d.ts +68 -28
  369. package/lib/utils/money/misc.js +35 -64
  370. package/lib/utils/money/misc.js.map +1 -1
  371. package/lib/utils/money/misc.mjs +32 -43
  372. package/lib/utils/money/misc.mjs.map +1 -1
  373. package/lib/utils/money/misc.private.d.ts +23 -0
  374. package/lib/utils/money/misc.private.js +46 -0
  375. package/lib/utils/money/misc.private.js.map +1 -0
  376. package/lib/utils/money/misc.private.mjs +21 -0
  377. package/lib/utils/money/misc.private.mjs.map +1 -0
  378. package/lib/utils/money/shipping.d.ts +5 -0
  379. package/lib/utils/money/shipping.js +8 -0
  380. package/lib/utils/money/shipping.js.map +1 -0
  381. package/lib/utils/money/shipping.mjs +6 -0
  382. package/lib/utils/money/shipping.mjs.map +1 -0
  383. package/lib/utils/money/tax.d.ts +38 -2
  384. package/lib/utils/money/tax.js +46 -10
  385. package/lib/utils/money/tax.js.map +1 -1
  386. package/lib/utils/money/tax.mjs +42 -11
  387. package/lib/utils/money/tax.mjs.map +1 -1
  388. package/lib/utils/money/tax.private.d.ts +17 -0
  389. package/lib/utils/money/tax.private.js +65 -0
  390. package/lib/utils/money/tax.private.js.map +1 -0
  391. package/lib/utils/money/tax.private.mjs +60 -0
  392. package/lib/utils/money/tax.private.mjs.map +1 -0
  393. package/lib/utils/money/types.d.ts +78 -3
  394. package/lib/utils/number.d.ts +1 -1
  395. package/lib/utils/number.js +1 -1
  396. package/lib/utils/number.js.map +1 -1
  397. package/lib/utils/number.mjs +1 -1
  398. package/lib/utils/number.mjs.map +1 -1
  399. package/lib/utils/productSort.d.ts +41 -0
  400. package/lib/utils/productSort.js +67 -0
  401. package/lib/utils/productSort.js.map +1 -0
  402. package/lib/utils/productSort.mjs +60 -0
  403. package/lib/utils/productSort.mjs.map +1 -0
  404. package/package.json +1 -1
  405. package/lib/assets/icons/menu/icon-globe.svg.js.map +0 -1
  406. package/lib/assets/icons/menu/icon-globe.svg.mjs +0 -3
  407. package/lib/assets/icons/menu/icon-globe.svg.mjs.map +0 -1
  408. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +0 -1
  409. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +0 -1
  410. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +0 -1
  411. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +0 -1
  412. package/lib/components/ResourceCalculatorV1/components/index.d.ts +0 -1
  413. package/lib/components/ResourceCalculatorV1/components/index.js +0 -5
  414. package/lib/components/ResourceCalculatorV1/components/index.mjs +0 -3
  415. package/lib/utils/validations.d.ts +0 -15
  416. package/lib/utils/validations.js +0 -23
  417. package/lib/utils/validations.js.map +0 -1
  418. package/lib/utils/validations.mjs +0 -21
  419. package/lib/utils/validations.mjs.map +0 -1
  420. /package/lib/components/{ResourceCalculatorV1/components → Header/Navigation/ProMenu}/index.mjs.map +0 -0
  421. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.d.ts +0 -0
  422. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.js +0 -0
  423. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.js.map +0 -0
  424. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.mjs +0 -0
  425. /package/lib/components/{ResourceCalculatorV1/components/HorizontalOptionSelect → HorizontalOptionSelect}/index.mjs.map +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productAmount.mjs","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAASC,YAAA,CAAA,IAAA,EAAAV,UAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAAT,SAAA,CAAA;IAKT;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAIA;IAAA;IAAA;IAAAD,YAAA,CAAA,IAAA,EAAAR,SAAA,CAAA;IACAQ,YAAA,CAAA,IAAA,EAAAP,eAAA,CAAA;IACAO,YAAA,CAAA,IAAA,EAAAN,cAAA,CAAA;IACAM,YAAA,CAAA,IAAA,EAAAL,IAAA,CAAA;IACAK,YAAA,CAAA,IAAA,EAAAJ,MAAA,CAAA;IAGE,MAAMM,WAAWH,cAAe,CAAAG,QAAA;IAK1B,MAAAC,kBAAA,GACJJ,cAAe,CAAAK,SAAA,GAAYL,cAAe,CAAAM,QAAA;IAE5CC,YAAA,CAAA,IAAA,EAAKhB,YAAaS,cAAe,CAAAK,SAAA,CAAA;IACjCE,YAAA,CAAA,IAAA,EAAKf,SAAY,EAAAW,QAAA,CAAA;IACjB,IAAA,CAAKG,WAAWN,cAAe,CAAAM,QAAA;IAC1BC,YAAA,CAAA,IAAA,EAAAd,SAAA,EAAY,IAAIe,oBAAqB,CAAA;MACxCC,uBAAuBT,cAAe,CAAAU,QAAA;MACtCC,kBAAoB,EAAAP,kBAAA;MACpBD;IACD,CAAA,CAAA,CAAA;IACII,YAAA,CAAA,IAAA,EAAAb,eAAA,EAAkB,IAAIc,oBAAqB,CAAA;MAC9CC,uBAAuBT,cAAe,CAAAY,cAAA;MACt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,CACdD,YAAK,CAAA,IAAA,EAAA3B,eAAA,CAAA,CAAgB6B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CACjE,CAAA;MACAqB,aAAe,EAAAS,MAAA,CACbD,YAAK,CAAA,IAAA,EAAA1B,cAAA,CAAA,CAAe4B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CAChE,CAAA;MACAsB,GAAA,EAAKQ,OAAOD,YAAK,CAAA,IAAA,EAAAzB,IAAA,CAAA,CAAK2B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC,CAAA;MACjEuB,KAAA,EAAOO,OAAOD,YAAK,CAAA,IAAA,EAAAxB,MAAA,CAAA,CAAO0B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC;IAAA,CACvE;EACF;AACF;AApFWD,UAAA,GAAA,IAAAiC,OAAA,CAAA,CAAA;AACAhC,SAAA,GAAA,IAAAgC,OAAA,CAAA,CAAA;AAST/B,SAAA,GAAA,IAAA+B,OAAA,CAAA,CAAA;AACA9B,eAAA,GAAA,IAAA8B,OAAA,CAAA,CAAA;AACA7B,cAAA,GAAA,IAAA6B,OAAA,CAAA,CAAA;AACA5B,IAAA,GAAA,IAAA4B,OAAA,CAAA,CAAA;AACA3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
@@ -1,37 +1,68 @@
1
- import { Currency } from "../../types";
2
- import type { CurrencyObj } from "./types";
1
+ import { Currency, StoreId } from "../../types";
2
+ import type { LocalizedCurrency, RoundingFn } from "./types";
3
+ export declare const Round: {
4
+ /**
5
+ * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
6
+ * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
7
+ * normalise the values so we use this method.
8
+ *
9
+ * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
10
+ * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
11
+ * @see
12
+ *
13
+ * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
14
+ * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
15
+ * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
16
+ * https://youtu.be/yuRdYlZvs1E
17
+ *
18
+ * If you really want to get knee-deep in the rounding subject, you can read the following:
19
+ * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
20
+ */
21
+ Financial: import("@dinero.js/core").RoundingMode;
22
+ Shipping: import("@dinero.js/core").RoundingMode;
23
+ Prettify: import("@dinero.js/core").RoundingMode;
24
+ Subunit: import("@dinero.js/core").RoundingMode;
25
+ };
3
26
  /**
4
27
  * Mapping of how prices should be rounded down to "whole numbers" after certain threshold
5
28
  */
6
29
  export declare const prettifyPriceLookup: Map<string, number>;
7
30
  /**
8
- * Map of currencycode to subunit digit count.
31
+ * Map of dinero code to subunit digit count.
9
32
  */
10
- export declare const smallestSubunitLookup: Map<string, [number, (value: number) => number]>;
33
+ export declare const smallestSubunitLookup: Map<string, [number, RoundingFn]>;
11
34
  /**
12
- * Mapping of maximum price filter
13
- * TODO: Add all possible currencies
35
+ * Precompiled list for faster currency and locale lookups
14
36
  */
15
- export declare const maximumPriceFilterLookup: Map<string, number>;
37
+ export declare const localizedCurrencyLookup: Map<Currency, LocalizedCurrency>;
16
38
  /**
17
- * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
18
- * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
19
- * normalise the values so we use this method.
20
- *
21
- * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
22
- * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
23
- * @see
24
- *
25
- * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
26
- * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
27
- * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
28
- * https://youtu.be/yuRdYlZvs1E
29
- *
30
- * If you really want to get knee-deep in the rounding subject, you can read the following:
31
- * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
39
+ * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a
40
+ * single line. Rest of the stores inherit default behavior that tax calculated on whole line item
32
41
  */
33
- export declare const financialRound: import("@dinero.js/core").RoundingMode;
42
+ export declare const storesWithPerItemTaxRate: Set<StoreId>;
34
43
  /**
35
- * Precompiled list for faster currency and locale lookups
44
+ * Dinero currency option block for working with tax rates within dinero
36
45
  */
37
- export declare const currencyObjLookup: Map<Currency, CurrencyObj>;
46
+ export declare const TAX_RATE_DINERO_CURRENCY: {
47
+ base: number;
48
+ /**
49
+ * We expect the tax rate to be in the range of 0..1
50
+ * 0 --> 0%
51
+ * 1 --> 100%
52
+ * 0.21 --> 21%
53
+ * 0.2169 --> 21.69%
54
+ * 0.12345678 --> 12.345678%
55
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
56
+ */
57
+ exponent: number;
58
+ code: string;
59
+ };
60
+ export declare const EXCHANGE_RATE_DINERO_CURRENCY: {
61
+ base: number;
62
+ /**
63
+ * We support having certain decimal places for exchange rates
64
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
65
+ */
66
+ exponent: number;
67
+ code: string;
68
+ };
@@ -5,6 +5,33 @@ var dinero_js = require('dinero.js');
5
5
  require('../../types/index.js');
6
6
  var generated = require('../../types/generated.js');
7
7
  "use strict";
8
+ const Round = {
9
+ /**
10
+ * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
11
+ * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
12
+ * normalise the values so we use this method.
13
+ *
14
+ * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
15
+ * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
16
+ * @see
17
+ *
18
+ * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
19
+ * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
20
+ * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
21
+ * https://youtu.be/yuRdYlZvs1E
22
+ *
23
+ * If you really want to get knee-deep in the rounding subject, you can read the following:
24
+ * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
25
+ */
26
+ Financial: dinero_js.halfEven,
27
+ // TODO: maybe we should have separate rounding functions depending on the input value?
28
+ // Reading from wiki "Round half toward zero" is better if the value is already "normalized to cents"
29
+ // But the "Round half to even" seems better for when working with float like values
30
+ // financialRound = Math.round;
31
+ Shipping: dinero_js.down,
32
+ Prettify: dinero_js.down,
33
+ Subunit: dinero_js.halfUp
34
+ };
8
35
  const prettifyPriceLookup = /* @__PURE__ */new Map([[currencies.USD.code, 20], [currencies.CAD.code, 20], [currencies.EUR.code, 20], [currencies.GBP.code, 20], [currencies.AED.code, 50],
9
36
  // Approximately every price above ~1.1 usd will be rounded in ZAR
10
37
  [currencies.ZAR.code, 20]]);
@@ -12,10 +39,8 @@ const smallestSubunitLookup = /* @__PURE__ */new Map([
12
39
  /**
13
40
  * TWD does not use subunits at all in day to day transactions.
14
41
  */
15
- [currencies.TWD.code, [0, dinero_js.halfUp]]]);
16
- const maximumPriceFilterLookup = /* @__PURE__ */new Map([[currencies.CAD.code, 7e4], [currencies.EUR.code, 7e4], [currencies.AED.code, 7e4]]);
17
- const financialRound = dinero_js.halfEven;
18
- const currencyObjLookup = /* @__PURE__ */new Map([[generated.Currency.Aed, {
42
+ [currencies.TWD.code, [0, Round.Subunit]]]);
43
+ const localizedCurrencyLookup = /* @__PURE__ */new Map([[generated.Currency.Aed, {
19
44
  currency: currencies.AED,
20
45
  locale: "ar-AE"
21
46
  }], [generated.Currency.Bgn, {
@@ -86,9 +111,49 @@ const currencyObjLookup = /* @__PURE__ */new Map([[generated.Currency.Aed, {
86
111
  currency: currencies.MXN,
87
112
  locale: "es-MX"
88
113
  }]]);
89
- exports.currencyObjLookup = currencyObjLookup;
90
- exports.financialRound = financialRound;
91
- exports.maximumPriceFilterLookup = maximumPriceFilterLookup;
114
+ const storesWithPerItemTaxRate = /* @__PURE__ */new Set([
115
+ // #############################################################################
116
+ // Stores with custom tax rates
117
+ // #############################################################################
118
+ generated.StoreId.Br, generated.StoreId.Tw
119
+ // #############################################################################
120
+ // Stores with Avalara, but will have custom company codes to treat
121
+ // FIXME: as PR is rushed we where able to test stores avalara custom codes that enable logic that calculates tax
122
+ // "per quantity", so for now disabling this logic and only applying to store with custom tax rates
123
+ // #############################################################################
124
+ // StoreId.Jp,
125
+ // StoreId.Sg,
126
+ ]);
127
+ const TAX_RATE_DINERO_CURRENCY = {
128
+ base: 10,
129
+ /**
130
+ * We expect the tax rate to be in the range of 0..1
131
+ * 0 --> 0%
132
+ * 1 --> 100%
133
+ * 0.21 --> 21%
134
+ * 0.2169 --> 21.69%
135
+ * 0.12345678 --> 12.345678%
136
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
137
+ */
138
+ exponent: 8,
139
+ code: ""
140
+ // Not important
141
+ };
142
+ const EXCHANGE_RATE_DINERO_CURRENCY = {
143
+ base: 10,
144
+ /**
145
+ * We support having certain decimal places for exchange rates
146
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
147
+ */
148
+ exponent: 6,
149
+ code: ""
150
+ // Not important
151
+ };
152
+ exports.EXCHANGE_RATE_DINERO_CURRENCY = EXCHANGE_RATE_DINERO_CURRENCY;
153
+ exports.Round = Round;
154
+ exports.TAX_RATE_DINERO_CURRENCY = TAX_RATE_DINERO_CURRENCY;
155
+ exports.localizedCurrencyLookup = localizedCurrencyLookup;
92
156
  exports.prettifyPriceLookup = prettifyPriceLookup;
93
157
  exports.smallestSubunitLookup = smallestSubunitLookup;
158
+ exports.storesWithPerItemTaxRate = storesWithPerItemTaxRate;
94
159
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { halfEven, halfUp } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport type { CurrencyObj } from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of currencycode to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<\n string,\n [number, (value: number) => number]\n>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, halfUp]],\n]);\n\n/**\n * Mapping of maximum price filter\n * TODO: Add all possible currencies\n */\nexport const maximumPriceFilterLookup = new Map([\n [CAD.code, 70000],\n [EUR.code, 70000],\n [AED.code, 70000],\n]);\n\n/**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\nexport const financialRound = halfEven;\n// TODO: maybe we should have separate rounding functions depending on the input value?\n// Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n// But the \"Round half to even\" seems better for when working with float like values\n// export const financialRound = Math.round;\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const currencyObjLookup = new Map<Currency, CurrencyObj>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n"],"names":["prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","halfUp","maximumPriceFilterLookup","financialRound","halfEven","currencyObjLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN"],"mappings":";;;;;;;AAoCa,MAAAA,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,UAAI,CAAAA,GAAA,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,UAAI,CAAAA,GAAA,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,UAAI,CAAAA,GAAA,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,UAAI,CAAAA,GAAA,CAAAH,IAAA,EAAM,EAAE,CAAA,EACb,CAACI,UAAI,CAAAA,GAAA,CAAAJ,IAAA,EAAM,EAAE,CAAA;AAAA;AAEb,CAACK,UAAI,CAAAA,GAAA,CAAAL,IAAA,EAAM,EAAE,CAAA,CACd,CAAA;AAKY,MAAAM,qBAAA,GAAA,mBAA4BR,GAGvC,CAAA;AAAA;AAAA;AAAA;AAIA,CAACS,UAAI,CAAAA,GAAA,CAAAP,IAAA,EAAM,CAAC,CAAA,EAAGQ,SAAM,CAAAA,MAAA,CAAC,CAAA,CACvB,CAAA;AAMY,MAAAC,wBAAA,GAAA,mBAA+BX,GAAI,CAAA,CAC9C,CAACG,UAAI,CAAAA,GAAA,CAAAD,IAAA,EAAM,GAAK,CAAA,EAChB,CAACE,UAAI,CAAAA,GAAA,CAAAF,IAAA,EAAM,GAAK,CAAA,EAChB,CAACI,UAAI,CAAAA,GAAA,CAAAJ,IAAA,EAAM,GAAK,CAAA,C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AEnC,UAAUR,UAAAA,CAAAA,GAAK;EAAAS,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAASsC,GAAK,EAAA;EAAEpC,UAAUqC,UAAAA,CAAAA,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;;;;;"}
1
+ {"version":3,"file":"constants.js","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfEven, halfUp } from \"dinero.js\";\n\nimport { Currency, StoreId } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\nexport const Round = {\n /**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\n Financial: halfEven,\n // TODO: maybe we should have separate rounding functions depending on the input value?\n // Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n // But the \"Round half to even\" seems better for when working with float like values\n // financialRound = Math.round;\n Shipping: down,\n Prettify: down,\n Subunit: halfUp,\n} satisfies Record<string, RoundingFn>;\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of dinero code to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<string, [Cents, RoundingFn]>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, Round.Subunit]],\n]);\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const localizedCurrencyLookup = new Map<Currency, LocalizedCurrency>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n\n// #############################################################################\n// Tax Rate\n// #############################################################################\n/**\n * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a\n * single line. Rest of the stores inherit default behavior that tax calculated on whole line item\n */\nexport const storesWithPerItemTaxRate = new Set([\n // #############################################################################\n // Stores with custom tax rates\n // #############################################################################\n StoreId.Br,\n StoreId.Tw,\n // #############################################################################\n // Stores with Avalara, but will have custom company codes to treat\n // FIXME: as PR is rushed we where able to test stores avalara custom codes that enable logic that calculates tax\n // \"per quantity\", so for now disabling this logic and only applying to store with custom tax rates\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n]);\n\n/**\n * Dinero currency option block for working with tax rates within dinero\n */\nexport const TAX_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We expect the tax rate to be in the range of 0..1\n * 0 --> 0%\n * 1 --> 100%\n * 0.21 --> 21%\n * 0.2169 --> 21.69%\n * 0.12345678 --> 12.345678%\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 8,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n\n// #############################################################################\n// Exchange Rate\n// #############################################################################\n\nexport const EXCHANGE_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We support having certain decimal places for exchange rates\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 6,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n"],"names":["Round","Financial","halfEven","Shipping","down","Prettify","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN","storesWithPerItemTaxRate","Set","StoreId","Br","Tw","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;;;AAsCO,MAAMA,KAAQ,GAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAkBnBC,SAAW,EAAAC,SAAA,CAAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAKXC,QAAU,EAAAC,SAAA,CAAAA,IAAA;EACVC,QAAU,EAAAD,SAAA,CAAAA,IAAA;EACVE,OAAS,EAAAC,SAAA,CAAAA;AACX,CAAA;AAKa,MAAAC,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,UAAI,CAAAA,GAAA,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,UAAI,CAAAA,GAAA,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,UAAI,CAAAA,GAAA,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,UAAI,CAAAA,GAAA,CAAAH,IAAA,EAAM,EAAE,CAAA,EACb,CAACI,UAAI,CAAAA,GAAA,CAAAJ,IAAA,EAAM,EAAE,CAAA;AAAA;AAEb,CAACK,UAAI,CAAAA,GAAA,CAAAL,IAAA,EAAM,EAAE,CAAA,CACd,CAAA;AAKY,MAAAM,qBAAA,GAAA,mBAA4BR,GAAiC,CAAA;AAAA;AAAA;AAAA;AAIxE,CAACS,UAAAA,CAAAA,GAAI,CAAAP,IAAA,EAAM,CAAC,CAAG,EAAAX,KAAA,CAAMM,OAAO,CAAC,CAAA,CAC9B,CAAA;AAKY,MAAAa,uBAAA,GAAA,mBAA8BV,GAAiC,CAAA,CAC1E,CAACW,SAAAA,CAAAA,SA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AAA,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;AASY,MAAAqC,wBAAA,GAAA,mBAA+BC,GAAI,CAAA;AAAA;AAAA;AAAA;AAI9CC,SAAAA,CAAAA,OAAQ,CAAAC,EAAA,EACRD,SAAAA,CAAAA,OAAQ,CAAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAQT,CAAA;AAKM,MAAMC,wBAA2B,GAAA;EACtCC,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVxD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAMyD,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVxD,IAAM,EAAA;EAAA;AACR,CAAA;;;;;;;"}
@@ -1,8 +1,35 @@
1
1
  import { USD, CAD, EUR, GBP, AED, ZAR, TWD, BGN, CHF, CZK, DKK, HRK, HUF, NOK, PLN, RON, SEK, INR, SGD, BRL, JPY, MXN } from '@dinero.js/currencies';
2
- import { halfUp, halfEven } from 'dinero.js';
2
+ import { halfEven, down, halfUp } from 'dinero.js';
3
3
  import '../../types/index.mjs';
4
- import { Currency } from '../../types/generated.mjs';
4
+ import { Currency, StoreId } from '../../types/generated.mjs';
5
5
  "use strict";
6
+ const Round = {
7
+ /**
8
+ * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
9
+ * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
10
+ * normalise the values so we use this method.
11
+ *
12
+ * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
13
+ * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
14
+ * @see
15
+ *
16
+ * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
17
+ * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
18
+ * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
19
+ * https://youtu.be/yuRdYlZvs1E
20
+ *
21
+ * If you really want to get knee-deep in the rounding subject, you can read the following:
22
+ * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
23
+ */
24
+ Financial: halfEven,
25
+ // TODO: maybe we should have separate rounding functions depending on the input value?
26
+ // Reading from wiki "Round half toward zero" is better if the value is already "normalized to cents"
27
+ // But the "Round half to even" seems better for when working with float like values
28
+ // financialRound = Math.round;
29
+ Shipping: down,
30
+ Prettify: down,
31
+ Subunit: halfUp
32
+ };
6
33
  const prettifyPriceLookup = /* @__PURE__ */new Map([[USD.code, 20], [CAD.code, 20], [EUR.code, 20], [GBP.code, 20], [AED.code, 50],
7
34
  // Approximately every price above ~1.1 usd will be rounded in ZAR
8
35
  [ZAR.code, 20]]);
@@ -10,10 +37,8 @@ const smallestSubunitLookup = /* @__PURE__ */new Map([
10
37
  /**
11
38
  * TWD does not use subunits at all in day to day transactions.
12
39
  */
13
- [TWD.code, [0, halfUp]]]);
14
- const maximumPriceFilterLookup = /* @__PURE__ */new Map([[CAD.code, 7e4], [EUR.code, 7e4], [AED.code, 7e4]]);
15
- const financialRound = halfEven;
16
- const currencyObjLookup = /* @__PURE__ */new Map([[Currency.Aed, {
40
+ [TWD.code, [0, Round.Subunit]]]);
41
+ const localizedCurrencyLookup = /* @__PURE__ */new Map([[Currency.Aed, {
17
42
  currency: AED,
18
43
  locale: "ar-AE"
19
44
  }], [Currency.Bgn, {
@@ -84,5 +109,43 @@ const currencyObjLookup = /* @__PURE__ */new Map([[Currency.Aed, {
84
109
  currency: MXN,
85
110
  locale: "es-MX"
86
111
  }]]);
87
- export { currencyObjLookup, financialRound, maximumPriceFilterLookup, prettifyPriceLookup, smallestSubunitLookup };
112
+ const storesWithPerItemTaxRate = /* @__PURE__ */new Set([
113
+ // #############################################################################
114
+ // Stores with custom tax rates
115
+ // #############################################################################
116
+ StoreId.Br, StoreId.Tw
117
+ // #############################################################################
118
+ // Stores with Avalara, but will have custom company codes to treat
119
+ // FIXME: as PR is rushed we where able to test stores avalara custom codes that enable logic that calculates tax
120
+ // "per quantity", so for now disabling this logic and only applying to store with custom tax rates
121
+ // #############################################################################
122
+ // StoreId.Jp,
123
+ // StoreId.Sg,
124
+ ]);
125
+ const TAX_RATE_DINERO_CURRENCY = {
126
+ base: 10,
127
+ /**
128
+ * We expect the tax rate to be in the range of 0..1
129
+ * 0 --> 0%
130
+ * 1 --> 100%
131
+ * 0.21 --> 21%
132
+ * 0.2169 --> 21.69%
133
+ * 0.12345678 --> 12.345678%
134
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
135
+ */
136
+ exponent: 8,
137
+ code: ""
138
+ // Not important
139
+ };
140
+ const EXCHANGE_RATE_DINERO_CURRENCY = {
141
+ base: 10,
142
+ /**
143
+ * We support having certain decimal places for exchange rates
144
+ * !!! Don't change as this value is tied to store.backend DB schema !!!
145
+ */
146
+ exponent: 6,
147
+ code: ""
148
+ // Not important
149
+ };
150
+ export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, smallestSubunitLookup, storesWithPerItemTaxRate };
88
151
  //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { halfEven, halfUp } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport type { CurrencyObj } from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of currencycode to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<\n string,\n [number, (value: number) => number]\n>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, halfUp]],\n]);\n\n/**\n * Mapping of maximum price filter\n * TODO: Add all possible currencies\n */\nexport const maximumPriceFilterLookup = new Map([\n [CAD.code, 70000],\n [EUR.code, 70000],\n [AED.code, 70000],\n]);\n\n/**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\nexport const financialRound = halfEven;\n// TODO: maybe we should have separate rounding functions depending on the input value?\n// Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n// But the \"Round half to even\" seems better for when working with float like values\n// export const financialRound = Math.round;\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const currencyObjLookup = new Map<Currency, CurrencyObj>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n"],"names":["prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","halfUp","maximumPriceFilterLookup","financialRound","halfEven","currencyObjLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN"],"mappings":";;;;;AAoCa,MAAAA,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,GAAI,CAA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A;AAEjD,CAACH,SAASqC,GAAK,EAAA;EAAEnC,UAAUR,GAAK;EAAAS,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAASsC,GAAK,EAAA;EAAEpC,UAAUqC,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;"}
1
+ {"version":3,"file":"constants.mjs","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfEven, halfUp } from \"dinero.js\";\n\nimport { Currency, StoreId } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\nexport const Round = {\n /**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\n Financial: halfEven,\n // TODO: maybe we should have separate rounding functions depending on the input value?\n // Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n // But the \"Round half to even\" seems better for when working with float like values\n // financialRound = Math.round;\n Shipping: down,\n Prettify: down,\n Subunit: halfUp,\n} satisfies Record<string, RoundingFn>;\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of dinero code to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<string, [Cents, RoundingFn]>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, Round.Subunit]],\n]);\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const localizedCurrencyLookup = new Map<Currency, LocalizedCurrency>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n\n// #############################################################################\n// Tax Rate\n// #############################################################################\n/**\n * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a\n * single line. Rest of the stores inherit default behavior that tax calculated on whole line item\n */\nexport const storesWithPerItemTaxRate = new Set([\n // #############################################################################\n // Stores with custom tax rates\n // #############################################################################\n StoreId.Br,\n StoreId.Tw,\n // #############################################################################\n // Stores with Avalara, but will have custom company codes to treat\n // FIXME: as PR is rushed we where able to test stores avalara custom codes that enable logic that calculates tax\n // \"per quantity\", so for now disabling this logic and only applying to store with custom tax rates\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n]);\n\n/**\n * Dinero currency option block for working with tax rates within dinero\n */\nexport const TAX_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We expect the tax rate to be in the range of 0..1\n * 0 --> 0%\n * 1 --> 100%\n * 0.21 --> 21%\n * 0.2169 --> 21.69%\n * 0.12345678 --> 12.345678%\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 8,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n\n// #############################################################################\n// Exchange Rate\n// #############################################################################\n\nexport const EXCHANGE_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We support having certain decimal places for exchange rates\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 6,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n"],"names":["Round","Financial","halfEven","Shipping","down","Prettify","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN","storesWithPerItemTaxRate","Set","StoreId","Br","Tw","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;AAsCO,MAAMA,KAAQ,GAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAkBnBC,SAAW,EAAAC,QAAA;EAAA;EAAA;EAAA;EAAA;EAKXC,QAAU,EAAAC,IAAA;EACVC,QAAU,EAAAD,IAAA;EACVE,OAAS,EAAAC;AACX,CAAA;AAKa,MAAAC,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,GAAI,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,GAAI,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,GAAI,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,GAAI,CAAAH,IAAA,EAAM,EAAE,CAAA,EACb,CAACI,GAAI,CAAAJ,IAAA,EAAM,EAAE,CAAA;AAAA;AAEb,CAACK,GAAI,CAAAL,IAAA,EAAM,EAAE,CAAA,CACd,CAAA;AAKY,MAAAM,qBAAA,GAAA,mBAA4BR,GAAiC,CAAA;AAAA;AAAA;AAAA;AAIxE,CAACS,GAAI,CAAAP,IAAA,EAAM,CAAC,CAAG,EAAAX,KAAA,CAAMM,OAAO,CAAC,CAAA,CAC9B,CAAA;AAKY,MAAAa,uBAAA,GAAA,mBAA8BV,GAAiC,CAAA,CAC1E,CAACW,SAASC,GAAK,EAAA;EAAEC,UAAUP,GAAK;EAAAQ,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAASI,GAAK,EAAA;EAAEF,UAAUG,GAAK;EAAAF,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAASM,G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A3B,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAS+B,GAAK,EAAA;EAAE7B,UAAU8B,GAAK;EAAA7B,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAASiC,GAAK,EAAA;EAAE/B,UAAUgC,GAAK;EAAA/B,MAAA,EAAQ;CAAS,CAAA;AAAA;AAEjD,CAACH,SAASmC,GAAK,EAAA;EAAEjC,UAAUkC,GAAK;EAAAjC,MAAA,EAAQ;CAAS,CAAA;AAAA;AAEjD,CAACH,SAASqC,GAAK,EAAA;EAAEnC,UAAUJ,GAAK;EAAAK,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAASsC,GAAK,EAAA;EAAEpC,UAAUqC,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;AASY,MAAAqC,wBAAA,GAAA,mBAA+BC,GAAI,CAAA;AAAA;AAAA;AAAA;AAI9CC,OAAQ,CAAAC,EAAA,EACRD,OAAQ,CAAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAQT,CAAA;AAKM,MAAMC,wBAA2B,GAAA;EACtCC,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVxD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAMyD,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVxD,IAAM,EAAA;EAAA;AACR,CAAA;"}
@@ -0,0 +1,31 @@
1
+ import type { Cents, TaxRate } from "./types";
2
+ /**
3
+ * Parse exchange rate to dinero friendly amount and scale.
4
+ *
5
+ * Used to prepare exchange rate for sending over API.
6
+ *
7
+ * @example
8
+ * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}
9
+ */
10
+ export declare const toSnapshotExchangeRate: (exchangeRate: TaxRate) => {
11
+ amount: Cents;
12
+ scale: number;
13
+ };
14
+ /**
15
+ * Converts an arbitrary exchange rate to a fixed decimal place number.
16
+ *
17
+ * Used to take in an input and convert it for storage in the database.
18
+ *
19
+ * @example
20
+ * toFixedExchangeRate("0.123456789") // "0.123457"
21
+ * toFixedExchangeRate("0.123456789", true) // 0.123457
22
+ */
23
+ export declare function toFixedExchangeRate(rate: string | number, asNumber?: boolean): string;
24
+ export declare function toFixedExchangeRate(rate: string | number, asNumber: true): number;
25
+ /**
26
+ * Invert an exchange rate by doing 1 / rate
27
+ * Used to fake a reverse exchange rate in case we don't have it
28
+ * @example
29
+ * invertExchangeRate("0.22") // "4.545455"
30
+ */
31
+ export declare function invertExchangeRate(rate: string | number): string;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var errors = require('../errors.js');
4
+ var number = require('../number.js');
5
+ var constants = require('./constants.js');
6
+ var misc_private = require('./misc.private.js');
7
+ "use strict";
8
+ const toSnapshotExchangeRate = exchangeRate => {
9
+ number.isFloat(exchangeRate, "Exchange rate");
10
+ errors.assert(exchangeRate > 0, "Exchange rate must be greater than 0");
11
+ const rateInt = misc_private.floatToInt(exchangeRate, constants.EXCHANGE_RATE_DINERO_CURRENCY.base, constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent);
12
+ return {
13
+ amount: rateInt,
14
+ scale: constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent
15
+ };
16
+ };
17
+ function toFixedExchangeRate(rate, asNumber) {
18
+ return number.toFixedRate(typeof rate === "string" ? +rate : rate, constants.EXCHANGE_RATE_DINERO_CURRENCY.exponent, asNumber);
19
+ }
20
+ function invertExchangeRate(rate) {
21
+ const exchangeRate = toFixedExchangeRate(rate, true);
22
+ return toFixedExchangeRate(1 / exchangeRate, false);
23
+ }
24
+ exports.invertExchangeRate = invertExchangeRate;
25
+ exports.toFixedExchangeRate = toFixedExchangeRate;
26
+ exports.toSnapshotExchangeRate = toSnapshotExchangeRate;
27
+ //# sourceMappingURL=exchangeRate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchangeRate.js","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\nimport type { Cents, TaxRate } from \"./types\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: TaxRate,\n): {\n amount: Cents;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,cAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAAA,CAAAA,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,YAAA,CAAAA,UAAA,CACdJ,YAAA,EACAK,SAAAA,CAAAA,6BAA8B,CAAAC,IAAA,EAC9BD,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,CAChC;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,SAA8B,CAAAA,6BAAA,CAAAE;EAAA,CACvC;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,MAAA,CAAAA,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,SAAAA,CAAAA,6BAA8B,CAAAE,QAAA,EAC9BK,QAAA,CACF;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;;;"}
@@ -0,0 +1,23 @@
1
+ import { assert } from '../errors.mjs';
2
+ import { isFloat, toFixedRate } from '../number.mjs';
3
+ import { EXCHANGE_RATE_DINERO_CURRENCY } from './constants.mjs';
4
+ import { floatToInt } from './misc.private.mjs';
5
+ "use strict";
6
+ const toSnapshotExchangeRate = exchangeRate => {
7
+ isFloat(exchangeRate, "Exchange rate");
8
+ assert(exchangeRate > 0, "Exchange rate must be greater than 0");
9
+ const rateInt = floatToInt(exchangeRate, EXCHANGE_RATE_DINERO_CURRENCY.base, EXCHANGE_RATE_DINERO_CURRENCY.exponent);
10
+ return {
11
+ amount: rateInt,
12
+ scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent
13
+ };
14
+ };
15
+ function toFixedExchangeRate(rate, asNumber) {
16
+ return toFixedRate(typeof rate === "string" ? +rate : rate, EXCHANGE_RATE_DINERO_CURRENCY.exponent, asNumber);
17
+ }
18
+ function invertExchangeRate(rate) {
19
+ const exchangeRate = toFixedExchangeRate(rate, true);
20
+ return toFixedExchangeRate(1 / exchangeRate, false);
21
+ }
22
+ export { invertExchangeRate, toFixedExchangeRate, toSnapshotExchangeRate };
23
+ //# sourceMappingURL=exchangeRate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchangeRate.mjs","sources":["../../../src/utils/money/exchangeRate.ts"],"sourcesContent":["import { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport { EXCHANGE_RATE_DINERO_CURRENCY } from \"./constants\";\nimport { floatToInt } from \"./misc.private\";\nimport type { Cents, TaxRate } from \"./types\";\n\n// FIXME: reconsider if needed her as only used in BE for exchange rate Graph other places in code use Float|number\n/**\n * Parse exchange rate to dinero friendly amount and scale.\n *\n * Used to prepare exchange rate for sending over API.\n *\n * @example\n * toSnapshotExchangeRate(0.22); // {amount: 22000, scale: 6}\n */\nexport const toSnapshotExchangeRate = (\n exchangeRate: TaxRate,\n): {\n amount: Cents;\n scale: number;\n} => {\n // Validate input\n isFloat(exchangeRate, \"Exchange rate\");\n assert(exchangeRate > 0, \"Exchange rate must be greater than 0\");\n\n // Get scale of exchange rate\n const rateInt = floatToInt(\n exchangeRate,\n EXCHANGE_RATE_DINERO_CURRENCY.base,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n );\n\n // Return dinero friendly amount and scale\n return {\n amount: rateInt,\n scale: EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n };\n};\n\n/**\n * Converts an arbitrary exchange rate to a fixed decimal place number.\n *\n * Used to take in an input and convert it for storage in the database.\n *\n * @example\n * toFixedExchangeRate(\"0.123456789\") // \"0.123457\"\n * toFixedExchangeRate(\"0.123456789\", true) // 0.123457\n */\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber: true,\n): number;\nexport function toFixedExchangeRate(\n rate: string | number,\n asNumber?: boolean,\n): string | number {\n // FIXME: Remove + but instead add proper parsing of the string --> number\n // https://stackoverflow.com/a/12862627/1378261\n return toFixedRate(\n typeof rate === \"string\" ? +rate : rate,\n EXCHANGE_RATE_DINERO_CURRENCY.exponent,\n asNumber,\n );\n}\n\n/**\n * Invert an exchange rate by doing 1 / rate\n * Used to fake a reverse exchange rate in case we don't have it\n * @example\n * invertExchangeRate(\"0.22\") // \"4.545455\"\n */\nexport function invertExchangeRate(rate: string | number) {\n const exchangeRate = toFixedExchangeRate(rate, true);\n return toFixedExchangeRate(1 / exchangeRate, false);\n}\n"],"names":["toSnapshotExchangeRate","exchangeRate","isFloat","assert","rateInt","floatToInt","EXCHANGE_RATE_DINERO_CURRENCY","base","exponent","amount","scale","toFixedExchangeRate","rate","asNumber","toFixedRate","invertExchangeRate"],"mappings":";;;;;AAea,MAAAA,sBAAA,GACXC,YAIG,IAAA;EAEHC,OAAA,CAAQD,cAAc,eAAe,CAAA;EAC9BE,MAAA,CAAAF,YAAA,GAAe,GAAG,sCAAsC,CAAA;EAG/D,MAAMG,OAAU,GAAAC,UAAA,CACdJ,YAAA,EACAK,6BAA8B,CAAAC,IAAA,EAC9BD,6BAA8B,CAAAE,QAAA,CAChC;EAGO,OAAA;IACLC,MAAQ,EAAAL,OAAA;IACRM,OAAOJ,6BAA8B,CAAAE;EAAA,CACvC;AACF,CAAA;AAmBgB,SAAAG,mBAAAA,CACdC,MACAC,QACiB,EAAA;EAGV,OAAAC,WAAA,CACL,OAAOF,IAAA,KAAS,QAAW,GAAA,CAACA,IAAO,GAAAA,IAAA,EACnCN,6BAA8B,CAAAE,QAAA,EAC9BK,QAAA,CACF;AACF;AAQO,SAASE,mBAAmBH,IAAuB,EAAA;EAClD,MAAAX,YAAA,GAAeU,mBAAoB,CAAAC,IAAA,EAAM,IAAI,CAAA;EAC5C,OAAAD,mBAAA,CAAoB,CAAI,GAAAV,YAAA,EAAc,KAAK,CAAA;AACpD;"}
@@ -1,11 +1,10 @@
1
- import type { Dinero } from "dinero.js";
2
1
  import type { Currency, Nullish } from "../../types";
3
- import type { Money } from "./misc";
4
- import type { CurrencyObj } from "./types";
5
- export declare const getCurrencyObj: (currencyCode: Nullish<Currency>) => CurrencyObj | undefined;
2
+ import type { Dino, LocalizedCurrency, Money } from "./types";
3
+ export declare const getLocalizedCurrency: (currencyCode: Nullish<Currency>) => LocalizedCurrency | undefined;
6
4
  export type FormatPriceOptions = {
7
5
  /**
8
6
  * Optionally remove trailing zeroes (only if all of them are 0)
7
+ * @default false
9
8
  * @example
10
9
  * "420,66 €" => "420,66 €"
11
10
  * "420,60 €" => "420,60 €"
@@ -18,6 +17,7 @@ export type FormatPriceOptions = {
18
17
  *
19
18
  * ! Only use for display purposes where monetary precision is not required!
20
19
  *
20
+ * @default false
21
21
  * @example
22
22
  * "420,66 €" => "420 €"
23
23
  * "420,60 €" => "420 €"
@@ -34,10 +34,15 @@ export type FormatPriceOptions = {
34
34
  * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,
35
35
  * just marked so it discourages usage of it)
36
36
  */
37
- export declare function formatPriceRaw(dineroObject: Dinero<number>, locale: string, options?: FormatPriceOptions): string;
37
+ export declare function formatPriceRaw(dinero: Dino, locale: string, options?: FormatPriceOptions): string;
38
38
  /**
39
39
  * Currency formatter based on dinero currency types and browser internationalizing functions
40
40
  *
41
41
  * In reality just a wrapper around `formatPriceRaw` that does the real formatting
42
42
  */
43
43
  export declare const formatPrice: (money: Money, options?: FormatPriceOptions) => string;
44
+ /**
45
+ * Prettify numbers depending on the currency using rounding down.
46
+ * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !
47
+ */
48
+ export declare const prettifyTotal: (total: Dino) => Dino;
@@ -1,10 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var dinero_js = require('dinero.js');
4
+ var errors = require('../errors.js');
4
5
  var constants = require('./constants.js');
6
+ var misc = require('./misc.js');
5
7
  "use strict";
6
- const getCurrencyObj = currencyCode => {
7
- return currencyCode ? constants.currencyObjLookup.get(currencyCode) : void 0;
8
+ const getLocalizedCurrency = currencyCode => {
9
+ return currencyCode ? constants.localizedCurrencyLookup.get(currencyCode) : void 0;
8
10
  };
9
11
  const currencyFormatterCache = /* @__PURE__ */new Map();
10
12
  const getCurrencyFormatter = (locale, currencyCode) => {
@@ -17,7 +19,7 @@ const getCurrencyFormatter = (locale, currencyCode) => {
17
19
  style: "currency",
18
20
  currency: currencyCode,
19
21
  /**
20
- * Explicitly define default behaviour - just in case some runtime overrides it
22
+ * Explicitly define default behavior - just in case some runtime overrides it
21
23
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign
22
24
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay
23
25
  */
@@ -27,8 +29,8 @@ const getCurrencyFormatter = (locale, currencyCode) => {
27
29
  currencyFormatterCache.set(cacheKey, formatter);
28
30
  return formatter;
29
31
  };
30
- function formatPriceRaw(dineroObject, locale, options) {
31
- return dinero_js.toFormat(dineroObject, ({
32
+ function formatPriceRaw(dinero, locale, options) {
33
+ return dinero_js.toFormat(dinero, ({
32
34
  amount,
33
35
  currency
34
36
  }) => {
@@ -51,17 +53,23 @@ function formatPriceRaw(dineroObject, locale, options) {
51
53
  });
52
54
  }
53
55
  const formatPrice = (money, options) => {
54
- const currencyObj = getCurrencyObj(money.currency);
55
- if (!currencyObj) {
56
- throw new Error(`Currency ${money.currency} not supported`);
56
+ const localizedCurrency = getLocalizedCurrency(money.currency);
57
+ errors.assert(!!localizedCurrency, `Currency ${money.currency} not supported`);
58
+ return formatPriceRaw(misc.getDinero(money.amount, money.currency), localizedCurrency.locale, options);
59
+ };
60
+ const prettifyTotal = total => {
61
+ if (!dinero_js.hasSubUnits(total)) {
62
+ return total;
57
63
  }
58
- const d = dinero_js.dinero({
59
- amount: money.amount,
60
- currency: currencyObj.currency
61
- });
62
- return formatPriceRaw(d, currencyObj.locale, options);
64
+ const totalJson = total.toJSON();
65
+ const minValueInclusiveToRoundDownFrom = constants.prettifyPriceLookup.get(totalJson.currency.code);
66
+ if (minValueInclusiveToRoundDownFrom == null || dinero_js.toUnit(total) < minValueInclusiveToRoundDownFrom) {
67
+ return total;
68
+ }
69
+ return misc.roundDinero(total, constants.Round.Prettify);
63
70
  };
64
71
  exports.formatPrice = formatPrice;
65
72
  exports.formatPriceRaw = formatPriceRaw;
66
- exports.getCurrencyObj = getCurrencyObj;
73
+ exports.getLocalizedCurrency = getLocalizedCurrency;
74
+ exports.prettifyTotal = prettifyTotal;
67
75
  //# sourceMappingURL=format.js.map