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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/cjs/{App-7ff737fa.js → App-b56aca04.js} +139 -94
  2. package/cjs/{App-7ff737fa.js.map → App-b56aca04.js.map} +1 -1
  3. package/cjs/{ChangePassword.container-a617190b.js → ChangePassword.container-ae35785e.js} +120 -62
  4. package/{esm/ChangePassword.container-ae0f9ce4.js.map → cjs/ChangePassword.container-ae35785e.js.map} +1 -1
  5. package/cjs/{ContensisDeliveryApi-9e32960d.js → ContensisDeliveryApi-4fcf049d.js} +71 -17
  6. package/{esm/ContensisDeliveryApi-c66b0cc3.js.map → cjs/ContensisDeliveryApi-4fcf049d.js.map} +1 -1
  7. package/cjs/CookieConstants-000427db.js.map +1 -1
  8. package/cjs/RouteLoader-c06dccd5.js +321 -0
  9. package/cjs/RouteLoader-c06dccd5.js.map +1 -0
  10. package/cjs/{ToJs-149fc5e1.js → ToJs-a8d8f3f0.js} +14 -6
  11. package/cjs/{ToJs-149fc5e1.js.map → ToJs-a8d8f3f0.js.map} +1 -1
  12. package/cjs/client.js +52 -22
  13. package/cjs/client.js.map +1 -1
  14. package/cjs/contensis-react-base.js +277 -140
  15. package/cjs/contensis-react-base.js.map +1 -1
  16. package/cjs/forms.js +717 -228
  17. package/cjs/forms.js.map +1 -1
  18. package/cjs/{fromJSLeaveImmer-7c363211.js → fromJSLeaveImmer-e74c673c.js} +4 -1
  19. package/cjs/{fromJSLeaveImmer-7c363211.js.map → fromJSLeaveImmer-e74c673c.js.map} +1 -1
  20. package/cjs/{reducers-9afb5f89.js → reducers-73a03ef4.js} +31 -10
  21. package/cjs/{reducers-9afb5f89.js.map → reducers-73a03ef4.js.map} +1 -1
  22. package/cjs/redux.js +4 -5
  23. package/cjs/redux.js.map +1 -1
  24. package/cjs/routing.js +6 -5
  25. package/cjs/routing.js.map +1 -1
  26. package/cjs/{sagas-e04b94c1.js → sagas-570f23ba.js} +286 -187
  27. package/cjs/{sagas-e04b94c1.js.map → sagas-570f23ba.js.map} +1 -1
  28. package/cjs/search.js +82 -56
  29. package/cjs/search.js.map +1 -1
  30. package/cjs/{selectors-46b689d0.js → selectors-14caa813.js} +6 -1
  31. package/cjs/selectors-14caa813.js.map +1 -0
  32. package/cjs/urls-6fcaf4c6.js.map +1 -1
  33. package/cjs/user.js +9 -4
  34. package/cjs/user.js.map +1 -1
  35. package/cjs/util.js +55 -35
  36. package/cjs/util.js.map +1 -1
  37. package/cjs/{version-79a027cb.js → version-34d91f68.js} +60 -26
  38. package/cjs/version-34d91f68.js.map +1 -0
  39. package/cjs/{version-afd4f77e.js → version-a410c88e.js} +6 -3
  40. package/cjs/{version-afd4f77e.js.map → version-a410c88e.js.map} +1 -1
  41. package/esm/{App-ff944c78.js → App-83107d7e.js} +137 -92
  42. package/esm/{App-ff944c78.js.map → App-83107d7e.js.map} +1 -1
  43. package/esm/{ChangePassword.container-ae0f9ce4.js → ChangePassword.container-76fd5e9b.js} +120 -62
  44. package/{cjs/ChangePassword.container-a617190b.js.map → esm/ChangePassword.container-76fd5e9b.js.map} +1 -1
  45. package/esm/{ContensisDeliveryApi-c66b0cc3.js → ContensisDeliveryApi-fe57a037.js} +71 -17
  46. package/{cjs/ContensisDeliveryApi-9e32960d.js.map → esm/ContensisDeliveryApi-fe57a037.js.map} +1 -1
  47. package/esm/CookieConstants-3d3b6531.js.map +1 -1
  48. package/esm/RouteLoader-29fd689a.js +310 -0
  49. package/esm/RouteLoader-29fd689a.js.map +1 -0
  50. package/esm/{ToJs-ae860aad.js → ToJs-df57f31d.js} +14 -6
  51. package/esm/{ToJs-ae860aad.js.map → ToJs-df57f31d.js.map} +1 -1
  52. package/esm/client.js +52 -23
  53. package/esm/client.js.map +1 -1
  54. package/esm/contensis-react-base.js +272 -137
  55. package/esm/contensis-react-base.js.map +1 -1
  56. package/esm/forms.js +717 -228
  57. package/esm/forms.js.map +1 -1
  58. package/esm/{fromJSLeaveImmer-e2dacd63.js → fromJSLeaveImmer-0114ffcf.js} +4 -1
  59. package/esm/{fromJSLeaveImmer-e2dacd63.js.map → fromJSLeaveImmer-0114ffcf.js.map} +1 -1
  60. package/esm/{reducers-3d5c37d1.js → reducers-aa8cef1e.js} +31 -10
  61. package/esm/{reducers-3d5c37d1.js.map → reducers-aa8cef1e.js.map} +1 -1
  62. package/esm/redux.js +7 -8
  63. package/esm/redux.js.map +1 -1
  64. package/esm/routing.js +3 -5
  65. package/esm/routing.js.map +1 -1
  66. package/esm/{sagas-933a8fc8.js → sagas-07e82e18.js} +239 -139
  67. package/esm/{sagas-933a8fc8.js.map → sagas-07e82e18.js.map} +1 -1
  68. package/esm/search.js +83 -57
  69. package/esm/search.js.map +1 -1
  70. package/esm/{selectors-01074974.js → selectors-691caf02.js} +6 -1
  71. package/esm/selectors-691caf02.js.map +1 -0
  72. package/esm/urls-eac9a747.js.map +1 -1
  73. package/esm/user.js +11 -6
  74. package/esm/user.js.map +1 -1
  75. package/esm/util.js +55 -35
  76. package/esm/util.js.map +1 -1
  77. package/esm/{version-346a9787.js → version-3d9911e2.js} +60 -26
  78. package/esm/version-3d9911e2.js.map +1 -0
  79. package/esm/{version-0fbd1b82.js → version-9f29becb.js} +6 -3
  80. package/esm/{version-0fbd1b82.js.map → version-9f29becb.js.map} +1 -1
  81. package/models/app/App.d.ts +3 -3
  82. package/models/app/pages/VersionInfo/components/VersionInfo.d.ts +5 -3
  83. package/models/redux/appstate.d.ts +2 -3
  84. package/models/redux/store/history.d.ts +2 -2
  85. package/models/routing/components/Loading.d.ts +2 -2
  86. package/models/routing/components/NotFound.d.ts +2 -2
  87. package/models/routing/components/Redirect.d.ts +5 -0
  88. package/models/routing/components/StaticRouteLoader.d.ts +6 -0
  89. package/models/routing/components/Status.d.ts +1 -1
  90. package/models/routing/httpContext.d.ts +7 -0
  91. package/models/routing/index.d.ts +3 -0
  92. package/models/routing/redux/actions.d.ts +2 -3
  93. package/models/routing/routes.d.ts +11 -5
  94. package/models/user/components/Login.d.ts +2 -1
  95. package/models/user/components/LoginForm.d.ts +2 -1
  96. package/models/user/components/LogoutForm.d.ts +2 -1
  97. package/models/user/containers/ChangePassword.container.d.ts +1 -1
  98. package/models/user/containers/ForgotPassword.container.d.ts +1 -1
  99. package/models/user/containers/Login.container.d.ts +1 -1
  100. package/models/user/containers/Registration.container.d.ts +1 -1
  101. package/models/user/hocs/withLogin.d.ts +2 -1
  102. package/models/user/hocs/withRegistration.d.ts +1 -1
  103. package/models/util/ContensisDeliveryApi.d.ts +0 -1
  104. package/models/util/ToJs.d.ts +1 -1
  105. package/models/util/mergeStaticRoutes.d.ts +1 -0
  106. package/package.json +7 -10
  107. package/cjs/RouteLoader-049e81e5.js +0 -203
  108. package/cjs/RouteLoader-049e81e5.js.map +0 -1
  109. package/cjs/selectors-46b689d0.js.map +0 -1
  110. package/cjs/version-79a027cb.js.map +0 -1
  111. package/esm/RouteLoader-02eef6d9.js +0 -197
  112. package/esm/RouteLoader-02eef6d9.js.map +0 -1
  113. package/esm/selectors-01074974.js.map +0 -1
  114. package/esm/version-346a9787.js.map +0 -1
@@ -1,12 +1,12 @@
1
- import { c as cachedSearch, d as deliveryApi } from './ContensisDeliveryApi-c66b0cc3.js';
1
+ import { c as cachedSearch, d as deliveryApi } from './ContensisDeliveryApi-fe57a037.js';
2
2
  import { Query as Query$1 } from 'contensis-delivery-api';
3
- import React from 'react';
3
+ import React$1 from 'react';
4
4
  import { Provider } from 'react-redux';
5
+ import { d as defaultExpressions, c as contentTypeIdExpression, f as filterExpressions, t as termExpressions, o as orderByExpression, a as customWhereExpressions } from './sagas-07e82e18.js';
5
6
  import mapJson from 'jsonpath-mapper';
6
7
  import 'reselect';
7
8
  import 'deepmerge';
8
9
  import 'query-string';
9
- import { d as defaultExpressions, c as contentTypeIdExpression, f as filterExpressions, t as termExpressions, o as orderByExpression, a as customWhereExpressions } from './sagas-933a8fc8.js';
10
10
  import 'immer';
11
11
  import 'deep-equal';
12
12
  import { Op, Query } from 'contensis-core-api';
@@ -19,8 +19,8 @@ import fs from 'fs';
19
19
  import path from 'path';
20
20
  import { path as path$1 } from 'app-root-path';
21
21
  import { renderToString } from 'react-dom/server';
22
- import { StaticRouter } from 'react-router-dom';
23
- import { matchRoutes } from 'react-router-config';
22
+ import require$$1 from 'history';
23
+ import require$$2, { matchRoutes } from 'react-router-dom';
24
24
  import { Helmet } from 'react-helmet';
25
25
  import { ServerStyleSheet } from 'styled-components';
26
26
  import serialize from 'serialize-javascript';
@@ -31,11 +31,12 @@ import { c as commonjsGlobal } from './_commonjsHelpers-1789f0cf.js';
31
31
  import { buildCleaner } from 'lodash-clean';
32
32
  import { CookiesProvider } from 'react-cookie';
33
33
  import cookiesMiddleware from 'universal-cookie-express';
34
- import { c as createStore } from './version-346a9787.js';
35
- import { h as history, p as pickProject, r as rootSaga } from './App-ff944c78.js';
36
- export { A as ReactApp } from './App-ff944c78.js';
37
- import { s as setVersionStatus, a as setVersion } from './version-0fbd1b82.js';
38
- import { s as selectSurrogateKeys, a as selectRouteEntry, b as selectCurrentProject, g as getImmutableOrJS, c as setCurrentProject } from './selectors-01074974.js';
34
+ import { c as createStore } from './version-3d9911e2.js';
35
+ import { h as history$1, p as pickProject, r as rootSaga } from './App-83107d7e.js';
36
+ export { A as ReactApp } from './App-83107d7e.js';
37
+ import { s as setVersionStatus, a as setVersion } from './version-9f29becb.js';
38
+ import { m as mergeStaticRoutes, H as HttpContext } from './RouteLoader-29fd689a.js';
39
+ import { s as selectSurrogateKeys, a as selectRouteEntry, b as selectCurrentProject, g as getImmutableOrJS, c as setCurrentProject } from './selectors-691caf02.js';
39
40
  import chalk from 'chalk';
40
41
  import './CookieConstants-3d3b6531.js';
41
42
  import 'loglevel';
@@ -44,13 +45,10 @@ import 'redux';
44
45
  import 'redux-thunk';
45
46
  import 'redux-saga';
46
47
  import 'redux-injectors';
47
- import './reducers-3d5c37d1.js';
48
- import 'history';
48
+ import './reducers-aa8cef1e.js';
49
49
  import 'await-to-js';
50
- import './ChangePassword.container-ae0f9ce4.js';
51
- import './ToJs-ae860aad.js';
52
- import 'react-hot-loader';
53
- import './RouteLoader-02eef6d9.js';
50
+ import './ChangePassword.container-76fd5e9b.js';
51
+ import './ToJs-df57f31d.js';
54
52
 
55
53
  /**
56
54
  * Util class holds our search results helper boilerplate methods
@@ -60,20 +58,26 @@ class Util {
60
58
  if (fieldId) {
61
59
  return entries === null || entries === void 0 ? void 0 : entries.map(e => {
62
60
  var _e$fieldId, _e$fieldId2, _e$fieldId2$sys;
61
+
63
62
  return Array.isArray(e === null || e === void 0 ? void 0 : e[fieldId]) ? e === null || e === void 0 ? void 0 : (_e$fieldId = e[fieldId]) === null || _e$fieldId === void 0 ? void 0 : _e$fieldId.map(f => {
64
63
  var _f$sys;
64
+
65
65
  return f === null || f === void 0 ? void 0 : (_f$sys = f.sys) === null || _f$sys === void 0 ? void 0 : _f$sys.id;
66
66
  }) : (e === null || e === void 0 ? void 0 : (_e$fieldId2 = e[fieldId]) === null || _e$fieldId2 === void 0 ? void 0 : (_e$fieldId2$sys = _e$fieldId2.sys) === null || _e$fieldId2$sys === void 0 ? void 0 : _e$fieldId2$sys.id) || '';
67
67
  }).flat();
68
68
  }
69
+
69
70
  return entries === null || entries === void 0 ? void 0 : entries.map(e => {
70
71
  var _e$sys;
72
+
71
73
  return (e === null || e === void 0 ? void 0 : (_e$sys = e.sys) === null || _e$sys === void 0 ? void 0 : _e$sys.id) || '';
72
74
  });
73
75
  }
76
+
74
77
  static GetItems(result) {
75
78
  return this.GetResults(result) ? result.items : [];
76
79
  }
80
+
77
81
  static GetResults(result) {
78
82
  if (result !== null && result !== void 0 && result.items) {
79
83
  return result;
@@ -81,18 +85,20 @@ class Util {
81
85
  return null;
82
86
  }
83
87
  }
88
+
84
89
  }
85
90
  const mergeResults = (results, parentResults, replaceContentTypeIds, linkFieldId) => results.map(r => {
86
91
  if (replaceContentTypeIds.some(c => c === r.sys.contentTypeId)) {
87
92
  const resolvedParent = parentResults === null || parentResults === void 0 ? void 0 : parentResults.find(e => {
88
93
  var _e$linkFieldId;
94
+
89
95
  return (_e$linkFieldId = e[linkFieldId]) === null || _e$linkFieldId === void 0 ? void 0 : _e$linkFieldId.some(l => {
90
96
  var _l$sys;
97
+
91
98
  return ((_l$sys = l.sys) === null || _l$sys === void 0 ? void 0 : _l$sys.id) === r.sys.id;
92
99
  });
93
100
  });
94
- if (resolvedParent) return {
95
- ...resolvedParent,
101
+ if (resolvedParent) return { ...resolvedParent,
96
102
  ...r,
97
103
  entryTitle: resolvedParent.entryTitle,
98
104
  entryDescription: resolvedParent.entryDescription,
@@ -100,10 +106,12 @@ const mergeResults = (results, parentResults, replaceContentTypeIds, linkFieldId
100
106
  originalSys: r.sys
101
107
  };else return r;
102
108
  }
109
+
103
110
  return r;
104
111
  }).filter(r => r);
105
112
 
106
113
  /* eslint-disable no-console */
114
+
107
115
  /**
108
116
  * Builds our complete Delivery API Query object from a set of provided arguments
109
117
  * @param queryParams
@@ -128,12 +136,13 @@ const searchQuery = ({
128
136
  const expressions$1 = [...defaultExpressions(versionStatus), ...contentTypeIdExpression(contentTypeIds, webpageTemplates, assetTypes), ...customWhereExpressions(customWhere), ...filterExpressions(filters), ...filterExpressions(idFilters), ...((sharedFilters === null || sharedFilters === void 0 ? void 0 : sharedFilters.length) > 0 ? [Op.or(...filterExpressions(sharedFilters, true))] : []), ...termExpressions(searchTerm || '', weightedSearchFields || [])];
129
137
  const query = new Query(...expressions$1);
130
138
  query.orderBy = orderByExpression(orderBy || []);
139
+
131
140
  if (fields && fields.length > 0) {
132
141
  query.fields = fields;
133
- }
134
-
135
- // (query as any).includeArchived = true;
142
+ } // (query as any).includeArchived = true;
136
143
  // (query as any).includeDeleted = true;
144
+
145
+
137
146
  query.pageIndex = pageIndex;
138
147
  query.pageSize = pageSize;
139
148
  return query;
@@ -156,8 +165,7 @@ const finalQuery = ({
156
165
  webpageTemplates,
157
166
  weightedSearchFields
158
167
  }, children) => {
159
- const expressions$1 = [...defaultExpressions(versionStatus), Op.or(Op.and(...contentTypeIdExpression(contentTypeIds, webpageTemplates, assetTypes), ...filterExpressions(filters), ...filterExpressions(idFilters || []), ...(sharedFilters !== null && sharedFilters !== void 0 && sharedFilters.length ? [Op.or(...filterExpressions(sharedFilters || [])
160
- // Op.and(
168
+ const expressions$1 = [...defaultExpressions(versionStatus), Op.or(Op.and(...contentTypeIdExpression(contentTypeIds, webpageTemplates, assetTypes), ...filterExpressions(filters), ...filterExpressions(idFilters || []), ...(sharedFilters !== null && sharedFilters !== void 0 && sharedFilters.length ? [Op.or(...filterExpressions(sharedFilters || []) // Op.and(
161
169
  // ...sharedFilters.map(sf =>
162
170
  // Op.not(exp.fieldExpression(sf.key, true, 'exists')[0])
163
171
  // ),
@@ -166,17 +174,17 @@ const finalQuery = ({
166
174
  )] : [])), ...children.map(child => Op.and(...contentTypeIdExpression(child.contentTypeIds, child.webpageTemplates, child.assetTypes), ...filterExpressions(child.sharedFilters || []), ...filterExpressions(child.idFilters || [])))), ...termExpressions(searchTerm || '', weightedSearchFields || [])];
167
175
  const query = new Query(...expressions$1);
168
176
  query.orderBy = orderByExpression(orderBy || []);
177
+
169
178
  if (fields && fields.length > 0) {
170
179
  query.fields = fields;
171
- }
172
-
173
- // (query as any).includeArchived = true;
180
+ } // (query as any).includeArchived = true;
174
181
  // (query as any).includeDeleted = true;
182
+
183
+
175
184
  query.pageIndex = pageIndex || 0;
176
185
  query.pageSize = pageSize;
177
186
  return query;
178
187
  };
179
-
180
188
  /**
181
189
  * Create a filter expression from a provided filters configuration object
182
190
  * and populate them based on the presence of that key in params, filter
@@ -185,10 +193,13 @@ const finalQuery = ({
185
193
  * @param params request.query object from Express middleware
186
194
  * @returns FilterExpression[] we can use to use with searchQuery function
187
195
  */
196
+
188
197
  const makeFilterExpressions = (f, params) => {
189
198
  const expressions = [];
199
+
190
200
  for (const [paramKey, filterConfig] of Object.entries(f)) {
191
201
  var _params$paramKey;
202
+
192
203
  const filterValues = (_params$paramKey = params[paramKey]) === null || _params$paramKey === void 0 ? void 0 : _params$paramKey.split(',');
193
204
  if (typeof filterValues !== 'undefined') expressions.push({
194
205
  key: typeof filterConfig === 'object' ? filterConfig.fieldId : filterConfig,
@@ -197,6 +208,7 @@ const makeFilterExpressions = (f, params) => {
197
208
  logicOperator: typeof filterConfig === 'object' && filterConfig.logicOperator ? filterConfig.logicOperator : 'or'
198
209
  });
199
210
  }
211
+
200
212
  return expressions;
201
213
  };
202
214
  const makeDerivedIdsFilterExpression = (prevFieldId, entries, ownIds = false, alwaysApplyFilter = false) => {
@@ -229,6 +241,7 @@ const resolveParentEntries = async (parentContentTypeIds, replaceContentTypeIds,
229
241
  };
230
242
 
231
243
  /* eslint-disable no-console */
244
+
232
245
  class QueryLevelResults {
233
246
  constructor({
234
247
  level: _level,
@@ -261,11 +274,13 @@ class QueryLevelResults {
261
274
  this.firstResults = {};
262
275
  this.finalQuery = new Query$1();
263
276
  this.finalResults = {};
277
+
264
278
  this.AddChild = ({
265
279
  child
266
280
  }) => {
267
281
  this.children.push(child);
268
282
  };
283
+
269
284
  this.RunFirstQuery = async () => {
270
285
  const {
271
286
  firstQuery: query,
@@ -273,17 +288,18 @@ class QueryLevelResults {
273
288
  parent,
274
289
  runFirstQuery
275
290
  } = this;
291
+
276
292
  if (parent !== null && parent !== void 0 && parent.validatedLinks.length) {
277
293
  // add any idFilters derived from parent query results
278
294
  appendSearchQueryFilters(query, makeFilterExpressions(Object.fromEntries(parent.validatedLinks.map(vl => [vl.linkFieldId, {
279
295
  fieldId: `sys.id`
280
296
  }])), Object.fromEntries(parent.validatedLinks.map(vl => [vl.linkFieldId, vl.entryIds.join(',') || `no ids from parent ${parent.level}`]))));
281
297
  }
298
+
282
299
  if (runFirstQuery) {
283
300
  if (this.debug) console.log(`\nLevel ${this.level} - First query: \n${JSON.stringify(query.toJSON()).substring(0, 1000)}`);
284
- this.firstResults = await cachedSearch.searchUsingPost(query, 0, params.projectId);
301
+ this.firstResults = await cachedSearch.searchUsingPost(query, 0, params.projectId); // mapResultsToValidatedLinks
285
302
 
286
- // mapResultsToValidatedLinks
287
303
  for (const linkFieldId of this.linkFieldIds) {
288
304
  this.validatedLinks.push({
289
305
  contentTypeId: this.linkFields[linkFieldId].contentTypeId || '',
@@ -293,6 +309,7 @@ class QueryLevelResults {
293
309
  }
294
310
  }
295
311
  };
312
+
296
313
  this.RunFinalQuery = async () => {
297
314
  const {
298
315
  level,
@@ -301,30 +318,31 @@ class QueryLevelResults {
301
318
  params,
302
319
  runFinalQuery
303
320
  } = this;
321
+
304
322
  if (!children.some(c => c.returnEntries)) {
305
- const firstChild = children === null || children === void 0 ? void 0 : children[0];
306
- // add any idFilters derived from child query results
323
+ const firstChild = children === null || children === void 0 ? void 0 : children[0]; // add any idFilters derived from child query results
324
+
307
325
  if (firstChild) appendSearchQueryFilters(query, makeFilterExpressions(Object.fromEntries(firstChild.validatedLinks.map(vl => [vl.linkFieldId, {
308
326
  fieldId: `${vl.linkFieldId}.sys.id`
309
327
  }])), Object.fromEntries(firstChild.validatedLinks.map(vl => [vl.linkFieldId, vl.entryIds.join(',') || `no ids from child ${firstChild.level}`]))));
310
328
  }
329
+
311
330
  if (level === 0 && this.returnEntries) {
312
331
  // This is the final query to be run and response returned to the caller
313
332
  // Only this bit cares about linkDepth, fields and pagination parameters
314
333
  query.fields = JSON.parse(params.fields || '[]');
315
334
  query.pageSize = params.pageSize;
316
- query.pageIndex = params.pageIndex;
317
- // query.orderBy = params.orderBy;
335
+ query.pageIndex = params.pageIndex; // query.orderBy = params.orderBy;
318
336
  }
319
337
 
320
338
  if (runFinalQuery) {
321
339
  if (this.debug) console.log(`\nLevel ${this.level} - Final query: \n${JSON.stringify(query.toJSON()).substring(0, 1000)}`);
322
340
  this.finalResults = await cachedSearch.searchUsingPost(query, Number(params.linkDepth) || 0, params.projectId);
323
- if (this.parent) this.parent.runFinalQuery = true;
341
+ if (this.parent) this.parent.runFinalQuery = true; // mapResultsToValidatedLinks
324
342
 
325
- // mapResultsToValidatedLinks
326
343
  for (const linkFieldId of ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.linkFieldIds) || []) {
327
344
  var _this$parent, _this$parent2;
345
+
328
346
  this.validatedLinks.push({
329
347
  contentTypeId: ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.linkFields[linkFieldId].contentTypeId) || '',
330
348
  linkFieldId,
@@ -333,14 +351,17 @@ class QueryLevelResults {
333
351
  }
334
352
  }
335
353
  };
354
+
336
355
  this.GetResultsEntries = () => {
337
356
  var _finalResults$items;
357
+
338
358
  const {
339
359
  finalResults,
340
360
  firstResults
341
361
  } = this;
342
362
  return finalResults !== null && finalResults !== void 0 && (_finalResults$items = finalResults.items) !== null && _finalResults$items !== void 0 && _finalResults$items.length ? finalResults.items : firstResults.items;
343
363
  };
364
+
344
365
  this.GetResults = () => {
345
366
  const {
346
367
  finalResults,
@@ -348,6 +369,7 @@ class QueryLevelResults {
348
369
  } = this;
349
370
  return typeof (finalResults === null || finalResults === void 0 ? void 0 : finalResults.totalCount) !== 'undefined' ? finalResults : firstResults;
350
371
  };
372
+
351
373
  this.level = _level;
352
374
  this.contentTypeIds = contentTypeIds;
353
375
  this.linkFields = linkFields;
@@ -384,9 +406,11 @@ class QueryLevelResults {
384
406
  versionStatus: _params.versionStatus
385
407
  });
386
408
  }
409
+
387
410
  }
388
411
 
389
412
  /* eslint-disable no-console */
413
+
390
414
  class LinkDepthSearchService {
391
415
  constructor({
392
416
  contentTypeId: _contentTypeId = '',
@@ -403,27 +427,29 @@ class LinkDepthSearchService {
403
427
  this.params = void 0;
404
428
  this.debug = void 0;
405
429
  this.queryLevels = void 0;
430
+
406
431
  this.DoSearch = async () => {
407
432
  // Run queries "top-down" through each level of `linkField`
408
433
  for (const queryLevel of this.queryLevels) {
409
434
  await queryLevel.RunFirstQuery();
410
- }
435
+ } // Run queries "bottom-up" through each level of `linkField`
436
+
411
437
 
412
- // Run queries "bottom-up" through each level of `linkField`
413
438
  for (const queryLevel of [...this.queryLevels].reverse()) {
414
439
  await queryLevel.RunFinalQuery();
415
- }
416
-
417
- // Run a final query that will aggregate the results from all levels
440
+ } // Run a final query that will aggregate the results from all levels
418
441
  // adding all levels to the query that have `returnEntries` set true
442
+
443
+
419
444
  return await this.RunFinalQueries();
420
445
  };
446
+
421
447
  this.RunFinalQueries = async () => {
422
- const finalQueryLevels = this.queryLevels.filter(ql => ql.level > 0 && ql.returnEntries || ql.level === 0 && ql.returnEntries !== false);
448
+ const finalQueryLevels = this.queryLevels.filter(ql => ql.level > 0 && ql.returnEntries || ql.level === 0 && ql.returnEntries !== false); // Decide if we need a further final query if any child level(s) have had `returnEntries` set to true
423
449
 
424
- // Decide if we need a further final query if any child level(s) have had `returnEntries` set to true
425
450
  if (finalQueryLevels.length > 1 || finalQueryLevels.length === 1 && finalQueryLevels[0].level !== 0) {
426
451
  var _params$orderBy;
452
+
427
453
  // Build final query
428
454
  const {
429
455
  contentTypeIds,
@@ -438,9 +464,9 @@ class LinkDepthSearchService {
438
464
  }
439
465
  }, {
440
466
  [vl.linkFieldId]: vl.entryIds.join(',') || 'no results for filter'
441
- })).flat() || [];
442
- // This is the final query to be run and response returned to the caller
467
+ })).flat() || []; // This is the final query to be run and response returned to the caller
443
468
  // Only this bit cares about linkDepth, fields and pagination parameters
469
+
444
470
  const query = finalQuery({
445
471
  contentTypeIds,
446
472
  filters: makeFilterExpressions(filters, params),
@@ -448,6 +474,7 @@ class LinkDepthSearchService {
448
474
  idFilters: derivedIdFilters,
449
475
  fields: params.fields ? [...JSON.parse(params.fields), ...finalQueryLevels.map(l => {
450
476
  var _l$parent;
477
+
451
478
  return ((_l$parent = l.parent) === null || _l$parent === void 0 ? void 0 : _l$parent.linkFieldIds) || [];
452
479
  }).flat()] : [],
453
480
  orderBy: (_params$orderBy = params.orderBy) === null || _params$orderBy === void 0 ? void 0 : _params$orderBy.split(','),
@@ -457,6 +484,7 @@ class LinkDepthSearchService {
457
484
  versionStatus: params.versionStatus
458
485
  }, (finalQueryLevels === null || finalQueryLevels === void 0 ? void 0 : finalQueryLevels[0].children.filter(ql => ql.returnEntries).map(ql => {
459
486
  var _ql$parent, _ql$parent2;
487
+
460
488
  const entriesAtLevel = ql.GetResultsEntries() || ((_ql$parent = ql.parent) === null || _ql$parent === void 0 ? void 0 : _ql$parent.GetResultsEntries());
461
489
  const previousIdsFilter = ql.returnEntries || !!ql.children.some(qc => qc.returnEntries) ? (_ql$parent2 = ql.parent) === null || _ql$parent2 === void 0 ? void 0 : _ql$parent2.linkFieldIds.map(fieldId => makeDerivedIdsFilterExpression(fieldId, entriesAtLevel, true, ql.runFinalQuery)).flat() : [];
462
490
  return {
@@ -467,28 +495,29 @@ class LinkDepthSearchService {
467
495
  };
468
496
  })) || []);
469
497
  if (this.debug) console.log(`\nFinal query: ${derivedIds.reduce((accumulator, object) => accumulator + object.entryIds.length, 0)} derived ids \n${JSON.stringify(query.toJSON()).substring(0, 1000)}`);
470
- const finalQueryResult = await cachedSearch.searchUsingPost(query, Number(params.linkDepth) || 0, params.projectId);
471
-
472
- // Resolve any parent entries
498
+ const finalQueryResult = await cachedSearch.searchUsingPost(query, Number(params.linkDepth) || 0, params.projectId); // Resolve any parent entries
473
499
 
474
500
  const resolveParentLevels = finalQueryLevels.filter(ql => ql.resolveFirstParent);
475
501
  let entries = finalQueryResult.items;
502
+
476
503
  for (const resolveParents of resolveParentLevels) {
477
504
  var _resolveParents$paren, _resolveParents$paren2;
478
- entries = await resolveParentEntries(((_resolveParents$paren = resolveParents.parent) === null || _resolveParents$paren === void 0 ? void 0 : _resolveParents$paren.contentTypeIds) || [], resolveParents.contentTypeIds, ((_resolveParents$paren2 = resolveParents.parent) === null || _resolveParents$paren2 === void 0 ? void 0 : _resolveParents$paren2.linkFieldIds[0]) || 'unknown', finalQueryResult.items,
479
- // or entries?
505
+
506
+ entries = await resolveParentEntries(((_resolveParents$paren = resolveParents.parent) === null || _resolveParents$paren === void 0 ? void 0 : _resolveParents$paren.contentTypeIds) || [], resolveParents.contentTypeIds, ((_resolveParents$paren2 = resolveParents.parent) === null || _resolveParents$paren2 === void 0 ? void 0 : _resolveParents$paren2.linkFieldIds[0]) || 'unknown', finalQueryResult.items, // or entries?
480
507
  this.params, this.debug);
481
508
  }
482
- return {
483
- ...finalQueryResult,
509
+
510
+ return { ...finalQueryResult,
484
511
  items: entries
485
512
  };
486
513
  } else {
487
514
  var _this$queryLevels$fin;
515
+
488
516
  if (this.debug) console.log(`\nNo further queries required\n`);
489
517
  return (_this$queryLevels$fin = this.queryLevels.find(ql => ql.level === 0)) === null || _this$queryLevels$fin === void 0 ? void 0 : _this$queryLevels$fin.GetResults();
490
518
  }
491
519
  };
520
+
492
521
  this.InitQueryLevels = () => {
493
522
  const createChildQueryLevels = (linkFields, parentQueryLevel, level = 1) => {
494
523
  return Object.entries(linkFields).map(([, {
@@ -521,6 +550,7 @@ class LinkDepthSearchService {
521
550
  return [thisLevel, ...createChildQueryLevels(linkFields, thisLevel, level + 1)];
522
551
  }).flat();
523
552
  };
553
+
524
554
  const {
525
555
  contentTypeIds,
526
556
  filters,
@@ -541,17 +571,17 @@ class LinkDepthSearchService {
541
571
  params,
542
572
  debug: this.debug
543
573
  });
544
- const queryLevels = [firstLevel, ...createChildQueryLevels(linkFields, firstLevel)];
545
- // return queryLevels;
546
-
574
+ const queryLevels = [firstLevel, ...createChildQueryLevels(linkFields, firstLevel)]; // return queryLevels;
547
575
  // If we are only returning entries from level 0
548
576
  // we can skip running the first query and finalQuery will suffice
577
+
549
578
  if (queryLevels.find(ql => ql.returnEntries && ql.level !== 0)) return queryLevels;else return queryLevels.map(ql => {
550
- ql.runFirstQuery = false;
551
- // ql.runFinalQuery = false;
579
+ ql.runFirstQuery = false; // ql.runFinalQuery = false;
580
+
552
581
  return ql;
553
582
  });
554
583
  };
584
+
555
585
  this.contentTypeIds = Array.isArray(_contentTypeId) ? _contentTypeId : [_contentTypeId];
556
586
  this.filters = _filters;
557
587
  this.sharedFilters = _sharedFilters;
@@ -560,6 +590,7 @@ class LinkDepthSearchService {
560
590
  this.debug = debug;
561
591
  this.queryLevels = this.InitQueryLevels();
562
592
  }
593
+
563
594
  }
564
595
 
565
596
  /**
@@ -579,9 +610,10 @@ const makeLinkDepthApi = (app, middlewareConfig) => {
579
610
  if (!contentTypeId || !linkFields || !uri) return;
580
611
  app.get(uri, makeLinkDepthMiddleware(middlewareConfig));
581
612
  };
582
-
583
613
  /** Create a content type hierarchy from supplied config and produces
584
614
  * a RequestHandler function to serve our Express middleware */
615
+
616
+
585
617
  const makeLinkDepthMiddleware = ({
586
618
  contentTypeId,
587
619
  filters = {},
@@ -597,9 +629,8 @@ const makeLinkDepthMiddleware = ({
597
629
  setCachingHeaders(res, {
598
630
  cacheControl: 'private',
599
631
  surrogateControl: '10'
600
- });
632
+ }); // Gather all params from the request, we will use them at the right query levels later
601
633
 
602
- // Gather all params from the request, we will use them at the right query levels later
603
634
  const params = Object.fromEntries([...Object.entries(req.params), ...Object.entries(req.query)].map(([k, v]) => [k, v === null || v === void 0 ? void 0 : v.toString()]));
604
635
  const result = await new LinkDepthSearchService({
605
636
  contentTypeId,
@@ -617,25 +648,35 @@ const makeLinkDepthMiddleware = ({
617
648
  res.json(error);
618
649
  }
619
650
  };
651
+
620
652
  return linkDepthMiddleware;
621
653
  } catch (error) {
622
654
  // This will be an error building the middleware
623
655
  // we can only serve what the error was as the request handler instead
624
656
  console.error(error);
657
+
625
658
  const errorMiddleware = async (req, res) => {
626
659
  res.statusCode = 500;
627
660
  res.json(JSON.stringify(error));
628
661
  };
662
+
629
663
  return errorMiddleware;
630
664
  }
631
665
  };
632
666
 
633
- const servers$1 = SERVERS; /* global SERVERS */
634
- const project = PROJECT; /* global PROJECT */
635
- const alias$1 = ALIAS; /* global ALIAS */
667
+ const servers$1 = SERVERS;
668
+ /* global SERVERS */
669
+
670
+ const project = PROJECT;
671
+ /* global PROJECT */
672
+
673
+ const alias$1 = ALIAS;
674
+ /* global ALIAS */
675
+
636
676
  const deliveryApiHostname = url(alias$1, project).api;
637
677
  const assetProxy = httpProxy.createProxyServer();
638
678
  const deliveryProxy = httpProxy.createProxyServer();
679
+
639
680
  const reverseProxies = (app, reverseProxyPaths = []) => {
640
681
  deliveryApiProxy(deliveryProxy, app);
641
682
  app.all(reverseProxyPaths, (req, res) => {
@@ -675,8 +716,8 @@ const CacheDuration = {
675
716
  static: '31536000',
676
717
  // Believe it or not these two max ages are the same in runtime
677
718
  expressStatic: '31557600h' // Believe it or not these two max ages are the same in runtime
678
- };
679
719
 
720
+ };
680
721
  const getCacheDuration = (status = 200) => {
681
722
  if (status > 400) return CacheDuration[404];
682
723
  return CacheDuration[200];
@@ -693,8 +734,10 @@ const bundleManipulationMiddleware = ({
693
734
  const filename = path.basename(req.path);
694
735
  const modernBundle = filename.endsWith('.mjs');
695
736
  const legacyBundle = filename.endsWith('.js');
737
+
696
738
  if ((legacyBundle || modernBundle) && filename.startsWith('runtime.')) {
697
739
  const jsRuntimeLocation = path.resolve(appRootPath, `dist/${staticFolderPath}/${modernBundle ? 'modern/js' : 'legacy/js'}/${filename}`);
740
+
698
741
  try {
699
742
  const jsRuntimeBundle = fs.readFileSync(jsRuntimeLocation, 'utf8');
700
743
  const modifiedBundle = replaceStaticPath(jsRuntimeBundle, staticRoutePath);
@@ -717,6 +760,7 @@ const bundleManipulationMiddleware = ({
717
760
  * @returns Response | next()
718
761
  * A middleware function to resolve /dist/static/startup.js under a supplied startupScriptFilename variable
719
762
  */
763
+
720
764
  const resolveStartupMiddleware = ({
721
765
  appRootPath,
722
766
  maxage,
@@ -725,6 +769,7 @@ const resolveStartupMiddleware = ({
725
769
  }) => async (req, res, next) => {
726
770
  if (startupScriptFilename !== 'startup.js' && req.path === `/${startupScriptFilename}`) {
727
771
  let startupFileLocation = '';
772
+
728
773
  try {
729
774
  const startupFilePaths = [`dist/static/startup.js`, `dist/${staticFolderPath}/startup.js`];
730
775
  let startupFilePath = '';
@@ -732,8 +777,7 @@ const resolveStartupMiddleware = ({
732
777
  try {
733
778
  fs.accessSync(testPath);
734
779
  startupFilePath = testPath;
735
- } catch (ex) {
736
- // Do nothing
780
+ } catch (ex) {// Do nothing
737
781
  }
738
782
  });
739
783
  startupFileLocation = path.resolve(appRootPath, startupFilePath);
@@ -770,8 +814,7 @@ const staticAssets = (app, {
770
814
  maxage: CacheDuration.static,
771
815
  startupScriptFilename: scripts.startup || startupScriptFilename,
772
816
  staticFolderPath
773
- }),
774
- // eslint-disable-next-line import/no-named-as-default-member
817
+ }), // eslint-disable-next-line import/no-named-as-default-member
775
818
  express.static(`dist/${staticFolderPath}`, {
776
819
  // these maxage values are different in config but the same in runtime,
777
820
  // this one is somehow converted and should end up being the same as CacheDuration.static
@@ -779,8 +822,11 @@ const staticAssets = (app, {
779
822
  }));
780
823
  };
781
824
 
782
- const servers = SERVERS; /* global SERVERS */
783
- const projects = PROJECTS; /* global PROJECTS */
825
+ const servers = SERVERS;
826
+ /* global SERVERS */
827
+
828
+ const projects = PROJECTS;
829
+ /* global PROJECTS */
784
830
 
785
831
  const DisplayStartupConfiguration = config => {
786
832
  /* eslint-disable no-console */
@@ -797,6 +843,73 @@ const DisplayStartupConfiguration = config => {
797
843
  /* eslint-enable no-console */
798
844
  };
799
845
 
846
+ var server$1 = {};
847
+
848
+ Object.defineProperty(server$1, '__esModule', { value: true });
849
+
850
+ var React = React$1;
851
+ var history = require$$1;
852
+ var reactRouterDom = require$$2;
853
+
854
+ /**
855
+ * A <Router> that may not transition to any other location. This is useful
856
+ * on the server where there is no stateful UI.
857
+ */
858
+ function StaticRouter({
859
+ basename,
860
+ children,
861
+ location: locationProp = "/"
862
+ }) {
863
+ if (typeof locationProp === "string") {
864
+ locationProp = history.parsePath(locationProp);
865
+ }
866
+
867
+ let action = history.Action.Pop;
868
+ let location = {
869
+ pathname: locationProp.pathname || "/",
870
+ search: locationProp.search || "",
871
+ hash: locationProp.hash || "",
872
+ state: locationProp.state || null,
873
+ key: locationProp.key || "default"
874
+ };
875
+ let staticNavigator = {
876
+ createHref(to) {
877
+ return typeof to === "string" ? to : history.createPath(to);
878
+ },
879
+
880
+ push(to) {
881
+ throw new Error(`You cannot use navigator.push() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)})\` somewhere in your app.`);
882
+ },
883
+
884
+ replace(to) {
885
+ throw new Error(`You cannot use navigator.replace() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)}, { replace: true })\` somewhere ` + `in your app.`);
886
+ },
887
+
888
+ go(delta) {
889
+ throw new Error(`You cannot use navigator.go() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${delta})\` somewhere in your app.`);
890
+ },
891
+
892
+ back() {
893
+ throw new Error(`You cannot use navigator.back() on the server because it is a stateless ` + `environment.`);
894
+ },
895
+
896
+ forward() {
897
+ throw new Error(`You cannot use navigator.forward() on the server because it is a stateless ` + `environment.`);
898
+ }
899
+
900
+ };
901
+ return /*#__PURE__*/React.createElement(reactRouterDom.Router, {
902
+ basename: basename,
903
+ children: children,
904
+ location: location,
905
+ navigationType: action,
906
+ navigator: staticNavigator,
907
+ static: true
908
+ });
909
+ }
910
+
911
+ var StaticRouter_1 = server$1.StaticRouter = StaticRouter;
912
+
800
913
  /**
801
914
  * Removes all key-value entries from the list cache.
802
915
  *
@@ -3597,17 +3710,20 @@ const handleResponse = (request, response, content, send = 'send') => {
3597
3710
  };
3598
3711
 
3599
3712
  const readFileSync = path => fs.readFileSync(path, 'utf8');
3713
+
3600
3714
  const loadableBundleData = ({
3601
3715
  stats,
3602
3716
  templates
3603
3717
  }, staticRoutePath, build) => {
3604
3718
  const bundle = {};
3719
+
3605
3720
  try {
3606
3721
  bundle.stats = stats ? JSON.parse(readFileSync(stats.replace('/target', build ? `/${build}` : ''))) : null;
3607
3722
  } catch (ex) {
3608
3723
  // console.info(ex);
3609
3724
  bundle.stats = null;
3610
3725
  }
3726
+
3611
3727
  try {
3612
3728
  bundle.templates = {
3613
3729
  templateHTML: replaceStaticPath(readFileSync(templates.html.replace('/target', build ? `/${build}` : '')), staticRoutePath),
@@ -3618,15 +3734,18 @@ const loadableBundleData = ({
3618
3734
  // console.info(ex);
3619
3735
  bundle.templates = null;
3620
3736
  }
3737
+
3621
3738
  return bundle;
3622
3739
  };
3623
3740
  const loadableChunkExtractors = () => {
3624
3741
  const commonLoadableExtractor = new ChunkExtractor({
3625
3742
  stats: {}
3626
3743
  });
3744
+
3627
3745
  try {
3628
3746
  let modern;
3629
3747
  let legacy;
3748
+
3630
3749
  try {
3631
3750
  modern = new ChunkExtractor({
3632
3751
  entrypoints: ['app'],
@@ -3636,6 +3755,7 @@ const loadableChunkExtractors = () => {
3636
3755
  } catch (e) {
3637
3756
  console.info('@loadable/server modern ChunkExtractor not available');
3638
3757
  }
3758
+
3639
3759
  try {
3640
3760
  legacy = new ChunkExtractor({
3641
3761
  entrypoints: ['app'],
@@ -3645,11 +3765,14 @@ const loadableChunkExtractors = () => {
3645
3765
  } catch (e) {
3646
3766
  console.info('@loadable/server legacy ChunkExtractor not available');
3647
3767
  }
3768
+
3648
3769
  commonLoadableExtractor.addChunk = chunk => {
3649
3770
  var _modern, _legacy, _legacy2;
3771
+
3650
3772
  (_modern = modern) === null || _modern === void 0 ? void 0 : _modern.addChunk(chunk);
3651
3773
  if (typeof ((_legacy = legacy) === null || _legacy === void 0 ? void 0 : _legacy.stats.assetsByChunkName[chunk]) !== 'undefined') (_legacy2 = legacy) === null || _legacy2 === void 0 ? void 0 : _legacy2.addChunk(chunk);
3652
3774
  };
3775
+
3653
3776
  return {
3654
3777
  commonLoadableExtractor,
3655
3778
  modern,
@@ -3670,9 +3793,7 @@ const getBundleData = (config, staticRoutePath) => {
3670
3793
  };
3671
3794
  if (!bundleData.default || Object.keys(bundleData.default || {}).length === 0) bundleData.default = bundleData.legacy || bundleData.modern;
3672
3795
  return bundleData;
3673
- };
3674
-
3675
- // export const buildBundleTags = (
3796
+ }; // export const buildBundleTags = (
3676
3797
  // bundles,
3677
3798
  // differentialBundles = false,
3678
3799
  // staticRoutePath = 'static',
@@ -3697,18 +3818,17 @@ const getBundleData = (config, staticRoutePath) => {
3697
3818
  // )}"></script>`;
3698
3819
  // })
3699
3820
  // .filter(f => f);
3700
-
3701
3821
  // return bundleTags;
3702
3822
  // };
3703
3823
 
3704
3824
  const getBundleTags = (loadableExtractor, scripts, staticRoutePath = 'static') => {
3705
- let startupTag = '';
3706
- // Add the static startup script to the bundleTags
3707
- if (scripts !== null && scripts !== void 0 && scripts.startup) startupTag = `<script ${stringifyAttributes(scripts.attributes)} src="/${staticRoutePath}/${scripts.startup}"></script>`;
3825
+ let startupTag = ''; // Add the static startup script to the bundleTags
3826
+
3827
+ if (scripts !== null && scripts !== void 0 && scripts.startup) startupTag = `<script ${stringifyAttributes(scripts.attributes)} src="/${staticRoutePath}/${scripts.startup}"></script>`; // Get the script tags from their respective extractor instances
3708
3828
 
3709
- // Get the script tags from their respective extractor instances
3710
3829
  if (loadableExtractor) {
3711
3830
  var _loadableExtractor$le, _loadableExtractor$mo;
3831
+
3712
3832
  const legacyScriptTags = (_loadableExtractor$le = loadableExtractor.legacy) === null || _loadableExtractor$le === void 0 ? void 0 : _loadableExtractor$le.getScriptTags({
3713
3833
  nomodule: 'nomodule'
3714
3834
  });
@@ -3718,20 +3838,21 @@ const getBundleTags = (loadableExtractor, scripts, staticRoutePath = 'static') =
3718
3838
  const scriptTags = `${startupTag}${legacyScriptTags || ''}${modernScriptTags || ''}`.replace(/"\/static\//g, `"/${staticRoutePath}/`);
3719
3839
  return scriptTags;
3720
3840
  }
3841
+
3721
3842
  return startupTag;
3722
3843
  };
3723
3844
 
3724
- const alias = ALIAS; /* global ALIAS */
3845
+ const alias = ALIAS;
3846
+ /* global ALIAS */
3725
3847
 
3726
3848
  const addStandardHeaders = (state, response, packagejson, groups) => {
3727
3849
  if (state) {
3728
3850
  try {
3729
3851
  console.info('About to add headers');
3730
- const routingSurrogateKeys = selectSurrogateKeys(state);
3731
-
3732
- // Check length of surrogate keys and prevent potential header overflow
3852
+ const routingSurrogateKeys = selectSurrogateKeys(state); // Check length of surrogate keys and prevent potential header overflow
3733
3853
  // errors in prod by replacing with `any-update` header that will indiscriminately
3734
3854
  // invalidate the SSR page cache when any content is updated
3855
+
3735
3856
  const surrogateKeys = routingSurrogateKeys.length >= 2000 ? `${alias}_any-update` : routingSurrogateKeys.join(' ');
3736
3857
  const surrogateKeyHeader = `${packagejson.name}-app ${surrogateKeys}`;
3737
3858
  response.setHeader('surrogate-key', surrogateKeyHeader);
@@ -3750,12 +3871,14 @@ const addVarnishAuthenticationHeaders = (state, response, groups = {}) => {
3750
3871
  const {
3751
3872
  globalGroups,
3752
3873
  allowedGroups
3753
- } = groups;
3754
- // console.info(globalGroups, allowedGroups);
3874
+ } = groups; // console.info(globalGroups, allowedGroups);
3875
+
3755
3876
  let allGroups = Array.from(globalGroups && globalGroups[project] || {});
3877
+
3756
3878
  if (stateEntry && getImmutableOrJS(stateEntry, ['authentication', 'isLoginRequired']) && allowedGroups && allowedGroups[project]) {
3757
3879
  allGroups = [...allGroups, ...allowedGroups[project]];
3758
3880
  }
3881
+
3759
3882
  response.header('x-contensis-viewer-groups', allGroups.join('|'));
3760
3883
  } catch (e) {
3761
3884
  console.info('Error adding authentication header', e);
@@ -3776,17 +3899,17 @@ const getVersionInfo = staticFolderPath => {
3776
3899
 
3777
3900
  /* eslint-disable no-console */
3778
3901
 
3779
- // Default exception types to add event listeners for
3780
3902
  const handleDefaultEvents = ['uncaughtException', 'unhandledRejection'];
3781
3903
  const unhandledExceptionHandler = (handleExceptions = handleDefaultEvents) => {
3782
3904
  const exceptionTypes = Array.isArray(handleExceptions) ? handleExceptions : handleExceptions === false ? [] : handleDefaultEvents;
3905
+
3783
3906
  for (const type of exceptionTypes) {
3784
3907
  process.on(type, err => {
3785
3908
  if (err && err instanceof Error) {
3786
3909
  // Print a message to inform admins and developers the error should not be ignored
3787
3910
  console.log(`${`[contensis-react-base] ❌ ${chalk.red.bold(`${type} - ${err.message}`)}`}`);
3788
- console.log(chalk.gray` - you are seeing this because we have tried to prevent the app from completely crashing - you should not ignore this problem`);
3789
- // Log the error to server console
3911
+ console.log(chalk.gray` - you are seeing this because we have tried to prevent the app from completely crashing - you should not ignore this problem`); // Log the error to server console
3912
+
3790
3913
  console.error(err);
3791
3914
  }
3792
3915
  });
@@ -3822,16 +3945,21 @@ const webApp = (app, ReactApp, config) => {
3822
3945
  const {
3823
3946
  url
3824
3947
  } = request;
3825
- const matchedStaticRoute = () => matchRoutes(routes.StaticRoutes, request.path);
3826
- const isStaticRoute = () => matchedStaticRoute().length > 0;
3827
- const staticRoute = isStaticRoute() && matchedStaticRoute()[0];
3948
+ const matchedStaticRoute = matchRoutes(routes.StaticRoutes, request.path);
3949
+ const isStaticRoute = matchedStaticRoute && matchedStaticRoute.length > 0;
3950
+
3951
+ if (isStaticRoute) {
3952
+ mergeStaticRoutes(matchedStaticRoute);
3953
+ }
3954
+
3955
+ const staticRoute = isStaticRoute ? matchedStaticRoute.pop() || null : null; // Allow certain routes to avoid SSR
3828
3956
 
3829
- // Allow certain routes to avoid SSR
3830
3957
  const onlyDynamic = staticRoute && staticRoute.route.ssr === false;
3831
3958
  const onlySSR = staticRoute && staticRoute.route.ssrOnly === true;
3832
- const normaliseQs = q => q && q.toLowerCase() === 'true' ? true : false;
3833
3959
 
3834
- // Determine functional params from QueryString and set access methods
3960
+ const normaliseQs = q => q && q.toLowerCase() === 'true' ? true : false; // Determine functional params from QueryString and set access methods
3961
+
3962
+
3835
3963
  const accessMethod = mapJson(request.query, {
3836
3964
  DYNAMIC: ({
3837
3965
  dynamic
@@ -3846,20 +3974,19 @@ const webApp = (app, ReactApp, config) => {
3846
3974
  static: value
3847
3975
  }) => normaliseQs(value) || onlySSR
3848
3976
  });
3849
- const context = {};
3850
- // Track the current statusCode via the response object
3851
- response.status(200);
3977
+ const context = {
3978
+ location: ''
3979
+ }; // Track the current statusCode via the response object
3852
3980
 
3853
- // Create a store (with a memory history) from our current url
3854
- const store = await createStore(withReducers, {}, history({
3855
- initialEntries: [url]
3856
- }), stateType);
3981
+ response.status(200); // Create a store (with a memory history) from our current url
3857
3982
 
3858
- // dispatch any global and non-saga related actions before calling our JSX
3859
- const versionStatus = deliveryApi.getServerSideVersionStatus(request);
3983
+ const store = await createStore(withReducers, {}, history$1({
3984
+ initialEntries: [url]
3985
+ }), stateType); // dispatch any global and non-saga related actions before calling our JSX
3860
3986
 
3861
- // In server-side blocks world, the hostname requested by the client resides in the x-orig-host header
3987
+ const versionStatus = deliveryApi.getServerSideVersionStatus(request); // In server-side blocks world, the hostname requested by the client resides in the x-orig-host header
3862
3988
  // Because of this, we prioritize x-orig-host when setting our hostname
3989
+
3863
3990
  const hostname = request.headers['x-orig-host'] || request.hostname;
3864
3991
  console.info(`Request for ${request.path} hostname: ${hostname} versionStatus: ${versionStatus}`);
3865
3992
  store.dispatch(setVersionStatus(versionStatus));
@@ -3868,42 +3995,43 @@ const webApp = (app, ReactApp, config) => {
3868
3995
  const groups = allowedGroups && allowedGroups[project];
3869
3996
  store.dispatch(setCurrentProject(project, groups, hostname));
3870
3997
  const loadableExtractor = loadableChunkExtractors();
3871
- const jsx = /*#__PURE__*/React.createElement(ChunkExtractorManager, {
3998
+ // Recast ChunkExtractorManager to avoid TS error `Property 'children' does not exist on type...`
3999
+ const ChunkExtractor = ChunkExtractorManager;
4000
+ const jsx = /*#__PURE__*/React$1.createElement(ChunkExtractor, {
3872
4001
  extractor: loadableExtractor.commonLoadableExtractor
3873
- }, /*#__PURE__*/React.createElement(CookiesProvider, {
4002
+ }, /*#__PURE__*/React$1.createElement(CookiesProvider, {
3874
4003
  cookies: request.universalCookies
3875
- }, /*#__PURE__*/React.createElement(Provider, {
4004
+ }, /*#__PURE__*/React$1.createElement(Provider, {
3876
4005
  store: store
3877
- }, /*#__PURE__*/React.createElement(StaticRouter, {
3878
- context: context,
4006
+ }, /*#__PURE__*/React$1.createElement(HttpContext.Provider, {
4007
+ value: context
4008
+ }, /*#__PURE__*/React$1.createElement(StaticRouter_1, {
3879
4009
  location: url
3880
- }, /*#__PURE__*/React.createElement(ReactApp, {
4010
+ }, /*#__PURE__*/React$1.createElement(ReactApp, {
3881
4011
  routes: routes,
3882
4012
  withEvents: withEvents
3883
- })))));
4013
+ }))))));
3884
4014
  const {
3885
4015
  templateHTML = '',
3886
4016
  templateHTMLFragment = '',
3887
4017
  templateHTMLStatic = ''
3888
- } = bundleData.default.templates || bundleData.legacy.templates || {};
4018
+ } = bundleData.default.templates || bundleData.legacy.templates || {}; // Serve a blank HTML page with client scripts to load the app in the browser
3889
4019
 
3890
- // Serve a blank HTML page with client scripts to load the app in the browser
3891
4020
  if (accessMethod.DYNAMIC) {
3892
4021
  // Dynamic doesn't need sagas
3893
- renderToString(jsx);
3894
-
3895
- // Dynamic page render has only the necessary bundles to start up the app
4022
+ renderToString(jsx); // Dynamic page render has only the necessary bundles to start up the app
3896
4023
  // and does not include any react-loadable code-split bundles
4024
+
3897
4025
  const bundleTags = getBundleTags(loadableExtractor, scripts, staticRoutePath);
3898
4026
  const isDynamicHints = `<script ${attributes}>window.versionStatus = "${versionStatus}"; window.isDynamic = true;</script>`;
3899
- const responseHtmlDynamic = templateHTML.replace('{{TITLE}}', '').replace('{{SEO_CRITICAL_METADATA}}', '').replace('{{CRITICAL_CSS}}', '').replace('{{APP}}', '').replace('{{LOADABLE_CHUNKS}}', bundleTags).replace('{{REDUX_DATA}}', isDynamicHints);
3900
- // Dynamic pages always return a 200 so we can run
4027
+ const responseHtmlDynamic = templateHTML.replace('{{TITLE}}', '').replace('{{SEO_CRITICAL_METADATA}}', '').replace('{{CRITICAL_CSS}}', '').replace('{{APP}}', '').replace('{{LOADABLE_CHUNKS}}', bundleTags).replace('{{REDUX_DATA}}', isDynamicHints); // Dynamic pages always return a 200 so we can run
3901
4028
  // the app and serve up all errors inside the client
4029
+
3902
4030
  response.setHeader('Surrogate-Control', `max-age=${getCacheDuration(200)}`);
3903
4031
  responseHandler(request, response, responseHtmlDynamic);
3904
- }
4032
+ } // Render the JSX server side and send response as per access method options
4033
+
3905
4034
 
3906
- // Render the JSX server side and send response as per access method options
3907
4035
  if (!accessMethod.DYNAMIC) {
3908
4036
  store.runSaga(rootSaga(withSagas)).toPromise().then(() => {
3909
4037
  const sheet = new ServerStyleSheet();
@@ -3913,14 +4041,15 @@ const webApp = (app, ReactApp, config) => {
3913
4041
  const htmlAttributes = helmet.htmlAttributes.toString();
3914
4042
  let title = helmet.title.toString();
3915
4043
  const metadata = helmet.meta.toString().concat(helmet.base.toString()).concat(helmet.link.toString()).concat(helmet.script.toString()).concat(helmet.noscript.toString());
4044
+
3916
4045
  if (context.url) {
3917
4046
  return response.redirect(context.statusCode || 302, context.url);
3918
4047
  }
3919
- const reduxState = store.getState();
3920
- const styleTags = sheet.getStyleTags();
3921
4048
 
3922
- // After running rootSaga there should be an additional react-loadable
4049
+ const reduxState = store.getState();
4050
+ const styleTags = sheet.getStyleTags(); // After running rootSaga there should be an additional react-loadable
3923
4051
  // code-split bundles for any page components as well as core app bundles
4052
+
3924
4053
  const bundleTags = getBundleTags(loadableExtractor, scripts, staticRoutePath);
3925
4054
  let serialisedReduxData = serialize(buildCleaner({
3926
4055
  isArray: identity,
@@ -3932,6 +4061,7 @@ const webApp = (app, ReactApp, config) => {
3932
4061
  isString: identity,
3933
4062
  isUndefined: noop
3934
4063
  })(cloneDeep_1(reduxState)));
4064
+
3935
4065
  if (context.statusCode !== 404) {
3936
4066
  // For a request that returns a redux state object as a response
3937
4067
  if (accessMethod.REDUX) {
@@ -3942,6 +4072,7 @@ const webApp = (app, ReactApp, config) => {
3942
4072
  responseHandler(request, response, serialisedReduxData, 'json');
3943
4073
  return true;
3944
4074
  }
4075
+
3945
4076
  if (!disableSsrRedux) {
3946
4077
  // window.versionStatus is not strictly required here and is added to support cases
3947
4078
  // where a consumer may not be using the contensisVersionStatus in redux and calling
@@ -3949,40 +4080,41 @@ const webApp = (app, ReactApp, config) => {
3949
4080
  serialisedReduxData = `<script ${attributes}>window.versionStatus = "${versionStatus}"; window.REDUX_DATA = ${serialisedReduxData}</script>`;
3950
4081
  }
3951
4082
  }
4083
+
3952
4084
  if ((context.statusCode || 200) >= 404) {
3953
4085
  accessMethod.STATIC = true;
3954
- }
4086
+ } // Responses
4087
+
3955
4088
 
3956
- // Responses
3957
4089
  let responseHTML = '';
3958
- if (context.statusCode === 404) title = '<title>404 page not found</title>';
4090
+ if (context.statusCode === 404) title = '<title>404 page not found</title>'; // Static page served as a fragment
3959
4091
 
3960
- // Static page served as a fragment
3961
4092
  if (accessMethod.FRAGMENT && accessMethod.STATIC) {
3962
4093
  responseHTML = minifyCssString(styleTags) + html;
3963
- }
4094
+ } // Page fragment served with client scripts and redux data that hydrate the app client side
4095
+
3964
4096
 
3965
- // Page fragment served with client scripts and redux data that hydrate the app client side
3966
4097
  if (accessMethod.FRAGMENT && !accessMethod.STATIC) {
3967
4098
  responseHTML = templateHTMLFragment.replace('{{TITLE}}', title).replace('{{SEO_CRITICAL_METADATA}}', metadata).replace('{{CRITICAL_CSS}}', minifyCssString(styleTags)).replace('{{APP}}', html).replace('{{LOADABLE_CHUNKS}}', bundleTags).replace('{{REDUX_DATA}}', serialisedReduxData);
3968
- }
4099
+ } // Full HTML page served statically
4100
+
3969
4101
 
3970
- // Full HTML page served statically
3971
4102
  if (!accessMethod.FRAGMENT && accessMethod.STATIC) {
3972
4103
  responseHTML = templateHTMLStatic.replace('{{TITLE}}', title).replace('{{SEO_CRITICAL_METADATA}}', metadata).replace('{{CRITICAL_CSS}}', minifyCssString(styleTags)).replace('{{APP}}', html).replace('{{LOADABLE_CHUNKS}}', '');
3973
- }
4104
+ } // Full HTML page served with client scripts and redux data that hydrate the app client side
4105
+
3974
4106
 
3975
- // Full HTML page served with client scripts and redux data that hydrate the app client side
3976
4107
  if (!accessMethod.FRAGMENT && !accessMethod.STATIC) {
3977
4108
  responseHTML = templateHTML.replace('{{TITLE}}', title).replace('{{SEO_CRITICAL_METADATA}}', metadata).replace('{{CRITICAL_CSS}}', styleTags).replace('{{APP}}', html).replace('{{LOADABLE_CHUNKS}}', bundleTags).replace('{{REDUX_DATA}}', serialisedReduxData);
3978
- }
4109
+ } // Set response.status from React StaticRouter
4110
+
3979
4111
 
3980
- // Set response.status from React StaticRouter
3981
4112
  if (typeof context.statusCode === 'number') response.status(context.statusCode);
3982
4113
  addStandardHeaders(reduxState, response, packagejson, {
3983
4114
  allowedGroups,
3984
4115
  globalGroups
3985
4116
  });
4117
+
3986
4118
  try {
3987
4119
  // If react-helmet htmlAttributes are being used,
3988
4120
  // replace the html tag with those attributes sepcified
@@ -3990,6 +4122,7 @@ const webApp = (app, ReactApp, config) => {
3990
4122
  if (htmlAttributes) {
3991
4123
  responseHTML = responseHTML.replace(/<html?.+?>/, `<html ${htmlAttributes}>`);
3992
4124
  }
4125
+
3993
4126
  responseHandler(request, response, responseHTML);
3994
4127
  } catch (err) {
3995
4128
  console.info(err.message);
@@ -4009,17 +4142,18 @@ const webApp = (app, ReactApp, config) => {
4009
4142
 
4010
4143
  const app = express();
4011
4144
  const server = http.createServer(app);
4145
+
4012
4146
  const start = (ReactApp, config, ServerFeatures) => {
4013
4147
  global.PACKAGE_JSON = config.packagejson;
4014
4148
  global.DISABLE_SSR_REDUX = config.disableSsrRedux;
4015
4149
  global.PROXY_DELIVERY_API = config.proxyDeliveryApi;
4016
4150
  global.REVERSE_PROXY_PATHS = Object(config.reverseProxyPaths);
4017
- app.disable('x-powered-by');
4018
- // Output some information about the used build/startup configuration
4151
+ app.disable('x-powered-by'); // Output some information about the used build/startup configuration
4152
+
4019
4153
  DisplayStartupConfiguration(config);
4020
- ServerFeatures(app);
4021
- // Set-up local proxy for images from cms, and delivery api requests
4154
+ ServerFeatures(app); // Set-up local proxy for images from cms, and delivery api requests
4022
4155
  // to save doing rewrites and extra code
4156
+
4023
4157
  reverseProxies(app, config.reverseProxyPaths);
4024
4158
  staticAssets(app, config);
4025
4159
  webApp(app, ReactApp, config);
@@ -4038,6 +4172,7 @@ const start = (ReactApp, config, ServerFeatures) => {
4038
4172
  });
4039
4173
  });
4040
4174
  };
4175
+
4041
4176
  var internalServer = {
4042
4177
  app,
4043
4178
  apiProxy: deliveryProxy,