node-pluginsmanager-plugin 6.1.0 → 6.2.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.
- package/lib/cjs/components/Mediator.js +2 -2
- package/lib/cjs/components/Server.js +4 -2
- package/lib/cjs/utils/cleanSendedError.d.ts +1 -1
- package/lib/cjs/utils/descriptor/extractPattern.d.ts +1 -1
- package/lib/cjs/utils/descriptor/extractSchemaType.d.ts +1 -1
- package/lib/cjs/utils/send.js +9 -4
- package/package.json +1 -1
|
@@ -88,14 +88,14 @@ class Mediator extends DescriptorUser_1.default {
|
|
|
88
88
|
return !foundPathMethod ? Promise.reject(new ReferenceError("Unknown operationId \"" + operationId + "\"")) : new Promise((resolve, reject) => {
|
|
89
89
|
// no content, no validation
|
|
90
90
|
if (204 === res.statusCode) {
|
|
91
|
-
return "undefined" !== typeof res.body ? reject(new ReferenceError("You should not have content data with 204 statusCode")) : resolve();
|
|
91
|
+
return "undefined" !== typeof res.body && "" !== res.body.trim() ? reject(new ReferenceError("You should not have content data with 204 statusCode")) : resolve();
|
|
92
92
|
}
|
|
93
93
|
// no content, no validation (put requests)
|
|
94
94
|
else if (201 === res.statusCode && "undefined" === typeof res.body) {
|
|
95
95
|
return resolve();
|
|
96
96
|
}
|
|
97
97
|
// validator cannot correctly check pure boolean return
|
|
98
|
-
else if ("undefined" !== typeof res.body && ["true", "false"].includes(res.body)) {
|
|
98
|
+
else if ("undefined" !== typeof res.body && ["true", "false"].includes(res.body.trim())) {
|
|
99
99
|
return resolve();
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
@@ -341,7 +341,8 @@ class Server extends MediatorUser_1.default {
|
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
343
|
else {
|
|
344
|
-
this._log("success", "<= [" + req.validatedIp + "] "
|
|
344
|
+
this._log("success", "<= [" + req.validatedIp + "] "
|
|
345
|
+
+ (Buffer.isBuffer(content) ? "Buffer" : JSON.stringify(content)));
|
|
345
346
|
return (0, send_1.default)(req, res, serverCodes_1.default.OK_PUT, content, {
|
|
346
347
|
"apiVersion": apiVersion,
|
|
347
348
|
"cors": this._cors,
|
|
@@ -359,7 +360,8 @@ class Server extends MediatorUser_1.default {
|
|
|
359
360
|
});
|
|
360
361
|
}
|
|
361
362
|
else {
|
|
362
|
-
this._log("success", "<= [" + req.validatedIp + "] "
|
|
363
|
+
this._log("success", "<= [" + req.validatedIp + "] "
|
|
364
|
+
+ (Buffer.isBuffer(content) ? "Buffer" : JSON.stringify(content)));
|
|
363
365
|
return (0, send_1.default)(req, res, serverCodes_1.default.OK, content, {
|
|
364
366
|
"apiVersion": apiVersion,
|
|
365
367
|
"cors": this._cors,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function cleanSendedError(data: any): string;
|
|
1
|
+
export default function cleanSendedError(data: Error | Record<string, any> | string | null): Record<string, any> | string | null;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { OpenApiDocument } from "express-openapi-validate";
|
|
1
|
+
import type { OpenApiDocument } from "express-openapi-validate";
|
|
2
2
|
export default function extractPattern(paths: OpenApiDocument["paths"], pathname: string, method: string): string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { OpenAPIV3_1 } from "openapi-types";
|
|
1
|
+
import type { OpenAPIV3_1 } from "openapi-types";
|
|
2
2
|
export default function extractSchemaType(schema: OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject, schemas: Record<string, any>): "boolean" | "object" | "number" | "string" | "integer" | "array";
|
package/lib/cjs/utils/send.js
CHANGED
|
@@ -31,13 +31,13 @@ function send(req, res, code, content, options) {
|
|
|
31
31
|
}
|
|
32
32
|
return result;
|
|
33
33
|
}
|
|
34
|
-
}).then((
|
|
34
|
+
}).then((formattedContent) => {
|
|
35
35
|
return new Promise((resolve) => {
|
|
36
36
|
// force data for checking
|
|
37
37
|
res.statusCode = code;
|
|
38
38
|
res.headers = Object.assign({
|
|
39
39
|
"Content-Type": options.mime,
|
|
40
|
-
"Content-Length":
|
|
40
|
+
"Content-Length": formattedContent ? Buffer.byteLength(formattedContent) : 0,
|
|
41
41
|
"Status-Code-Url-Cat": "https://http.cat/" + code,
|
|
42
42
|
"API-Version": options.apiVersion
|
|
43
43
|
}, options.cors ? {
|
|
@@ -71,9 +71,14 @@ function send(req, res, code, content, options) {
|
|
|
71
71
|
} : {});
|
|
72
72
|
// send data
|
|
73
73
|
res.writeHead(res.statusCode, res.headers);
|
|
74
|
-
if (""
|
|
74
|
+
if ("string" === typeof formattedContent) {
|
|
75
75
|
res.body = content; // for Mediator response validator
|
|
76
|
-
res.end(
|
|
76
|
+
res.end(formattedContent, "utf-8", () => {
|
|
77
|
+
resolve();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else if (Buffer.isBuffer(formattedContent)) {
|
|
81
|
+
res.end(formattedContent, () => {
|
|
77
82
|
resolve();
|
|
78
83
|
});
|
|
79
84
|
}
|