badmfck-api-server 3.0.3 → 3.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.
@@ -118,6 +118,7 @@ class BaseEndpoint {
|
|
118
118
|
const report = await Validator_1.Validator.validateStructure(structure, req.data);
|
119
119
|
if (report)
|
120
120
|
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: report };
|
121
|
+
Validator_1.Validator.filterStructure(structure, req.data);
|
121
122
|
}
|
122
123
|
createStream(req) {
|
123
124
|
const res = req.response;
|
@@ -50,7 +50,7 @@ exports.REQ_XT.listener = async ({ id, req }) => {
|
|
50
50
|
exports.REQ_EXTERNAL_CALL.listener = async ({ id, requestName, requestData }) => {
|
51
51
|
if (ExternalService.allInstances.length === 0) {
|
52
52
|
console.error("ExternalService.allInstances.length === 0");
|
53
|
-
return { ...DefaultErrors_1.default.BAD_REQUEST, details: "no external
|
53
|
+
return { ...DefaultErrors_1.default.BAD_REQUEST, details: "no external service found: " + id + ", requestName:" + requestName, stack: [requestData] };
|
54
54
|
}
|
55
55
|
for (let i of ExternalService.allInstances) {
|
56
56
|
if (i.options.id === id)
|
@@ -21,7 +21,8 @@ export declare enum ValidationReport {
|
|
21
21
|
}
|
22
22
|
export declare class Validator {
|
23
23
|
static validateObject(fields: string[], object: any): boolean;
|
24
|
-
static validateStructure(structure: any, object: any): Promise<string[] | undefined>;
|
24
|
+
static validateStructure(structure: any, object: any, level?: number): Promise<string[] | undefined>;
|
25
|
+
static filterStructure(structure: any, object: any): void;
|
25
26
|
static convertToType<T>(value: any, type: "string" | "number" | "boolean" | "date"): T | null;
|
26
27
|
static validateValue(value: string | number | boolean, opt?: IValidatorOptions): ValidationReport;
|
27
28
|
}
|
@@ -24,7 +24,7 @@ class Validator {
|
|
24
24
|
}
|
25
25
|
return true;
|
26
26
|
}
|
27
|
-
static async validateStructure(structure, object) {
|
27
|
+
static async validateStructure(structure, object, level = 0) {
|
28
28
|
if (!structure)
|
29
29
|
return;
|
30
30
|
if (!object)
|
@@ -65,7 +65,7 @@ class Validator {
|
|
65
65
|
if (typeof object[i] !== typeof structure[i])
|
66
66
|
errors.push("wrong datatype for field '" + i + "' expected " + typeof structure[i] + " got " + typeof object[i]);
|
67
67
|
if (typeof structure[i] === "object" || typeof structure[i] === "function") {
|
68
|
-
const result = await this.validateStructure(structure[i], object[i]);
|
68
|
+
const result = await this.validateStructure(structure[i], object[i], level++);
|
69
69
|
if (result) {
|
70
70
|
for (let j of result)
|
71
71
|
errors.push(j);
|
@@ -121,6 +121,21 @@ class Validator {
|
|
121
121
|
return errors;
|
122
122
|
return;
|
123
123
|
}
|
124
|
+
static filterStructure(structure, object) {
|
125
|
+
if (!structure || !object)
|
126
|
+
return;
|
127
|
+
if (typeof structure !== "object" || typeof object !== "object")
|
128
|
+
return;
|
129
|
+
if (Array.isArray(structure))
|
130
|
+
return;
|
131
|
+
for (let key in object) {
|
132
|
+
if (!(key in structure)) {
|
133
|
+
delete object[key];
|
134
|
+
continue;
|
135
|
+
}
|
136
|
+
this.filterStructure(structure[key], object[key]);
|
137
|
+
}
|
138
|
+
}
|
124
139
|
static convertToType(value, type) {
|
125
140
|
if (value === null || value === undefined)
|
126
141
|
return null;
|