@sneat/auth-models 0.1.1
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/eslint.config.js +7 -0
- package/ng-package.json +7 -0
- package/package.json +14 -0
- package/project.json +38 -0
- package/src/index.ts +3 -0
- package/src/lib/avatar.spec.ts +8 -0
- package/src/lib/avatar.ts +7 -0
- package/src/lib/person-names.ts +95 -0
- package/src/lib/user.ts +34 -0
- package/src/test-setup.ts +1 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +19 -0
- package/tsconfig.lib.prod.json +7 -0
- package/tsconfig.spec.json +31 -0
- package/vite.config.mts +10 -0
package/eslint.config.js
ADDED
package/ng-package.json
ADDED
package/package.json
ADDED
package/project.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "auth-models",
|
|
3
|
+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"projectType": "library",
|
|
5
|
+
"sourceRoot": "libs/auth/models/src",
|
|
6
|
+
"prefix": "sneat",
|
|
7
|
+
"targets": {
|
|
8
|
+
"build": {
|
|
9
|
+
"executor": "@nx/angular:ng-packagr-lite",
|
|
10
|
+
"outputs": [
|
|
11
|
+
"{workspaceRoot}/dist/libs/auth/models"
|
|
12
|
+
],
|
|
13
|
+
"options": {
|
|
14
|
+
"project": "libs/auth/models/ng-package.json",
|
|
15
|
+
"tsConfig": "libs/auth/models/tsconfig.lib.json"
|
|
16
|
+
},
|
|
17
|
+
"configurations": {
|
|
18
|
+
"production": {
|
|
19
|
+
"tsConfig": "libs/auth/models/tsconfig.lib.prod.json"
|
|
20
|
+
},
|
|
21
|
+
"development": {}
|
|
22
|
+
},
|
|
23
|
+
"defaultConfiguration": "production"
|
|
24
|
+
},
|
|
25
|
+
"test": {
|
|
26
|
+
"executor": "@nx/vitest:test",
|
|
27
|
+
"outputs": [
|
|
28
|
+
"{workspaceRoot}/coverage/libs/auth/models"
|
|
29
|
+
],
|
|
30
|
+
"options": {
|
|
31
|
+
"tsConfig": "libs/auth/models/tsconfig.spec.json"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"lint": {
|
|
35
|
+
"executor": "@nx/eslint:lint"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// TODO: Find a proper "non-auth" library for this file
|
|
2
|
+
|
|
3
|
+
export interface IPersonNames {
|
|
4
|
+
readonly firstName?: string;
|
|
5
|
+
readonly lastName?: string;
|
|
6
|
+
readonly middleName?: string;
|
|
7
|
+
readonly nickName?: string;
|
|
8
|
+
readonly fullName?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function mustHaveAtLeastOneName(names?: IPersonNames): void {
|
|
12
|
+
if (!names) {
|
|
13
|
+
throw new Error('Names are required');
|
|
14
|
+
}
|
|
15
|
+
if (
|
|
16
|
+
!names.firstName &&
|
|
17
|
+
!names.lastName &&
|
|
18
|
+
!names.middleName &&
|
|
19
|
+
!names.nickName &&
|
|
20
|
+
!names.fullName
|
|
21
|
+
) {
|
|
22
|
+
throw new Error('At least one name is required');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function namesToUrlParams(names?: IPersonNames): string {
|
|
27
|
+
if (!names) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
const { firstName, lastName, middleName, nickName, fullName } = names;
|
|
31
|
+
const params: string[] = [];
|
|
32
|
+
if (firstName) {
|
|
33
|
+
params.push(`firstName=${encodeURIComponent(firstName)}`);
|
|
34
|
+
}
|
|
35
|
+
if (lastName) {
|
|
36
|
+
params.push(`lastName=${encodeURIComponent(lastName)}`);
|
|
37
|
+
}
|
|
38
|
+
if (middleName) {
|
|
39
|
+
params.push(`middleName=${encodeURIComponent(middleName)}`);
|
|
40
|
+
}
|
|
41
|
+
if (nickName) {
|
|
42
|
+
params.push(`nickName=${encodeURIComponent(nickName)}`);
|
|
43
|
+
}
|
|
44
|
+
if (fullName && fullName !== `${firstName} ${lastName}`) {
|
|
45
|
+
params.push(`fullName=${encodeURIComponent(fullName)}`);
|
|
46
|
+
}
|
|
47
|
+
return params.join('&');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isNameEmpty(n?: IPersonNames): boolean {
|
|
51
|
+
// noinspection UnnecessaryLocalVariableJS
|
|
52
|
+
const result =
|
|
53
|
+
!n ||
|
|
54
|
+
(!n.fullName?.trim() &&
|
|
55
|
+
!n.firstName?.trim() &&
|
|
56
|
+
!n.lastName?.trim() &&
|
|
57
|
+
!n.middleName?.trim() &&
|
|
58
|
+
!n.nickName?.trim());
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function trimNames(n: IPersonNames): IPersonNames {
|
|
63
|
+
const first = n.firstName?.trim(),
|
|
64
|
+
middle = n.middleName?.trim(),
|
|
65
|
+
last = n.lastName?.trim(),
|
|
66
|
+
full = n.fullName?.trim();
|
|
67
|
+
if (
|
|
68
|
+
first !== n?.firstName ||
|
|
69
|
+
last !== n?.lastName ||
|
|
70
|
+
middle != n.middleName ||
|
|
71
|
+
full != n.fullName
|
|
72
|
+
) {
|
|
73
|
+
n = {
|
|
74
|
+
firstName: first,
|
|
75
|
+
middleName: middle,
|
|
76
|
+
lastName: last,
|
|
77
|
+
fullName: full,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return n;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getFullName(n: IPersonNames): string {
|
|
84
|
+
if (n.fullName) {
|
|
85
|
+
return n.fullName;
|
|
86
|
+
}
|
|
87
|
+
return [
|
|
88
|
+
n.firstName,
|
|
89
|
+
n.middleName,
|
|
90
|
+
n.lastName,
|
|
91
|
+
n.nickName ? `(${n.nickName})` : '',
|
|
92
|
+
]
|
|
93
|
+
.filter((v) => !!v)
|
|
94
|
+
.join(' ');
|
|
95
|
+
}
|
package/src/lib/user.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EnumAsUnionOfKeys, SpaceType } from '@sneat/core';
|
|
2
|
+
import { IAvatar } from './avatar';
|
|
3
|
+
import { IPersonNames } from './person-names';
|
|
4
|
+
|
|
5
|
+
// Does not contain an ID as it's a key.
|
|
6
|
+
// Use IRecord<IUserRecord> to keep record paired with ID
|
|
7
|
+
export interface IUserRecord {
|
|
8
|
+
readonly accounts?: string[];
|
|
9
|
+
readonly title: string;
|
|
10
|
+
readonly countryID?: string;
|
|
11
|
+
readonly email?: string;
|
|
12
|
+
readonly emailIsVerified?: boolean;
|
|
13
|
+
readonly avatar?: IAvatar;
|
|
14
|
+
readonly spaceIDs?: readonly string[];
|
|
15
|
+
readonly spaces?: Record<string, IUserSpaceBrief>;
|
|
16
|
+
readonly names?: IPersonNames;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export enum SpaceMemberTypeEnum {
|
|
20
|
+
creator = 'creator',
|
|
21
|
+
member = 'member',
|
|
22
|
+
pet = 'pet',
|
|
23
|
+
pupil = 'pupil',
|
|
24
|
+
staff = 'staff',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type SpaceMemberType = EnumAsUnionOfKeys<typeof SpaceMemberTypeEnum>;
|
|
28
|
+
|
|
29
|
+
export interface IUserSpaceBrief {
|
|
30
|
+
readonly title: string;
|
|
31
|
+
readonly type: SpaceType;
|
|
32
|
+
readonly roles: string[];
|
|
33
|
+
readonly userContactID: string;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@sneat/core/testing-light';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.lib.base.json",
|
|
3
|
+
"exclude": [
|
|
4
|
+
"vite.config.ts",
|
|
5
|
+
"vite.config.mts",
|
|
6
|
+
"vitest.config.ts",
|
|
7
|
+
"vitest.config.mts",
|
|
8
|
+
"src/**/*.test.ts",
|
|
9
|
+
"src/**/*.spec.ts",
|
|
10
|
+
"src/**/*.test.tsx",
|
|
11
|
+
"src/**/*.spec.tsx",
|
|
12
|
+
"src/**/*.test.js",
|
|
13
|
+
"src/**/*.spec.js",
|
|
14
|
+
"src/**/*.test.jsx",
|
|
15
|
+
"src/**/*.spec.jsx",
|
|
16
|
+
"src/test-setup.ts",
|
|
17
|
+
"src/lib/testing/**/*"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"vitest/globals",
|
|
7
|
+
"vitest/importMeta",
|
|
8
|
+
"vite/client",
|
|
9
|
+
"node",
|
|
10
|
+
"vitest"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"vite.config.ts",
|
|
15
|
+
"vite.config.mts",
|
|
16
|
+
"vitest.config.ts",
|
|
17
|
+
"vitest.config.mts",
|
|
18
|
+
"src/**/*.test.ts",
|
|
19
|
+
"src/**/*.spec.ts",
|
|
20
|
+
"src/**/*.test.tsx",
|
|
21
|
+
"src/**/*.spec.tsx",
|
|
22
|
+
"src/**/*.test.js",
|
|
23
|
+
"src/**/*.spec.js",
|
|
24
|
+
"src/**/*.test.jsx",
|
|
25
|
+
"src/**/*.spec.jsx",
|
|
26
|
+
"src/**/*.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"files": [
|
|
29
|
+
"src/test-setup.ts"
|
|
30
|
+
]
|
|
31
|
+
}
|
package/vite.config.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types='vitest' />
|
|
2
|
+
import { defineConfig } from 'vitest/config';
|
|
3
|
+
import { createBaseViteConfig } from '../../../vite.config.base';
|
|
4
|
+
|
|
5
|
+
export default defineConfig(() =>
|
|
6
|
+
createBaseViteConfig({
|
|
7
|
+
dirname: __dirname,
|
|
8
|
+
name: 'auth-models',
|
|
9
|
+
}),
|
|
10
|
+
);
|