badmfck-api-server 4.0.96 → 4.0.98
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/APIService.d.ts +5 -2
- package/dist/apiServer/APIService.js +1 -1
- package/dist/apiServer/DBService.js +9 -10
- package/dist/apiServer/documentation/Documentation.d.ts +1 -1
- package/dist/apiServer/documentation/Documentation.js +22 -3
- package/dist/apiServer/documentation/index.html +56 -42
- package/dist/apiServer/external/MicroserviceClient.js +4 -1
- package/dist/apiServer/helper/DataProvider.js +1 -2
- package/dist/apiServer/helper/Validator.js +38 -20
- package/package.json +2 -2
- package/untitled folder/assets/index-BQHWfl2U.js +0 -40
- package/untitled folder/index.html +0 -12
|
@@ -9,6 +9,9 @@ export interface IMonitorUser {
|
|
|
9
9
|
login: string;
|
|
10
10
|
password: string;
|
|
11
11
|
}
|
|
12
|
+
export interface IDocumentationUser extends IMonitorUser {
|
|
13
|
+
endpoints?: string[];
|
|
14
|
+
}
|
|
12
15
|
export interface APIServiceNetworkLogItem {
|
|
13
16
|
id: number;
|
|
14
17
|
created: number;
|
|
@@ -40,7 +43,7 @@ export interface APIServiceOptions<TInterceptor = unknown> {
|
|
|
40
43
|
preproducer?: (req: HTTPRequestVO | undefined | null) => any;
|
|
41
44
|
access: {
|
|
42
45
|
monitor?: IMonitorUser[];
|
|
43
|
-
documentation?:
|
|
46
|
+
documentation?: IDocumentationUser[];
|
|
44
47
|
};
|
|
45
48
|
appVersion?: string;
|
|
46
49
|
fileTempDir: string;
|
|
@@ -58,7 +61,7 @@ export declare const REQ_HTTP_SERVER: Req<void, {
|
|
|
58
61
|
}>;
|
|
59
62
|
export declare const REQ_INTERNAL_CALL: Req<HTTPRequestVO, IError | any>;
|
|
60
63
|
export declare const REQ_MONITOR_USERS: Req<void, IMonitorUser[]>;
|
|
61
|
-
export declare const REQ_DOC_USERS: Req<void,
|
|
64
|
+
export declare const REQ_DOC_USERS: Req<void, IDocumentationUser[]>;
|
|
62
65
|
export declare const S_APP_STARTED: Signal<void>;
|
|
63
66
|
export declare function Initializer(services: IBaseService[]): Promise<void>;
|
|
64
67
|
export declare class APIService<TInterceptorResult = any, TInternalCallParams = any> extends BaseService {
|
|
@@ -284,7 +284,7 @@ class DBService extends BaseService_1.BaseService {
|
|
|
284
284
|
return error;
|
|
285
285
|
}
|
|
286
286
|
async reportQuery(result, req) {
|
|
287
|
-
const hour =
|
|
287
|
+
const hour = new Date().getHours().toString().padStart(2, "0");
|
|
288
288
|
if (this.queriesStat.hour !== hour) {
|
|
289
289
|
this.queriesStat.hour = hour;
|
|
290
290
|
this.queriesStat.stat = { failed: 0, success: 0, failedQueries: [] };
|
|
@@ -297,15 +297,14 @@ class DBService extends BaseService_1.BaseService {
|
|
|
297
297
|
this.queriesStat.stat.success++;
|
|
298
298
|
const execTime = result.execution.finished_at - result.execution.started_at;
|
|
299
299
|
if (execTime && execTime > 0) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
300
|
+
const minLong = this.longQueries.length < 20 || execTime > this.longQueries[0].execution;
|
|
301
|
+
if (minLong) {
|
|
302
|
+
this.longQueries.push({
|
|
303
|
+
execution: execTime,
|
|
304
|
+
query: req.query,
|
|
305
|
+
started_at: result.execution.started_at,
|
|
306
|
+
finished_at: result.execution.finished_at
|
|
307
|
+
});
|
|
309
308
|
}
|
|
310
309
|
this.longQueries.sort((a, b) => a.execution - b.execution);
|
|
311
310
|
if (this.longQueries.length > 20)
|
|
@@ -9,5 +9,5 @@ export declare class Documentation extends BaseEndpoint {
|
|
|
9
9
|
data: Record<string, any>[];
|
|
10
10
|
}>;
|
|
11
11
|
html(req: HTTPRequestVO): Promise<TransferPacketVO<any>>;
|
|
12
|
-
checkAuthorization(req: HTTPRequestVO): Promise<
|
|
12
|
+
checkAuthorization(req: HTTPRequestVO): Promise<string[] | undefined>;
|
|
13
13
|
}
|
|
@@ -33,8 +33,27 @@ class Documentation extends BaseEndpoint_1.BaseEndpoint {
|
|
|
33
33
|
}]);
|
|
34
34
|
}
|
|
35
35
|
async json(req) {
|
|
36
|
-
await this.checkAuthorization(req);
|
|
37
|
-
|
|
36
|
+
const endpoints = await this.checkAuthorization(req);
|
|
37
|
+
let doc = JSON.parse(JSON.stringify(await DocumentService_1.REQ_DOC.request()));
|
|
38
|
+
if (endpoints && endpoints.length > 0) {
|
|
39
|
+
doc = doc.filter((group) => {
|
|
40
|
+
if (group.endpoints && Array.isArray(group.endpoints)) {
|
|
41
|
+
group.endpoints = group.endpoints.filter((ep) => {
|
|
42
|
+
const path = ep.name;
|
|
43
|
+
return endpoints.some((pattern) => {
|
|
44
|
+
if (pattern.endsWith('/*')) {
|
|
45
|
+
const base = pattern.slice(0, -2);
|
|
46
|
+
return path === base || path.startsWith(base + '/');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return path === pattern;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return group.endpoints && group.endpoints.length > 0;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
38
57
|
return { data: doc };
|
|
39
58
|
}
|
|
40
59
|
async html(req) {
|
|
@@ -80,7 +99,7 @@ class Documentation extends BaseEndpoint_1.BaseEndpoint {
|
|
|
80
99
|
for (let i of users) {
|
|
81
100
|
const hash = crypto_1.default.createHash("sha256").update(i.login + ":" + i.password).digest("hex");
|
|
82
101
|
if (hash === header) {
|
|
83
|
-
return;
|
|
102
|
+
return i.endpoints;
|
|
84
103
|
}
|
|
85
104
|
}
|
|
86
105
|
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Invalid user" };
|