ecrs-auth-core 1.0.42 → 1.0.44

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.
Files changed (56) hide show
  1. package/README.md +263 -0
  2. package/dist/auth.controller.d.ts +26 -19
  3. package/dist/auth.controller.js +41 -41
  4. package/dist/auth.module.d.ts +9 -9
  5. package/dist/auth.module.js +143 -143
  6. package/dist/auth.service.d.ts +47 -40
  7. package/dist/auth.service.js +185 -168
  8. package/dist/constants/constants.d.ts +1 -1
  9. package/dist/constants/constants.js +4 -4
  10. package/dist/decorators/current-user.decorator.d.ts +1 -1
  11. package/dist/decorators/current-user.decorator.js +9 -9
  12. package/dist/decorators/feature.decorator.d.ts +1 -1
  13. package/dist/decorators/feature.decorator.js +11 -11
  14. package/dist/decorators/has-permission.decorator.d.ts +6 -6
  15. package/dist/decorators/has-permission.decorator.js +8 -8
  16. package/dist/decorators/roles.decorator.d.ts +1 -1
  17. package/dist/decorators/roles.decorator.js +6 -6
  18. package/dist/decorators/route-permission.decorator.d.ts +1 -1
  19. package/dist/decorators/route-permission.decorator.js +11 -11
  20. package/dist/dtos/login.dto.d.ts +4 -4
  21. package/dist/dtos/login.dto.js +7 -7
  22. package/dist/entities/feature.entity.d.ts +9 -9
  23. package/dist/entities/feature.entity.js +48 -48
  24. package/dist/entities/module-route.entity.d.ts +9 -9
  25. package/dist/entities/module-route.entity.js +48 -48
  26. package/dist/entities/module-screen-permission.entity.d.ts +15 -15
  27. package/dist/entities/module-screen-permission.entity.js +44 -44
  28. package/dist/entities/module.entity.d.ts +8 -8
  29. package/dist/entities/module.entity.js +44 -44
  30. package/dist/entities/role.entity.d.ts +7 -7
  31. package/dist/entities/role.entity.js +44 -44
  32. package/dist/entities/user-feature-access.entity.d.ts +19 -19
  33. package/dist/entities/user-feature-access.entity.js +88 -88
  34. package/dist/entities/user-module-access.entity.d.ts +12 -12
  35. package/dist/entities/user-module-access.entity.js +60 -60
  36. package/dist/entities/user.entity.d.ts +25 -24
  37. package/dist/entities/user.entity.js +112 -108
  38. package/dist/guards/feature.guard.d.ts +7 -7
  39. package/dist/guards/feature.guard.js +34 -34
  40. package/dist/guards/module.guard.d.ts +8 -8
  41. package/dist/guards/module.guard.js +36 -36
  42. package/dist/guards/permission.guard.d.ts +7 -7
  43. package/dist/guards/permission.guard.js +41 -41
  44. package/dist/guards/roles.guard.d.ts +7 -7
  45. package/dist/guards/roles.guard.js +34 -34
  46. package/dist/guards/route.guard.d.ts +7 -7
  47. package/dist/guards/route.guard.js +34 -34
  48. package/dist/index.d.ts +23 -23
  49. package/dist/index.js +45 -45
  50. package/dist/interfaces/auth-core-options.interface.d.ts +30 -30
  51. package/dist/interfaces/auth-core-options.interface.js +2 -2
  52. package/dist/jwt/jwt.guard.d.ts +4 -4
  53. package/dist/jwt/jwt.guard.js +18 -18
  54. package/dist/jwt/jwt.strategy.d.ts +14 -14
  55. package/dist/jwt/jwt.strategy.js +42 -42
  56. package/package.json +47 -47
@@ -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);
@@ -1,40 +1,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
- export declare class AuthService {
13
- private readonly jwtService;
14
- private readonly options;
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);
24
- validateUser(email: string, password: string): Promise<User | null>;
25
- login(user: User): Promise<{
26
- status: boolean;
27
- message: string;
28
- data: {
29
- user: {
30
- id: number;
31
- email: string;
32
- roleId: number;
33
- moduleId: number;
34
- };
35
- };
36
- access_token: string;
37
- }>;
38
- findUserById(id: number): Promise<User | null>;
39
- private loadPermissions;
40
- }
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
+ export declare class AuthService {
13
+ private readonly jwtService;
14
+ private readonly options;
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);
24
+ validateUser(email: string, password: string): Promise<User | null>;
25
+ login(user: User): Promise<{
26
+ status: boolean;
27
+ message: string;
28
+ data: {
29
+ user: {
30
+ id: number;
31
+ email: string;
32
+ roleId: number;
33
+ roleName: string | null;
34
+ moduleId: number;
35
+ name: string;
36
+ firstName: string;
37
+ lastName: string;
38
+ mobileNo: number;
39
+ userImage: string;
40
+ employeeId: number;
41
+ };
42
+ };
43
+ access_token: string;
44
+ }>;
45
+ findUserById(id: number): Promise<User | null>;
46
+ private loadPermissions;
47
+ }