@zengenti/contensis-react-base 3.0.0-beta.6 → 3.0.0-beta.60

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