badmfck-api-server 5.0.17 → 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.
- package/README.md +163 -6
- package/dist/apiServer/DBService.js +1 -2
- package/dist/apiServer/db/MysqlAdapter.d.ts +4 -0
- package/dist/apiServer/db/MysqlAdapter.js +93 -84
- package/dist/apiServer/db/PostgresAdapter.d.ts +10 -3
- package/dist/apiServer/monitor/MonitorAuth.d.ts +11 -1
- package/dist/apiServer/monitor/MonitorAuth.js +157 -31
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -3
- package/package.json +2 -2
- package/dist/apiServer/MysqlService.d.ts +0 -123
- package/dist/apiServer/MysqlService.js +0 -817
- package/dist/apiServer/WSAPITransport.d.ts +0 -0
- package/dist/apiServer/WSAPITransport.js +0 -1
- package/dist/apiServer/WebSocketHandler.d.ts +0 -0
- package/dist/apiServer/WebSocketHandler.js +0 -1
- package/dist/apiServer/WebsocketServerService.d.ts +0 -9
- package/dist/apiServer/WebsocketServerService.js +0 -18
- package/dist/apiServer/deployment/Deployment.d.ts +0 -10
- package/dist/apiServer/deployment/Deployment.js +0 -24
- package/dist/apiServer/interceptors/IntHmacSha256.d.ts +0 -5
- 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
|
-
|
|
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
|
-
|
|
75
|
-
|
|
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
|
|
79
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
fs_1.default.
|
|
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
|
-
|
|
423
|
+
const rec = { secret: pending.secret, enrolledAt: Date.now(), lastCounter: 0 };
|
|
304
424
|
MonitorAuth.pendingEnrollments.delete(token);
|
|
305
|
-
MonitorAuth.
|
|
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
|
}
|
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,7 +19,7 @@ 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,
|
|
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";
|
|
26
25
|
export { REQ_WS_SERVER } from "./apiServer/APIService";
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.
|
|
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;
|
|
7
7
|
const APIService_1 = require("./apiServer/APIService");
|
|
8
8
|
Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
|
|
9
9
|
Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
|
|
10
10
|
const LocalRequest_1 = require("./apiServer/LocalRequest");
|
|
11
11
|
Object.defineProperty(exports, "LocalRequest", { enumerable: true, get: function () { return LocalRequest_1.LocalRequest; } });
|
|
12
|
-
const MysqlService_1 = require("./apiServer/MysqlService");
|
|
13
|
-
Object.defineProperty(exports, "MysqlService", { enumerable: true, get: function () { return MysqlService_1.MysqlService; } });
|
|
14
12
|
const Validator_1 = require("./apiServer/helper/Validator");
|
|
15
13
|
Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return Validator_1.Validator; } });
|
|
16
14
|
const LogService_1 = require("./apiServer/LogService");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "badmfck-api-server",
|
|
3
|
-
"version": "
|
|
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;
|