@punks/backend-entity-manager 0.0.176 → 0.0.177

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.
@@ -1,6 +1,7 @@
1
- import { IAuthRole, IAuthUser } from "../abstractions";
1
+ import { IAuthPermission, IAuthRole, IAuthUser } from "../abstractions";
2
2
  export type CurrentUserData = {
3
3
  user: IAuthUser;
4
4
  roles: IAuthRole[];
5
+ permissions: IAuthPermission[];
5
6
  };
6
7
  export declare const CurrentUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
@@ -1,6 +1,7 @@
1
1
  import { AppRole, RolesGuardOptions } from "../types";
2
2
  export declare const Public: () => import("@nestjs/common").CustomDecorator<string>;
3
3
  export declare const Authenticated: () => import("@nestjs/common").CustomDecorator<string>;
4
+ export declare const Permissions: (...permissions: string[]) => import("@nestjs/common").CustomDecorator<string>;
4
5
  export declare const Roles: (...roles: string[]) => import("@nestjs/common").CustomDecorator<string>;
5
6
  export declare const MemberOf: (...groups: string[]) => import("@nestjs/common").CustomDecorator<string>;
6
7
  export declare const buildRolesGuard: ({ mainRole, secondaryRoles, }: {
@@ -8,5 +8,6 @@ export declare const AuthenticationGuardsSymbols: {
8
8
  Authenticated: string;
9
9
  Public: string;
10
10
  Roles: string;
11
+ Permissions: string;
11
12
  MemberOf: string;
12
13
  };
@@ -6,5 +6,6 @@ export declare class AuthenticationMiddleware implements NestMiddleware {
6
6
  use(req: any, res: any, next: (error?: any) => void): Promise<void>;
7
7
  private getUserFromToken;
8
8
  private getUserRoles;
9
+ private getUserPermissions;
9
10
  private extractTokenFromHeader;
10
11
  }
package/dist/esm/index.js CHANGED
@@ -2497,9 +2497,11 @@ const CurrentUser = createParamDecorator((data, context) => {
2497
2497
  }
2498
2498
  const user = request.auth.user;
2499
2499
  const roles = request.auth.roles;
2500
+ const permissions = request.auth.permissions;
2500
2501
  return {
2501
2502
  user,
2502
2503
  roles,
2504
+ permissions,
2503
2505
  };
2504
2506
  });
2505
2507
 
@@ -2513,6 +2515,7 @@ const AuthenticationGuardsSymbols = {
2513
2515
  Authenticated: "guard:authenticated",
2514
2516
  Public: "guard:public",
2515
2517
  Roles: "guard:roles",
2518
+ Permissions: "guard:permissions",
2516
2519
  MemberOf: "guard:memberOf",
2517
2520
  };
2518
2521
 
@@ -22010,9 +22013,11 @@ let AuthenticationMiddleware = class AuthenticationMiddleware {
22010
22013
  if (parsedToken.isValid) {
22011
22014
  const user = await this.getUserFromToken(parsedToken.data);
22012
22015
  const roles = user ? await this.getUserRoles(user) : [];
22016
+ const permissions = user ? await this.getUserPermissions(user) : [];
22013
22017
  req.auth = {
22014
22018
  user,
22015
22019
  roles,
22020
+ permissions,
22016
22021
  };
22017
22022
  }
22018
22023
  }
@@ -22024,6 +22029,9 @@ let AuthenticationMiddleware = class AuthenticationMiddleware {
22024
22029
  async getUserRoles(user) {
22025
22030
  return await this.authService.userRolesService.getUserRoles(user.id);
22026
22031
  }
22032
+ async getUserPermissions(user) {
22033
+ return await this.authService.userRolesService.getUserPermissions(user.id);
22034
+ }
22027
22035
  extractTokenFromHeader(request) {
22028
22036
  const [type, token] = request.headers.authorization?.split(" ") ?? [];
22029
22037
  return type === "Bearer" ? token : undefined;