node-pluginsmanager-plugin 5.0.14 → 5.1.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.
@@ -1,6 +1,6 @@
1
- import { OpenApiValidator } from "express-openapi-validate";
2
1
  import { iServerResponse } from "./Server";
3
2
  import DescriptorUser, { iDescriptorUserOptions } from "./DescriptorUser";
3
+ import { OpenApiValidator } from "express-openapi-validate";
4
4
  export interface iUrlParameters {
5
5
  "path": {
6
6
  [key: string]: any;
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- // deps
7
- // externals
8
- const express_openapi_validate_1 = require("express-openapi-validate");
9
6
  const checkObject_1 = require("../checkers/TypeError/checkObject");
10
7
  const checkNonEmptyString_1 = require("../checkers/RangeError/checkNonEmptyString");
11
8
  const checkNonEmptyObject_1 = require("../checkers/RangeError/checkNonEmptyObject");
12
9
  const extractPathMethodByOperationId_1 = __importDefault(require("../utils/descriptor/extractPathMethodByOperationId"));
13
10
  const DescriptorUser_1 = __importDefault(require("./DescriptorUser"));
11
+ // types & interfaces
12
+ // externals
13
+ const express_openapi_validate_1 = require("express-openapi-validate");
14
14
  // module
15
15
  class Mediator extends DescriptorUser_1.default {
16
16
  // constructor
@@ -34,7 +34,6 @@ export default class Orchestrator extends MediatorUser {
34
34
  scripts: object | null;
35
35
  version: string;
36
36
  constructor(options: iOrchestratorOptions);
37
- checkDescriptor(): Promise<void>;
38
37
  checkConf(): Promise<void>;
39
38
  isEnable(): Promise<void>;
40
39
  checkFiles(): Promise<void>;
@@ -4,9 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  // deps
7
- // externals
7
+ // natives
8
8
  const node_path_1 = require("node:path");
9
- const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
10
9
  // locals
11
10
  const checkObject_1 = require("../checkers/TypeError/checkObject");
12
11
  const MediatorUser_1 = __importDefault(require("./MediatorUser"));
@@ -46,13 +45,6 @@ class Orchestrator extends MediatorUser_1.default {
46
45
  this.version = "";
47
46
  }
48
47
  // public
49
- checkDescriptor() {
50
- return super.checkDescriptor().then(() => {
51
- return swagger_parser_1.default.validate(this._descriptorFile);
52
- }).then(() => {
53
- return Promise.resolve();
54
- });
55
- }
56
48
  // checkers
57
49
  checkConf() {
58
50
  return Promise.resolve();
@@ -255,11 +247,17 @@ class Orchestrator extends MediatorUser_1.default {
255
247
  return this.isEnable();
256
248
  }).then(() => {
257
249
  return !this.enabled ? Promise.resolve() : Promise.resolve().then(() => {
258
- // create Descriptor
259
- return swagger_parser_1.default.bundle(this._descriptorFile).then((content) => {
260
- return Promise.resolve(content);
261
- }).then((content) => {
262
- this._Descriptor = content;
250
+ const SwaggerParser = require("@apidevtools/swagger-parser");
251
+ // generate descriptor
252
+ return SwaggerParser.bundle(this._descriptorFile).then((bundledDescriptor) => {
253
+ // force validate because of stupid malformatted references
254
+ return SwaggerParser.validate(bundledDescriptor).then((validatedDescriptor) => {
255
+ this._Descriptor = validatedDescriptor;
256
+ if (!this._Descriptor.servers) {
257
+ this._Descriptor.servers = [];
258
+ }
259
+ });
260
+ }).then(() => {
263
261
  return this.checkDescriptor().catch((err) => {
264
262
  this._Descriptor = null;
265
263
  return Promise.reject(err);
@@ -85,6 +85,7 @@ class Server extends MediatorUser_1.default {
85
85
  return next();
86
86
  }
87
87
  this.checkDescriptor().then(() => {
88
+ var _a;
88
89
  // parse
89
90
  const { pathname, query } = (0, node_url_1.parse)(req.url, true);
90
91
  req.method = req.method ? req.method.toLowerCase() : "get";
@@ -121,29 +122,14 @@ class Server extends MediatorUser_1.default {
121
122
  node_os_1.EOL + "content-length : " + req.headers["content-length"] : ""));
122
123
  // get descriptor
123
124
  if ("/" + this._Descriptor.info.title + "/api/descriptor" === req.pattern && "get" === req.method) {
124
- return Promise.resolve().then(() => {
125
- // cannot extract only validate because of stupid malformatted references
126
- const SwaggerParser = require("@apidevtools/swagger-parser");
127
- return SwaggerParser.validate(this._Descriptor).then((api) => {
128
- // force compatibility
129
- return Promise.resolve(api);
130
- });
131
- // add current server
132
- }).then((api) => {
133
- var _a;
134
- if (!api.servers) {
135
- api.servers = [];
136
- }
137
- const port = res.socket && res.socket.localPort ? res.socket.localPort : ((_a = res.socket) === null || _a === void 0 ? void 0 : _a.address()).port;
138
- api.servers.push({
139
- "url": req.validatedIp + ":" + port,
140
- "description": "Actual current server"
141
- });
142
- return Promise.resolve(api);
143
- }).then((api) => {
144
- this._log("info", "<= [" + req.validatedIp + "] " + JSON.stringify(api));
145
- return (0, send_1.default)(req, res, serverCodes_1.default.OK, api, this._Descriptor.info.version, this._cors);
146
- }).catch((err) => {
125
+ // add current server
126
+ const port = res.socket && res.socket.localPort ? res.socket.localPort : ((_a = res.socket) === null || _a === void 0 ? void 0 : _a.address()).port;
127
+ this._Descriptor.servers.push({
128
+ "url": req.validatedIp + ":" + port,
129
+ "description": "Actual current server"
130
+ });
131
+ this._log("info", "<= [" + req.validatedIp + "] " + JSON.stringify(this._Descriptor));
132
+ return (0, send_1.default)(req, res, serverCodes_1.default.OK, this._Descriptor, this._Descriptor.info.version, this._cors).catch((err) => {
147
133
  this._log("error", err);
148
134
  const result = {
149
135
  "code": "INTERNAL_SERVER_ERROR",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "node-pluginsmanager-plugin",
4
- "version": "5.0.14",
4
+ "version": "5.1.0",
5
5
  "description": "An abstract parent plugin for node-pluginsmanager",
6
6
 
7
7
  "type": "commonjs",
@@ -19,11 +19,10 @@
19
19
 
20
20
  "scripts": {
21
21
 
22
- "build": "npx tsc --project \"./tsconfig.json\"",
22
+ "build": "node ./removeOldBuild.js && npx tsc --project \"./tsconfig.json\"",
23
23
 
24
24
  "lint": "npx eslint ./test/**/*.js",
25
25
  "check-requires": "npx used-deps-analyzer \"./package.json\" \"./src\" --no-dev --overkill \"fs-extra\" \"node-promfs\"",
26
- "check-requires-tests": "npx used-deps-analyzer \"./package.json\" \"./test\" --no-dev --overkill \"fs-extra\" \"node-promfs\"",
27
26
  "check-updates": "npx check-version-modules",
28
27
  "unit-tests": "npm run build && npx nyc --reporter=html --reporter=text mocha",
29
28
 
@@ -46,7 +45,7 @@
46
45
  },
47
46
  "devDependencies": {
48
47
  "@types/express": "4.17.17",
49
- "@types/node": "20.5.0",
48
+ "@types/node": "20.5.4",
50
49
  "@types/socket.io": "3.0.2",
51
50
  "@types/uniqid": "5.3.2",
52
51
  "@types/ws": "8.5.5",