@bmfk/api 0.0.0-stage → 1.0.0
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/CHANGELOG.md +83 -0
- package/LICENSE +21 -0
- package/README.md +1293 -2
- package/dist/apiServer/APIService.d.ts +125 -0
- package/dist/apiServer/APIService.js +769 -0
- package/dist/apiServer/BaseEndpoint.d.ts +90 -0
- package/dist/apiServer/BaseEndpoint.js +314 -0
- package/dist/apiServer/BaseService.d.ts +17 -0
- package/dist/apiServer/BaseService.js +39 -0
- package/dist/apiServer/DBService.d.ts +131 -0
- package/dist/apiServer/DBService.js +290 -0
- package/dist/apiServer/DocumentService.d.ts +9 -0
- package/dist/apiServer/DocumentService.js +65 -0
- package/dist/apiServer/LocalRequest.d.ts +3 -0
- package/dist/apiServer/LocalRequest.js +6 -0
- package/dist/apiServer/LogService.d.ts +78 -0
- package/dist/apiServer/LogService.js +349 -0
- package/dist/apiServer/MonitorService.d.ts +102 -0
- package/dist/apiServer/MonitorService.js +615 -0
- package/dist/apiServer/StatService.d.ts +4 -0
- package/dist/apiServer/StatService.js +10 -0
- package/dist/apiServer/TimeframeService.d.ts +28 -0
- package/dist/apiServer/TimeframeService.js +97 -0
- package/dist/apiServer/WebSocketServer.d.ts +39 -0
- package/dist/apiServer/WebSocketServer.js +173 -0
- package/dist/apiServer/db/IDBAdapter.d.ts +14 -0
- package/dist/apiServer/db/IDBAdapter.js +2 -0
- package/dist/apiServer/db/MysqlAdapter.d.ts +72 -0
- package/dist/apiServer/db/MysqlAdapter.js +869 -0
- package/dist/apiServer/db/PostgresAdapter.d.ts +41 -0
- package/dist/apiServer/db/PostgresAdapter.js +73 -0
- package/dist/apiServer/deployment/AccessConfigWizard.d.ts +5 -0
- package/dist/apiServer/deployment/AccessConfigWizard.js +254 -0
- package/dist/apiServer/deployment/Activate.d.ts +4 -0
- package/dist/apiServer/deployment/Activate.js +124 -0
- package/dist/apiServer/deployment/BackupManager.d.ts +33 -0
- package/dist/apiServer/deployment/BackupManager.js +174 -0
- package/dist/apiServer/deployment/Backups.d.ts +2 -0
- package/dist/apiServer/deployment/Backups.js +44 -0
- package/dist/apiServer/deployment/BlueGreenState.d.ts +31 -0
- package/dist/apiServer/deployment/BlueGreenState.js +150 -0
- package/dist/apiServer/deployment/Bundler.d.ts +12 -0
- package/dist/apiServer/deployment/Bundler.js +178 -0
- package/dist/apiServer/deployment/ConfigService.d.ts +203 -0
- package/dist/apiServer/deployment/ConfigService.js +195 -0
- package/dist/apiServer/deployment/Deploy.d.ts +4 -0
- package/dist/apiServer/deployment/Deploy.js +404 -0
- package/dist/apiServer/deployment/DeployKeyWizard.d.ts +2 -0
- package/dist/apiServer/deployment/DeployKeyWizard.js +84 -0
- package/dist/apiServer/deployment/Deployer.d.ts +13 -0
- package/dist/apiServer/deployment/Deployer.js +96 -0
- package/dist/apiServer/deployment/DeployerInit.d.ts +25 -0
- package/dist/apiServer/deployment/DeployerInit.js +214 -0
- package/dist/apiServer/deployment/DeployerService.d.ts +378 -0
- package/dist/apiServer/deployment/DeployerService.js +1553 -0
- package/dist/apiServer/deployment/HashPassword.d.ts +3 -0
- package/dist/apiServer/deployment/HashPassword.js +126 -0
- package/dist/apiServer/deployment/MigrateConfigsWizard.d.ts +1 -0
- package/dist/apiServer/deployment/MigrateConfigsWizard.js +202 -0
- package/dist/apiServer/deployment/MigrateProject.d.ts +31 -0
- package/dist/apiServer/deployment/MigrateProject.js +335 -0
- package/dist/apiServer/deployment/NginxHelper.d.ts +10 -0
- package/dist/apiServer/deployment/NginxHelper.js +111 -0
- package/dist/apiServer/deployment/Notifier.d.ts +30 -0
- package/dist/apiServer/deployment/Notifier.js +82 -0
- package/dist/apiServer/deployment/ProjectConfigWizard.d.ts +1 -0
- package/dist/apiServer/deployment/ProjectConfigWizard.js +148 -0
- package/dist/apiServer/deployment/Restore.d.ts +2 -0
- package/dist/apiServer/deployment/Restore.js +89 -0
- package/dist/apiServer/deployment/ReviewStore.d.ts +62 -0
- package/dist/apiServer/deployment/ReviewStore.js +186 -0
- package/dist/apiServer/deployment/SecretsInjector.d.ts +21 -0
- package/dist/apiServer/deployment/SecretsInjector.js +189 -0
- package/dist/apiServer/deployment/SetupConfigWizard.d.ts +1 -0
- package/dist/apiServer/deployment/SetupConfigWizard.js +238 -0
- package/dist/apiServer/deployment/Status.d.ts +2 -0
- package/dist/apiServer/deployment/Status.js +83 -0
- package/dist/apiServer/deployment/TelegramNotifier.d.ts +8 -0
- package/dist/apiServer/deployment/TelegramNotifier.js +23 -0
- package/dist/apiServer/deployment/Watchdog.d.ts +15 -0
- package/dist/apiServer/deployment/Watchdog.js +65 -0
- package/dist/apiServer/deployment/Wizards.d.ts +1 -0
- package/dist/apiServer/deployment/Wizards.js +83 -0
- package/dist/apiServer/deployment/cli.d.ts +2 -0
- package/dist/apiServer/deployment/cli.js +224 -0
- package/dist/apiServer/deployment/cliCommon.d.ts +27 -0
- package/dist/apiServer/deployment/cliCommon.js +110 -0
- package/dist/apiServer/deployment/cliPrompt.d.ts +5 -0
- package/dist/apiServer/deployment/cliPrompt.js +38 -0
- package/dist/apiServer/deployment/resolveConfig.d.ts +19 -0
- package/dist/apiServer/deployment/resolveConfig.js +139 -0
- package/dist/apiServer/documentation/Documentation.d.ts +18 -0
- package/dist/apiServer/documentation/Documentation.js +143 -0
- package/dist/apiServer/documentation/index.html +460 -0
- package/dist/apiServer/external/MicroserviceClient.d.ts +28 -0
- package/dist/apiServer/external/MicroserviceClient.js +144 -0
- package/dist/apiServer/external/MicroserviceHost.d.ts +52 -0
- package/dist/apiServer/external/MicroserviceHost.js +183 -0
- package/dist/apiServer/external/MicroserviceHostController.d.ts +6 -0
- package/dist/apiServer/external/MicroserviceHostController.js +65 -0
- package/dist/apiServer/helper/AppDataPath.d.ts +9 -0
- package/dist/apiServer/helper/AppDataPath.js +81 -0
- package/dist/apiServer/helper/ClientIp.d.ts +3 -0
- package/dist/apiServer/helper/ClientIp.js +33 -0
- package/dist/apiServer/helper/DataProvider.d.ts +18 -0
- package/dist/apiServer/helper/DataProvider.js +57 -0
- package/dist/apiServer/helper/IpAllowList.d.ts +8 -0
- package/dist/apiServer/helper/IpAllowList.js +40 -0
- package/dist/apiServer/helper/JSONStableStringify.d.ts +1 -0
- package/dist/apiServer/helper/JSONStableStringify.js +15 -0
- package/dist/apiServer/helper/PasswordHash.d.ts +5 -0
- package/dist/apiServer/helper/PasswordHash.js +52 -0
- package/dist/apiServer/helper/Sleep.d.ts +1 -0
- package/dist/apiServer/helper/Sleep.js +5 -0
- package/dist/apiServer/helper/Trace.d.ts +8 -0
- package/dist/apiServer/helper/Trace.js +30 -0
- package/dist/apiServer/helper/UID.d.ts +16 -0
- package/dist/apiServer/helper/UID.js +98 -0
- package/dist/apiServer/helper/Validator.d.ts +86 -0
- package/dist/apiServer/helper/Validator.js +560 -0
- package/dist/apiServer/helper/YYYYMMDDHH.d.ts +2 -0
- package/dist/apiServer/helper/YYYYMMDDHH.js +31 -0
- package/dist/apiServer/helper/ZipUtils.d.ts +6 -0
- package/dist/apiServer/helper/ZipUtils.js +28 -0
- package/dist/apiServer/http/Http.d.ts +183 -0
- package/dist/apiServer/http/Http.js +627 -0
- package/dist/apiServer/interceptors/InterceptorPayAuth.d.ts +19 -0
- package/dist/apiServer/interceptors/InterceptorPayAuth.js +124 -0
- package/dist/apiServer/interceptors/InterceptorSignedAuth.d.ts +40 -0
- package/dist/apiServer/interceptors/InterceptorSignedAuth.js +150 -0
- package/dist/apiServer/monitor/AccessStore.d.ts +27 -0
- package/dist/apiServer/monitor/AccessStore.js +163 -0
- package/dist/apiServer/monitor/LogFiles.d.ts +34 -0
- package/dist/apiServer/monitor/LogFiles.js +109 -0
- package/dist/apiServer/monitor/Monitor.d.ts +54 -0
- package/dist/apiServer/monitor/Monitor.js +447 -0
- package/dist/apiServer/monitor/MonitorAuth.d.ts +87 -0
- package/dist/apiServer/monitor/MonitorAuth.js +474 -0
- package/dist/apiServer/monitor/ProcessMonitor.d.ts +177 -0
- package/dist/apiServer/monitor/ProcessMonitor.js +468 -0
- package/dist/apiServer/monitor/SystemInfo.d.ts +70 -0
- package/dist/apiServer/monitor/SystemInfo.js +217 -0
- package/dist/apiServer/monitor/ThreatMonitor.d.ts +73 -0
- package/dist/apiServer/monitor/ThreatMonitor.js +239 -0
- package/dist/apiServer/monitor/index.html +591 -0
- package/dist/apiServer/review/Review.d.ts +23 -0
- package/dist/apiServer/review/Review.js +149 -0
- package/dist/apiServer/review/ReviewAuth.d.ts +56 -0
- package/dist/apiServer/review/ReviewAuth.js +147 -0
- package/dist/apiServer/review/ReviewDiff.d.ts +43 -0
- package/dist/apiServer/review/ReviewDiff.js +175 -0
- package/dist/apiServer/review/index.html +501 -0
- package/dist/apiServer/routes/Liveness.d.ts +7 -0
- package/dist/apiServer/routes/Liveness.js +27 -0
- package/dist/apiServer/routes/Readiness.d.ts +13 -0
- package/dist/apiServer/routes/Readiness.js +20 -0
- package/dist/apiServer/security/BlockedIps.d.ts +46 -0
- package/dist/apiServer/security/BlockedIps.js +185 -0
- package/dist/apiServer/structures/DefaultErrors.d.ts +36 -0
- package/dist/apiServer/structures/DefaultErrors.js +52 -0
- package/dist/apiServer/structures/HTTPStatus.d.ts +7 -0
- package/dist/apiServer/structures/HTTPStatus.js +11 -0
- package/dist/apiServer/structures/Interfaces.d.ts +55 -0
- package/dist/apiServer/structures/Interfaces.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +110 -0
- package/dist/signal/Signal.d.ts +23 -0
- package/dist/signal/Signal.js +85 -0
- package/package.json +88 -4
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Validator = exports.ValidationReport = void 0;
|
|
7
|
+
const dns_1 = __importDefault(require("dns"));
|
|
8
|
+
var ValidationReport;
|
|
9
|
+
(function (ValidationReport) {
|
|
10
|
+
ValidationReport[ValidationReport["OK"] = 1] = "OK";
|
|
11
|
+
ValidationReport[ValidationReport["VALUE_IS_NULL"] = 2] = "VALUE_IS_NULL";
|
|
12
|
+
ValidationReport[ValidationReport["TYPE_MISSMATCH"] = 3] = "TYPE_MISSMATCH";
|
|
13
|
+
ValidationReport[ValidationReport["VALUE_TOO_BIG"] = 4] = "VALUE_TOO_BIG";
|
|
14
|
+
ValidationReport[ValidationReport["VALUE_TOO_SHORT"] = 5] = "VALUE_TOO_SHORT";
|
|
15
|
+
ValidationReport[ValidationReport["VALUE_INCORRECT"] = 6] = "VALUE_INCORRECT";
|
|
16
|
+
})(ValidationReport || (exports.ValidationReport = ValidationReport = {}));
|
|
17
|
+
class Validator {
|
|
18
|
+
static validateObject(fields, object) {
|
|
19
|
+
if (!object || typeof object !== "object")
|
|
20
|
+
return false;
|
|
21
|
+
for (let i of fields) {
|
|
22
|
+
if (!(i in object) || object[i] === undefined)
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
static documentStructure(structure) {
|
|
28
|
+
const params = {};
|
|
29
|
+
if (!structure || typeof structure !== "object")
|
|
30
|
+
return;
|
|
31
|
+
for (let i in structure) {
|
|
32
|
+
if (i.startsWith("$__"))
|
|
33
|
+
continue;
|
|
34
|
+
let structureOptions = Validator.parseStructureOptions(i, structure);
|
|
35
|
+
let childs = undefined;
|
|
36
|
+
if (typeof structure[i] === "object") {
|
|
37
|
+
if (!structureOptions || !structureOptions.ignore_in_documentation)
|
|
38
|
+
childs = this.documentStructure(structure[i]);
|
|
39
|
+
else
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
params[i] = {
|
|
43
|
+
...structureOptions,
|
|
44
|
+
childs: childs
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return params;
|
|
48
|
+
}
|
|
49
|
+
static boundFromKey(structure, name) {
|
|
50
|
+
const v = structure[name];
|
|
51
|
+
if (v === undefined || v === null || v === "" || typeof v === "boolean")
|
|
52
|
+
return undefined;
|
|
53
|
+
const n = Number(v);
|
|
54
|
+
return isNaN(n) ? undefined : n;
|
|
55
|
+
}
|
|
56
|
+
static numericSamples(structure, parentPath = "") {
|
|
57
|
+
if (!structure || typeof structure !== "object")
|
|
58
|
+
return [];
|
|
59
|
+
if (Array.isArray(structure))
|
|
60
|
+
return Validator.numericSamples(structure[0], parentPath);
|
|
61
|
+
const found = [];
|
|
62
|
+
for (const key of Object.keys(structure)) {
|
|
63
|
+
if (key.startsWith("$__"))
|
|
64
|
+
continue;
|
|
65
|
+
const value = structure[key];
|
|
66
|
+
if (typeof value === "number" && value !== 0) {
|
|
67
|
+
const o = Validator.parseStructureOptions(key, structure);
|
|
68
|
+
if (o.min === undefined && o.max === undefined)
|
|
69
|
+
found.push(`${parentPath}${key} (${value})`);
|
|
70
|
+
}
|
|
71
|
+
else if (value && typeof value === "object") {
|
|
72
|
+
found.push(...Validator.numericSamples(value, `${parentPath}${key}.`));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
static parseStructureOptions(key, structure) {
|
|
78
|
+
let k = '$__' + key;
|
|
79
|
+
let s_options = structure[k];
|
|
80
|
+
if (!s_options)
|
|
81
|
+
s_options = {};
|
|
82
|
+
if (typeof s_options === "string")
|
|
83
|
+
s_options = { details: s_options };
|
|
84
|
+
k = k + "_";
|
|
85
|
+
if (s_options.min == undefined || isNaN(s_options.min))
|
|
86
|
+
s_options.min = Validator.boundFromKey(structure, k + "min") ?? s_options.min;
|
|
87
|
+
if (s_options.ignore_in_documentation === undefined && structure[k + "ignore_in_documentation"] !== undefined)
|
|
88
|
+
s_options.ignore_in_documentation = structure[k + "ignore_in_documentation"];
|
|
89
|
+
if (s_options.values === undefined && structure[k + "values"] !== undefined)
|
|
90
|
+
s_options.values = structure[k + "values"];
|
|
91
|
+
if (s_options.values === undefined && typeof structure[key] === "string" && structure[key].includes(","))
|
|
92
|
+
s_options.values = structure[key].split(",").map((v) => v.trim()).filter((v) => v.length > 0);
|
|
93
|
+
if (s_options.min !== undefined && isNaN(s_options.min))
|
|
94
|
+
s_options.min = undefined;
|
|
95
|
+
if (s_options.max == undefined || isNaN(s_options.max))
|
|
96
|
+
s_options.max = Validator.boundFromKey(structure, k + "max") ?? s_options.max;
|
|
97
|
+
if (s_options.max !== undefined && isNaN(s_options.max))
|
|
98
|
+
s_options.max = undefined;
|
|
99
|
+
if (s_options && !s_options.type) {
|
|
100
|
+
let type = typeof structure[key];
|
|
101
|
+
if (type === "object" && Array.isArray(structure[key]))
|
|
102
|
+
type = "array";
|
|
103
|
+
if (structure[key] === "@")
|
|
104
|
+
type = "email";
|
|
105
|
+
s_options.type = type;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
...s_options,
|
|
109
|
+
optional: s_options.optional === undefined ? structure[k + 'optional'] ?? false : s_options.optional,
|
|
110
|
+
default: s_options.default === undefined ? structure[k + 'default'] ?? undefined : s_options.default,
|
|
111
|
+
regex: s_options.regex === undefined ? structure[k + 'regex'] ?? undefined : s_options.regex,
|
|
112
|
+
details: s_options.details === undefined ? structure[k + 'details'] ?? undefined : s_options.details,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
static async validateStructure(structure, object, level = 0, parentPath = "") {
|
|
116
|
+
if (!structure)
|
|
117
|
+
return;
|
|
118
|
+
if (!object)
|
|
119
|
+
return ["no data"];
|
|
120
|
+
if (typeof structure !== "object") {
|
|
121
|
+
if (typeof object === "object")
|
|
122
|
+
return ["wrong datatype"];
|
|
123
|
+
if (typeof object !== typeof structure)
|
|
124
|
+
return ["datatype missmatch"];
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (typeof structure === "function") {
|
|
128
|
+
let result = ['can`t validate data'];
|
|
129
|
+
try {
|
|
130
|
+
result = await structure(object);
|
|
131
|
+
}
|
|
132
|
+
catch (e) { }
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
let errors = [];
|
|
136
|
+
let foundKeys = [];
|
|
137
|
+
for (let i in structure) {
|
|
138
|
+
if (i.startsWith("$__")) {
|
|
139
|
+
foundKeys.push(i);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (structure[i] === null) {
|
|
143
|
+
foundKeys.push(i);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (typeof structure[i] === "object" && Array.isArray(structure[i]) && structure[i].length === 0) {
|
|
147
|
+
foundKeys.push(i);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (typeof structure[i] === "object" && Object.keys(structure[i]).length === 0) {
|
|
151
|
+
foundKeys.push(i);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
let structureOptions = Validator.parseStructureOptions(i, structure);
|
|
155
|
+
if (structureOptions.skip_validation) {
|
|
156
|
+
foundKeys.push(i);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if ((object[i] === null || object[i] === undefined || !(i in object)) && structure[i] !== null && structure[i] !== undefined) {
|
|
160
|
+
if (structureOptions.default) {
|
|
161
|
+
object[i] = structureOptions.default;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
if (structureOptions.optional) {
|
|
165
|
+
foundKeys.push(i);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
if (Array.isArray(object) && !isNaN(parseInt(`${i}`))) {
|
|
170
|
+
const p = parentPath.length > 0 ? parentPath.slice(0, -1) : parentPath;
|
|
171
|
+
errors.push("no item for '" + p + "[" + i + "]'");
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
errors.push("no field '" + parentPath + i + "'");
|
|
175
|
+
}
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (structureOptions.optional && typeof object[i] === "object" && object[i] !== null) {
|
|
181
|
+
const isEmpty = Array.isArray(object[i]) ? object[i].length === 0 : Object.keys(object[i]).length === 0;
|
|
182
|
+
if (isEmpty) {
|
|
183
|
+
foundKeys.push(i);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if ((object[i] === null || object[i] === undefined)) {
|
|
188
|
+
if (structure[i] === null || structure[i] === undefined) {
|
|
189
|
+
foundKeys.push(i);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
errors.push("no field '" + parentPath + i + "'");
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (typeof structure[i] === "number" && typeof object[i] === "string") {
|
|
198
|
+
let num = parseInt(object[i]);
|
|
199
|
+
if (object[i].includes("."))
|
|
200
|
+
num = parseFloat(object[i]);
|
|
201
|
+
if (isNaN(num))
|
|
202
|
+
num = structureOptions.default !== undefined ? structureOptions.default : NaN;
|
|
203
|
+
if (isNaN(num))
|
|
204
|
+
errors.push("wrong value for field '" + parentPath + i + "', expected number got " + object[i]);
|
|
205
|
+
else
|
|
206
|
+
object[i] = num;
|
|
207
|
+
}
|
|
208
|
+
if (typeof structure[i] === "boolean") {
|
|
209
|
+
if (typeof object[i] === "number") {
|
|
210
|
+
if (object[i] === 1)
|
|
211
|
+
object[i] = true;
|
|
212
|
+
if (object[i] === 0)
|
|
213
|
+
object[i] = false;
|
|
214
|
+
}
|
|
215
|
+
if (typeof object[i] === "string") {
|
|
216
|
+
if (object[i].trim().toLowerCase() === "true")
|
|
217
|
+
object[i] = true;
|
|
218
|
+
if (object[i].trim().toLowerCase() === "false")
|
|
219
|
+
object[i] = false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (typeof object[i] !== typeof structure[i])
|
|
223
|
+
errors.push("wrong datatype for field '" + i + "' expected " + typeof structure[i] + " got " + typeof object[i]);
|
|
224
|
+
if (typeof structure[i] === "object" || typeof structure[i] === "function") {
|
|
225
|
+
if (typeof object[i] !== "object") {
|
|
226
|
+
errors.push("wrong type for: " + parentPath + i);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
if (Array.isArray(structure[i]) && !Array.isArray(object[i])) {
|
|
230
|
+
errors.push("array expected for " + parentPath + i);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
const result = await this.validateStructure(structure[i], object[i], level++, parentPath + i + ".");
|
|
234
|
+
if (result) {
|
|
235
|
+
for (let j of result)
|
|
236
|
+
errors.push(j);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (typeof structure[i] === "string" && structure[i].includes(",")) {
|
|
242
|
+
const expected = structure[i].split(",").map((v) => v.trim().toLowerCase());
|
|
243
|
+
if (expected.length) {
|
|
244
|
+
const value = object[i].toString().toLowerCase().trim();
|
|
245
|
+
if (value.length === 0)
|
|
246
|
+
errors.push("empty value for field '" + parentPath + i + "'");
|
|
247
|
+
else if (expected.indexOf(value) === -1)
|
|
248
|
+
errors.push("wrong value for field '" + parentPath + i + "', expected " + expected.join(", ") + " got: " + value);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (structure['$__' + i + "_values"])
|
|
252
|
+
structureOptions.values = structure['$__' + i + "_values"];
|
|
253
|
+
if (Array.isArray(structureOptions.values) && structureOptions.values.length) {
|
|
254
|
+
const checkOneValue = (val) => {
|
|
255
|
+
if (structureOptions.values.includes(val))
|
|
256
|
+
return null;
|
|
257
|
+
let caseValue = null;
|
|
258
|
+
for (const av of structureOptions.values) {
|
|
259
|
+
if (av === null || av === undefined)
|
|
260
|
+
continue;
|
|
261
|
+
if ((av + "").toLowerCase().trim() === (val + "").toLowerCase().trim()) {
|
|
262
|
+
caseValue = av;
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
if (typeof av === "object") {
|
|
266
|
+
for (const key of Object.keys(av)) {
|
|
267
|
+
if ((av[key] + "").toLowerCase().trim() === (val + "").toLowerCase().trim()) {
|
|
268
|
+
caseValue = av[key];
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return "wrong value for field '" + parentPath + i + "'" + (caseValue ? ", check case for: " + caseValue : "");
|
|
275
|
+
};
|
|
276
|
+
if (Array.isArray(object[i])) {
|
|
277
|
+
for (const item of object[i]) {
|
|
278
|
+
const err = checkOneValue(item);
|
|
279
|
+
if (err)
|
|
280
|
+
errors.push(err);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const isEmpty = object[i] === "" || object[i] === null || object[i] === undefined;
|
|
285
|
+
if (isEmpty && structureOptions.default !== undefined && structureOptions.values.includes(structureOptions.default)) {
|
|
286
|
+
object[i] = structureOptions.default;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const err = checkOneValue(object[i]);
|
|
290
|
+
if (err)
|
|
291
|
+
errors.push(err);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (typeof structure[i] === "string" && structureOptions.regex) {
|
|
295
|
+
const val = object[i];
|
|
296
|
+
const isEmpty = val === "" || val === null || val === undefined;
|
|
297
|
+
if (!(structureOptions.optional && isEmpty)) {
|
|
298
|
+
const reg = new RegExp(structureOptions.regex);
|
|
299
|
+
if (reg.test(val) === false)
|
|
300
|
+
errors.push("wrong value for field '" + parentPath + i + "', false mask for: >" + val + "<");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (typeof structure[i] === "string" && (structure[i] === "@" || structure[i] === "email")) {
|
|
304
|
+
const value = object[i].toString().toLowerCase().trim();
|
|
305
|
+
if (value.replaceAll(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,6}$/g, "").length !== 0)
|
|
306
|
+
errors.push("wrong value for field '" + parentPath + i + "', expected email got: " + object[i]);
|
|
307
|
+
const domain = value.split("@")[1];
|
|
308
|
+
try {
|
|
309
|
+
await dns_1.default.promises.resolveMx(domain);
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
return ["MX Domain is incorrect"];
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (typeof structure[i] === "number") {
|
|
316
|
+
if (typeof object[i] === "string") {
|
|
317
|
+
if (object[i].indexOf(".") !== -1)
|
|
318
|
+
object[i] = parseFloat(object[i]);
|
|
319
|
+
else
|
|
320
|
+
object[i] = parseInt(object[i]);
|
|
321
|
+
}
|
|
322
|
+
if (isNaN(object[i]))
|
|
323
|
+
errors.push("wrong value for field '" + parentPath + i + "', expected number got " + object[i]);
|
|
324
|
+
}
|
|
325
|
+
if (typeof structure[i] === "number" && structureOptions.min !== undefined && !isNaN(structureOptions.min)) {
|
|
326
|
+
if (object[i] < structureOptions.min)
|
|
327
|
+
errors.push("value for field '" + parentPath + i + "' is too small, expected more than " + structureOptions.min + " got: " + object[i]);
|
|
328
|
+
}
|
|
329
|
+
if (typeof structure[i] === "number" && structureOptions.max !== undefined && !isNaN(structureOptions.max)) {
|
|
330
|
+
if (object[i] > structureOptions.max)
|
|
331
|
+
errors.push("value for field '" + parentPath + i + "' is too big, expected less than " + structureOptions.max + " got: " + object[i]);
|
|
332
|
+
}
|
|
333
|
+
if (typeof structure[i] === "string" && !structureOptions.optional) {
|
|
334
|
+
let min = structureOptions.min || 1;
|
|
335
|
+
if (isNaN(min) || min < 1)
|
|
336
|
+
min = 1;
|
|
337
|
+
if (object[i].toString().trim().length < min)
|
|
338
|
+
errors.push("empty value for field '" + parentPath + i + "'");
|
|
339
|
+
}
|
|
340
|
+
if (typeof object[i] === "string" && structureOptions.min !== undefined && !isNaN(structureOptions.min)) {
|
|
341
|
+
if (object[i].length < structureOptions.min)
|
|
342
|
+
errors.push("value length for field '" + parentPath + i + "' is too small, expected more than " + structureOptions.min + " got: " + object[i].length);
|
|
343
|
+
}
|
|
344
|
+
if (typeof object[i] === "string" && structureOptions.max !== undefined && !isNaN(structureOptions.max)) {
|
|
345
|
+
if (object[i].length > structureOptions.max)
|
|
346
|
+
errors.push("value length for field '" + parentPath + i + "' is too big, expected less than " + structureOptions.max + " got: " + object[i].length);
|
|
347
|
+
}
|
|
348
|
+
foundKeys.push(i);
|
|
349
|
+
}
|
|
350
|
+
if (errors.length > 0)
|
|
351
|
+
return errors;
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
static filterStructure(structure, object) {
|
|
355
|
+
if (!structure || !object)
|
|
356
|
+
return;
|
|
357
|
+
if (typeof structure !== "object" || typeof object !== "object")
|
|
358
|
+
return;
|
|
359
|
+
if (Array.isArray(structure)) {
|
|
360
|
+
if (!Array.isArray(object))
|
|
361
|
+
return;
|
|
362
|
+
if (structure.length < 1)
|
|
363
|
+
return;
|
|
364
|
+
for (let i of object)
|
|
365
|
+
this.filterStructure(structure[0], i);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
for (let key of Object.keys(object)) {
|
|
369
|
+
if (!(key in structure)) {
|
|
370
|
+
delete object[key];
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (key.startsWith("$__"))
|
|
374
|
+
delete object[key];
|
|
375
|
+
if (typeof object[key] === "object")
|
|
376
|
+
this.filterStructure(structure[key], object[key]);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
static isPlainObject(v) {
|
|
380
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
381
|
+
}
|
|
382
|
+
static clone(v) {
|
|
383
|
+
if (typeof structuredClone === "function")
|
|
384
|
+
return structuredClone(v);
|
|
385
|
+
return JSON.parse(JSON.stringify(v));
|
|
386
|
+
}
|
|
387
|
+
static syncStructure(structure, node) {
|
|
388
|
+
if (structure === null || typeof structure !== "object")
|
|
389
|
+
return node;
|
|
390
|
+
if (structure && typeof structure === "object" && Object.keys(structure).length === 0)
|
|
391
|
+
return node;
|
|
392
|
+
if (Array.isArray(structure)) {
|
|
393
|
+
const tmpl = structure[0];
|
|
394
|
+
if (!Array.isArray(node) && this.isPlainObject(node)) {
|
|
395
|
+
const numericKeys = Object.keys(node)
|
|
396
|
+
.filter((k) => String(+k) === k)
|
|
397
|
+
.map((k) => +k)
|
|
398
|
+
.sort((a, b) => a - b);
|
|
399
|
+
const items = numericKeys.length > 0
|
|
400
|
+
? numericKeys.map((i) => node[String(i)])
|
|
401
|
+
: Object.values(node);
|
|
402
|
+
return items.map((it) => this.syncStructure(tmpl, it));
|
|
403
|
+
}
|
|
404
|
+
if (!Array.isArray(node))
|
|
405
|
+
return node;
|
|
406
|
+
if (tmpl === undefined)
|
|
407
|
+
return node;
|
|
408
|
+
const out = new Array(node.length);
|
|
409
|
+
for (let i = 0; i < node.length; i++) {
|
|
410
|
+
const item = node[i];
|
|
411
|
+
if (item === null || item === undefined) {
|
|
412
|
+
out[i] = this.syncStructure(tmpl, this.clone(tmpl));
|
|
413
|
+
}
|
|
414
|
+
else if (this.isPlainObject(tmpl) && this.isPlainObject(item)) {
|
|
415
|
+
out[i] = this.syncStructure(tmpl, item);
|
|
416
|
+
}
|
|
417
|
+
else if (Array.isArray(tmpl) && Array.isArray(item)) {
|
|
418
|
+
out[i] = this.syncStructure(tmpl, item);
|
|
419
|
+
}
|
|
420
|
+
else if (!this.isPlainObject(tmpl) && !Array.isArray(tmpl)) {
|
|
421
|
+
const wantType = typeof tmpl;
|
|
422
|
+
if (typeof item === wantType) {
|
|
423
|
+
out[i] = item;
|
|
424
|
+
}
|
|
425
|
+
else if (wantType === "string" || wantType === "number" || wantType === "boolean") {
|
|
426
|
+
const converted = this.convertToType(item, wantType);
|
|
427
|
+
const bad = converted === null || (wantType === "number" && Number.isNaN(converted));
|
|
428
|
+
out[i] = bad ? this.clone(tmpl) : converted;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
out[i] = item;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
out[i] = this.syncStructure(tmpl, this.clone(tmpl));
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return out;
|
|
439
|
+
}
|
|
440
|
+
const out = {};
|
|
441
|
+
const src = this.isPlainObject(node) ? node : {};
|
|
442
|
+
for (const k of Object.keys(structure)) {
|
|
443
|
+
const sv = structure[k];
|
|
444
|
+
if (k.startsWith("$__")) {
|
|
445
|
+
out[k] = this.clone(sv);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
const has = Object.prototype.hasOwnProperty.call(src, k);
|
|
449
|
+
const ov = has ? src[k] : undefined;
|
|
450
|
+
const { optional, skip_validation, default: def } = this.parseStructureOptions(k, structure);
|
|
451
|
+
if (!has) {
|
|
452
|
+
if (sv && typeof sv === "object") {
|
|
453
|
+
out[k] = this.syncStructure(sv, this.clone(sv));
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
out[k] = this.clone(sv);
|
|
457
|
+
}
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (ov === null || ov === undefined) {
|
|
461
|
+
if (def !== undefined && !optional) {
|
|
462
|
+
out[k] = this.clone(def);
|
|
463
|
+
}
|
|
464
|
+
else if (!optional || skip_validation) {
|
|
465
|
+
out[k] = sv && typeof sv === "object"
|
|
466
|
+
? this.syncStructure(sv, this.clone(sv))
|
|
467
|
+
: this.clone(sv);
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
out[k] = ov;
|
|
471
|
+
}
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (sv && typeof sv === "object") {
|
|
475
|
+
out[k] = this.syncStructure(sv, ov);
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
out[k] = ov;
|
|
479
|
+
}
|
|
480
|
+
return out;
|
|
481
|
+
}
|
|
482
|
+
static convertToType(value, type) {
|
|
483
|
+
if (value === null || value === undefined)
|
|
484
|
+
return null;
|
|
485
|
+
if (type === "string") {
|
|
486
|
+
if (typeof value === "object") {
|
|
487
|
+
let result = null;
|
|
488
|
+
try {
|
|
489
|
+
result = JSON.stringify(value);
|
|
490
|
+
}
|
|
491
|
+
catch (e) { }
|
|
492
|
+
if (result !== null)
|
|
493
|
+
return result;
|
|
494
|
+
}
|
|
495
|
+
return value + "";
|
|
496
|
+
}
|
|
497
|
+
if (type === "boolean") {
|
|
498
|
+
if (typeof value === "boolean")
|
|
499
|
+
return value;
|
|
500
|
+
if (typeof value === "number")
|
|
501
|
+
return value > 0;
|
|
502
|
+
if (typeof value === "object")
|
|
503
|
+
return false;
|
|
504
|
+
if (typeof value === "string")
|
|
505
|
+
return (value.toLowerCase() === "true");
|
|
506
|
+
}
|
|
507
|
+
if (type === "date") {
|
|
508
|
+
if (typeof value === "string" || typeof value === "number")
|
|
509
|
+
return new Date(value);
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
if (typeof value === "number")
|
|
513
|
+
return value;
|
|
514
|
+
if (typeof value === "object")
|
|
515
|
+
return 0;
|
|
516
|
+
const num = parseInt(value + "");
|
|
517
|
+
return num;
|
|
518
|
+
}
|
|
519
|
+
static validateValue(value, opt) {
|
|
520
|
+
if (value === undefined || value === null)
|
|
521
|
+
return ValidationReport.VALUE_IS_NULL;
|
|
522
|
+
if (!opt)
|
|
523
|
+
return ValidationReport.OK;
|
|
524
|
+
if (!opt.type)
|
|
525
|
+
opt.type = "string";
|
|
526
|
+
if (opt.type === "boolean") {
|
|
527
|
+
if (typeof value === "boolean")
|
|
528
|
+
return ValidationReport.OK;
|
|
529
|
+
if (typeof value === "number" && (value === 1 || value === 0))
|
|
530
|
+
return ValidationReport.OK;
|
|
531
|
+
return ValidationReport.TYPE_MISSMATCH;
|
|
532
|
+
}
|
|
533
|
+
if (opt.type === "number") {
|
|
534
|
+
if (typeof value !== "number")
|
|
535
|
+
return ValidationReport.TYPE_MISSMATCH;
|
|
536
|
+
if (opt.max !== undefined && value > opt.max)
|
|
537
|
+
return ValidationReport.VALUE_TOO_BIG;
|
|
538
|
+
if (opt.min !== undefined && value < opt.min)
|
|
539
|
+
return ValidationReport.VALUE_TOO_SHORT;
|
|
540
|
+
return ValidationReport.OK;
|
|
541
|
+
}
|
|
542
|
+
if (typeof value !== "string")
|
|
543
|
+
return ValidationReport.TYPE_MISSMATCH;
|
|
544
|
+
if (opt.max !== undefined && value.length > opt.max)
|
|
545
|
+
return ValidationReport.VALUE_TOO_BIG;
|
|
546
|
+
if (opt.min !== undefined && value.length < opt.min)
|
|
547
|
+
return ValidationReport.VALUE_TOO_SHORT;
|
|
548
|
+
if (opt.type === "email" && !opt.regex) {
|
|
549
|
+
opt.regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,6}$/g;
|
|
550
|
+
}
|
|
551
|
+
if (opt.regex) {
|
|
552
|
+
const globalRegex = new RegExp(opt.regex.source, opt.regex.flags.includes('g') ? opt.regex.flags : opt.regex.flags + 'g');
|
|
553
|
+
const tmp = value.replaceAll(globalRegex, "");
|
|
554
|
+
if (tmp.length !== 0)
|
|
555
|
+
return ValidationReport.VALUE_INCORRECT;
|
|
556
|
+
}
|
|
557
|
+
return ValidationReport.OK;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
exports.Validator = Validator;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.YYYYMMDDHH = YYYYMMDDHH;
|
|
4
|
+
exports.YYYYMMDDHH_toDate = YYYYMMDDHH_toDate;
|
|
5
|
+
function YYYYMMDDHH(date, format = "yyyymmddhh") {
|
|
6
|
+
const year = date.getFullYear();
|
|
7
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
8
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
9
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
10
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
11
|
+
switch (format) {
|
|
12
|
+
case "yyyymmddhh":
|
|
13
|
+
return `${year}${month}${day}${hours}`;
|
|
14
|
+
case "yyyymmdd":
|
|
15
|
+
return `${year}${month}${day}`;
|
|
16
|
+
case "yyyymm":
|
|
17
|
+
return `${year}${month}`;
|
|
18
|
+
case "yyyymmddhhmm":
|
|
19
|
+
return `${year}${month}${day}${hours}${minutes}`;
|
|
20
|
+
default:
|
|
21
|
+
return `${year}${month}${day}${hours}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function YYYYMMDDHH_toDate(yyyymmddhh) {
|
|
25
|
+
const str = String(yyyymmddhh);
|
|
26
|
+
const year = parseInt(str.slice(0, 4), 10);
|
|
27
|
+
const month = parseInt(str.slice(4, 6), 10) - 1;
|
|
28
|
+
const day = parseInt(str.slice(6, 8), 10);
|
|
29
|
+
const hours = parseInt(str.slice(8, 10), 10);
|
|
30
|
+
return new Date(year, month, day, hours);
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ZipUtils = void 0;
|
|
7
|
+
const zlib_1 = __importDefault(require("zlib"));
|
|
8
|
+
class ZipUtils {
|
|
9
|
+
static zipBufferToBase64 = (input) => {
|
|
10
|
+
const compressed = zlib_1.default.gzipSync(input);
|
|
11
|
+
return compressed.toString("base64");
|
|
12
|
+
};
|
|
13
|
+
static unzipBase64ToBuffer = (base64) => {
|
|
14
|
+
const compressed = Buffer.from(base64, "base64");
|
|
15
|
+
return zlib_1.default.gunzipSync(compressed);
|
|
16
|
+
};
|
|
17
|
+
static zipStringToBase64 = (input) => {
|
|
18
|
+
const buffer = Buffer.from(input, "utf-8");
|
|
19
|
+
const compressed = zlib_1.default.gzipSync(buffer);
|
|
20
|
+
return compressed.toString("base64");
|
|
21
|
+
};
|
|
22
|
+
static unzipBase64ToString = (base64) => {
|
|
23
|
+
const compressed = Buffer.from(base64, "base64");
|
|
24
|
+
const uncompressed = zlib_1.default.gunzipSync(compressed);
|
|
25
|
+
return uncompressed.toString("utf-8");
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.ZipUtils = ZipUtils;
|