@ubnt/store.core 10.10.3 → 10.11.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (498) hide show
  1. package/CHANGELOG.md +281 -19
  2. package/lib/assets/ai-360.jpg +0 -0
  3. package/lib/assets/ai-3602.jpg +0 -0
  4. package/lib/assets/ai-theta2.jpg +0 -0
  5. package/lib/assets/ai-theta3.jpg +0 -0
  6. package/lib/assets/attention.svg +5 -5
  7. package/lib/assets/attention2.svg +5 -5
  8. package/lib/assets/building-bridge.jpg +0 -0
  9. package/lib/assets/building-bridge2.jpg +0 -0
  10. package/lib/assets/compact.svg +2 -2
  11. package/lib/assets/compact3.svg +2 -2
  12. package/lib/assets/crestron.svg +3 -0
  13. package/lib/assets/door-hub.jpg +0 -0
  14. package/lib/assets/door-hub2.jpg +0 -0
  15. package/lib/assets/express7.jpg +0 -0
  16. package/lib/assets/express72.jpg +0 -0
  17. package/lib/assets/g2-reader-pro.jpg +0 -0
  18. package/lib/assets/g2-reader-pro2.jpg +0 -0
  19. package/lib/assets/g2-reader.jpg +0 -0
  20. package/lib/assets/g2-reader2.jpg +0 -0
  21. package/lib/assets/g3-reader-flex.jpg +0 -0
  22. package/lib/assets/g3-reader-flex2.jpg +0 -0
  23. package/lib/assets/g3-reader.jpg +0 -0
  24. package/lib/assets/g3-reader2.jpg +0 -0
  25. package/lib/assets/g4-instant.jpg +0 -0
  26. package/lib/assets/g4-instant2.jpg +0 -0
  27. package/lib/assets/g5-dome.jpg +0 -0
  28. package/lib/assets/g5-dome2.jpg +0 -0
  29. package/lib/assets/g5-turret-ultra.jpg +0 -0
  30. package/lib/assets/g5-turret-ultra2.jpg +0 -0
  31. package/lib/assets/u6-extender.jpg +0 -0
  32. package/lib/assets/u6-extender2.jpg +0 -0
  33. package/lib/assets/u7-pro-max.jpg +0 -0
  34. package/lib/assets/u7-pro-max2.jpg +0 -0
  35. package/lib/assets/ucg-fiber.png +0 -0
  36. package/lib/assets/ucgFiber.jpg +0 -0
  37. package/lib/assets/ucgFiber2.jpg +0 -0
  38. package/lib/assets/udr2.jpg +0 -0
  39. package/lib/assets/udr3.jpg +0 -0
  40. package/lib/assets/udr7.png +0 -0
  41. package/lib/assets/ux.png +0 -0
  42. package/lib/assets/ux7.png +0 -0
  43. package/lib/components/BodyPortal/BodyPortal.d.ts +6 -0
  44. package/lib/components/BodyPortal/BodyPortal.js +18 -0
  45. package/lib/components/BodyPortal/BodyPortal.js.map +1 -0
  46. package/lib/components/BodyPortal/BodyPortal.mjs +16 -0
  47. package/lib/components/BodyPortal/BodyPortal.mjs.map +1 -0
  48. package/lib/components/BodyPortal/index.d.ts +1 -0
  49. package/lib/components/BodyPortal/index.js +6 -0
  50. package/lib/components/BodyPortal/index.js.map +1 -0
  51. package/lib/components/BodyPortal/index.mjs +3 -0
  52. package/lib/components/BodyPortal/index.mjs.map +1 -0
  53. package/lib/components/Header/AccountMenu/AccountMenu.js +14 -2
  54. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  55. package/lib/components/Header/AccountMenu/AccountMenu.mjs +14 -2
  56. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  57. package/lib/components/Header/CartIcon/CartIcon.d.ts +1 -1
  58. package/lib/components/Header/CartIcon/CartIcon.js +5 -1
  59. package/lib/components/Header/CartIcon/CartIcon.js.map +1 -1
  60. package/lib/components/Header/CartIcon/CartIcon.mjs +5 -1
  61. package/lib/components/Header/CartIcon/CartIcon.mjs.map +1 -1
  62. package/lib/components/Header/CartIcon/CartIcon.types.d.ts +2 -0
  63. package/lib/components/Header/Header.js +1 -1
  64. package/lib/components/Header/Header.js.map +1 -1
  65. package/lib/components/Header/Header.mjs +2 -2
  66. package/lib/components/Header/Header.mjs.map +1 -1
  67. package/lib/components/Header/Header.stories.d.ts +2 -0
  68. package/lib/components/Header/Header.styles.d.ts +5 -3
  69. package/lib/components/Header/Header.styles.js +11 -10
  70. package/lib/components/Header/Header.styles.js.map +1 -1
  71. package/lib/components/Header/Header.styles.mjs +12 -10
  72. package/lib/components/Header/Header.styles.mjs.map +1 -1
  73. package/lib/components/Header/Header.types.d.ts +8 -0
  74. package/lib/components/Header/Header.types.js.map +1 -1
  75. package/lib/components/Header/Header.types.mjs.map +1 -1
  76. package/lib/components/Header/ProHeader/ProHeader.d.ts +2 -0
  77. package/lib/components/Header/ProHeader/ProHeader.js +78 -32
  78. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  79. package/lib/components/Header/ProHeader/ProHeader.mjs +80 -35
  80. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  81. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +8 -0
  82. package/lib/components/Header/ProHeader/ProHeader.styles.js +74 -1
  83. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  84. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +69 -2
  85. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  86. package/lib/components/Microsites/MicrositeProductPage.js +1 -1
  87. package/lib/components/Microsites/MicrositeProductPage.js.map +1 -1
  88. package/lib/components/Microsites/MicrositeProductPage.mjs +1 -1
  89. package/lib/components/Microsites/MicrositeProductPage.mjs.map +1 -1
  90. package/lib/components/Microsites/Microsites.types.d.ts +5 -2
  91. package/lib/components/Microsites/Microsites.types.js.map +1 -1
  92. package/lib/components/Microsites/Microsites.types.mjs.map +1 -1
  93. package/lib/components/ModelCompareV3/ModelCompareV3.d.ts +2 -18
  94. package/lib/components/ModelCompareV3/ModelCompareV3.js +25 -12
  95. package/lib/components/ModelCompareV3/ModelCompareV3.js.map +1 -1
  96. package/lib/components/ModelCompareV3/ModelCompareV3.mjs +26 -13
  97. package/lib/components/ModelCompareV3/ModelCompareV3.mjs.map +1 -1
  98. package/lib/components/ModelCompareV3/ModelCompareV3.types.d.ts +29 -0
  99. package/lib/components/ModelCompareV3/data/index.d.ts +56 -56
  100. package/lib/components/ModelCompareV3/data/index.js +335 -166
  101. package/lib/components/ModelCompareV3/data/index.js.map +1 -1
  102. package/lib/components/ModelCompareV3/data/index.mjs +225 -165
  103. package/lib/components/ModelCompareV3/data/index.mjs.map +1 -1
  104. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +607 -2
  105. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  106. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +603 -2
  107. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  108. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +5 -1
  109. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +4 -0
  110. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  111. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +4 -0
  112. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  113. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js +1 -5
  114. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js.map +1 -1
  115. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs +2 -6
  116. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs.map +1 -1
  117. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  118. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  119. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  120. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  121. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  122. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  123. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  124. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  125. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-fiber.png.js +27 -0
  126. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-fiber.png.js.map +1 -0
  127. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-fiber.png.mjs +3 -0
  128. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-fiber.png.mjs.map +1 -0
  129. package/lib/components/ResourceCalculatorV1/assets/consoles/udr7.png.js +27 -0
  130. package/lib/components/ResourceCalculatorV1/assets/consoles/udr7.png.js.map +1 -0
  131. package/lib/components/ResourceCalculatorV1/assets/consoles/udr7.png.mjs +3 -0
  132. package/lib/components/ResourceCalculatorV1/assets/consoles/udr7.png.mjs.map +1 -0
  133. package/lib/components/ResourceCalculatorV1/assets/consoles/ux.png.js +27 -0
  134. package/lib/components/ResourceCalculatorV1/assets/consoles/ux.png.js.map +1 -0
  135. package/lib/components/ResourceCalculatorV1/assets/consoles/ux.png.mjs +3 -0
  136. package/lib/components/ResourceCalculatorV1/assets/consoles/ux.png.mjs.map +1 -0
  137. package/lib/components/ResourceCalculatorV1/assets/consoles/ux7.png.js +27 -0
  138. package/lib/components/ResourceCalculatorV1/assets/consoles/ux7.png.js.map +1 -0
  139. package/lib/components/ResourceCalculatorV1/assets/consoles/ux7.png.mjs +3 -0
  140. package/lib/components/ResourceCalculatorV1/assets/consoles/ux7.png.mjs.map +1 -0
  141. package/lib/components/ResourceCalculatorV1/translations/en.json.js +4 -0
  142. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  143. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +4 -0
  144. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  145. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  146. package/lib/constants/modelCompareData/assets/BuildingBridge/building-bridge.jpg.js +1 -1
  147. package/lib/constants/modelCompareData/assets/BuildingBridge/building-bridge.jpg.mjs +2 -2
  148. package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.js +1 -1
  149. package/lib/constants/modelCompareData/assets/Compact/g4-instant.jpg.mjs +2 -2
  150. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/express7.jpg.js +5 -5
  151. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/express7.jpg.mjs +2 -2
  152. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/ucgFiber.jpg.js +5 -5
  153. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/ucgFiber.jpg.mjs +2 -2
  154. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.js +1 -1
  155. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
  156. package/lib/constants/modelCompareData/assets/Consoles/express7.jpg.js +1 -1
  157. package/lib/constants/modelCompareData/assets/Consoles/express7.jpg.mjs +2 -2
  158. package/lib/constants/modelCompareData/assets/Consoles/ucgFiber.jpg.js +1 -1
  159. package/lib/constants/modelCompareData/assets/Consoles/ucgFiber.jpg.mjs +2 -2
  160. package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.js +1 -1
  161. package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.mjs +2 -2
  162. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.js +1 -1
  163. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.mjs +2 -2
  164. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.js +1 -1
  165. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.mjs +2 -2
  166. package/lib/constants/modelCompareData/assets/DomeTurret/g5-turret-ultra.jpg.js +1 -1
  167. package/lib/constants/modelCompareData/assets/DomeTurret/g5-turret-ultra.jpg.mjs +2 -2
  168. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.js +1 -1
  169. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.mjs +2 -2
  170. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader-pro.jpg.js +1 -1
  171. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader-pro.jpg.mjs +2 -2
  172. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.js +1 -1
  173. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.mjs +2 -2
  174. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.js +1 -1
  175. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.mjs +2 -2
  176. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader.jpg.js +1 -1
  177. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader.jpg.mjs +2 -2
  178. package/lib/constants/modelCompareData/assets/Flagship/u7-pro-max.jpg.js +1 -1
  179. package/lib/constants/modelCompareData/assets/Flagship/u7-pro-max.jpg.mjs +2 -2
  180. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.js +1 -1
  181. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.mjs +2 -2
  182. package/lib/constants/modelCompareData/assets/Wall/u6-extender.jpg.js +1 -1
  183. package/lib/constants/modelCompareData/assets/Wall/u6-extender.jpg.mjs +2 -2
  184. package/lib/constants/modelCompareData/assets/compact.svg.js +1 -1
  185. package/lib/constants/modelCompareData/assets/compact.svg.mjs +2 -2
  186. package/lib/constants/modelCompareData/assets/crestron.svg.js +27 -0
  187. package/lib/constants/modelCompareData/assets/crestron.svg.js.map +1 -0
  188. package/lib/constants/modelCompareData/assets/crestron.svg.mjs +3 -0
  189. package/lib/constants/modelCompareData/assets/crestron.svg.mjs.map +1 -0
  190. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.js +1 -1
  191. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g4-instant.jpg.mjs +2 -2
  192. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.js +1 -1
  193. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.mjs +2 -2
  194. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.js +1 -1
  195. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.mjs +2 -2
  196. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-turret-ultra.jpg.js +1 -1
  197. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-turret-ultra.jpg.mjs +2 -2
  198. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.js +1 -1
  199. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.mjs +2 -2
  200. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader-pro.jpg.js +1 -1
  201. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader-pro.jpg.mjs +2 -2
  202. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.js +1 -1
  203. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.mjs +2 -2
  204. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.js +1 -1
  205. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.mjs +2 -2
  206. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader.jpg.js +1 -1
  207. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader.jpg.mjs +2 -2
  208. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.js +1 -1
  209. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.mjs +2 -2
  210. package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.js +1 -1
  211. package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.mjs +2 -2
  212. package/lib/constants/modelCompareData/assets/product-list-assets/wifi/building-bridge/building-bridge.jpg.js +1 -1
  213. package/lib/constants/modelCompareData/assets/product-list-assets/wifi/building-bridge/building-bridge.jpg.mjs +2 -2
  214. package/lib/constants/modelCompareData/assets/product-list-assets/wifi/flagship/u7-pro-max.jpg.js +1 -1
  215. package/lib/constants/modelCompareData/assets/product-list-assets/wifi/flagship/u7-pro-max.jpg.mjs +2 -2
  216. package/lib/constants/modelCompareData/assets/product-list-assets/wifi/wall/u6-extender.jpg.js +1 -1
  217. package/lib/constants/modelCompareData/assets/product-list-assets/wifi/wall/u6-extender.jpg.mjs +2 -2
  218. package/lib/constants/modelCompareData/data/CloudGateways.js +13 -13
  219. package/lib/constants/modelCompareData/data/CloudGateways.mjs +11 -11
  220. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.js +1 -1
  221. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.mjs +1 -1
  222. package/lib/constants/modelCompareData/data/EnterpriseSwitching.js +3 -2
  223. package/lib/constants/modelCompareData/data/EnterpriseSwitching.js.map +1 -1
  224. package/lib/constants/modelCompareData/data/EnterpriseSwitching.mjs +3 -2
  225. package/lib/constants/modelCompareData/data/EnterpriseSwitching.mjs.map +1 -1
  226. package/lib/constants/modelCompareData/data/MegaCapacityWiFI.js +3 -3
  227. package/lib/constants/modelCompareData/data/MegaCapacityWiFI.mjs +3 -3
  228. package/lib/constants/modelCompareData/data/MobileRouters.js +2 -2
  229. package/lib/constants/modelCompareData/data/MobileRouters.mjs +2 -2
  230. package/lib/constants/modelCompareData/data/ProfessionalMaxSwitching.d.ts +1 -1
  231. package/lib/constants/modelCompareData/data/ProfessionalMaxSwitching.js +5 -4
  232. package/lib/constants/modelCompareData/data/ProfessionalMaxSwitching.js.map +1 -1
  233. package/lib/constants/modelCompareData/data/ProfessionalMaxSwitching.mjs +5 -4
  234. package/lib/constants/modelCompareData/data/ProfessionalMaxSwitching.mjs.map +1 -1
  235. package/lib/constants/modelCompareData/data/Switching.js +2 -1
  236. package/lib/constants/modelCompareData/data/Switching.js.map +1 -1
  237. package/lib/constants/modelCompareData/data/Switching.mjs +2 -1
  238. package/lib/constants/modelCompareData/data/Switching.mjs.map +1 -1
  239. package/lib/constants/modelCompareData/data/index.d.ts +1 -1
  240. package/lib/constants/modelCompareData/data/index.js +1 -1
  241. package/lib/constants/modelCompareData/data/index.mjs +1 -1
  242. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.js +1 -1
  243. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.mjs +1 -1
  244. package/lib/constants/modelCompareData/data/product-list-groups/compact.js +1 -1
  245. package/lib/constants/modelCompareData/data/product-list-groups/compact.mjs +1 -1
  246. package/lib/constants/modelCompareData/data/products/aggregation.js +7 -0
  247. package/lib/constants/modelCompareData/data/products/aggregation.js.map +1 -1
  248. package/lib/constants/modelCompareData/data/products/aggregation.mjs +7 -0
  249. package/lib/constants/modelCompareData/data/products/aggregation.mjs.map +1 -1
  250. package/lib/constants/modelCompareData/data/products/ai360.js +2 -2
  251. package/lib/constants/modelCompareData/data/products/ai360.mjs +2 -2
  252. package/lib/constants/modelCompareData/data/products/buildingBridge.js +2 -2
  253. package/lib/constants/modelCompareData/data/products/buildingBridge.mjs +2 -2
  254. package/lib/constants/modelCompareData/data/products/doorHub.js +2 -2
  255. package/lib/constants/modelCompareData/data/products/doorHub.mjs +2 -2
  256. package/lib/constants/modelCompareData/data/products/efg.js +3 -3
  257. package/lib/constants/modelCompareData/data/products/efg.mjs +2 -2
  258. package/lib/constants/modelCompareData/data/products/elevatorHub.js +6 -12
  259. package/lib/constants/modelCompareData/data/products/elevatorHub.js.map +1 -1
  260. package/lib/constants/modelCompareData/data/products/elevatorHub.mjs +6 -12
  261. package/lib/constants/modelCompareData/data/products/elevatorHub.mjs.map +1 -1
  262. package/lib/constants/modelCompareData/data/products/enterpriseAggregation.js +7 -0
  263. package/lib/constants/modelCompareData/data/products/enterpriseAggregation.js.map +1 -1
  264. package/lib/constants/modelCompareData/data/products/enterpriseAggregation.mjs +7 -0
  265. package/lib/constants/modelCompareData/data/products/enterpriseAggregation.mjs.map +1 -1
  266. package/lib/constants/modelCompareData/data/products/enterpriseCampus24PoE.js +7 -0
  267. package/lib/constants/modelCompareData/data/products/enterpriseCampus24PoE.js.map +1 -1
  268. package/lib/constants/modelCompareData/data/products/enterpriseCampus24PoE.mjs +7 -0
  269. package/lib/constants/modelCompareData/data/products/enterpriseCampus24PoE.mjs.map +1 -1
  270. package/lib/constants/modelCompareData/data/products/enterpriseCampus48PoE.js +7 -0
  271. package/lib/constants/modelCompareData/data/products/enterpriseCampus48PoE.js.map +1 -1
  272. package/lib/constants/modelCompareData/data/products/enterpriseCampus48PoE.mjs +7 -0
  273. package/lib/constants/modelCompareData/data/products/enterpriseCampus48PoE.mjs.map +1 -1
  274. package/lib/constants/modelCompareData/data/products/express.js +3 -3
  275. package/lib/constants/modelCompareData/data/products/express.mjs +2 -2
  276. package/lib/constants/modelCompareData/data/products/express7.js +3 -3
  277. package/lib/constants/modelCompareData/data/products/express7.mjs +2 -2
  278. package/lib/constants/modelCompareData/data/products/g2Reader.js +2 -2
  279. package/lib/constants/modelCompareData/data/products/g2Reader.mjs +2 -2
  280. package/lib/constants/modelCompareData/data/products/g2ReaderPro.js +2 -2
  281. package/lib/constants/modelCompareData/data/products/g2ReaderPro.mjs +2 -2
  282. package/lib/constants/modelCompareData/data/products/g3Reader.js +2 -2
  283. package/lib/constants/modelCompareData/data/products/g3Reader.mjs +2 -2
  284. package/lib/constants/modelCompareData/data/products/g3ReaderFlex.js +2 -2
  285. package/lib/constants/modelCompareData/data/products/g3ReaderFlex.mjs +2 -2
  286. package/lib/constants/modelCompareData/data/products/g3TouchEnterprise.js +1 -1
  287. package/lib/constants/modelCompareData/data/products/g3TouchEnterprise.mjs +1 -1
  288. package/lib/constants/modelCompareData/data/products/g3TouchWall.js +1 -1
  289. package/lib/constants/modelCompareData/data/products/g3TouchWall.mjs +1 -1
  290. package/lib/constants/modelCompareData/data/products/g4Instant.js +2 -2
  291. package/lib/constants/modelCompareData/data/products/g4Instant.mjs +2 -2
  292. package/lib/constants/modelCompareData/data/products/g5Dome.js +2 -2
  293. package/lib/constants/modelCompareData/data/products/g5Dome.mjs +2 -2
  294. package/lib/constants/modelCompareData/data/products/g5TurretUltra.js +2 -2
  295. package/lib/constants/modelCompareData/data/products/g5TurretUltra.mjs +2 -2
  296. package/lib/constants/modelCompareData/data/products/highCapacityAggregation.js +7 -0
  297. package/lib/constants/modelCompareData/data/products/highCapacityAggregation.js.map +1 -1
  298. package/lib/constants/modelCompareData/data/products/highCapacityAggregation.mjs +7 -0
  299. package/lib/constants/modelCompareData/data/products/highCapacityAggregation.mjs.map +1 -1
  300. package/lib/constants/modelCompareData/data/products/missionCritical.js +7 -0
  301. package/lib/constants/modelCompareData/data/products/missionCritical.js.map +1 -1
  302. package/lib/constants/modelCompareData/data/products/missionCritical.mjs +7 -0
  303. package/lib/constants/modelCompareData/data/products/missionCritical.mjs.map +1 -1
  304. package/lib/constants/modelCompareData/data/products/professionalMax16.js +7 -0
  305. package/lib/constants/modelCompareData/data/products/professionalMax16.js.map +1 -1
  306. package/lib/constants/modelCompareData/data/products/professionalMax16.mjs +7 -0
  307. package/lib/constants/modelCompareData/data/products/professionalMax16.mjs.map +1 -1
  308. package/lib/constants/modelCompareData/data/products/professionalMax16PoE.js +7 -0
  309. package/lib/constants/modelCompareData/data/products/professionalMax16PoE.js.map +1 -1
  310. package/lib/constants/modelCompareData/data/products/professionalMax16PoE.mjs +7 -0
  311. package/lib/constants/modelCompareData/data/products/professionalMax16PoE.mjs.map +1 -1
  312. package/lib/constants/modelCompareData/data/products/professionalMax24.js +7 -0
  313. package/lib/constants/modelCompareData/data/products/professionalMax24.js.map +1 -1
  314. package/lib/constants/modelCompareData/data/products/professionalMax24.mjs +7 -0
  315. package/lib/constants/modelCompareData/data/products/professionalMax24.mjs.map +1 -1
  316. package/lib/constants/modelCompareData/data/products/professionalMax24PoE.js +7 -0
  317. package/lib/constants/modelCompareData/data/products/professionalMax24PoE.js.map +1 -1
  318. package/lib/constants/modelCompareData/data/products/professionalMax24PoE.mjs +7 -0
  319. package/lib/constants/modelCompareData/data/products/professionalMax24PoE.mjs.map +1 -1
  320. package/lib/constants/modelCompareData/data/products/professionalMax48.js +7 -0
  321. package/lib/constants/modelCompareData/data/products/professionalMax48.js.map +1 -1
  322. package/lib/constants/modelCompareData/data/products/professionalMax48.mjs +7 -0
  323. package/lib/constants/modelCompareData/data/products/professionalMax48.mjs.map +1 -1
  324. package/lib/constants/modelCompareData/data/products/professionalMax48PoE.js +7 -0
  325. package/lib/constants/modelCompareData/data/products/professionalMax48PoE.js.map +1 -1
  326. package/lib/constants/modelCompareData/data/products/professionalMax48PoE.mjs +7 -0
  327. package/lib/constants/modelCompareData/data/products/professionalMax48PoE.mjs.map +1 -1
  328. package/lib/constants/modelCompareData/data/products/shared-product-data/e7Audience.js +1 -1
  329. package/lib/constants/modelCompareData/data/products/shared-product-data/e7Audience.mjs +1 -1
  330. package/lib/constants/modelCompareData/data/products/switchesEnterprise.js +8 -0
  331. package/lib/constants/modelCompareData/data/products/switchesEnterprise.js.map +1 -1
  332. package/lib/constants/modelCompareData/data/products/switchesEnterprise.mjs +8 -0
  333. package/lib/constants/modelCompareData/data/products/switchesEnterprise.mjs.map +1 -1
  334. package/lib/constants/modelCompareData/data/products/switchesProfessional.js +7 -0
  335. package/lib/constants/modelCompareData/data/products/switchesProfessional.js.map +1 -1
  336. package/lib/constants/modelCompareData/data/products/switchesProfessional.mjs +7 -0
  337. package/lib/constants/modelCompareData/data/products/switchesProfessional.mjs.map +1 -1
  338. package/lib/constants/modelCompareData/data/products/switchesProfessionalMax.js +10 -1
  339. package/lib/constants/modelCompareData/data/products/switchesProfessionalMax.js.map +1 -1
  340. package/lib/constants/modelCompareData/data/products/switchesProfessionalMax.mjs +10 -1
  341. package/lib/constants/modelCompareData/data/products/switchesProfessionalMax.mjs.map +1 -1
  342. package/lib/constants/modelCompareData/data/products/switchesStandard.js +7 -0
  343. package/lib/constants/modelCompareData/data/products/switchesStandard.js.map +1 -1
  344. package/lib/constants/modelCompareData/data/products/switchesStandard.mjs +7 -0
  345. package/lib/constants/modelCompareData/data/products/switchesStandard.mjs.map +1 -1
  346. package/lib/constants/modelCompareData/data/products/theta.js +2 -2
  347. package/lib/constants/modelCompareData/data/products/theta.mjs +2 -2
  348. package/lib/constants/modelCompareData/data/products/u6Extender.js +2 -2
  349. package/lib/constants/modelCompareData/data/products/u6Extender.mjs +2 -2
  350. package/lib/constants/modelCompareData/data/products/u7proMax.js +2 -2
  351. package/lib/constants/modelCompareData/data/products/u7proMax.mjs +2 -2
  352. package/lib/constants/modelCompareData/data/products/u7proOutdoor.mjs +1 -1
  353. package/lib/constants/modelCompareData/data/products/ucgFiber.js +3 -3
  354. package/lib/constants/modelCompareData/data/products/ucgFiber.mjs +2 -2
  355. package/lib/constants/modelCompareData/data/products/ucgMax.js +3 -3
  356. package/lib/constants/modelCompareData/data/products/ucgMax.mjs +2 -2
  357. package/lib/constants/modelCompareData/data/products/ucgUltra.js +3 -3
  358. package/lib/constants/modelCompareData/data/products/ucgUltra.mjs +2 -2
  359. package/lib/constants/modelCompareData/data/products/udmPro.js +3 -3
  360. package/lib/constants/modelCompareData/data/products/udmPro.mjs +2 -2
  361. package/lib/constants/modelCompareData/data/products/udmProMax.js +3 -3
  362. package/lib/constants/modelCompareData/data/products/udmProMax.mjs +2 -2
  363. package/lib/constants/modelCompareData/data/products/udmProSpecial.js +3 -3
  364. package/lib/constants/modelCompareData/data/products/udmProSpecial.mjs +2 -2
  365. package/lib/constants/modelCompareData/data/products/udr.js +5 -5
  366. package/lib/constants/modelCompareData/data/products/udr.mjs +5 -5
  367. package/lib/constants/modelCompareData/data/products/udr7.js +2 -2
  368. package/lib/constants/modelCompareData/data/products/udr7.mjs +1 -1
  369. package/lib/constants/modelCompareData/data/products/udw.js +3 -3
  370. package/lib/constants/modelCompareData/data/products/udw.mjs +2 -2
  371. package/lib/constants/modelCompareData/data/products/uispSwitch.js +3 -3
  372. package/lib/constants/modelCompareData/data/products/uispSwitch.mjs +2 -2
  373. package/lib/constants/modelCompareData/data/products/uispSwitchPlus.js +3 -3
  374. package/lib/constants/modelCompareData/data/products/uispSwitchPlus.mjs +2 -2
  375. package/lib/constants/modelCompareData/data/products/umr.mjs +1 -1
  376. package/lib/constants/modelCompareData/data/products/umrIndustrial.mjs +1 -1
  377. package/lib/constants/modelCompareData/data/products/umrUltra.js +1 -1
  378. package/lib/constants/modelCompareData/data/products/umrUltra.mjs +2 -2
  379. package/lib/constants/modelCompareData/data/products/wanSwitch.js +2 -2
  380. package/lib/constants/modelCompareData/data/products/wanSwitch.js.map +1 -1
  381. package/lib/constants/modelCompareData/data/products/wanSwitch.mjs +2 -2
  382. package/lib/constants/modelCompareData/data/products/wanSwitch.mjs.map +1 -1
  383. package/lib/constants/modelCompareData/data/properties/crestronNaxNvxCertified.d.ts +2 -0
  384. package/lib/constants/modelCompareData/data/properties/crestronNaxNvxCertified.js +18 -0
  385. package/lib/constants/modelCompareData/data/properties/crestronNaxNvxCertified.js.map +1 -0
  386. package/lib/constants/modelCompareData/data/properties/crestronNaxNvxCertified.mjs +10 -0
  387. package/lib/constants/modelCompareData/data/properties/crestronNaxNvxCertified.mjs.map +1 -0
  388. package/lib/constants/modelCompareData/data/properties/index.d.ts +1 -0
  389. package/lib/constants/modelCompareData/data/properties/index.js +2 -0
  390. package/lib/constants/modelCompareData/data/properties/index.js.map +1 -1
  391. package/lib/constants/modelCompareData/data/properties/index.mjs +1 -0
  392. package/lib/constants/modelCompareData/data/properties/index.mjs.map +1 -1
  393. package/lib/constants/modelCompareData/translations/en.json.js +2 -0
  394. package/lib/constants/modelCompareData/translations/en.json.js.map +1 -1
  395. package/lib/constants/modelCompareData/translations/en.json.mjs +2 -0
  396. package/lib/constants/modelCompareData/translations/en.json.mjs.map +1 -1
  397. package/lib/constants/modelCompareData/translations/es.json.js +2 -1
  398. package/lib/constants/modelCompareData/translations/es.json.js.map +1 -1
  399. package/lib/constants/modelCompareData/translations/es.json.mjs +2 -1
  400. package/lib/constants/modelCompareData/translations/es.json.mjs.map +1 -1
  401. package/lib/constants/modelCompareData/translations/useModelCompareTranslation.d.ts +2 -2
  402. package/lib/constants/modelCompareData/types.d.ts +1 -0
  403. package/lib/constants/modelCompareData/types.js +1 -0
  404. package/lib/constants/modelCompareData/types.js.map +1 -1
  405. package/lib/constants/modelCompareData/types.mjs +1 -0
  406. package/lib/constants/modelCompareData/types.mjs.map +1 -1
  407. package/lib/constants/proStoreCategories/mapping/filters.d.ts +1 -1
  408. package/lib/constants/proStoreCategories/mapping/filters.js +1 -1
  409. package/lib/constants/proStoreCategories/mapping/filters.js.map +1 -1
  410. package/lib/constants/proStoreCategories/mapping/filters.mjs +1 -1
  411. package/lib/constants/proStoreCategories/mapping/filters.mjs.map +1 -1
  412. package/lib/constants/proStoreCategories/mapping/index.d.ts +2 -0
  413. package/lib/constants/proStoreCategories/mapping/index.js +14 -4
  414. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  415. package/lib/constants/proStoreCategories/mapping/index.mjs +14 -4
  416. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  417. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +3 -1
  418. package/lib/constants/proStoreCategories/mapping/unifi.js +2 -0
  419. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  420. package/lib/constants/proStoreCategories/mapping/unifi.mjs +2 -0
  421. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  422. package/lib/constants/proStoreCategories/translations/ar.json.js +5 -1
  423. package/lib/constants/proStoreCategories/translations/ar.json.js.map +1 -1
  424. package/lib/constants/proStoreCategories/translations/ar.json.mjs +5 -2
  425. package/lib/constants/proStoreCategories/translations/ar.json.mjs.map +1 -1
  426. package/lib/constants/proStoreCategories/translations/de.json.js +5 -1
  427. package/lib/constants/proStoreCategories/translations/de.json.js.map +1 -1
  428. package/lib/constants/proStoreCategories/translations/de.json.mjs +5 -2
  429. package/lib/constants/proStoreCategories/translations/de.json.mjs.map +1 -1
  430. package/lib/constants/proStoreCategories/translations/el.json.js +5 -1
  431. package/lib/constants/proStoreCategories/translations/el.json.js.map +1 -1
  432. package/lib/constants/proStoreCategories/translations/el.json.mjs +5 -2
  433. package/lib/constants/proStoreCategories/translations/el.json.mjs.map +1 -1
  434. package/lib/constants/proStoreCategories/translations/en.json.js +5 -1
  435. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  436. package/lib/constants/proStoreCategories/translations/en.json.mjs +5 -2
  437. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  438. package/lib/constants/proStoreCategories/translations/es.json.js +5 -1
  439. package/lib/constants/proStoreCategories/translations/es.json.js.map +1 -1
  440. package/lib/constants/proStoreCategories/translations/es.json.mjs +5 -2
  441. package/lib/constants/proStoreCategories/translations/es.json.mjs.map +1 -1
  442. package/lib/constants/proStoreCategories/translations/fr.json.js +5 -1
  443. package/lib/constants/proStoreCategories/translations/fr.json.js.map +1 -1
  444. package/lib/constants/proStoreCategories/translations/fr.json.mjs +5 -2
  445. package/lib/constants/proStoreCategories/translations/fr.json.mjs.map +1 -1
  446. package/lib/constants/proStoreCategories/translations/it.json.js +5 -1
  447. package/lib/constants/proStoreCategories/translations/it.json.js.map +1 -1
  448. package/lib/constants/proStoreCategories/translations/it.json.mjs +5 -2
  449. package/lib/constants/proStoreCategories/translations/it.json.mjs.map +1 -1
  450. package/lib/constants/proStoreCategories/translations/ja.json.js +5 -1
  451. package/lib/constants/proStoreCategories/translations/ja.json.js.map +1 -1
  452. package/lib/constants/proStoreCategories/translations/ja.json.mjs +5 -2
  453. package/lib/constants/proStoreCategories/translations/ja.json.mjs.map +1 -1
  454. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +5 -1
  455. package/lib/constants/proStoreCategories/translations/pt-BR.json.js.map +1 -1
  456. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +5 -2
  457. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs.map +1 -1
  458. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +5 -1
  459. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js.map +1 -1
  460. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +5 -2
  461. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs.map +1 -1
  462. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +5 -1
  463. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js.map +1 -1
  464. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +5 -2
  465. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs.map +1 -1
  466. package/lib/constants/proStoreFilters/mapping.d.ts +2 -1
  467. package/lib/constants/proStoreFilters/mapping.js +8 -6
  468. package/lib/constants/proStoreFilters/mapping.js.map +1 -1
  469. package/lib/constants/proStoreFilters/mapping.mjs +8 -6
  470. package/lib/constants/proStoreFilters/mapping.mjs.map +1 -1
  471. package/lib/contexts/MenuContext/context.js +30 -2
  472. package/lib/contexts/MenuContext/context.js.map +1 -1
  473. package/lib/contexts/MenuContext/context.mjs +31 -3
  474. package/lib/contexts/MenuContext/context.mjs.map +1 -1
  475. package/lib/contexts/MenuContext/types.d.ts +3 -0
  476. package/lib/contexts/MenuContext/types.js +1 -0
  477. package/lib/contexts/MenuContext/types.js.map +1 -1
  478. package/lib/contexts/MenuContext/types.mjs +1 -0
  479. package/lib/contexts/MenuContext/types.mjs.map +1 -1
  480. package/lib/hooks/useIsTouchDevice.d.ts +1 -0
  481. package/lib/hooks/useIsTouchDevice.js +20 -0
  482. package/lib/hooks/useIsTouchDevice.js.map +1 -0
  483. package/lib/hooks/useIsTouchDevice.mjs +18 -0
  484. package/lib/hooks/useIsTouchDevice.mjs.map +1 -0
  485. package/lib/utils/money/constants.d.ts +6 -0
  486. package/lib/utils/money/constants.js +23 -1
  487. package/lib/utils/money/constants.js.map +1 -1
  488. package/lib/utils/money/constants.mjs +23 -2
  489. package/lib/utils/money/constants.mjs.map +1 -1
  490. package/lib/utils/money/index.js +1 -0
  491. package/lib/utils/money/index.js.map +1 -1
  492. package/lib/utils/money/index.mjs +1 -1
  493. package/lib/utils/shipping.d.ts +8 -2
  494. package/lib/utils/shipping.js +46 -2
  495. package/lib/utils/shipping.js.map +1 -1
  496. package/lib/utils/shipping.mjs +40 -2
  497. package/lib/utils/shipping.mjs.map +1 -1
  498. package/package.json +26 -26
@@ -8,6 +8,7 @@ import type { LocalizedCurrency, RoundingFn } from "./types";
8
8
  * @see: https://ubiquiti.atlassian.net/browse/NEP-3846
9
9
  */
10
10
  export declare const roundToNearestFull059: RoundingFn;
11
+ export declare const roundToNearestValidUiCarePrice: RoundingFn;
11
12
  /**
12
13
  * Custom rounding method to be used with dinero.js
13
14
  * This rounding method will round to
@@ -66,6 +67,11 @@ export declare const Round: {
66
67
  */
67
68
  PrettifyHalfUnitCents: RoundingFn;
68
69
  Subunit: import("@dinero.js/core").RoundingMode;
70
+ /**
71
+ * ! Disclaimer may not work for "weird" currencies as expected
72
+ * ! For correct rounding UI Care prices, used for auto managed UI Care products.
73
+ */
74
+ ValidUiCarePrice: RoundingFn;
69
75
  };
70
76
  /**
71
77
  * Mapping of how prices should be rounded down to "whole numbers" after certain threshold
@@ -22,6 +22,22 @@ const roundToNearestFull059 = input => {
22
22
  return roundedNumber - remainder + 9;
23
23
  }
24
24
  };
25
+ const roundToNearestValidUiCarePrice = input => {
26
+ if (input === 0) {
27
+ return 0;
28
+ }
29
+ if (input <= 5) {
30
+ return 5;
31
+ }
32
+ const remainder = input % 10;
33
+ if (remainder <= 2) {
34
+ return input - remainder - 1;
35
+ } else if (remainder <= 5) {
36
+ return input - remainder + 5;
37
+ } else {
38
+ return input - remainder + 9;
39
+ }
40
+ };
25
41
  const roundToNearestDecimalCent = input => {
26
42
  if (input === 0) {
27
43
  return 0;
@@ -86,7 +102,12 @@ const Round = {
86
102
  * ! Disclaimer may not work for "weird" currencies as expected
87
103
  */
88
104
  PrettifyHalfUnitCents: roundToNearestHalfUnitCent,
89
- Subunit: dinero_js.halfUp
105
+ Subunit: dinero_js.halfUp,
106
+ /**
107
+ * ! Disclaimer may not work for "weird" currencies as expected
108
+ * ! For correct rounding UI Care prices, used for auto managed UI Care products.
109
+ */
110
+ ValidUiCarePrice: roundToNearestValidUiCarePrice
90
111
  };
91
112
  const prettifyPriceLookup = /* @__PURE__ */new Map([[currencies.USD.code, 20], [currencies.AED.code, 50],
92
113
  // Approximately every price above ~1.1 usd will be rounded in ZAR
@@ -218,6 +239,7 @@ exports.prettifyPriceLookup = prettifyPriceLookup;
218
239
  exports.roundToNearestDecimalCent = roundToNearestDecimalCent;
219
240
  exports.roundToNearestFull059 = roundToNearestFull059;
220
241
  exports.roundToNearestHalfUnitCent = roundToNearestHalfUnitCent;
242
+ exports.roundToNearestValidUiCarePrice = roundToNearestValidUiCarePrice;
221
243
  exports.smallestSubunitLookup = smallestSubunitLookup;
222
244
  exports.storesWithPerItemTaxRate = storesWithPerItemTaxRate;
223
245
  //# 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 CNY,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PHP,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfAwayFromZero, halfUp } from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { Currency } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to nearest FULL 0/5/9 (and strip cents)\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestFull059: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-5.00\n if (input <= 5) {\n return 5;\n }\n\n /**\n * Input comes as float, for this rounding we don't need cents, so round\n * to nearest full number\n */\n const roundedNumber = Math.round(input);\n\n // Determine nearest rounding value\n const remainder = roundedNumber % 10;\n if (remainder <= 2) {\n // Round down to nearest 0\n return roundedNumber - remainder;\n } else if (remainder <= 7) {\n // Round to nearest 5\n return roundedNumber - remainder + 5;\n } else {\n // Round up to nearest 9\n return roundedNumber - remainder + 9;\n }\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest decimal cent. e.g. 1.53 = 1.50 / 1.57 = 1.60\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestDecimalCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.09\n if (input <= 0.1) {\n return 0.1;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n */\n return parseFloat((Math.round(input * 10) / 10).toFixed(1));\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest .50 or .00. e.g. 11.22 = 11 / 11.55 = 11.50 / 11.90 = 12\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestHalfUnitCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.5\n if (input <= 0.5) {\n return 0.5;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n *\n * Multiply by 2, round to the nearest integer, then divide by 2 to get the nearest .5 or .0\n * Return with fixed precision to avoid floating-point artifacts\n */\n return parseFloat((Math.round(input * 2) / 2).toFixed(2));\n};\n\nexport const Round = {\n /**\n * !!!!!!!!!!!!!!\n * ! Update 2024\n * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax\n * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html\n * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\n * !!!!!!!!!!!!!!\n *\n * OLD: halfEven docs\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 * normalize 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/v2.0.0-alpha.8/packages/core/src/round/halfEven.ts\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behavior\n * based on if the rounded 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\n * (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: halfAwayFromZero,\n // https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\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: roundToNearestDecimalCent,\n Prettify: down,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyFull059: roundToNearestFull059,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyDecimalCents: roundToNearestDecimalCent,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyHalfUnitCents: roundToNearestHalfUnitCent,\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 [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n [MXN.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 [Currency.Php, { currency: PHP, locale: \"en-PH\" }],\n [Currency.Cny, { currency: CNY, locale: \"zh-CN\" }],\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 *\n * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change\n *\n * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires\n * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for\n * different tax calculations is there just need to enable on the share side and test if it works\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 handle per-item tax rate\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n] as StoreId[]);\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":["roundToNearestFull059","input","roundedNumber","Math","round","remainder","roundToNearestDecimalCent","parseFloat","toFixed","roundToNearestHalfUnitCent","Round","Financial","halfAwayFromZero","Shipping","Prettify","down","PrettifyFull059","PrettifyDecimalCents","PrettifyHalfUnitCents","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","AED","ZAR","MXN","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","CAD","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","EUR","Gbp","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","Php","PHP","Cny","CNY","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;;;AA+Ca,MAAAA,qBAAA,GAAqCC,KAAkB,IAAA;EAClE,IAAIA,UAAU,CAAG,EAAA;IACR,OAAA,CAAA;EAAA;EAIT,IAAIA,SAAS,CAAG,EAAA;IACP,OAAA,CAAA;EAAA;EAOH,MAAAC,aAAA,GAAgBC,IAAK,CAAAC,KAAA,CAAMH,KAAK,CAAA;EAGtC,MAAMI,YAAYH,aAAgB,GAAA,EAAA;EAClC,IAAIG,aAAa,CAAG,EAAA;IAElB,OAAOH,aAAgB,GAAAG,SAAA;EAAA,CACzB,MAAA,IAAWA,aAAa,CAAG,EAAA;IAEzB,OAAOH,gBAAgBG,SAAY,GAAA,CAAA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,EAAA;EAAA;AACR,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 CNY,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PHP,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfAwayFromZero, halfUp } from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { Currency } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to nearest FULL 0/5/9 (and strip cents)\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestFull059: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-5.00\n if (input <= 5) {\n return 5;\n }\n\n /**\n * Input comes as float, for this rounding we don't need cents, so round\n * to nearest full number\n */\n const roundedNumber = Math.round(input);\n\n // Determine nearest rounding value\n const remainder = roundedNumber % 10;\n if (remainder <= 2) {\n // Round down to nearest 0\n return roundedNumber - remainder;\n } else if (remainder <= 7) {\n // Round to nearest 5\n return roundedNumber - remainder + 5;\n } else {\n // Round up to nearest 9\n return roundedNumber - remainder + 9;\n }\n};\n\nexport const roundToNearestValidUiCarePrice: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-5.00\n if (input <= 5) {\n return 5;\n }\n\n // Determine nearest rounding value\n const remainder = input % 10;\n if (remainder <= 2) {\n // Round down to nearest 9\n return input - remainder - 1;\n } else if (remainder <= 5) {\n // Round to nearest 5\n return input - remainder + 5;\n } else {\n // Round up to nearest 9\n return input - remainder + 9;\n }\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest decimal cent. e.g. 1.53 = 1.50 / 1.57 = 1.60\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestDecimalCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.09\n if (input <= 0.1) {\n return 0.1;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n */\n return parseFloat((Math.round(input * 10) / 10).toFixed(1));\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest .50 or .00. e.g. 11.22 = 11 / 11.55 = 11.50 / 11.90 = 12\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestHalfUnitCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.5\n if (input <= 0.5) {\n return 0.5;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n *\n * Multiply by 2, round to the nearest integer, then divide by 2 to get the nearest .5 or .0\n * Return with fixed precision to avoid floating-point artifacts\n */\n return parseFloat((Math.round(input * 2) / 2).toFixed(2));\n};\n\nexport const Round = {\n /**\n * !!!!!!!!!!!!!!\n * ! Update 2024\n * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax\n * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html\n * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\n * !!!!!!!!!!!!!!\n *\n * OLD: halfEven docs\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 * normalize 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/v2.0.0-alpha.8/packages/core/src/round/halfEven.ts\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behavior\n * based on if the rounded 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\n * (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: halfAwayFromZero,\n // https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\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: roundToNearestDecimalCent,\n Prettify: down,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyFull059: roundToNearestFull059,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyDecimalCents: roundToNearestDecimalCent,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyHalfUnitCents: roundToNearestHalfUnitCent,\n Subunit: halfUp,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n * ! For correct rounding UI Care prices, used for auto managed UI Care products.\n */\n ValidUiCarePrice: roundToNearestValidUiCarePrice,\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 [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n [MXN.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 [Currency.Php, { currency: PHP, locale: \"en-PH\" }],\n [Currency.Cny, { currency: CNY, locale: \"zh-CN\" }],\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 *\n * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change\n *\n * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires\n * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for\n * different tax calculations is there just need to enable on the share side and test if it works\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 handle per-item tax rate\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n] as StoreId[]);\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":["roundToNearestFull059","input","roundedNumber","Math","round","remainder","roundToNearestValidUiCarePrice","roundToNearestDecimalCent","parseFloat","toFixed","roundToNearestHalfUnitCent","Round","Financial","halfAwayFromZero","Shipping","Prettify","down","PrettifyFull059","PrettifyDecimalCents","PrettifyHalfUnitCents","Subunit","halfUp","ValidUiCarePrice","prettifyPriceLookup","Map","USD","code","AED","ZAR","MXN","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","CAD","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","EUR","Gbp","GBP","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar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AAlC,MAAA,EAAQ;CAAS,CAAA;AAAA;AAEjD,CAACH,SAAAA,CAAAA,SAASsC,GAAK,EAAA;EAAEpC,UAAUqC,UAAAA,CAAAA,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA;AAAA;AAEjD,CAACH,SAAAA,CAAAA,SAASwC,GAAK,EAAA;EAAEtC,UAAUJ,UAAAA,CAAAA,GAAK;EAAAK,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAASyC,GAAK,EAAA;EAAEvC,UAAUN,UAAAA,CAAAA,GAAK;EAAAO,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAAS0C,GAAK,EAAA;EAAExC,UAAUyC,UAAAA,CAAAA,GAAK;EAAAxC,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAAS4C,GAAK,EAAA;EAAE1C,UAAU2C,UAAK,CAAAA,GAAA;EAAA1C,MAAA,EAAQ;AAAS,CAAA,CAAA,CAClD,CAAA;AAeY,MAAA2C,wBAAA,GAAA,mBAA+BC,GAAI,CAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA,CAWlC,CAAA;AAKP,MAAMC,wBAA2B,GAAA;EACtCC,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVzD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAM0D,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVzD,IAAM,EAAA;EAAA;AACR,CAAA;;;;;;;;;;;"}
@@ -20,6 +20,22 @@ const roundToNearestFull059 = input => {
20
20
  return roundedNumber - remainder + 9;
21
21
  }
22
22
  };
23
+ const roundToNearestValidUiCarePrice = input => {
24
+ if (input === 0) {
25
+ return 0;
26
+ }
27
+ if (input <= 5) {
28
+ return 5;
29
+ }
30
+ const remainder = input % 10;
31
+ if (remainder <= 2) {
32
+ return input - remainder - 1;
33
+ } else if (remainder <= 5) {
34
+ return input - remainder + 5;
35
+ } else {
36
+ return input - remainder + 9;
37
+ }
38
+ };
23
39
  const roundToNearestDecimalCent = input => {
24
40
  if (input === 0) {
25
41
  return 0;
@@ -84,7 +100,12 @@ const Round = {
84
100
  * ! Disclaimer may not work for "weird" currencies as expected
85
101
  */
86
102
  PrettifyHalfUnitCents: roundToNearestHalfUnitCent,
87
- Subunit: halfUp
103
+ Subunit: halfUp,
104
+ /**
105
+ * ! Disclaimer may not work for "weird" currencies as expected
106
+ * ! For correct rounding UI Care prices, used for auto managed UI Care products.
107
+ */
108
+ ValidUiCarePrice: roundToNearestValidUiCarePrice
88
109
  };
89
110
  const prettifyPriceLookup = /* @__PURE__ */new Map([[USD.code, 20], [AED.code, 50],
90
111
  // Approximately every price above ~1.1 usd will be rounded in ZAR
@@ -208,5 +229,5 @@ const EXCHANGE_RATE_DINERO_CURRENCY = {
208
229
  code: ""
209
230
  // Not important
210
231
  };
211
- export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, roundToNearestDecimalCent, roundToNearestFull059, roundToNearestHalfUnitCent, smallestSubunitLookup, storesWithPerItemTaxRate };
232
+ export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, roundToNearestDecimalCent, roundToNearestFull059, roundToNearestHalfUnitCent, roundToNearestValidUiCarePrice, smallestSubunitLookup, storesWithPerItemTaxRate };
212
233
  //# 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 CNY,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PHP,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfAwayFromZero, halfUp } from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { Currency } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to nearest FULL 0/5/9 (and strip cents)\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestFull059: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-5.00\n if (input <= 5) {\n return 5;\n }\n\n /**\n * Input comes as float, for this rounding we don't need cents, so round\n * to nearest full number\n */\n const roundedNumber = Math.round(input);\n\n // Determine nearest rounding value\n const remainder = roundedNumber % 10;\n if (remainder <= 2) {\n // Round down to nearest 0\n return roundedNumber - remainder;\n } else if (remainder <= 7) {\n // Round to nearest 5\n return roundedNumber - remainder + 5;\n } else {\n // Round up to nearest 9\n return roundedNumber - remainder + 9;\n }\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest decimal cent. e.g. 1.53 = 1.50 / 1.57 = 1.60\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestDecimalCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.09\n if (input <= 0.1) {\n return 0.1;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n */\n return parseFloat((Math.round(input * 10) / 10).toFixed(1));\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest .50 or .00. e.g. 11.22 = 11 / 11.55 = 11.50 / 11.90 = 12\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestHalfUnitCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.5\n if (input <= 0.5) {\n return 0.5;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n *\n * Multiply by 2, round to the nearest integer, then divide by 2 to get the nearest .5 or .0\n * Return with fixed precision to avoid floating-point artifacts\n */\n return parseFloat((Math.round(input * 2) / 2).toFixed(2));\n};\n\nexport const Round = {\n /**\n * !!!!!!!!!!!!!!\n * ! Update 2024\n * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax\n * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html\n * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\n * !!!!!!!!!!!!!!\n *\n * OLD: halfEven docs\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 * normalize 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/v2.0.0-alpha.8/packages/core/src/round/halfEven.ts\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behavior\n * based on if the rounded 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\n * (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: halfAwayFromZero,\n // https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\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: roundToNearestDecimalCent,\n Prettify: down,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyFull059: roundToNearestFull059,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyDecimalCents: roundToNearestDecimalCent,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyHalfUnitCents: roundToNearestHalfUnitCent,\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 [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n [MXN.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 [Currency.Php, { currency: PHP, locale: \"en-PH\" }],\n [Currency.Cny, { currency: CNY, locale: \"zh-CN\" }],\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 *\n * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change\n *\n * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires\n * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for\n * different tax calculations is there just need to enable on the share side and test if it works\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 handle per-item tax rate\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n] as StoreId[]);\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":["roundToNearestFull059","input","roundedNumber","Math","round","remainder","roundToNearestDecimalCent","parseFloat","toFixed","roundToNearestHalfUnitCent","Round","Financial","halfAwayFromZero","Shipping","Prettify","down","PrettifyFull059","PrettifyDecimalCents","PrettifyHalfUnitCents","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","AED","ZAR","MXN","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","CAD","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","EUR","Gbp","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","Php","PHP","Cny","CNY","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;AA+Ca,MAAAA,qBAAA,GAAqCC,KAAkB,IAAA;EAClE,IAAIA,UAAU,CAAG,EAAA;IACR,OAAA,CAAA;EAAA;EAIT,IAAIA,SAAS,CAAG,EAAA;IACP,OAAA,CAAA;EAAA;EAOH,MAAAC,aAAA,GAAgBC,IAAK,CAAAC,KAAA,CAAMH,KAAK,CAAA;EAGtC,MAAMI,YAAYH,aAAgB,GAAA,EAAA;EAClC,IAAIG,aAAa,CAAG,EAAA;IAElB,OAAOH,aAAgB,GAAAG,SAAA;EAAA,CACzB,MAAA,IAAWA,aAAa,CAAG,EAAA;IAEzB,OAAOH,gBAAgBG,SAAY,GAAA,CAAA;EAAA,CAC9B,MAAA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AeY,MAAA2C,wBAAA,GAAA,mBAA+BC,GAAI,CAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA,CAWlC,CAAA;AAKP,MAAMC,wBAA2B,GAAA;EACtCC,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVzD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAM0D,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVzD,IAAM,EAAA;EAAA;AACR,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 CNY,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PHP,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfAwayFromZero, halfUp } from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { Currency } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to nearest FULL 0/5/9 (and strip cents)\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestFull059: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-5.00\n if (input <= 5) {\n return 5;\n }\n\n /**\n * Input comes as float, for this rounding we don't need cents, so round\n * to nearest full number\n */\n const roundedNumber = Math.round(input);\n\n // Determine nearest rounding value\n const remainder = roundedNumber % 10;\n if (remainder <= 2) {\n // Round down to nearest 0\n return roundedNumber - remainder;\n } else if (remainder <= 7) {\n // Round to nearest 5\n return roundedNumber - remainder + 5;\n } else {\n // Round up to nearest 9\n return roundedNumber - remainder + 9;\n }\n};\n\nexport const roundToNearestValidUiCarePrice: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-5.00\n if (input <= 5) {\n return 5;\n }\n\n // Determine nearest rounding value\n const remainder = input % 10;\n if (remainder <= 2) {\n // Round down to nearest 9\n return input - remainder - 1;\n } else if (remainder <= 5) {\n // Round to nearest 5\n return input - remainder + 5;\n } else {\n // Round up to nearest 9\n return input - remainder + 9;\n }\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest decimal cent. e.g. 1.53 = 1.50 / 1.57 = 1.60\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestDecimalCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.09\n if (input <= 0.1) {\n return 0.1;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n */\n return parseFloat((Math.round(input * 10) / 10).toFixed(1));\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest .50 or .00. e.g. 11.22 = 11 / 11.55 = 11.50 / 11.90 = 12\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestHalfUnitCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.5\n if (input <= 0.5) {\n return 0.5;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n *\n * Multiply by 2, round to the nearest integer, then divide by 2 to get the nearest .5 or .0\n * Return with fixed precision to avoid floating-point artifacts\n */\n return parseFloat((Math.round(input * 2) / 2).toFixed(2));\n};\n\nexport const Round = {\n /**\n * !!!!!!!!!!!!!!\n * ! Update 2024\n * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax\n * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html\n * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\n * !!!!!!!!!!!!!!\n *\n * OLD: halfEven docs\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 * normalize 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/v2.0.0-alpha.8/packages/core/src/round/halfEven.ts\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behavior\n * based on if the rounded 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\n * (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: halfAwayFromZero,\n // https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\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: roundToNearestDecimalCent,\n Prettify: down,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyFull059: roundToNearestFull059,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyDecimalCents: roundToNearestDecimalCent,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyHalfUnitCents: roundToNearestHalfUnitCent,\n Subunit: halfUp,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n * ! For correct rounding UI Care prices, used for auto managed UI Care products.\n */\n ValidUiCarePrice: roundToNearestValidUiCarePrice,\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 [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n [MXN.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 [Currency.Php, { currency: PHP, locale: \"en-PH\" }],\n [Currency.Cny, { currency: CNY, locale: \"zh-CN\" }],\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 *\n * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change\n *\n * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires\n * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for\n * different tax calculations is there just need to enable on the share side and test if it works\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 handle per-item tax rate\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n] as StoreId[]);\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":["roundToNearestFull059","input","roundedNumber","Math","round","remainder","roundToNearestValidUiCarePrice","roundToNearestDecimalCent","parseFloat","toFixed","roundToNearestHalfUnitCent","Round","Financial","halfAwayFromZero","Shipping","Prettify","down","PrettifyFull059","PrettifyDecimalCents","PrettifyHalfUnitCents","Subunit","halfUp","ValidUiCarePrice","prettifyPriceLookup","Map","USD","code","AED","ZAR","MXN","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","CAD","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","EUR","Gbp","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","Php","PHP","Cny","CNY","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;AA+Ca,MAAAA,qBAAA,GAAqCC,KAAkB,IAAA;EAClE,IAAIA,UAAU,CAAG,EAAA;IACR,OAAA,CAAA;EAAA;EAIT,IAAIA,SAAS,CAAG,EAAA;IACP,OAAA,CAAA;EAAA;EAOH,MAAAC,aAAA,GAAgBC,IAAK,CAAAC,KAAA,CAAMH,KAAK,CAAA;EAGtC,MAAMI,YAAYH,aAAgB,GAAA,EAAA;EAClC,IAAIG,aAAa,CAAG,EAAA;IAElB,OAAOH,aAAgB,GAAAG,SAAA;EAAA,CACzB,MAAA,IAAWA,aAAa,CAAG,EAAA;IAEzB,OAAOH,gBAAgBG,SAAY,GAAA,CAAA;EAAA,CAC9B,MAAA;IAEL,OAAOH,gBAAgBG,SAAY,GAAA,CAAA;EAAA;AAEvC,CAAA;AAEa,MAAAC,8BAAA,GAA8CL,KAAkB,IAAA;EAC3E,IAAIA,UAAU,CAAG,EAAA;IACR,OAAA,CAAA;EAAA;EAIT,IAAIA,SAAS,CAAG,EAAA;IACP,OAAA,CAAA;EAAA;EAIT,MAAMI,YAAYJ,K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EvC,UAAUN,GAAK;EAAAO,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAS0C,GAAK,EAAA;EAAExC,UAAUyC,GAAK;EAAAxC,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAS4C,GAAK,EAAA;EAAE1C,UAAU2C,GAAK;EAAA1C,MAAA,EAAQ;AAAS,CAAA,CAAA,CAClD,CAAA;AAeY,MAAA2C,wBAAA,GAAA,mBAA+BC,GAAI,CAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA,CAWlC,CAAA;AAKP,MAAMC,wBAA2B,GAAA;EACtCC,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVzD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAM0D,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVzD,IAAM,EAAA;EAAA;AACR,CAAA;"}
@@ -20,6 +20,7 @@ exports.prettifyPriceLookup = constants.prettifyPriceLookup;
20
20
  exports.roundToNearestDecimalCent = constants.roundToNearestDecimalCent;
21
21
  exports.roundToNearestFull059 = constants.roundToNearestFull059;
22
22
  exports.roundToNearestHalfUnitCent = constants.roundToNearestHalfUnitCent;
23
+ exports.roundToNearestValidUiCarePrice = constants.roundToNearestValidUiCarePrice;
23
24
  exports.smallestSubunitLookup = constants.smallestSubunitLookup;
24
25
  exports.storesWithPerItemTaxRate = constants.storesWithPerItemTaxRate;
25
26
  exports.invertExchangeRate = exchangeRate.invertExchangeRate;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  export { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
2
2
  export { ProductAmountAllocator } from './allocators/productAmount.mjs';
3
- export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, roundToNearestDecimalCent, roundToNearestFull059, roundToNearestHalfUnitCent, smallestSubunitLookup, storesWithPerItemTaxRate } from './constants.mjs';
3
+ export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, roundToNearestDecimalCent, roundToNearestFull059, roundToNearestHalfUnitCent, roundToNearestValidUiCarePrice, smallestSubunitLookup, storesWithPerItemTaxRate } from './constants.mjs';
4
4
  export { invertExchangeRate, toFixedExchangeRate, toSnapshotExchangeRate } from './exchangeRate.mjs';
5
5
  export { formatPrice, formatPriceRaw, getLocalizedCurrency, prettifyTotal } from './format.mjs';
6
6
  export { addMany, amount, centsToCurrencyUnit, currency, dineroToCurrencyUnit, getDinero, getDineroCurrency, money, multiplyByFullPercent, parseCurrencyCode, parseFloatToDinero, parseFloatToDineroRaw, roundDinero, stringAmountToDinero, subtractMany, toSmallestSubunit } from './misc.mjs';
@@ -7,9 +7,15 @@ import type { Money } from "./money/types";
7
7
  export declare const getFreeShippingDaysPerStore: (storeId: Nullish<StoreId>) => Nullish<number>;
8
8
  export declare const getIsSignatureRequired: (options: {
9
9
  storeId: StoreId;
10
- subtotal: Money;
10
+ items: {
11
+ subtotal: Money;
12
+ sku: string[];
13
+ };
14
+ shipment: {
15
+ isNextDay: boolean;
16
+ };
11
17
  customer: Nullish<{
12
- isGuest: boolean;
18
+ ssoCreatedAt: Nullish<Date>;
13
19
  }>;
14
20
  paymentProvider: Nullish<PaymentProvider>;
15
21
  }) => boolean;
@@ -1,10 +1,17 @@
1
1
  'use strict';
2
2
 
3
+ var dayjs = require('dayjs');
3
4
  var dinero_js = require('dinero.js');
4
5
  require('../types/index.js');
5
6
  var errors = require('./errors.js');
6
7
  var misc = require('./money/misc.js');
7
8
  var generated = require('../types/generated.js');
9
+ function _interopDefault(e) {
10
+ return e && e.__esModule ? e : {
11
+ default: e
12
+ };
13
+ }
14
+ var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
8
15
  "use strict";
9
16
  const getFreeShippingDaysPerStore = storeId => {
10
17
  if (!storeId) {
@@ -42,7 +49,6 @@ const getFreeShippingDaysPerStore = storeId => {
42
49
  }
43
50
  };
44
51
  const getIsSignatureRequired = options => {
45
- const isGuest = options.customer ? options.customer.isGuest : true;
46
52
  switch (options.storeId) {
47
53
  case generated.StoreId.Br:
48
54
  case generated.StoreId.Ca:
@@ -62,8 +68,46 @@ const getIsSignatureRequired = options => {
62
68
  }
63
69
  case generated.StoreId.Us:
64
70
  {
71
+ let isGuestLike = true;
72
+ if (options.customer?.ssoCreatedAt) {
73
+ const daysSinceCreation = dayjs__default["default"]().diff(dayjs__default["default"](options.customer.ssoCreatedAt), "days");
74
+ if (daysSinceCreation >= 90) {
75
+ isGuestLike = false;
76
+ }
77
+ }
78
+ if (!isGuestLike) {
79
+ return false;
80
+ }
65
81
  const threshold = options.paymentProvider === generated.PaymentProvider.Paypal ? misc.getDinero(1e5, generated.Currency.Usd) : misc.getDinero(2e5, generated.Currency.Usd);
66
- return isGuest && dinero_js.greaterThanOrEqual(misc.getDinero(options.subtotal.amount, options.subtotal.currency), threshold);
82
+ if (options.shipment.isNextDay) {
83
+ if (options.items.sku.length === 1) {
84
+ return true;
85
+ }
86
+ const {
87
+ hasUswPro,
88
+ hasUacc,
89
+ hasUCable
90
+ } = options.items.sku.reduce((acc, curr) => {
91
+ if (curr.toLowerCase().startsWith("usw-pro")) {
92
+ acc.hasUswPro = true;
93
+ }
94
+ if (curr.toLowerCase().startsWith("uacc")) {
95
+ acc.hasUacc = true;
96
+ }
97
+ if (curr.toLowerCase().startsWith("u-cable")) {
98
+ acc.hasUCable = true;
99
+ }
100
+ return acc;
101
+ }, {
102
+ hasUswPro: false,
103
+ hasUacc: false,
104
+ hasUCable: false
105
+ });
106
+ if (hasUswPro && (hasUacc || hasUCable)) {
107
+ return true;
108
+ }
109
+ }
110
+ return dinero_js.greaterThanOrEqual(misc.getDinero(options.items.subtotal.amount, options.items.subtotal.currency), threshold);
67
111
  }
68
112
  default:
69
113
  {
@@ -1 +1 @@
1
- {"version":3,"file":"shipping.js","sources":["../../src/utils/shipping.ts"],"sourcesContent":["import { greaterThanOrEqual } from \"dinero.js\";\n\nimport type { Nullish } from \"../types\";\nimport { Currency, PaymentProvider, StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\nimport { getDinero } from \"./money/misc\";\nimport type { Money } from \"./money/types\";\n\n/**\n * Utility to get how many days free shipping will be for a specific store, defaulting to a fallback value\n */\nexport const getFreeShippingDaysPerStore = (\n // Instead of using StoreId type using plain string so if we add a new store it won't break types as we already have\n // configured a explicity default behavior\n storeId: Nullish<StoreId>,\n): Nullish<number> => {\n if (!storeId) {\n // Return undefined to indicate detect \"loading state\" as we can't determine it yet\n return undefined;\n }\n\n /**\n * Reasoning for values:\n * - Singapore - https://ui.slack.com/archives/C02CXF2Q7B4/p1709209947062139\n * - Brazil - we read dynamically latest option as free so there is no guarantee\n * - Japan - same as other just standard 5-days\n */\n switch (storeId) {\n case StoreId.Ca:\n case StoreId.Za:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return 5;\n }\n case StoreId.Me: {\n return 2;\n }\n case StoreId.Us:\n case StoreId.Mx:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.In:\n case StoreId.Cn:\n case StoreId.Br: {\n // Return null to indicate \"no match\"\n return null;\n }\n\n default: {\n checkUnreachable(storeId);\n // Return null to indicate \"no match\"\n return null;\n }\n }\n};\n\nexport const getIsSignatureRequired = (options: {\n storeId: StoreId;\n subtotal: Money;\n customer: Nullish<{ isGuest: boolean }>;\n paymentProvider: Nullish<PaymentProvider>;\n}): boolean => {\n // If customer is not present, assume it's guest by default\n const isGuest = options.customer ? options.customer.isGuest : true;\n\n switch (options.storeId) {\n case StoreId.Br:\n case StoreId.Ca:\n case StoreId.Cn:\n case StoreId.Eu:\n case StoreId.In:\n case StoreId.Jp:\n case StoreId.Me:\n case StoreId.Mx:\n case StoreId.Ph:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Uk:\n case StoreId.Za: {\n return false;\n }\n\n case StoreId.Us: {\n const threshold =\n options.paymentProvider === PaymentProvider.Paypal\n ? getDinero(1000_00, Currency.Usd)\n : getDinero(2000_00, Currency.Usd);\n\n return (\n isGuest &&\n greaterThanOrEqual(\n getDinero(options.subtotal.amount, options.subtotal.currency),\n threshold,\n )\n );\n }\n\n default: {\n checkUnreachable(options.storeId);\n return false;\n }\n }\n};\n"],"names":["getFreeShippingDaysPerStore","storeId","StoreId","Ca","Za","Sg","Tw","Jp","Ph","Me","Us","Mx","Eu","Uk","In","Cn","Br","checkUnreachable","getIsSignatureRequired","options","isGuest","customer","threshold","paymentProvider","PaymentProvider","Paypal","getDinero","Currency","Usd","greaterThanOrEqual","subtotal","amount","currency"],"mappings":";;;;;;;;AAWa,MAAAA,2BAAA,GAGXC,OACoB,IAAA;EACpB,IAAI,CAACA,OAAS,EAAA;IAEL,OAAA,KAAA,CAAA;EAAA;EAST,QAAQA,OAAS;IACf,KAAKC,SAAQ,CAAAA,OAAA,CAAAC,EAAA;IACb,KAAKD,SAAQ,CAAAA,OAAA,CAAAE,EAAA;IACb,KAAKF,SAAQ,CAAAA,OAAA,CAAAG,EAAA;IACb,KAAKH,SAAQ,CAAAA,OAAA,CAAAI,EAAA;IACb,KAAKJ,SAAQ,CAAAA,OAAA,CAAAK,EAAA;IACb,KAAKL,SAAAA,CAAAA,QAAQM,EAAI;MAAA;QACR,OAAA,CAAA;MAAA;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;IACb,KAAKX,SAAAA,CAAAA,QAAQE,EAAI;MAAA;QACR,OAAA,KAAA;MAAA;IAGT,KAAKF,SAAAA,CAAAA,QAAQQ,EAAI;MAAA;QACf,MAAMY,SACJ,GAAAH,OAAA,CAAQI,eAAoB,KAAAC,SAAA,CAAAA,eAAA,CAAgBC,MACxC,GAAAC,IAAA,CAAAA,SAAA,CAAU,GAAS,EAAAC,SAAA,CAAAA,QAAA,CAASC,GAAG,CAAA,GAC/BF,IAAAA,CAAAA,SAAU,CAAA,GAAA,EAASC,SAAAA,CAAAA,SAASC,GAAG,CAAA;QAErC,OACER,OACA,IAAAS,SAAA,CAAAA,kBAAA,CACEH,eAAUP,OAAQ,CAAAW,QAAA,CAASC,MAAQ,EAAAZ,OAAA,CAAQW,SAASE,QAAQ,CAAA,EAC5DV,SACF,CAAA;MAAA;IAIJ;MAAS;QACPL,MAAA,CAAAA,gBAAA,CAAiBE,QAAQlB,OAAO,CAAA;QACzB,OAAA,KAAA;MAAA;EACT;AAEJ,CAAA;;"}
1
+ {"version":3,"file":"shipping.js","sources":["../../src/utils/shipping.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport { greaterThanOrEqual } from \"dinero.js\";\n\nimport type { Nullish } from \"../types\";\nimport { Currency, PaymentProvider, StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\nimport { getDinero } from \"./money/misc\";\nimport type { Money } from \"./money/types\";\n\n/**\n * Utility to get how many days free shipping will be for a specific store, defaulting to a fallback value\n */\nexport const getFreeShippingDaysPerStore = (\n // Instead of using StoreId type using plain string so if we add a new store it won't break types as we already have\n // configured a explicity default behavior\n storeId: Nullish<StoreId>,\n): Nullish<number> => {\n if (!storeId) {\n // Return undefined to indicate detect \"loading state\" as we can't determine it yet\n return undefined;\n }\n\n /**\n * Reasoning for values:\n * - Singapore - https://ui.slack.com/archives/C02CXF2Q7B4/p1709209947062139\n * - Brazil - we read dynamically latest option as free so there is no guarantee\n * - Japan - same as other just standard 5-days\n */\n switch (storeId) {\n case StoreId.Ca:\n case StoreId.Za:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return 5;\n }\n case StoreId.Me: {\n return 2;\n }\n case StoreId.Us:\n case StoreId.Mx:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.In:\n case StoreId.Cn:\n case StoreId.Br: {\n // Return null to indicate \"no match\"\n return null;\n }\n\n default: {\n checkUnreachable(storeId);\n // Return null to indicate \"no match\"\n return null;\n }\n }\n};\n\nexport const getIsSignatureRequired = (options: {\n storeId: StoreId;\n items: {\n subtotal: Money;\n sku: string[];\n };\n shipment: {\n isNextDay: boolean;\n };\n customer: Nullish<{ ssoCreatedAt: Nullish<Date> }>;\n paymentProvider: Nullish<PaymentProvider>;\n}): boolean => {\n switch (options.storeId) {\n case StoreId.Br:\n case StoreId.Ca:\n case StoreId.Cn:\n case StoreId.Eu:\n case StoreId.In:\n case StoreId.Jp:\n case StoreId.Me:\n case StoreId.Mx:\n case StoreId.Ph:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Uk:\n case StoreId.Za: {\n return false;\n }\n\n case StoreId.Us: {\n // Assume by default customer is guest like\n let isGuestLike = true;\n\n // Consider customer as guest like, if their account was created within last 3 months\n if (options.customer?.ssoCreatedAt) {\n // Using dayjs\n const daysSinceCreation = dayjs().diff(\n dayjs(options.customer.ssoCreatedAt),\n \"days\",\n );\n if (daysSinceCreation >= 90) {\n isGuestLike = false;\n }\n }\n\n // If customer is not guest like, we don't need to check for signature requirement\n if (!isGuestLike) {\n return false;\n }\n\n const threshold =\n options.paymentProvider === PaymentProvider.Paypal\n ? getDinero(1000_00, Currency.Usd)\n : getDinero(2000_00, Currency.Usd);\n\n // Next day shipment scenario:\n if (options.shipment.isNextDay) {\n if (options.items.sku.length === 1) {\n return true;\n }\n\n const { hasUswPro, hasUacc, hasUCable } = options.items.sku.reduce<{\n hasUswPro: boolean;\n hasUacc: boolean;\n hasUCable: boolean;\n }>(\n (acc, curr) => {\n if (curr.toLowerCase().startsWith(\"usw-pro\")) {\n acc.hasUswPro = true;\n }\n\n if (curr.toLowerCase().startsWith(\"uacc\")) {\n acc.hasUacc = true;\n }\n\n if (curr.toLowerCase().startsWith(\"u-cable\")) {\n acc.hasUCable = true;\n }\n\n return acc;\n },\n {\n hasUswPro: false,\n hasUacc: false,\n hasUCable: false,\n },\n );\n\n if (hasUswPro && (hasUacc || hasUCable)) {\n return true;\n }\n }\n\n // Threshold scenario:\n return greaterThanOrEqual(\n getDinero(\n options.items.subtotal.amount,\n options.items.subtotal.currency,\n ),\n threshold,\n );\n }\n\n default: {\n checkUnreachable(options.storeId);\n return false;\n }\n }\n};\n"],"names":["getFreeShippingDaysPerStore","storeId","StoreId","Ca","Za","Sg","Tw","Jp","Ph","Me","Us","Mx","Eu","Uk","In","Cn","Br","checkUnreachable","getIsSignatureRequired","options","isGuestLike","customer","ssoCreatedAt","daysSinceCreation","dayjs","diff","threshold","paymentProvider","PaymentProvider","Paypal","getDinero","Currency","Usd","shipment","isNextDay","items","sku","length","hasUswPro","hasUacc","hasUCable","reduce","acc","curr","toLowerCase","startsWith","greaterThanOrEqual","subtotal","amount","currency"],"mappings":";;;;;;;;;;;;;;;AAYa,MAAAA,2BAAA,GAGXC,OACoB,IAAA;EACpB,IAAI,CAACA,OAAS,EAAA;IAEL,OAAA,KAAA,CAAA;EAAA;EAST,QAAQA,OAAS;IACf,KAAKC,SAAQ,CAAAA,OAAA,CAAAC,EAAA;IACb,KAAKD,SAAQ,CAAAA,OAAA,CAAAE,EAAA;IACb,KAAKF,SAAQ,CAAAA,OAAA,CAAAG,EAAA;IACb,KAAKH,SAAQ,CAAAA,OAAA,CAAAI,EAAA;IACb,KAAKJ,SAAQ,CAAAA,OAAA,CAAAK,EAAA;IACb,KAAKL,SAAAA,CAAAA,QAAQM,EAAI;MAAA;QACR,OAAA,CAAA;MAAA;IAET,KAAKN,SAAAA,CAAAA,QAAQO,EAAI;MAAA;QACR,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AAE,GAAA;UACT,CAAA,EACA;YACEJ,SAAW,EAAA,KAAA;YACXC,OAAS,EAAA,KAAA;YACTC,SAAW,EAAA;UAAA,CAEf,CAAA;UAEI,IAAAF,SAAA,KAAcC,WAAWC,SAAY,CAAA,EAAA;YAChC,OAAA,IAAA;UAAA;QACT;QAIK,OAAAM,SAAA,CAAAA,kBAAA,CACLhB,IAAA,CAAAA,SAAA,CACEX,OAAA,CAAQgB,MAAMY,QAAS,CAAAC,MAAA,EACvB7B,OAAA,CAAQgB,MAAMY,QAAS,CAAAE,QACzB,CAAA,EACAvB,SACF,CAAA;MAAA;IAGF;MAAS;QACPT,MAAA,CAAAA,gBAAA,CAAiBE,QAAQlB,OAAO,CAAA;QACzB,OAAA,KAAA;MAAA;EACT;AAEJ,CAAA;;"}
@@ -1,3 +1,4 @@
1
+ import dayjs from 'dayjs';
1
2
  import { greaterThanOrEqual } from 'dinero.js';
2
3
  import '../types/index.mjs';
3
4
  import { checkUnreachable } from './errors.mjs';
@@ -40,7 +41,6 @@ const getFreeShippingDaysPerStore = storeId => {
40
41
  }
41
42
  };
42
43
  const getIsSignatureRequired = options => {
43
- const isGuest = options.customer ? options.customer.isGuest : true;
44
44
  switch (options.storeId) {
45
45
  case StoreId.Br:
46
46
  case StoreId.Ca:
@@ -60,8 +60,46 @@ const getIsSignatureRequired = options => {
60
60
  }
61
61
  case StoreId.Us:
62
62
  {
63
+ let isGuestLike = true;
64
+ if (options.customer?.ssoCreatedAt) {
65
+ const daysSinceCreation = dayjs().diff(dayjs(options.customer.ssoCreatedAt), "days");
66
+ if (daysSinceCreation >= 90) {
67
+ isGuestLike = false;
68
+ }
69
+ }
70
+ if (!isGuestLike) {
71
+ return false;
72
+ }
63
73
  const threshold = options.paymentProvider === PaymentProvider.Paypal ? getDinero(1e5, Currency.Usd) : getDinero(2e5, Currency.Usd);
64
- return isGuest && greaterThanOrEqual(getDinero(options.subtotal.amount, options.subtotal.currency), threshold);
74
+ if (options.shipment.isNextDay) {
75
+ if (options.items.sku.length === 1) {
76
+ return true;
77
+ }
78
+ const {
79
+ hasUswPro,
80
+ hasUacc,
81
+ hasUCable
82
+ } = options.items.sku.reduce((acc, curr) => {
83
+ if (curr.toLowerCase().startsWith("usw-pro")) {
84
+ acc.hasUswPro = true;
85
+ }
86
+ if (curr.toLowerCase().startsWith("uacc")) {
87
+ acc.hasUacc = true;
88
+ }
89
+ if (curr.toLowerCase().startsWith("u-cable")) {
90
+ acc.hasUCable = true;
91
+ }
92
+ return acc;
93
+ }, {
94
+ hasUswPro: false,
95
+ hasUacc: false,
96
+ hasUCable: false
97
+ });
98
+ if (hasUswPro && (hasUacc || hasUCable)) {
99
+ return true;
100
+ }
101
+ }
102
+ return greaterThanOrEqual(getDinero(options.items.subtotal.amount, options.items.subtotal.currency), threshold);
65
103
  }
66
104
  default:
67
105
  {
@@ -1 +1 @@
1
- {"version":3,"file":"shipping.mjs","sources":["../../src/utils/shipping.ts"],"sourcesContent":["import { greaterThanOrEqual } from \"dinero.js\";\n\nimport type { Nullish } from \"../types\";\nimport { Currency, PaymentProvider, StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\nimport { getDinero } from \"./money/misc\";\nimport type { Money } from \"./money/types\";\n\n/**\n * Utility to get how many days free shipping will be for a specific store, defaulting to a fallback value\n */\nexport const getFreeShippingDaysPerStore = (\n // Instead of using StoreId type using plain string so if we add a new store it won't break types as we already have\n // configured a explicity default behavior\n storeId: Nullish<StoreId>,\n): Nullish<number> => {\n if (!storeId) {\n // Return undefined to indicate detect \"loading state\" as we can't determine it yet\n return undefined;\n }\n\n /**\n * Reasoning for values:\n * - Singapore - https://ui.slack.com/archives/C02CXF2Q7B4/p1709209947062139\n * - Brazil - we read dynamically latest option as free so there is no guarantee\n * - Japan - same as other just standard 5-days\n */\n switch (storeId) {\n case StoreId.Ca:\n case StoreId.Za:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return 5;\n }\n case StoreId.Me: {\n return 2;\n }\n case StoreId.Us:\n case StoreId.Mx:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.In:\n case StoreId.Cn:\n case StoreId.Br: {\n // Return null to indicate \"no match\"\n return null;\n }\n\n default: {\n checkUnreachable(storeId);\n // Return null to indicate \"no match\"\n return null;\n }\n }\n};\n\nexport const getIsSignatureRequired = (options: {\n storeId: StoreId;\n subtotal: Money;\n customer: Nullish<{ isGuest: boolean }>;\n paymentProvider: Nullish<PaymentProvider>;\n}): boolean => {\n // If customer is not present, assume it's guest by default\n const isGuest = options.customer ? options.customer.isGuest : true;\n\n switch (options.storeId) {\n case StoreId.Br:\n case StoreId.Ca:\n case StoreId.Cn:\n case StoreId.Eu:\n case StoreId.In:\n case StoreId.Jp:\n case StoreId.Me:\n case StoreId.Mx:\n case StoreId.Ph:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Uk:\n case StoreId.Za: {\n return false;\n }\n\n case StoreId.Us: {\n const threshold =\n options.paymentProvider === PaymentProvider.Paypal\n ? getDinero(1000_00, Currency.Usd)\n : getDinero(2000_00, Currency.Usd);\n\n return (\n isGuest &&\n greaterThanOrEqual(\n getDinero(options.subtotal.amount, options.subtotal.currency),\n threshold,\n )\n );\n }\n\n default: {\n checkUnreachable(options.storeId);\n return false;\n }\n }\n};\n"],"names":["getFreeShippingDaysPerStore","storeId","StoreId","Ca","Za","Sg","Tw","Jp","Ph","Me","Us","Mx","Eu","Uk","In","Cn","Br","checkUnreachable","getIsSignatureRequired","options","isGuest","customer","threshold","paymentProvider","PaymentProvider","Paypal","getDinero","Currency","Usd","greaterThanOrEqual","subtotal","amount","currency"],"mappings":";;;;;;AAWa,MAAAA,2BAAA,GAGXC,OACoB,IAAA;EACpB,IAAI,CAACA,OAAS,EAAA;IAEL,OAAA,KAAA,CAAA;EAAA;EAST,QAAQA,OAAS;IACf,KAAKC,OAAQ,CAAAC,EAAA;IACb,KAAKD,OAAQ,CAAAE,EAAA;IACb,KAAKF,OAA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AA,CAAgBC,MACxC,GAAAC,SAAA,CAAU,GAAS,EAAAC,QAAA,CAASC,GAAG,CAAA,GAC/BF,SAAU,CAAA,GAAA,EAASC,SAASC,GAAG,CAAA;QAErC,OACER,OACA,IAAAS,kBAAA,CACEH,UAAUP,OAAQ,CAAAW,QAAA,CAASC,MAAQ,EAAAZ,OAAA,CAAQW,SAASE,QAAQ,CAAA,EAC5DV,SACF,CAAA;MAAA;IAIJ;MAAS;QACPL,gBAAA,CAAiBE,QAAQlB,OAAO,CAAA;QACzB,OAAA,KAAA;MAAA;EACT;AAEJ,CAAA;"}
1
+ {"version":3,"file":"shipping.mjs","sources":["../../src/utils/shipping.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport { greaterThanOrEqual } from \"dinero.js\";\n\nimport type { Nullish } from \"../types\";\nimport { Currency, PaymentProvider, StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\nimport { getDinero } from \"./money/misc\";\nimport type { Money } from \"./money/types\";\n\n/**\n * Utility to get how many days free shipping will be for a specific store, defaulting to a fallback value\n */\nexport const getFreeShippingDaysPerStore = (\n // Instead of using StoreId type using plain string so if we add a new store it won't break types as we already have\n // configured a explicity default behavior\n storeId: Nullish<StoreId>,\n): Nullish<number> => {\n if (!storeId) {\n // Return undefined to indicate detect \"loading state\" as we can't determine it yet\n return undefined;\n }\n\n /**\n * Reasoning for values:\n * - Singapore - https://ui.slack.com/archives/C02CXF2Q7B4/p1709209947062139\n * - Brazil - we read dynamically latest option as free so there is no guarantee\n * - Japan - same as other just standard 5-days\n */\n switch (storeId) {\n case StoreId.Ca:\n case StoreId.Za:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return 5;\n }\n case StoreId.Me: {\n return 2;\n }\n case StoreId.Us:\n case StoreId.Mx:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.In:\n case StoreId.Cn:\n case StoreId.Br: {\n // Return null to indicate \"no match\"\n return null;\n }\n\n default: {\n checkUnreachable(storeId);\n // Return null to indicate \"no match\"\n return null;\n }\n }\n};\n\nexport const getIsSignatureRequired = (options: {\n storeId: StoreId;\n items: {\n subtotal: Money;\n sku: string[];\n };\n shipment: {\n isNextDay: boolean;\n };\n customer: Nullish<{ ssoCreatedAt: Nullish<Date> }>;\n paymentProvider: Nullish<PaymentProvider>;\n}): boolean => {\n switch (options.storeId) {\n case StoreId.Br:\n case StoreId.Ca:\n case StoreId.Cn:\n case StoreId.Eu:\n case StoreId.In:\n case StoreId.Jp:\n case StoreId.Me:\n case StoreId.Mx:\n case StoreId.Ph:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Uk:\n case StoreId.Za: {\n return false;\n }\n\n case StoreId.Us: {\n // Assume by default customer is guest like\n let isGuestLike = true;\n\n // Consider customer as guest like, if their account was created within last 3 months\n if (options.customer?.ssoCreatedAt) {\n // Using dayjs\n const daysSinceCreation = dayjs().diff(\n dayjs(options.customer.ssoCreatedAt),\n \"days\",\n );\n if (daysSinceCreation >= 90) {\n isGuestLike = false;\n }\n }\n\n // If customer is not guest like, we don't need to check for signature requirement\n if (!isGuestLike) {\n return false;\n }\n\n const threshold =\n options.paymentProvider === PaymentProvider.Paypal\n ? getDinero(1000_00, Currency.Usd)\n : getDinero(2000_00, Currency.Usd);\n\n // Next day shipment scenario:\n if (options.shipment.isNextDay) {\n if (options.items.sku.length === 1) {\n return true;\n }\n\n const { hasUswPro, hasUacc, hasUCable } = options.items.sku.reduce<{\n hasUswPro: boolean;\n hasUacc: boolean;\n hasUCable: boolean;\n }>(\n (acc, curr) => {\n if (curr.toLowerCase().startsWith(\"usw-pro\")) {\n acc.hasUswPro = true;\n }\n\n if (curr.toLowerCase().startsWith(\"uacc\")) {\n acc.hasUacc = true;\n }\n\n if (curr.toLowerCase().startsWith(\"u-cable\")) {\n acc.hasUCable = true;\n }\n\n return acc;\n },\n {\n hasUswPro: false,\n hasUacc: false,\n hasUCable: false,\n },\n );\n\n if (hasUswPro && (hasUacc || hasUCable)) {\n return true;\n }\n }\n\n // Threshold scenario:\n return greaterThanOrEqual(\n getDinero(\n options.items.subtotal.amount,\n options.items.subtotal.currency,\n ),\n threshold,\n );\n }\n\n default: {\n checkUnreachable(options.storeId);\n return false;\n }\n }\n};\n"],"names":["getFreeShippingDaysPerStore","storeId","StoreId","Ca","Za","Sg","Tw","Jp","Ph","Me","Us","Mx","Eu","Uk","In","Cn","Br","checkUnreachable","getIsSignatureRequired","options","isGuestLike","customer","ssoCreatedAt","daysSinceCreation","dayjs","diff","threshold","paymentProvider","PaymentProvider","Paypal","getDinero","Currency","Usd","shipment","isNextDay","items","sku","length","hasUswPro","hasUacc","hasUCable","reduce","acc","curr","toLowerCase","startsWith","greaterThanOrEqual","subtotal","amount","currency"],"mappings":";;;;;;;AAYa,MAAAA,2BAAA,GAGXC,OACoB,IAAA;EACpB,IAAI,CAACA,OAAS,EAAA;IAEL,OAAA,KAAA,CAAA;EAAA;EAST,QAAQA,OAAS;IACf,KAAKC,OAAQ,CAAAC,EAAA;IACb,KAAKD,OAAQ,CAAAE,EAAA;IACb,KAAKF,OAAQ,CAAAG,EAAA;IACb,KAAKH,OAAQ,CAAAI,EAAA;IACb,KAAKJ,OAAQ,CAAAK,EAAA;IACb,KAAKL,QAAQM,EAAI;MAAA;QACR,OAAA,CAAA;MAAA;IAET,KAAKN,QAAQO,EAAI;MAAA;QACR,OAAA,CAAA;MAAA;IAET,KAAKP,OAAQ,CAAAQ,EAAA;IACb,KAAKR,OAAQ,CAAAS,EAAA;IACb,KAAKT,OAAQ,CAAAU,EAAA;IACb,KAAKV,OAAQ,CAAAW,EAAA;IACb,KAAKX,OAAQ,CAAAY,EAAA;IACb,KAAKZ,OAAQ,CAAAa,EAAA;IACb,KAAKb,QAAQc,EAAI;MAAA;QAER,OAAA,IAAA;MAAA;IAGT;MAAS;QACPC,gBAAA,CAAiBhB,OAAO,CAAA;QAEjB,OAAA,IAAA;MAAA;EACT;AAEJ,CAAA;AAEa,MAAAi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AA;YAASC;UAAc,CAAA,GAAArB,OAAA,CAAQgB,MAAMC,GAAI,CAAAK,MAAA,CAK1D,CAACC,KAAKC,IAAS,KAAA;YACb,IAAIA,IAAK,CAAAC,WAAA,CAAA,CAAc,CAAAC,UAAA,CAAW,SAAS,CAAG,EAAA;cAC5CH,GAAA,CAAIJ,SAAY,GAAA,IAAA;YAAA;YAGlB,IAAIK,IAAK,CAAAC,WAAA,CAAA,CAAc,CAAAC,UAAA,CAAW,MAAM,CAAG,EAAA;cACzCH,GAAA,CAAIH,OAAU,GAAA,IAAA;YAAA;YAGhB,IAAII,IAAK,CAAAC,WAAA,CAAA,CAAc,CAAAC,UAAA,CAAW,SAAS,CAAG,EAAA;cAC5CH,GAAA,CAAIF,SAAY,GAAA,IAAA;YAAA;YAGX,OAAAE,GAAA;UACT,CAAA,EACA;YACEJ,SAAW,EAAA,KAAA;YACXC,OAAS,EAAA,KAAA;YACTC,SAAW,EAAA;UAAA,CAEf,CAAA;UAEI,IAAAF,SAAA,KAAcC,WAAWC,SAAY,CAAA,EAAA;YAChC,OAAA,IAAA;UAAA;QACT;QAIK,OAAAM,kBAAA,CACLhB,SAAA,CACEX,OAAA,CAAQgB,MAAMY,QAAS,CAAAC,MAAA,EACvB7B,OAAA,CAAQgB,MAAMY,QAAS,CAAAE,QACzB,CAAA,EACAvB,SACF,CAAA;MAAA;IAGF;MAAS;QACPT,gBAAA,CAAiBE,QAAQlB,OAAO,CAAA;QACzB,OAAA,KAAA;MAAA;EACT;AAEJ,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "10.10.3",
3
+ "version": "10.11.0-beta.1",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -22,6 +22,30 @@
22
22
  "terser": "5.39.0",
23
23
  "tldts": "6.1.84"
24
24
  },
25
+ "devDependencies": {
26
+ "@babel/types": "7.26.9",
27
+ "@rollup/plugin-commonjs": "28.0.3",
28
+ "@rollup/plugin-json": "6.1.0",
29
+ "@rollup/plugin-multi-entry": "6.0.1",
30
+ "@rollup/plugin-node-resolve": "16.0.0",
31
+ "@types/adm-zip": "0.5.7",
32
+ "@types/big.js": "6.2.2",
33
+ "@types/react": "^17.0.0 || ^18.3.18 || ^19.0.8",
34
+ "@types/url-join": "^4.0.3",
35
+ "babel-plugin-styled-components": "2.1.4",
36
+ "css-loader": "7.1.2",
37
+ "nodemon": "2.0.22",
38
+ "react-hook-form": "7.54.2",
39
+ "rollup": "4.35.0",
40
+ "rollup-plugin-copy": "3.5.0",
41
+ "rollup-plugin-delete": "3.0.0",
42
+ "rollup-plugin-esbuild": "6.2.1",
43
+ "rollup-plugin-external-assets": "4.1.1",
44
+ "rollup-plugin-peer-deps-external": "2.2.4",
45
+ "sass": "1.85.1",
46
+ "sass-loader": "16.0.5",
47
+ "style-loader": "4.0.0"
48
+ },
25
49
  "peerDependencies": {
26
50
  "@babel/core": "7.26.9",
27
51
  "@dinero.js/currencies": "2.0.0-alpha.8",
@@ -40,10 +64,10 @@
40
64
  "libphonenumber-js": "^1.12.4",
41
65
  "lodash-es": "^4.17.21",
42
66
  "next": "^14.2.23 || ^15.1.0",
67
+ "react": "^17.0.0 || ^18.3.1 || ^19.0.0",
43
68
  "react-countup": "6.5.3",
44
69
  "react-dom": "^17.0.0 || ^18.3.1 || ^19.0.0",
45
70
  "react-use": "^17.5.1",
46
- "react": "^17.0.0 || ^18.3.1 || ^19.0.0",
47
71
  "slugify": "^1.6.6",
48
72
  "styled-components": "^6.1.13",
49
73
  "url-join": "^4.0.1",
@@ -71,29 +95,5 @@
71
95
  "styled-components": {
72
96
  "optional": true
73
97
  }
74
- },
75
- "devDependencies": {
76
- "@babel/types": "7.26.9",
77
- "@rollup/plugin-commonjs": "28.0.3",
78
- "@rollup/plugin-json": "6.1.0",
79
- "@rollup/plugin-multi-entry": "6.0.1",
80
- "@rollup/plugin-node-resolve": "16.0.0",
81
- "@types/adm-zip": "0.5.7",
82
- "@types/big.js": "6.2.2",
83
- "@types/react": "^17.0.0 || ^18.3.18 || ^19.0.8",
84
- "@types/url-join": "^4.0.3",
85
- "babel-plugin-styled-components": "2.1.4",
86
- "css-loader": "7.1.2",
87
- "nodemon": "2.0.22",
88
- "react-hook-form": "7.54.2",
89
- "rollup-plugin-copy": "3.5.0",
90
- "rollup-plugin-delete": "3.0.0",
91
- "rollup-plugin-esbuild": "6.2.1",
92
- "rollup-plugin-external-assets": "4.1.1",
93
- "rollup-plugin-peer-deps-external": "2.2.4",
94
- "rollup": "4.35.0",
95
- "sass-loader": "16.0.5",
96
- "sass": "1.85.1",
97
- "style-loader": "4.0.0"
98
98
  }
99
99
  }