@zengenti/contensis-react-base 3.1.0 → 4.0.0-beta.2

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 (114) hide show
  1. package/cjs/{App-7ff737fa.js → App-b56aca04.js} +139 -94
  2. package/cjs/{App-7ff737fa.js.map → App-b56aca04.js.map} +1 -1
  3. package/cjs/{ChangePassword.container-a617190b.js → ChangePassword.container-ae35785e.js} +120 -62
  4. package/{esm/ChangePassword.container-ae0f9ce4.js.map → cjs/ChangePassword.container-ae35785e.js.map} +1 -1
  5. package/cjs/{ContensisDeliveryApi-9e32960d.js → ContensisDeliveryApi-4fcf049d.js} +71 -17
  6. package/{esm/ContensisDeliveryApi-c66b0cc3.js.map → cjs/ContensisDeliveryApi-4fcf049d.js.map} +1 -1
  7. package/cjs/CookieConstants-000427db.js.map +1 -1
  8. package/cjs/RouteLoader-c06dccd5.js +321 -0
  9. package/cjs/RouteLoader-c06dccd5.js.map +1 -0
  10. package/cjs/{ToJs-149fc5e1.js → ToJs-a8d8f3f0.js} +14 -6
  11. package/cjs/{ToJs-149fc5e1.js.map → ToJs-a8d8f3f0.js.map} +1 -1
  12. package/cjs/client.js +52 -22
  13. package/cjs/client.js.map +1 -1
  14. package/cjs/contensis-react-base.js +277 -140
  15. package/cjs/contensis-react-base.js.map +1 -1
  16. package/cjs/forms.js +717 -228
  17. package/cjs/forms.js.map +1 -1
  18. package/cjs/{fromJSLeaveImmer-7c363211.js → fromJSLeaveImmer-e74c673c.js} +4 -1
  19. package/cjs/{fromJSLeaveImmer-7c363211.js.map → fromJSLeaveImmer-e74c673c.js.map} +1 -1
  20. package/cjs/{reducers-9afb5f89.js → reducers-73a03ef4.js} +31 -10
  21. package/cjs/{reducers-9afb5f89.js.map → reducers-73a03ef4.js.map} +1 -1
  22. package/cjs/redux.js +4 -5
  23. package/cjs/redux.js.map +1 -1
  24. package/cjs/routing.js +6 -5
  25. package/cjs/routing.js.map +1 -1
  26. package/cjs/{sagas-e04b94c1.js → sagas-570f23ba.js} +286 -187
  27. package/cjs/{sagas-e04b94c1.js.map → sagas-570f23ba.js.map} +1 -1
  28. package/cjs/search.js +82 -56
  29. package/cjs/search.js.map +1 -1
  30. package/cjs/{selectors-46b689d0.js → selectors-14caa813.js} +6 -1
  31. package/cjs/selectors-14caa813.js.map +1 -0
  32. package/cjs/urls-6fcaf4c6.js.map +1 -1
  33. package/cjs/user.js +9 -4
  34. package/cjs/user.js.map +1 -1
  35. package/cjs/util.js +55 -35
  36. package/cjs/util.js.map +1 -1
  37. package/cjs/{version-79a027cb.js → version-34d91f68.js} +60 -26
  38. package/cjs/version-34d91f68.js.map +1 -0
  39. package/cjs/{version-afd4f77e.js → version-a410c88e.js} +6 -3
  40. package/cjs/{version-afd4f77e.js.map → version-a410c88e.js.map} +1 -1
  41. package/esm/{App-ff944c78.js → App-83107d7e.js} +137 -92
  42. package/esm/{App-ff944c78.js.map → App-83107d7e.js.map} +1 -1
  43. package/esm/{ChangePassword.container-ae0f9ce4.js → ChangePassword.container-76fd5e9b.js} +120 -62
  44. package/{cjs/ChangePassword.container-a617190b.js.map → esm/ChangePassword.container-76fd5e9b.js.map} +1 -1
  45. package/esm/{ContensisDeliveryApi-c66b0cc3.js → ContensisDeliveryApi-fe57a037.js} +71 -17
  46. package/{cjs/ContensisDeliveryApi-9e32960d.js.map → esm/ContensisDeliveryApi-fe57a037.js.map} +1 -1
  47. package/esm/CookieConstants-3d3b6531.js.map +1 -1
  48. package/esm/RouteLoader-29fd689a.js +310 -0
  49. package/esm/RouteLoader-29fd689a.js.map +1 -0
  50. package/esm/{ToJs-ae860aad.js → ToJs-df57f31d.js} +14 -6
  51. package/esm/{ToJs-ae860aad.js.map → ToJs-df57f31d.js.map} +1 -1
  52. package/esm/client.js +52 -23
  53. package/esm/client.js.map +1 -1
  54. package/esm/contensis-react-base.js +272 -137
  55. package/esm/contensis-react-base.js.map +1 -1
  56. package/esm/forms.js +717 -228
  57. package/esm/forms.js.map +1 -1
  58. package/esm/{fromJSLeaveImmer-e2dacd63.js → fromJSLeaveImmer-0114ffcf.js} +4 -1
  59. package/esm/{fromJSLeaveImmer-e2dacd63.js.map → fromJSLeaveImmer-0114ffcf.js.map} +1 -1
  60. package/esm/{reducers-3d5c37d1.js → reducers-aa8cef1e.js} +31 -10
  61. package/esm/{reducers-3d5c37d1.js.map → reducers-aa8cef1e.js.map} +1 -1
  62. package/esm/redux.js +7 -8
  63. package/esm/redux.js.map +1 -1
  64. package/esm/routing.js +3 -5
  65. package/esm/routing.js.map +1 -1
  66. package/esm/{sagas-933a8fc8.js → sagas-07e82e18.js} +239 -139
  67. package/esm/{sagas-933a8fc8.js.map → sagas-07e82e18.js.map} +1 -1
  68. package/esm/search.js +83 -57
  69. package/esm/search.js.map +1 -1
  70. package/esm/{selectors-01074974.js → selectors-691caf02.js} +6 -1
  71. package/esm/selectors-691caf02.js.map +1 -0
  72. package/esm/urls-eac9a747.js.map +1 -1
  73. package/esm/user.js +11 -6
  74. package/esm/user.js.map +1 -1
  75. package/esm/util.js +55 -35
  76. package/esm/util.js.map +1 -1
  77. package/esm/{version-346a9787.js → version-3d9911e2.js} +60 -26
  78. package/esm/version-3d9911e2.js.map +1 -0
  79. package/esm/{version-0fbd1b82.js → version-9f29becb.js} +6 -3
  80. package/esm/{version-0fbd1b82.js.map → version-9f29becb.js.map} +1 -1
  81. package/models/app/App.d.ts +3 -3
  82. package/models/app/pages/VersionInfo/components/VersionInfo.d.ts +5 -3
  83. package/models/redux/appstate.d.ts +2 -3
  84. package/models/redux/store/history.d.ts +2 -2
  85. package/models/routing/components/Loading.d.ts +2 -2
  86. package/models/routing/components/NotFound.d.ts +2 -2
  87. package/models/routing/components/Redirect.d.ts +5 -0
  88. package/models/routing/components/StaticRouteLoader.d.ts +6 -0
  89. package/models/routing/components/Status.d.ts +1 -1
  90. package/models/routing/httpContext.d.ts +7 -0
  91. package/models/routing/index.d.ts +3 -0
  92. package/models/routing/redux/actions.d.ts +2 -3
  93. package/models/routing/routes.d.ts +11 -5
  94. package/models/user/components/Login.d.ts +2 -1
  95. package/models/user/components/LoginForm.d.ts +2 -1
  96. package/models/user/components/LogoutForm.d.ts +2 -1
  97. package/models/user/containers/ChangePassword.container.d.ts +1 -1
  98. package/models/user/containers/ForgotPassword.container.d.ts +1 -1
  99. package/models/user/containers/Login.container.d.ts +1 -1
  100. package/models/user/containers/Registration.container.d.ts +1 -1
  101. package/models/user/hocs/withLogin.d.ts +2 -1
  102. package/models/user/hocs/withRegistration.d.ts +1 -1
  103. package/models/util/ContensisDeliveryApi.d.ts +0 -1
  104. package/models/util/ToJs.d.ts +1 -1
  105. package/models/util/mergeStaticRoutes.d.ts +1 -0
  106. package/package.json +7 -10
  107. package/cjs/RouteLoader-049e81e5.js +0 -203
  108. package/cjs/RouteLoader-049e81e5.js.map +0 -1
  109. package/cjs/selectors-46b689d0.js.map +0 -1
  110. package/cjs/version-79a027cb.js.map +0 -1
  111. package/esm/RouteLoader-02eef6d9.js +0 -197
  112. package/esm/RouteLoader-02eef6d9.js.map +0 -1
  113. package/esm/selectors-01074974.js.map +0 -1
  114. package/esm/version-346a9787.js.map +0 -1
@@ -81,8 +81,7 @@ var types = /*#__PURE__*/Object.freeze({
81
81
  });
82
82
 
83
83
  const withMappers = (action, mappers) => {
84
- return {
85
- ...action,
84
+ return { ...action,
86
85
  mappers
87
86
  };
88
87
  };
@@ -202,47 +201,53 @@ var actions = /*#__PURE__*/Object.freeze({
202
201
  updateSortOrder: updateSortOrder$1
203
202
  });
204
203
 
205
- let Context = /*#__PURE__*/function (Context) {
204
+ exports.Context = void 0; // export type Context = 'facets' | 'listings' | 'minilist';
205
+
206
+ (function (Context) {
206
207
  Context["facets"] = "facets";
207
208
  Context["listings"] = "listings";
208
209
  Context["minilist"] = "minilist";
209
- return Context;
210
- }({});
211
- // export type Context = 'facets' | 'listings' | 'minilist';
210
+ })(exports.Context || (exports.Context = {}));
212
211
 
213
- // Find a fromJS function from global that is dynamically loaded in createStore
214
212
  // or replace with a stub function for non-immutable gets
213
+
215
214
  const makeFromJS = (returnType = globalThis.STATE_TYPE || 'immutable') => {
216
215
  var _immutable, _immutable2;
216
+
217
217
  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;
218
218
  };
219
+
219
220
  const getImmutableOrJS = (state, stateKey, fallbackValue, returnType = globalThis.STATE_TYPE || 'immutable') => {
220
221
  // Find a fromJS function from global that is dynamically loaded in createStore
221
222
  // or replace with a stub function for non-immutable gets
222
223
  const fromJS = makeFromJS(returnType);
224
+
223
225
  if (state && 'get' in state && typeof state.get === 'function' && 'getIn' in state && typeof state.getIn === 'function' && 'toJS' in state && typeof state.toJS === 'function') {
224
226
  if (Array.isArray(stateKey)) return fromJS(state.getIn(stateKey, fallbackValue));
225
227
  return fromJS(state.get(stateKey, fallbackValue));
226
228
  }
229
+
227
230
  if (Array.isArray(stateKey) && state && typeof state === 'object') {
228
231
  const result = mapJson.jpath(stateKey.join('.'), state);
229
232
  if (typeof result === 'undefined') return fallbackValue;
230
233
  return result;
231
234
  }
235
+
232
236
  const result = state && typeof state === 'object' ? state[stateKey] : undefined;
233
237
  if (typeof result === 'undefined') return fallbackValue;
234
238
  return result;
235
239
  };
236
240
 
237
- const getSearchContext = state => getImmutableOrJS(state, ['search', 'context'], Context.facets);
238
- const getCurrent = (state, context = Context.facets) => context === Context.facets ? getCurrentFacet(state) : getCurrentListing(state);
241
+ const getSearchContext = state => getImmutableOrJS(state, ['search', 'context'], exports.Context.facets);
242
+ const getCurrent = (state, context = exports.Context.facets) => context === exports.Context.facets ? getCurrentFacet(state) : getCurrentListing(state);
239
243
  const getCurrentFacet = state => getImmutableOrJS(state, ['search', 'currentFacet']);
240
244
  const getCurrentListing = state => getImmutableOrJS(state, ['search', 'currentListing']);
241
- const getCurrentTab = state => getImmutableOrJS(state, ['search', Context.facets, getCurrentFacet(state), 'tabId'], 0);
242
- const getFacets = (state, returnType) => getImmutableOrJS(state, ['search', Context.facets], {}, returnType);
245
+ const getCurrentTab = state => getImmutableOrJS(state, ['search', exports.Context.facets, getCurrentFacet(state), 'tabId'], 0);
246
+ const getFacets = (state, returnType) => getImmutableOrJS(state, ['search', exports.Context.facets], {}, returnType);
243
247
  const getTabFacets = state => Object.fromEntries(Object.entries(getFacets(state, 'js')).filter(([key]) => getImmutableOrJS(getFacets(state), [key, 'tabId'], 0) === getCurrentTab(state)));
244
248
  const getFacetTitles = state => Object.entries(getFacets(state, 'js')).map(([key, facet = {}]) => {
245
249
  var _facet$pagingInfo;
250
+
246
251
  return {
247
252
  isSelected: getCurrentFacet(state) === key,
248
253
  key,
@@ -250,29 +255,28 @@ const getFacetTitles = state => Object.entries(getFacets(state, 'js')).map(([key
250
255
  totalCount: (_facet$pagingInfo = facet.pagingInfo) === null || _facet$pagingInfo === void 0 ? void 0 : _facet$pagingInfo.totalCount
251
256
  };
252
257
  });
253
- const getFacet = (state, facetName = '', context = Context.facets, returnType) => {
258
+ const getFacet = (state, facetName = '', context = exports.Context.facets, returnType) => {
254
259
  const currentFacet = facetName || getCurrentFacet(state);
255
260
  return getImmutableOrJS(state, ['search', context, currentFacet], {}, returnType);
256
261
  };
257
262
  const getListing = (state, listing = '') => {
258
263
  const currentListing = listing || getCurrentListing(state);
259
- return getImmutableOrJS(state, ['search', Context.listings, currentListing], {});
264
+ return getImmutableOrJS(state, ['search', exports.Context.listings, currentListing], {});
260
265
  };
261
- const getFilters = (state, facet, context = Context.facets, returnType) => {
266
+ const getFilters = (state, facet, context = exports.Context.facets, returnType) => {
262
267
  return getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'filters'], {}, returnType);
263
268
  };
264
- 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));
265
- const getFiltersToLoad = (state, facet, context = Context.facets, returnType) => {
269
+ 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));
270
+ const getFiltersToLoad = (state, facet, context = exports.Context.facets, returnType) => {
266
271
  const filters = getFilters(state, facet, context, returnType);
267
272
  const loadedFilters = Object.entries(filters).map(([key, f = {}]) => [key, (f.items || []).filter(i => {
268
273
  const title = i === null || i === void 0 ? void 0 : i.title;
269
274
  return typeof title !== 'undefined' && !!title;
270
275
  }).length > 0 && (f.isError || false) === false]);
271
276
  return loadedFilters.map(([filterKey, isLoaded]) => !isLoaded ? filterKey : null).filter(f => !!f);
272
- };
277
+ }; // We lowercase the filter key unless it's an ISO date string where the T must be uppercase
273
278
 
274
- // We lowercase the filter key unless it's an ISO date string where the T must be uppercase
275
- const getSelectedFilters = (state, facet = '', context = Context.facets, returnType) => {
279
+ const getSelectedFilters = (state, facet = '', context = exports.Context.facets, returnType) => {
276
280
  const filters = getFilters(state, facet, context, 'js');
277
281
  const isoDateRegex = RegExp(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d/);
278
282
  const selectedFilters = Object.fromEntries(Object.entries(filters).map(([key, filter = {}]) => [key, (filter.items || []).filter(item => !!(item.isSelected || false)).map(item => {
@@ -283,61 +287,60 @@ const getSelectedFilters = (state, facet = '', context = Context.facets, returnT
283
287
  const fromJS = makeFromJS(returnType);
284
288
  return fromJS(selectedFilters);
285
289
  };
286
- const getResults = (state, current = '', context = Context.facets, returnType) => {
290
+ const getResults = (state, current = '', context = exports.Context.facets, returnType) => {
287
291
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'results'], [], returnType);
288
292
  };
289
- const getIsInternalPaging = (state, current, context = Context.facets) => {
293
+ const getIsInternalPaging = (state, current, context = exports.Context.facets) => {
290
294
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'queryParams', 'internalPaging'], false);
291
295
  };
292
- const getIsLoaded = (state, context = Context.facets, facet) => {
296
+ const getIsLoaded = (state, context = exports.Context.facets, facet) => {
293
297
  return !!getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'queryDuration'], 0);
294
298
  };
295
- const getIsLoading = (state, context = Context.facets, facet) => {
299
+ const getIsLoading = (state, context = exports.Context.facets, facet) => {
296
300
  return getImmutableOrJS(state, ['search', context, facet || getCurrent(state, context), 'entries', 'isLoading']);
297
301
  };
298
302
  const getIsSsr = state => getImmutableOrJS(state, ['search', 'config', 'ssr'], false);
299
- const getFeaturedResults = (state, current = '', context = Context.facets, returnType) => {
303
+ const getFeaturedResults = (state, current = '', context = exports.Context.facets, returnType) => {
300
304
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'featuredResults'], [], returnType);
301
305
  };
302
- const getPaging = (state, current = '', context = Context.facets, returnType) => {
306
+ const getPaging = (state, current = '', context = exports.Context.facets, returnType) => {
303
307
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo'], {}, returnType);
304
308
  };
305
- const getPageIndex = (state, current = '', context = Context.facets) => {
309
+ const getPageIndex = (state, current = '', context = exports.Context.facets) => {
306
310
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'pageIndex']);
307
311
  };
308
- const getPageSize = (state, current = '', context = Context.facets) => {
312
+ const getPageSize = (state, current = '', context = exports.Context.facets) => {
309
313
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'pageSize'], 0 // Defaults to 0 because we want it to fall back to a query param if not defined
310
314
  );
311
315
  };
312
-
313
- const getPrevPageIndex = (state, current = '', context = Context.facets) => {
316
+ const getPrevPageIndex = (state, current = '', context = exports.Context.facets) => {
314
317
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'prevPageIndex']);
315
318
  };
316
- const getPageIsLoading = (state, current = '', context = Context.facets) => {
319
+ const getPageIsLoading = (state, current = '', context = exports.Context.facets) => {
317
320
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'isLoading']);
318
321
  };
319
- const getPagesLoaded = (state, current = '', context = Context.facets) => {
322
+ const getPagesLoaded = (state, current = '', context = exports.Context.facets) => {
320
323
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'pagesLoaded'], [], 'js');
321
324
  };
322
- const getTotalCount = (state, current = '', context = Context.facets) => {
325
+ const getTotalCount = (state, current = '', context = exports.Context.facets) => {
323
326
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'pagingInfo', 'totalCount']);
324
327
  };
325
328
  const getSearchTerm = state => getImmutableOrJS(state, ['search', 'term']);
326
329
  const getSearchTabs = (state, returnType) => getImmutableOrJS(state, ['search', 'tabs'], [], returnType);
327
- const getQueryParams = (state, current = '', context = Context.facets) => {
330
+ const getQueryParams = (state, current = '', context = exports.Context.facets) => {
328
331
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'queryParams'], {}, 'js');
329
332
  };
330
333
  const getQueryParameter = ({
331
334
  state,
332
335
  facet,
333
- context = Context.facets
336
+ context = exports.Context.facets
334
337
  }, key, ifnull = null) => {
335
338
  return getImmutableOrJS(getQueryParams(state, facet, context), key, ifnull, 'js');
336
339
  };
337
- const getCustomApi = (state, current, context = Context.facets, returnType) => {
340
+ const getCustomApi = (state, current, context = exports.Context.facets, returnType) => {
338
341
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'customApi'], null, returnType);
339
342
  };
340
- const getCustomEnv = (state, current, context = Context.facets) => {
343
+ const getCustomEnv = (state, current, context = exports.Context.facets) => {
341
344
  return getImmutableOrJS(state, ['search', context, current || getCurrent(state, context), 'env']);
342
345
  };
343
346
  const getTabsAndFacets = (state, returnType) => {
@@ -352,9 +355,8 @@ const getTabsAndFacets = (state, returnType) => {
352
355
  if (!countFields || countFields.find((f = []) => (f === null || f === void 0 ? void 0 : f[0]) === facetName)) return getImmutableOrJS(facet, ['pagingInfo', 'totalCount']);
353
356
  return 0;
354
357
  }).reduce((a, b) => a + b, 0);
355
- return {
356
- ...tab,
357
- [Context.facets]: Object.fromEntries(thisTabFacets),
358
+ return { ...tab,
359
+ [exports.Context.facets]: Object.fromEntries(thisTabFacets),
358
360
  totalCount: thisTabTotal
359
361
  };
360
362
  });
@@ -370,12 +372,12 @@ const getFacetsTotalCount = state => {
370
372
  const facets = getFacets(state);
371
373
  const wholeSearchTotal = Object.entries(facets).map(([, t = {}]) => {
372
374
  var _t$pagingInfo;
375
+
373
376
  return ((_t$pagingInfo = t.pagingInfo) === null || _t$pagingInfo === void 0 ? void 0 : _t$pagingInfo.totalCount) || 0;
374
377
  }).reduce((a, b) => a + b, 0);
375
378
  return wholeSearchTotal;
376
- };
379
+ }; // An exported copy of the relevant selectors scoped by default to a facets context
377
380
 
378
- // An exported copy of the relevant selectors scoped by default to a facets context
379
381
  const selectFacets = {
380
382
  getCurrent: getCurrentFacet,
381
383
  getCurrentTab,
@@ -394,14 +396,14 @@ const selectFacets = {
394
396
  getPageIsLoading,
395
397
  getPagesLoaded,
396
398
  getPaging,
397
- getQueryParams: (state, facet) => getQueryParams(state, facet, Context.facets),
399
+ getQueryParams: (state, facet) => getQueryParams(state, facet, exports.Context.facets),
398
400
  getQueryParameter: ({
399
401
  state,
400
402
  facet
401
403
  }, key, ifnull) => getQueryParameter({
402
404
  state,
403
405
  facet,
404
- context: Context.facets
406
+ context: exports.Context.facets
405
407
  }, key, ifnull),
406
408
  getRenderableFilters,
407
409
  getResults,
@@ -412,35 +414,34 @@ const selectFacets = {
412
414
  getSearchTerm,
413
415
  getSearchTotalCount,
414
416
  getSelectedFilters
415
- };
417
+ }; // An exported copy of the relevant selectors pre-scoped to a listing context
416
418
 
417
- // An exported copy of the relevant selectors pre-scoped to a listing context
418
419
  const selectListing = {
419
420
  getCurrent: getCurrentListing,
420
- getFeaturedResults: (state, listing = '') => getFeaturedResults(state, listing, Context.listings, 'js'),
421
- getFilters: (state, listing = '') => getFilters(state, listing, Context.listings, 'js'),
422
- getFiltersToLoad: (state, listing = '') => getFiltersToLoad(state, listing, Context.listings),
421
+ getFeaturedResults: (state, listing = '') => getFeaturedResults(state, listing, exports.Context.listings, 'js'),
422
+ getFilters: (state, listing = '') => getFilters(state, listing, exports.Context.listings, 'js'),
423
+ getFiltersToLoad: (state, listing = '') => getFiltersToLoad(state, listing, exports.Context.listings),
423
424
  getListing,
424
- getIsLoaded: state => getIsLoaded(state, Context.listings),
425
- getIsLoading: state => getIsLoading(state, Context.listings),
426
- getPageIndex: (state, listing = '') => getPageIndex(state, listing, Context.listings),
427
- getPaging: (state, listing = '') => getPaging(state, listing, Context.listings, 'js'),
428
- getPageIsLoading: (state, listing = '') => getPageIsLoading(state, listing, Context.listings),
429
- getPagesLoaded: (state, listing = '') => getPagesLoaded(state, listing, Context.listings),
430
- getQueryParams: (state, listing = '') => getQueryParams(state, listing, Context.listings),
425
+ getIsLoaded: state => getIsLoaded(state, exports.Context.listings),
426
+ getIsLoading: state => getIsLoading(state, exports.Context.listings),
427
+ getPageIndex: (state, listing = '') => getPageIndex(state, listing, exports.Context.listings),
428
+ getPaging: (state, listing = '') => getPaging(state, listing, exports.Context.listings, 'js'),
429
+ getPageIsLoading: (state, listing = '') => getPageIsLoading(state, listing, exports.Context.listings),
430
+ getPagesLoaded: (state, listing = '') => getPagesLoaded(state, listing, exports.Context.listings),
431
+ getQueryParams: (state, listing = '') => getQueryParams(state, listing, exports.Context.listings),
431
432
  getQueryParameter: ({
432
433
  state,
433
434
  facet
434
435
  }, key, ifnull) => getQueryParameter({
435
436
  state,
436
437
  facet,
437
- context: Context.listings
438
+ context: exports.Context.listings
438
439
  }, key, ifnull),
439
- getRenderableFilters: (state, listing = '') => getRenderableFilters(state, listing, Context.listings),
440
- getResults: (state, listing = '') => getResults(state, listing, Context.listings, 'js'),
440
+ getRenderableFilters: (state, listing = '') => getRenderableFilters(state, listing, exports.Context.listings),
441
+ getResults: (state, listing = '') => getResults(state, listing, exports.Context.listings, 'js'),
441
442
  getSearchTerm,
442
- getTotalCount: (state, listing = '') => getTotalCount(state, listing, Context.listings),
443
- getSelectedFilters: (state, listing = '') => getSelectedFilters(state, listing, Context.listings, 'js')
443
+ getTotalCount: (state, listing = '') => getTotalCount(state, listing, exports.Context.listings),
444
+ getSelectedFilters: (state, listing = '') => getSelectedFilters(state, listing, exports.Context.listings, 'js')
444
445
  };
445
446
  const selectCurrentPath = state => getImmutableOrJS(state, ['routing', 'currentPath']);
446
447
  const selectCurrentProject = state => getImmutableOrJS(state, ['routing', 'currentProject']);
@@ -495,23 +496,31 @@ const now = () => {
495
496
  if (typeof window == 'undefined') {
496
497
  return Date.now();
497
498
  }
499
+
498
500
  return window.performance.now();
499
501
  };
500
502
 
501
503
  const getClientConfig = (project, env) => {
502
- let config = DELIVERY_API_CONFIG; /* global DELIVERY_API_CONFIG */
504
+ let config = DELIVERY_API_CONFIG;
505
+ /* global DELIVERY_API_CONFIG */
506
+
503
507
  if (project) {
504
508
  config.projectId = project;
505
509
  }
506
- if (typeof window != 'undefined' && PROXY_DELIVERY_API /* global PROXY_DELIVERY_API */) {
510
+
511
+ if (typeof window != 'undefined' && PROXY_DELIVERY_API
512
+ /* global PROXY_DELIVERY_API */
513
+ ) {
507
514
  // ensure a relative url is used to bypass the need for CORS (separate OPTIONS calls)
508
515
  config.rootUrl = env || '';
509
516
  config.responseHandler = {
510
517
  404: () => null
511
518
  };
512
519
  }
520
+
513
521
  return config;
514
522
  };
523
+
515
524
  class CacheNode {
516
525
  constructor(key, value) {
517
526
  this.key = key;
@@ -519,7 +528,9 @@ class CacheNode {
519
528
  this.next = null;
520
529
  this.prev = null;
521
530
  }
531
+
522
532
  }
533
+
523
534
  class LruCache {
524
535
  constructor(limit = 100) {
525
536
  this.map = {};
@@ -528,6 +539,7 @@ class LruCache {
528
539
  this.limit = limit || 100;
529
540
  this.size = 0;
530
541
  }
542
+
531
543
  get(key) {
532
544
  if (this.map[key]) {
533
545
  let value = this.map[key].value;
@@ -537,8 +549,10 @@ class LruCache {
537
549
  return value;
538
550
  }
539
551
  }
552
+
540
553
  set(key, value) {
541
554
  let node = new CacheNode(key, value);
555
+
542
556
  if (this.map[key]) {
543
557
  this.remove(key);
544
558
  } else {
@@ -549,46 +563,60 @@ class LruCache {
549
563
  this.tail.next = null;
550
564
  }
551
565
  }
566
+
552
567
  this.setHead(node);
553
568
  }
569
+
554
570
  setHead(node) {
555
571
  node.next = this.head;
556
572
  node.prev = null;
573
+
557
574
  if (this.head) {
558
575
  this.head.prev = node;
559
576
  }
577
+
560
578
  this.head = node;
579
+
561
580
  if (!this.tail) {
562
581
  this.tail = node;
563
582
  }
583
+
564
584
  this.size++;
565
585
  this.map[node.key] = node;
566
586
  }
587
+
567
588
  remove(key) {
568
589
  let node = this.map[key];
590
+
569
591
  if (node.prev) {
570
592
  node.prev.next = node.next;
571
593
  } else {
572
594
  this.head = node.next;
573
595
  }
596
+
574
597
  if (node.next) {
575
598
  node.next.prev = node.prev;
576
599
  } else {
577
600
  this.tail = node.prev;
578
601
  }
602
+
579
603
  delete this.map[key];
580
604
  this.size--;
581
605
  }
606
+
582
607
  }
608
+
583
609
  class CachedSearch {
584
610
  constructor() {
585
611
  this.cache = new LruCache();
586
612
  this.taxonomyLookup = {};
587
613
  }
614
+
588
615
  search(query, linkDepth, project, env) {
589
616
  const client = contensisDeliveryApi.Client.create(getClientConfig(project, env));
590
617
  return this.request(project + JSON.stringify(query) + linkDepth.toString(), () => client.entries.search(query, linkDepth));
591
618
  }
619
+
592
620
  getTaxonomyNodeByPath(path, project, env) {
593
621
  const client = contensisDeliveryApi.Client.create(getClientConfig(project, env));
594
622
  return this.request(`[TAXONOMY NODE] ${path}`, () => client.taxonomy.getNodeByPath({
@@ -597,6 +625,7 @@ class CachedSearch {
597
625
  childDepth: 2
598
626
  }).then(node => this.extendTaxonomyNode(node)));
599
627
  }
628
+
600
629
  request(key, execute) {
601
630
  if (!this.cache.get(key) || typeof window == 'undefined') {
602
631
  let promise = execute();
@@ -605,36 +634,41 @@ class CachedSearch {
605
634
  this.cache.remove(key);
606
635
  });
607
636
  }
637
+
608
638
  return this.cache.get(key);
609
639
  }
640
+
610
641
  extendTaxonomyNode(node) {
611
642
  let id = this.getTaxonomyId(node);
612
643
  this.taxonomyLookup[id] = node.key;
613
- return {
614
- ...node,
644
+ return { ...node,
615
645
  id,
616
646
  children: node.children ? node.children.map(n => this.extendTaxonomyNode(n)) : null
617
647
  };
618
648
  }
649
+
619
650
  getTaxonomyId(node) {
620
651
  if (node.key) {
621
652
  let parts = node.key.split('/');
622
653
  return parts[parts.length - 1];
623
654
  }
655
+
624
656
  return '';
625
657
  }
658
+
626
659
  fetch(uri, opts = {}) {
627
660
  return this.request(`[FETCH] ${uri} ${JSON.stringify(opts)}`, () => fetch(uri, opts));
628
661
  }
662
+
629
663
  }
664
+
630
665
  const cachedSearch = new CachedSearch();
631
666
 
632
667
  // eslint-disable-next-line import/default
633
668
  function fixFreeTextForElastic(s) {
634
669
  const illegalChars = ['>', '<', '=', '|', '!', '{', '}', '[', ']', '^', '~', '*', '?', ':', '\\', '/'];
635
670
  const illegalRegEx = new RegExp(illegalChars.map(c => '\\' + c).join('|'), 'g');
636
- s = s.replace(illegalRegEx, '');
637
- // s = s.replace(encodedRegEx, ''); // (m) => '\\\\' + m);
671
+ s = s.replace(illegalRegEx, ''); // s = s.replace(encodedRegEx, ''); // (m) => '\\\\' + m);
638
672
 
639
673
  return s;
640
674
  }
@@ -654,11 +688,13 @@ const getItemsFromResult = result => {
654
688
  const {
655
689
  payload
656
690
  } = result || {};
691
+
657
692
  if (payload) {
658
693
  if (Array.isArray(payload)) return payload;
659
694
  if (Array.isArray(payload.items)) return payload.items;
660
695
  return payload;
661
696
  }
697
+
662
698
  return [];
663
699
  };
664
700
  const extractQuotedPhrases = searchTerm => {
@@ -670,7 +706,6 @@ const buildUrl = (route, params) => {
670
706
  const path = qs ? `${route}${route.includes('?') ? '&' : '?'}${qs}` : route;
671
707
  return path;
672
708
  };
673
-
674
709
  /**
675
710
  * Returns all params from the current route query string or static route
676
711
  * Supply static route argument if reading parameters from the route path
@@ -679,14 +714,15 @@ const buildUrl = (route, params) => {
679
714
  * @param location location object containing at least pathname and search
680
715
  * @returns Keyed params object
681
716
  */
717
+
682
718
  const routeParams = (staticRoute, location) => {
683
719
  var _staticRoute$match;
720
+
684
721
  // match.params is react-router-config/react-router@5 style
685
722
  // params is supplied with RouteObject in react-router@6
686
723
  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) || {};
687
724
  const queryParams = queryString.parse(typeof window !== 'undefined' ? window.location.search : (location === null || location === void 0 ? void 0 : location.search) || '');
688
- return {
689
- ...pathParams,
725
+ return { ...pathParams,
690
726
  ...queryParams
691
727
  };
692
728
  };
@@ -694,11 +730,13 @@ const callCustomApi = async (customApi, filters) => {
694
730
  const apiUri = customApi.uri || '';
695
731
  let uri = buildUrl(apiUri, filters);
696
732
  if (!uri) throw new Error('uri is required to use customApi');
733
+
697
734
  if (typeof window == 'undefined') {
698
735
  if (!uri.startsWith('http')) uri = `http://localhost:3001${uri}`;
699
736
  const response = await fetch(uri);
700
737
  return await response.json();
701
738
  }
739
+
702
740
  const response = await cachedSearch.fetch(uri);
703
741
  return await response.clone().json();
704
742
  };
@@ -706,27 +744,32 @@ const removeEmptyAttributes = obj => {
706
744
  Object.entries(obj).forEach(([key, val]) => val && typeof val === 'object' && removeEmptyAttributes(val) || (typeof val === 'undefined' || val === null || val === '') && delete obj[key]);
707
745
  return obj;
708
746
  };
709
- const toArray = (obj, seperator = ',') => typeof obj === 'undefined' || obj === null ? obj : Array.isArray(obj) ? obj : obj.split(seperator);
747
+ const toArray = (obj, seperator = ',') => typeof obj === 'undefined' || obj === null ? obj : Array.isArray(obj) ? obj : obj.split(seperator); // assumes array elements are primitive types
710
748
 
711
- // assumes array elements are primitive types
712
749
  const areArraysEqualSets = (a1, a2) => {
713
750
  const superSet = {};
751
+
714
752
  for (const ai of a1) {
715
753
  const e = ai + typeof ai;
716
754
  superSet[e] = 1;
717
755
  }
756
+
718
757
  for (const ai of a2) {
719
758
  const e = ai + typeof ai;
759
+
720
760
  if (!superSet[e]) {
721
761
  return false;
722
762
  }
763
+
723
764
  superSet[e] = 2;
724
765
  }
766
+
725
767
  for (const e in superSet) {
726
768
  if (superSet[e] === 1) {
727
769
  return false;
728
770
  }
729
771
  }
772
+
730
773
  return true;
731
774
  };
732
775
 
@@ -737,12 +780,12 @@ const searchUriTemplate = {
737
780
  }) => {
738
781
  const context = getSearchContext(state);
739
782
  const currentPath = selectCurrentPath(state) || '/search';
783
+
740
784
  if (context !== 'listings') {
741
785
  const currentFacet = facet || getCurrentFacet(state);
742
786
  const filters = getSelectedFilters(state, facet, context);
743
- const currentFilter = filters.contentTypeId;
787
+ const currentFilter = filters.contentTypeId; // Check if we have a filter first
744
788
 
745
- // Check if we have a filter first
746
789
  const newPath = (currentFilter === null || currentFilter === void 0 ? void 0 : currentFilter.length) > 0 && currentFacet ? `${currentPath}/${currentFacet}/${currentFilter}` : currentFacet ? `${currentPath}/${currentFacet}` : currentPath;
747
790
  return newPath;
748
791
  } else {
@@ -757,29 +800,29 @@ const searchUriTemplate = {
757
800
  pageIndex,
758
801
  pageSize
759
802
  }) => {
760
- const searchContext = getSearchContext(state);
761
- // Lose stateFilters and currentSearch if a new
803
+ const searchContext = getSearchContext(state); // Lose stateFilters and currentSearch if a new
762
804
  // term is passed via an argument
805
+
763
806
  const stateFilters = term ? {} : Object.fromEntries(Object.entries(getSelectedFilters(state, facet, searchContext, 'js')).map(([k, f]) => [k, f === null || f === void 0 ? void 0 : f.join(',')]));
764
807
  const currentSearch = !term && getImmutableOrJS(state, ['routing', 'location', 'search']);
765
808
  const currentQs = removeEmptyAttributes(queryString.parse(currentSearch));
766
809
  if (orderBy) currentQs.orderBy = orderBy;
767
- const searchTerm = getSearchTerm(state);
768
- // Use Immutable's merge to merge the stateFilters with any current Qs
810
+ const searchTerm = getSearchTerm(state); // Use Immutable's merge to merge the stateFilters with any current Qs
769
811
  // to build the new Qs.
812
+
770
813
  const mergedSearch = removeEmptyAttributes(merge__default["default"](currentQs, stateFilters));
771
814
  if (searchTerm) mergedSearch.term = searchTerm;
772
815
  if (pageIndex) mergedSearch.pageIndex = pageIndex + 1;
773
816
  if (pageIndex === 0) mergedSearch.pageIndex = undefined;
774
- if (pageSize) mergedSearch.pageSize = pageSize;
817
+ if (pageSize) mergedSearch.pageSize = pageSize; // We don't want these as search params in the url, we just need the search package to see them
775
818
 
776
- // We don't want these as search params in the url, we just need the search package to see them
777
819
  return queryString.stringify(mergedSearch);
778
820
  },
779
821
  hash: ({
780
822
  state
781
823
  }) => getImmutableOrJS(state, ['routing', 'location', 'hash'], '').replace('#', '')
782
824
  };
825
+
783
826
  const mapStateToSearchUri = state => mapJson__default["default"](state, searchUriTemplate);
784
827
 
785
828
  const DataFormats = {
@@ -814,8 +857,7 @@ const Fields = {
814
857
 
815
858
  const fieldExpression = (field, value, operator = 'equalTo', weight, fuzzySearch = false) => {
816
859
  if (!field || !value || Array.isArray(value) && value.length === 0) return [];
817
- if (Array.isArray(field))
818
- // If an array of fieldIds have been provided, call self for each fieldId
860
+ if (Array.isArray(field)) // If an array of fieldIds have been provided, call self for each fieldId
819
861
  // to generate expressions that are combined with an 'or' operator
820
862
  return [contensisCoreApi.Op.or(...field.map(fieldId => fieldExpression(fieldId, value, operator, weight, fuzzySearch)).flat())];
821
863
  if (operator === 'between') return between(field, value);
@@ -824,15 +866,19 @@ const fieldExpression = (field, value, operator = 'equalTo', weight, fuzzySearch
824
866
  const contentTypeIdExpression = (contentTypeIds, webpageTemplates, assetTypes) => {
825
867
  const expressions = [];
826
868
  if (!contentTypeIds && !webpageTemplates && !assetTypes) return expressions;
869
+
827
870
  if (contentTypeIds && contentTypeIds.length > 0) {
828
871
  expressions.push(...dataFormatExpression(contentTypeIds, DataFormats.entry));
829
872
  }
873
+
830
874
  if (webpageTemplates && webpageTemplates.length > 0) {
831
875
  expressions.push(...dataFormatExpression(webpageTemplates, DataFormats.webpage));
832
876
  }
877
+
833
878
  if (assetTypes && assetTypes.length > 0) {
834
879
  expressions.push(...dataFormatExpression(assetTypes, DataFormats.asset));
835
880
  }
881
+
836
882
  if (expressions.length > 1) return [contensisCoreApi.Op.or(...expressions)];
837
883
  return expressions;
838
884
  };
@@ -840,16 +886,14 @@ const filterExpressions = (filters, isOptional = false) => {
840
886
  if (!filters) return [];
841
887
  const expressions = [];
842
888
  filters.map(selectedFilter => {
843
- if (selectedFilter.logicOperator === 'and')
844
- // using 'and' logic operator we loop through each filter
889
+ if (selectedFilter.logicOperator === 'and') // using 'and' logic operator we loop through each filter
845
890
  // and loop through all values to add an expression for each filter value
846
891
  selectedFilter.values.forEach(value => expressions.push(...fieldExpression(selectedFilter.key, value, selectedFilter.fieldOperator || 'equalTo')));else if (selectedFilter.logicOperator === 'not') {
847
892
  const fieldExpressions = fieldExpression(selectedFilter.key, selectedFilter.values, selectedFilter.fieldOperator || 'in');
848
893
  fieldExpressions.forEach(expr => {
849
894
  expressions.push(contensisCoreApi.Op.not(expr));
850
895
  });
851
- }
852
- // using 'or' logic operator we loop over each filter
896
+ } // using 'or' logic operator we loop over each filter
853
897
  // and simply add the array of values to an expression with an 'in' operator
854
898
  else expressions.push(...fieldExpression(selectedFilter.key, selectedFilter.values, selectedFilter.fieldOperator || 'in'));
855
899
  if (isOptional) expressions.push(contensisCoreApi.Op.not(fieldExpression(selectedFilter.key, true, 'exists')[0]));
@@ -873,6 +917,7 @@ const dataFormatExpression = (contentTypeIds, dataFormat = DataFormats.entry) =>
873
917
  if (notContentTypeIds.length > 0 && notExpr) andExpr.add(notExpr);
874
918
  return [andExpr];
875
919
  }
920
+
876
921
  return [];
877
922
  };
878
923
  const featuredResultsExpression = ({
@@ -881,22 +926,24 @@ const featuredResultsExpression = ({
881
926
  fieldValue = true
882
927
  } = {}) => {
883
928
  const expressions = [];
929
+
884
930
  if (contentTypeId) {
885
931
  expressions.push(...contentTypeIdExpression(Array.isArray(contentTypeId) ? contentTypeId : [contentTypeId]));
886
932
  }
933
+
887
934
  if (fieldId && fieldValue) {
888
935
  expressions.push(...fieldExpression(fieldId, fieldValue));
889
936
  }
937
+
890
938
  return expressions;
891
939
  };
892
940
  const languagesExpression = languages => fieldExpression(Fields.sys.language, languages);
893
941
  const includeInSearchExpressions = (webpageTemplates, includeInSearchFields) => {
894
- const expressions = [];
895
- // Or include this expression if we have explicity specified non-default includeInSearch fields
896
- 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))));
942
+ const expressions = []; // Or include this expression if we have explicity specified non-default includeInSearch fields
897
943
 
898
- // If webpageTemplates have been specified, include this expression
944
+ 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
899
945
  // with the default includeInSearch field from classic Contensis.
946
+
900
947
  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)));
901
948
  return expressions;
902
949
  };
@@ -916,52 +963,69 @@ const excludeIdsExpression = excludeIds => {
916
963
  };
917
964
  const orderByExpression = orderBy => {
918
965
  let expression;
966
+
919
967
  if (orderBy && orderBy.length > 0) {
920
968
  expression = contensisCoreApi.OrderBy;
969
+
921
970
  for (const ob of orderBy) {
922
971
  var _expression, _expression2;
972
+
923
973
  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);
924
974
  }
925
975
  }
976
+
926
977
  return expression;
927
978
  };
979
+
928
980
  const equalToOrIn = (field, value, operator = 'equalTo', fuzzySearch = false) => {
929
981
  if (value.length === 0) return [];
982
+
930
983
  if (Array.isArray(value)) {
931
984
  if (operator === 'equalTo' || operator === 'in') return [contensisCoreApi.Op.in(field, ...value)];
932
985
  const expressions = value.map(innerValue => {
933
986
  var _between, _distanceWithin;
987
+
934
988
  switch (operator) {
935
989
  case 'between':
936
990
  return (_between = between(field, innerValue)) === null || _between === void 0 ? void 0 : _between[0];
991
+
937
992
  case 'distanceWithin':
938
993
  return (_distanceWithin = distanceWithin(field, innerValue)) === null || _distanceWithin === void 0 ? void 0 : _distanceWithin[0];
994
+
939
995
  case 'exists':
940
996
  return contensisCoreApi.Op.exists(field, innerValue);
997
+
941
998
  case 'freeText':
942
999
  // TODO: Potentially needs further implementation of new options
943
1000
  return contensisCoreApi.Op[operator](field, innerValue, fuzzySearch, undefined);
1001
+
944
1002
  default:
945
1003
  return contensisCoreApi.Op[operator](field, innerValue);
946
1004
  }
947
1005
  });
948
1006
  return (expressions === null || expressions === void 0 ? void 0 : expressions.length) > 1 ? [contensisCoreApi.Op.or(...expressions)] : expressions || [];
949
1007
  }
1008
+
950
1009
  switch (operator) {
951
1010
  case 'between':
952
1011
  return between(field, value);
1012
+
953
1013
  case 'distanceWithin':
954
1014
  return distanceWithin(field, value);
1015
+
955
1016
  case 'freeText':
956
1017
  // TODO: Potentially needs further implementation of new options
957
1018
  return [contensisCoreApi.Op.freeText(field, value, fuzzySearch, undefined)];
1019
+
958
1020
  default:
959
1021
  return [contensisCoreApi.Op[operator](field, value)];
960
1022
  }
961
1023
  };
1024
+
962
1025
  const between = (field, value) => {
963
1026
  const handle = betweenValue => {
964
1027
  const valArr = betweenValue.split('--');
1028
+
965
1029
  if (valArr.length > 1) {
966
1030
  const [minimum, maximum] = valArr;
967
1031
  return contensisCoreApi.Op.between(field, minimum, maximum);
@@ -971,14 +1035,17 @@ const between = (field, value) => {
971
1035
  return false;
972
1036
  }
973
1037
  };
1038
+
974
1039
  if (value.length === 0) return [];
975
1040
  if (Array.isArray(value)) return [contensisCoreApi.Op.or(...value.map(handle).filter(bc => bc !== false))];
976
1041
  const op = handle(value);
977
1042
  return op ? [op] : [];
978
1043
  };
1044
+
979
1045
  const distanceWithin = (field, value) => {
980
1046
  const handle = distanceValue => {
981
1047
  const valArr = distanceValue.split(' ');
1048
+
982
1049
  if (valArr.length > 1) {
983
1050
  const [lat, lon] = valArr;
984
1051
  return contensisCoreApi.Op.distanceWithin(field, Number(lat), Number(lon), (valArr === null || valArr === void 0 ? void 0 : valArr[2]) || '10mi');
@@ -988,27 +1055,28 @@ const distanceWithin = (field, value) => {
988
1055
  return false;
989
1056
  }
990
1057
  };
1058
+
991
1059
  if (value.length === 0) return [];
992
1060
  if (Array.isArray(value)) return [contensisCoreApi.Op.or(...value.map(handle).filter(bc => bc !== false))];
993
1061
  const op = handle(value);
994
1062
  return op ? [op] : [];
995
1063
  };
996
-
997
1064
  /**
998
1065
  * Accept HTTP style objects and map them to
999
1066
  * their equivalent JS client "Op" expressions
1000
1067
  * @param {array} where the where array as you'd provide it to the HTTP API
1001
1068
  * @returns {array} array of constructed Delivery API Operators
1002
1069
  */
1070
+
1071
+
1003
1072
  const customWhereExpressions = where => {
1004
- if (!where || !Array.isArray(where)) return [];
1073
+ if (!where || !Array.isArray(where)) return []; // Map each clause inside the where array
1005
1074
 
1006
- // Map each clause inside the where array
1007
1075
  return where.map(clause => {
1008
- let expression;
1009
- // Map through each property in the clause so we can
1076
+ let expression; // Map through each property in the clause so we can
1010
1077
  // capture the values required and reconstruct them as
1011
1078
  // a Delivery API expression
1079
+
1012
1080
  let operator;
1013
1081
  Object.keys(clause).map((key, idx) => {
1014
1082
  // The clause may contain only one key
@@ -1016,6 +1084,7 @@ const customWhereExpressions = where => {
1016
1084
  const field = clause.field;
1017
1085
  const value = clause[Object.keys(clause).find(k => !['field', 'weight'].includes(k)) || ''];
1018
1086
  const weight = clause.weight;
1087
+
1019
1088
  if (idx === 0) {
1020
1089
  if (operator === 'and' || operator === 'or') {
1021
1090
  // These are array expressions so we can call ourself recursively
@@ -1023,21 +1092,24 @@ const customWhereExpressions = where => {
1023
1092
  const recurseExpr = customWhereExpressions(clause[operator]);
1024
1093
  expression = contensisCoreApi.Op[operator](...recurseExpr);
1025
1094
  }
1095
+
1026
1096
  if (['not'].includes(operator)) {
1027
1097
  // A 'not' expression is an object with only one inner field and inner operator
1028
1098
  Object.keys(value).map((notKey, notIdx) => {
1029
1099
  const innerOperator = notKey;
1030
1100
  const innerValue = value[notKey];
1031
- const innerField = value.field;
1032
- // Map the expression when we've looped and scoped to
1101
+ const innerField = value.field; // Map the expression when we've looped and scoped to
1033
1102
  // the second property inside the clause
1103
+
1034
1104
  if (notIdx === 1) expression = contensisCoreApi.Op.not(makeJsExpression(innerOperator, innerField, innerValue));
1035
1105
  });
1036
1106
  }
1037
- }
1038
- // Map the expression when we've looped and scoped to
1107
+ } // Map the expression when we've looped and scoped to
1039
1108
  // the second property inside the clause
1109
+
1110
+
1040
1111
  operator = Object.keys(clause).find(clauseKey => !['field', 'weight'].includes(clauseKey));
1112
+
1041
1113
  if (idx === 1) {
1042
1114
  expression = makeJsExpression(operator, field, value);
1043
1115
  if (typeof weight === 'number') expression = expression.weight(weight);
@@ -1046,29 +1118,28 @@ const customWhereExpressions = where => {
1046
1118
  return expression;
1047
1119
  });
1048
1120
  };
1121
+
1049
1122
  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);
1123
+
1050
1124
  const termExpressions = (searchTerm, weightedSearchFields, fuzzySearch, omitSearchFields = []) => {
1051
1125
  if (searchTerm && weightedSearchFields && weightedSearchFields.length > 0) {
1052
1126
  // Extract any phrases in quotes to array
1053
- const quotedPhrases = extractQuotedPhrases(searchTerm);
1127
+ const quotedPhrases = extractQuotedPhrases(searchTerm); // Modify the search term to remove any quoted phrases to leave any remaining terms
1054
1128
 
1055
- // Modify the search term to remove any quoted phrases to leave any remaining terms
1056
1129
  let modifiedSearchTerm = searchTerm;
1057
- quotedPhrases.forEach(qp => modifiedSearchTerm = modifiedSearchTerm.replace(qp, '').replace('""', '').trim());
1130
+ quotedPhrases.forEach(qp => modifiedSearchTerm = modifiedSearchTerm.replace(qp, '').replace('""', '').trim()); // Push to the operators array to include in the query
1058
1131
 
1059
- // Push to the operators array to include in the query
1060
- const operators = [];
1132
+ const operators = []; // Helper functions to generate Op expressions
1061
1133
 
1062
- // Helper functions to generate Op expressions
1063
1134
  const containsOp = (f, term) => fieldExpression(f.fieldId, fixFreeTextForElastic(term), 'contains', f.weight);
1064
- const freeTextOp = (f, term) => fieldExpression(f.fieldId, fixFreeTextForElastic(term), 'freeText', f.weight, fuzzySearch);
1065
1135
 
1066
- // For each weighted search field
1136
+ const freeTextOp = (f, term) => fieldExpression(f.fieldId, fixFreeTextForElastic(term), 'freeText', f.weight, fuzzySearch); // For each weighted search field
1137
+
1138
+
1067
1139
  weightedSearchFields.forEach(wsf => {
1068
1140
  // Push to field operators
1069
- const fieldOperators = [];
1141
+ const fieldOperators = []; // Add operator expressions for modified search term
1070
1142
 
1071
- // Add operator expressions for modified search term
1072
1143
  if (modifiedSearchTerm) {
1073
1144
  if ([Fields.keywords, Fields.sys.filename, Fields.sys.uri].includes(wsf.fieldId)) {
1074
1145
  fieldOperators.push(...containsOp(wsf, modifiedSearchTerm));
@@ -1079,35 +1150,33 @@ const termExpressions = (searchTerm, weightedSearchFields, fuzzySearch, omitSear
1079
1150
  fieldOperators.push(...freeTextOp(wsf, modifiedSearchTerm));
1080
1151
  }
1081
1152
  }
1082
- }
1153
+ } // Add operator expressions for any quoted phrases
1083
1154
 
1084
- // Add operator expressions for any quoted phrases
1085
- quotedPhrases.forEach(qp => fieldOperators.push(...containsOp(wsf, qp)));
1086
1155
 
1087
- // If we are using multiple operators for a field we will
1156
+ quotedPhrases.forEach(qp => fieldOperators.push(...containsOp(wsf, qp))); // If we are using multiple operators for a field we will
1088
1157
  // wrap each field inside an And operator so we will match
1089
1158
  // all terms/phrases rather than any terms/phrases
1159
+
1090
1160
  if (fieldOperators.length > 1) {
1091
1161
  operators.push(contensisCoreApi.Op.and(...fieldOperators));
1092
1162
  } else {
1093
1163
  operators.push(...fieldOperators);
1094
1164
  }
1095
- });
1165
+ }); // Wrap operators in an Or operator
1096
1166
 
1097
- // Wrap operators in an Or operator
1098
1167
  const expressions = contensisCoreApi.Op.or().addRange(operators);
1099
- if (!omitSearchFields.find(sf => sf === Fields.searchContent))
1100
- // include "searchContent" field by default unless omitted
1168
+ if (!omitSearchFields.find(sf => sf === Fields.searchContent)) // include "searchContent" field by default unless omitted
1101
1169
  return [expressions.add(contensisCoreApi.Op.freeText(Fields.searchContent, searchTerm, fuzzySearch))];else return [expressions];
1102
1170
  } else if (searchTerm) {
1103
1171
  // Searching without weightedSearchFields defined will fall back
1104
1172
  // to a default set of search fields with arbritary weights set.
1105
-
1106
1173
  const exp = [];
1174
+
1107
1175
  if (!omitSearchFields.find(sf => sf === Fields.entryTitle)) {
1108
1176
  exp.push(contensisCoreApi.Op.equalTo(Fields.entryTitle, searchTerm).weight(10));
1109
1177
  exp.push(contensisCoreApi.Op.freeText(Fields.entryTitle, searchTerm, fuzzySearch).weight(2));
1110
1178
  }
1179
+
1111
1180
  if (!omitSearchFields.find(sf => sf === Fields.entryDescription)) exp.push(contensisCoreApi.Op.freeText(Fields.entryDescription, searchTerm, fuzzySearch).weight(2));
1112
1181
  if (!omitSearchFields.find(sf => sf === Fields.keywords)) exp.push(contensisCoreApi.Op.contains(Fields.keywords, searchTerm).weight(2));
1113
1182
  if (!omitSearchFields.find(sf => sf === Fields.sys.uri)) exp.push(contensisCoreApi.Op.contains(Fields.sys.uri, searchTerm).weight(2));
@@ -1169,9 +1238,11 @@ const searchQuery = ({
1169
1238
  const query = new contensisCoreApi.Query(...expressions);
1170
1239
  if (!searchTerm) query.orderBy = orderByExpression(orderBy);
1171
1240
  if (dynamicOrderBy && dynamicOrderBy.length) query.orderBy = orderByExpression(dynamicOrderBy);
1241
+
1172
1242
  if (fields && fields.length > 0 && !isFeatured) {
1173
1243
  query.fields = fields;
1174
1244
  }
1245
+
1175
1246
  query.pageIndex = isFeatured ? 0 : pageIndex;
1176
1247
  query.pageSize = isFeatured && typeof featuredResults.count === 'number' ? featuredResults.count : pageSize;
1177
1248
  return query;
@@ -1192,6 +1263,7 @@ const mapEntriesToSearchResults = ({
1192
1263
  const mapperFunc = mapper || mappers && mappers.results;
1193
1264
  return items && typeof mapperFunc === 'function' ? mapperFunc(items, facet, context, state) : [];
1194
1265
  };
1266
+
1195
1267
  const facetTemplate = {
1196
1268
  type: () => SET_SEARCH_ENTRIES,
1197
1269
  context: 'action.context',
@@ -1234,9 +1306,11 @@ const facetTemplate = {
1234
1306
  pagesLoaded
1235
1307
  }) => {
1236
1308
  const loaded = [...(pagesLoaded || [])];
1309
+
1237
1310
  if (isNaN(loaded.find(l => l === pageIndex))) {
1238
1311
  loaded.push(pageIndex);
1239
1312
  }
1313
+
1240
1314
  return loaded.sort((a, b) => a - b);
1241
1315
  }
1242
1316
  },
@@ -1259,21 +1333,18 @@ const facetTemplate = {
1259
1333
  prevPageIndex
1260
1334
  } = action.queryParams;
1261
1335
  const results = mapEntriesToSearchResults(action, getItemsFromResult(result), state);
1262
- if (!loadMorePaging) return results;
1336
+ if (!loadMorePaging) return results; // add a _pageIndex property to the returned results to help us later
1263
1337
 
1264
- // add a _pageIndex property to the returned results to help us later
1265
1338
  const nextResults = results.map((r, idx) => ({
1266
1339
  _pageIndex: pageIndex,
1267
1340
  _pagePosition: idx,
1268
1341
  ...r
1269
1342
  }));
1270
- const loadedPages = pagesLoaded || [];
1271
-
1272
- // if pageIndex is found in loadedPages, we have already loaded this page
1273
- if (!isNaN(loadedPages.find(l => l === pageIndex))) return prevResults;
1343
+ const loadedPages = pagesLoaded || []; // if pageIndex is found in loadedPages, we have already loaded this page
1274
1344
 
1275
- // Determine where we put the results depending on if we
1345
+ if (!isNaN(loadedPages.find(l => l === pageIndex))) return prevResults; // Determine where we put the results depending on if we
1276
1346
  // are paging forwards, backwards, or doing a new search
1347
+
1277
1348
  const firstResultSet = pageIndex > prevPageIndex ? prevResults || [] : nextResults;
1278
1349
  const secondResultSet = pageIndex > prevPageIndex ? nextResults : prevResults || [];
1279
1350
  const onlyResultSet = loadedPages.length === 0 ? nextResults : false;
@@ -1304,11 +1375,13 @@ const filterTemplate = {
1304
1375
  if (payload && (payload.items || payload.children)) {
1305
1376
  const items = (payload.items || payload.children).map(item => {
1306
1377
  var _item$sys;
1378
+
1307
1379
  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);
1308
1380
  return item;
1309
1381
  });
1310
1382
  return mapper(items);
1311
1383
  }
1384
+
1312
1385
  return [];
1313
1386
  }
1314
1387
  },
@@ -1331,22 +1404,22 @@ const filterExpressionMapper = {
1331
1404
  fieldOperator: 'fieldOperator',
1332
1405
  logicOperator: 'logicOperator'
1333
1406
  };
1407
+
1334
1408
  const mapFilterToFilterExpression = filter => mapJson__default["default"](filter, filterExpressionMapper);
1335
1409
 
1336
1410
  const mapFiltersToFilterExpression = (filters, selectedFilters) => {
1337
1411
  if (!selectedFilters || Object.keys(selectedFilters).length === 0) return [];
1338
- const filterExpressions = [];
1339
-
1340
- // Iterate through the keys in selectedFilters and locate
1412
+ const filterExpressions = []; // Iterate through the keys in selectedFilters and locate
1341
1413
  // the items that are selected and queryable
1414
+
1342
1415
  Object.entries(selectedFilters).map(([fkey, selectedValues]) => {
1343
1416
  const filter = filters[fkey];
1417
+
1344
1418
  if (selectedValues && filter) {
1345
1419
  // Where we have a value for a selectedFilter
1346
1420
  // and a filter is found for the current key
1347
1421
  // map the filter to a filterExpression object
1348
- const expr = mapFilterToFilterExpression({
1349
- ...filter,
1422
+ const expr = mapFilterToFilterExpression({ ...filter,
1350
1423
  selectedValues
1351
1424
  });
1352
1425
  filterExpressions.push(expr);
@@ -1382,8 +1455,8 @@ const queryParamsTemplate = {
1382
1455
  context
1383
1456
  }) => {
1384
1457
  const stateFilters = getFilters(state, facet, context, 'js');
1385
- const selectedFilters = getSelectedFilters(state, facet, context, 'js');
1386
- // Use another mapping function to map the filter parameters for the query
1458
+ const selectedFilters = getSelectedFilters(state, facet, context, 'js'); // Use another mapping function to map the filter parameters for the query
1459
+
1387
1460
  const filterParams = mapFiltersToFilterExpression(stateFilters, selectedFilters);
1388
1461
  return filterParams;
1389
1462
  },
@@ -1433,9 +1506,10 @@ const queryParamsTemplate = {
1433
1506
  context
1434
1507
  }) => {
1435
1508
  var _getFacet;
1509
+
1436
1510
  return ((_getFacet = getFacet(state, facet, context, 'js')) === null || _getFacet === void 0 ? void 0 : _getFacet.projectId) || selectCurrentProject(state);
1437
1511
  },
1438
- searchTerm: root => root.context !== Context.minilist || getQueryParameter(root, 'useSearchTerm', false) ? getSearchTerm(root.state) : '',
1512
+ searchTerm: root => root.context !== exports.Context.minilist || getQueryParameter(root, 'useSearchTerm', false) ? getSearchTerm(root.state) : '',
1439
1513
  selectedFilters: ({
1440
1514
  state,
1441
1515
  facet,
@@ -1447,12 +1521,11 @@ const queryParamsTemplate = {
1447
1521
  weightedSearchFields: root => {
1448
1522
  const wsf = getQueryParameter(root, 'weightedSearchFields', []);
1449
1523
  const deduped = wsf.filter((v, i, a) => a.findIndex(t => t.fieldId === v.fieldId) === i);
1450
- return deduped;
1451
- // return wsf;
1524
+ return deduped; // return wsf;
1452
1525
  },
1453
-
1454
1526
  webpageTemplates: root => getQueryParameter(root, 'webpageTemplates', [])
1455
1527
  };
1528
+
1456
1529
  const mapStateToQueryParams = sourceJson => mapJson__default["default"](sourceJson, queryParamsTemplate);
1457
1530
 
1458
1531
  /**
@@ -1466,9 +1539,9 @@ const generateQueryParams = (action, state) => {
1466
1539
  const {
1467
1540
  context,
1468
1541
  facet
1469
- } = action;
1470
- // Map parameters using state and some additional
1542
+ } = action; // Map parameters using state and some additional
1471
1543
  // inputs from the action
1544
+
1472
1545
  const queryParams = mapStateToQueryParams({
1473
1546
  context,
1474
1547
  facet,
@@ -1477,12 +1550,12 @@ const generateQueryParams = (action, state) => {
1477
1550
  });
1478
1551
  return [queryParams, runSearch(action, state, queryParams)];
1479
1552
  };
1480
-
1481
1553
  /**
1482
1554
  * Checks if we have already loaded everything we're asking for and tells us to run the search or not
1483
1555
  * @param action
1484
1556
  * @param state
1485
1557
  */
1558
+
1486
1559
  const runSearch = (action, state, queryParams) => {
1487
1560
  const {
1488
1561
  context,
@@ -1494,14 +1567,13 @@ const runSearch = (action, state, queryParams) => {
1494
1567
  } = action;
1495
1568
  let willRun = false;
1496
1569
  const facetIsLoaded = defaultLang ? false : getIsLoaded(state, context, facet);
1497
- const stateParams = {
1498
- ...getQueryParams(ogState, facet, context)
1570
+ const stateParams = { ...getQueryParams(ogState, facet, context)
1499
1571
  };
1500
1572
  stateParams.pageIndex = getPageIndex(ogState, facet, context);
1501
1573
  stateParams.searchTerm = getSearchTerm(ogState);
1502
1574
  stateParams.pageSize = getPageSize(ogState, facet, context);
1503
- if (context === Context.facets && ssr ||
1504
- // context === Context.minilist ||
1575
+
1576
+ if (context === exports.Context.facets && ssr || // context === Context.minilist ||
1505
1577
  preload || !facetIsLoaded || filterParamsChanged(action) || defaultLang) {
1506
1578
  willRun = true;
1507
1579
  } else {
@@ -1509,24 +1581,28 @@ const runSearch = (action, state, queryParams) => {
1509
1581
  // are the same as what we already have in state
1510
1582
  Object.entries(stateParams).forEach(([param, value]) => {
1511
1583
  const queryParam = queryParams[param];
1584
+
1512
1585
  if (JSON.stringify(value) !== JSON.stringify(queryParam)) {
1513
1586
  willRun = true;
1514
1587
  }
1515
1588
  });
1516
1589
  }
1590
+
1517
1591
  const internalPaging = getIsInternalPaging(ogState, facet, context);
1592
+
1518
1593
  if (internalPaging && facetIsLoaded) {
1519
1594
  willRun = false;
1520
1595
  }
1596
+
1521
1597
  return willRun;
1522
1598
  };
1523
-
1524
1599
  /**
1525
1600
  * This will tell us if filter parameters have been
1526
1601
  * changed by some external event such as a route change
1527
1602
  * @param action
1528
1603
  * @returns true or false
1529
1604
  */
1605
+
1530
1606
  const filterParamsChanged = (action, state) => {
1531
1607
  const {
1532
1608
  context,
@@ -1541,13 +1617,12 @@ const filterParamsChanged = (action, state) => {
1541
1617
  });
1542
1618
  return paramsChanged.filter(f => f === true).length > 0;
1543
1619
  };
1544
-
1545
1620
  /* eslint-disable no-console */
1621
+
1546
1622
  const debugExecuteSearch = (action, state) => {
1547
1623
  const [queryParams, runSearch] = generateQueryParams(action, state);
1548
1624
  console.log('runSearch', runSearch, 'action', action, 'filterParamsChanged', filterParamsChanged(action, state), 'getIsLoaded(state, context, facet)', getIsLoaded(state, action.context, action.facet));
1549
- const stateParams = {
1550
- ...getQueryParams(action.ogState || state, action.facet, action.context),
1625
+ const stateParams = { ...getQueryParams(action.ogState || state, action.facet, action.context),
1551
1626
  pageIndex: getPageIndex(action.ogState || state, action.facet, action.context),
1552
1627
  searchTerm: getSearchTerm(action.ogState || state)
1553
1628
  };
@@ -1556,8 +1631,7 @@ const debugExecuteSearch = (action, state) => {
1556
1631
  };
1557
1632
  const scrollTo = scrollToElement => {
1558
1633
  if (typeof window !== 'undefined') {
1559
- if (typeof scrollToElement === 'number')
1560
- // Used to be Y coordinate, deprecated, because it's not accessible
1634
+ if (typeof scrollToElement === 'number') // Used to be Y coordinate, deprecated, because it's not accessible
1561
1635
  console.warn('updatePageIndex arg2 needs string');else if (typeof scrollToElement === 'string') {
1562
1636
  /* Effectively simulates an anchor link. Needed for accessibility, as window.scrollTo
1563
1637
  does not change focus, only scrolls the screen */
@@ -1566,11 +1640,10 @@ const scrollTo = scrollToElement => {
1566
1640
  }
1567
1641
  };
1568
1642
 
1569
- // *** FILTER ITEM MAPPING ***
1570
-
1571
1643
  // Base mapping, fields that are the same across all mappings
1572
1644
  // to save repeating these elements in every mapper, spread this
1573
1645
  // into your discrete mappings
1646
+
1574
1647
  const base = {
1575
1648
  contentTypeId: Fields.sys.contentTypeId,
1576
1649
  title: 'entryTitle',
@@ -1578,13 +1651,16 @@ const base = {
1578
1651
  path: 'sys.slug',
1579
1652
  isSelected: 'isSelected'
1580
1653
  };
1654
+
1581
1655
  const mapEntriesToFilterItems = entries => {
1582
1656
  if (!entries) return [];
1583
1657
  return entries.map(entry => {
1584
1658
  const template = base;
1659
+
1585
1660
  if (template) {
1586
1661
  return mapJson__default["default"](entry, template);
1587
1662
  }
1663
+
1588
1664
  return entry;
1589
1665
  });
1590
1666
  };
@@ -1614,7 +1690,9 @@ const mapQueryParamsToCustomApi = queryParams => {
1614
1690
  };
1615
1691
 
1616
1692
  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_PAGE_SIZE, updatePageSize), effects.takeEvery(UPDATE_SEARCH_TERM, updateSearchTerm), effects.takeEvery(UPDATE_SORT_ORDER, updateSortOrder), effects.takeEvery(UPDATE_SELECTED_FILTERS, applySearchFilter)];
1693
+
1617
1694
  const toJS = obj => obj && 'toJS' in obj && typeof obj.toJS === 'function' ? obj.toJS() : obj;
1695
+
1618
1696
  function* setRouteFilters(action) {
1619
1697
  const {
1620
1698
  mappers,
@@ -1623,19 +1701,19 @@ function* setRouteFilters(action) {
1623
1701
  defaultLang,
1624
1702
  debug
1625
1703
  } = action;
1626
- const context = listingType ? Context.listings : Context.facets;
1704
+ const context = listingType ? exports.Context.listings : exports.Context.facets;
1627
1705
  const state = toJS(yield effects.select());
1628
- const ssr = getIsSsr(state);
1706
+ const ssr = getIsSsr(state); // Get current facet from params or state
1629
1707
 
1630
- // Get current facet from params or state
1631
- let currentFacet = params && params.facet || listingType;
1708
+ let currentFacet = params && params.facet || listingType; // Pick the default facet from initialState
1632
1709
 
1633
- // Pick the default facet from initialState
1634
1710
  if (!currentFacet) {
1635
1711
  var _Object$keys;
1712
+
1636
1713
  const tabs = getSearchTabs(state, 'js');
1637
1714
  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]) || '';
1638
1715
  }
1716
+
1639
1717
  const nextAction = {
1640
1718
  type: SET_ROUTE_FILTERS,
1641
1719
  context,
@@ -1646,50 +1724,48 @@ function* setRouteFilters(action) {
1646
1724
  ssr,
1647
1725
  debug
1648
1726
  };
1649
- yield effects.put(nextAction);
1727
+ yield effects.put(nextAction); // keep track of this state ref for comparing changes to params later
1650
1728
 
1651
- // keep track of this state ref for comparing changes to params later
1652
1729
  const ogState = {
1653
1730
  search: state.search
1654
- };
1655
-
1656
- // Using call instead of triggering from the put
1731
+ }; // Using call instead of triggering from the put
1657
1732
  // to allow this exported saga to continue during SSR
1658
- yield effects.call(ensureSearch, {
1659
- ...nextAction,
1733
+
1734
+ yield effects.call(ensureSearch, { ...nextAction,
1660
1735
  ogState
1661
1736
  });
1662
1737
  }
1663
1738
  function* doSearch(action) {
1664
1739
  var _action$params;
1740
+
1665
1741
  const state = toJS(yield effects.select());
1742
+
1666
1743
  if (action.config) {
1667
1744
  // If the action contains a config object, we can add this to the
1668
1745
  // state at runtime
1669
- yield effects.put({
1670
- ...action,
1746
+ yield effects.put({ ...action,
1671
1747
  type: APPLY_CONFIG
1672
1748
  });
1673
1749
  }
1674
- const nextAction = {
1675
- ...action,
1750
+
1751
+ const nextAction = { ...action,
1676
1752
  type: SET_SEARCH_FILTERS,
1677
1753
  ssr: getIsSsr(state),
1678
1754
  facet: action.facet || ((_action$params = action.params) === null || _action$params === void 0 ? void 0 : _action$params.facet)
1679
1755
  };
1756
+
1680
1757
  if (nextAction.facet && (action.config || Object.keys(getFacet(state, nextAction.facet, action.context, 'js')).length > 0)) {
1681
- yield effects.put(nextAction);
1758
+ yield effects.put(nextAction); // keep track of this state ref for comparing changes to params later
1682
1759
 
1683
- // keep track of this state ref for comparing changes to params later
1684
1760
  const ogState = {
1685
1761
  search: state.search
1686
1762
  };
1687
- yield effects.call(ensureSearch, {
1688
- ...nextAction,
1763
+ yield effects.call(ensureSearch, { ...nextAction,
1689
1764
  ogState
1690
1765
  });
1691
1766
  }
1692
1767
  }
1768
+
1693
1769
  function* loadFilters(action) {
1694
1770
  const {
1695
1771
  facet: facetKey,
@@ -1697,6 +1773,7 @@ function* loadFilters(action) {
1697
1773
  mappers = {}
1698
1774
  } = action;
1699
1775
  const filtersToLoad = yield effects.select(getFiltersToLoad, facetKey, context, 'js');
1776
+
1700
1777
  if (filtersToLoad.length > 0) {
1701
1778
  yield effects.put({
1702
1779
  type: LOAD_FILTERS,
@@ -1722,6 +1799,7 @@ function* loadFilters(action) {
1722
1799
  if (filtersToLoadSagas) yield effects.all(filtersToLoadSagas);
1723
1800
  }
1724
1801
  }
1802
+
1725
1803
  function* loadFilter(action) {
1726
1804
  const {
1727
1805
  facetKey,
@@ -1747,6 +1825,7 @@ function* loadFilter(action) {
1747
1825
  selectedKeys,
1748
1826
  mapper
1749
1827
  };
1828
+
1750
1829
  try {
1751
1830
  if (contentTypeId) {
1752
1831
  const versionStatus = yield effects.select(selectVersionStatus);
@@ -1756,6 +1835,7 @@ function* loadFilter(action) {
1756
1835
  if (payload.type === 'error') throw payload;
1757
1836
  createStateFrom.payload = payload;
1758
1837
  }
1838
+
1759
1839
  if (path) {
1760
1840
  const payload = yield cachedSearch.getTaxonomyNodeByPath(path, projectId);
1761
1841
  if (!payload) throw new Error(`No payload returned for taxonomy path: '${path}'`);
@@ -1766,33 +1846,35 @@ function* loadFilter(action) {
1766
1846
  createStateFrom.type = LOAD_FILTERS_ERROR;
1767
1847
  createStateFrom.error = error;
1768
1848
  }
1849
+
1769
1850
  const nextAction = mapJson__default["default"](createStateFrom, filterTemplate);
1770
1851
  yield effects.put(nextAction);
1771
1852
  }
1853
+
1772
1854
  function* ensureSearch(action) {
1773
1855
  const {
1774
1856
  context,
1775
1857
  facet,
1776
1858
  debug
1777
1859
  } = action;
1860
+
1778
1861
  try {
1779
1862
  const state = yield effects.select();
1780
- const nextAction = {
1781
- ...action,
1863
+ const nextAction = { ...action,
1782
1864
  ogState: action.ogState || {
1783
1865
  search: state.search
1784
1866
  }
1785
1867
  };
1786
1868
  const [queryParams, runSearch] = generateQueryParams(nextAction, state);
1787
1869
  if (debug && (debug === true || debug.executeSearch)) debugExecuteSearch(nextAction, state);
1870
+
1788
1871
  if (runSearch) {
1789
1872
  yield effects.put({
1790
1873
  type: EXECUTE_SEARCH,
1791
1874
  facet,
1792
1875
  context
1793
1876
  });
1794
- yield effects.call(executeSearch, {
1795
- ...nextAction,
1877
+ yield effects.call(executeSearch, { ...nextAction,
1796
1878
  context,
1797
1879
  facet,
1798
1880
  queryParams,
@@ -1804,6 +1886,7 @@ function* ensureSearch(action) {
1804
1886
  log__namespace.error(...['Error running search saga:', error, error.stack]);
1805
1887
  }
1806
1888
  }
1889
+
1807
1890
  function* executeSearch(action) {
1808
1891
  const {
1809
1892
  context,
@@ -1811,12 +1894,14 @@ function* executeSearch(action) {
1811
1894
  queryParams,
1812
1895
  mappers
1813
1896
  } = action;
1897
+
1814
1898
  try {
1815
1899
  const state = yield effects.select();
1816
1900
  let result = {};
1817
1901
  let featuredResult;
1818
1902
  let featuredQuery;
1819
1903
  const customApi = getCustomApi(state, facet, context, 'js');
1904
+
1820
1905
  if (customApi) {
1821
1906
  const apiParams = typeof mappers === 'object' && typeof mappers.customApi === 'function' && mappers.customApi(queryParams) || mapQueryParamsToCustomApi(queryParams);
1822
1907
  result.payload = yield callCustomApi(customApi, apiParams);
@@ -1824,16 +1909,19 @@ function* executeSearch(action) {
1824
1909
  } else {
1825
1910
  if (queryParams.featuredResults) {
1826
1911
  featuredQuery = searchQuery(queryParams, true);
1827
- featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env);
1828
- // eslint-disable-next-line require-atomic-updates
1912
+ featuredResult = yield timedSearch(featuredQuery, queryParams.linkDepth, queryParams.projectId, queryParams.env); // eslint-disable-next-line require-atomic-updates
1913
+
1829
1914
  queryParams.excludeIds = getItemsFromResult(featuredResult).map(fi => {
1830
1915
  var _fi$sys;
1916
+
1831
1917
  return fi === null || fi === void 0 ? void 0 : (_fi$sys = fi.sys) === null || _fi$sys === void 0 ? void 0 : _fi$sys.id;
1832
1918
  }).filter(fi => typeof fi === 'string');
1833
1919
  }
1920
+
1834
1921
  const query = searchQuery(queryParams);
1835
1922
  result = yield timedSearch(query, queryParams.linkDepth, queryParams.projectId, queryParams.env);
1836
1923
  }
1924
+
1837
1925
  const createStateFrom = {
1838
1926
  action,
1839
1927
  featuredResult,
@@ -1849,6 +1937,7 @@ function* executeSearch(action) {
1849
1937
  log__namespace.error(...['Error running search saga:', error, error.stack]);
1850
1938
  }
1851
1939
  }
1940
+
1852
1941
  function* preloadOtherFacets(action) {
1853
1942
  const {
1854
1943
  preload,
@@ -1858,19 +1947,18 @@ function* preloadOtherFacets(action) {
1858
1947
  } = action;
1859
1948
  const state = yield effects.select();
1860
1949
  const currentFacet = getCurrentFacet(state);
1861
- if (!preload && facet === currentFacet && context !== Context.listings) {
1950
+
1951
+ if (!preload && facet === currentFacet && context !== exports.Context.listings) {
1862
1952
  const allFacets = getFacets(state, 'js');
1863
1953
  const otherFacets = Object.keys(allFacets).filter(f => f !== currentFacet);
1864
1954
  yield effects.all(otherFacets.map((preloadFacet = '') => {
1865
- const preloadAction = {
1866
- ...action,
1955
+ const preloadAction = { ...action,
1867
1956
  facet: preloadFacet,
1868
1957
  preload: true
1869
1958
  };
1870
1959
  const [queryParams, runSearch] = generateQueryParams(preloadAction, state);
1871
1960
  if (debug && (debug === true || debug.preloadOtherFacets)) debugExecuteSearch(preloadAction, state);
1872
- return runSearch && effects.call(executeSearch, {
1873
- ...action,
1961
+ return runSearch && effects.call(executeSearch, { ...action,
1874
1962
  type: EXECUTE_SEARCH_PRELOAD,
1875
1963
  preload: true,
1876
1964
  facet: preloadFacet,
@@ -1879,6 +1967,7 @@ function* preloadOtherFacets(action) {
1879
1967
  }));
1880
1968
  }
1881
1969
  }
1970
+
1882
1971
  function* updateCurrentTab(action) {
1883
1972
  const {
1884
1973
  id,
@@ -1888,16 +1977,19 @@ function* updateCurrentTab(action) {
1888
1977
  const facets = getFacets(state, 'js');
1889
1978
  const tabs = getSearchTabs(state, 'js');
1890
1979
  let nextFacet = tabs === null || tabs === void 0 ? void 0 : tabs[id].currentFacet;
1980
+
1891
1981
  if (!nextFacet) {
1892
1982
  Object.entries(facets).map(([facetName, facet]) => {
1893
1983
  if (facet.tabId === id && (tabs === null || tabs === void 0 ? void 0 : tabs[id].defaultFacet) === facetName) nextFacet = facetName;
1894
1984
  });
1895
- }
1896
- // If the next Tab does not have a defaultFacet,
1985
+ } // If the next Tab does not have a defaultFacet,
1897
1986
  // take the first facet for that tab
1987
+
1988
+
1898
1989
  if (!nextFacet) nextFacet = Object.entries(facets).filter(([, f]) => f.tabId === id)[0][0];
1899
1990
  yield effects.put(withMappers(updateCurrentFacet$1(nextFacet), mappers));
1900
1991
  }
1992
+
1901
1993
  function* clearFilters(action) {
1902
1994
  const {
1903
1995
  mappers
@@ -1905,6 +1997,7 @@ function* clearFilters(action) {
1905
1997
  const uri = yield buildUri({}, mappers);
1906
1998
  yield effects.put(navigate(uri));
1907
1999
  }
2000
+
1908
2001
  function* updateCurrentFacet(action) {
1909
2002
  const {
1910
2003
  facet,
@@ -1917,6 +2010,7 @@ function* updateCurrentFacet(action) {
1917
2010
  }, mappers);
1918
2011
  yield effects.put(navigate(uri));
1919
2012
  }
2013
+
1920
2014
  function* updateSearchTerm(action) {
1921
2015
  const {
1922
2016
  term,
@@ -1927,6 +2021,7 @@ function* updateSearchTerm(action) {
1927
2021
  }, mappers);
1928
2022
  yield effects.put(navigate(uri));
1929
2023
  }
2024
+
1930
2025
  function* updateSortOrder(action) {
1931
2026
  const {
1932
2027
  orderBy,
@@ -1939,6 +2034,7 @@ function* updateSortOrder(action) {
1939
2034
  }, mappers);
1940
2035
  yield effects.put(navigate(uri));
1941
2036
  }
2037
+
1942
2038
  function* updatePageIndex(action) {
1943
2039
  const {
1944
2040
  pageIndex,
@@ -1951,6 +2047,7 @@ function* updatePageIndex(action) {
1951
2047
  yield effects.put(navigate(uri));
1952
2048
  if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
1953
2049
  }
2050
+
1954
2051
  function* updatePageSize(action) {
1955
2052
  const {
1956
2053
  pageSize,
@@ -1963,6 +2060,7 @@ function* updatePageSize(action) {
1963
2060
  yield effects.put(navigate(uri));
1964
2061
  if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
1965
2062
  }
2063
+
1966
2064
  function* applySearchFilter(action) {
1967
2065
  const {
1968
2066
  mappers,
@@ -1972,6 +2070,7 @@ function* applySearchFilter(action) {
1972
2070
  yield effects.put(navigate(uri));
1973
2071
  if (typeof scrollToElement !== 'undefined') scrollTo(scrollToElement);
1974
2072
  }
2073
+
1975
2074
  function* buildUri({
1976
2075
  facet,
1977
2076
  orderBy,
@@ -1988,10 +2087,11 @@ function* buildUri({
1988
2087
  pageIndex,
1989
2088
  pageSize,
1990
2089
  term
1991
- });
1992
- // return uri;
2090
+ }); // return uri;
2091
+
1993
2092
  return `${uri.path}${uri.search && `?${uri.search}` || ''}${uri.hash && `#${uri.hash}` || ''}`;
1994
2093
  }
2094
+
1995
2095
  function* triggerMinilistSsr(options) {
1996
2096
  yield effects.call(doSearch, {
1997
2097
  type: DO_SEARCH,
@@ -2007,7 +2107,6 @@ function* triggerSearchSsr(options) {
2007
2107
 
2008
2108
  exports.APPLY_CONFIG = APPLY_CONFIG;
2009
2109
  exports.CLEAR_FILTERS = CLEAR_FILTERS;
2010
- exports.Context = Context;
2011
2110
  exports.EXECUTE_SEARCH = EXECUTE_SEARCH;
2012
2111
  exports.EXECUTE_SEARCH_ERROR = EXECUTE_SEARCH_ERROR;
2013
2112
  exports.LOAD_FILTERS = LOAD_FILTERS;
@@ -2073,4 +2172,4 @@ exports.updateSearchTerm = updateSearchTerm$1;
2073
2172
  exports.updateSelectedFilters = updateSelectedFilters;
2074
2173
  exports.updateSortOrder = updateSortOrder$1;
2075
2174
  exports.withMappers = withMappers;
2076
- //# sourceMappingURL=sagas-e04b94c1.js.map
2175
+ //# sourceMappingURL=sagas-570f23ba.js.map