node-pluginsmanager-plugin 4.7.1 → 4.8.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/components/Server.js
CHANGED
|
@@ -17,15 +17,16 @@
|
|
|
17
17
|
// locals
|
|
18
18
|
const MediatorUser = require(join(__dirname, "MediatorUser.js"));
|
|
19
19
|
const { checkInteger, checkNonEmptyObject, checkNonEmptyString } = require(join(__dirname, "..", "checkers", "main.js"));
|
|
20
|
-
const errToString = require(join(__dirname, "..", "utils", "errToString.js"));
|
|
21
20
|
const { extractPattern, extractParams, extractSchemaType } = require(join(__dirname, "..", "utils", "descriptor", "main.js"));
|
|
22
21
|
const { extractBody, extractIp, extractCookies } = require(join(__dirname, "..", "utils", "request", "main.js"));
|
|
23
22
|
const send = require(join(__dirname, "..", "utils", "send.js"));
|
|
24
23
|
const getUniqueID = require(join(__dirname, "..", "utils", "getUniqueID.js"));
|
|
24
|
+
const cleanSendedError = require(join(__dirname, "..", "utils", "cleanSendedError.js"));
|
|
25
25
|
|
|
26
26
|
// consts
|
|
27
27
|
|
|
28
28
|
const WEBSOCKET_STATE_OPEN = 1;
|
|
29
|
+
const SERVER_CODES = require(join(__dirname, "..", "utils", "serverCodes.json"));
|
|
29
30
|
|
|
30
31
|
// module
|
|
31
32
|
|
|
@@ -145,7 +146,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
145
146
|
);
|
|
146
147
|
|
|
147
148
|
// get descriptor
|
|
148
|
-
if ("/" + this._Descriptor.info.title + "/descriptor" === req.pattern && "get" === req.method) {
|
|
149
|
+
if ("/" + this._Descriptor.info.title + "/api/descriptor" === req.pattern && "get" === req.method) {
|
|
149
150
|
|
|
150
151
|
return new Promise((resolve, reject) => {
|
|
151
152
|
|
|
@@ -157,35 +158,54 @@ module.exports = class Server extends MediatorUser {
|
|
|
157
158
|
return err ? reject(err) : resolve(api);
|
|
158
159
|
});
|
|
159
160
|
|
|
161
|
+
// add current server
|
|
162
|
+
}).then((api) => {
|
|
163
|
+
|
|
164
|
+
const protocol = res.socket && Boolean(res.socket.encrypted) ? "https" : "http";
|
|
165
|
+
|
|
166
|
+
let port = res.socket && res.socket.localPort ? res.socket.localPort : 0;
|
|
167
|
+
if (!port) {
|
|
168
|
+
port = "http" === protocol ? 80 : 443;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!api.servers) {
|
|
172
|
+
api.servers = [];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
api.servers.push({
|
|
176
|
+
"url": protocol + "://" + req.validatedIp + ":" + port,
|
|
177
|
+
"description": "Actual current server"
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return Promise.resolve(api);
|
|
181
|
+
|
|
160
182
|
}).then((api) => {
|
|
161
183
|
|
|
162
184
|
this._log("info", "<= [" + req.validatedIp + "] " + JSON.stringify(api));
|
|
163
|
-
return send(req, res,
|
|
185
|
+
return send(req, res, SERVER_CODES.OK, api, this._Descriptor.info.version, this._cors);
|
|
164
186
|
|
|
165
187
|
}).catch((err) => {
|
|
166
188
|
|
|
167
|
-
this.emit("error", err);
|
|
168
|
-
|
|
169
189
|
const result = {
|
|
170
190
|
"code": "INTERNAL_SERVER_ERROR",
|
|
171
|
-
"message":
|
|
191
|
+
"message": cleanSendedError(err)
|
|
172
192
|
};
|
|
173
193
|
|
|
174
|
-
this._log("error", "<= " + JSON.stringify(result));
|
|
175
|
-
return send(req, res,
|
|
194
|
+
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
195
|
+
return send(req, res, SERVER_CODES.INTERNAL_SERVER_ERROR, result, this._Descriptor.info.version, this._cors);
|
|
176
196
|
|
|
177
197
|
});
|
|
178
198
|
|
|
179
199
|
}
|
|
180
200
|
|
|
181
201
|
// get plugin status
|
|
182
|
-
else if ("/" + this._Descriptor.info.title + "/status" === req.pattern && "get" === req.method) {
|
|
202
|
+
else if ("/" + this._Descriptor.info.title + "/api/status" === req.pattern && "get" === req.method) {
|
|
183
203
|
|
|
184
204
|
const initialized = this.initialized && this._Mediator.initialized;
|
|
185
205
|
const status = initialized ? "INITIALIZED" : "ENABLED";
|
|
186
206
|
|
|
187
207
|
this._log("info", "<= [" + req.validatedIp + "] " + status);
|
|
188
|
-
return send(req, res,
|
|
208
|
+
return send(req, res, SERVER_CODES.OK, status, this._Descriptor.info.version, this._cors);
|
|
189
209
|
|
|
190
210
|
}
|
|
191
211
|
|
|
@@ -198,7 +218,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
198
218
|
};
|
|
199
219
|
|
|
200
220
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
201
|
-
return send(req, res,
|
|
221
|
+
return send(req, res, SERVER_CODES.NOT_IMPLEMENTED, result, this._Descriptor.info.version, this._cors);
|
|
202
222
|
|
|
203
223
|
}
|
|
204
224
|
|
|
@@ -211,7 +231,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
211
231
|
};
|
|
212
232
|
|
|
213
233
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
214
|
-
return send(req, res,
|
|
234
|
+
return send(req, res, SERVER_CODES.NOT_IMPLEMENTED, result, this._Descriptor.info.version, this._cors);
|
|
215
235
|
|
|
216
236
|
}
|
|
217
237
|
|
|
@@ -226,7 +246,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
226
246
|
};
|
|
227
247
|
|
|
228
248
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
229
|
-
return send(req, res,
|
|
249
|
+
return send(req, res, SERVER_CODES.MISSING_HEADER, result, this._Descriptor.info.version, this._cors);
|
|
230
250
|
|
|
231
251
|
}
|
|
232
252
|
|
|
@@ -398,12 +418,12 @@ module.exports = class Server extends MediatorUser {
|
|
|
398
418
|
|
|
399
419
|
if ("undefined" === typeof content || null === content) {
|
|
400
420
|
this._log("success", "<= [" + req.validatedIp + "] no content");
|
|
401
|
-
return send(req, res,
|
|
421
|
+
return send(req, res, SERVER_CODES.OK_PUT, undefined, this._Descriptor.info.version, this._cors);
|
|
402
422
|
}
|
|
403
423
|
|
|
404
424
|
else {
|
|
405
425
|
this._log("success", "<= [" + req.validatedIp + "] " + JSON.stringify(content));
|
|
406
|
-
return send(req, res,
|
|
426
|
+
return send(req, res, SERVER_CODES.OK_PUT, content, this._Descriptor.info.version, this._cors);
|
|
407
427
|
}
|
|
408
428
|
|
|
409
429
|
}
|
|
@@ -411,12 +431,12 @@ module.exports = class Server extends MediatorUser {
|
|
|
411
431
|
// no content
|
|
412
432
|
else if ("undefined" === typeof content || null === content) {
|
|
413
433
|
this._log("warning", "<= [" + req.validatedIp + "] no content");
|
|
414
|
-
return send(req, res,
|
|
434
|
+
return send(req, res, SERVER_CODES.OK_NO_CONTENT, undefined, this._Descriptor.info.version, this._cors);
|
|
415
435
|
}
|
|
416
436
|
|
|
417
437
|
else {
|
|
418
438
|
this._log("success", "<= [" + req.validatedIp + "] " + JSON.stringify(content));
|
|
419
|
-
return send(req, res,
|
|
439
|
+
return send(req, res, SERVER_CODES.OK, content, this._Descriptor.info.version, this._cors);
|
|
420
440
|
}
|
|
421
441
|
|
|
422
442
|
}).catch((err) => {
|
|
@@ -425,55 +445,55 @@ module.exports = class Server extends MediatorUser {
|
|
|
425
445
|
|
|
426
446
|
const result = {
|
|
427
447
|
"code": "MISSING_PARAMETER",
|
|
428
|
-
"message":
|
|
448
|
+
"message": cleanSendedError(err)
|
|
429
449
|
};
|
|
430
450
|
|
|
431
451
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
432
|
-
return send(req, res,
|
|
452
|
+
return send(req, res, SERVER_CODES.MISSING_PARAMETER, result, this._Descriptor.info.version, this._cors);
|
|
433
453
|
|
|
434
454
|
}
|
|
435
455
|
else if (err instanceof TypeError) {
|
|
436
456
|
|
|
437
457
|
const result = {
|
|
438
458
|
"code": "WRONG_TYPE_PARAMETER",
|
|
439
|
-
"message":
|
|
459
|
+
"message": cleanSendedError(err)
|
|
440
460
|
};
|
|
441
461
|
|
|
442
462
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
443
|
-
return send(req, res,
|
|
463
|
+
return send(req, res, SERVER_CODES.WRONG_TYPE_PARAMETER, result, this._Descriptor.info.version, this._cors);
|
|
444
464
|
|
|
445
465
|
}
|
|
446
466
|
else if (err instanceof RangeError) {
|
|
447
467
|
|
|
448
468
|
const result = {
|
|
449
469
|
"code": "EMPTY_OR_RANGE_OR_ENUM_PARAMETER",
|
|
450
|
-
"message":
|
|
470
|
+
"message": cleanSendedError(err)
|
|
451
471
|
};
|
|
452
472
|
|
|
453
473
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
454
|
-
return send(req, res,
|
|
474
|
+
return send(req, res, SERVER_CODES.EMPTY_OR_RANGE_OR_ENUM_PARAMETER, result, this._Descriptor.info.version, this._cors);
|
|
455
475
|
|
|
456
476
|
}
|
|
457
477
|
else if (err instanceof SyntaxError) {
|
|
458
478
|
|
|
459
479
|
const result = {
|
|
460
480
|
"code": "JSON_PARSE",
|
|
461
|
-
"message":
|
|
481
|
+
"message": cleanSendedError(err)
|
|
462
482
|
};
|
|
463
483
|
|
|
464
484
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
465
|
-
return send(req, res,
|
|
485
|
+
return send(req, res, SERVER_CODES.JSON_PARSE, result, this._Descriptor.info.version, this._cors);
|
|
466
486
|
|
|
467
487
|
}
|
|
468
488
|
else {
|
|
469
489
|
|
|
470
490
|
const result = {
|
|
471
491
|
"code": "INTERNAL_SERVER_ERROR",
|
|
472
|
-
"message":
|
|
492
|
+
"message": cleanSendedError(err)
|
|
473
493
|
};
|
|
474
494
|
|
|
475
495
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
476
|
-
return send(req, res,
|
|
496
|
+
return send(req, res, SERVER_CODES.INTERNAL_SERVER_ERROR, result, this._Descriptor.info.version, this._cors);
|
|
477
497
|
|
|
478
498
|
}
|
|
479
499
|
|
|
@@ -561,7 +581,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
561
581
|
};
|
|
562
582
|
|
|
563
583
|
if ("undefined" !== typeof data) {
|
|
564
|
-
result.data = data;
|
|
584
|
+
result.data = cleanSendedError(data);
|
|
565
585
|
}
|
|
566
586
|
|
|
567
587
|
return Promise.resolve(JSON.stringify(result));
|
|
@@ -602,7 +622,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
602
622
|
}
|
|
603
623
|
|
|
604
624
|
}).catch((err) => {
|
|
605
|
-
this.
|
|
625
|
+
this._log("error", err);
|
|
606
626
|
});
|
|
607
627
|
|
|
608
628
|
return this;
|
|
@@ -626,7 +646,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
626
646
|
};
|
|
627
647
|
|
|
628
648
|
if ("undefined" !== typeof data) {
|
|
629
|
-
result.data = data;
|
|
649
|
+
result.data = cleanSendedError(data);
|
|
630
650
|
}
|
|
631
651
|
|
|
632
652
|
return Promise.resolve(JSON.stringify(result));
|
|
@@ -683,7 +703,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
683
703
|
|
|
684
704
|
}
|
|
685
705
|
}).catch((err) => {
|
|
686
|
-
this.
|
|
706
|
+
this._log("error", err);
|
|
687
707
|
});
|
|
688
708
|
|
|
689
709
|
return this;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// module
|
|
4
|
+
|
|
5
|
+
module.exports = function cleanSendedError (data) {
|
|
6
|
+
|
|
7
|
+
if ("object" === typeof data) {
|
|
8
|
+
|
|
9
|
+
if (data instanceof Error) {
|
|
10
|
+
return data.message ? data.message : data;
|
|
11
|
+
}
|
|
12
|
+
else if (data.message && data.message instanceof Error) {
|
|
13
|
+
|
|
14
|
+
data.message = data.message.message ? data.message.message : data.message;
|
|
15
|
+
|
|
16
|
+
return data;
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
else if (data.error) { // 1 level recursive for "error" data (avoid too deep recursive analyse)
|
|
20
|
+
|
|
21
|
+
if (data.error instanceof Error) {
|
|
22
|
+
data.error = data.error.message ? data.error.message : data.error;
|
|
23
|
+
}
|
|
24
|
+
else if (data.error.message && data.error.message instanceof Error) {
|
|
25
|
+
data.error.message = data.error.message.message ? data.error.message.message : data.error.message;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return data;
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
else if (data.err && data.err instanceof Error) { // 1 level recursive for "err" data (avoid too deep recursive analyse)
|
|
32
|
+
|
|
33
|
+
data.err = data.err.message ? data.err.message : data.err;
|
|
34
|
+
|
|
35
|
+
return data;
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
|
|
3
|
+
"OK": 200,
|
|
4
|
+
"OK_PUT": 201,
|
|
5
|
+
"OK_NO_CONTENT": 204,
|
|
6
|
+
|
|
7
|
+
"MISSING_PARAMETER": 400,
|
|
8
|
+
"WRONG_TYPE_PARAMETER": 400,
|
|
9
|
+
"EMPTY_OR_RANGE_OR_ENUM_PARAMETER": 400,
|
|
10
|
+
"JSON_PARSE": 400,
|
|
11
|
+
"MISSING_HEADER": 411,
|
|
12
|
+
|
|
13
|
+
"INTERNAL_SERVER_ERROR": 500,
|
|
14
|
+
"NOT_IMPLEMENTED": 501
|
|
15
|
+
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-pluginsmanager-plugin",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.1",
|
|
4
4
|
"description": "An abstract parent plugin for node-pluginsmanager",
|
|
5
5
|
"main": "lib/main.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -35,25 +35,25 @@
|
|
|
35
35
|
"url": "https://github.com/Psychopoulet/node-pluginsmanager-plugin/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@apidevtools/swagger-parser": "10.0.
|
|
38
|
+
"@apidevtools/swagger-parser": "10.0.3",
|
|
39
39
|
"express-openapi-validate": "0.6.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "
|
|
42
|
+
"@types/node": "17.0.25",
|
|
43
43
|
"@types/socket.io": "3.0.2",
|
|
44
|
-
"@types/ws": "
|
|
45
|
-
"check-version-modules": "1.3.
|
|
44
|
+
"@types/ws": "8.5.3",
|
|
45
|
+
"check-version-modules": "1.3.5",
|
|
46
46
|
"coveralls": "3.1.1",
|
|
47
47
|
"colors": "1.4.0",
|
|
48
|
-
"eslint": "
|
|
49
|
-
"express": "4.17.
|
|
50
|
-
"husky": "7.0.
|
|
51
|
-
"mocha": "9.
|
|
48
|
+
"eslint": "8.13.0",
|
|
49
|
+
"express": "4.17.3",
|
|
50
|
+
"husky": "7.0.4",
|
|
51
|
+
"mocha": "9.2.2",
|
|
52
52
|
"nyc": "15.1.0",
|
|
53
|
-
"socket.io": "4.1
|
|
54
|
-
"socket.io-client": "4.1
|
|
55
|
-
"typescript": "4.3
|
|
56
|
-
"ws": "8.
|
|
53
|
+
"socket.io": "4.4.1",
|
|
54
|
+
"socket.io-client": "4.4.1",
|
|
55
|
+
"typescript": "4.6.3",
|
|
56
|
+
"ws": "8.5.0"
|
|
57
57
|
},
|
|
58
58
|
"homepage": "https://github.com/Psychopoulet/node-pluginsmanager-plugin#readme",
|
|
59
59
|
"engines": {
|