@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.
Files changed (169) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1293 -2
  4. package/dist/apiServer/APIService.d.ts +125 -0
  5. package/dist/apiServer/APIService.js +769 -0
  6. package/dist/apiServer/BaseEndpoint.d.ts +90 -0
  7. package/dist/apiServer/BaseEndpoint.js +314 -0
  8. package/dist/apiServer/BaseService.d.ts +17 -0
  9. package/dist/apiServer/BaseService.js +39 -0
  10. package/dist/apiServer/DBService.d.ts +131 -0
  11. package/dist/apiServer/DBService.js +290 -0
  12. package/dist/apiServer/DocumentService.d.ts +9 -0
  13. package/dist/apiServer/DocumentService.js +65 -0
  14. package/dist/apiServer/LocalRequest.d.ts +3 -0
  15. package/dist/apiServer/LocalRequest.js +6 -0
  16. package/dist/apiServer/LogService.d.ts +78 -0
  17. package/dist/apiServer/LogService.js +349 -0
  18. package/dist/apiServer/MonitorService.d.ts +102 -0
  19. package/dist/apiServer/MonitorService.js +615 -0
  20. package/dist/apiServer/StatService.d.ts +4 -0
  21. package/dist/apiServer/StatService.js +10 -0
  22. package/dist/apiServer/TimeframeService.d.ts +28 -0
  23. package/dist/apiServer/TimeframeService.js +97 -0
  24. package/dist/apiServer/WebSocketServer.d.ts +39 -0
  25. package/dist/apiServer/WebSocketServer.js +173 -0
  26. package/dist/apiServer/db/IDBAdapter.d.ts +14 -0
  27. package/dist/apiServer/db/IDBAdapter.js +2 -0
  28. package/dist/apiServer/db/MysqlAdapter.d.ts +72 -0
  29. package/dist/apiServer/db/MysqlAdapter.js +869 -0
  30. package/dist/apiServer/db/PostgresAdapter.d.ts +41 -0
  31. package/dist/apiServer/db/PostgresAdapter.js +73 -0
  32. package/dist/apiServer/deployment/AccessConfigWizard.d.ts +5 -0
  33. package/dist/apiServer/deployment/AccessConfigWizard.js +254 -0
  34. package/dist/apiServer/deployment/Activate.d.ts +4 -0
  35. package/dist/apiServer/deployment/Activate.js +124 -0
  36. package/dist/apiServer/deployment/BackupManager.d.ts +33 -0
  37. package/dist/apiServer/deployment/BackupManager.js +174 -0
  38. package/dist/apiServer/deployment/Backups.d.ts +2 -0
  39. package/dist/apiServer/deployment/Backups.js +44 -0
  40. package/dist/apiServer/deployment/BlueGreenState.d.ts +31 -0
  41. package/dist/apiServer/deployment/BlueGreenState.js +150 -0
  42. package/dist/apiServer/deployment/Bundler.d.ts +12 -0
  43. package/dist/apiServer/deployment/Bundler.js +178 -0
  44. package/dist/apiServer/deployment/ConfigService.d.ts +203 -0
  45. package/dist/apiServer/deployment/ConfigService.js +195 -0
  46. package/dist/apiServer/deployment/Deploy.d.ts +4 -0
  47. package/dist/apiServer/deployment/Deploy.js +404 -0
  48. package/dist/apiServer/deployment/DeployKeyWizard.d.ts +2 -0
  49. package/dist/apiServer/deployment/DeployKeyWizard.js +84 -0
  50. package/dist/apiServer/deployment/Deployer.d.ts +13 -0
  51. package/dist/apiServer/deployment/Deployer.js +96 -0
  52. package/dist/apiServer/deployment/DeployerInit.d.ts +25 -0
  53. package/dist/apiServer/deployment/DeployerInit.js +214 -0
  54. package/dist/apiServer/deployment/DeployerService.d.ts +378 -0
  55. package/dist/apiServer/deployment/DeployerService.js +1553 -0
  56. package/dist/apiServer/deployment/HashPassword.d.ts +3 -0
  57. package/dist/apiServer/deployment/HashPassword.js +126 -0
  58. package/dist/apiServer/deployment/MigrateConfigsWizard.d.ts +1 -0
  59. package/dist/apiServer/deployment/MigrateConfigsWizard.js +202 -0
  60. package/dist/apiServer/deployment/MigrateProject.d.ts +31 -0
  61. package/dist/apiServer/deployment/MigrateProject.js +335 -0
  62. package/dist/apiServer/deployment/NginxHelper.d.ts +10 -0
  63. package/dist/apiServer/deployment/NginxHelper.js +111 -0
  64. package/dist/apiServer/deployment/Notifier.d.ts +30 -0
  65. package/dist/apiServer/deployment/Notifier.js +82 -0
  66. package/dist/apiServer/deployment/ProjectConfigWizard.d.ts +1 -0
  67. package/dist/apiServer/deployment/ProjectConfigWizard.js +148 -0
  68. package/dist/apiServer/deployment/Restore.d.ts +2 -0
  69. package/dist/apiServer/deployment/Restore.js +89 -0
  70. package/dist/apiServer/deployment/ReviewStore.d.ts +62 -0
  71. package/dist/apiServer/deployment/ReviewStore.js +186 -0
  72. package/dist/apiServer/deployment/SecretsInjector.d.ts +21 -0
  73. package/dist/apiServer/deployment/SecretsInjector.js +189 -0
  74. package/dist/apiServer/deployment/SetupConfigWizard.d.ts +1 -0
  75. package/dist/apiServer/deployment/SetupConfigWizard.js +238 -0
  76. package/dist/apiServer/deployment/Status.d.ts +2 -0
  77. package/dist/apiServer/deployment/Status.js +83 -0
  78. package/dist/apiServer/deployment/TelegramNotifier.d.ts +8 -0
  79. package/dist/apiServer/deployment/TelegramNotifier.js +23 -0
  80. package/dist/apiServer/deployment/Watchdog.d.ts +15 -0
  81. package/dist/apiServer/deployment/Watchdog.js +65 -0
  82. package/dist/apiServer/deployment/Wizards.d.ts +1 -0
  83. package/dist/apiServer/deployment/Wizards.js +83 -0
  84. package/dist/apiServer/deployment/cli.d.ts +2 -0
  85. package/dist/apiServer/deployment/cli.js +224 -0
  86. package/dist/apiServer/deployment/cliCommon.d.ts +27 -0
  87. package/dist/apiServer/deployment/cliCommon.js +110 -0
  88. package/dist/apiServer/deployment/cliPrompt.d.ts +5 -0
  89. package/dist/apiServer/deployment/cliPrompt.js +38 -0
  90. package/dist/apiServer/deployment/resolveConfig.d.ts +19 -0
  91. package/dist/apiServer/deployment/resolveConfig.js +139 -0
  92. package/dist/apiServer/documentation/Documentation.d.ts +18 -0
  93. package/dist/apiServer/documentation/Documentation.js +143 -0
  94. package/dist/apiServer/documentation/index.html +460 -0
  95. package/dist/apiServer/external/MicroserviceClient.d.ts +28 -0
  96. package/dist/apiServer/external/MicroserviceClient.js +144 -0
  97. package/dist/apiServer/external/MicroserviceHost.d.ts +52 -0
  98. package/dist/apiServer/external/MicroserviceHost.js +183 -0
  99. package/dist/apiServer/external/MicroserviceHostController.d.ts +6 -0
  100. package/dist/apiServer/external/MicroserviceHostController.js +65 -0
  101. package/dist/apiServer/helper/AppDataPath.d.ts +9 -0
  102. package/dist/apiServer/helper/AppDataPath.js +81 -0
  103. package/dist/apiServer/helper/ClientIp.d.ts +3 -0
  104. package/dist/apiServer/helper/ClientIp.js +33 -0
  105. package/dist/apiServer/helper/DataProvider.d.ts +18 -0
  106. package/dist/apiServer/helper/DataProvider.js +57 -0
  107. package/dist/apiServer/helper/IpAllowList.d.ts +8 -0
  108. package/dist/apiServer/helper/IpAllowList.js +40 -0
  109. package/dist/apiServer/helper/JSONStableStringify.d.ts +1 -0
  110. package/dist/apiServer/helper/JSONStableStringify.js +15 -0
  111. package/dist/apiServer/helper/PasswordHash.d.ts +5 -0
  112. package/dist/apiServer/helper/PasswordHash.js +52 -0
  113. package/dist/apiServer/helper/Sleep.d.ts +1 -0
  114. package/dist/apiServer/helper/Sleep.js +5 -0
  115. package/dist/apiServer/helper/Trace.d.ts +8 -0
  116. package/dist/apiServer/helper/Trace.js +30 -0
  117. package/dist/apiServer/helper/UID.d.ts +16 -0
  118. package/dist/apiServer/helper/UID.js +98 -0
  119. package/dist/apiServer/helper/Validator.d.ts +86 -0
  120. package/dist/apiServer/helper/Validator.js +560 -0
  121. package/dist/apiServer/helper/YYYYMMDDHH.d.ts +2 -0
  122. package/dist/apiServer/helper/YYYYMMDDHH.js +31 -0
  123. package/dist/apiServer/helper/ZipUtils.d.ts +6 -0
  124. package/dist/apiServer/helper/ZipUtils.js +28 -0
  125. package/dist/apiServer/http/Http.d.ts +183 -0
  126. package/dist/apiServer/http/Http.js +627 -0
  127. package/dist/apiServer/interceptors/InterceptorPayAuth.d.ts +19 -0
  128. package/dist/apiServer/interceptors/InterceptorPayAuth.js +124 -0
  129. package/dist/apiServer/interceptors/InterceptorSignedAuth.d.ts +40 -0
  130. package/dist/apiServer/interceptors/InterceptorSignedAuth.js +150 -0
  131. package/dist/apiServer/monitor/AccessStore.d.ts +27 -0
  132. package/dist/apiServer/monitor/AccessStore.js +163 -0
  133. package/dist/apiServer/monitor/LogFiles.d.ts +34 -0
  134. package/dist/apiServer/monitor/LogFiles.js +109 -0
  135. package/dist/apiServer/monitor/Monitor.d.ts +54 -0
  136. package/dist/apiServer/monitor/Monitor.js +447 -0
  137. package/dist/apiServer/monitor/MonitorAuth.d.ts +87 -0
  138. package/dist/apiServer/monitor/MonitorAuth.js +474 -0
  139. package/dist/apiServer/monitor/ProcessMonitor.d.ts +177 -0
  140. package/dist/apiServer/monitor/ProcessMonitor.js +468 -0
  141. package/dist/apiServer/monitor/SystemInfo.d.ts +70 -0
  142. package/dist/apiServer/monitor/SystemInfo.js +217 -0
  143. package/dist/apiServer/monitor/ThreatMonitor.d.ts +73 -0
  144. package/dist/apiServer/monitor/ThreatMonitor.js +239 -0
  145. package/dist/apiServer/monitor/index.html +591 -0
  146. package/dist/apiServer/review/Review.d.ts +23 -0
  147. package/dist/apiServer/review/Review.js +149 -0
  148. package/dist/apiServer/review/ReviewAuth.d.ts +56 -0
  149. package/dist/apiServer/review/ReviewAuth.js +147 -0
  150. package/dist/apiServer/review/ReviewDiff.d.ts +43 -0
  151. package/dist/apiServer/review/ReviewDiff.js +175 -0
  152. package/dist/apiServer/review/index.html +501 -0
  153. package/dist/apiServer/routes/Liveness.d.ts +7 -0
  154. package/dist/apiServer/routes/Liveness.js +27 -0
  155. package/dist/apiServer/routes/Readiness.d.ts +13 -0
  156. package/dist/apiServer/routes/Readiness.js +20 -0
  157. package/dist/apiServer/security/BlockedIps.d.ts +46 -0
  158. package/dist/apiServer/security/BlockedIps.js +185 -0
  159. package/dist/apiServer/structures/DefaultErrors.d.ts +36 -0
  160. package/dist/apiServer/structures/DefaultErrors.js +52 -0
  161. package/dist/apiServer/structures/HTTPStatus.d.ts +7 -0
  162. package/dist/apiServer/structures/HTTPStatus.js +11 -0
  163. package/dist/apiServer/structures/Interfaces.d.ts +55 -0
  164. package/dist/apiServer/structures/Interfaces.js +2 -0
  165. package/dist/index.d.ts +45 -0
  166. package/dist/index.js +110 -0
  167. package/dist/signal/Signal.d.ts +23 -0
  168. package/dist/signal/Signal.js +85 -0
  169. package/package.json +88 -4
@@ -0,0 +1,185 @@
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.BlockedIps = exports.BLOCKED_IPS_FILE = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const crypto_1 = __importDefault(require("crypto"));
10
+ const IpAllowList_1 = require("../helper/IpAllowList");
11
+ const AppDataPath_1 = require("../helper/AppDataPath");
12
+ const LogService_1 = require("../LogService");
13
+ exports.BLOCKED_IPS_FILE = "blocked-ips.json";
14
+ class BlockedIps {
15
+ static file = null;
16
+ static entries = [];
17
+ static list = null;
18
+ static nextExpiry = Infinity;
19
+ static hash = "";
20
+ static refusedHash = "";
21
+ static debounce = null;
22
+ static watching = false;
23
+ static hits = new Map();
24
+ static configure(file) {
25
+ BlockedIps.file = path_1.default.resolve(file || BlockedIps.defaultPath());
26
+ BlockedIps.load(true);
27
+ BlockedIps.watch();
28
+ }
29
+ static get path() { return BlockedIps.file; }
30
+ static defaultPath() {
31
+ const dir = AppDataPath_1.AppData.dir("");
32
+ return dir ? path_1.default.join(dir, exports.BLOCKED_IPS_FILE) : (0, AppDataPath_1.appDataPath)("blocked-ips", ".json");
33
+ }
34
+ static validate(value) {
35
+ if (!Array.isArray(value))
36
+ return "the file must hold an array of { ip, reason?, until? }";
37
+ for (const [i, e] of value.entries()) {
38
+ if (!e || typeof e !== "object" || typeof e.ip !== "string")
39
+ return `entry ${i}: "ip" is required`;
40
+ const built = IpAllowList_1.IpAllowList.build([e.ip]);
41
+ if (built.error)
42
+ return `entry ${i}: ${built.error}`;
43
+ if (e.until !== undefined && e.until !== null && Number.isNaN(Date.parse(e.until)))
44
+ return `entry ${i}: "until" is not a date`;
45
+ if (e.reason !== undefined && typeof e.reason !== "string")
46
+ return `entry ${i}: "reason" must be text`;
47
+ }
48
+ return null;
49
+ }
50
+ static load(initial = false) {
51
+ const file = BlockedIps.file;
52
+ if (!file)
53
+ return;
54
+ let raw;
55
+ try {
56
+ raw = fs_1.default.readFileSync(file, "utf-8");
57
+ }
58
+ catch (e) {
59
+ if (e?.code === "ENOENT") {
60
+ if (BlockedIps.hash !== "missing") {
61
+ BlockedIps.hash = "missing";
62
+ BlockedIps.apply([]);
63
+ }
64
+ return;
65
+ }
66
+ (0, LogService_1.logWarn)(`Blocked IPs: cannot read ${file} (${e?.message ?? e}) — keeping the current list`);
67
+ return;
68
+ }
69
+ const hash = crypto_1.default.createHash("sha256").update(raw).digest("hex");
70
+ if (hash === BlockedIps.hash || hash === BlockedIps.refusedHash)
71
+ return;
72
+ let parsed;
73
+ try {
74
+ parsed = raw.trim() ? JSON.parse(raw) : [];
75
+ }
76
+ catch (e) {
77
+ BlockedIps.refusedHash = hash;
78
+ (0, LogService_1.logError)(`Blocked IPs: ${file} is not valid JSON (${e?.message ?? e}) — change ignored, keeping the current list`);
79
+ return;
80
+ }
81
+ const problem = BlockedIps.validate(parsed);
82
+ if (problem) {
83
+ BlockedIps.refusedHash = hash;
84
+ (0, LogService_1.logError)(`Blocked IPs: ${file} — ${problem}; change ignored, keeping the current list`);
85
+ return;
86
+ }
87
+ BlockedIps.hash = hash;
88
+ BlockedIps.refusedHash = "";
89
+ BlockedIps.apply(parsed);
90
+ const active = BlockedIps.entries.filter(e => BlockedIps.active(e)).length;
91
+ (0, LogService_1.logInfo)(`Blocked IPs ${initial ? "loaded" : "reloaded"} from ${file}: ${active} active of ${parsed.length}`);
92
+ }
93
+ static active(e, now = Date.now()) {
94
+ return !e.until || Date.parse(e.until) > now;
95
+ }
96
+ static apply(entries) {
97
+ BlockedIps.entries = entries;
98
+ const now = Date.now();
99
+ const live = entries.filter(e => BlockedIps.active(e, now));
100
+ BlockedIps.list = IpAllowList_1.IpAllowList.build(live.map(e => e.ip)).list;
101
+ BlockedIps.nextExpiry = Math.min(Infinity, ...live.filter(e => e.until).map(e => Date.parse(e.until)));
102
+ }
103
+ static isBlocked(ip) {
104
+ if (!BlockedIps.list || !ip || ip === "127.0.0.1" || ip === "::1")
105
+ return false;
106
+ if (Date.now() >= BlockedIps.nextExpiry)
107
+ BlockedIps.apply(BlockedIps.entries);
108
+ return !!BlockedIps.list && IpAllowList_1.IpAllowList.allows(BlockedIps.list, ip);
109
+ }
110
+ static noteHit(ip) {
111
+ const h = BlockedIps.hits.get(ip) ?? { count: 0, lastLogged: 0 };
112
+ h.count++;
113
+ if (Date.now() - h.lastLogged > 10 * 60 * 1000) {
114
+ h.lastLogged = Date.now();
115
+ (0, LogService_1.logWarn)(`Blocked IPs: refused ${ip} (${h.count} request(s) so far)`);
116
+ }
117
+ BlockedIps.hits.set(ip, h);
118
+ if (BlockedIps.hits.size > 10000)
119
+ BlockedIps.hits.delete(BlockedIps.hits.keys().next().value);
120
+ }
121
+ static snapshot() {
122
+ const now = Date.now();
123
+ return {
124
+ file: BlockedIps.file,
125
+ entries: BlockedIps.entries.map(e => ({ ...e, active: BlockedIps.active(e, now) })),
126
+ hits: Object.fromEntries(Array.from(BlockedIps.hits.entries()).map(([ip, h]) => [ip, h.count])),
127
+ };
128
+ }
129
+ static update(change) {
130
+ const file = BlockedIps.file;
131
+ if (!file)
132
+ throw new Error("blocked IPs are not configured");
133
+ let current = [];
134
+ const raw = fs_1.default.existsSync(file) ? fs_1.default.readFileSync(file, "utf-8") : "";
135
+ if (raw.trim()) {
136
+ let parsed;
137
+ try {
138
+ parsed = JSON.parse(raw);
139
+ }
140
+ catch {
141
+ throw new Error(`${file} is not valid JSON — fix it by hand first`);
142
+ }
143
+ const problem = BlockedIps.validate(parsed);
144
+ if (problem)
145
+ throw new Error(`${file} is invalid (${problem}) — fix it by hand first`);
146
+ current = parsed;
147
+ }
148
+ const next = change(current);
149
+ const tmp = file + ".tmp";
150
+ fs_1.default.writeFileSync(tmp, JSON.stringify(next, null, 2) + "\n", { encoding: "utf-8", mode: 0o600 });
151
+ fs_1.default.renameSync(tmp, file);
152
+ BlockedIps.load();
153
+ }
154
+ static add(entry) {
155
+ BlockedIps.update(list => [...list.filter(e => e.ip !== entry.ip), entry]);
156
+ }
157
+ static remove(ip) {
158
+ let removed = false;
159
+ BlockedIps.update(list => list.filter(e => { if (e.ip === ip) {
160
+ removed = true;
161
+ return false;
162
+ } return true; }));
163
+ return removed;
164
+ }
165
+ static watch() {
166
+ if (BlockedIps.watching || !BlockedIps.file)
167
+ return;
168
+ BlockedIps.watching = true;
169
+ const dir = path_1.default.dirname(BlockedIps.file), name = path_1.default.basename(BlockedIps.file);
170
+ try {
171
+ fs_1.default.watch(dir, (_e, filename) => {
172
+ if (filename && filename !== name)
173
+ return;
174
+ if (BlockedIps.debounce)
175
+ clearTimeout(BlockedIps.debounce);
176
+ BlockedIps.debounce = setTimeout(() => { BlockedIps.debounce = null; BlockedIps.load(); }, 200);
177
+ }).unref();
178
+ }
179
+ catch (e) {
180
+ (0, LogService_1.logWarn)(`Blocked IPs: cannot watch ${dir} (${e?.message ?? e}) — changes are picked up within a minute`);
181
+ }
182
+ setInterval(() => BlockedIps.load(), 60_000).unref();
183
+ }
184
+ }
185
+ exports.BlockedIps = BlockedIps;
@@ -0,0 +1,36 @@
1
+ import { IError } from "./Interfaces";
2
+ declare class DefaultErrors {
3
+ static NOT_IMPLEMENTED: IError;
4
+ static UNKNOWN_REQUEST: IError;
5
+ static JSON_MALFORMED: IError;
6
+ static FILE_TOO_LARGE: IError;
7
+ static CANT_SEND_FILE: IError;
8
+ static FILE_NOT_EXISTS: IError;
9
+ static UNAUTHORIZED: IError;
10
+ static BAD_REQUEST: IError;
11
+ static SERVICE_NOT_WORKING: IError;
12
+ static TIMEOUT: IError;
13
+ static METHOD_NOT_ALLOWED: IError;
14
+ static DB_ERROR: IError;
15
+ static DB_DUPLICATE_ERROR: IError;
16
+ static FORBIDDEN: IError;
17
+ static NOT_FOUND: IError;
18
+ static INTERNAL_SERVER_ERROR: IError;
19
+ static INVALID_TOKEN: IError;
20
+ static INVALID_CREDENTIALS: IError;
21
+ static INVALID_DATA: IError;
22
+ static INVALID_FILE: IError;
23
+ static EXTERNAL_SERVICE_ERROR: IError;
24
+ static MAINTENANCE_MODE: IError;
25
+ static CONFLICT: IError;
26
+ static WRONG_DATA_TYPE: IError;
27
+ static UPROCESSIABLE_CONTENT: IError;
28
+ static WRONG_PARAMS: IError;
29
+ static ACCEPTED: IError;
30
+ static INTERNAL_ERROR: IError;
31
+ }
32
+ export declare class ErrorUtils {
33
+ static isError(obj: any): obj is IError;
34
+ static appendStack(error: IError, stack?: IError[]): IError;
35
+ }
36
+ export default DefaultErrors;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorUtils = void 0;
4
+ const Validator_1 = require("../helper/Validator");
5
+ class DefaultErrors {
6
+ static NOT_IMPLEMENTED = { code: 1, message: "Not implemented" };
7
+ static UNKNOWN_REQUEST = { code: 2, message: "Unknown request" };
8
+ static JSON_MALFORMED = { code: 3, message: "JSON malformed" };
9
+ static FILE_TOO_LARGE = { code: 4, message: "File is too large", httpStatus: 413 };
10
+ static CANT_SEND_FILE = { code: 5, message: "Can't send file" };
11
+ static FILE_NOT_EXISTS = { code: 5, message: "File not exists", httpStatus: 404 };
12
+ static UNAUTHORIZED = { code: 6, message: "Unauthorized", httpStatus: 401 };
13
+ static BAD_REQUEST = { code: 7, message: "Bad request", httpStatus: 400 };
14
+ static SERVICE_NOT_WORKING = { code: 8, message: "Service not working" };
15
+ static TIMEOUT = { code: 9, message: "Timeout", httpStatus: 408 };
16
+ static METHOD_NOT_ALLOWED = { code: 10, message: "Method not allowed", httpStatus: 405 };
17
+ static DB_ERROR = { code: 11, message: "DB error", httpStatus: 500 };
18
+ static DB_DUPLICATE_ERROR = { code: 28, message: "DB duplicate entry", httpStatus: 409 };
19
+ static FORBIDDEN = { code: 12, message: "Forbidden", httpStatus: 403 };
20
+ static NOT_FOUND = { code: 13, message: "Not found", httpStatus: 404 };
21
+ static INTERNAL_SERVER_ERROR = { code: 14, message: "Internal server error.", httpStatus: 500 };
22
+ static INVALID_TOKEN = { code: 15, message: "Invalid token", httpStatus: 401 };
23
+ static INVALID_CREDENTIALS = { code: 16, message: "Invalid credentials", httpStatus: 401 };
24
+ static INVALID_DATA = { code: 17, message: "Invalid data", httpStatus: 422 };
25
+ static INVALID_FILE = { code: 18, message: "Invalid file", httpStatus: 422 };
26
+ static EXTERNAL_SERVICE_ERROR = { code: 19, message: "External service error", httpStatus: 502 };
27
+ static MAINTENANCE_MODE = { code: 21, message: "Service in maintenance mode", httpStatus: 503 };
28
+ static CONFLICT = { code: 22, message: "Conflict", httpStatus: 409 };
29
+ static WRONG_DATA_TYPE = { code: 23, message: "Wrong data type", httpStatus: 422 };
30
+ static UPROCESSIABLE_CONTENT = { code: 24, message: "Unprocessable content", httpStatus: 422 };
31
+ static WRONG_PARAMS = { code: 25, message: "Wrong params", httpStatus: 400 };
32
+ static ACCEPTED = { code: 26, message: "Accepted", httpStatus: 202 };
33
+ static INTERNAL_ERROR = { code: 27, message: "Internal error", httpStatus: 500 };
34
+ }
35
+ class ErrorUtils {
36
+ static isError(obj) {
37
+ const isFieldsExists = Validator_1.Validator.validateObject(['code', 'message'], obj);
38
+ if (!isFieldsExists)
39
+ return false;
40
+ if (Validator_1.Validator.validateValue(obj.code, { type: "number" }) !== Validator_1.ValidationReport.OK)
41
+ return false;
42
+ if (Validator_1.Validator.validateValue(obj.message, { type: "string" }) !== Validator_1.ValidationReport.OK)
43
+ return false;
44
+ return true;
45
+ }
46
+ static appendStack(error, stack) {
47
+ error.stack = stack;
48
+ return error;
49
+ }
50
+ }
51
+ exports.ErrorUtils = ErrorUtils;
52
+ exports.default = DefaultErrors;
@@ -0,0 +1,7 @@
1
+ export declare enum HTTP_STATUS {
2
+ OK = 200,
3
+ NOT_FOUND = 404,
4
+ UNAUTHORIZED = 401,
5
+ BAD_REQUEST = 400,
6
+ SERVER_ERROR = 500
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HTTP_STATUS = void 0;
4
+ var HTTP_STATUS;
5
+ (function (HTTP_STATUS) {
6
+ HTTP_STATUS[HTTP_STATUS["OK"] = 200] = "OK";
7
+ HTTP_STATUS[HTTP_STATUS["NOT_FOUND"] = 404] = "NOT_FOUND";
8
+ HTTP_STATUS[HTTP_STATUS["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
9
+ HTTP_STATUS[HTTP_STATUS["BAD_REQUEST"] = 400] = "BAD_REQUEST";
10
+ HTTP_STATUS[HTTP_STATUS["SERVER_ERROR"] = 500] = "SERVER_ERROR";
11
+ })(HTTP_STATUS || (exports.HTTP_STATUS = HTTP_STATUS = {}));
@@ -0,0 +1,55 @@
1
+ import { FileArray } from "express-fileupload";
2
+ import { Readable } from "stream";
3
+ export interface IResponse<T = any> {
4
+ data?: T | null;
5
+ error?: IError | null;
6
+ responseTime?: number;
7
+ traceId?: string;
8
+ version?: string;
9
+ core?: string;
10
+ endpoint?: string;
11
+ httpStatus?: number;
12
+ redirect?: string;
13
+ rawResponse?: boolean;
14
+ headers?: {
15
+ [key: string]: string;
16
+ };
17
+ file?: string;
18
+ blockResponse?: boolean;
19
+ project?: string;
20
+ ignoreHttpLogging?: boolean;
21
+ }
22
+ export interface IRequest<T = any, TInterceptor = any> {
23
+ raw: any;
24
+ response: any;
25
+ method: string;
26
+ data: T;
27
+ params: {
28
+ [key: string]: string;
29
+ };
30
+ headers: Record<string, string>;
31
+ endpoint: string;
32
+ interceptorResult?: any;
33
+ preproducerResult?: any;
34
+ precheck?: IResponse<any> | null;
35
+ files: FileArray | null | undefined;
36
+ referer?: string;
37
+ ip?: string;
38
+ traceId?: string;
39
+ unlocked?: boolean;
40
+ internalCall?: boolean;
41
+ stream?: Readable;
42
+ endStream?: (force?: boolean) => void;
43
+ internalCallParams?: any;
44
+ }
45
+ export interface IError {
46
+ code: number;
47
+ message: string;
48
+ details?: string;
49
+ httpStatus?: number;
50
+ stack?: IError[];
51
+ }
52
+ export interface HTTPRequestVO<T = any, TInterceptor = any> extends IRequest<T, TInterceptor> {
53
+ }
54
+ export interface TransferPacketVO<T = any> extends IResponse<T> {
55
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,45 @@
1
+ export { APIService, Initializer, getDefaultOptions, REQ_HTTP_LOG, REQ_HTTP_REQUESTS_COUNT, REQ_HTTP_SERVER, REQ_INTERNAL_CALL, REQ_WS_SERVER, S_APP_STARTED } from "./apiServer/APIService";
2
+ export type { APIServiceOptions, APIServiceNetworkLogItem, IInterceptor, IMonitorUser, IDocumentationUser, IDeployerUser, IWebSocketServerOptions } from "./apiServer/APIService";
3
+ export { BaseService } from "./apiServer/BaseService";
4
+ export type { IBaseService } from "./apiServer/BaseService";
5
+ export { BaseEndpoint } from "./apiServer/BaseEndpoint";
6
+ export type { IBaseEndpoint, IHandler, IEndpointHandler } from "./apiServer/BaseEndpoint";
7
+ export { LocalRequest } from "./apiServer/LocalRequest";
8
+ export type { IRequest, IResponse, IError, HTTPRequestVO, TransferPacketVO } from "./apiServer/structures/Interfaces";
9
+ export { default as DefaultErrors, ErrorUtils } from "./apiServer/structures/DefaultErrors";
10
+ export { Validator, ValidationModel, ValidationReport } from "./apiServer/helper/Validator";
11
+ export type { TValidatorType, IStructureOptions, IValidatorOptions } from "./apiServer/helper/Validator";
12
+ export { InterceptorSignedAuth } from "./apiServer/interceptors/InterceptorSignedAuth";
13
+ export type { ISignedAuthResult, ISignedAuthVerdict } from "./apiServer/interceptors/InterceptorSignedAuth";
14
+ export { InterceptorPayAuth } from "./apiServer/interceptors/InterceptorPayAuth";
15
+ export { LogService, LOG_LEVEL, getDefaultLogOptions, logInfo, logWarn, logError, logCrit, logDB, logAPI, S_LOG, REQ_LOG } from "./apiServer/LogService";
16
+ export type { ILogItem, ILogServiceOptions } from "./apiServer/LogService";
17
+ export { Trace, TRACE_HEADER } from "./apiServer/helper/Trace";
18
+ export { DBService, REQ_DB, REQ_DBX, REQ_DB_TBEGIN, REQ_DB_TCOMMIT, REQ_DB_TROLLBACK } from "./apiServer/DBService";
19
+ export type { IDBQuery, IDBQueryField, IDBQueryFields, IDBBulkQuery, IDBBulkQueryItem, IDBError, IDBResult, IDBSericeOptions, DBAdapterOptions } from "./apiServer/DBService";
20
+ export { MysqlAdapter, isError as isDBError } from "./apiServer/db/MysqlAdapter";
21
+ export { PostgresAdapter } from "./apiServer/db/PostgresAdapter";
22
+ export type { IDBAdapter } from "./apiServer/db/IDBAdapter";
23
+ export { Http } from "./apiServer/http/Http";
24
+ export type { HttpMethod, THttpResult, THttpOk, THttpErr, THttpConfig, TRequestOptions, TRetryPolicy } from "./apiServer/http/Http";
25
+ export { MicroserviceHost, MemoryJobStore } from "./apiServer/external/MicroserviceHost";
26
+ export type { IMicroserviceHostOptions, IMicroserviceCaller, IMicroserviceCall, IMicroserviceJob, IMicroserviceJobStore } from "./apiServer/external/MicroserviceHost";
27
+ export { MicroserviceClient, REQ_MICROSERVICE_CALL } from "./apiServer/external/MicroserviceClient";
28
+ export type { IMicroserviceClientOptions } from "./apiServer/external/MicroserviceClient";
29
+ 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";
30
+ export type { WebSocketAuthorizer } from "./apiServer/WebSocketServer";
31
+ export { TimeframeService, REQ_TIMEFRAME_TASK_ADD, S_TIMEFRAME_TASK_EXECUTED } from "./apiServer/TimeframeService";
32
+ export type { ITimeframeTask } from "./apiServer/TimeframeService";
33
+ export { S_MONITOR_REGISTRATE_ACTION, S_MONITOR_RESTART_REQUESTED } from "./apiServer/monitor/Monitor";
34
+ export { ProcessMonitor } from "./apiServer/monitor/ProcessMonitor";
35
+ export type { IAccess } from "./apiServer/monitor/AccessStore";
36
+ export { Deploy } from "./apiServer/deployment/Deploy";
37
+ export { Activate } from "./apiServer/deployment/Activate";
38
+ export { S_BLUEGREEN_STATE_CHANGED, onLiveChange, getBlueGreenActiveState, getBlueGreenStateSync } from "./apiServer/deployment/BlueGreenState";
39
+ export type { IBlueGreenState, IBlueGreenStateOptions } from "./apiServer/deployment/BlueGreenState";
40
+ export { Signal, Req } from "./signal/Signal";
41
+ export { DataProvider } from "./apiServer/helper/DataProvider";
42
+ export { UID } from "./apiServer/helper/UID";
43
+ export { YYYYMMDDHH, YYYYMMDDHH_toDate } from "./apiServer/helper/YYYYMMDDHH";
44
+ export { JSONStableStringify } from "./apiServer/helper/JSONStableStringify";
45
+ export { ZipUtils } from "./apiServer/helper/ZipUtils";
package/dist/index.js ADDED
@@ -0,0 +1,110 @@
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.S_WS_ON_CLOSE = exports.S_WS_ON_MESSAGE = exports.S_WS_ON_CONNECTED = exports.WebSocketConnection = exports.WebSocketServer = exports.REQ_MICROSERVICE_CALL = exports.MicroserviceClient = exports.MemoryJobStore = exports.MicroserviceHost = exports.Http = exports.PostgresAdapter = exports.isDBError = exports.MysqlAdapter = exports.REQ_DB_TROLLBACK = exports.REQ_DB_TCOMMIT = exports.REQ_DB_TBEGIN = exports.REQ_DBX = exports.REQ_DB = exports.DBService = exports.TRACE_HEADER = exports.Trace = exports.REQ_LOG = exports.S_LOG = exports.logAPI = exports.logDB = exports.logCrit = exports.logError = exports.logWarn = exports.logInfo = exports.getDefaultLogOptions = exports.LOG_LEVEL = exports.LogService = exports.InterceptorPayAuth = exports.InterceptorSignedAuth = exports.ValidationReport = exports.Validator = exports.ErrorUtils = exports.DefaultErrors = exports.LocalRequest = exports.BaseEndpoint = exports.BaseService = exports.S_APP_STARTED = exports.REQ_WS_SERVER = exports.REQ_INTERNAL_CALL = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.getDefaultOptions = exports.Initializer = exports.APIService = void 0;
7
+ exports.ZipUtils = exports.JSONStableStringify = exports.YYYYMMDDHH_toDate = exports.YYYYMMDDHH = exports.UID = exports.DataProvider = exports.Req = exports.Signal = exports.getBlueGreenStateSync = exports.getBlueGreenActiveState = exports.onLiveChange = exports.S_BLUEGREEN_STATE_CHANGED = exports.Activate = exports.Deploy = exports.ProcessMonitor = exports.S_MONITOR_RESTART_REQUESTED = exports.S_MONITOR_REGISTRATE_ACTION = exports.S_TIMEFRAME_TASK_EXECUTED = exports.REQ_TIMEFRAME_TASK_ADD = exports.TimeframeService = exports.WS_CLOSE_INTERNAL = exports.WS_CLOSE_RATE_LIMIT = exports.WS_CLOSE_AUTH_TIMEOUT = exports.WS_CLOSE_UNAUTHORIZED = void 0;
8
+ var APIService_1 = require("./apiServer/APIService");
9
+ Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
10
+ Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
11
+ Object.defineProperty(exports, "getDefaultOptions", { enumerable: true, get: function () { return APIService_1.getDefaultOptions; } });
12
+ Object.defineProperty(exports, "REQ_HTTP_LOG", { enumerable: true, get: function () { return APIService_1.REQ_HTTP_LOG; } });
13
+ Object.defineProperty(exports, "REQ_HTTP_REQUESTS_COUNT", { enumerable: true, get: function () { return APIService_1.REQ_HTTP_REQUESTS_COUNT; } });
14
+ Object.defineProperty(exports, "REQ_HTTP_SERVER", { enumerable: true, get: function () { return APIService_1.REQ_HTTP_SERVER; } });
15
+ Object.defineProperty(exports, "REQ_INTERNAL_CALL", { enumerable: true, get: function () { return APIService_1.REQ_INTERNAL_CALL; } });
16
+ Object.defineProperty(exports, "REQ_WS_SERVER", { enumerable: true, get: function () { return APIService_1.REQ_WS_SERVER; } });
17
+ Object.defineProperty(exports, "S_APP_STARTED", { enumerable: true, get: function () { return APIService_1.S_APP_STARTED; } });
18
+ var BaseService_1 = require("./apiServer/BaseService");
19
+ Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return BaseService_1.BaseService; } });
20
+ var BaseEndpoint_1 = require("./apiServer/BaseEndpoint");
21
+ Object.defineProperty(exports, "BaseEndpoint", { enumerable: true, get: function () { return BaseEndpoint_1.BaseEndpoint; } });
22
+ var LocalRequest_1 = require("./apiServer/LocalRequest");
23
+ Object.defineProperty(exports, "LocalRequest", { enumerable: true, get: function () { return LocalRequest_1.LocalRequest; } });
24
+ var DefaultErrors_1 = require("./apiServer/structures/DefaultErrors");
25
+ Object.defineProperty(exports, "DefaultErrors", { enumerable: true, get: function () { return __importDefault(DefaultErrors_1).default; } });
26
+ Object.defineProperty(exports, "ErrorUtils", { enumerable: true, get: function () { return DefaultErrors_1.ErrorUtils; } });
27
+ var Validator_1 = require("./apiServer/helper/Validator");
28
+ Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return Validator_1.Validator; } });
29
+ Object.defineProperty(exports, "ValidationReport", { enumerable: true, get: function () { return Validator_1.ValidationReport; } });
30
+ var InterceptorSignedAuth_1 = require("./apiServer/interceptors/InterceptorSignedAuth");
31
+ Object.defineProperty(exports, "InterceptorSignedAuth", { enumerable: true, get: function () { return InterceptorSignedAuth_1.InterceptorSignedAuth; } });
32
+ var InterceptorPayAuth_1 = require("./apiServer/interceptors/InterceptorPayAuth");
33
+ Object.defineProperty(exports, "InterceptorPayAuth", { enumerable: true, get: function () { return InterceptorPayAuth_1.InterceptorPayAuth; } });
34
+ var LogService_1 = require("./apiServer/LogService");
35
+ Object.defineProperty(exports, "LogService", { enumerable: true, get: function () { return LogService_1.LogService; } });
36
+ Object.defineProperty(exports, "LOG_LEVEL", { enumerable: true, get: function () { return LogService_1.LOG_LEVEL; } });
37
+ Object.defineProperty(exports, "getDefaultLogOptions", { enumerable: true, get: function () { return LogService_1.getDefaultLogOptions; } });
38
+ Object.defineProperty(exports, "logInfo", { enumerable: true, get: function () { return LogService_1.logInfo; } });
39
+ Object.defineProperty(exports, "logWarn", { enumerable: true, get: function () { return LogService_1.logWarn; } });
40
+ Object.defineProperty(exports, "logError", { enumerable: true, get: function () { return LogService_1.logError; } });
41
+ Object.defineProperty(exports, "logCrit", { enumerable: true, get: function () { return LogService_1.logCrit; } });
42
+ Object.defineProperty(exports, "logDB", { enumerable: true, get: function () { return LogService_1.logDB; } });
43
+ Object.defineProperty(exports, "logAPI", { enumerable: true, get: function () { return LogService_1.logAPI; } });
44
+ Object.defineProperty(exports, "S_LOG", { enumerable: true, get: function () { return LogService_1.S_LOG; } });
45
+ Object.defineProperty(exports, "REQ_LOG", { enumerable: true, get: function () { return LogService_1.REQ_LOG; } });
46
+ var Trace_1 = require("./apiServer/helper/Trace");
47
+ Object.defineProperty(exports, "Trace", { enumerable: true, get: function () { return Trace_1.Trace; } });
48
+ Object.defineProperty(exports, "TRACE_HEADER", { enumerable: true, get: function () { return Trace_1.TRACE_HEADER; } });
49
+ var DBService_1 = require("./apiServer/DBService");
50
+ Object.defineProperty(exports, "DBService", { enumerable: true, get: function () { return DBService_1.DBService; } });
51
+ Object.defineProperty(exports, "REQ_DB", { enumerable: true, get: function () { return DBService_1.REQ_DB; } });
52
+ Object.defineProperty(exports, "REQ_DBX", { enumerable: true, get: function () { return DBService_1.REQ_DBX; } });
53
+ Object.defineProperty(exports, "REQ_DB_TBEGIN", { enumerable: true, get: function () { return DBService_1.REQ_DB_TBEGIN; } });
54
+ Object.defineProperty(exports, "REQ_DB_TCOMMIT", { enumerable: true, get: function () { return DBService_1.REQ_DB_TCOMMIT; } });
55
+ Object.defineProperty(exports, "REQ_DB_TROLLBACK", { enumerable: true, get: function () { return DBService_1.REQ_DB_TROLLBACK; } });
56
+ var MysqlAdapter_1 = require("./apiServer/db/MysqlAdapter");
57
+ Object.defineProperty(exports, "MysqlAdapter", { enumerable: true, get: function () { return MysqlAdapter_1.MysqlAdapter; } });
58
+ Object.defineProperty(exports, "isDBError", { enumerable: true, get: function () { return MysqlAdapter_1.isError; } });
59
+ var PostgresAdapter_1 = require("./apiServer/db/PostgresAdapter");
60
+ Object.defineProperty(exports, "PostgresAdapter", { enumerable: true, get: function () { return PostgresAdapter_1.PostgresAdapter; } });
61
+ var Http_1 = require("./apiServer/http/Http");
62
+ Object.defineProperty(exports, "Http", { enumerable: true, get: function () { return Http_1.Http; } });
63
+ var MicroserviceHost_1 = require("./apiServer/external/MicroserviceHost");
64
+ Object.defineProperty(exports, "MicroserviceHost", { enumerable: true, get: function () { return MicroserviceHost_1.MicroserviceHost; } });
65
+ Object.defineProperty(exports, "MemoryJobStore", { enumerable: true, get: function () { return MicroserviceHost_1.MemoryJobStore; } });
66
+ var MicroserviceClient_1 = require("./apiServer/external/MicroserviceClient");
67
+ Object.defineProperty(exports, "MicroserviceClient", { enumerable: true, get: function () { return MicroserviceClient_1.MicroserviceClient; } });
68
+ Object.defineProperty(exports, "REQ_MICROSERVICE_CALL", { enumerable: true, get: function () { return MicroserviceClient_1.REQ_MICROSERVICE_CALL; } });
69
+ var WebSocketServer_1 = require("./apiServer/WebSocketServer");
70
+ Object.defineProperty(exports, "WebSocketServer", { enumerable: true, get: function () { return WebSocketServer_1.WebSocketServer; } });
71
+ Object.defineProperty(exports, "WebSocketConnection", { enumerable: true, get: function () { return WebSocketServer_1.WebSocketConnection; } });
72
+ Object.defineProperty(exports, "S_WS_ON_CONNECTED", { enumerable: true, get: function () { return WebSocketServer_1.S_WS_ON_CONNECTED; } });
73
+ Object.defineProperty(exports, "S_WS_ON_MESSAGE", { enumerable: true, get: function () { return WebSocketServer_1.S_WS_ON_MESSAGE; } });
74
+ Object.defineProperty(exports, "S_WS_ON_CLOSE", { enumerable: true, get: function () { return WebSocketServer_1.S_WS_ON_CLOSE; } });
75
+ Object.defineProperty(exports, "WS_CLOSE_UNAUTHORIZED", { enumerable: true, get: function () { return WebSocketServer_1.WS_CLOSE_UNAUTHORIZED; } });
76
+ Object.defineProperty(exports, "WS_CLOSE_AUTH_TIMEOUT", { enumerable: true, get: function () { return WebSocketServer_1.WS_CLOSE_AUTH_TIMEOUT; } });
77
+ Object.defineProperty(exports, "WS_CLOSE_RATE_LIMIT", { enumerable: true, get: function () { return WebSocketServer_1.WS_CLOSE_RATE_LIMIT; } });
78
+ Object.defineProperty(exports, "WS_CLOSE_INTERNAL", { enumerable: true, get: function () { return WebSocketServer_1.WS_CLOSE_INTERNAL; } });
79
+ var TimeframeService_1 = require("./apiServer/TimeframeService");
80
+ Object.defineProperty(exports, "TimeframeService", { enumerable: true, get: function () { return TimeframeService_1.TimeframeService; } });
81
+ Object.defineProperty(exports, "REQ_TIMEFRAME_TASK_ADD", { enumerable: true, get: function () { return TimeframeService_1.REQ_TIMEFRAME_TASK_ADD; } });
82
+ Object.defineProperty(exports, "S_TIMEFRAME_TASK_EXECUTED", { enumerable: true, get: function () { return TimeframeService_1.S_TIMEFRAME_TASK_EXECUTED; } });
83
+ var Monitor_1 = require("./apiServer/monitor/Monitor");
84
+ Object.defineProperty(exports, "S_MONITOR_REGISTRATE_ACTION", { enumerable: true, get: function () { return Monitor_1.S_MONITOR_REGISTRATE_ACTION; } });
85
+ Object.defineProperty(exports, "S_MONITOR_RESTART_REQUESTED", { enumerable: true, get: function () { return Monitor_1.S_MONITOR_RESTART_REQUESTED; } });
86
+ var ProcessMonitor_1 = require("./apiServer/monitor/ProcessMonitor");
87
+ Object.defineProperty(exports, "ProcessMonitor", { enumerable: true, get: function () { return ProcessMonitor_1.ProcessMonitor; } });
88
+ var Deploy_1 = require("./apiServer/deployment/Deploy");
89
+ Object.defineProperty(exports, "Deploy", { enumerable: true, get: function () { return Deploy_1.Deploy; } });
90
+ var Activate_1 = require("./apiServer/deployment/Activate");
91
+ Object.defineProperty(exports, "Activate", { enumerable: true, get: function () { return Activate_1.Activate; } });
92
+ var BlueGreenState_1 = require("./apiServer/deployment/BlueGreenState");
93
+ Object.defineProperty(exports, "S_BLUEGREEN_STATE_CHANGED", { enumerable: true, get: function () { return BlueGreenState_1.S_BLUEGREEN_STATE_CHANGED; } });
94
+ Object.defineProperty(exports, "onLiveChange", { enumerable: true, get: function () { return BlueGreenState_1.onLiveChange; } });
95
+ Object.defineProperty(exports, "getBlueGreenActiveState", { enumerable: true, get: function () { return BlueGreenState_1.getBlueGreenActiveState; } });
96
+ Object.defineProperty(exports, "getBlueGreenStateSync", { enumerable: true, get: function () { return BlueGreenState_1.getBlueGreenStateSync; } });
97
+ var Signal_1 = require("./signal/Signal");
98
+ Object.defineProperty(exports, "Signal", { enumerable: true, get: function () { return Signal_1.Signal; } });
99
+ Object.defineProperty(exports, "Req", { enumerable: true, get: function () { return Signal_1.Req; } });
100
+ var DataProvider_1 = require("./apiServer/helper/DataProvider");
101
+ Object.defineProperty(exports, "DataProvider", { enumerable: true, get: function () { return DataProvider_1.DataProvider; } });
102
+ var UID_1 = require("./apiServer/helper/UID");
103
+ Object.defineProperty(exports, "UID", { enumerable: true, get: function () { return UID_1.UID; } });
104
+ var YYYYMMDDHH_1 = require("./apiServer/helper/YYYYMMDDHH");
105
+ Object.defineProperty(exports, "YYYYMMDDHH", { enumerable: true, get: function () { return YYYYMMDDHH_1.YYYYMMDDHH; } });
106
+ Object.defineProperty(exports, "YYYYMMDDHH_toDate", { enumerable: true, get: function () { return YYYYMMDDHH_1.YYYYMMDDHH_toDate; } });
107
+ var JSONStableStringify_1 = require("./apiServer/helper/JSONStableStringify");
108
+ Object.defineProperty(exports, "JSONStableStringify", { enumerable: true, get: function () { return JSONStableStringify_1.JSONStableStringify; } });
109
+ var ZipUtils_1 = require("./apiServer/helper/ZipUtils");
110
+ Object.defineProperty(exports, "ZipUtils", { enumerable: true, get: function () { return ZipUtils_1.ZipUtils; } });
@@ -0,0 +1,23 @@
1
+ export declare class Signal<T> {
2
+ private static nextID;
3
+ static onError: (signal: Signal<any>, error: unknown) => void;
4
+ readonly name: string;
5
+ private subscribers;
6
+ private queue;
7
+ private running;
8
+ constructor(name?: string);
9
+ subscribe(callback: (data: T) => void, id?: string): string;
10
+ unsubscribe(id: string): boolean;
11
+ removeAll(): void;
12
+ get size(): number;
13
+ invoke(data: T): void;
14
+ }
15
+ export declare class Req<T, K> {
16
+ private static nextID;
17
+ readonly name: string;
18
+ private worker?;
19
+ constructor(worker?: (request: T) => Promise<K>, name?: string);
20
+ set listener(worker: (request: T) => Promise<K>);
21
+ get hasListener(): boolean;
22
+ request(data: T): Promise<K>;
23
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Req = exports.Signal = void 0;
4
+ class Signal {
5
+ static nextID = 0;
6
+ static onError = (signal, error) => {
7
+ try {
8
+ console.error(`Signal ${signal.name}: a subscriber threw`, error);
9
+ }
10
+ catch { }
11
+ };
12
+ name;
13
+ subscribers = [];
14
+ queue = [];
15
+ running = false;
16
+ constructor(name) {
17
+ this.name = name || "S_" + Signal.nextID++;
18
+ }
19
+ subscribe(callback, id) {
20
+ const existing = this.subscribers.find(s => s.cb === callback);
21
+ if (existing)
22
+ return existing.id;
23
+ const subscriber = { cb: callback, id: id ?? "" + Signal.nextID++ };
24
+ this.subscribers = [...this.subscribers, subscriber];
25
+ return subscriber.id;
26
+ }
27
+ unsubscribe(id) {
28
+ const before = this.subscribers.length;
29
+ this.subscribers = this.subscribers.filter(s => s.id !== id);
30
+ return this.subscribers.length < before;
31
+ }
32
+ removeAll() {
33
+ this.subscribers = [];
34
+ }
35
+ get size() {
36
+ return this.subscribers.length;
37
+ }
38
+ invoke(data) {
39
+ this.queue.push(data);
40
+ if (this.running)
41
+ return;
42
+ this.running = true;
43
+ try {
44
+ while (this.queue.length) {
45
+ const next = this.queue.shift();
46
+ for (const s of this.subscribers) {
47
+ try {
48
+ s.cb(next);
49
+ }
50
+ catch (e) {
51
+ try {
52
+ Signal.onError(this, e);
53
+ }
54
+ catch { }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ finally {
60
+ this.running = false;
61
+ }
62
+ }
63
+ }
64
+ exports.Signal = Signal;
65
+ class Req {
66
+ static nextID = 1;
67
+ name;
68
+ worker;
69
+ constructor(worker, name) {
70
+ this.name = name || "Req_" + Req.nextID++;
71
+ this.worker = worker;
72
+ }
73
+ set listener(worker) {
74
+ this.worker = worker;
75
+ }
76
+ get hasListener() {
77
+ return this.worker !== undefined;
78
+ }
79
+ async request(data) {
80
+ if (!this.worker)
81
+ throw new Error(`No worker registered in ${this.name}`);
82
+ return this.worker(data);
83
+ }
84
+ }
85
+ exports.Req = Req;