@zengenti/contensis-react-base 3.0.2-beta.1 → 3.0.2-beta.10
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.
- package/cjs/{App-ee485b92.js → App-81a45001.js} +111 -427
- package/cjs/App-81a45001.js.map +1 -0
- package/cjs/ContensisDeliveryApi-de88df2a.js +231 -0
- package/cjs/ContensisDeliveryApi-de88df2a.js.map +1 -0
- package/cjs/{RouteLoader-3aa6456e.js → RouteLoader-47d70a26.js} +23 -37
- package/{esm/RouteLoader-5171c63f.js.map → cjs/RouteLoader-47d70a26.js.map} +1 -1
- package/cjs/{ToJs-a9a8522b.js → ToJs-61c03582.js} +3 -4
- package/cjs/{ToJs-a9a8522b.js.map → ToJs-61c03582.js.map} +1 -1
- package/cjs/client.js +20 -27
- package/cjs/client.js.map +1 -1
- package/cjs/contensis-react-base.js +124 -188
- package/cjs/contensis-react-base.js.map +1 -1
- package/cjs/forms.js +15 -154
- package/cjs/forms.js.map +1 -1
- package/cjs/{fromJSLeaveImmer-e74c673c.js → fromJSLeaveImmer-7c363211.js} +1 -4
- package/cjs/{fromJSLeaveImmer-e74c673c.js.map → fromJSLeaveImmer-7c363211.js.map} +1 -1
- package/cjs/{login-840860bc.js → login-51b66359.js} +64 -113
- package/cjs/login-51b66359.js.map +1 -0
- package/cjs/{reducers-3a4f8971.js → reducers-9afb5f89.js} +14 -31
- package/cjs/reducers-9afb5f89.js.map +1 -0
- package/cjs/redux.js +17 -17
- package/cjs/redux.js.map +1 -1
- package/cjs/routing.js +6 -7
- package/cjs/routing.js.map +1 -1
- package/cjs/{sagas-e2a34262.js → sagas-6d12e7ca.js} +183 -282
- package/cjs/sagas-6d12e7ca.js.map +1 -0
- package/cjs/search.js +56 -82
- package/cjs/search.js.map +1 -1
- package/cjs/{selectors-656da4b7.js → selectors-c76c2676.js} +84 -7
- package/cjs/selectors-c76c2676.js.map +1 -0
- package/cjs/urls-6fcaf4c6.js.map +1 -1
- package/cjs/user.js +4 -13
- package/cjs/user.js.map +1 -1
- package/cjs/util.js +45 -53
- package/cjs/util.js.map +1 -1
- package/cjs/{version-78dfc3bd.js → version-38afaf2a.js} +45 -158
- package/cjs/version-38afaf2a.js.map +1 -0
- package/cjs/version-886f49d8.js +98 -0
- package/cjs/version-886f49d8.js.map +1 -0
- package/esm/{App-640239d2.js → App-5f914483.js} +93 -407
- package/esm/App-5f914483.js.map +1 -0
- package/esm/ContensisDeliveryApi-ad06857d.js +227 -0
- package/esm/ContensisDeliveryApi-ad06857d.js.map +1 -0
- package/esm/{RouteLoader-5171c63f.js → RouteLoader-f5d5f733.js} +22 -36
- package/{cjs/RouteLoader-3aa6456e.js.map → esm/RouteLoader-f5d5f733.js.map} +1 -1
- package/esm/{ToJs-4e02a04d.js → ToJs-0066e629.js} +3 -4
- package/esm/{ToJs-4e02a04d.js.map → ToJs-0066e629.js.map} +1 -1
- package/esm/client.js +15 -22
- package/esm/client.js.map +1 -1
- package/esm/contensis-react-base.js +119 -183
- package/esm/contensis-react-base.js.map +1 -1
- package/esm/forms.js +15 -154
- package/esm/forms.js.map +1 -1
- package/esm/{fromJSLeaveImmer-0114ffcf.js → fromJSLeaveImmer-e2dacd63.js} +1 -4
- package/esm/{fromJSLeaveImmer-0114ffcf.js.map → fromJSLeaveImmer-e2dacd63.js.map} +1 -1
- package/esm/{login-57395c9c.js → login-4d07c2de.js} +63 -112
- package/esm/login-4d07c2de.js.map +1 -0
- package/esm/{reducers-8e5d6232.js → reducers-3d5c37d1.js} +14 -31
- package/esm/reducers-3d5c37d1.js.map +1 -0
- package/esm/redux.js +9 -8
- package/esm/redux.js.map +1 -1
- package/esm/routing.js +3 -4
- package/esm/routing.js.map +1 -1
- package/esm/{sagas-bb925ef4.js → sagas-53d2aefb.js} +135 -235
- package/esm/sagas-53d2aefb.js.map +1 -0
- package/esm/search.js +57 -83
- package/esm/search.js.map +1 -1
- package/esm/{selectors-a5e5835b.js → selectors-3f0d804d.js} +70 -7
- package/esm/selectors-3f0d804d.js.map +1 -0
- package/esm/urls-eac9a747.js.map +1 -1
- package/esm/user.js +6 -15
- package/esm/user.js.map +1 -1
- package/esm/util.js +42 -53
- package/esm/util.js.map +1 -1
- package/esm/{version-e3a5ec66.js → version-dd31c7f0.js} +32 -141
- package/esm/version-dd31c7f0.js.map +1 -0
- package/esm/version-f4629693.js +87 -0
- package/esm/version-f4629693.js.map +1 -0
- package/models/util/ContensisDeliveryApi.d.ts +6 -0
- package/models/util/index.d.ts +1 -0
- package/package.json +1 -1
- package/cjs/App-ee485b92.js.map +0 -1
- package/cjs/actions-8dc9e8de.js +0 -87
- package/cjs/actions-8dc9e8de.js.map +0 -1
- package/cjs/login-840860bc.js.map +0 -1
- package/cjs/reducers-3a4f8971.js.map +0 -1
- package/cjs/sagas-e2a34262.js.map +0 -1
- package/cjs/selectors-656da4b7.js.map +0 -1
- package/cjs/version-78dfc3bd.js.map +0 -1
- package/cjs/version-eba6d09b.js +0 -20
- package/cjs/version-eba6d09b.js.map +0 -1
- package/esm/App-640239d2.js.map +0 -1
- package/esm/actions-180948dd.js +0 -72
- package/esm/actions-180948dd.js.map +0 -1
- package/esm/login-57395c9c.js.map +0 -1
- package/esm/reducers-8e5d6232.js.map +0 -1
- package/esm/sagas-bb925ef4.js.map +0 -1
- package/esm/selectors-a5e5835b.js.map +0 -1
- package/esm/version-2485e2fb.js +0 -15
- package/esm/version-2485e2fb.js.map +0 -1
- package/esm/version-e3a5ec66.js.map +0 -1
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
var history$1 = require('history');
|
|
4
4
|
var effects = require('@redux-saga/core/effects');
|
|
5
5
|
var log = require('loglevel');
|
|
6
|
+
var ContensisDeliveryApi = require('./ContensisDeliveryApi-de88df2a.js');
|
|
7
|
+
var version = require('./version-38afaf2a.js');
|
|
8
|
+
var version$1 = require('./version-886f49d8.js');
|
|
9
|
+
var selectors = require('./selectors-c76c2676.js');
|
|
10
|
+
var login = require('./login-51b66359.js');
|
|
6
11
|
var contensisDeliveryApi = require('contensis-delivery-api');
|
|
7
|
-
var queryString = require('query-string');
|
|
8
|
-
var actions = require('./actions-8dc9e8de.js');
|
|
9
|
-
var version = require('./version-78dfc3bd.js');
|
|
10
|
-
var version$1 = require('./version-eba6d09b.js');
|
|
11
|
-
var selectors = require('./selectors-656da4b7.js');
|
|
12
|
-
var login = require('./login-840860bc.js');
|
|
13
12
|
var awaitToJs = require('await-to-js');
|
|
14
|
-
var reducers = require('./reducers-
|
|
15
|
-
var ToJs = require('./ToJs-
|
|
13
|
+
var reducers = require('./reducers-9afb5f89.js');
|
|
14
|
+
var ToJs = require('./ToJs-61c03582.js');
|
|
16
15
|
var React = require('react');
|
|
17
16
|
require('react-hot-loader');
|
|
18
17
|
require('jsonpath-mapper');
|
|
19
|
-
|
|
18
|
+
require('query-string');
|
|
19
|
+
var RouteLoader = require('./RouteLoader-47d70a26.js');
|
|
20
20
|
|
|
21
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
22
|
|
|
@@ -41,279 +41,7 @@ function _interopNamespace(e) {
|
|
|
41
41
|
var log__namespace = /*#__PURE__*/_interopNamespace(log);
|
|
42
42
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
const keys = response.headers.get ? response.headers.get('surrogate-key') : response.headers.map['surrogate-key'];
|
|
46
|
-
if (keys) version.reduxStore === null || version.reduxStore === void 0 ? void 0 : version.reduxStore.dispatch(actions.setSurrogateKeys(keys, response.url));
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const getClientConfig = project => {
|
|
50
|
-
let config = DELIVERY_API_CONFIG;
|
|
51
|
-
/* global DELIVERY_API_CONFIG */
|
|
52
|
-
|
|
53
|
-
config.responseHandler = {};
|
|
54
|
-
|
|
55
|
-
if (project) {
|
|
56
|
-
config.projectId = project;
|
|
57
|
-
} // we only want the surrogate key header in a server context
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (typeof window === 'undefined') {
|
|
61
|
-
config.defaultHeaders = {
|
|
62
|
-
'x-require-surrogate-key': true
|
|
63
|
-
};
|
|
64
|
-
config.responseHandler[200] = storeSurrogateKeys;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (typeof window !== 'undefined' && PROXY_DELIVERY_API
|
|
68
|
-
/* global PROXY_DELIVERY_API */
|
|
69
|
-
) {
|
|
70
|
-
// ensure a relative url is used to bypass the need for CORS (separate OPTIONS calls)
|
|
71
|
-
config.rootUrl = '';
|
|
72
|
-
|
|
73
|
-
config.responseHandler[404] = () => null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return config;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
class DeliveryApi {
|
|
80
|
-
constructor() {
|
|
81
|
-
this.getClientSideVersionStatus = () => {
|
|
82
|
-
if (typeof window !== 'undefined') {
|
|
83
|
-
// Allow overriding versionStatus with the querystring
|
|
84
|
-
const {
|
|
85
|
-
versionStatus
|
|
86
|
-
} = queryString.parse(window.location.search);
|
|
87
|
-
if (versionStatus) return versionStatus; // Client-side we will have a global variable set if rendered by SSR in production
|
|
88
|
-
|
|
89
|
-
if (typeof window.versionStatus !== 'undefined') return window.versionStatus; // For localhost development we can only work out versionStatus from the current hostname
|
|
90
|
-
|
|
91
|
-
const currentHostname = window.location.hostname;
|
|
92
|
-
return this.getVersionStatusFromHostname(currentHostname);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return null;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
this.getServerSideVersionStatus = request => request.query.versionStatus || deliveryApi.getVersionStatusFromHeaders(request.headers) || deliveryApi.getVersionStatusFromHostname(request.hostname);
|
|
99
|
-
|
|
100
|
-
this.getVersionStatusFromHeaders = headers => {
|
|
101
|
-
const versionStatusHeader = headers['x-entry-versionstatus'];
|
|
102
|
-
if (typeof versionStatusHeader !== 'undefined') return versionStatusHeader;
|
|
103
|
-
return null;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
this.getVersionStatusFromHostname = currentHostname => {
|
|
107
|
-
if (currentHostname.indexOf('localhost') > -1) return 'latest';
|
|
108
|
-
|
|
109
|
-
if (currentHostname.endsWith('contensis.cloud')) {
|
|
110
|
-
if (currentHostname.indexOf('preview.') > -1) {
|
|
111
|
-
return 'latest';
|
|
112
|
-
} else {
|
|
113
|
-
return 'published';
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (currentHostname.endsWith('cloud.contensis.com')) {
|
|
118
|
-
if (currentHostname.indexOf('preview-') > -1) {
|
|
119
|
-
return 'latest';
|
|
120
|
-
} else {
|
|
121
|
-
return 'published';
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return 'published';
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
this.search = (query, linkDepth, project, env) => {
|
|
129
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
130
|
-
return client.entries.search(query, typeof linkDepth !== 'undefined' ? linkDepth : 1);
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
this.getClient = (deliveryApiStatus = 'published', project, env) => {
|
|
134
|
-
const baseConfig = getClientConfig(project);
|
|
135
|
-
baseConfig.versionStatus = deliveryApiStatus;
|
|
136
|
-
return contensisDeliveryApi.Client.create(baseConfig);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
this.getEntry = (id, linkDepth = 0, deliveryApiStatus = 'published', project, env) => {
|
|
140
|
-
const baseConfig = getClientConfig(project);
|
|
141
|
-
baseConfig.versionStatus = deliveryApiStatus;
|
|
142
|
-
const client = contensisDeliveryApi.Client.create(baseConfig); // return client.entries.get(id, linkDepth);
|
|
143
|
-
|
|
144
|
-
return client.entries.get({
|
|
145
|
-
id,
|
|
146
|
-
linkDepth
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const deliveryApi = new DeliveryApi();
|
|
154
|
-
|
|
155
|
-
class CacheNode {
|
|
156
|
-
constructor(key, value) {
|
|
157
|
-
this.key = key;
|
|
158
|
-
this.value = value;
|
|
159
|
-
this.next = null;
|
|
160
|
-
this.prev = null;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
class LruCache {
|
|
166
|
-
constructor(limit = 100) {
|
|
167
|
-
this.map = {};
|
|
168
|
-
this.head = null;
|
|
169
|
-
this.tail = null;
|
|
170
|
-
this.limit = limit || 100;
|
|
171
|
-
this.size = 0;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
get(key) {
|
|
175
|
-
if (this.map[key]) {
|
|
176
|
-
let value = this.map[key].value;
|
|
177
|
-
let node = new CacheNode(key, value);
|
|
178
|
-
this.remove(key);
|
|
179
|
-
this.setHead(node);
|
|
180
|
-
return value;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
set(key, value) {
|
|
185
|
-
let node = new CacheNode(key, value);
|
|
186
|
-
|
|
187
|
-
if (this.map[key]) {
|
|
188
|
-
this.remove(key);
|
|
189
|
-
} else {
|
|
190
|
-
if (this.size >= this.limit) {
|
|
191
|
-
delete this.map[this.tail.key];
|
|
192
|
-
this.size--;
|
|
193
|
-
this.tail = this.tail.prev;
|
|
194
|
-
this.tail.next = null;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
this.setHead(node);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
setHead(node) {
|
|
202
|
-
node.next = this.head;
|
|
203
|
-
node.prev = null;
|
|
204
|
-
|
|
205
|
-
if (this.head) {
|
|
206
|
-
this.head.prev = node;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.head = node;
|
|
210
|
-
|
|
211
|
-
if (!this.tail) {
|
|
212
|
-
this.tail = node;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
this.size++;
|
|
216
|
-
this.map[node.key] = node;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
remove(key) {
|
|
220
|
-
let node = this.map[key];
|
|
221
|
-
if (!node) return; // This is sometimes null and crashes the container without this check
|
|
222
|
-
|
|
223
|
-
if (node.prev) {
|
|
224
|
-
node.prev.next = node.next;
|
|
225
|
-
} else {
|
|
226
|
-
this.head = node.next;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (node.next) {
|
|
230
|
-
node.next.prev = node.prev;
|
|
231
|
-
} else {
|
|
232
|
-
this.tail = node.prev;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
delete this.map[key];
|
|
236
|
-
this.size--;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
class CachedSearch {
|
|
242
|
-
constructor() {
|
|
243
|
-
this.cache = new LruCache();
|
|
244
|
-
this.taxonomyLookup = {};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
search(query, linkDepth, project, env) {
|
|
248
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
249
|
-
return this.request(project + JSON.stringify(query) + linkDepth.toString(), () => client.entries.search(query, linkDepth));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
searchUsingPost(query, linkDepth = 0, project = '', env) {
|
|
253
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
254
|
-
return this.request(project + JSON.stringify(query) + linkDepth.toString(), () => client.entries.searchUsingPost(query, linkDepth));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
get(id, linkDepth, versionStatus, project, env) {
|
|
258
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
259
|
-
client.clientConfig.versionStatus = versionStatus;
|
|
260
|
-
return this.request(id, () => client.entries.get({
|
|
261
|
-
id,
|
|
262
|
-
linkDepth
|
|
263
|
-
}));
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
getContentType(id, project, env) {
|
|
267
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
268
|
-
return this.request(`[CONTENT TYPE] ${id} ${project}`, () => client.contentTypes.get(id));
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
getTaxonomyNode(key, project, env) {
|
|
272
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
273
|
-
return this.request(`[TAXONOMY NODE] ${key}`, () => client.taxonomy.resolveChildren(key).then(node => this.extendTaxonomyNode(node)));
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
getRootNode(options, project, env) {
|
|
277
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
278
|
-
return this.request(`${project} / ${JSON.stringify(options)}`, () => client.nodes.getRoot(options));
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
getNode(options, project, env) {
|
|
282
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
283
|
-
return this.request(`${project} ${options && options.path || options} ${JSON.stringify(options)}`, () => client.nodes.get(options));
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
getAncestors(options, project, env) {
|
|
287
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
288
|
-
return this.request(`${project} [A] ${options && options.id || options} ${JSON.stringify(options)}`, () => client.nodes.getAncestors(options));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
getChildren(options, project, env) {
|
|
292
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
293
|
-
return this.request(`${project} [C] ${options && options.id || options} ${JSON.stringify(options)}`, () => client.nodes.getChildren(options));
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
getSiblings(options, project, env) {
|
|
297
|
-
const client = contensisDeliveryApi.Client.create(getClientConfig(project));
|
|
298
|
-
return this.request(`${project} [S] ${options && options.id || options} ${JSON.stringify(options)}`, () => client.nodes.getSiblings(options));
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
request(key, execute) {
|
|
302
|
-
if (!this.cache.get(key) || typeof window == 'undefined') {
|
|
303
|
-
let promise = execute();
|
|
304
|
-
this.cache.set(key, promise);
|
|
305
|
-
promise.catch(() => {
|
|
306
|
-
this.cache.remove(key);
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return this.cache.get(key);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const cachedSearch = new CachedSearch();
|
|
316
|
-
|
|
44
|
+
// Create a history depending on the environment
|
|
317
45
|
const selectedHistory = typeof window !== 'undefined' ? history$1.createBrowserHistory : history$1.createMemoryHistory;
|
|
318
46
|
const history = (options = {}) => selectedHistory(options);
|
|
319
47
|
const browserHistory = selectedHistory();
|
|
@@ -321,15 +49,13 @@ const browserHistory = selectedHistory();
|
|
|
321
49
|
const navigationSagas = [effects.takeEvery(version.GET_NODE_TREE, ensureNodeTreeSaga)];
|
|
322
50
|
function* ensureNodeTreeSaga(action) {
|
|
323
51
|
const state = yield effects.select();
|
|
324
|
-
|
|
325
52
|
try {
|
|
326
|
-
if (!version.hasNavigationTree(state)) {
|
|
327
|
-
const deliveryApiVersionStatus = yield effects.select(version
|
|
53
|
+
if (!version$1.hasNavigationTree(state)) {
|
|
54
|
+
const deliveryApiVersionStatus = yield effects.select(version.selectVersionStatus);
|
|
328
55
|
const project = yield effects.select(selectors.selectCurrentProject);
|
|
329
|
-
const nodes = yield deliveryApi.getClient(deliveryApiVersionStatus, project).nodes.getRoot({
|
|
56
|
+
const nodes = yield ContensisDeliveryApi.deliveryApi.getClient(deliveryApiVersionStatus, project).nodes.getRoot({
|
|
330
57
|
depth: action.treeDepth || 0
|
|
331
58
|
});
|
|
332
|
-
|
|
333
59
|
if (nodes) {
|
|
334
60
|
yield effects.put({
|
|
335
61
|
type: version.SET_NODE_TREE,
|
|
@@ -376,7 +102,6 @@ const fieldExpression = (field, value, operator = 'equalTo', weight = null) => {
|
|
|
376
102
|
const defaultExpressions = versionStatus => {
|
|
377
103
|
return [contensisDeliveryApi.Op.equalTo(Fields.sys.versionStatus, versionStatus)];
|
|
378
104
|
};
|
|
379
|
-
|
|
380
105
|
const equalToOrIn = (field, arr, operator = 'equalTo') => arr.length === 0 ? [] : arr.length === 1 ? [contensisDeliveryApi.Op[operator](field, arr[0])] : [contensisDeliveryApi.Op.in(field, ...arr)];
|
|
381
106
|
|
|
382
107
|
const routeEntryByFieldsQuery = (id, language = 'en-GB', fields = [], versionStatus = 'published') => {
|
|
@@ -385,12 +110,12 @@ const routeEntryByFieldsQuery = (id, language = 'en-GB', fields = [], versionSta
|
|
|
385
110
|
return query;
|
|
386
111
|
};
|
|
387
112
|
|
|
388
|
-
const routingSagas = [effects.takeEvery(
|
|
113
|
+
const routingSagas = [effects.takeEvery(selectors.SET_NAVIGATION_PATH, getRouteSaga), effects.takeEvery(selectors.SET_ROUTE, setRouteSaga)];
|
|
114
|
+
|
|
389
115
|
/**
|
|
390
116
|
* To navigate / push a specific route via redux middleware
|
|
391
117
|
* @param {path, state} action
|
|
392
118
|
*/
|
|
393
|
-
|
|
394
119
|
function* setRouteSaga(action) {
|
|
395
120
|
yield effects.put({
|
|
396
121
|
type: 'CALL_HISTORY_METHOD',
|
|
@@ -400,37 +125,35 @@ function* setRouteSaga(action) {
|
|
|
400
125
|
}
|
|
401
126
|
});
|
|
402
127
|
}
|
|
403
|
-
|
|
404
128
|
function* getRouteSaga(action) {
|
|
405
129
|
let entry = null;
|
|
406
|
-
|
|
407
130
|
try {
|
|
408
131
|
var _staticRoute$route, _staticRoute$route$pa, _staticRoute$route2, _staticRoute$route2$p, _pathNode2, _pathNode2$entry, _pathNode2$entry$sys, _pathNode3, _pathNode3$entry, _pathNode3$entry$sys;
|
|
409
|
-
|
|
410
132
|
const {
|
|
411
133
|
withEvents,
|
|
412
134
|
routes: {
|
|
413
135
|
ContentTypeMappings = {}
|
|
414
136
|
} = {},
|
|
415
137
|
staticRoute
|
|
416
|
-
} = action;
|
|
138
|
+
} = action;
|
|
417
139
|
|
|
418
|
-
|
|
140
|
+
// Inject redux { key, reducer, saga } provided by staticRoute
|
|
141
|
+
if (staticRoute && staticRoute.route.injectRedux) yield effects.call(reduxInjectorSaga, staticRoute.route.injectRedux);
|
|
419
142
|
|
|
143
|
+
// Variables we will pass to setRouteEntry
|
|
420
144
|
let pathNode = null,
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
let contentTypeMapping = {};
|
|
425
|
-
// calls to withEvents.onRouteLoad and onRouteLoaded
|
|
145
|
+
ancestors = null,
|
|
146
|
+
children = [],
|
|
147
|
+
siblings = null;
|
|
148
|
+
let contentTypeMapping = {};
|
|
426
149
|
|
|
150
|
+
// These variables are the return values from
|
|
151
|
+
// calls to withEvents.onRouteLoad and onRouteLoaded
|
|
427
152
|
let appsays,
|
|
428
|
-
|
|
429
|
-
|
|
153
|
+
requireLogin = false;
|
|
430
154
|
if (withEvents && withEvents.onRouteLoad) {
|
|
431
155
|
appsays = yield withEvents.onRouteLoad(action);
|
|
432
156
|
}
|
|
433
|
-
|
|
434
157
|
const staticRouteLinkDepth = staticRoute === null || staticRoute === void 0 ? void 0 : (_staticRoute$route = staticRoute.route) === null || _staticRoute$route === void 0 ? void 0 : (_staticRoute$route$pa = _staticRoute$route.params) === null || _staticRoute$route$pa === void 0 ? void 0 : _staticRoute$route$pa.linkDepth;
|
|
435
158
|
const staticRouteFields = staticRoute === null || staticRoute === void 0 ? void 0 : (_staticRoute$route2 = staticRoute.route) === null || _staticRoute$route2 === void 0 ? void 0 : (_staticRoute$route2$p = _staticRoute$route2.params) === null || _staticRoute$route2$p === void 0 ? void 0 : _staticRoute$route2$p.fields;
|
|
436
159
|
const entryLinkDepth = appsays && appsays.entryLinkDepth !== undefined ? appsays.entryLinkDepth : 2;
|
|
@@ -439,32 +162,31 @@ function* getRouteSaga(action) {
|
|
|
439
162
|
const routeEntry = selectors.selectRouteEntry(state, 'js');
|
|
440
163
|
const routeNode = selectors.selectCurrentNode(state, 'js');
|
|
441
164
|
const currentPath = action.path; //selectCurrentPath(state);
|
|
442
|
-
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
165
|
+
const deliveryApiStatus = version.selectVersionStatus(state);
|
|
166
|
+
const project = selectors.selectCurrentProject(state);
|
|
167
|
+
// const isHome = currentPath === '/';
|
|
446
168
|
const isPreview = currentPath && currentPath.startsWith('/preview/');
|
|
447
169
|
const defaultLang = appsays && appsays.defaultLang || 'en-GB';
|
|
448
|
-
|
|
449
170
|
if (!isPreview && (appsays && appsays.customRouting || staticRoute && !staticRoute.route.fetchNode || routeEntry && action.statePath === action.path && (appsays && appsays.refetchNode) !== true)) {
|
|
450
171
|
// To prevent erroneous 404s and wasted network calls, this covers
|
|
451
172
|
// - appsays customRouting and does SET_ENTRY etc. via the consuming app
|
|
452
173
|
// - all staticRoutes (where custom 'route.fetchNode' attribute is falsey)
|
|
453
174
|
// - standard Contensis SiteView Routing where we already have that entry in state
|
|
454
175
|
if (routeEntry && (!staticRoute || staticRoute.route && staticRoute.route.fetchNode)) {
|
|
455
|
-
pathNode = {
|
|
176
|
+
pathNode = {
|
|
177
|
+
...routeNode,
|
|
456
178
|
entry: null
|
|
457
179
|
};
|
|
458
|
-
pathNode.entry = entry = routeEntry;
|
|
180
|
+
pathNode.entry = entry = routeEntry;
|
|
181
|
+
//Do nothing, the entry is allready the right one.
|
|
459
182
|
// yield put({
|
|
460
183
|
// type: SET_ENTRY,
|
|
461
184
|
// entry,
|
|
462
185
|
// node: routeNode,
|
|
463
186
|
// isLoading: false,
|
|
464
187
|
// });
|
|
465
|
-
|
|
466
188
|
yield effects.put({
|
|
467
|
-
type:
|
|
189
|
+
type: selectors.UPDATE_LOADING_STATE,
|
|
468
190
|
isLoading: false
|
|
469
191
|
});
|
|
470
192
|
} else yield effects.call(setRouteEntry, routeEntry, yield effects.select(selectors.selectCurrentNode), yield effects.select(selectors.selectCurrentAncestors), yield effects.select(selectors.selectCurrentSiblings));
|
|
@@ -474,21 +196,20 @@ function* getRouteSaga(action) {
|
|
|
474
196
|
let splitPath = currentPath.split('/');
|
|
475
197
|
let entryGuid = splitPath[2];
|
|
476
198
|
let language = defaultLang;
|
|
477
|
-
|
|
478
199
|
if (splitPath.length >= 3) {
|
|
479
200
|
//set lang key if available in the path, else use default lang
|
|
480
201
|
//assumes preview url on content type is: http://preview.ALIAS.contensis.cloud/preview/{GUID}/{LANG}
|
|
481
|
-
if (splitPath.length == 4) language = splitPath[3];
|
|
202
|
+
if (splitPath.length == 4) language = splitPath[3];
|
|
203
|
+
// According to product dev we cannot use Node API
|
|
482
204
|
// for previewing entries as it gives a response of []
|
|
483
205
|
// -- apparently it is not correct to request latest content
|
|
484
206
|
// with Node API
|
|
485
207
|
|
|
486
|
-
let previewEntry = yield deliveryApi.getClient(deliveryApiStatus, project).entries.get({
|
|
208
|
+
let previewEntry = yield ContensisDeliveryApi.deliveryApi.getClient(deliveryApiStatus, project).entries.get({
|
|
487
209
|
id: entryGuid,
|
|
488
210
|
language,
|
|
489
211
|
linkDepth: entryLinkDepth
|
|
490
212
|
});
|
|
491
|
-
|
|
492
213
|
if (previewEntry) {
|
|
493
214
|
pathNode = {
|
|
494
215
|
entry: previewEntry
|
|
@@ -500,9 +221,8 @@ function* getRouteSaga(action) {
|
|
|
500
221
|
}
|
|
501
222
|
} else {
|
|
502
223
|
var _pathNode, _pathNode$entry, _pathNode$entry$sys;
|
|
503
|
-
|
|
504
224
|
// Handle all other routes
|
|
505
|
-
pathNode = yield cachedSearch.getNode({
|
|
225
|
+
pathNode = yield ContensisDeliveryApi.cachedSearch.getNode({
|
|
506
226
|
depth: 0,
|
|
507
227
|
path: currentPath,
|
|
508
228
|
entryFields: setContentTypeLimits ? ['sys.contentTypeId', 'sys.id'] : staticRouteFields || '*',
|
|
@@ -513,10 +233,8 @@ function* getRouteSaga(action) {
|
|
|
513
233
|
({
|
|
514
234
|
entry
|
|
515
235
|
} = pathNode || {});
|
|
516
|
-
|
|
517
236
|
if (setContentTypeLimits && (_pathNode = pathNode) !== null && _pathNode !== void 0 && (_pathNode$entry = _pathNode.entry) !== null && _pathNode$entry !== void 0 && (_pathNode$entry$sys = _pathNode$entry.sys) !== null && _pathNode$entry$sys !== void 0 && _pathNode$entry$sys.id) {
|
|
518
237
|
var _payload$items;
|
|
519
|
-
|
|
520
238
|
// Get fields[] and linkDepth from ContentTypeMapping to get the entry data
|
|
521
239
|
// and current node's ordinates at a specified depth with specified fields
|
|
522
240
|
contentTypeMapping = login.findContentTypeMapping(ContentTypeMappings, pathNode.entry.sys.contentTypeId) || {};
|
|
@@ -525,16 +243,15 @@ function* getRouteSaga(action) {
|
|
|
525
243
|
linkDepth
|
|
526
244
|
} = contentTypeMapping;
|
|
527
245
|
const query = routeEntryByFieldsQuery(pathNode.entry.sys.id, pathNode.entry.sys.language, fields, deliveryApiStatus);
|
|
528
|
-
const payload = yield cachedSearch.search(query, typeof linkDepth !== 'undefined' ? linkDepth : entryLinkDepth || 0, project);
|
|
529
|
-
|
|
246
|
+
const payload = yield ContensisDeliveryApi.cachedSearch.search(query, typeof linkDepth !== 'undefined' ? linkDepth : entryLinkDepth || 0, project);
|
|
530
247
|
if ((payload === null || payload === void 0 ? void 0 : (_payload$items = payload.items) === null || _payload$items === void 0 ? void 0 : _payload$items.length) > 0) {
|
|
531
248
|
pathNode.entry = entry = payload.items[0];
|
|
532
249
|
}
|
|
533
250
|
}
|
|
534
|
-
}
|
|
535
|
-
// siblings or entire node tree
|
|
536
|
-
|
|
251
|
+
}
|
|
537
252
|
|
|
253
|
+
// make calls to fetch node ancestors, children,
|
|
254
|
+
// siblings or entire node tree
|
|
538
255
|
[ancestors, children, siblings] = yield effects.call(resolveCurrentNodeOrdinates, {
|
|
539
256
|
appsays,
|
|
540
257
|
contentTypeMapping,
|
|
@@ -546,37 +263,34 @@ function* getRouteSaga(action) {
|
|
|
546
263
|
});
|
|
547
264
|
if (children) pathNode.children = children;
|
|
548
265
|
}
|
|
266
|
+
const resolvedContentTypeMapping = login.findContentTypeMapping(ContentTypeMappings, (_pathNode2 = pathNode) === null || _pathNode2 === void 0 ? void 0 : (_pathNode2$entry = _pathNode2.entry) === null || _pathNode2$entry === void 0 ? void 0 : (_pathNode2$entry$sys = _pathNode2$entry.sys) === null || _pathNode2$entry$sys === void 0 ? void 0 : _pathNode2$entry$sys.contentTypeId) || {};
|
|
549
267
|
|
|
550
|
-
|
|
551
|
-
|
|
268
|
+
// Inject redux { key, reducer, saga } provided by ContentTypeMapping
|
|
552
269
|
if (resolvedContentTypeMapping.injectRedux) yield effects.call(reduxInjectorSaga, resolvedContentTypeMapping.injectRedux);
|
|
553
|
-
|
|
554
270
|
if (withEvents && withEvents.onRouteLoaded) {
|
|
555
271
|
// Check if the app has provided a requireLogin boolean flag or groups array
|
|
556
272
|
// in addition to checking if requireLogin is set in the route definition
|
|
557
273
|
({
|
|
558
274
|
requireLogin
|
|
559
|
-
} = (yield withEvents.onRouteLoaded({
|
|
275
|
+
} = (yield withEvents.onRouteLoaded({
|
|
276
|
+
...action,
|
|
560
277
|
entry
|
|
561
278
|
})) || {});
|
|
562
279
|
}
|
|
563
|
-
|
|
564
280
|
if (requireLogin !== false) {
|
|
565
281
|
// Do not call the login feature saga if requireLogin is false
|
|
566
|
-
yield effects.call(login.handleRequiresLoginSaga, {
|
|
282
|
+
yield effects.call(login.handleRequiresLoginSaga, {
|
|
283
|
+
...action,
|
|
567
284
|
entry,
|
|
568
285
|
requireLogin
|
|
569
286
|
});
|
|
570
287
|
}
|
|
571
|
-
|
|
572
288
|
if (!appsays || !appsays.preventScrollTop) {
|
|
573
289
|
// Scroll into View
|
|
574
290
|
if (typeof window !== 'undefined') window.scrollTo(0, 0);
|
|
575
291
|
}
|
|
576
|
-
|
|
577
292
|
if ((_pathNode3 = pathNode) !== null && _pathNode3 !== void 0 && (_pathNode3$entry = _pathNode3.entry) !== null && _pathNode3$entry !== void 0 && (_pathNode3$entry$sys = _pathNode3$entry.sys) !== null && _pathNode3$entry$sys !== void 0 && _pathNode3$entry$sys.id) {
|
|
578
293
|
var _staticRoute$route3, _staticRoute$route3$f, _appsays;
|
|
579
|
-
|
|
580
294
|
entry = pathNode.entry;
|
|
581
295
|
yield effects.call(setRouteEntry, entry, pathNode, ancestors, siblings, (staticRoute === null || staticRoute === void 0 ? void 0 : (_staticRoute$route3 = staticRoute.route) === null || _staticRoute$route3 === void 0 ? void 0 : (_staticRoute$route3$f = _staticRoute$route3.fetchNode) === null || _staticRoute$route3$f === void 0 ? void 0 : _staticRoute$route3$f.entryMapper) || resolvedContentTypeMapping.entryMapper, false, (_appsays = appsays) === null || _appsays === void 0 ? void 0 : _appsays.refetchNode);
|
|
582
296
|
} else {
|
|
@@ -587,7 +301,6 @@ function* getRouteSaga(action) {
|
|
|
587
301
|
yield effects.call(do500, e);
|
|
588
302
|
}
|
|
589
303
|
}
|
|
590
|
-
|
|
591
304
|
function* resolveCurrentNodeOrdinates({
|
|
592
305
|
appsays,
|
|
593
306
|
contentTypeMapping,
|
|
@@ -597,10 +310,11 @@ function* resolveCurrentNodeOrdinates({
|
|
|
597
310
|
project,
|
|
598
311
|
versionStatus
|
|
599
312
|
}) {
|
|
600
|
-
const apiCall = [() => null, () => null, () => null, () => null];
|
|
313
|
+
const apiCall = [() => null, () => null, () => null, () => null];
|
|
314
|
+
|
|
315
|
+
// if appsays customNavigation: true, we will set doNavigation to false
|
|
601
316
|
// if appsays customNavigation: { ... }, we will set doNavigation to the customNavigation object and check for child elements
|
|
602
317
|
// if appsays nothing we will set doNavigation to true and continue to do navigation calls
|
|
603
|
-
|
|
604
318
|
const doNavigation = !appsays || ((appsays === null || appsays === void 0 ? void 0 : appsays.customNavigation) === true ? false : (appsays === null || appsays === void 0 ? void 0 : appsays.customNavigation) || true);
|
|
605
319
|
const {
|
|
606
320
|
entryLinkDepth = 0,
|
|
@@ -608,12 +322,11 @@ function* resolveCurrentNodeOrdinates({
|
|
|
608
322
|
linkDepth,
|
|
609
323
|
nodeOptions = {}
|
|
610
324
|
} = contentTypeMapping;
|
|
611
|
-
|
|
612
325
|
if (pathNode && pathNode.id) {
|
|
613
326
|
if (doNavigation === true || doNavigation.ancestors) {
|
|
614
327
|
apiCall[0] = function* getAncestors() {
|
|
615
328
|
try {
|
|
616
|
-
return yield cachedSearch.getAncestors({
|
|
329
|
+
return yield ContensisDeliveryApi.cachedSearch.getAncestors({
|
|
617
330
|
id: pathNode.id,
|
|
618
331
|
language,
|
|
619
332
|
versionStatus
|
|
@@ -624,15 +337,12 @@ function* resolveCurrentNodeOrdinates({
|
|
|
624
337
|
}
|
|
625
338
|
};
|
|
626
339
|
}
|
|
627
|
-
|
|
628
340
|
const childrenDepth = doNavigation === true || doNavigation.children === true ? 1 : doNavigation && doNavigation.children || 0;
|
|
629
|
-
|
|
630
341
|
if (typeof (nodeOptions === null || nodeOptions === void 0 ? void 0 : nodeOptions.children) === 'undefined' && childrenDepth > 0 || nodeOptions.children) {
|
|
631
342
|
const childrenOptions = typeof nodeOptions.children === 'boolean' ? {} : nodeOptions.children;
|
|
632
|
-
|
|
633
343
|
apiCall[1] = function* getChildren() {
|
|
634
344
|
try {
|
|
635
|
-
return yield cachedSearch.getNode({
|
|
345
|
+
return yield ContensisDeliveryApi.cachedSearch.getNode({
|
|
636
346
|
depth: childrenOptions.depth !== undefined ? childrenOptions.depth : childrenDepth,
|
|
637
347
|
path,
|
|
638
348
|
entryFields: childrenOptions.fields || fields || undefined,
|
|
@@ -646,13 +356,11 @@ function* resolveCurrentNodeOrdinates({
|
|
|
646
356
|
}
|
|
647
357
|
};
|
|
648
358
|
}
|
|
649
|
-
|
|
650
359
|
if (typeof (nodeOptions === null || nodeOptions === void 0 ? void 0 : nodeOptions.siblings) === 'undefined' && doNavigation.siblings || nodeOptions.siblings) {
|
|
651
360
|
apiCall[2] = function* getSiblings() {
|
|
652
361
|
try {
|
|
653
362
|
var _nodeOptions$siblings, _nodeOptions$siblings2;
|
|
654
|
-
|
|
655
|
-
return yield cachedSearch.getSiblings({
|
|
363
|
+
return yield ContensisDeliveryApi.cachedSearch.getSiblings({
|
|
656
364
|
id: pathNode.id,
|
|
657
365
|
entryFields: (nodeOptions === null || nodeOptions === void 0 ? void 0 : (_nodeOptions$siblings = nodeOptions.siblings) === null || _nodeOptions$siblings === void 0 ? void 0 : _nodeOptions$siblings.fields) || fields || undefined,
|
|
658
366
|
entryLinkDepth: typeof (nodeOptions === null || nodeOptions === void 0 ? void 0 : (_nodeOptions$siblings2 = nodeOptions.siblings) === null || _nodeOptions$siblings2 === void 0 ? void 0 : _nodeOptions$siblings2.linkDepth) !== 'undefined' ? nodeOptions.siblings.linkDepth : typeof linkDepth !== 'undefined' ? linkDepth : entryLinkDepth,
|
|
@@ -667,11 +375,9 @@ function* resolveCurrentNodeOrdinates({
|
|
|
667
375
|
};
|
|
668
376
|
}
|
|
669
377
|
}
|
|
670
|
-
|
|
671
|
-
const isTreeLoaded = yield effects.select(version.hasNavigationTree);
|
|
378
|
+
const isTreeLoaded = yield effects.select(version$1.hasNavigationTree);
|
|
672
379
|
if (!isTreeLoaded && (doNavigation === true || doNavigation.tree)) apiCall[3] = function* getNodeTree() {
|
|
673
380
|
const treeDepth = doNavigation === true || !doNavigation.tree || doNavigation.tree === true ? 2 : doNavigation.tree;
|
|
674
|
-
|
|
675
381
|
if (typeof window !== 'undefined') {
|
|
676
382
|
return yield effects.put({
|
|
677
383
|
type: version.GET_NODE_TREE,
|
|
@@ -687,32 +393,35 @@ function* resolveCurrentNodeOrdinates({
|
|
|
687
393
|
const [ancestors, nodeWithChildren, siblings] = yield effects.all([loadAncestors(), loadChildren(), loadSiblings(), loadTree()]);
|
|
688
394
|
return [ancestors, nodeWithChildren === null || nodeWithChildren === void 0 ? void 0 : nodeWithChildren.children, siblings];
|
|
689
395
|
}
|
|
690
|
-
|
|
691
396
|
function* setRouteEntry(entry, node, ancestors, siblings, entryMapper, notFound = false, remapEntry = false) {
|
|
692
397
|
const entrySys = entry && entry.sys || {};
|
|
398
|
+
|
|
399
|
+
// Update a window global to provide the preview toolbar
|
|
400
|
+
// an updated entry id in client-side navigation
|
|
401
|
+
if (typeof window !== 'undefined') window.ContensisEntryId = entrySys.id;
|
|
693
402
|
const currentEntryId = yield effects.select(selectors.selectRouteEntryEntryId);
|
|
694
403
|
const currentEntryLang = yield effects.select(selectors.selectRouteEntryLanguage);
|
|
695
|
-
const mappedEntry = currentEntryId === entrySys.id && currentEntryLang === entrySys.language && remapEntry === false ? (yield effects.select(selectors.selectMappedEntry, 'js')) || {} : yield mapRouteEntry(entryMapper, {
|
|
404
|
+
const mappedEntry = currentEntryId === entrySys.id && currentEntryLang === entrySys.language && remapEntry === false ? (yield effects.select(selectors.selectMappedEntry, 'js')) || {} : yield mapRouteEntry(entryMapper, {
|
|
405
|
+
...node,
|
|
696
406
|
entry,
|
|
697
407
|
ancestors,
|
|
698
408
|
siblings
|
|
699
409
|
});
|
|
700
410
|
yield effects.all([effects.put({
|
|
701
|
-
type:
|
|
411
|
+
type: selectors.SET_ENTRY,
|
|
702
412
|
id: entrySys.id,
|
|
703
413
|
entry,
|
|
704
414
|
mappedEntry,
|
|
705
415
|
node,
|
|
706
416
|
notFound
|
|
707
417
|
}), ancestors && effects.put({
|
|
708
|
-
type:
|
|
418
|
+
type: selectors.SET_ANCESTORS,
|
|
709
419
|
ancestors
|
|
710
420
|
}), siblings && effects.put({
|
|
711
|
-
type:
|
|
421
|
+
type: selectors.SET_SIBLINGS,
|
|
712
422
|
siblings
|
|
713
423
|
})]);
|
|
714
424
|
}
|
|
715
|
-
|
|
716
425
|
function* mapRouteEntry(entryMapper, node) {
|
|
717
426
|
try {
|
|
718
427
|
if (typeof entryMapper === 'function') {
|
|
@@ -723,33 +432,30 @@ function* mapRouteEntry(entryMapper, node) {
|
|
|
723
432
|
} catch (e) {
|
|
724
433
|
log__namespace.error(...['Error running entryMapper:', e, e.stack]);
|
|
725
434
|
}
|
|
726
|
-
|
|
727
435
|
return;
|
|
728
436
|
}
|
|
729
|
-
|
|
730
437
|
function* do404() {
|
|
731
438
|
yield effects.call(clientReloadHitServer);
|
|
732
439
|
yield effects.put({
|
|
733
|
-
type:
|
|
440
|
+
type: selectors.SET_ENTRY,
|
|
734
441
|
id: null,
|
|
735
442
|
entry: null,
|
|
736
443
|
notFound: true
|
|
737
444
|
});
|
|
738
445
|
}
|
|
739
|
-
|
|
740
446
|
function* clientReloadHitServer() {
|
|
741
|
-
const stateEntry = yield effects.select(selectors.selectRouteEntry);
|
|
447
|
+
const stateEntry = yield effects.select(selectors.selectRouteEntry);
|
|
448
|
+
|
|
449
|
+
// If in client and there is a stateEntry.sys field reload the page,
|
|
742
450
|
// on the 2nd load stateEntry.sys should be null at this point,
|
|
743
451
|
// we do not wish to reload again and get stuck in an infinite reloading loop
|
|
744
|
-
|
|
745
452
|
if (typeof window !== 'undefined' && (stateEntry !== null && stateEntry !== void 0 && stateEntry.sys || null)) {
|
|
746
453
|
window.location.reload();
|
|
747
454
|
}
|
|
748
455
|
}
|
|
749
|
-
|
|
750
456
|
function* do500(error) {
|
|
751
457
|
yield effects.put({
|
|
752
|
-
type:
|
|
458
|
+
type: selectors.SET_ENTRY,
|
|
753
459
|
id: null,
|
|
754
460
|
entry: null,
|
|
755
461
|
notFound: true,
|
|
@@ -758,7 +464,6 @@ function* do500(error) {
|
|
|
758
464
|
statusCode: error && error.status ? error.status : 500
|
|
759
465
|
});
|
|
760
466
|
}
|
|
761
|
-
|
|
762
467
|
function* reduxInjectorSaga(injectorFn) {
|
|
763
468
|
if (typeof injectorFn === 'function') {
|
|
764
469
|
const {
|
|
@@ -766,7 +471,7 @@ function* reduxInjectorSaga(injectorFn) {
|
|
|
766
471
|
reducer,
|
|
767
472
|
saga
|
|
768
473
|
} = yield injectorFn();
|
|
769
|
-
version.injectRedux({
|
|
474
|
+
version$1.injectRedux({
|
|
770
475
|
key,
|
|
771
476
|
reducer,
|
|
772
477
|
saga
|
|
@@ -775,19 +480,18 @@ function* reduxInjectorSaga(injectorFn) {
|
|
|
775
480
|
}
|
|
776
481
|
|
|
777
482
|
const registerSagas = [effects.takeEvery(reducers.REGISTER_USER, registerSaga), effects.takeEvery(reducers.REGISTER_USER_SUCCESS, redirectSaga)];
|
|
778
|
-
|
|
779
483
|
function* registerSaga({
|
|
780
484
|
user,
|
|
781
485
|
mappers
|
|
782
486
|
}) {
|
|
783
|
-
let requestBody = user;
|
|
487
|
+
let requestBody = user;
|
|
488
|
+
// Allow use of request mapper to take a user object
|
|
784
489
|
// of any format and return the payload for the api request
|
|
785
|
-
|
|
786
490
|
if (mappers && mappers.request && typeof mappers.request === 'function') {
|
|
787
491
|
requestBody = yield mappers.request(user);
|
|
788
|
-
}
|
|
789
|
-
|
|
492
|
+
}
|
|
790
493
|
|
|
494
|
+
// Make POST call to register API
|
|
791
495
|
const response = yield fetch('/account/register', {
|
|
792
496
|
method: 'POST',
|
|
793
497
|
headers: {
|
|
@@ -796,19 +500,16 @@ function* registerSaga({
|
|
|
796
500
|
},
|
|
797
501
|
body: JSON.stringify(requestBody)
|
|
798
502
|
});
|
|
799
|
-
|
|
800
503
|
if (response.ok) {
|
|
801
504
|
let mappedResponse;
|
|
802
505
|
const [, responseBody] = yield awaitToJs.to(response.json());
|
|
803
|
-
|
|
804
506
|
if (responseBody) {
|
|
805
507
|
// Allow use of response mapper to convert the successful user object
|
|
806
508
|
// from the api response body into a user object of any format
|
|
807
509
|
if (mappers && mappers.response && typeof mappers.response === 'function') {
|
|
808
510
|
mappedResponse = yield mappers.response(responseBody);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
|
|
511
|
+
}
|
|
512
|
+
// Update user object with mappedResponse or responseBody
|
|
812
513
|
yield effects.put({
|
|
813
514
|
type: reducers.REGISTER_USER_SUCCESS,
|
|
814
515
|
user: mappedResponse || responseBody
|
|
@@ -827,26 +528,25 @@ function* registerSaga({
|
|
|
827
528
|
// or status codes echoed from the responses received from
|
|
828
529
|
// management api when registering the user
|
|
829
530
|
const [, errorResponse] = yield awaitToJs.to(response.json());
|
|
830
|
-
const error = errorResponse && errorResponse.error || errorResponse || {};
|
|
831
|
-
|
|
531
|
+
const error = errorResponse && errorResponse.error || errorResponse || {};
|
|
532
|
+
// Get something meaningful from the response if there is no message in the body
|
|
832
533
|
if (!error.message) {
|
|
833
534
|
error.message = `Registration service: ${response.statusText}`;
|
|
834
535
|
error.status = response.status;
|
|
835
536
|
}
|
|
836
|
-
|
|
837
537
|
yield effects.put({
|
|
838
538
|
type: reducers.REGISTER_USER_FAILED,
|
|
839
539
|
error
|
|
840
540
|
});
|
|
841
541
|
}
|
|
842
542
|
}
|
|
843
|
-
|
|
844
543
|
function* redirectSaga() {
|
|
845
544
|
// Check if querystring contains a redirect_uri
|
|
846
545
|
const currentQs = selectors.queryParams(yield effects.select(selectors.selectCurrentSearch));
|
|
847
|
-
const redirectUri = currentQs.redirect_uri || currentQs.redirect;
|
|
546
|
+
const redirectUri = currentQs.redirect_uri || currentQs.redirect;
|
|
848
547
|
|
|
849
|
-
|
|
548
|
+
// We must use redux based navigation to preserve the registration state
|
|
549
|
+
if (redirectUri) yield effects.put(selectors.setRoute(redirectUri));
|
|
850
550
|
}
|
|
851
551
|
|
|
852
552
|
const PAP_URL = 'https://pap.zengenti.com';
|
|
@@ -863,36 +563,36 @@ const BASE_OPTIONS = {
|
|
|
863
563
|
};
|
|
864
564
|
class UserHelper {
|
|
865
565
|
static async GetUsersEnvironments(securityToken) {
|
|
866
|
-
const options = {
|
|
566
|
+
const options = {
|
|
567
|
+
...BASE_OPTIONS,
|
|
867
568
|
headers: {
|
|
868
569
|
'x-security-token': securityToken
|
|
869
570
|
}
|
|
870
571
|
};
|
|
871
572
|
return await UserHelper.get(USER_ENVS_URL, options);
|
|
872
573
|
}
|
|
873
|
-
|
|
874
574
|
static async ResendUserVerification(userEmail) {
|
|
875
|
-
const options = {
|
|
575
|
+
const options = {
|
|
576
|
+
...BASE_OPTIONS
|
|
876
577
|
};
|
|
877
578
|
return await UserHelper.get(`/${USER_RESEND_VERIFICATION_URI}?user=${userEmail}`, options);
|
|
878
579
|
}
|
|
879
|
-
|
|
880
580
|
static async RequestPasswordReset(userEmailObject) {
|
|
881
|
-
const options = {
|
|
581
|
+
const options = {
|
|
582
|
+
...BASE_OPTIONS,
|
|
882
583
|
body: JSON.stringify(userEmailObject)
|
|
883
584
|
};
|
|
884
585
|
options.method = 'POST';
|
|
885
586
|
return await UserHelper.get(`/${USER_REQUEST_PASSWORD_RESET_URI}`, options);
|
|
886
587
|
}
|
|
887
|
-
|
|
888
588
|
static async ResetPassword(resetPasswordObject) {
|
|
889
|
-
const options = {
|
|
589
|
+
const options = {
|
|
590
|
+
...BASE_OPTIONS,
|
|
890
591
|
body: JSON.stringify(resetPasswordObject)
|
|
891
592
|
};
|
|
892
593
|
options.method = 'POST';
|
|
893
594
|
return await UserHelper.get(`/${USER_RESET_PASSWORD_URI}`, options);
|
|
894
595
|
}
|
|
895
|
-
|
|
896
596
|
static async get(url, options = BASE_OPTIONS) {
|
|
897
597
|
try {
|
|
898
598
|
const responseBody = await api(url, options);
|
|
@@ -905,9 +605,7 @@ class UserHelper {
|
|
|
905
605
|
};
|
|
906
606
|
}
|
|
907
607
|
}
|
|
908
|
-
|
|
909
608
|
}
|
|
910
|
-
|
|
911
609
|
async function api(url, options) {
|
|
912
610
|
return fetch(url, options).then(async response => {
|
|
913
611
|
return response.json().then(data => data);
|
|
@@ -917,17 +615,14 @@ async function api(url, options) {
|
|
|
917
615
|
}
|
|
918
616
|
|
|
919
617
|
const resetPasswordSagas = [effects.takeEvery(reducers.REQUEST_USER_PASSWORD_RESET, requestPasswordResetSaga), effects.takeEvery(reducers.RESET_USER_PASSWORD, resetPasswordSaga), effects.takeEvery(reducers.CHANGE_USER_PASSWORD, changePasswordSaga)];
|
|
920
|
-
|
|
921
618
|
function* requestPasswordResetSaga(action) {
|
|
922
619
|
const userEmailObject = action.userEmailObject;
|
|
923
620
|
yield effects.put({
|
|
924
621
|
type: reducers.REQUEST_USER_PASSWORD_RESET_SENDING
|
|
925
622
|
});
|
|
926
|
-
|
|
927
623
|
if (userEmailObject && userEmailObject.userEmail) {
|
|
928
624
|
try {
|
|
929
625
|
const passwordResetRequestResponse = yield UserHelper.RequestPasswordReset(userEmailObject);
|
|
930
|
-
|
|
931
626
|
if (passwordResetRequestResponse) {
|
|
932
627
|
if (!passwordResetRequestResponse.error) {
|
|
933
628
|
yield effects.put({
|
|
@@ -958,17 +653,14 @@ function* requestPasswordResetSaga(action) {
|
|
|
958
653
|
});
|
|
959
654
|
}
|
|
960
655
|
}
|
|
961
|
-
|
|
962
656
|
function* resetPasswordSaga(action) {
|
|
963
657
|
const resetPasswordObject = action.resetPasswordObject;
|
|
964
658
|
yield effects.put({
|
|
965
659
|
type: reducers.RESET_USER_PASSWORD_SENDING
|
|
966
660
|
});
|
|
967
|
-
|
|
968
661
|
if (resetPasswordObject.token && resetPasswordObject.password) {
|
|
969
662
|
try {
|
|
970
663
|
const resetPasswordResponse = yield UserHelper.ResetPassword(resetPasswordObject);
|
|
971
|
-
|
|
972
664
|
if (resetPasswordResponse) {
|
|
973
665
|
if (!resetPasswordResponse.error) {
|
|
974
666
|
yield effects.put({
|
|
@@ -999,11 +691,11 @@ function* resetPasswordSaga(action) {
|
|
|
999
691
|
error: 'Invalid object'
|
|
1000
692
|
});
|
|
1001
693
|
}
|
|
1002
|
-
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// userId
|
|
1003
697
|
// existingPassword
|
|
1004
698
|
// newPassword
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
699
|
function* changePasswordSaga(action) {
|
|
1008
700
|
if (!action || !action.userId || !action.currentPassword || !action.newPassword) {
|
|
1009
701
|
yield effects.put({
|
|
@@ -1012,7 +704,6 @@ function* changePasswordSaga(action) {
|
|
|
1012
704
|
});
|
|
1013
705
|
return;
|
|
1014
706
|
}
|
|
1015
|
-
|
|
1016
707
|
try {
|
|
1017
708
|
const changePasswordObject = {
|
|
1018
709
|
userId: action.userId,
|
|
@@ -1023,25 +714,24 @@ function* changePasswordSaga(action) {
|
|
|
1023
714
|
type: reducers.CHANGE_USER_PASSWORD_SENDING
|
|
1024
715
|
});
|
|
1025
716
|
const clientCredentials = yield effects.select(ToJs.selectClientCredentials, 'js');
|
|
1026
|
-
const client = yield login.getManagementApiClient({
|
|
717
|
+
const client = yield login.getManagementApiClient({
|
|
718
|
+
...clientCredentials
|
|
1027
719
|
});
|
|
1028
720
|
const [err, res] = yield awaitToJs.to(client.security.users.updatePassword(changePasswordObject));
|
|
1029
|
-
|
|
1030
721
|
if (err) {
|
|
1031
722
|
var _err$data, _err$data$data, _err$data2;
|
|
1032
|
-
|
|
1033
723
|
const error = (err === null || err === void 0 ? void 0 : (_err$data = err.data) === null || _err$data === void 0 ? void 0 : (_err$data$data = _err$data.data) === null || _err$data$data === void 0 ? void 0 : _err$data$data.length) > 0 && err.data.data[0].message || (err === null || err === void 0 ? void 0 : (_err$data2 = err.data) === null || _err$data2 === void 0 ? void 0 : _err$data2.message);
|
|
1034
724
|
yield effects.put({
|
|
1035
725
|
type: reducers.CHANGE_USER_PASSWORD_ERROR,
|
|
1036
726
|
error
|
|
1037
727
|
});
|
|
1038
728
|
return;
|
|
1039
|
-
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// // eslint-disable-next-line no-console
|
|
1040
732
|
// console.log(changePasswordObject);
|
|
1041
733
|
// // eslint-disable-next-line no-console
|
|
1042
734
|
// console.log(userCredentialsObject);
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
735
|
yield effects.put({
|
|
1046
736
|
type: reducers.CHANGE_USER_PASSWORD_SUCCESS
|
|
1047
737
|
});
|
|
@@ -1063,35 +753,32 @@ function rootSaga (featureSagas = []) {
|
|
|
1063
753
|
};
|
|
1064
754
|
}
|
|
1065
755
|
|
|
1066
|
-
const servers = SERVERS;
|
|
1067
|
-
/* global SERVERS */
|
|
1068
|
-
|
|
756
|
+
const servers = SERVERS; /* global SERVERS */
|
|
1069
757
|
const alias = servers.alias.toLowerCase();
|
|
1070
|
-
const publicUri = PUBLIC_URI;
|
|
1071
|
-
/* global
|
|
758
|
+
const publicUri = PUBLIC_URI; /* global PUBLIC_URI */
|
|
759
|
+
const projects = PROJECTS; /* global PROJECTS */
|
|
1072
760
|
|
|
1073
|
-
const projects = PROJECTS;
|
|
1074
|
-
/* global PROJECTS */
|
|
1075
761
|
// return a projectId via the request hostname
|
|
1076
|
-
|
|
1077
762
|
const pickProject = (hostname, query) => {
|
|
1078
763
|
// if localhost we can only infer via a querystring, and take your word for it
|
|
1079
764
|
if (hostname == 'localhost') {
|
|
1080
765
|
return query && query.p || projects[0].id;
|
|
1081
|
-
}
|
|
1082
|
-
|
|
766
|
+
}
|
|
1083
767
|
|
|
768
|
+
// if hostname is the actual public uri we can return the first project from the list
|
|
1084
769
|
if (hostname == publicUri) {
|
|
1085
770
|
return projects[0].id;
|
|
1086
771
|
}
|
|
772
|
+
let project = 'unknown';
|
|
1087
773
|
|
|
1088
|
-
|
|
774
|
+
// // go through all the defined projects
|
|
1089
775
|
// Object.entries(projects).map(([, p]) => {
|
|
776
|
+
const p = projects[0];
|
|
1090
777
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
if (hostname.includes(p.publicUri)) project = p.id; // the url structure is different for website (we don't prefix)
|
|
778
|
+
// check if we're accessing via the project's public uri
|
|
779
|
+
if (hostname.includes(p.publicUri)) project = p.id;
|
|
1094
780
|
|
|
781
|
+
// the url structure is different for website (we don't prefix)
|
|
1095
782
|
if (p.id.startsWith('website')) {
|
|
1096
783
|
// check for internal and external hostnames
|
|
1097
784
|
// we check live and preview distinctly so our rule does not clash with
|
|
@@ -1100,9 +787,8 @@ const pickProject = (hostname, query) => {
|
|
|
1100
787
|
} else {
|
|
1101
788
|
// check for internal and external hostnames, prefixed with the projectId
|
|
1102
789
|
if (hostname.includes(`${p.id.toLowerCase()}-${alias}.cloud.contensis.com`) || hostname.includes(`${p.id.toLowerCase()}.${alias}.contensis.cloud`)) project = p.id;
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
|
|
790
|
+
}
|
|
791
|
+
// });
|
|
1106
792
|
return project === 'unknown' ? p.id : project;
|
|
1107
793
|
};
|
|
1108
794
|
|
|
@@ -1112,9 +798,7 @@ const AppRoot = props => {
|
|
|
1112
798
|
|
|
1113
799
|
exports.AppRoot = AppRoot;
|
|
1114
800
|
exports.browserHistory = browserHistory;
|
|
1115
|
-
exports.cachedSearch = cachedSearch;
|
|
1116
|
-
exports.deliveryApi = deliveryApi;
|
|
1117
801
|
exports.history = history;
|
|
1118
802
|
exports.pickProject = pickProject;
|
|
1119
803
|
exports.rootSaga = rootSaga;
|
|
1120
|
-
//# sourceMappingURL=App-
|
|
804
|
+
//# sourceMappingURL=App-81a45001.js.map
|