@bmfk/api 0.0.0-stage → 1.0.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/CHANGELOG.md +90 -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,18 @@
|
|
|
1
|
+
import { APIServiceOptions } from "../APIService";
|
|
2
|
+
import { BaseEndpoint } from "../BaseEndpoint";
|
|
3
|
+
import { IRequest, IResponse } from "../structures/Interfaces";
|
|
4
|
+
export declare class Documentation extends BaseEndpoint {
|
|
5
|
+
indexHtmlFile: string | null;
|
|
6
|
+
apiServiceOptions: APIServiceOptions;
|
|
7
|
+
constructor(options: APIServiceOptions);
|
|
8
|
+
private static users;
|
|
9
|
+
private session;
|
|
10
|
+
login(req: IRequest): Promise<IResponse>;
|
|
11
|
+
enroll2fa(req: IRequest): Promise<IResponse>;
|
|
12
|
+
logout(req: IRequest): Promise<IResponse>;
|
|
13
|
+
private requireUser;
|
|
14
|
+
json(req: IRequest): Promise<{
|
|
15
|
+
data: Record<string, any>[];
|
|
16
|
+
}>;
|
|
17
|
+
html(req: IRequest): Promise<IResponse<any>>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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.Documentation = void 0;
|
|
7
|
+
const LogService_1 = require("../LogService");
|
|
8
|
+
const APIService_1 = require("../APIService");
|
|
9
|
+
const BaseEndpoint_1 = require("../BaseEndpoint");
|
|
10
|
+
const DocumentService_1 = require("../DocumentService");
|
|
11
|
+
const DefaultErrors_1 = __importDefault(require("../structures/DefaultErrors"));
|
|
12
|
+
const MonitorAuth_1 = require("../monitor/MonitorAuth");
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const REALM = "doc:";
|
|
16
|
+
class Documentation extends BaseEndpoint_1.BaseEndpoint {
|
|
17
|
+
indexHtmlFile = null;
|
|
18
|
+
apiServiceOptions;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
super("doc");
|
|
21
|
+
this.apiServiceOptions = options;
|
|
22
|
+
this.ignoreInDocumentation = true;
|
|
23
|
+
this.ignoreHttpLogging = true;
|
|
24
|
+
this.registerEndpoints([
|
|
25
|
+
{ ignoreInDocumentation: true, endpoint: "html", handler: this.html, ignoreInterceptor: true },
|
|
26
|
+
{ ignoreInDocumentation: true, endpoint: "json", handler: this.json, ignoreInterceptor: true },
|
|
27
|
+
{ ignoreInDocumentation: true, endpoint: "login", handler: this.login, ignoreInterceptor: true,
|
|
28
|
+
validationModel: { login: "", password: "", totp: "", $__totp_optional: true } },
|
|
29
|
+
{ ignoreInDocumentation: true, endpoint: "enroll2fa", handler: this.enroll2fa, ignoreInterceptor: true,
|
|
30
|
+
validationModel: { enrollmentToken: "", totp: "" } },
|
|
31
|
+
{ ignoreInDocumentation: true, endpoint: "logout", handler: this.logout, ignoreInterceptor: true },
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
static users(list) {
|
|
35
|
+
return (list ?? []).map(u => ({ ...u, login: REALM + u.login }));
|
|
36
|
+
}
|
|
37
|
+
session(login) {
|
|
38
|
+
const s = MonitorAuth_1.MonitorAuth.createSession(REALM + login);
|
|
39
|
+
return { token: s.token, login, idleTimeoutMs: MonitorAuth_1.MonitorAuth.SESSION_IDLE_MS, maxLifetimeMs: MonitorAuth_1.MonitorAuth.SESSION_MAX_MS, twoFactor: true };
|
|
40
|
+
}
|
|
41
|
+
async login(req) {
|
|
42
|
+
const users = await APIService_1.REQ_DOC_USERS.request();
|
|
43
|
+
if (!users || users.length === 0) {
|
|
44
|
+
(0, LogService_1.logWarn)("Documentation: sign-in refused — no documentation users are configured (access.documentation)");
|
|
45
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED };
|
|
46
|
+
}
|
|
47
|
+
const login = String(req.data.login);
|
|
48
|
+
const { user, error, enrollmentRequired } = await MonitorAuth_1.MonitorAuth.authenticate(Documentation.users(users), REALM + login, req.data.password, req.data.totp);
|
|
49
|
+
if (!user || error) {
|
|
50
|
+
(0, LogService_1.logWarn)(`Documentation login failed for "${login}" from ${req.ip ?? "unknown"}: ${error}`);
|
|
51
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: error ?? "Invalid user" };
|
|
52
|
+
}
|
|
53
|
+
if (enrollmentRequired) {
|
|
54
|
+
const issuer = (this.apiServiceOptions.projectName || "API") + " documentation";
|
|
55
|
+
const { token, secret, uri } = MonitorAuth_1.MonitorAuth.beginEnrollment(REALM + login, issuer, login);
|
|
56
|
+
(0, LogService_1.logInfo)(`Documentation 2FA enrollment started for "${login}"`);
|
|
57
|
+
return { data: { enrollmentRequired: true, enrollmentToken: token, secret, otpauthUri: uri, expiresInMs: MonitorAuth_1.MonitorAuth.ENROLLMENT_TTL_MS } };
|
|
58
|
+
}
|
|
59
|
+
(0, LogService_1.logInfo)(`Documentation login: "${login}" from ${req.ip ?? "unknown"}`);
|
|
60
|
+
return { data: this.session(login) };
|
|
61
|
+
}
|
|
62
|
+
async enroll2fa(req) {
|
|
63
|
+
const { login, error } = MonitorAuth_1.MonitorAuth.completeEnrollment(req.data.enrollmentToken, req.data.totp);
|
|
64
|
+
if (!login || error || !login.startsWith(REALM)) {
|
|
65
|
+
(0, LogService_1.logWarn)(`Documentation 2FA enrollment failed: ${error ?? "not a documentation enrollment"}`);
|
|
66
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: error ?? "Enrollment failed" };
|
|
67
|
+
}
|
|
68
|
+
return { data: this.session(login.slice(REALM.length)) };
|
|
69
|
+
}
|
|
70
|
+
async logout(req) {
|
|
71
|
+
const token = (req.headers['authorization'] ?? "").split(" ").pop() ?? "";
|
|
72
|
+
const s = MonitorAuth_1.MonitorAuth.touchSession(token);
|
|
73
|
+
if (s?.login.startsWith(REALM))
|
|
74
|
+
MonitorAuth_1.MonitorAuth.revokeSession(token);
|
|
75
|
+
return { data: { ok: true } };
|
|
76
|
+
}
|
|
77
|
+
async requireUser(req) {
|
|
78
|
+
const token = (req.headers['authorization'] ?? "").split(" ").pop() ?? "";
|
|
79
|
+
const s = token ? MonitorAuth_1.MonitorAuth.touchSession(token) : null;
|
|
80
|
+
if (!s || !s.login.startsWith(REALM))
|
|
81
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Sign in again" };
|
|
82
|
+
const login = s.login.slice(REALM.length);
|
|
83
|
+
const user = (await APIService_1.REQ_DOC_USERS.request())?.find(u => u?.login === login);
|
|
84
|
+
if (!user) {
|
|
85
|
+
MonitorAuth_1.MonitorAuth.revokeAllFor(s.login);
|
|
86
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "User no longer has documentation access" };
|
|
87
|
+
}
|
|
88
|
+
return user;
|
|
89
|
+
}
|
|
90
|
+
async json(req) {
|
|
91
|
+
const endpoints = (await this.requireUser(req)).endpoints;
|
|
92
|
+
let doc = JSON.parse(JSON.stringify(await DocumentService_1.REQ_DOC.request()));
|
|
93
|
+
if (endpoints && endpoints.length > 0) {
|
|
94
|
+
doc = doc.filter((group) => {
|
|
95
|
+
if (group.endpoints && Array.isArray(group.endpoints)) {
|
|
96
|
+
group.endpoints = group.endpoints.filter((ep) => {
|
|
97
|
+
const name = ep.name;
|
|
98
|
+
return endpoints.some((pattern) => {
|
|
99
|
+
if (pattern.endsWith('/*')) {
|
|
100
|
+
const base = pattern.slice(0, -2);
|
|
101
|
+
return name === base || name.startsWith(base + '/');
|
|
102
|
+
}
|
|
103
|
+
return name === pattern;
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return group.endpoints && group.endpoints.length > 0;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return { data: doc };
|
|
111
|
+
}
|
|
112
|
+
async html(req) {
|
|
113
|
+
if (!this.indexHtmlFile) {
|
|
114
|
+
this.indexHtmlFile = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "index.html")).toString("utf-8");
|
|
115
|
+
let bend = this.apiServiceOptions.baseEndPoint;
|
|
116
|
+
if (!bend.endsWith("/"))
|
|
117
|
+
bend += "/";
|
|
118
|
+
let end = this.endpoint;
|
|
119
|
+
if (!end.endsWith("/"))
|
|
120
|
+
end += "/";
|
|
121
|
+
if (end.startsWith("/"))
|
|
122
|
+
end = end.substring(1);
|
|
123
|
+
const endpoint = bend + end + "json";
|
|
124
|
+
this.indexHtmlFile = this.indexHtmlFile.replace(/{{host}}/g, endpoint);
|
|
125
|
+
let projectName = this.apiServiceOptions.projectName;
|
|
126
|
+
if (!projectName)
|
|
127
|
+
projectName = "API Server";
|
|
128
|
+
projectName += " - Documentation";
|
|
129
|
+
if (this.apiServiceOptions.appVersion)
|
|
130
|
+
projectName += " (v.:" + this.apiServiceOptions.appVersion + ")";
|
|
131
|
+
this.indexHtmlFile = this.indexHtmlFile.replace(/{{title}}/g, projectName);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
rawResponse: true,
|
|
135
|
+
data: this.indexHtmlFile,
|
|
136
|
+
headers: {
|
|
137
|
+
"Content-Type": "text/html",
|
|
138
|
+
"Content-Length": Buffer.byteLength(this.indexHtmlFile).toString()
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.Documentation = Documentation;
|