@zengenti/contensis-react-base 3.0.0-beta.9 → 3.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +128 -1
  2. package/cjs/{App-5d20127f.js → App-c5698b06.js} +229 -182
  3. package/cjs/App-c5698b06.js.map +1 -0
  4. package/cjs/{RouteLoader-df3de0cb.js → RouteLoader-3aa6456e.js} +47 -28
  5. package/cjs/RouteLoader-3aa6456e.js.map +1 -0
  6. package/cjs/{ToJs-697ace9f.js → ToJs-a9a8522b.js} +39 -34
  7. package/cjs/ToJs-a9a8522b.js.map +1 -0
  8. package/cjs/{actions-a24bf46e.js → actions-8dc9e8de.js} +5 -4
  9. package/cjs/actions-8dc9e8de.js.map +1 -0
  10. package/cjs/client.js +22 -44
  11. package/cjs/client.js.map +1 -1
  12. package/cjs/contensis-react-base.js +3956 -136
  13. package/cjs/contensis-react-base.js.map +1 -1
  14. package/cjs/forms.js +547 -580
  15. package/cjs/forms.js.map +1 -1
  16. package/cjs/{fromJSLeaveImmer-65d26804.js → fromJSLeaveImmer-e74c673c.js} +2 -2
  17. package/cjs/fromJSLeaveImmer-e74c673c.js.map +1 -0
  18. package/cjs/{login-bc55ee33.js → login-6b9de6a1.js} +92 -55
  19. package/cjs/login-6b9de6a1.js.map +1 -0
  20. package/cjs/{reducers-fde41d6b.js → reducers-3a4f8971.js} +26 -25
  21. package/cjs/reducers-3a4f8971.js.map +1 -0
  22. package/cjs/redux.js +6 -5
  23. package/cjs/redux.js.map +1 -1
  24. package/cjs/routing.js +5 -4
  25. package/cjs/routing.js.map +1 -1
  26. package/cjs/sagas-594b5ecd.js +2090 -0
  27. package/cjs/sagas-594b5ecd.js.map +1 -0
  28. package/cjs/search.js +296 -1915
  29. package/cjs/search.js.map +1 -1
  30. package/cjs/{selectors-0ec95076.js → selectors-656da4b7.js} +8 -3
  31. package/cjs/selectors-656da4b7.js.map +1 -0
  32. package/cjs/setCachingHeaders-ee619bdf.js +12 -0
  33. package/cjs/setCachingHeaders-ee619bdf.js.map +1 -0
  34. package/cjs/user.js +21 -12
  35. package/cjs/user.js.map +1 -1
  36. package/cjs/util.js +17 -17
  37. package/cjs/util.js.map +1 -1
  38. package/cjs/{version-bf00e6d7.js → version-78dfc3bd.js} +35 -23
  39. package/cjs/version-78dfc3bd.js.map +1 -0
  40. package/cjs/{version-be0c7b7a.js → version-eba6d09b.js} +2 -2
  41. package/{esm/version-ad2ec52c.js.map → cjs/version-eba6d09b.js.map} +1 -1
  42. package/esm/{App-4224ba21.js → App-069378e0.js} +229 -183
  43. package/esm/App-069378e0.js.map +1 -0
  44. package/esm/{RouteLoader-027215f2.js → RouteLoader-5171c63f.js} +47 -28
  45. package/esm/RouteLoader-5171c63f.js.map +1 -0
  46. package/esm/{ToJs-46761960.js → ToJs-4e02a04d.js} +38 -32
  47. package/esm/ToJs-4e02a04d.js.map +1 -0
  48. package/esm/{actions-b949ef5c.js → actions-180948dd.js} +5 -4
  49. package/esm/actions-180948dd.js.map +1 -0
  50. package/esm/client.js +24 -27
  51. package/esm/client.js.map +1 -1
  52. package/esm/contensis-react-base.js +3954 -135
  53. package/esm/contensis-react-base.js.map +1 -1
  54. package/esm/forms.js +547 -583
  55. package/esm/forms.js.map +1 -1
  56. package/esm/{fromJSLeaveImmer-e2f0f331.js → fromJSLeaveImmer-0114ffcf.js} +2 -2
  57. package/esm/fromJSLeaveImmer-0114ffcf.js.map +1 -0
  58. package/esm/{login-6eab4c94.js → login-508cac0f.js} +92 -55
  59. package/esm/login-508cac0f.js.map +1 -0
  60. package/esm/{reducers-d6c0edb1.js → reducers-8e5d6232.js} +26 -25
  61. package/esm/reducers-8e5d6232.js.map +1 -0
  62. package/esm/redux.js +8 -7
  63. package/esm/redux.js.map +1 -1
  64. package/esm/routing.js +5 -4
  65. package/esm/routing.js.map +1 -1
  66. package/esm/sagas-1f2b2aa0.js +2000 -0
  67. package/esm/sagas-1f2b2aa0.js.map +1 -0
  68. package/esm/search.js +252 -1856
  69. package/esm/search.js.map +1 -1
  70. package/esm/{selectors-8fca7fb2.js → selectors-a5e5835b.js} +9 -6
  71. package/esm/selectors-a5e5835b.js.map +1 -0
  72. package/esm/setCachingHeaders-d49060e1.js +10 -0
  73. package/esm/setCachingHeaders-d49060e1.js.map +1 -0
  74. package/esm/user.js +23 -14
  75. package/esm/user.js.map +1 -1
  76. package/esm/util.js +17 -17
  77. package/esm/util.js.map +1 -1
  78. package/esm/{version-ad2ec52c.js → version-2485e2fb.js} +2 -2
  79. package/{cjs/version-be0c7b7a.js.map → esm/version-2485e2fb.js.map} +1 -1
  80. package/esm/{version-3b4fe08d.js → version-e3a5ec66.js} +34 -23
  81. package/esm/version-e3a5ec66.js.map +1 -0
  82. package/models/app/pages/VersionInfo/components/VersionInfo.d.ts +1 -1
  83. package/models/forms/index.d.ts +3 -1
  84. package/models/index.d.ts +1 -0
  85. package/models/redux/appstate.d.ts +5 -10
  86. package/models/redux/sagas/navigation.d.ts +1 -1
  87. package/models/redux/selectors/navigation.d.ts +2 -1
  88. package/models/routing/components/RouteLoader.d.ts +2 -19
  89. package/models/routing/redux/actions.d.ts +1 -1
  90. package/models/routing/redux/selectors.d.ts +1 -1
  91. package/models/routing/routes.d.ts +22 -4
  92. package/models/routing/util/expressions.d.ts +3 -2
  93. package/models/routing/util/queries.d.ts +1 -1
  94. package/models/search/containers/withListing.d.ts +1 -1
  95. package/models/search/containers/withSearch.d.ts +1 -1
  96. package/models/search/hooks/useFacets.hook.d.ts +3 -0
  97. package/models/search/hooks/useListing.hook.d.ts +3 -0
  98. package/models/search/hooks/useMinilist.hook.d.ts +2 -9
  99. package/models/search/index.d.ts +6 -2
  100. package/models/search/models/Queries.d.ts +8 -5
  101. package/models/search/models/Search.d.ts +60 -28
  102. package/models/search/models/SearchActions.d.ts +9 -5
  103. package/models/search/models/SearchProps.d.ts +52 -7
  104. package/models/search/models/SearchState.d.ts +5 -1
  105. package/models/search/models/index.d.ts +3 -1
  106. package/models/search/redux/actions.d.ts +5 -2
  107. package/models/search/redux/reducers.d.ts +230 -314
  108. package/models/search/redux/sagas.d.ts +11 -7
  109. package/models/search/redux/selectors.d.ts +21 -24
  110. package/models/search/redux/util.d.ts +1 -0
  111. package/models/search/search/ContensisDeliveryApi.d.ts +1 -0
  112. package/models/search/search/expressions.d.ts +5 -8
  113. package/models/search/{redux → search}/queries.d.ts +0 -0
  114. package/models/search/search/util.d.ts +14 -0
  115. package/models/search/transformations/entry-to-filteritem.mapper.d.ts +2 -1
  116. package/models/search/transformations/filter-to-filterexpression.mapper.d.ts +6 -0
  117. package/models/search/transformations/filters-to-filterexpressions.mapper.d.ts +3 -0
  118. package/models/search/transformations/index.d.ts +3 -0
  119. package/models/search/transformations/queryParams-to-customapi.mapper.d.ts +3 -0
  120. package/models/search/transformations/state-to-searchuri.d.ts +2 -13
  121. package/models/server/features/linkdepth-api/LinkDepthSearchService.d.ts +24 -0
  122. package/models/server/features/linkdepth-api/QueryLevelResults.d.ts +50 -0
  123. package/models/server/features/linkdepth-api/api.d.ts +12 -0
  124. package/models/server/features/linkdepth-api/events-api.config.d.ts +37 -0
  125. package/models/server/features/linkdepth-api/search.d.ts +31 -0
  126. package/models/server/features/linkdepth-api/util.d.ts +11 -0
  127. package/models/server/middleware/bundleManipulation.d.ts +2 -1
  128. package/models/server/util/bundles.d.ts +17 -21
  129. package/models/server/util/getVersionInfo.d.ts +1 -0
  130. package/models/server/util/headers.d.ts +3 -2
  131. package/models/user/components/Login.d.ts +1 -2
  132. package/models/user/components/LoginForm.d.ts +1 -2
  133. package/models/user/hocs/withLogin.d.ts +4 -2
  134. package/models/user/hocs/withRegistration.d.ts +2 -0
  135. package/models/user/hooks/useLogin.d.ts +5 -3
  136. package/models/user/redux/reducers.d.ts +4 -5
  137. package/models/user/redux/sagas/login.d.ts +11 -8
  138. package/models/user/redux/selectors.d.ts +12 -6
  139. package/models/user/util/LoginHelper.class.d.ts +4 -3
  140. package/models/util/ContensisDeliveryApi.d.ts +4 -4
  141. package/models/util/json-mapper.d.ts +9 -3
  142. package/models/util/merge.d.ts +1 -0
  143. package/package.json +61 -56
  144. package/CHANGELOG.md +0 -293
  145. package/cjs/App-5d20127f.js.map +0 -1
  146. package/cjs/RouteLoader-df3de0cb.js.map +0 -1
  147. package/cjs/ToJs-697ace9f.js.map +0 -1
  148. package/cjs/actions-a24bf46e.js.map +0 -1
  149. package/cjs/fromJSLeaveImmer-65d26804.js.map +0 -1
  150. package/cjs/login-bc55ee33.js.map +0 -1
  151. package/cjs/reducers-fde41d6b.js.map +0 -1
  152. package/cjs/selectors-0ec95076.js.map +0 -1
  153. package/cjs/version-bf00e6d7.js.map +0 -1
  154. package/esm/App-4224ba21.js.map +0 -1
  155. package/esm/RouteLoader-027215f2.js.map +0 -1
  156. package/esm/ToJs-46761960.js.map +0 -1
  157. package/esm/actions-b949ef5c.js.map +0 -1
  158. package/esm/fromJSLeaveImmer-e2f0f331.js.map +0 -1
  159. package/esm/login-6eab4c94.js.map +0 -1
  160. package/esm/reducers-d6c0edb1.js.map +0 -1
  161. package/esm/selectors-8fca7fb2.js.map +0 -1
  162. package/esm/version-3b4fe08d.js.map +0 -1
  163. package/models/search/transformations/filters-to-filterexpression.d.ts +0 -1
  164. package/models/search/transformations/filters-to-filterexpression.mapper.d.ts +0 -2
  165. package/models/server/features/caching/cacheHashing.d.ts +0 -1
  166. package/package-lock.json +0 -14093
@@ -0,0 +1,2000 @@
1
+ import * as log from 'loglevel';
2
+ import { takeEvery, select, put, call, all } from '@redux-saga/core/effects';
3
+ import { Client } from 'contensis-delivery-api';
4
+ import { parse, stringify } from 'query-string';
5
+ import mapJson, { jpath } from 'jsonpath-mapper';
6
+ import { Op, OrderBy, Query } from 'contensis-core-api';
7
+ import merge from 'deepmerge';
8
+
9
+ const ACTION_PREFIX = '@SEARCH/';
10
+ const APPLY_CONFIG = `${ACTION_PREFIX}APPLY_CONFIG`;
11
+ const CLEAR_FILTERS = `${ACTION_PREFIX}CLEAR_FILTERS`;
12
+ const DO_SEARCH = `${ACTION_PREFIX}DO_SEARCH`;
13
+ const EXECUTE_SEARCH = `${ACTION_PREFIX}EXECUTE_SEARCH`;
14
+ const EXECUTE_SEARCH_ERROR = `${ACTION_PREFIX}EXECUTE_SEARCH_ERROR`;
15
+ const EXECUTE_SEARCH_PRELOAD = `${ACTION_PREFIX}EXECUTE_SEARCH_PRELOAD`;
16
+ const LOAD_FILTERS = `${ACTION_PREFIX}LOAD_FILTERS`;
17
+ const LOAD_FILTERS_COMPLETE = `${ACTION_PREFIX}LOAD_FILTERS_COMPLETE`;
18
+ const LOAD_FILTERS_ERROR = `${ACTION_PREFIX}LOAD_FILTERS_ERROR`;
19
+ const SET_FEATURED_ENTRIES = `${ACTION_PREFIX}SET_FEATURED_ENTRIES`;
20
+ const SET_ROUTE_FILTERS = `${ACTION_PREFIX}SET_ROUTE_FILTERS`;
21
+ const SET_SEARCH_FILTERS = `${ACTION_PREFIX}SET_SEARCH_FILTERS`;
22
+ const SET_SEARCH_ENTRIES = `${ACTION_PREFIX}SET_SEARCH_ENTRIES`;
23
+ const SET_SELECTED_FILTER = `${ACTION_PREFIX}SET_SELECTED_FILTER`;
24
+ const UPDATE_CURRENT_FACET = `${ACTION_PREFIX}UPDATE_CURRENT_FACET`;
25
+ const UPDATE_CURRENT_TAB = `${ACTION_PREFIX}UPDATE_CURRENT_TAB`;
26
+ const UPDATE_SORT_ORDER = `${ACTION_PREFIX}UPDATE_SORT_ORDER`;
27
+ const UPDATE_PAGE_INDEX = `${ACTION_PREFIX}UPDATE_PAGE_INDEX`;
28
+ const UPDATE_SEARCH_TERM = `${ACTION_PREFIX}UPDATE_SEARCH_TERM`;
29
+ const UPDATE_SELECTED_FILTERS = `${ACTION_PREFIX}UPDATE_SELECTED_FILTERS`;
30
+
31
+ var types = /*#__PURE__*/Object.freeze({
32
+ __proto__: null,
33
+ APPLY_CONFIG: APPLY_CONFIG,
34
+ CLEAR_FILTERS: CLEAR_FILTERS,
35
+ DO_SEARCH: DO_SEARCH,
36
+ EXECUTE_SEARCH: EXECUTE_SEARCH,
37
+ EXECUTE_SEARCH_ERROR: EXECUTE_SEARCH_ERROR,
38
+ EXECUTE_SEARCH_PRELOAD: EXECUTE_SEARCH_PRELOAD,
39
+ LOAD_FILTERS: LOAD_FILTERS,
40
+ LOAD_FILTERS_COMPLETE: LOAD_FILTERS_COMPLETE,
41
+ LOAD_FILTERS_ERROR: LOAD_FILTERS_ERROR,
42
+ SET_FEATURED_ENTRIES: SET_FEATURED_ENTRIES,
43
+ SET_ROUTE_FILTERS: SET_ROUTE_FILTERS,
44
+ SET_SEARCH_FILTERS: SET_SEARCH_FILTERS,
45
+ SET_SEARCH_ENTRIES: SET_SEARCH_ENTRIES,
46
+ SET_SELECTED_FILTER: SET_SELECTED_FILTER,
47
+ UPDATE_CURRENT_FACET: UPDATE_CURRENT_FACET,
48
+ UPDATE_CURRENT_TAB: UPDATE_CURRENT_TAB,
49
+ UPDATE_SORT_ORDER: UPDATE_SORT_ORDER,
50
+ UPDATE_PAGE_INDEX: UPDATE_PAGE_INDEX,
51
+ UPDATE_SEARCH_TERM: UPDATE_SEARCH_TERM,
52
+ UPDATE_SELECTED_FILTERS: UPDATE_SELECTED_FILTERS
53
+ });
54
+
55
+ const withMappers = (action, mappers) => {
56
+ return { ...action,
57
+ mappers
58
+ };
59
+ };
60
+ const triggerSearch = ({
61
+ config,
62
+ context,
63
+ debug,
64
+ defaultLang,
65
+ excludeIds,
66
+ facet,
67
+ mapper,
68
+ mappers,
69
+ params
70
+ }) => {
71
+ return {
72
+ type: DO_SEARCH,
73
+ config,
74
+ context,
75
+ debug,
76
+ defaultLang,
77
+ excludeIds,
78
+ facet,
79
+ mapper,
80
+ mappers,
81
+ params
82
+ };
83
+ };
84
+ const initListing = ({
85
+ context,
86
+ facet,
87
+ mapper,
88
+ params
89
+ }) => {
90
+ return {
91
+ type: SET_ROUTE_FILTERS,
92
+ context,
93
+ facet,
94
+ mapper,
95
+ params
96
+ };
97
+ };
98
+ const navigate = (path, state) => {
99
+ return {
100
+ type: '@ROUTING/_SET_ROUTE',
101
+ path,
102
+ state
103
+ };
104
+ };
105
+ const clearFilters$1 = filterKey => {
106
+ return {
107
+ type: CLEAR_FILTERS,
108
+ filterKey
109
+ };
110
+ };
111
+ const updatePageIndex$1 = (pageIndex, scrollYPos) => {
112
+ return {
113
+ type: UPDATE_PAGE_INDEX,
114
+ pageIndex,
115
+ scrollYPos
116
+ };
117
+ };
118
+ const updateCurrentFacet$1 = facet => {
119
+ return {
120
+ type: UPDATE_CURRENT_FACET,
121
+ facet
122
+ };
123
+ };
124
+ const updateCurrentTab$1 = id => {
125
+ return {
126
+ type: UPDATE_CURRENT_TAB,
127
+ id
128
+ };
129
+ };
130
+ const updateSearchTerm$1 = term => {
131
+ return {
132
+ type: UPDATE_SEARCH_TERM,
133
+ term
134
+ };
135
+ };
136
+ const updateSelectedFilters = (filter, key, isUnknownItem = false, scrollYPos) => {
137
+ return {
138
+ type: UPDATE_SELECTED_FILTERS,
139
+ filter,
140
+ key,
141
+ isUnknownItem,
142
+ scrollYPos
143
+ };
144
+ };
145
+ const updateSortOrder$1 = (orderBy, facet) => {
146
+ return {
147
+ type: UPDATE_SORT_ORDER,
148
+ orderBy,
149
+ facet
150
+ };
151
+ };
152
+
153
+ var actions = /*#__PURE__*/Object.freeze({
154
+ __proto__: null,
155
+ withMappers: withMappers,
156
+ triggerSearch: triggerSearch,
157
+ initListing: initListing,
158
+ navigate: navigate,
159
+ clearFilters: clearFilters$1,
160
+ updatePageIndex: updatePageIndex$1,
161
+ updateCurrentFacet: updateCurrentFacet$1,
162
+ updateCurrentTab: updateCurrentTab$1,
163
+ updateSearchTerm: updateSearchTerm$1,
164
+ updateSelectedFilters: updateSelectedFilters,
165
+ updateSortOrder: updateSortOrder$1
166
+ });
167
+
168
+ let Context; // export type Context = 'facets' | 'listings' | 'minilist';
169
+
170
+ (function (Context) {
171
+ Context["facets"] = "facets";
172
+ Context["listings"] = "listings";
173
+ Context["minilist"] = "minilist";
174
+ })(Context || (Context = {}));
175
+
176
+ // or replace with a stub function for non-immutable gets
177
+
178
+ const makeFromJS = (returnType = globalThis.STATE_TYPE || 'immutable') => {
179
+ var _immutable, _immutable2;
180
+
181
+ return returnType === 'immutable' ? ((_immutable = globalThis.immutable) === null || _immutable === void 0 ? void 0 : _immutable.fromJSOrdered) || ((_immutable2 = globalThis.immutable) === null || _immutable2 === void 0 ? void 0 : _immutable2.fromJS) || (v => v) : v => v;
182
+ };
183
+
184
+ const getImmutableOrJS = (state, stateKey, fallbackValue, returnType = globalThis.STATE_TYPE || 'immutable') => {
185
+ // Find a fromJS function from global that is dynamically loaded in createStore
186
+ // or replace with a stub function for non-immutable gets
187
+ const fromJS = makeFromJS(returnType);
188
+
189
+ if (state && 'get' in state && typeof state.get === 'function' && 'getIn' in state && typeof state.getIn === 'function' && 'toJS' in state && typeof state.toJS === 'function') {
190
+ if (Array.isArray(stateKey)) return fromJS(state.getIn(stateKey, fallbackValue));
191
+ return fromJS(state.get(stateKey, fallbackValue));
192
+ }
193
+
194
+ if (Array.isArray(stateKey) && state && typeof state === 'object') {
195
+ const result = jpath(stateKey.join('.'), state);
196
+ if (typeof result === 'undefined') return fallbackValue;
197
+ return result;
198
+ }
199
+
200
+ const result = state && typeof state === 'object' ? state[stateKey] : undefined;
201
+ if (typeof result === 'undefined') return fallbackValue;
202
+ return result;
203
+ };
204
+
205
+ const getSearchContext = state => getImmutableOrJS(state, ['search', 'context'], Context.facets);
206
+ const getCurrent = (state, context = Context.facets) => context === Context.facets ? getCurrentFacet(state) : getCurrentListing(state);
207
+ const getCurrentFacet = state => getImmutableOrJS(state, ['search', 'currentFacet']);
208
+ const getCurrentListing = state => getImmutableOrJS(state, ['search', 'currentListing']);
209
+ const getCurrentTab = state => getImmutableOrJS(state, ['search', Context.facets, getCurrentFacet(state), 'tabId'], 0);
210
+ const getFacets = (state, returnType) => getImmutableOrJS(state, ['search', Context.facets], {}, returnType);
211
+ const getTabFacets = state => Object.fromEntries(Object.entries(getFacets(state, 'js')).filter(([key]) => getImmutableOrJS(getFacets(state), [key, 'tabId'], 0) === getCurrentTab(state)));
212
+ const getFacetTitles = state => Object.entries(getFacets(state, 'js')).map(([key, facet = {}]) => {
213
+ var _facet$pagingInfo;
214
+
215
+ return {
216
+ isSelected: getCurrentFacet(state) === key,
217
+ key,
218
+ title: facet.title,
219
+ totalCount: (_facet$pagingInfo = facet.pagingInfo) === null || _facet$pagingInfo === void 0 ? void 0 : _facet$pagingInfo.totalCount
220
+ };
221
+ });
222
+ const getFacet = (state, facetName = '', context = Context.facets, returnType) => {
223
+ const currentFacet = facetName || getCurrentFacet(state);
224
+ return getImmutableOrJS(state, ['search', context, currentFacet], {}, returnType);
225
+ };
226
+ const getListing = (state, listing = '') => {
227
+ const currentListing = listing || getCurrentListing(state);
228
+ return getImmutableOrJS(state, ['search', Context.listings, currentListing], {});
229
+ };
230
+ const getFilters = (state, facet, context = Context.facets, returnType) => {
231
+ return getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'filters'], {}, returnType);
232
+ };
233
+ const getRenderableFilters = (state, facet = '', context = Context.facets) => Object.fromEntries(Object.entries(getFilters(state, facet, context, 'js')).filter(([, f = {}]) => typeof f.renderable !== 'boolean' ? true : f.renderable));
234
+ const getFiltersToLoad = (state, facet, context = Context.facets, returnType) => {
235
+ const filters = getFilters(state, facet, context, returnType);
236
+ const loadedFilters = Object.entries(filters).map(([key, f = {}]) => [key, (f.items || []).filter(i => {
237
+ const title = i === null || i === void 0 ? void 0 : i.title;
238
+ return typeof title !== 'undefined' && !!title;
239
+ }).length > 0 && (f.isError || false) === false]);
240
+ return loadedFilters.map(([filterKey, isLoaded]) => !isLoaded ? filterKey : null).filter(f => !!f);
241
+ }; // We lowercase the filter key unless it's an ISO date string where the T must be uppercase
242
+
243
+ const getSelectedFilters = (state, facet = '', context = Context.facets, returnType) => {
244
+ const filters = getFilters(state, facet, context, 'js');
245
+ const isoDateRegex = RegExp(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d/);
246
+ const selectedFilters = Object.fromEntries(Object.entries(filters).map(([key, filter = {}]) => [key, (filter.items || []).filter(item => !!(item.isSelected || false)).map(item => {
247
+ const key = (item === null || item === void 0 ? void 0 : item.key) || '';
248
+ const isIsoDate = isoDateRegex.test(key);
249
+ return isIsoDate ? key : typeof key.toLowerCase !== 'undefined' ? key.toLowerCase() : key;
250
+ })]));
251
+ const fromJS = makeFromJS(returnType);
252
+ return fromJS(selectedFilters);
253
+ };
254
+ const getResults = (state, current = '', context = Context.facets, returnType) => {
255
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'results'], [], returnType);
256
+ };
257
+ const getIsInternalPaging = (state, current, context = Context.facets) => {
258
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'queryParams', 'internalPaging'], false);
259
+ };
260
+ const getIsLoaded = (state, context = Context.facets, facet) => {
261
+ return !!getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'queryDuration'], 0);
262
+ };
263
+ const getIsLoading = (state, context = Context.facets, facet) => {
264
+ return getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'entries', 'isLoading']);
265
+ };
266
+ const getIsSsr = state => getImmutableOrJS(state, ['search', 'config', 'ssr'], false);
267
+ const getFeaturedResults = (state, current = '', context = Context.facets, returnType) => {
268
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'featuredResults'], [], returnType);
269
+ };
270
+ const getPaging = (state, current = '', context = Context.facets, returnType) => {
271
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo'], {}, returnType);
272
+ };
273
+ const getPageIndex = (state, current = '', context = Context.facets) => {
274
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'pageIndex']);
275
+ };
276
+ const getPrevPageIndex = (state, current = '', context = Context.facets) => {
277
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'prevPageIndex']);
278
+ };
279
+ const getPageIsLoading = (state, current = '', context = Context.facets) => {
280
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'isLoading']);
281
+ };
282
+ const getPagesLoaded = (state, current = '', context = Context.facets) => {
283
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'pagesLoaded'], [], 'js');
284
+ };
285
+ const getTotalCount = (state, current = '', context = Context.facets) => {
286
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'totalCount']);
287
+ };
288
+ const getSearchTerm = state => getImmutableOrJS(state, ['search', 'term']);
289
+ const getSearchTabs = (state, returnType) => getImmutableOrJS(state, ['search', 'tabs'], [], returnType);
290
+ const getQueryParams = (state, current = '', context = Context.facets) => {
291
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'queryParams'], {}, 'js');
292
+ };
293
+ const getQueryParameter = ({
294
+ state,
295
+ facet,
296
+ context = Context.facets
297
+ }, key, ifnull = null) => {
298
+ return getImmutableOrJS(getQueryParams(state, facet, context), key, ifnull, 'js');
299
+ };
300
+ const getCustomApi = (state, current, context = Context.facets, returnType) => {
301
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'customApi'], null, returnType);
302
+ };
303
+ const getCustomEnv = (state, current, context = Context.facets) => {
304
+ return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'env']);
305
+ };
306
+ const getTabsAndFacets = (state, returnType) => {
307
+ const tabs = getSearchTabs(state, 'js');
308
+ const facets = getFacets(state, 'js');
309
+ const tabsAndFacets = (tabs || []).map((tab = {}) => {
310
+ const fieldsToCount = tab.totalCount;
311
+ let countFields;
312
+ if (typeof fieldsToCount === 'string') countFields = [[fieldsToCount]];
313
+ const thisTabFacets = Object.entries(facets).filter(([key]) => getImmutableOrJS(facets, [key, 'tabId'], 0) === tab.id);
314
+ const thisTabTotal = thisTabFacets.map(([facetName, facet = {}]) => {
315
+ if (!countFields || countFields.find((f = []) => (f === null || f === void 0 ? void 0 : f[0]) === facetName)) return getImmutableOrJS(facet, ['pagingInfo', 'totalCount']);
316
+ return 0;
317
+ }).reduce((a, b) => a + b, 0);
318
+ return { ...tab,
319
+ [Context.facets]: Object.fromEntries(thisTabFacets),
320
+ totalCount: thisTabTotal
321
+ };
322
+ });
323
+ const fromJS = makeFromJS(returnType);
324
+ return fromJS(tabsAndFacets);
325
+ };
326
+ const getSearchTotalCount = state => {
327
+ const tabsAndFacets = getTabsAndFacets(state, 'js');
328
+ const wholeSearchTotal = tabsAndFacets.map((t = {}) => t.totalCount).reduce((a, b) => a + b, 0);
329
+ return wholeSearchTotal;
330
+ };
331
+ const getFacetsTotalCount = state => {
332
+ const facets = getFacets(state);
333
+ const wholeSearchTotal = Object.entries(facets).map(([, t = {}]) => {
334
+ var _t$pagingInfo;
335
+
336
+ return ((_t$pagingInfo = t.pagingInfo) === null || _t$pagingInfo === void 0 ? void 0 : _t$pagingInfo.totalCount) || 0;
337
+ }).reduce((a, b) => a + b, 0);
338
+ return wholeSearchTotal;
339
+ }; // An exported copy of the relevant selectors scoped by default to a facets context
340
+
341
+ const selectFacets = {
342
+ getCurrent: getCurrentFacet,
343
+ getCurrentTab,
344
+ getCustomApi,
345
+ getCustomEnv,
346
+ getFacet,
347
+ getFacetTitles,
348
+ getFacets,
349
+ getFacetsTotalCount,
350
+ getFeaturedResults,
351
+ getFilters,
352
+ getFiltersToLoad,
353
+ getIsLoaded,
354
+ getIsLoading,
355
+ getPageIndex,
356
+ getPageIsLoading,
357
+ getPagesLoaded,
358
+ getPaging,
359
+ getQueryParams: (state, facet) => getQueryParams(state, facet, Context.facets),
360
+ getQueryParameter: ({
361
+ state,
362
+ facet
363
+ }, key, ifnull) => getQueryParameter({
364
+ state,
365
+ facet,
366
+ context: Context.facets
367
+ }, key, ifnull),
368
+ getRenderableFilters,
369
+ getResults,
370
+ getTabFacets,
371
+ getTabsAndFacets,
372
+ getTotalCount,
373
+ getSearchTabs,
374
+ getSearchTerm,
375
+ getSearchTotalCount,
376
+ getSelectedFilters
377
+ }; // An exported copy of the relevant selectors pre-scoped to a listing context
378
+
379
+ const selectListing = {
380
+ getCurrent: getCurrentListing,
381
+ getFeaturedResults: (state, listing = '') => getFeaturedResults(state, listing, Context.listings, 'js'),
382
+ getFilters: (state, listing = '') => getFilters(state, listing, Context.listings, 'js'),
383
+ getFiltersToLoad: (state, listing = '') => getFiltersToLoad(state, listing, Context.listings),
384
+ getListing,
385
+ getIsLoaded: state => getIsLoaded(state, Context.listings),
386
+ getIsLoading: state => getIsLoading(state, Context.listings),
387
+ getPageIndex: (state, listing = '') => getPageIndex(state, listing, Context.listings),
388
+ getPaging: (state, listing = '') => getPaging(state, listing, Context.listings, 'js'),
389
+ getPageIsLoading: (state, listing = '') => getPageIsLoading(state, listing, Context.listings),
390
+ getPagesLoaded: (state, listing = '') => getPagesLoaded(state, listing, Context.listings),
391
+ getQueryParams: (state, listing = '') => getQueryParams(state, listing, Context.listings),
392
+ getQueryParameter: ({
393
+ state,
394
+ facet
395
+ }, key, ifnull) => getQueryParameter({
396
+ state,
397
+ facet,
398
+ context: Context.listings
399
+ }, key, ifnull),
400
+ getRenderableFilters: (state, listing = '') => getRenderableFilters(state, listing, Context.listings),
401
+ getResults: (state, listing = '') => getResults(state, listing, Context.listings, 'js'),
402
+ getSearchTerm,
403
+ getTotalCount: (state, listing = '') => getTotalCount(state, listing, Context.listings),
404
+ getSelectedFilters: (state, listing = '') => getSelectedFilters(state, listing, Context.listings, 'js')
405
+ };
406
+ const selectCurrentPath = state => getImmutableOrJS(state, ['routing', 'currentPath']);
407
+ const selectCurrentProject = state => getImmutableOrJS(state, ['routing', 'currentProject']);
408
+ const selectVersionStatus = state => getImmutableOrJS(state, ['version', 'contensisVersionStatus']);
409
+
410
+ var selectors = /*#__PURE__*/Object.freeze({
411
+ __proto__: null,
412
+ getSearchContext: getSearchContext,
413
+ getCurrent: getCurrent,
414
+ getCurrentFacet: getCurrentFacet,
415
+ getCurrentListing: getCurrentListing,
416
+ getCurrentTab: getCurrentTab,
417
+ getFacets: getFacets,
418
+ getTabFacets: getTabFacets,
419
+ getFacetTitles: getFacetTitles,
420
+ getFacet: getFacet,
421
+ getListing: getListing,
422
+ getFilters: getFilters,
423
+ getRenderableFilters: getRenderableFilters,
424
+ getFiltersToLoad: getFiltersToLoad,
425
+ getSelectedFilters: getSelectedFilters,
426
+ getResults: getResults,
427
+ getIsInternalPaging: getIsInternalPaging,
428
+ getIsLoaded: getIsLoaded,
429
+ getIsLoading: getIsLoading,
430
+ getIsSsr: getIsSsr,
431
+ getFeaturedResults: getFeaturedResults,
432
+ getPaging: getPaging,
433
+ getPageIndex: getPageIndex,
434
+ getPrevPageIndex: getPrevPageIndex,
435
+ getPageIsLoading: getPageIsLoading,
436
+ getPagesLoaded: getPagesLoaded,
437
+ getTotalCount: getTotalCount,
438
+ getSearchTerm: getSearchTerm,
439
+ getSearchTabs: getSearchTabs,
440
+ getQueryParams: getQueryParams,
441
+ getQueryParameter: getQueryParameter,
442
+ getCustomApi: getCustomApi,
443
+ getCustomEnv: getCustomEnv,
444
+ getTabsAndFacets: getTabsAndFacets,
445
+ getSearchTotalCount: getSearchTotalCount,
446
+ getFacetsTotalCount: getFacetsTotalCount,
447
+ selectFacets: selectFacets,
448
+ selectListing: selectListing,
449
+ selectCurrentPath: selectCurrentPath,
450
+ selectCurrentProject: selectCurrentProject,
451
+ selectVersionStatus: selectVersionStatus
452
+ });
453
+
454
+ const now = () => {
455
+ if (typeof window == 'undefined') {
456
+ return Date.now();
457
+ }
458
+
459
+ return window.performance.now();
460
+ };
461
+
462
+ const getClientConfig = (project, env) => {
463
+ let config = DELIVERY_API_CONFIG;
464
+ /* global DELIVERY_API_CONFIG */
465
+
466
+ if (project) {
467
+ config.projectId = project;
468
+ }
469
+
470
+ if (typeof window != 'undefined' && PROXY_DELIVERY_API
471
+ /* global PROXY_DELIVERY_API */
472
+ ) {
473
+ // ensure a relative url is used to bypass the need for CORS (separate OPTIONS calls)
474
+ config.rootUrl = env || '';
475
+ config.responseHandler = {
476
+ 404: () => null
477
+ };
478
+ }
479
+
480
+ return config;
481
+ };
482
+
483
+ class CacheNode {
484
+ constructor(key, value) {
485
+ this.key = key;
486
+ this.value = value;
487
+ this.next = null;
488
+ this.prev = null;
489
+ }
490
+
491
+ }
492
+
493
+ class LruCache {
494
+ constructor(limit = 100) {
495
+ this.map = {};
496
+ this.head = null;
497
+ this.tail = null;
498
+ this.limit = limit || 100;
499
+ this.size = 0;
500
+ }
501
+
502
+ get(key) {
503
+ if (this.map[key]) {
504
+ let value = this.map[key].value;
505
+ let node = new CacheNode(key, value);
506
+ this.remove(key);
507
+ this.setHead(node);
508
+ return value;
509
+ }
510
+ }
511
+
512
+ set(key, value) {
513
+ let node = new CacheNode(key, value);
514
+
515
+ if (this.map[key]) {
516
+ this.remove(key);
517
+ } else {
518
+ if (this.size >= this.limit) {
519
+ delete this.map[this.tail.key];
520
+ this.size--;
521
+ this.tail = this.tail.prev;
522
+ this.tail.next = null;
523
+ }
524
+ }
525
+
526
+ this.setHead(node);
527
+ }
528
+
529
+ setHead(node) {
530
+ node.next = this.head;
531
+ node.prev = null;
532
+
533
+ if (this.head) {
534
+ this.head.prev = node;
535
+ }
536
+
537
+ this.head = node;
538
+
539
+ if (!this.tail) {
540
+ this.tail = node;
541
+ }
542
+
543
+ this.size++;
544
+ this.map[node.key] = node;
545
+ }
546
+
547
+ remove(key) {
548
+ let node = this.map[key];
549
+
550
+ if (node.prev) {
551
+ node.prev.next = node.next;
552
+ } else {
553
+ this.head = node.next;
554
+ }
555
+
556
+ if (node.next) {
557
+ node.next.prev = node.prev;
558
+ } else {
559
+ this.tail = node.prev;
560
+ }
561
+
562
+ delete this.map[key];
563
+ this.size--;
564
+ }
565
+
566
+ }
567
+
568
+ class CachedSearch {
569
+ constructor() {
570
+ this.cache = new LruCache();
571
+ this.taxonomyLookup = {};
572
+ }
573
+
574
+ search(query, linkDepth, project, env) {
575
+ const client = Client.create(getClientConfig(project, env));
576
+ return this.request(project + JSON.stringify(query) + linkDepth.toString(), () => client.entries.search(query, linkDepth));
577
+ }
578
+
579
+ getTaxonomyNodeByPath(path, project, env) {
580
+ const client = Client.create(getClientConfig(project, env));
581
+ return this.request(`[TAXONOMY NODE] ${path}`, () => client.taxonomy.getNodeByPath({
582
+ path: path,
583
+ order: 'defined',
584
+ childDepth: 2
585
+ }).then(node => this.extendTaxonomyNode(node)));
586
+ }
587
+
588
+ request(key, execute) {
589
+ if (!this.cache.get(key) || typeof window == 'undefined') {
590
+ let promise = execute();
591
+ this.cache.set(key, promise);
592
+ promise.catch(() => {
593
+ this.cache.remove(key);
594
+ });
595
+ }
596
+
597
+ return this.cache.get(key);
598
+ }
599
+
600
+ extendTaxonomyNode(node) {
601
+ let id = this.getTaxonomyId(node);
602
+ this.taxonomyLookup[id] = node.key;
603
+ return { ...node,
604
+ id,
605
+ children: node.children ? node.children.map(n => this.extendTaxonomyNode(n)) : null
606
+ };
607
+ }
608
+
609
+ getTaxonomyId(node) {
610
+ if (node.key) {
611
+ let parts = node.key.split('/');
612
+ return parts[parts.length - 1];
613
+ }
614
+
615
+ return '';
616
+ }
617
+
618
+ fetch(uri, opts = {}) {
619
+ return this.request(`[FETCH] ${uri} ${JSON.stringify(opts)}`, () => fetch(uri, opts));
620
+ }
621
+
622
+ }
623
+
624
+ const cachedSearch = new CachedSearch();
625
+
626
+ // eslint-disable-next-line import/default
627
+ function fixFreeTextForElastic(s) {
628
+ const illegalChars = ['>', '<', '=', '|', '!', '{', '}', '[', ']', '^', '~', '*', '?', ':', '\\', '/'];
629
+ const illegalRegEx = new RegExp(illegalChars.map(c => '\\' + c).join('|'), 'g');
630
+ s = s.replace(illegalRegEx, ''); // s = s.replace(encodedRegEx, ''); // (m) => '\\\\' + m);
631
+
632
+ return s;
633
+ }
634
+ const timedSearch = async (query, linkDepth = 0, projectId, env) => {
635
+ if (!query) return null;
636
+ let duration = 0;
637
+ const start = now();
638
+ const payload = await cachedSearch.search(query, linkDepth, projectId, env);
639
+ const end = now();
640
+ duration = end - start;
641
+ return {
642
+ duration,
643
+ payload
644
+ };
645
+ };
646
+ const getItemsFromResult = result => {
647
+ const {
648
+ payload
649
+ } = result || {};
650
+
651
+ if (payload) {
652
+ if (Array.isArray(payload)) return payload;
653
+ if (Array.isArray(payload.items)) return payload.items;
654
+ return payload;
655
+ }
656
+
657
+ return [];
658
+ };
659
+ const extractQuotedPhrases = searchTerm => {
660
+ const pattern = new RegExp(/(?=["'])(?:"[^"\\]*(?:\\[\s\S][^"\\]*)*"|'[^'\\]*(?:\\[\s\S][^'\\]*)*')/gm);
661
+ return (searchTerm.match(pattern) || []).map(match => match.replace(/"/g, ''));
662
+ };
663
+ const buildUrl = (route, params) => {
664
+ const qs = stringify(params);
665
+ const path = qs ? `${route}${route.includes('?') ? '&' : '?'}${qs}` : route;
666
+ return path;
667
+ };
668
+ /**
669
+ * Returns all params from the current route query string or static route
670
+ * Supply static route argument if reading parameters from the route path
671
+ * Supply location argument for the params to be read in SSR
672
+ * @param staticRoute Matched static route from react-router 5 or 6
673
+ * @param location location object containing at least pathname and search
674
+ * @returns Keyed params object
675
+ */
676
+
677
+ const routeParams = (staticRoute, location) => {
678
+ var _staticRoute$match;
679
+
680
+ // match.params is react-router-config/react-router@5 style
681
+ // params is supplied with RouteObject in react-router@6
682
+ const pathParams = (staticRoute === null || staticRoute === void 0 ? void 0 : (_staticRoute$match = staticRoute.match) === null || _staticRoute$match === void 0 ? void 0 : _staticRoute$match.params) || (staticRoute === null || staticRoute === void 0 ? void 0 : staticRoute.params) || {};
683
+ const queryParams = parse(typeof window !== 'undefined' ? window.location.search : (location === null || location === void 0 ? void 0 : location.search) || '');
684
+ return { ...pathParams,
685
+ ...queryParams
686
+ };
687
+ };
688
+ const callCustomApi = async (customApi, filters) => {
689
+ const apiUri = customApi.uri || '';
690
+ let uri = buildUrl(apiUri, filters);
691
+ if (!uri) throw new Error('uri is required to use customApi');
692
+ if (typeof window == 'undefined' && uri.startsWith('/')) uri = `http://localhost:3001${uri}`;
693
+ const response = await cachedSearch.fetch(uri);
694
+ return await response.clone().json();
695
+ };
696
+ const removeEmptyAttributes = obj => {
697
+ Object.entries(obj).forEach(([key, val]) => val && typeof val === 'object' && removeEmptyAttributes(val) || (typeof val === 'undefined' || val === null || val === '') && delete obj[key]);
698
+ return obj;
699
+ };
700
+ const toArray = (obj, seperator = ',') => typeof obj === 'undefined' || obj === null ? obj : Array.isArray(obj) ? obj : obj.split(seperator); // assumes array elements are primitive types
701
+
702
+ const areArraysEqualSets = (a1, a2) => {
703
+ const superSet = {};
704
+
705
+ for (const ai of a1) {
706
+ const e = ai + typeof ai;
707
+ superSet[e] = 1;
708
+ }
709
+
710
+ for (const ai of a2) {
711
+ const e = ai + typeof ai;
712
+
713
+ if (!superSet[e]) {
714
+ return false;
715
+ }
716
+
717
+ superSet[e] = 2;
718
+ }
719
+
720
+ for (const e in superSet) {
721
+ if (superSet[e] === 1) {
722
+ return false;
723
+ }
724
+ }
725
+
726
+ return true;
727
+ };
728
+
729
+ const searchUriTemplate = {
730
+ path: ({
731
+ state,
732
+ facet,
733
+ pageIndex
734
+ }) => {
735
+ const currentFacet = getSearchContext(state) !== Context.listings && (facet || getCurrentFacet(state));
736
+ const currentPath = selectCurrentPath(state) || '/search';
737
+ const newPath = currentFacet ? `${currentPath}/${currentFacet}` : currentPath;
738
+ if (pageIndex) return `${newPath}/${pageIndex + 1}`;
739
+ return newPath;
740
+ },
741
+ search: ({
742
+ state,
743
+ facet,
744
+ orderBy,
745
+ term
746
+ }) => {
747
+ const searchContext = getSearchContext(state); // Lose stateFilters and currentSearch if a new
748
+ // term is passed via an argument
749
+
750
+ const stateFilters = term ? {} : Object.fromEntries(Object.entries(getSelectedFilters(state, facet, searchContext, 'js')).map(([key, f]) => [key, f === null || f === void 0 ? void 0 : f.join(',')]));
751
+ const currentSearch = !term && getImmutableOrJS(state, ['routing', 'location', 'search']);
752
+ const currentQs = removeEmptyAttributes(parse(currentSearch));
753
+ if (orderBy) currentQs.orderBy = orderBy;
754
+ const searchTerm = getSearchTerm(state); // Merge the stateFilters with any current qs to build the new qs
755
+
756
+ const mergedSearch = removeEmptyAttributes({ ...merge(currentQs, stateFilters),
757
+ term: searchTerm
758
+ });
759
+ return stringify(mergedSearch);
760
+ },
761
+ hash: state => getImmutableOrJS(state, ['routing', 'location', 'hash'], '').replace('#', '')
762
+ };
763
+
764
+ const mapStateToSearchUri = params => mapJson(params, searchUriTemplate);
765
+
766
+ const DataFormats = {
767
+ asset: 'asset',
768
+ entry: 'entry',
769
+ webpage: 'webpage'
770
+ };
771
+ const FilterExpressionTypes = {
772
+ contentType: 'contentType',
773
+ field: 'field'
774
+ };
775
+ const sys = {
776
+ allUris: 'sys.allUris',
777
+ contentTypeId: 'sys.contentTypeId',
778
+ dataFormat: 'sys.dataFormat',
779
+ filename: 'sys.properties.filename',
780
+ id: 'sys.id',
781
+ includeInSearch: 'sys.metadata.includeInSearch',
782
+ language: 'sys.language',
783
+ uri: 'sys.uri',
784
+ versionStatus: 'sys.versionStatus'
785
+ };
786
+ const Fields = {
787
+ entryDescription: 'entryDescription',
788
+ entryTitle: 'entryTitle',
789
+ keywords: 'keywords',
790
+ searchContent: 'searchContent',
791
+ sys,
792
+ contentTypeId: 'sys.contentTypeId',
793
+ wildcard: '*'
794
+ };
795
+
796
+ const fieldExpression = (field, value, operator = 'equalTo', weight) => {
797
+ if (!field || !value || Array.isArray(value) && value.length === 0) return [];
798
+ if (Array.isArray(field)) // If an array of fieldIds have been provided, call self for each fieldId
799
+ // to generate expressions that are combined with an 'or' operator
800
+ return [Op.or(...field.map(fieldId => fieldExpression(fieldId, value, operator, weight)).flat())];
801
+ if (operator === 'between') return between(field, value);
802
+ if (Array.isArray(value)) return equalToOrIn(field, value, operator);else return !weight ? equalToOrIn(field, value, operator) : [equalToOrIn(field, value, operator)[0].weight(weight)];
803
+ };
804
+ const contentTypeIdExpression = (contentTypeIds, webpageTemplates, assetTypes) => {
805
+ const expressions = [];
806
+ if (!contentTypeIds && !webpageTemplates && !assetTypes) return expressions;
807
+
808
+ if (contentTypeIds && contentTypeIds.length > 0) {
809
+ expressions.push(...dataFormatExpression(contentTypeIds, DataFormats.entry));
810
+ }
811
+
812
+ if (webpageTemplates && webpageTemplates.length > 0) {
813
+ expressions.push(...dataFormatExpression(webpageTemplates, DataFormats.webpage));
814
+ }
815
+
816
+ if (assetTypes && assetTypes.length > 0) {
817
+ expressions.push(...dataFormatExpression(assetTypes, DataFormats.asset));
818
+ }
819
+
820
+ if (expressions.length > 1) return [Op.or(...expressions)];
821
+ return expressions;
822
+ };
823
+ const filterExpressions = (filters, isOptional = false) => {
824
+ if (!filters) return [];
825
+ const expressions = [];
826
+ filters.map(selectedFilter => {
827
+ if (selectedFilter.logicOperator === 'and') // using 'and' logic operator we loop through each filter
828
+ // and loop through all values to add an expression for each filter value
829
+ selectedFilter.values.forEach(value => expressions.push(...fieldExpression(selectedFilter.key, value, selectedFilter.fieldOperator || 'equalTo')));else if (selectedFilter.logicOperator === 'not') {
830
+ const fieldExpressions = fieldExpression(selectedFilter.key, selectedFilter.values, selectedFilter.fieldOperator || 'in');
831
+ fieldExpressions.forEach(expr => {
832
+ expressions.push(Op.not(expr));
833
+ });
834
+ } // using 'or' logic operator we loop over each filter
835
+ // and simply add the array of values to an expression with an 'in' operator
836
+ else expressions.push(...fieldExpression(selectedFilter.key, selectedFilter.values, selectedFilter.fieldOperator || 'in'));
837
+ if (isOptional) expressions.push(Op.not(fieldExpression(selectedFilter.key, true, 'exists')[0]));
838
+ });
839
+ return expressions;
840
+ };
841
+ const dataFormatExpression = (contentTypeIds, dataFormat = DataFormats.entry) => {
842
+ if (contentTypeIds && contentTypeIds.length > 0) {
843
+ /**
844
+ * We have an array of contentTypeIds some may be prefixed with a "!"
845
+ * to indicate this is a "not" expression
846
+ */
847
+ const withContentTypeIds = contentTypeIds.filter(c => !c.startsWith('!'));
848
+ const notContentTypeIds = contentTypeIds.filter(c => c.startsWith('!')).map(id => id.substring(1));
849
+ const andExpr = Op.and();
850
+ const dataFormatExpr = fieldExpression(Fields.sys.dataFormat, dataFormat)[0];
851
+ const withExpr = fieldExpression(Fields.sys.contentTypeId, withContentTypeIds)[0];
852
+ const notExpr = Op.not(fieldExpression(Fields.sys.contentTypeId, notContentTypeIds)[0]);
853
+ andExpr.add(dataFormatExpr);
854
+ if (withContentTypeIds.length > 0 && withExpr) andExpr.add(withExpr);
855
+ if (notContentTypeIds.length > 0 && notExpr) andExpr.add(notExpr);
856
+ return [andExpr];
857
+ }
858
+
859
+ return [];
860
+ };
861
+ const featuredResultsExpression = ({
862
+ contentTypeId,
863
+ fieldId,
864
+ fieldValue = true
865
+ } = {}) => {
866
+ const expressions = [];
867
+
868
+ if (contentTypeId) {
869
+ expressions.push(...contentTypeIdExpression(Array.isArray(contentTypeId) ? contentTypeId : [contentTypeId]));
870
+ }
871
+
872
+ if (fieldId && fieldValue) {
873
+ expressions.push(...fieldExpression(fieldId, fieldValue));
874
+ }
875
+
876
+ return expressions;
877
+ };
878
+ const languagesExpression = languages => fieldExpression(Fields.sys.language, languages);
879
+ const includeInSearchExpressions = (webpageTemplates, includeInSearchFields) => {
880
+ const expressions = []; // Or include this expression if we have explicity specified non-default includeInSearch fields
881
+
882
+ if (Array.isArray(includeInSearchFields)) expressions.push(...includeInSearchFields.map(includeInSearchField => Op.or(Op.and(Op.exists(includeInSearchField, true), Op.equalTo(includeInSearchField, true)), Op.exists(includeInSearchField, false)))); // If webpageTemplates have been specified, include this expression
883
+ // with the default includeInSearch field from classic Contensis.
884
+
885
+ if (Array.isArray(webpageTemplates) && webpageTemplates.length > 0) expressions.push(Op.or(Op.and(Op.exists(Fields.sys.includeInSearch, true), Op.equalTo(Fields.sys.includeInSearch, true)), Op.exists(Fields.sys.includeInSearch, false)));
886
+ return expressions;
887
+ };
888
+ const defaultExpressions = versionStatus => {
889
+ return [Op.equalTo(Fields.sys.versionStatus, versionStatus)];
890
+ };
891
+ const includeIdsExpression = includeIds => {
892
+ if (Array.isArray(includeIds) && includeIds.length > 0) {
893
+ return fieldExpression(Fields.sys.id, includeIds);
894
+ } else return [];
895
+ };
896
+ const excludeIdsExpression = excludeIds => {
897
+ if (Array.isArray(excludeIds) && excludeIds.length > 0) {
898
+ const [expr] = fieldExpression(Fields.sys.id, excludeIds);
899
+ return [Op.not(expr)];
900
+ } else return [];
901
+ };
902
+ const orderByExpression = orderBy => {
903
+ let expression;
904
+
905
+ if (orderBy && orderBy.length > 0) {
906
+ expression = OrderBy;
907
+
908
+ for (const ob of orderBy) {
909
+ var _expression, _expression2;
910
+
911
+ expression = ob.startsWith('-') ? (_expression = expression) === null || _expression === void 0 ? void 0 : _expression.desc(ob.substring(1)) : (_expression2 = expression) === null || _expression2 === void 0 ? void 0 : _expression2.asc(ob);
912
+ }
913
+ }
914
+
915
+ return expression;
916
+ };
917
+
918
+ const equalToOrIn = (field, value, operator = 'equalTo') => {
919
+ if (value.length === 0) return [];
920
+
921
+ if (Array.isArray(value)) {
922
+ if (operator === 'equalTo' || operator === 'in') return [Op.in(field, ...value)];
923
+ const expressions = value.map(innerValue => {
924
+ var _between, _distanceWithin;
925
+
926
+ switch (operator) {
927
+ case 'between':
928
+ return (_between = between(field, innerValue)) === null || _between === void 0 ? void 0 : _between[0];
929
+
930
+ case 'distanceWithin':
931
+ return (_distanceWithin = distanceWithin(field, innerValue)) === null || _distanceWithin === void 0 ? void 0 : _distanceWithin[0];
932
+
933
+ case 'exists':
934
+ return Op.exists(field, innerValue);
935
+
936
+ case 'freeText':
937
+ // TODO: Potentially needs further implementation of new options
938
+ return Op[operator](field, innerValue, false, undefined);
939
+
940
+ default:
941
+ return Op[operator](field, innerValue);
942
+ }
943
+ });
944
+ return (expressions === null || expressions === void 0 ? void 0 : expressions.length) > 1 ? [Op.or(...expressions)] : expressions || [];
945
+ }
946
+
947
+ switch (operator) {
948
+ case 'between':
949
+ return between(field, value);
950
+
951
+ case 'distanceWithin':
952
+ return distanceWithin(field, value);
953
+
954
+ case 'freeText':
955
+ // TODO: Potentially needs further implementation of new options
956
+ return [Op.freeText(field, value, false, undefined)];
957
+
958
+ default:
959
+ return [Op[operator](field, value)];
960
+ }
961
+ };
962
+
963
+ const between = (field, value) => {
964
+ const handle = betweenValue => {
965
+ const valArr = betweenValue.split('--');
966
+
967
+ if (valArr.length > 1) {
968
+ const [minimum, maximum] = valArr;
969
+ return Op.between(field, minimum, maximum);
970
+ } else {
971
+ // eslint-disable-next-line no-console
972
+ console.log(`[search] You have supplied only one value to a "between" operator which must have two values. Your supplied value "${valArr.length && valArr[0]}" has been discarded.`);
973
+ return false;
974
+ }
975
+ };
976
+
977
+ if (value.length === 0) return [];
978
+ if (Array.isArray(value)) return [Op.or(...value.map(handle).filter(bc => bc !== false))];
979
+ const op = handle(value);
980
+ return op ? [op] : [];
981
+ };
982
+
983
+ const distanceWithin = (field, value) => {
984
+ const handle = distanceValue => {
985
+ const valArr = distanceValue.split(' ');
986
+
987
+ if (valArr.length > 1) {
988
+ const [lat, lon] = valArr;
989
+ return Op.distanceWithin(field, Number(lat), Number(lon), (valArr === null || valArr === void 0 ? void 0 : valArr[2]) || '10mi');
990
+ } else {
991
+ // eslint-disable-next-line no-console
992
+ console.log(`[search] You have supplied only one value to a "distanceWithin" operator which must be made up of "lat,lon,distance". Your supplied value "${valArr.length && valArr[0]}" has been discarded.`);
993
+ return false;
994
+ }
995
+ };
996
+
997
+ if (value.length === 0) return [];
998
+ if (Array.isArray(value)) return [Op.or(...value.map(handle).filter(bc => bc !== false))];
999
+ const op = handle(value);
1000
+ return op ? [op] : [];
1001
+ };
1002
+ /**
1003
+ * Accept HTTP style objects and map them to
1004
+ * their equivalent JS client "Op" expressions
1005
+ * @param {array} where the where array as you'd provide it to the HTTP API
1006
+ * @returns {array} array of constructed Delivery API Operators
1007
+ */
1008
+
1009
+
1010
+ const customWhereExpressions = where => {
1011
+ if (!where || !Array.isArray(where)) return []; // Map each clause inside the where array
1012
+
1013
+ return where.map(clause => {
1014
+ let expression; // Map through each property in the clause so we can
1015
+ // capture the values required and reconstruct them as
1016
+ // a Delivery API expression
1017
+
1018
+ let operator;
1019
+ Object.keys(clause).map((key, idx) => {
1020
+ // The clause may contain only one key
1021
+ if (idx === 0) operator = key;
1022
+ const field = clause.field;
1023
+ const value = clause[Object.keys(clause).find(k => !['field', 'weight'].includes(k)) || ''];
1024
+ const weight = clause.weight;
1025
+
1026
+ if (idx === 0) {
1027
+ if (operator === 'and' || operator === 'or') {
1028
+ // These are array expressions so we can call ourself recursively
1029
+ // to map these inner values to expressions
1030
+ const recurseExpr = customWhereExpressions(clause[operator]);
1031
+ expression = Op[operator](...recurseExpr);
1032
+ }
1033
+
1034
+ if (['not'].includes(operator)) {
1035
+ // A 'not' expression is an object with only one inner field and inner operator
1036
+ Object.keys(value).map((notKey, notIdx) => {
1037
+ const innerOperator = notKey;
1038
+ const innerValue = value[notKey];
1039
+ const innerField = value.field; // Map the expression when we've looped and scoped to
1040
+ // the second property inside the clause
1041
+
1042
+ if (notIdx === 1) expression = Op.not(makeJsExpression(innerOperator, innerField, innerValue));
1043
+ });
1044
+ }
1045
+ } // Map the expression when we've looped and scoped to
1046
+ // the second property inside the clause
1047
+
1048
+
1049
+ operator = Object.keys(clause).find(clauseKey => !['field', 'weight'].includes(clauseKey));
1050
+
1051
+ if (idx === 1) {
1052
+ expression = makeJsExpression(operator, field, value);
1053
+ if (typeof weight === 'number') expression = expression.weight(weight);
1054
+ }
1055
+ });
1056
+ return expression;
1057
+ });
1058
+ };
1059
+
1060
+ const makeJsExpression = (operator, field, value) => operator === 'freeText' || operator === 'contains' ? Op[operator](field, value) : operator === 'in' ? Op[operator](field, ...value) : operator === 'exists' ? Op[operator](field, value) : operator === 'between' ? Op[operator](field, value[0], value[1]) : operator === 'distanceWithin' ? Op[operator](field, value === null || value === void 0 ? void 0 : value.lat, value === null || value === void 0 ? void 0 : value.lon, value === null || value === void 0 ? void 0 : value.distance) : Op[operator](field, value);
1061
+
1062
+ const termExpressions = (searchTerm, weightedSearchFields) => {
1063
+ if (searchTerm && weightedSearchFields && weightedSearchFields.length > 0) {
1064
+ // Extract any phrases in quotes to array
1065
+ const quotedPhrases = extractQuotedPhrases(searchTerm); // Modify the search term to remove any quoted phrases to leave any remaining terms
1066
+
1067
+ let modifiedSearchTerm = searchTerm;
1068
+ quotedPhrases.forEach(qp => modifiedSearchTerm = modifiedSearchTerm.replace(qp, '').replace('""', '').trim()); // Push to the operators array to include in the query
1069
+
1070
+ const operators = []; // Helper functions to generate Op expressions
1071
+
1072
+ const containsOp = (f, term) => fieldExpression(f.fieldId, fixFreeTextForElastic(term), 'contains', f.weight);
1073
+
1074
+ const freeTextOp = (f, term) => fieldExpression(f.fieldId, fixFreeTextForElastic(term), 'freeText', f.weight); // For each weighted search field
1075
+
1076
+
1077
+ weightedSearchFields.forEach(wsf => {
1078
+ // Push to field operators
1079
+ const fieldOperators = []; // Add operator expressions for modified search term
1080
+
1081
+ if (modifiedSearchTerm) {
1082
+ if ([Fields.keywords, Fields.sys.filename, Fields.sys.uri].includes(wsf.fieldId)) {
1083
+ fieldOperators.push(...containsOp(wsf, modifiedSearchTerm));
1084
+ } else {
1085
+ if ([Fields.entryTitle].includes(wsf.fieldId)) {
1086
+ fieldOperators.push(Op.or(...containsOp(wsf, modifiedSearchTerm), ...freeTextOp(wsf, modifiedSearchTerm)));
1087
+ } else {
1088
+ fieldOperators.push(...freeTextOp(wsf, modifiedSearchTerm));
1089
+ }
1090
+ }
1091
+ } // Add operator expressions for any quoted phrases
1092
+
1093
+
1094
+ quotedPhrases.forEach(qp => fieldOperators.push(...containsOp(wsf, qp))); // If we are using multiple operators for a field we will
1095
+ // wrap each field inside an And operator so we will match
1096
+ // all terms/phrases rather than any terms/phrases
1097
+
1098
+ if (fieldOperators.length > 1) {
1099
+ operators.push(Op.and(...fieldOperators));
1100
+ } else {
1101
+ operators.push(...fieldOperators);
1102
+ }
1103
+ }); // Wrap operators in an Or operator
1104
+
1105
+ return [Op.or().addRange(operators).add(Op.freeText(Fields.searchContent, searchTerm))];
1106
+ } else if (searchTerm) {
1107
+ // Searching without weightedSearchFields defined will fall back
1108
+ // to a default set of search fields with arbritary weights set.
1109
+ return [Op.or(Op.equalTo(Fields.entryTitle, searchTerm).weight(10), Op.freeText(Fields.entryTitle, searchTerm).weight(2), Op.freeText(Fields.entryDescription, searchTerm).weight(2), Op.contains(Fields.keywords, searchTerm).weight(2), Op.contains(Fields.sys.uri, searchTerm).weight(2), Op.contains(Fields.sys.allUris, searchTerm), Op.freeText(Fields.searchContent, searchTerm))];
1110
+ } else {
1111
+ return [];
1112
+ }
1113
+ };
1114
+
1115
+ var expressions = /*#__PURE__*/Object.freeze({
1116
+ __proto__: null,
1117
+ fieldExpression: fieldExpression,
1118
+ contentTypeIdExpression: contentTypeIdExpression,
1119
+ filterExpressions: filterExpressions,
1120
+ dataFormatExpression: dataFormatExpression,
1121
+ featuredResultsExpression: featuredResultsExpression,
1122
+ languagesExpression: languagesExpression,
1123
+ includeInSearchExpressions: includeInSearchExpressions,
1124
+ defaultExpressions: defaultExpressions,
1125
+ includeIdsExpression: includeIdsExpression,
1126
+ excludeIdsExpression: excludeIdsExpression,
1127
+ orderByExpression: orderByExpression,
1128
+ customWhereExpressions: customWhereExpressions,
1129
+ termExpressions: termExpressions
1130
+ });
1131
+
1132
+ const filterQuery = (contentTypeIds, versionStatus, customWhere) => {
1133
+ const query = new Query(...[...contentTypeIdExpression(contentTypeIds), ...defaultExpressions(versionStatus), ...customWhereExpressions(customWhere)]);
1134
+ query.orderBy = OrderBy.asc(Fields.entryTitle);
1135
+ query.pageSize = 100;
1136
+ return query;
1137
+ };
1138
+ const searchQuery = ({
1139
+ assetTypes,
1140
+ contentTypeIds,
1141
+ customWhere,
1142
+ dynamicOrderBy,
1143
+ excludeIds,
1144
+ featuredResults,
1145
+ fields,
1146
+ filters,
1147
+ includeInSearchFields,
1148
+ languages,
1149
+ pageSize,
1150
+ pageIndex,
1151
+ orderBy,
1152
+ searchTerm,
1153
+ versionStatus,
1154
+ webpageTemplates,
1155
+ weightedSearchFields
1156
+ }, isFeatured = false) => {
1157
+ let expressions = [...termExpressions(searchTerm, weightedSearchFields), ...defaultExpressions(versionStatus), ...includeInSearchExpressions(webpageTemplates, includeInSearchFields), ...languagesExpression(languages), ...customWhereExpressions(customWhere), ...excludeIdsExpression(excludeIds)];
1158
+ if (isFeatured) expressions = [...expressions, ...featuredResultsExpression(featuredResults)];
1159
+ if (!isFeatured || featuredResults && !featuredResults.contentTypeId) expressions = [...expressions, ...filterExpressions(filters), ...contentTypeIdExpression(contentTypeIds, webpageTemplates, assetTypes)];
1160
+ const query = new Query(...expressions);
1161
+ if (!searchTerm) query.orderBy = orderByExpression(orderBy);
1162
+ if (dynamicOrderBy && dynamicOrderBy.length) query.orderBy = orderByExpression(dynamicOrderBy);
1163
+
1164
+ if (fields && fields.length > 0 && !isFeatured) {
1165
+ query.fields = fields;
1166
+ }
1167
+
1168
+ query.pageIndex = isFeatured ? 0 : pageIndex;
1169
+ query.pageSize = isFeatured && typeof featuredResults.count === 'number' ? featuredResults.count : pageSize;
1170
+ return query;
1171
+ };
1172
+
1173
+ var queries = /*#__PURE__*/Object.freeze({
1174
+ __proto__: null,
1175
+ filterQuery: filterQuery,
1176
+ searchQuery: searchQuery
1177
+ });
1178
+
1179
+ const mapEntriesToSearchResults = ({
1180
+ mappers,
1181
+ mapper,
1182
+ context,
1183
+ facet
1184
+ }, items, state) => {
1185
+ const mapperFunc = mapper || mappers && mappers.results;
1186
+ return items && typeof mapperFunc === 'function' ? mapperFunc(items, facet, context, state) : [];
1187
+ };
1188
+
1189
+ const facetTemplate = {
1190
+ type: () => SET_SEARCH_ENTRIES,
1191
+ context: 'action.context',
1192
+ facet: 'action.facet',
1193
+ mappers: 'action.mappers',
1194
+ nextFacet: {
1195
+ entries: {
1196
+ isLoading: () => false,
1197
+ isError: () => false
1198
+ },
1199
+ featuredEntries: {
1200
+ isLoading: () => false,
1201
+ isError: () => false
1202
+ },
1203
+ featuredResults: ({
1204
+ action,
1205
+ featuredResult,
1206
+ state
1207
+ }) => mapEntriesToSearchResults(action, getItemsFromResult(featuredResult), state),
1208
+ queryDuration: 'result.duration',
1209
+ pagingInfo: {
1210
+ isLoading: () => false,
1211
+ pageCount: {
1212
+ $path: 'result.payload.pageCount',
1213
+ $default: 0
1214
+ },
1215
+ totalCount: {
1216
+ $path: 'result.payload.totalCount',
1217
+ $default: 0
1218
+ },
1219
+ pageSize: {
1220
+ $path: 'result.payload.pageSize',
1221
+ $default: 0
1222
+ },
1223
+ pageIndex: 'pageIndex',
1224
+ pagesLoaded: {
1225
+ $path: 'action.queryParams',
1226
+ $formatting: ({
1227
+ pageIndex,
1228
+ pagesLoaded
1229
+ }) => {
1230
+ const loaded = [...(pagesLoaded || [])];
1231
+
1232
+ if (isNaN(loaded.find(l => l === pageIndex))) {
1233
+ loaded.push(pageIndex);
1234
+ }
1235
+
1236
+ return loaded.sort((a, b) => a - b);
1237
+ }
1238
+ },
1239
+ prevPageIndex: 'action.queryParams.prevPageIndex'
1240
+ },
1241
+ preloaded: {
1242
+ $path: 'preload',
1243
+ $default: false
1244
+ },
1245
+ results: ({
1246
+ action,
1247
+ pageIndex,
1248
+ result,
1249
+ prevResults,
1250
+ state
1251
+ }) => {
1252
+ const {
1253
+ loadMorePaging,
1254
+ pagesLoaded,
1255
+ prevPageIndex
1256
+ } = action.queryParams;
1257
+ const results = mapEntriesToSearchResults(action, getItemsFromResult(result), state);
1258
+ if (!loadMorePaging) return results; // add a _pageIndex property to the returned results to help us later
1259
+
1260
+ const nextResults = results.map((r, idx) => ({
1261
+ _pageIndex: pageIndex,
1262
+ _pagePosition: idx,
1263
+ ...r
1264
+ }));
1265
+ const loadedPages = pagesLoaded || []; // if pageIndex is found in loadedPages, we have already loaded this page
1266
+
1267
+ if (!isNaN(loadedPages.find(l => l === pageIndex))) return prevResults; // Determine where we put the results depending on if we
1268
+ // are paging forwards, backwards, or doing a new search
1269
+
1270
+ const firstResultSet = pageIndex > prevPageIndex ? prevResults || [] : nextResults;
1271
+ const secondResultSet = pageIndex > prevPageIndex ? nextResults : prevResults || [];
1272
+ const onlyResultSet = loadedPages.length === 0 ? nextResults : false;
1273
+ return onlyResultSet || [...firstResultSet, ...secondResultSet];
1274
+ }
1275
+ },
1276
+ preload: 'action.preload',
1277
+ ogState: 'action.ogState',
1278
+ debug: 'action.debug'
1279
+ };
1280
+ const filterTemplate = {
1281
+ type: ({
1282
+ type
1283
+ }) => type || LOAD_FILTERS_COMPLETE,
1284
+ context: 'context',
1285
+ facetKey: 'facetKey',
1286
+ filterKey: 'filterKey',
1287
+ nextFilter: {
1288
+ isLoading: () => false,
1289
+ isError: ({
1290
+ type
1291
+ }) => type === LOAD_FILTERS_ERROR,
1292
+ items: ({
1293
+ payload,
1294
+ selectedKeys,
1295
+ mapper
1296
+ }) => {
1297
+ if (payload && (payload.items || payload.children)) {
1298
+ const items = (payload.items || payload.children).map(item => {
1299
+ var _item$sys;
1300
+
1301
+ item.isSelected = selectedKeys === null || selectedKeys === void 0 ? void 0 : selectedKeys.includes((item === null || item === void 0 ? void 0 : (_item$sys = item.sys) === null || _item$sys === void 0 ? void 0 : _item$sys.id) || item.key);
1302
+ return item;
1303
+ });
1304
+ return mapper(items);
1305
+ }
1306
+
1307
+ return [];
1308
+ }
1309
+ },
1310
+ error: {
1311
+ $path: 'error',
1312
+ $disable: e => !e
1313
+ }
1314
+ };
1315
+
1316
+ const filterExpressionMapper = {
1317
+ // Expression type: so we can identify how to build the query
1318
+ expressionType: ({
1319
+ contentTypeId
1320
+ }) => contentTypeId ? FilterExpressionTypes.contentType : FilterExpressionTypes.field,
1321
+ // Key: so we can target the query to a specific field
1322
+ key: 'fieldId',
1323
+ // Value: so we can filter a specific field by an array of values
1324
+ // e.g. taxonomy key or contentTypeId array
1325
+ values: 'selectedValues',
1326
+ fieldOperator: 'fieldOperator',
1327
+ logicOperator: 'logicOperator'
1328
+ };
1329
+
1330
+ const mapFilterToFilterExpression = filter => mapJson(filter, filterExpressionMapper);
1331
+
1332
+ const mapFiltersToFilterExpression = (filters, selectedFilters) => {
1333
+ if (!selectedFilters || Object.keys(selectedFilters).length === 0) return [];
1334
+ const filterExpressions = []; // Iterate through the keys in selectedFilters and locate
1335
+ // the items that are selected and queryable
1336
+
1337
+ Object.entries(selectedFilters).map(([fkey, selectedValues]) => {
1338
+ const filter = filters[fkey];
1339
+
1340
+ if (selectedValues && filter) {
1341
+ // Where we have a value for a selectedFilter
1342
+ // and a filter is found for the current key
1343
+ // map the filter to a filterExpression object
1344
+ const expr = mapFilterToFilterExpression({ ...filter,
1345
+ selectedValues
1346
+ });
1347
+ filterExpressions.push(expr);
1348
+ }
1349
+ });
1350
+ return filterExpressions;
1351
+ };
1352
+
1353
+ const queryParamsTemplate = {
1354
+ assetTypes: root => getQueryParameter(root, 'assetTypes', []),
1355
+ contentTypeIds: root => getQueryParameter(root, 'contentTypeIds', []),
1356
+ customWhere: root => getQueryParameter(root, 'customWhere', []),
1357
+ dynamicOrderBy: root => getQueryParameter(root, 'dynamicOrderBy', []),
1358
+ env: ({
1359
+ state,
1360
+ facet,
1361
+ context
1362
+ }) => getCustomEnv(state, facet, context),
1363
+ excludeIds: ({
1364
+ action: {
1365
+ excludeIds
1366
+ }
1367
+ }) => {
1368
+ // Exclude current route entry id from minilist searches or any supplied ids
1369
+ if (excludeIds) return Array.isArray(excludeIds) ? excludeIds : excludeIds.split(',').map(id => id.trim());
1370
+ return null;
1371
+ },
1372
+ featuredResults: root => getQueryParameter(root, 'featuredResults', null),
1373
+ fields: root => getQueryParameter(root, 'fields', []),
1374
+ filters: ({
1375
+ state,
1376
+ facet,
1377
+ context
1378
+ }) => {
1379
+ const stateFilters = getFilters(state, facet, context, 'js');
1380
+ const selectedFilters = getSelectedFilters(state, facet, context, 'js'); // Use another mapping function to map the filter parameters for the query
1381
+
1382
+ const filterParams = mapFiltersToFilterExpression(stateFilters, selectedFilters);
1383
+ return filterParams;
1384
+ },
1385
+ includeInSearchFields: root => getQueryParameter(root, 'includeInSearch', []),
1386
+ internalPageIndex: ({
1387
+ action,
1388
+ state
1389
+ }) => getPageIndex(state, '', action.context),
1390
+ internalPaging: root => getQueryParameter(root, 'internalPaging', false),
1391
+ languages: ({
1392
+ action
1393
+ }) => action.defaultLang ? [action.defaultLang] : [],
1394
+ linkDepth: root => getQueryParameter(root, 'linkDepth', 0),
1395
+ loadMorePaging: root => getQueryParameter(root, 'loadMorePaging', false),
1396
+ orderBy: root => getQueryParameter(root, 'orderBy', []),
1397
+ pageIndex: root => {
1398
+ const {
1399
+ action,
1400
+ state
1401
+ } = root;
1402
+ if (getQueryParameter(root, 'internalPaging', false)) return 0;
1403
+ if (action.type === UPDATE_PAGE_INDEX) return action.params.pageIndex;
1404
+ return !action.preload ? getPageIndex(state, action.facet, action.context) : 0;
1405
+ },
1406
+ pageSize: root => getQueryParameter(root, 'pageSize'),
1407
+ pagesLoaded: ({
1408
+ state,
1409
+ facet,
1410
+ context
1411
+ }) => getPagesLoaded(state, facet, context),
1412
+ prevPageIndex: ({
1413
+ state,
1414
+ facet,
1415
+ context
1416
+ }) => getPrevPageIndex(state, facet, context),
1417
+ projectId: ({
1418
+ state,
1419
+ facet,
1420
+ context
1421
+ }) => {
1422
+ var _getFacet;
1423
+
1424
+ return ((_getFacet = getFacet(state, facet, context)) === null || _getFacet === void 0 ? void 0 : _getFacet.projectId) || selectCurrentProject(state);
1425
+ },
1426
+ searchTerm: root => root.context !== Context.minilist || getQueryParameter(root, 'useSearchTerm', false) ? getSearchTerm(root.state) : '',
1427
+ selectedFilters: ({
1428
+ state,
1429
+ facet,
1430
+ context
1431
+ }) => Object.fromEntries(Object.entries(getSelectedFilters(state, facet, context, 'js')).map(([key, f]) => [key, f === null || f === void 0 ? void 0 : f.join(',')])),
1432
+ versionStatus: ({
1433
+ state
1434
+ }) => selectVersionStatus(state),
1435
+ weightedSearchFields: root => {
1436
+ const wsf = getQueryParameter(root, 'weightedSearchFields', []);
1437
+ const deduped = wsf.filter((v, i, a) => a.findIndex(t => t.fieldId === v.fieldId) === i);
1438
+ return deduped; // return wsf;
1439
+ },
1440
+ webpageTemplates: root => getQueryParameter(root, 'webpageTemplates', [])
1441
+ };
1442
+
1443
+ const mapStateToQueryParams = sourceJson => mapJson(sourceJson, queryParamsTemplate);
1444
+
1445
+ /**
1446
+ * 1, Generates all the parameters required to run the search query.
1447
+ * 2, Tells us if we should run the search.
1448
+ * @param {object} action
1449
+ * @param {AppState} state
1450
+ * @returns [queryParams, runSearch]
1451
+ */
1452
+ const generateQueryParams = (action, state) => {
1453
+ const {
1454
+ context,
1455
+ facet
1456
+ } = action; // Map parameters using state and some additional
1457
+ // inputs from the action
1458
+
1459
+ const queryParams = mapStateToQueryParams({
1460
+ context,
1461
+ facet,
1462
+ action,
1463
+ state
1464
+ });
1465
+ return [queryParams, runSearch(action, state, queryParams)];
1466
+ };
1467
+ /**
1468
+ * Checks if we have already loaded everything we're asking for and tells us to run the search or not
1469
+ * @param action
1470
+ * @param state
1471
+ */
1472
+
1473
+ const runSearch = (action, state, queryParams) => {
1474
+ const {
1475
+ context,
1476
+ defaultLang,
1477
+ facet,
1478
+ ogState = state,
1479
+ preload,
1480
+ ssr
1481
+ } = action;
1482
+ let willRun = false;
1483
+ const facetIsLoaded = defaultLang ? false : getIsLoaded(state, context, facet);
1484
+ const stateParams = { ...getQueryParams(ogState, facet, context)
1485
+ };
1486
+ stateParams.pageIndex = getPageIndex(ogState, facet, context);
1487
+ stateParams.searchTerm = getSearchTerm(ogState);
1488
+
1489
+ if (context === Context.facets && ssr || // context === Context.minilist ||
1490
+ preload || !facetIsLoaded || filterParamsChanged(action) || defaultLang) {
1491
+ willRun = true;
1492
+ } else {
1493
+ // Don't execute the search if the inbound query params
1494
+ // are the same as what we already have in state
1495
+ Object.entries(stateParams).forEach(([param, value]) => {
1496
+ const queryParam = queryParams[param];
1497
+
1498
+ if (JSON.stringify(value) !== JSON.stringify(queryParam)) {
1499
+ willRun = true;
1500
+ }
1501
+ });
1502
+ }
1503
+
1504
+ const internalPaging = getIsInternalPaging(ogState, facet, context);
1505
+
1506
+ if (internalPaging && facetIsLoaded) {
1507
+ willRun = false;
1508
+ }
1509
+
1510
+ return willRun;
1511
+ };
1512
+ /**
1513
+ * This will tell us if filter parameters have been
1514
+ * changed by some external event such as a route change
1515
+ * @param action
1516
+ * @returns true or false
1517
+ */
1518
+
1519
+ const filterParamsChanged = (action, state) => {
1520
+ const {
1521
+ context,
1522
+ facet,
1523
+ params,
1524
+ ogState = state
1525
+ } = action;
1526
+ const selectedFilters = getSelectedFilters(ogState, facet, context, 'js');
1527
+ const paramsChanged = Object.entries(selectedFilters).map(([filterKey, selectedValues]) => {
1528
+ const inboundValues = params && params[filterKey] && params[filterKey].split(',') || [];
1529
+ if (!areArraysEqualSets(selectedValues, inboundValues)) return true;
1530
+ });
1531
+ return paramsChanged.filter(f => f === true).length > 0;
1532
+ };
1533
+ /* eslint-disable no-console */
1534
+
1535
+ const debugExecuteSearch = (action, state) => {
1536
+ const [queryParams, runSearch] = generateQueryParams(action, state);
1537
+ console.log('runSearch', runSearch, 'action', action, 'filterParamsChanged', filterParamsChanged(action, state), 'getIsLoaded(state, context, facet)', getIsLoaded(state, action.context, action.facet));
1538
+ const stateParams = { ...getQueryParams(action.ogState || state, action.facet, action.context),
1539
+ pageIndex: getPageIndex(action.ogState || state, action.facet, action.context),
1540
+ searchTerm: getSearchTerm(action.ogState || state)
1541
+ };
1542
+ console.log(stateParams, queryParams);
1543
+ console.log('getSelectedFilters', getSelectedFilters(action.ogState || state, action.facet, action.context, 'js'), 'params', action.params);
1544
+ };
1545
+ const scrollTop = scrollYPos => {
1546
+ if (typeof window !== 'undefined') window.scrollTo(0, scrollYPos);
1547
+ };
1548
+
1549
+ // Base mapping, fields that are the same across all mappings
1550
+ // to save repeating these elements in every mapper, spread this
1551
+ // into your discrete mappings
1552
+
1553
+ const base = {
1554
+ contentTypeId: Fields.sys.contentTypeId,
1555
+ title: 'entryTitle',
1556
+ key: 'sys.id',
1557
+ path: 'sys.slug',
1558
+ isSelected: 'isSelected'
1559
+ };
1560
+
1561
+ const mapEntriesToFilterItems = entries => {
1562
+ if (!entries) return [];
1563
+ return entries.map(entry => {
1564
+ const template = base;
1565
+
1566
+ if (template) {
1567
+ return mapJson(entry, template);
1568
+ }
1569
+
1570
+ return entry;
1571
+ });
1572
+ };
1573
+
1574
+ const mapQueryParamsToCustomApi = queryParams => {
1575
+ const customApiMapping = {
1576
+ fields: ({
1577
+ fields
1578
+ }) => JSON.stringify(fields),
1579
+ orderBy: 'orderBy',
1580
+ linkDepth: 'linkDepth',
1581
+ pageSize: 'pageSize',
1582
+ pageIndex: 'pageIndex',
1583
+ term: {
1584
+ $path: 'searchTerm',
1585
+ $disable: t => !t
1586
+ },
1587
+ versionStatus: 'versionStatus'
1588
+ };
1589
+ Object.keys(queryParams.selectedFilters).forEach(k => {
1590
+ customApiMapping[k] = {
1591
+ $path: `selectedFilters.${k}`,
1592
+ $disable: f => !f
1593
+ };
1594
+ });
1595
+ return mapJson(queryParams, customApiMapping);
1596
+ };
1597
+
1598
+ const searchSagas = [takeEvery(CLEAR_FILTERS, clearFilters), takeEvery(DO_SEARCH, doSearch), takeEvery(SET_ROUTE_FILTERS, loadFilters), takeEvery(SET_SEARCH_ENTRIES, preloadOtherFacets), takeEvery(UPDATE_CURRENT_FACET, updateCurrentFacet), takeEvery(UPDATE_CURRENT_TAB, updateCurrentTab), takeEvery(UPDATE_PAGE_INDEX, updatePageIndex), takeEvery(UPDATE_SEARCH_TERM, updateSearchTerm), takeEvery(UPDATE_SORT_ORDER, updateSortOrder), takeEvery(UPDATE_SELECTED_FILTERS, applySearchFilter)];
1599
+
1600
+ const toJS = obj => obj && 'toJS' in obj && typeof obj.toJS === 'function' ? obj.toJS() : obj;
1601
+
1602
+ function* setRouteFilters(action) {
1603
+ const {
1604
+ mappers,
1605
+ params,
1606
+ listingType,
1607
+ defaultLang,
1608
+ debug
1609
+ } = action;
1610
+ const context = listingType ? Context.listings : Context.facets;
1611
+ const state = toJS(yield select());
1612
+ const ssr = getIsSsr(state); // Get current facet from params or state
1613
+
1614
+ let currentFacet = params && params.facet || listingType; // Pick the default facet from initialState
1615
+
1616
+ if (!currentFacet) {
1617
+ var _Object$keys;
1618
+
1619
+ const tabs = getSearchTabs(state, 'js');
1620
+ currentFacet = (tabs === null || tabs === void 0 ? void 0 : tabs[0].defaultFacet) || ((_Object$keys = Object.keys(getFacets(state, 'js'))) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0]) || '';
1621
+ }
1622
+
1623
+ const nextAction = {
1624
+ type: SET_ROUTE_FILTERS,
1625
+ context,
1626
+ facet: currentFacet,
1627
+ mappers,
1628
+ params,
1629
+ defaultLang,
1630
+ ssr,
1631
+ debug
1632
+ };
1633
+ yield put(nextAction); // keep track of this state ref for comparing changes to params later
1634
+
1635
+ const ogState = {
1636
+ search: state.search
1637
+ }; // Using call instead of triggering from the put
1638
+ // to allow this exported saga to continue during SSR
1639
+
1640
+ yield call(ensureSearch, { ...nextAction,
1641
+ ogState
1642
+ });
1643
+ }
1644
+ function* doSearch(action) {
1645
+ var _action$params;
1646
+
1647
+ const state = toJS(yield select());
1648
+
1649
+ if (action.config) {
1650
+ // If the action contains a config object, we can add this to the
1651
+ // state at runtime
1652
+ yield put({ ...action,
1653
+ type: APPLY_CONFIG
1654
+ });
1655
+ }
1656
+
1657
+ const nextAction = { ...action,
1658
+ type: SET_SEARCH_FILTERS,
1659
+ ssr: getIsSsr(state),
1660
+ facet: action.facet || ((_action$params = action.params) === null || _action$params === void 0 ? void 0 : _action$params.facet)
1661
+ };
1662
+
1663
+ if (nextAction.facet && (action.config || Object.keys(getFacet(state, nextAction.facet, action.context, 'js')).length > 0)) {
1664
+ yield put(nextAction); // keep track of this state ref for comparing changes to params later
1665
+
1666
+ const ogState = {
1667
+ search: state.search
1668
+ };
1669
+ yield call(ensureSearch, { ...nextAction,
1670
+ ogState
1671
+ });
1672
+ }
1673
+ }
1674
+
1675
+ function* loadFilters(action) {
1676
+ const {
1677
+ facet: facetKey,
1678
+ context,
1679
+ mappers = {}
1680
+ } = action;
1681
+ const filtersToLoad = yield select(getFiltersToLoad, facetKey, context, 'js');
1682
+
1683
+ if (filtersToLoad.length > 0) {
1684
+ yield put({
1685
+ type: LOAD_FILTERS,
1686
+ filtersToLoad,
1687
+ facetKey,
1688
+ context
1689
+ });
1690
+ const selectedKeys = yield select(getSelectedFilters, facetKey, context, 'js');
1691
+ const facet = yield select(getFacet, facetKey, context, 'js');
1692
+ const filters = facet.filters || {};
1693
+ const projectId = facet.projectId;
1694
+ const filtersToLoadSagas = filters && filtersToLoad.map((filterKey = '') => {
1695
+ return call(loadFilter, {
1696
+ facetKey,
1697
+ filterKey,
1698
+ filter: filters[filterKey],
1699
+ projectId,
1700
+ selectedKeys: selectedKeys[filterKey],
1701
+ context,
1702
+ mapper: 'filterItems' in mappers && mappers.filterItems || mapEntriesToFilterItems
1703
+ });
1704
+ });
1705
+ if (filtersToLoadSagas) yield all(filtersToLoadSagas);
1706
+ }
1707
+ }
1708
+
1709
+ function* loadFilter(action) {
1710
+ const {
1711
+ facetKey,
1712
+ filterKey,
1713
+ filter,
1714
+ projectId,
1715
+ selectedKeys,
1716
+ context,
1717
+ mapper
1718
+ } = action;
1719
+ const {
1720
+ contentTypeId,
1721
+ customWhere,
1722
+ path
1723
+ } = filter;
1724
+ const createStateFrom = {
1725
+ type: LOAD_FILTERS_COMPLETE,
1726
+ context,
1727
+ error: undefined,
1728
+ facetKey,
1729
+ filterKey,
1730
+ payload: {},
1731
+ selectedKeys,
1732
+ mapper
1733
+ };
1734
+
1735
+ try {
1736
+ if (contentTypeId) {
1737
+ const versionStatus = yield select(selectVersionStatus);
1738
+ const query = filterQuery(Array.isArray(contentTypeId) ? contentTypeId : [contentTypeId], versionStatus, customWhere);
1739
+ const payload = yield cachedSearch.search(query, 0, projectId);
1740
+ if (!payload) throw new Error('No payload returned by search');
1741
+ if (payload.type === 'error') throw payload;
1742
+ createStateFrom.payload = payload;
1743
+ }
1744
+
1745
+ if (path) {
1746
+ const payload = yield cachedSearch.getTaxonomyNodeByPath(path, projectId);
1747
+ if (!payload) throw new Error(`No payload returned for taxonomy path: '${path}'`);
1748
+ if (payload.type === 'error') throw payload;
1749
+ createStateFrom.payload = payload;
1750
+ }
1751
+ } catch (error) {
1752
+ createStateFrom.type = LOAD_FILTERS_ERROR;
1753
+ createStateFrom.error = error;
1754
+ }
1755
+
1756
+ const nextAction = mapJson(createStateFrom, filterTemplate);
1757
+ yield put(nextAction);
1758
+ }
1759
+
1760
+ function* ensureSearch(action) {
1761
+ const {
1762
+ context,
1763
+ facet,
1764
+ debug
1765
+ } = action;
1766
+
1767
+ try {
1768
+ const state = yield select();
1769
+ const nextAction = { ...action,
1770
+ ogState: action.ogState || {
1771
+ search: state.search
1772
+ }
1773
+ };
1774
+ const [queryParams, runSearch] = generateQueryParams(nextAction, state);
1775
+ if (debug && (debug === true || debug.executeSearch)) debugExecuteSearch(nextAction, state);
1776
+
1777
+ if (runSearch) {
1778
+ yield put({
1779
+ type: EXECUTE_SEARCH,
1780
+ facet,
1781
+ context
1782
+ });
1783
+ yield call(executeSearch, { ...nextAction,
1784
+ context,
1785
+ facet,
1786
+ queryParams,
1787
+ debug
1788
+ });
1789
+ }
1790
+ } catch (error) {
1791
+ // eslint-disable-next-line import/namespace
1792
+ log.error(...['Error running search saga:', error, error.stack]);
1793
+ }
1794
+ }
1795
+
1796
+ function* executeSearch(action) {
1797
+ const {
1798
+ context,
1799
+ facet,
1800
+ queryParams,
1801
+ mappers
1802
+ } = action;
1803
+
1804
+ try {
1805
+ const state = yield select();
1806
+ let result = {};
1807
+ let featuredResult;
1808
+ let featuredQuery;
1809
+ const customApi = getCustomApi(state, facet, context, 'js');
1810
+
1811
+ if (customApi) {
1812
+ const apiParams = typeof mappers === 'object' && typeof mappers.customApi === 'function' && mappers.customApi(queryParams) || mapQueryParamsToCustomApi(queryParams);
1813
+ result.payload = yield callCustomApi(customApi, apiParams);
1814
+ result.duration = 1;
1815
+ } else {
1816
+ if (queryParams.featuredResults) {
1817
+ featuredQuery = searchQuery(queryParams, true);
1818
+ featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env); // eslint-disable-next-line require-atomic-updates
1819
+
1820
+ queryParams.excludeIds = getItemsFromResult(featuredResult).map(fi => {
1821
+ var _fi$sys;
1822
+
1823
+ return fi === null || fi === void 0 ? void 0 : (_fi$sys = fi.sys) === null || _fi$sys === void 0 ? void 0 : _fi$sys.id;
1824
+ }).filter(fi => typeof fi === 'string');
1825
+ }
1826
+
1827
+ const query = searchQuery(queryParams);
1828
+ result = yield timedSearch(query, queryParams.linkDepth, queryParams.projectId, queryParams.env);
1829
+ }
1830
+
1831
+ const createStateFrom = {
1832
+ action,
1833
+ featuredResult,
1834
+ pageIndex: queryParams.internalPaging && queryParams.internalPageIndex || queryParams.pageIndex,
1835
+ prevResults: getResults(state, facet, action.context, 'js'),
1836
+ result,
1837
+ state
1838
+ };
1839
+ const nextAction = mapJson(createStateFrom, facetTemplate);
1840
+ yield put(nextAction);
1841
+ } catch (error) {
1842
+ // eslint-disable-next-line import/namespace
1843
+ log.error(...['Error running search saga:', error, error.stack]);
1844
+ }
1845
+ }
1846
+
1847
+ function* preloadOtherFacets(action) {
1848
+ const {
1849
+ preload,
1850
+ context,
1851
+ facet,
1852
+ debug
1853
+ } = action;
1854
+ const state = yield select();
1855
+ const currentFacet = getCurrentFacet(state);
1856
+
1857
+ if (!preload && facet === currentFacet && context !== Context.listings) {
1858
+ const allFacets = getFacets(state, 'js');
1859
+ const otherFacets = Object.keys(allFacets).filter(f => f !== currentFacet);
1860
+ yield all(otherFacets.map((preloadFacet = '') => {
1861
+ const preloadAction = { ...action,
1862
+ facet: preloadFacet,
1863
+ preload: true
1864
+ };
1865
+ const [queryParams, runSearch] = generateQueryParams(preloadAction, state);
1866
+ if (debug && (debug === true || debug.preloadOtherFacets)) debugExecuteSearch(preloadAction, state);
1867
+ return runSearch && call(executeSearch, { ...action,
1868
+ type: EXECUTE_SEARCH_PRELOAD,
1869
+ preload: true,
1870
+ facet: preloadFacet,
1871
+ queryParams
1872
+ });
1873
+ }));
1874
+ }
1875
+ }
1876
+
1877
+ function* updateCurrentTab(action) {
1878
+ const {
1879
+ id,
1880
+ mappers
1881
+ } = action;
1882
+ const state = yield select();
1883
+ const facets = getFacets(state, 'js');
1884
+ const tabs = getSearchTabs(state, 'js');
1885
+ let nextFacet = tabs === null || tabs === void 0 ? void 0 : tabs[id].currentFacet;
1886
+
1887
+ if (!nextFacet) {
1888
+ Object.entries(facets).map(([facetName, facet]) => {
1889
+ if (facet.tabId === id && (tabs === null || tabs === void 0 ? void 0 : tabs[id].defaultFacet) === facetName) nextFacet = facetName;
1890
+ });
1891
+ } // If the next Tab does not have a defaultFacet,
1892
+ // take the first facet for that tab
1893
+
1894
+
1895
+ if (!nextFacet) nextFacet = Object.entries(facets).filter(([, f]) => f.tabId === id)[0][0];
1896
+ yield put(withMappers(updateCurrentFacet$1(nextFacet), mappers));
1897
+ }
1898
+
1899
+ function* clearFilters(action) {
1900
+ const {
1901
+ mappers
1902
+ } = action;
1903
+ const uri = yield buildUri({}, mappers);
1904
+ yield put(navigate(uri));
1905
+ }
1906
+
1907
+ function* updateCurrentFacet(action) {
1908
+ const {
1909
+ facet,
1910
+ mappers
1911
+ } = action;
1912
+ const pageIndex = yield select(getPageIndex, facet);
1913
+ const uri = yield buildUri({
1914
+ facet,
1915
+ pageIndex
1916
+ }, mappers);
1917
+ yield put(navigate(uri));
1918
+ }
1919
+
1920
+ function* updateSearchTerm(action) {
1921
+ const {
1922
+ term,
1923
+ mappers
1924
+ } = action;
1925
+ const uri = yield buildUri({
1926
+ term
1927
+ }, mappers);
1928
+ yield put(navigate(uri));
1929
+ }
1930
+
1931
+ function* updateSortOrder(action) {
1932
+ const {
1933
+ orderBy,
1934
+ facet,
1935
+ mappers
1936
+ } = action;
1937
+ const uri = yield buildUri({
1938
+ orderBy,
1939
+ facet
1940
+ }, mappers);
1941
+ yield put(navigate(uri));
1942
+ }
1943
+
1944
+ function* updatePageIndex(action) {
1945
+ const {
1946
+ pageIndex,
1947
+ mappers,
1948
+ scrollYPos
1949
+ } = action;
1950
+ const uri = yield buildUri({
1951
+ pageIndex
1952
+ }, mappers);
1953
+ yield put(navigate(uri));
1954
+ if (typeof scrollYPos !== 'undefined') scrollTop(scrollYPos);
1955
+ }
1956
+
1957
+ function* applySearchFilter(action) {
1958
+ const {
1959
+ mappers,
1960
+ scrollYPos
1961
+ } = action;
1962
+ const uri = yield buildUri({}, mappers);
1963
+ yield put(navigate(uri));
1964
+ if (typeof scrollYPos !== 'undefined') scrollTop(scrollYPos);
1965
+ }
1966
+
1967
+ function* buildUri({
1968
+ facet,
1969
+ orderBy,
1970
+ pageIndex = 0,
1971
+ term
1972
+ }, mappers) {
1973
+ const state = yield select();
1974
+ const mapUri = (mappers === null || mappers === void 0 ? void 0 : mappers.navigate) || mapStateToSearchUri;
1975
+ const uri = mapUri({
1976
+ state,
1977
+ facet,
1978
+ orderBy,
1979
+ pageIndex,
1980
+ term
1981
+ }); // return uri;
1982
+
1983
+ return `${uri.path}${uri.search && `?${uri.search}` || ''}${uri.hash && `#${uri.hash}` || ''}`;
1984
+ }
1985
+
1986
+ function* triggerMinilistSsr(options) {
1987
+ yield call(doSearch, {
1988
+ type: DO_SEARCH,
1989
+ ...options
1990
+ });
1991
+ }
1992
+ function* triggerListingSsr(options) {
1993
+ yield call(setRouteFilters, options);
1994
+ }
1995
+ function* triggerSearchSsr(options) {
1996
+ yield call(setRouteFilters, options);
1997
+ }
1998
+
1999
+ export { APPLY_CONFIG as $, clearFilters$1 as A, updateCurrentFacet$1 as B, updateCurrentTab$1 as C, updatePageIndex$1 as D, updateSearchTerm$1 as E, updateSelectedFilters as F, updateSortOrder$1 as G, selectListing as H, mapStateToSearchUri as I, Context as J, selectFacets as K, triggerSearch as L, getFilters as M, toArray as N, UPDATE_SELECTED_FILTERS as O, UPDATE_SEARCH_TERM as P, UPDATE_PAGE_INDEX as Q, SET_SEARCH_ENTRIES as R, SET_SEARCH_FILTERS as S, SET_ROUTE_FILTERS as T, UPDATE_SORT_ORDER as U, LOAD_FILTERS_COMPLETE as V, LOAD_FILTERS_ERROR as W, LOAD_FILTERS as X, EXECUTE_SEARCH_ERROR as Y, EXECUTE_SEARCH as Z, CLEAR_FILTERS as _, customWhereExpressions as a, actions as a0, selectors as a1, types as a2, expressions as a3, queries as a4, doSearch as a5, setRouteFilters as a6, searchSagas as a7, triggerListingSsr as a8, triggerMinilistSsr as a9, triggerSearchSsr as aa, routeParams as ab, getPageIndex as b, contentTypeIdExpression as c, defaultExpressions as d, getCurrentTab as e, filterExpressions as f, getCurrentFacet as g, getFacet as h, getTabFacets as i, getFacetsTotalCount as j, getFacetTitles as k, getFeaturedResults as l, getRenderableFilters as m, getIsLoading as n, orderByExpression as o, getPaging as p, getPageIsLoading as q, getResults as r, getSearchTerm as s, termExpressions as t, getSearchTotalCount as u, getSelectedFilters as v, getQueryParameter as w, getTabsAndFacets as x, getTotalCount as y, withMappers as z };
2000
+ //# sourceMappingURL=sagas-1f2b2aa0.js.map