@fast-simon/dashboard-utilities 1.0.96 → 1.0.97

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 (278) hide show
  1. package/dist/@types/autocomplete.d.ts +58 -58
  2. package/dist/@types/autocomplete.js +1 -1
  3. package/dist/@types/autocomplete.js.map +1 -1
  4. package/dist/@types/banner.d.ts +7 -7
  5. package/dist/@types/banner.js +1 -1
  6. package/dist/@types/banner.js.map +1 -1
  7. package/dist/@types/categories.d.ts +113 -113
  8. package/dist/@types/categories.js +1 -1
  9. package/dist/@types/categories.js.map +1 -1
  10. package/dist/@types/categoriesNavigation.d.ts +27 -27
  11. package/dist/@types/categoriesNavigation.js +1 -1
  12. package/dist/@types/categoriesNavigation.js.map +1 -1
  13. package/dist/@types/context.d.ts +49 -49
  14. package/dist/@types/context.js +1 -1
  15. package/dist/@types/context.js.map +1 -1
  16. package/dist/@types/currency.d.ts +1 -1
  17. package/dist/@types/currency.js +1 -1
  18. package/dist/@types/currency.js.map +1 -1
  19. package/dist/@types/editorProduct.d.ts +26 -26
  20. package/dist/@types/editorProduct.js +5 -5
  21. package/dist/@types/editorProduct.js.map +1 -1
  22. package/dist/@types/facets.d.ts +59 -59
  23. package/dist/@types/facets.js +18 -18
  24. package/dist/@types/facets.js.map +1 -1
  25. package/dist/@types/iconProps.d.ts +9 -9
  26. package/dist/@types/iconProps.js +1 -1
  27. package/dist/@types/iconProps.js.map +1 -1
  28. package/dist/@types/narrow.d.ts +7 -7
  29. package/dist/@types/narrow.js +1 -1
  30. package/dist/@types/narrow.js.map +1 -1
  31. package/dist/@types/product.d.ts +160 -160
  32. package/dist/@types/product.js +7 -7
  33. package/dist/@types/product.js.map +1 -1
  34. package/dist/@types/productLabel.d.ts +1 -1
  35. package/dist/@types/productLabel.js +1 -1
  36. package/dist/@types/promoTile.d.ts +11 -11
  37. package/dist/@types/promoTile.js +1 -1
  38. package/dist/@types/promoTile.js.map +1 -1
  39. package/dist/@types/results.d.ts +142 -142
  40. package/dist/@types/results.js +1 -1
  41. package/dist/@types/results.js.map +1 -1
  42. package/dist/@types/sideMenu.d.ts +19 -19
  43. package/dist/@types/sideMenu.js +1 -1
  44. package/dist/@types/sideMenu.js.map +1 -1
  45. package/dist/@types/sortBy.d.ts +3 -3
  46. package/dist/@types/sortBy.js +1 -1
  47. package/dist/@types/sortBy.js.map +1 -1
  48. package/dist/@types/widget.d.ts +8 -8
  49. package/dist/@types/widget.js +1 -1
  50. package/dist/@types/widget.js.map +1 -1
  51. package/dist/App.d.ts +3 -3
  52. package/dist/App.js +14 -14
  53. package/dist/App.js.map +1 -1
  54. package/dist/components/BackOfficeFiltersMenu/BackOfficeFiltersMenu.d.ts +9 -9
  55. package/dist/components/BackOfficeFiltersMenu/BackOfficeFiltersMenu.js +73 -73
  56. package/dist/components/BackOfficeFiltersMenu/BackOfficeFiltersMenu.js.map +1 -1
  57. package/dist/components/BackOfficeFiltersMenu/index.d.ts +1 -1
  58. package/dist/components/BackOfficeFiltersMenu/index.js +1 -1
  59. package/dist/components/BackOfficeFiltersMenu/index.js.map +1 -1
  60. package/dist/components/BackOfficeFiltersMenu/styles.module.css +9 -9
  61. package/dist/components/BackOfficeFiltersMenu/utils.d.ts +7 -7
  62. package/dist/components/BackOfficeFiltersMenu/utils.js +238 -238
  63. package/dist/components/BackOfficeFiltersMenu/utils.js.map +1 -1
  64. package/dist/components/CheckboxFilter/Checkbox/Checkbox.d.ts +10 -10
  65. package/dist/components/CheckboxFilter/Checkbox/Checkbox.js +6 -6
  66. package/dist/components/CheckboxFilter/Checkbox/Checkbox.js.map +1 -1
  67. package/dist/components/CheckboxFilter/Checkbox/styles.module.css +142 -142
  68. package/dist/components/CheckboxFilter/CheckboxFilter.d.ts +6 -6
  69. package/dist/components/CheckboxFilter/CheckboxFilter.js +8 -8
  70. package/dist/components/CheckboxFilter/CheckboxFilter.js.map +1 -1
  71. package/dist/components/CheckboxFilter/styles.module.css +4 -4
  72. package/dist/components/DragAndDrop/DndContextWrapper.d.ts +19 -19
  73. package/dist/components/DragAndDrop/DndContextWrapper.js +30 -30
  74. package/dist/components/DragAndDrop/DndContextWrapper.js.map +1 -1
  75. package/dist/components/DragAndDrop/Droppable.d.ts +7 -7
  76. package/dist/components/DragAndDrop/Droppable.js +9 -9
  77. package/dist/components/DragAndDrop/Droppable.js.map +1 -1
  78. package/dist/components/DragAndDrop/SortableItem.d.ts +13 -13
  79. package/dist/components/DragAndDrop/SortableItem.js +38 -38
  80. package/dist/components/DragAndDrop/SortableItem.js.map +1 -1
  81. package/dist/components/DragAndDrop/styles.module.css +15 -15
  82. package/dist/components/FacetItem/FacetItem.d.ts +13 -13
  83. package/dist/components/FacetItem/FacetItem.js +39 -39
  84. package/dist/components/FacetItem/FacetItem.js.map +1 -1
  85. package/dist/components/FacetItem/styles.module.css +54 -54
  86. package/dist/components/FastSimonApi/FastSimonApi.d.ts +39 -39
  87. package/dist/components/FastSimonApi/FastSimonApi.js +605 -605
  88. package/dist/components/FastSimonApi/FastSimonApi.js.map +1 -1
  89. package/dist/components/FastSimonApi/context.d.ts +62 -62
  90. package/dist/components/FastSimonApi/context.js +9 -9
  91. package/dist/components/FastSimonApi/context.js.map +1 -1
  92. package/dist/components/FastSimonApi/index.d.ts +3 -3
  93. package/dist/components/FastSimonApi/index.js +2 -2
  94. package/dist/components/FastSimonApi/index.js.map +1 -1
  95. package/dist/components/FastSimonApi/reducer.d.ts +458 -458
  96. package/dist/components/FastSimonApi/reducer.js +76 -76
  97. package/dist/components/FastSimonApi/reducer.js.map +1 -1
  98. package/dist/components/FromToFilter/From/From.d.ts +17 -17
  99. package/dist/components/FromToFilter/From/From.js +21 -21
  100. package/dist/components/FromToFilter/From/From.js.map +1 -1
  101. package/dist/components/FromToFilter/From/styles.module.css +8 -8
  102. package/dist/components/FromToFilter/FromToFilter.d.ts +14 -14
  103. package/dist/components/FromToFilter/FromToFilter.js +57 -57
  104. package/dist/components/FromToFilter/FromToFilter.js.map +1 -1
  105. package/dist/components/FromToFilter/To/To.d.ts +18 -18
  106. package/dist/components/FromToFilter/To/To.js +22 -22
  107. package/dist/components/FromToFilter/To/To.js.map +1 -1
  108. package/dist/components/FromToFilter/To/styles.module.css +8 -8
  109. package/dist/components/FromToFilter/styles.module.css +33 -33
  110. package/dist/components/FromToFilter/utils.d.ts +25 -25
  111. package/dist/components/FromToFilter/utils.js +6 -6
  112. package/dist/components/FromToFilter/utils.js.map +1 -1
  113. package/dist/components/InStoreFiltersMenu/InStoreFiltersMenu.d.ts +10 -10
  114. package/dist/components/InStoreFiltersMenu/InStoreFiltersMenu.js +33 -33
  115. package/dist/components/InStoreFiltersMenu/InStoreFiltersMenu.js.map +1 -1
  116. package/dist/components/InStoreFiltersMenu/index.d.ts +1 -1
  117. package/dist/components/InStoreFiltersMenu/index.js +1 -1
  118. package/dist/components/InStoreFiltersMenu/index.js.map +1 -1
  119. package/dist/components/InStoreFiltersMenu/styles.module.css +9 -9
  120. package/dist/components/Input/Input.d.ts +22 -22
  121. package/dist/components/Input/Input.js +48 -48
  122. package/dist/components/Input/Input.js.map +1 -1
  123. package/dist/components/Input/index.d.ts +1 -1
  124. package/dist/components/Input/index.js +1 -1
  125. package/dist/components/Input/index.js.map +1 -1
  126. package/dist/components/Input/styles.module.css +2 -2
  127. package/dist/components/LastReceivedDateFilter/LastReceivedDate.d.ts +9 -9
  128. package/dist/components/LastReceivedDateFilter/LastReceivedDate.js +87 -87
  129. package/dist/components/LastReceivedDateFilter/LastReceivedDate.js.map +1 -1
  130. package/dist/components/LastReceivedDateFilter/styles.module.css +40 -40
  131. package/dist/components/LastReceivedDateFilter/utils.d.ts +3 -3
  132. package/dist/components/LastReceivedDateFilter/utils.js +42 -42
  133. package/dist/components/LastReceivedDateFilter/utils.js.map +1 -1
  134. package/dist/components/ProductLabel/ProductLabel.d.ts +11 -11
  135. package/dist/components/ProductLabel/ProductLabel.js +10 -10
  136. package/dist/components/ProductLabel/ProductLabel.js.map +1 -1
  137. package/dist/components/ProductLabel/index.d.ts +1 -1
  138. package/dist/components/ProductLabel/index.js +1 -1
  139. package/dist/components/ProductLabel/index.js.map +1 -1
  140. package/dist/components/ProductLabel/styles.module.css +41 -41
  141. package/dist/components/ProductLabel/utils.d.ts +8 -8
  142. package/dist/components/ProductLabel/utils.js +8 -8
  143. package/dist/components/ProductLabel/utils.js.map +1 -1
  144. package/dist/components/RadioFilter/Radio/Radio.d.ts +10 -10
  145. package/dist/components/RadioFilter/Radio/Radio.js +6 -6
  146. package/dist/components/RadioFilter/Radio/Radio.js.map +1 -1
  147. package/dist/components/RadioFilter/Radio/styles.module.css +144 -144
  148. package/dist/components/RadioFilter/RadioFilter.d.ts +9 -9
  149. package/dist/components/RadioFilter/RadioFilter.js +44 -44
  150. package/dist/components/RadioFilter/RadioFilter.js.map +1 -1
  151. package/dist/components/RadioFilter/styles.module.css +22 -22
  152. package/dist/components/RadioFilter/utils.d.ts +1 -1
  153. package/dist/components/RadioFilter/utils.js +7 -7
  154. package/dist/components/RadioFilter/utils.js.map +1 -1
  155. package/dist/components/ReactDatePicker/ReactDatePicker.d.ts +11 -11
  156. package/dist/components/ReactDatePicker/ReactDatePicker.js +15 -15
  157. package/dist/components/ReactDatePicker/ReactDatePicker.js.map +1 -1
  158. package/dist/components/ReactDatePicker/index.d.ts +1 -1
  159. package/dist/components/ReactDatePicker/index.js +1 -1
  160. package/dist/components/ReactDatePicker/index.js.map +1 -1
  161. package/dist/components/ReactDatePicker/styles.module.css +2 -2
  162. package/dist/components/RenderIfVisible/RenderIfVisible.d.ts +12 -12
  163. package/dist/components/RenderIfVisible/RenderIfVisible.js +58 -58
  164. package/dist/components/RenderIfVisible/RenderIfVisible.js.map +1 -1
  165. package/dist/components/RenderIfVisible/index.d.ts +1 -1
  166. package/dist/components/RenderIfVisible/index.js +1 -1
  167. package/dist/components/RenderIfVisible/index.js.map +1 -1
  168. package/dist/components/ScrollToTop/ScrollToTop.d.ts +6 -6
  169. package/dist/components/ScrollToTop/ScrollToTop.js +27 -27
  170. package/dist/components/ScrollToTop/ScrollToTop.js.map +1 -1
  171. package/dist/components/ScrollToTop/styles.module.css +18 -18
  172. package/dist/components/SelectCard/SelectCard.d.ts +5 -5
  173. package/dist/components/SelectCard/SelectCard.js +6 -6
  174. package/dist/components/SelectCard/SelectCard.js.map +1 -1
  175. package/dist/components/SelectCard/index.d.ts +1 -1
  176. package/dist/components/SelectCard/index.js +1 -1
  177. package/dist/components/SelectCard/index.js.map +1 -1
  178. package/dist/components/SelectCard/styles.module.css +20 -20
  179. package/dist/components/SingleFilter/SingleFilter.d.ts +11 -11
  180. package/dist/components/SingleFilter/SingleFilter.js +89 -89
  181. package/dist/components/SingleFilter/SingleFilter.js.map +1 -1
  182. package/dist/components/SingleFilter/styles.module.css +23 -23
  183. package/dist/components/SingleFilter/utils.d.ts +3 -3
  184. package/dist/components/SingleFilter/utils.js +41 -41
  185. package/dist/components/SingleFilter/utils.js.map +1 -1
  186. package/dist/components/SliderFilter/SliderFilter.d.ts +20 -20
  187. package/dist/components/SliderFilter/SliderFilter.js +45 -45
  188. package/dist/components/SliderFilter/SliderFilter.js.map +1 -1
  189. package/dist/components/SliderFilter/index.d.ts +1 -1
  190. package/dist/components/SliderFilter/index.js +1 -1
  191. package/dist/components/SliderFilter/index.js.map +1 -1
  192. package/dist/components/SliderFilter/styles.module.css +15 -15
  193. package/dist/components/Tooltip/Tooltip.d.ts +8 -8
  194. package/dist/components/Tooltip/Tooltip.js +8 -8
  195. package/dist/components/Tooltip/Tooltip.js.map +1 -1
  196. package/dist/components/Tooltip/styles.module.css +33 -33
  197. package/dist/components/common.d.ts +23 -23
  198. package/dist/components/common.js +30 -30
  199. package/dist/components/common.js.map +1 -1
  200. package/dist/components/productGrid/ProductGrid.d.ts +11 -11
  201. package/dist/components/productGrid/ProductGrid.js +32 -32
  202. package/dist/components/productGrid/ProductGrid.js.map +1 -1
  203. package/dist/components/productGrid/index.d.ts +1 -1
  204. package/dist/components/productGrid/index.js +1 -1
  205. package/dist/components/productGrid/index.js.map +1 -1
  206. package/dist/components/productGrid/styles.module.css +25 -25
  207. package/dist/icons/BackOfficeFiltersIcon.d.ts +2 -2
  208. package/dist/icons/BackOfficeFiltersIcon.js +6 -6
  209. package/dist/icons/BackOfficeFiltersIcon.js.map +1 -1
  210. package/dist/icons/BannersIcon.d.ts +2 -2
  211. package/dist/icons/BannersIcon.js +6 -6
  212. package/dist/icons/BannersIcon.js.map +1 -1
  213. package/dist/icons/GeneralIcon.d.ts +2 -2
  214. package/dist/icons/GeneralIcon.js +6 -6
  215. package/dist/icons/GeneralIcon.js.map +1 -1
  216. package/dist/icons/HelpIcon.d.ts +7 -7
  217. package/dist/icons/HelpIcon.js +4 -4
  218. package/dist/icons/HelpIcon.js.map +1 -1
  219. package/dist/icons/InStoreFiltersIcon.d.ts +2 -2
  220. package/dist/icons/InStoreFiltersIcon.js +6 -6
  221. package/dist/icons/InStoreFiltersIcon.js.map +1 -1
  222. package/dist/icons/PromoteIcon.d.ts +2 -2
  223. package/dist/icons/PromoteIcon.js +6 -6
  224. package/dist/icons/PromoteIcon.js.map +1 -1
  225. package/dist/icons/RemoveIcon.d.ts +2 -2
  226. package/dist/icons/RemoveIcon.js +6 -6
  227. package/dist/icons/RemoveIcon.js.map +1 -1
  228. package/dist/icons/RestoreIcon.d.ts +2 -2
  229. package/dist/icons/RestoreIcon.js +6 -6
  230. package/dist/icons/RestoreIcon.js.map +1 -1
  231. package/dist/icons/styles.module.css +60 -60
  232. package/dist/index.css +13 -0
  233. package/dist/index.d.ts +41 -41
  234. package/dist/index.js +32 -32
  235. package/dist/index.js.map +1 -1
  236. package/dist/main.d.ts +1 -1
  237. package/dist/main.js +5 -5
  238. package/dist/main.js.map +1 -1
  239. package/dist/services/API.d.ts +21 -21
  240. package/dist/services/API.js +49 -49
  241. package/dist/services/API.js.map +1 -1
  242. package/dist/services/autocomplete.d.ts +4 -4
  243. package/dist/services/autocomplete.js +25 -25
  244. package/dist/services/autocomplete.js.map +1 -1
  245. package/dist/services/getFormatProducts.d.ts +13 -13
  246. package/dist/services/getFormatProducts.js +43 -43
  247. package/dist/services/getFormatProducts.js.map +1 -1
  248. package/dist/services/landingPage.d.ts +28 -28
  249. package/dist/services/landingPage.js +86 -86
  250. package/dist/services/landingPage.js.map +1 -1
  251. package/dist/services/products.d.ts +9 -9
  252. package/dist/services/products.js +30 -30
  253. package/dist/services/products.js.map +1 -1
  254. package/dist/services/search.d.ts +13 -13
  255. package/dist/services/search.js +113 -113
  256. package/dist/services/search.js.map +1 -1
  257. package/dist/services/smartCollections.d.ts +5 -5
  258. package/dist/services/smartCollections.js +44 -44
  259. package/dist/services/smartCollections.js.map +1 -1
  260. package/dist/utils/customTagsFilters.d.ts +4 -4
  261. package/dist/utils/customTagsFilters.js +9 -9
  262. package/dist/utils/customTagsFilters.js.map +1 -1
  263. package/dist/utils/getCacheSettings.d.ts +16 -16
  264. package/dist/utils/getCacheSettings.js +25 -25
  265. package/dist/utils/getCacheSettings.js.map +1 -1
  266. package/dist/utils/getInternalURL.d.ts +1 -1
  267. package/dist/utils/getInternalURL.js +7 -7
  268. package/dist/utils/getInternalURL.js.map +1 -1
  269. package/dist/utils/getLSVectorSearch.d.ts +4 -4
  270. package/dist/utils/getLSVectorSearch.js +8 -8
  271. package/dist/utils/getLSVectorSearch.js.map +1 -1
  272. package/dist/utils/useDragToSelect.d.ts +13 -13
  273. package/dist/utils/useDragToSelect.js +172 -172
  274. package/dist/utils/useDragToSelect.js.map +1 -1
  275. package/dist/utils/useProductsPerRow.d.ts +3 -3
  276. package/dist/utils/useProductsPerRow.js +18 -18
  277. package/dist/utils/useProductsPerRow.js.map +1 -1
  278. package/package.json +64 -64
@@ -1,606 +1,606 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
- import { jsx as _jsx } from "react/jsx-runtime";
22
- import { useEffect, useReducer, useState } from "react";
23
- import { FastState, FastStateFunctions } from "./context";
24
- import { ThemeProvider } from "react-jss";
25
- import { fastStateReducer } from "./reducer";
26
- import { newObject } from "../common";
27
- import { FullTextSearch } from "../../services/search";
28
- import { SmartCollections } from "../../services/smartCollections";
29
- import { Autocomplete } from "../../services/autocomplete";
30
- const mainTheme = {
31
- primaryColor: "#1976d2",
32
- lighterPrimary: "rgba(25,118,210,0.71)",
33
- successGreen: "#4BB543",
34
- errorRed: "#ff0033",
35
- loadingYellow: "#f3b706",
36
- };
37
- const FastSimonApi = (_a) => {
38
- var _b;
39
- var { storeID, uuid, siteKey, children, defaultSort, promoTiles = false, theme, withProductAttributes = false, isInfiniteScroll = false, getTitle, useFilters, noReport = false, customTitleChange, isEnterpriseMerchandising = false, subscription = 0, marketContext = null } = _a, props = __rest(_a, ["storeID", "uuid", "siteKey", "children", "defaultSort", "promoTiles", "theme", "withProductAttributes", "isInfiniteScroll", "getTitle", "useFilters", "noReport", "customTitleChange", "isEnterpriseMerchandising", "subscription", "marketContext"]);
40
- const [state, dispatch] = useReducer === null || useReducer === void 0 ? void 0 : useReducer(fastStateReducer, {
41
- isReady: false,
42
- type: (_b = props.type) !== null && _b !== void 0 ? _b : 'SPA',
43
- page: 1,
44
- query: '',
45
- sortBy: defaultSort,
46
- isLoading: {
47
- products: false,
48
- filters: false,
49
- },
50
- collectionID: props.collectionID,
51
- narrow: undefined,
52
- results: undefined,
53
- recommendations: {},
54
- singleProducts: {},
55
- searchWithinSearch: "",
56
- segments: undefined,
57
- flag: [],
58
- custom_sort_settings: undefined,
59
- isAutocomplete: false
60
- });
61
- const [categories, setCategories] = useState([]);
62
- const [analyticsFetched, setAnalyticsFetched] = useState(false);
63
- const [lastAnalyticsQuery, setLastAnalyticsQuery] = useState('');
64
- const [lastAnalyticsCollection, setLastAnalyticsCollection] = useState('');
65
- const [lastAnalyticsMode, setLastAnalyticsMode] = useState('');
66
- // Only enable analytics for enterprise merchants or subscription level 5
67
- const isAnalyticsEnabled = isEnterpriseMerchandising || subscription === 5;
68
- const { results, isLoading, query, sortBy, type, collectionID, page, narrow, recommendations, singleProducts, isReady, autocomplete, segments, isAutocomplete } = state;
69
- function setResults(results) {
70
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setResults', payload: results });
71
- }
72
- function mergeResults(results, infiniteScroll) {
73
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'mergeResults', payload: { results, infiniteScroll } });
74
- }
75
- function mergeFacetsWithResults(facets) {
76
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'mergeFacetsWithResults', payload: facets });
77
- }
78
- function mergeResultsKeepProduct(results) {
79
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'mergeResultsKeepProduct', payload: { results } });
80
- }
81
- function setIsLoading(isLoading) {
82
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setIsLoading', payload: isLoading });
83
- }
84
- function setIsAutocomplete(isAutocomplete) {
85
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setIsAutocomplete', payload: isAutocomplete });
86
- }
87
- function setQuery(query, isAutocomplete) {
88
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setQuery', payload: query });
89
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setIsAutocomplete', payload: isAutocomplete ? isAutocomplete : false });
90
- // Create the object with the computed property
91
- let fetchParams = {
92
- siteKey: siteKey,
93
- uuid: uuid,
94
- storeID: storeID,
95
- term: query,
96
- sortBy: defaultSort,
97
- segments: state.segments,
98
- withProductAttributes: withProductAttributes,
99
- custom_sort_settings: state.custom_sort_settings,
100
- disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
101
- disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
102
- disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
103
- disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
104
- disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
105
- disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
106
- };
107
- fetchResults(fetchParams, isInfiniteScroll, isAutocomplete ? isAutocomplete : false);
108
- }
109
- function setCustomSort(customSortSettings) {
110
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setCustomSort', payload: customSortSettings });
111
- // Create the object with the computed property
112
- let fetchParams = {
113
- siteKey: siteKey,
114
- uuid: uuid,
115
- storeID: storeID,
116
- term: state.query,
117
- narrowBy: state.narrow,
118
- sortBy: state.sortBy,
119
- categoryID: state.collectionID,
120
- segments: state.segments,
121
- withProductAttributes: state.withProductAttributes,
122
- searchWithinSearch: state.searchWithinSearch,
123
- custom_sort_settings: customSortSettings,
124
- disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
125
- disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
126
- disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
127
- disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
128
- disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
129
- disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
130
- };
131
- fetchResults(fetchParams, isInfiniteScroll);
132
- }
133
- function setFlag(flags) {
134
- const flagsToData = flags.map((f) => { return "disable_" + f; });
135
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setFlag', payload: flagsToData });
136
- // Create the object with the computed property
137
- let fetchParams = {
138
- siteKey: siteKey,
139
- uuid: uuid,
140
- storeID: storeID,
141
- term: state.query,
142
- narrowBy: state.narrow,
143
- sortBy: state.defaultSort,
144
- segments: state.segments,
145
- categoryID: state.collectionID,
146
- withProductAttributes: withProductAttributes,
147
- searchWithinSearch: state.searchWithinSearch,
148
- custom_sort_settings: state.custom_sort_settings,
149
- };
150
- if (flags.length > 0) {
151
- flags.forEach((f) => {
152
- let flagProp = "disable_" + f;
153
- // Add the dynamic key to the object
154
- // @ts-ignore
155
- fetchParams[flagProp] = true;
156
- });
157
- }
158
- fetchResults(fetchParams, isInfiniteScroll, state.isAutocomplete);
159
- }
160
- function setSortBy(sortBy) {
161
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setSortBy', payload: sortBy });
162
- // Create the object with the computed property
163
- let fetchParams = {
164
- siteKey: siteKey,
165
- uuid: uuid,
166
- storeID: storeID,
167
- term: state.query,
168
- narrowBy: state.narrow,
169
- sortBy: sortBy,
170
- categoryID: state.collectionID,
171
- segments: state.segments,
172
- withProductAttributes: withProductAttributes,
173
- searchWithinSearch: state.searchWithinSearch,
174
- custom_sort_settings: state.custom_sort_settings,
175
- disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
176
- disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
177
- disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
178
- disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
179
- disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
180
- disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
181
- };
182
- fetchResults(fetchParams, isInfiniteScroll);
183
- }
184
- function setSegments(segments) {
185
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setSegments', payload: segments });
186
- let fetchParams = {
187
- withProductAttributes: withProductAttributes,
188
- siteKey: siteKey,
189
- uuid: uuid,
190
- storeID: storeID,
191
- term: state.query,
192
- narrowBy: state.narrow,
193
- sortBy: state.sortBy,
194
- categoryID: state.collectionID,
195
- segments: segments,
196
- searchWithinSearch: state.searchWithinSearch,
197
- custom_sort_settings: state.custom_sort_settings,
198
- disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
199
- disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
200
- disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
201
- disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
202
- disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
203
- disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
204
- };
205
- fetchResults(fetchParams, isInfiniteScroll, state.isAutocomplete);
206
- }
207
- function setType(type) {
208
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setType', payload: type });
209
- }
210
- function setCollectionID(collectionID) {
211
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setCollectionID', payload: collectionID });
212
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setIsAutocomplete', payload: false });
213
- // Create the object with the computed property
214
- let fetchParams = {
215
- siteKey: siteKey,
216
- uuid: uuid,
217
- storeID: storeID,
218
- categoryID: collectionID,
219
- sortBy: defaultSort,
220
- segments: state.segments,
221
- custom_sort_settings: state.custom_sort_settings,
222
- disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
223
- disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
224
- disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
225
- disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
226
- disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
227
- disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
228
- };
229
- fetchResults(fetchParams, isInfiniteScroll);
230
- }
231
- function setPage(page) {
232
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setPage', payload: page });
233
- let fetchParams = {
234
- withProductAttributes: withProductAttributes,
235
- siteKey: siteKey,
236
- uuid: uuid,
237
- storeID: storeID,
238
- term: state.query,
239
- narrowBy: state.narrow,
240
- sortBy: state.sortBy,
241
- categoryID: state.collectionID,
242
- page: page,
243
- segments: state.segments,
244
- searchWithinSearch: state.searchWithinSearch,
245
- custom_sort_settings: state.custom_sort_settings,
246
- disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
247
- disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
248
- disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
249
- disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
250
- disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
251
- disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
252
- };
253
- fetchResults(fetchParams, isInfiniteScroll);
254
- }
255
- function setNarrow(narrow) {
256
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setNarrow', payload: narrow });
257
- let fetchParams = {
258
- withProductAttributes: withProductAttributes,
259
- siteKey: siteKey,
260
- uuid: uuid,
261
- storeID: storeID,
262
- term: state.query,
263
- narrowBy: narrow,
264
- sortBy: state.sortBy,
265
- categoryID: state.collectionID,
266
- segments: state.segments,
267
- searchWithinSearch: state.searchWithinSearch,
268
- custom_sort_settings: state.custom_sort_settings,
269
- disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
270
- disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
271
- disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
272
- disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
273
- disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
274
- disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
275
- };
276
- fetchResults(fetchParams, isInfiniteScroll);
277
- }
278
- function setState(_a) {
279
- var _b;
280
- var newState = __rest(_a, []);
281
- console.log("state", state);
282
- console.log("setState", newState);
283
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setState', payload: newState });
284
- fetchResults({
285
- siteKey: siteKey,
286
- uuid: uuid,
287
- storeID: storeID,
288
- term: newState.query,
289
- narrowBy: newState.narrow ? newState.narrow : undefined,
290
- sortBy: (_b = newState.sortBy) !== null && _b !== void 0 ? _b : defaultSort,
291
- categoryID: newState.collectionID,
292
- page: newState.page,
293
- segments: newState.segments,
294
- }, Boolean(!results && isInfiniteScroll && newState.page && newState.page > 1));
295
- }
296
- function setSingleProducts(products) {
297
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: "setSingleProducts", payload: products });
298
- }
299
- function setReady(isReady) {
300
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: "setReady", payload: isReady });
301
- }
302
- function setSearchWithinSearch(searchWithinSearch) {
303
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: "setSearchWithinSearch", payload: searchWithinSearch });
304
- let fetchParams = {
305
- withProductAttributes: withProductAttributes,
306
- siteKey: siteKey,
307
- uuid: uuid,
308
- storeID: storeID,
309
- term: query,
310
- narrowBy: state.narrow,
311
- sortBy: state.sortBy,
312
- categoryID: state.collectionID,
313
- segments: state.segments,
314
- searchWithinSearch: searchWithinSearch,
315
- custom_sort_settings: state.custom_sort_settings,
316
- disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
317
- disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
318
- disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
319
- disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
320
- disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
321
- disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
322
- };
323
- fetchResults(fetchParams, isInfiniteScroll);
324
- }
325
- function fetchResults(props, isInfiniteScroll, autocomplete = false) {
326
- // on first request check if we need to fetch more then 1 product
327
- if (props.term && !autocomplete) {
328
- onSearch(newObject(Object.assign(Object.assign({}, props), { page: props.page || 1, infiniteScrollPage: isInfiniteScroll })), isInfiniteScroll);
329
- }
330
- else if (props.term && autocomplete) {
331
- onAutocompleteSearch(newObject(Object.assign({}, props)));
332
- }
333
- else if (props.categoryID) {
334
- onCollection(newObject(Object.assign(Object.assign({}, props), { page: props.page || 1, infiniteScrollPage: isInfiniteScroll })), isInfiniteScroll);
335
- }
336
- return;
337
- }
338
- useEffect(() => {
339
- function handleSetQueryEvent(event) {
340
- setQuery(event.detail);
341
- }
342
- function handleSetFlagEvent(event) {
343
- setFlag(event.details);
344
- }
345
- function handleSetCollectionEvent(event) {
346
- setCollectionID(event.detail);
347
- }
348
- function handleSetCollectionURLEvent(event) {
349
- getAllCategories().then(r => {
350
- var _a;
351
- const id = (_a = r.find(c => c.u === event.detail)) === null || _a === void 0 ? void 0 : _a.id;
352
- if (id) {
353
- setCollectionID(id);
354
- return;
355
- }
356
- window.location.href = event.detail;
357
- });
358
- }
359
- function handleSetPageEvent(event) {
360
- setPage(event.detail);
361
- }
362
- function handleSetSortEvent(event) {
363
- setSortBy(event.detail);
364
- }
365
- function handleSetNarrowEvent(event) {
366
- setNarrow(event.detail);
367
- }
368
- function handleSetSegmentsEvent(event) {
369
- setSegments(event.detail);
370
- }
371
- function handleSetIsAutocomplete(event) {
372
- setIsAutocomplete(event.detail);
373
- }
374
- window.addEventListener('fast-simon-update-query', handleSetQueryEvent);
375
- window.addEventListener('fast-simon-update-collection', handleSetCollectionEvent);
376
- window.addEventListener('fast-simon-update-collection-url', handleSetCollectionURLEvent);
377
- window.addEventListener('fast-simon-update-page', handleSetPageEvent);
378
- window.addEventListener('fast-simon-update-sort', handleSetSortEvent);
379
- window.addEventListener('fast-simon-update-narrow', handleSetNarrowEvent);
380
- window.addEventListener('fast-simon-update-segments', handleSetSegmentsEvent);
381
- window.addEventListener('fast-simon-update-flag', handleSetFlagEvent);
382
- window.addEventListener('fast-simon-update-is-autocomplete', handleSetIsAutocomplete);
383
- return () => {
384
- window.removeEventListener('fast-simon-update-query', handleSetQueryEvent);
385
- window.removeEventListener('fast-simon-update-collection', handleSetCollectionEvent);
386
- window.removeEventListener('fast-simon-update-collection-url', handleSetCollectionURLEvent);
387
- window.removeEventListener('fast-simon-update-page', handleSetPageEvent);
388
- window.removeEventListener('fast-simon-update-sort', handleSetSortEvent);
389
- window.removeEventListener('fast-simon-update-narrow', handleSetNarrowEvent);
390
- window.removeEventListener('fast-simon-update-segments', handleSetSegmentsEvent);
391
- window.removeEventListener('fast-simon-update-flag', handleSetFlagEvent);
392
- window.removeEventListener('fast-simon-update-is-autocomplete', handleSetIsAutocomplete);
393
- };
394
- }, []);
395
- const onSearch = (props, isInfiniteScroll) => {
396
- setIsLoading({ products: true, filters: true });
397
- // Pass with_product_analytics only on first request for this query OR when switching from collection to search
398
- // AND only if merchant is enterprise or subscription level 5
399
- const currentQuery = props.term || '';
400
- const shouldFetchAnalytics = isAnalyticsEnabled && (currentQuery !== lastAnalyticsQuery || lastAnalyticsMode !== 'search');
401
- FullTextSearch.getReasoningFullTextSearch(Object.assign(Object.assign({}, props), { withAttributes: promoTiles || withProductAttributes, with_product_analytics: shouldFetchAnalytics, market_context: marketContext })).then((response) => __awaiter(void 0, void 0, void 0, function* () {
402
- var _a;
403
- // Mark analytics as fetched only if response contains analytics data with badges
404
- if (shouldFetchAnalytics && ((_a = response.analytics) === null || _a === void 0 ? void 0 : _a.badges)) {
405
- setAnalyticsFetched(true);
406
- setLastAnalyticsQuery(currentQuery);
407
- setLastAnalyticsMode('search');
408
- }
409
- // Preserve existing analytics if new response doesn't have it
410
- const existingAnalytics = results === null || results === void 0 ? void 0 : results.analytics;
411
- response = getFormatedData(response, existingAnalytics);
412
- // Handle turbolink responses - skip additional API calls to prevent errors
413
- if (response.turbolink && response.totalResults === 0) {
414
- mergeResults(response, isInfiniteScroll);
415
- if (!customTitleChange) {
416
- document.title = `Search Result for ${query}`;
417
- }
418
- else {
419
- customTitleChange(results);
420
- }
421
- setIsLoading({ filters: false, products: false });
422
- return;
423
- }
424
- const listIdRequestProps = Object.assign({}, props);
425
- listIdRequestProps.searchWithinSearch = undefined;
426
- listIdRequestProps.productsPerPage = 1000000;
427
- listIdRequestProps.page = 1;
428
- listIdRequestProps.market_context = marketContext;
429
- let listIdRes = yield FullTextSearch.getReasoningFullTextSearchProductsIds(listIdRequestProps).then((response) => {
430
- return response;
431
- });
432
- response.id_list = listIdRes.id_list;
433
- const facetsRequestProps = Object.assign({}, props);
434
- facetsRequestProps.facetRequired = 2;
435
- facetsRequestProps.searchWithinSearch = props.searchWithinSearch;
436
- facetsRequestProps.productsPerPage = props.productsPerPage;
437
- facetsRequestProps.page = props.page;
438
- facetsRequestProps.market_context = marketContext;
439
- let facetsRes = yield FullTextSearch.getReasoningFullTextSearch(facetsRequestProps).then((response) => {
440
- return response;
441
- });
442
- response.facets = facetsRes.facets;
443
- mergeResults(response, isInfiniteScroll);
444
- if (!customTitleChange) {
445
- document.title = `Search Result for ${query}`;
446
- }
447
- else {
448
- customTitleChange(results);
449
- }
450
- if (!response) {
451
- setIsLoading({
452
- filters: true, products: false
453
- });
454
- }
455
- else {
456
- setIsLoading({
457
- filters: false, products: false
458
- });
459
- }
460
- }));
461
- };
462
- const onAutocompleteSearch = (props) => {
463
- setIsLoading({ products: true, filters: true });
464
- Autocomplete.getAutocompleteReasoning(Object.assign(Object.assign({}, props), { withAttributes: promoTiles || withProductAttributes, market_context: marketContext })).then((response) => __awaiter(void 0, void 0, void 0, function* () {
465
- response = getFormatedData(response);
466
- mergeResults(response, false);
467
- if (!customTitleChange) {
468
- document.title = `Autocomplete Result for ${query}`;
469
- }
470
- else {
471
- customTitleChange(results);
472
- }
473
- if (!response) {
474
- setIsLoading({
475
- filters: true, products: false
476
- });
477
- }
478
- else {
479
- setIsLoading({
480
- filters: false, products: false
481
- });
482
- }
483
- }));
484
- };
485
- const onCollection = (props, isInfiniteScroll) => {
486
- setIsLoading({ products: true, filters: true });
487
- // Pass with_product_analytics only on first request for this collection OR when switching from search to collection
488
- // AND only if merchant is enterprise or subscription level 5
489
- const currentCollection = props.categoryID || '';
490
- const shouldFetchAnalytics = isAnalyticsEnabled && (currentCollection !== lastAnalyticsCollection || lastAnalyticsMode !== 'collection');
491
- SmartCollections.getSmartCollections(Object.assign(Object.assign({}, props), { withAttributes: promoTiles || withProductAttributes, with_product_analytics: shouldFetchAnalytics, market_context: marketContext }))
492
- .then((response) => __awaiter(void 0, void 0, void 0, function* () {
493
- var _a;
494
- // Mark analytics as fetched only if response contains analytics data with badges
495
- if (shouldFetchAnalytics && ((_a = response.analytics) === null || _a === void 0 ? void 0 : _a.badges)) {
496
- setAnalyticsFetched(true);
497
- setLastAnalyticsCollection(currentCollection);
498
- setLastAnalyticsMode('collection');
499
- }
500
- // Preserve existing analytics if new response doesn't have it
501
- const existingAnalytics = results === null || results === void 0 ? void 0 : results.analytics;
502
- response = getFormatedData(response, existingAnalytics);
503
- const listIdRequestProps = Object.assign({}, props);
504
- listIdRequestProps.searchWithinSearch = undefined;
505
- listIdRequestProps.productsPerPage = 1000000;
506
- listIdRequestProps.page = 1;
507
- listIdRequestProps.market_context = marketContext;
508
- let listIdRes = yield SmartCollections.getSmartCollectionsProductsIds(listIdRequestProps).then((response) => {
509
- return response;
510
- });
511
- response.id_list = listIdRes.id_list;
512
- const facetsRequestProps = Object.assign({}, props);
513
- facetsRequestProps.facetRequired = 2;
514
- facetsRequestProps.searchWithinSearch = props.searchWithinSearch;
515
- facetsRequestProps.productsPerPage = props.productsPerPage;
516
- facetsRequestProps.page = props.page;
517
- facetsRequestProps.market_context = marketContext;
518
- let facetsRes = yield SmartCollections.getSmartCollections(facetsRequestProps).then((response) => {
519
- return response;
520
- });
521
- response.facets = facetsRes.facets;
522
- mergeResults(response, isInfiniteScroll);
523
- if (!response) {
524
- setIsLoading({
525
- filters: true, products: false
526
- });
527
- }
528
- else {
529
- setIsLoading({
530
- filters: false, products: false
531
- });
532
- }
533
- getAllCategories().then(r => {
534
- var _a, _b;
535
- if (!customTitleChange) {
536
- document.title = (_b = (_a = r.find(c => c.id === props.categoryID)) === null || _a === void 0 ? void 0 : _a.l) !== null && _b !== void 0 ? _b : "Collection";
537
- }
538
- else {
539
- customTitleChange(results);
540
- }
541
- });
542
- })).then(() => {
543
- });
544
- };
545
- const getAllCategories = () => __awaiter(void 0, void 0, void 0, function* () {
546
- if (categories.length > 0) {
547
- return new Promise(resolve => resolve(categories));
548
- }
549
- const data = categories || [];
550
- setCategories(data);
551
- return data;
552
- });
553
- const getFormatedData = (response, existingAnalytics) => {
554
- const results = response;
555
- results.products = response.items;
556
- delete results.items;
557
- results.totalResults = response.total_results;
558
- delete results.total_results;
559
- if (response.sort_by) {
560
- results.sortBy = response.sort_by;
561
- delete results.sort_by;
562
- }
563
- if (response.pop_products_no_results) {
564
- results.isNoResults = true;
565
- }
566
- if (response.total_p) {
567
- results.pageCount = response.total_p;
568
- delete results.total_p;
569
- }
570
- if (response.ancestor_categories) {
571
- results.ancestors = response.ancestor_categories;
572
- delete results.ancestor_categories;
573
- }
574
- if (response.avoid_tag_prefixes) {
575
- results.avoidPrefixList = response.avoid_tag_prefixes.split(",");
576
- }
577
- results.page = response.p || 1;
578
- delete results.p;
579
- // Preserve analytics field if present (contains winners/overexposed data)
580
- // If response has new analytics, use it; otherwise keep existing analytics
581
- if (response.analytics) {
582
- results.analytics = response.analytics;
583
- }
584
- else if (existingAnalytics) {
585
- results.analytics = existingAnalytics;
586
- }
587
- return results;
588
- };
589
- // @ts-ignore
590
- return (_jsx(FastStateFunctions.Provider, Object.assign({ value: {
591
- setQuery,
592
- setSort: setSortBy,
593
- setNarrow,
594
- setPage,
595
- getAllCategories,
596
- setCollection: setCollectionID,
597
- setState,
598
- setSearchWithinSearch,
599
- setSegments,
600
- setFlag,
601
- setCustomSort,
602
- setIsAutocomplete
603
- } }, { children: _jsx(FastState.Provider, Object.assign({ value: { narrow, results, page, query, sortBy, type, collectionID, isLoading, recommendations, singleProducts, isReady, autocomplete, isAutocomplete } }, { children: _jsx(ThemeProvider, Object.assign({ theme: Object.assign(Object.assign({}, mainTheme), theme) }, { children: children })) })) })));
604
- };
605
- export default FastSimonApi;
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ import { useEffect, useReducer, useState } from "react";
23
+ import { FastState, FastStateFunctions } from "./context";
24
+ import { ThemeProvider } from "react-jss";
25
+ import { fastStateReducer } from "./reducer";
26
+ import { newObject } from "../common";
27
+ import { FullTextSearch } from "../../services/search";
28
+ import { SmartCollections } from "../../services/smartCollections";
29
+ import { Autocomplete } from "../../services/autocomplete";
30
+ const mainTheme = {
31
+ primaryColor: "#1976d2",
32
+ lighterPrimary: "rgba(25,118,210,0.71)",
33
+ successGreen: "#4BB543",
34
+ errorRed: "#ff0033",
35
+ loadingYellow: "#f3b706",
36
+ };
37
+ const FastSimonApi = (_a) => {
38
+ var _b;
39
+ var { storeID, uuid, siteKey, children, defaultSort, promoTiles = false, theme, withProductAttributes = false, isInfiniteScroll = false, getTitle, useFilters, noReport = false, customTitleChange, isEnterpriseMerchandising = false, subscription = 0, marketContext = null } = _a, props = __rest(_a, ["storeID", "uuid", "siteKey", "children", "defaultSort", "promoTiles", "theme", "withProductAttributes", "isInfiniteScroll", "getTitle", "useFilters", "noReport", "customTitleChange", "isEnterpriseMerchandising", "subscription", "marketContext"]);
40
+ const [state, dispatch] = useReducer === null || useReducer === void 0 ? void 0 : useReducer(fastStateReducer, {
41
+ isReady: false,
42
+ type: (_b = props.type) !== null && _b !== void 0 ? _b : 'SPA',
43
+ page: 1,
44
+ query: '',
45
+ sortBy: defaultSort,
46
+ isLoading: {
47
+ products: false,
48
+ filters: false,
49
+ },
50
+ collectionID: props.collectionID,
51
+ narrow: undefined,
52
+ results: undefined,
53
+ recommendations: {},
54
+ singleProducts: {},
55
+ searchWithinSearch: "",
56
+ segments: undefined,
57
+ flag: [],
58
+ custom_sort_settings: undefined,
59
+ isAutocomplete: false
60
+ });
61
+ const [categories, setCategories] = useState([]);
62
+ const [analyticsFetched, setAnalyticsFetched] = useState(false);
63
+ const [lastAnalyticsQuery, setLastAnalyticsQuery] = useState('');
64
+ const [lastAnalyticsCollection, setLastAnalyticsCollection] = useState('');
65
+ const [lastAnalyticsMode, setLastAnalyticsMode] = useState('');
66
+ // Only enable analytics for enterprise merchants or subscription level 5
67
+ const isAnalyticsEnabled = isEnterpriseMerchandising || subscription === 5;
68
+ const { results, isLoading, query, sortBy, type, collectionID, page, narrow, recommendations, singleProducts, isReady, autocomplete, segments, isAutocomplete } = state;
69
+ function setResults(results) {
70
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setResults', payload: results });
71
+ }
72
+ function mergeResults(results, infiniteScroll) {
73
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'mergeResults', payload: { results, infiniteScroll } });
74
+ }
75
+ function mergeFacetsWithResults(facets) {
76
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'mergeFacetsWithResults', payload: facets });
77
+ }
78
+ function mergeResultsKeepProduct(results) {
79
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'mergeResultsKeepProduct', payload: { results } });
80
+ }
81
+ function setIsLoading(isLoading) {
82
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setIsLoading', payload: isLoading });
83
+ }
84
+ function setIsAutocomplete(isAutocomplete) {
85
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setIsAutocomplete', payload: isAutocomplete });
86
+ }
87
+ function setQuery(query, isAutocomplete) {
88
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setQuery', payload: query });
89
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setIsAutocomplete', payload: isAutocomplete ? isAutocomplete : false });
90
+ // Create the object with the computed property
91
+ let fetchParams = {
92
+ siteKey: siteKey,
93
+ uuid: uuid,
94
+ storeID: storeID,
95
+ term: query,
96
+ sortBy: defaultSort,
97
+ segments: state.segments,
98
+ withProductAttributes: withProductAttributes,
99
+ custom_sort_settings: state.custom_sort_settings,
100
+ disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
101
+ disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
102
+ disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
103
+ disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
104
+ disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
105
+ disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
106
+ };
107
+ fetchResults(fetchParams, isInfiniteScroll, isAutocomplete ? isAutocomplete : false);
108
+ }
109
+ function setCustomSort(customSortSettings) {
110
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setCustomSort', payload: customSortSettings });
111
+ // Create the object with the computed property
112
+ let fetchParams = {
113
+ siteKey: siteKey,
114
+ uuid: uuid,
115
+ storeID: storeID,
116
+ term: state.query,
117
+ narrowBy: state.narrow,
118
+ sortBy: state.sortBy,
119
+ categoryID: state.collectionID,
120
+ segments: state.segments,
121
+ withProductAttributes: state.withProductAttributes,
122
+ searchWithinSearch: state.searchWithinSearch,
123
+ custom_sort_settings: customSortSettings,
124
+ disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
125
+ disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
126
+ disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
127
+ disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
128
+ disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
129
+ disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
130
+ };
131
+ fetchResults(fetchParams, isInfiniteScroll);
132
+ }
133
+ function setFlag(flags) {
134
+ const flagsToData = flags.map((f) => { return "disable_" + f; });
135
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setFlag', payload: flagsToData });
136
+ // Create the object with the computed property
137
+ let fetchParams = {
138
+ siteKey: siteKey,
139
+ uuid: uuid,
140
+ storeID: storeID,
141
+ term: state.query,
142
+ narrowBy: state.narrow,
143
+ sortBy: state.defaultSort,
144
+ segments: state.segments,
145
+ categoryID: state.collectionID,
146
+ withProductAttributes: withProductAttributes,
147
+ searchWithinSearch: state.searchWithinSearch,
148
+ custom_sort_settings: state.custom_sort_settings,
149
+ };
150
+ if (flags.length > 0) {
151
+ flags.forEach((f) => {
152
+ let flagProp = "disable_" + f;
153
+ // Add the dynamic key to the object
154
+ // @ts-ignore
155
+ fetchParams[flagProp] = true;
156
+ });
157
+ }
158
+ fetchResults(fetchParams, isInfiniteScroll, state.isAutocomplete);
159
+ }
160
+ function setSortBy(sortBy) {
161
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setSortBy', payload: sortBy });
162
+ // Create the object with the computed property
163
+ let fetchParams = {
164
+ siteKey: siteKey,
165
+ uuid: uuid,
166
+ storeID: storeID,
167
+ term: state.query,
168
+ narrowBy: state.narrow,
169
+ sortBy: sortBy,
170
+ categoryID: state.collectionID,
171
+ segments: state.segments,
172
+ withProductAttributes: withProductAttributes,
173
+ searchWithinSearch: state.searchWithinSearch,
174
+ custom_sort_settings: state.custom_sort_settings,
175
+ disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
176
+ disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
177
+ disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
178
+ disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
179
+ disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
180
+ disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
181
+ };
182
+ fetchResults(fetchParams, isInfiniteScroll);
183
+ }
184
+ function setSegments(segments) {
185
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setSegments', payload: segments });
186
+ let fetchParams = {
187
+ withProductAttributes: withProductAttributes,
188
+ siteKey: siteKey,
189
+ uuid: uuid,
190
+ storeID: storeID,
191
+ term: state.query,
192
+ narrowBy: state.narrow,
193
+ sortBy: state.sortBy,
194
+ categoryID: state.collectionID,
195
+ segments: segments,
196
+ searchWithinSearch: state.searchWithinSearch,
197
+ custom_sort_settings: state.custom_sort_settings,
198
+ disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
199
+ disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
200
+ disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
201
+ disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
202
+ disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
203
+ disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
204
+ };
205
+ fetchResults(fetchParams, isInfiniteScroll, state.isAutocomplete);
206
+ }
207
+ function setType(type) {
208
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setType', payload: type });
209
+ }
210
+ function setCollectionID(collectionID) {
211
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setCollectionID', payload: collectionID });
212
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setIsAutocomplete', payload: false });
213
+ // Create the object with the computed property
214
+ let fetchParams = {
215
+ siteKey: siteKey,
216
+ uuid: uuid,
217
+ storeID: storeID,
218
+ categoryID: collectionID,
219
+ sortBy: defaultSort,
220
+ segments: state.segments,
221
+ custom_sort_settings: state.custom_sort_settings,
222
+ disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
223
+ disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
224
+ disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
225
+ disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
226
+ disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
227
+ disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
228
+ };
229
+ fetchResults(fetchParams, isInfiniteScroll);
230
+ }
231
+ function setPage(page) {
232
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setPage', payload: page });
233
+ let fetchParams = {
234
+ withProductAttributes: withProductAttributes,
235
+ siteKey: siteKey,
236
+ uuid: uuid,
237
+ storeID: storeID,
238
+ term: state.query,
239
+ narrowBy: state.narrow,
240
+ sortBy: state.sortBy,
241
+ categoryID: state.collectionID,
242
+ page: page,
243
+ segments: state.segments,
244
+ searchWithinSearch: state.searchWithinSearch,
245
+ custom_sort_settings: state.custom_sort_settings,
246
+ disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
247
+ disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
248
+ disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
249
+ disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
250
+ disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
251
+ disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
252
+ };
253
+ fetchResults(fetchParams, isInfiniteScroll);
254
+ }
255
+ function setNarrow(narrow) {
256
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setNarrow', payload: narrow });
257
+ let fetchParams = {
258
+ withProductAttributes: withProductAttributes,
259
+ siteKey: siteKey,
260
+ uuid: uuid,
261
+ storeID: storeID,
262
+ term: state.query,
263
+ narrowBy: narrow,
264
+ sortBy: state.sortBy,
265
+ categoryID: state.collectionID,
266
+ segments: state.segments,
267
+ searchWithinSearch: state.searchWithinSearch,
268
+ custom_sort_settings: state.custom_sort_settings,
269
+ disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
270
+ disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
271
+ disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
272
+ disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
273
+ disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
274
+ disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
275
+ };
276
+ fetchResults(fetchParams, isInfiniteScroll);
277
+ }
278
+ function setState(_a) {
279
+ var _b;
280
+ var newState = __rest(_a, []);
281
+ console.log("state", state);
282
+ console.log("setState", newState);
283
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'setState', payload: newState });
284
+ fetchResults({
285
+ siteKey: siteKey,
286
+ uuid: uuid,
287
+ storeID: storeID,
288
+ term: newState.query,
289
+ narrowBy: newState.narrow ? newState.narrow : undefined,
290
+ sortBy: (_b = newState.sortBy) !== null && _b !== void 0 ? _b : defaultSort,
291
+ categoryID: newState.collectionID,
292
+ page: newState.page,
293
+ segments: newState.segments,
294
+ }, Boolean(!results && isInfiniteScroll && newState.page && newState.page > 1));
295
+ }
296
+ function setSingleProducts(products) {
297
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: "setSingleProducts", payload: products });
298
+ }
299
+ function setReady(isReady) {
300
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: "setReady", payload: isReady });
301
+ }
302
+ function setSearchWithinSearch(searchWithinSearch) {
303
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: "setSearchWithinSearch", payload: searchWithinSearch });
304
+ let fetchParams = {
305
+ withProductAttributes: withProductAttributes,
306
+ siteKey: siteKey,
307
+ uuid: uuid,
308
+ storeID: storeID,
309
+ term: query,
310
+ narrowBy: state.narrow,
311
+ sortBy: state.sortBy,
312
+ categoryID: state.collectionID,
313
+ segments: state.segments,
314
+ searchWithinSearch: searchWithinSearch,
315
+ custom_sort_settings: state.custom_sort_settings,
316
+ disable_merchandising: state.flag.find((f) => f == "disable_merchandising") ? 1 : 0,
317
+ disable_semantics: state.flag.find((f) => f == "disable_semantics") ? 1 : 0,
318
+ disable_turbolinks: state.flag.find((f) => f == "disable_turbolinks") ? 1 : 0,
319
+ disable_strategies: state.flag.find((f) => f == "disable_strategies") ? 1 : 0,
320
+ disable_merchandising_rules: state.flag.find((f) => f == "disable_merchandising_rules") ? 1 : 0,
321
+ disable_antonyms: state.flag.find((f) => f == "disable_antonyms") ? 1 : 0,
322
+ };
323
+ fetchResults(fetchParams, isInfiniteScroll);
324
+ }
325
+ function fetchResults(props, isInfiniteScroll, autocomplete = false) {
326
+ // on first request check if we need to fetch more then 1 product
327
+ if (props.term && !autocomplete) {
328
+ onSearch(newObject(Object.assign(Object.assign({}, props), { page: props.page || 1, infiniteScrollPage: isInfiniteScroll })), isInfiniteScroll);
329
+ }
330
+ else if (props.term && autocomplete) {
331
+ onAutocompleteSearch(newObject(Object.assign({}, props)));
332
+ }
333
+ else if (props.categoryID) {
334
+ onCollection(newObject(Object.assign(Object.assign({}, props), { page: props.page || 1, infiniteScrollPage: isInfiniteScroll })), isInfiniteScroll);
335
+ }
336
+ return;
337
+ }
338
+ useEffect(() => {
339
+ function handleSetQueryEvent(event) {
340
+ setQuery(event.detail);
341
+ }
342
+ function handleSetFlagEvent(event) {
343
+ setFlag(event.details);
344
+ }
345
+ function handleSetCollectionEvent(event) {
346
+ setCollectionID(event.detail);
347
+ }
348
+ function handleSetCollectionURLEvent(event) {
349
+ getAllCategories().then(r => {
350
+ var _a;
351
+ const id = (_a = r.find(c => c.u === event.detail)) === null || _a === void 0 ? void 0 : _a.id;
352
+ if (id) {
353
+ setCollectionID(id);
354
+ return;
355
+ }
356
+ window.location.href = event.detail;
357
+ });
358
+ }
359
+ function handleSetPageEvent(event) {
360
+ setPage(event.detail);
361
+ }
362
+ function handleSetSortEvent(event) {
363
+ setSortBy(event.detail);
364
+ }
365
+ function handleSetNarrowEvent(event) {
366
+ setNarrow(event.detail);
367
+ }
368
+ function handleSetSegmentsEvent(event) {
369
+ setSegments(event.detail);
370
+ }
371
+ function handleSetIsAutocomplete(event) {
372
+ setIsAutocomplete(event.detail);
373
+ }
374
+ window.addEventListener('fast-simon-update-query', handleSetQueryEvent);
375
+ window.addEventListener('fast-simon-update-collection', handleSetCollectionEvent);
376
+ window.addEventListener('fast-simon-update-collection-url', handleSetCollectionURLEvent);
377
+ window.addEventListener('fast-simon-update-page', handleSetPageEvent);
378
+ window.addEventListener('fast-simon-update-sort', handleSetSortEvent);
379
+ window.addEventListener('fast-simon-update-narrow', handleSetNarrowEvent);
380
+ window.addEventListener('fast-simon-update-segments', handleSetSegmentsEvent);
381
+ window.addEventListener('fast-simon-update-flag', handleSetFlagEvent);
382
+ window.addEventListener('fast-simon-update-is-autocomplete', handleSetIsAutocomplete);
383
+ return () => {
384
+ window.removeEventListener('fast-simon-update-query', handleSetQueryEvent);
385
+ window.removeEventListener('fast-simon-update-collection', handleSetCollectionEvent);
386
+ window.removeEventListener('fast-simon-update-collection-url', handleSetCollectionURLEvent);
387
+ window.removeEventListener('fast-simon-update-page', handleSetPageEvent);
388
+ window.removeEventListener('fast-simon-update-sort', handleSetSortEvent);
389
+ window.removeEventListener('fast-simon-update-narrow', handleSetNarrowEvent);
390
+ window.removeEventListener('fast-simon-update-segments', handleSetSegmentsEvent);
391
+ window.removeEventListener('fast-simon-update-flag', handleSetFlagEvent);
392
+ window.removeEventListener('fast-simon-update-is-autocomplete', handleSetIsAutocomplete);
393
+ };
394
+ }, []);
395
+ const onSearch = (props, isInfiniteScroll) => {
396
+ setIsLoading({ products: true, filters: true });
397
+ // Pass with_product_analytics only on first request for this query OR when switching from collection to search
398
+ // AND only if merchant is enterprise or subscription level 5
399
+ const currentQuery = props.term || '';
400
+ const shouldFetchAnalytics = isAnalyticsEnabled && (currentQuery !== lastAnalyticsQuery || lastAnalyticsMode !== 'search');
401
+ FullTextSearch.getReasoningFullTextSearch(Object.assign(Object.assign({}, props), { withAttributes: promoTiles || withProductAttributes, with_product_analytics: shouldFetchAnalytics, market_context: marketContext })).then((response) => __awaiter(void 0, void 0, void 0, function* () {
402
+ var _a;
403
+ // Mark analytics as fetched only if response contains analytics data with badges
404
+ if (shouldFetchAnalytics && ((_a = response.analytics) === null || _a === void 0 ? void 0 : _a.badges)) {
405
+ setAnalyticsFetched(true);
406
+ setLastAnalyticsQuery(currentQuery);
407
+ setLastAnalyticsMode('search');
408
+ }
409
+ // Preserve existing analytics if new response doesn't have it
410
+ const existingAnalytics = results === null || results === void 0 ? void 0 : results.analytics;
411
+ response = getFormatedData(response, existingAnalytics);
412
+ // Handle turbolink responses - skip additional API calls to prevent errors
413
+ if (response.turbolink && response.totalResults === 0) {
414
+ mergeResults(response, isInfiniteScroll);
415
+ if (!customTitleChange) {
416
+ document.title = `Search Result for ${query}`;
417
+ }
418
+ else {
419
+ customTitleChange(results);
420
+ }
421
+ setIsLoading({ filters: false, products: false });
422
+ return;
423
+ }
424
+ const listIdRequestProps = Object.assign({}, props);
425
+ listIdRequestProps.searchWithinSearch = undefined;
426
+ listIdRequestProps.productsPerPage = 1000000;
427
+ listIdRequestProps.page = 1;
428
+ listIdRequestProps.market_context = marketContext;
429
+ let listIdRes = yield FullTextSearch.getReasoningFullTextSearchProductsIds(listIdRequestProps).then((response) => {
430
+ return response;
431
+ });
432
+ response.id_list = listIdRes.id_list;
433
+ const facetsRequestProps = Object.assign({}, props);
434
+ facetsRequestProps.facetRequired = 2;
435
+ facetsRequestProps.searchWithinSearch = props.searchWithinSearch;
436
+ facetsRequestProps.productsPerPage = props.productsPerPage;
437
+ facetsRequestProps.page = props.page;
438
+ facetsRequestProps.market_context = marketContext;
439
+ let facetsRes = yield FullTextSearch.getReasoningFullTextSearch(facetsRequestProps).then((response) => {
440
+ return response;
441
+ });
442
+ response.facets = facetsRes.facets;
443
+ mergeResults(response, isInfiniteScroll);
444
+ if (!customTitleChange) {
445
+ document.title = `Search Result for ${query}`;
446
+ }
447
+ else {
448
+ customTitleChange(results);
449
+ }
450
+ if (!response) {
451
+ setIsLoading({
452
+ filters: true, products: false
453
+ });
454
+ }
455
+ else {
456
+ setIsLoading({
457
+ filters: false, products: false
458
+ });
459
+ }
460
+ }));
461
+ };
462
+ const onAutocompleteSearch = (props) => {
463
+ setIsLoading({ products: true, filters: true });
464
+ Autocomplete.getAutocompleteReasoning(Object.assign(Object.assign({}, props), { withAttributes: promoTiles || withProductAttributes, market_context: marketContext })).then((response) => __awaiter(void 0, void 0, void 0, function* () {
465
+ response = getFormatedData(response);
466
+ mergeResults(response, false);
467
+ if (!customTitleChange) {
468
+ document.title = `Autocomplete Result for ${query}`;
469
+ }
470
+ else {
471
+ customTitleChange(results);
472
+ }
473
+ if (!response) {
474
+ setIsLoading({
475
+ filters: true, products: false
476
+ });
477
+ }
478
+ else {
479
+ setIsLoading({
480
+ filters: false, products: false
481
+ });
482
+ }
483
+ }));
484
+ };
485
+ const onCollection = (props, isInfiniteScroll) => {
486
+ setIsLoading({ products: true, filters: true });
487
+ // Pass with_product_analytics only on first request for this collection OR when switching from search to collection
488
+ // AND only if merchant is enterprise or subscription level 5
489
+ const currentCollection = props.categoryID || '';
490
+ const shouldFetchAnalytics = isAnalyticsEnabled && (currentCollection !== lastAnalyticsCollection || lastAnalyticsMode !== 'collection');
491
+ SmartCollections.getSmartCollections(Object.assign(Object.assign({}, props), { withAttributes: promoTiles || withProductAttributes, with_product_analytics: shouldFetchAnalytics, market_context: marketContext }))
492
+ .then((response) => __awaiter(void 0, void 0, void 0, function* () {
493
+ var _a;
494
+ // Mark analytics as fetched only if response contains analytics data with badges
495
+ if (shouldFetchAnalytics && ((_a = response.analytics) === null || _a === void 0 ? void 0 : _a.badges)) {
496
+ setAnalyticsFetched(true);
497
+ setLastAnalyticsCollection(currentCollection);
498
+ setLastAnalyticsMode('collection');
499
+ }
500
+ // Preserve existing analytics if new response doesn't have it
501
+ const existingAnalytics = results === null || results === void 0 ? void 0 : results.analytics;
502
+ response = getFormatedData(response, existingAnalytics);
503
+ const listIdRequestProps = Object.assign({}, props);
504
+ listIdRequestProps.searchWithinSearch = undefined;
505
+ listIdRequestProps.productsPerPage = 1000000;
506
+ listIdRequestProps.page = 1;
507
+ listIdRequestProps.market_context = marketContext;
508
+ let listIdRes = yield SmartCollections.getSmartCollectionsProductsIds(listIdRequestProps).then((response) => {
509
+ return response;
510
+ });
511
+ response.id_list = listIdRes.id_list;
512
+ const facetsRequestProps = Object.assign({}, props);
513
+ facetsRequestProps.facetRequired = 2;
514
+ facetsRequestProps.searchWithinSearch = props.searchWithinSearch;
515
+ facetsRequestProps.productsPerPage = props.productsPerPage;
516
+ facetsRequestProps.page = props.page;
517
+ facetsRequestProps.market_context = marketContext;
518
+ let facetsRes = yield SmartCollections.getSmartCollections(facetsRequestProps).then((response) => {
519
+ return response;
520
+ });
521
+ response.facets = facetsRes.facets;
522
+ mergeResults(response, isInfiniteScroll);
523
+ if (!response) {
524
+ setIsLoading({
525
+ filters: true, products: false
526
+ });
527
+ }
528
+ else {
529
+ setIsLoading({
530
+ filters: false, products: false
531
+ });
532
+ }
533
+ getAllCategories().then(r => {
534
+ var _a, _b;
535
+ if (!customTitleChange) {
536
+ document.title = (_b = (_a = r.find(c => c.id === props.categoryID)) === null || _a === void 0 ? void 0 : _a.l) !== null && _b !== void 0 ? _b : "Collection";
537
+ }
538
+ else {
539
+ customTitleChange(results);
540
+ }
541
+ });
542
+ })).then(() => {
543
+ });
544
+ };
545
+ const getAllCategories = () => __awaiter(void 0, void 0, void 0, function* () {
546
+ if (categories.length > 0) {
547
+ return new Promise(resolve => resolve(categories));
548
+ }
549
+ const data = categories || [];
550
+ setCategories(data);
551
+ return data;
552
+ });
553
+ const getFormatedData = (response, existingAnalytics) => {
554
+ const results = response;
555
+ results.products = response.items;
556
+ delete results.items;
557
+ results.totalResults = response.total_results;
558
+ delete results.total_results;
559
+ if (response.sort_by) {
560
+ results.sortBy = response.sort_by;
561
+ delete results.sort_by;
562
+ }
563
+ if (response.pop_products_no_results) {
564
+ results.isNoResults = true;
565
+ }
566
+ if (response.total_p) {
567
+ results.pageCount = response.total_p;
568
+ delete results.total_p;
569
+ }
570
+ if (response.ancestor_categories) {
571
+ results.ancestors = response.ancestor_categories;
572
+ delete results.ancestor_categories;
573
+ }
574
+ if (response.avoid_tag_prefixes) {
575
+ results.avoidPrefixList = response.avoid_tag_prefixes.split(",");
576
+ }
577
+ results.page = response.p || 1;
578
+ delete results.p;
579
+ // Preserve analytics field if present (contains winners/overexposed data)
580
+ // If response has new analytics, use it; otherwise keep existing analytics
581
+ if (response.analytics) {
582
+ results.analytics = response.analytics;
583
+ }
584
+ else if (existingAnalytics) {
585
+ results.analytics = existingAnalytics;
586
+ }
587
+ return results;
588
+ };
589
+ // @ts-ignore
590
+ return (_jsx(FastStateFunctions.Provider, Object.assign({ value: {
591
+ setQuery,
592
+ setSort: setSortBy,
593
+ setNarrow,
594
+ setPage,
595
+ getAllCategories,
596
+ setCollection: setCollectionID,
597
+ setState,
598
+ setSearchWithinSearch,
599
+ setSegments,
600
+ setFlag,
601
+ setCustomSort,
602
+ setIsAutocomplete
603
+ } }, { children: _jsx(FastState.Provider, Object.assign({ value: { narrow, results, page, query, sortBy, type, collectionID, isLoading, recommendations, singleProducts, isReady, autocomplete, isAutocomplete } }, { children: _jsx(ThemeProvider, Object.assign({ theme: Object.assign(Object.assign({}, mainTheme), theme) }, { children: children })) })) })));
604
+ };
605
+ export default FastSimonApi;
606
606
  //# sourceMappingURL=FastSimonApi.js.map