@pristine-ts/validation 0.0.198 → 0.0.201
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.
- package/dist/lib/cjs/decorators/body-validation.decorator.js +18 -1
- package/dist/lib/cjs/decorators/body-validation.decorator.js.map +1 -1
- package/dist/lib/cjs/interceptors/body-validation.request-interceptor.js +21 -2
- package/dist/lib/cjs/interceptors/body-validation.request-interceptor.js.map +1 -1
- package/dist/lib/esm/decorators/body-validation.decorator.js +18 -1
- package/dist/lib/esm/decorators/body-validation.decorator.js.map +1 -1
- package/dist/lib/esm/interceptors/body-validation.request-interceptor.js +21 -2
- package/dist/lib/esm/interceptors/body-validation.request-interceptor.js.map +1 -1
- package/dist/types/decorators/body-validation.decorator.d.ts +5 -1
- package/dist/types/interceptors/body-validation.request-interceptor.d.ts +17 -0
- package/package.json +5 -5
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bodyValidation = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The bodyValidation decorator can be used to validate the body of a request.
|
|
6
|
+
* @param classType The class that the request body is expected to fit.
|
|
7
|
+
*/
|
|
4
8
|
const bodyValidation = (classType) => {
|
|
5
|
-
return (
|
|
9
|
+
return (
|
|
10
|
+
/**
|
|
11
|
+
* The class on which the decorator is used.
|
|
12
|
+
*/
|
|
13
|
+
target,
|
|
14
|
+
/**
|
|
15
|
+
* The method on which the decorator is used.
|
|
16
|
+
*/
|
|
17
|
+
propertyKey,
|
|
18
|
+
/**
|
|
19
|
+
* The descriptor of the property.
|
|
20
|
+
*/
|
|
21
|
+
descriptor) => {
|
|
6
22
|
// If there's a descriptor, then it's not a controller guard, but a method guard
|
|
7
23
|
if (target.constructor.prototype.hasOwnProperty("__metadata__") === false) {
|
|
8
24
|
target.constructor.prototype["__metadata__"] = {};
|
|
@@ -16,6 +32,7 @@ const bodyValidation = (classType) => {
|
|
|
16
32
|
if (target.constructor.prototype["__metadata__"]["methods"][propertyKey].hasOwnProperty("__routeContext__") === false) {
|
|
17
33
|
target.constructor.prototype["__metadata__"]["methods"][propertyKey]["__routeContext__"] = {};
|
|
18
34
|
}
|
|
35
|
+
// Adds the validation to the route context.
|
|
19
36
|
target.constructor.prototype["__metadata__"]["methods"][propertyKey]["__routeContext__"]["bodyValidator"] = {
|
|
20
37
|
classType,
|
|
21
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-validation.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/body-validation.decorator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"body-validation.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/body-validation.decorator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,SAAmB,EAAE,EAAE;IAClD,OAAO;IACH;;OAEG;IACH,MAAc;IAEd;;OAEG;IACH,WAA4B;IAE5B;;OAEG;IACH,UAA8B,EAChC,EAAE;QAEA,gFAAgF;QAChF,IAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,cAAc,CAAC,KAAK,KAAK,EAAE;YACtE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,CAAA;SACpD;QAED,IAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,KAAK,EAAE;YACjF,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAA;SAC/D;QAED,IAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,KAAK,KAAK,EAAE;YAC9F,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAA;SAC5E;QAED,IAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,kBAAkB,CAAC,KAAK,KAAK,EAAE;YAClH,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAA;SAChG;QAED,4CAA4C;QAC5C,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAAC,kBAAkB,CAAC,CAAC,eAAe,CAAC,GAAG;YACxG,SAAS;SACZ,CAAC;IACN,CAAC,CAAA;AACL,CAAC,CAAA;AAxCY,QAAA,cAAc,kBAwC1B"}
|
|
@@ -28,26 +28,45 @@ const common_1 = require("@pristine-ts/common");
|
|
|
28
28
|
const validation_module_keyname_1 = require("../validation.module.keyname");
|
|
29
29
|
const tsyringe_1 = require("tsyringe");
|
|
30
30
|
const class_transformer_1 = require("class-transformer");
|
|
31
|
+
/**
|
|
32
|
+
* This class is an interceptor to validate the body of an incoming request.
|
|
33
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
34
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
35
|
+
*/
|
|
31
36
|
let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
37
|
+
/**
|
|
38
|
+
* This class is an interceptor to validate the body of an incoming request.
|
|
39
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
40
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
41
|
+
* @param loghandler The log handler to output logs.
|
|
42
|
+
*/
|
|
32
43
|
constructor(loghandler) {
|
|
33
44
|
this.loghandler = loghandler;
|
|
34
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Intercepts the request and validates that the body of the request matches the expected class.
|
|
48
|
+
* It also validates the content of properties using the class-validator library.
|
|
49
|
+
* @param request The request being intercepted.
|
|
50
|
+
* @param methodNode The method node.
|
|
51
|
+
*/
|
|
35
52
|
interceptRequest(request, methodNode) {
|
|
36
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
54
|
if (methodNode.route.context.bodyValidator === undefined || methodNode.route.context.bodyValidator.classType === undefined) {
|
|
38
55
|
return request;
|
|
39
56
|
}
|
|
40
|
-
// Validate, else reject by throwing an error.
|
|
41
|
-
const mappedBody = class_transformer_1.plainToClass(methodNode.route.context.bodyValidator.classType, request.body);
|
|
42
57
|
this.loghandler.debug("BodyValidationRequestEnricher", {
|
|
43
58
|
request,
|
|
44
59
|
methodNode,
|
|
45
60
|
routeContext: methodNode.route.context,
|
|
46
61
|
}, validation_module_keyname_1.ValidationModuleKeyname);
|
|
62
|
+
// Validates that the body can be mapped to the expected type
|
|
63
|
+
const mappedBody = class_transformer_1.plainToClass(methodNode.route.context.bodyValidator.classType, request.body);
|
|
64
|
+
// Validates if all the conditions are respected in the expected type.
|
|
47
65
|
const errors = yield class_validator_1.validate(mappedBody);
|
|
48
66
|
if (errors.length == 0) {
|
|
49
67
|
return request;
|
|
50
68
|
}
|
|
69
|
+
// If we received some error while validating we reject by throwing an error.
|
|
51
70
|
throw new networking_1.BadRequestHttpError("Validation error", errors);
|
|
52
71
|
});
|
|
53
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAAyC;AACzC,wDAA4D;AAC5D,gDAAyF;AACzF,4EAAqE;AACrE,uCAA4C;AAC5C,yDAAiD;
|
|
1
|
+
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"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;IASI,WAAA,iBAAM,CAAC,qBAAqB,CAAC,CAAA;;GARjC,gCAAgC,CAyC5C;AAzCY,4EAAgC"}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bodyValidation decorator can be used to validate the body of a request.
|
|
3
|
+
* @param classType The class that the request body is expected to fit.
|
|
4
|
+
*/
|
|
1
5
|
export const bodyValidation = (classType) => {
|
|
2
|
-
return (
|
|
6
|
+
return (
|
|
7
|
+
/**
|
|
8
|
+
* The class on which the decorator is used.
|
|
9
|
+
*/
|
|
10
|
+
target,
|
|
11
|
+
/**
|
|
12
|
+
* The method on which the decorator is used.
|
|
13
|
+
*/
|
|
14
|
+
propertyKey,
|
|
15
|
+
/**
|
|
16
|
+
* The descriptor of the property.
|
|
17
|
+
*/
|
|
18
|
+
descriptor) => {
|
|
3
19
|
// If there's a descriptor, then it's not a controller guard, but a method guard
|
|
4
20
|
if (target.constructor.prototype.hasOwnProperty("__metadata__") === false) {
|
|
5
21
|
target.constructor.prototype["__metadata__"] = {};
|
|
@@ -13,6 +29,7 @@ export const bodyValidation = (classType) => {
|
|
|
13
29
|
if (target.constructor.prototype["__metadata__"]["methods"][propertyKey].hasOwnProperty("__routeContext__") === false) {
|
|
14
30
|
target.constructor.prototype["__metadata__"]["methods"][propertyKey]["__routeContext__"] = {};
|
|
15
31
|
}
|
|
32
|
+
// Adds the validation to the route context.
|
|
16
33
|
target.constructor.prototype["__metadata__"]["methods"][propertyKey]["__routeContext__"]["bodyValidator"] = {
|
|
17
34
|
classType,
|
|
18
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-validation.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/body-validation.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"body-validation.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/body-validation.decorator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,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C,CAAA"}
|
|
@@ -25,26 +25,45 @@ import { moduleScoped, ServiceDefinitionTagEnum, tag } from "@pristine-ts/common
|
|
|
25
25
|
import { ValidationModuleKeyname } from "../validation.module.keyname";
|
|
26
26
|
import { injectable, inject } from "tsyringe";
|
|
27
27
|
import { plainToClass } from 'class-transformer';
|
|
28
|
+
/**
|
|
29
|
+
* This class is an interceptor to validate the body of an incoming request.
|
|
30
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
31
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
32
|
+
*/
|
|
28
33
|
let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
34
|
+
/**
|
|
35
|
+
* This class is an interceptor to validate the body of an incoming request.
|
|
36
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
37
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
38
|
+
* @param loghandler The log handler to output logs.
|
|
39
|
+
*/
|
|
29
40
|
constructor(loghandler) {
|
|
30
41
|
this.loghandler = loghandler;
|
|
31
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Intercepts the request and validates that the body of the request matches the expected class.
|
|
45
|
+
* It also validates the content of properties using the class-validator library.
|
|
46
|
+
* @param request The request being intercepted.
|
|
47
|
+
* @param methodNode The method node.
|
|
48
|
+
*/
|
|
32
49
|
interceptRequest(request, methodNode) {
|
|
33
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
51
|
if (methodNode.route.context.bodyValidator === undefined || methodNode.route.context.bodyValidator.classType === undefined) {
|
|
35
52
|
return request;
|
|
36
53
|
}
|
|
37
|
-
// Validate, else reject by throwing an error.
|
|
38
|
-
const mappedBody = plainToClass(methodNode.route.context.bodyValidator.classType, request.body);
|
|
39
54
|
this.loghandler.debug("BodyValidationRequestEnricher", {
|
|
40
55
|
request,
|
|
41
56
|
methodNode,
|
|
42
57
|
routeContext: methodNode.route.context,
|
|
43
58
|
}, ValidationModuleKeyname);
|
|
59
|
+
// Validates that the body can be mapped to the expected type
|
|
60
|
+
const mappedBody = plainToClass(methodNode.route.context.bodyValidator.classType, request.body);
|
|
61
|
+
// Validates if all the conditions are respected in the expected type.
|
|
44
62
|
const errors = yield validate(mappedBody);
|
|
45
63
|
if (errors.length == 0) {
|
|
46
64
|
return request;
|
|
47
65
|
}
|
|
66
|
+
// If we received some error while validating we reject by throwing an error.
|
|
48
67
|
throw new BadRequestHttpError("Validation error", errors);
|
|
49
68
|
});
|
|
50
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAC,UAAU,EA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|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The bodyValidation decorator can be used to validate the body of a request.
|
|
3
|
+
* @param classType The class that the request body is expected to fit.
|
|
4
|
+
*/
|
|
5
|
+
export declare const bodyValidation: (classType: Function) => (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { RequestInterceptorInterface, MethodRouterNode } from "@pristine-ts/networking";
|
|
2
2
|
import { Request } from "@pristine-ts/common";
|
|
3
3
|
import { LogHandlerInterface } from "@pristine-ts/logging";
|
|
4
|
+
/**
|
|
5
|
+
* This class is an interceptor to validate the body of an incoming request.
|
|
6
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
7
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
8
|
+
*/
|
|
4
9
|
export declare class BodyValidationRequestInterceptor implements RequestInterceptorInterface {
|
|
5
10
|
private readonly loghandler;
|
|
11
|
+
/**
|
|
12
|
+
* This class is an interceptor to validate the body of an incoming request.
|
|
13
|
+
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
14
|
+
* It is module scoped to the Validation module so that it is only registered if the validation module is imported.
|
|
15
|
+
* @param loghandler The log handler to output logs.
|
|
16
|
+
*/
|
|
6
17
|
constructor(loghandler: LogHandlerInterface);
|
|
18
|
+
/**
|
|
19
|
+
* Intercepts the request and validates that the body of the request matches the expected class.
|
|
20
|
+
* It also validates the content of properties using the class-validator library.
|
|
21
|
+
* @param request The request being intercepted.
|
|
22
|
+
* @param methodNode The method node.
|
|
23
|
+
*/
|
|
7
24
|
interceptRequest(request: Request, methodNode: MethodRouterNode): Promise<Request>;
|
|
8
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/validation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.201",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/validation.module.js",
|
|
6
6
|
"main": "dist/lib/cjs/validation.module.js",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"test:cov": "jest --coverage"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@pristine-ts/common": "^0.0.
|
|
16
|
-
"@pristine-ts/core": "^0.0.
|
|
17
|
-
"@pristine-ts/networking": "^0.0.
|
|
15
|
+
"@pristine-ts/common": "^0.0.201",
|
|
16
|
+
"@pristine-ts/core": "^0.0.201",
|
|
17
|
+
"@pristine-ts/networking": "^0.0.201",
|
|
18
18
|
"class-transformer": "^0.4.0",
|
|
19
19
|
"class-validator": "^0.13.1"
|
|
20
20
|
},
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"src/*.{js,ts}"
|
|
61
61
|
]
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "b598572236c71ba1bc08697777d8455b890a7c50"
|
|
64
64
|
}
|