@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,3 @@
1
+ export declare function askHidden(question: string): Promise<string>;
2
+ export declare function HashPassword(target: "monitor" | "deployer"): Promise<void>;
3
+ export declare function ProjectToken(mode: "generate" | "hash"): Promise<void>;
@@ -0,0 +1,126 @@
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.askHidden = askHidden;
7
+ exports.HashPassword = HashPassword;
8
+ exports.ProjectToken = ProjectToken;
9
+ const crypto_1 = __importDefault(require("crypto"));
10
+ const promises_1 = require("readline/promises");
11
+ const process_1 = require("process");
12
+ const PasswordHash_1 = require("../helper/PasswordHash");
13
+ const MonitorAuth_1 = require("../monitor/MonitorAuth");
14
+ const cliCommon_1 = require("./cliCommon");
15
+ function askHidden(question) {
16
+ return new Promise(resolve => {
17
+ const wasRaw = !!process_1.stdin.isRaw;
18
+ process_1.stdin.setRawMode(true);
19
+ process_1.stdout.write(question);
20
+ process_1.stdin.setEncoding("utf8");
21
+ process_1.stdin.resume();
22
+ let value = "";
23
+ const finish = () => {
24
+ process_1.stdin.removeListener("data", onData);
25
+ process_1.stdin.setRawMode(wasRaw);
26
+ process_1.stdin.pause();
27
+ process_1.stdout.write("\n");
28
+ };
29
+ const onData = (chunk) => {
30
+ for (const ch of chunk) {
31
+ if (ch === "\r" || ch === "\n" || ch === "\u0004") {
32
+ finish();
33
+ resolve(value);
34
+ return;
35
+ }
36
+ if (ch === "\u0003") {
37
+ finish();
38
+ process.exit(130);
39
+ }
40
+ if (ch === "\u007f" || ch === "\b") {
41
+ value = value.slice(0, -1);
42
+ continue;
43
+ }
44
+ if (ch >= " ")
45
+ value += ch;
46
+ }
47
+ };
48
+ process_1.stdin.on("data", onData);
49
+ });
50
+ }
51
+ async function HashPassword(target) {
52
+ const { red, green, yellow, dim, bold } = (0, cliCommon_1.palette)();
53
+ if (!process_1.stdin.isTTY) {
54
+ console.error(red("✗ hash-password needs an interactive terminal — the password is never accepted as an argument."));
55
+ process.exit(1);
56
+ }
57
+ console.log(bold(`\nHash a ${target} password`) + dim(target === "deployer" ? " (setup.json users)" : " (APIService access.monitor)"));
58
+ const rl = (0, promises_1.createInterface)({ input: process_1.stdin, output: process_1.stdout });
59
+ let login;
60
+ try {
61
+ login = (await rl.question("Login: ")).trim();
62
+ }
63
+ finally {
64
+ rl.close();
65
+ }
66
+ if (!login) {
67
+ console.error(red("✗ Login is required."));
68
+ process.exit(1);
69
+ }
70
+ {
71
+ const pass1 = await askHidden("Password: ");
72
+ const policy = MonitorAuth_1.MonitorAuth.passwordPolicyError(pass1);
73
+ if (policy) {
74
+ console.error(red(`✗ ${policy}.`));
75
+ process.exit(1);
76
+ }
77
+ const pass2 = await askHidden("Repeat password: ");
78
+ if (pass1 !== pass2) {
79
+ console.error(red("✗ Passwords do not match."));
80
+ process.exit(1);
81
+ }
82
+ const secret = target === "deployer"
83
+ ? crypto_1.default.createHash("sha256").update(login + ":" + pass1).digest("hex")
84
+ : pass1;
85
+ const hash = await PasswordHash_1.PasswordHash.hash(secret);
86
+ console.log("");
87
+ console.log(green(bold("✓ Put this in the config instead of the plain password:")));
88
+ console.log(`\n { "login": ${JSON.stringify(login)}, "password": ${JSON.stringify(hash)} }\n`);
89
+ if (target === "deployer")
90
+ console.log(yellow(" Deployer users stored as a hash need an up-to-date bmfk CLI on the deploying machine."));
91
+ console.log(dim(" The hash is salted — running this again for the same password gives a different, equally valid hash."));
92
+ }
93
+ }
94
+ async function ProjectToken(mode) {
95
+ const { red, green, yellow, dim, bold } = (0, cliCommon_1.palette)();
96
+ if (!process_1.stdin.isTTY) {
97
+ console.error(red("✗ project-token needs an interactive terminal — its output is a secret and must not land in CI logs."));
98
+ process.exit(1);
99
+ }
100
+ let token;
101
+ if (mode === "generate") {
102
+ token = crypto_1.default.randomBytes(32).toString("hex");
103
+ }
104
+ else {
105
+ console.log(bold("\nHash an existing project token") + dim(" (the project config on the deployer)"));
106
+ token = (await askHidden("Token: ")).trim();
107
+ if (!token) {
108
+ console.error(red("✗ Token is required."));
109
+ process.exit(1);
110
+ }
111
+ if (token.length < 32)
112
+ console.log(yellow(` ⚠ This token is short (${token.length} chars). Consider generating a new one: npx bmfk project-token`));
113
+ }
114
+ const hash = await PasswordHash_1.PasswordHash.hash(token);
115
+ console.log("");
116
+ if (mode === "generate") {
117
+ console.log(green(bold("✓ New project token")));
118
+ console.log(`\n deploy.json (your project, keep out of git): "token": ${JSON.stringify(token)}`);
119
+ console.log(` project config on the deployer: "token": ${JSON.stringify(hash)}\n`);
120
+ }
121
+ else {
122
+ console.log(green(bold("✓ Put this in the project config on the deployer instead of the plain token:")));
123
+ console.log(`\n "token": ${JSON.stringify(hash)}\n`);
124
+ }
125
+ console.log(dim(" The hash is salted — running this again gives a different, equally valid hash."));
126
+ }
@@ -0,0 +1 @@
1
+ export declare function MigrateConfigsWizard(folder?: string, assumeYes?: boolean): Promise<void>;
@@ -0,0 +1,202 @@
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.MigrateConfigsWizard = MigrateConfigsWizard;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const ConfigService_1 = require("./ConfigService");
9
+ const path_1 = __importDefault(require("path"));
10
+ const crypto_1 = __importDefault(require("crypto"));
11
+ const process_1 = require("process");
12
+ const PasswordHash_1 = require("../helper/PasswordHash");
13
+ const MonitorAuth_1 = require("../monitor/MonitorAuth");
14
+ const cliCommon_1 = require("./cliCommon");
15
+ const cliPrompt_1 = require("./cliPrompt");
16
+ const sha256 = (s) => crypto_1.default.createHash("sha256").update(s).digest("hex");
17
+ async function MigrateConfigsWizard(folder, assumeYes = false) {
18
+ const { red, green, yellow, dim, bold } = (0, cliCommon_1.palette)();
19
+ if (!process_1.stdin.isTTY && !assumeYes) {
20
+ console.error(red("✗ migrate-configs asks for confirmation — run it in a terminal, or add --yes."));
21
+ process.exit(1);
22
+ }
23
+ console.log(bold("\nMove deployer and access files to hashed secrets") + dim(assumeYes ? " (--yes: no confirmation)" : " (nothing is written before you confirm)"));
24
+ console.log(yellow(" Run this right after upgrading to 6.x: older versions don't understand hashes, newer ones refuse plain text.\n"));
25
+ let setupFile, projectsDir, accessFiles;
26
+ if (folder) {
27
+ if (!fs_1.default.existsSync(folder) || !fs_1.default.statSync(folder).isDirectory()) {
28
+ console.error(red(`✗ ${folder} is not a folder.`));
29
+ process.exit(1);
30
+ }
31
+ projectsDir = folder;
32
+ const inside = path_1.default.join(folder, "setup.json");
33
+ if (fs_1.default.existsSync(inside))
34
+ setupFile = inside;
35
+ else if (assumeYes) {
36
+ setupFile = "";
37
+ console.log(yellow(` ⚠ No setup.json in ${folder} — deployer users are not converted.`));
38
+ }
39
+ else
40
+ setupFile = await (0, cliPrompt_1.ask)(`No setup.json in ${folder}. Deployer setup.json (empty = skip)`, "");
41
+ accessFiles = [];
42
+ }
43
+ else {
44
+ const defSetup = ["setup.json", "projects/setup.json"].find(f => fs_1.default.existsSync(f)) ?? "";
45
+ setupFile = await (0, cliPrompt_1.ask)("Deployer setup.json (empty = skip)", defSetup);
46
+ projectsDir = await (0, cliPrompt_1.ask)("Folder with project configs (empty = skip)", setupFile ? path_1.default.dirname(setupFile) : "");
47
+ accessFiles = (0, cliPrompt_1.list)(await (0, cliPrompt_1.ask)("access.json files of apps, comma-separated (empty = skip)", ""));
48
+ }
49
+ const plans = [];
50
+ const readJson = (file) => {
51
+ try {
52
+ return JSON.parse(fs_1.default.readFileSync(file, "utf-8"));
53
+ }
54
+ catch (e) {
55
+ console.log(red(` ✗ ${file}: ${e?.code === "ENOENT" ? "not found" : "not valid JSON"} — skipped`));
56
+ return null;
57
+ }
58
+ };
59
+ const plain = (v) => typeof v === "string" && v.length > 0 && !PasswordHash_1.PasswordHash.isHash(v);
60
+ if (setupFile) {
61
+ const doc = readJson(setupFile);
62
+ if (doc) {
63
+ const plan = { file: path_1.default.resolve(setupFile), doc, changes: [], notes: [] };
64
+ (doc.users ?? []).forEach((u, i) => {
65
+ if (u && u.login === undefined && typeof u.username === "string") {
66
+ plan.notes.push(`users[${i}]: "username" renamed to "login" (${u.username})`);
67
+ u.login = u.username;
68
+ delete u.username;
69
+ }
70
+ if (u && plain(u.password)) {
71
+ if (u.password === u.login)
72
+ plan.notes.push(`deployer user "${u.login}": the password is the same as the login — change it (npx bmfk hash-password --deployer, and the client's deploy.json)`);
73
+ else if (MonitorAuth_1.MonitorAuth.passwordPolicyError(u.password))
74
+ plan.notes.push(`deployer user "${u.login}": password shorter than 12 characters — change it (npx bmfk hash-password --deployer, and the client's deploy.json)`);
75
+ const secret = sha256(u.login + ":" + u.password);
76
+ plan.changes.push({ file: plan.file, label: `deployer user "${u.login}"`, secret,
77
+ apply: (d, h) => { d.users[i].password = h; }, read: d => d.users[i].password });
78
+ }
79
+ });
80
+ (doc.reviewers ?? []).forEach((r, i) => {
81
+ if (r && plain(r.password)) {
82
+ if (r.password === r.login)
83
+ plan.notes.push(`reviewer "${r.login}": the password is the same as the login — change it later`);
84
+ else if (MonitorAuth_1.MonitorAuth.passwordPolicyError(r.password))
85
+ plan.notes.push(`reviewer "${r.login}": password shorter than 12 characters — change it later`);
86
+ plan.changes.push({ file: plan.file, label: `reviewer "${r.login}"`, secret: r.password,
87
+ apply: (d, h) => { d.reviewers[i].password = h; }, read: d => d.reviewers[i].password });
88
+ }
89
+ });
90
+ plans.push(plan);
91
+ }
92
+ }
93
+ if (projectsDir) {
94
+ let names = [];
95
+ try {
96
+ names = fs_1.default.readdirSync(projectsDir).filter(n => n.endsWith(".json")).sort();
97
+ }
98
+ catch {
99
+ console.log(red(` ✗ ${projectsDir}: not a readable folder — skipped`));
100
+ }
101
+ for (const n of names) {
102
+ const file = path_1.default.resolve(projectsDir, n);
103
+ if (setupFile && file === path_1.default.resolve(setupFile))
104
+ continue;
105
+ if (n.endsWith("_state_.json"))
106
+ continue;
107
+ const doc = readJson(file);
108
+ if (!doc || typeof doc !== "object" || typeof doc.name !== "string" || typeof doc.token !== "string")
109
+ continue;
110
+ const plan = { file, doc, changes: [], notes: [] };
111
+ const nameProblem = (0, ConfigService_1.projectNameProblem)(doc.name);
112
+ if (nameProblem)
113
+ plan.notes.push(`${nameProblem} — the deployer ignores this project until it is renamed`);
114
+ if (plain(doc.token)) {
115
+ if (doc.token.length < 32)
116
+ plan.notes.push(`project "${doc.name}": short token (${doc.token.length} chars) — consider a new one: npx bmfk project-token`);
117
+ plan.changes.push({ file, label: `project token "${doc.name}"`, secret: doc.token,
118
+ apply: (d, h) => { d.token = h; }, read: d => d.token });
119
+ }
120
+ plans.push(plan);
121
+ }
122
+ }
123
+ for (const f of accessFiles) {
124
+ const doc = readJson(f);
125
+ if (!doc)
126
+ continue;
127
+ const plan = { file: path_1.default.resolve(f), doc, changes: [], notes: [] };
128
+ (doc.monitor ?? []).forEach((u, i) => {
129
+ if (u && plain(u.password)) {
130
+ if (u.password === u.login)
131
+ plan.notes.push(`monitor user "${u.login}": the password is the same as the login — change it later (npx bmfk access-config)`);
132
+ else if (MonitorAuth_1.MonitorAuth.passwordPolicyError(u.password))
133
+ plan.notes.push(`monitor user "${u.login}": password shorter than 12 characters — change it later (npx bmfk access-config)`);
134
+ plan.changes.push({ file: plan.file, label: `monitor user "${u.login}"`, secret: u.password,
135
+ apply: (d, h) => { d.monitor[i].password = h; }, read: d => d.monitor[i].password });
136
+ }
137
+ });
138
+ (doc.documentation ?? []).forEach((u, i) => {
139
+ if (u && plain(u.password)) {
140
+ if (u.password === u.login)
141
+ plan.notes.push(`documentation user "${u.login}": the password is the same as the login — change it later (npx bmfk access-config)`);
142
+ else if (MonitorAuth_1.MonitorAuth.passwordPolicyError(u.password))
143
+ plan.notes.push(`documentation user "${u.login}": password shorter than 12 characters — change it later (npx bmfk access-config)`);
144
+ plan.changes.push({ file: plan.file, label: `documentation user "${u.login}"`, secret: u.password,
145
+ apply: (d, h) => { d.documentation[i].password = h; }, read: d => d.documentation[i].password });
146
+ }
147
+ });
148
+ plans.push(plan);
149
+ }
150
+ const todo = plans.filter(p => p.changes.length || p.notes.some(n => n.includes("renamed")));
151
+ console.log("\n" + bold("Report"));
152
+ for (const p of plans) {
153
+ const head = p.changes.length ? yellow(`${p.changes.length} to hash`) : green("already hashed");
154
+ console.log(` ${p.file} ${head}`);
155
+ for (const c of p.changes)
156
+ console.log(dim(` • ${c.label}`));
157
+ for (const n of p.notes)
158
+ console.log(yellow(` ⚠ ${n}`));
159
+ }
160
+ if (!todo.length) {
161
+ console.log(green("\n✓ Nothing to change."));
162
+ return;
163
+ }
164
+ if (!assumeYes && !(await (0, cliPrompt_1.yes)(`\nHash ${todo.reduce((n, p) => n + p.changes.length, 0)} value(s) in ${todo.length} file(s)?`, false))) {
165
+ console.log(dim("Nothing was changed."));
166
+ return;
167
+ }
168
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
169
+ const backupDir = path_1.default.resolve(path_1.default.dirname(todo[0].file), `.pre-hash-backup-${stamp}`);
170
+ fs_1.default.mkdirSync(backupDir, { recursive: true, mode: 0o700 });
171
+ for (const [i, p] of todo.entries()) {
172
+ const copy = path_1.default.join(backupDir, `${i + 1}-${path_1.default.basename(p.file)}`);
173
+ fs_1.default.copyFileSync(p.file, copy);
174
+ fs_1.default.chmodSync(copy, 0o600);
175
+ }
176
+ let failed = 0;
177
+ for (const p of todo) {
178
+ for (const c of p.changes)
179
+ c.apply(p.doc, await PasswordHash_1.PasswordHash.hash(c.secret));
180
+ const tmp = p.file + ".tmp";
181
+ fs_1.default.writeFileSync(tmp, JSON.stringify(p.doc, null, 4) + "\n", { encoding: "utf-8", mode: 0o600 });
182
+ fs_1.default.chmodSync(tmp, 0o600);
183
+ fs_1.default.renameSync(tmp, p.file);
184
+ const back = JSON.parse(fs_1.default.readFileSync(p.file, "utf-8"));
185
+ for (const c of p.changes) {
186
+ if (await PasswordHash_1.PasswordHash.verify(c.secret, c.read(back)))
187
+ continue;
188
+ failed++;
189
+ console.log(red(` ✗ ${p.file}: ${c.label} did not verify — restore it from ${backupDir}`));
190
+ }
191
+ console.log((failed ? yellow : green)(` ✓ ${p.file}`) + dim(" (0600)"));
192
+ }
193
+ console.log("");
194
+ if (failed) {
195
+ console.log(red(`✗ ${failed} value(s) did not verify. The originals are in ${backupDir}.`));
196
+ process.exit(1);
197
+ }
198
+ console.log(green("✓ Done. A running 6.x deployer and apps pick the files up without a restart."));
199
+ console.log(yellow(` The originals (with the plain secrets) are in ${backupDir}.`));
200
+ console.log(yellow(" Check that deploys and monitor sign-in work, then delete that folder:"));
201
+ console.log(` rm -rf ${JSON.stringify(backupDir)}`);
202
+ }
@@ -0,0 +1,31 @@
1
+ export interface IMigrationFile {
2
+ file: string;
3
+ before: string;
4
+ after: string;
5
+ changes: number;
6
+ }
7
+ export interface IMigrationPlan {
8
+ files: IMigrationFile[];
9
+ notes: string[];
10
+ }
11
+ export declare function rootExportNames(indexFile: string): Set<string>;
12
+ export declare function migrateSource(text: string, rel: string, exported: Set<string>): {
13
+ text: string;
14
+ changes: number;
15
+ notes: string[];
16
+ };
17
+ export declare function migratePackageJson(text: string): {
18
+ text: string;
19
+ changes: number;
20
+ notes: string[];
21
+ };
22
+ type TS = any;
23
+ export declare function projectTypeScript(dir: string): TS | null;
24
+ export declare function migrateModels(text: string, rel: string, ts: TS): {
25
+ text: string;
26
+ changes: number;
27
+ notes: string[];
28
+ };
29
+ export declare function planMigration(dir: string, exported: Set<string>): IMigrationPlan;
30
+ export declare function MigrateProject(args: string[]): Promise<void>;
31
+ export {};