node-pluginsmanager-plugin 6.0.1 → 6.0.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.
@@ -1,31 +1,31 @@
1
- import { iIncomingMessage, iServerResponse } from "./Server";
2
- import DescriptorUser, { iDescriptorUserOptions } from "./DescriptorUser";
3
- import { OpenApiValidator } from "express-openapi-validate";
4
- export interface iIncomingMessageForMediatorValidation extends iIncomingMessage {
5
- "body": any;
6
- }
7
- export interface iServerResponseForMediatorValidation extends iServerResponse {
8
- "body": any;
9
- }
10
- export interface iUrlParameters {
11
- "path": {
12
- [key: string]: any;
13
- };
14
- "query": {
15
- [key: string]: any;
16
- };
17
- "headers": {
18
- [key: string]: any;
19
- };
20
- "cookies": {
21
- [key: string]: any;
22
- };
23
- }
24
- export default class Mediator extends DescriptorUser {
25
- protected _validator: OpenApiValidator | null;
26
- constructor(options: iDescriptorUserOptions);
27
- checkParameters(operationId: string, urlParams: iUrlParameters, bodyParams: string): Promise<void>;
28
- checkResponse(operationId: string, res: iServerResponseForMediatorValidation): Promise<void>;
29
- init(...data: any): Promise<void>;
30
- release(...data: any): Promise<void>;
31
- }
1
+ import { iIncomingMessage, iServerResponse } from "./Server";
2
+ import DescriptorUser, { iDescriptorUserOptions } from "./DescriptorUser";
3
+ import { OpenApiValidator } from "express-openapi-validate";
4
+ export interface iIncomingMessageForMediatorValidation extends iIncomingMessage {
5
+ "body": any;
6
+ }
7
+ export interface iServerResponseForMediatorValidation extends iServerResponse {
8
+ "body": any;
9
+ }
10
+ export interface iUrlParameters {
11
+ "path": {
12
+ [key: string]: any;
13
+ };
14
+ "query": {
15
+ [key: string]: any;
16
+ };
17
+ "headers": {
18
+ [key: string]: any;
19
+ };
20
+ "cookies": {
21
+ [key: string]: any;
22
+ };
23
+ }
24
+ export default class Mediator extends DescriptorUser {
25
+ protected _validator: OpenApiValidator | null;
26
+ constructor(options: iDescriptorUserOptions);
27
+ checkParameters(operationId: string, urlParams: iUrlParameters, bodyParams: any): Promise<void>;
28
+ checkResponse(operationId: string, res: iServerResponseForMediatorValidation): Promise<void>;
29
+ init(...data: any): Promise<void>;
30
+ release(...data: any): Promise<void>;
31
+ }
@@ -8,7 +8,6 @@ const checkObject_1 = require("../checkers/TypeError/checkObject");
8
8
  const checkNonEmptyString_1 = require("../checkers/RangeError/checkNonEmptyString");
9
9
  const checkNonEmptyObject_1 = require("../checkers/RangeError/checkNonEmptyObject");
10
10
  const extractPathMethodByOperationId_1 = __importDefault(require("../utils/descriptor/extractPathMethodByOperationId"));
11
- const jsonParser_1 = __importDefault(require("../utils/jsonParser"));
12
11
  const DescriptorUser_1 = __importDefault(require("./DescriptorUser"));
13
12
  // types & interfaces
14
13
  // externals
@@ -108,9 +107,6 @@ class Mediator extends DescriptorUser_1.default {
108
107
  if ("undefined" === typeof mutedRes.body || "" === mutedRes.body) {
109
108
  mutedRes.body = {};
110
109
  }
111
- else {
112
- mutedRes.body = (0, jsonParser_1.default)(mutedRes.body);
113
- }
114
110
  const validateResponse = this._validator.validateResponse(foundPathMethod.method, foundPathMethod.path);
115
111
  validateResponse(mutedRes);
116
112
  return resolve();
@@ -1,55 +1,55 @@
1
- /// <reference types="node" />
2
- import MediatorUser from "./MediatorUser";
3
- import { IncomingMessage, ServerResponse } from "node:http";
4
- import { Server as WebSocketServer } from "ws";
5
- import { Server as SocketIOServer } from "socket.io";
6
- import { iMediatorUserOptions } from "./MediatorUser";
7
- export interface iClient {
8
- "id": string;
9
- "status": "CONNECTED" | "DISCONNECTED";
10
- }
11
- export interface iIncomingMessage extends IncomingMessage {
12
- "method": string;
13
- "pattern": string;
14
- "validatedIp": string;
15
- "headers": {
16
- [key: string]: any;
17
- };
18
- "cookies": {
19
- [key: string]: any;
20
- };
21
- "query": {
22
- [key: string]: any;
23
- };
24
- "params": {
25
- [key: string]: any;
26
- };
27
- "body": string;
28
- }
29
- export interface iServerResponse extends ServerResponse {
30
- "body": string;
31
- "headers": {
32
- [key: string]: any;
33
- };
34
- }
35
- export default class Server extends MediatorUser {
36
- protected _socketServer: WebSocketServer | SocketIOServer | null;
37
- protected _checkParameters: boolean;
38
- protected _checkResponse: boolean;
39
- protected _cors: boolean;
40
- constructor(opt: iMediatorUserOptions);
41
- protected _serverType(): "NO_SERVER" | "WEBSOCKET" | "SOCKETIO" | "UNKNOWN";
42
- disableCheckParameters(): this;
43
- enableCheckParameters(): this;
44
- disableCheckResponse(): this;
45
- enableCheckResponse(): this;
46
- disableCors(): this;
47
- enableCors(): this;
48
- appMiddleware(req: iIncomingMessage, res: iServerResponse, next: Function): void;
49
- socketMiddleware(socketServer: WebSocketServer | SocketIOServer): void;
50
- push(command: string, data?: any, log?: boolean): this;
51
- getClients(): Array<iClient>;
52
- pushClient(clientId: string, command: string, data: any, log?: boolean): this;
53
- init(...data: any): Promise<void>;
54
- release(...data: any): Promise<void>;
55
- }
1
+ /// <reference types="node" />
2
+ import MediatorUser from "./MediatorUser";
3
+ import { IncomingMessage, ServerResponse } from "node:http";
4
+ import { Server as WebSocketServer } from "ws";
5
+ import { Server as SocketIOServer } from "socket.io";
6
+ import { iMediatorUserOptions } from "./MediatorUser";
7
+ export interface iClient {
8
+ "id": string;
9
+ "status": "CONNECTED" | "DISCONNECTED";
10
+ }
11
+ export interface iIncomingMessage extends IncomingMessage {
12
+ "method": string;
13
+ "pattern": string;
14
+ "validatedIp": string;
15
+ "headers": {
16
+ [key: string]: any;
17
+ };
18
+ "cookies": {
19
+ [key: string]: any;
20
+ };
21
+ "query": {
22
+ [key: string]: any;
23
+ };
24
+ "params": {
25
+ [key: string]: any;
26
+ };
27
+ "body": string;
28
+ }
29
+ export interface iServerResponse extends ServerResponse {
30
+ "body": string;
31
+ "headers": {
32
+ [key: string]: any;
33
+ };
34
+ }
35
+ export default class Server extends MediatorUser {
36
+ protected _socketServer: WebSocketServer | SocketIOServer | null;
37
+ protected _checkParameters: boolean;
38
+ protected _checkResponse: boolean;
39
+ protected _cors: boolean;
40
+ constructor(opt: iMediatorUserOptions);
41
+ protected _serverType(): "NO_SERVER" | "WEBSOCKET" | "SOCKETIO" | "UNKNOWN";
42
+ disableCheckParameters(): this;
43
+ enableCheckParameters(): this;
44
+ disableCheckResponse(): this;
45
+ enableCheckResponse(): this;
46
+ disableCors(): this;
47
+ enableCors(): this;
48
+ appMiddleware(req: iIncomingMessage, res: iServerResponse, next: Function): void;
49
+ socketMiddleware(socketServer: WebSocketServer | SocketIOServer): void;
50
+ push(command: string, data?: any, log?: boolean): this;
51
+ getClients(): Array<iClient>;
52
+ pushClient(clientId: string, command: string, data: any, log?: boolean): this;
53
+ init(...data: any): Promise<void>;
54
+ release(...data: any): Promise<void>;
55
+ }
@@ -1,30 +1,30 @@
1
- import { checkExists, checkExistsSync } from "./checkers/ReferenceError/checkExists";
2
- import { checkBoolean, checkBooleanSync } from "./checkers/TypeError/checkBoolean";
3
- import { checkFunction, checkFunctionSync } from "./checkers/TypeError/checkFunction";
4
- import { checkNumber, checkNumberSync } from "./checkers/TypeError/checkNumber";
5
- import { checkObject, checkObjectSync } from "./checkers/TypeError/checkObject";
6
- import { checkString, checkStringSync } from "./checkers/TypeError/checkString";
7
- import { checkArray, checkArraySync } from "./checkers/TypeError/checkArray";
8
- import { checkInteger, checkIntegerSync } from "./checkers/TypeError/checkInteger";
9
- import { checkNonEmptyArray, checkNonEmptyArraySync } from "./checkers/RangeError/checkNonEmptyArray";
10
- import { checkNonEmptyInteger, checkNonEmptyIntegerSync } from "./checkers/RangeError/checkNonEmptyInteger";
11
- import { checkNonEmptyNumber, checkNonEmptyNumberSync } from "./checkers/RangeError/checkNonEmptyNumber";
12
- import { checkNonEmptyObject, checkNonEmptyObjectSync } from "./checkers/RangeError/checkNonEmptyObject";
13
- import { checkNonEmptyString, checkNonEmptyStringSync } from "./checkers/RangeError/checkNonEmptyString";
14
- import { checkNumberBetween, checkNumberBetweenSync } from "./checkers/RangeError/checkNumberBetween";
15
- import { checkObjectLength, checkObjectLengthSync } from "./checkers/RangeError/checkObjectLength";
16
- import { checkObjectLengthBetween, checkObjectLengthBetweenSync } from "./checkers/RangeError/checkObjectLengthBetween";
17
- import { checkStringLength, checkStringLengthSync } from "./checkers/RangeError/checkStringLength";
18
- import { checkStringLengthBetween, checkStringLengthBetweenSync } from "./checkers/RangeError/checkStringLengthBetween";
19
- import { checkIntegerBetween, checkIntegerBetweenSync } from "./checkers/RangeError/checkIntegerBetween";
20
- import { checkArrayLength, checkArrayLengthSync } from "./checkers/RangeError/checkArrayLength";
21
- import { checkArrayLengthBetween, checkArrayLengthBetweenSync } from "./checkers/RangeError/checkArrayLengthBetween";
22
- export { checkExists, checkExistsSync, checkBoolean, checkBooleanSync, checkFunction, checkFunctionSync, checkNumber, checkNumberSync, checkObject, checkObjectSync, checkString, checkStringSync, checkArray, checkArraySync, checkInteger, checkIntegerSync, checkNonEmptyArray, checkNonEmptyArraySync, checkNonEmptyInteger, checkNonEmptyIntegerSync, checkNonEmptyNumber, checkNonEmptyNumberSync, checkNonEmptyObject, checkNonEmptyObjectSync, checkNonEmptyString, checkNonEmptyStringSync, checkNumberBetween, checkNumberBetweenSync, checkObjectLength, checkObjectLengthSync, checkObjectLengthBetween, checkObjectLengthBetweenSync, checkStringLength, checkStringLengthSync, checkStringLengthBetween, checkStringLengthBetweenSync, checkIntegerBetween, checkIntegerBetweenSync, checkArrayLength, checkArrayLengthSync, checkArrayLengthBetween, checkArrayLengthBetweenSync };
23
- import DescriptorUser, { iDescriptorUserOptions, tLogType, tLogger } from "./components/DescriptorUser";
24
- import Mediator, { iUrlParameters } from "./components/Mediator";
25
- import MediatorUser, { iMediatorUserOptions } from "./components/MediatorUser";
26
- import NotFoundError from "./components/NotFoundError";
27
- import Orchestrator, { iOrchestratorOptions } from "./components/Orchestrator";
28
- import Server, { iClient, iIncomingMessage, iServerResponse } from "./components/Server";
29
- export { tLogType, tLogger, iUrlParameters, iClient, iIncomingMessage, iServerResponse };
30
- export { DescriptorUser, iDescriptorUserOptions, Mediator, MediatorUser, iMediatorUserOptions, NotFoundError, Orchestrator, iOrchestratorOptions, Server };
1
+ import { checkExists, checkExistsSync } from "./checkers/ReferenceError/checkExists";
2
+ import { checkBoolean, checkBooleanSync } from "./checkers/TypeError/checkBoolean";
3
+ import { checkFunction, checkFunctionSync } from "./checkers/TypeError/checkFunction";
4
+ import { checkNumber, checkNumberSync } from "./checkers/TypeError/checkNumber";
5
+ import { checkObject, checkObjectSync } from "./checkers/TypeError/checkObject";
6
+ import { checkString, checkStringSync } from "./checkers/TypeError/checkString";
7
+ import { checkArray, checkArraySync } from "./checkers/TypeError/checkArray";
8
+ import { checkInteger, checkIntegerSync } from "./checkers/TypeError/checkInteger";
9
+ import { checkNonEmptyArray, checkNonEmptyArraySync } from "./checkers/RangeError/checkNonEmptyArray";
10
+ import { checkNonEmptyInteger, checkNonEmptyIntegerSync } from "./checkers/RangeError/checkNonEmptyInteger";
11
+ import { checkNonEmptyNumber, checkNonEmptyNumberSync } from "./checkers/RangeError/checkNonEmptyNumber";
12
+ import { checkNonEmptyObject, checkNonEmptyObjectSync } from "./checkers/RangeError/checkNonEmptyObject";
13
+ import { checkNonEmptyString, checkNonEmptyStringSync } from "./checkers/RangeError/checkNonEmptyString";
14
+ import { checkNumberBetween, checkNumberBetweenSync } from "./checkers/RangeError/checkNumberBetween";
15
+ import { checkObjectLength, checkObjectLengthSync } from "./checkers/RangeError/checkObjectLength";
16
+ import { checkObjectLengthBetween, checkObjectLengthBetweenSync } from "./checkers/RangeError/checkObjectLengthBetween";
17
+ import { checkStringLength, checkStringLengthSync } from "./checkers/RangeError/checkStringLength";
18
+ import { checkStringLengthBetween, checkStringLengthBetweenSync } from "./checkers/RangeError/checkStringLengthBetween";
19
+ import { checkIntegerBetween, checkIntegerBetweenSync } from "./checkers/RangeError/checkIntegerBetween";
20
+ import { checkArrayLength, checkArrayLengthSync } from "./checkers/RangeError/checkArrayLength";
21
+ import { checkArrayLengthBetween, checkArrayLengthBetweenSync } from "./checkers/RangeError/checkArrayLengthBetween";
22
+ export { checkExists, checkExistsSync, checkBoolean, checkBooleanSync, checkFunction, checkFunctionSync, checkNumber, checkNumberSync, checkObject, checkObjectSync, checkString, checkStringSync, checkArray, checkArraySync, checkInteger, checkIntegerSync, checkNonEmptyArray, checkNonEmptyArraySync, checkNonEmptyInteger, checkNonEmptyIntegerSync, checkNonEmptyNumber, checkNonEmptyNumberSync, checkNonEmptyObject, checkNonEmptyObjectSync, checkNonEmptyString, checkNonEmptyStringSync, checkNumberBetween, checkNumberBetweenSync, checkObjectLength, checkObjectLengthSync, checkObjectLengthBetween, checkObjectLengthBetweenSync, checkStringLength, checkStringLengthSync, checkStringLengthBetween, checkStringLengthBetweenSync, checkIntegerBetween, checkIntegerBetweenSync, checkArrayLength, checkArrayLengthSync, checkArrayLengthBetween, checkArrayLengthBetweenSync };
23
+ import DescriptorUser, { iDescriptorUserOptions, tLogType, tLogger } from "./components/DescriptorUser";
24
+ import Mediator, { iUrlParameters } from "./components/Mediator";
25
+ import MediatorUser, { iMediatorUserOptions } from "./components/MediatorUser";
26
+ import NotFoundError from "./components/NotFoundError";
27
+ import Orchestrator, { iOrchestratorOptions } from "./components/Orchestrator";
28
+ import Server, { iClient, iIncomingMessage, iServerResponse } from "./components/Server";
29
+ export { tLogType, tLogger, iUrlParameters, iClient, iIncomingMessage, iServerResponse };
30
+ export { DescriptorUser, iDescriptorUserOptions, Mediator, MediatorUser, iMediatorUserOptions, NotFoundError, Orchestrator, iOrchestratorOptions, Server };
@@ -1,6 +1,6 @@
1
- import { iIncomingMessage, iServerResponse } from "../components/Server";
2
- export default function send(req: iIncomingMessage, res: iServerResponse, code: number, content: string, options: {
3
- "apiVersion": string;
4
- "cors": boolean;
5
- "mime": string;
6
- }): Promise<void>;
1
+ import { iIncomingMessage, iServerResponse } from "../components/Server";
2
+ export default function send(req: iIncomingMessage, res: iServerResponse, code: number, content: any, options: {
3
+ "apiVersion": string;
4
+ "cors": boolean;
5
+ "mime": string;
6
+ }): Promise<void>;
@@ -1,54 +1,84 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // module
4
- function send(req, res, code, content, options) {
5
- return new Promise((resolve) => {
6
- // force data for checking
7
- res.statusCode = code;
8
- res.headers = Object.assign({
9
- "Content-Type": options.mime,
10
- "Content-Length": content ? Buffer.byteLength(content) : 0,
11
- "Status-Code-Url-Cat": "https://http.cat/" + code,
12
- "API-Version": options.apiVersion
13
- }, options.cors ? {
14
- "Access-Control-Allow-Origin": "*",
15
- "Access-Control-Allow-Credentials": true,
16
- "Access-Control-Allow-Methods": req.headers["access-control-request-method"] ? req.headers["access-control-request-method"] : [
17
- "GET",
18
- "POST",
19
- "PUT",
20
- "DELETE",
21
- "PATCH",
22
- "OPTIONS"
23
- ].join(", "),
24
- "Access-Control-Allow-Headers": req.headers["access-control-request-headers"] ? req.headers["access-control-request-headers"] : [
25
- "Origin",
26
- "Accept",
27
- "Accept-Version",
28
- "Content-Length",
29
- "Content-MD5",
30
- "Content-Type",
31
- "Date",
32
- "X-Api-Version",
33
- "X-File-Name",
34
- "X-CSRF-Token",
35
- "X-Requested-With"
36
- ].join(", ")
37
- } : {});
38
- // send data
39
- res.writeHead(res.statusCode, res.headers);
40
- if (content) {
41
- res.body = content; // for Mediator response validator
42
- res.end(content, "utf-8", () => {
43
- resolve();
44
- });
45
- }
46
- else {
47
- res.end(() => {
48
- resolve();
49
- });
50
- }
51
- });
52
- }
53
- exports.default = send;
54
- ;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // module
4
+ function send(req, res, code, content, options) {
5
+ return Promise.resolve().then(() => {
6
+ if (!content) {
7
+ return "";
8
+ }
9
+ else {
10
+ let result = "";
11
+ if (options.mime.includes("application/json")) {
12
+ if ("string" === typeof content) {
13
+ try {
14
+ JSON.parse(content); // is content json & parseable ?
15
+ result = content; // yes => valid JSON string, send it as it is
16
+ }
17
+ catch (e) {
18
+ result = JSON.stringify(content); // no => not JSON string, send formatted one
19
+ }
20
+ }
21
+ else {
22
+ const stringified = JSON.stringify(content);
23
+ if (stringified !== content) {
24
+ result = stringified;
25
+ }
26
+ }
27
+ }
28
+ else {
29
+ result = content;
30
+ }
31
+ return result;
32
+ }
33
+ }).then((stringifiedContent) => {
34
+ return new Promise((resolve) => {
35
+ // force data for checking
36
+ res.statusCode = code;
37
+ res.headers = Object.assign({
38
+ "Content-Type": options.mime,
39
+ "Content-Length": stringifiedContent ? Buffer.byteLength(stringifiedContent) : 0,
40
+ "Status-Code-Url-Cat": "https://http.cat/" + code,
41
+ "API-Version": options.apiVersion
42
+ }, options.cors ? {
43
+ "Access-Control-Allow-Origin": "*",
44
+ "Access-Control-Allow-Credentials": true,
45
+ "Access-Control-Allow-Methods": req.headers["access-control-request-method"] ? req.headers["access-control-request-method"] : [
46
+ "GET",
47
+ "POST",
48
+ "PUT",
49
+ "DELETE",
50
+ "PATCH",
51
+ "OPTIONS"
52
+ ].join(", "),
53
+ "Access-Control-Allow-Headers": req.headers["access-control-request-headers"] ? req.headers["access-control-request-headers"] : [
54
+ "Origin",
55
+ "Accept",
56
+ "Accept-Version",
57
+ "Content-Length",
58
+ "Content-MD5",
59
+ "Content-Type",
60
+ "Date",
61
+ "X-Api-Version",
62
+ "X-File-Name",
63
+ "X-CSRF-Token",
64
+ "X-Requested-With"
65
+ ].join(", ")
66
+ } : {});
67
+ // send data
68
+ res.writeHead(res.statusCode, res.headers);
69
+ if ("" !== stringifiedContent) {
70
+ res.body = content; // for Mediator response validator
71
+ res.end(stringifiedContent, "utf-8", () => {
72
+ resolve();
73
+ });
74
+ }
75
+ else {
76
+ res.end(() => {
77
+ resolve();
78
+ });
79
+ }
80
+ });
81
+ });
82
+ }
83
+ exports.default = send;
84
+ ;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "node-pluginsmanager-plugin",
4
- "version": "6.0.1",
4
+ "version": "6.0.3",
5
5
  "description": "An abstract parent plugin for node-pluginsmanager",
6
6
 
7
7
  "type": "commonjs",
@@ -45,14 +45,14 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/express": "4.17.21",
48
- "@types/node": "20.10.1",
48
+ "@types/node": "20.10.3",
49
49
  "@types/socket.io": "3.0.2",
50
50
  "@types/uniqid": "5.3.4",
51
51
  "@types/ws": "8.5.10",
52
52
  "check-version-modules": "2.0.0",
53
53
  "coveralls": "3.1.1",
54
54
  "colors": "1.4.0",
55
- "eslint": "8.54.0",
55
+ "eslint": "8.55.0",
56
56
  "express": "4.18.2",
57
57
  "husky": "8.0.3",
58
58
  "mocha": "10.2.0",