@ubnt/store.core 9.15.0-alpha.3 → 9.15.0-prealpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/CHANGELOG.md +1 -138
  2. package/lib/_virtual/_virtual_multi-entry.js +12 -27
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +10 -14
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/close.svg +1 -3
  7. package/lib/assets/close2.svg +2 -3
  8. package/lib/assets/close3.svg +4 -1
  9. package/lib/assets/minus4.svg +8 -8
  10. package/lib/assets/minus5.svg +8 -8
  11. package/lib/assets/pause.svg +3 -3
  12. package/lib/assets/pause2.svg +3 -3
  13. package/lib/assets/plus5.svg +9 -9
  14. package/lib/assets/plus6.svg +9 -9
  15. package/lib/assets/ucgMax.jpg +0 -0
  16. package/lib/assets/ucgMax2.jpg +0 -0
  17. package/lib/assets/ucgUltra.jpg +0 -0
  18. package/lib/assets/ucgUltra2.jpg +0 -0
  19. package/lib/assets/udmPro.jpg +0 -0
  20. package/lib/assets/udmPro2.jpg +0 -0
  21. package/lib/assets/udmProMax.jpg +0 -0
  22. package/lib/assets/udmProMax2.jpg +0 -0
  23. package/lib/assets/udmProSpecial.jpg +0 -0
  24. package/lib/assets/udmProSpecial2.jpg +0 -0
  25. package/lib/components/CustomImage/CustomImage.js +1 -1
  26. package/lib/components/CustomImage/CustomImage.mjs +1 -1
  27. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  28. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  29. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  30. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  31. package/lib/components/GridGallery/GridModal/GridModal.js +1 -1
  32. package/lib/components/GridGallery/GridModal/GridModal.mjs +1 -1
  33. package/lib/components/Header/CartModalV2/CartModal.js +1 -1
  34. package/lib/components/Header/CartModalV2/CartModal.mjs +1 -1
  35. package/lib/components/Header/Header.js +1 -1
  36. package/lib/components/Header/Header.mjs +1 -1
  37. package/lib/components/LandingPagePro/LandingPagePro.d.ts +0 -3
  38. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  39. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  40. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  41. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  42. package/lib/components/LandingPageSidebar/LandingPageSidebar.js +1 -1
  43. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs +1 -1
  44. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  45. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  46. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  47. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  48. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  49. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  50. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  51. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  52. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  53. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  54. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  55. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  56. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  57. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  58. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  59. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  60. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  61. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  62. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  63. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  64. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  65. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  66. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  67. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  68. package/lib/components/ModelCompareV3/data/CloudGateways.js +15 -15
  69. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +10 -10
  70. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  71. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  72. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  73. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  74. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  75. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  76. package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
  77. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
  78. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  79. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  80. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +17 -313
  81. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  82. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +17 -311
  83. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  84. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +2 -3
  85. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +0 -2
  86. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  87. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +0 -2
  88. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  89. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js +34 -120
  90. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js.map +1 -1
  91. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs +34 -120
  92. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs.map +1 -1
  93. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.d.ts +2 -16
  94. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js +12 -54
  95. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js.map +1 -1
  96. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs +11 -50
  97. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs.map +1 -1
  98. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowLeftPrimary.svg.js +5 -5
  99. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowRightPrimary.svg.js +5 -5
  100. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  101. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  102. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  103. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  104. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +0 -2
  105. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  106. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +0 -2
  107. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  108. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  109. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  110. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  111. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  112. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  113. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  114. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
  115. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
  116. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
  117. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
  118. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +4 -4
  119. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js.map +1 -1
  120. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +4 -4
  121. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs.map +1 -1
  122. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  123. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  124. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  125. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  126. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js +2 -1
  127. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js.map +1 -1
  128. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs +2 -1
  129. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs.map +1 -1
  130. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.d.ts +1 -1
  131. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.js +1 -3
  132. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +1 -0
  133. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.mjs +1 -3
  134. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +1 -0
  135. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.d.ts +0 -1
  136. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.js +7 -10
  137. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +1 -0
  138. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.mjs +7 -10
  139. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +1 -0
  140. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.types.d.ts +0 -1
  141. package/lib/components/ResourceCalculatorV1/components/index.d.ts +1 -0
  142. package/lib/components/ResourceCalculatorV1/components/index.js +5 -0
  143. package/lib/{utils/money/allocators → components/ResourceCalculatorV1/components}/index.js.map +1 -1
  144. package/lib/components/ResourceCalculatorV1/components/index.mjs +3 -0
  145. package/lib/{utils/money/allocators → components/ResourceCalculatorV1/components}/index.mjs.map +1 -1
  146. package/lib/components/ResourceCalculatorV1/translations/en.json.js +4 -6
  147. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  148. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +4 -6
  149. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  150. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  151. package/lib/components/Search/Input/Input.js +1 -1
  152. package/lib/components/Search/Input/Input.mjs +1 -1
  153. package/lib/components/VideoPlayerNew/VideoPlayer.js +2 -2
  154. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +2 -2
  155. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  156. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  157. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  158. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  159. package/lib/components/index.d.ts +0 -1
  160. package/lib/components/index.js +0 -2
  161. package/lib/components/index.js.map +1 -1
  162. package/lib/components/index.mjs +0 -2
  163. package/lib/components/index.mjs.map +1 -1
  164. package/lib/constants/icons/generic/close.svg.js +1 -1
  165. package/lib/constants/icons/generic/close.svg.mjs +2 -2
  166. package/lib/constants/icons/generic/index.js +1 -1
  167. package/lib/constants/icons/generic/index.mjs +1 -1
  168. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -1
  169. package/lib/constants/proStoreCategories/mapping/index.js +11 -16
  170. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  171. package/lib/constants/proStoreCategories/mapping/index.mjs +11 -16
  172. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  173. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -2
  174. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -1
  175. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  176. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -1
  177. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  178. package/lib/constants/proStoreCategories/translations/en.json.js +0 -3
  179. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  180. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -3
  181. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  182. package/lib/constants/proStoreCategories/translations/fr.json.js +1 -1
  183. package/lib/constants/proStoreCategories/translations/fr.json.mjs +1 -1
  184. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +1 -1
  185. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +1 -1
  186. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +1 -1
  187. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +1 -1
  188. package/lib/helpers/index.d.ts +0 -1
  189. package/lib/helpers/index.js +0 -11
  190. package/lib/helpers/index.js.map +1 -1
  191. package/lib/helpers/index.mjs +0 -1
  192. package/lib/helpers/index.mjs.map +1 -1
  193. package/lib/types/index.d.ts +0 -1
  194. package/lib/types/index.js +0 -2
  195. package/lib/types/index.js.map +1 -1
  196. package/lib/types/index.mjs +0 -1
  197. package/lib/types/index.mjs.map +1 -1
  198. package/lib/utils/array.d.ts +0 -4
  199. package/lib/utils/array.js +0 -10
  200. package/lib/utils/array.js.map +1 -1
  201. package/lib/utils/array.mjs +1 -10
  202. package/lib/utils/array.mjs.map +1 -1
  203. package/lib/utils/money/constants.d.ts +25 -56
  204. package/lib/utils/money/constants.js +7 -72
  205. package/lib/utils/money/constants.js.map +1 -1
  206. package/lib/utils/money/constants.mjs +7 -70
  207. package/lib/utils/money/constants.mjs.map +1 -1
  208. package/lib/utils/money/format.d.ts +5 -10
  209. package/lib/utils/money/format.js +14 -22
  210. package/lib/utils/money/format.js.map +1 -1
  211. package/lib/utils/money/format.mjs +16 -23
  212. package/lib/utils/money/format.mjs.map +1 -1
  213. package/lib/utils/money/index.d.ts +1 -4
  214. package/lib/utils/money/index.js +8 -26
  215. package/lib/utils/money/index.js.map +1 -1
  216. package/lib/utils/money/index.mjs +4 -8
  217. package/lib/utils/money/index.mjs.map +1 -1
  218. package/lib/utils/money/misc.d.ts +28 -68
  219. package/lib/utils/money/misc.js +64 -35
  220. package/lib/utils/money/misc.js.map +1 -1
  221. package/lib/utils/money/misc.mjs +43 -32
  222. package/lib/utils/money/misc.mjs.map +1 -1
  223. package/lib/utils/money/tax.d.ts +2 -38
  224. package/lib/utils/money/tax.js +10 -46
  225. package/lib/utils/money/tax.js.map +1 -1
  226. package/lib/utils/money/tax.mjs +11 -42
  227. package/lib/utils/money/tax.mjs.map +1 -1
  228. package/lib/utils/money/types.d.ts +3 -78
  229. package/lib/utils/number.d.ts +1 -1
  230. package/lib/utils/number.js +1 -1
  231. package/lib/utils/number.js.map +1 -1
  232. package/lib/utils/number.mjs +1 -1
  233. package/lib/utils/number.mjs.map +1 -1
  234. package/lib/utils/validations.d.ts +15 -0
  235. package/lib/utils/validations.js +23 -0
  236. package/lib/utils/validations.js.map +1 -0
  237. package/lib/utils/validations.mjs +21 -0
  238. package/lib/utils/validations.mjs.map +1 -0
  239. package/package.json +1 -1
  240. package/lib/assets/efg.png +0 -0
  241. package/lib/assets/ucg-max.png +0 -0
  242. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +0 -1
  243. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +0 -1
  244. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +0 -1
  245. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +0 -1
  246. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js +0 -27
  247. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +0 -1
  248. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +0 -3
  249. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +0 -1
  250. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js +0 -27
  251. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +0 -1
  252. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +0 -3
  253. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +0 -1
  254. package/lib/helpers/product.d.ts +0 -87
  255. package/lib/helpers/product.js +0 -346
  256. package/lib/helpers/product.js.map +0 -1
  257. package/lib/helpers/product.mjs +0 -335
  258. package/lib/helpers/product.mjs.map +0 -1
  259. package/lib/types/product.d.ts +0 -87
  260. package/lib/types/product.js +0 -14
  261. package/lib/types/product.js.map +0 -1
  262. package/lib/types/product.mjs +0 -13
  263. package/lib/types/product.mjs.map +0 -1
  264. package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
  265. package/lib/utils/money/allocators/fixedAmount.js +0 -55
  266. package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
  267. package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
  268. package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
  269. package/lib/utils/money/allocators/index.d.ts +0 -2
  270. package/lib/utils/money/allocators/index.js +0 -8
  271. package/lib/utils/money/allocators/index.mjs +0 -4
  272. package/lib/utils/money/allocators/productAmount.d.ts +0 -13
  273. package/lib/utils/money/allocators/productAmount.js +0 -110
  274. package/lib/utils/money/allocators/productAmount.js.map +0 -1
  275. package/lib/utils/money/allocators/productAmount.mjs +0 -108
  276. package/lib/utils/money/allocators/productAmount.mjs.map +0 -1
  277. package/lib/utils/money/exchangeRate.d.ts +0 -31
  278. package/lib/utils/money/exchangeRate.js +0 -27
  279. package/lib/utils/money/exchangeRate.js.map +0 -1
  280. package/lib/utils/money/exchangeRate.mjs +0 -23
  281. package/lib/utils/money/exchangeRate.mjs.map +0 -1
  282. package/lib/utils/money/misc.private.d.ts +0 -23
  283. package/lib/utils/money/misc.private.js +0 -46
  284. package/lib/utils/money/misc.private.js.map +0 -1
  285. package/lib/utils/money/misc.private.mjs +0 -21
  286. package/lib/utils/money/misc.private.mjs.map +0 -1
  287. package/lib/utils/money/shipping.d.ts +0 -5
  288. package/lib/utils/money/shipping.js +0 -8
  289. package/lib/utils/money/shipping.js.map +0 -1
  290. package/lib/utils/money/shipping.mjs +0 -6
  291. package/lib/utils/money/shipping.mjs.map +0 -1
  292. package/lib/utils/money/tax.private.d.ts +0 -17
  293. package/lib/utils/money/tax.private.js +0 -65
  294. package/lib/utils/money/tax.private.js.map +0 -1
  295. package/lib/utils/money/tax.private.mjs +0 -60
  296. package/lib/utils/money/tax.private.mjs.map +0 -1
  297. package/lib/utils/productSort.d.ts +0 -41
  298. package/lib/utils/productSort.js +0 -66
  299. package/lib/utils/productSort.js.map +0 -1
  300. package/lib/utils/productSort.mjs +0 -59
  301. package/lib/utils/productSort.mjs.map +0 -1
  302. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.d.ts +0 -0
  303. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js +0 -0
  304. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js.map +0 -0
  305. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs +0 -0
  306. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs.map +0 -0
@@ -1,65 +0,0 @@
1
- 'use strict';
2
-
3
- var dinero_js = require('dinero.js');
4
- var errors = require('../errors.js');
5
- var fixedAmount = require('./allocators/fixedAmount.js');
6
- var misc = require('./misc.js');
7
- "use strict";
8
- const taxRateToDineroAllocation = taxRate => {
9
- if (taxRate <= 0 || taxRate >= 1) {
10
- throw new RangeError("Unsupported rate, expected in range of 0>rate<1");
11
- }
12
- const rateScale = String(taxRate).split(".")[1]?.length;
13
- errors.assert(rateScale !== void 0, "rateScale is undefined");
14
- const rateInt = Math.round(taxRate * Math.pow(10, rateScale));
15
- return [rateInt, Math.pow(10, rateScale) - rateInt];
16
- };
17
- const allocatePerItemTaxableAmount = itemSummary => {
18
- if (itemSummary.quantity === 1) {
19
- return [itemSummary];
20
- }
21
- const preDiscountAmount = dinero_js.add(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), misc.getDinero(itemSummary.discountAmount, itemSummary.currency));
22
- const allocator = new fixedAmount.FixedAmountAllocator({
23
- initialAllocateAmount: itemSummary.discountAmount,
24
- initialTotalAmount: misc.amount(preDiscountAmount),
25
- currency: itemSummary.currency
26
- });
27
- return Array.from({
28
- length: itemSummary.quantity
29
- }, () => {
30
- const discountAllocatedAmount = allocator.allocate(itemSummary.itemPrice, itemSummary.currency);
31
- const taxableAmount = dinero_js.subtract(misc.getDinero(itemSummary.itemPrice, itemSummary.currency), discountAllocatedAmount);
32
- return {
33
- itemPrice: itemSummary.itemPrice,
34
- taxableAmount: misc.amount(taxableAmount),
35
- discountAmount: misc.amount(discountAllocatedAmount),
36
- currency: itemSummary.currency,
37
- quantity: 1
38
- };
39
- });
40
- };
41
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
42
- if (taxRate === 0) {
43
- return misc.getDinero(0, itemSummary.currency);
44
- }
45
- const [taxAmount] = dinero_js.allocate(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
46
- errors.assert(taxAmount !== void 0, "taxAmount is undefined");
47
- return taxAmount;
48
- };
49
- const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
50
- if (taxRate === 0) {
51
- return misc.getDinero(0, itemSummary.currency);
52
- }
53
- const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
54
- let totalTaxAmount = misc.getDinero(0, itemSummary.currency);
55
- singleItemSummaries.forEach(itemSummary2 => {
56
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
57
- totalTaxAmount = dinero_js.add(totalTaxAmount, taxAmount);
58
- });
59
- return totalTaxAmount;
60
- };
61
- exports.allocatePerItemTaxableAmount = allocatePerItemTaxableAmount;
62
- exports.calculatePerQtyLineItemTax = calculatePerQtyLineItemTax;
63
- exports.calculateWholeQtyLineItemTax = calculateWholeQtyLineItemTax;
64
- exports.taxRateToDineroAllocation = taxRateToDineroAllocation;
65
- //# sourceMappingURL=tax.private.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, allocate, subtract } from \"dinero.js\";\n\nimport { assert } from \"../errors\";\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { amount, getDinero } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Private helper to convert a floating number to a dinero friendly allocation integer pair\n * @see https://v2.dinerojs.com/docs/api/mutations/allocate\n * @example\n * taxRateToDineroAllocation(0.1) // [1, 9]\n * taxRateToDineroAllocation(0.5) // [5, 5]\n */\nexport const taxRateToDineroAllocation = (\n taxRate: TaxRate,\n): [number, number] => {\n if (taxRate <= 0 || taxRate >= 1) {\n throw new RangeError(\"Unsupported rate, expected in range of 0>rate<1\");\n }\n\n // Get the scale of the rate\n const rateScale = String(taxRate).split(\".\")[1]?.length;\n assert(rateScale !== undefined, \"rateScale is undefined\");\n\n // Convert to integers\n const rateInt = Math.round(taxRate * Math.pow(10, rateScale));\n return [rateInt, Math.pow(10, rateScale) - rateInt];\n};\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * FIXME: look into approach with multiply and different scale for control over rounding, currently we just inherit\n * what dinero gives us which cause unexpected rounding issue\n */\n const [taxAmount] = allocate(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRateToDineroAllocation(taxRate),\n );\n\n assert(taxAmount !== undefined, \"taxAmount is undefined\");\n return taxAmount;\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["taxRateToDineroAllocation","taxRate","RangeError","rateScale","String","split","length","assert","rateInt","Math","round","pow","allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWhole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AYM,QAAQ,CAAA;EAElCgB,mBAAA,CAAAE,OAAA,CAASxB,YAAgB,IAAA;IAGrC,MAAAoB,SAAA,GAAYD,4BAA6BnB,CAAAA,YAAAA,EAAaZ,OAAO,CAAA;IAClDmC,cAAA,GAAApB,SAAA,CAAAA,GAAA,CAAIoB,gBAAgBH,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAG,cAAA;AACT,CAAA;;;;"}
@@ -1,60 +0,0 @@
1
- import { add, subtract, allocate } from 'dinero.js';
2
- import { assert } from '../errors.mjs';
3
- import { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
4
- import { getDinero, amount } from './misc.mjs';
5
- "use strict";
6
- const taxRateToDineroAllocation = taxRate => {
7
- if (taxRate <= 0 || taxRate >= 1) {
8
- throw new RangeError("Unsupported rate, expected in range of 0>rate<1");
9
- }
10
- const rateScale = String(taxRate).split(".")[1]?.length;
11
- assert(rateScale !== void 0, "rateScale is undefined");
12
- const rateInt = Math.round(taxRate * Math.pow(10, rateScale));
13
- return [rateInt, Math.pow(10, rateScale) - rateInt];
14
- };
15
- const allocatePerItemTaxableAmount = itemSummary => {
16
- if (itemSummary.quantity === 1) {
17
- return [itemSummary];
18
- }
19
- const preDiscountAmount = add(getDinero(itemSummary.taxableAmount, itemSummary.currency), getDinero(itemSummary.discountAmount, itemSummary.currency));
20
- const allocator = new FixedAmountAllocator({
21
- initialAllocateAmount: itemSummary.discountAmount,
22
- initialTotalAmount: amount(preDiscountAmount),
23
- currency: itemSummary.currency
24
- });
25
- return Array.from({
26
- length: itemSummary.quantity
27
- }, () => {
28
- const discountAllocatedAmount = allocator.allocate(itemSummary.itemPrice, itemSummary.currency);
29
- const taxableAmount = subtract(getDinero(itemSummary.itemPrice, itemSummary.currency), discountAllocatedAmount);
30
- return {
31
- itemPrice: itemSummary.itemPrice,
32
- taxableAmount: amount(taxableAmount),
33
- discountAmount: amount(discountAllocatedAmount),
34
- currency: itemSummary.currency,
35
- quantity: 1
36
- };
37
- });
38
- };
39
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
40
- if (taxRate === 0) {
41
- return getDinero(0, itemSummary.currency);
42
- }
43
- const [taxAmount] = allocate(getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
44
- assert(taxAmount !== void 0, "taxAmount is undefined");
45
- return taxAmount;
46
- };
47
- const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
48
- if (taxRate === 0) {
49
- return getDinero(0, itemSummary.currency);
50
- }
51
- const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
52
- let totalTaxAmount = getDinero(0, itemSummary.currency);
53
- singleItemSummaries.forEach(itemSummary2 => {
54
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
55
- totalTaxAmount = add(totalTaxAmount, taxAmount);
56
- });
57
- return totalTaxAmount;
58
- };
59
- export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, taxRateToDineroAllocation };
60
- //# sourceMappingURL=tax.private.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, allocate, subtract } from \"dinero.js\";\n\nimport { assert } from \"../errors\";\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { amount, getDinero } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Private helper to convert a floating number to a dinero friendly allocation integer pair\n * @see https://v2.dinerojs.com/docs/api/mutations/allocate\n * @example\n * taxRateToDineroAllocation(0.1) // [1, 9]\n * taxRateToDineroAllocation(0.5) // [5, 5]\n */\nexport const taxRateToDineroAllocation = (\n taxRate: TaxRate,\n): [number, number] => {\n if (taxRate <= 0 || taxRate >= 1) {\n throw new RangeError(\"Unsupported rate, expected in range of 0>rate<1\");\n }\n\n // Get the scale of the rate\n const rateScale = String(taxRate).split(\".\")[1]?.length;\n assert(rateScale !== undefined, \"rateScale is undefined\");\n\n // Convert to integers\n const rateInt = Math.round(taxRate * Math.pow(10, rateScale));\n return [rateInt, Math.pow(10, rateScale) - rateInt];\n};\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * FIXME: look into approach with multiply and different scale for control over rounding, currently we just inherit\n * what dinero gives us which cause unexpected rounding issue\n */\n const [taxAmount] = allocate(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRateToDineroAllocation(taxRate),\n );\n\n assert(taxAmount !== undefined, \"taxAmount is undefined\");\n return taxAmount;\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["taxRateToDineroAllocation","taxRate","RangeError","rateScale","String","split","length","assert","rateInt","Math","round","pow","allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxAmount","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;AAwBa,MAAAA,yBAAA,GACXC,OACqB,IAAA;EACjB,IAAAA,OAAA,IAAW,CAAK,IAAAA,OAAA,IAAW,CAAG,EAAA;IAC1B,MAAA,IAAIC,WAAW,iDAAiD,CAAA;EACxE;EAGM,MAAAC,SAAA,GAAYC,OAAOH,OAAO,CAAA,CAAEI,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EAC1CC,MAAA,CAAAJ,SAAA,KAAc,QAAW,wBAAwB,CAAA;EAGlD,MAAAK,OAAA,GAAUC,KAAKC,KAAM,CAAAT,OAAA,GAAU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Z,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAgB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAMM,MAAA,CAACc,SAAS,CAAI,GAAAJ,QAAA,CAClBZ,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDnB,0BAA0BC,OAAO,CAAA,CACnC;EAEOM,MAAA,CAAA0B,SAAA,KAAc,QAAW,wBAAwB,CAAA;EACjD,OAAAA,SAAA;AACT,CAAA;AAEa,MAAAC,0BAAA,GAA6BA,CACxCrB,WAAA,EACAZ,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAgB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGM,MAAAgB,mBAAA,GAAsBvB,6BAA6BC,WAAW,CAAA;EAGpE,IAAIuB,cAAiB,GAAAnB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCgB,mBAAA,CAAAE,OAAA,CAASxB,YAAgB,IAAA;IAGrC,MAAAoB,SAAA,GAAYD,4BAA6BnB,CAAAA,YAAAA,EAAaZ,OAAO,CAAA;IAClDmC,cAAA,GAAApB,GAAA,CAAIoB,gBAAgBH,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAG,cAAA;AACT,CAAA;"}
@@ -1,41 +0,0 @@
1
- import type { Nullish, StorefrontProduct, StoreId, UnionToAllPossibleTuples } from "../types";
2
- import { DisplayProductStatus } from "../types";
3
- /**
4
- * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product
5
- */
6
- type ProductMinFieldsForSorting = Pick<StorefrontProduct, "status" | "tags" | "minDisplayPrice"> & {
7
- variants: {
8
- availableInOtherStores: Array<{
9
- __typename: string;
10
- }>;
11
- }[];
12
- linkedProducts?: {
13
- status: StorefrontProduct["status"];
14
- }[];
15
- };
16
- export declare enum Sort {
17
- HighestPrice = "highest-price",
18
- LowestPrice = "lowest-price",
19
- Availability = "availability"
20
- }
21
- export declare enum SortOrder {
22
- Asc = "Asc",
23
- Desc = "Desc"
24
- }
25
- /**
26
- * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the
27
- * lookup for `.indexOf()` would return `-1`, thus being "worse" then DisplayProductStatus.SoldOut and moved to the very
28
- * back of list
29
- */
30
- export declare const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus>;
31
- export declare const sortByAvailabilityDesc: (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => number;
32
- export declare const sortByPrice: (order: SortOrder) => (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => number;
33
- /**
34
- * Sorts products based on the given sort type.
35
- * @param currentSort - sort type
36
- * @param sortByWeightTag - if false, then sort by weight tag is
37
- * ignored (e.g. for `Related Add-ons` where
38
- * we don't want to sort by weight tag)
39
- */
40
- export declare const sortProducts: (currentSort: Nullish<string | Sort>, storeId?: StoreId, sortByWeightTag?: boolean) => (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => number;
41
- export {};
@@ -1,66 +0,0 @@
1
- 'use strict';
2
-
3
- require('../types/index.js');
4
- var array = require('./array.js');
5
- var product$1 = require('./product.js');
6
- var product = require('../types/product.js');
7
- "use strict";
8
- var Sort = /* @__PURE__ */(Sort2 => {
9
- Sort2["HighestPrice"] = "highest-price";
10
- Sort2["LowestPrice"] = "lowest-price";
11
- Sort2["Availability"] = "availability";
12
- return Sort2;
13
- })(Sort || {});
14
- var SortOrder = /* @__PURE__ */(SortOrder2 => {
15
- SortOrder2["Asc"] = "Asc";
16
- SortOrder2["Desc"] = "Desc";
17
- return SortOrder2;
18
- })(SortOrder || {});
19
- const sortedStatusesByPriorityAsc = [product.DisplayProductStatus.Unavailable, product.DisplayProductStatus.ComingSoon, product.DisplayProductStatus.SoldOut, product.DisplayProductStatus.RegionNotAvailable, product.DisplayProductStatus.Backorder, product.DisplayProductStatus.Available];
20
- const getProductStatusPriority = product$1 => {
21
- let sortStatus = product$1.status;
22
- if (product$1.variants.some(variant => variant.availableInOtherStores.length) || product$1.linkedProducts && product$1.linkedProducts.some(linkedProduct => linkedProduct.status === product.DisplayProductStatus.Available)) {
23
- sortStatus = product.DisplayProductStatus.Available;
24
- }
25
- return sortedStatusesByPriorityAsc.indexOf(sortStatus);
26
- };
27
- const sortByAvailabilityDesc = (current, next) => {
28
- return array.normalizeSortResult(getProductStatusPriority(next) - getProductStatusPriority(current));
29
- };
30
- const sortByPrice = order => (current, next) => {
31
- const currentProductPrice = current.minDisplayPrice.amount;
32
- const nextProductPrice = next.minDisplayPrice.amount;
33
- if (order === "Desc" /* Desc */) {
34
- return nextProductPrice - currentProductPrice;
35
- } else {
36
- return currentProductPrice - nextProductPrice;
37
- }
38
- };
39
- const sortProducts = (currentSort, storeId, sortByWeightTag = true) => (current, next) => {
40
- switch (currentSort) {
41
- case "highest-price" /* HighestPrice */:
42
- case "lowest-price" /* LowestPrice */:
43
- {
44
- return sortByPrice(currentSort === "highest-price" /* HighestPrice */ ? "Desc" /* Desc */ : "Asc" /* Asc */)(current, next);
45
- }
46
- case "availability" /* Availability */:
47
- {
48
- return sortByAvailabilityDesc(current, next);
49
- }
50
- default:
51
- {
52
- const sorts = [sortByAvailabilityDesc];
53
- if (sortByWeightTag) {
54
- sorts.push(product$1.sortByTagWeight(product$1.SortSiteId.Store, storeId));
55
- }
56
- return array.combineSorts(sorts)(current, next);
57
- }
58
- }
59
- };
60
- exports.Sort = Sort;
61
- exports.SortOrder = SortOrder;
62
- exports.sortByAvailabilityDesc = sortByAvailabilityDesc;
63
- exports.sortByPrice = sortByPrice;
64
- exports.sortProducts = sortProducts;
65
- exports.sortedStatusesByPriorityAsc = sortedStatusesByPriorityAsc;
66
- //# sourceMappingURL=productSort.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"productSort.js","sources":["../../src/utils/productSort.ts"],"sourcesContent":["import type { Nullish, StorefrontProduct, StoreId, UnionToAllPossibleTuples } from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { combineSorts, normalizeSortResult } from \"./array\";\nimport { sortByTagWeight, SortSiteId } from \"./product\";\n\n/**\n * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product\n */\ntype ProductMinFieldsForSorting = Pick<\n StorefrontProduct,\n \"status\" | \"tags\" | \"minDisplayPrice\"\n> & {\n variants: {\n // We only need bare minimum from array to compare array length\n // FIXME: move it to backend as a boolean field so we don't need to fetch entire array to reduce it to a boolean ourselves\n availableInOtherStores: Array<{ __typename: string }>;\n }[];\n linkedProducts?: {\n status: StorefrontProduct[\"status\"];\n }[];\n};\n\nexport enum Sort {\n HighestPrice = \"highest-price\",\n LowestPrice = \"lowest-price\",\n Availability = \"availability\",\n}\n\nexport enum SortOrder {\n Asc = \"Asc\",\n Desc = \"Desc\",\n}\n\n/**\n * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the\n * lookup for `.indexOf()` would return `-1`, thus being \"worse\" then DisplayProductStatus.SoldOut and moved to the very\n * back of list\n */\nexport const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus> =\n [\n DisplayProductStatus.Unavailable,\n DisplayProductStatus.ComingSoon,\n DisplayProductStatus.SoldOut,\n DisplayProductStatus.RegionNotAvailable,\n DisplayProductStatus.Backorder,\n DisplayProductStatus.Available,\n ];\n/**\n * Due to currently variant status being nullable for historical reasons we need to have a fallback state\n * TODO: remove once display status is StorefrontProductVariant.status is non-nullable\n */\nconst getProductStatusPriority = (\n product: ProductMinFieldsForSorting,\n): number => {\n let sortStatus = product.status;\n\n // Virtually set sort status as available if it has alternative stores\n if (\n product.variants.some((variant) => variant.availableInOtherStores.length) ||\n (product.linkedProducts &&\n product.linkedProducts.some(\n (linkedProduct) =>\n linkedProduct.status === DisplayProductStatus.Available,\n ))\n ) {\n sortStatus = DisplayProductStatus.Available;\n }\n\n return sortedStatusesByPriorityAsc.indexOf(sortStatus);\n};\n\nexport const sortByAvailabilityDesc = (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n): number => {\n return normalizeSortResult(\n getProductStatusPriority(next) - getProductStatusPriority(current),\n );\n};\n\nexport const sortByPrice =\n (order: SortOrder) => (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n ): number => {\n const currentProductPrice = current.minDisplayPrice.amount;\n\n const nextProductPrice = next.minDisplayPrice.amount;\n\n if (order === SortOrder.Desc) {\n return nextProductPrice - currentProductPrice;\n } else {\n return currentProductPrice - nextProductPrice;\n }\n };\n\n\n/**\n * Sorts products based on the given sort type.\n * @param currentSort - sort type\n * @param sortByWeightTag - if false, then sort by weight tag is\n * ignored (e.g. for `Related Add-ons` where\n * we don't want to sort by weight tag)\n */\nexport const sortProducts = (\n currentSort: Nullish<string | Sort>,\n storeId?: StoreId,\n sortByWeightTag = true,\n ) =>\n (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => {\n switch (currentSort) {\n // Sort by price\n case Sort.HighestPrice:\n case Sort.LowestPrice: {\n return sortByPrice(\n currentSort === Sort.HighestPrice ? SortOrder.Desc : SortOrder.Asc,\n )(current, next);\n }\n\n case Sort.Availability: {\n return sortByAvailabilityDesc(current, next);\n }\n\n default: {\n const sorts = [sortByAvailabilityDesc];\n\n // Add sorting by tag weight\n if (sortByWeightTag) {\n sorts.push(sortByTagWeight(SortSiteId.Store, storeId));\n }\n\n // Do additional sorting by tag weight only after initial sorting resulting in \"same group\"\n return combineSorts(sorts)(current, next);\n }\n }\n };"],"names":["Sort","SortOrder","sortedStatusesByPriorityAsc","DisplayProductStatus","Unavailable","ComingSoon","SoldOut","RegionNotAvailable","Backorder","Available","getProductStatusPriority","product","sortStatus","status","variants","some","variant","availableInOtherStores","length","linkedProducts","linkedProduct","indexOf","sortByAvailabilityDesc","current","next","normalizeSortResult","sortByPrice","order","currentProductPrice","minDisplayPrice","amount","nextProductPrice","sortProducts","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@@ -1,59 +0,0 @@
1
- import '../types/index.mjs';
2
- import { normalizeSortResult, combineSorts } from './array.mjs';
3
- import { sortByTagWeight, SortSiteId } from './product.mjs';
4
- import { DisplayProductStatus } from '../types/product.mjs';
5
- "use strict";
6
- var Sort = /* @__PURE__ */(Sort2 => {
7
- Sort2["HighestPrice"] = "highest-price";
8
- Sort2["LowestPrice"] = "lowest-price";
9
- Sort2["Availability"] = "availability";
10
- return Sort2;
11
- })(Sort || {});
12
- var SortOrder = /* @__PURE__ */(SortOrder2 => {
13
- SortOrder2["Asc"] = "Asc";
14
- SortOrder2["Desc"] = "Desc";
15
- return SortOrder2;
16
- })(SortOrder || {});
17
- const sortedStatusesByPriorityAsc = [DisplayProductStatus.Unavailable, DisplayProductStatus.ComingSoon, DisplayProductStatus.SoldOut, DisplayProductStatus.RegionNotAvailable, DisplayProductStatus.Backorder, DisplayProductStatus.Available];
18
- const getProductStatusPriority = product => {
19
- let sortStatus = product.status;
20
- if (product.variants.some(variant => variant.availableInOtherStores.length) || product.linkedProducts && product.linkedProducts.some(linkedProduct => linkedProduct.status === DisplayProductStatus.Available)) {
21
- sortStatus = DisplayProductStatus.Available;
22
- }
23
- return sortedStatusesByPriorityAsc.indexOf(sortStatus);
24
- };
25
- const sortByAvailabilityDesc = (current, next) => {
26
- return normalizeSortResult(getProductStatusPriority(next) - getProductStatusPriority(current));
27
- };
28
- const sortByPrice = order => (current, next) => {
29
- const currentProductPrice = current.minDisplayPrice.amount;
30
- const nextProductPrice = next.minDisplayPrice.amount;
31
- if (order === "Desc" /* Desc */) {
32
- return nextProductPrice - currentProductPrice;
33
- } else {
34
- return currentProductPrice - nextProductPrice;
35
- }
36
- };
37
- const sortProducts = (currentSort, storeId, sortByWeightTag = true) => (current, next) => {
38
- switch (currentSort) {
39
- case "highest-price" /* HighestPrice */:
40
- case "lowest-price" /* LowestPrice */:
41
- {
42
- return sortByPrice(currentSort === "highest-price" /* HighestPrice */ ? "Desc" /* Desc */ : "Asc" /* Asc */)(current, next);
43
- }
44
- case "availability" /* Availability */:
45
- {
46
- return sortByAvailabilityDesc(current, next);
47
- }
48
- default:
49
- {
50
- const sorts = [sortByAvailabilityDesc];
51
- if (sortByWeightTag) {
52
- sorts.push(sortByTagWeight(SortSiteId.Store, storeId));
53
- }
54
- return combineSorts(sorts)(current, next);
55
- }
56
- }
57
- };
58
- export { Sort, SortOrder, sortByAvailabilityDesc, sortByPrice, sortProducts, sortedStatusesByPriorityAsc };
59
- //# sourceMappingURL=productSort.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"productSort.mjs","sources":["../../src/utils/productSort.ts"],"sourcesContent":["import type { Nullish, StorefrontProduct, StoreId, UnionToAllPossibleTuples } from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { combineSorts, normalizeSortResult } from \"./array\";\nimport { sortByTagWeight, SortSiteId } from \"./product\";\n\n/**\n * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product\n */\ntype ProductMinFieldsForSorting = Pick<\n StorefrontProduct,\n \"status\" | \"tags\" | \"minDisplayPrice\"\n> & {\n variants: {\n // We only need bare minimum from array to compare array length\n // FIXME: move it to backend as a boolean field so we don't need to fetch entire array to reduce it to a boolean ourselves\n availableInOtherStores: Array<{ __typename: string }>;\n }[];\n linkedProducts?: {\n status: StorefrontProduct[\"status\"];\n }[];\n};\n\nexport enum Sort {\n HighestPrice = \"highest-price\",\n LowestPrice = \"lowest-price\",\n Availability = \"availability\",\n}\n\nexport enum SortOrder {\n Asc = \"Asc\",\n Desc = \"Desc\",\n}\n\n/**\n * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the\n * lookup for `.indexOf()` would return `-1`, thus being \"worse\" then DisplayProductStatus.SoldOut and moved to the very\n * back of list\n */\nexport const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus> =\n [\n DisplayProductStatus.Unavailable,\n DisplayProductStatus.ComingSoon,\n DisplayProductStatus.SoldOut,\n DisplayProductStatus.RegionNotAvailable,\n DisplayProductStatus.Backorder,\n DisplayProductStatus.Available,\n ];\n/**\n * Due to currently variant status being nullable for historical reasons we need to have a fallback state\n * TODO: remove once display status is StorefrontProductVariant.status is non-nullable\n */\nconst getProductStatusPriority = (\n product: ProductMinFieldsForSorting,\n): number => {\n let sortStatus = product.status;\n\n // Virtually set sort status as available if it has alternative stores\n if (\n product.variants.some((variant) => variant.availableInOtherStores.length) ||\n (product.linkedProducts &&\n product.linkedProducts.some(\n (linkedProduct) =>\n linkedProduct.status === DisplayProductStatus.Available,\n ))\n ) {\n sortStatus = DisplayProductStatus.Available;\n }\n\n return sortedStatusesByPriorityAsc.indexOf(sortStatus);\n};\n\nexport const sortByAvailabilityDesc = (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n): number => {\n return normalizeSortResult(\n getProductStatusPriority(next) - getProductStatusPriority(current),\n );\n};\n\nexport const sortByPrice =\n (order: SortOrder) => (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n ): number => {\n const currentProductPrice = current.minDisplayPrice.amount;\n\n const nextProductPrice = next.minDisplayPrice.amount;\n\n if (order === SortOrder.Desc) {\n return nextProductPrice - currentProductPrice;\n } else {\n return currentProductPrice - nextProductPrice;\n }\n };\n\n\n/**\n * Sorts products based on the given sort type.\n * @param currentSort - sort type\n * @param sortByWeightTag - if false, then sort by weight tag is\n * ignored (e.g. for `Related Add-ons` where\n * we don't want to sort by weight tag)\n */\nexport const sortProducts = (\n currentSort: Nullish<string | Sort>,\n storeId?: StoreId,\n sortByWeightTag = true,\n ) =>\n (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => {\n switch (currentSort) {\n // Sort by price\n case Sort.HighestPrice:\n case Sort.LowestPrice: {\n return sortByPrice(\n currentSort === Sort.HighestPrice ? SortOrder.Desc : SortOrder.Asc,\n )(current, next);\n }\n\n case Sort.Availability: {\n return sortByAvailabilityDesc(current, next);\n }\n\n default: {\n const sorts = [sortByAvailabilityDesc];\n\n // Add sorting by tag weight\n if (sortByWeightTag) {\n sorts.push(sortByTagWeight(SortSiteId.Store, storeId));\n }\n\n // Do additional sorting by tag weight only after initial sorting resulting in \"same group\"\n return combineSorts(sorts)(current, next);\n }\n }\n };"],"names":["Sort","SortOrder","sortedStatusesByPriorityAsc","DisplayProductStatus","Unavailable","ComingSoon","SoldOut","RegionNotAvailable","Backorder","Available","getProductStatusPriority","product","sortStatus","status","variants","some","variant","availableInOtherStores","length","linkedProducts","linkedProduct","indexOf","sortByAvailabilityDesc","current","next","normalizeSortResult","sortByPrice","order","currentProductPrice","minDisplayPrice","amount","nextProductPrice","sortProducts","currentSort","storeId","sortByWeightTag","sorts","push","sortByTagWeight","SortSiteId","Store","combineSorts"],"mappings":";;;;;AAsBY,IAAAA,IAAA,GAAA,gBAAAA,KAAL,IAAA;EACLA,MAAA,cAAe,CAAA,GAAA,eAAA;EACfA,MAAA,aAAc,CAAA,GAAA,cAAA;EACdA,MAAA,cAAe,CAAA,GAAA,cAAA;EAHLA,OAAAA,KAAAA;AAAA,CAAA,EAAAA,IAAA,IAAA,CAAA,CAAA,CAAA;AAMA,IAAAC,SAAA,GAAA,gBAAAA,UAAL,IAAA;EACLA,WAAA,KAAM,CAAA,GAAA,KAAA;EACNA,WAAA,MAAO,CAAA,GAAA,MAAA;EAFGA,OAAAA,UAAAA;AAAA,CAAA,EAAAA,SAAA,IAAA,CAAA,CAAA,CAAA;AAUL,MAAMC,2BACX,GAAA,CACEC,oBAAqB,CAAAC,WAAA,EACrBD,oBAAqB,CAAAE,UAAA,EACrBF,oBAAqB,CAAAG,OAAA,EACrBH,oBAAqB,CAAAI,kBAAA,EACrBJ,oBAAqB,CAAAK,SAAA,EACrBL,oBAAqB,CAAAM,SAAA,CACvB;AAKF,MAAMC,wBAAA,GACJC,OACW,IAAA;EACX,IAAIC,aAAaD,OAAQ,CAAAE,MAAA;EAGzB,IACEF,OAAQ,CAAAG,QAAA,CAASC,IAAK,CAACC,OAAY,IAAAA,OAA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