badmfck-api-server 5.0.16 → 6.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.
Files changed (33) hide show
  1. package/README.md +824 -0
  2. package/dist/apiServer/APIService.d.ts +16 -4
  3. package/dist/apiServer/APIService.js +92 -3
  4. package/dist/apiServer/DBService.js +1 -2
  5. package/dist/apiServer/WebSocketServer.d.ts +39 -0
  6. package/dist/apiServer/WebSocketServer.js +173 -0
  7. package/dist/apiServer/db/MysqlAdapter.d.ts +4 -0
  8. package/dist/apiServer/db/MysqlAdapter.js +93 -84
  9. package/dist/apiServer/db/PostgresAdapter.d.ts +10 -3
  10. package/dist/apiServer/deployment/NginxHelper.d.ts +1 -1
  11. package/dist/apiServer/deployment/NginxHelper.js +3 -0
  12. package/dist/apiServer/monitor/AccessStore.d.ts +24 -0
  13. package/dist/apiServer/monitor/AccessStore.js +146 -0
  14. package/dist/apiServer/monitor/Monitor.js +5 -4
  15. package/dist/apiServer/monitor/MonitorAuth.d.ts +11 -1
  16. package/dist/apiServer/monitor/MonitorAuth.js +157 -31
  17. package/dist/apiServer/monitor/index.html +3 -3
  18. package/dist/index.d.ts +12 -2
  19. package/dist/index.js +27 -3
  20. package/monitoring.help.md +1 -1
  21. package/package.json +2 -2
  22. package/dist/apiServer/MysqlService.d.ts +0 -123
  23. package/dist/apiServer/MysqlService.js +0 -817
  24. package/dist/apiServer/WSAPITransport.d.ts +0 -0
  25. package/dist/apiServer/WSAPITransport.js +0 -1
  26. package/dist/apiServer/WebSocketHandler.d.ts +0 -0
  27. package/dist/apiServer/WebSocketHandler.js +0 -1
  28. package/dist/apiServer/WebsocketServerService.d.ts +0 -9
  29. package/dist/apiServer/WebsocketServerService.js +0 -18
  30. package/dist/apiServer/deployment/Deployment.d.ts +0 -10
  31. package/dist/apiServer/deployment/Deployment.js +0 -24
  32. package/dist/apiServer/interceptors/IntHmacSha256.d.ts +0 -5
  33. package/dist/apiServer/interceptors/IntHmacSha256.js +0 -22
@@ -43,62 +43,182 @@ class MonitorAuth {
43
43
  else
44
44
  MonitorAuth.authFile = null;
45
45
  MonitorAuth.projectKey = (project && project.length > 0 ? project : "default");
46
+ MonitorAuth.stopWatchingStore();
46
47
  MonitorAuth.enrolled.clear();
48
+ MonitorAuth.storeHash = "";
49
+ MonitorAuth.refusedHash = "";
50
+ MonitorAuth.missingSince = 0;
47
51
  MonitorAuth.storeLoaded = false;
48
52
  MonitorAuth.loadStore();
49
53
  if (!MonitorAuth.authFile)
50
54
  (0, LogService_1.logWarn)("Monitor 2FA: neither monitorAuthFile nor monitorAuthDir is set — enrollments live in memory only and are LOST on restart");
51
55
  }
56
+ static storeHash = "";
57
+ static refusedHash = "";
58
+ static storeWatcher = null;
59
+ static storePoll = null;
60
+ static storeDebounce = null;
61
+ static missingSince = 0;
62
+ static sectionOf(doc) {
63
+ const section = doc?.projects?.[MonitorAuth.projectKey]?.users ?? doc?.users ?? {};
64
+ const out = new Map();
65
+ for (const [login, rec] of Object.entries(section ?? {})) {
66
+ const r = rec;
67
+ if (r && typeof r.secret === "string" && r.secret.length > 0)
68
+ out.set(login, { secret: r.secret, enrolledAt: Number(r.enrolledAt) || 0, lastCounter: Number(r.lastCounter) || 0 });
69
+ }
70
+ return out;
71
+ }
52
72
  static loadStore() {
53
73
  if (MonitorAuth.storeLoaded)
54
74
  return;
55
75
  MonitorAuth.storeLoaded = true;
56
76
  if (!MonitorAuth.authFile)
57
77
  return;
78
+ MonitorAuth.reloadStore(true);
79
+ MonitorAuth.watchStore();
80
+ }
81
+ static reloadStore(initial = false) {
82
+ const file = MonitorAuth.authFile;
83
+ if (!file)
84
+ return;
85
+ let raw = null;
58
86
  try {
59
- if (!fs_1.default.existsSync(MonitorAuth.authFile))
87
+ raw = fs_1.default.readFileSync(file, "utf-8");
88
+ }
89
+ catch (e) {
90
+ if (e?.code !== "ENOENT") {
91
+ (0, LogService_1.logWarn)(`Monitor 2FA: cannot read ${file} (${e?.message ?? e}) — keeping current enrollments`);
60
92
  return;
61
- const raw = JSON.parse(fs_1.default.readFileSync(MonitorAuth.authFile, "utf-8"));
62
- const section = raw?.projects?.[MonitorAuth.projectKey]?.users ?? raw?.users ?? {};
63
- for (const [login, rec] of Object.entries(section)) {
64
- const r = rec;
65
- if (r && typeof r.secret === "string" && r.secret.length > 0)
66
- MonitorAuth.enrolled.set(login, {
67
- secret: r.secret,
68
- enrolledAt: Number(r.enrolledAt) || 0,
69
- lastCounter: Number(r.lastCounter) || 0,
70
- });
71
93
  }
72
- (0, LogService_1.logInfo)(`Monitor 2FA: loaded ${MonitorAuth.enrolled.size} enrollment(s) for project "${MonitorAuth.projectKey}" from ${MonitorAuth.authFile}`, "MonitorAuth");
73
94
  }
74
- catch (e) {
75
- (0, LogService_1.logWarn)("Monitor 2FA: cannot read store, treating as empty: " + (e?.message ?? e));
95
+ let next;
96
+ let hash;
97
+ if (raw === null) {
98
+ if (!initial && MonitorAuth.storeHash !== "missing") {
99
+ if (!MonitorAuth.missingSince) {
100
+ MonitorAuth.missingSince = Date.now();
101
+ setTimeout(() => MonitorAuth.reloadStore(), 1000).unref();
102
+ return;
103
+ }
104
+ if (Date.now() - MonitorAuth.missingSince < 900)
105
+ return;
106
+ }
107
+ next = new Map();
108
+ hash = "missing";
109
+ }
110
+ else {
111
+ MonitorAuth.missingSince = 0;
112
+ hash = crypto_1.default.createHash("sha256").update(raw).digest("hex");
113
+ if (hash === MonitorAuth.storeHash || hash === MonitorAuth.refusedHash)
114
+ return;
115
+ try {
116
+ next = MonitorAuth.sectionOf(JSON.parse(raw));
117
+ }
118
+ catch (e) {
119
+ MonitorAuth.refusedHash = hash;
120
+ (0, LogService_1.logError)(`Monitor 2FA: ${file} is not valid JSON (${e?.message ?? e}) — change ignored, keeping current enrollments`);
121
+ return;
122
+ }
123
+ }
124
+ MonitorAuth.missingSince = 0;
125
+ if (hash === MonitorAuth.storeHash)
126
+ return;
127
+ MonitorAuth.storeHash = hash;
128
+ MonitorAuth.refusedHash = "";
129
+ for (const [login, rec] of MonitorAuth.enrolled) {
130
+ const now = next.get(login);
131
+ if (now && now.secret === rec.secret)
132
+ continue;
133
+ MonitorAuth.revokeAllFor(login);
134
+ MonitorAuth.usedTotpCounter.delete(login);
135
+ (0, LogService_1.logWarn)(`Monitor 2FA: enrollment of "${login}" ${now ? "changed" : "removed"} — sessions revoked${now ? "" : ", the next login enrolls again"}`, "MonitorAuth");
76
136
  }
137
+ MonitorAuth.enrolled = next;
138
+ if (raw !== null) {
139
+ try {
140
+ const mode = fs_1.default.statSync(file).mode;
141
+ if (mode & 0o077)
142
+ (0, LogService_1.logWarn)(`Monitor 2FA: ${file} is readable by other users (mode ${(mode & 0o777).toString(8)}) — chmod 600 it`);
143
+ }
144
+ catch { }
145
+ }
146
+ if (initial)
147
+ (0, LogService_1.logInfo)(`Monitor 2FA: loaded ${next.size} enrollment(s) for project "${MonitorAuth.projectKey}" from ${file}`, "MonitorAuth");
148
+ else
149
+ (0, LogService_1.logInfo)(`Monitor 2FA: reloaded ${file} — ${next.size} enrollment(s)`, "MonitorAuth");
77
150
  }
78
- static saveStore() {
79
- if (!MonitorAuth.authFile)
151
+ static watchStore() {
152
+ const file = MonitorAuth.authFile;
153
+ if (!file)
80
154
  return;
155
+ MonitorAuth.stopWatchingStore();
156
+ const dir = path_1.default.dirname(file), name = path_1.default.basename(file);
157
+ try {
158
+ fs_1.default.mkdirSync(dir, { recursive: true });
159
+ MonitorAuth.storeWatcher = fs_1.default.watch(dir, (_event, filename) => {
160
+ if (filename && filename !== name)
161
+ return;
162
+ if (MonitorAuth.storeDebounce)
163
+ clearTimeout(MonitorAuth.storeDebounce);
164
+ MonitorAuth.storeDebounce = setTimeout(() => { MonitorAuth.storeDebounce = null; MonitorAuth.reloadStore(); }, 200);
165
+ });
166
+ MonitorAuth.storeWatcher.unref();
167
+ }
168
+ catch (e) {
169
+ (0, LogService_1.logWarn)(`Monitor 2FA: cannot watch ${dir} (${e?.message ?? e}) — changes are picked up within a minute`);
170
+ }
171
+ MonitorAuth.storePoll = setInterval(() => MonitorAuth.reloadStore(), 60_000);
172
+ MonitorAuth.storePoll.unref();
173
+ }
174
+ static stopWatchingStore() {
175
+ MonitorAuth.storeWatcher?.close();
176
+ MonitorAuth.storeWatcher = null;
177
+ if (MonitorAuth.storePoll)
178
+ clearInterval(MonitorAuth.storePoll);
179
+ MonitorAuth.storePoll = null;
180
+ }
181
+ static saveEnrollment(login, rec) {
182
+ const file = MonitorAuth.authFile;
183
+ if (!file)
184
+ return true;
81
185
  try {
82
- const users = {};
83
- for (const [login, rec] of MonitorAuth.enrolled)
84
- users[login] = rec;
85
186
  let doc = { version: 1, projects: {} };
86
187
  try {
87
- if (fs_1.default.existsSync(MonitorAuth.authFile)) {
88
- const existing = JSON.parse(fs_1.default.readFileSync(MonitorAuth.authFile, "utf-8"));
89
- if (existing && typeof existing === "object")
90
- doc = { version: 1, projects: existing.projects ?? {} };
188
+ const existing = JSON.parse(fs_1.default.readFileSync(file, "utf-8"));
189
+ if (existing && typeof existing === "object")
190
+ doc = { version: 1, projects: existing.projects ?? {} };
191
+ if (existing?.users && !existing.projects?.[MonitorAuth.projectKey])
192
+ doc.projects[MonitorAuth.projectKey] = { users: existing.users };
193
+ }
194
+ catch (e) {
195
+ if (e?.code !== "ENOENT") {
196
+ (0, LogService_1.logError)(`Monitor 2FA: cannot update ${file} (${e?.message ?? e}) — enrollment not saved`);
197
+ return false;
91
198
  }
92
199
  }
93
- catch { }
94
- doc.projects[MonitorAuth.projectKey] = { users };
95
- const tmp = MonitorAuth.authFile + ".tmp";
96
- fs_1.default.mkdirSync(path_1.default.dirname(MonitorAuth.authFile), { recursive: true });
97
- fs_1.default.writeFileSync(tmp, JSON.stringify(doc, null, 2), { encoding: "utf-8", mode: 0o600 });
98
- fs_1.default.renameSync(tmp, MonitorAuth.authFile);
200
+ const section = doc.projects[MonitorAuth.projectKey] ?? { users: {} };
201
+ section.users = { ...(section.users ?? {}), [login]: rec };
202
+ doc.projects[MonitorAuth.projectKey] = section;
203
+ const text = JSON.stringify(doc, null, 2);
204
+ const tmp = file + ".tmp";
205
+ fs_1.default.mkdirSync(path_1.default.dirname(file), { recursive: true });
206
+ fs_1.default.writeFileSync(tmp, text, { encoding: "utf-8", mode: 0o600 });
207
+ fs_1.default.renameSync(tmp, file);
208
+ const prev = MonitorAuth.enrolled;
209
+ MonitorAuth.enrolled = MonitorAuth.sectionOf(doc);
210
+ for (const [l, r] of prev)
211
+ if (!MonitorAuth.enrolled.has(l) || MonitorAuth.enrolled.get(l).secret !== r.secret) {
212
+ MonitorAuth.revokeAllFor(l);
213
+ (0, LogService_1.logWarn)(`Monitor 2FA: enrollment of "${l}" was removed on disk — sessions revoked`, "MonitorAuth");
214
+ }
215
+ MonitorAuth.storeHash = crypto_1.default.createHash("sha256").update(text).digest("hex");
216
+ MonitorAuth.missingSince = 0;
217
+ return true;
99
218
  }
100
219
  catch (e) {
101
220
  (0, LogService_1.logWarn)("Monitor 2FA: cannot persist store: " + (e?.message ?? e));
221
+ return false;
102
222
  }
103
223
  }
104
224
  static secretFor(user) {
@@ -300,9 +420,15 @@ class MonitorAuth {
300
420
  const err = MonitorAuth.verifyTotp(pending.login, pending.secret, code);
301
421
  if (err)
302
422
  return { error: err };
303
- MonitorAuth.enrolled.set(pending.login, { secret: pending.secret, enrolledAt: Date.now(), lastCounter: 0 });
423
+ const rec = { secret: pending.secret, enrolledAt: Date.now(), lastCounter: 0 };
304
424
  MonitorAuth.pendingEnrollments.delete(token);
305
- MonitorAuth.saveStore();
425
+ if (MonitorAuth.authFile) {
426
+ if (!MonitorAuth.saveEnrollment(pending.login, rec))
427
+ return { error: "cannot save the enrollment on the server, try again later" };
428
+ }
429
+ else {
430
+ MonitorAuth.enrolled.set(pending.login, rec);
431
+ }
306
432
  (0, LogService_1.logInfo)(`Monitor 2FA enrolled for "${pending.login}"`, "MonitorAuth");
307
433
  return { login: pending.login };
308
434
  }
@@ -1,8 +1,8 @@
1
1
  <!doctype html>
2
2
  <html lang="en">
3
3
  <head>
4
- <!-- Build: 2026-10-28T15:37:14.586Z | Version: 1.0.26 -->
5
- <script>var __ver = "1.0.26";</script>
4
+ <!-- Build: 2026-11-03T16:43:22.836Z | Version: 1.0.27 -->
5
+ <script>var __ver = "1.0.27";</script>
6
6
  <meta charset="UTF-8" />
7
7
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
8
8
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
@@ -528,4 +528,4 @@ const z2={background:"#a7a7a7",backgroundSelected:"#66bb6a",toggle:"#FFFFFF"},U2
528
528
  <body>
529
529
  <div id="root"></div>
530
530
  </body>
531
- </html>
531
+ </html>
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { APIService, Initializer } from "./apiServer/APIService";
2
2
  import { LocalRequest } from "./apiServer/LocalRequest";
3
- import { MysqlService } from "./apiServer/MysqlService";
4
3
  import { Validator, ValidationModel } from "./apiServer/helper/Validator";
5
4
  import { LogService } from "./apiServer/LogService";
6
5
  import { ErrorUtils } from "./apiServer/structures/DefaultErrors";
@@ -20,6 +19,17 @@ import { MicroserviceClient } from "./apiServer/external/MicroserviceClient";
20
19
  import { Deploy } from "./apiServer/deployment/Deploy";
21
20
  import { Activate } from "./apiServer/deployment/Activate";
22
21
  import { InterceptorPayAuth } from "./apiServer/interceptors/InterceptorPayAuth";
23
- export { MicroserviceHost, MicroserviceClient, Http, ZipUtils, UID, YYYYMMDDHH, JSONStableStringify, APIService, Initializer, LocalRequest, ValidationModel, MysqlService, TimeframeService, Validator, LogService, DataProvider, ErrorUtils, ExternalService, DBService, Deploy, Activate, InterceptorPayAuth, S_MONITOR_REGISTRATE_ACTION, S_MONITOR_RESTART_REQUESTED, ProcessMonitor };
22
+ export { MicroserviceHost, MicroserviceClient, Http, ZipUtils, UID, YYYYMMDDHH, JSONStableStringify, APIService, Initializer, LocalRequest, ValidationModel, TimeframeService, Validator, LogService, DataProvider, ErrorUtils, ExternalService, DBService, Deploy, Activate, InterceptorPayAuth, S_MONITOR_REGISTRATE_ACTION, S_MONITOR_RESTART_REQUESTED, ProcessMonitor };
24
23
  export type { IBlueGreenState, IBlueGreenStateOptions } from "./apiServer/deployment/BlueGreenState";
25
24
  export { S_BLUEGREEN_STATE_CHANGED } from "./apiServer/deployment/BlueGreenState";
25
+ export { REQ_WS_SERVER } from "./apiServer/APIService";
26
+ export type { IWebSocketServerOptions } from "./apiServer/APIService";
27
+ export { WebSocketServer, WebSocketConnection, S_WS_ON_CONNECTED, S_WS_ON_MESSAGE, S_WS_ON_CLOSE, WS_CLOSE_UNAUTHORIZED, WS_CLOSE_AUTH_TIMEOUT, WS_CLOSE_RATE_LIMIT, WS_CLOSE_INTERNAL } from "./apiServer/WebSocketServer";
28
+ export type { WebSocketAuthorizer } from "./apiServer/WebSocketServer";
29
+ export { getDefaultOptions } from "./apiServer/APIService";
30
+ export type { APIServiceOptions, IInterceptor, IMonitorUser, IDocumentationUser } from "./apiServer/APIService";
31
+ export { BaseEndpoint } from "./apiServer/BaseEndpoint";
32
+ export { default as DefaultErrors } from "./apiServer/structures/DefaultErrors";
33
+ export type { HTTPRequestVO, TransferPacketVO, IError } from "./apiServer/structures/Interfaces";
34
+ export { logInfo, logWarn, logError, logCrit } from "./apiServer/LogService";
35
+ export type { IAccess } from "./apiServer/monitor/AccessStore";
package/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.S_BLUEGREEN_STATE_CHANGED = exports.ProcessMonitor = exports.S_MONITOR_RESTART_REQUESTED = exports.S_MONITOR_REGISTRATE_ACTION = exports.InterceptorPayAuth = exports.Activate = exports.Deploy = exports.DBService = exports.ExternalService = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.TimeframeService = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.JSONStableStringify = exports.YYYYMMDDHH = exports.UID = exports.ZipUtils = exports.Http = exports.MicroserviceClient = exports.MicroserviceHost = void 0;
6
+ exports.logCrit = exports.logError = exports.logWarn = exports.logInfo = exports.DefaultErrors = exports.BaseEndpoint = exports.getDefaultOptions = exports.WS_CLOSE_INTERNAL = exports.WS_CLOSE_RATE_LIMIT = exports.WS_CLOSE_AUTH_TIMEOUT = exports.WS_CLOSE_UNAUTHORIZED = exports.S_WS_ON_CLOSE = exports.S_WS_ON_MESSAGE = exports.S_WS_ON_CONNECTED = exports.WebSocketConnection = exports.WebSocketServer = exports.REQ_WS_SERVER = exports.S_BLUEGREEN_STATE_CHANGED = exports.ProcessMonitor = exports.S_MONITOR_RESTART_REQUESTED = exports.S_MONITOR_REGISTRATE_ACTION = exports.InterceptorPayAuth = exports.Activate = exports.Deploy = exports.DBService = exports.ExternalService = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.TimeframeService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.JSONStableStringify = exports.YYYYMMDDHH = exports.UID = exports.ZipUtils = exports.Http = exports.MicroserviceClient = exports.MicroserviceHost = void 0;
4
7
  const APIService_1 = require("./apiServer/APIService");
5
8
  Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
6
9
  Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
7
10
  const LocalRequest_1 = require("./apiServer/LocalRequest");
8
11
  Object.defineProperty(exports, "LocalRequest", { enumerable: true, get: function () { return LocalRequest_1.LocalRequest; } });
9
- const MysqlService_1 = require("./apiServer/MysqlService");
10
- Object.defineProperty(exports, "MysqlService", { enumerable: true, get: function () { return MysqlService_1.MysqlService; } });
11
12
  const Validator_1 = require("./apiServer/helper/Validator");
12
13
  Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return Validator_1.Validator; } });
13
14
  const LogService_1 = require("./apiServer/LogService");
@@ -49,3 +50,26 @@ const InterceptorPayAuth_1 = require("./apiServer/interceptors/InterceptorPayAut
49
50
  Object.defineProperty(exports, "InterceptorPayAuth", { enumerable: true, get: function () { return InterceptorPayAuth_1.InterceptorPayAuth; } });
50
51
  var BlueGreenState_1 = require("./apiServer/deployment/BlueGreenState");
51
52
  Object.defineProperty(exports, "S_BLUEGREEN_STATE_CHANGED", { enumerable: true, get: function () { return BlueGreenState_1.S_BLUEGREEN_STATE_CHANGED; } });
53
+ var APIService_2 = require("./apiServer/APIService");
54
+ Object.defineProperty(exports, "REQ_WS_SERVER", { enumerable: true, get: function () { return APIService_2.REQ_WS_SERVER; } });
55
+ var WebSocketServer_1 = require("./apiServer/WebSocketServer");
56
+ Object.defineProperty(exports, "WebSocketServer", { enumerable: true, get: function () { return WebSocketServer_1.WebSocketServer; } });
57
+ Object.defineProperty(exports, "WebSocketConnection", { enumerable: true, get: function () { return WebSocketServer_1.WebSocketConnection; } });
58
+ Object.defineProperty(exports, "S_WS_ON_CONNECTED", { enumerable: true, get: function () { return WebSocketServer_1.S_WS_ON_CONNECTED; } });
59
+ Object.defineProperty(exports, "S_WS_ON_MESSAGE", { enumerable: true, get: function () { return WebSocketServer_1.S_WS_ON_MESSAGE; } });
60
+ Object.defineProperty(exports, "S_WS_ON_CLOSE", { enumerable: true, get: function () { return WebSocketServer_1.S_WS_ON_CLOSE; } });
61
+ Object.defineProperty(exports, "WS_CLOSE_UNAUTHORIZED", { enumerable: true, get: function () { return WebSocketServer_1.WS_CLOSE_UNAUTHORIZED; } });
62
+ Object.defineProperty(exports, "WS_CLOSE_AUTH_TIMEOUT", { enumerable: true, get: function () { return WebSocketServer_1.WS_CLOSE_AUTH_TIMEOUT; } });
63
+ Object.defineProperty(exports, "WS_CLOSE_RATE_LIMIT", { enumerable: true, get: function () { return WebSocketServer_1.WS_CLOSE_RATE_LIMIT; } });
64
+ Object.defineProperty(exports, "WS_CLOSE_INTERNAL", { enumerable: true, get: function () { return WebSocketServer_1.WS_CLOSE_INTERNAL; } });
65
+ var APIService_3 = require("./apiServer/APIService");
66
+ Object.defineProperty(exports, "getDefaultOptions", { enumerable: true, get: function () { return APIService_3.getDefaultOptions; } });
67
+ var BaseEndpoint_1 = require("./apiServer/BaseEndpoint");
68
+ Object.defineProperty(exports, "BaseEndpoint", { enumerable: true, get: function () { return BaseEndpoint_1.BaseEndpoint; } });
69
+ var DefaultErrors_2 = require("./apiServer/structures/DefaultErrors");
70
+ Object.defineProperty(exports, "DefaultErrors", { enumerable: true, get: function () { return __importDefault(DefaultErrors_2).default; } });
71
+ var LogService_2 = require("./apiServer/LogService");
72
+ Object.defineProperty(exports, "logInfo", { enumerable: true, get: function () { return LogService_2.logInfo; } });
73
+ Object.defineProperty(exports, "logWarn", { enumerable: true, get: function () { return LogService_2.logWarn; } });
74
+ Object.defineProperty(exports, "logError", { enumerable: true, get: function () { return LogService_2.logError; } });
75
+ Object.defineProperty(exports, "logCrit", { enumerable: true, get: function () { return LogService_2.logCrit; } });
@@ -64,7 +64,7 @@ Authorization: Bearer ‹token из login›
64
64
 
65
65
  - Токен держи **в памяти вкладки**, не в localStorage.
66
66
  - Повторное подключение 2FA через API **невозможно** — это защита от перепривязки чужим человеком, узнавшим пароль. Потерян телефон → администратор удаляет запись в файле 2FA на сервере.
67
- - Пароль короче 12 символов настроить нельзя: вход такой учёткой вернёт `password policy violation` с причиной.
67
+ - Пароль в конфиге хранится **только как хеш** (`npx badmfck hash-password`; длину не меньше 12 символов проверяет сама команда). Если в конфиге пароль открытым текстом, вход с верным паролем вернёт `password is built incorrectly — the config must hold a hash…`, а с неверным — обычный `Invalid user`. Покажи `details` как есть: исправить это может только администратор сервера.
68
68
 
69
69
  ```js
70
70
  async function sm(endpoint, body = {}, token) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "5.0.16",
3
+ "version": "6.0.1",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  "badmfck": "dist/apiServer/deployment/cli.js"
10
10
  },
11
11
  "scripts": {
12
- "build": "npm version patch && tsc && cp ./src/apiServer/monitor/index.html ./dist/apiServer/monitor/index.html && cp ./src/apiServer/documentation/index.html ./dist/apiServer/documentation/index.html && chmod +x ./dist/apiServer/deployment/cli.js",
12
+ "build": "npm version patch && rm -rf dist && tsc && cp ./src/apiServer/monitor/index.html ./dist/apiServer/monitor/index.html && cp ./src/apiServer/documentation/index.html ./dist/apiServer/documentation/index.html && chmod +x ./dist/apiServer/deployment/cli.js",
13
13
  "test": "echo \"Error: no test specified\" && exit 1"
14
14
  },
15
15
  "keywords": [
@@ -1,123 +0,0 @@
1
- import { BaseService } from "./BaseService";
2
- import Signal, { Req } from "badmfck-signal";
3
- import * as mysql from "mysql2/promise";
4
- import fs from "fs";
5
- export declare const DEPRECATED_S_MYSQL_STARTED: Signal<void>;
6
- export declare const DEPRECATED_REQ_MYSQL_QUERY: Req<MySqlQuery[] | MySqlQuery, MysqlResult[]>;
7
- export declare const DEPRECATED_REQ_MYSQL_TBEGIN: Req<void, number | MysqlError>;
8
- export declare const DEPRECATED_REQ_MYSQL_TQUERY: Req<{
9
- query: MySqlQuery;
10
- tid: number;
11
- }, MysqlResult>;
12
- export declare const DEPRECATED_REQ_MYSQL_TCOMMIT: Req<number, MysqlError | null>;
13
- export declare const DEPRECATED_REQ_MYSQL_TROLLBACK: Req<number, MysqlError | null>;
14
- export declare const executeQuery: (query: MySqlQuery | MySqlQuery[]) => Promise<MysqlResult[]>;
15
- export interface MysqlServiceOptions {
16
- connectionLimit: number;
17
- host: string;
18
- user: string;
19
- password: string;
20
- port: number;
21
- database: string;
22
- queueLimit?: number;
23
- transactionFailReport?: (trx: ITransaction, message: string) => void;
24
- transactionFailReportDir?: string;
25
- debug?: boolean;
26
- naxTransactionWaitTime?: number;
27
- migrations?: {
28
- dir: string;
29
- callback: () => void;
30
- } | null;
31
- }
32
- export interface MysqlError {
33
- code: string;
34
- errno: number;
35
- sql: string;
36
- name: string;
37
- message: string;
38
- fatal?: boolean;
39
- throwable: boolean;
40
- }
41
- export declare const isMysqlError: (e: any) => e is MysqlError;
42
- export interface MysqlResult {
43
- error?: MysqlError | null;
44
- rollbackError?: MysqlError | null;
45
- isDuplicateError?: boolean;
46
- data: any;
47
- count: number;
48
- }
49
- export interface MySqlQuery {
50
- query: string;
51
- fields: MysqlQueryField[] | MysqlQueryFieldObject;
52
- rollbackQuery?: string | null;
53
- transactionID?: number;
54
- throwable?: boolean;
55
- calculateCount?: boolean;
56
- }
57
- export interface MysqlQueryField {
58
- name: string;
59
- value: string | number | boolean | null | undefined;
60
- system?: boolean;
61
- ignoreInInsert?: boolean;
62
- ignoreInUpdate?: boolean;
63
- useInReplace?: boolean;
64
- _parsedValue?: string | number | boolean | null;
65
- }
66
- export interface ITransaction {
67
- id: number;
68
- timestamp: number;
69
- conn: mysql.PoolConnection;
70
- queries: {
71
- sql: string;
72
- status: string;
73
- }[];
74
- }
75
- export interface MysqlQueryFieldObject extends Record<string, string | number | boolean | null | undefined | {
76
- name?: string | null;
77
- value: string | number | boolean | null | undefined;
78
- system?: boolean;
79
- ignoreInInsert?: boolean;
80
- ignoreInUpdate?: boolean;
81
- useInReplace?: boolean;
82
- }> {
83
- }
84
- export declare class MysqlService extends BaseService {
85
- reconnectionTimeout: number;
86
- reconnecting: boolean;
87
- pool: mysql.Pool | null;
88
- options: MysqlServiceOptions;
89
- serviceStarted: boolean;
90
- timeoutID: any;
91
- debug: boolean;
92
- queries: never[];
93
- static nextTransactionID: number;
94
- transactions: ITransaction[];
95
- maxTransactionWaitTime: number;
96
- lastSuccessQueryTime: number;
97
- pingInterval: number;
98
- failReportFileStream: fs.WriteStream | null;
99
- failReportFileStreamName: string | null;
100
- failReportLastAccessTime: number;
101
- constructor(options: MysqlServiceOptions);
102
- static executeQuery(query: MySqlQuery | MySqlQuery[]): Promise<MysqlResult[]>;
103
- init(): Promise<void>;
104
- commit(trx: ITransaction): Promise<MysqlError | null>;
105
- rollbackTransaction(trx: ITransaction, donNotRemove?: boolean): Promise<MysqlError | null>;
106
- finishApp(): Promise<void>;
107
- prepareCountQuery(query: string): string;
108
- storeTransactionAsProblem(trx: ITransaction, message: string): Promise<void>;
109
- recreatePool(): Promise<boolean>;
110
- onApplicationReady(): Promise<void>;
111
- static fieldsToObject(fields: MysqlQueryField[] | MysqlQueryFieldObject, ignoreSystemParameters?: boolean): MysqlQueryFieldObject;
112
- static objectToFields(obj: MysqlQueryFieldObject | MysqlQueryField[]): MysqlQueryField[];
113
- static prepareQuery(query: string, fields: MysqlQueryField[] | MysqlQueryFieldObject): string;
114
- static prepareQueryFieldValue(value: string | number | boolean | null | undefined, system?: boolean): string | number | boolean | null | undefined;
115
- execute(query: string, rollbackQuery: string | null, transactionID: number, throwable: boolean, calculateCount: boolean): Promise<MysqlResult>;
116
- sendQuery(conn: mysql.PoolConnection, query: string, resolve: (data: MysqlResult) => void, rollback: string | null, throwable: boolean, calculateCount: boolean): Promise<void>;
117
- queryAsync(conn: mysql.PoolConnection, query: string): Promise<{
118
- err: MysqlError | null;
119
- results?: any;
120
- }>;
121
- createMysqlQueryError(err: any, throwable?: boolean): MysqlError;
122
- }
123
- export default MysqlService;