@tomei/sso 0.8.13 → 0.9.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/__tests__/unit/components/login-user/login-user.spec.ts +32 -24
- package/__tests__/unit/system-privilege/system-privilage.spec.ts +91 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js +32 -22
- package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -1
- package/dist/__tests__/unit/system-privilege/system-privilage.spec.d.ts +0 -0
- package/dist/__tests__/unit/system-privilege/system-privilage.spec.js +6 -0
- package/dist/__tests__/unit/system-privilege/system-privilage.spec.js.map +1 -0
- package/dist/src/components/login-user/login-user.d.ts +2 -1
- package/dist/src/components/login-user/login-user.js +1 -3
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/components/system-privilege/privilege.d.ts +6 -0
- package/dist/src/components/system-privilege/privilege.js +77 -0
- package/dist/src/components/system-privilege/privilege.js.map +1 -0
- package/dist/src/components/system-privilege/system-privilege.repository.d.ts +6 -0
- package/dist/src/components/system-privilege/system-privilege.repository.js +35 -0
- package/dist/src/components/system-privilege/system-privilege.repository.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/components/login-user/login-user.ts +5 -5
- package/src/components/system-privilege/privilege.ts +74 -0
- package/src/components/system-privilege/system-privilege.repository.ts +23 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tomei/sso",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.9.1",
|
4
4
|
"description": "Tomei SSO Package",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"scripts": {
|
@@ -75,6 +75,7 @@
|
|
75
75
|
]
|
76
76
|
},
|
77
77
|
"dependencies": {
|
78
|
-
"@tomei/config": "^0.2.0"
|
78
|
+
"@tomei/config": "^0.2.0",
|
79
|
+
"cuid": "^3.0.0"
|
79
80
|
}
|
80
81
|
}
|
@@ -65,8 +65,6 @@ export class LoginUser extends LoginUserBase {
|
|
65
65
|
) {
|
66
66
|
super();
|
67
67
|
this._SessionService = sessionService;
|
68
|
-
// this._PasswordHashService = new PasswordHashService();
|
69
|
-
// this._MailService = new MailService();
|
70
68
|
|
71
69
|
if (dbTransaction) {
|
72
70
|
this._dbTransaction = dbTransaction;
|
@@ -83,9 +81,11 @@ export class LoginUser extends LoginUserBase {
|
|
83
81
|
}
|
84
82
|
}
|
85
83
|
|
86
|
-
static async init(
|
87
|
-
|
88
|
-
|
84
|
+
static async init(
|
85
|
+
sessionService: ISessionService,
|
86
|
+
userId?: string,
|
87
|
+
dbTransaction = null,
|
88
|
+
): Promise<LoginUser> {
|
89
89
|
if (userId) {
|
90
90
|
if (dbTransaction) {
|
91
91
|
LoginUser._Repository = new UserRepository();
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { SystemRepository } from '../system/system.repository';
|
2
|
+
import { SystemPrivilegeRepository } from './system-privilege.repository';
|
3
|
+
import * as cuid from 'cuid';
|
4
|
+
|
5
|
+
export class Privilege {
|
6
|
+
private static _Repository = new SystemPrivilegeRepository();
|
7
|
+
private static _SystemRepository = new SystemRepository();
|
8
|
+
|
9
|
+
static async loadPrivileges(
|
10
|
+
packageName: string | string[],
|
11
|
+
systemCode: string,
|
12
|
+
transaction?: any,
|
13
|
+
) {
|
14
|
+
try {
|
15
|
+
//retrive SystemId from systemCode from database
|
16
|
+
const system = await Privilege._SystemRepository.findOne({
|
17
|
+
where: {
|
18
|
+
code: systemCode,
|
19
|
+
},
|
20
|
+
transaction,
|
21
|
+
});
|
22
|
+
|
23
|
+
if (!system) {
|
24
|
+
throw new Error('System not found');
|
25
|
+
}
|
26
|
+
|
27
|
+
if (Array.isArray(packageName)) {
|
28
|
+
for (const name of packageName) {
|
29
|
+
await this.loadPrivilege(name, system.id, transaction);
|
30
|
+
}
|
31
|
+
} else {
|
32
|
+
await this.loadPrivilege(packageName, system.id, transaction);
|
33
|
+
}
|
34
|
+
} catch (error) {
|
35
|
+
throw error;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
private static async loadPrivilege(
|
40
|
+
packageName: string,
|
41
|
+
systemId: number,
|
42
|
+
transaction?: any,
|
43
|
+
) {
|
44
|
+
try {
|
45
|
+
let privileges = [];
|
46
|
+
try {
|
47
|
+
const { Privileges } = await import(
|
48
|
+
`@tomei/${packageName}/privileges.json`
|
49
|
+
);
|
50
|
+
privileges = Privileges;
|
51
|
+
} catch (error) {
|
52
|
+
throw new Error('Module not found');
|
53
|
+
}
|
54
|
+
for (const privilege of privileges) {
|
55
|
+
const { Code, Description } = privilege;
|
56
|
+
await Privilege._Repository.findOrCreate(
|
57
|
+
{
|
58
|
+
Code,
|
59
|
+
SystemId: systemId,
|
60
|
+
Description,
|
61
|
+
},
|
62
|
+
{
|
63
|
+
PrivilegeId: cuid(),
|
64
|
+
CreatedAt: new Date(),
|
65
|
+
UpdatedAt: new Date(),
|
66
|
+
},
|
67
|
+
transaction,
|
68
|
+
);
|
69
|
+
}
|
70
|
+
} catch (error) {
|
71
|
+
throw error;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import SystemPrivilege from '../../models/system-privilege.entity';
|
2
|
+
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
3
|
+
|
4
|
+
export class SystemPrivilegeRepository
|
5
|
+
extends RepositoryBase<SystemPrivilege>
|
6
|
+
implements IRepositoryBase<SystemPrivilege>
|
7
|
+
{
|
8
|
+
constructor() {
|
9
|
+
super(SystemPrivilege);
|
10
|
+
}
|
11
|
+
|
12
|
+
async findOrCreate(where: any, defaults: any, transaction: any) {
|
13
|
+
try {
|
14
|
+
return await SystemPrivilege.findOrCreate({
|
15
|
+
where,
|
16
|
+
defaults,
|
17
|
+
transaction,
|
18
|
+
});
|
19
|
+
} catch (error) {
|
20
|
+
throw error;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|