asab_webui_shell 26.1.2 → 26.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -82,21 +82,8 @@ class Application extends _react.Component {
82
82
  constructor(props) {
83
83
  super(props);
84
84
 
85
- // Global AppStore variables
86
- var appStore = {
87
- state: null,
88
- dispatch: null
89
- }; // Create the store object (fields stays writable so the provider can update them)
90
- Object.seal(appStore); // Lock the shape, so no adding/removing properties (but existing fields remain writable)
91
- Object.defineProperty(this, 'AppStore', {
92
- value: appStore,
93
- writable: false,
94
- // Can't reassign this.AppStore
95
- configurable: false,
96
- // Can't redefine/delete the property
97
- enumerable: true // Makes it show up in Object.keys/console
98
- }); // Define a read-only, non-configurable property on the instance
99
-
85
+ // Create App store with global AppStore variables
86
+ this.AppStore = (0, _asab_webui_components.createAppStore)();
100
87
  this.Modules = [];
101
88
  this.Services = {};
102
89
  this.ReduxService = new _ReduxService.default(this, "ReduxService");
@@ -599,7 +586,7 @@ class Application extends _react.Component {
599
586
  var _this$AppStore$dispat3, _this$AppStore3;
600
587
  if (enabled === 0) {
601
588
  var _state$advmode;
602
- var state = this.AppStore.state;
589
+ var state = this.AppStore.getState();
603
590
  enabled = !(state !== null && state !== void 0 && (_state$advmode = state.advmode) !== null && _state$advmode !== void 0 && _state$advmode.enabled);
604
591
  }
605
592
  (_this$AppStore$dispat3 = (_this$AppStore3 = this.AppStore).dispatch) === null || _this$AppStore$dispat3 === void 0 || _this$AppStore$dispat3.call(_this$AppStore3, {
@@ -619,7 +606,7 @@ class Application extends _react.Component {
619
606
  */
620
607
  setFullScreenMode(status) {
621
608
  var _state$fullscreenmode, _this$AppStore$dispat4, _this$AppStore4;
622
- var state = this.AppStore.state;
609
+ var state = this.AppStore.getState();
623
610
  if (status === 'on' && (state === null || state === void 0 || (_state$fullscreenmode = state.fullscreenmode) === null || _state$fullscreenmode === void 0 ? void 0 : _state$fullscreenmode.status) === 'on') {
624
611
  status = 'off';
625
612
  }
@@ -169,7 +169,7 @@ class AuthModule extends _asab_webui_components.Module {
169
169
  type: _actions.types.AUTH_RESOURCES,
170
170
  resources: resources
171
171
  });
172
- yield _this.validateNavigation({
172
+ _this.validateNavigation({
173
173
  resources
174
174
  });
175
175
  }
@@ -263,75 +263,57 @@ class AuthModule extends _asab_webui_components.Module {
263
263
  window.location.reload();
264
264
  });
265
265
  }
266
-
267
- // TODO: reconsider removing async/await with promise
268
266
  validateNavigation(_ref) {
269
- var _this3 = this;
270
- return (0, _asyncToGenerator2.default)(function* () {
271
- var _state$navigation, _this3$App$AppStore$d, _this3$App$AppStore;
272
- var {
273
- resources
274
- } = _ref;
275
- var state = _this3.App.AppStore.state;
276
- var navItems = (_state$navigation = state.navigation) === null || _state$navigation === void 0 ? void 0 : _state$navigation.navItems;
277
- var authorizedNavItems = [];
278
- navItems && (yield Promise.all(navItems.map(/*#__PURE__*/function () {
279
- var _ref2 = (0, _asyncToGenerator2.default)(function* (itm, idx) {
280
- if (resources.indexOf('authz:superuser') !== -1) {
281
- // If user is superuser, validate every navigation item
267
+ var _state$navigation, _this$App$AppStore$di, _this$App$AppStore;
268
+ var {
269
+ resources
270
+ } = _ref;
271
+ var state = this.App.AppStore.getState();
272
+ var navItems = (_state$navigation = state.navigation) === null || _state$navigation === void 0 ? void 0 : _state$navigation.navItems;
273
+ var authorizedNavItems = [];
274
+ navItems && navItems.map((itm, idx) => {
275
+ if (resources.indexOf('authz:superuser') !== -1) {
276
+ // If user is superuser, validate every navigation item
277
+ authorizedNavItems.push(itm);
278
+ } else {
279
+ if (itm.resource) {
280
+ if (itm.children) {
281
+ itm.children = this._validateChildrenNav(itm, resources);
282
+ }
283
+ // Item validation
284
+ var access_auth = this._validateItemNav(itm.resource, resources);
285
+ if (access_auth == true) {
282
286
  authorizedNavItems.push(itm);
283
- } else {
284
- if (itm.resource) {
285
- if (itm.children) {
286
- itm.children = yield _this3._validateChildrenNav(itm, resources);
287
- }
288
- // Item validation
289
- var access_auth = _this3._validateItemNav(itm.resource, resources);
290
- if (access_auth == true) {
291
- authorizedNavItems.push(itm);
292
- }
293
- } else {
294
- if (itm.children) {
295
- itm.children = yield _this3._validateChildrenNav(itm, resources);
296
- if (itm.children.length > 0) {
297
- authorizedNavItems.push(itm);
298
- }
299
- }
287
+ }
288
+ } else {
289
+ if (itm.children) {
290
+ itm.children = this._validateChildrenNav(itm, resources);
291
+ if (itm.children.length > 0) {
292
+ authorizedNavItems.push(itm);
300
293
  }
301
294
  }
302
- });
303
- return function (_x, _x2) {
304
- return _ref2.apply(this, arguments);
305
- };
306
- }())));
307
- (_this3$App$AppStore$d = (_this3$App$AppStore = _this3.App.AppStore).dispatch) === null || _this3$App$AppStore$d === void 0 || _this3$App$AppStore$d.call(_this3$App$AppStore, {
308
- type: _actions2.SET_NAVIGATION_ITEMS,
309
- navItems: authorizedNavItems
310
- });
311
- })();
295
+ }
296
+ }
297
+ });
298
+ (_this$App$AppStore$di = (_this$App$AppStore = this.App.AppStore).dispatch) === null || _this$App$AppStore$di === void 0 || _this$App$AppStore$di.call(_this$App$AppStore, {
299
+ type: _actions2.SET_NAVIGATION_ITEMS,
300
+ navItems: authorizedNavItems
301
+ });
312
302
  }
313
303
 
314
304
  // Validate sidebar's item children
315
305
  _validateChildrenNav(itm, resources) {
316
- var _this4 = this;
317
- return (0, _asyncToGenerator2.default)(function* () {
318
- // Item's children validation
319
- var authorizedNavChildren = [];
320
- yield Promise.all(itm.children.map(/*#__PURE__*/function () {
321
- var _ref3 = (0, _asyncToGenerator2.default)(function* (child, id) {
322
- if (child.resource) {
323
- var access_auth = _this4._validateItemNav(child.resource, resources);
324
- if (access_auth == true) {
325
- authorizedNavChildren.push(child);
326
- }
327
- }
328
- });
329
- return function (_x3, _x4) {
330
- return _ref3.apply(this, arguments);
331
- };
332
- }()));
333
- return authorizedNavChildren;
334
- })();
306
+ // Item's children validation
307
+ var authorizedNavChildren = [];
308
+ itm.children.map((child, id) => {
309
+ if (child.resource) {
310
+ var access_auth = this._validateItemNav(child.resource, resources);
311
+ if (access_auth == true) {
312
+ authorizedNavChildren.push(child);
313
+ }
314
+ }
315
+ });
316
+ return authorizedNavChildren;
335
317
  }
336
318
 
337
319
  // Validate sidebar items
@@ -361,38 +343,38 @@ class AuthModule extends _asab_webui_components.Module {
361
343
  return valid;
362
344
  }
363
345
  updateUserInfo() {
364
- var _this5 = this;
346
+ var _this3 = this;
365
347
  return (0, _asyncToGenerator2.default)(function* () {
366
348
  var _response$data;
367
349
  var response;
368
350
  try {
369
- response = yield _this5.Api.userinfo(_this5.OAuthTokens.access_token);
351
+ response = yield _this3.Api.userinfo(_this3.OAuthTokens.access_token);
370
352
  } catch (err) {
371
353
  console.error("Failed to update user info", err);
372
- _this5.UserInfo = null;
373
- if (_this5.App.AppStore) {
374
- var _this5$App$AppStore$d, _this5$App$AppStore;
375
- (_this5$App$AppStore$d = (_this5$App$AppStore = _this5.App.AppStore).dispatch) === null || _this5$App$AppStore$d === void 0 || _this5$App$AppStore$d.call(_this5$App$AppStore, {
354
+ _this3.UserInfo = null;
355
+ if (_this3.App.AppStore) {
356
+ var _this3$App$AppStore$d, _this3$App$AppStore;
357
+ (_this3$App$AppStore$d = (_this3$App$AppStore = _this3.App.AppStore).dispatch) === null || _this3$App$AppStore$d === void 0 || _this3$App$AppStore$d.call(_this3$App$AppStore, {
376
358
  type: _actions.types.AUTH_USERINFO,
377
- payload: _this5.UserInfo
359
+ payload: _this3.UserInfo
378
360
  });
379
361
  }
380
362
  return false;
381
363
  }
382
- _this5.UserInfo = response.data;
383
- _this5.SessionExpiration = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.exp;
384
- if (_this5.App.AppStore) {
385
- var _this5$App$AppStore$d2, _this5$App$AppStore2;
386
- (_this5$App$AppStore$d2 = (_this5$App$AppStore2 = _this5.App.AppStore).dispatch) === null || _this5$App$AppStore$d2 === void 0 || _this5$App$AppStore$d2.call(_this5$App$AppStore2, {
364
+ _this3.UserInfo = response.data;
365
+ _this3.SessionExpiration = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.exp;
366
+ if (_this3.App.AppStore) {
367
+ var _this3$App$AppStore$d2, _this3$App$AppStore2;
368
+ (_this3$App$AppStore$d2 = (_this3$App$AppStore2 = _this3.App.AppStore).dispatch) === null || _this3$App$AppStore$d2 === void 0 || _this3$App$AppStore$d2.call(_this3$App$AppStore2, {
387
369
  type: _actions.types.AUTH_USERINFO,
388
- payload: _this5.UserInfo
370
+ payload: _this3.UserInfo
389
371
  });
390
372
  }
391
373
 
392
374
  /** Check for TenantService and pass tenants list obtained from userinfo */
393
- var availableTenants = _this5.UserInfo.tenants;
394
- if (_this5.App.Services.TenantService) {
395
- yield _this5.App.Services.TenantService.setTenants(availableTenants, _this5._getAuthorizedTenant(_this5.UserInfo));
375
+ var availableTenants = _this3.UserInfo.tenants;
376
+ if (_this3.App.Services.TenantService) {
377
+ yield _this3.App.Services.TenantService.setTenants(availableTenants, _this3._getAuthorizedTenant(_this3.UserInfo));
396
378
  }
397
379
  return true;
398
380
  })();
@@ -400,11 +382,11 @@ class AuthModule extends _asab_webui_components.Module {
400
382
 
401
383
  // Method for obtaining and storing the OAuth tokens based on authorization code
402
384
  _exchangeCodeForTokens(authorization_code) {
403
- var _this6 = this;
385
+ var _this4 = this;
404
386
  return (0, _asyncToGenerator2.default)(function* () {
405
387
  try {
406
- var response = yield _this6.Api.token_authorization_code(authorization_code, _this6.RedirectURL);
407
- _this6.OAuthTokens = response.data;
388
+ var response = yield _this4.Api.token_authorization_code(authorization_code, _this4.RedirectURL);
389
+ _this4.OAuthTokens = response.data;
408
390
  sessionStorage.setItem('SeaCatOAuth2Tokens', JSON.stringify(response.data));
409
391
  return true;
410
392
  } catch (err) {
@@ -416,16 +398,16 @@ class AuthModule extends _asab_webui_components.Module {
416
398
 
417
399
  // Method for refreshing OAuth tokens
418
400
  _refreshTokens() {
419
- var _this7 = this;
401
+ var _this5 = this;
420
402
  return (0, _asyncToGenerator2.default)(function* () {
421
- var _this7$OAuthTokens;
403
+ var _this5$OAuthTokens;
422
404
  // If no refresh_token found, return false
423
- if (!((_this7$OAuthTokens = _this7.OAuthTokens) !== null && _this7$OAuthTokens !== void 0 && _this7$OAuthTokens.refresh_token)) {
405
+ if (!((_this5$OAuthTokens = _this5.OAuthTokens) !== null && _this5$OAuthTokens !== void 0 && _this5$OAuthTokens.refresh_token)) {
424
406
  return false;
425
407
  }
426
408
  try {
427
- var response = yield _this7.Api.token_refresh(_this7.OAuthTokens.refresh_token);
428
- _this7.OAuthTokens = response.data;
409
+ var response = yield _this5.Api.token_refresh(_this5.OAuthTokens.refresh_token);
410
+ _this5.OAuthTokens = response.data;
429
411
  sessionStorage.setItem('SeaCatOAuth2Tokens', JSON.stringify(response.data));
430
412
  return true;
431
413
  } catch (err) {
@@ -452,9 +434,9 @@ class AuthModule extends _asab_webui_components.Module {
452
434
 
453
435
  // Loop validating session expiration
454
436
  _startSessionExpirationValidation() {
455
- var _this8 = this;
437
+ var _this6 = this;
456
438
  return (0, _asyncToGenerator2.default)(function* () {
457
- if (!_this8.SessionExpiration) {
439
+ if (!_this6.SessionExpiration) {
458
440
  console.warn("Session expiration is not set.");
459
441
  return;
460
442
  }
@@ -463,7 +445,7 @@ class AuthModule extends _asab_webui_components.Module {
463
445
  var MAX_SESSION_DURATION = Math.pow(2, 31) - 1;
464
446
 
465
447
  // Proactivelly validate session expiration
466
- var lastKnownExpiration = _this8.SessionExpiration; // Last known session expiration
448
+ var lastKnownExpiration = _this6.SessionExpiration; // Last known session expiration
467
449
  var sessionStartTime = Date.now() / 1000; // Session start time
468
450
  var sessionDuration = lastKnownExpiration - sessionStartTime; // Session duration
469
451
  // Prevent glitches on very large time remaining values
@@ -476,9 +458,9 @@ class AuthModule extends _asab_webui_components.Module {
476
458
  var warningDisplayed = false; // Tracks if the "about to expire" warning has been shown
477
459
 
478
460
  var _validateSession = /*#__PURE__*/function () {
479
- var _ref4 = (0, _asyncToGenerator2.default)(function* () {
461
+ var _ref2 = (0, _asyncToGenerator2.default)(function* () {
480
462
  var currentTime = Date.now() / 1000; // Convert milliseconds to seconds
481
- var timeRemaining = _this8.SessionExpiration - currentTime; // Time difference for triggering "about to expire" warning
463
+ var timeRemaining = _this6.SessionExpiration - currentTime; // Time difference for triggering "about to expire" warning
482
464
  // Prevent glitches on very large time remaining values
483
465
  if (timeRemaining > MAX_SESSION_DURATION) {
484
466
  // Set timeout to maximum allowed value
@@ -488,13 +470,13 @@ class AuthModule extends _asab_webui_components.Module {
488
470
  // Validate session on half of the session expiration or if the remaining time is <= 5min
489
471
  if (!refreshSessionDone && (timeRemaining <= 300 || currentTime >= sessionMidpoint)) {
490
472
  refreshSessionDone = true;
491
- var tokensRefreshed = yield _this8._refreshTokens();
473
+ var tokensRefreshed = yield _this6._refreshTokens();
492
474
  // Recalculate if session expiration was extended
493
475
  if (tokensRefreshed) {
494
- yield _this8.updateUserInfo(); // Update userinfo
476
+ yield _this6.updateUserInfo(); // Update userinfo
495
477
  // If current session expiration differs from last known expiration, recalculate session variables
496
- if (_this8.SessionExpiration !== lastKnownExpiration) {
497
- lastKnownExpiration = _this8.SessionExpiration;
478
+ if (_this6.SessionExpiration !== lastKnownExpiration) {
479
+ lastKnownExpiration = _this6.SessionExpiration;
498
480
  sessionStartTime = currentTime;
499
481
  sessionDuration = lastKnownExpiration - sessionStartTime;
500
482
  // Prevent glitches on very large time remaining values
@@ -510,31 +492,31 @@ class AuthModule extends _asab_webui_components.Module {
510
492
 
511
493
  // If remaining time is between 1 and 60s, repetitivelly ask for userInfo and trigger "about to expire" warning
512
494
  if (timeRemaining <= 60 && timeRemaining > 0) {
513
- var _tokensRefreshed = yield _this8._refreshTokens(); // Returns true/false if token is refreshed/not refreshed
514
- yield _this8.updateUserInfo(); // Continue updating user info
495
+ var _tokensRefreshed = yield _this6._refreshTokens(); // Returns true/false if token is refreshed/not refreshed
496
+ yield _this6.updateUserInfo(); // Continue updating user info
515
497
  if (!_tokensRefreshed && !warningDisplayed) {
516
- _this8.App.addAlert("info", "General|Your session will expire soon", 30, true);
498
+ _this6.App.addAlert("info", "General|Your session will expire soon", 30, true);
517
499
  warningDisplayed = true; // Mark the warning as displayed
518
500
  }
519
501
  }
520
502
 
521
503
  // Validation on expired session
522
- if (_this8.SessionExpiration <= currentTime) {
504
+ if (_this6.SessionExpiration <= currentTime) {
523
505
  // Handle refresh token prior updating user info
524
- yield _this8._refreshTokens();
506
+ yield _this6._refreshTokens();
525
507
  // Handle session expiration
526
- var isUserInfoUpdated = yield _this8.updateUserInfo();
508
+ var isUserInfoUpdated = yield _this6.updateUserInfo();
527
509
  if (!isUserInfoUpdated) {
528
510
  // Stop further checks
529
- clearTimeout(_this8.sessionValidationInterval);
530
- _this8.sessionValidationInterval = null;
531
- _this8.App.addAlert("info", "ASABAuthModule|Your session has expired.", 3600 * 1000, true, alert => /*#__PURE__*/_react.default.createElement(_SessionExpirationAlert.SessionExpirationAlert, {
511
+ clearTimeout(_this6.sessionValidationInterval);
512
+ _this6.sessionValidationInterval = null;
513
+ _this6.App.addAlert("info", "ASABAuthModule|Your session has expired.", 3600 * 1000, true, alert => /*#__PURE__*/_react.default.createElement(_SessionExpirationAlert.SessionExpirationAlert, {
532
514
  alert: alert
533
515
  }));
534
516
  // Disable UI elements
535
- if (_this8.App.AppStore) {
536
- var _this8$App$AppStore$d, _this8$App$AppStore;
537
- (_this8$App$AppStore$d = (_this8$App$AppStore = _this8.App.AppStore).dispatch) === null || _this8$App$AppStore$d === void 0 || _this8$App$AppStore$d.call(_this8$App$AppStore, {
517
+ if (_this6.App.AppStore) {
518
+ var _this6$App$AppStore$d, _this6$App$AppStore;
519
+ (_this6$App$AppStore$d = (_this6$App$AppStore = _this6.App.AppStore).dispatch) === null || _this6$App$AppStore$d === void 0 || _this6$App$AppStore$d.call(_this6$App$AppStore, {
538
520
  type: _actions.types.AUTH_SESSION_EXPIRATION,
539
521
  sessionExpired: true
540
522
  });
@@ -555,10 +537,10 @@ class AuthModule extends _asab_webui_components.Module {
555
537
  }
556
538
 
557
539
  // Re-trigger validation after 10 seconds
558
- _this8.sessionValidationInterval = setTimeout(_validateSession, 10000);
540
+ _this6.sessionValidationInterval = setTimeout(_validateSession, 10000);
559
541
  });
560
542
  return function validateSession() {
561
- return _ref4.apply(this, arguments);
543
+ return _ref2.apply(this, arguments);
562
544
  };
563
545
  }();
564
546
 
@@ -126,7 +126,7 @@ class TenantService extends _asab_webui_components.Service {
126
126
  // getCurrentTenant() method is used for obtaining current tenant
127
127
  getCurrentTenant() {
128
128
  var _this$App, _state$tenant;
129
- var state = (_this$App = this.App) === null || _this$App === void 0 || (_this$App = _this$App.AppStore) === null || _this$App === void 0 ? void 0 : _this$App.state;
129
+ var state = (_this$App = this.App) === null || _this$App === void 0 || (_this$App = _this$App.AppStore) === null || _this$App === void 0 ? void 0 : _this$App.getState();
130
130
  var currentTenant = state === null || state === void 0 || (_state$tenant = state.tenant) === null || _state$tenant === void 0 ? void 0 : _state$tenant.current;
131
131
  // If current tenant is not in Application store yet, get it from the URL params
132
132
  if (!currentTenant) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_shell",
3
- "version": "26.1.2",
3
+ "version": "26.1.3",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Shell Application",
6
6
  "contributors": [