@sneat/auth-models 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ const baseConfig = require('../../../eslint.config.js');
2
+ const { sneatLibConfig } = require('../../../eslint.lib.config.js');
3
+
4
+ module.exports = [
5
+ ...baseConfig,
6
+ ...sneatLibConfig(__dirname),
7
+ ];
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../../dist/libs/auth/models",
4
+ "lib": {
5
+ "entryFile": "src/index.ts"
6
+ }
7
+ }
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@sneat/auth-models",
3
+ "version": "0.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "peerDependencies": {
8
+ "@angular/common": ">=21.0.0",
9
+ "@angular/core": ">=21.0.0"
10
+ },
11
+ "dependencies": {
12
+ "tslib": "2.8.1"
13
+ }
14
+ }
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,3 @@
1
+ export * from './lib/avatar';
2
+ export * from './lib/user';
3
+ export * from './lib/person-names';
@@ -0,0 +1,8 @@
1
+ import { IAvatar } from './avatar';
2
+
3
+ describe('auth models sanity', () => {
4
+ it('should allow creating an IAvatar object', () => {
5
+ const avatar: IAvatar = { gravatar: 'test' };
6
+ expect(avatar.gravatar).toBe('test');
7
+ });
8
+ });
@@ -0,0 +1,7 @@
1
+ export interface IAvatar {
2
+ readonly gravatar?: string;
3
+ readonly external?: {
4
+ readonly provider?: string;
5
+ readonly url?: string;
6
+ };
7
+ }
@@ -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
+ }
@@ -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,13 @@
1
+ {
2
+ "extends": "../../../tsconfig.angular.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "./tsconfig.lib.json"
8
+ },
9
+ {
10
+ "path": "./tsconfig.spec.json"
11
+ }
12
+ ]
13
+ }
@@ -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,7 @@
1
+ {
2
+ "extends": "./tsconfig.lib.json",
3
+ "compilerOptions": {
4
+ "declarationMap": false
5
+ },
6
+ "angularCompilerOptions": {}
7
+ }
@@ -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
+ }
@@ -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
+ );