@bmfk/api 0.0.0-stage → 1.0.0
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/CHANGELOG.md +83 -0
- package/LICENSE +21 -0
- package/README.md +1293 -2
- package/dist/apiServer/APIService.d.ts +125 -0
- package/dist/apiServer/APIService.js +769 -0
- package/dist/apiServer/BaseEndpoint.d.ts +90 -0
- package/dist/apiServer/BaseEndpoint.js +314 -0
- package/dist/apiServer/BaseService.d.ts +17 -0
- package/dist/apiServer/BaseService.js +39 -0
- package/dist/apiServer/DBService.d.ts +131 -0
- package/dist/apiServer/DBService.js +290 -0
- package/dist/apiServer/DocumentService.d.ts +9 -0
- package/dist/apiServer/DocumentService.js +65 -0
- package/dist/apiServer/LocalRequest.d.ts +3 -0
- package/dist/apiServer/LocalRequest.js +6 -0
- package/dist/apiServer/LogService.d.ts +78 -0
- package/dist/apiServer/LogService.js +349 -0
- package/dist/apiServer/MonitorService.d.ts +102 -0
- package/dist/apiServer/MonitorService.js +615 -0
- package/dist/apiServer/StatService.d.ts +4 -0
- package/dist/apiServer/StatService.js +10 -0
- package/dist/apiServer/TimeframeService.d.ts +28 -0
- package/dist/apiServer/TimeframeService.js +97 -0
- package/dist/apiServer/WebSocketServer.d.ts +39 -0
- package/dist/apiServer/WebSocketServer.js +173 -0
- package/dist/apiServer/db/IDBAdapter.d.ts +14 -0
- package/dist/apiServer/db/IDBAdapter.js +2 -0
- package/dist/apiServer/db/MysqlAdapter.d.ts +72 -0
- package/dist/apiServer/db/MysqlAdapter.js +869 -0
- package/dist/apiServer/db/PostgresAdapter.d.ts +41 -0
- package/dist/apiServer/db/PostgresAdapter.js +73 -0
- package/dist/apiServer/deployment/AccessConfigWizard.d.ts +5 -0
- package/dist/apiServer/deployment/AccessConfigWizard.js +254 -0
- package/dist/apiServer/deployment/Activate.d.ts +4 -0
- package/dist/apiServer/deployment/Activate.js +124 -0
- package/dist/apiServer/deployment/BackupManager.d.ts +33 -0
- package/dist/apiServer/deployment/BackupManager.js +174 -0
- package/dist/apiServer/deployment/Backups.d.ts +2 -0
- package/dist/apiServer/deployment/Backups.js +44 -0
- package/dist/apiServer/deployment/BlueGreenState.d.ts +31 -0
- package/dist/apiServer/deployment/BlueGreenState.js +150 -0
- package/dist/apiServer/deployment/Bundler.d.ts +12 -0
- package/dist/apiServer/deployment/Bundler.js +178 -0
- package/dist/apiServer/deployment/ConfigService.d.ts +203 -0
- package/dist/apiServer/deployment/ConfigService.js +195 -0
- package/dist/apiServer/deployment/Deploy.d.ts +4 -0
- package/dist/apiServer/deployment/Deploy.js +404 -0
- package/dist/apiServer/deployment/DeployKeyWizard.d.ts +2 -0
- package/dist/apiServer/deployment/DeployKeyWizard.js +84 -0
- package/dist/apiServer/deployment/Deployer.d.ts +13 -0
- package/dist/apiServer/deployment/Deployer.js +96 -0
- package/dist/apiServer/deployment/DeployerInit.d.ts +25 -0
- package/dist/apiServer/deployment/DeployerInit.js +214 -0
- package/dist/apiServer/deployment/DeployerService.d.ts +378 -0
- package/dist/apiServer/deployment/DeployerService.js +1553 -0
- package/dist/apiServer/deployment/HashPassword.d.ts +3 -0
- package/dist/apiServer/deployment/HashPassword.js +126 -0
- package/dist/apiServer/deployment/MigrateConfigsWizard.d.ts +1 -0
- package/dist/apiServer/deployment/MigrateConfigsWizard.js +202 -0
- package/dist/apiServer/deployment/MigrateProject.d.ts +31 -0
- package/dist/apiServer/deployment/MigrateProject.js +335 -0
- package/dist/apiServer/deployment/NginxHelper.d.ts +10 -0
- package/dist/apiServer/deployment/NginxHelper.js +111 -0
- package/dist/apiServer/deployment/Notifier.d.ts +30 -0
- package/dist/apiServer/deployment/Notifier.js +82 -0
- package/dist/apiServer/deployment/ProjectConfigWizard.d.ts +1 -0
- package/dist/apiServer/deployment/ProjectConfigWizard.js +148 -0
- package/dist/apiServer/deployment/Restore.d.ts +2 -0
- package/dist/apiServer/deployment/Restore.js +89 -0
- package/dist/apiServer/deployment/ReviewStore.d.ts +62 -0
- package/dist/apiServer/deployment/ReviewStore.js +186 -0
- package/dist/apiServer/deployment/SecretsInjector.d.ts +21 -0
- package/dist/apiServer/deployment/SecretsInjector.js +189 -0
- package/dist/apiServer/deployment/SetupConfigWizard.d.ts +1 -0
- package/dist/apiServer/deployment/SetupConfigWizard.js +238 -0
- package/dist/apiServer/deployment/Status.d.ts +2 -0
- package/dist/apiServer/deployment/Status.js +83 -0
- package/dist/apiServer/deployment/TelegramNotifier.d.ts +8 -0
- package/dist/apiServer/deployment/TelegramNotifier.js +23 -0
- package/dist/apiServer/deployment/Watchdog.d.ts +15 -0
- package/dist/apiServer/deployment/Watchdog.js +65 -0
- package/dist/apiServer/deployment/Wizards.d.ts +1 -0
- package/dist/apiServer/deployment/Wizards.js +83 -0
- package/dist/apiServer/deployment/cli.d.ts +2 -0
- package/dist/apiServer/deployment/cli.js +224 -0
- package/dist/apiServer/deployment/cliCommon.d.ts +27 -0
- package/dist/apiServer/deployment/cliCommon.js +110 -0
- package/dist/apiServer/deployment/cliPrompt.d.ts +5 -0
- package/dist/apiServer/deployment/cliPrompt.js +38 -0
- package/dist/apiServer/deployment/resolveConfig.d.ts +19 -0
- package/dist/apiServer/deployment/resolveConfig.js +139 -0
- package/dist/apiServer/documentation/Documentation.d.ts +18 -0
- package/dist/apiServer/documentation/Documentation.js +143 -0
- package/dist/apiServer/documentation/index.html +460 -0
- package/dist/apiServer/external/MicroserviceClient.d.ts +28 -0
- package/dist/apiServer/external/MicroserviceClient.js +144 -0
- package/dist/apiServer/external/MicroserviceHost.d.ts +52 -0
- package/dist/apiServer/external/MicroserviceHost.js +183 -0
- package/dist/apiServer/external/MicroserviceHostController.d.ts +6 -0
- package/dist/apiServer/external/MicroserviceHostController.js +65 -0
- package/dist/apiServer/helper/AppDataPath.d.ts +9 -0
- package/dist/apiServer/helper/AppDataPath.js +81 -0
- package/dist/apiServer/helper/ClientIp.d.ts +3 -0
- package/dist/apiServer/helper/ClientIp.js +33 -0
- package/dist/apiServer/helper/DataProvider.d.ts +18 -0
- package/dist/apiServer/helper/DataProvider.js +57 -0
- package/dist/apiServer/helper/IpAllowList.d.ts +8 -0
- package/dist/apiServer/helper/IpAllowList.js +40 -0
- package/dist/apiServer/helper/JSONStableStringify.d.ts +1 -0
- package/dist/apiServer/helper/JSONStableStringify.js +15 -0
- package/dist/apiServer/helper/PasswordHash.d.ts +5 -0
- package/dist/apiServer/helper/PasswordHash.js +52 -0
- package/dist/apiServer/helper/Sleep.d.ts +1 -0
- package/dist/apiServer/helper/Sleep.js +5 -0
- package/dist/apiServer/helper/Trace.d.ts +8 -0
- package/dist/apiServer/helper/Trace.js +30 -0
- package/dist/apiServer/helper/UID.d.ts +16 -0
- package/dist/apiServer/helper/UID.js +98 -0
- package/dist/apiServer/helper/Validator.d.ts +86 -0
- package/dist/apiServer/helper/Validator.js +560 -0
- package/dist/apiServer/helper/YYYYMMDDHH.d.ts +2 -0
- package/dist/apiServer/helper/YYYYMMDDHH.js +31 -0
- package/dist/apiServer/helper/ZipUtils.d.ts +6 -0
- package/dist/apiServer/helper/ZipUtils.js +28 -0
- package/dist/apiServer/http/Http.d.ts +183 -0
- package/dist/apiServer/http/Http.js +627 -0
- package/dist/apiServer/interceptors/InterceptorPayAuth.d.ts +19 -0
- package/dist/apiServer/interceptors/InterceptorPayAuth.js +124 -0
- package/dist/apiServer/interceptors/InterceptorSignedAuth.d.ts +40 -0
- package/dist/apiServer/interceptors/InterceptorSignedAuth.js +150 -0
- package/dist/apiServer/monitor/AccessStore.d.ts +27 -0
- package/dist/apiServer/monitor/AccessStore.js +163 -0
- package/dist/apiServer/monitor/LogFiles.d.ts +34 -0
- package/dist/apiServer/monitor/LogFiles.js +109 -0
- package/dist/apiServer/monitor/Monitor.d.ts +54 -0
- package/dist/apiServer/monitor/Monitor.js +447 -0
- package/dist/apiServer/monitor/MonitorAuth.d.ts +87 -0
- package/dist/apiServer/monitor/MonitorAuth.js +474 -0
- package/dist/apiServer/monitor/ProcessMonitor.d.ts +177 -0
- package/dist/apiServer/monitor/ProcessMonitor.js +468 -0
- package/dist/apiServer/monitor/SystemInfo.d.ts +70 -0
- package/dist/apiServer/monitor/SystemInfo.js +217 -0
- package/dist/apiServer/monitor/ThreatMonitor.d.ts +73 -0
- package/dist/apiServer/monitor/ThreatMonitor.js +239 -0
- package/dist/apiServer/monitor/index.html +591 -0
- package/dist/apiServer/review/Review.d.ts +23 -0
- package/dist/apiServer/review/Review.js +149 -0
- package/dist/apiServer/review/ReviewAuth.d.ts +56 -0
- package/dist/apiServer/review/ReviewAuth.js +147 -0
- package/dist/apiServer/review/ReviewDiff.d.ts +43 -0
- package/dist/apiServer/review/ReviewDiff.js +175 -0
- package/dist/apiServer/review/index.html +501 -0
- package/dist/apiServer/routes/Liveness.d.ts +7 -0
- package/dist/apiServer/routes/Liveness.js +27 -0
- package/dist/apiServer/routes/Readiness.d.ts +13 -0
- package/dist/apiServer/routes/Readiness.js +20 -0
- package/dist/apiServer/security/BlockedIps.d.ts +46 -0
- package/dist/apiServer/security/BlockedIps.js +185 -0
- package/dist/apiServer/structures/DefaultErrors.d.ts +36 -0
- package/dist/apiServer/structures/DefaultErrors.js +52 -0
- package/dist/apiServer/structures/HTTPStatus.d.ts +7 -0
- package/dist/apiServer/structures/HTTPStatus.js +11 -0
- package/dist/apiServer/structures/Interfaces.d.ts +55 -0
- package/dist/apiServer/structures/Interfaces.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +110 -0
- package/dist/signal/Signal.d.ts +23 -0
- package/dist/signal/Signal.js +85 -0
- package/package.json +88 -4
|
@@ -0,0 +1,404 @@
|
|
|
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.Deploy = Deploy;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const UID_1 = require("../helper/UID");
|
|
11
|
+
const DefaultErrors_1 = require("../structures/DefaultErrors");
|
|
12
|
+
const Http_1 = require("../http/Http");
|
|
13
|
+
const os_1 = __importDefault(require("os"));
|
|
14
|
+
const undici_1 = require("undici");
|
|
15
|
+
const resolveConfig_1 = require("./resolveConfig");
|
|
16
|
+
const cliCommon_1 = require("./cliCommon");
|
|
17
|
+
const InterceptorSignedAuth_1 = require("../interceptors/InterceptorSignedAuth");
|
|
18
|
+
const Bundler_1 = require("./Bundler");
|
|
19
|
+
async function Deploy(opt) {
|
|
20
|
+
opt = await (0, resolveConfig_1.resolveConfig)(opt);
|
|
21
|
+
const archiveName = UID_1.UID.sha256(opt.name.replaceAll(".", "_")) + ".tar.gz";
|
|
22
|
+
const { red, green, yellow, dim, bold } = (0, cliCommon_1.palette)();
|
|
23
|
+
const line = dim("─".repeat(60));
|
|
24
|
+
const log = (0, cliCommon_1.stepLog)();
|
|
25
|
+
console.log("");
|
|
26
|
+
console.log(`${bold("▸ DEPLOY")} ${bold(opt.name)} ${dim("→")} ${opt.host}`);
|
|
27
|
+
console.log(line);
|
|
28
|
+
const config = path_1.default.resolve("src", "Config.ts");
|
|
29
|
+
if (!fs_1.default.existsSync(config)) {
|
|
30
|
+
log.skip("config", "src/Config.ts not found — scheme switch skipped");
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const configSrc = fs_1.default.readFileSync(config).toString("utf-8");
|
|
34
|
+
const schemeRe = /(\bscheme\s*:\s*Scheme\s*=\s*)local\b/g;
|
|
35
|
+
let replaced = 0;
|
|
36
|
+
const updated = configSrc.replace(schemeRe, (_match, prefix) => {
|
|
37
|
+
replaced++;
|
|
38
|
+
return prefix + "live";
|
|
39
|
+
});
|
|
40
|
+
if (replaced > 0) {
|
|
41
|
+
fs_1.default.writeFileSync(config, updated);
|
|
42
|
+
log.ok("config", `switched to live (${replaced} occurrence${replaced === 1 ? "" : "s"})`);
|
|
43
|
+
}
|
|
44
|
+
else if (/\bscheme\s*:\s*Scheme\s*=\s*live\b/.test(configSrc)) {
|
|
45
|
+
log.ok("config", "already live");
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
log.warn("config", "no 'scheme: Scheme = local|live' pattern found in " + config +
|
|
49
|
+
" — check the file was not renamed/restructured");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const pkgPath = path_1.default.resolve("package.json");
|
|
53
|
+
const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath).toString("utf-8"));
|
|
54
|
+
const oldVersion = String(pkg.version || "0.0.0");
|
|
55
|
+
const pkgName = String(pkg.name || opt.name);
|
|
56
|
+
let newVersion = oldVersion;
|
|
57
|
+
if (opt.versionBump !== false) {
|
|
58
|
+
const parts = oldVersion.split(".").map(p => parseInt(p, 10) || 0);
|
|
59
|
+
while (parts.length < 3)
|
|
60
|
+
parts.push(0);
|
|
61
|
+
parts[parts.length - 1] += 1;
|
|
62
|
+
newVersion = parts.join(".");
|
|
63
|
+
pkg.version = newVersion;
|
|
64
|
+
fs_1.default.writeFileSync(pkgPath, JSON.stringify(pkg, null, "\t") + "\n");
|
|
65
|
+
log.ok("version", `${oldVersion} ${dim("→")} ${bold(newVersion)}`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
log.ok("version", `${oldVersion} ${dim("(not bumped: versionBump false)")}`);
|
|
69
|
+
}
|
|
70
|
+
if (fs_1.default.existsSync(path_1.default.resolve(archiveName))) {
|
|
71
|
+
fs_1.default.rmSync(path_1.default.resolve(archiveName));
|
|
72
|
+
}
|
|
73
|
+
const buildStep = log.start("build", "npm run build");
|
|
74
|
+
const build = await exec("npm run build");
|
|
75
|
+
if (build.code !== 0) {
|
|
76
|
+
buildStep.fail(`npm run build failed (exit code ${build.code})`);
|
|
77
|
+
const out = (build.stdout.trim() + "\n" + build.stderr.trim()).trim();
|
|
78
|
+
if (out)
|
|
79
|
+
console.error("\n" + out + "\n");
|
|
80
|
+
process.exit(build.code);
|
|
81
|
+
}
|
|
82
|
+
buildStep.ok();
|
|
83
|
+
for (const l of build.stderr.split(/\r?\n/))
|
|
84
|
+
if (l.trim())
|
|
85
|
+
log.note(l);
|
|
86
|
+
const items = [];
|
|
87
|
+
let spaMode = false;
|
|
88
|
+
const binExists = fs_1.default.existsSync("./bin");
|
|
89
|
+
if (binExists) {
|
|
90
|
+
if (!opt.bundle)
|
|
91
|
+
items.push("./bin");
|
|
92
|
+
if (fs_1.default.existsSync("package.json")) {
|
|
93
|
+
items.push("package.json");
|
|
94
|
+
}
|
|
95
|
+
if (fs_1.default.existsSync("package-lock.json")) {
|
|
96
|
+
items.push("package-lock.json");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (fs_1.default.existsSync("./dist") && fs_1.default.existsSync(path_1.default.resolve("dist", "index.html"))) {
|
|
100
|
+
spaMode = true;
|
|
101
|
+
}
|
|
102
|
+
const staged = [];
|
|
103
|
+
if (Array.isArray(opt.includes)) {
|
|
104
|
+
for (const raw of opt.includes) {
|
|
105
|
+
const inc = typeof raw === "string" ? { src: raw, dest: raw } : raw;
|
|
106
|
+
if (!inc || typeof inc.src !== "string" || inc.src.length === 0)
|
|
107
|
+
continue;
|
|
108
|
+
const src = inc.src;
|
|
109
|
+
const dest = (inc.dest && inc.dest.length > 0 ? inc.dest : src).replace(/^\.\//, "");
|
|
110
|
+
if (src.startsWith("-") || dest.startsWith("-"))
|
|
111
|
+
throw new Error(`Include path must not start with '-': ${src} -> ${dest}`);
|
|
112
|
+
if (!fs_1.default.existsSync(src))
|
|
113
|
+
throw new Error(`Include source does not exist: ${src}`);
|
|
114
|
+
if (path_1.default.isAbsolute(dest) || dest.split(/[\\/]/).includes(".."))
|
|
115
|
+
throw new Error(`Include 'dest' must be a relative path inside the slot, without '..': ${dest}`);
|
|
116
|
+
if (dest === src.replace(/^\.\//, "")) {
|
|
117
|
+
items.push(src);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
staged.push({ src, dest });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const s of staged) {
|
|
124
|
+
const clash = items.some(i => i.replace(/^\.\//, "") === s.dest);
|
|
125
|
+
if (clash)
|
|
126
|
+
log.warn("include", `dest "${s.dest}" collides with an already-archived path — the later entry wins on extraction`);
|
|
127
|
+
}
|
|
128
|
+
if (items.length === 0 && !spaMode && staged.length === 0 && !opt.bundle) {
|
|
129
|
+
throw new Error("Nothing to archive (no ./bin, no ./dist/index.html, no valid includes)");
|
|
130
|
+
}
|
|
131
|
+
const excludes = new Set();
|
|
132
|
+
const addExclude = (raw, source) => {
|
|
133
|
+
if (typeof raw !== "string")
|
|
134
|
+
return;
|
|
135
|
+
const trimmed = raw.trim();
|
|
136
|
+
if (trimmed.length === 0 || trimmed.startsWith("#"))
|
|
137
|
+
return;
|
|
138
|
+
if (trimmed.startsWith("-")) {
|
|
139
|
+
log.warn("exclude", `skipped, starts with '-' (from ${source}): ${trimmed}`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
excludes.add(trimmed);
|
|
143
|
+
};
|
|
144
|
+
addExclude("._*", "built-in");
|
|
145
|
+
addExclude(".DS_Store", "built-in");
|
|
146
|
+
const ignoreFile = path_1.default.resolve(".deployignore");
|
|
147
|
+
if (fs_1.default.existsSync(ignoreFile)) {
|
|
148
|
+
const lines = fs_1.default.readFileSync(ignoreFile, "utf-8").split(/\r?\n/);
|
|
149
|
+
for (const line of lines)
|
|
150
|
+
addExclude(line, ".deployignore");
|
|
151
|
+
}
|
|
152
|
+
if (Array.isArray(opt.excludes)) {
|
|
153
|
+
for (const ex of opt.excludes)
|
|
154
|
+
addExclude(ex, "config.excludes");
|
|
155
|
+
}
|
|
156
|
+
const excludeArgs = Array.from(excludes).map(p => `--exclude=${p}`);
|
|
157
|
+
let bundle = null;
|
|
158
|
+
if (opt.bundle) {
|
|
159
|
+
const minified = typeof opt.bundle === "object" && opt.bundle.minify === true;
|
|
160
|
+
const bundleStep = log.start("bundle", "bundling the project's code into one file");
|
|
161
|
+
try {
|
|
162
|
+
bundle = await (0, Bundler_1.Bundle)(opt.bundle, pkg);
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
bundleStep.fail();
|
|
166
|
+
throw e;
|
|
167
|
+
}
|
|
168
|
+
bundleStep.ok(`${bundle.outFile} ${dim("·")} ${bundle.modules} source files` + (minified ? ` ${dim("·")} minified` : ""));
|
|
169
|
+
for (const w of bundle.warnings)
|
|
170
|
+
log.note(yellow("⚠ " + w));
|
|
171
|
+
}
|
|
172
|
+
const tarArgs = ["-czf", archiveName, ...excludeArgs];
|
|
173
|
+
if (spaMode) {
|
|
174
|
+
tarArgs.push("-C", "./dist", ".");
|
|
175
|
+
if (items.length > 0) {
|
|
176
|
+
tarArgs.push("-C", process.cwd(), ...items);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
if (bundle) {
|
|
181
|
+
tarArgs.push("-C", bundle.stageDir, "bin");
|
|
182
|
+
if (items.length > 0)
|
|
183
|
+
tarArgs.push("-C", process.cwd());
|
|
184
|
+
}
|
|
185
|
+
tarArgs.push(...items);
|
|
186
|
+
}
|
|
187
|
+
let stageDir = null;
|
|
188
|
+
const relocated = [];
|
|
189
|
+
if (staged.length > 0) {
|
|
190
|
+
stageDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "bmfk-deploy-"));
|
|
191
|
+
for (const { src, dest } of staged) {
|
|
192
|
+
const target = path_1.default.join(stageDir, dest);
|
|
193
|
+
fs_1.default.mkdirSync(path_1.default.dirname(target), { recursive: true });
|
|
194
|
+
fs_1.default.cpSync(path_1.default.resolve(src), target, { recursive: true });
|
|
195
|
+
relocated.push(`${src} → ${dest}`);
|
|
196
|
+
}
|
|
197
|
+
tarArgs.push("-C", stageDir, ".");
|
|
198
|
+
}
|
|
199
|
+
const archived = [
|
|
200
|
+
...(spaMode ? ["contents of ./dist (at archive root)"] : []),
|
|
201
|
+
...(bundle ? ["bin (bundle)"] : []),
|
|
202
|
+
...items.map(i => i.replace(/^\.\//, "")),
|
|
203
|
+
];
|
|
204
|
+
const archiveStep = log.start("archive", archived.join(", "));
|
|
205
|
+
try {
|
|
206
|
+
(0, child_process_1.execFileSync)("tar", tarArgs, {
|
|
207
|
+
encoding: "utf-8",
|
|
208
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
209
|
+
env: { ...process.env, COPYFILE_DISABLE: "1" },
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
archiveStep.fail(`tar failed while creating ${archiveName}`);
|
|
214
|
+
const out = (err.stdout || "").toString().trim();
|
|
215
|
+
const errOut = (err.stderr || "").toString().trim();
|
|
216
|
+
if (out)
|
|
217
|
+
console.error(out);
|
|
218
|
+
if (errOut)
|
|
219
|
+
console.error(errOut);
|
|
220
|
+
process.exit(typeof err.status === "number" ? err.status : 1);
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
for (const dir of [stageDir, bundle?.stageDir]) {
|
|
224
|
+
if (!dir)
|
|
225
|
+
continue;
|
|
226
|
+
try {
|
|
227
|
+
fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
228
|
+
}
|
|
229
|
+
catch (e) {
|
|
230
|
+
console.warn(`Could not remove staging dir ${dir}: ${e?.message ?? e}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!fs_1.default.existsSync(path_1.default.resolve(archiveName))) {
|
|
235
|
+
archiveStep.fail("archive was not created");
|
|
236
|
+
return "";
|
|
237
|
+
}
|
|
238
|
+
const archiveSize = (0, cliCommon_1.fmtSize)(Math.max(1, Math.round(fs_1.default.statSync(path_1.default.resolve(archiveName)).size / 1024)));
|
|
239
|
+
archiveStep.ok(`${countFiles(archiveName)} files ${dim("·")} ${archiveSize}`);
|
|
240
|
+
log.note(archived.join(", "));
|
|
241
|
+
for (const r of relocated)
|
|
242
|
+
log.note("include: " + r);
|
|
243
|
+
const ownExcludes = Array.from(excludes).filter(e => e !== "._*" && e !== ".DS_Store");
|
|
244
|
+
if (ownExcludes.length > 0)
|
|
245
|
+
log.note("excluded: " + ownExcludes.join(", "));
|
|
246
|
+
const archivePath = path_1.default.resolve(archiveName);
|
|
247
|
+
const signedFields = { token: opt.token, name: opt.name };
|
|
248
|
+
const uploadHeaders = (0, cliCommon_1.deployerHeaders)(opt, opt.host, signedFields, opt.privateKey ? { file: await InterceptorSignedAuth_1.InterceptorSignedAuth.sha256File(archivePath) } : undefined);
|
|
249
|
+
const fileBlob = await fs_1.default.openAsBlob(archivePath);
|
|
250
|
+
const formData = new FormData();
|
|
251
|
+
formData.set("token", opt.token);
|
|
252
|
+
formData.set("name", opt.name);
|
|
253
|
+
formData.set("file", fileBlob, archiveName);
|
|
254
|
+
const uploadStep = log.start("upload", `${archiveSize} ${dim("·")} the server unpacks, installs and restarts`);
|
|
255
|
+
const startedAt = Date.now();
|
|
256
|
+
const uploadAgent = new undici_1.Agent({
|
|
257
|
+
headersTimeout: 5 * 60 * 1000,
|
|
258
|
+
bodyTimeout: 5 * 60 * 1000,
|
|
259
|
+
});
|
|
260
|
+
const uploadResponse = await Http_1.Http.post(opt.host, formData, {
|
|
261
|
+
headers: uploadHeaders,
|
|
262
|
+
dispatcher: uploadAgent,
|
|
263
|
+
timeoutMs: 5 * 60 * 1000,
|
|
264
|
+
retry: { enabled: false },
|
|
265
|
+
});
|
|
266
|
+
const elapsedMs = Date.now() - startedAt;
|
|
267
|
+
if (uploadResponse.ok)
|
|
268
|
+
uploadStep.ok(`${archiveSize} sent, server answered`);
|
|
269
|
+
else
|
|
270
|
+
uploadStep.fail("no successful answer from the server");
|
|
271
|
+
const deployedAt = new Date();
|
|
272
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
273
|
+
const stamp = `${deployedAt.getFullYear()}-${pad(deployedAt.getMonth() + 1)}-${pad(deployedAt.getDate())} ${pad(deployedAt.getHours())}:${pad(deployedAt.getMinutes())}:${pad(deployedAt.getSeconds())}`;
|
|
274
|
+
console.log("");
|
|
275
|
+
if (!uploadResponse.ok) {
|
|
276
|
+
const statusStr = uploadResponse.status !== undefined
|
|
277
|
+
? `HTTP ${uploadResponse.status}`
|
|
278
|
+
: "network error (no response)";
|
|
279
|
+
console.error(red(bold("✗ DEPLOY FAILED — transport error")));
|
|
280
|
+
console.error(line);
|
|
281
|
+
console.error(` ${dim("host: ")} ${opt.host}`);
|
|
282
|
+
console.error(` ${dim("status: ")} ${statusStr}`);
|
|
283
|
+
console.error(` ${dim("elapsed: ")} ${elapsedMs}ms`);
|
|
284
|
+
if (uploadResponse.error !== undefined) {
|
|
285
|
+
const errText = typeof uploadResponse.error === "string"
|
|
286
|
+
? uploadResponse.error
|
|
287
|
+
: JSON.stringify(uploadResponse.error);
|
|
288
|
+
const clipped = errText.length > 400 ? errText.slice(0, 400) + `... (${errText.length} total)` : errText;
|
|
289
|
+
console.error(` ${dim("error: ")} ${clipped}`);
|
|
290
|
+
}
|
|
291
|
+
console.error(line);
|
|
292
|
+
process.exit(1);
|
|
293
|
+
}
|
|
294
|
+
const body = uploadResponse.data;
|
|
295
|
+
let appError = null;
|
|
296
|
+
if (body && typeof body === "object") {
|
|
297
|
+
if (DefaultErrors_1.ErrorUtils.isError(body?.error))
|
|
298
|
+
appError = body.error;
|
|
299
|
+
else if (DefaultErrors_1.ErrorUtils.isError(body?.data?.error))
|
|
300
|
+
appError = body.data.error;
|
|
301
|
+
else if (DefaultErrors_1.ErrorUtils.isError(body?.data))
|
|
302
|
+
appError = body.data;
|
|
303
|
+
else if (DefaultErrors_1.ErrorUtils.isError(body))
|
|
304
|
+
appError = body;
|
|
305
|
+
}
|
|
306
|
+
if (appError) {
|
|
307
|
+
console.error(red(bold("✗ DEPLOY REJECTED BY SERVER")));
|
|
308
|
+
console.error(line);
|
|
309
|
+
console.error(` ${dim("host: ")} ${opt.host}`);
|
|
310
|
+
console.error(` ${dim("code: ")} ${appError.code}`);
|
|
311
|
+
console.error(` ${dim("message: ")} ${appError.message}`);
|
|
312
|
+
if (appError.httpStatus)
|
|
313
|
+
console.error(` ${dim("httpCode: ")} ${appError.httpStatus}`);
|
|
314
|
+
if (appError.details !== undefined) {
|
|
315
|
+
const d = typeof appError.details === "string" ? appError.details : JSON.stringify(appError.details);
|
|
316
|
+
const clipped = d.length > 400 ? d.slice(0, 400) + `... (${d.length} total)` : d;
|
|
317
|
+
console.error(` ${dim("details: ")} ${clipped}`);
|
|
318
|
+
}
|
|
319
|
+
console.error(` ${dim("elapsed: ")} ${elapsedMs}ms`);
|
|
320
|
+
console.error(line);
|
|
321
|
+
process.exit(1);
|
|
322
|
+
}
|
|
323
|
+
const emptyResponse = body === null || body === undefined
|
|
324
|
+
|| (typeof body === "object" && Object.keys(body).length === 0);
|
|
325
|
+
const pending = body?.data?.data;
|
|
326
|
+
if (pending && typeof pending === "object" && pending.pendingReview === true) {
|
|
327
|
+
console.log(yellow(bold("⏳ UPLOADED — WAITING FOR REVIEW (not deployed yet)")));
|
|
328
|
+
console.log(line);
|
|
329
|
+
console.log(` ${dim("project: ")} ${opt.name}`);
|
|
330
|
+
console.log(` ${dim("version: ")} ${oldVersion} ${dim("→")} ${bold(newVersion)}`);
|
|
331
|
+
console.log(` ${dim("reviewers:")} ${(pending.reviewers ?? []).join(", ")} ${dim(pending.mode === "all" ? "(all must accept)" : "(any one can accept)")}`);
|
|
332
|
+
if (Array.isArray(pending.notNotified) && pending.notNotified.length)
|
|
333
|
+
console.log(` ${yellow("⚠ email not delivered to:")} ${pending.notNotified.join(", ")}`);
|
|
334
|
+
if (pending.expiresAt)
|
|
335
|
+
console.log(` ${dim("link valid until:")} ${new Date(pending.expiresAt).toISOString()}`);
|
|
336
|
+
if (pending.replacedPrevious)
|
|
337
|
+
console.log(` ${dim("replaced the previous pending upload — its links no longer work")}`);
|
|
338
|
+
console.log(` ${dim("elapsed: ")} ${elapsedMs}ms`);
|
|
339
|
+
console.log(line);
|
|
340
|
+
console.log("");
|
|
341
|
+
return archiveName;
|
|
342
|
+
}
|
|
343
|
+
if (emptyResponse) {
|
|
344
|
+
console.log(yellow(bold("⚠ DEPLOY LIKELY OK (server returned empty response)")));
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
console.log(green(bold("✓ DEPLOY SUCCESSFUL")));
|
|
348
|
+
}
|
|
349
|
+
console.log(line);
|
|
350
|
+
console.log(` ${dim("project: ")} ${opt.name}`);
|
|
351
|
+
console.log(` ${dim("package: ")} ${pkgName}`);
|
|
352
|
+
console.log(` ${dim("version: ")} ${oldVersion} ${dim("→")} ${bold(newVersion)}`);
|
|
353
|
+
console.log(` ${dim("archive: ")} ${archiveName}`);
|
|
354
|
+
console.log(` ${dim("host: ")} ${opt.host}`);
|
|
355
|
+
console.log(` ${dim("status: ")} HTTP ${uploadResponse.status}`);
|
|
356
|
+
console.log(` ${dim("elapsed: ")} ${elapsedMs}ms`);
|
|
357
|
+
console.log(` ${dim("time: ")} ${stamp}`);
|
|
358
|
+
const info = body?.data?.data;
|
|
359
|
+
if (info && typeof info === "object" && "ok" in info) {
|
|
360
|
+
if (info.project && info.project !== opt.name) {
|
|
361
|
+
console.log(` ${dim("server project:")} ${info.project}`);
|
|
362
|
+
}
|
|
363
|
+
if (info.bluegreen === true) {
|
|
364
|
+
const slotBadge = info.activeThisDeploy
|
|
365
|
+
? green("← active in production")
|
|
366
|
+
: yellow("(inactive — deploy landed but nginx still points at " + info.active + "; run /pckg/switch to promote)");
|
|
367
|
+
console.log(` ${dim("mode: ")} blue-green`);
|
|
368
|
+
console.log(` ${dim("slot: ")} ${bold(String(info.slot))} ${slotBadge}`);
|
|
369
|
+
if (info.active && info.active !== info.slot) {
|
|
370
|
+
console.log(` ${dim("active: ")} ${info.active}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else if (info.bluegreen === false) {
|
|
374
|
+
console.log(` ${dim("mode: ")} single-instance ${green("← active")}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (!emptyResponse) {
|
|
378
|
+
const payload = JSON.stringify(body);
|
|
379
|
+
const clipped = payload.length > 300 ? payload.slice(0, 300) + `... (${payload.length} total)` : payload;
|
|
380
|
+
console.log(` ${dim("response:")} ${clipped}`);
|
|
381
|
+
}
|
|
382
|
+
console.log(line);
|
|
383
|
+
console.log("");
|
|
384
|
+
return archiveName;
|
|
385
|
+
}
|
|
386
|
+
function exec(cmd) {
|
|
387
|
+
return new Promise(resolve => {
|
|
388
|
+
const child = (0, child_process_1.spawn)(cmd, { shell: true });
|
|
389
|
+
let stdout = "", stderr = "";
|
|
390
|
+
child.stdout.on("data", d => stdout += d);
|
|
391
|
+
child.stderr.on("data", d => stderr += d);
|
|
392
|
+
child.on("error", e => resolve({ code: 1, stdout, stderr: stderr + String(e?.message ?? e) }));
|
|
393
|
+
child.on("close", code => resolve({ code: code ?? 1, stdout, stderr }));
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function countFiles(archive) {
|
|
397
|
+
try {
|
|
398
|
+
return (0, child_process_1.execFileSync)("tar", ["-tzf", archive], { encoding: "utf-8", maxBuffer: 256 * 1024 * 1024 })
|
|
399
|
+
.split("\n").filter(l => l.length > 0 && !l.endsWith("/")).length;
|
|
400
|
+
}
|
|
401
|
+
catch {
|
|
402
|
+
return "?";
|
|
403
|
+
}
|
|
404
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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.DeployKeyWizard = DeployKeyWizard;
|
|
7
|
+
exports.MicroserviceKey = MicroserviceKey;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const process_1 = require("process");
|
|
11
|
+
const InterceptorSignedAuth_1 = require("../interceptors/InterceptorSignedAuth");
|
|
12
|
+
const cliCommon_1 = require("./cliCommon");
|
|
13
|
+
const cliPrompt_1 = require("./cliPrompt");
|
|
14
|
+
async function DeployKeyWizard(target) {
|
|
15
|
+
const { red, green, yellow, dim, bold } = (0, cliCommon_1.palette)();
|
|
16
|
+
if (!process_1.stdin.isTTY) {
|
|
17
|
+
console.error(red("✗ deploy-key needs an interactive terminal — its output is a secret."));
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
console.log(bold("\nSigning key for deploys") + dim(" (Ed25519: the deployer keeps only the public key)"));
|
|
21
|
+
const candidates = target ? [target] : [
|
|
22
|
+
...(fs_1.default.existsSync("deploy.json") ? ["deploy.json"] : []),
|
|
23
|
+
...(fs_1.default.existsSync("deploy") && fs_1.default.statSync("deploy").isDirectory()
|
|
24
|
+
? fs_1.default.readdirSync("deploy").filter(f => f.endsWith(".json")).map(f => path_1.default.join("deploy", f)) : []),
|
|
25
|
+
];
|
|
26
|
+
let file = "";
|
|
27
|
+
if (candidates.length === 1)
|
|
28
|
+
file = await (0, cliPrompt_1.ask)("deploy.json to put the private key into (empty = only print it)", candidates[0]);
|
|
29
|
+
else if (candidates.length > 1) {
|
|
30
|
+
candidates.forEach((c, i) => console.log(` ${i + 1}) ${c}`));
|
|
31
|
+
const pick = await (0, cliPrompt_1.askValid)("deploy.json (number, path, or empty = only print)", "1", v => !v || !/^\d+$/.test(v) || candidates[+v - 1] ? null : "no such number");
|
|
32
|
+
file = /^\d+$/.test(pick) ? candidates[+pick - 1] : pick;
|
|
33
|
+
}
|
|
34
|
+
else
|
|
35
|
+
file = await (0, cliPrompt_1.ask)("deploy.json to put the private key into (empty = only print it)", "");
|
|
36
|
+
let cfg = null;
|
|
37
|
+
if (file) {
|
|
38
|
+
try {
|
|
39
|
+
cfg = JSON.parse(fs_1.default.readFileSync(file, "utf-8"));
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.error(red(`✗ ${file}: ${e?.code === "ENOENT" ? "not found" : "not valid JSON"}`));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
if (cfg.privateKey && !(await (0, cliPrompt_1.yes)(`${file} already has a privateKey — replace it?`, false)))
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const login = await (0, cliPrompt_1.askValid)("Deployer user login", cfg?.username ?? "", v => /^[A-Za-z0-9._@-]+$/.test(v) ? null : "letters, digits, '.', '_', '-', '@' only");
|
|
49
|
+
const { publicKey, privateKey } = InterceptorSignedAuth_1.InterceptorSignedAuth.generateKeyPair();
|
|
50
|
+
if (cfg) {
|
|
51
|
+
cfg.username = login;
|
|
52
|
+
cfg.privateKey = privateKey;
|
|
53
|
+
const hadPassword = "password" in cfg;
|
|
54
|
+
delete cfg.password;
|
|
55
|
+
const tmp = file + ".tmp";
|
|
56
|
+
fs_1.default.writeFileSync(tmp, JSON.stringify(cfg, null, 4) + "\n", { encoding: "utf-8", mode: 0o600 });
|
|
57
|
+
fs_1.default.chmodSync(tmp, 0o600);
|
|
58
|
+
fs_1.default.renameSync(tmp, file);
|
|
59
|
+
console.log(green(`\n✓ ${path_1.default.resolve(file)}`) + dim(` — privateKey written${hadPassword ? ", password removed" : ""} (0600)`));
|
|
60
|
+
console.log(yellow(" This file can deploy on its own: never commit or share it. In CI keep it in a secret."));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log(`\nPrivate key — put it into deploy.json as "privateKey" (and keep that file out of git):\n\n ${bold(privateKey)}\n`);
|
|
64
|
+
}
|
|
65
|
+
console.log(`\nPublic key of ${bold(login)} — for the deployer's setup.json:\n\n ${bold(publicKey)}\n`);
|
|
66
|
+
console.log(dim(" On the deployer: npx bmfk setup-config → \"set a deployer user's public key\""));
|
|
67
|
+
console.log(dim(` or by hand: { "login": "${login}", "publicKey": "${publicKey}" }`));
|
|
68
|
+
console.log(dim(" Until the deployer has this public key, this deploy.json can't deploy."));
|
|
69
|
+
}
|
|
70
|
+
function MicroserviceKey() {
|
|
71
|
+
const { red, yellow, dim, bold } = (0, cliCommon_1.palette)();
|
|
72
|
+
if (!process_1.stdin.isTTY) {
|
|
73
|
+
console.error(red("✗ ms-key needs an interactive terminal — its output is a secret."));
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
const { publicKey, privateKey } = InterceptorSignedAuth_1.InterceptorSignedAuth.generateKeyPair();
|
|
77
|
+
console.log(bold("\nMicroservice signing key") + dim(" (Ed25519)"));
|
|
78
|
+
console.log(`\nPrivate key — "privateKey" of this service (host or caller). A secret: keep it out of git.\n\n ${bold(privateKey)}\n`);
|
|
79
|
+
console.log(`Public key — not a secret:`);
|
|
80
|
+
console.log(dim(` a caller's → the host's clients: { "<kid>": { publicKey: "…" } }`));
|
|
81
|
+
console.log(dim(` a host's → each caller's hostPublicKey`));
|
|
82
|
+
console.log(`\n ${bold(publicKey)}\n`);
|
|
83
|
+
console.log(yellow("A new pair for every service — never reuse one key on two services."));
|
|
84
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseEndpoint } from "../BaseEndpoint";
|
|
2
|
+
import { IRequest, IResponse } from "../structures/Interfaces";
|
|
3
|
+
export declare class Deployer extends BaseEndpoint {
|
|
4
|
+
ignoreInDocumentation: boolean;
|
|
5
|
+
private signed;
|
|
6
|
+
constructor();
|
|
7
|
+
file(req: IRequest): Promise<IResponse<any>>;
|
|
8
|
+
switchSlot(req: IRequest): Promise<IResponse<any>>;
|
|
9
|
+
status(req: IRequest): Promise<IResponse<any>>;
|
|
10
|
+
backups(req: IRequest): Promise<IResponse<any>>;
|
|
11
|
+
restore(req: IRequest): Promise<IResponse<any>>;
|
|
12
|
+
slot(req: IRequest): Promise<IResponse<any>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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.Deployer = void 0;
|
|
7
|
+
const BaseEndpoint_1 = require("../BaseEndpoint");
|
|
8
|
+
const DefaultErrors_1 = __importDefault(require("../structures/DefaultErrors"));
|
|
9
|
+
const DeployerService_1 = require("./DeployerService");
|
|
10
|
+
const InterceptorSignedAuth_1 = require("../interceptors/InterceptorSignedAuth");
|
|
11
|
+
class Deployer extends BaseEndpoint_1.BaseEndpoint {
|
|
12
|
+
ignoreInDocumentation = true;
|
|
13
|
+
signed = new InterceptorSignedAuth_1.InterceptorSignedAuth(login => DeployerService_1.REQ_DEPLOYER_PUBLIC_KEY.request(login));
|
|
14
|
+
constructor() {
|
|
15
|
+
super("pckg");
|
|
16
|
+
this.registerEndpoints([
|
|
17
|
+
{
|
|
18
|
+
ignoreInterceptor: true,
|
|
19
|
+
endpoint: "add",
|
|
20
|
+
handler: this.file,
|
|
21
|
+
validationModel: {
|
|
22
|
+
token: "",
|
|
23
|
+
name: "",
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
ignoreInterceptor: true,
|
|
28
|
+
endpoint: "switch",
|
|
29
|
+
handler: this.switchSlot,
|
|
30
|
+
validationModel: {
|
|
31
|
+
token: "",
|
|
32
|
+
name: "",
|
|
33
|
+
scheme: "",
|
|
34
|
+
$__scheme_values: ["blue", "green"],
|
|
35
|
+
$__scheme_optional: true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
ignoreInterceptor: true,
|
|
40
|
+
endpoint: "status",
|
|
41
|
+
handler: this.status,
|
|
42
|
+
validationModel: {
|
|
43
|
+
name: "",
|
|
44
|
+
$__name_optional: true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
ignoreInterceptor: true,
|
|
49
|
+
ignoreHttpLogging: true,
|
|
50
|
+
endpoint: "slot",
|
|
51
|
+
handler: this.slot,
|
|
52
|
+
validationModel: {
|
|
53
|
+
name: "",
|
|
54
|
+
token: "",
|
|
55
|
+
slot: "",
|
|
56
|
+
$__slot_values: ["blue", "green"],
|
|
57
|
+
$__slot_optional: true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
ignoreInterceptor: true,
|
|
62
|
+
endpoint: "backups",
|
|
63
|
+
handler: this.backups,
|
|
64
|
+
validationModel: { name: "" }
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
ignoreInterceptor: true,
|
|
68
|
+
endpoint: "restore",
|
|
69
|
+
handler: this.restore,
|
|
70
|
+
validationModel: { name: "", token: "", backup: "" }
|
|
71
|
+
}
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
async file(req) {
|
|
75
|
+
if (!req.files)
|
|
76
|
+
throw { ...DefaultErrors_1.default.FILE_NOT_EXISTS, details: "No files were uploaded" };
|
|
77
|
+
const result = await DeployerService_1.REQ_DEPLOYMENT_PROCEED.request({ ...req.data, files: req.files, auth: req.headers.authorization, authLogin: req.headers["x-deployer-login"], ip: req.ip, sig: await this.signed.verify(req) });
|
|
78
|
+
return { data: result };
|
|
79
|
+
}
|
|
80
|
+
async switchSlot(req) {
|
|
81
|
+
return await DeployerService_1.REQ_DEPLOYMENT_SWITCH.request({ ...req.data, auth: req.headers.authorization, authLogin: req.headers["x-deployer-login"], ip: req.ip, sig: await this.signed.verify(req) });
|
|
82
|
+
}
|
|
83
|
+
async status(req) {
|
|
84
|
+
return await DeployerService_1.REQ_DEPLOYMENT_STATUS.request({ ...req.data, auth: req.headers.authorization, authLogin: req.headers["x-deployer-login"], ip: req.ip, sig: await this.signed.verify(req) });
|
|
85
|
+
}
|
|
86
|
+
async backups(req) {
|
|
87
|
+
return await DeployerService_1.REQ_DEPLOYMENT_BACKUPS.request({ name: req.data.name, auth: req.headers.authorization, authLogin: req.headers["x-deployer-login"], ip: req.ip, sig: await this.signed.verify(req) });
|
|
88
|
+
}
|
|
89
|
+
async restore(req) {
|
|
90
|
+
return await DeployerService_1.REQ_DEPLOYMENT_RESTORE.request({ name: req.data.name, token: req.data.token, backup: req.data.backup, auth: req.headers.authorization, authLogin: req.headers["x-deployer-login"], ip: req.ip, sig: await this.signed.verify(req) });
|
|
91
|
+
}
|
|
92
|
+
async slot(req) {
|
|
93
|
+
return await DeployerService_1.REQ_DEPLOYMENT_SLOT.request({ name: req.data.name, token: req.data.token, slot: req.data.slot });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.Deployer = Deployer;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface IDeployerInitAnswers {
|
|
2
|
+
name: string;
|
|
3
|
+
port: number;
|
|
4
|
+
baseEndPoint: string;
|
|
5
|
+
maxArchiveMb: number;
|
|
6
|
+
projectsPath: string;
|
|
7
|
+
setupPath: string;
|
|
8
|
+
users: {
|
|
9
|
+
login: string;
|
|
10
|
+
publicKey: string;
|
|
11
|
+
}[];
|
|
12
|
+
allowedIps: string[];
|
|
13
|
+
telegram?: {
|
|
14
|
+
bot: string;
|
|
15
|
+
chat: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare function publicKeyProblem(key: string): string | null;
|
|
19
|
+
export declare function normalizeBase(base: string): string;
|
|
20
|
+
export declare function deployerInitFiles(a: IDeployerInitAnswers, packageJson: string | null): Record<string, {
|
|
21
|
+
content: string;
|
|
22
|
+
mode?: number;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function nginxSnippet(a: IDeployerInitAnswers): string;
|
|
25
|
+
export declare function DeployerInit(args: string[]): Promise<void>;
|