@zengenti/contensis-react-base 4.0.0-beta.1 → 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 (98) hide show
  1. package/cjs/{App-cf7e3103.js → App-b56aca04.js} +139 -93
  2. package/{esm/App-6e8e803b.js.map → cjs/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-3e284fd6.js → RouteLoader-c06dccd5.js} +182 -63
  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 +20 -14
  13. package/cjs/client.js.map +1 -1
  14. package/cjs/contensis-react-base.js +275 -139
  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 -4
  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-6e8e803b.js → App-83107d7e.js} +137 -91
  42. package/{cjs/App-cf7e3103.js.map → esm/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 +21 -15
  53. package/esm/client.js.map +1 -1
  54. package/esm/contensis-react-base.js +270 -136
  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 -4
  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/redux/appstate.d.ts +2 -3
  82. package/models/redux/store/history.d.ts +2 -2
  83. package/models/routing/components/Redirect.d.ts +5 -0
  84. package/models/routing/components/StaticRouteLoader.d.ts +6 -0
  85. package/models/routing/httpContext.d.ts +7 -0
  86. package/models/routing/index.d.ts +3 -0
  87. package/models/routing/redux/actions.d.ts +2 -3
  88. package/models/routing/routes.d.ts +11 -5
  89. package/models/util/ContensisDeliveryApi.d.ts +0 -1
  90. package/models/util/mergeStaticRoutes.d.ts +1 -0
  91. package/package.json +3 -5
  92. package/cjs/RouteLoader-3e284fd6.js.map +0 -1
  93. package/cjs/selectors-46b689d0.js.map +0 -1
  94. package/cjs/version-79a027cb.js.map +0 -1
  95. package/esm/RouteLoader-e3c5505f.js +0 -196
  96. package/esm/RouteLoader-e3c5505f.js.map +0 -1
  97. package/esm/selectors-01074974.js.map +0 -1
  98. package/esm/version-346a9787.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var effects = require('@redux-saga/core/effects');
4
- var reducers = require('./reducers-9afb5f89.js');
5
- var ToJs = require('./ToJs-149fc5e1.js');
6
- var selectors = require('./selectors-46b689d0.js');
4
+ var reducers = require('./reducers-73a03ef4.js');
5
+ var ToJs = require('./ToJs-a8d8f3f0.js');
6
+ var selectors = require('./selectors-14caa813.js');
7
7
  var mapJson = require('jsonpath-mapper');
8
8
  var to = require('await-to-js');
9
9
  var CookieConstants = require('./CookieConstants-000427db.js');
@@ -48,7 +48,6 @@ const clientCredentials = {
48
48
  var mapClientCredentials = (obj => mapJson__default["default"](obj, clientCredentials));
49
49
 
50
50
  // import { Client } from 'contensis-management-api';
51
-
52
51
  const getManagementApiClient = async ({
53
52
  bearerToken,
54
53
  bearerTokenExpiryDate,
@@ -58,10 +57,14 @@ const getManagementApiClient = async ({
58
57
  username,
59
58
  password
60
59
  }) => {
61
- const rootUrl = SERVERS.api || SERVERS.cms; /* global SERVERS */
62
- const projectId = PROJECTS[0].id; /* global PROJECTS */
60
+ const rootUrl = SERVERS.api || SERVERS.cms;
61
+ /* global SERVERS */
62
+
63
+ const projectId = PROJECTS[0].id;
64
+ /* global PROJECTS */
63
65
 
64
66
  let config = {};
67
+
65
68
  if (refreshToken) {
66
69
  config = {
67
70
  clientType: 'contensis_classic_refresh_token',
@@ -78,17 +81,19 @@ const getManagementApiClient = async ({
78
81
  }
79
82
  };
80
83
  }
84
+
81
85
  let {
82
86
  Client
83
87
  } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('contensis-management-api')); });
88
+
84
89
  if (typeof window === 'undefined') {
85
90
  const {
86
91
  UniversalClient
87
92
  } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('contensis-management-api')); });
88
93
  Client = UniversalClient;
89
94
  }
90
- const client = Client.create({
91
- ...config,
95
+
96
+ const client = Client.create({ ...config,
92
97
  projectId,
93
98
  rootUrl
94
99
  });
@@ -101,8 +106,11 @@ const getManagementApiClient = async ({
101
106
  };
102
107
 
103
108
  const context$1 = typeof window != 'undefined' ? window : global;
104
- const requireOidc = process.env.NODE_ENV === 'development' ? WSFED_LOGIN === 'true' /* global WSFED_LOGIN */ : context$1.WSFED_LOGIN === 'true';
105
- const servers = SERVERS; /* global SERVERS */
109
+ const requireOidc = process.env.NODE_ENV === 'development' ? WSFED_LOGIN === 'true'
110
+ /* global WSFED_LOGIN */
111
+ : context$1.WSFED_LOGIN === 'true';
112
+ const servers = SERVERS;
113
+ /* global SERVERS */
106
114
 
107
115
  const userManagerConfig = typeof window !== 'undefined' ? {
108
116
  authority: `${servers.cms}/authenticate/`,
@@ -118,7 +126,9 @@ const createUserManager = async config => {
118
126
  try {
119
127
  const {
120
128
  UserManager
121
- } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require( /* webpackChunkName: "oidcclient" */'oidc-client')); });
129
+ } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
130
+ /* webpackChunkName: "oidcclient" */
131
+ 'oidc-client')); });
122
132
  return new UserManager(config);
123
133
  } catch (e) {
124
134
  console.error('Exception in createUserManager: ', e);
@@ -133,6 +143,7 @@ class LoginHelper {
133
143
  this.cookies = void 0;
134
144
  this.cookies = cookies;
135
145
  }
146
+
136
147
  SetLoginCookies({
137
148
  contensisClassicToken,
138
149
  refreshToken
@@ -141,6 +152,7 @@ class LoginHelper {
141
152
  if (contensisClassicToken) this.cookies.SetCookie(CookieConstants.LOGIN_COOKIE, contensisClassicToken);
142
153
  if (refreshToken) this.cookies.SetCookie(CookieConstants.REFRESH_TOKEN_COOKIE, refreshToken);
143
154
  }
155
+
144
156
  GetCachedCredentials() {
145
157
  return {
146
158
  bearerToken: null,
@@ -150,22 +162,27 @@ class LoginHelper {
150
162
  contensisClassicToken: this.cookies.GetCookie(CookieConstants.LOGIN_COOKIE)
151
163
  };
152
164
  }
165
+
153
166
  ClearCachedCredentials() {
154
167
  this.cookies.DeleteCookie(CookieConstants.LOGIN_COOKIE);
155
168
  this.cookies.DeleteCookie(CookieConstants.REFRESH_TOKEN_COOKIE);
169
+
156
170
  if (LoginHelper.WSFED_LOGIN && typeof window !== 'undefined') {
157
171
  // remove any oidc keys left over in localStorage
158
172
  const {
159
173
  localStorage
160
174
  } = window;
161
175
  const keys = [];
176
+
162
177
  for (let i = 0; i < localStorage.length; i++) {
163
178
  const key = localStorage.key(i);
164
179
  if (typeof key === 'string' && key.startsWith('oidc.')) keys.push(localStorage.key(i));
165
180
  }
181
+
166
182
  keys.forEach(key => localStorage.removeItem(key));
167
183
  }
168
184
  }
185
+
169
186
  async LoginUser({
170
187
  username,
171
188
  password,
@@ -180,17 +197,16 @@ class LoginHelper {
180
197
  };
181
198
  let transientClient;
182
199
  let user;
200
+
183
201
  if (username && password) {
184
202
  // Get a management client with username and password
185
203
  transientClient = await getManagementApiClient({
186
204
  username,
187
205
  password
188
- });
206
+ }); // Ensure the client has requested a bearer token
189
207
 
190
- // Ensure the client has requested a bearer token
191
- const [loginError, clientBearerToken] = await to.to(transientClient.ensureBearerToken());
208
+ const [loginError, clientBearerToken] = await to.to(transientClient.ensureBearerToken()); // Problem getting token with username and password
192
209
 
193
- // Problem getting token with username and password
194
210
  if (loginError) {
195
211
  authenticationState = {
196
212
  clientCredentials: null,
@@ -200,9 +216,9 @@ class LoginHelper {
200
216
  isError: true
201
217
  };
202
218
  this.ClearCachedCredentials();
203
- }
219
+ } // Got a token using username and password
220
+
204
221
 
205
- // Got a token using username and password
206
222
  if (clientBearerToken) {
207
223
  // Set credentials so we can continue to GetUserDetails
208
224
  credentials = mapClientCredentials(transientClient);
@@ -214,14 +230,15 @@ class LoginHelper {
214
230
  isError: false
215
231
  };
216
232
  }
217
- }
218
-
219
- // If we have credentials supplied by a successful username and password login
233
+ } // If we have credentials supplied by a successful username and password login
220
234
  // or clientCredentials supplied in the options argument we can continue to
221
235
  // fetch the user's details
236
+
237
+
222
238
  if (credentials) {
223
239
  const client = transientClient || (await getManagementApiClient(credentials));
224
240
  const [error, userDetails] = await LoginHelper.GetUserDetails(client);
241
+
225
242
  if (error) {
226
243
  authenticationState = {
227
244
  clientCredentials: null,
@@ -244,22 +261,27 @@ class LoginHelper {
244
261
  };
245
262
  }
246
263
  }
264
+
247
265
  return {
248
266
  authenticationState,
249
267
  user
250
268
  };
251
269
  }
270
+
252
271
  LogoutUser(redirectPath) {
253
272
  this.ClearCachedCredentials();
273
+
254
274
  if (LoginHelper.WSFED_LOGIN) {
255
275
  LoginHelper.WsFedLogout(redirectPath);
256
276
  } else {
257
277
  if (redirectPath) LoginHelper.ClientRedirectToPath(redirectPath);else LoginHelper.ClientRedirectToSignInPage();
258
278
  }
259
279
  }
280
+
260
281
  static ClientRedirectToHome(location) {
261
282
  if (typeof window != 'undefined') {
262
283
  let url = '/';
284
+
263
285
  if (location) {
264
286
  const {
265
287
  search,
@@ -268,11 +290,14 @@ class LoginHelper {
268
290
  url = search ? `${url}${search}` : url;
269
291
  url = hash ? `${url}${hash}` : url;
270
292
  }
293
+
271
294
  window.location.href = url;
272
295
  }
273
296
  }
297
+
274
298
  static async ClientRedirectToSignInPage(redirectPath) {
275
299
  if (typeof location === 'undefined') return;
300
+
276
301
  if (LoginHelper.WSFED_LOGIN) {
277
302
  await LoginHelper.WsFedLogout();
278
303
  await LoginHelper.WsFedLogin();
@@ -283,19 +308,23 @@ class LoginHelper {
283
308
  if (typeof location !== 'undefined' && redirectPath !== LoginHelper.LOGIN_ROUTE) location.replace(url);
284
309
  }
285
310
  }
311
+
286
312
  static GetAccessDeniedRoute(originalPath) {
287
313
  let url = LoginHelper.ACCESS_DENIED_ROUTE;
288
314
  if (originalPath !== url && typeof originalPath === 'string') url = `${url}?original_uri=${originalPath}`;
289
315
  return url;
290
316
  }
317
+
291
318
  static ClientRedirectToAccessDeniedPage(originalPath) {
292
319
  if (typeof location !== 'undefined') location.href = LoginHelper.GetAccessDeniedRoute(originalPath);
293
320
  }
321
+
294
322
  static ClientRedirectToPath(redirectPath) {
295
323
  if (typeof redirectPath === 'string') {
296
324
  if (typeof location !== 'undefined') window.location.href = redirectPath;
297
325
  } else LoginHelper.ClientRedirectToHome();
298
326
  }
327
+
299
328
  static async WsFedLogin(redirectUri) {
300
329
  const userManager = await createUserManager(userManagerConfig);
301
330
  userManager.signinRedirect({
@@ -304,18 +333,22 @@ class LoginHelper {
304
333
  redirect_uri: redirectUri || window.location.toString()
305
334
  });
306
335
  }
336
+
307
337
  static RemoveSecurityTokenQuery() {
308
338
  const params = new URLSearchParams(window.location.search);
339
+
309
340
  if (params.has('securitytoken') || params.has('securityToken')) {
310
341
  params.delete('securitytoken');
311
342
  params.delete('securityToken');
312
343
  window.location = `${window.location.pathname}${params.toString() ? `?${params}` : ''}`;
313
344
  }
314
345
  }
346
+
315
347
  static async WsFedLogout(redirectPath) {
316
348
  await fetch(`${LoginHelper.CMS_URL}/authenticate/logout?jsonResponseRequired=true`, {
317
349
  credentials: 'include'
318
350
  });
351
+
319
352
  if (redirectPath) {
320
353
  window.location = redirectPath;
321
354
  } else {
@@ -324,6 +357,7 @@ class LoginHelper {
324
357
  LoginHelper.RemoveSecurityTokenQuery();
325
358
  }
326
359
  }
360
+
327
361
  static async GetCredentialsForSecurityToken(securityToken) {
328
362
  const [error, response] = await to.to(fetch(`${LoginHelper.CMS_URL}/REST/Contensis/Security/IsAuthenticated`, {
329
363
  method: 'POST',
@@ -338,6 +372,7 @@ class LoginHelper {
338
372
  if (error) return [{
339
373
  message: 'Failed to fetch credentials'
340
374
  }];
375
+
341
376
  if (response.ok) {
342
377
  const [parseError, body] = await to.to(response.json());
343
378
  if (parseError) return [parseError];
@@ -345,6 +380,7 @@ class LoginHelper {
345
380
  LogonResult,
346
381
  ApplicationData = []
347
382
  } = body;
383
+
348
384
  if (LogonResult !== 0) {
349
385
  console.info(`Security token is invalid - LogonResult: ${LogonResult}`);
350
386
  return [{
@@ -352,16 +388,19 @@ class LoginHelper {
352
388
  data: ApplicationData
353
389
  }];
354
390
  }
391
+
355
392
  if (ApplicationData.length > 0) {
356
393
  let refreshToken;
357
394
  ApplicationData.forEach(item => {
358
395
  if (item.Key === 'ContensisSecurityRefreshToken') refreshToken = item.Value;
359
396
  });
397
+
360
398
  if (!refreshToken) {
361
399
  return [{
362
400
  message: 'Fetch credentials: Unable to find ContensisSecurityRefreshToken'
363
401
  }];
364
402
  }
403
+
365
404
  return [undefined, refreshToken];
366
405
  } else {
367
406
  return [{
@@ -373,29 +412,35 @@ class LoginHelper {
373
412
  message: `Fetch credentials error: ${response.status} ${response.statusText}`
374
413
  }];
375
414
  }
376
- }
377
-
378
- // static isZengentiStaff(email) {
415
+ } // static isZengentiStaff(email) {
379
416
  // const emailRefs = ['@zengenti', '@contensis'];
380
-
381
417
  // return emailRefs.some(emailRef => {
382
418
  // if (email.includes(emailRef)) {
383
419
  // return true;
384
420
  // }
385
421
  // });
386
422
  // }
423
+
424
+
387
425
  }
388
- LoginHelper.CMS_URL = SERVERS.cms /* global SERVERS */;
389
- LoginHelper.WSFED_LOGIN = process.env.NODE_ENV === 'development' ? WSFED_LOGIN === 'true' /* global WSFED_LOGIN */ : context.WSFED_LOGIN === 'true';
426
+ LoginHelper.CMS_URL = SERVERS.cms
427
+ /* global SERVERS */
428
+ ;
429
+ LoginHelper.WSFED_LOGIN = process.env.NODE_ENV === 'development' ? WSFED_LOGIN === 'true'
430
+ /* global WSFED_LOGIN */
431
+ : context.WSFED_LOGIN === 'true';
390
432
  LoginHelper.LOGIN_ROUTE = '/account/login';
391
433
  LoginHelper.ACCESS_DENIED_ROUTE = '/account/access-denied';
434
+
392
435
  LoginHelper.withCookies = cookieHelper => new LoginHelper(cookieHelper);
436
+
393
437
  LoginHelper.GetUserDetails = async client => {
394
438
  let userError,
395
- groupsError,
396
- user = {},
397
- groupsResult;
439
+ groupsError,
440
+ user = {},
441
+ groupsResult;
398
442
  [userError, user] = await to.to(client.security.users.getCurrent());
443
+
399
444
  if (user && user.id) {
400
445
  [groupsError, groupsResult] = await to.to(client.security.users.getUserGroups({
401
446
  userId: user.id,
@@ -403,21 +448,22 @@ LoginHelper.GetUserDetails = async client => {
403
448
  pageOptions: {
404
449
  pageSize: 100
405
450
  }
406
- }));
407
- // Set groups attribute in user object to be the items
451
+ })); // Set groups attribute in user object to be the items
408
452
  // array from the getUserGroups result
409
- if (groupsResult && groupsResult.items) user.groups = groupsResult.items;
410
453
 
411
- //If groups call fails then log the error but allow the user to login still
454
+ if (groupsResult && groupsResult.items) user.groups = groupsResult.items; //If groups call fails then log the error but allow the user to login still
412
455
  // eslint-disable-next-line no-console
456
+
413
457
  if (groupsError) console.log(groupsError);
414
458
  }
459
+
415
460
  return [userError, user];
416
461
  };
417
462
 
418
463
  const loginSagas = [effects.takeEvery(reducers.LOGIN_USER, loginUserSaga), effects.takeEvery(reducers.LOGOUT_USER, logoutUserSaga), effects.takeEvery(reducers.VALIDATE_USER, validateUserSaga), effects.takeEvery(reducers.SET_AUTHENTICATION_STATE, redirectAfterSuccessfulLoginSaga)];
419
464
  function* handleRequiresLoginSaga(action) {
420
465
  var _entry$sys;
466
+
421
467
  const {
422
468
  cookies,
423
469
  entry,
@@ -428,43 +474,41 @@ function* handleRequiresLoginSaga(action) {
428
474
  },
429
475
  staticRoute
430
476
  } = action;
431
- let userLoggedIn = yield effects.select(ToJs.selectUserIsAuthenticated);
477
+ let userLoggedIn = yield effects.select(ToJs.selectUserIsAuthenticated); // Check for a securityToken in querystring
432
478
 
433
- // Check for a securityToken in querystring
434
479
  const currentQs = selectors.queryParams(yield effects.select(selectors.selectCurrentSearch));
435
- const securityToken = currentQs.securityToken || currentQs.securitytoken;
480
+ const securityToken = currentQs.securityToken || currentQs.securitytoken; // Check if any of the defined routes have "requireLogin" attribute
436
481
 
437
- // Check if any of the defined routes have "requireLogin" attribute
438
482
  const {
439
483
  requireLogin: authRoute
440
484
  } = staticRoute && staticRoute.route || {};
441
485
  const {
442
486
  requireLogin: authContentType
443
- } = entry && findContentTypeMapping(ContentTypeMappings, entry === null || entry === void 0 ? void 0 : (_entry$sys = entry.sys) === null || _entry$sys === void 0 ? void 0 : _entry$sys.contentTypeId) || {};
444
-
445
- // If requireLogin, authRoute or authContentType has been specified as an
487
+ } = entry && findContentTypeMapping(ContentTypeMappings, entry === null || entry === void 0 ? void 0 : (_entry$sys = entry.sys) === null || _entry$sys === void 0 ? void 0 : _entry$sys.contentTypeId) || {}; // If requireLogin, authRoute or authContentType has been specified as an
446
488
  // array of groups we can merge all the arrays and match on any group supplied
489
+
447
490
  const routeRequiresGroups = [...(Array.isArray(authContentType) && authContentType || []), ...(Array.isArray(authRoute) && authRoute || []), ...(Array.isArray(requireLogin) && requireLogin || [])];
448
491
  const routeRequiresLogin = !!authContentType || !!authRoute || !!requireLogin;
492
+
449
493
  if (!userLoggedIn) {
450
494
  // If cookies or securityToken are found on any route change
451
495
  // always validate and login the user
452
496
  if (routeRequiresLogin) {
453
- console.info(`Route requires login: ${path}`);
454
- // If routeRequiresLogin do a blocking call that returns userLoggedIn
497
+ console.info(`Route requires login: ${path}`); // If routeRequiresLogin do a blocking call that returns userLoggedIn
498
+
455
499
  userLoggedIn = yield effects.call(validateUserSaga, {
456
500
  cookies,
457
501
  securityToken
458
502
  });
459
503
  console.info(`User logged in: ${userLoggedIn}`);
460
- }
461
- // otherwise do a non blocking put to handle validation in the background
504
+ } // otherwise do a non blocking put to handle validation in the background
462
505
  else yield effects.put({
463
506
  type: reducers.VALIDATE_USER,
464
507
  cookies,
465
508
  securityToken
466
509
  });
467
510
  }
511
+
468
512
  if (routeRequiresLogin) {
469
513
  // If a security token is in the querystring and we are not already
470
514
  // logged in something is wrong and we won't bother going on another redirect loop
@@ -476,15 +520,18 @@ function* handleRequiresLoginSaga(action) {
476
520
  if (!groupMatch) LoginHelper.ClientRedirectToAccessDeniedPage(action.location.pathname);
477
521
  }
478
522
  }
523
+
479
524
  return userLoggedIn;
480
525
  }
526
+
481
527
  function* validateUserSaga({
482
528
  cookies,
483
529
  securityToken
484
530
  }) {
485
- const login = LoginHelper.withCookies(cookies);
486
- // Check for refreshToken in cookies
531
+ const login = LoginHelper.withCookies(cookies); // Check for refreshToken in cookies
532
+
487
533
  let clientCredentials = login.GetCachedCredentials();
534
+
488
535
  if (securityToken || clientCredentials.securityToken || clientCredentials.refreshToken) {
489
536
  // We only attempt to validate the user if one of the stored
490
537
  // tokens are found, in this case we set loading state manually
@@ -494,11 +541,12 @@ function* validateUserSaga({
494
541
  authenticationState: {
495
542
  isLoading: true
496
543
  }
497
- });
498
- // If we have just a security token we will call a CMS endpoint
544
+ }); // If we have just a security token we will call a CMS endpoint
499
545
  // and provide us with a RefreshToken cookie we can use during login
546
+
500
547
  if (securityToken || clientCredentials.securityToken && !clientCredentials.refreshToken) {
501
548
  const [error, refreshToken] = yield LoginHelper.GetCredentialsForSecurityToken(securityToken || clientCredentials.securityToken);
549
+
502
550
  if (refreshToken) {
503
551
  // Set cookies and reload values
504
552
  login.SetLoginCookies({
@@ -507,6 +555,7 @@ function* validateUserSaga({
507
555
  });
508
556
  clientCredentials = login.GetCachedCredentials();
509
557
  }
558
+
510
559
  if (error) {
511
560
  login.ClearCachedCredentials();
512
561
  yield effects.put({
@@ -517,9 +566,9 @@ function* validateUserSaga({
517
566
  }
518
567
  });
519
568
  }
520
- }
569
+ } // Log the user in if a refreshToken is found
570
+
521
571
 
522
- // Log the user in if a refreshToken is found
523
572
  if (clientCredentials.refreshToken) {
524
573
  console.info(`Login user with refreshToken ${clientCredentials.refreshToken}`);
525
574
  yield effects.call(loginUserSaga, {
@@ -527,11 +576,12 @@ function* validateUserSaga({
527
576
  cookies: login.cookies
528
577
  });
529
578
  }
530
- }
579
+ } // Tell any callers have we successfully logged in?
580
+
531
581
 
532
- // Tell any callers have we successfully logged in?
533
582
  return yield effects.select(ToJs.selectUserIsAuthenticated);
534
583
  }
584
+
535
585
  function* loginUserSaga(action = {}) {
536
586
  const {
537
587
  username,
@@ -539,10 +589,9 @@ function* loginUserSaga(action = {}) {
539
589
  clientCredentials,
540
590
  cookies
541
591
  } = action;
542
- const login = LoginHelper.withCookies(cookies);
543
-
544
- // If a WSFED_LOGIN site has dispatched the loginUser action
592
+ const login = LoginHelper.withCookies(cookies); // If a WSFED_LOGIN site has dispatched the loginUser action
545
593
  // just redirect them to the Identity Provider sign in
594
+
546
595
  if (action.type === reducers.LOGIN_USER && LoginHelper.WSFED_LOGIN) LoginHelper.ClientRedirectToSignInPage();
547
596
  const {
548
597
  authenticationState,
@@ -558,30 +607,33 @@ function* loginUserSaga(action = {}) {
558
607
  user
559
608
  });
560
609
  }
610
+
561
611
  const removeHostnamePart = path => {
562
612
  // eslint-disable-next-line no-console
563
613
  console.log(path);
564
- const relativePath = '/' + path.split('/').splice(3).join('/');
565
- // eslint-disable-next-line no-console
614
+ const relativePath = '/' + path.split('/').splice(3).join('/'); // eslint-disable-next-line no-console
615
+
566
616
  console.log(relativePath);
567
617
  return relativePath;
568
618
  };
619
+
569
620
  function* redirectAfterSuccessfulLoginSaga() {
570
621
  const isLoggedIn = yield effects.select(ToJs.selectUserIsAuthenticated);
571
622
  const {
572
623
  redirect_uri: redirectPath,
573
624
  ReturnURL: assetRedirectPath
574
625
  } = selectors.queryParams(yield effects.select(selectors.selectCurrentSearch));
626
+
575
627
  if (isLoggedIn && assetRedirectPath && typeof window != 'undefined') {
576
- const path = removeHostnamePart(assetRedirectPath);
577
- // This has to be a hard href to get the app to
628
+ const path = removeHostnamePart(assetRedirectPath); // This has to be a hard href to get the app to
578
629
  // leave React and hit the server for the IIS hosted assets
579
- window.location.href = path;
580
- // yield put(setRoute(path)); // does not work in this scenario
630
+
631
+ window.location.href = path; // yield put(setRoute(path)); // does not work in this scenario
581
632
  } else if (isLoggedIn && redirectPath) {
582
633
  yield effects.put(selectors.setRoute(redirectPath));
583
634
  }
584
635
  }
636
+
585
637
  function* logoutUserSaga({
586
638
  redirectPath,
587
639
  cookies
@@ -592,8 +644,10 @@ function* logoutUserSaga({
592
644
  });
593
645
  yield LoginHelper.withCookies(cookies).LogoutUser(redirectPath);
594
646
  }
647
+
595
648
  function* refreshSecurityToken() {
596
649
  const clientCredentials = yield effects.select(ToJs.selectClientCredentials, 'js');
650
+
597
651
  if (Object.keys(clientCredentials).length > 0) {
598
652
  const client = yield getManagementApiClient(clientCredentials);
599
653
  yield client.authenticate();
@@ -670,6 +724,7 @@ const LoginContainer = ({
670
724
  const userProps = useLogin();
671
725
  return children(userProps);
672
726
  };
727
+
673
728
  LoginContainer.propTypes = {};
674
729
  var Login_container = ToJs.toJS(LoginContainer);
675
730
 
@@ -692,6 +747,7 @@ const RegistrationContainer = ({
692
747
  const userProps = useRegistration();
693
748
  return children(userProps);
694
749
  };
750
+
695
751
  RegistrationContainer.propTypes = {};
696
752
  var Registration_container = ToJs.toJS(RegistrationContainer);
697
753
 
@@ -720,6 +776,7 @@ const ForgotPasswordContainer = ({
720
776
  const userProps = useForgotPassword();
721
777
  return children(userProps);
722
778
  };
779
+
723
780
  ForgotPasswordContainer.propTypes = {};
724
781
  var ForgotPassword_container = ToJs.toJS(ForgotPasswordContainer);
725
782
 
@@ -743,6 +800,7 @@ const ChangePasswordContainer = ({
743
800
  const userProps = useChangePassword();
744
801
  return children(userProps);
745
802
  };
803
+
746
804
  ChangePasswordContainer.propTypes = {};
747
805
  var ChangePassword_container = ToJs.toJS(ChangePasswordContainer);
748
806
 
@@ -764,4 +822,4 @@ exports.useChangePassword = useChangePassword;
764
822
  exports.useForgotPassword = useForgotPassword;
765
823
  exports.useLogin = useLogin;
766
824
  exports.useRegistration = useRegistration;
767
- //# sourceMappingURL=ChangePassword.container-a617190b.js.map
825
+ //# sourceMappingURL=ChangePassword.container-ae35785e.js.map