sea-backend-helpers 1.4.1 → 1.5.1

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 (34) hide show
  1. package/dist/validators/index.d.ts +1 -0
  2. package/dist/validators/index.d.ts.map +1 -1
  3. package/dist/validators/index.js +3 -1
  4. package/dist/validators/is-date-after/index.d.ts +3 -0
  5. package/dist/validators/is-date-after/index.d.ts.map +1 -0
  6. package/dist/validators/is-date-after/index.js +31 -0
  7. package/package.json +2 -2
  8. package/dist/guards/index.d.ts +0 -3
  9. package/dist/guards/index.d.ts.map +0 -1
  10. package/dist/guards/index.js +0 -7
  11. package/dist/guards/jwt-auth/index.d.ts +0 -1
  12. package/dist/guards/jwt-auth/index.d.ts.map +0 -1
  13. package/dist/guards/jwt-auth/index.js +0 -1
  14. package/dist/guards/jwt-auth-guard/index.d.ts +0 -4
  15. package/dist/guards/jwt-auth-guard/index.d.ts.map +0 -1
  16. package/dist/guards/jwt-auth-guard/index.js +0 -34
  17. package/dist/guards/jwt-auth-guard/jwt-auth.guard.d.ts +0 -5
  18. package/dist/guards/jwt-auth-guard/jwt-auth.guard.d.ts.map +0 -1
  19. package/dist/guards/jwt-auth-guard/jwt-auth.guard.js +0 -34
  20. package/dist/guards/jwt-auth.guard.d.ts +0 -5
  21. package/dist/guards/jwt-auth.guard.d.ts.map +0 -1
  22. package/dist/guards/jwt-auth.guard.js +0 -34
  23. package/dist/guards/jwt-authorization-guard/index..d.ts +0 -9
  24. package/dist/guards/jwt-authorization-guard/index..d.ts.map +0 -1
  25. package/dist/guards/jwt-authorization-guard/index..js +0 -48
  26. package/dist/guards/jwt-authorization-guard/index.d.ts +0 -9
  27. package/dist/guards/jwt-authorization-guard/index.d.ts.map +0 -1
  28. package/dist/guards/jwt-authorization-guard/index.js +0 -48
  29. package/dist/guards/jwt-authorization-guard/jwt-authorization.guard.d.ts +0 -9
  30. package/dist/guards/jwt-authorization-guard/jwt-authorization.guard.d.ts.map +0 -1
  31. package/dist/guards/jwt-authorization-guard/jwt-authorization.guard.js +0 -48
  32. package/dist/guards/jwt-authorization.guard.d.ts +0 -9
  33. package/dist/guards/jwt-authorization.guard.d.ts.map +0 -1
  34. package/dist/guards/jwt-authorization.guard.js +0 -48
@@ -1,3 +1,4 @@
1
1
  export { IsArrayValuesInConstraint } from "./is-array-values-in";
2
2
  export { IsDateRangeWithinLimit } from "./is-date-range-within-limit";
3
+ export { IsDateAfter } from "./is-date-after";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsDateRangeWithinLimit = exports.IsArrayValuesInConstraint = void 0;
3
+ exports.IsDateAfter = exports.IsDateRangeWithinLimit = exports.IsArrayValuesInConstraint = void 0;
4
4
  var is_array_values_in_1 = require("./is-array-values-in");
5
5
  Object.defineProperty(exports, "IsArrayValuesInConstraint", { enumerable: true, get: function () { return is_array_values_in_1.IsArrayValuesInConstraint; } });
6
6
  var is_date_range_within_limit_1 = require("./is-date-range-within-limit");
7
7
  Object.defineProperty(exports, "IsDateRangeWithinLimit", { enumerable: true, get: function () { return is_date_range_within_limit_1.IsDateRangeWithinLimit; } });
8
+ var is_date_after_1 = require("./is-date-after");
9
+ Object.defineProperty(exports, "IsDateAfter", { enumerable: true, get: function () { return is_date_after_1.IsDateAfter; } });
@@ -0,0 +1,3 @@
1
+ import { ValidationOptions } from "class-validator";
2
+ export declare function IsDateAfter(startKey: string, endKey: string, validationOptions?: ValidationOptions): (constructor: any) => void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validators/is-date-after/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,iBAAiB,EAElB,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,iBAAiB,CAAC,EAAE,iBAAiB,iBAEP,GAAG,UA0BlC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsDateAfter = IsDateAfter;
4
+ // file: validators/is-date-after.ts
5
+ const class_validator_1 = require("class-validator");
6
+ function IsDateAfter(startKey, endKey, validationOptions) {
7
+ return function (constructor) {
8
+ (0, class_validator_1.registerDecorator)({
9
+ name: "IsDateAfter",
10
+ target: constructor,
11
+ propertyName: endKey,
12
+ options: validationOptions,
13
+ constraints: [startKey, endKey],
14
+ validator: {
15
+ validate(_, args) {
16
+ const [startKey, endKey] = args.constraints;
17
+ const obj = args.object;
18
+ const start = new Date(obj[startKey]);
19
+ const end = new Date(obj[endKey]);
20
+ if (isNaN(start.getTime()) || isNaN(end.getTime()))
21
+ return false;
22
+ return end > start;
23
+ },
24
+ defaultMessage(args) {
25
+ const [startKey, endKey] = args.constraints;
26
+ return `${endKey} must be after ${startKey}`;
27
+ },
28
+ },
29
+ });
30
+ };
31
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sea-backend-helpers",
3
3
  "description": "SEA Backend helpers library",
4
- "version": "1.4.1",
4
+ "version": "1.5.1",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc --build",
@@ -27,7 +27,7 @@
27
27
  "reflect-metadata": "^0.1.13",
28
28
  "rxjs": "^7.0.0",
29
29
  "sea-backend-helpers": "file:",
30
- "sea-platform-helpers": "^1.3.1"
30
+ "sea-platform-helpers": "^1.5.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@nestjs/common": "^10.0.0",
@@ -1,3 +0,0 @@
1
- export { createJWTAuthGuard } from "./jwt-auth-guard";
2
- export { JWTAuthorizationGuard } from "./jwt-authorization-guard";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JWTAuthorizationGuard = exports.createJWTAuthGuard = void 0;
4
- var jwt_auth_guard_1 = require("./jwt-auth-guard");
5
- Object.defineProperty(exports, "createJWTAuthGuard", { enumerable: true, get: function () { return jwt_auth_guard_1.createJWTAuthGuard; } });
6
- var jwt_authorization_guard_1 = require("./jwt-authorization-guard");
7
- Object.defineProperty(exports, "JWTAuthorizationGuard", { enumerable: true, get: function () { return jwt_authorization_guard_1.JWTAuthorizationGuard; } });
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/guards/jwt-auth/index.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,4 +0,0 @@
1
- import { CanActivate } from "@nestjs/common";
2
- import { JwtVerifyOptions } from "@nestjs/jwt";
3
- export declare function createJWTAuthGuard(verifyJWT: (token: string, options?: JwtVerifyOptions) => any, getConfig: <T>(name: string) => T, secretKeyName: string): CanActivate;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/guards/jwt-auth-guard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,GAAG,EAC7D,SAAS,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,EACjC,aAAa,EAAE,MAAM,GACpB,WAAW,CAmCb"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createJWTAuthGuard = createJWTAuthGuard;
4
- const common_1 = require("@nestjs/common");
5
- function createJWTAuthGuard(verifyJWT, getConfig, secretKeyName) {
6
- return {
7
- canActivate(context) {
8
- const request = context
9
- .switchToHttp()
10
- .getRequest();
11
- const authorization = request.headers.get("authorization");
12
- if (!authorization) {
13
- throw new common_1.UnauthorizedException("Missing Authorization header (Bearer token)");
14
- }
15
- const token = authorization.startsWith("Bearer ")
16
- ? authorization.slice(7)
17
- : authorization;
18
- try {
19
- const secret = getConfig(secretKeyName);
20
- const payload = verifyJWT(token, { secret });
21
- request.context = {
22
- id: payload.id,
23
- account: undefined,
24
- permissionKeys: payload.permissionKeys,
25
- applicationKeys: payload.applicationKeys,
26
- };
27
- return true;
28
- }
29
- catch (err) {
30
- throw new common_1.UnauthorizedException("Invalid or expired token");
31
- }
32
- },
33
- };
34
- }
@@ -1,5 +0,0 @@
1
- import { CanActivate } from "@nestjs/common";
2
- import { JwtService } from "@nestjs/jwt";
3
- import { ConfigService } from "@nestjs/config";
4
- export declare function createJWTAuthGuard(jwtService: JwtService, configService: ConfigService, secretKeyName: string): CanActivate;
5
- //# sourceMappingURL=jwt-auth.guard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt-auth.guard.d.ts","sourceRoot":"","sources":["../../../src/guards/jwt-auth-guard/jwt-auth.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,MAAM,GACpB,WAAW,CAmCb"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createJWTAuthGuard = createJWTAuthGuard;
4
- const common_1 = require("@nestjs/common");
5
- function createJWTAuthGuard(jwtService, configService, secretKeyName) {
6
- return {
7
- canActivate(context) {
8
- const request = context
9
- .switchToHttp()
10
- .getRequest();
11
- const authorization = request.headers.get("authorization");
12
- if (!authorization) {
13
- throw new common_1.UnauthorizedException("Missing Authorization header (Bearer token)");
14
- }
15
- const token = authorization.startsWith("Bearer ")
16
- ? authorization.slice(7)
17
- : authorization;
18
- try {
19
- const secret = configService.get(secretKeyName);
20
- const payload = jwtService.verify(token, { secret });
21
- request.context = {
22
- id: payload.id,
23
- account: undefined,
24
- permissionKeys: payload.permissionKeys,
25
- applicationKeys: payload.applicationKeys,
26
- };
27
- return true;
28
- }
29
- catch (err) {
30
- throw new common_1.UnauthorizedException("Invalid or expired token");
31
- }
32
- },
33
- };
34
- }
@@ -1,5 +0,0 @@
1
- import { CanActivate } from "@nestjs/common";
2
- import { JwtService } from "@nestjs/jwt";
3
- import { ConfigService } from "@nestjs/config";
4
- export declare function createJWTAuthGuard(jwtService: JwtService, configService: ConfigService, secretKeyName: string): CanActivate;
5
- //# sourceMappingURL=jwt-auth.guard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt-auth.guard.d.ts","sourceRoot":"","sources":["../../src/guards/jwt-auth.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,MAAM,GACpB,WAAW,CAmCb"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createJWTAuthGuard = createJWTAuthGuard;
4
- const common_1 = require("@nestjs/common");
5
- function createJWTAuthGuard(jwtService, configService, secretKeyName) {
6
- return {
7
- canActivate(context) {
8
- const request = context
9
- .switchToHttp()
10
- .getRequest();
11
- const authorization = request.headers.get("authorization");
12
- if (!authorization) {
13
- throw new common_1.UnauthorizedException("Missing Authorization header (Bearer token)");
14
- }
15
- const token = authorization.startsWith("Bearer ")
16
- ? authorization.slice(7)
17
- : authorization;
18
- try {
19
- const secret = configService.get(secretKeyName);
20
- const payload = jwtService.verify(token, { secret });
21
- request.context = {
22
- id: payload.id,
23
- account: undefined,
24
- permissionKeys: payload.permissionKeys,
25
- applicationKeys: payload.applicationKeys,
26
- };
27
- return true;
28
- }
29
- catch (err) {
30
- throw new common_1.UnauthorizedException("Invalid or expired token");
31
- }
32
- },
33
- };
34
- }
@@ -1,9 +0,0 @@
1
- import { CanActivate, ExecutionContext } from "@nestjs/common";
2
- import { Reflector } from "@nestjs/core";
3
- export declare class JWTAuthorizationGuard implements CanActivate {
4
- private readonly reflector;
5
- constructor(reflector: Reflector);
6
- canActivate(context: ExecutionContext): boolean;
7
- private checkPermissions;
8
- }
9
- //# sourceMappingURL=index..d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index..d.ts","sourceRoot":"","sources":["../../../src/guards/jwt-authorization-guard/index..ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,qBACa,qBAAsB,YAAW,WAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAEjD,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IA4B/C,OAAO,CAAC,gBAAgB;CAgBzB"}
@@ -1,48 +0,0 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.JWTAuthorizationGuard = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const core_1 = require("@nestjs/core");
15
- let JWTAuthorizationGuard = class JWTAuthorizationGuard {
16
- constructor(reflector) {
17
- this.reflector = reflector;
18
- }
19
- canActivate(context) {
20
- var _a;
21
- const requiredPermissions = this.reflector.get("permissions", context.getHandler()) || [];
22
- const strategy = this.reflector.get("permissionStrategy", context.getHandler()) || "all";
23
- const request = context
24
- .switchToHttp()
25
- .getRequest();
26
- if (!((_a = request.context) === null || _a === void 0 ? void 0 : _a.permissionKeys)) {
27
- throw new common_1.UnauthorizedException("Missing permissions in request context");
28
- }
29
- return this.checkPermissions(request.context.permissionKeys, requiredPermissions, strategy);
30
- }
31
- checkPermissions(userPermissions, required, strategy) {
32
- switch (strategy) {
33
- case "all":
34
- return required.every((p) => userPermissions.includes(p));
35
- case "some":
36
- return required.some((p) => userPermissions.includes(p));
37
- case "one":
38
- return required.length > 0 && userPermissions.includes(required[0]);
39
- default:
40
- return false;
41
- }
42
- }
43
- };
44
- exports.JWTAuthorizationGuard = JWTAuthorizationGuard;
45
- exports.JWTAuthorizationGuard = JWTAuthorizationGuard = __decorate([
46
- (0, common_1.Injectable)(),
47
- __metadata("design:paramtypes", [core_1.Reflector])
48
- ], JWTAuthorizationGuard);
@@ -1,9 +0,0 @@
1
- import { CanActivate, ExecutionContext } from "@nestjs/common";
2
- import { Reflector } from "@nestjs/core";
3
- export declare class JWTAuthorizationGuard implements CanActivate {
4
- private readonly reflector;
5
- constructor(reflector: Reflector);
6
- canActivate(context: ExecutionContext): boolean;
7
- private checkPermissions;
8
- }
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/guards/jwt-authorization-guard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,qBACa,qBAAsB,YAAW,WAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAEjD,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IA4B/C,OAAO,CAAC,gBAAgB;CAgBzB"}
@@ -1,48 +0,0 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.JWTAuthorizationGuard = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const core_1 = require("@nestjs/core");
15
- let JWTAuthorizationGuard = class JWTAuthorizationGuard {
16
- constructor(reflector) {
17
- this.reflector = reflector;
18
- }
19
- canActivate(context) {
20
- var _a;
21
- const requiredPermissions = this.reflector.get("permissions", context.getHandler()) || [];
22
- const strategy = this.reflector.get("permissionStrategy", context.getHandler()) || "all";
23
- const request = context
24
- .switchToHttp()
25
- .getRequest();
26
- if (!((_a = request.context) === null || _a === void 0 ? void 0 : _a.permissionKeys)) {
27
- throw new common_1.UnauthorizedException("Missing permissions in request context");
28
- }
29
- return this.checkPermissions(request.context.permissionKeys, requiredPermissions, strategy);
30
- }
31
- checkPermissions(userPermissions, required, strategy) {
32
- switch (strategy) {
33
- case "all":
34
- return required.every((p) => userPermissions.includes(p));
35
- case "some":
36
- return required.some((p) => userPermissions.includes(p));
37
- case "one":
38
- return required.length > 0 && userPermissions.includes(required[0]);
39
- default:
40
- return false;
41
- }
42
- }
43
- };
44
- exports.JWTAuthorizationGuard = JWTAuthorizationGuard;
45
- exports.JWTAuthorizationGuard = JWTAuthorizationGuard = __decorate([
46
- (0, common_1.Injectable)(),
47
- __metadata("design:paramtypes", [core_1.Reflector])
48
- ], JWTAuthorizationGuard);
@@ -1,9 +0,0 @@
1
- import { CanActivate, ExecutionContext } from "@nestjs/common";
2
- import { Reflector } from "@nestjs/core";
3
- export declare class JWTAuthorizationGuard implements CanActivate {
4
- private readonly reflector;
5
- constructor(reflector: Reflector);
6
- canActivate(context: ExecutionContext): boolean;
7
- private checkPermissions;
8
- }
9
- //# sourceMappingURL=jwt-authorization.guard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt-authorization.guard.d.ts","sourceRoot":"","sources":["../../../src/guards/jwt-authorization-guard/jwt-authorization.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,qBACa,qBAAsB,YAAW,WAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAEjD,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IA4B/C,OAAO,CAAC,gBAAgB;CAgBzB"}
@@ -1,48 +0,0 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.JWTAuthorizationGuard = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const core_1 = require("@nestjs/core");
15
- let JWTAuthorizationGuard = class JWTAuthorizationGuard {
16
- constructor(reflector) {
17
- this.reflector = reflector;
18
- }
19
- canActivate(context) {
20
- var _a;
21
- const requiredPermissions = this.reflector.get("permissions", context.getHandler()) || [];
22
- const strategy = this.reflector.get("permissionStrategy", context.getHandler()) || "all";
23
- const request = context
24
- .switchToHttp()
25
- .getRequest();
26
- if (!((_a = request.context) === null || _a === void 0 ? void 0 : _a.permissionKeys)) {
27
- throw new common_1.UnauthorizedException("Missing permissions in request context");
28
- }
29
- return this.checkPermissions(request.context.permissionKeys, requiredPermissions, strategy);
30
- }
31
- checkPermissions(userPermissions, required, strategy) {
32
- switch (strategy) {
33
- case "all":
34
- return required.every((p) => userPermissions.includes(p));
35
- case "some":
36
- return required.some((p) => userPermissions.includes(p));
37
- case "one":
38
- return required.length > 0 && userPermissions.includes(required[0]);
39
- default:
40
- return false;
41
- }
42
- }
43
- };
44
- exports.JWTAuthorizationGuard = JWTAuthorizationGuard;
45
- exports.JWTAuthorizationGuard = JWTAuthorizationGuard = __decorate([
46
- (0, common_1.Injectable)(),
47
- __metadata("design:paramtypes", [core_1.Reflector])
48
- ], JWTAuthorizationGuard);
@@ -1,9 +0,0 @@
1
- import { CanActivate, ExecutionContext } from "@nestjs/common";
2
- import { Reflector } from "@nestjs/core";
3
- export declare class JWTAuthorizationGuard implements CanActivate {
4
- private readonly reflector;
5
- constructor(reflector: Reflector);
6
- canActivate(context: ExecutionContext): boolean;
7
- private checkPermissions;
8
- }
9
- //# sourceMappingURL=jwt-authorization.guard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt-authorization.guard.d.ts","sourceRoot":"","sources":["../../src/guards/jwt-authorization.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,qBACa,qBAAsB,YAAW,WAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAEjD,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IA4B/C,OAAO,CAAC,gBAAgB;CAgBzB"}
@@ -1,48 +0,0 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.JWTAuthorizationGuard = void 0;
13
- const common_1 = require("@nestjs/common");
14
- const core_1 = require("@nestjs/core");
15
- let JWTAuthorizationGuard = class JWTAuthorizationGuard {
16
- constructor(reflector) {
17
- this.reflector = reflector;
18
- }
19
- canActivate(context) {
20
- var _a;
21
- const requiredPermissions = this.reflector.get("permissions", context.getHandler()) || [];
22
- const strategy = this.reflector.get("permissionStrategy", context.getHandler()) || "all";
23
- const request = context
24
- .switchToHttp()
25
- .getRequest();
26
- if (!((_a = request.context) === null || _a === void 0 ? void 0 : _a.permissionKeys)) {
27
- throw new common_1.UnauthorizedException("Missing permissions in request context");
28
- }
29
- return this.checkPermissions(request.context.permissionKeys, requiredPermissions, strategy);
30
- }
31
- checkPermissions(userPermissions, required, strategy) {
32
- switch (strategy) {
33
- case "all":
34
- return required.every((p) => userPermissions.includes(p));
35
- case "some":
36
- return required.some((p) => userPermissions.includes(p));
37
- case "one":
38
- return required.length > 0 && userPermissions.includes(required[0]);
39
- default:
40
- return false;
41
- }
42
- }
43
- };
44
- exports.JWTAuthorizationGuard = JWTAuthorizationGuard;
45
- exports.JWTAuthorizationGuard = JWTAuthorizationGuard = __decorate([
46
- (0, common_1.Injectable)(),
47
- __metadata("design:paramtypes", [core_1.Reflector])
48
- ], JWTAuthorizationGuard);