@ubnt/store.core 9.24.0-beta.1 → 9.25.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 (273) hide show
  1. package/CHANGELOG.md +3 -17
  2. package/lib/_virtual/_virtual_multi-entry.js +2 -15
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +0 -2
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/clients.svg +2 -2
  7. package/lib/assets/cloudKeyG2Nvr.jpg +0 -0
  8. package/lib/assets/envr.jpg +0 -0
  9. package/lib/assets/keyFeatures/clients.svg +2 -2
  10. package/lib/assets/keyFeatures/phased_array.svg +1 -1
  11. package/lib/assets/keyFeatures/phased_array.svg.js +1 -1
  12. package/lib/assets/keyFeatures/phased_array.svg.mjs +2 -2
  13. package/lib/assets/keyFeatures/poe_plus_plus_plus_outlined.svg +6 -0
  14. package/lib/assets/keyFeatures/poe_plus_plus_plus_outlined.svg.js +27 -0
  15. package/lib/assets/keyFeatures/poe_plus_plus_plus_outlined.svg.js.map +1 -0
  16. package/lib/assets/keyFeatures/poe_plus_plus_plus_outlined.svg.mjs +3 -0
  17. package/lib/assets/keyFeatures/poe_plus_plus_plus_outlined.svg.mjs.map +1 -0
  18. package/lib/assets/minus4.svg +8 -8
  19. package/lib/assets/minus5.svg +8 -8
  20. package/lib/assets/nvr.jpg +0 -0
  21. package/lib/assets/nvrPro.jpg +0 -0
  22. package/lib/assets/pause.svg +3 -3
  23. package/lib/assets/pause2.svg +3 -3
  24. package/lib/assets/plus5.svg +9 -9
  25. package/lib/assets/plus6.svg +9 -9
  26. package/lib/assets/poe_plus_plus_plus_outlined.svg +6 -0
  27. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  28. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  29. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  30. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  31. package/lib/components/ModelCompareV3/ModelCompareV3.types.d.ts +3 -2
  32. package/lib/components/ModelCompareV3/assets/{cloudKeyG2.png.js → VideoRecorders/cloudKeyG2Nvr.jpg.js} +2 -2
  33. package/lib/components/ModelCompareV3/assets/VideoRecorders/cloudKeyG2Nvr.jpg.js.map +1 -0
  34. package/lib/components/ModelCompareV3/assets/VideoRecorders/cloudKeyG2Nvr.jpg.mjs +3 -0
  35. package/lib/components/ModelCompareV3/assets/VideoRecorders/cloudKeyG2Nvr.jpg.mjs.map +1 -0
  36. package/lib/components/ModelCompareV3/assets/{nvr.png.js → VideoRecorders/envr.jpg.js} +2 -2
  37. package/lib/components/ModelCompareV3/assets/VideoRecorders/envr.jpg.js.map +1 -0
  38. package/lib/components/ModelCompareV3/assets/VideoRecorders/envr.jpg.mjs +3 -0
  39. package/lib/components/ModelCompareV3/assets/VideoRecorders/envr.jpg.mjs.map +1 -0
  40. package/lib/components/ModelCompareV3/assets/{envr.png.js → VideoRecorders/nvr.jpg.js} +2 -2
  41. package/lib/components/ModelCompareV3/assets/VideoRecorders/nvr.jpg.js.map +1 -0
  42. package/lib/components/ModelCompareV3/assets/VideoRecorders/nvr.jpg.mjs +3 -0
  43. package/lib/components/ModelCompareV3/assets/VideoRecorders/nvr.jpg.mjs.map +1 -0
  44. package/lib/components/ModelCompareV3/assets/{nvrPro.png.js → VideoRecorders/nvrPro.jpg.js} +2 -2
  45. package/lib/components/ModelCompareV3/assets/VideoRecorders/nvrPro.jpg.js.map +1 -0
  46. package/lib/components/ModelCompareV3/assets/VideoRecorders/nvrPro.jpg.mjs +3 -0
  47. package/lib/components/ModelCompareV3/assets/VideoRecorders/nvrPro.jpg.mjs.map +1 -0
  48. package/lib/components/ModelCompareV3/data/VideoRecorders.js +8 -6
  49. package/lib/components/ModelCompareV3/data/VideoRecorders.js.map +1 -1
  50. package/lib/components/ModelCompareV3/data/VideoRecorders.mjs +8 -6
  51. package/lib/components/ModelCompareV3/data/VideoRecorders.mjs.map +1 -1
  52. package/lib/components/ModelCompareV3/data/products/cloudKeyG2Plus.js +5 -3
  53. package/lib/components/ModelCompareV3/data/products/cloudKeyG2Plus.js.map +1 -1
  54. package/lib/components/ModelCompareV3/data/products/cloudKeyG2Plus.mjs +5 -3
  55. package/lib/components/ModelCompareV3/data/products/cloudKeyG2Plus.mjs.map +1 -1
  56. package/lib/components/ModelCompareV3/data/products/cloudKeyG2PlusNvr.js +14 -12
  57. package/lib/components/ModelCompareV3/data/products/cloudKeyG2PlusNvr.js.map +1 -1
  58. package/lib/components/ModelCompareV3/data/products/cloudKeyG2PlusNvr.mjs +14 -12
  59. package/lib/components/ModelCompareV3/data/products/cloudKeyG2PlusNvr.mjs.map +1 -1
  60. package/lib/components/ModelCompareV3/data/products/envr.js +10 -8
  61. package/lib/components/ModelCompareV3/data/products/envr.js.map +1 -1
  62. package/lib/components/ModelCompareV3/data/products/envr.mjs +10 -8
  63. package/lib/components/ModelCompareV3/data/products/envr.mjs.map +1 -1
  64. package/lib/components/ModelCompareV3/data/products/nvr.js +12 -9
  65. package/lib/components/ModelCompareV3/data/products/nvr.js.map +1 -1
  66. package/lib/components/ModelCompareV3/data/products/nvr.mjs +12 -9
  67. package/lib/components/ModelCompareV3/data/products/nvr.mjs.map +1 -1
  68. package/lib/components/ModelCompareV3/data/products/nvrPro.js +11 -9
  69. package/lib/components/ModelCompareV3/data/products/nvrPro.js.map +1 -1
  70. package/lib/components/ModelCompareV3/data/products/nvrPro.mjs +11 -9
  71. package/lib/components/ModelCompareV3/data/products/nvrPro.mjs.map +1 -1
  72. package/lib/components/ModelCompareV3/data/properties/driveHotSwap.js +2 -1
  73. package/lib/components/ModelCompareV3/data/properties/driveHotSwap.js.map +1 -1
  74. package/lib/components/ModelCompareV3/data/properties/driveHotSwap.mjs +2 -1
  75. package/lib/components/ModelCompareV3/data/properties/driveHotSwap.mjs.map +1 -1
  76. package/lib/components/ModelCompareV3/data/properties/index.d.ts +1 -0
  77. package/lib/components/ModelCompareV3/data/properties/index.js +2 -0
  78. package/lib/components/ModelCompareV3/data/properties/index.js.map +1 -1
  79. package/lib/components/ModelCompareV3/data/properties/index.mjs +1 -0
  80. package/lib/components/ModelCompareV3/data/properties/index.mjs.map +1 -1
  81. package/lib/components/ModelCompareV3/data/properties/managedCameras.js +4 -3
  82. package/lib/components/ModelCompareV3/data/properties/managedCameras.js.map +1 -1
  83. package/lib/components/ModelCompareV3/data/properties/managedCameras.mjs +4 -3
  84. package/lib/components/ModelCompareV3/data/properties/managedCameras.mjs.map +1 -1
  85. package/lib/components/ModelCompareV3/data/properties/vantagePoint.d.ts +2 -0
  86. package/lib/components/ModelCompareV3/data/properties/vantagePoint.js +20 -0
  87. package/lib/components/ModelCompareV3/data/properties/vantagePoint.js.map +1 -0
  88. package/lib/components/ModelCompareV3/data/properties/vantagePoint.mjs +12 -0
  89. package/lib/components/ModelCompareV3/data/properties/vantagePoint.mjs.map +1 -0
  90. package/lib/components/ModelCompareV3/translations/ar.json.js +5 -2
  91. package/lib/components/ModelCompareV3/translations/ar.json.js.map +1 -1
  92. package/lib/components/ModelCompareV3/translations/ar.json.mjs +5 -2
  93. package/lib/components/ModelCompareV3/translations/ar.json.mjs.map +1 -1
  94. package/lib/components/ModelCompareV3/translations/de.json.js +5 -2
  95. package/lib/components/ModelCompareV3/translations/de.json.js.map +1 -1
  96. package/lib/components/ModelCompareV3/translations/de.json.mjs +5 -2
  97. package/lib/components/ModelCompareV3/translations/de.json.mjs.map +1 -1
  98. package/lib/components/ModelCompareV3/translations/el.json.js +5 -2
  99. package/lib/components/ModelCompareV3/translations/el.json.js.map +1 -1
  100. package/lib/components/ModelCompareV3/translations/el.json.mjs +5 -2
  101. package/lib/components/ModelCompareV3/translations/el.json.mjs.map +1 -1
  102. package/lib/components/ModelCompareV3/translations/en.json.js +5 -2
  103. package/lib/components/ModelCompareV3/translations/en.json.js.map +1 -1
  104. package/lib/components/ModelCompareV3/translations/en.json.mjs +5 -2
  105. package/lib/components/ModelCompareV3/translations/en.json.mjs.map +1 -1
  106. package/lib/components/ModelCompareV3/translations/es.json.js +5 -2
  107. package/lib/components/ModelCompareV3/translations/es.json.js.map +1 -1
  108. package/lib/components/ModelCompareV3/translations/es.json.mjs +5 -2
  109. package/lib/components/ModelCompareV3/translations/es.json.mjs.map +1 -1
  110. package/lib/components/ModelCompareV3/translations/fr.json.js +5 -2
  111. package/lib/components/ModelCompareV3/translations/fr.json.js.map +1 -1
  112. package/lib/components/ModelCompareV3/translations/fr.json.mjs +5 -2
  113. package/lib/components/ModelCompareV3/translations/fr.json.mjs.map +1 -1
  114. package/lib/components/ModelCompareV3/translations/it.json.js +5 -2
  115. package/lib/components/ModelCompareV3/translations/it.json.js.map +1 -1
  116. package/lib/components/ModelCompareV3/translations/it.json.mjs +5 -2
  117. package/lib/components/ModelCompareV3/translations/it.json.mjs.map +1 -1
  118. package/lib/components/ModelCompareV3/translations/ja.json.js +5 -2
  119. package/lib/components/ModelCompareV3/translations/ja.json.js.map +1 -1
  120. package/lib/components/ModelCompareV3/translations/ja.json.mjs +5 -2
  121. package/lib/components/ModelCompareV3/translations/ja.json.mjs.map +1 -1
  122. package/lib/components/ModelCompareV3/translations/pt-BR.json.js +5 -2
  123. package/lib/components/ModelCompareV3/translations/pt-BR.json.js.map +1 -1
  124. package/lib/components/ModelCompareV3/translations/pt-BR.json.mjs +5 -2
  125. package/lib/components/ModelCompareV3/translations/pt-BR.json.mjs.map +1 -1
  126. package/lib/components/ModelCompareV3/translations/useModelCompareTranslation.d.ts +2 -2
  127. package/lib/components/ModelCompareV3/translations/zh-Hans.json.js +5 -2
  128. package/lib/components/ModelCompareV3/translations/zh-Hans.json.js.map +1 -1
  129. package/lib/components/ModelCompareV3/translations/zh-Hans.json.mjs +5 -2
  130. package/lib/components/ModelCompareV3/translations/zh-Hans.json.mjs.map +1 -1
  131. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.js +5 -2
  132. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.js.map +1 -1
  133. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.mjs +5 -2
  134. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.mjs.map +1 -1
  135. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  136. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  137. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  138. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  139. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  140. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  141. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  142. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  143. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  144. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  145. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  146. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  147. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  148. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  149. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  150. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  151. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  152. package/lib/constants/icons/options/colors/index.js +3 -3
  153. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  154. package/lib/constants/icons/options/styles/index.js +3 -3
  155. package/lib/constants/keyFeatureIcons.d.ts +1 -0
  156. package/lib/constants/keyFeatureIcons.js +6 -3
  157. package/lib/constants/keyFeatureIcons.js.map +1 -1
  158. package/lib/constants/keyFeatureIcons.mjs +6 -3
  159. package/lib/constants/keyFeatureIcons.mjs.map +1 -1
  160. package/lib/constants/optionIcons.js +6 -6
  161. package/lib/constants/optionIcons.mjs +4 -4
  162. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -2
  163. package/lib/constants/proStoreCategories/mapping/index.js +46 -56
  164. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  165. package/lib/constants/proStoreCategories/mapping/index.mjs +46 -56
  166. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  167. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -3
  168. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -2
  169. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  170. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -2
  171. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  172. package/lib/constants/proStoreCategories/translations/ar.json.js +1 -2
  173. package/lib/constants/proStoreCategories/translations/ar.json.js.map +1 -1
  174. package/lib/constants/proStoreCategories/translations/ar.json.mjs +1 -2
  175. package/lib/constants/proStoreCategories/translations/ar.json.mjs.map +1 -1
  176. package/lib/constants/proStoreCategories/translations/de.json.js +1 -2
  177. package/lib/constants/proStoreCategories/translations/de.json.js.map +1 -1
  178. package/lib/constants/proStoreCategories/translations/de.json.mjs +1 -2
  179. package/lib/constants/proStoreCategories/translations/de.json.mjs.map +1 -1
  180. package/lib/constants/proStoreCategories/translations/el.json.js +1 -2
  181. package/lib/constants/proStoreCategories/translations/el.json.js.map +1 -1
  182. package/lib/constants/proStoreCategories/translations/el.json.mjs +1 -2
  183. package/lib/constants/proStoreCategories/translations/el.json.mjs.map +1 -1
  184. package/lib/constants/proStoreCategories/translations/en.json.js +0 -4
  185. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  186. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -4
  187. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  188. package/lib/constants/proStoreCategories/translations/es.json.js +1 -2
  189. package/lib/constants/proStoreCategories/translations/es.json.js.map +1 -1
  190. package/lib/constants/proStoreCategories/translations/es.json.mjs +1 -2
  191. package/lib/constants/proStoreCategories/translations/es.json.mjs.map +1 -1
  192. package/lib/constants/proStoreCategories/translations/fr.json.js +2 -3
  193. package/lib/constants/proStoreCategories/translations/fr.json.js.map +1 -1
  194. package/lib/constants/proStoreCategories/translations/fr.json.mjs +2 -3
  195. package/lib/constants/proStoreCategories/translations/fr.json.mjs.map +1 -1
  196. package/lib/constants/proStoreCategories/translations/it.json.js +1 -2
  197. package/lib/constants/proStoreCategories/translations/it.json.js.map +1 -1
  198. package/lib/constants/proStoreCategories/translations/it.json.mjs +1 -2
  199. package/lib/constants/proStoreCategories/translations/it.json.mjs.map +1 -1
  200. package/lib/constants/proStoreCategories/translations/ja.json.js +1 -2
  201. package/lib/constants/proStoreCategories/translations/ja.json.js.map +1 -1
  202. package/lib/constants/proStoreCategories/translations/ja.json.mjs +1 -2
  203. package/lib/constants/proStoreCategories/translations/ja.json.mjs.map +1 -1
  204. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +1 -2
  205. package/lib/constants/proStoreCategories/translations/pt-BR.json.js.map +1 -1
  206. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +1 -2
  207. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs.map +1 -1
  208. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +2 -3
  209. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js.map +1 -1
  210. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +2 -3
  211. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs.map +1 -1
  212. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +2 -3
  213. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js.map +1 -1
  214. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +2 -3
  215. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs.map +1 -1
  216. package/lib/constants/shopify/keyFeatureIcons.js +5 -1
  217. package/lib/constants/shopify/keyFeatureIcons.js.map +1 -1
  218. package/lib/constants/shopify/keyFeatureIcons.mjs +4 -1
  219. package/lib/constants/shopify/keyFeatureIcons.mjs.map +1 -1
  220. package/lib/helpers/index.d.ts +0 -1
  221. package/lib/helpers/index.js +0 -11
  222. package/lib/helpers/index.js.map +1 -1
  223. package/lib/helpers/index.mjs +0 -1
  224. package/lib/helpers/index.mjs.map +1 -1
  225. package/lib/types/index.d.ts +0 -1
  226. package/lib/types/index.js +0 -2
  227. package/lib/types/index.js.map +1 -1
  228. package/lib/types/index.mjs +0 -1
  229. package/lib/types/index.mjs.map +1 -1
  230. package/lib/utils/array.d.ts +0 -4
  231. package/lib/utils/array.js +0 -10
  232. package/lib/utils/array.js.map +1 -1
  233. package/lib/utils/array.mjs +1 -10
  234. package/lib/utils/array.mjs.map +1 -1
  235. package/lib/utils/money/tax.private.d.ts +8 -0
  236. package/lib/utils/money/tax.private.js +14 -5
  237. package/lib/utils/money/tax.private.js.map +1 -1
  238. package/lib/utils/money/tax.private.mjs +16 -8
  239. package/lib/utils/money/tax.private.mjs.map +1 -1
  240. package/package.json +1 -1
  241. package/lib/assets/cloudKeyG2.png +0 -0
  242. package/lib/assets/envr.png +0 -0
  243. package/lib/assets/nvr.png +0 -0
  244. package/lib/assets/nvrPro.png +0 -0
  245. package/lib/assets/phased_array.svg +0 -3
  246. package/lib/components/ModelCompareV3/assets/cloudKeyG2.png.js.map +0 -1
  247. package/lib/components/ModelCompareV3/assets/cloudKeyG2.png.mjs +0 -3
  248. package/lib/components/ModelCompareV3/assets/cloudKeyG2.png.mjs.map +0 -1
  249. package/lib/components/ModelCompareV3/assets/envr.png.js.map +0 -1
  250. package/lib/components/ModelCompareV3/assets/envr.png.mjs +0 -3
  251. package/lib/components/ModelCompareV3/assets/envr.png.mjs.map +0 -1
  252. package/lib/components/ModelCompareV3/assets/nvr.png.js.map +0 -1
  253. package/lib/components/ModelCompareV3/assets/nvr.png.mjs +0 -3
  254. package/lib/components/ModelCompareV3/assets/nvr.png.mjs.map +0 -1
  255. package/lib/components/ModelCompareV3/assets/nvrPro.png.js.map +0 -1
  256. package/lib/components/ModelCompareV3/assets/nvrPro.png.mjs +0 -3
  257. package/lib/components/ModelCompareV3/assets/nvrPro.png.mjs.map +0 -1
  258. package/lib/helpers/product.d.ts +0 -87
  259. package/lib/helpers/product.js +0 -346
  260. package/lib/helpers/product.js.map +0 -1
  261. package/lib/helpers/product.mjs +0 -335
  262. package/lib/helpers/product.mjs.map +0 -1
  263. package/lib/helpers/product.test.d.ts +0 -1
  264. package/lib/types/product.d.ts +0 -87
  265. package/lib/types/product.js +0 -14
  266. package/lib/types/product.js.map +0 -1
  267. package/lib/types/product.mjs +0 -13
  268. package/lib/types/product.mjs.map +0 -1
  269. package/lib/utils/productSort.d.ts +0 -41
  270. package/lib/utils/productSort.js +0 -67
  271. package/lib/utils/productSort.js.map +0 -1
  272. package/lib/utils/productSort.mjs +0 -60
  273. package/lib/utils/productSort.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, dinero, subtract } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): 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":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxRate","dinero","Round","Financial","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount"],"mappings":";;;;;;;AAqBa,MAAAA,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAoB,GAAAC,SAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYO,cAAgB,EAAAP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEM,MAAAE,SAAA,GAAY,IAAIC,gCAAqB,CAAA;IACzCC,uBAAuBV,WAAY,CAAAO,cAAA;IACnCI,kBAAA,EAAoBC,YAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAY,CAAAM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAK,CAAA;IAAEC,QAAQf,WAAY,CAAAC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAU,CAAAS,QAAA,CACxCjB,WAAY,CAAAkB,SAAA,EACZlB,WAAY,CAAAM,QAAA,CACd;IAEA,MAAMD,aAAgB,GAAAc,SAAA,CAAAA,QAAA,CACpBf,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYkB,SAAW,EAAAlB,WAAA,CAAYM,QAAQ,CAAA,EACrDU,uBAAA,CACF;IAEO,OAAA;MACLE,WAAWlB,WAAY,CAAAkB,SAAA;MACvBb,aAAA,EAAeO,YAAOP,aAAa,CAAA;MACnCE,cAAA,EAAgBK,YAAOI,uBAAuB,CAAA;MAC9CV,UAAUN,WAAY,CAAAM,QAAA;MACtBL,QAAU,EAAA;IAAA,CACZ;EAAA,CACD,CAAA;AACH,CAAA;AAEa,MAAAmB,4BAAA,GAA+BA,CAC1CpB,WAAA,EACAqB,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAjB,cAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAMA,OAAOgB,gBAAO,CAAA;IACZV,MAAQ,EAAAW,SAAAA,CAAAA,KAAA,CAAMC,SAAU,CAAAxB,WAAA,CAAYK,gBAAgBgB,OAAO,CAAA;IAC3Df,QAAA,EAAUmB,IAAAA,CAAAA,iBAAkB,CAAAzB,WAAA,CAAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEa,MAAAoB,0BAAA,GAA6BA,CACxC1B,WAAA,EACAqB,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAjB,cAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGM,MAAAqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAiB,GAAAxB,IAAA,CAAAA,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCqB,mBAAA,CAAAE,OAAA,CAAS7B,YAAgB,IAAA;IAGrC,MAAA8B,SAAA,GAAYV,4BAA6BpB,CAAAA,YAAAA,EAAaqB,OAAO,CAAA;IAClDO,cAAA,GAAAzB,SAAA,CAAAA,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAF,cAAA;AACT,CAAA;;;"}
1
+ {"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport 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":"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"}
@@ -1,8 +1,17 @@
1
- import { add, subtract, dinero } from 'dinero.js';
1
+ import { add, subtract, allocate } from 'dinero.js';
2
+ import { assert } from '../errors.mjs';
2
3
  import { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
3
- import { Round } from './constants.mjs';
4
- import { getDinero, amount, getDineroCurrency } from './misc.mjs';
4
+ import { getDinero, amount } from './misc.mjs';
5
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
+ };
6
15
  const allocatePerItemTaxableAmount = itemSummary => {
7
16
  if (itemSummary.quantity === 1) {
8
17
  return [itemSummary];
@@ -31,10 +40,9 @@ const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
31
40
  if (taxRate === 0) {
32
41
  return getDinero(0, itemSummary.currency);
33
42
  }
34
- return dinero({
35
- amount: Round.Financial(itemSummary.taxableAmount * taxRate),
36
- currency: getDineroCurrency(itemSummary.currency)
37
- });
43
+ const [taxAmount] = allocate(getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
44
+ assert(taxAmount !== void 0, "taxAmount is undefined");
45
+ return taxAmount;
38
46
  };
39
47
  const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
40
48
  if (taxRate === 0) {
@@ -48,5 +56,5 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
48
56
  });
49
57
  return totalTaxAmount;
50
58
  };
51
- export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax };
59
+ export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, taxRateToDineroAllocation };
52
60
  //# sourceMappingURL=tax.private.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, dinero, subtract } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): 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":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxRate","dinero","Round","Financial","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount"],"mappings":";;;;;AAqBa,MAAAA,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAoB,GAAAC,GAAA,CACxBC,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,SAAU,CAAAJ,WAAA,CAAYO,cAAgB,EAAAP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEM,MAAAE,SAAA,GAAY,IAAIC,oBAAqB,CAAA;IACzCC,uBAAuBV,WAAY,CAAAO,cAAA;IACnCI,kBAAA,EAAoBC,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAY,CAAAM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAK,CAAA;IAAEC,QAAQf,WAAY,CAAAC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAU,CAAAS,QAAA,CACxCjB,WAAY,CAAAkB,SAAA,EACZlB,WAAY,CAAAM,QAAA,CACd;IAEA,MAAMD,aAAgB,GAAAc,QAAA,CACpBf,SAAU,CAAAJ,WAAA,CAAYkB,SAAW,EAAAlB,WAAA,CAAYM,QAAQ,CAAA,EACrDU,uBAAA,CACF;IAEO,OAAA;MACLE,WAAWlB,WAAY,CAAAkB,SAAA;MACvBb,aAAA,EAAeO,OAAOP,aAAa,CAAA;MACnCE,cAAA,EAAgBK,OAAOI,uBAAuB,CAAA;MAC9CV,UAAUN,WAAY,CAAAM,QAAA;MACtBL,QAAU,EAAA;IAAA,CACZ;EAAA,CACD,CAAA;AACH,CAAA;AAEa,MAAAmB,4BAAA,GAA+BA,CAC1CpB,WAAA,EACAqB,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAjB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAMA,OAAOgB,MAAO,CAAA;IACZV,MAAQ,EAAAW,KAAA,CAAMC,SAAU,CAAAxB,WAAA,CAAYK,gBAAgBgB,OAAO,CAAA;IAC3Df,QAAA,EAAUmB,iBAAkB,CAAAzB,WAAA,CAAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEa,MAAAoB,0BAAA,GAA6BA,CACxC1B,WAAA,EACAqB,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAjB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGM,MAAAqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAiB,GAAAxB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCqB,mBAAA,CAAAE,OAAA,CAAS7B,YAAgB,IAAA;IAGrC,MAAA8B,SAAA,GAAYV,4BAA6BpB,CAAAA,YAAAA,EAAaqB,OAAO,CAAA;IAClDO,cAAA,GAAAzB,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAF,cAAA;AACT,CAAA;"}
1
+ {"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport 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":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "9.24.0-beta.1",
3
+ "version": "9.25.0",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {
Binary file
Binary file
Binary file
Binary file
@@ -1,3 +0,0 @@
1
- <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M18.94 15.3999C19.2821 15.3999 19.5594 15.6685 19.5594 15.9999C19.5594 17.9881 17.8956 19.5999 15.8432 19.5999C15.5012 19.5999 15.2239 19.3313 15.2239 18.9999C15.2239 18.6685 15.5012 18.3999 15.8432 18.3999C17.2115 18.3999 18.3207 17.3254 18.3207 15.9999C18.3207 15.6685 18.598 15.3999 18.94 15.3999ZM0.97873 15.3999C1.32079 15.3999 1.59808 15.6685 1.59808 15.9999C1.59808 17.3254 2.70726 18.3999 4.0755 18.3999C4.41756 18.3999 4.69486 18.6685 4.69486 18.9999C4.69486 19.3313 4.41756 19.5999 4.0755 19.5999C2.02314 19.5999 0.359375 17.9881 0.359375 15.9999C0.359375 15.6685 0.63667 15.3999 0.97873 15.3999ZM15.8432 15.3999C16.1853 15.3999 16.4626 15.6685 16.4626 15.9999C16.4626 16.3313 16.1853 16.5999 15.8432 16.5999C15.5012 16.5999 15.2239 16.3313 15.2239 15.9999C15.2239 15.6685 15.5012 15.3999 15.8432 15.3999ZM4.0755 15.3999C4.41756 15.3999 4.69486 15.6685 4.69486 15.9999C4.69486 16.3313 4.41756 16.5999 4.0755 16.5999C3.73344 16.5999 3.45615 16.3313 3.45615 15.9999C3.45615 15.6685 3.73344 15.3999 4.0755 15.3999ZM9.6497 3.9999C13.0703 3.9999 15.8432 6.68619 15.8432 9.9999C15.8432 13.3136 13.0703 15.9999 9.6497 15.9999C6.2291 15.9999 3.45615 13.3136 3.45615 9.9999C3.45615 6.68619 6.2291 3.9999 9.6497 3.9999ZM9.6497 5.1999C6.91322 5.1999 4.69486 7.34894 4.69486 9.9999C4.69486 12.6509 6.91322 14.7999 9.6497 14.7999C12.3862 14.7999 14.6045 12.6509 14.6045 9.9999C14.6045 7.34894 12.3862 5.1999 9.6497 5.1999ZM9.6497 7.5999C11.0179 7.5999 12.1271 8.67442 12.1271 9.9999C12.1271 11.3254 11.0179 12.3999 9.6497 12.3999C8.28146 12.3999 7.17228 11.3254 7.17228 9.9999C7.17228 8.67442 8.28146 7.5999 9.6497 7.5999ZM9.6497 8.7999C8.96558 8.7999 8.41099 9.33716 8.41099 9.9999C8.41099 10.6626 8.96558 11.1999 9.6497 11.1999C10.3338 11.1999 10.8884 10.6626 10.8884 9.9999C10.8884 9.33716 10.3338 8.7999 9.6497 8.7999ZM15.8432 3.3999C16.1853 3.3999 16.4626 3.66853 16.4626 3.9999C16.4626 4.33127 16.1853 4.5999 15.8432 4.5999C15.5012 4.5999 15.2239 4.33127 15.2239 3.9999C15.2239 3.66853 15.5012 3.3999 15.8432 3.3999ZM15.8432 0.399902C17.8956 0.399902 19.5594 2.01168 19.5594 3.9999C19.5594 4.33127 19.2821 4.5999 18.94 4.5999C18.598 4.5999 18.3207 4.33127 18.3207 3.9999C18.3207 2.67442 17.2115 1.5999 15.8432 1.5999C15.5012 1.5999 15.2239 1.33127 15.2239 0.999902C15.2239 0.668532 15.5012 0.399902 15.8432 0.399902ZM4.0755 3.3999C4.41756 3.3999 4.69486 3.66853 4.69486 3.9999C4.69486 4.33127 4.41756 4.5999 4.0755 4.5999C3.73344 4.5999 3.45615 4.33127 3.45615 3.9999C3.45615 3.66853 3.73344 3.3999 4.0755 3.3999ZM4.0755 0.399902C4.41756 0.399902 4.69486 0.668532 4.69486 0.999902C4.69486 1.33127 4.41756 1.5999 4.0755 1.5999C2.70726 1.5999 1.59808 2.67442 1.59808 3.9999C1.59808 4.33127 1.32079 4.5999 0.97873 4.5999C0.63667 4.5999 0.359375 4.33127 0.359375 3.9999C0.359375 2.01168 2.02314 0.399902 4.0755 0.399902Z" fill="#212124"/>
3
- </svg>
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloudKeyG2.png.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +0,0 @@
1
- export * from "../../../assets/cloudKeyG2.png";
2
- export { default } from "../../../assets/cloudKeyG2.png";
3
- //# sourceMappingURL=cloudKeyG2.png.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloudKeyG2.png.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"envr.png.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +0,0 @@
1
- export * from "../../../assets/envr.png";
2
- export { default } from "../../../assets/envr.png";
3
- //# sourceMappingURL=envr.png.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"envr.png.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"nvr.png.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +0,0 @@
1
- export * from "../../../assets/nvr.png";
2
- export { default } from "../../../assets/nvr.png";
3
- //# sourceMappingURL=nvr.png.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nvr.png.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"nvrPro.png.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +0,0 @@
1
- export * from "../../../assets/nvrPro.png";
2
- export { default } from "../../../assets/nvrPro.png";
3
- //# sourceMappingURL=nvrPro.png.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nvrPro.png.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,87 +0,0 @@
1
- import type { ParsedCategoryItem } from "../constants/proStoreCategories";
2
- import type { CollectionSection, MappedProductSection, Nullish, ProductTagFragment, Section, StorefrontOption, StorefrontProduct, StoreId } from "../types";
3
- export declare const isNonNullish: <T>(entry: T | null | undefined) => entry is T;
4
- /**
5
- * Removes products that have tag starting with `EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX`
6
- * and ends with `storeId`, e.g. `"exclude-from-store-grid:us`
7
- *
8
- * @warning Use this function only on grid and breadcrumbs products
9
- */
10
- export declare const removeExcludedProducts: <T extends {
11
- tags: ProductTagFragment[];
12
- }>(products: T[], storeId: StoreId) => T[];
13
- export declare enum HDDProductSlugs {
14
- HDD_1TB = "uacc-hdd-s-1tb",
15
- HDD_8TB_Enterprise = "uacc-hdd-e-8tb",
16
- HDD_16TB_Enterprise = "uacc-hdd-e-16tb"
17
- }
18
- /**
19
- * Recursively create section hierarchy
20
- */
21
- export declare const createSectionHierarchy: (sections: CollectionSection[], level?: number) => Section[];
22
- export declare enum MagicCollectionTags {
23
- /**
24
- * Used to determine if collection should be shown in an accessory
25
- * layout style where sections are placed inside variant cards
26
- */
27
- LayoutAccessories = "layout-accessories",
28
- /**
29
- * Used to determine if collection is pro-store specific and should
30
- * be redirected to pro-store's appropriate category
31
- */
32
- ProStore = "pro-store",
33
- /**
34
- * Used to disable length options (disable product splitting by "length")
35
- */
36
- DisableLengthOptions = "disable-length-options",
37
- /**
38
- * Used to disable speed options (disable product splitting by "speed")
39
- */
40
- DisableSpeedOptions = "disable-speed-options"
41
- }
42
- export declare enum ProductOptions {
43
- Length = "length",
44
- Speed = "speed",
45
- Color = "color"
46
- }
47
- export declare const COLLECTION_SECTION_OTHER_ID = "other";
48
- /**
49
- * Create product groups
50
- */
51
- export declare const getProductGroups: <T extends StorefrontProduct & {
52
- options: StorefrontOption[];
53
- }>(products?: T[], sectionHierarchy?: Nullish<Section[]>, tags?: Array<{
54
- id: string;
55
- name: string;
56
- }>) => MappedProductSection<T>[] | undefined;
57
- export declare const getProStoreCategory: ({ queryCategory, product, ignoreQuery, }: {
58
- queryCategory?: string;
59
- product: Pick<StorefrontProduct, "collectionSlug" | "organizationalCollectionSlug" | "proCollectionSlug">;
60
- ignoreQuery?: boolean;
61
- }) => string | null;
62
- type StoreProductsData = ({
63
- category: {
64
- id: string;
65
- label: string | null;
66
- } | undefined;
67
- } & {
68
- products: StorefrontProduct[];
69
- }) | {
70
- productGroups: MappedProductSection<StorefrontProduct>[];
71
- };
72
- export declare const getStoreProducts: ({ storeId, queryCategory, currentProduct, collections, allCategoryItems, }: {
73
- storeId: StoreId;
74
- queryCategory: string | undefined;
75
- currentProduct: Pick<StorefrontProduct, "id" | "slug" | "collectionSlug" | "organizationalCollectionSlug" | "proCollectionSlug">;
76
- collections: Array<{
77
- slug: string;
78
- sections: Array<{
79
- id: string;
80
- title: string;
81
- productTags: Array<string>;
82
- }>;
83
- products: Array<Pick<StorefrontProduct, "id" | "slug" | "tags" | "variants" | "options" | "title" | "status" | "minDisplayPrice">>;
84
- }>;
85
- allCategoryItems: ParsedCategoryItem[];
86
- }) => StoreProductsData;
87
- export {};
@@ -1,346 +0,0 @@
1
- 'use strict';
2
-
3
- var lodashEs = require('lodash-es');
4
- require('../constants/proStoreCategories/index.js');
5
- require('../types/index.js');
6
- var array = require('../utils/array.js');
7
- var productSort = require('../utils/productSort.js');
8
- var proStoreCategories = require('./proStoreCategories.js');
9
- var unifi = require('../constants/proStoreCategories/mapping/unifi.js');
10
- var uisp = require('../constants/proStoreCategories/mapping/uisp.js');
11
- var product = require('../types/product.js');
12
- "use strict";
13
- const isNonNullish = entry => entry !== null && entry !== void 0;
14
- const EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX = "exclude-from-store-grid:";
15
- const removeExcludedProducts = (products, storeId) => {
16
- const excludeTag = `${EXCLUDE_PRODUCT_FROM_STORE_GRID_TAG_PREFIX}${storeId}`.toLowerCase();
17
- return products.filter(product => {
18
- return !product.tags.some(tag => tag.name.toLowerCase() === excludeTag);
19
- });
20
- };
21
- const isAccessoryCategoryItem = categoryItem => {
22
- return !!categoryItem && [unifi.UniFiCategoryId.Accessories, uisp.UISPCategoryId.AccessoryTech].includes(
23
- // TODO: Check why this TS error appears
24
- // @ts-expect-error: Unreachable code error
25
- categoryItem.id);
26
- };
27
- var HDDProductSlugs = /* @__PURE__ */(HDDProductSlugs2 => {
28
- HDDProductSlugs2["HDD_1TB"] = "uacc-hdd-s-1tb";
29
- HDDProductSlugs2["HDD_8TB_Enterprise"] = "uacc-hdd-e-8tb";
30
- HDDProductSlugs2["HDD_16TB_Enterprise"] = "uacc-hdd-e-16tb";
31
- return HDDProductSlugs2;
32
- })(HDDProductSlugs || {});
33
- const isAllowedAccessoryCategoryProduct = ({
34
- slug
35
- }) => {
36
- const allowedAccessoryProductSlugs = ["u-lte", "u-lte-backup-pro", "uacc-hdd-s-1tb" /* HDD_1TB */, "uacc-hdd-e-8tb" /* HDD_8TB_Enterprise */, "uacc-hdd-e-16tb" /* HDD_16TB_Enterprise */];
37
- return allowedAccessoryProductSlugs.includes(slug);
38
- };
39
- const isAccessoryCategorySubItem = (categorySubItem, allCategoryItems) => {
40
- const categoryItem = allCategoryItems.find(item => item.items?.some(subItem => subItem.id === categorySubItem.id));
41
- return isAccessoryCategoryItem(categoryItem);
42
- };
43
- const createSectionHierarchy = (sections, level = 1) => {
44
- const currentLevelSections = sections.filter(section => section.productTags.length === level);
45
- if (!currentLevelSections.length) {
46
- return [];
47
- }
48
- return currentLevelSections.map(section => ({
49
- ...section,
50
- items: createSectionHierarchy(sections.filter(nextSection => section.productTags.every(tag => nextSection.productTags.includes(tag))), level + 1)
51
- }));
52
- };
53
- var MagicCollectionTags = /* @__PURE__ */(MagicCollectionTags2 => {
54
- MagicCollectionTags2["LayoutAccessories"] = "layout-accessories";
55
- MagicCollectionTags2["ProStore"] = "pro-store";
56
- MagicCollectionTags2["DisableLengthOptions"] = "disable-length-options";
57
- MagicCollectionTags2["DisableSpeedOptions"] = "disable-speed-options";
58
- return MagicCollectionTags2;
59
- })(MagicCollectionTags || {});
60
- var ProductOptions = /* @__PURE__ */(ProductOptions2 => {
61
- ProductOptions2["Length"] = "length";
62
- ProductOptions2["Speed"] = "speed";
63
- ProductOptions2["Color"] = "color";
64
- return ProductOptions2;
65
- })(ProductOptions || {});
66
- const formatOptionValueTitleToTag = optionValueTitle => optionValueTitle.toLowerCase().replace(/[,\s]/g, "").replace(".", "-");
67
- const divideProductByOption = (product, optionTitle) => {
68
- const option = product.options.find(option2 => option2.slug === optionTitle);
69
- if (!option) {
70
- return [product];
71
- }
72
- return option.values.map(value => {
73
- return {
74
- ...product,
75
- options: product.options.filter(option2 => option2.slug !== optionTitle),
76
- tags: [...product.tags, {
77
- id: value.id,
78
- name: formatOptionValueTitleToTag(value.slug)
79
- }],
80
- variants: product.variants.filter(variant => variant.optionValueIds?.includes(value.id))
81
- };
82
- });
83
- };
84
- const COLLECTION_SECTION_OTHER_ID = "other";
85
- const UNIT_FACTORS = {
86
- m: 1,
87
- km: 1e3
88
- };
89
- const DISTANCE_REGEX = /^\s*(\d+)\s*(m|km)\s*$/;
90
- const mapProductsToSections = (products, section) => {
91
- const productsInThisSection = products.filter(product => {
92
- return section.productTags.every(sectionTag => {
93
- return product.tags.find(tag => tag.name === sectionTag);
94
- });
95
- });
96
- if (productsInThisSection.length === 0) {
97
- return void 0;
98
- }
99
- const items = section?.items?.map(item => mapProductsToSections(productsInThisSection, item)).filter(isNonNullish) ?? [];
100
- const otherProducts = productsInThisSection.filter(product => {
101
- return !items.some(item => item.products.find(p => p.id === product.id));
102
- });
103
- if (otherProducts.length && items.length) {
104
- items.push({
105
- id: `${section.id}-${COLLECTION_SECTION_OTHER_ID}`,
106
- // TODO: Add translation
107
- title: "Other",
108
- productTags: section.productTags,
109
- items: [],
110
- products: otherProducts
111
- });
112
- }
113
- return {
114
- ...section,
115
- items,
116
- products: productsInThisSection
117
- };
118
- };
119
- const compareDistanceTitles = (a, b) => {
120
- const aMatch = a.title.match(DISTANCE_REGEX);
121
- const bMatch = b.title.match(DISTANCE_REGEX);
122
- if (!aMatch?.[1] || !aMatch[2] || !bMatch?.[1] || !bMatch[2]) {
123
- return 0;
124
- }
125
- const aValue = parseInt(aMatch[1]) * (UNIT_FACTORS[aMatch[2]] || 0);
126
- const bValue = parseInt(bMatch[1]) * (UNIT_FACTORS[bMatch[2]] || 0);
127
- return aValue - bValue;
128
- };
129
- const processSectionProductsWithDistanceInOptions = sections => {
130
- return sections.map(section => ({
131
- ...section,
132
- items: section.items.map(sec => {
133
- const section2 = lodashEs.cloneDeep(sec);
134
- const sectionWithDistanceTag = section2.items.find(section3 => section3.productTags.includes("distance"));
135
- const sectionsMainProductTag = sectionWithDistanceTag?.productTags.filter(tag => tag !== "distance");
136
- if (!sectionWithDistanceTag || !sectionsMainProductTag) {
137
- return section2;
138
- }
139
- sectionWithDistanceTag.products.forEach(product => {
140
- const optionValues = product?.options[0]?.values;
141
- if (!optionValues?.length) {
142
- return;
143
- }
144
- const formattedOptionValues = optionValues.map(value => ({
145
- ...value,
146
- titleInTagFormat: formatOptionValueTitleToTag(value.title)
147
- }));
148
- formattedOptionValues.forEach(currentValue => {
149
- const newSecondLevelSectionsTags = [...sectionsMainProductTag, currentValue.titleInTagFormat];
150
- const alreadyExistingSecondLevelSection = section2.items.findIndex(section3 => array.areEqualArrays(section3.productTags, newSecondLevelSectionsTags));
151
- const variantToAdd = product.variants.find(variant => variant.optionValueIds?.includes(currentValue.id));
152
- if (!variantToAdd) {
153
- return;
154
- }
155
- const productToAdd = {
156
- ...product,
157
- options: product.options.filter(option => option.values.some(value => value.id === currentValue.id)).map(option => ({
158
- ...option,
159
- values: option.values.filter(value => value.id === currentValue.id)
160
- })),
161
- variants: [variantToAdd]
162
- };
163
- if (alreadyExistingSecondLevelSection >= 0) {
164
- section2.items[alreadyExistingSecondLevelSection]?.products.push(productToAdd);
165
- } else {
166
- const sectionToAdd = {
167
- id: currentValue.id,
168
- // TODO: Maybe so>me different ID would be better
169
- items: [],
170
- // FIXME: This is problem!
171
- products: [productToAdd],
172
- productTags: newSecondLevelSectionsTags,
173
- title: currentValue.title
174
- };
175
- section2.items.push(sectionToAdd);
176
- }
177
- });
178
- });
179
- return {
180
- ...section2,
181
- items: section2.items.sort(compareDistanceTitles).filter(section3 => !section3.productTags.includes("distance"))
182
- };
183
- })
184
- }));
185
- };
186
- const processSectionsWithOutOfStockProducts = section => {
187
- const isDisabled = section.products.every(product$1 => product$1.variants.every(variant => variant.status !== product.DisplayProductStatus.Available));
188
- return {
189
- ...section,
190
- isDisabled,
191
- items: section.items.map(processSectionsWithOutOfStockProducts)
192
- };
193
- };
194
- const getProductGroups = (products, sectionHierarchy, tags) => {
195
- if (!products?.length || !sectionHierarchy) return void 0;
196
- const processedProducts = products.flatMap(product => {
197
- const disableLengthOptions = tags?.find(tag => tag.name === "disable-length-options" /* DisableLengthOptions */);
198
- const lengthOptions = !disableLengthOptions && product?.options?.find(option => option.slug === "length" /* Length */);
199
- if (lengthOptions && product.options !== void 0) {
200
- return divideProductByOption(product, "length" /* Length */);
201
- }
202
- const disableSpeedOptions = tags?.find(tag => tag.name === "disable-speed-options" /* DisableSpeedOptions */);
203
- const speedOptions = !disableSpeedOptions && product?.options?.find(option => {
204
- return option.slug === "speed" /* Speed */;
205
- });
206
- if (speedOptions) {
207
- return divideProductByOption(product, "speed" /* Speed */);
208
- }
209
- return [product];
210
- });
211
- const mappedProductGroups = sectionHierarchy.map(section => {
212
- return mapProductsToSections(processedProducts, section);
213
- }).filter(section => !!section);
214
- const otherProducts = products.filter(product => {
215
- return !mappedProductGroups.some(section => {
216
- return section.products.find(p => p.id === product.id);
217
- });
218
- });
219
- if (otherProducts.length) {
220
- otherProducts.forEach(product => {
221
- mappedProductGroups.push({
222
- id: product.id,
223
- products: [product],
224
- title: "",
225
- items: [],
226
- productTags: []
227
- });
228
- });
229
- }
230
- const processedProductGroups = processSectionProductsWithDistanceInOptions(mappedProductGroups).map(processSectionsWithOutOfStockProducts);
231
- return processedProductGroups.sort((a, b) => {
232
- const aFirstProductId = a?.products?.[0]?.id;
233
- const bFirstProductId = b?.products?.[0]?.id;
234
- const aFirstProduct = products.findIndex(product => product.id === aFirstProductId);
235
- const bFirstProduct = products.findIndex(product => product.id === bFirstProductId);
236
- return aFirstProduct - bFirstProduct;
237
- });
238
- };
239
- const getProStoreCategory = ({
240
- queryCategory,
241
- product,
242
- ignoreQuery
243
- }) => {
244
- return (
245
- /**
246
- * If category specified via the url search/query parameter then use it
247
- */
248
- !ignoreQuery && queryCategory ||
249
- /**
250
- * Attempt to find category by it's default collection or fallback to the virtual default collection
251
- */
252
- proStoreCategories.getSubCategoryIdByCollectionSlug(product.collectionSlug) || proStoreCategories.getSubCategoryIdByCollectionSlug(product.organizationalCollectionSlug) ||
253
- /**
254
- * If all else fails fallback detecting to category from pro store collection, unlikely but wouldn't hurt to do so
255
- */
256
- proStoreCategories.getSubCategoryIdByCollectionSlug(product.proCollectionSlug)
257
- );
258
- };
259
- const getStoreProducts = ({
260
- storeId,
261
- queryCategory,
262
- currentProduct,
263
- collections,
264
- allCategoryItems
265
- }) => {
266
- const returnObj = {
267
- category: void 0,
268
- products: []
269
- };
270
- const category = getProStoreCategory({
271
- queryCategory,
272
- product: currentProduct
273
- });
274
- const categoryItem = allCategoryItems.find(item => item.items?.some(subItem => subItem.id === category));
275
- const categorySubItem = categoryItem?.items?.find(subItem => subItem.id === category);
276
- const categoryId = categorySubItem?.id ?? category;
277
- if (categoryId) {
278
- returnObj.category = {
279
- id: categoryId,
280
- label: categoryItem?.label ?? null
281
- };
282
- }
283
- const filteredCollections = collections.map(collection => ({
284
- ...collection,
285
- products: removeExcludedProducts(collection.products, storeId)
286
- }));
287
- if (categoryItem?.hideSubItems) {
288
- const products = filteredCollections.flatMap(collection => collection.products);
289
- if (isAccessoryCategoryItem(categoryItem)) {
290
- returnObj.products = isAllowedAccessoryCategoryProduct(currentProduct) ? products.filter(isAllowedAccessoryCategoryProduct) : [];
291
- } else {
292
- returnObj.products = products;
293
- }
294
- } else {
295
- const collection = filteredCollections.find(collection2 => collection2.products.some(el => el.id === currentProduct.id));
296
- if (!collection) {
297
- throw new Error("Collection not found");
298
- }
299
- const subItems = (categoryItem?.items?.slice(1) ?? allCategoryItems.flatMap(el => el.items?.slice(1))).filter(Boolean);
300
- const subItem = subItems.find(item => item.collectionSlugs.includes(collection.slug));
301
- if (subItem && returnObj.category) {
302
- returnObj.category = {
303
- id: subItem.id,
304
- label: subItem.label
305
- };
306
- }
307
- const subItemCollections = filteredCollections.filter(el => subItem?.collectionSlugs.includes(el.slug));
308
- const products = subItemCollections.flatMap(el => el.products);
309
- if (subItem) {
310
- if (isAccessoryCategorySubItem(subItem, allCategoryItems)) {
311
- returnObj.products = isAllowedAccessoryCategoryProduct(currentProduct) ? products.filter(isAllowedAccessoryCategoryProduct) : [];
312
- } else {
313
- returnObj.products = products;
314
- }
315
- }
316
- const sections = subItemCollections.flatMap(el => el.sections);
317
- const sectionHierarchy = createSectionHierarchy(sections);
318
- const productGroups = getProductGroups(products, sectionHierarchy);
319
- if (productGroups) {
320
- return {
321
- category: returnObj.category,
322
- productGroups: productGroups.sort((a, b) => {
323
- if (a.products[0] && b.products[0]) {
324
- return productSort.sortProducts(null, storeId)(a.products[0], b.products[0]);
325
- }
326
- return 0;
327
- })
328
- };
329
- }
330
- }
331
- return {
332
- ...returnObj,
333
- products: returnObj.products.sort(productSort.sortProducts(null, storeId))
334
- };
335
- };
336
- exports.COLLECTION_SECTION_OTHER_ID = COLLECTION_SECTION_OTHER_ID;
337
- exports.HDDProductSlugs = HDDProductSlugs;
338
- exports.MagicCollectionTags = MagicCollectionTags;
339
- exports.ProductOptions = ProductOptions;
340
- exports.createSectionHierarchy = createSectionHierarchy;
341
- exports.getProStoreCategory = getProStoreCategory;
342
- exports.getProductGroups = getProductGroups;
343
- exports.getStoreProducts = getStoreProducts;
344
- exports.isNonNullish = isNonNullish;
345
- exports.removeExcludedProducts = removeExcludedProducts;
346
- //# sourceMappingURL=product.js.map