node-pluginsmanager-plugin 4.8.0 → 4.8.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.
package/lib/components/Server.js
CHANGED
|
@@ -16,16 +16,18 @@
|
|
|
16
16
|
|
|
17
17
|
// locals
|
|
18
18
|
const MediatorUser = require(join(__dirname, "MediatorUser.js"));
|
|
19
|
+
const NotFoundError = require(join(__dirname, "NotFoundError.js"));
|
|
19
20
|
const { checkInteger, checkNonEmptyObject, checkNonEmptyString } = require(join(__dirname, "..", "checkers", "main.js"));
|
|
20
|
-
const errToString = require(join(__dirname, "..", "utils", "errToString.js"));
|
|
21
21
|
const { extractPattern, extractParams, extractSchemaType } = require(join(__dirname, "..", "utils", "descriptor", "main.js"));
|
|
22
22
|
const { extractBody, extractIp, extractCookies } = require(join(__dirname, "..", "utils", "request", "main.js"));
|
|
23
23
|
const send = require(join(__dirname, "..", "utils", "send.js"));
|
|
24
24
|
const getUniqueID = require(join(__dirname, "..", "utils", "getUniqueID.js"));
|
|
25
|
+
const cleanSendedError = require(join(__dirname, "..", "utils", "cleanSendedError.js"));
|
|
25
26
|
|
|
26
27
|
// consts
|
|
27
28
|
|
|
28
29
|
const WEBSOCKET_STATE_OPEN = 1;
|
|
30
|
+
const SERVER_CODES = require(join(__dirname, "..", "utils", "serverCodes.json"));
|
|
29
31
|
|
|
30
32
|
// module
|
|
31
33
|
|
|
@@ -181,19 +183,19 @@ module.exports = class Server extends MediatorUser {
|
|
|
181
183
|
}).then((api) => {
|
|
182
184
|
|
|
183
185
|
this._log("info", "<= [" + req.validatedIp + "] " + JSON.stringify(api));
|
|
184
|
-
return send(req, res,
|
|
186
|
+
return send(req, res, SERVER_CODES.OK, api, this._Descriptor.info.version, this._cors);
|
|
185
187
|
|
|
186
188
|
}).catch((err) => {
|
|
187
189
|
|
|
188
|
-
this.
|
|
190
|
+
this._log("error", err);
|
|
189
191
|
|
|
190
192
|
const result = {
|
|
191
193
|
"code": "INTERNAL_SERVER_ERROR",
|
|
192
|
-
"message":
|
|
194
|
+
"message": cleanSendedError(err)
|
|
193
195
|
};
|
|
194
196
|
|
|
195
|
-
this._log("error", "<= " + JSON.stringify(result));
|
|
196
|
-
return send(req, res,
|
|
197
|
+
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
198
|
+
return send(req, res, SERVER_CODES.INTERNAL_SERVER_ERROR, result, this._Descriptor.info.version, this._cors);
|
|
197
199
|
|
|
198
200
|
});
|
|
199
201
|
|
|
@@ -206,7 +208,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
206
208
|
const status = initialized ? "INITIALIZED" : "ENABLED";
|
|
207
209
|
|
|
208
210
|
this._log("info", "<= [" + req.validatedIp + "] " + status);
|
|
209
|
-
return send(req, res,
|
|
211
|
+
return send(req, res, SERVER_CODES.OK, status, this._Descriptor.info.version, this._cors);
|
|
210
212
|
|
|
211
213
|
}
|
|
212
214
|
|
|
@@ -219,7 +221,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
219
221
|
};
|
|
220
222
|
|
|
221
223
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
222
|
-
return send(req, res,
|
|
224
|
+
return send(req, res, SERVER_CODES.NOT_IMPLEMENTED, result, this._Descriptor.info.version, this._cors);
|
|
223
225
|
|
|
224
226
|
}
|
|
225
227
|
|
|
@@ -232,7 +234,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
232
234
|
};
|
|
233
235
|
|
|
234
236
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
235
|
-
return send(req, res,
|
|
237
|
+
return send(req, res, SERVER_CODES.NOT_IMPLEMENTED, result, this._Descriptor.info.version, this._cors);
|
|
236
238
|
|
|
237
239
|
}
|
|
238
240
|
|
|
@@ -247,7 +249,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
247
249
|
};
|
|
248
250
|
|
|
249
251
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
250
|
-
return send(req, res,
|
|
252
|
+
return send(req, res, SERVER_CODES.MISSING_HEADER, result, this._Descriptor.info.version, this._cors);
|
|
251
253
|
|
|
252
254
|
}
|
|
253
255
|
|
|
@@ -419,12 +421,12 @@ module.exports = class Server extends MediatorUser {
|
|
|
419
421
|
|
|
420
422
|
if ("undefined" === typeof content || null === content) {
|
|
421
423
|
this._log("success", "<= [" + req.validatedIp + "] no content");
|
|
422
|
-
return send(req, res,
|
|
424
|
+
return send(req, res, SERVER_CODES.OK_PUT, undefined, this._Descriptor.info.version, this._cors);
|
|
423
425
|
}
|
|
424
426
|
|
|
425
427
|
else {
|
|
426
428
|
this._log("success", "<= [" + req.validatedIp + "] " + JSON.stringify(content));
|
|
427
|
-
return send(req, res,
|
|
429
|
+
return send(req, res, SERVER_CODES.OK_PUT, content, this._Descriptor.info.version, this._cors);
|
|
428
430
|
}
|
|
429
431
|
|
|
430
432
|
}
|
|
@@ -432,12 +434,12 @@ module.exports = class Server extends MediatorUser {
|
|
|
432
434
|
// no content
|
|
433
435
|
else if ("undefined" === typeof content || null === content) {
|
|
434
436
|
this._log("warning", "<= [" + req.validatedIp + "] no content");
|
|
435
|
-
return send(req, res,
|
|
437
|
+
return send(req, res, SERVER_CODES.OK_NO_CONTENT, undefined, this._Descriptor.info.version, this._cors);
|
|
436
438
|
}
|
|
437
439
|
|
|
438
440
|
else {
|
|
439
441
|
this._log("success", "<= [" + req.validatedIp + "] " + JSON.stringify(content));
|
|
440
|
-
return send(req, res,
|
|
442
|
+
return send(req, res, SERVER_CODES.OK, content, this._Descriptor.info.version, this._cors);
|
|
441
443
|
}
|
|
442
444
|
|
|
443
445
|
}).catch((err) => {
|
|
@@ -446,55 +448,68 @@ module.exports = class Server extends MediatorUser {
|
|
|
446
448
|
|
|
447
449
|
const result = {
|
|
448
450
|
"code": "MISSING_PARAMETER",
|
|
449
|
-
"message":
|
|
451
|
+
"message": cleanSendedError(err)
|
|
450
452
|
};
|
|
451
453
|
|
|
452
454
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
453
|
-
return send(req, res,
|
|
455
|
+
return send(req, res, SERVER_CODES.MISSING_PARAMETER, result, this._Descriptor.info.version, this._cors);
|
|
454
456
|
|
|
455
457
|
}
|
|
456
458
|
else if (err instanceof TypeError) {
|
|
457
459
|
|
|
458
460
|
const result = {
|
|
459
461
|
"code": "WRONG_TYPE_PARAMETER",
|
|
460
|
-
"message":
|
|
462
|
+
"message": cleanSendedError(err)
|
|
461
463
|
};
|
|
462
464
|
|
|
463
465
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
464
|
-
return send(req, res,
|
|
466
|
+
return send(req, res, SERVER_CODES.WRONG_TYPE_PARAMETER, result, this._Descriptor.info.version, this._cors);
|
|
465
467
|
|
|
466
468
|
}
|
|
467
469
|
else if (err instanceof RangeError) {
|
|
468
470
|
|
|
469
471
|
const result = {
|
|
470
472
|
"code": "EMPTY_OR_RANGE_OR_ENUM_PARAMETER",
|
|
471
|
-
"message":
|
|
473
|
+
"message": cleanSendedError(err)
|
|
472
474
|
};
|
|
473
475
|
|
|
474
476
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
475
|
-
return send(req, res,
|
|
477
|
+
return send(req, res, SERVER_CODES.EMPTY_OR_RANGE_OR_ENUM_PARAMETER, result, this._Descriptor.info.version, this._cors);
|
|
476
478
|
|
|
477
479
|
}
|
|
478
480
|
else if (err instanceof SyntaxError) {
|
|
479
481
|
|
|
480
482
|
const result = {
|
|
481
483
|
"code": "JSON_PARSE",
|
|
482
|
-
"message":
|
|
484
|
+
"message": cleanSendedError(err)
|
|
483
485
|
};
|
|
484
486
|
|
|
485
487
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
486
|
-
return send(req, res,
|
|
488
|
+
return send(req, res, SERVER_CODES.JSON_PARSE, result, this._Descriptor.info.version, this._cors);
|
|
489
|
+
|
|
490
|
+
}
|
|
491
|
+
else if (err instanceof NotFoundError) {
|
|
492
|
+
|
|
493
|
+
const result = {
|
|
494
|
+
"code": "NOT_FOUND",
|
|
495
|
+
"message": cleanSendedError(err)
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
499
|
+
return send(req, res, SERVER_CODES.NOT_FOUND, result, this._Descriptor.info.version, this._cors);
|
|
487
500
|
|
|
488
501
|
}
|
|
489
502
|
else {
|
|
490
503
|
|
|
504
|
+
this._log("error", err);
|
|
505
|
+
|
|
491
506
|
const result = {
|
|
492
507
|
"code": "INTERNAL_SERVER_ERROR",
|
|
493
|
-
"message":
|
|
508
|
+
"message": cleanSendedError(err)
|
|
494
509
|
};
|
|
495
510
|
|
|
496
511
|
this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
|
|
497
|
-
return send(req, res,
|
|
512
|
+
return send(req, res, SERVER_CODES.INTERNAL_SERVER_ERROR, result, this._Descriptor.info.version, this._cors);
|
|
498
513
|
|
|
499
514
|
}
|
|
500
515
|
|
|
@@ -582,7 +597,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
582
597
|
};
|
|
583
598
|
|
|
584
599
|
if ("undefined" !== typeof data) {
|
|
585
|
-
result.data = data;
|
|
600
|
+
result.data = cleanSendedError(data);
|
|
586
601
|
}
|
|
587
602
|
|
|
588
603
|
return Promise.resolve(JSON.stringify(result));
|
|
@@ -623,7 +638,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
623
638
|
}
|
|
624
639
|
|
|
625
640
|
}).catch((err) => {
|
|
626
|
-
this.
|
|
641
|
+
this._log("error", err);
|
|
627
642
|
});
|
|
628
643
|
|
|
629
644
|
return this;
|
|
@@ -647,7 +662,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
647
662
|
};
|
|
648
663
|
|
|
649
664
|
if ("undefined" !== typeof data) {
|
|
650
|
-
result.data = data;
|
|
665
|
+
result.data = cleanSendedError(data);
|
|
651
666
|
}
|
|
652
667
|
|
|
653
668
|
return Promise.resolve(JSON.stringify(result));
|
|
@@ -704,7 +719,7 @@ module.exports = class Server extends MediatorUser {
|
|
|
704
719
|
|
|
705
720
|
}
|
|
706
721
|
}).catch((err) => {
|
|
707
|
-
this.
|
|
722
|
+
this._log("error", err);
|
|
708
723
|
});
|
|
709
724
|
|
|
710
725
|
return this;
|
package/lib/components/main.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
const MediatorUser = require(join(__dirname, "MediatorUser.js"));
|
|
12
12
|
const Orchestrator = require(join(__dirname, "Orchestrator.js"));
|
|
13
13
|
const Server = require(join(__dirname, "Server.js"));
|
|
14
|
+
const NotFoundError = require(join(__dirname, "NotFoundError.js"));
|
|
14
15
|
|
|
15
16
|
// module
|
|
16
17
|
|
|
@@ -19,5 +20,6 @@ module.exports = {
|
|
|
19
20
|
Mediator,
|
|
20
21
|
MediatorUser,
|
|
21
22
|
Orchestrator,
|
|
22
|
-
Server
|
|
23
|
+
Server,
|
|
24
|
+
NotFoundError
|
|
23
25
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -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,17 @@
|
|
|
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
|
+
"NOT_FOUND": 404,
|
|
12
|
+
"MISSING_HEADER": 411,
|
|
13
|
+
|
|
14
|
+
"INTERNAL_SERVER_ERROR": 500,
|
|
15
|
+
"NOT_IMPLEMENTED": 501
|
|
16
|
+
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-pluginsmanager-plugin",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.3",
|
|
4
4
|
"description": "An abstract parent plugin for node-pluginsmanager",
|
|
5
5
|
"main": "lib/main.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -39,19 +39,19 @@
|
|
|
39
39
|
"express-openapi-validate": "0.6.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "17.0.
|
|
42
|
+
"@types/node": "17.0.29",
|
|
43
43
|
"@types/socket.io": "3.0.2",
|
|
44
44
|
"@types/ws": "8.5.3",
|
|
45
45
|
"check-version-modules": "1.3.5",
|
|
46
46
|
"coveralls": "3.1.1",
|
|
47
47
|
"colors": "1.4.0",
|
|
48
|
-
"eslint": "8.
|
|
49
|
-
"express": "4.
|
|
48
|
+
"eslint": "8.14.0",
|
|
49
|
+
"express": "4.18.0",
|
|
50
50
|
"husky": "7.0.4",
|
|
51
51
|
"mocha": "9.2.2",
|
|
52
52
|
"nyc": "15.1.0",
|
|
53
|
-
"socket.io": "4.
|
|
54
|
-
"socket.io-client": "4.
|
|
53
|
+
"socket.io": "4.5.0",
|
|
54
|
+
"socket.io-client": "4.5.0",
|
|
55
55
|
"typescript": "4.6.3",
|
|
56
56
|
"ws": "8.5.0"
|
|
57
57
|
},
|