ecrs-auth-core 1.0.89 → 1.0.91

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.
@@ -55,12 +55,12 @@ let AuthController = class AuthController {
55
55
  console.warn(`⚠️ Invalid module ID provided by user ${body.email}: ${body.moduleId}`);
56
56
  throw new common_1.UnauthorizedException('You are not authorized to access this module');
57
57
  }
58
- console.log(`🔍 Checking module access for user ID ${user.id} and module ID ${requestedModuleId}...`);
59
- const allowedDb = await this.authService.hasModuleAccess(user.id, requestedModuleId);
60
- console.log(`📊 Module access check result for user ID ${user.id} and module ID ${requestedModuleId}: ${allowedDb ? 'Allowed' : 'Denied'}`);
61
- if (!allowedDb) {
62
- throw new common_1.UnauthorizedException('You are not authorized to access this module');
63
- }
58
+ // console.log(`🔍 Checking module access for user ID ${user.id} and module ID ${requestedModuleId}...`);
59
+ // const allowedDb = await this.authService.hasModuleAccess(user.id, requestedModuleId);
60
+ // console.log(`📊 Module access check result for user ID ${user.id} and module ID ${requestedModuleId}: ${allowedDb ? 'Allowed' : 'Denied'}`);
61
+ // if (!allowedDb) {
62
+ // throw new UnauthorizedException('You are not authorized to access this module');
63
+ // }
64
64
  // const perms = await this.authService.getPermissions(user.id);
65
65
  // console.log(`📊 User permissions for ${body.email}:`, perms);
66
66
  // if (!Array.isArray(perms.modules) || !perms.modules.includes(requestedModuleId)) {
@@ -9,11 +9,6 @@ export type RoutePermissionSet = {
9
9
  import?: boolean;
10
10
  export?: boolean;
11
11
  };
12
- interface PermissionsTree {
13
- features: Record<string, string[]>;
14
- modules: number[];
15
- routes: Record<string, string[]>;
16
- }
17
12
  export declare class AuthService {
18
13
  private readonly jwtService;
19
14
  private readonly options;
@@ -22,7 +17,6 @@ export declare class AuthService {
22
17
  private readonly moduleRepo;
23
18
  private readonly featureRepo;
24
19
  private readonly routeRepo;
25
- private readonly featureAccessRepo;
26
20
  private readonly moduleAccessRepo;
27
21
  private readonly screenPermissionRepo;
28
22
  private readonly ipRestrictionsRepo;
@@ -45,7 +39,7 @@ export declare class AuthService {
45
39
  private normalizeIp;
46
40
  private validateIpRestriction;
47
41
  hasModuleAccess(userId: number, moduleId: number): Promise<boolean>;
48
- getPermissions(userId: number): Promise<PermissionsTree>;
42
+ getPermissions(userId: number): Promise<void>;
49
43
  /**
50
44
  * Save user last login details
51
45
  * Updates the tbl_user_last_login table with latest login info
@@ -120,7 +114,5 @@ export declare class AuthService {
120
114
  */
121
115
  extractUserIpv4(clientIp: string | undefined): string;
122
116
  findUserById(id: number): Promise<User | null>;
123
- private loadPermissions;
124
117
  private loadModulePermissions;
125
118
  }
126
- export {};
@@ -61,7 +61,7 @@ let AuthService = class AuthService {
61
61
  this.moduleRepo = repositories.moduleRepo;
62
62
  this.featureRepo = repositories.featureRepo;
63
63
  this.routeRepo = repositories.routeRepo;
64
- this.featureAccessRepo = repositories.featureAccessRepo;
64
+ // this.featureAccessRepo = repositories.featureAccessRepo;
65
65
  this.moduleAccessRepo = repositories.moduleAccessRepo;
66
66
  this.screenPermissionRepo = repositories.screenPermissionRepo;
67
67
  // Optional repositories
@@ -164,10 +164,6 @@ let AuthService = class AuthService {
164
164
  if (!Number.isFinite(moduleId))
165
165
  return false;
166
166
  console.log(`🔍 Checking module access for user ID ${userId} and module ID ${moduleId}...`);
167
- const access = await this.moduleAccessRepo.findOne({
168
- where: { userId, moduleId, isDeleted: 0, status: 1 },
169
- });
170
- console.log(access);
171
167
  const access1 = await this.moduleAccessRepo
172
168
  .createQueryBuilder("ma")
173
169
  .where("ma.userId = :userId", { userId })
@@ -176,12 +172,22 @@ let AuthService = class AuthService {
176
172
  .andWhere("ma.isDeleted = 0")
177
173
  .getOne();
178
174
  console.log(access1);
175
+ let access;
176
+ try {
177
+ access = await this.moduleAccessRepo.findOne({
178
+ where: { userId, moduleId, isDeleted: 0, status: 1 },
179
+ });
180
+ console.log(access);
181
+ }
182
+ catch (error) {
183
+ console.error(error);
184
+ }
179
185
  console.log(`📊 Module access check result for user ID ${userId} and module ID ${moduleId}: ${access ? 'Allowed' : 'Denied'}`);
180
186
  return !!access;
181
187
  }
182
188
  async getPermissions(userId) {
183
189
  console.log(`🔍 Loading permissions for user ID ${userId}...`);
184
- return this.loadPermissions(userId);
190
+ // return this.loadPermissions(userId);
185
191
  }
186
192
  /**
187
193
  * Save user last login details
@@ -545,68 +551,60 @@ let AuthService = class AuthService {
545
551
  async findUserById(id) {
546
552
  return this.userRepo.findOne({ where: { id } });
547
553
  }
548
- async loadPermissions(userId) {
549
- // Feature Permissions
550
- const featureAccessList = await this.featureAccessRepo.find({
551
- where: { userId, isDeleted: 0 },
552
- });
553
- const featurePermissions = {};
554
- const allFeatures = await this.featureRepo.find();
555
- const featureMap = new Map(allFeatures.map((f) => [f.id, f]));
556
- for (const access of featureAccessList) {
557
- const feature = featureMap.get(access.featureId);
558
- if (!feature)
559
- continue;
560
- const perms = [];
561
- if (access.canView)
562
- perms.push('view');
563
- if (access.canCreate)
564
- perms.push('create');
565
- if (access.canModify)
566
- perms.push('update');
567
- if (access.canDelete)
568
- perms.push('delete');
569
- if (access.canImport)
570
- perms.push('import');
571
- if (access.canExport)
572
- perms.push('export');
573
- if (perms.length) {
574
- featurePermissions[feature.featureName] = perms;
575
- }
576
- }
577
- // Module Access - only count active (non-deleted, status=1) assignments
578
- const moduleAccess = await this.moduleAccessRepo.find({
579
- where: { userId, isDeleted: 0, status: 1 },
580
- });
581
- const moduleIds = moduleAccess.map((m) => m.moduleId);
582
- // Route Permissions
583
- const screenPermissionsList = await this.screenPermissionRepo.find({
584
- where: { userId, isActive: true },
585
- });
586
- const routePermissions = {};
587
- const allRoutes = await this.routeRepo.find();
588
- const routeMap = new Map(allRoutes.map((r) => [r.id, r]));
589
- for (const screen of screenPermissionsList) {
590
- const route = routeMap.get(screen.moduleRouteId);
591
- if (!route)
592
- continue;
593
- const perms = [];
594
- const keys = ['view', 'create', 'update', 'delete', 'import', 'export'];
595
- for (const key of keys) {
596
- if (screen.permissions?.[key]) {
597
- perms.push(key);
598
- }
599
- }
600
- if (perms.length) {
601
- routePermissions[route.routeName] = perms;
602
- }
603
- }
604
- return {
605
- features: featurePermissions,
606
- modules: moduleIds,
607
- routes: routePermissions,
608
- };
609
- }
554
+ // private async loadPermissions(userId: number): Promise<PermissionsTree> {
555
+ // // Feature Permissions
556
+ // const featureAccessList = await this.featureAccessRepo.find({
557
+ // where: { userId, isDeleted: 0 },
558
+ // });
559
+ // const featurePermissions: Record<string, string[]> = {};
560
+ // const allFeatures = await this.featureRepo.find();
561
+ // const featureMap = new Map(allFeatures.map((f) => [f.id, f]));
562
+ // for (const access of featureAccessList) {
563
+ // const feature = featureMap.get(access.featureId);
564
+ // if (!feature) continue;
565
+ // const perms: string[] = [];
566
+ // if (access.canView) perms.push('view');
567
+ // if (access.canCreate) perms.push('create');
568
+ // if (access.canModify) perms.push('update');
569
+ // if (access.canDelete) perms.push('delete');
570
+ // if (access.canImport) perms.push('import');
571
+ // if (access.canExport) perms.push('export');
572
+ // if (perms.length) {
573
+ // featurePermissions[feature.featureName] = perms;
574
+ // }
575
+ // }
576
+ // // Module Access - only count active (non-deleted, status=1) assignments
577
+ // const moduleAccess = await this.moduleAccessRepo.find({
578
+ // where: { userId, isDeleted: 0, status: 1 },
579
+ // });
580
+ // const moduleIds = moduleAccess.map((m) => m.moduleId);
581
+ // // Route Permissions
582
+ // const screenPermissionsList = await this.screenPermissionRepo.find({
583
+ // where: { userId, isActive: true },
584
+ // });
585
+ // const routePermissions: Record<string, string[]> = {};
586
+ // const allRoutes = await this.routeRepo.find();
587
+ // const routeMap = new Map(allRoutes.map((r) => [r.id, r]));
588
+ // for (const screen of screenPermissionsList) {
589
+ // const route = routeMap.get(screen.moduleRouteId);
590
+ // if (!route) continue;
591
+ // const perms: string[] = [];
592
+ // const keys = ['view', 'create', 'update', 'delete', 'import', 'export'] as const;
593
+ // for (const key of keys) {
594
+ // if (screen.permissions?.[key]) {
595
+ // perms.push(key);
596
+ // }
597
+ // }
598
+ // if (perms.length) {
599
+ // routePermissions[route.routeName] = perms;
600
+ // }
601
+ // }
602
+ // return {
603
+ // features: featurePermissions,
604
+ // modules: moduleIds,
605
+ // routes: routePermissions,
606
+ // };
607
+ // }
610
608
  async loadModulePermissions(userId, moduleId) {
611
609
  if (!Number.isFinite(moduleId)) {
612
610
  return [];
package/dist/index.d.ts CHANGED
@@ -22,7 +22,6 @@ export * from './entities/role.entity';
22
22
  export * from './entities/module.entity';
23
23
  export * from './entities/feature.entity';
24
24
  export * from './entities/module-route.entity';
25
- export * from './entities/user-feature-access.entity';
26
25
  export * from './entities/user-module-access.entity';
27
26
  export * from './entities/module-screen-permission.entity';
28
27
  export * from './entities/api-key.entity';
package/dist/index.js CHANGED
@@ -45,7 +45,7 @@ __exportStar(require("./entities/role.entity"), exports);
45
45
  __exportStar(require("./entities/module.entity"), exports);
46
46
  __exportStar(require("./entities/feature.entity"), exports);
47
47
  __exportStar(require("./entities/module-route.entity"), exports);
48
- __exportStar(require("./entities/user-feature-access.entity"), exports);
48
+ // export * from './entities/user-feature-access.entity';
49
49
  __exportStar(require("./entities/user-module-access.entity"), exports);
50
50
  __exportStar(require("./entities/module-screen-permission.entity"), exports);
51
51
  __exportStar(require("./entities/api-key.entity"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecrs-auth-core",
3
- "version": "1.0.89",
3
+ "version": "1.0.91",
4
4
  "description": "Centralized authentication and authorization module for ECRS apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",