@nu-art/user-account-shared 0.400.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_entity/account/api-def.d.ts +115 -0
- package/_entity/account/api-def.js +24 -0
- package/_entity/account/db-def.d.ts +3 -0
- package/_entity/account/db-def.js +30 -0
- package/_entity/account/index.d.ts +3 -0
- package/_entity/account/index.js +3 -0
- package/_entity/account/types.d.ts +34 -0
- package/_entity/account/types.js +5 -0
- package/_entity/failed-login-attempt/consts.d.ts +2 -0
- package/_entity/failed-login-attempt/consts.js +2 -0
- package/_entity/failed-login-attempt/db-def.d.ts +3 -0
- package/_entity/failed-login-attempt/db-def.js +22 -0
- package/_entity/failed-login-attempt/index.d.ts +3 -0
- package/_entity/failed-login-attempt/index.js +4 -0
- package/_entity/failed-login-attempt/types.d.ts +18 -0
- package/_entity/failed-login-attempt/types.js +1 -0
- package/_entity/login-attempts/db-def.d.ts +3 -0
- package/_entity/login-attempts/db-def.js +25 -0
- package/_entity/login-attempts/index.d.ts +2 -0
- package/_entity/login-attempts/index.js +3 -0
- package/_entity/login-attempts/types.d.ts +25 -0
- package/_entity/login-attempts/types.js +3 -0
- package/_entity/session/consts.d.ts +5 -0
- package/_entity/session/consts.js +6 -0
- package/_entity/session/db-def.d.ts +5 -0
- package/_entity/session/db-def.js +25 -0
- package/_entity/session/index.d.ts +3 -0
- package/_entity/session/index.js +3 -0
- package/_entity/session/types.d.ts +21 -0
- package/_entity/session/types.js +1 -0
- package/_entity.d.ts +4 -0
- package/_entity.js +4 -0
- package/_enum/password-assertion/index.d.ts +2 -0
- package/_enum/password-assertion/index.js +2 -0
- package/_enum/password-assertion/types.d.ts +16 -0
- package/_enum/password-assertion/types.js +14 -0
- package/_enum/password-assertion/validator.d.ts +2 -0
- package/_enum/password-assertion/validator.js +39 -0
- package/_enum.d.ts +1 -0
- package/_enum.js +1 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +77 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ApiDefResolver, BodyApi, QueryApi } from '@nu-art/thunderstorm-shared';
|
|
2
|
+
import { DB_BaseObject, UniqueId } from '@nu-art/ts-common';
|
|
3
|
+
import { AccountType, DB_Account, UI_Account } from './types.js';
|
|
4
|
+
import { DB_Session, QueryParam_RedirectUrl } from '../session/index.js';
|
|
5
|
+
import { PasswordAssertionConfig } from '../../_enum/password-assertion/index.js';
|
|
6
|
+
export type Response_Auth = UI_Account & DB_BaseObject;
|
|
7
|
+
export type AccountEmail = {
|
|
8
|
+
email: string;
|
|
9
|
+
};
|
|
10
|
+
export type AccountEmailWithDevice = AccountEmail & {
|
|
11
|
+
deviceId: string;
|
|
12
|
+
};
|
|
13
|
+
export type AccountPassword = {
|
|
14
|
+
password: string;
|
|
15
|
+
};
|
|
16
|
+
export type PasswordWithCheck = AccountPassword & {
|
|
17
|
+
passwordCheck: string;
|
|
18
|
+
};
|
|
19
|
+
export type DBAccountType = {
|
|
20
|
+
type: AccountType;
|
|
21
|
+
};
|
|
22
|
+
export type AccountToAssertPassword = AccountEmail & Partial<PasswordWithCheck>;
|
|
23
|
+
export type AccountToSpice = AccountEmail & AccountPassword;
|
|
24
|
+
export type Request_RegisterAccount = DBAccountType & AccountEmailWithDevice & PasswordWithCheck;
|
|
25
|
+
export type Account_RegisterAccount = {
|
|
26
|
+
request: AccountEmailWithDevice & PasswordWithCheck;
|
|
27
|
+
response: Response_Auth;
|
|
28
|
+
};
|
|
29
|
+
export type Account_CreateAccount = {
|
|
30
|
+
request: DBAccountType & AccountEmail & Partial<PasswordWithCheck>;
|
|
31
|
+
response: UI_Account & DB_BaseObject;
|
|
32
|
+
};
|
|
33
|
+
export type Account_ChangePassword = {
|
|
34
|
+
request: PasswordWithCheck & {
|
|
35
|
+
oldPassword: string;
|
|
36
|
+
};
|
|
37
|
+
response: Response_Auth;
|
|
38
|
+
};
|
|
39
|
+
export type Account_Login = {
|
|
40
|
+
request: AccountEmailWithDevice & AccountPassword;
|
|
41
|
+
response: Response_Auth;
|
|
42
|
+
};
|
|
43
|
+
export type Account_CreateToken = {
|
|
44
|
+
request: {
|
|
45
|
+
accountId: UniqueId;
|
|
46
|
+
ttl: number;
|
|
47
|
+
label: string;
|
|
48
|
+
};
|
|
49
|
+
response: {
|
|
50
|
+
token: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export type Account_SetPassword = {
|
|
54
|
+
request: PasswordWithCheck;
|
|
55
|
+
response: Response_Auth;
|
|
56
|
+
};
|
|
57
|
+
export type Account_GetSessions = {
|
|
58
|
+
request: DB_BaseObject;
|
|
59
|
+
response: {
|
|
60
|
+
sessions: DB_Session[];
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export type Account_ChangeThumbnail = {
|
|
64
|
+
request: {
|
|
65
|
+
accountId: string;
|
|
66
|
+
hash: string;
|
|
67
|
+
};
|
|
68
|
+
response: {
|
|
69
|
+
account: DB_Account;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export type Account_GetPasswordAssertionConfig = {
|
|
73
|
+
request: void;
|
|
74
|
+
response: {
|
|
75
|
+
config: PasswordAssertionConfig | undefined;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export type ApiStruct_Account = {
|
|
79
|
+
_v1: {
|
|
80
|
+
registerAccount: BodyApi<Account_RegisterAccount['response'], Account_RegisterAccount['request']>;
|
|
81
|
+
refreshSession: QueryApi<void>;
|
|
82
|
+
createAccount: BodyApi<Account_CreateAccount['response'], Account_CreateAccount['request']>;
|
|
83
|
+
changePassword: BodyApi<Account_ChangePassword['response'], Account_ChangePassword['request']>;
|
|
84
|
+
login: BodyApi<Account_Login['response'], Account_Login['request']>;
|
|
85
|
+
logout: QueryApi<void>;
|
|
86
|
+
createToken: BodyApi<Account_CreateToken['response'], Account_CreateToken['request']>;
|
|
87
|
+
setPassword: BodyApi<Account_SetPassword['response'], Account_SetPassword['request']>;
|
|
88
|
+
getSessions: QueryApi<Account_GetSessions['response'], Account_GetSessions['request']>;
|
|
89
|
+
changeThumbnail: BodyApi<Account_ChangeThumbnail['response'], Account_ChangeThumbnail['request']>;
|
|
90
|
+
getPasswordAssertionConfig: QueryApi<Account_GetPasswordAssertionConfig['response']>;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
export declare const ApiDef_Account: ApiDefResolver<ApiStruct_Account>;
|
|
94
|
+
export type SAML_Login = {
|
|
95
|
+
request: {
|
|
96
|
+
[QueryParam_RedirectUrl]: string;
|
|
97
|
+
deviceId: string;
|
|
98
|
+
};
|
|
99
|
+
response: {
|
|
100
|
+
loginUrl: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
export type SAML_Assert = {
|
|
104
|
+
request: {
|
|
105
|
+
RelayState: string;
|
|
106
|
+
};
|
|
107
|
+
response: void;
|
|
108
|
+
};
|
|
109
|
+
export type ApiStruct_SAML = {
|
|
110
|
+
_v1: {
|
|
111
|
+
loginSaml: QueryApi<SAML_Login['response'], SAML_Login['request']>;
|
|
112
|
+
assertSAML: BodyApi<SAML_Assert['response'], SAML_Assert['request']>;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export declare const ApiDef_SAML: ApiDefResolver<ApiStruct_SAML>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HttpMethod } from '@nu-art/thunderstorm-shared';
|
|
2
|
+
import { Minute } from '@nu-art/ts-common';
|
|
3
|
+
import { QueryParam_RedirectUrl } from '../session/index.js';
|
|
4
|
+
export const ApiDef_Account = {
|
|
5
|
+
_v1: {
|
|
6
|
+
registerAccount: { method: HttpMethod.POST, path: '/v1/account/register-account' },
|
|
7
|
+
refreshSession: { method: HttpMethod.GET, path: '/v1/account/refresh-session' },
|
|
8
|
+
createAccount: { method: HttpMethod.POST, path: '/v1/account/create-account' },
|
|
9
|
+
changePassword: { method: HttpMethod.POST, path: '/v1/account/change-password' },
|
|
10
|
+
login: { method: HttpMethod.POST, path: 'v1/account/login', timeout: Minute },
|
|
11
|
+
logout: { method: HttpMethod.GET, path: 'v1/account/logout' },
|
|
12
|
+
createToken: { method: HttpMethod.POST, path: 'v1/account/create-token', timeout: Minute },
|
|
13
|
+
setPassword: { method: HttpMethod.POST, path: '/v1/account/set-password' },
|
|
14
|
+
getSessions: { method: HttpMethod.GET, path: 'v1/account/get-sessions' },
|
|
15
|
+
changeThumbnail: { method: HttpMethod.POST, path: '/v1/account/change-thumbnail' },
|
|
16
|
+
getPasswordAssertionConfig: { method: HttpMethod.GET, path: '/v1/account/get-password-assertion-config' }
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const ApiDef_SAML = {
|
|
20
|
+
_v1: {
|
|
21
|
+
loginSaml: { method: HttpMethod.GET, path: 'v1/account/login-saml' },
|
|
22
|
+
assertSAML: { method: HttpMethod.POST, path: 'v1/account/assert' }
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { tsValidateBoolean, tsValidateEmail, tsValidateString, tsValidateValue, tsValidator_nonMandatoryString } from '@nu-art/ts-common';
|
|
2
|
+
import { _accountTypes } from './types.js';
|
|
3
|
+
import { accountGroupName } from '../session/consts.js';
|
|
4
|
+
const modifiablePropsValidator = {
|
|
5
|
+
email: tsValidateEmail,
|
|
6
|
+
type: tsValidateValue(_accountTypes),
|
|
7
|
+
thumbnail: tsValidateString(undefined, false),
|
|
8
|
+
displayName: tsValidateString(undefined, false),
|
|
9
|
+
description: tsValidateString(undefined, false)
|
|
10
|
+
};
|
|
11
|
+
const generatedPropsValidator = {
|
|
12
|
+
_auditorId: tsValidateString(),
|
|
13
|
+
_newPasswordRequired: tsValidateBoolean(false),
|
|
14
|
+
salt: tsValidator_nonMandatoryString,
|
|
15
|
+
saltedPassword: tsValidator_nonMandatoryString,
|
|
16
|
+
};
|
|
17
|
+
export const DBDef_Accounts = {
|
|
18
|
+
dbKey: 'user-account--accounts',
|
|
19
|
+
entityName: 'Account',
|
|
20
|
+
modifiablePropsValidator: modifiablePropsValidator,
|
|
21
|
+
generatedPropsValidator: generatedPropsValidator,
|
|
22
|
+
versions: ['1.0.0'],
|
|
23
|
+
frontend: {
|
|
24
|
+
group: accountGroupName,
|
|
25
|
+
name: 'account'
|
|
26
|
+
},
|
|
27
|
+
backend: {
|
|
28
|
+
name: 'user-account--accounts',
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AuditableV2, DB_BaseObject, DB_Object, DBProto, Proto_DB_Object, TypedKeyValue, VersionsDeclaration } from '@nu-art/ts-common';
|
|
2
|
+
export declare const AccountType_User: AccountType;
|
|
3
|
+
export declare const AccountType_Service: AccountType;
|
|
4
|
+
export declare const _accountTypes: string[];
|
|
5
|
+
export declare const accountTypes: readonly string[];
|
|
6
|
+
export type AccountType = typeof accountTypes[number];
|
|
7
|
+
type VersionTypes_Account = {
|
|
8
|
+
'1.0.0': DB_Account;
|
|
9
|
+
};
|
|
10
|
+
type Versions = VersionsDeclaration<['1.0.0'], VersionTypes_Account>;
|
|
11
|
+
type Dependencies = {};
|
|
12
|
+
type UniqueKeys = '_id';
|
|
13
|
+
type GeneratedKeys = keyof AuditableV2 | '_newPasswordRequired' | 'salt' | 'saltedPassword';
|
|
14
|
+
export declare const Account_DbKey = "user-account--accounts";
|
|
15
|
+
type Proto = Proto_DB_Object<DB_Account, typeof Account_DbKey, GeneratedKeys, Versions, UniqueKeys, Dependencies>;
|
|
16
|
+
export type DBProto_Account = DBProto<Proto>;
|
|
17
|
+
export type UI_Account = DBProto_Account['uiType'];
|
|
18
|
+
export type SafeDB_Account = UI_Account & DB_BaseObject;
|
|
19
|
+
export type UI_SessionAccount = UI_Account & DB_BaseObject & SessionData_HasPassword;
|
|
20
|
+
export type _SessionKey_Account = TypedKeyValue<'account', UI_SessionAccount>;
|
|
21
|
+
export type DB_Account = DB_Object & AuditableV2 & {
|
|
22
|
+
type: AccountType;
|
|
23
|
+
email: string;
|
|
24
|
+
displayName?: string;
|
|
25
|
+
thumbnail?: string;
|
|
26
|
+
salt?: string;
|
|
27
|
+
saltedPassword?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
_newPasswordRequired?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type SessionData_HasPassword = {
|
|
32
|
+
hasPassword: boolean;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { tsValidateNumber, tsValidateUniqueId } from '@nu-art/ts-common';
|
|
2
|
+
import { accountGroupName } from '../session/index.js';
|
|
3
|
+
const Validator_ModifiableProps = {
|
|
4
|
+
count: tsValidateNumber(),
|
|
5
|
+
accountId: tsValidateUniqueId,
|
|
6
|
+
loginSuccessfulAt: tsValidateNumber(false)
|
|
7
|
+
};
|
|
8
|
+
const Validator_GeneratedProps = {};
|
|
9
|
+
export const DBDef_FailedLoginAttempt = {
|
|
10
|
+
modifiablePropsValidator: Validator_ModifiableProps,
|
|
11
|
+
generatedPropsValidator: Validator_GeneratedProps,
|
|
12
|
+
versions: ['1.0.0'],
|
|
13
|
+
dbKey: 'failed-login-attempt',
|
|
14
|
+
entityName: 'failed-login-attempt',
|
|
15
|
+
frontend: {
|
|
16
|
+
group: accountGroupName,
|
|
17
|
+
name: 'failed-login-attempt'
|
|
18
|
+
},
|
|
19
|
+
backend: {
|
|
20
|
+
name: 'user-account--failed-login-attempt'
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DB_Object, DBProto, Proto_DB_Object, UniqueId, VersionsDeclaration } from '@nu-art/ts-common';
|
|
2
|
+
type VersionTypes_FailedLoginAttempt = {
|
|
3
|
+
'1.0.0': DB_FailedLoginAttempt;
|
|
4
|
+
};
|
|
5
|
+
type Versions = VersionsDeclaration<['1.0.0'], VersionTypes_FailedLoginAttempt>;
|
|
6
|
+
type Dependencies = {};
|
|
7
|
+
type UniqueKeys = '_id';
|
|
8
|
+
type GeneratedProps = never;
|
|
9
|
+
type DBKey = 'failed-login-attempt';
|
|
10
|
+
type Proto = Proto_DB_Object<DB_FailedLoginAttempt, DBKey, GeneratedProps, Versions, UniqueKeys, Dependencies>;
|
|
11
|
+
export type DBProto_FailedLoginAttempt = DBProto<Proto>;
|
|
12
|
+
export type UI_FailedLoginAttempt = DBProto_FailedLoginAttempt['uiType'];
|
|
13
|
+
export type DB_FailedLoginAttempt = DB_Object & {
|
|
14
|
+
accountId: UniqueId;
|
|
15
|
+
count: number;
|
|
16
|
+
loginSuccessfulAt?: number;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { tsValidateIpAddress, tsValidateOptionalId, tsValidateUniqueId, tsValidateValue } from '@nu-art/ts-common';
|
|
2
|
+
import { LoginStatus_Failed, LoginStatus_Success } from './types.js';
|
|
3
|
+
const Validator_ModifiableProps = {
|
|
4
|
+
accountId: tsValidateUniqueId,
|
|
5
|
+
status: tsValidateValue([LoginStatus_Success, LoginStatus_Failed]),
|
|
6
|
+
metadata: {
|
|
7
|
+
ipAddress: tsValidateIpAddress(false),
|
|
8
|
+
deviceId: tsValidateOptionalId
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const Validator_GeneratedProps = {};
|
|
12
|
+
export const DBDef_LoginAttempt = {
|
|
13
|
+
modifiablePropsValidator: Validator_ModifiableProps,
|
|
14
|
+
generatedPropsValidator: Validator_GeneratedProps,
|
|
15
|
+
versions: ['1.0.0'],
|
|
16
|
+
dbKey: 'login-attempt',
|
|
17
|
+
entityName: 'login-attempt',
|
|
18
|
+
frontend: {
|
|
19
|
+
group: 'ts-default',
|
|
20
|
+
name: 'login-attempt'
|
|
21
|
+
},
|
|
22
|
+
backend: {
|
|
23
|
+
name: 'user-account--login-attempt'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DB_Object, DBProto, Proto_DB_Object, UniqueId, VersionsDeclaration } from '@nu-art/ts-common';
|
|
2
|
+
type VersionTypes_LoginAttempt = {
|
|
3
|
+
'1.0.0': DB_LoginAttempt;
|
|
4
|
+
};
|
|
5
|
+
type Versions = VersionsDeclaration<['1.0.0'], VersionTypes_LoginAttempt>;
|
|
6
|
+
type Dependencies = {};
|
|
7
|
+
type UniqueKeys = '_id';
|
|
8
|
+
type GeneratedProps = never;
|
|
9
|
+
type DBKey = 'login-attempt';
|
|
10
|
+
type Proto = Proto_DB_Object<DB_LoginAttempt, DBKey, GeneratedProps, Versions, UniqueKeys, Dependencies>;
|
|
11
|
+
export type DBProto_LoginAttempt = DBProto<Proto>;
|
|
12
|
+
export type UI_LoginAttempt = DBProto_LoginAttempt['uiType'];
|
|
13
|
+
export declare const LoginStatus_Success = "success";
|
|
14
|
+
export declare const LoginStatus_Failed = "failed";
|
|
15
|
+
export type LoginStatus = typeof LoginStatus_Failed | typeof LoginStatus_Success;
|
|
16
|
+
export type LoginMetadata = {
|
|
17
|
+
ipAddress?: string;
|
|
18
|
+
deviceId?: string;
|
|
19
|
+
};
|
|
20
|
+
export type DB_LoginAttempt = DB_Object & {
|
|
21
|
+
accountId: UniqueId;
|
|
22
|
+
status: LoginStatus;
|
|
23
|
+
metadata: LoginMetadata;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const accountGroupName = "account";
|
|
2
|
+
export declare const QueryParam_Email = "userEmail";
|
|
3
|
+
export declare const QueryParam_SessionId = "Authorization";
|
|
4
|
+
export declare const QueryParam_RedirectUrl = "redirectUrl";
|
|
5
|
+
export declare const HeaderKey_CurrentPage = "current-page";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HeaderKey_Authorization } from '@nu-art/thunderstorm-shared';
|
|
2
|
+
export const accountGroupName = 'account';
|
|
3
|
+
export const QueryParam_Email = 'userEmail';
|
|
4
|
+
export const QueryParam_SessionId = HeaderKey_Authorization;
|
|
5
|
+
export const QueryParam_RedirectUrl = 'redirectUrl';
|
|
6
|
+
export const HeaderKey_CurrentPage = 'current-page';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DBDef_V3 } from '@nu-art/ts-common';
|
|
2
|
+
import { DBProto_Session } from './types.js';
|
|
3
|
+
export declare const Validator_Modifiable: DBProto_Session['modifiablePropsValidator'];
|
|
4
|
+
export declare const Validator_Generated: DBProto_Session['generatedPropsValidator'];
|
|
5
|
+
export declare const DBDef_Session: DBDef_V3<DBProto_Session>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { tsValidateArray, tsValidateOptionalId, tsValidateString, tsValidateUniqueId } from '@nu-art/ts-common';
|
|
2
|
+
import { accountGroupName } from './consts.js';
|
|
3
|
+
export const Validator_Modifiable = {
|
|
4
|
+
label: tsValidateString(100, false),
|
|
5
|
+
accountId: tsValidateUniqueId,
|
|
6
|
+
deviceId: tsValidateUniqueId,
|
|
7
|
+
linkedSessionId: tsValidateOptionalId,
|
|
8
|
+
validSessionJwtMd5s: tsValidateArray(tsValidateUniqueId), //array of MD5s of previous sessions.
|
|
9
|
+
sessionIdJwt: tsValidateString(),
|
|
10
|
+
};
|
|
11
|
+
export const Validator_Generated = {};
|
|
12
|
+
export const DBDef_Session = {
|
|
13
|
+
modifiablePropsValidator: Validator_Modifiable,
|
|
14
|
+
generatedPropsValidator: Validator_Generated,
|
|
15
|
+
dbKey: 'user-account--sessions',
|
|
16
|
+
entityName: 'Session',
|
|
17
|
+
versions: ['1.0.0'],
|
|
18
|
+
frontend: {
|
|
19
|
+
group: accountGroupName,
|
|
20
|
+
name: 'session',
|
|
21
|
+
},
|
|
22
|
+
backend: {
|
|
23
|
+
name: 'user-account--sessions'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DB_Object, DBProto, Proto_DB_Object, TypedKeyValue, UniqueId, VersionsDeclaration } from '@nu-art/ts-common';
|
|
2
|
+
type VersionTypes = {
|
|
3
|
+
'1.0.0': DB_Session;
|
|
4
|
+
};
|
|
5
|
+
type Versions = VersionsDeclaration<['1.0.0'], VersionTypes>;
|
|
6
|
+
type UniqueIds = 'accountId' | 'deviceId';
|
|
7
|
+
type DBKey = 'user-account--sessions';
|
|
8
|
+
type GeneratedKeys = keyof DB_Object;
|
|
9
|
+
type Proto = Proto_DB_Object<DB_Session, DBKey, GeneratedKeys, Versions, UniqueIds>;
|
|
10
|
+
export type DBProto_Session = DBProto<Proto>;
|
|
11
|
+
export type UI_Session = DBProto_Session['uiType'];
|
|
12
|
+
export type DB_Session = DB_Object & {
|
|
13
|
+
validSessionJwtMd5s: UniqueId[];
|
|
14
|
+
label?: string;
|
|
15
|
+
accountId: UniqueId;
|
|
16
|
+
deviceId: UniqueId;
|
|
17
|
+
linkedSessionId?: UniqueId;
|
|
18
|
+
sessionIdJwt: string;
|
|
19
|
+
};
|
|
20
|
+
export type _SessionKey_SessionId = TypedKeyValue<'_id', UniqueId>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/_entity.d.ts
ADDED
package/_entity.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ResponseError } from '@nu-art/ts-common/core/exceptions/types';
|
|
2
|
+
export declare const PasswordAssertionType_MinLength = "min-length";
|
|
3
|
+
export declare const PasswordAssertionType_MaxLength = "max-length";
|
|
4
|
+
export declare const PasswordAssertionType_SpecialChars = "special-chars";
|
|
5
|
+
export declare const PasswordAssertionType_Numbers = "numbers";
|
|
6
|
+
export declare const PasswordAssertionType_LowerCaseLetters = "lower-case-letters";
|
|
7
|
+
export declare const PasswordAssertionType_CapitalLetters = "capital-letters";
|
|
8
|
+
export declare const PasswordAssertionTypes: readonly ["min-length", "max-length", "special-chars", "numbers", "lower-case-letters", "capital-letters"];
|
|
9
|
+
export type PasswordAssertionType = typeof PasswordAssertionTypes[number];
|
|
10
|
+
export type PasswordAssertionConfig = {
|
|
11
|
+
[K in PasswordAssertionType]?: number;
|
|
12
|
+
};
|
|
13
|
+
export type PasswordFailureReport = {
|
|
14
|
+
[K in PasswordAssertionType]?: string;
|
|
15
|
+
};
|
|
16
|
+
export type PasswordAssertionResponseError = ResponseError<'password-assertion-error', PasswordFailureReport>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const PasswordAssertionType_MinLength = 'min-length';
|
|
2
|
+
export const PasswordAssertionType_MaxLength = 'max-length';
|
|
3
|
+
export const PasswordAssertionType_SpecialChars = 'special-chars';
|
|
4
|
+
export const PasswordAssertionType_Numbers = 'numbers';
|
|
5
|
+
export const PasswordAssertionType_LowerCaseLetters = 'lower-case-letters';
|
|
6
|
+
export const PasswordAssertionType_CapitalLetters = 'capital-letters';
|
|
7
|
+
export const PasswordAssertionTypes = [
|
|
8
|
+
PasswordAssertionType_MinLength,
|
|
9
|
+
PasswordAssertionType_MaxLength,
|
|
10
|
+
PasswordAssertionType_SpecialChars,
|
|
11
|
+
PasswordAssertionType_Numbers,
|
|
12
|
+
PasswordAssertionType_LowerCaseLetters,
|
|
13
|
+
PasswordAssertionType_CapitalLetters,
|
|
14
|
+
];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { _keys, generateArray, tsValidateRegexp, tsValidateResult, tsValidateString, tsValidateStringMinLength } from '@nu-art/ts-common';
|
|
2
|
+
import { PasswordAssertionType_CapitalLetters, PasswordAssertionType_LowerCaseLetters, PasswordAssertionType_MaxLength, PasswordAssertionType_MinLength, PasswordAssertionType_Numbers, PasswordAssertionType_SpecialChars, PasswordAssertionTypes } from './types.js';
|
|
3
|
+
const specialChars = '.*?[!@#$%^&*()_\\+\\-=\\[\\]{},.\\/;\':"<> |\\\\]';
|
|
4
|
+
const numbers = '.*?[0-9]';
|
|
5
|
+
const lowerCaseLetters = '.*?[a-z]';
|
|
6
|
+
const capitalLetters = '.*?[A-Z]';
|
|
7
|
+
const Validator_PasswordAssertion = {
|
|
8
|
+
[PasswordAssertionType_MinLength]: (amount) => tsValidateStringMinLength(amount),
|
|
9
|
+
[PasswordAssertionType_MaxLength]: (amount) => tsValidateString(amount),
|
|
10
|
+
[PasswordAssertionType_SpecialChars]: (amount) => tsValidateRegexp(new RegExp(generateArray(amount, _ => specialChars).join(''))),
|
|
11
|
+
[PasswordAssertionType_Numbers]: (amount) => tsValidateRegexp(new RegExp(generateArray(amount, _ => numbers).join(''))),
|
|
12
|
+
[PasswordAssertionType_LowerCaseLetters]: (amount) => tsValidateRegexp(new RegExp(generateArray(amount, _ => lowerCaseLetters).join(''))),
|
|
13
|
+
[PasswordAssertionType_CapitalLetters]: (amount) => tsValidateRegexp(new RegExp(generateArray(amount, _ => capitalLetters).join(''))),
|
|
14
|
+
};
|
|
15
|
+
const PasswordFailureMessages = {
|
|
16
|
+
[PasswordAssertionType_MinLength]: (amount) => `Password is shorter than ${amount} characters`,
|
|
17
|
+
[PasswordAssertionType_MaxLength]: (amount) => `Password is longer than ${amount} characters`,
|
|
18
|
+
[PasswordAssertionType_SpecialChars]: (amount) => `Password does not contain at least ${amount} special characters`,
|
|
19
|
+
[PasswordAssertionType_Numbers]: (amount) => `Password does not contain at least ${amount} numbers`,
|
|
20
|
+
[PasswordAssertionType_LowerCaseLetters]: (amount) => `Password does not contain at least ${amount} lower case characters`,
|
|
21
|
+
[PasswordAssertionType_CapitalLetters]: (amount) => `Password does not contain at least ${amount} capital letters`,
|
|
22
|
+
};
|
|
23
|
+
export const assertPasswordRules = (password, assertionConfig) => {
|
|
24
|
+
if (!assertionConfig)
|
|
25
|
+
return;
|
|
26
|
+
const results = _keys(assertionConfig).reduce((results, assertionKey) => {
|
|
27
|
+
if (!PasswordAssertionTypes.includes(assertionKey)) {
|
|
28
|
+
results[assertionKey] = `Unknown assertion key ${assertionKey}`;
|
|
29
|
+
return results;
|
|
30
|
+
}
|
|
31
|
+
const amount = assertionConfig[assertionKey];
|
|
32
|
+
const validator = Validator_PasswordAssertion[assertionKey](amount);
|
|
33
|
+
const result = tsValidateResult(password, validator);
|
|
34
|
+
if (result)
|
|
35
|
+
results[assertionKey] = PasswordFailureMessages[assertionKey](amount);
|
|
36
|
+
return results;
|
|
37
|
+
}, {});
|
|
38
|
+
return _keys(results).length ? results : undefined;
|
|
39
|
+
};
|
package/_enum.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './_enum/password-assertion/index.js';
|
package/_enum.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './_enum/password-assertion/index.js';
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nu-art/user-account-shared",
|
|
3
|
+
"version": "0.400.5",
|
|
4
|
+
"description": "User Account Shared",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"TacB0sS",
|
|
7
|
+
"create account",
|
|
8
|
+
"express",
|
|
9
|
+
"infra",
|
|
10
|
+
"login",
|
|
11
|
+
"nu-art",
|
|
12
|
+
"saml",
|
|
13
|
+
"thunderstorm",
|
|
14
|
+
"typescript",
|
|
15
|
+
"user-account"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/nu-art-js/user-account",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/nu-art-js/user-account/issues"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"directory": "dist",
|
|
23
|
+
"linkDirectory": true
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+ssh://git@github.com:nu-art-js/user-account.git"
|
|
28
|
+
},
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"author": "TacB0sS",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"run-tests": "firebase emulators:exec \"npm run test\"",
|
|
34
|
+
"test": "ts-mocha -w -p src/test/tsconfig.json --timeout 0 --inspect=8107 --watch-files 'src/test/**/*.test.ts' src/test/**/*.test.ts"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@nu-art/ts-common": "0.400.5",
|
|
38
|
+
"@nu-art/firebase-shared": "0.400.5",
|
|
39
|
+
"@nu-art/thunderstorm-shared": "0.400.5",
|
|
40
|
+
"@nu-art/ts-styles": "0.400.5",
|
|
41
|
+
"@nu-art/slack-shared": "0.400.5",
|
|
42
|
+
"firebase": "^11.9.0",
|
|
43
|
+
"firebase-admin": "13.4.0",
|
|
44
|
+
"firebase-functions": "6.3.2",
|
|
45
|
+
"react": "^18.0.0",
|
|
46
|
+
"moment": "^2.29.4",
|
|
47
|
+
"saml2-js": "^4.0.1",
|
|
48
|
+
"xmlbuilder": "^15.1.1",
|
|
49
|
+
"express": "^4.18.2",
|
|
50
|
+
"request": "^2.88.0",
|
|
51
|
+
"pako": "^2.1.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@nu-art/google-services-backend": "0.400.5",
|
|
55
|
+
"@types/react": "^18.0.0",
|
|
56
|
+
"@types/express": "^4.17.17",
|
|
57
|
+
"@types/history": "^4.7.2",
|
|
58
|
+
"@types/request": "^2.48.1",
|
|
59
|
+
"@types/saml2-js": "^1.6.8",
|
|
60
|
+
"@types/pako": "^2.0.0",
|
|
61
|
+
"@types/jsonwebtoken": "^9.0.6"
|
|
62
|
+
},
|
|
63
|
+
"unitConfig": {
|
|
64
|
+
"type": "typescript-lib"
|
|
65
|
+
},
|
|
66
|
+
"type": "module",
|
|
67
|
+
"exports": {
|
|
68
|
+
".": {
|
|
69
|
+
"types": "./index.d.ts",
|
|
70
|
+
"import": "./index.js"
|
|
71
|
+
},
|
|
72
|
+
"./*": {
|
|
73
|
+
"types": "./*.d.ts",
|
|
74
|
+
"import": "./*.js"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|