@yamato-daiwa/express-extensions 0.2.1 → 0.3.0
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/Distributable/RequestBody/parseAndValidateJSON_RequestBody.d.ts +2 -1
- package/Distributable/RequestBody/parseAndValidateJSON_RequestBody.js +9 -3
- package/Distributable/RequestBody/validateAndProcessJSON_RequestBody.d.ts +4 -3
- package/Distributable/RequestBody/validateAndProcessJSON_RequestBody.js +11 -17
- package/README.md +3 -1
- package/package.json +5 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RawObjectDataProcessor, type ReadonlyParsedJSON } from "@yamato-daiwa/es-extensions";
|
|
2
|
-
export declare function parseAndValidateJSON_RequestBody<RequestData extends ReadonlyParsedJSON>(
|
|
2
|
+
export declare function parseAndValidateJSON_RequestBody<RequestData extends ReadonlyParsedJSON>({ requestBodySizeLimit__bytesPackageFormat, validationAndProcessing, mustLogDataAfterParsing }: Readonly<{
|
|
3
3
|
requestBodySizeLimit__bytesPackageFormat: string | number;
|
|
4
4
|
validationAndProcessing: RawObjectDataProcessor.ObjectDataSpecification;
|
|
5
|
+
mustLogDataAfterParsing?: boolean;
|
|
5
6
|
}>): (request: unknown, response: unknown, toNextMiddleware: (error?: unknown) => void) => void;
|
|
@@ -6,16 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.parseAndValidateJSON_RequestBody = parseAndValidateJSON_RequestBody;
|
|
7
7
|
const body_parser_1 = __importDefault(require("body-parser"));
|
|
8
8
|
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
9
|
-
function parseAndValidateJSON_RequestBody(
|
|
9
|
+
function parseAndValidateJSON_RequestBody({ requestBodySizeLimit__bytesPackageFormat, validationAndProcessing, mustLogDataAfterParsing = false }) {
|
|
10
10
|
return (_request, _response, toNextMiddleware) => {
|
|
11
11
|
const request = _request;
|
|
12
12
|
const response = _response;
|
|
13
|
-
body_parser_1.default.json({ limit:
|
|
13
|
+
body_parser_1.default.json({ limit: requestBodySizeLimit__bytesPackageFormat })(request, response, (error) => {
|
|
14
14
|
if ((0, es_extensions_1.isNeitherUndefinedNorNull)(error)) {
|
|
15
15
|
toNextMiddleware(error);
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
es_extensions_1.Logger.logInfo({
|
|
19
|
+
title: `${request.method.toUpperCase()}::${request.url}`,
|
|
20
|
+
description: "Parsed request body:",
|
|
21
|
+
additionalData: request.body,
|
|
22
|
+
mustOutputIf: mustLogDataAfterParsing
|
|
23
|
+
});
|
|
24
|
+
const requestBodyValidationAndProcessingResult = es_extensions_1.RawObjectDataProcessor.process(request.body, validationAndProcessing);
|
|
19
25
|
if (requestBodyValidationAndProcessingResult.rawDataIsInvalid) {
|
|
20
26
|
response.
|
|
21
27
|
status(es_extensions_1.HTTP_StatusCodes.badRequest).
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { RawObjectDataProcessor } from "@yamato-daiwa/es-extensions";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { RawObjectDataProcessor, type ReadonlyParsedJSON } from "@yamato-daiwa/es-extensions";
|
|
2
|
+
export declare function validateAndProcessJSON_RequestBody<RequestData extends ReadonlyParsedJSON>(validationAndProcessing: RawObjectDataProcessor.ObjectDataSpecification, { mustLogDataAfterParsing }?: Readonly<{
|
|
3
|
+
mustLogDataAfterParsing?: boolean;
|
|
4
|
+
}>): (request: unknown, response: unknown, toNextMiddleware: () => void) => void;
|
|
@@ -2,24 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateAndProcessJSON_RequestBody = validateAndProcessJSON_RequestBody;
|
|
4
4
|
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
5
|
-
function validateAndProcessJSON_RequestBody(
|
|
6
|
-
return (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
messageSpecificPart: `The "request" is not object and has type "${typeof request}"`
|
|
16
|
-
}),
|
|
17
|
-
occurrenceLocation: "validateAndProcessRequestBody -> innerFunction(request, response, toNextMiddleware)"
|
|
18
|
-
});
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
5
|
+
function validateAndProcessJSON_RequestBody(validationAndProcessing, { mustLogDataAfterParsing = false } = { mustLogDataAfterParsing: false }) {
|
|
6
|
+
return (_request, _response, toNextMiddleware) => {
|
|
7
|
+
const request = _request;
|
|
8
|
+
const response = _response;
|
|
9
|
+
es_extensions_1.Logger.logInfo({
|
|
10
|
+
title: `${request.method.toUpperCase()}::${request.url}`,
|
|
11
|
+
description: "Parsed request body:",
|
|
12
|
+
additionalData: request.body,
|
|
13
|
+
mustOutputIf: mustLogDataAfterParsing
|
|
14
|
+
});
|
|
21
15
|
const requestBodyProcessingResult = es_extensions_1.RawObjectDataProcessor.
|
|
22
|
-
process(request.body,
|
|
16
|
+
process(request.body, validationAndProcessing);
|
|
23
17
|
if (requestBodyProcessingResult.rawDataIsInvalid) {
|
|
24
18
|
response.
|
|
25
19
|
status(es_extensions_1.HTTP_StatusCodes.badRequest).
|
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ The wrapper for [`session.destroy(callback)`](https://www.npmjs.com/package/expr
|
|
|
139
139
|
settings: Readonly<{
|
|
140
140
|
requestBodySizeLimit__bytesPackageFormat: string | number;
|
|
141
141
|
validationAndProcessing: RawObjectDataProcessor.ObjectDataSpecification;
|
|
142
|
+
mustLogDataAfterParsing?: boolean;
|
|
142
143
|
}>
|
|
143
144
|
): ExpressMiddleware
|
|
144
145
|
```
|
|
@@ -161,7 +162,8 @@ The *alternative* to [class-transformer](https://github.com/typestack/class-tran
|
|
|
161
162
|
|
|
162
163
|
```
|
|
163
164
|
<RequestData extends ReadonlyParsedJSON>(
|
|
164
|
-
|
|
165
|
+
validationAndProcessing: RawObjectDataProcessor.ObjectDataSpecification,
|
|
166
|
+
{ mustLogDataAfterParsing = false }: Readonly<{ mustLogDataAfterParsing?: boolean; }> = { mustLogDataAfterParsing: false }
|
|
165
167
|
): ExpressMiddleware
|
|
166
168
|
```
|
|
167
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamato-daiwa/express-extensions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Additional functionality for Express.js and also \"routing-controllers\" aimed to reduce the routine code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nodejs",
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"express-session": "~1.18.0",
|
|
35
35
|
"routing-controllers": "~0.11.0"
|
|
36
36
|
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@yamato-daiwa/es-extensions": "1.7.2",
|
|
39
|
+
"fundamental-constants": "0.7.0"
|
|
40
|
+
},
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@types/express-session": "1.18.1",
|
|
39
43
|
"@yamato-daiwa/style_guides": "0.6.3",
|
|
@@ -49,9 +53,5 @@
|
|
|
49
53
|
"Rebuild Distributable": "rimraf Distributable && tsc",
|
|
50
54
|
"Rebuild Distributable and Realize Alpha": "npm run \"Rebuild Distributable\" && npm publish --tag alpha",
|
|
51
55
|
"Rebuild Distributable and Realize RC": "npm run \"Rebuild Distributable\" && npm publish --tag rc"
|
|
52
|
-
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"@yamato-daiwa/es-extensions": "1.7.2",
|
|
55
|
-
"fundamental-constants": "0.7.0"
|
|
56
56
|
}
|
|
57
57
|
}
|