badmfck-api-server 4.1.25 → 4.1.27
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/dist/apiServer/BaseEndpoint.d.ts +26 -0
- package/dist/apiServer/BaseEndpoint.js +58 -0
- package/dist/apiServer/BaseService.d.ts +4 -0
- package/dist/apiServer/BaseService.js +9 -1
- package/dist/apiServer/LogService.d.ts +5 -0
- package/dist/apiServer/LogService.js +47 -0
- package/dist/apiServer/documentation/index.html +46 -46
- package/dist/apiServer/http/Http.d.ts +75 -0
- package/dist/apiServer/http/Http.js +201 -4
- package/dist/apiServer/monitor/Monitor.d.ts +5 -0
- package/dist/apiServer/monitor/Monitor.js +50 -0
- package/dist/apiServer/monitor/ProcessMonitor.d.ts +117 -0
- package/dist/apiServer/monitor/ProcessMonitor.js +308 -0
- package/dist/apiServer/monitor/SystemInfo.d.ts +71 -0
- package/dist/apiServer/monitor/SystemInfo.js +218 -0
- package/dist/apiServer/monitor/index.html +140 -68
- package/package.json +1 -1
|
@@ -37,6 +37,7 @@ export interface IEndpointHandler {
|
|
|
37
37
|
resultModel?: any;
|
|
38
38
|
}
|
|
39
39
|
export declare class BaseEndpoint implements IBaseEndpoint {
|
|
40
|
+
static allInstances: BaseEndpoint[];
|
|
40
41
|
private inializedEndpointNames;
|
|
41
42
|
description: string;
|
|
42
43
|
endpoints?: IEndpointHandler[];
|
|
@@ -44,6 +45,8 @@ export declare class BaseEndpoint implements IBaseEndpoint {
|
|
|
44
45
|
ignoreInDocumentation: boolean;
|
|
45
46
|
private static entrypoint;
|
|
46
47
|
endpoint: string;
|
|
48
|
+
createdAt: number;
|
|
49
|
+
initializedAt: number | null;
|
|
47
50
|
protected streamOptions: Record<string, any>;
|
|
48
51
|
static setEntryPoint: (ep: string) => void;
|
|
49
52
|
static getEntryPoint: () => string;
|
|
@@ -51,6 +54,29 @@ export declare class BaseEndpoint implements IBaseEndpoint {
|
|
|
51
54
|
registerEndpoints(endpoints: IEndpointHandler[]): void;
|
|
52
55
|
init(): Promise<void>;
|
|
53
56
|
getInitalizedEndpointNames(): String[];
|
|
57
|
+
getInventory(): {
|
|
58
|
+
className: string;
|
|
59
|
+
basePath: string;
|
|
60
|
+
ignoreHttpLogging: boolean;
|
|
61
|
+
ignoreInDocumentation: boolean;
|
|
62
|
+
description: string;
|
|
63
|
+
createdAt: number;
|
|
64
|
+
initializedAt: number | null;
|
|
65
|
+
handlerCount: number;
|
|
66
|
+
handlers: {
|
|
67
|
+
path: string;
|
|
68
|
+
methods: string[];
|
|
69
|
+
ignoreInterceptor: boolean;
|
|
70
|
+
ignoreInDocumentation: boolean;
|
|
71
|
+
ignoreHttpLogging: boolean;
|
|
72
|
+
independed: boolean;
|
|
73
|
+
asStream: boolean;
|
|
74
|
+
hasValidationModel: boolean;
|
|
75
|
+
hasResultModel: boolean;
|
|
76
|
+
description?: string | undefined;
|
|
77
|
+
title?: string | undefined;
|
|
78
|
+
}[];
|
|
79
|
+
};
|
|
54
80
|
__precheck(req: HTTPRequestVO): Promise<TransferPacketVO<any> | null>;
|
|
55
81
|
__execute(req: HTTPRequestVO): Promise<TransferPacketVO<any>>;
|
|
56
82
|
protected validateStructure(structure: any, req: HTTPRequestVO): Promise<void>;
|
|
@@ -10,6 +10,7 @@ const DefaultErrors_1 = __importDefault(require("./structures/DefaultErrors"));
|
|
|
10
10
|
const stream_1 = require("stream");
|
|
11
11
|
const httpMethods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD", "TRACE", "CONNECT"];
|
|
12
12
|
class BaseEndpoint {
|
|
13
|
+
static allInstances = [];
|
|
13
14
|
inializedEndpointNames = [];
|
|
14
15
|
description = "no description";
|
|
15
16
|
endpoints;
|
|
@@ -17,6 +18,8 @@ class BaseEndpoint {
|
|
|
17
18
|
ignoreInDocumentation = false;
|
|
18
19
|
static entrypoint = "/";
|
|
19
20
|
endpoint = "";
|
|
21
|
+
createdAt = Date.now();
|
|
22
|
+
initializedAt = null;
|
|
20
23
|
streamOptions = {};
|
|
21
24
|
static setEntryPoint = (ep) => {
|
|
22
25
|
this.entrypoint = ep;
|
|
@@ -35,6 +38,7 @@ class BaseEndpoint {
|
|
|
35
38
|
if (!endpoint.endsWith("/"))
|
|
36
39
|
endpoint = endpoint + "/";
|
|
37
40
|
this.endpoint = endpoint;
|
|
41
|
+
BaseEndpoint.allInstances.push(this);
|
|
38
42
|
}
|
|
39
43
|
registerEndpoints(endpoints) {
|
|
40
44
|
for (let i of endpoints) {
|
|
@@ -63,11 +67,65 @@ class BaseEndpoint {
|
|
|
63
67
|
(0, LogService_1.logInfo)("${BaseEndpoint.js}", "endpoint: " + i.endpoint + " initalized, ignoreInterceptor: " + (i.ignoreInterceptor ?? "false"));
|
|
64
68
|
this.inializedEndpointNames.push(i.endpoint + " ignore interceptor: " + (i.ignoreInterceptor ?? "false"));
|
|
65
69
|
}
|
|
70
|
+
this.initializedAt = Date.now();
|
|
66
71
|
}
|
|
67
72
|
;
|
|
68
73
|
getInitalizedEndpointNames() {
|
|
69
74
|
return this.inializedEndpointNames;
|
|
70
75
|
}
|
|
76
|
+
getInventory() {
|
|
77
|
+
const handlers = [];
|
|
78
|
+
for (const i of this.endpoints ?? []) {
|
|
79
|
+
let methods = [];
|
|
80
|
+
let asStream = i.asStream === true;
|
|
81
|
+
let hasVm = i.validationModel !== undefined;
|
|
82
|
+
let hasRm = i.resultModel !== undefined;
|
|
83
|
+
if (typeof i.handler === "function") {
|
|
84
|
+
methods = ["ANY"];
|
|
85
|
+
}
|
|
86
|
+
else if (i.handler && typeof i.handler === "object") {
|
|
87
|
+
for (const key of Object.keys(i.handler)) {
|
|
88
|
+
const h = i.handler[key];
|
|
89
|
+
if (typeof h === "function") {
|
|
90
|
+
methods.push(key);
|
|
91
|
+
}
|
|
92
|
+
else if (h && typeof h === "object" && typeof h.controller === "function") {
|
|
93
|
+
methods.push(key);
|
|
94
|
+
if (h.asStream)
|
|
95
|
+
asStream = true;
|
|
96
|
+
if (h.validationModel !== undefined)
|
|
97
|
+
hasVm = true;
|
|
98
|
+
if (h.resultModel !== undefined)
|
|
99
|
+
hasRm = true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
handlers.push({
|
|
104
|
+
path: (BaseEndpoint.entrypoint + i.endpoint).replaceAll("//", "/"),
|
|
105
|
+
methods,
|
|
106
|
+
ignoreInterceptor: i.ignoreInterceptor === true,
|
|
107
|
+
ignoreInDocumentation: i.ignoreInDocumentation === true,
|
|
108
|
+
ignoreHttpLogging: i.ignoreHttpLogging === true,
|
|
109
|
+
independed: i.independed === true,
|
|
110
|
+
asStream,
|
|
111
|
+
hasValidationModel: hasVm,
|
|
112
|
+
hasResultModel: hasRm,
|
|
113
|
+
description: i.description,
|
|
114
|
+
title: i.title,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
className: this.constructor.name,
|
|
119
|
+
basePath: this.endpoint,
|
|
120
|
+
ignoreHttpLogging: this.ignoreHttpLogging,
|
|
121
|
+
ignoreInDocumentation: this.ignoreInDocumentation,
|
|
122
|
+
description: this.description,
|
|
123
|
+
createdAt: this.createdAt,
|
|
124
|
+
initializedAt: this.initializedAt,
|
|
125
|
+
handlerCount: handlers.length,
|
|
126
|
+
handlers,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
71
129
|
async __precheck(req) { return null; }
|
|
72
130
|
async __execute(req) {
|
|
73
131
|
if (this.endpoints && this.endpoints.length > 0) {
|
|
@@ -4,7 +4,11 @@ export interface IBaseService {
|
|
|
4
4
|
getName: () => string;
|
|
5
5
|
}
|
|
6
6
|
export declare class BaseService implements IBaseService {
|
|
7
|
+
static allInstances: BaseService[];
|
|
7
8
|
protected name: string;
|
|
9
|
+
createdAt: number;
|
|
10
|
+
initializedAt: number | null;
|
|
11
|
+
applicationReadyAt: number | null;
|
|
8
12
|
constructor(name: string);
|
|
9
13
|
init(): Promise<void>;
|
|
10
14
|
finishService(): Promise<void>;
|
|
@@ -11,14 +11,20 @@ process.on('SIGTERM', async () => {
|
|
|
11
11
|
process.exit(0);
|
|
12
12
|
});
|
|
13
13
|
class BaseService {
|
|
14
|
+
static allInstances = [];
|
|
14
15
|
name = "BaseService";
|
|
16
|
+
createdAt = Date.now();
|
|
17
|
+
initializedAt = null;
|
|
18
|
+
applicationReadyAt = null;
|
|
15
19
|
constructor(name) {
|
|
16
20
|
this.name = name;
|
|
17
21
|
this.finishService = this.finishService.bind(this);
|
|
22
|
+
BaseService.allInstances.push(this);
|
|
18
23
|
}
|
|
19
24
|
async init() {
|
|
20
25
|
console.log("Service: " + this.name + " initialized");
|
|
21
26
|
finalize.push(this.finishService);
|
|
27
|
+
this.initializedAt = Date.now();
|
|
22
28
|
}
|
|
23
29
|
async finishService() {
|
|
24
30
|
console.log("finishService -> " + (this.name ?? "no-name"));
|
|
@@ -26,6 +32,8 @@ class BaseService {
|
|
|
26
32
|
getName() {
|
|
27
33
|
return this.name;
|
|
28
34
|
}
|
|
29
|
-
applicationReady() {
|
|
35
|
+
applicationReady() {
|
|
36
|
+
this.applicationReadyAt = Date.now();
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
39
|
exports.BaseService = BaseService;
|
|
@@ -62,4 +62,9 @@ export declare class LogService extends BaseService {
|
|
|
62
62
|
createDate(d?: Date): string;
|
|
63
63
|
leadZero(num: number): string;
|
|
64
64
|
createText(data: any, level: LOG_LEVEL): string;
|
|
65
|
+
private static readonly SANITIZERS;
|
|
66
|
+
static sanitize(text: string): string;
|
|
67
|
+
private static readonly PAN_CANDIDATE_REGEX;
|
|
68
|
+
private static isLuhnValid;
|
|
69
|
+
static maskPAN(text: string): string;
|
|
65
70
|
}
|
|
@@ -244,7 +244,54 @@ class LogService extends BaseService_1.BaseService {
|
|
|
244
244
|
}
|
|
245
245
|
if (res.length > this.options.textLimit && level === LOG_LEVEL.INFO)
|
|
246
246
|
res = res.substring(0, this.options.textLimit) + "... (total: " + res.length + ")";
|
|
247
|
+
res = LogService.sanitize(res);
|
|
247
248
|
return res;
|
|
248
249
|
}
|
|
250
|
+
static SANITIZERS = [
|
|
251
|
+
[/-----BEGIN [A-Z0-9 ]+-----[\s\S]+?-----END [A-Z0-9 ]+-----/g, "<REDACTED PEM>"],
|
|
252
|
+
[/eyJ[A-Za-z0-9_-]{5,}\.eyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]+/g, "<REDACTED JWT>"],
|
|
253
|
+
[/(Bearer|Basic|Digest)\s+[A-Za-z0-9\-._~+\/=]+/gi, "$1 <REDACTED>"],
|
|
254
|
+
[/%B\d{13,19}\^[^?]{2,50}\^\d{4,}[^?]*\?/g, "<REDACTED TRACK1>"],
|
|
255
|
+
[/;\d{13,19}=\d{4,}[^?]*\?/g, "<REDACTED TRACK2>"],
|
|
256
|
+
[/("(?:password|passwd|pwd|secret|api[_-]?key|api[_-]?secret|client[_-]?secret|access[_-]?key|private[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|token|authorization|cookie|set[_-]?cookie|session[_-]?id|sess[_-]?id|sid|cvv2?|cvc2?|cvn|cav2?|cid|security[_-]?code|card[_-]?verification[_-]?(?:value|code)?|pin|pin[_-]?block|encrypted[_-]?pin|iso[_-]?9564|exp|expiry|expiration|expiration[_-]?date|exp[_-]?date|exp[_-]?month|exp[_-]?year|cardholder[_-]?name|holder[_-]?name|card[_-]?holder)"\s*:\s*)"[^"]*"/gi, '$1"<REDACTED>"'],
|
|
257
|
+
[/("(?:cvv2?|cvc2?|pin|exp[_-]?month|exp[_-]?year|service[_-]?code)"\s*:\s*)(-?\d+)/gi, '$1"<REDACTED>"'],
|
|
258
|
+
];
|
|
259
|
+
static sanitize(text) {
|
|
260
|
+
if (!text || text.length < 3)
|
|
261
|
+
return text;
|
|
262
|
+
let out = text;
|
|
263
|
+
for (const [re, repl] of LogService.SANITIZERS)
|
|
264
|
+
out = out.replace(re, repl);
|
|
265
|
+
return LogService.maskPAN(out);
|
|
266
|
+
}
|
|
267
|
+
static PAN_CANDIDATE_REGEX = /(?<!\d)(?:\d[ -]?){12,18}\d(?!\d)/g;
|
|
268
|
+
static isLuhnValid(digits) {
|
|
269
|
+
if (digits.length < 13 || digits.length > 19)
|
|
270
|
+
return false;
|
|
271
|
+
let sum = 0;
|
|
272
|
+
let alt = false;
|
|
273
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
274
|
+
const d = digits.charCodeAt(i) - 48;
|
|
275
|
+
if (d < 0 || d > 9)
|
|
276
|
+
return false;
|
|
277
|
+
let x = d;
|
|
278
|
+
if (alt) {
|
|
279
|
+
x *= 2;
|
|
280
|
+
if (x > 9)
|
|
281
|
+
x -= 9;
|
|
282
|
+
}
|
|
283
|
+
sum += x;
|
|
284
|
+
alt = !alt;
|
|
285
|
+
}
|
|
286
|
+
return sum % 10 === 0;
|
|
287
|
+
}
|
|
288
|
+
static maskPAN(text) {
|
|
289
|
+
if (!text || text.length < 13)
|
|
290
|
+
return text;
|
|
291
|
+
return text.replace(LogService.PAN_CANDIDATE_REGEX, (match) => {
|
|
292
|
+
const digits = match.replace(/\D/g, "");
|
|
293
|
+
return LogService.isLuhnValid(digits) ? "xxxx...xxxx" : match;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
249
296
|
}
|
|
250
297
|
exports.LogService = LogService;
|