badmfck-api-server 4.1.52 → 4.1.57

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 (40) hide show
  1. package/dist/apiServer/APIService.d.ts +3 -4
  2. package/dist/apiServer/APIService.js +19 -9
  3. package/dist/apiServer/BaseEndpoint.d.ts +2 -2
  4. package/dist/apiServer/LocalRequest.d.ts +1 -1
  5. package/dist/apiServer/LogService.js +17 -7
  6. package/dist/apiServer/MonitorService.d.ts +0 -1
  7. package/dist/apiServer/MonitorService.js +17 -7
  8. package/dist/apiServer/MysqlService.d.ts +1 -2
  9. package/dist/apiServer/MysqlService.js +17 -7
  10. package/dist/apiServer/TimeframeService.js +17 -7
  11. package/dist/apiServer/db/MysqlAdapter.d.ts +1 -1
  12. package/dist/apiServer/db/MysqlAdapter.js +37 -12
  13. package/dist/apiServer/deployment/Activate.d.ts +3 -9
  14. package/dist/apiServer/deployment/Activate.js +3 -13
  15. package/dist/apiServer/deployment/ConfigService.d.ts +26 -26
  16. package/dist/apiServer/deployment/ConfigService.js +17 -7
  17. package/dist/apiServer/deployment/Deploy.d.ts +2 -9
  18. package/dist/apiServer/deployment/Deploy.js +3 -97
  19. package/dist/apiServer/deployment/DeployerService.d.ts +9 -9
  20. package/dist/apiServer/deployment/cli.d.ts +2 -0
  21. package/dist/apiServer/deployment/cli.js +63 -0
  22. package/dist/apiServer/deployment/resolveConfig.d.ts +12 -0
  23. package/dist/apiServer/deployment/resolveConfig.js +104 -0
  24. package/dist/apiServer/documentation/index.html +25 -25
  25. package/dist/apiServer/external/ExternalService.js +17 -7
  26. package/dist/apiServer/external/MicroserviceClient.js +17 -7
  27. package/dist/apiServer/external/MicroserviceHost.js +17 -7
  28. package/dist/apiServer/external/MicroserviceHostController.js +17 -7
  29. package/dist/apiServer/helper/JSONStableStringify.js +1 -2
  30. package/dist/apiServer/helper/YYYYMMDDHH.js +2 -3
  31. package/dist/apiServer/helper/ZipUtils.d.ts +0 -2
  32. package/dist/apiServer/monitor/Monitor.d.ts +1 -0
  33. package/dist/apiServer/monitor/Monitor.js +5 -0
  34. package/dist/apiServer/monitor/ProcessMonitor.d.ts +45 -1
  35. package/dist/apiServer/monitor/ProcessMonitor.js +147 -0
  36. package/dist/apiServer/monitor/SystemInfo.d.ts +7 -8
  37. package/dist/apiServer/monitor/SystemInfo.js +1 -2
  38. package/dist/apiServer/monitor/index.html +54 -54
  39. package/dist/apiServer/structures/Interfaces.d.ts +0 -1
  40. package/package.json +5 -2
@@ -3,109 +3,16 @@ 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.Deploy = void 0;
6
+ exports.Deploy = Deploy;
7
7
  const child_process_1 = require("child_process");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const __1 = require("../..");
11
11
  const crypto_1 = __importDefault(require("crypto"));
12
12
  const undici_1 = require("undici");
13
- const promises_1 = require("readline/promises");
14
- const process_1 = require("process");
15
- function validateConfig(cfg) {
16
- if (!cfg || typeof cfg !== "object")
17
- return "not an object";
18
- if (!cfg.name || !cfg.token || !cfg.host || !cfg.username || !cfg.password)
19
- return "missing one of: name, token, host, username, password";
20
- if (cfg.includes && !Array.isArray(cfg.includes))
21
- return "includes must be an array";
22
- if (cfg.excludes && !Array.isArray(cfg.excludes))
23
- return "excludes must be an array";
24
- return null;
25
- }
26
- async function selectConfig(configs) {
27
- if (configs.length === 0) {
28
- throw new Error("No valid deploy configs found");
29
- }
30
- if (configs.length === 1) {
31
- console.log(`Using deploy config: ${configs[0].name}`);
32
- return configs[0];
33
- }
34
- if (!process_1.stdin.isTTY) {
35
- throw new Error(`Found ${configs.length} deploy configs (${configs.map(c => c.name).join(", ")}) but stdin is not a TTY — ` +
36
- `cannot prompt for a choice. Pass a specific config explicitly, e.g. Deploy("deploy/<name>.json").`);
37
- }
38
- console.log("\nAvailable deploy configs:\n");
39
- configs.forEach((config, index) => {
40
- console.log(`[${index + 1}] ${config.name ?? "bad-config-file"}`);
41
- });
42
- const rl = (0, promises_1.createInterface)({
43
- input: process_1.stdin,
44
- output: process_1.stdout,
45
- });
46
- try {
47
- while (true) {
48
- const answer = await rl.question(`\nChoose config [1-${configs.length}]: `);
49
- const selectedIndex = Number.parseInt(answer.trim(), 10) - 1;
50
- if (Number.isInteger(selectedIndex) &&
51
- selectedIndex >= 0 &&
52
- selectedIndex < configs.length) {
53
- return configs[selectedIndex];
54
- }
55
- console.error(`Invalid selection. Enter a number from 1 to ${configs.length}.`);
56
- }
57
- }
58
- finally {
59
- rl.close();
60
- }
61
- }
13
+ const resolveConfig_1 = require("./resolveConfig");
62
14
  async function Deploy(opt) {
63
- if (!opt) {
64
- const dir = path_1.default.resolve("deploy");
65
- const single = path_1.default.resolve("deploy.json");
66
- if (fs_1.default.existsSync(dir) && fs_1.default.statSync(dir).isDirectory()) {
67
- const files = fs_1.default.readdirSync(dir).filter(f => f.endsWith(".json"));
68
- if (files.length === 0)
69
- throw new Error(`No .json configs found in ${dir}`);
70
- const configs = [];
71
- for (const f of files) {
72
- const filePath = path_1.default.resolve(dir, f);
73
- let parsed;
74
- try {
75
- parsed = JSON.parse(fs_1.default.readFileSync(filePath).toString("utf-8"));
76
- }
77
- catch (e) {
78
- console.error(`Skipping ${f}: failed to parse JSON:`, e.message);
79
- continue;
80
- }
81
- const reason = validateConfig(parsed);
82
- if (reason) {
83
- console.error(`Skipping ${f}: ${reason}`);
84
- continue;
85
- }
86
- configs.push(parsed);
87
- }
88
- if (configs.length === 0)
89
- throw new Error(`No valid deploy configs in ${dir} (all ${files.length} were skipped)`);
90
- opt = await selectConfig(configs);
91
- }
92
- else if (fs_1.default.existsSync(single)) {
93
- opt = single;
94
- }
95
- else {
96
- throw new Error(`No deploy config found: neither ${dir}/ nor ${single} exists`);
97
- }
98
- }
99
- if (typeof opt === "string") {
100
- if (!fs_1.default.existsSync(opt)) {
101
- throw new Error(`File not found: ${opt}`);
102
- }
103
- opt = JSON.parse(fs_1.default.readFileSync(opt).toString("utf-8"));
104
- }
105
- const invalidReason = validateConfig(opt);
106
- if (invalidReason) {
107
- throw new Error(`Invalid deploy config: ${invalidReason}`);
108
- }
15
+ opt = await (0, resolveConfig_1.resolveConfig)(opt);
109
16
  const archiveName = __1.UID.sha256(opt.name.replaceAll(".", "_")) + ".tar.gz";
110
17
  console.log("Changing Config to live");
111
18
  const config = path_1.default.resolve("src", "Config.ts");
@@ -365,7 +272,6 @@ async function Deploy(opt) {
365
272
  console.log("");
366
273
  return archiveName;
367
274
  }
368
- exports.Deploy = Deploy;
369
275
  function run(cmd) {
370
276
  try {
371
277
  return (0, child_process_1.execSync)(cmd, { encoding: "utf-8" });
@@ -32,14 +32,14 @@ export declare const REQ_DEPLOYMENT_PROCEED: Req<{
32
32
  };
33
33
  }, any>;
34
34
  export declare const REQ_DEPLOYMENT_SWITCH: Req<{
35
- auth?: string | undefined;
35
+ auth?: string;
36
36
  name: string;
37
37
  token: string;
38
- scheme?: "blue" | "green" | undefined;
38
+ scheme?: "blue" | "green";
39
39
  }, any>;
40
40
  export declare const REQ_DEPLOYMENT_STATUS: Req<{
41
- auth?: string | undefined;
42
- name?: string | undefined;
41
+ auth?: string;
42
+ name?: string;
43
43
  }, any>;
44
44
  export declare class DeployerService extends BaseService {
45
45
  options: IDeployerServiceOptions;
@@ -68,6 +68,7 @@ export declare class DeployerService extends BaseService {
68
68
  };
69
69
  data?: undefined;
70
70
  } | {
71
+ error?: undefined;
71
72
  data: {
72
73
  ok: boolean;
73
74
  project: string;
@@ -76,7 +77,6 @@ export declare class DeployerService extends BaseService {
76
77
  active: "blue" | "green" | null;
77
78
  activeThisDeploy: boolean;
78
79
  };
79
- error?: undefined;
80
80
  }>;
81
81
  switchSlot(data: {
82
82
  auth?: string;
@@ -84,38 +84,38 @@ export declare class DeployerService extends BaseService {
84
84
  token: string;
85
85
  scheme?: "blue" | "green";
86
86
  }): Promise<{
87
+ data?: undefined;
87
88
  error: {
88
89
  code: number;
89
90
  message: string;
90
91
  httpStatus: number;
91
92
  };
92
- data?: undefined;
93
93
  } | {
94
+ error?: undefined;
94
95
  data: {
95
96
  active: "blue" | "green";
96
97
  previousActive: "blue" | "green";
97
98
  action: "rollback" | "switch";
98
99
  hookError: string | null;
99
100
  };
100
- error?: undefined;
101
101
  }>;
102
102
  status(data: {
103
103
  auth?: string;
104
104
  name?: string;
105
105
  }): Promise<{
106
+ data?: undefined;
106
107
  error: {
107
108
  code: number;
108
109
  message: string;
109
110
  httpStatus: number;
110
111
  };
111
- data?: undefined;
112
112
  } | {
113
+ error?: undefined;
113
114
  data: Record<string, {
114
115
  hasBlueGreen: boolean;
115
116
  state: IProjectState | null;
116
117
  readyToSwitch: boolean;
117
118
  }>;
118
- error?: undefined;
119
119
  }>;
120
120
  tokensMatch(a: string | undefined, b: string | undefined): boolean;
121
121
  private _checkUserAuth;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const Deploy_1 = require("./Deploy");
5
+ const Activate_1 = require("./Activate");
6
+ function usage() {
7
+ console.error("Usage:");
8
+ console.error(" badmfck deploy [config.json] — build + upload the current project");
9
+ console.error(" badmfck activate [config.json] [blue|green] — switch blue-green slot (omit slot for lastDeployed)");
10
+ console.error("");
11
+ console.error("Config path is optional (auto-discovers deploy/ folder → deploy.json when omitted).");
12
+ console.error("Via npm, prefix args with -- e.g. npm run deploy -- deploy/custom.json");
13
+ process.exit(1);
14
+ }
15
+ function parseArgs(args) {
16
+ let scheme;
17
+ let config;
18
+ for (const a of args) {
19
+ if (a === "blue" || a === "green") {
20
+ if (scheme) {
21
+ console.error(`Slot specified twice ("${scheme}" and "${a}").`);
22
+ process.exit(1);
23
+ }
24
+ scheme = a;
25
+ }
26
+ else {
27
+ if (config) {
28
+ console.error(`Config path specified twice ("${config}" and "${a}").`);
29
+ process.exit(1);
30
+ }
31
+ config = a;
32
+ }
33
+ }
34
+ return { scheme, config };
35
+ }
36
+ async function main() {
37
+ const command = process.argv[2];
38
+ const rest = process.argv.slice(3);
39
+ switch (command) {
40
+ case "deploy": {
41
+ const { scheme, config } = parseArgs(rest);
42
+ if (scheme) {
43
+ console.error(`"deploy" does not take a slot argument ("${scheme}").`);
44
+ process.exit(1);
45
+ }
46
+ await (0, Deploy_1.Deploy)(config);
47
+ break;
48
+ }
49
+ case "activate": {
50
+ const { scheme, config } = parseArgs(rest);
51
+ await (0, Activate_1.Activate)(config, scheme);
52
+ break;
53
+ }
54
+ default:
55
+ if (command)
56
+ console.error(`Unknown command: ${command}\n`);
57
+ usage();
58
+ }
59
+ }
60
+ main().catch((err) => {
61
+ console.error("\n" + (err instanceof Error ? err.message : String(err)));
62
+ process.exit(1);
63
+ });
@@ -0,0 +1,12 @@
1
+ export interface IDeployerConfig {
2
+ name: string;
3
+ token: string;
4
+ host: string;
5
+ username: string;
6
+ password: string;
7
+ includes?: string[];
8
+ excludes?: string[];
9
+ switch_host?: string;
10
+ }
11
+ export declare function validateConfig(cfg: any): string | null;
12
+ export declare function resolveConfig(opt?: IDeployerConfig | string | null): Promise<IDeployerConfig>;
@@ -0,0 +1,104 @@
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.validateConfig = validateConfig;
7
+ exports.resolveConfig = resolveConfig;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const promises_1 = require("readline/promises");
11
+ const process_1 = require("process");
12
+ function validateConfig(cfg) {
13
+ if (!cfg || typeof cfg !== "object")
14
+ return "not an object";
15
+ if (!cfg.name || !cfg.token || !cfg.host || !cfg.username || !cfg.password)
16
+ return "missing one of: name, token, host, username, password";
17
+ if (cfg.includes && !Array.isArray(cfg.includes))
18
+ return "includes must be an array";
19
+ if (cfg.excludes && !Array.isArray(cfg.excludes))
20
+ return "excludes must be an array";
21
+ if (cfg.switch_host && typeof cfg.switch_host !== "string")
22
+ return "switch_host must be a string";
23
+ return null;
24
+ }
25
+ async function selectConfig(configs) {
26
+ if (configs.length === 0) {
27
+ throw new Error("No valid deploy configs found");
28
+ }
29
+ if (configs.length === 1) {
30
+ console.log(`Using deploy config: ${configs[0].name}`);
31
+ return configs[0];
32
+ }
33
+ if (!process_1.stdin.isTTY) {
34
+ throw new Error(`Found ${configs.length} deploy configs (${configs.map(c => c.name).join(", ")}) but stdin is not a TTY — ` +
35
+ `cannot prompt for a choice. Pass a specific config explicitly, e.g. "deploy/<name>.json".`);
36
+ }
37
+ console.log("\nAvailable deploy configs:\n");
38
+ configs.forEach((config, index) => {
39
+ console.log(`[${index + 1}] ${config.name ?? "bad-config-file"}`);
40
+ });
41
+ const rl = (0, promises_1.createInterface)({ input: process_1.stdin, output: process_1.stdout });
42
+ try {
43
+ while (true) {
44
+ const answer = await rl.question(`\nChoose config [1-${configs.length}]: `);
45
+ const selectedIndex = Number.parseInt(answer.trim(), 10) - 1;
46
+ if (Number.isInteger(selectedIndex) && selectedIndex >= 0 && selectedIndex < configs.length) {
47
+ return configs[selectedIndex];
48
+ }
49
+ console.error(`Invalid selection. Enter a number from 1 to ${configs.length}.`);
50
+ }
51
+ }
52
+ finally {
53
+ rl.close();
54
+ }
55
+ }
56
+ async function resolveConfig(opt) {
57
+ if (!opt) {
58
+ const dir = path_1.default.resolve("deploy");
59
+ const single = path_1.default.resolve("deploy.json");
60
+ if (fs_1.default.existsSync(dir) && fs_1.default.statSync(dir).isDirectory()) {
61
+ const files = fs_1.default.readdirSync(dir).filter(f => f.endsWith(".json"));
62
+ if (files.length === 0)
63
+ throw new Error(`No .json configs found in ${dir}`);
64
+ const configs = [];
65
+ for (const f of files) {
66
+ const filePath = path_1.default.resolve(dir, f);
67
+ let parsed;
68
+ try {
69
+ parsed = JSON.parse(fs_1.default.readFileSync(filePath).toString("utf-8"));
70
+ }
71
+ catch (e) {
72
+ console.error(`Skipping ${f}: failed to parse JSON:`, e.message);
73
+ continue;
74
+ }
75
+ const reason = validateConfig(parsed);
76
+ if (reason) {
77
+ console.error(`Skipping ${f}: ${reason}`);
78
+ continue;
79
+ }
80
+ configs.push(parsed);
81
+ }
82
+ if (configs.length === 0)
83
+ throw new Error(`No valid deploy configs in ${dir} (all ${files.length} were skipped)`);
84
+ opt = await selectConfig(configs);
85
+ }
86
+ else if (fs_1.default.existsSync(single)) {
87
+ opt = single;
88
+ }
89
+ else {
90
+ throw new Error(`No deploy config found: neither ${dir}/ nor ${single} exists`);
91
+ }
92
+ }
93
+ if (typeof opt === "string") {
94
+ if (!fs_1.default.existsSync(opt)) {
95
+ throw new Error(`Config file not found: ${opt}`);
96
+ }
97
+ opt = JSON.parse(fs_1.default.readFileSync(opt).toString("utf-8"));
98
+ }
99
+ const invalidReason = validateConfig(opt);
100
+ if (invalidReason) {
101
+ throw new Error(`Invalid deploy config: ${invalidReason}`);
102
+ }
103
+ return opt;
104
+ }