plac-micro-common 1.2.2 → 1.2.3

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.
@@ -13,6 +13,7 @@ exports.PermissionsGuard = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const core_1 = require("@nestjs/core");
15
15
  const constants_1 = require("../constants");
16
+ const types_1 = require("../../types");
16
17
  let PermissionsGuard = class PermissionsGuard {
17
18
  constructor(reflector) {
18
19
  this.reflector = reflector;
@@ -28,13 +29,16 @@ let PermissionsGuard = class PermissionsGuard {
28
29
  ? req.current_permissions
29
30
  : [];
30
31
  if (!perms.length) {
31
- // If JWT guard didn't run, or token had no permissions
32
- throw new common_1.UnauthorizedException("Missing permissions in request");
32
+ throw new common_1.UnauthorizedException("The current request does not consist of any permissions!");
33
33
  }
34
34
  // require ALL permissions by default
35
35
  const hasAll = required.every((p) => perms.includes(p));
36
36
  if (!hasAll) {
37
- throw new common_1.ForbiddenException("Insufficient permissions");
37
+ throw new common_1.ForbiddenException({
38
+ code: types_1.ErrorCode.PermissionDenied,
39
+ message: "The user does not have sufficient permissions to access this resource or perform this action!",
40
+ details: constants_1.REQUIRE_PERMISSIONS_KEY,
41
+ });
38
42
  }
39
43
  return true;
40
44
  }
@@ -1,4 +1,5 @@
1
1
  export declare enum ErrorCode {
2
2
  AccessTokenExpired = "ACCESS_TOKEN_EXPIRED",
3
- InvalidToken = "INVALID_TOKEN"
3
+ InvalidToken = "INVALID_TOKEN",
4
+ PermissionDenied = "PERMISSION_DENIED"
4
5
  }
@@ -5,4 +5,5 @@ var ErrorCode;
5
5
  (function (ErrorCode) {
6
6
  ErrorCode["AccessTokenExpired"] = "ACCESS_TOKEN_EXPIRED";
7
7
  ErrorCode["InvalidToken"] = "INVALID_TOKEN";
8
+ ErrorCode["PermissionDenied"] = "PERMISSION_DENIED";
8
9
  })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plac-micro-common",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {