badmfck-api-server 4.0.3 → 4.0.5
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.
|
@@ -3,7 +3,7 @@ import { Application, Response } from 'express';
|
|
|
3
3
|
import { BaseService, IBaseService } from './BaseService';
|
|
4
4
|
import { IBaseEndpoint } from './BaseEndpoint';
|
|
5
5
|
import { HTTPRequestVO, IError, TransferPacketVO } from './structures/Interfaces';
|
|
6
|
-
import { Req } from "badmfck-signal";
|
|
6
|
+
import Signal, { Req } from "badmfck-signal";
|
|
7
7
|
import http from 'http';
|
|
8
8
|
export interface IMonitorUser {
|
|
9
9
|
login: string;
|
|
@@ -57,6 +57,7 @@ export declare const REQ_HTTP_SERVER: Req<void, {
|
|
|
57
57
|
export declare const REQ_INTERNAL_CALL: Req<HTTPRequestVO, IError | any>;
|
|
58
58
|
export declare const REQ_MONITOR_USERS: Req<void, IMonitorUser[]>;
|
|
59
59
|
export declare const REQ_DOC_USERS: Req<void, IMonitorUser[]>;
|
|
60
|
+
export declare const S_APP_STARTED: Signal<void>;
|
|
60
61
|
export declare function Initializer(services: IBaseService[]): Promise<void>;
|
|
61
62
|
export declare class APIService<TInterceptorResult = any, TInternalCallParams = any> extends BaseService {
|
|
62
63
|
private version;
|
|
@@ -26,13 +26,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.APIService = exports.Initializer = exports.REQ_DOC_USERS = exports.REQ_MONITOR_USERS = exports.REQ_INTERNAL_CALL = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.getDefaultOptions = void 0;
|
|
29
|
+
exports.APIService = exports.Initializer = exports.S_APP_STARTED = exports.REQ_DOC_USERS = exports.REQ_MONITOR_USERS = exports.REQ_INTERNAL_CALL = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.getDefaultOptions = void 0;
|
|
30
30
|
const express_1 = __importDefault(require("express"));
|
|
31
31
|
const BaseService_1 = require("./BaseService");
|
|
32
32
|
const cors_1 = __importDefault(require("cors"));
|
|
33
33
|
const BaseEndpoint_1 = require("./BaseEndpoint");
|
|
34
34
|
const DefaultErrors_1 = __importStar(require("./structures/DefaultErrors"));
|
|
35
|
-
const badmfck_signal_1 = require("badmfck-signal");
|
|
35
|
+
const badmfck_signal_1 = __importStar(require("badmfck-signal"));
|
|
36
36
|
const LogService_1 = require("./LogService");
|
|
37
37
|
const Monitor_1 = require("./monitor/Monitor");
|
|
38
38
|
const express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
@@ -79,6 +79,7 @@ exports.REQ_HTTP_SERVER = new badmfck_signal_1.Req(undefined, "REQ_HTTP_SERVER")
|
|
|
79
79
|
exports.REQ_INTERNAL_CALL = new badmfck_signal_1.Req(undefined, "REQ_INTERNAL_CALL");
|
|
80
80
|
exports.REQ_MONITOR_USERS = new badmfck_signal_1.Req(undefined, "REQ_MONITOR_USERS");
|
|
81
81
|
exports.REQ_DOC_USERS = new badmfck_signal_1.Req(undefined, "REQ_DOC_USERS");
|
|
82
|
+
exports.S_APP_STARTED = new badmfck_signal_1.default("S_APP_STARTED");
|
|
82
83
|
const activeServices = [];
|
|
83
84
|
async function Initializer(services) {
|
|
84
85
|
services.push(new StatService_1.StatService());
|
|
@@ -87,13 +88,14 @@ async function Initializer(services) {
|
|
|
87
88
|
activeServices.push(i.getName());
|
|
88
89
|
MonitorService_1.S_STAT_REGISTRATE_SERVICE.invoke(i.getName());
|
|
89
90
|
}
|
|
91
|
+
exports.S_APP_STARTED.invoke();
|
|
90
92
|
for (let i of services) {
|
|
91
93
|
i.applicationReady();
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
exports.Initializer = Initializer;
|
|
95
97
|
class APIService extends BaseService_1.BaseService {
|
|
96
|
-
version = "4.0.
|
|
98
|
+
version = "4.0.5";
|
|
97
99
|
options;
|
|
98
100
|
monitor = null;
|
|
99
101
|
started = new Date();
|
|
@@ -38,7 +38,6 @@ class MicroserviceClient extends BaseService_1.BaseService {
|
|
|
38
38
|
const nonce = crypto_1.default.randomBytes(16).toString("hex");
|
|
39
39
|
const headers = {
|
|
40
40
|
"Content-Type": "application/json",
|
|
41
|
-
"x-microservice-id": this.options.id,
|
|
42
41
|
"x-microservice-ts": ts,
|
|
43
42
|
"x-microservice-nonce": nonce
|
|
44
43
|
};
|
|
@@ -69,12 +69,12 @@ class MicroserviceHost extends BaseService_1.BaseService {
|
|
|
69
69
|
const key = crypto_1.default.pbkdf2Sync(secret, salt, 100, 32, "sha256");
|
|
70
70
|
const iv = crypto_1.default.pbkdf2Sync(secret, salt, 100, 16, "sha256");
|
|
71
71
|
const aad = Buffer.from(ts + "." + nonce + "." + this.options.id + "." + this.options.password, "utf8");
|
|
72
|
-
const tag = req.data.tag;
|
|
73
|
-
const
|
|
72
|
+
const tag = Buffer.from(req.data.tag, "base64");
|
|
73
|
+
const enc = Buffer.from(req.data.enc, "base64");
|
|
74
74
|
const decipher = crypto_1.default.createDecipheriv("aes-256-gcm", key, iv);
|
|
75
75
|
decipher.setAAD(aad);
|
|
76
76
|
decipher.setAuthTag(tag);
|
|
77
|
-
const decrypted = Buffer.concat([decipher.update(
|
|
77
|
+
const decrypted = Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
78
78
|
let request = null;
|
|
79
79
|
try {
|
|
80
80
|
request = JSON.parse(decrypted.toString("utf8"));
|
|
@@ -108,6 +108,14 @@ class Validator {
|
|
|
108
108
|
foundKeys.push(i);
|
|
109
109
|
continue;
|
|
110
110
|
}
|
|
111
|
+
if (typeof structure[i] === "object" && Array.isArray(structure[i]) && structure[i].length === 0) {
|
|
112
|
+
foundKeys.push(i);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (typeof structure[i] === "object" && Object.keys(structure[i]).length === 0) {
|
|
116
|
+
foundKeys.push(i);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
111
119
|
let structureOptions = Validator.parseStructureOptions(i, structure);
|
|
112
120
|
if (structureOptions.skip_validation) {
|
|
113
121
|
foundKeys.push(i);
|
|
@@ -327,6 +335,8 @@ class Validator {
|
|
|
327
335
|
static syncStructure(structure, node) {
|
|
328
336
|
if (structure === null || typeof structure !== "object")
|
|
329
337
|
return node;
|
|
338
|
+
if (structure && typeof structure === "object" && Object.keys(structure).length === 0)
|
|
339
|
+
return node;
|
|
330
340
|
if (Array.isArray(structure)) {
|
|
331
341
|
const tmpl = structure[0];
|
|
332
342
|
if (!Array.isArray(node) && this.isPlainObject(node)) {
|