asab_webui_shell 25.1.11 → 25.1.13

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 (66) hide show
  1. package/dist/components/locationReplace.js +4 -16
  2. package/dist/config/ConfigReducer.js +1 -1
  3. package/dist/config/ConfigService.js +116 -137
  4. package/dist/containers/AdvancedMode/reducer.js +2 -2
  5. package/dist/containers/Alerts/index.js +18 -30
  6. package/dist/containers/Alerts/reducer.js +5 -6
  7. package/dist/containers/Application.js +531 -663
  8. package/dist/containers/AttentionRequired/reducer.js +2 -2
  9. package/dist/containers/FullscreenMode/reducer.js +2 -2
  10. package/dist/containers/Header/ApplicationScreenTitle/ApplicationScreenTitle.js +15 -16
  11. package/dist/containers/Header/ApplicationScreenTitle/index.js +6 -6
  12. package/dist/containers/Header/Help/HelpButton.js +17 -27
  13. package/dist/containers/Header/Help/HelpService.js +13 -24
  14. package/dist/containers/Header/Preview/PreviewFlag.js +6 -5
  15. package/dist/containers/Header/Preview/PreviewService.js +13 -24
  16. package/dist/containers/Header/index.js +15 -17
  17. package/dist/containers/Header/reducer.js +4 -4
  18. package/dist/containers/Navigation/index.js +35 -55
  19. package/dist/containers/Navigation/reducer.js +7 -13
  20. package/dist/containers/RouteErrorHandler/ErrorContainer.js +17 -19
  21. package/dist/containers/RouteErrorHandler/index.js +28 -44
  22. package/dist/containers/Router/ApplicationRouter.js +14 -16
  23. package/dist/containers/Router/index.js +26 -42
  24. package/dist/containers/Router/reducer.js +3 -3
  25. package/dist/containers/Sidebar/NavbarBrand.js +14 -23
  26. package/dist/containers/Sidebar/SidebarBottomItem.js +16 -15
  27. package/dist/containers/Sidebar/SidebarIcon.js +9 -7
  28. package/dist/containers/Sidebar/SidebarItem.js +70 -85
  29. package/dist/containers/Sidebar/SidebarItemRenderer.js +20 -20
  30. package/dist/containers/Sidebar/index.js +20 -36
  31. package/dist/containers/Sidebar/reducer.js +3 -3
  32. package/dist/containers/Sidepanel/Sidepanel.js +18 -26
  33. package/dist/containers/Toast/ToastComponent.js +12 -12
  34. package/dist/containers/Toast/ToastContainer.js +19 -30
  35. package/dist/containers/Toast/reducer.js +3 -6
  36. package/dist/index.js +5 -5
  37. package/dist/modules/about/AboutScreen.js +30 -38
  38. package/dist/modules/about/index.js +8 -26
  39. package/dist/modules/auth/api.js +110 -156
  40. package/dist/modules/auth/components/SessionExpirationAlert.js +10 -9
  41. package/dist/modules/auth/header.js +25 -23
  42. package/dist/modules/auth/index.js +440 -692
  43. package/dist/modules/auth/reducer.js +2 -2
  44. package/dist/modules/auth/screens/AccessControlScreen.js +24 -25
  45. package/dist/modules/auth/screens/InvitationScreen.js +89 -128
  46. package/dist/modules/i18n/dropdown.js +24 -23
  47. package/dist/modules/i18n/index.js +20 -33
  48. package/dist/modules/i18n/reducer.js +2 -2
  49. package/dist/modules/i18n/service.js +48 -102
  50. package/dist/modules/tenant/TenantDropdown.js +28 -27
  51. package/dist/modules/tenant/access/AccessDeniedCard.js +28 -54
  52. package/dist/modules/tenant/index.js +16 -29
  53. package/dist/modules/tenant/reducer.js +1 -1
  54. package/dist/modules/tenant/service.js +123 -207
  55. package/dist/screens/InvalidRouteScreen.js +10 -9
  56. package/dist/screens/SuspenseScreen.js +11 -20
  57. package/dist/screens/UnauthorizedAccessScreen.js +18 -21
  58. package/dist/services/AttentionRequiredService.js +117 -142
  59. package/dist/services/BrandingService.js +63 -80
  60. package/dist/services/HeaderService.js +47 -66
  61. package/dist/services/ReduxService.js +11 -17
  62. package/dist/services/TitleService.js +13 -24
  63. package/dist/theme/ThemeButton.js +13 -10
  64. package/dist/theme/ThemeReducer.js +1 -1
  65. package/dist/theme/ThemeService.js +25 -38
  66. package/package.json +1 -1
@@ -4,16 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports["default"] = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
7
+ exports.default = void 0;
11
8
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
9
  var _react = _interopRequireWildcard(require("react"));
18
10
  var _asab_webui_components = require("asab_webui_components");
19
11
  var _header = require("./header");
@@ -23,36 +15,23 @@ var _actions2 = require("../../actions");
23
15
  var _api = require("./api");
24
16
  var _locationReplace = require("../../components/locationReplace");
25
17
  var _SessionExpirationAlert = require("./components/SessionExpirationAlert");
26
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
27
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
28
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
29
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != (0, _typeof2["default"])(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } // TODO: Use SessionExpirationAlert only after proper fix of the component
30
- var AccessControlScreen = /*#__PURE__*/(0, _react.lazy)(function () {
31
- return Promise.resolve().then(function () {
32
- return _interopRequireWildcard(require("./screens/AccessControlScreen"));
33
- });
34
- });
35
- var InvitationScreen = /*#__PURE__*/(0, _react.lazy)(function () {
36
- return Promise.resolve().then(function () {
37
- return _interopRequireWildcard(require("./screens/InvitationScreen"));
38
- });
39
- });
40
- var AuthModule = exports["default"] = /*#__PURE__*/function (_Module) {
41
- function AuthModule(app, name) {
42
- var _this;
43
- (0, _classCallCheck2["default"])(this, AuthModule);
44
- _this = _callSuper(this, AuthModule, [app, "AuthModule"]);
45
- _this.OAuthToken = JSON.parse(sessionStorage.getItem('SeaCatOAuth2Token'));
46
- _this.UserInfo = null;
47
- _this.Api = new _api.SeaCatAuthApi(app);
48
- _this.RedirectURL = window.location.href;
49
- _this.MustAuthenticate = true; // Setting this to false means, that we can operate without authenticated user
50
- app.ReduxService.addReducer("auth", _reducer["default"]);
51
- _this.App.addSplashScreenRequestor(_this);
52
- _this.Authorization = _this.App.Config.get("authorization"); // Get authorization settings from configuration
18
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } // TODO: Use SessionExpirationAlert only after proper fix of the component
19
+ var AccessControlScreen = /*#__PURE__*/(0, _react.lazy)(() => Promise.resolve().then(() => _interopRequireWildcard(require("./screens/AccessControlScreen"))));
20
+ var InvitationScreen = /*#__PURE__*/(0, _react.lazy)(() => Promise.resolve().then(() => _interopRequireWildcard(require("./screens/InvitationScreen"))));
21
+ class AuthModule extends _asab_webui_components.Module {
22
+ constructor(app, name) {
23
+ super(app, "AuthModule");
24
+ this.OAuthToken = JSON.parse(sessionStorage.getItem('SeaCatOAuth2Token'));
25
+ this.UserInfo = null;
26
+ this.Api = new _api.SeaCatAuthApi(app);
27
+ this.RedirectURL = window.location.href;
28
+ this.MustAuthenticate = true; // Setting this to false means, that we can operate without authenticated user
29
+ app.ReduxService.addReducer("auth", _reducer.default);
30
+ this.App.addSplashScreenRequestor(this);
31
+ this.Authorization = this.App.Config.get("authorization"); // Get authorization settings from configuration
53
32
 
54
- _this.SessionExpiration = null; // Session expiration as defined in user info
55
- _this.sessionValidationInterval = null; // Initialize session validation interval
33
+ this.SessionExpiration = null; // Session expiration as defined in user info
34
+ this.sessionValidationInterval = null; // Initialize session validation interval
56
35
 
57
36
  // Access control screen
58
37
  app.Router.addRoute({
@@ -71,691 +50,460 @@ var AuthModule = exports["default"] = /*#__PURE__*/function (_Module) {
71
50
  component: InvitationScreen,
72
51
  resource: "seacat:tenant:assign"
73
52
  });
74
- return _this;
75
53
  }
76
- (0, _inherits2["default"])(AuthModule, _Module);
77
- return (0, _createClass2["default"])(AuthModule, [{
78
- key: "initialize",
79
- value: function () {
80
- var _initialize = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
81
- var headerService, qs, authorization_code, errorType, stateIndex, state, reloadUrl, result, force_login_prompt, tenantAuthorized, _force_login_prompt, currentTenant, resources, _force_login_prompt2, _force_login_prompt3;
82
- return _regenerator["default"].wrap(function _callee$(_context) {
83
- while (1) switch (_context.prev = _context.next) {
84
- case 0:
85
- headerService = this.App.locateService("HeaderService");
86
- headerService.addComponent({
87
- component: _header.AuthHeaderInvitation,
88
- componentProps: {
89
- AuthModule: this
90
- },
91
- order: 200
92
- });
93
- headerService.addComponent({
94
- component: _header.AuthHeaderDropdown,
95
- componentProps: {
96
- AuthModule: this
97
- },
98
- order: 700
99
- });
100
- if (!(typeof MOCK_USERINFO !== 'undefined')) {
101
- _context.next = 8;
102
- break;
103
- }
104
- _context.next = 6;
105
- return this.simulateUserinfo(MOCK_USERINFO);
106
- case 6:
107
- _context.next = 63;
108
- break;
109
- case 8:
110
- // Check the query string for 'code'
111
- qs = new URLSearchParams(window.location.search);
112
- authorization_code = qs.get('code'); // Checking error type in params
113
- errorType = qs.get('error');
114
- if (!(errorType != undefined && errorType != 'tenant_access_denied')) {
115
- _context.next = 13;
116
- break;
117
- }
118
- return _context.abrupt("return");
119
- case 13:
120
- if (!(authorization_code !== null)) {
121
- _context.next = 25;
122
- break;
123
- }
124
- _context.next = 16;
125
- return this._updateToken(authorization_code);
126
- case 16:
127
- // Remove 'code' from a query string
128
- qs["delete"]('code');
129
- stateIndex = qs.get("state");
130
- state = ""; // Check if stateIndex is present, eventually return empty state string
131
- if (stateIndex != undefined) {
132
- // Check if oauth2_state_ is present, eventually return empty string
133
- if (localStorage.getItem("oauth2_state_".concat(stateIndex)) != undefined) {
134
- state = localStorage.getItem("oauth2_state_".concat(stateIndex));
135
- }
136
- }
137
- localStorage.removeItem("oauth2_state_".concat(stateIndex));
54
+ initialize() {
55
+ var _this = this;
56
+ return (0, _asyncToGenerator2.default)(function* () {
57
+ var headerService = _this.App.locateService("HeaderService");
58
+ headerService.addComponent({
59
+ component: _header.AuthHeaderInvitation,
60
+ componentProps: {
61
+ AuthModule: _this
62
+ },
63
+ order: 200
64
+ });
65
+ headerService.addComponent({
66
+ component: _header.AuthHeaderDropdown,
67
+ componentProps: {
68
+ AuthModule: _this
69
+ },
70
+ order: 700
71
+ });
72
+ if (typeof MOCK_USERINFO !== 'undefined') {
73
+ /* This section is only for DEV purposes! */
74
+ yield _this.simulateUserinfo(MOCK_USERINFO);
75
+ /* End of DEV section */
76
+ } else {
77
+ // Check the query string for 'code'
78
+ var qs = new URLSearchParams(window.location.search);
79
+ var authorization_code = qs.get('code');
138
80
 
139
- // Remove 'state' from a query string
140
- qs["delete"]("state");
81
+ // Checking error type in params
82
+ var errorType = qs.get('error');
83
+ if (errorType != undefined && errorType != 'tenant_access_denied') {
84
+ /*
85
+ If error appears in the URL search params and is NOT
86
+ tenant_access_denied, user will stay in splashscreen
87
+ with Access denied card
88
+ */
89
+ return;
90
+ }
91
+ if (authorization_code !== null) {
92
+ yield _this._updateToken(authorization_code);
93
+ // Remove 'code' from a query string
94
+ qs.delete('code');
95
+ var stateIndex = qs.get("state");
96
+ var state = "";
97
+ // Check if stateIndex is present, eventually return empty state string
98
+ if (stateIndex != undefined) {
99
+ // Check if oauth2_state_ is present, eventually return empty string
100
+ if (localStorage.getItem("oauth2_state_".concat(stateIndex)) != undefined) {
101
+ state = localStorage.getItem("oauth2_state_".concat(stateIndex));
102
+ }
103
+ }
104
+ localStorage.removeItem("oauth2_state_".concat(stateIndex));
141
105
 
142
- // Construct the new URL without `code` in the query string
143
- // For this case, condition on empty qs string is sufficient and tested
106
+ // Remove 'state' from a query string
107
+ qs.delete("state");
144
108
 
145
- if (qs.toString() == '') {
146
- // Remove `?` part from URL completely, if empty
147
- reloadUrl = window.location.pathname + state; // part form localstorage instead of hash
148
- } else {
149
- reloadUrl = window.location.pathname + '?' + qs.toString() + state; // part form localstorage instead of hash
150
- }
109
+ // Construct the new URL without `code` in the query string
110
+ // For this case, condition on empty qs string is sufficient and tested
111
+ var reloadUrl;
112
+ if (qs.toString() == '') {
113
+ // Remove `?` part from URL completely, if empty
114
+ reloadUrl = window.location.pathname + state; // part form localstorage instead of hash
115
+ } else {
116
+ reloadUrl = window.location.pathname + '?' + qs.toString() + state; // part form localstorage instead of hash
117
+ }
151
118
 
152
- // Reload the app with `code` removed
153
- _context.next = 25;
154
- return (0, _locationReplace.locationReplace)(reloadUrl);
155
- case 25:
156
- if (!(this.OAuthToken != null)) {
157
- _context.next = 58;
158
- break;
159
- }
160
- _context.next = 28;
161
- return this.updateUserInfo();
162
- case 28:
163
- result = _context.sent;
164
- if (result) {
165
- _context.next = 35;
166
- break;
167
- }
168
- // User info not found - go to login
169
- sessionStorage.removeItem('SeaCatOAuth2Token');
170
- force_login_prompt = true;
171
- _context.next = 34;
172
- return this.Api.login(this.RedirectURL, force_login_prompt);
173
- case 34:
174
- return _context.abrupt("return");
175
- case 35:
176
- // Add interceptor with Bearer token in the Header into axios calls
177
- this.App.addAxiosInterceptor(this.authInterceptor());
178
- // Add webSocket interceptor with Bearer token into websocket calls
179
- this.App.addWebSocketInterceptor(this.webSocketAuthInterceptor());
119
+ // Reload the app with `code` removed
120
+ yield (0, _locationReplace.locationReplace)(reloadUrl);
121
+ }
180
122
 
181
- // Authorization of the user based on tenant access
182
- if (!(this.App.Config.get("authorization") !== "disabled" && this.App.Services.TenantService)) {
183
- _context.next = 44;
184
- break;
185
- }
186
- // Tenant access validation
187
- tenantAuthorized = this.validateTenant();
188
- if (tenantAuthorized) {
189
- _context.next = 44;
190
- break;
191
- }
123
+ // Do we have an oauth token (we are authorized to use the app)
124
+ if (_this.OAuthToken != null) {
125
+ // Update the user info
126
+ var result = yield _this.updateUserInfo();
127
+ if (!result) {
128
+ // User info not found - go to login
129
+ sessionStorage.removeItem('SeaCatOAuth2Token');
130
+ var force_login_prompt = true;
131
+ yield _this.Api.login(_this.RedirectURL, force_login_prompt);
132
+ return;
133
+ }
134
+
135
+ // Add interceptor with Bearer token in the Header into axios calls
136
+ _this.App.addAxiosInterceptor(_this.authInterceptor());
137
+ // Add webSocket interceptor with Bearer token into websocket calls
138
+ _this.App.addWebSocketInterceptor(_this.webSocketAuthInterceptor());
139
+
140
+ // Authorization of the user based on tenant access
141
+ if (_this.App.Config.get("authorization") !== "disabled" && _this.App.Services.TenantService) {
142
+ // Tenant access validation
143
+ var tenantAuthorized = _this.validateTenant();
144
+ if (!tenantAuthorized) {
192
145
  // If tenant not authorized, redirect to Access denied card
193
- _force_login_prompt = false;
194
- _context.next = 43;
195
- return this.Api.login(this.RedirectURL, _force_login_prompt);
196
- case 43:
197
- return _context.abrupt("return");
198
- case 44:
199
- if (!(this.App.Store && this.App.Services.TenantService && this.UserInfo !== null)) {
200
- _context.next = 55;
201
- break;
202
- }
203
- currentTenant = this.App.Services.TenantService.getCurrentTenant();
204
- resources = this.UserInfo.resources ? this.UserInfo.resources[currentTenant] : [];
205
- /*
206
- When switching between tenants,
207
- we need to force authorization to obtain
208
- correct data (resources) for particular
209
- tenant (this is unavailable until auth token is updated)
210
- */
211
- if (!(resources == undefined)) {
212
- _context.next = 52;
213
- break;
214
- }
215
- _force_login_prompt2 = false;
216
- _context.next = 51;
217
- return this.Api.login(this.RedirectURL, _force_login_prompt2);
218
- case 51:
219
- return _context.abrupt("return");
220
- case 52:
221
- if (this.App.Store != null) {
222
- this.App.Store.dispatch({
223
- type: _actions.types.AUTH_RESOURCES,
224
- resources: resources
225
- });
226
- }
227
- _context.next = 55;
228
- return this.validateNavigation();
229
- case 55:
230
- if (!(this.UserInfo != null)) {
231
- _context.next = 58;
232
- break;
233
- }
234
- _context.next = 58;
235
- return this._startSessionExpirationValidation();
236
- case 58:
237
- if (!(this.UserInfo == null && this.MustAuthenticate)) {
238
- _context.next = 63;
239
- break;
240
- }
241
- // TODO: force_login_prompt = true to break authentication failure loop
242
- _force_login_prompt3 = false;
243
- _context.next = 62;
244
- return this.Api.login(this.RedirectURL, _force_login_prompt3);
245
- case 62:
246
- return _context.abrupt("return");
247
- case 63:
248
- this.App.removeSplashScreenRequestor(this);
249
- case 64:
250
- case "end":
251
- return _context.stop();
146
+ var _force_login_prompt = false;
147
+ yield _this.Api.login(_this.RedirectURL, _force_login_prompt);
148
+ return;
149
+ }
252
150
  }
253
- }, _callee, this);
254
- }));
255
- function initialize() {
256
- return _initialize.apply(this, arguments);
257
- }
258
- return initialize;
259
- }()
260
- }, {
261
- key: "authInterceptor",
262
- value: function authInterceptor() {
263
- var _this2 = this;
264
- var interceptor = function interceptor(config) {
265
- config.headers['Authorization'] = 'Bearer ' + _this2.OAuthToken['access_token'];
266
- return config;
267
- };
268
- return interceptor;
269
- }
270
- }, {
271
- key: "webSocketAuthInterceptor",
272
- value: function webSocketAuthInterceptor() {
273
- return "access_token_".concat(this.OAuthToken['access_token']);
274
- }
275
- }, {
276
- key: "simulateUserinfo",
277
- value: function () {
278
- var _simulateUserinfo = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(mock_userinfo) {
279
- var mockParams, availableTenants;
280
- return _regenerator["default"].wrap(function _callee2$(_context2) {
281
- while (1) switch (_context2.prev = _context2.next) {
282
- case 0:
283
- /*
284
- This method takes parameters from wepack.dev.js settings
285
- plugins: [
286
- ...
287
- new webpack.DefinePlugin({
288
- 'MOCK_USERINFO': JSON.stringify({ // Inject mocked UserInfo object, this means the application will NOT require user authorization
289
- "username": "johndev",
290
- "email": "dev@dev.de",
291
- "phone": "123456789",
292
- "resources": ["authz:superuser"],
293
- "roles": ["default/Admin"],
294
- "sub": "devdb:dev:1abc2def3456",
295
- "tenants": ["default"]
296
- })
297
- }),
298
- ...
299
- ],
300
- */
301
- this.App.addAlert("warning", "ASABAuthModule|You are using MOCK_USERINFO!", 1, true);
302
- mockParams = mock_userinfo;
303
- if (mockParams.resources) {
304
- mockParams["resources"] = Object.values(mockParams.resources);
305
- }
306
- if (mockParams.roles) {
307
- mockParams["roles"] = Object.values(mockParams.roles);
308
- }
309
- if (mockParams.tenants) {
310
- mockParams["tenants"] = Object.values(mockParams.tenants);
311
- }
312
- if (this.App.Store != null) {
313
- this.App.Store.dispatch({
314
- type: _actions.types.AUTH_USERINFO,
315
- payload: mockParams
316
- });
317
- this.App.Store.dispatch({
318
- type: _actions.types.AUTH_RESOURCES,
319
- resources: mockParams["resources"]
320
- });
321
- }
322
151
 
323
- /** Check for TenantService and pass tenants list obtained from userinfo */
324
- availableTenants = mockParams.tenants;
325
- if (!this.App.Services.TenantService) {
326
- _context2.next = 10;
327
- break;
328
- }
329
- _context2.next = 10;
330
- return this.App.Services.TenantService.setTenants(availableTenants, this._getAuthorizedTenant(mockParams));
331
- case 10:
332
- case "end":
333
- return _context2.stop();
152
+ // Validate resources of items and children in navigation (resource validation depends on tenant)
153
+ if (_this.App.Store && _this.App.Services.TenantService && _this.UserInfo !== null) {
154
+ var currentTenant = _this.App.Services.TenantService.getCurrentTenant();
155
+ var resources = _this.UserInfo.resources ? _this.UserInfo.resources[currentTenant] : [];
156
+ /*
157
+ When switching between tenants,
158
+ we need to force authorization to obtain
159
+ correct data (resources) for particular
160
+ tenant (this is unavailable until auth token is updated)
161
+ */
162
+ if (resources == undefined) {
163
+ var _force_login_prompt2 = false;
164
+ yield _this.Api.login(_this.RedirectURL, _force_login_prompt2);
165
+ return;
166
+ }
167
+ if (_this.App.Store != null) {
168
+ _this.App.Store.dispatch({
169
+ type: _actions.types.AUTH_RESOURCES,
170
+ resources: resources
171
+ });
172
+ }
173
+ yield _this.validateNavigation();
174
+ }
175
+ if (_this.UserInfo != null) {
176
+ yield _this._startSessionExpirationValidation(); // Start session validation
334
177
  }
335
- }, _callee2, this);
336
- }));
337
- function simulateUserinfo(_x) {
338
- return _simulateUserinfo.apply(this, arguments);
178
+ }
179
+ if (_this.UserInfo == null && _this.MustAuthenticate) {
180
+ // TODO: force_login_prompt = true to break authentication failure loop
181
+ var _force_login_prompt3 = false;
182
+ yield _this.Api.login(_this.RedirectURL, _force_login_prompt3);
183
+ return;
184
+ }
185
+ }
186
+ _this.App.removeSplashScreenRequestor(_this);
187
+ })();
188
+ }
189
+ authInterceptor() {
190
+ var interceptor = config => {
191
+ config.headers['Authorization'] = 'Bearer ' + this.OAuthToken['access_token'];
192
+ return config;
193
+ };
194
+ return interceptor;
195
+ }
196
+ webSocketAuthInterceptor() {
197
+ return "access_token_".concat(this.OAuthToken['access_token']);
198
+ }
199
+ simulateUserinfo(mock_userinfo) {
200
+ var _this2 = this;
201
+ return (0, _asyncToGenerator2.default)(function* () {
202
+ /*
203
+ This method takes parameters from wepack.dev.js settings
204
+ plugins: [
205
+ ...
206
+ new webpack.DefinePlugin({
207
+ 'MOCK_USERINFO': JSON.stringify({ // Inject mocked UserInfo object, this means the application will NOT require user authorization
208
+ "username": "johndev",
209
+ "email": "dev@dev.de",
210
+ "phone": "123456789",
211
+ "resources": ["authz:superuser"],
212
+ "roles": ["default/Admin"],
213
+ "sub": "devdb:dev:1abc2def3456",
214
+ "tenants": ["default"]
215
+ })
216
+ }),
217
+ ...
218
+ ],
219
+ */
220
+ _this2.App.addAlert("warning", "ASABAuthModule|You are using MOCK_USERINFO!", 1, true);
221
+ var mockParams = mock_userinfo;
222
+ if (mockParams.resources) {
223
+ mockParams["resources"] = Object.values(mockParams.resources);
224
+ }
225
+ if (mockParams.roles) {
226
+ mockParams["roles"] = Object.values(mockParams.roles);
227
+ }
228
+ if (mockParams.tenants) {
229
+ mockParams["tenants"] = Object.values(mockParams.tenants);
230
+ }
231
+ if (_this2.App.Store != null) {
232
+ _this2.App.Store.dispatch({
233
+ type: _actions.types.AUTH_USERINFO,
234
+ payload: mockParams
235
+ });
236
+ _this2.App.Store.dispatch({
237
+ type: _actions.types.AUTH_RESOURCES,
238
+ resources: mockParams["resources"]
239
+ });
339
240
  }
340
- return simulateUserinfo;
341
- }()
342
- }, {
343
- key: "logout",
344
- value: function logout() {
345
- this.App.addSplashScreenRequestor(this);
346
- this._stopSessionExpirationValidation(); // Stop session validation and clear the timeout
347
241
 
348
- sessionStorage.removeItem('SeaCatOAuth2Token');
349
- var promise = this.Api.logout(this.OAuthToken['access_token']);
350
- if (promise == null) {
351
- window.location.reload();
242
+ /** Check for TenantService and pass tenants list obtained from userinfo */
243
+ var availableTenants = mockParams.tenants;
244
+ if (_this2.App.Services.TenantService) {
245
+ yield _this2.App.Services.TenantService.setTenants(availableTenants, _this2._getAuthorizedTenant(mockParams));
352
246
  }
353
- promise.then(function (response) {
354
- window.location.reload();
355
- })["catch"](function (error) {
356
- window.location.reload();
357
- });
247
+ })();
248
+ }
249
+ logout() {
250
+ this.App.addSplashScreenRequestor(this);
251
+ this._stopSessionExpirationValidation(); // Stop session validation and clear the timeout
252
+
253
+ sessionStorage.removeItem('SeaCatOAuth2Token');
254
+ var promise = this.Api.logout(this.OAuthToken['access_token']);
255
+ if (promise == null) {
256
+ window.location.reload();
358
257
  }
258
+ promise.then(response => {
259
+ window.location.reload();
260
+ }).catch(error => {
261
+ window.location.reload();
262
+ });
263
+ }
359
264
 
360
- // TODO: reconsider removing async/await with promise
361
- }, {
362
- key: "validateNavigation",
363
- value: function () {
364
- var _validateNavigation = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
365
- var _state$navigation,
366
- _state$auth,
367
- _this3 = this;
368
- var state, navItems, resources, authorizedNavItems;
369
- return _regenerator["default"].wrap(function _callee4$(_context4) {
370
- while (1) switch (_context4.prev = _context4.next) {
371
- case 0:
372
- state = this.App.Store.getState();
373
- navItems = (_state$navigation = state.navigation) === null || _state$navigation === void 0 ? void 0 : _state$navigation.navItems;
374
- resources = (_state$auth = state.auth) === null || _state$auth === void 0 ? void 0 : _state$auth.resources;
375
- authorizedNavItems = [];
376
- _context4.t0 = navItems;
377
- if (!_context4.t0) {
378
- _context4.next = 8;
379
- break;
265
+ // TODO: reconsider removing async/await with promise
266
+ validateNavigation() {
267
+ var _this3 = this;
268
+ return (0, _asyncToGenerator2.default)(function* () {
269
+ var _state$navigation, _state$auth;
270
+ var state = _this3.App.Store.getState();
271
+ var navItems = (_state$navigation = state.navigation) === null || _state$navigation === void 0 ? void 0 : _state$navigation.navItems;
272
+ var resources = (_state$auth = state.auth) === null || _state$auth === void 0 ? void 0 : _state$auth.resources;
273
+ var authorizedNavItems = [];
274
+ navItems && (yield Promise.all(navItems.map(/*#__PURE__*/function () {
275
+ var _ref = (0, _asyncToGenerator2.default)(function* (itm, idx) {
276
+ if (resources.indexOf('authz:superuser') !== -1) {
277
+ // If user is superuser, validate every navigation item
278
+ authorizedNavItems.push(itm);
279
+ } else {
280
+ if (itm.resource) {
281
+ if (itm.children) {
282
+ itm.children = yield _this3._validateChildrenNav(itm, resources);
380
283
  }
381
- _context4.next = 8;
382
- return Promise.all(navItems.map(/*#__PURE__*/function () {
383
- var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(itm, idx) {
384
- var access_auth;
385
- return _regenerator["default"].wrap(function _callee3$(_context3) {
386
- while (1) switch (_context3.prev = _context3.next) {
387
- case 0:
388
- if (!(resources.indexOf('authz:superuser') !== -1)) {
389
- _context3.next = 4;
390
- break;
391
- }
392
- // If user is superuser, validate every navigation item
393
- authorizedNavItems.push(itm);
394
- _context3.next = 18;
395
- break;
396
- case 4:
397
- if (!itm.resource) {
398
- _context3.next = 13;
399
- break;
400
- }
401
- if (!itm.children) {
402
- _context3.next = 9;
403
- break;
404
- }
405
- _context3.next = 8;
406
- return _this3._validateChildrenNav(itm, resources);
407
- case 8:
408
- itm.children = _context3.sent;
409
- case 9:
410
- // Item validation
411
- access_auth = _this3._validateItemNav(itm.resource, resources);
412
- if (access_auth == true) {
413
- authorizedNavItems.push(itm);
414
- }
415
- _context3.next = 18;
416
- break;
417
- case 13:
418
- if (!itm.children) {
419
- _context3.next = 18;
420
- break;
421
- }
422
- _context3.next = 16;
423
- return _this3._validateChildrenNav(itm, resources);
424
- case 16:
425
- itm.children = _context3.sent;
426
- if (itm.children.length > 0) {
427
- authorizedNavItems.push(itm);
428
- }
429
- case 18:
430
- case "end":
431
- return _context3.stop();
432
- }
433
- }, _callee3);
434
- }));
435
- return function (_x2, _x3) {
436
- return _ref.apply(this, arguments);
437
- };
438
- }()));
439
- case 8:
440
- this.App.Store.dispatch({
441
- type: _actions2.SET_NAVIGATION_ITEMS,
442
- navItems: authorizedNavItems
443
- });
444
- case 9:
445
- case "end":
446
- return _context4.stop();
284
+ // Item validation
285
+ var access_auth = _this3._validateItemNav(itm.resource, resources);
286
+ if (access_auth == true) {
287
+ authorizedNavItems.push(itm);
288
+ }
289
+ } else {
290
+ if (itm.children) {
291
+ itm.children = yield _this3._validateChildrenNav(itm, resources);
292
+ if (itm.children.length > 0) {
293
+ authorizedNavItems.push(itm);
294
+ }
295
+ }
296
+ }
447
297
  }
448
- }, _callee4, this);
449
- }));
450
- function validateNavigation() {
451
- return _validateNavigation.apply(this, arguments);
452
- }
453
- return validateNavigation;
454
- }() // Validate sidebar's item children
455
- }, {
456
- key: "_validateChildrenNav",
457
- value: function () {
458
- var _validateChildrenNav2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(itm, resources) {
459
- var _this4 = this;
460
- var authorizedNavChildren;
461
- return _regenerator["default"].wrap(function _callee6$(_context6) {
462
- while (1) switch (_context6.prev = _context6.next) {
463
- case 0:
464
- // Item's children validation
465
- authorizedNavChildren = [];
466
- _context6.next = 3;
467
- return Promise.all(itm.children.map(/*#__PURE__*/function () {
468
- var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(child, id) {
469
- var access_auth;
470
- return _regenerator["default"].wrap(function _callee5$(_context5) {
471
- while (1) switch (_context5.prev = _context5.next) {
472
- case 0:
473
- if (child.resource) {
474
- access_auth = _this4._validateItemNav(child.resource, resources);
475
- if (access_auth == true) {
476
- authorizedNavChildren.push(child);
477
- }
478
- }
479
- case 1:
480
- case "end":
481
- return _context5.stop();
482
- }
483
- }, _callee5);
484
- }));
485
- return function (_x6, _x7) {
486
- return _ref2.apply(this, arguments);
487
- };
488
- }()));
489
- case 3:
490
- return _context6.abrupt("return", authorizedNavChildren);
491
- case 4:
492
- case "end":
493
- return _context6.stop();
298
+ });
299
+ return function (_x, _x2) {
300
+ return _ref.apply(this, arguments);
301
+ };
302
+ }())));
303
+ _this3.App.Store.dispatch({
304
+ type: _actions2.SET_NAVIGATION_ITEMS,
305
+ navItems: authorizedNavItems
306
+ });
307
+ })();
308
+ }
309
+
310
+ // Validate sidebar's item children
311
+ _validateChildrenNav(itm, resources) {
312
+ var _this4 = this;
313
+ return (0, _asyncToGenerator2.default)(function* () {
314
+ // Item's children validation
315
+ var authorizedNavChildren = [];
316
+ yield Promise.all(itm.children.map(/*#__PURE__*/function () {
317
+ var _ref2 = (0, _asyncToGenerator2.default)(function* (child, id) {
318
+ if (child.resource) {
319
+ var access_auth = _this4._validateItemNav(child.resource, resources);
320
+ if (access_auth == true) {
321
+ authorizedNavChildren.push(child);
322
+ }
494
323
  }
495
- }, _callee6);
496
- }));
497
- function _validateChildrenNav(_x4, _x5) {
498
- return _validateChildrenNav2.apply(this, arguments);
499
- }
500
- return _validateChildrenNav;
501
- }() // Validate sidebar items
502
- }, {
503
- key: "_validateItemNav",
504
- value: function _validateItemNav(resource, resources) {
505
- var valid = resources ? resources.indexOf(resource) !== -1 : false;
506
- // If user is superuser, then item is enabled
507
- if (resources.indexOf('authz:superuser') !== -1) {
508
- valid = true;
509
- }
510
- return valid;
324
+ });
325
+ return function (_x3, _x4) {
326
+ return _ref2.apply(this, arguments);
327
+ };
328
+ }()));
329
+ return authorizedNavChildren;
330
+ })();
331
+ }
332
+
333
+ // Validate sidebar items
334
+ _validateItemNav(resource, resources) {
335
+ var valid = resources ? resources.indexOf(resource) !== -1 : false;
336
+ // If user is superuser, then item is enabled
337
+ if (resources.indexOf('authz:superuser') !== -1) {
338
+ valid = true;
511
339
  }
340
+ return valid;
341
+ }
512
342
 
513
- // Validate tenant access
514
- }, {
515
- key: "validateTenant",
516
- value: function validateTenant() {
517
- var resources = [];
518
- var tenants = [];
519
- var currentTenant = this.App.Services.TenantService.getCurrentTenant();
520
- if (this.UserInfo !== null) {
521
- resources = this.UserInfo.resources ? this.UserInfo.resources[currentTenant] : [];
522
- tenants = this.UserInfo.tenants ? this.UserInfo.tenants : [];
343
+ // Validate tenant access
344
+ validateTenant() {
345
+ var resources = [];
346
+ var tenants = [];
347
+ var currentTenant = this.App.Services.TenantService.getCurrentTenant();
348
+ if (this.UserInfo !== null) {
349
+ resources = this.UserInfo.resources ? this.UserInfo.resources[currentTenant] : [];
350
+ tenants = this.UserInfo.tenants ? this.UserInfo.tenants : [];
351
+ }
352
+ var valid = tenants ? tenants.indexOf(currentTenant) !== -1 : false;
353
+ // If user is superuser, then tenant access is granted
354
+ if (resources && resources.indexOf('authz:superuser') !== -1) {
355
+ valid = true;
356
+ }
357
+ return valid;
358
+ }
359
+ updateUserInfo() {
360
+ var _this5 = this;
361
+ return (0, _asyncToGenerator2.default)(function* () {
362
+ var _response$data;
363
+ var response;
364
+ try {
365
+ response = yield _this5.Api.userinfo(_this5.OAuthToken.access_token);
366
+ } catch (err) {
367
+ console.error("Failed to update user info", err);
368
+ _this5.UserInfo = null;
369
+ if (_this5.App.Store != null) {
370
+ _this5.App.Store.dispatch({
371
+ type: _actions.types.AUTH_USERINFO,
372
+ payload: _this5.UserInfo
373
+ });
374
+ }
375
+ return false;
523
376
  }
524
- var valid = tenants ? tenants.indexOf(currentTenant) !== -1 : false;
525
- // If user is superuser, then tenant access is granted
526
- if (resources && resources.indexOf('authz:superuser') !== -1) {
527
- valid = true;
377
+ _this5.UserInfo = response.data;
378
+ _this5.SessionExpiration = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.exp;
379
+ if (_this5.App.Store != null) {
380
+ _this5.App.Store.dispatch({
381
+ type: _actions.types.AUTH_USERINFO,
382
+ payload: _this5.UserInfo
383
+ });
528
384
  }
529
- return valid;
530
- }
531
- }, {
532
- key: "updateUserInfo",
533
- value: function () {
534
- var _updateUserInfo = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
535
- var _response$data;
536
- var response, availableTenants;
537
- return _regenerator["default"].wrap(function _callee7$(_context7) {
538
- while (1) switch (_context7.prev = _context7.next) {
539
- case 0:
540
- _context7.prev = 0;
541
- _context7.next = 3;
542
- return this.Api.userinfo(this.OAuthToken.access_token);
543
- case 3:
544
- response = _context7.sent;
545
- _context7.next = 12;
546
- break;
547
- case 6:
548
- _context7.prev = 6;
549
- _context7.t0 = _context7["catch"](0);
550
- console.error("Failed to update user info", _context7.t0);
551
- this.UserInfo = null;
552
- if (this.App.Store != null) {
553
- this.App.Store.dispatch({
554
- type: _actions.types.AUTH_USERINFO,
555
- payload: this.UserInfo
556
- });
557
- }
558
- return _context7.abrupt("return", false);
559
- case 12:
560
- this.UserInfo = response.data;
561
- this.SessionExpiration = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.exp;
562
- if (this.App.Store != null) {
563
- this.App.Store.dispatch({
564
- type: _actions.types.AUTH_USERINFO,
565
- payload: this.UserInfo
566
- });
567
- }
568
385
 
569
- /** Check for TenantService and pass tenants list obtained from userinfo */
570
- availableTenants = this.UserInfo.tenants;
571
- if (!this.App.Services.TenantService) {
572
- _context7.next = 19;
573
- break;
574
- }
575
- _context7.next = 19;
576
- return this.App.Services.TenantService.setTenants(availableTenants, this._getAuthorizedTenant(this.UserInfo));
577
- case 19:
578
- return _context7.abrupt("return", true);
579
- case 20:
580
- case "end":
581
- return _context7.stop();
582
- }
583
- }, _callee7, this, [[0, 6]]);
584
- }));
585
- function updateUserInfo() {
586
- return _updateUserInfo.apply(this, arguments);
386
+ /** Check for TenantService and pass tenants list obtained from userinfo */
387
+ var availableTenants = _this5.UserInfo.tenants;
388
+ if (_this5.App.Services.TenantService) {
389
+ yield _this5.App.Services.TenantService.setTenants(availableTenants, _this5._getAuthorizedTenant(_this5.UserInfo));
587
390
  }
588
- return updateUserInfo;
589
- }()
590
- }, {
591
- key: "_updateToken",
592
- value: function () {
593
- var _updateToken2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(authorization_code) {
594
- var response;
595
- return _regenerator["default"].wrap(function _callee8$(_context8) {
596
- while (1) switch (_context8.prev = _context8.next) {
597
- case 0:
598
- _context8.prev = 0;
599
- _context8.next = 3;
600
- return this.Api.token_authorization_code(authorization_code, this.RedirectURL);
601
- case 3:
602
- response = _context8.sent;
603
- _context8.next = 10;
604
- break;
605
- case 6:
606
- _context8.prev = 6;
607
- _context8.t0 = _context8["catch"](0);
608
- console.error("Failed to update token", _context8.t0);
609
- return _context8.abrupt("return", false);
610
- case 10:
611
- this.OAuthToken = response.data;
612
- sessionStorage.setItem('SeaCatOAuth2Token', JSON.stringify(response.data));
613
- return _context8.abrupt("return", true);
614
- case 13:
615
- case "end":
616
- return _context8.stop();
617
- }
618
- }, _callee8, this, [[0, 6]]);
619
- }));
620
- function _updateToken(_x8) {
621
- return _updateToken2.apply(this, arguments);
391
+ return true;
392
+ })();
393
+ }
394
+ _updateToken(authorization_code) {
395
+ var _this6 = this;
396
+ return (0, _asyncToGenerator2.default)(function* () {
397
+ var response;
398
+ try {
399
+ response = yield _this6.Api.token_authorization_code(authorization_code, _this6.RedirectURL);
400
+ } catch (err) {
401
+ console.error("Failed to update token", err);
402
+ return false;
622
403
  }
623
- return _updateToken;
624
- }()
625
- }, {
626
- key: "_getAuthorizedTenant",
627
- value: function _getAuthorizedTenant(userInfo) {
628
- /*
629
- Return the authorized tenant ID from userinfo.
630
- Pick the first one if there are multiple tenants.
631
- */
632
- if (userInfo !== null && userInfo !== void 0 && userInfo.resources) {
633
- for (var tenantId in userInfo.resources) {
634
- if (tenantId != '*' && userInfo.resources.hasOwnProperty(tenantId)) {
635
- return tenantId;
636
- }
404
+ _this6.OAuthToken = response.data;
405
+ sessionStorage.setItem('SeaCatOAuth2Token', JSON.stringify(response.data));
406
+ return true;
407
+ })();
408
+ }
409
+ _getAuthorizedTenant(userInfo) {
410
+ /*
411
+ Return the authorized tenant ID from userinfo.
412
+ Pick the first one if there are multiple tenants.
413
+ */
414
+ if (userInfo !== null && userInfo !== void 0 && userInfo.resources) {
415
+ for (var tenantId in userInfo.resources) {
416
+ if (tenantId != '*' && userInfo.resources.hasOwnProperty(tenantId)) {
417
+ return tenantId;
637
418
  }
638
- } else {
639
- return undefined;
640
419
  }
420
+ } else {
421
+ return undefined;
641
422
  }
423
+ }
642
424
 
643
- // Loop validating session expiration
644
- }, {
645
- key: "_startSessionExpirationValidation",
646
- value: function () {
647
- var _startSessionExpirationValidation2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee10() {
648
- var _this5 = this;
649
- var warningDisplayed, _validateSession;
650
- return _regenerator["default"].wrap(function _callee10$(_context10) {
651
- while (1) switch (_context10.prev = _context10.next) {
652
- case 0:
653
- if (this.SessionExpiration) {
654
- _context10.next = 3;
655
- break;
656
- }
657
- console.warn("Session expiration is not set.");
658
- return _context10.abrupt("return");
659
- case 3:
660
- warningDisplayed = false; // Tracks if the "about to expire" warning has been shown
661
- _validateSession = /*#__PURE__*/function () {
662
- var _ref3 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9() {
663
- var currentTime, timeRemaining, isUserInfoUpdated;
664
- return _regenerator["default"].wrap(function _callee9$(_context9) {
665
- while (1) switch (_context9.prev = _context9.next) {
666
- case 0:
667
- currentTime = Date.now() / 1000; // Convert milliseconds to seconds
668
- timeRemaining = _this5.SessionExpiration - currentTime; // Time difference for triggering "about to expire" warning
669
- // Prevent glitches on very large time remaining values
670
- if (timeRemaining >= Math.pow(2, 31)) {
671
- // Set timeout to maximum allowed value
672
- timeRemaining = Math.pow(2, 31) - 1;
673
- }
425
+ // Loop validating session expiration
426
+ _startSessionExpirationValidation() {
427
+ var _this7 = this;
428
+ return (0, _asyncToGenerator2.default)(function* () {
429
+ if (!_this7.SessionExpiration) {
430
+ console.warn("Session expiration is not set.");
431
+ return;
432
+ }
433
+ var warningDisplayed = false; // Tracks if the "about to expire" warning has been shown
434
+
435
+ var _validateSession = /*#__PURE__*/function () {
436
+ var _ref3 = (0, _asyncToGenerator2.default)(function* () {
437
+ var currentTime = Date.now() / 1000; // Convert milliseconds to seconds
438
+ var timeRemaining = _this7.SessionExpiration - currentTime; // Time difference for triggering "about to expire" warning
439
+ // Prevent glitches on very large time remaining values
440
+ if (timeRemaining >= Math.pow(2, 31)) {
441
+ // Set timeout to maximum allowed value
442
+ timeRemaining = Math.pow(2, 31) - 1;
443
+ }
674
444
 
675
- // If remaining time is between 1 and 60s, repetitivelly ask for userInfo and trigger "about to expire" warning
676
- if (!(timeRemaining <= 60 && timeRemaining > 0)) {
677
- _context9.next = 7;
678
- break;
679
- }
680
- if (!warningDisplayed) {
681
- _this5.App.addAlert("info", "General|Your session will expire soon", 30, true);
682
- warningDisplayed = true; // Mark the warning as displayed
683
- }
684
- _context9.next = 7;
685
- return _this5.updateUserInfo();
686
- case 7:
687
- if (!(_this5.SessionExpiration <= currentTime)) {
688
- _context9.next = 17;
689
- break;
690
- }
691
- _context9.next = 10;
692
- return _this5.updateUserInfo();
693
- case 10:
694
- isUserInfoUpdated = _context9.sent;
695
- if (isUserInfoUpdated) {
696
- _context9.next = 17;
697
- break;
698
- }
699
- // Stop further checks
700
- clearTimeout(_this5.sessionValidationInterval);
701
- _this5.sessionValidationInterval = null;
702
- _this5.App.addAlert("info", "ASABAuthModule|Your session has expired.", 3600 * 1000, true, function (alert, store) {
703
- return /*#__PURE__*/_react["default"].createElement(_SessionExpirationAlert.SessionExpirationAlert, {
704
- alert: alert,
705
- store: store
706
- });
707
- });
708
- // Disable UI elements
709
- if (_this5.App.Store) {
710
- _this5.App.Store.dispatch({
711
- type: _actions.types.AUTH_SESSION_EXPIRATION,
712
- sessionExpired: true
713
- });
445
+ // If remaining time is between 1 and 60s, repetitivelly ask for userInfo and trigger "about to expire" warning
446
+ if (timeRemaining <= 60 && timeRemaining > 0) {
447
+ if (!warningDisplayed) {
448
+ _this7.App.addAlert("info", "General|Your session will expire soon", 30, true);
449
+ warningDisplayed = true; // Mark the warning as displayed
450
+ }
451
+ yield _this7.updateUserInfo(); // Continue updating user info
452
+ }
453
+
454
+ // Validation on expired session
455
+ if (_this7.SessionExpiration <= currentTime) {
456
+ // Handle session expiration
457
+ var isUserInfoUpdated = yield _this7.updateUserInfo();
458
+ if (!isUserInfoUpdated) {
459
+ // Stop further checks
460
+ clearTimeout(_this7.sessionValidationInterval);
461
+ _this7.sessionValidationInterval = null;
462
+ _this7.App.addAlert("info", "ASABAuthModule|Your session has expired.", 3600 * 1000, true, (alert, store) => /*#__PURE__*/_react.default.createElement(_SessionExpirationAlert.SessionExpirationAlert, {
463
+ alert: alert,
464
+ store: store
465
+ }));
466
+ // Disable UI elements
467
+ if (_this7.App.Store) {
468
+ _this7.App.Store.dispatch({
469
+ type: _actions.types.AUTH_SESSION_EXPIRATION,
470
+ sessionExpired: true
471
+ });
714
472
 
715
- // Disable UI elements
716
- (0, _toConsumableArray2["default"])(document.querySelectorAll('#app-sidebar .nav-link, [class^="btn"]:not(.alert-button), [class*=" btn"]:not(.alert-button), .btn-group a, .page-item, input, select')).forEach(function (i) {
717
- i.classList.add("disabled");
718
- i.setAttribute("disabled", "");
719
- });
473
+ // Disable UI elements
474
+ [...document.querySelectorAll('#app-sidebar .nav-link, [class^="btn"]:not(.alert-button), [class*=" btn"]:not(.alert-button), .btn-group a, .page-item, input, select')].forEach(i => {
475
+ i.classList.add("disabled");
476
+ i.setAttribute("disabled", "");
477
+ });
720
478
 
721
- // Reload on navigation actions
722
- window.addEventListener("popstate", function () {
723
- window.location.reload();
724
- });
725
- }
726
- return _context9.abrupt("return");
727
- case 17:
728
- // Re-trigger validation after 10 seconds
729
- _this5.sessionValidationInterval = setTimeout(_validateSession, 10000);
730
- case 18:
731
- case "end":
732
- return _context9.stop();
733
- }
734
- }, _callee9);
735
- }));
736
- return function validateSession() {
737
- return _ref3.apply(this, arguments);
738
- };
739
- }(); // Start the first validation cycle
740
- _validateSession();
741
- case 6:
742
- case "end":
743
- return _context10.stop();
479
+ // Reload on navigation actions
480
+ window.addEventListener("popstate", () => {
481
+ window.location.reload();
482
+ });
483
+ }
484
+ return;
485
+ }
744
486
  }
745
- }, _callee10, this);
746
- }));
747
- function _startSessionExpirationValidation() {
748
- return _startSessionExpirationValidation2.apply(this, arguments);
749
- }
750
- return _startSessionExpirationValidation;
751
- }() // Stop looping on session expiration validation
752
- }, {
753
- key: "_stopSessionExpirationValidation",
754
- value: function _stopSessionExpirationValidation() {
755
- if (this.sessionValidationInterval) {
756
- clearInterval(this.sessionValidationInterval);
757
- this.sessionValidationInterval = null;
758
- }
487
+
488
+ // Re-trigger validation after 10 seconds
489
+ _this7.sessionValidationInterval = setTimeout(_validateSession, 10000);
490
+ });
491
+ return function validateSession() {
492
+ return _ref3.apply(this, arguments);
493
+ };
494
+ }();
495
+
496
+ // Start the first validation cycle
497
+ _validateSession();
498
+ })();
499
+ }
500
+
501
+ // Stop looping on session expiration validation
502
+ _stopSessionExpirationValidation() {
503
+ if (this.sessionValidationInterval) {
504
+ clearInterval(this.sessionValidationInterval);
505
+ this.sessionValidationInterval = null;
759
506
  }
760
- }]);
761
- }(_asab_webui_components.Module);
507
+ }
508
+ }
509
+ exports.default = AuthModule;