ecrs-auth-core 1.0.16 → 1.0.17
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/dist/auth.module.js
CHANGED
|
@@ -29,9 +29,12 @@ let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
|
29
29
|
return {
|
|
30
30
|
module: AuthCoreModule_1,
|
|
31
31
|
imports: [
|
|
32
|
-
jwt_1.JwtModule.
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
jwt_1.JwtModule.registerAsync({
|
|
33
|
+
useFactory: (options) => ({
|
|
34
|
+
secret: options.jwtSecret,
|
|
35
|
+
signOptions: { expiresIn: options.jwtExpiresIn },
|
|
36
|
+
}),
|
|
37
|
+
inject: [exports.AUTH_CORE_OPTIONS],
|
|
35
38
|
}),
|
|
36
39
|
],
|
|
37
40
|
controllers: [auth_controller_1.AuthController],
|
package/dist/auth.service.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JwtService } from
|
|
2
|
-
import { AuthCoreOptions } from
|
|
3
|
-
import { User } from
|
|
1
|
+
import { JwtService } from '@nestjs/jwt';
|
|
2
|
+
import { AuthCoreOptions } from './interfaces/auth-core-options.interface';
|
|
3
|
+
import { User } from './entities/user.entity';
|
|
4
4
|
export type RoutePermissionSet = {
|
|
5
5
|
view?: boolean;
|
|
6
6
|
create?: boolean;
|
|
@@ -10,12 +10,17 @@ export type RoutePermissionSet = {
|
|
|
10
10
|
export?: boolean;
|
|
11
11
|
};
|
|
12
12
|
export declare class AuthService {
|
|
13
|
-
private jwtService;
|
|
13
|
+
private readonly jwtService;
|
|
14
14
|
private readonly options;
|
|
15
|
-
private readonly
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
private readonly userRepo;
|
|
16
|
+
private readonly roleRepo;
|
|
17
|
+
private readonly moduleRepo;
|
|
18
|
+
private readonly featureRepo;
|
|
19
|
+
private readonly routeRepo;
|
|
20
|
+
private readonly featureAccessRepo;
|
|
21
|
+
private readonly moduleAccessRepo;
|
|
22
|
+
private readonly screenPermissionRepo;
|
|
23
|
+
constructor(jwtService: JwtService, options: AuthCoreOptions);
|
|
19
24
|
validateUser(email: string, password: string): Promise<User | null>;
|
|
20
25
|
login(user: User): Promise<{
|
|
21
26
|
access_token: string;
|
package/dist/auth.service.js
CHANGED
|
@@ -49,15 +49,24 @@ exports.AuthService = void 0;
|
|
|
49
49
|
const common_1 = require("@nestjs/common");
|
|
50
50
|
const jwt_1 = require("@nestjs/jwt");
|
|
51
51
|
const bcrypt = __importStar(require("bcrypt"));
|
|
52
|
+
const auth_module_1 = require("./auth.module");
|
|
52
53
|
let AuthService = class AuthService {
|
|
53
|
-
constructor(jwtService, options
|
|
54
|
+
constructor(jwtService, options) {
|
|
54
55
|
this.jwtService = jwtService;
|
|
55
56
|
this.options = options;
|
|
56
|
-
|
|
57
|
+
const { userRepo, roleRepo, moduleRepo, featureRepo, routeRepo, featureAccessRepo, moduleAccessRepo, screenPermissionRepo, } = options.repositories;
|
|
58
|
+
this.userRepo = userRepo;
|
|
59
|
+
this.roleRepo = roleRepo;
|
|
60
|
+
this.moduleRepo = moduleRepo;
|
|
61
|
+
this.featureRepo = featureRepo;
|
|
62
|
+
this.routeRepo = routeRepo;
|
|
63
|
+
this.featureAccessRepo = featureAccessRepo;
|
|
64
|
+
this.moduleAccessRepo = moduleAccessRepo;
|
|
65
|
+
this.screenPermissionRepo = screenPermissionRepo;
|
|
57
66
|
}
|
|
58
67
|
async validateUser(email, password) {
|
|
59
|
-
const user = await this.
|
|
60
|
-
if (!user
|
|
68
|
+
const user = await this.userRepo.findOne({ where: { email } });
|
|
69
|
+
if (!user)
|
|
61
70
|
return null;
|
|
62
71
|
const isValid = await bcrypt.compare(password, user.password);
|
|
63
72
|
return isValid ? user : null;
|
|
@@ -76,15 +85,15 @@ let AuthService = class AuthService {
|
|
|
76
85
|
};
|
|
77
86
|
}
|
|
78
87
|
async findUserById(id) {
|
|
79
|
-
return this.
|
|
88
|
+
return this.userRepo.findOne({ where: { id } });
|
|
80
89
|
}
|
|
81
90
|
async loadPermissions(userId) {
|
|
82
|
-
//
|
|
83
|
-
const featureAccessList = await this.
|
|
91
|
+
// Feature Permissions
|
|
92
|
+
const featureAccessList = await this.featureAccessRepo.find({
|
|
84
93
|
where: { userId, isDeleted: 0 },
|
|
85
94
|
});
|
|
86
95
|
const featurePermissions = {};
|
|
87
|
-
const allFeatures = await this.
|
|
96
|
+
const allFeatures = await this.featureRepo.find();
|
|
88
97
|
const featureMap = new Map(allFeatures.map((f) => [f.id, f]));
|
|
89
98
|
for (const access of featureAccessList) {
|
|
90
99
|
const feature = featureMap.get(access.featureId);
|
|
@@ -92,40 +101,40 @@ let AuthService = class AuthService {
|
|
|
92
101
|
continue;
|
|
93
102
|
const perms = [];
|
|
94
103
|
if (access.canView)
|
|
95
|
-
perms.push(
|
|
104
|
+
perms.push('view');
|
|
96
105
|
if (access.canCreate)
|
|
97
|
-
perms.push(
|
|
106
|
+
perms.push('create');
|
|
98
107
|
if (access.canModify)
|
|
99
|
-
perms.push(
|
|
108
|
+
perms.push('update');
|
|
100
109
|
if (access.canDelete)
|
|
101
|
-
perms.push(
|
|
110
|
+
perms.push('delete');
|
|
102
111
|
if (access.canImport)
|
|
103
|
-
perms.push(
|
|
112
|
+
perms.push('import');
|
|
104
113
|
if (access.canExport)
|
|
105
|
-
perms.push(
|
|
114
|
+
perms.push('export');
|
|
106
115
|
if (perms.length) {
|
|
107
116
|
featurePermissions[feature.featureName] = perms;
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
|
-
//
|
|
111
|
-
const moduleAccess = await this.
|
|
119
|
+
// Module Access
|
|
120
|
+
const moduleAccess = await this.moduleAccessRepo.find({
|
|
112
121
|
where: { userId, isDeleted: 0 },
|
|
113
122
|
});
|
|
114
123
|
const moduleIds = moduleAccess.map((m) => m.moduleId);
|
|
115
|
-
//
|
|
116
|
-
const screenPermissionsList = await this.
|
|
124
|
+
// Route Permissions
|
|
125
|
+
const screenPermissionsList = await this.screenPermissionRepo.find({
|
|
117
126
|
where: { userId, isActive: true },
|
|
118
127
|
});
|
|
119
128
|
const routePermissions = {};
|
|
120
|
-
const allRoutes = await this.
|
|
129
|
+
const allRoutes = await this.routeRepo.find();
|
|
121
130
|
const routeMap = new Map(allRoutes.map((r) => [r.id, r]));
|
|
122
131
|
for (const screen of screenPermissionsList) {
|
|
123
132
|
const route = routeMap.get(screen.moduleRouteId);
|
|
124
133
|
if (!route)
|
|
125
134
|
continue;
|
|
126
135
|
const perms = [];
|
|
127
|
-
const
|
|
128
|
-
for (const key of
|
|
136
|
+
const keys = ['view', 'create', 'update', 'delete', 'import', 'export'];
|
|
137
|
+
for (const key of keys) {
|
|
129
138
|
if (screen.permissions?.[key]) {
|
|
130
139
|
perms.push(key);
|
|
131
140
|
}
|
|
@@ -144,7 +153,6 @@ let AuthService = class AuthService {
|
|
|
144
153
|
exports.AuthService = AuthService;
|
|
145
154
|
exports.AuthService = AuthService = __decorate([
|
|
146
155
|
(0, common_1.Injectable)(),
|
|
147
|
-
__param(1, (0, common_1.Inject)(
|
|
148
|
-
|
|
149
|
-
__metadata("design:paramtypes", [jwt_1.JwtService, Object, Object])
|
|
156
|
+
__param(1, (0, common_1.Inject)(auth_module_1.AUTH_CORE_OPTIONS)),
|
|
157
|
+
__metadata("design:paramtypes", [jwt_1.JwtService, Object])
|
|
150
158
|
], AuthService);
|
|
@@ -7,7 +7,7 @@ import { ModuleRoute } from '../entities/module-route.entity';
|
|
|
7
7
|
import { UserFeatureAccess } from '../entities/user-feature-access.entity';
|
|
8
8
|
import { UserModuleAccess } from '../entities/user-module-access.entity';
|
|
9
9
|
import { ModuleScreenPermission } from '../entities/module-screen-permission.entity';
|
|
10
|
-
export interface
|
|
10
|
+
export interface Repositories {
|
|
11
11
|
userRepo: Repository<User>;
|
|
12
12
|
roleRepo: Repository<Role>;
|
|
13
13
|
moduleRepo: Repository<Module>;
|
|
@@ -17,3 +17,14 @@ export interface AuthCoreOptions {
|
|
|
17
17
|
routeRepo: Repository<ModuleRoute>;
|
|
18
18
|
moduleAccessRepo: Repository<UserModuleAccess>;
|
|
19
19
|
}
|
|
20
|
+
export interface AuthModuleConfig {
|
|
21
|
+
enable2FA?: boolean;
|
|
22
|
+
tokenIssuer?: string;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
export interface AuthCoreOptions {
|
|
26
|
+
jwtSecret: string;
|
|
27
|
+
jwtExpiresIn: string;
|
|
28
|
+
repositories: Repositories;
|
|
29
|
+
moduleConfig?: AuthModuleConfig;
|
|
30
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Strategy } from 'passport-jwt';
|
|
2
2
|
import { AuthService } from '../auth.service';
|
|
3
|
-
declare const JwtStrategy_base: new (...args: [
|
|
4
|
-
validate(...args: any[]): unknown;
|
|
5
|
-
};
|
|
3
|
+
declare const JwtStrategy_base: new (...args: any[]) => Strategy;
|
|
6
4
|
export declare class JwtStrategy extends JwtStrategy_base {
|
|
7
5
|
private readonly authService;
|
|
8
6
|
constructor(authService: AuthService);
|