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

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