badmfck-api-server 3.0.9 → 3.1.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/dist/apiServer/APIService.js +2 -2
- package/dist/apiServer/BaseEndpoint.d.ts +2 -0
- package/dist/apiServer/DocumentService.js +4 -2
- package/dist/apiServer/documentation/Documentation.d.ts +4 -4
- package/dist/apiServer/documentation/Documentation.js +10 -4
- package/dist/apiServer/helper/Validator.js +5 -3
- package/package.json +1 -1
@@ -96,7 +96,7 @@ async function Initializer(services) {
|
|
96
96
|
exports.Initializer = Initializer;
|
97
97
|
class APIService extends BaseService_1.BaseService {
|
98
98
|
static nextLogID = 0;
|
99
|
-
version = "3.
|
99
|
+
version = "3.1.1";
|
100
100
|
options;
|
101
101
|
monitor = null;
|
102
102
|
monitorIndexFile;
|
@@ -119,7 +119,7 @@ class APIService extends BaseService_1.BaseService {
|
|
119
119
|
this.monitor.init();
|
120
120
|
this.options.endpoints.push(new Monitor_1.Monitor());
|
121
121
|
}
|
122
|
-
this.options.endpoints.push(new Documentation_1.Documentation());
|
122
|
+
this.options.endpoints.push(new Documentation_1.Documentation(this.options));
|
123
123
|
this.options.endpoints.push(new ExternalServiceEndpoint_1.ExternalServiceEndpoint());
|
124
124
|
this.options.endpoints.push(new Liveness_1.Liveness(this.started), new Readiness_1.Readiness(this.started));
|
125
125
|
exports.REQ_HTTP_REQUESTS_COUNT.listener = async () => this.requestsCount;
|
@@ -13,6 +13,7 @@ export type IHandler = Record<HTTPMethod, ((req: HTTPRequestVO) => Promise<Trans
|
|
13
13
|
ignoreInterceptor?: boolean;
|
14
14
|
allowInterceptorError?: boolean;
|
15
15
|
validationModel?: any;
|
16
|
+
resultModel?: any;
|
16
17
|
asStream?: boolean;
|
17
18
|
ignoreInDocumentation?: boolean;
|
18
19
|
ignoreHttpLogging?: boolean;
|
@@ -31,6 +32,7 @@ export interface IEndpointHandler {
|
|
31
32
|
description?: string;
|
32
33
|
title?: string;
|
33
34
|
validationModel?: any;
|
35
|
+
resultModel?: any;
|
34
36
|
}
|
35
37
|
export declare class BaseEndpoint implements IBaseEndpoint {
|
36
38
|
private inializedEndpointNames;
|
@@ -33,7 +33,8 @@ class DocumentGenerator {
|
|
33
33
|
title: j.title || "",
|
34
34
|
description: j.description,
|
35
35
|
parameters: Validator_1.Validator.documentStructure(j.validationModel),
|
36
|
-
authorized: !j.ignoreInterceptor
|
36
|
+
authorized: !j.ignoreInterceptor,
|
37
|
+
returns: j.resultModel ? Validator_1.Validator.documentStructure(j.resultModel) : undefined
|
37
38
|
};
|
38
39
|
}
|
39
40
|
else if (typeof j.handler === "object") {
|
@@ -45,7 +46,8 @@ class DocumentGenerator {
|
|
45
46
|
title: handler.title || j.title || "",
|
46
47
|
description: handler.description || j.description,
|
47
48
|
parameters: Validator_1.Validator.documentStructure(handler.validationModel),
|
48
|
-
authorized: !handler.ignoreInterceptor
|
49
|
+
authorized: !handler.ignoreInterceptor,
|
50
|
+
returns: j.resultModel ? Validator_1.Validator.documentStructure(j.resultModel) : undefined
|
49
51
|
};
|
50
52
|
}
|
51
53
|
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
|
2
|
-
/// <reference types="node" />
|
1
|
+
import { APIServiceOptions } from "../APIService";
|
3
2
|
import { BaseEndpoint } from "../BaseEndpoint";
|
4
3
|
import { HTTPRequestVO, TransferPacketVO } from "../structures/Interfaces";
|
5
4
|
export declare class Documentation extends BaseEndpoint {
|
6
|
-
indexHtmlFile:
|
7
|
-
|
5
|
+
indexHtmlFile: string | null;
|
6
|
+
apiServiceOptions: APIServiceOptions;
|
7
|
+
constructor(options: APIServiceOptions);
|
8
8
|
json(req: HTTPRequestVO): Promise<{
|
9
9
|
data: Record<string, any>[];
|
10
10
|
}>;
|
@@ -13,8 +13,11 @@ const fs_1 = __importDefault(require("fs"));
|
|
13
13
|
const path_1 = __importDefault(require("path"));
|
14
14
|
class Documentation extends BaseEndpoint_1.BaseEndpoint {
|
15
15
|
indexHtmlFile = null;
|
16
|
-
|
16
|
+
apiServiceOptions;
|
17
|
+
constructor(options) {
|
17
18
|
super("doc");
|
19
|
+
this.apiServiceOptions = options;
|
20
|
+
this.ignoreInDocumentation = true;
|
18
21
|
this.registerEndpoints([{
|
19
22
|
ignoreInDocumentation: true,
|
20
23
|
endpoint: "json",
|
@@ -34,14 +37,17 @@ class Documentation extends BaseEndpoint_1.BaseEndpoint {
|
|
34
37
|
return { data: doc };
|
35
38
|
}
|
36
39
|
async html(req) {
|
37
|
-
if (!this.indexHtmlFile)
|
38
|
-
this.indexHtmlFile = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "index.html"));
|
40
|
+
if (!this.indexHtmlFile) {
|
41
|
+
this.indexHtmlFile = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "index.html")).toString("utf-8");
|
42
|
+
const endpoint = "./" + this.apiServiceOptions.baseEndPoint + this.endpoint + "/" + "json";
|
43
|
+
this.indexHtmlFile = this.indexHtmlFile.replace(/{{HOST}}/g, endpoint);
|
44
|
+
}
|
39
45
|
return {
|
40
46
|
rawResponse: true,
|
41
47
|
data: this.indexHtmlFile,
|
42
48
|
headers: {
|
43
49
|
"Content-Type": "text/html",
|
44
|
-
"Content-Length": this.indexHtmlFile.
|
50
|
+
"Content-Length": this.indexHtmlFile.length.toString()
|
45
51
|
}
|
46
52
|
};
|
47
53
|
}
|
@@ -32,11 +32,13 @@ class Validator {
|
|
32
32
|
if (i.startsWith("$__"))
|
33
33
|
continue;
|
34
34
|
let type = typeof structure[i];
|
35
|
-
let description = structure[
|
35
|
+
let description = structure['$__' + i] || "";
|
36
36
|
let childs = undefined;
|
37
|
-
let optional = structure[
|
37
|
+
let optional = structure['$__optional_' + i] || "";
|
38
38
|
if (optional === undefined)
|
39
39
|
optional = structure[i] === null || structure[i] === undefined;
|
40
|
+
if (type === "object" && Array.isArray(structure[i]))
|
41
|
+
type = "array";
|
40
42
|
if (typeof structure[i] === "object")
|
41
43
|
childs = this.documentStructure(structure[i]);
|
42
44
|
if (structure[i] === "@")
|
@@ -81,7 +83,7 @@ class Validator {
|
|
81
83
|
foundKeys.push(i);
|
82
84
|
continue;
|
83
85
|
}
|
84
|
-
let optional = structure[
|
86
|
+
let optional = structure['$__optional_' + i] || false;
|
85
87
|
if (!(i in object)) {
|
86
88
|
if (!optional)
|
87
89
|
errors.push("no field '" + i + "'");
|