@nu-art/user-account-frontend 0.401.9 → 0.500.6

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 (38) hide show
  1. package/_ats/account-editor/ATS_AccountEditor.d.ts +2 -1
  2. package/_ats/account-editor/ATS_AccountEditor.js +4 -4
  3. package/_ats/account-editor/ATS_AccountEditor.scss +2 -2
  4. package/_ats_session-data/ATS_SessionData.d.ts +3 -1
  5. package/_ats_session-data/ATS_SessionData.js +2 -2
  6. package/_entity/account/ModuleFE_Account.d.ts +24 -13
  7. package/_entity/account/ModuleFE_Account.js +255 -139
  8. package/_entity/account/consts.d.ts +1 -1
  9. package/_entity/account/consts.js +2 -2
  10. package/_entity/session/ModuleFE_Session.d.ts +3 -4
  11. package/_entity/session/ModuleFE_Session.js +17 -8
  12. package/_entity/session/no-auth-listener.d.ts +5 -0
  13. package/_entity/session/no-auth-listener.js +2 -0
  14. package/account-editor/Component_AccountEditor.d.ts +3 -3
  15. package/account-editor/Component_AccountEditor.js +23 -33
  16. package/index.d.ts +4 -2
  17. package/index.js +4 -2
  18. package/module-pack.js +1 -1
  19. package/package.json +18 -10
  20. package/ui/Component_AccountThumbnail/Component_AccountThumbnail.d.ts +18 -4
  21. package/ui/Component_AccountThumbnail/Component_AccountThumbnail.js +15 -13
  22. package/ui/Component_ChangePassword/Component_ChangePassword.d.ts +1 -1
  23. package/ui/Component_ChangePassword/Component_ChangePassword.js +7 -9
  24. package/ui/Component_GoogleSAMLLogin/Component_GoogleSAMLLogin.js +4 -3
  25. package/ui/Component_Login/Component_Login.d.ts +4 -4
  26. package/ui/Component_Login/Component_Login.js +7 -7
  27. package/ui/Component_LoginBlocked/Component_LoginBlocked.d.ts +1 -1
  28. package/ui/Component_LoginBlocked/Component_LoginBlocked.js +1 -1
  29. package/ui/Component_Register.d.ts +1 -1
  30. package/ui/Component_Register.js +10 -11
  31. package/ui/PopUp_AccountMenu/PopUp_AccountMenu.d.ts +1 -1
  32. package/ui/PopUp_AccountMenu/PopUp_AccountMenu.js +10 -15
  33. package/_entity/account/index.d.ts +0 -3
  34. package/_entity/account/index.js +0 -3
  35. package/_entity.d.ts +0 -3
  36. package/_entity.js +0 -3
  37. package/ui/Component_Login/index.d.ts +0 -1
  38. package/ui/Component_Login/index.js +0 -18
@@ -1,6 +1,7 @@
1
1
  import './ATS_AccountEditor.scss';
2
- import { AppToolsScreen, ComponentSync } from '@nu-art/thunderstorm-frontend/index';
3
2
  import { DB_Account } from '@nu-art/user-account-shared';
3
+ import { ComponentSync } from '@nu-art/thunder-widgets';
4
+ import { AppToolsScreen } from '@nu-art/thunder-ui-modules';
4
5
  type Props = {};
5
6
  type State = {
6
7
  selectedUser?: DB_Account;
@@ -1,9 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import './ATS_AccountEditor.scss';
3
- import { _className, Button, ComponentSync, LL_H_C, LL_V_L, TS_PropRenderer } from '@nu-art/thunderstorm-frontend/index';
4
3
  import { Component_AccountEditor } from '../../account-editor/Component_AccountEditor.js';
5
4
  import { generateUUID } from '@nu-art/ts-common';
6
- import { ModuleFE_Account } from '../../_entity/account/index.js';
5
+ import { ModuleFE_Account } from '../../_entity/account/ModuleFE_Account.js';
6
+ import { ComponentSync, LL_H_C, TS_PropRenderer } from '@nu-art/thunder-widgets';
7
+ import { Button, LL_V_L } from '@nu-art/thunder-widgets/v3';
8
+ import { _className } from '@nu-art/thunder-core';
7
9
  export class ATS_AccountEditor extends ComponentSync {
8
10
  static screen = {
9
11
  name: 'Accounts Editor',
@@ -12,12 +14,10 @@ export class ATS_AccountEditor extends ComponentSync {
12
14
  group: 'Permissions',
13
15
  modulesToAwait: [ModuleFE_Account]
14
16
  };
15
- // ######################### Life Cycle #########################
16
17
  deriveStateFromProps(nextProps, state) {
17
18
  state = this.state ? { ...this.state } : {};
18
19
  return state;
19
20
  }
20
- // ######################### Logic #########################
21
21
  setSelectedAccount = (account) => {
22
22
  if (!account)
23
23
  this.setState({ isPreview: false, selectedUser: undefined });
@@ -21,8 +21,8 @@
21
21
  overflow: auto;
22
22
 
23
23
  .users-list {
24
- cursor: pointer;
25
- padding: 10px;
24
+ cursor: pointer;
25
+ padding: 10px;
26
26
 
27
27
  .row {
28
28
  &.selected {
@@ -1,4 +1,6 @@
1
- import { AppToolsScreen, ComponentSync, OnStorageKeyChangedListener } from '@nu-art/thunderstorm-frontend/index';
1
+ import { ComponentSync } from '@nu-art/thunder-widgets';
2
+ import { AppToolsScreen } from '@nu-art/thunder-ui-modules';
3
+ import { OnStorageKeyChangedListener } from '@nu-art/thunder-core';
2
4
  type ATS_SessionData_Props = {};
3
5
  type ATS_SessionData_State = {
4
6
  sessionId?: string;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { __stringify } from '@nu-art/ts-common';
3
- import { ModuleFE_Account } from '../_entity/account/index.js';
4
- import { ComponentSync, LL_V_L, TS_Input, TS_TextArea } from '@nu-art/thunderstorm-frontend/index';
3
+ import { ModuleFE_Account } from '../_entity/account/ModuleFE_Account.js';
4
+ import { ComponentSync, LL_V_L, TS_Input, TS_TextArea } from '@nu-art/thunder-widgets';
5
5
  export class ATS_SessionData extends ComponentSync {
6
6
  static screen = { name: `SessionData`, renderer: this, group: 'Permissions' };
7
7
  static defaultProps = {
@@ -1,14 +1,14 @@
1
1
  import * as React from 'react';
2
- import { ModuleFE_BaseApi, ThunderDispatcher } from '@nu-art/thunderstorm-frontend/index';
3
- import { ApiDefCaller } from '@nu-art/thunderstorm-shared';
4
- import { ApiStruct_Account, ApiStruct_SAML, DB_Account, DBProto_Account, PasswordAssertionConfig, UI_Account } from '@nu-art/user-account-shared';
5
- import { ApiCallerEventType } from '@nu-art/thunderstorm-frontend/core/db-api-gen/types';
2
+ import { ModuleFE_BaseApi } from '@nu-art/db-api-frontend';
3
+ import { ApiCallerEventType } from '@nu-art/db-api-shared';
4
+ import { API_SAML, API_UserAccount, DatabaseDef_Account, DB_Account, PasswordAssertionConfig, UI_Account } from '@nu-art/user-account-shared';
6
5
  import { OnSessionUpdated } from '../session/ModuleFE_Session.js';
6
+ import { ThunderDispatcher } from '@nu-art/thunder-core';
7
7
  export interface OnLoginStatusUpdated {
8
8
  __onLoginStatusUpdated: () => void;
9
9
  }
10
10
  export interface OnAccountsUpdated {
11
- __onAccountsUpdated: (...params: ApiCallerEventType<DBProto_Account>) => void;
11
+ __onAccountsUpdated: (...params: ApiCallerEventType<DB_Account>) => void;
12
12
  }
13
13
  export declare enum LoggedStatus {
14
14
  VALIDATING = 0,
@@ -17,15 +17,25 @@ export declare enum LoggedStatus {
17
17
  LOGGED_IN = 3
18
18
  }
19
19
  export declare const dispatch_onLoginStatusChanged: ThunderDispatcher<OnLoginStatusUpdated, "__onLoginStatusUpdated", [], void>;
20
- export declare const dispatch_onAccountsUpdated: ThunderDispatcher<OnAccountsUpdated, "__onAccountsUpdated", ApiCallerEventType<DBProto_Account>, void>;
21
- type ApiDefCaller_Account = ApiDefCaller<{
22
- _v1: ApiStruct_Account['_v1'] & ApiStruct_SAML['_v1'];
23
- }>;
24
- declare class ModuleFE_Account_Class extends ModuleFE_BaseApi<DBProto_Account> implements ApiDefCaller_Account, OnLoginStatusUpdated, OnSessionUpdated {
25
- readonly _v1: ApiDefCaller_Account['_v1'];
20
+ export declare const dispatch_onAccountsUpdated: ThunderDispatcher<OnAccountsUpdated, "__onAccountsUpdated", ApiCallerEventType<DB_Account>, void>;
21
+ declare class ModuleFE_Account_Class extends ModuleFE_BaseApi<DatabaseDef_Account> implements OnLoginStatusUpdated, OnSessionUpdated {
26
22
  private status;
27
23
  __onLoginStatusUpdated(): void;
28
24
  constructor();
25
+ refreshSession(_params?: API_UserAccount['refreshSession']['Params']): Promise<API_UserAccount['refreshSession']['Response']>;
26
+ registerAccount(body: API_UserAccount['registerAccount']['Body']): Promise<API_UserAccount['registerAccount']['Response']>;
27
+ createAccount(body: API_UserAccount['createAccount']['Body']): Promise<API_UserAccount['createAccount']['Response']>;
28
+ changePassword(body: API_UserAccount['changePassword']['Body']): Promise<API_UserAccount['changePassword']['Response']>;
29
+ login(body: API_UserAccount['login']['Body']): Promise<API_UserAccount['login']['Response']>;
30
+ logout(_params?: API_UserAccount['logout']['Params']): Promise<API_UserAccount['logout']['Response']>;
31
+ createToken(body: API_UserAccount['createToken']['Body']): Promise<API_UserAccount['createToken']['Response']>;
32
+ setPassword(body: API_UserAccount['setPassword']['Body']): Promise<API_UserAccount['setPassword']['Response']>;
33
+ getSessions(params: API_UserAccount['getSessions']['Params']): Promise<API_UserAccount['getSessions']['Response']>;
34
+ changeThumbnail(body: API_UserAccount['changeThumbnail']['Body']): Promise<API_UserAccount['changeThumbnail']['Response']>;
35
+ loginSaml(params: API_SAML['loginSaml']['Params']): Promise<API_SAML['loginSaml']['Response']>;
36
+ assertSAML(body: API_SAML['assertSAML']['Body']): Promise<API_SAML['assertSAML']['Response']>;
37
+ getPasswordAssertionConfig(_params?: API_UserAccount['getPasswordAssertionConfig']['Params']): Promise<API_UserAccount['getPasswordAssertionConfig']['Response']>;
38
+ deleteAccount(params: API_UserAccount['deleteAccount']['Params']): Promise<API_UserAccount['deleteAccount']['Response']>;
29
39
  protected init(): void;
30
40
  getAccounts(): UI_Account[];
31
41
  getLoggedStatus: () => LoggedStatus;
@@ -33,15 +43,16 @@ declare class ModuleFE_Account_Class extends ModuleFE_BaseApi<DBProto_Account> i
33
43
  __onSessionUpdated(): void;
34
44
  protected setLoggedStatus: (newStatus: LoggedStatus) => void;
35
45
  composeSAMLUrl: () => string;
36
- logout: (url?: string) => Promise<string | undefined>;
46
+ performLogout: (url?: string) => Promise<string | undefined>;
37
47
  uploadAccountThumbnail: (e: React.MouseEvent, account: DB_Account) => void;
38
48
  private encodeFile;
39
- getPasswordAssertionConfig: () => PasswordAssertionConfig | undefined;
49
+ passwordAssertionConfig: () => PasswordAssertionConfig | undefined;
40
50
  getCurrentlyLoggedAccount: () => import("@nu-art/user-account-shared").UI_SessionAccount;
41
51
  private onAccountCreated;
42
52
  private onThumbnailChanged;
43
53
  private onLoginCompletedSAML;
44
54
  private onPasswordAssertionConfig;
55
+ private onAccountDeleted;
45
56
  }
46
57
  export declare const ModuleFE_Account: ModuleFE_Account_Class;
47
58
  export {};
@@ -1,10 +1,46 @@
1
- import { apiWithBody, apiWithQuery, ModuleFE_BaseApi, ModuleFE_XHR, readFileContent, StorageKey, ThunderDispatcher } from '@nu-art/thunderstorm-frontend/index';
2
- import { HeaderKey_DeviceId, HeaderKey_TabId } from '@nu-art/thunderstorm-shared';
3
- import { dispatcher_onAuthRequired } from '@nu-art/thunderstorm-shared/no-auth-listener';
4
- import { ApiDef_Account, ApiDef_SAML, DBDef_Accounts, QueryParam_SessionId } from '@nu-art/user-account-shared';
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import { buildConfigFromDBDef, ModuleFE_BaseApi } from '@nu-art/db-api-frontend';
36
+ import { ApiCaller, HttpClient } from '@nu-art/http-client';
37
+ import { CrudApiDef } from '@nu-art/db-api-shared';
38
+ import { ApiDef_SAML, ApiDef_UserAccount, DBDef_Accounts, HeaderKey_DeviceId, HeaderKey_TabId, QueryParam_SessionId } from '@nu-art/user-account-shared';
5
39
  import { SessionKeyFE_Account, StorageKey_DeviceId, StorageKey_TabId } from './consts.js';
6
40
  import { asArray, cloneObj, composeUrl, Exception, generateHex, KB } from '@nu-art/ts-common';
7
41
  import { ModuleFE_Session } from '../session/ModuleFE_Session.js';
42
+ import { readFileAs_ArrayBuffer, StorageKey, ThunderDispatcher } from '@nu-art/thunder-core';
43
+ import { dispatcher_onAuthRequired } from '../session/no-auth-listener.js';
8
44
  export var LoggedStatus;
9
45
  (function (LoggedStatus) {
10
46
  LoggedStatus[LoggedStatus["VALIDATING"] = 0] = "VALIDATING";
@@ -15,142 +51,222 @@ export var LoggedStatus;
15
51
  export const dispatch_onLoginStatusChanged = new ThunderDispatcher('__onLoginStatusUpdated');
16
52
  export const dispatch_onAccountsUpdated = new ThunderDispatcher('__onAccountsUpdated');
17
53
  const StorageKey_PasswordAssertionConfig = new StorageKey('account__password-assertion-config', false);
18
- class ModuleFE_Account_Class extends ModuleFE_BaseApi {
19
- _v1;
20
- status = LoggedStatus.LOGGED_OUT;
21
- __onLoginStatusUpdated() {
22
- //Get the password assertion config if needed
23
- if ([LoggedStatus.LOGGED_OUT, LoggedStatus.SESSION_TIMEOUT].includes(this.status))
24
- this._v1.getPasswordAssertionConfig({}).executeSync();
25
- }
26
- constructor() {
27
- super(DBDef_Accounts, dispatch_onAccountsUpdated);
28
- // const login = apiWithBody(ApiDef_Account._v1.login, this.setLoginInfo);
29
- this._v1 = {
30
- refreshSession: apiWithQuery(ApiDef_Account._v1.refreshSession),
31
- registerAccount: apiWithBody(ApiDef_Account._v1.registerAccount),
32
- createAccount: apiWithBody(ApiDef_Account._v1.createAccount, this.onAccountCreated),
33
- changePassword: apiWithBody(ApiDef_Account._v1.changePassword),
34
- login: apiWithBody(ApiDef_Account._v1.login),
35
- // login: (account: Account_Login['request']) => {
36
- //
37
- // toUpsert = this.cleanUp(toUpsert);
38
- // this.validateInternal(toUpsert);
39
- // return this.updatePending(toUpsert as DB_BaseObject, upsert(toUpsert), 'upsert');
40
- // },
41
- logout: apiWithQuery(ApiDef_Account._v1.logout),
42
- createToken: apiWithBody(ApiDef_Account._v1.createToken),
43
- setPassword: apiWithBody(ApiDef_Account._v1.setPassword),
44
- getSessions: apiWithQuery(ApiDef_Account._v1.getSessions),
45
- changeThumbnail: apiWithBody(ApiDef_Account._v1.changeThumbnail, this.onThumbnailChanged),
46
- loginSaml: apiWithQuery(ApiDef_SAML._v1.loginSaml, this.onLoginCompletedSAML),
47
- assertSAML: apiWithBody(ApiDef_SAML._v1.assertSAML),
48
- getPasswordAssertionConfig: apiWithQuery(ApiDef_Account._v1.getPasswordAssertionConfig, this.onPasswordAssertionConfig),
49
- deleteAccount: apiWithQuery(ApiDef_Account._v1.deleteAccount, async (response) => {
50
- await this.onEntryDeleted(response.account);
51
- }),
52
- };
53
- }
54
- init() {
55
- super.init();
56
- let defaultTabId = StorageKey_TabId.get();
57
- let defaultDeviceId = StorageKey_DeviceId.get();
58
- if (!defaultDeviceId) {
59
- defaultDeviceId = generateHex(32);
60
- console.log(`Defining new device Id: ${defaultDeviceId}`);
61
- StorageKey_DeviceId.set(defaultDeviceId);
62
- }
63
- if (!defaultTabId) {
64
- defaultTabId = generateHex(32);
65
- console.log(`Defining new tab Id: ${defaultTabId}`);
66
- StorageKey_TabId.set(defaultTabId);
67
- }
68
- ModuleFE_XHR.addDefaultHeader(HeaderKey_DeviceId, () => defaultDeviceId);
69
- ModuleFE_XHR.addDefaultHeader(HeaderKey_TabId, defaultTabId);
70
- }
71
- // ######################## Logic ########################
72
- getAccounts() {
73
- return this.cache.all().map(i => cloneObj(i));
74
- }
75
- getLoggedStatus = () => this.status;
76
- isStatus = (status) => asArray(status).includes(this.status);
77
- __onSessionUpdated() {
78
- if (!ModuleFE_Session.hasSession())
79
- return this.setLoggedStatus(LoggedStatus.LOGGED_OUT);
80
- if (!ModuleFE_Session.isSessionValid())
81
- return this.setLoggedStatus(LoggedStatus.SESSION_TIMEOUT);
82
- return this.setLoggedStatus(LoggedStatus.LOGGED_IN);
83
- }
84
- setLoggedStatus = (newStatus) => {
85
- if (this.status === newStatus)
86
- return;
87
- const pervStatus = this.status;
88
- this.status = newStatus;
89
- this.logInfo(`Login status changes: ${LoggedStatus[pervStatus]} => ${LoggedStatus[newStatus]}`);
90
- dispatch_onLoginStatusChanged.dispatchUI();
91
- dispatch_onLoginStatusChanged.dispatchModule();
92
- };
93
- composeSAMLUrl = () => {
94
- const params = new URLSearchParams(window.location.search);
95
- const paramsObj = {};
96
- for (const [key, value] of params) {
97
- paramsObj[key] = value;
98
- }
99
- return composeUrl(window.location.origin + window.location.pathname, {
100
- ...paramsObj,
101
- [QueryParam_SessionId]: QueryParam_SessionId.toUpperCase(),
102
- });
103
- };
104
- logout = async (url) => {
105
- await this._v1.logout({}).executeSync();
106
- dispatcher_onAuthRequired.dispatchModule(undefined);
107
- if (url)
108
- return window.location.href = url;
109
- };
110
- uploadAccountThumbnail = (e, account) => {
111
- const input = document.createElement('input');
112
- input.type = 'file';
113
- // input.accept = '.jpg,.jpeg,.png';
114
- input.style.display = 'none';
115
- input.addEventListener('change', async (e) => {
116
- const file = input.files[0];
117
- if (!file)
118
- return;
119
- try {
120
- const hash = await this.encodeFile(file);
121
- await this._v1.changeThumbnail({ accountId: account._id, hash }).executeSync();
54
+ let ModuleFE_Account_Class = (() => {
55
+ let _classSuper = ModuleFE_BaseApi;
56
+ let _instanceExtraInitializers = [];
57
+ let _refreshSession_decorators;
58
+ let _registerAccount_decorators;
59
+ let _createAccount_decorators;
60
+ let _changePassword_decorators;
61
+ let _login_decorators;
62
+ let _logout_decorators;
63
+ let _createToken_decorators;
64
+ let _setPassword_decorators;
65
+ let _getSessions_decorators;
66
+ let _changeThumbnail_decorators;
67
+ let _loginSaml_decorators;
68
+ let _assertSAML_decorators;
69
+ let _getPasswordAssertionConfig_decorators;
70
+ let _deleteAccount_decorators;
71
+ return class ModuleFE_Account_Class extends _classSuper {
72
+ static {
73
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
74
+ _refreshSession_decorators = [ApiCaller(ApiDef_UserAccount.refreshSession)];
75
+ _registerAccount_decorators = [ApiCaller(ApiDef_UserAccount.registerAccount)];
76
+ _createAccount_decorators = [ApiCaller(ApiDef_UserAccount.createAccount, { onComplete: (m, ctx) => m.onAccountCreated(ctx) })];
77
+ _changePassword_decorators = [ApiCaller(ApiDef_UserAccount.changePassword)];
78
+ _login_decorators = [ApiCaller(ApiDef_UserAccount.login)];
79
+ _logout_decorators = [ApiCaller(ApiDef_UserAccount.logout)];
80
+ _createToken_decorators = [ApiCaller(ApiDef_UserAccount.createToken)];
81
+ _setPassword_decorators = [ApiCaller(ApiDef_UserAccount.setPassword)];
82
+ _getSessions_decorators = [ApiCaller(ApiDef_UserAccount.getSessions)];
83
+ _changeThumbnail_decorators = [ApiCaller(ApiDef_UserAccount.changeThumbnail, { onComplete: (m, ctx) => m.onThumbnailChanged(ctx) })];
84
+ _loginSaml_decorators = [ApiCaller(ApiDef_SAML.loginSaml, { onComplete: (m, ctx) => m.onLoginCompletedSAML(ctx) })];
85
+ _assertSAML_decorators = [ApiCaller(ApiDef_SAML.assertSAML)];
86
+ _getPasswordAssertionConfig_decorators = [ApiCaller(ApiDef_UserAccount.getPasswordAssertionConfig, { onComplete: (m, ctx) => m.onPasswordAssertionConfig(ctx) })];
87
+ _deleteAccount_decorators = [ApiCaller(ApiDef_UserAccount.deleteAccount, { onComplete: (m, ctx) => m.onAccountDeleted(ctx) })];
88
+ __esDecorate(this, null, _refreshSession_decorators, { kind: "method", name: "refreshSession", static: false, private: false, access: { has: obj => "refreshSession" in obj, get: obj => obj.refreshSession }, metadata: _metadata }, null, _instanceExtraInitializers);
89
+ __esDecorate(this, null, _registerAccount_decorators, { kind: "method", name: "registerAccount", static: false, private: false, access: { has: obj => "registerAccount" in obj, get: obj => obj.registerAccount }, metadata: _metadata }, null, _instanceExtraInitializers);
90
+ __esDecorate(this, null, _createAccount_decorators, { kind: "method", name: "createAccount", static: false, private: false, access: { has: obj => "createAccount" in obj, get: obj => obj.createAccount }, metadata: _metadata }, null, _instanceExtraInitializers);
91
+ __esDecorate(this, null, _changePassword_decorators, { kind: "method", name: "changePassword", static: false, private: false, access: { has: obj => "changePassword" in obj, get: obj => obj.changePassword }, metadata: _metadata }, null, _instanceExtraInitializers);
92
+ __esDecorate(this, null, _login_decorators, { kind: "method", name: "login", static: false, private: false, access: { has: obj => "login" in obj, get: obj => obj.login }, metadata: _metadata }, null, _instanceExtraInitializers);
93
+ __esDecorate(this, null, _logout_decorators, { kind: "method", name: "logout", static: false, private: false, access: { has: obj => "logout" in obj, get: obj => obj.logout }, metadata: _metadata }, null, _instanceExtraInitializers);
94
+ __esDecorate(this, null, _createToken_decorators, { kind: "method", name: "createToken", static: false, private: false, access: { has: obj => "createToken" in obj, get: obj => obj.createToken }, metadata: _metadata }, null, _instanceExtraInitializers);
95
+ __esDecorate(this, null, _setPassword_decorators, { kind: "method", name: "setPassword", static: false, private: false, access: { has: obj => "setPassword" in obj, get: obj => obj.setPassword }, metadata: _metadata }, null, _instanceExtraInitializers);
96
+ __esDecorate(this, null, _getSessions_decorators, { kind: "method", name: "getSessions", static: false, private: false, access: { has: obj => "getSessions" in obj, get: obj => obj.getSessions }, metadata: _metadata }, null, _instanceExtraInitializers);
97
+ __esDecorate(this, null, _changeThumbnail_decorators, { kind: "method", name: "changeThumbnail", static: false, private: false, access: { has: obj => "changeThumbnail" in obj, get: obj => obj.changeThumbnail }, metadata: _metadata }, null, _instanceExtraInitializers);
98
+ __esDecorate(this, null, _loginSaml_decorators, { kind: "method", name: "loginSaml", static: false, private: false, access: { has: obj => "loginSaml" in obj, get: obj => obj.loginSaml }, metadata: _metadata }, null, _instanceExtraInitializers);
99
+ __esDecorate(this, null, _assertSAML_decorators, { kind: "method", name: "assertSAML", static: false, private: false, access: { has: obj => "assertSAML" in obj, get: obj => obj.assertSAML }, metadata: _metadata }, null, _instanceExtraInitializers);
100
+ __esDecorate(this, null, _getPasswordAssertionConfig_decorators, { kind: "method", name: "getPasswordAssertionConfig", static: false, private: false, access: { has: obj => "getPasswordAssertionConfig" in obj, get: obj => obj.getPasswordAssertionConfig }, metadata: _metadata }, null, _instanceExtraInitializers);
101
+ __esDecorate(this, null, _deleteAccount_decorators, { kind: "method", name: "deleteAccount", static: false, private: false, access: { has: obj => "deleteAccount" in obj, get: obj => obj.deleteAccount }, metadata: _metadata }, null, _instanceExtraInitializers);
102
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
103
+ }
104
+ status = (__runInitializers(this, _instanceExtraInitializers), LoggedStatus.LOGGED_OUT);
105
+ __onLoginStatusUpdated() {
106
+ if ([LoggedStatus.LOGGED_OUT, LoggedStatus.SESSION_TIMEOUT].includes(this.status))
107
+ void this.getPasswordAssertionConfig({});
108
+ }
109
+ constructor() {
110
+ super({
111
+ config: buildConfigFromDBDef(DBDef_Accounts),
112
+ crudApiDef: CrudApiDef(DBDef_Accounts.dbKey),
113
+ dispatcher: (...args) => dispatch_onAccountsUpdated.dispatchAll(...args)
114
+ });
115
+ }
116
+ async refreshSession(_params) {
117
+ return undefined;
118
+ }
119
+ async registerAccount(body) {
120
+ void body;
121
+ return undefined;
122
+ }
123
+ async createAccount(body) {
124
+ void body;
125
+ return undefined;
126
+ }
127
+ async changePassword(body) {
128
+ void body;
129
+ return undefined;
130
+ }
131
+ async login(body) {
132
+ void body;
133
+ return undefined;
134
+ }
135
+ async logout(_params) {
136
+ return undefined;
137
+ }
138
+ async createToken(body) {
139
+ void body;
140
+ return undefined;
141
+ }
142
+ async setPassword(body) {
143
+ void body;
144
+ return undefined;
145
+ }
146
+ async getSessions(params) {
147
+ void params;
148
+ return undefined;
149
+ }
150
+ async changeThumbnail(body) {
151
+ void body;
152
+ return undefined;
153
+ }
154
+ async loginSaml(params) {
155
+ void params;
156
+ return undefined;
157
+ }
158
+ async assertSAML(body) {
159
+ void body;
160
+ return undefined;
161
+ }
162
+ async getPasswordAssertionConfig(_params) {
163
+ return undefined;
164
+ }
165
+ async deleteAccount(params) {
166
+ void params;
167
+ return undefined;
168
+ }
169
+ init() {
170
+ super.init();
171
+ let defaultTabId = StorageKey_TabId.get();
172
+ let defaultDeviceId = StorageKey_DeviceId.get();
173
+ if (!defaultDeviceId) {
174
+ defaultDeviceId = generateHex(32);
175
+ console.log(`Defining new device Id: ${defaultDeviceId}`);
176
+ StorageKey_DeviceId.set(defaultDeviceId);
122
177
  }
123
- catch (err) {
124
- this.logError(err.message, err);
178
+ if (!defaultTabId) {
179
+ defaultTabId = generateHex(32);
180
+ console.log(`Defining new tab Id: ${defaultTabId}`);
181
+ StorageKey_TabId.set(defaultTabId);
125
182
  }
126
- });
127
- input.click();
128
- };
129
- encodeFile = async (file) => {
130
- const arrayBuffer = await readFileContent(file);
131
- if (arrayBuffer.byteLength > 200 * KB)
132
- throw new Exception('File size exceeds 200KB');
133
- const buffer = new Uint8Array(arrayBuffer);
134
- return window.btoa(buffer.reduce((acc, byte) => acc + String.fromCharCode(byte), ''));
135
- };
136
- getPasswordAssertionConfig = () => StorageKey_PasswordAssertionConfig.get();
137
- getCurrentlyLoggedAccount = () => {
138
- return SessionKeyFE_Account.get();
139
- };
140
- // ######################## API Callbacks ########################
141
- onAccountCreated = async (response) => {
142
- await this.onEntriesUpdated([response]);
143
- };
144
- onThumbnailChanged = async (response) => {
145
- await this.onEntryUpdated(response.account, response.account);
146
- };
147
- onLoginCompletedSAML = async (response) => {
148
- if (!response.loginUrl)
149
- return;
150
- window.location.href = response.loginUrl;
151
- };
152
- onPasswordAssertionConfig = async (response) => {
153
- StorageKey_PasswordAssertionConfig.set(response.config);
183
+ HttpClient.default.addDefaultHeader(HeaderKey_DeviceId, () => defaultDeviceId);
184
+ HttpClient.default.addDefaultHeader(HeaderKey_TabId, () => defaultTabId);
185
+ }
186
+ getAccounts() {
187
+ return this.cache.all().map(i => cloneObj(i));
188
+ }
189
+ getLoggedStatus = () => this.status;
190
+ isStatus = (status) => asArray(status).includes(this.status);
191
+ __onSessionUpdated() {
192
+ if (!ModuleFE_Session.hasSession())
193
+ return this.setLoggedStatus(LoggedStatus.LOGGED_OUT);
194
+ if (!ModuleFE_Session.isSessionValid())
195
+ return this.setLoggedStatus(LoggedStatus.SESSION_TIMEOUT);
196
+ return this.setLoggedStatus(LoggedStatus.LOGGED_IN);
197
+ }
198
+ setLoggedStatus = (newStatus) => {
199
+ if (this.status === newStatus)
200
+ return;
201
+ const pervStatus = this.status;
202
+ this.status = newStatus;
203
+ this.logInfo(`Login status changes: ${LoggedStatus[pervStatus]} => ${LoggedStatus[newStatus]}`);
204
+ dispatch_onLoginStatusChanged.dispatchAll();
205
+ };
206
+ composeSAMLUrl = () => {
207
+ const params = new URLSearchParams(window.location.search);
208
+ const paramsObj = {};
209
+ for (const [key, value] of params) {
210
+ paramsObj[key] = value;
211
+ }
212
+ return composeUrl(window.location.origin + window.location.pathname, {
213
+ ...paramsObj,
214
+ [QueryParam_SessionId]: QueryParam_SessionId.toUpperCase(),
215
+ });
216
+ };
217
+ performLogout = async (url) => {
218
+ await this.logout({});
219
+ dispatcher_onAuthRequired.dispatchModule();
220
+ if (url)
221
+ return window.location.href = url;
222
+ };
223
+ uploadAccountThumbnail = (e, account) => {
224
+ const input = document.createElement('input');
225
+ input.type = 'file';
226
+ // input.accept = '.jpg,.jpeg,.png';
227
+ input.style.display = 'none';
228
+ input.addEventListener('change', async (e) => {
229
+ const file = input.files[0];
230
+ if (!file)
231
+ return;
232
+ try {
233
+ const hash = await this.encodeFile(file);
234
+ await this.changeThumbnail({ accountId: account._id, hash });
235
+ }
236
+ catch (err) {
237
+ this.logError(err.message, err);
238
+ }
239
+ });
240
+ input.click();
241
+ };
242
+ encodeFile = async (file) => {
243
+ const arrayBuffer = await readFileAs_ArrayBuffer(file);
244
+ if (arrayBuffer.byteLength > 200 * KB)
245
+ throw new Exception('File size exceeds 200KB');
246
+ const buffer = new Uint8Array(arrayBuffer);
247
+ return window.btoa(buffer.reduce((acc, byte) => acc + String.fromCharCode(byte), ''));
248
+ };
249
+ passwordAssertionConfig = () => StorageKey_PasswordAssertionConfig.get();
250
+ getCurrentlyLoggedAccount = () => {
251
+ return SessionKeyFE_Account.get();
252
+ };
253
+ onAccountCreated = async (ctx) => {
254
+ await this.onEntriesUpdated([ctx.response]);
255
+ };
256
+ onThumbnailChanged = async (ctx) => {
257
+ await this.onEntryUpdated(ctx.response.account, ctx.response.account);
258
+ };
259
+ onLoginCompletedSAML = async (ctx) => {
260
+ if (!ctx.response.loginUrl)
261
+ return;
262
+ window.location.href = ctx.response.loginUrl;
263
+ };
264
+ onPasswordAssertionConfig = async (ctx) => {
265
+ StorageKey_PasswordAssertionConfig.set(ctx.response.config);
266
+ };
267
+ onAccountDeleted = async (ctx) => {
268
+ await this.onEntryDeleted(ctx.response.account);
269
+ };
154
270
  };
155
- }
271
+ })();
156
272
  export const ModuleFE_Account = new ModuleFE_Account_Class();
@@ -1,7 +1,7 @@
1
- import { StorageKey } from '@nu-art/thunderstorm-frontend/index';
2
1
  import { _SessionKey_Account, DB_Account } from '@nu-art/user-account-shared';
3
2
  import { SessionKey_FE } from '../session/ModuleFE_Session.js';
4
3
  import { TypedKeyValue } from '@nu-art/ts-common';
4
+ import { StorageKey } from '@nu-art/thunder-core';
5
5
  export declare const SessionKeyFE_Account: SessionKey_FE<_SessionKey_Account>;
6
6
  export declare const StorageKey_DeviceId: StorageKey<string>;
7
7
  export declare const StorageKey_TabId: StorageKey<string>;
@@ -1,6 +1,6 @@
1
- import { StorageKey } from '@nu-art/thunderstorm-frontend/index';
2
- import { HeaderKey_DeviceId, HeaderKey_TabId } from '@nu-art/thunderstorm-shared/headers';
1
+ import { HeaderKey_DeviceId, HeaderKey_TabId } from '@nu-art/user-account-shared';
3
2
  import { SessionKey_FE } from '../session/ModuleFE_Session.js';
3
+ import { StorageKey } from '@nu-art/thunder-core';
4
4
  export const SessionKeyFE_Account = new SessionKey_FE('account');
5
5
  export const StorageKey_DeviceId = new StorageKey(`storage--${HeaderKey_DeviceId}`).withstandDeletion();
6
6
  export const StorageKey_TabId = new StorageKey(`storage--${HeaderKey_TabId}`, false).withstandDeletion();
@@ -1,7 +1,6 @@
1
- import { OnStorageKeyChangedListener, StorageKey, ThunderDispatcher } from '@nu-art/thunderstorm-frontend/index';
1
+ import { OnStorageKeyChangedListener, StorageKey, ThunderDispatcher } from '@nu-art/thunder-core';
2
2
  import { Module, ResolvableContent, TS_Object, TypedKeyValue } from '@nu-art/ts-common';
3
- import { BaseHttpRequest } from '@nu-art/thunderstorm-shared';
4
- import { OnAuthRequiredListener } from '@nu-art/thunderstorm-shared/no-auth-listener';
3
+ import { OnAuthRequiredListener } from './no-auth-listener.js';
5
4
  export interface OnSessionUpdated {
6
5
  __onSessionUpdated: VoidFunction;
7
6
  }
@@ -23,7 +22,7 @@ declare class ModuleFE_Session_Class extends Module implements OnStorageKeyChang
23
22
  init(): void;
24
23
  setSessionKey(sessionKey: ResolvableContent<string>): void;
25
24
  __onStorageKeyEvent(event: StorageEvent): Promise<void>;
26
- __onAuthRequiredListener(request: BaseHttpRequest<any>): void;
25
+ __onAuthRequiredListener(): void;
27
26
  private onSessionUpdated;
28
27
  hasSession(): boolean;
29
28
  isSessionValid(): Promise<boolean>;