ecrs-auth-core 1.0.55 → 1.0.57
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.controller.d.ts +26 -26
- package/dist/auth.controller.js +99 -41
- package/dist/auth.module.d.ts +9 -9
- package/dist/auth.module.js +143 -143
- package/dist/auth.service.d.ts +55 -47
- package/dist/auth.service.js +197 -185
- package/dist/constants/constants.d.ts +1 -1
- package/dist/constants/constants.js +4 -4
- package/dist/decorators/current-user.decorator.d.ts +1 -1
- package/dist/decorators/current-user.decorator.js +9 -9
- package/dist/decorators/feature.decorator.d.ts +1 -1
- package/dist/decorators/feature.decorator.js +11 -11
- package/dist/decorators/has-permission.decorator.d.ts +6 -6
- package/dist/decorators/has-permission.decorator.js +8 -8
- package/dist/decorators/roles.decorator.d.ts +1 -1
- package/dist/decorators/roles.decorator.js +6 -6
- package/dist/decorators/route-permission.decorator.d.ts +1 -1
- package/dist/decorators/route-permission.decorator.js +11 -11
- package/dist/dtos/login-response.dto.d.ts +23 -0
- package/dist/dtos/login-response.dto.js +86 -0
- package/dist/dtos/login.dto.d.ts +5 -4
- package/dist/dtos/login.dto.js +32 -7
- package/dist/entities/feature.entity.d.ts +9 -9
- package/dist/entities/feature.entity.js +48 -48
- package/dist/entities/module-route.entity.d.ts +9 -9
- package/dist/entities/module-route.entity.js +48 -48
- package/dist/entities/module-screen-permission.entity.d.ts +15 -15
- package/dist/entities/module-screen-permission.entity.js +44 -44
- package/dist/entities/module.entity.d.ts +8 -8
- package/dist/entities/module.entity.js +44 -44
- package/dist/entities/role.entity.d.ts +7 -7
- package/dist/entities/role.entity.js +44 -44
- package/dist/entities/user-feature-access.entity.d.ts +19 -19
- package/dist/entities/user-feature-access.entity.js +88 -88
- package/dist/entities/user-module-access.entity.d.ts +12 -12
- package/dist/entities/user-module-access.entity.js +60 -60
- package/dist/entities/user.entity.d.ts +25 -25
- package/dist/entities/user.entity.js +112 -112
- package/dist/guards/feature.guard.d.ts +7 -7
- package/dist/guards/feature.guard.js +34 -34
- package/dist/guards/module.guard.d.ts +8 -8
- package/dist/guards/module.guard.js +36 -36
- package/dist/guards/permission.guard.d.ts +7 -7
- package/dist/guards/permission.guard.js +41 -41
- package/dist/guards/roles.guard.d.ts +7 -7
- package/dist/guards/roles.guard.js +34 -34
- package/dist/guards/route.guard.d.ts +7 -7
- package/dist/guards/route.guard.js +34 -34
- package/dist/index.d.ts +25 -23
- package/dist/index.js +48 -45
- package/dist/interfaces/auth-core-options.interface.d.ts +30 -30
- package/dist/interfaces/auth-core-options.interface.js +2 -2
- package/dist/jwt/jwt.guard.d.ts +4 -4
- package/dist/jwt/jwt.guard.js +18 -18
- package/dist/jwt/jwt.strategy.d.ts +14 -14
- package/dist/jwt/jwt.strategy.js +49 -42
- package/package.json +6 -4
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { AuthService } from './auth.service';
|
|
2
|
-
import { LoginDto } from './dtos/login.dto';
|
|
3
|
-
export declare class AuthController {
|
|
4
|
-
private readonly authService;
|
|
5
|
-
constructor(authService: AuthService);
|
|
6
|
-
login(body: LoginDto): Promise<{
|
|
7
|
-
status: boolean;
|
|
8
|
-
message: string;
|
|
9
|
-
data: {
|
|
10
|
-
user: {
|
|
11
|
-
id: number;
|
|
12
|
-
email: string;
|
|
13
|
-
roleId: number;
|
|
14
|
-
roleName: string | null;
|
|
15
|
-
moduleId: number;
|
|
16
|
-
name: string;
|
|
17
|
-
firstName: string;
|
|
18
|
-
lastName: string;
|
|
19
|
-
mobileNo: number;
|
|
20
|
-
userImage: string;
|
|
21
|
-
employeeId: number;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
access_token: string;
|
|
25
|
-
}>;
|
|
26
|
-
}
|
|
1
|
+
import { AuthService } from './auth.service';
|
|
2
|
+
import { LoginDto } from './dtos/login.dto';
|
|
3
|
+
export declare class AuthController {
|
|
4
|
+
private readonly authService;
|
|
5
|
+
constructor(authService: AuthService);
|
|
6
|
+
login(body: LoginDto): Promise<{
|
|
7
|
+
status: boolean;
|
|
8
|
+
message: string;
|
|
9
|
+
data: {
|
|
10
|
+
user: {
|
|
11
|
+
id: number;
|
|
12
|
+
email: string;
|
|
13
|
+
roleId: number;
|
|
14
|
+
roleName: string | null;
|
|
15
|
+
moduleId: number;
|
|
16
|
+
name: string;
|
|
17
|
+
firstName: string;
|
|
18
|
+
lastName: string;
|
|
19
|
+
mobileNo: number;
|
|
20
|
+
userImage: string;
|
|
21
|
+
employeeId: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
access_token: string;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
package/dist/auth.controller.js
CHANGED
|
@@ -1,41 +1,99 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.AuthController = void 0;
|
|
16
|
-
const common_1 = require("@nestjs/common");
|
|
17
|
-
const auth_service_1 = require("./auth.service");
|
|
18
|
-
const login_dto_1 = require("./dtos/login.dto");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AuthController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const auth_service_1 = require("./auth.service");
|
|
18
|
+
const login_dto_1 = require("./dtos/login.dto");
|
|
19
|
+
const login_response_dto_1 = require("./dtos/login-response.dto");
|
|
20
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
21
|
+
let AuthController = class AuthController {
|
|
22
|
+
constructor(authService) {
|
|
23
|
+
this.authService = authService;
|
|
24
|
+
}
|
|
25
|
+
async login(body) {
|
|
26
|
+
const user = await this.authService.validateUser(body.email, body.password);
|
|
27
|
+
if (!user)
|
|
28
|
+
throw new common_1.UnauthorizedException('Invalid credentials');
|
|
29
|
+
const requestedModuleId = Number(body.moduleId);
|
|
30
|
+
if (!Number.isFinite(requestedModuleId)) {
|
|
31
|
+
throw new common_1.UnauthorizedException('You are not authorized to access this module');
|
|
32
|
+
}
|
|
33
|
+
const allowedDb = await this.authService.hasModuleAccess(user.id, requestedModuleId);
|
|
34
|
+
if (!allowedDb) {
|
|
35
|
+
throw new common_1.UnauthorizedException('You are not authorized to access this module');
|
|
36
|
+
}
|
|
37
|
+
// Double-check against computed permissions tree to avoid edge cases
|
|
38
|
+
const perms = await this.authService.getPermissions(user.id);
|
|
39
|
+
if (!Array.isArray(perms.modules) || !perms.modules.includes(requestedModuleId)) {
|
|
40
|
+
throw new common_1.UnauthorizedException('You are not authorized to access this module');
|
|
41
|
+
}
|
|
42
|
+
return this.authService.login(user, requestedModuleId);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.AuthController = AuthController;
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, common_1.Post)('login'),
|
|
48
|
+
(0, common_1.HttpCode)(200),
|
|
49
|
+
(0, swagger_1.ApiBody)({
|
|
50
|
+
required: true,
|
|
51
|
+
description: 'Credentials required for authentication',
|
|
52
|
+
schema: {
|
|
53
|
+
$ref: (0, swagger_1.getSchemaPath)(login_dto_1.LoginDto),
|
|
54
|
+
example: { email: 'user@example.com', password: 'StrongP@ssw0rd', moduleId: '3' },
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
(0, swagger_1.ApiOperation)({
|
|
58
|
+
summary: 'User login',
|
|
59
|
+
description: 'Authenticate user and return access token'
|
|
60
|
+
}),
|
|
61
|
+
(0, swagger_1.ApiOkResponse)({
|
|
62
|
+
description: 'Login successful',
|
|
63
|
+
schema: {
|
|
64
|
+
$ref: (0, swagger_1.getSchemaPath)(login_response_dto_1.LoginResponseDto),
|
|
65
|
+
example: {
|
|
66
|
+
status: true,
|
|
67
|
+
message: 'Login successful',
|
|
68
|
+
data: {
|
|
69
|
+
user: {
|
|
70
|
+
id: 1,
|
|
71
|
+
email: 'user@example.com',
|
|
72
|
+
roleId: 2,
|
|
73
|
+
roleName: 'Admin',
|
|
74
|
+
moduleId: 3,
|
|
75
|
+
name: 'John Doe',
|
|
76
|
+
firstName: 'John',
|
|
77
|
+
lastName: 'Doe',
|
|
78
|
+
mobileNo: 9876543210,
|
|
79
|
+
userImage: 'https://cdn.example.com/avatar.png',
|
|
80
|
+
employeeId: 1001
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
access_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
(0, swagger_1.ApiUnauthorizedResponse)({ description: 'Invalid credentials' }),
|
|
88
|
+
__param(0, (0, common_1.Body)()),
|
|
89
|
+
__metadata("design:type", Function),
|
|
90
|
+
__metadata("design:paramtypes", [login_dto_1.LoginDto]),
|
|
91
|
+
__metadata("design:returntype", Promise)
|
|
92
|
+
], AuthController.prototype, "login", null);
|
|
93
|
+
exports.AuthController = AuthController = __decorate([
|
|
94
|
+
(0, swagger_1.ApiTags)('auth'),
|
|
95
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
96
|
+
(0, swagger_1.ApiExtraModels)(login_dto_1.LoginDto, login_response_dto_1.LoginResponseDto),
|
|
97
|
+
(0, common_1.Controller)('auth'),
|
|
98
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
|
99
|
+
], AuthController);
|
package/dist/auth.module.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { AuthCoreOptions } from './interfaces/auth-core-options.interface';
|
|
3
|
-
export declare const AUTH_CORE_OPTIONS = "AUTH_CORE_OPTIONS";
|
|
4
|
-
export declare class AuthCoreModule {
|
|
5
|
-
static registerAsync(options: {
|
|
6
|
-
inject: any[];
|
|
7
|
-
useFactory: (...args: any[]) => Promise<AuthCoreOptions>;
|
|
8
|
-
}): DynamicModule;
|
|
9
|
-
}
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { AuthCoreOptions } from './interfaces/auth-core-options.interface';
|
|
3
|
+
export declare const AUTH_CORE_OPTIONS = "AUTH_CORE_OPTIONS";
|
|
4
|
+
export declare class AuthCoreModule {
|
|
5
|
+
static registerAsync(options: {
|
|
6
|
+
inject: any[];
|
|
7
|
+
useFactory: (...args: any[]) => Promise<AuthCoreOptions>;
|
|
8
|
+
}): DynamicModule;
|
|
9
|
+
}
|
package/dist/auth.module.js
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var AuthCoreModule_1;
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.AuthCoreModule = exports.AUTH_CORE_OPTIONS = void 0;
|
|
11
|
-
const common_1 = require("@nestjs/common");
|
|
12
|
-
const jwt_1 = require("@nestjs/jwt");
|
|
13
|
-
const auth_service_1 = require("./auth.service");
|
|
14
|
-
const auth_controller_1 = require("./auth.controller");
|
|
15
|
-
const jwt_strategy_1 = require("./jwt/jwt.strategy");
|
|
16
|
-
const jwt_guard_1 = require("./jwt/jwt.guard");
|
|
17
|
-
const module_guard_1 = require("./guards/module.guard");
|
|
18
|
-
const roles_guard_1 = require("./guards/roles.guard");
|
|
19
|
-
const feature_guard_1 = require("./guards/feature.guard");
|
|
20
|
-
const route_guard_1 = require("./guards/route.guard");
|
|
21
|
-
const permission_guard_1 = require("./guards/permission.guard");
|
|
22
|
-
exports.AUTH_CORE_OPTIONS = 'AUTH_CORE_OPTIONS';
|
|
23
|
-
// @Global()
|
|
24
|
-
// @Module({})
|
|
25
|
-
// export class AuthCoreModule {
|
|
26
|
-
// static registerAsync(options: {
|
|
27
|
-
// inject: any[];
|
|
28
|
-
// useFactory: (...args: any[]) => Promise<AuthCoreOptions>;
|
|
29
|
-
// }): DynamicModule {
|
|
30
|
-
// const asyncProvider = {
|
|
31
|
-
// provide: AUTH_CORE_OPTIONS,
|
|
32
|
-
// inject: options.inject,
|
|
33
|
-
// useFactory: options.useFactory,
|
|
34
|
-
// };
|
|
35
|
-
// return {
|
|
36
|
-
// module: AuthCoreModule,
|
|
37
|
-
// imports: [
|
|
38
|
-
// JwtModule.registerAsync({
|
|
39
|
-
// inject: options.inject,
|
|
40
|
-
// useFactory: async (...args: any[]) => {
|
|
41
|
-
// const config = await options.useFactory(...args);
|
|
42
|
-
// console.log("🔐 JWT Secret from AUTH_CORE_OPTIONS:", config.jwtSecret);
|
|
43
|
-
// console.log("⏳ JWT Expiry:", config.jwtExpiresIn);
|
|
44
|
-
// return {
|
|
45
|
-
// secret: config.jwtSecret,
|
|
46
|
-
// signOptions: { expiresIn: config.jwtExpiresIn },
|
|
47
|
-
// };
|
|
48
|
-
// },
|
|
49
|
-
// }),
|
|
50
|
-
// ],
|
|
51
|
-
// providers: [
|
|
52
|
-
// asyncProvider,
|
|
53
|
-
// {
|
|
54
|
-
// provide: 'MODULE_CONFIG',
|
|
55
|
-
// useFactory: (options: AuthCoreOptions) => options.moduleConfig || {},
|
|
56
|
-
// inject: [AUTH_CORE_OPTIONS],
|
|
57
|
-
// },
|
|
58
|
-
// AuthService,
|
|
59
|
-
// JwtStrategy,
|
|
60
|
-
// JwtAuthGuard,
|
|
61
|
-
// ModuleGuard,
|
|
62
|
-
// RolesGuard,
|
|
63
|
-
// FeatureGuard,
|
|
64
|
-
// RouteGuard,
|
|
65
|
-
// PermissionGuard,
|
|
66
|
-
// ],
|
|
67
|
-
// controllers: [AuthController],
|
|
68
|
-
// exports: [
|
|
69
|
-
// AuthService,
|
|
70
|
-
// JwtStrategy,
|
|
71
|
-
// JwtAuthGuard,
|
|
72
|
-
// ModuleGuard,
|
|
73
|
-
// RolesGuard,
|
|
74
|
-
// FeatureGuard,
|
|
75
|
-
// RouteGuard,
|
|
76
|
-
// PermissionGuard,
|
|
77
|
-
// JwtModule,
|
|
78
|
-
// ],
|
|
79
|
-
// };
|
|
80
|
-
// }
|
|
81
|
-
// }
|
|
82
|
-
let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
83
|
-
static registerAsync(options) {
|
|
84
|
-
const asyncProvider = {
|
|
85
|
-
provide: exports.AUTH_CORE_OPTIONS,
|
|
86
|
-
inject: options.inject,
|
|
87
|
-
useFactory: options.useFactory,
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
module: AuthCoreModule_1,
|
|
91
|
-
imports: [
|
|
92
|
-
jwt_1.JwtModule.registerAsync({
|
|
93
|
-
inject: options.inject,
|
|
94
|
-
useFactory: async (...args) => {
|
|
95
|
-
const config = await options.useFactory(...args);
|
|
96
|
-
console.log('🔐 JWT Secret from AUTH_CORE_OPTIONS:', config.jwtSecret);
|
|
97
|
-
console.log('⏳ JWT Expiry:', config.jwtExpiresIn);
|
|
98
|
-
return {
|
|
99
|
-
secret: config.jwtSecret,
|
|
100
|
-
signOptions: { expiresIn: config.jwtExpiresIn },
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
}),
|
|
104
|
-
],
|
|
105
|
-
providers: [
|
|
106
|
-
asyncProvider,
|
|
107
|
-
{
|
|
108
|
-
provide: 'MODULE_CONFIG',
|
|
109
|
-
useFactory: (opts) => opts.moduleConfig || {},
|
|
110
|
-
inject: [exports.AUTH_CORE_OPTIONS],
|
|
111
|
-
},
|
|
112
|
-
auth_service_1.AuthService,
|
|
113
|
-
jwt_strategy_1.JwtStrategy,
|
|
114
|
-
jwt_guard_1.JwtAuthGuard,
|
|
115
|
-
module_guard_1.ModuleGuard,
|
|
116
|
-
roles_guard_1.RolesGuard,
|
|
117
|
-
feature_guard_1.FeatureGuard,
|
|
118
|
-
route_guard_1.RouteGuard,
|
|
119
|
-
permission_guard_1.PermissionGuard,
|
|
120
|
-
],
|
|
121
|
-
controllers: [auth_controller_1.AuthController],
|
|
122
|
-
exports: [
|
|
123
|
-
// ⬇️ export these so Superadmin can resolve guard deps
|
|
124
|
-
exports.AUTH_CORE_OPTIONS,
|
|
125
|
-
'MODULE_CONFIG',
|
|
126
|
-
jwt_1.JwtModule,
|
|
127
|
-
auth_service_1.AuthService,
|
|
128
|
-
jwt_strategy_1.JwtStrategy,
|
|
129
|
-
jwt_guard_1.JwtAuthGuard,
|
|
130
|
-
module_guard_1.ModuleGuard,
|
|
131
|
-
roles_guard_1.RolesGuard,
|
|
132
|
-
feature_guard_1.FeatureGuard,
|
|
133
|
-
route_guard_1.RouteGuard,
|
|
134
|
-
permission_guard_1.PermissionGuard,
|
|
135
|
-
],
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
exports.AuthCoreModule = AuthCoreModule;
|
|
140
|
-
exports.AuthCoreModule = AuthCoreModule = AuthCoreModule_1 = __decorate([
|
|
141
|
-
(0, common_1.Global)(),
|
|
142
|
-
(0, common_1.Module)({})
|
|
143
|
-
], AuthCoreModule);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var AuthCoreModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AuthCoreModule = exports.AUTH_CORE_OPTIONS = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
13
|
+
const auth_service_1 = require("./auth.service");
|
|
14
|
+
const auth_controller_1 = require("./auth.controller");
|
|
15
|
+
const jwt_strategy_1 = require("./jwt/jwt.strategy");
|
|
16
|
+
const jwt_guard_1 = require("./jwt/jwt.guard");
|
|
17
|
+
const module_guard_1 = require("./guards/module.guard");
|
|
18
|
+
const roles_guard_1 = require("./guards/roles.guard");
|
|
19
|
+
const feature_guard_1 = require("./guards/feature.guard");
|
|
20
|
+
const route_guard_1 = require("./guards/route.guard");
|
|
21
|
+
const permission_guard_1 = require("./guards/permission.guard");
|
|
22
|
+
exports.AUTH_CORE_OPTIONS = 'AUTH_CORE_OPTIONS';
|
|
23
|
+
// @Global()
|
|
24
|
+
// @Module({})
|
|
25
|
+
// export class AuthCoreModule {
|
|
26
|
+
// static registerAsync(options: {
|
|
27
|
+
// inject: any[];
|
|
28
|
+
// useFactory: (...args: any[]) => Promise<AuthCoreOptions>;
|
|
29
|
+
// }): DynamicModule {
|
|
30
|
+
// const asyncProvider = {
|
|
31
|
+
// provide: AUTH_CORE_OPTIONS,
|
|
32
|
+
// inject: options.inject,
|
|
33
|
+
// useFactory: options.useFactory,
|
|
34
|
+
// };
|
|
35
|
+
// return {
|
|
36
|
+
// module: AuthCoreModule,
|
|
37
|
+
// imports: [
|
|
38
|
+
// JwtModule.registerAsync({
|
|
39
|
+
// inject: options.inject,
|
|
40
|
+
// useFactory: async (...args: any[]) => {
|
|
41
|
+
// const config = await options.useFactory(...args);
|
|
42
|
+
// console.log("🔐 JWT Secret from AUTH_CORE_OPTIONS:", config.jwtSecret);
|
|
43
|
+
// console.log("⏳ JWT Expiry:", config.jwtExpiresIn);
|
|
44
|
+
// return {
|
|
45
|
+
// secret: config.jwtSecret,
|
|
46
|
+
// signOptions: { expiresIn: config.jwtExpiresIn },
|
|
47
|
+
// };
|
|
48
|
+
// },
|
|
49
|
+
// }),
|
|
50
|
+
// ],
|
|
51
|
+
// providers: [
|
|
52
|
+
// asyncProvider,
|
|
53
|
+
// {
|
|
54
|
+
// provide: 'MODULE_CONFIG',
|
|
55
|
+
// useFactory: (options: AuthCoreOptions) => options.moduleConfig || {},
|
|
56
|
+
// inject: [AUTH_CORE_OPTIONS],
|
|
57
|
+
// },
|
|
58
|
+
// AuthService,
|
|
59
|
+
// JwtStrategy,
|
|
60
|
+
// JwtAuthGuard,
|
|
61
|
+
// ModuleGuard,
|
|
62
|
+
// RolesGuard,
|
|
63
|
+
// FeatureGuard,
|
|
64
|
+
// RouteGuard,
|
|
65
|
+
// PermissionGuard,
|
|
66
|
+
// ],
|
|
67
|
+
// controllers: [AuthController],
|
|
68
|
+
// exports: [
|
|
69
|
+
// AuthService,
|
|
70
|
+
// JwtStrategy,
|
|
71
|
+
// JwtAuthGuard,
|
|
72
|
+
// ModuleGuard,
|
|
73
|
+
// RolesGuard,
|
|
74
|
+
// FeatureGuard,
|
|
75
|
+
// RouteGuard,
|
|
76
|
+
// PermissionGuard,
|
|
77
|
+
// JwtModule,
|
|
78
|
+
// ],
|
|
79
|
+
// };
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
83
|
+
static registerAsync(options) {
|
|
84
|
+
const asyncProvider = {
|
|
85
|
+
provide: exports.AUTH_CORE_OPTIONS,
|
|
86
|
+
inject: options.inject,
|
|
87
|
+
useFactory: options.useFactory,
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
module: AuthCoreModule_1,
|
|
91
|
+
imports: [
|
|
92
|
+
jwt_1.JwtModule.registerAsync({
|
|
93
|
+
inject: options.inject,
|
|
94
|
+
useFactory: async (...args) => {
|
|
95
|
+
const config = await options.useFactory(...args);
|
|
96
|
+
console.log('🔐 JWT Secret from AUTH_CORE_OPTIONS:', config.jwtSecret);
|
|
97
|
+
console.log('⏳ JWT Expiry:', config.jwtExpiresIn);
|
|
98
|
+
return {
|
|
99
|
+
secret: config.jwtSecret,
|
|
100
|
+
signOptions: { expiresIn: config.jwtExpiresIn },
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
],
|
|
105
|
+
providers: [
|
|
106
|
+
asyncProvider,
|
|
107
|
+
{
|
|
108
|
+
provide: 'MODULE_CONFIG',
|
|
109
|
+
useFactory: (opts) => opts.moduleConfig || {},
|
|
110
|
+
inject: [exports.AUTH_CORE_OPTIONS],
|
|
111
|
+
},
|
|
112
|
+
auth_service_1.AuthService,
|
|
113
|
+
jwt_strategy_1.JwtStrategy,
|
|
114
|
+
jwt_guard_1.JwtAuthGuard,
|
|
115
|
+
module_guard_1.ModuleGuard,
|
|
116
|
+
roles_guard_1.RolesGuard,
|
|
117
|
+
feature_guard_1.FeatureGuard,
|
|
118
|
+
route_guard_1.RouteGuard,
|
|
119
|
+
permission_guard_1.PermissionGuard,
|
|
120
|
+
],
|
|
121
|
+
controllers: [auth_controller_1.AuthController],
|
|
122
|
+
exports: [
|
|
123
|
+
// ⬇️ export these so Superadmin can resolve guard deps
|
|
124
|
+
exports.AUTH_CORE_OPTIONS,
|
|
125
|
+
'MODULE_CONFIG',
|
|
126
|
+
jwt_1.JwtModule,
|
|
127
|
+
auth_service_1.AuthService,
|
|
128
|
+
jwt_strategy_1.JwtStrategy,
|
|
129
|
+
jwt_guard_1.JwtAuthGuard,
|
|
130
|
+
module_guard_1.ModuleGuard,
|
|
131
|
+
roles_guard_1.RolesGuard,
|
|
132
|
+
feature_guard_1.FeatureGuard,
|
|
133
|
+
route_guard_1.RouteGuard,
|
|
134
|
+
permission_guard_1.PermissionGuard,
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
exports.AuthCoreModule = AuthCoreModule;
|
|
140
|
+
exports.AuthCoreModule = AuthCoreModule = AuthCoreModule_1 = __decorate([
|
|
141
|
+
(0, common_1.Global)(),
|
|
142
|
+
(0, common_1.Module)({})
|
|
143
|
+
], AuthCoreModule);
|
package/dist/auth.service.d.ts
CHANGED
|
@@ -1,47 +1,55 @@
|
|
|
1
|
-
import { JwtService } from '@nestjs/jwt';
|
|
2
|
-
import { AuthCoreOptions } from './interfaces/auth-core-options.interface';
|
|
3
|
-
import { User } from './entities/user.entity';
|
|
4
|
-
export type RoutePermissionSet = {
|
|
5
|
-
view?: boolean;
|
|
6
|
-
create?: boolean;
|
|
7
|
-
update?: boolean;
|
|
8
|
-
delete?: boolean;
|
|
9
|
-
import?: boolean;
|
|
10
|
-
export?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private readonly
|
|
19
|
-
private readonly
|
|
20
|
-
private readonly
|
|
21
|
-
private readonly
|
|
22
|
-
private readonly
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
import { JwtService } from '@nestjs/jwt';
|
|
2
|
+
import { AuthCoreOptions } from './interfaces/auth-core-options.interface';
|
|
3
|
+
import { User } from './entities/user.entity';
|
|
4
|
+
export type RoutePermissionSet = {
|
|
5
|
+
view?: boolean;
|
|
6
|
+
create?: boolean;
|
|
7
|
+
update?: boolean;
|
|
8
|
+
delete?: boolean;
|
|
9
|
+
import?: boolean;
|
|
10
|
+
export?: boolean;
|
|
11
|
+
};
|
|
12
|
+
interface PermissionsTree {
|
|
13
|
+
features: Record<string, string[]>;
|
|
14
|
+
modules: number[];
|
|
15
|
+
routes: Record<string, string[]>;
|
|
16
|
+
}
|
|
17
|
+
export declare class AuthService {
|
|
18
|
+
private readonly jwtService;
|
|
19
|
+
private readonly options;
|
|
20
|
+
private readonly userRepo;
|
|
21
|
+
private readonly roleRepo;
|
|
22
|
+
private readonly moduleRepo;
|
|
23
|
+
private readonly featureRepo;
|
|
24
|
+
private readonly routeRepo;
|
|
25
|
+
private readonly featureAccessRepo;
|
|
26
|
+
private readonly moduleAccessRepo;
|
|
27
|
+
private readonly screenPermissionRepo;
|
|
28
|
+
constructor(jwtService: JwtService, options: AuthCoreOptions);
|
|
29
|
+
validateUser(email: string, password: string): Promise<User | null>;
|
|
30
|
+
hasModuleAccess(userId: number, moduleId: number): Promise<boolean>;
|
|
31
|
+
getPermissions(userId: number): Promise<PermissionsTree>;
|
|
32
|
+
login(user: User, selectedModuleId?: number): Promise<{
|
|
33
|
+
status: boolean;
|
|
34
|
+
message: string;
|
|
35
|
+
data: {
|
|
36
|
+
user: {
|
|
37
|
+
id: number;
|
|
38
|
+
email: string;
|
|
39
|
+
roleId: number;
|
|
40
|
+
roleName: string | null;
|
|
41
|
+
moduleId: number;
|
|
42
|
+
name: string;
|
|
43
|
+
firstName: string;
|
|
44
|
+
lastName: string;
|
|
45
|
+
mobileNo: number;
|
|
46
|
+
userImage: string;
|
|
47
|
+
employeeId: number;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
access_token: string;
|
|
51
|
+
}>;
|
|
52
|
+
findUserById(id: number): Promise<User | null>;
|
|
53
|
+
private loadPermissions;
|
|
54
|
+
}
|
|
55
|
+
export {};
|