ecrs-auth-core 1.0.90 → 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
@@ -187,7 +187,7 @@ let AuthService = class AuthService {
187
187
  }
188
188
  async getPermissions(userId) {
189
189
  console.log(`🔍 Loading permissions for user ID ${userId}...`);
190
- return this.loadPermissions(userId);
190
+ // return this.loadPermissions(userId);
191
191
  }
192
192
  /**
193
193
  * Save user last login details
@@ -551,68 +551,60 @@ let AuthService = class AuthService {
551
551
  async findUserById(id) {
552
552
  return this.userRepo.findOne({ where: { id } });
553
553
  }
554
- async loadPermissions(userId) {
555
- // Feature Permissions
556
- const featureAccessList = await this.featureAccessRepo.find({
557
- where: { userId, isDeleted: 0 },
558
- });
559
- const featurePermissions = {};
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)
565
- continue;
566
- const perms = [];
567
- if (access.canView)
568
- perms.push('view');
569
- if (access.canCreate)
570
- perms.push('create');
571
- if (access.canModify)
572
- perms.push('update');
573
- if (access.canDelete)
574
- perms.push('delete');
575
- if (access.canImport)
576
- perms.push('import');
577
- if (access.canExport)
578
- perms.push('export');
579
- if (perms.length) {
580
- featurePermissions[feature.featureName] = perms;
581
- }
582
- }
583
- // Module Access - only count active (non-deleted, status=1) assignments
584
- const moduleAccess = await this.moduleAccessRepo.find({
585
- where: { userId, isDeleted: 0, status: 1 },
586
- });
587
- const moduleIds = moduleAccess.map((m) => m.moduleId);
588
- // Route Permissions
589
- const screenPermissionsList = await this.screenPermissionRepo.find({
590
- where: { userId, isActive: true },
591
- });
592
- const routePermissions = {};
593
- const allRoutes = await this.routeRepo.find();
594
- const routeMap = new Map(allRoutes.map((r) => [r.id, r]));
595
- for (const screen of screenPermissionsList) {
596
- const route = routeMap.get(screen.moduleRouteId);
597
- if (!route)
598
- continue;
599
- const perms = [];
600
- const keys = ['view', 'create', 'update', 'delete', 'import', 'export'];
601
- for (const key of keys) {
602
- if (screen.permissions?.[key]) {
603
- perms.push(key);
604
- }
605
- }
606
- if (perms.length) {
607
- routePermissions[route.routeName] = perms;
608
- }
609
- }
610
- return {
611
- features: featurePermissions,
612
- modules: moduleIds,
613
- routes: routePermissions,
614
- };
615
- }
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
+ // }
616
608
  async loadModulePermissions(userId, moduleId) {
617
609
  if (!Number.isFinite(moduleId)) {
618
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.90",
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",