@ubercode/channelvault 0.2.1 → 0.3.0-rc.2
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 +38 -0
- package/README.md +26 -7
- package/dist/cli.js +836 -190
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +124 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { spawnSync } from "child_process";
|
|
5
|
-
import {
|
|
6
|
-
import { existsSync as
|
|
5
|
+
import { cp, lstat as lstat3, mkdir as mkdir5, mkdtemp, readFile as readFile6, realpath as realpath4, rm as rm4, writeFile as writeFile6 } from "fs/promises";
|
|
6
|
+
import { existsSync as existsSync6 } from "fs";
|
|
7
7
|
import { tmpdir } from "os";
|
|
8
8
|
import { createRequire } from "module";
|
|
9
|
-
import * as
|
|
9
|
+
import * as path7 from "path";
|
|
10
10
|
import { createInterface } from "readline/promises";
|
|
11
11
|
import { Command, CommanderError } from "commander";
|
|
12
12
|
|
|
13
13
|
// src/explode/index.ts
|
|
14
14
|
import { AsyncLocalStorage } from "async_hooks";
|
|
15
15
|
import { existsSync } from "fs";
|
|
16
|
-
import { lstat, mkdir, readFile as readFile2, realpath, writeFile } from "fs/promises";
|
|
16
|
+
import { lstat, mkdir, readFile as readFile2, readdir, realpath, writeFile } from "fs/promises";
|
|
17
17
|
import * as path from "path";
|
|
18
18
|
|
|
19
19
|
// src/types.ts
|
|
@@ -600,12 +600,13 @@ async function readWithinRoot(root, target, rel) {
|
|
|
600
600
|
}
|
|
601
601
|
return readFile2(realTarget, "utf8");
|
|
602
602
|
}
|
|
603
|
-
|
|
603
|
+
var pathKey = (file) => process.platform === "win32" ? file.toLowerCase() : file;
|
|
604
|
+
async function resolveMarkers(value, jsonDir, root, referenced) {
|
|
604
605
|
if (Array.isArray(value)) {
|
|
605
606
|
const out = [];
|
|
606
607
|
for (const item of value) {
|
|
607
608
|
if (isRefMarker(item) && !existsSync(resolveWithinRoot(root, jsonDir, item["@ref"]))) continue;
|
|
608
|
-
out.push(await resolveMarkers(item, jsonDir, root));
|
|
609
|
+
out.push(await resolveMarkers(item, jsonDir, root, referenced));
|
|
609
610
|
}
|
|
610
611
|
return out;
|
|
611
612
|
}
|
|
@@ -616,25 +617,81 @@ async function resolveMarkers(value, jsonDir, root) {
|
|
|
616
617
|
if (isRefMarker(value)) {
|
|
617
618
|
const target = resolveWithinRoot(root, jsonDir, value["@ref"]);
|
|
618
619
|
const text = await readWithinRoot(root, target, value["@ref"]);
|
|
620
|
+
referenced.add(pathKey(await realpath(target)));
|
|
619
621
|
const parsed = parseJson(text, target);
|
|
620
|
-
return resolveMarkers(parsed, path.dirname(target), root);
|
|
622
|
+
return resolveMarkers(parsed, path.dirname(target), root, referenced);
|
|
621
623
|
}
|
|
622
624
|
if (isPlainObject(value)) {
|
|
623
625
|
const out = {};
|
|
624
626
|
for (const [k, v] of Object.entries(value)) {
|
|
625
627
|
if (isRefMarker(v) && !existsSync(resolveWithinRoot(root, jsonDir, v["@ref"]))) continue;
|
|
626
|
-
out[k] = await resolveMarkers(v, jsonDir, root);
|
|
628
|
+
out[k] = await resolveMarkers(v, jsonDir, root, referenced);
|
|
627
629
|
}
|
|
628
630
|
return out;
|
|
629
631
|
}
|
|
630
632
|
return value;
|
|
631
633
|
}
|
|
634
|
+
async function discoverResources(config, root, referenced) {
|
|
635
|
+
const realRoot = await realpath(root);
|
|
636
|
+
const contained = async (file) => {
|
|
637
|
+
const real = await realpath(file);
|
|
638
|
+
if (real !== realRoot && !real.startsWith(realRoot + path.sep)) throw new Error(`resource path escapes the working tree through a link: ${file}`);
|
|
639
|
+
return real;
|
|
640
|
+
};
|
|
641
|
+
const layouts = [
|
|
642
|
+
{ folder: "channels", filename: "channel.json", container: "channels", member: "channel" },
|
|
643
|
+
{ folder: "codeTemplates", filename: "library.json", container: "codeTemplateLibraries", member: "codeTemplateLibrary" },
|
|
644
|
+
{ folder: "channelGroups", filename: null, container: "channelGroups", member: "channelGroup" }
|
|
645
|
+
];
|
|
646
|
+
for (const layout of layouts) {
|
|
647
|
+
const dir = path.join(root, layout.folder);
|
|
648
|
+
if (!existsSync(dir)) continue;
|
|
649
|
+
await contained(dir);
|
|
650
|
+
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
651
|
+
const additions = [];
|
|
652
|
+
for (const entry of entries) {
|
|
653
|
+
let file = path.join(dir, entry.name);
|
|
654
|
+
if (layout.filename) {
|
|
655
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
656
|
+
await contained(file);
|
|
657
|
+
file = path.join(file, layout.filename);
|
|
658
|
+
if (!existsSync(file)) continue;
|
|
659
|
+
} else if (!entry.name.endsWith(".json")) continue;
|
|
660
|
+
const real = await contained(file);
|
|
661
|
+
if (referenced.has(pathKey(real))) continue;
|
|
662
|
+
const parsed = parseJson(await readWithinRoot(root, file, file), file);
|
|
663
|
+
const resource = await resolveMarkers(parsed, path.dirname(file), root, referenced);
|
|
664
|
+
if (!isPlainObject(resource) || typeof resource["id"] !== "string" || !resource["id"].trim() || typeof resource["name"] !== "string" || !resource["name"].trim()) {
|
|
665
|
+
throw new Error(`new resource ${file} needs a nonempty id and name`);
|
|
666
|
+
}
|
|
667
|
+
additions.push(resource);
|
|
668
|
+
referenced.add(pathKey(real));
|
|
669
|
+
}
|
|
670
|
+
if (!additions.length) continue;
|
|
671
|
+
const container = isPlainObject(config[layout.container]) ? config[layout.container] : {};
|
|
672
|
+
const old = container[layout.member];
|
|
673
|
+
const members = [...old == null || old === "" ? [] : asArray(old), ...additions];
|
|
674
|
+
const ids = /* @__PURE__ */ new Set();
|
|
675
|
+
for (const member of members.filter(isPlainObject)) {
|
|
676
|
+
const id = String(member["id"]);
|
|
677
|
+
if (ids.has(id)) throw new Error(`duplicate ${layout.member} id ${id}: a copied resource keeps its source's id; give each copy a new UUID`);
|
|
678
|
+
ids.add(id);
|
|
679
|
+
}
|
|
680
|
+
config[layout.container] = { ...container, [layout.member]: members.length === 1 ? members[0] : members };
|
|
681
|
+
}
|
|
682
|
+
}
|
|
632
683
|
async function implode(opts) {
|
|
633
684
|
const root = path.resolve(opts.root);
|
|
685
|
+
if (existsSync(path.join(root, ".channelvault-transaction.json"))) {
|
|
686
|
+
throw new Error("working tree has a pending replacement; run a channelvault CLI command with the original --dotenv selection to recover it before reading");
|
|
687
|
+
}
|
|
634
688
|
const serverDir = path.join(root, "server");
|
|
635
689
|
const configPath = path.join(serverDir, "configuration.json");
|
|
636
|
-
const parsed = await
|
|
637
|
-
const
|
|
690
|
+
const parsed = parseJson(await readWithinRoot(root, configPath, configPath), configPath);
|
|
691
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
692
|
+
const resolved = await resolveMarkers(parsed, serverDir, root, referenced);
|
|
693
|
+
if (!isPlainObject(resolved)) throw new Error("server/configuration.json must hold a configuration object");
|
|
694
|
+
await discoverResources(resolved, root, referenced);
|
|
638
695
|
return resolved;
|
|
639
696
|
}
|
|
640
697
|
function createExplodeEngine() {
|
|
@@ -932,25 +989,31 @@ function elementSegment(el, index) {
|
|
|
932
989
|
if (el && typeof el === "object" && !Array.isArray(el)) {
|
|
933
990
|
const id = el["id"] ?? el["metaDataId"];
|
|
934
991
|
if (typeof id === "string" || typeof id === "number") return `[${String(id)}]`;
|
|
992
|
+
const mapKey = CONFIG_PROPERTY in el ? configMapKeyOf(el) : void 0;
|
|
993
|
+
if (mapKey !== void 0) return `[${mapKey}]`;
|
|
935
994
|
}
|
|
936
995
|
return `[${index}]`;
|
|
937
996
|
}
|
|
997
|
+
function configMapKeyOf(entry) {
|
|
998
|
+
const key = entry["string"];
|
|
999
|
+
if (typeof key === "string") return key;
|
|
1000
|
+
return Array.isArray(key) && typeof key[0] === "string" ? key[0] : void 0;
|
|
1001
|
+
}
|
|
938
1002
|
function mapLeaves(config, visit) {
|
|
939
|
-
const walk = (node, key,
|
|
1003
|
+
const walk = (node, key, path8, labels, section, cmKey) => {
|
|
940
1004
|
if (typeof node === "string") {
|
|
941
|
-
return visit(node, { location:
|
|
1005
|
+
return visit(node, { location: path8.join("/"), key, labels, section, configMapKey: cmKey });
|
|
942
1006
|
}
|
|
943
1007
|
if (Array.isArray(node)) {
|
|
944
|
-
return node.map((el, i) => walk(el, key, [...
|
|
1008
|
+
return node.map((el, i) => walk(el, key, [...path8.slice(0, -1), `${path8[path8.length - 1]}${elementSegment(el, i)}`], labels, section, cmKey));
|
|
945
1009
|
}
|
|
946
1010
|
if (node && typeof node === "object") {
|
|
947
1011
|
const name = node["name"];
|
|
948
1012
|
const inner = typeof name === "string" && name.trim() !== "" ? [...labels, name] : labels;
|
|
949
|
-
const
|
|
950
|
-
const mapKey = section === "configurationMap" && CONFIG_PROPERTY in node ? typeof entryKey === "string" ? entryKey : Array.isArray(entryKey) && typeof entryKey[0] === "string" ? entryKey[0] : void 0 : cmKey;
|
|
1013
|
+
const mapKey = section === "configurationMap" && CONFIG_PROPERTY in node ? configMapKeyOf(node) : cmKey;
|
|
951
1014
|
const out = {};
|
|
952
1015
|
for (const [k, v] of Object.entries(node)) {
|
|
953
|
-
out[k] = walk(v, k, [...
|
|
1016
|
+
out[k] = walk(v, k, [...path8, k], inner, section || k, mapKey);
|
|
954
1017
|
}
|
|
955
1018
|
return out;
|
|
956
1019
|
}
|
|
@@ -1292,6 +1355,41 @@ function formatFindings(findings) {
|
|
|
1292
1355
|
${"".padEnd(20)} at ${f.location} context ${f.context}`).join("\n");
|
|
1293
1356
|
}
|
|
1294
1357
|
|
|
1358
|
+
// src/client/validate.ts
|
|
1359
|
+
var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1360
|
+
function liveConfiguration(payload) {
|
|
1361
|
+
const bad = (detail) => {
|
|
1362
|
+
throw new Error(`invalid server configuration response: ${detail}; nothing should be written from this snapshot`);
|
|
1363
|
+
};
|
|
1364
|
+
if (!object(payload) || Object.keys(payload).length !== 1 || !("serverConfiguration" in payload)) bad("expected the serverConfiguration wrapper");
|
|
1365
|
+
const config = payload["serverConfiguration"];
|
|
1366
|
+
if (!object(config)) bad("expected a configuration object");
|
|
1367
|
+
const c = config;
|
|
1368
|
+
if (typeof c["@version"] !== "string" || !/^\d+\.\d+(?:\.\d+)*(?:[-+][A-Za-z0-9.-]+)?$/.test(c["@version"])) bad("missing or invalid engine version");
|
|
1369
|
+
if (!("channels" in c)) bad("missing channels collection");
|
|
1370
|
+
const collection = (container, key, where) => {
|
|
1371
|
+
if (container == null || container === "") return [];
|
|
1372
|
+
if (!object(container)) bad(`invalid ${where} collection`);
|
|
1373
|
+
if (!(key in container) && Object.keys(container).some((k) => !k.startsWith("@"))) bad(`missing resource list in ${where}`);
|
|
1374
|
+
const raw = container[key];
|
|
1375
|
+
if (raw == null || raw === "") return [];
|
|
1376
|
+
const items = Array.isArray(raw) ? raw : [raw];
|
|
1377
|
+
for (const item of items) {
|
|
1378
|
+
if (!object(item) || typeof item.id !== "string" || !item.id.trim() || typeof item.name !== "string" || !item.name.trim()) bad(`invalid resource in ${where}`);
|
|
1379
|
+
if ("revision" in item && (!Number.isSafeInteger(item.revision) || Number(item.revision) < 0)) bad(`invalid revision in ${where}`);
|
|
1380
|
+
}
|
|
1381
|
+
return items;
|
|
1382
|
+
};
|
|
1383
|
+
collection(c.channels, "channel", "channels");
|
|
1384
|
+
if ("codeTemplateLibraries" in c) {
|
|
1385
|
+
for (const library of collection(c.codeTemplateLibraries, "codeTemplateLibrary", "code template libraries")) {
|
|
1386
|
+
if ("codeTemplates" in library) collection(library.codeTemplates, "codeTemplate", "code templates");
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
if ("channelGroups" in c) collection(c.channelGroups, "channelGroup", "channel groups");
|
|
1390
|
+
return c;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1295
1393
|
// src/client/index.ts
|
|
1296
1394
|
var UNTRUSTED_CERT_CODES = /* @__PURE__ */ new Set([
|
|
1297
1395
|
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
@@ -1405,16 +1503,20 @@ var MirthClientImpl = class {
|
|
|
1405
1503
|
/**
|
|
1406
1504
|
* GET /server/configuration -> canonical config.
|
|
1407
1505
|
*
|
|
1408
|
-
* Requests JSON
|
|
1409
|
-
*
|
|
1410
|
-
* a multi-key object is returned as-is).
|
|
1506
|
+
* Requests JSON and validates the envelope and core resource collections
|
|
1507
|
+
* before this snapshot can be used to replace a tree or plan server writes.
|
|
1411
1508
|
*/
|
|
1412
1509
|
async getServerConfiguration() {
|
|
1413
1510
|
const response = await this.request("GET", "/server/configuration", {
|
|
1414
1511
|
headers: { Accept: "application/json" }
|
|
1415
1512
|
});
|
|
1416
|
-
|
|
1417
|
-
|
|
1513
|
+
let json;
|
|
1514
|
+
try {
|
|
1515
|
+
json = await response.json();
|
|
1516
|
+
} catch {
|
|
1517
|
+
throw new Error("invalid server configuration response: expected JSON");
|
|
1518
|
+
}
|
|
1519
|
+
return liveConfiguration(json);
|
|
1418
1520
|
}
|
|
1419
1521
|
/**
|
|
1420
1522
|
* PUT /server/configuration <- canonical config.
|
|
@@ -1442,7 +1544,9 @@ var MirthClientImpl = class {
|
|
|
1442
1544
|
}
|
|
1443
1545
|
async getServerId() {
|
|
1444
1546
|
const response = await this.request("GET", "/server/id", { headers: { Accept: "text/plain" } });
|
|
1445
|
-
|
|
1547
|
+
const id = (await response.text()).trim();
|
|
1548
|
+
if (!/^[^\p{Cc}\p{Cf}]{1,255}$/u.test(id)) throw new Error("the server returned an invalid installation ID");
|
|
1549
|
+
return id;
|
|
1446
1550
|
}
|
|
1447
1551
|
async getServerConfigurationXml() {
|
|
1448
1552
|
const response = await this.request("GET", "/server/configuration", { headers: { Accept: "application/xml" } });
|
|
@@ -1459,12 +1563,23 @@ var MirthClientImpl = class {
|
|
|
1459
1563
|
// Override is on: Mirth does not reject a stale revision anyway (verified on
|
|
1460
1564
|
// 4.5.2), so conflict detection happens in the push planner instead.
|
|
1461
1565
|
async getChannel(id) {
|
|
1462
|
-
|
|
1566
|
+
return this.getResource(`/channels/${encodeURIComponent(id)}`);
|
|
1567
|
+
}
|
|
1568
|
+
async getCodeTemplate(id) {
|
|
1569
|
+
return this.getResource(`/codeTemplates/${encodeURIComponent(id)}`);
|
|
1570
|
+
}
|
|
1571
|
+
async getResource(resourcePath) {
|
|
1572
|
+
const response = await this.request("GET", resourcePath, {
|
|
1463
1573
|
headers: { Accept: "application/json" }
|
|
1574
|
+
}).catch((err) => {
|
|
1575
|
+
if (err.status === 404) return null;
|
|
1576
|
+
throw err;
|
|
1464
1577
|
});
|
|
1578
|
+
if (!response) return null;
|
|
1465
1579
|
const text = await response.text();
|
|
1466
1580
|
if (text.trim() === "") return null;
|
|
1467
|
-
|
|
1581
|
+
const parsed = JSON.parse(text);
|
|
1582
|
+
return parsed === null ? null : unwrapSingleKey(parsed);
|
|
1468
1583
|
}
|
|
1469
1584
|
async close() {
|
|
1470
1585
|
await this.dispatcher.close();
|
|
@@ -1498,15 +1613,15 @@ var MirthClientImpl = class {
|
|
|
1498
1613
|
await this.request("POST", `/channels/${encodeURIComponent(id)}/_deploy`, { query: { returnErrors: true } });
|
|
1499
1614
|
}
|
|
1500
1615
|
/** Send a JSON body; Mirth answers some updates with `{"boolean": false}` instead of an error status. */
|
|
1501
|
-
async sendJson(method,
|
|
1502
|
-
const response = await this.request(method,
|
|
1616
|
+
async sendJson(method, path8, body, query) {
|
|
1617
|
+
const response = await this.request(method, path8, {
|
|
1503
1618
|
query,
|
|
1504
1619
|
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
1505
1620
|
body: JSON.stringify(body)
|
|
1506
1621
|
});
|
|
1507
1622
|
const text = await response.text();
|
|
1508
1623
|
if (/^\s*\{\s*"boolean"\s*:\s*false\s*\}\s*$/.test(text)) {
|
|
1509
|
-
throw new Error(`${method} ${
|
|
1624
|
+
throw new Error(`${method} ${path8}: the server refused the update`);
|
|
1510
1625
|
}
|
|
1511
1626
|
}
|
|
1512
1627
|
// --- internal transport ---------------------------------------------------
|
|
@@ -1515,11 +1630,11 @@ var MirthClientImpl = class {
|
|
|
1515
1630
|
* on a 401 while authenticated resets auth, re-logs in once, and retries.
|
|
1516
1631
|
* Throws an {@link ApiError}-shaped error on a non-2xx response.
|
|
1517
1632
|
*/
|
|
1518
|
-
async request(method,
|
|
1633
|
+
async request(method, path8, options = {}, isRetry = false) {
|
|
1519
1634
|
if (!this.authenticated) {
|
|
1520
1635
|
await this.login();
|
|
1521
1636
|
}
|
|
1522
|
-
const url = this.buildUrl(
|
|
1637
|
+
const url = this.buildUrl(path8, options.query);
|
|
1523
1638
|
const headers = {
|
|
1524
1639
|
"X-Requested-With": "XMLHttpRequest",
|
|
1525
1640
|
...options.headers
|
|
@@ -1533,7 +1648,7 @@ var MirthClientImpl = class {
|
|
|
1533
1648
|
if (response.status === 401 && this.authenticated && !isRetry) {
|
|
1534
1649
|
this.authenticated = false;
|
|
1535
1650
|
await this.login();
|
|
1536
|
-
return this.request(method,
|
|
1651
|
+
return this.request(method, path8, options, true);
|
|
1537
1652
|
}
|
|
1538
1653
|
if (!response.ok) {
|
|
1539
1654
|
throw await this.toApiError(response);
|
|
@@ -1553,8 +1668,8 @@ var MirthClientImpl = class {
|
|
|
1553
1668
|
}
|
|
1554
1669
|
}
|
|
1555
1670
|
/** Build an absolute URL with an optional query string. */
|
|
1556
|
-
buildUrl(
|
|
1557
|
-
const url = `${this.baseUrl}${
|
|
1671
|
+
buildUrl(path8, query) {
|
|
1672
|
+
const url = `${this.baseUrl}${path8}`;
|
|
1558
1673
|
if (!query || Object.keys(query).length === 0) {
|
|
1559
1674
|
return url;
|
|
1560
1675
|
}
|
|
@@ -1659,8 +1774,17 @@ function same(a, b) {
|
|
|
1659
1774
|
}
|
|
1660
1775
|
return false;
|
|
1661
1776
|
}
|
|
1777
|
+
var ASSOCIATIONS = ["channelTags", "dependentIds", "dependencyIds"];
|
|
1778
|
+
function withSortedContexts(o) {
|
|
1779
|
+
const set = o["contextSet"];
|
|
1780
|
+
const delegate = isObj(set) ? set["delegate"] : void 0;
|
|
1781
|
+
const types = isObj(delegate) ? delegate["contextType"] : void 0;
|
|
1782
|
+
if (!isObj(set) || !isObj(delegate) || !Array.isArray(types)) return o;
|
|
1783
|
+
const sorted = [...types].sort((a, b) => String(a).localeCompare(String(b), "en"));
|
|
1784
|
+
return { ...o, contextSet: { ...set, delegate: { ...delegate, contextType: sorted } } };
|
|
1785
|
+
}
|
|
1662
1786
|
function stripVolatile(o) {
|
|
1663
|
-
const out = { ...o };
|
|
1787
|
+
const out = withSortedContexts({ ...o });
|
|
1664
1788
|
delete out["revision"];
|
|
1665
1789
|
delete out["lastModified"];
|
|
1666
1790
|
const exportData = out["exportData"];
|
|
@@ -1680,11 +1804,16 @@ function withoutVolatile(c) {
|
|
|
1680
1804
|
const strip = (o) => {
|
|
1681
1805
|
delete o["revision"];
|
|
1682
1806
|
delete o["lastModified"];
|
|
1683
|
-
const
|
|
1807
|
+
const exportData = o["exportData"];
|
|
1808
|
+
const md = isObj(exportData) ? exportData["metadata"] : void 0;
|
|
1684
1809
|
if (isObj(md)) {
|
|
1685
1810
|
delete md["lastModified"];
|
|
1686
1811
|
delete md["userId"];
|
|
1687
1812
|
}
|
|
1813
|
+
if (isObj(exportData)) {
|
|
1814
|
+
for (const key of ASSOCIATIONS) if (exportData[key] === null) delete exportData[key];
|
|
1815
|
+
}
|
|
1816
|
+
if (isObj(o["contextSet"])) o["contextSet"] = withSortedContexts(o)["contextSet"];
|
|
1688
1817
|
};
|
|
1689
1818
|
for (const ch of channelsOf(out)) strip(ch);
|
|
1690
1819
|
for (const lib of librariesOf(out)) {
|
|
@@ -1717,6 +1846,14 @@ function libraryShape(lib) {
|
|
|
1717
1846
|
out["codeTemplates"] = templatesOf2(lib).map(idOf);
|
|
1718
1847
|
return out;
|
|
1719
1848
|
}
|
|
1849
|
+
function withRetainedMembers(local, remote, localIds, deletedIds) {
|
|
1850
|
+
const retained = templatesOf2(remote).filter((t) => !localIds.has(idOf(t)) && !deletedIds.has(idOf(t)));
|
|
1851
|
+
if (!retained.length) return local;
|
|
1852
|
+
return { ...local, codeTemplates: {
|
|
1853
|
+
...isObj(local["codeTemplates"]) ? local["codeTemplates"] : {},
|
|
1854
|
+
codeTemplate: [...templatesOf2(local), ...retained]
|
|
1855
|
+
} };
|
|
1856
|
+
}
|
|
1720
1857
|
function hashGlobalScripts(c) {
|
|
1721
1858
|
return createHash2("sha256").update(JSON.stringify(normalizeEolDeep(c["globalScripts"] ?? null))).digest("hex");
|
|
1722
1859
|
}
|
|
@@ -1730,6 +1867,25 @@ function resourceIds(c) {
|
|
|
1730
1867
|
globalScripts: hashGlobalScripts(c)
|
|
1731
1868
|
};
|
|
1732
1869
|
}
|
|
1870
|
+
function adoptTarget(local, target) {
|
|
1871
|
+
const config = structuredClone(local);
|
|
1872
|
+
const mine = resourceIds(local);
|
|
1873
|
+
const theirs = resourceIds(target);
|
|
1874
|
+
const intersect = (key) => Object.fromEntries(Object.entries(theirs[key]).filter(([id]) => id in mine[key]));
|
|
1875
|
+
const known = {
|
|
1876
|
+
channels: intersect("channels"),
|
|
1877
|
+
libraries: intersect("libraries"),
|
|
1878
|
+
codeTemplates: intersect("codeTemplates"),
|
|
1879
|
+
globalScripts: theirs.globalScripts
|
|
1880
|
+
};
|
|
1881
|
+
const rebase = (items, revisions) => {
|
|
1882
|
+
for (const item of items) item["revision"] = revisions[idOf(item)] ?? 0;
|
|
1883
|
+
};
|
|
1884
|
+
rebase(channelsOf(config), theirs.channels);
|
|
1885
|
+
rebase(librariesOf(config), theirs.libraries);
|
|
1886
|
+
rebase(librariesOf(config).flatMap(templatesOf2), theirs.codeTemplates);
|
|
1887
|
+
return { config, known };
|
|
1888
|
+
}
|
|
1733
1889
|
function knownFrom(raw) {
|
|
1734
1890
|
if (!isObj(raw)) return void 0;
|
|
1735
1891
|
const r = raw;
|
|
@@ -1887,11 +2043,13 @@ rename one of them, or delete or rename the other in a push of its own first`
|
|
|
1887
2043
|
const remoteLibById = new Map(rl.map((l) => [idOf(l), l]));
|
|
1888
2044
|
const remoteTemplates = new Map(rl.flatMap((l) => templatesOf2(l).map((t) => [idOf(t), t])));
|
|
1889
2045
|
const localTemplateIds = new Set(ll.flatMap((l) => templatesOf2(l).map(idOf)));
|
|
2046
|
+
const deletedTemplateIds = new Set([...remoteTemplates.keys()].filter((id) => !localTemplateIds.has(id) && (!known || id in known.codeTemplates)));
|
|
1890
2047
|
const allChannelIds = [...effective.keys()];
|
|
1891
2048
|
for (const lib of ll.filter(inScope)) {
|
|
1892
2049
|
const r = remoteLibById.get(idOf(lib));
|
|
1893
2050
|
let touched = false;
|
|
1894
|
-
|
|
2051
|
+
const effectiveLib = r && !opts.wholeReplace ? withRetainedMembers(lib, r, localTemplateIds, deletedTemplateIds) : lib;
|
|
2052
|
+
if (!r || !same(libraryShape(effectiveLib), libraryShape(r))) {
|
|
1895
2053
|
changes.push({ kind: "library", op: r ? "update" : "create", id: idOf(lib), label: nameOf(lib) });
|
|
1896
2054
|
touched = true;
|
|
1897
2055
|
if (r && revisionOf(r) > revisionOf(lib)) conflicts.push(`library "${nameOf(lib)}" (server revision ${revisionOf(r)}, tree ${revisionOf(lib)})`);
|
|
@@ -1916,6 +2074,9 @@ rename one of them, or delete or rename the other in a push of its own first`
|
|
|
1916
2074
|
}
|
|
1917
2075
|
for (const r of rl.filter(inScope)) {
|
|
1918
2076
|
if (!ll.some((l) => idOf(l) === idOf(r))) {
|
|
2077
|
+
if (!opts.wholeReplace && known && idOf(r) in known.libraries && templatesOf2(r).some((t) => !localTemplateIds.has(idOf(t)) && !(idOf(t) in known.codeTemplates))) {
|
|
2078
|
+
throw new Error(`cannot delete library "${nameOf(r)}": it contains server-only code templates; pull and review their membership first`);
|
|
2079
|
+
}
|
|
1919
2080
|
const before = changes.length;
|
|
1920
2081
|
missingLocally("library", r, nameOf(r), known?.libraries);
|
|
1921
2082
|
if (changes.length > before) for (const id of channelsUsing(r, allChannelIds)) deploy.add(id);
|
|
@@ -1951,12 +2112,19 @@ function librariesToSend(local, remote, scope, plan) {
|
|
|
1951
2112
|
const rl = librariesOf(remote);
|
|
1952
2113
|
const inScope = scope.libraries === void 0 ? () => true : (o) => scope.libraries.includes(nameOf(o)) || scope.libraries.includes(idOf(o));
|
|
1953
2114
|
const deleted = new Set(plan.changes.filter((c) => c.kind === "library" && c.op === "delete").map((c) => c.id));
|
|
2115
|
+
const deletedTemplates = new Set(plan.changes.filter((c) => c.kind === "codeTemplate" && c.op === "delete").map((c) => c.id));
|
|
2116
|
+
const localTemplateIds = new Set(ll.flatMap(templatesOf2).map(idOf));
|
|
1954
2117
|
const localById = new Map(ll.map((l) => [idOf(l), l]));
|
|
1955
2118
|
const out = [];
|
|
1956
2119
|
for (const r of rl) {
|
|
1957
|
-
if (deleted.has(idOf(r)))
|
|
2120
|
+
if (deleted.has(idOf(r))) {
|
|
2121
|
+
if (templatesOf2(r).some((t) => !localTemplateIds.has(idOf(t)) && !deletedTemplates.has(idOf(t)))) {
|
|
2122
|
+
throw new Error(`cannot delete library "${nameOf(r)}": it contains server-only code templates; pull and review their membership first`);
|
|
2123
|
+
}
|
|
2124
|
+
continue;
|
|
2125
|
+
}
|
|
1958
2126
|
const l = localById.get(idOf(r));
|
|
1959
|
-
out.push(l && inScope(l) ? l : r);
|
|
2127
|
+
out.push(l && inScope(l) ? withRetainedMembers(l, r, localTemplateIds, deletedTemplates) : r);
|
|
1960
2128
|
}
|
|
1961
2129
|
for (const l of ll) if (inScope(l) && !rl.some((r) => idOf(r) === idOf(l))) out.push(l);
|
|
1962
2130
|
return out;
|
|
@@ -1973,16 +2141,20 @@ function changedSince(plan, before, after) {
|
|
|
1973
2141
|
else if (c.kind === "library") [b, a] = [lb.get(c.id), la.get(c.id)];
|
|
1974
2142
|
else if (!same(before["globalScripts"], after["globalScripts"])) out.push("global scripts");
|
|
1975
2143
|
if (c.kind === "globalScripts") continue;
|
|
1976
|
-
|
|
1977
|
-
const exists = a !== void 0;
|
|
1978
|
-
if (existed !== exists || a && b && revisionOf(a) !== revisionOf(b)) out.push(`${c.kind} "${c.label}"`);
|
|
2144
|
+
if (resourceChanged(c.kind, b, a)) out.push(`${c.kind} "${c.label}"`);
|
|
1979
2145
|
}
|
|
1980
2146
|
if (plan.changes.some((c) => c.kind === "library")) {
|
|
1981
|
-
|
|
1982
|
-
|
|
2147
|
+
if (lb.size !== la.size || [...lb].some(([id, l]) => resourceChanged("library", l, la.get(id)))) {
|
|
2148
|
+
out.push("code template libraries (the library list is saved as a whole)");
|
|
2149
|
+
}
|
|
1983
2150
|
}
|
|
1984
2151
|
return [...new Set(out)];
|
|
1985
2152
|
}
|
|
2153
|
+
function resourceChanged(kind, before, after) {
|
|
2154
|
+
if (!before || !after) return before !== after;
|
|
2155
|
+
const shape = kind === "library" ? libraryShape : stripVolatile;
|
|
2156
|
+
return revisionOf(before) !== revisionOf(after) || !same(shape(before), shape(after));
|
|
2157
|
+
}
|
|
1986
2158
|
function sameServerConfig(a, b) {
|
|
1987
2159
|
const { date: _a, ...ra } = a;
|
|
1988
2160
|
const { date: _b, ...rb } = b;
|
|
@@ -2007,7 +2179,7 @@ function findChannel(c, id) {
|
|
|
2007
2179
|
}
|
|
2008
2180
|
|
|
2009
2181
|
// src/push/apply.ts
|
|
2010
|
-
import { readdir, writeFile as writeFile2 } from "fs/promises";
|
|
2182
|
+
import { readdir as readdir2, writeFile as writeFile2 } from "fs/promises";
|
|
2011
2183
|
import { existsSync as existsSync2 } from "fs";
|
|
2012
2184
|
import * as path2 from "path";
|
|
2013
2185
|
var ORDER = [
|
|
@@ -2022,13 +2194,19 @@ async function applyPlan(client, plan, local, remote, scope, opts = {}) {
|
|
|
2022
2194
|
const applied = [];
|
|
2023
2195
|
const touchedIds = /* @__PURE__ */ new Set();
|
|
2024
2196
|
let librariesSent = false;
|
|
2197
|
+
let sentLibraries;
|
|
2025
2198
|
for (const [kind, ops] of ORDER) {
|
|
2026
2199
|
for (const change of plan.changes.filter((c) => c.kind === kind && ops.includes(c.op))) {
|
|
2027
2200
|
try {
|
|
2028
2201
|
if (kind === "library") {
|
|
2029
2202
|
if (!librariesSent) {
|
|
2030
|
-
const
|
|
2031
|
-
|
|
2203
|
+
const current = await client.getServerConfiguration();
|
|
2204
|
+
const moved = changedSince({ ...plan, changes: plan.changes.filter((c) => c.kind === "library") }, remote, current);
|
|
2205
|
+
if (!opts.force && moved.length) throw new Error(`changed on the server during the push: ${moved.join(", ")}; pull and try again`);
|
|
2206
|
+
const inSync = librariesInSync(local, current);
|
|
2207
|
+
const payload = librariesToSend(local, current, scope, plan);
|
|
2208
|
+
await client.putCodeTemplateLibraries(payload);
|
|
2209
|
+
sentLibraries = payload;
|
|
2032
2210
|
librariesSent = true;
|
|
2033
2211
|
const sentFromTree = librariesOf(local).filter(
|
|
2034
2212
|
(l) => scope.libraries === void 0 || scope.libraries.includes(String(l["name"])) || scope.libraries.includes(String(l["id"]))
|
|
@@ -2037,35 +2215,52 @@ async function applyPlan(client, plan, local, remote, scope, opts = {}) {
|
|
|
2037
2215
|
for (const id of inSync) touchedIds.add(id);
|
|
2038
2216
|
}
|
|
2039
2217
|
} else if (kind === "codeTemplate" && change.op === "delete") {
|
|
2218
|
+
await checkTemplate(client, change, remote, opts.force === true);
|
|
2040
2219
|
await client.deleteCodeTemplate(change.id);
|
|
2041
2220
|
} else if (kind === "codeTemplate") {
|
|
2221
|
+
await checkTemplate(client, change, remote, opts.force === true);
|
|
2042
2222
|
await client.putCodeTemplate(findTemplate(local, change.id));
|
|
2043
2223
|
} else if (kind === "channel" && change.op === "delete") {
|
|
2224
|
+
const current = await client.getChannel(change.id);
|
|
2225
|
+
checkResource(change, findChannel(remote, change.id), current, opts.force === true);
|
|
2044
2226
|
await client.deleteChannel(change.id);
|
|
2045
2227
|
} else if (kind === "channel") {
|
|
2228
|
+
const before = findChannel(remote, change.id);
|
|
2229
|
+
const channel = findChannel(local, change.id);
|
|
2230
|
+
if (!before || before["name"] !== channel["name"]) {
|
|
2231
|
+
planPush(local, await client.getServerConfiguration(), scope);
|
|
2232
|
+
}
|
|
2046
2233
|
await client.putChannel(
|
|
2047
|
-
await withServerAssociations(client,
|
|
2234
|
+
await withServerAssociations(client, channel, change, before, opts.force === true)
|
|
2048
2235
|
);
|
|
2049
2236
|
} else {
|
|
2237
|
+
const current = await client.getServerConfiguration();
|
|
2238
|
+
if (!opts.force && changedSince({ ...plan, changes: [change] }, remote, current).length) {
|
|
2239
|
+
throw new Error("global scripts changed on the server during the push; pull and try again");
|
|
2240
|
+
}
|
|
2050
2241
|
await client.putGlobalScripts(local["globalScripts"]);
|
|
2051
2242
|
}
|
|
2052
2243
|
} catch (err) {
|
|
2053
|
-
return { applied, failed: { change, error: err instanceof Error ? err.message : String(err) }, touchedIds };
|
|
2244
|
+
return { applied, failed: { change, error: err instanceof Error ? err.message : String(err) }, touchedIds, sentLibraries };
|
|
2054
2245
|
}
|
|
2055
2246
|
applied.push(change);
|
|
2056
2247
|
touchedIds.add(change.id);
|
|
2057
2248
|
}
|
|
2058
2249
|
}
|
|
2059
|
-
return { applied, touchedIds };
|
|
2250
|
+
return { applied, touchedIds, sentLibraries };
|
|
2060
2251
|
}
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
const server = await client.getChannel(String(channel["id"]));
|
|
2065
|
-
const [now, then] = [Number(server?.["revision"] ?? 0), Number(planned?.["revision"] ?? 0)];
|
|
2066
|
-
if (!force && now > then) {
|
|
2067
|
-
throw new Error(`changed on the server during the push (revision ${now}, planned against ${then}); pull and try again`);
|
|
2252
|
+
function checkResource(change, before, current, force) {
|
|
2253
|
+
if (!force && resourceChanged(change.kind, before, current ?? void 0)) {
|
|
2254
|
+
throw new Error(`${change.label} changed on the server during the push (revision ${String(current?.["revision"] ?? "absent")}, planned against ${String(before?.["revision"] ?? "absent")}); pull and try again`);
|
|
2068
2255
|
}
|
|
2256
|
+
}
|
|
2257
|
+
async function checkTemplate(client, change, remote, force) {
|
|
2258
|
+
checkResource(change, findTemplate(remote, change.id), await client.getCodeTemplate(change.id), force);
|
|
2259
|
+
}
|
|
2260
|
+
async function withServerAssociations(client, channel, change, planned, force) {
|
|
2261
|
+
const server = await client.getChannel(String(channel["id"]));
|
|
2262
|
+
checkResource(change, planned, server, force);
|
|
2263
|
+
if (change.op !== "update") return channel;
|
|
2069
2264
|
const serverExport = server?.["exportData"];
|
|
2070
2265
|
if (!serverExport) return channel;
|
|
2071
2266
|
const exportData = { ...channel["exportData"] ?? {} };
|
|
@@ -2073,15 +2268,22 @@ async function withServerAssociations(client, channel, op, planned, force) {
|
|
|
2073
2268
|
return { ...channel, exportData };
|
|
2074
2269
|
}
|
|
2075
2270
|
async function deployChannels(client, ids, nameOf2) {
|
|
2271
|
+
const deployed = [];
|
|
2272
|
+
const skipped = [];
|
|
2076
2273
|
const failures = [];
|
|
2077
2274
|
for (const id of ids) {
|
|
2078
2275
|
try {
|
|
2276
|
+
if (!(await client.getDeployedChannelIds()).has(id)) {
|
|
2277
|
+
skipped.push(nameOf2(id));
|
|
2278
|
+
continue;
|
|
2279
|
+
}
|
|
2079
2280
|
await client.deployChannel(id);
|
|
2281
|
+
deployed.push(nameOf2(id));
|
|
2080
2282
|
} catch (err) {
|
|
2081
2283
|
failures.push({ name: nameOf2(id), error: err instanceof Error ? err.message : String(err) });
|
|
2082
2284
|
}
|
|
2083
2285
|
}
|
|
2084
|
-
return failures;
|
|
2286
|
+
return { deployed, skipped, failures };
|
|
2085
2287
|
}
|
|
2086
2288
|
function copyVersionFields(target, source) {
|
|
2087
2289
|
if (!source) return false;
|
|
@@ -2102,7 +2304,7 @@ function copyVersionFields(target, source) {
|
|
|
2102
2304
|
}
|
|
2103
2305
|
async function jsonFiles(dir, name) {
|
|
2104
2306
|
if (!existsSync2(dir)) return [];
|
|
2105
|
-
const entries = await
|
|
2307
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
2106
2308
|
return entries.filter((e) => e.isDirectory()).map((e) => path2.join(dir, e.name, name)).filter((f) => existsSync2(f));
|
|
2107
2309
|
}
|
|
2108
2310
|
async function refreshRevisions(root, server, ids) {
|
|
@@ -2127,7 +2329,7 @@ async function refreshRevisions(root, server, ids) {
|
|
|
2127
2329
|
// src/secrets/envfile.ts
|
|
2128
2330
|
import { randomBytes } from "crypto";
|
|
2129
2331
|
import { existsSync as existsSync3 } from "fs";
|
|
2130
|
-
import { appendFile, chmod, copyFile, mkdir as mkdir2, readFile as readFile3, readdir as
|
|
2332
|
+
import { appendFile, chmod, copyFile, mkdir as mkdir2, readFile as readFile3, readdir as readdir3, realpath as realpath2, rename, rm, writeFile as writeFile3 } from "fs/promises";
|
|
2131
2333
|
import * as path3 from "path";
|
|
2132
2334
|
import { parse } from "dotenv";
|
|
2133
2335
|
var BASE64_PREFIX = "cv-base64:";
|
|
@@ -2213,25 +2415,25 @@ async function backupEnvFile(file, updates, dir) {
|
|
|
2213
2415
|
for (let n = 2; existsSync3(target); n += 1) target = path3.join(dir, `${prefix}${stamp2}-${String(n).padStart(2, "0")}`);
|
|
2214
2416
|
await copyFile(file, target);
|
|
2215
2417
|
await chmod(target, 384);
|
|
2216
|
-
const others = (await
|
|
2418
|
+
const others = (await readdir3(dir)).filter((f) => f.startsWith(prefix) && f !== path3.basename(target)).sort();
|
|
2217
2419
|
for (const old of others.slice(0, Math.max(0, others.length - (ENV_BACKUPS_KEPT - 1)))) {
|
|
2218
2420
|
await rm(path3.join(dir, old));
|
|
2219
2421
|
}
|
|
2220
2422
|
return target;
|
|
2221
2423
|
}
|
|
2222
2424
|
var IGNORE_LINES = [".env", ".env.*", "!.env.example", ".secrets/"];
|
|
2223
|
-
async function ensureEnvIgnored(dir, envFile) {
|
|
2425
|
+
async function ensureEnvIgnored(dir, envFile, treeRoot = dir) {
|
|
2224
2426
|
const file = path3.join(dir, ".gitignore");
|
|
2225
2427
|
const text = existsSync3(file) ? await readFile3(file, "utf8") : "";
|
|
2226
|
-
const
|
|
2428
|
+
const present2 = new Set(text.split(/\r?\n/).map((l) => l.trim()));
|
|
2227
2429
|
const wanted = [...IGNORE_LINES];
|
|
2228
2430
|
if (envFile) {
|
|
2229
|
-
const rel = path3.relative(
|
|
2431
|
+
const rel = path3.relative(treeRoot, envFile).split(path3.sep).join("/");
|
|
2230
2432
|
const base = path3.basename(envFile);
|
|
2231
2433
|
const covered = !rel.includes("/") && (base === ".env" || base.startsWith(".env.") && base !== ".env.example");
|
|
2232
2434
|
if (!covered && !rel.startsWith("..") && !path3.isAbsolute(rel)) wanted.push(`/${rel}`);
|
|
2233
2435
|
}
|
|
2234
|
-
const missing = wanted.filter((l) => !
|
|
2436
|
+
const missing = wanted.filter((l) => !present2.has(l));
|
|
2235
2437
|
if (missing.length === 0) return false;
|
|
2236
2438
|
const prefix = text === "" || text.endsWith("\n") ? "" : "\n";
|
|
2237
2439
|
await appendFile(file, `${prefix}# channelvault: secrets and per-environment values
|
|
@@ -2243,7 +2445,7 @@ ${missing.join("\n")}
|
|
|
2243
2445
|
// src/backup/index.ts
|
|
2244
2446
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
2245
2447
|
import { existsSync as existsSync4, realpathSync } from "fs";
|
|
2246
|
-
import { mkdir as mkdir3, readdir as
|
|
2448
|
+
import { mkdir as mkdir3, readdir as readdir4, readFile as readFile4, rename as rename2, rm as rm2, writeFile as writeFile4 } from "fs/promises";
|
|
2247
2449
|
import * as path4 from "path";
|
|
2248
2450
|
var DEFAULT_BACKUP_DIR = ".backup";
|
|
2249
2451
|
var DEFAULT_KEEP = 10;
|
|
@@ -2268,7 +2470,7 @@ function stamp(date) {
|
|
|
2268
2470
|
async function listBackups(dir) {
|
|
2269
2471
|
if (!existsSync4(dir)) return [];
|
|
2270
2472
|
const out = [];
|
|
2271
|
-
for (const name of await
|
|
2473
|
+
for (const name of await readdir4(dir)) {
|
|
2272
2474
|
const m = FILE_NAME.exec(name);
|
|
2273
2475
|
if (m) out.push({ file: path4.join(dir, name), server: m[1], stamp: m[2], seq: m[3] ? Number(m[3]) : 1 });
|
|
2274
2476
|
}
|
|
@@ -2286,8 +2488,8 @@ async function readManifest(dir) {
|
|
|
2286
2488
|
}
|
|
2287
2489
|
}
|
|
2288
2490
|
async function writeManifest(dir, files) {
|
|
2289
|
-
const
|
|
2290
|
-
await writePrivate(path4.join(dir, MANIFEST), `${JSON.stringify({ version: 1, files:
|
|
2491
|
+
const present2 = Object.fromEntries(Object.entries(files).filter(([name]) => existsSync4(path4.join(dir, name))));
|
|
2492
|
+
await writePrivate(path4.join(dir, MANIFEST), `${JSON.stringify({ version: 1, files: present2 }, null, 2)}
|
|
2291
2493
|
`);
|
|
2292
2494
|
}
|
|
2293
2495
|
async function backupsOf(dir, serverId) {
|
|
@@ -2357,6 +2559,256 @@ function compareVersions(a, b) {
|
|
|
2357
2559
|
return 0;
|
|
2358
2560
|
}
|
|
2359
2561
|
|
|
2562
|
+
// src/xml/chars.ts
|
|
2563
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
2564
|
+
import * as path6 from "path";
|
|
2565
|
+
|
|
2566
|
+
// src/tree/transaction.ts
|
|
2567
|
+
import { randomUUID } from "crypto";
|
|
2568
|
+
import { constants, existsSync as existsSync5 } from "fs";
|
|
2569
|
+
import { copyFile as copyFile2, lstat as lstat2, mkdir as mkdir4, readdir as readdir5, readlink, realpath as realpath3, rename as rename3, rm as rm3, rmdir, unlink, writeFile as writeFile5 } from "fs/promises";
|
|
2570
|
+
import { hostname } from "os";
|
|
2571
|
+
import * as path5 from "path";
|
|
2572
|
+
import { setTimeout as delay } from "timers/promises";
|
|
2573
|
+
var MANAGED_DIRS = ["server", "channels", "codeTemplates", "channelGroups"];
|
|
2574
|
+
async function treeFiles(base) {
|
|
2575
|
+
const out = [];
|
|
2576
|
+
for (const d of MANAGED_DIRS) {
|
|
2577
|
+
if (!existsSync5(path5.join(base, d))) continue;
|
|
2578
|
+
for (const entry of await readdir5(path5.join(base, d), { recursive: true, withFileTypes: true })) {
|
|
2579
|
+
if (entry.isFile()) out.push(path5.relative(base, path5.join(entry.parentPath, entry.name)).split(path5.sep).join("/"));
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
return out;
|
|
2583
|
+
}
|
|
2584
|
+
var STAGING_DIR = ".channelvault-staging";
|
|
2585
|
+
var JOURNAL = ".channelvault-transaction.json";
|
|
2586
|
+
var ITEMS = [...MANAGED_DIRS, "channelvault.json", ".gitignore", ".secrets", "env"];
|
|
2587
|
+
var RM = { recursive: true, force: true, maxRetries: 5, retryDelay: 50 };
|
|
2588
|
+
async function present(file) {
|
|
2589
|
+
return lstat2(file).then(() => true, (err) => {
|
|
2590
|
+
if (err.code === "ENOENT") return false;
|
|
2591
|
+
throw err;
|
|
2592
|
+
});
|
|
2593
|
+
}
|
|
2594
|
+
async function canonical(file, depth = 0) {
|
|
2595
|
+
if (depth > 64) throw new Error(`too many links in path: ${file}`);
|
|
2596
|
+
let existing = path5.resolve(file);
|
|
2597
|
+
while (!await present(existing) && path5.dirname(existing) !== existing) existing = path5.dirname(existing);
|
|
2598
|
+
const info = await lstat2(existing);
|
|
2599
|
+
const base = info.isSymbolicLink() ? await canonical(path5.resolve(path5.dirname(existing), await readlink(existing)), depth + 1) : await realpath3(existing);
|
|
2600
|
+
return path5.join(base, path5.relative(existing, path5.resolve(file)));
|
|
2601
|
+
}
|
|
2602
|
+
var samePath = (a, b) => process.platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
2603
|
+
async function move(from, to) {
|
|
2604
|
+
for (let attempt = 0; ; attempt++) {
|
|
2605
|
+
try {
|
|
2606
|
+
await rename3(from, to);
|
|
2607
|
+
return;
|
|
2608
|
+
} catch (err) {
|
|
2609
|
+
if (attempt >= 5 || !["EPERM", "EBUSY", "ENOTEMPTY", "EACCES"].includes(err.code ?? "")) throw err;
|
|
2610
|
+
await delay(50 * (attempt + 1));
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
async function lockTree(root) {
|
|
2615
|
+
await mkdir4(path5.dirname(root), { recursive: true });
|
|
2616
|
+
const lock = `${await canonical(root)}.channelvault-lock`;
|
|
2617
|
+
const ownerFile = path5.join(lock, "owner.json");
|
|
2618
|
+
const owner = { pid: process.pid, host: hostname(), token: randomUUID() };
|
|
2619
|
+
try {
|
|
2620
|
+
await mkdir4(lock);
|
|
2621
|
+
} catch (err) {
|
|
2622
|
+
if (err.code !== "EEXIST") throw err;
|
|
2623
|
+
if ((await lstat2(lock)).isSymbolicLink()) throw new Error(`refusing a linked working-tree lock: ${lock}`);
|
|
2624
|
+
let previous;
|
|
2625
|
+
try {
|
|
2626
|
+
previous = await readJson(ownerFile);
|
|
2627
|
+
} catch {
|
|
2628
|
+
throw new Error(`working-tree lock has no readable owner: ${lock}; inspect it before removing it`);
|
|
2629
|
+
}
|
|
2630
|
+
const dead = () => {
|
|
2631
|
+
if (previous.host !== hostname() || !Number.isInteger(previous.pid) || previous.pid <= 0) return false;
|
|
2632
|
+
try {
|
|
2633
|
+
process.kill(previous.pid, 0);
|
|
2634
|
+
return false;
|
|
2635
|
+
} catch (error) {
|
|
2636
|
+
return error.code === "ESRCH";
|
|
2637
|
+
}
|
|
2638
|
+
};
|
|
2639
|
+
if (!dead()) throw new Error(`working tree is locked by process ${previous.pid} on ${previous.host}: ${lock}`);
|
|
2640
|
+
const reaping = path5.join(lock, "reaping");
|
|
2641
|
+
try {
|
|
2642
|
+
await mkdir4(reaping);
|
|
2643
|
+
} catch {
|
|
2644
|
+
throw new Error(`another process is recovering the working-tree lock: ${lock}; retry`);
|
|
2645
|
+
}
|
|
2646
|
+
try {
|
|
2647
|
+
const check = await readJson(ownerFile);
|
|
2648
|
+
if (check.token !== previous.token || !dead()) throw new Error(`working-tree lock changed: ${lock}; retry`);
|
|
2649
|
+
await unlink(ownerFile);
|
|
2650
|
+
} finally {
|
|
2651
|
+
await rmdir(reaping);
|
|
2652
|
+
}
|
|
2653
|
+
await rmdir(lock);
|
|
2654
|
+
await mkdir4(lock);
|
|
2655
|
+
}
|
|
2656
|
+
try {
|
|
2657
|
+
await writeFile5(ownerFile, JSON.stringify(owner), { flag: "wx", mode: 384 });
|
|
2658
|
+
} catch (err) {
|
|
2659
|
+
await rmdir(lock).catch(() => void 0);
|
|
2660
|
+
throw err;
|
|
2661
|
+
}
|
|
2662
|
+
return async () => {
|
|
2663
|
+
const check = await readJson(ownerFile);
|
|
2664
|
+
if (check.token !== owner.token) throw new Error(`working-tree lock ownership changed: ${lock}`);
|
|
2665
|
+
await unlink(ownerFile);
|
|
2666
|
+
await rmdir(lock);
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2669
|
+
async function assertStage(root) {
|
|
2670
|
+
for (const suffix of ["", "next", "previous"]) {
|
|
2671
|
+
const stage = path5.join(root, STAGING_DIR, suffix);
|
|
2672
|
+
const info = await lstat2(stage).catch((err) => {
|
|
2673
|
+
if (err.code !== "ENOENT") throw err;
|
|
2674
|
+
return void 0;
|
|
2675
|
+
});
|
|
2676
|
+
if (info?.isSymbolicLink()) throw new Error(`refusing a linked staging directory: ${stage}`);
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
function targetOf(root, journal, name) {
|
|
2680
|
+
return name === "env" ? journal.envFile : path5.join(root, name);
|
|
2681
|
+
}
|
|
2682
|
+
function copies(root, journal, name) {
|
|
2683
|
+
return name === "env" ? { old: `${journal.envFile}.channelvault-${journal.id}.previous`, next: `${journal.envFile}.channelvault-${journal.id}.next` } : { old: path5.join(root, STAGING_DIR, "previous", name), next: path5.join(root, STAGING_DIR, "next", name) };
|
|
2684
|
+
}
|
|
2685
|
+
async function cleanup(root, journal) {
|
|
2686
|
+
if (journal.entries.some((e) => e.name === "env")) {
|
|
2687
|
+
const { old, next } = copies(root, journal, "env");
|
|
2688
|
+
await rm3(old, { force: true });
|
|
2689
|
+
await rm3(next, { force: true });
|
|
2690
|
+
}
|
|
2691
|
+
await rm3(path5.join(root, STAGING_DIR), RM);
|
|
2692
|
+
}
|
|
2693
|
+
async function rollback(root, journal) {
|
|
2694
|
+
for (const entry of [...journal.entries].reverse()) {
|
|
2695
|
+
const target = targetOf(root, journal, entry.name);
|
|
2696
|
+
const { old, next } = copies(root, journal, entry.name);
|
|
2697
|
+
if (await present(old)) {
|
|
2698
|
+
await rm3(target, RM);
|
|
2699
|
+
await move(old, target);
|
|
2700
|
+
} else if (!entry.hadOld && !await present(next)) {
|
|
2701
|
+
await rm3(target, RM);
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
async function recoverTree(root, envFile) {
|
|
2706
|
+
const file = path5.join(root, JOURNAL);
|
|
2707
|
+
if (!existsSync5(file)) return;
|
|
2708
|
+
await assertStage(root);
|
|
2709
|
+
const journal = await readJson(file);
|
|
2710
|
+
if (journal.version !== 1 || !/^[a-f0-9-]{36}$/.test(journal.id) || !["prepared", "committed"].includes(journal.state) || !Array.isArray(journal.entries) || journal.entries.some((e) => !ITEMS.includes(e.name) || typeof e.hadOld !== "boolean") || new Set(journal.entries.map((e) => e.name)).size !== journal.entries.length || typeof journal.envFile !== "string" || !samePath(journal.envFile, await canonical(envFile))) {
|
|
2711
|
+
throw new Error(`invalid transaction journal or different env file: ${file}; use the original --dotenv selection to recover`);
|
|
2712
|
+
}
|
|
2713
|
+
if (journal.state === "prepared") await rollback(root, journal);
|
|
2714
|
+
await cleanup(root, journal);
|
|
2715
|
+
await unlink(file);
|
|
2716
|
+
}
|
|
2717
|
+
async function replaceTree(root, envFile, prepare) {
|
|
2718
|
+
await recoverTree(root, envFile);
|
|
2719
|
+
await assertStage(root);
|
|
2720
|
+
const stage = path5.join(root, STAGING_DIR);
|
|
2721
|
+
await rm3(stage, RM);
|
|
2722
|
+
const next = path5.join(stage, "next");
|
|
2723
|
+
await mkdir4(next, { recursive: true });
|
|
2724
|
+
let journal;
|
|
2725
|
+
try {
|
|
2726
|
+
await prepare(next);
|
|
2727
|
+
const targetEnv = await canonical(envFile);
|
|
2728
|
+
journal = { version: 1, id: randomUUID(), state: "prepared", envFile: targetEnv, entries: [] };
|
|
2729
|
+
for (const name of ITEMS) {
|
|
2730
|
+
if (!MANAGED_DIRS.includes(name) && !existsSync5(path5.join(next, name === "env" ? ".env" : name))) continue;
|
|
2731
|
+
const target = targetOf(root, journal, name);
|
|
2732
|
+
const info = await lstat2(target).catch((err) => {
|
|
2733
|
+
if (err.code !== "ENOENT") throw err;
|
|
2734
|
+
return void 0;
|
|
2735
|
+
});
|
|
2736
|
+
journal.entries.push({ name, hadOld: info !== void 0 });
|
|
2737
|
+
}
|
|
2738
|
+
await mkdir4(path5.join(stage, "previous"));
|
|
2739
|
+
await writePrivate(path5.join(root, JOURNAL), JSON.stringify(journal));
|
|
2740
|
+
if (journal.entries.some((e) => e.name === "env")) {
|
|
2741
|
+
await mkdir4(path5.dirname(targetEnv), { recursive: true });
|
|
2742
|
+
await copyFile2(path5.join(next, ".env"), copies(root, journal, "env").next, constants.COPYFILE_EXCL);
|
|
2743
|
+
}
|
|
2744
|
+
for (const entry of journal.entries) {
|
|
2745
|
+
const target = targetOf(root, journal, entry.name);
|
|
2746
|
+
const files = copies(root, journal, entry.name);
|
|
2747
|
+
if (entry.hadOld) await move(target, files.old);
|
|
2748
|
+
if (existsSync5(files.next)) {
|
|
2749
|
+
await mkdir4(path5.dirname(target), { recursive: true });
|
|
2750
|
+
await move(files.next, target);
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
journal.state = "committed";
|
|
2754
|
+
await writePrivate(path5.join(root, JOURNAL), JSON.stringify(journal));
|
|
2755
|
+
} catch (err) {
|
|
2756
|
+
if (journal && existsSync5(path5.join(root, JOURNAL))) {
|
|
2757
|
+
try {
|
|
2758
|
+
await rollback(root, journal);
|
|
2759
|
+
} catch (recoveryError) {
|
|
2760
|
+
throw new Error(`replacement failed and recovery is pending in ${path5.join(root, JOURNAL)}; retry this command with the same env file`, { cause: recoveryError });
|
|
2761
|
+
}
|
|
2762
|
+
await cleanup(root, journal);
|
|
2763
|
+
await unlink(path5.join(root, JOURNAL));
|
|
2764
|
+
}
|
|
2765
|
+
await rm3(stage, RM);
|
|
2766
|
+
throw err;
|
|
2767
|
+
}
|
|
2768
|
+
await cleanup(root, journal);
|
|
2769
|
+
await unlink(path5.join(root, JOURNAL));
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
// src/xml/chars.ts
|
|
2773
|
+
var FORBIDDEN = /[\x00-\x08\x0b\x0c\x0e-\x1f\ud800-\udfff]/gu;
|
|
2774
|
+
var hex = (ch) => `U+${ch.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
2775
|
+
function positions(text) {
|
|
2776
|
+
const out = [];
|
|
2777
|
+
text.split(/\r\n|\r|\n/).forEach((line, i) => {
|
|
2778
|
+
for (const m of line.matchAll(FORBIDDEN)) {
|
|
2779
|
+
out.push({ line: i + 1, column: [...line.slice(0, m.index)].length + 1, codePoint: hex(m[0]) });
|
|
2780
|
+
}
|
|
2781
|
+
});
|
|
2782
|
+
return out;
|
|
2783
|
+
}
|
|
2784
|
+
function forbiddenXmlChars(config) {
|
|
2785
|
+
const out = [];
|
|
2786
|
+
mapLeaves(config, (value, leaf) => {
|
|
2787
|
+
const owner = leaf.configMapKey !== void 0 ? [`configuration map ${leaf.configMapKey}`] : leaf.labels.length ? leaf.labels : [leaf.location];
|
|
2788
|
+
for (const p of positions(value)) out.push({ where: [...owner, leaf.key].join(" \u203A "), ...p });
|
|
2789
|
+
return value;
|
|
2790
|
+
});
|
|
2791
|
+
return out;
|
|
2792
|
+
}
|
|
2793
|
+
async function forbiddenInFiles(root) {
|
|
2794
|
+
const out = [];
|
|
2795
|
+
for (const file of await treeFiles(root)) {
|
|
2796
|
+
for (const p of positions(await readFile5(path6.join(root, file), "utf8"))) out.push(`${file}:${p.line}:${p.column} (${p.codePoint})`);
|
|
2797
|
+
}
|
|
2798
|
+
return out;
|
|
2799
|
+
}
|
|
2800
|
+
async function xmlSafetyProblem(config, treeRoot) {
|
|
2801
|
+
const found = forbiddenXmlChars(config);
|
|
2802
|
+
if (found.length === 0) return void 0;
|
|
2803
|
+
const files = treeRoot ? await forbiddenInFiles(treeRoot) : [];
|
|
2804
|
+
return [
|
|
2805
|
+
`${found.length} character(s) that XML 1.0 forbids; Mirth would save them and then fail to export its configuration (HTTP 500), breaking every later pull, push and restore:`,
|
|
2806
|
+
...found.map((f) => ` ${f.where}: line ${f.line}, column ${f.column} of the value (${f.codePoint})`),
|
|
2807
|
+
...files.length ? ["in the tree:", ...files.map((f) => ` ${f}`)] : [],
|
|
2808
|
+
"escape them in the script, for example \\uFFFE inside a regex or string"
|
|
2809
|
+
].join("\n");
|
|
2810
|
+
}
|
|
2811
|
+
|
|
2360
2812
|
// src/cli.ts
|
|
2361
2813
|
var engine = createExplodeEngine();
|
|
2362
2814
|
var xml = new XmlConfigAdapter();
|
|
@@ -2367,8 +2819,6 @@ function fail(message) {
|
|
|
2367
2819
|
throw new CliError(message);
|
|
2368
2820
|
}
|
|
2369
2821
|
var errorExitCode = 1;
|
|
2370
|
-
var MANAGED_DIRS = ["server", "channels", "codeTemplates", "channelGroups"];
|
|
2371
|
-
var STAGING_DIR = ".channelvault-staging";
|
|
2372
2822
|
var RM_OPTS = { recursive: true, force: true, maxRetries: 5, retryDelay: 50 };
|
|
2373
2823
|
function resolveClientConfig(flags) {
|
|
2374
2824
|
const host = flags.host ?? process.env.MIRTH_HOST;
|
|
@@ -2416,7 +2866,7 @@ function addBackupDirFlags(cmd) {
|
|
|
2416
2866
|
return cmd.option("--backup-dir <dir>", `where backups are kept (default ./${DEFAULT_BACKUP_DIR})`).option("--keep <n>", `backups kept per server (default ${DEFAULT_KEEP})`);
|
|
2417
2867
|
}
|
|
2418
2868
|
function backupDirOf(flags) {
|
|
2419
|
-
return
|
|
2869
|
+
return path7.resolve(flags.backupDir ?? DEFAULT_BACKUP_DIR);
|
|
2420
2870
|
}
|
|
2421
2871
|
function keepOf(flags) {
|
|
2422
2872
|
if (flags.keep === void 0) return DEFAULT_KEEP;
|
|
@@ -2448,8 +2898,36 @@ async function saveServerBackup(client, text, flags, protect) {
|
|
|
2448
2898
|
async function backupBeforePush(client, flags) {
|
|
2449
2899
|
if (flags.backup === false) return;
|
|
2450
2900
|
const file = await saveServerBackup(client, await client.getServerConfigurationXml(), flags);
|
|
2451
|
-
process.stdout.write(`backed up the server to ${file} (undo with:
|
|
2901
|
+
process.stdout.write(`backed up the server to ${file} (undo with: ${undoCommand(file, flags)})
|
|
2452
2902
|
`);
|
|
2903
|
+
printUndoLimits(flags);
|
|
2904
|
+
}
|
|
2905
|
+
function shellArgument(value) {
|
|
2906
|
+
return process.platform === "win32" ? `'${value.replace(/'/g, "''")}'` : `'${value.replace(/'/g, "'\\''")}'`;
|
|
2907
|
+
}
|
|
2908
|
+
function undoCommand(file, flags) {
|
|
2909
|
+
const cfg = resolveClientConfig(flags);
|
|
2910
|
+
const args = [
|
|
2911
|
+
"channelvault",
|
|
2912
|
+
"restore",
|
|
2913
|
+
shellArgument(file),
|
|
2914
|
+
"--host",
|
|
2915
|
+
shellArgument(cfg.host),
|
|
2916
|
+
"--port",
|
|
2917
|
+
String(cfg.port),
|
|
2918
|
+
"--user",
|
|
2919
|
+
shellArgument(cfg.username),
|
|
2920
|
+
"--backup-dir",
|
|
2921
|
+
shellArgument(backupDirOf(flags))
|
|
2922
|
+
];
|
|
2923
|
+
if (cfg.https === false) args.push("--no-https");
|
|
2924
|
+
if (cfg.disableTlsCheck) args.push("--insecure");
|
|
2925
|
+
if (flags.overwriteConfigMap) args.push("--overwrite-config-map");
|
|
2926
|
+
return args.join(" ");
|
|
2927
|
+
}
|
|
2928
|
+
function printUndoLimits(flags) {
|
|
2929
|
+
if (flags.pass !== void 0) process.stdout.write("undo authentication: supply this server's password through MIRTH_PASS; it is omitted from the command\n");
|
|
2930
|
+
if (flags.deploy) process.stdout.write("the undo restores saved configuration; runtime deployment state is not in the backup. Review targeted redeployment separately\n");
|
|
2453
2931
|
}
|
|
2454
2932
|
function hostOf(flags) {
|
|
2455
2933
|
const cfg = resolveClientConfig(flags);
|
|
@@ -2491,7 +2969,7 @@ function summarize(config) {
|
|
|
2491
2969
|
codeTemplates
|
|
2492
2970
|
};
|
|
2493
2971
|
}
|
|
2494
|
-
async function writeMeta(root, source, config, previous) {
|
|
2972
|
+
async function writeMeta(root, source, config, previous, serverId, resources = resourceIds(config)) {
|
|
2495
2973
|
const meta = {
|
|
2496
2974
|
tool: "channelvault",
|
|
2497
2975
|
version: VERSION,
|
|
@@ -2499,14 +2977,15 @@ async function writeMeta(root, source, config, previous) {
|
|
|
2499
2977
|
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2500
2978
|
// XML adapter yields `@_version`; the live JSON API yields `@version` (Jackson).
|
|
2501
2979
|
engineVersion: typeof config["@_version"] === "string" ? config["@_version"] : typeof config["@version"] === "string" ? config["@version"] : null,
|
|
2502
|
-
resources
|
|
2980
|
+
resources,
|
|
2981
|
+
serverId
|
|
2503
2982
|
};
|
|
2504
|
-
const file =
|
|
2505
|
-
if (previous && JSON.stringify({ ...previous, pulledAt: "" }) === JSON.stringify({ ...meta, pulledAt: "" }))
|
|
2506
|
-
await
|
|
2983
|
+
const file = path7.join(root, "channelvault.json");
|
|
2984
|
+
if (previous && JSON.stringify({ ...previous, pulledAt: "" }) === JSON.stringify({ ...meta, pulledAt: "" })) meta.pulledAt = previous.pulledAt;
|
|
2985
|
+
await writeFile6(file, JSON.stringify(meta, null, 2) + "\n", "utf8");
|
|
2507
2986
|
}
|
|
2508
2987
|
function envFilePath(root, flags) {
|
|
2509
|
-
return flags.dotenv ?
|
|
2988
|
+
return flags.dotenv ? path7.resolve(flags.dotenv) : path7.join(root, ".env");
|
|
2510
2989
|
}
|
|
2511
2990
|
async function loadEnv(file) {
|
|
2512
2991
|
return { ...await readEnvFile(file), ...process.env };
|
|
@@ -2518,7 +2997,7 @@ function addExtractFlag(cmd) {
|
|
|
2518
2997
|
return cmd.option("--extract-secrets", "move secrets found inside values (URLs, scripts, headers) to the env file", false);
|
|
2519
2998
|
}
|
|
2520
2999
|
async function existingTree(root) {
|
|
2521
|
-
return
|
|
3000
|
+
return existsSync6(path7.join(root, "server", "configuration.json")) ? engine.implode({ root }) : null;
|
|
2522
3001
|
}
|
|
2523
3002
|
async function renderedTree(root, flags) {
|
|
2524
3003
|
const tree = await engine.implode({ root });
|
|
@@ -2547,12 +3026,12 @@ function scrub(text) {
|
|
|
2547
3026
|
}
|
|
2548
3027
|
var ALLOW_FILE = "channelvault.allow.json";
|
|
2549
3028
|
async function readAllow(root) {
|
|
2550
|
-
const file =
|
|
2551
|
-
if (!
|
|
3029
|
+
const file = path7.join(root, ALLOW_FILE);
|
|
3030
|
+
if (!existsSync6(file)) return [];
|
|
2552
3031
|
const parsed = await readJson(file);
|
|
2553
3032
|
return parsed.ignore ?? [];
|
|
2554
3033
|
}
|
|
2555
|
-
async function writeTree(root, fetched, source, flags) {
|
|
3034
|
+
async function writeTree(root, fetched, source, flags, serverId) {
|
|
2556
3035
|
const envFile = envFilePath(root, flags);
|
|
2557
3036
|
const previousMeta = await preflightTree(root, envFile);
|
|
2558
3037
|
const env = await loadEnv(envFile);
|
|
@@ -2573,15 +3052,30 @@ Rerun with --extract-secrets to move them to ${envFile}, or list false positives
|
|
|
2573
3052
|
const envUpdates = { ...templated.envUpdates, ...scan.envUpdates };
|
|
2574
3053
|
rememberSecrets(config, { ...env, ...envUpdates });
|
|
2575
3054
|
const echoes = findEchoes(config, { ...await readEnvFile(envFile), ...envUpdates });
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
3055
|
+
const rel = path7.relative(root, envFile);
|
|
3056
|
+
const envInTree = !rel.startsWith("..") && !path7.isAbsolute(rel);
|
|
3057
|
+
let backup = null;
|
|
3058
|
+
await replaceTree(root, envFile, async (next) => {
|
|
3059
|
+
await engine.explode(config, { root: next });
|
|
3060
|
+
await writeMeta(next, source, fetched, previousMeta, serverId);
|
|
3061
|
+
if (Object.keys(envUpdates).length > 0) {
|
|
3062
|
+
const history = path7.join(root, ".secrets");
|
|
3063
|
+
if (existsSync6(history)) {
|
|
3064
|
+
if ((await lstat3(history)).isSymbolicLink()) fail(`refusing a linked secret history directory: ${history}`);
|
|
3065
|
+
await cp(history, path7.join(next, ".secrets"), { recursive: true });
|
|
3066
|
+
}
|
|
3067
|
+
const stagedBackup = await backupEnvFile(envFile, envUpdates, path7.join(next, ".secrets"));
|
|
3068
|
+
if (stagedBackup) backup = path7.join(root, ".secrets", path7.basename(stagedBackup));
|
|
3069
|
+
if (backup || envInTree) {
|
|
3070
|
+
const ignore = path7.join(root, ".gitignore");
|
|
3071
|
+
if (existsSync6(ignore)) await writeFile6(path7.join(next, ".gitignore"), await readFile6(ignore));
|
|
3072
|
+
await ensureEnvIgnored(next, envInTree ? envFile : void 0, root);
|
|
3073
|
+
}
|
|
3074
|
+
const stagedEnv = path7.join(next, ".env");
|
|
3075
|
+
if (existsSync6(envFile)) await writeFile6(stagedEnv, await readFile6(envFile), { mode: 384 });
|
|
3076
|
+
await updateEnvFile(stagedEnv, envUpdates);
|
|
3077
|
+
}
|
|
3078
|
+
});
|
|
2585
3079
|
if (scan.findings.length > 0) process.stdout.write(`extracted ${scan.findings.length} secret(s) found in values
|
|
2586
3080
|
`);
|
|
2587
3081
|
const updated = Object.keys(envUpdates).length;
|
|
@@ -2595,34 +3089,34 @@ Rerun with --extract-secrets to move them to ${envFile}, or list false positives
|
|
|
2595
3089
|
process.stderr.write(`warning: the value of ${e.name} also appears in plain text at ${e.where}
|
|
2596
3090
|
`);
|
|
2597
3091
|
}
|
|
2598
|
-
if (
|
|
3092
|
+
if (existsSync6(envFile) && gitWouldCommit(envFile)) {
|
|
2599
3093
|
process.stderr.write(`warning: git does not ignore ${envFile}, so its secret values could be committed; add it to .gitignore
|
|
2600
3094
|
`);
|
|
2601
3095
|
}
|
|
2602
3096
|
}
|
|
2603
3097
|
function gitWouldCommit(file) {
|
|
2604
|
-
const r = spawnSync("git", ["check-ignore", "-q",
|
|
3098
|
+
const r = spawnSync("git", ["check-ignore", "-q", path7.basename(file)], { cwd: path7.dirname(file) });
|
|
2605
3099
|
return r.status === 1;
|
|
2606
3100
|
}
|
|
2607
3101
|
async function resolvedPath(p) {
|
|
2608
|
-
const abs =
|
|
3102
|
+
const abs = path7.resolve(p);
|
|
2609
3103
|
let existing = abs;
|
|
2610
|
-
while (!
|
|
2611
|
-
return
|
|
3104
|
+
while (!existsSync6(existing) && path7.dirname(existing) !== existing) existing = path7.dirname(existing);
|
|
3105
|
+
return path7.join(await realpath4(existing), path7.relative(existing, abs));
|
|
2612
3106
|
}
|
|
2613
3107
|
function isWithin(child, parent) {
|
|
2614
3108
|
const norm = (p) => process.platform === "win32" ? p.toLowerCase() : p;
|
|
2615
|
-
const rel =
|
|
2616
|
-
return rel === "" || rel !== ".." && !rel.startsWith(`..${
|
|
3109
|
+
const rel = path7.relative(norm(parent), norm(child));
|
|
3110
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${path7.sep}`) && !path7.isAbsolute(rel);
|
|
2617
3111
|
}
|
|
2618
3112
|
async function preflightTree(root, envFile) {
|
|
2619
3113
|
const [realRoot, realEnv] = await Promise.all([resolvedPath(root), resolvedPath(envFile)]);
|
|
2620
|
-
const doomed = [...MANAGED_DIRS, STAGING_DIR].find(
|
|
2621
|
-
(d) => isWithin(
|
|
3114
|
+
const doomed = [...MANAGED_DIRS, STAGING_DIR, JOURNAL, "channelvault.json", ".gitignore", ".secrets"].find(
|
|
3115
|
+
(d) => isWithin(path7.resolve(envFile), path7.resolve(root, d)) || isWithin(realEnv, path7.join(realRoot, d))
|
|
2622
3116
|
);
|
|
2623
3117
|
if (doomed) fail(`the env file ${envFile} is inside ${doomed}/, which this command replaces; keep it elsewhere`);
|
|
2624
|
-
const metaPath =
|
|
2625
|
-
if (
|
|
3118
|
+
const metaPath = path7.join(root, "channelvault.json");
|
|
3119
|
+
if (existsSync6(metaPath)) {
|
|
2626
3120
|
let meta;
|
|
2627
3121
|
try {
|
|
2628
3122
|
meta = await readJson(metaPath);
|
|
@@ -2636,7 +3130,7 @@ async function preflightTree(root, envFile) {
|
|
|
2636
3130
|
}
|
|
2637
3131
|
return meta;
|
|
2638
3132
|
}
|
|
2639
|
-
const foreign = MANAGED_DIRS.filter((d) =>
|
|
3133
|
+
const foreign = MANAGED_DIRS.filter((d) => existsSync6(path7.join(root, d)));
|
|
2640
3134
|
if (foreign.length > 0) {
|
|
2641
3135
|
fail(
|
|
2642
3136
|
`${root} is not a channelvault tree (no channelvault.json) but has ${foreign.map((d) => `${d}/`).join(", ")}, which this command would replace; nothing was written. Use a new or empty directory (or, if an earlier pull or explode into it was interrupted, delete those directories).`
|
|
@@ -2644,27 +3138,14 @@ async function preflightTree(root, envFile) {
|
|
|
2644
3138
|
}
|
|
2645
3139
|
return null;
|
|
2646
3140
|
}
|
|
2647
|
-
async function replaceTree(root, config) {
|
|
2648
|
-
const staging = path5.join(root, STAGING_DIR);
|
|
2649
|
-
await rm3(staging, RM_OPTS);
|
|
2650
|
-
try {
|
|
2651
|
-
await engine.explode(config, { root: staging });
|
|
2652
|
-
for (const d of MANAGED_DIRS) {
|
|
2653
|
-
await rm3(path5.join(root, d), RM_OPTS);
|
|
2654
|
-
if (existsSync5(path5.join(staging, d))) await rename3(path5.join(staging, d), path5.join(root, d));
|
|
2655
|
-
}
|
|
2656
|
-
} finally {
|
|
2657
|
-
await rm3(staging, RM_OPTS);
|
|
2658
|
-
}
|
|
2659
|
-
}
|
|
2660
3141
|
function assertTree(root) {
|
|
2661
|
-
if (!
|
|
3142
|
+
if (!existsSync6(path7.join(root, "server", "configuration.json"))) {
|
|
2662
3143
|
fail(`${root} is not a channelvault tree (missing server/configuration.json). Run 'pull' or 'explode' first.`);
|
|
2663
3144
|
}
|
|
2664
3145
|
}
|
|
2665
3146
|
async function readTreeOrigin(root) {
|
|
2666
|
-
const metaPath =
|
|
2667
|
-
if (!
|
|
3147
|
+
const metaPath = path7.join(root, "channelvault.json");
|
|
3148
|
+
if (!existsSync6(metaPath)) return "unknown";
|
|
2668
3149
|
try {
|
|
2669
3150
|
const meta = await readJson(metaPath);
|
|
2670
3151
|
if (typeof meta.source === "string") {
|
|
@@ -2691,18 +3172,32 @@ async function assertCompatibleOrigin(root, config, wants, force) {
|
|
|
2691
3172
|
function collect(value, previous) {
|
|
2692
3173
|
return [...previous ?? [], value];
|
|
2693
3174
|
}
|
|
3175
|
+
async function bindingProblems(root, serverId) {
|
|
3176
|
+
const file = path7.join(root, "channelvault.json");
|
|
3177
|
+
const meta = existsSync6(file) ? await readJson(file) : null;
|
|
3178
|
+
if (meta?.serverId === serverId) return [];
|
|
3179
|
+
return [`this tree's baseline belongs to ${meta?.serverId ? `installation ${meta.serverId}` : "an unknown installation"}, not the target (${serverId}); pull the target and merge your edits, or review with 'adopt <dir> --plan-only' and run 'adopt <dir>' to establish its baseline; --force does not bypass installation binding`];
|
|
3180
|
+
}
|
|
3181
|
+
async function xmlProblems(root, config) {
|
|
3182
|
+
const problem = await xmlSafetyProblem(config, root);
|
|
3183
|
+
return problem ? [problem] : [];
|
|
3184
|
+
}
|
|
3185
|
+
async function assertBinding(client, root) {
|
|
3186
|
+
const problems = await bindingProblems(root, await client.getServerId());
|
|
3187
|
+
if (problems.length) fail(problems.join("\n"));
|
|
3188
|
+
}
|
|
2694
3189
|
async function readKnown(root) {
|
|
2695
|
-
const metaPath =
|
|
2696
|
-
if (!
|
|
3190
|
+
const metaPath = path7.join(root, "channelvault.json");
|
|
3191
|
+
if (!existsSync6(metaPath)) return void 0;
|
|
2697
3192
|
return knownFrom((await readJson(metaPath)).resources);
|
|
2698
3193
|
}
|
|
2699
3194
|
async function writeKnown(root, known) {
|
|
2700
|
-
const metaPath =
|
|
2701
|
-
if (!
|
|
3195
|
+
const metaPath = path7.join(root, "channelvault.json");
|
|
3196
|
+
if (!existsSync6(metaPath)) return;
|
|
2702
3197
|
const meta = await readJson(metaPath);
|
|
2703
3198
|
if (!meta.resources) return;
|
|
2704
3199
|
meta.resources = known;
|
|
2705
|
-
await
|
|
3200
|
+
await writeFile6(metaPath, JSON.stringify(meta, null, 2) + "\n", "utf8");
|
|
2706
3201
|
}
|
|
2707
3202
|
function printNameChange(incoming, current) {
|
|
2708
3203
|
const [to, from] = [configuredName(incoming), configuredName(current)];
|
|
@@ -2744,6 +3239,7 @@ function reportPlanOnly(flags, plan, problems, extra) {
|
|
|
2744
3239
|
writeJson2({
|
|
2745
3240
|
target: extra.target,
|
|
2746
3241
|
mode: extra.mode,
|
|
3242
|
+
...extra.serverId ? { serverId: extra.serverId } : {},
|
|
2747
3243
|
changes: plan.changes,
|
|
2748
3244
|
conflicts: plan.conflicts,
|
|
2749
3245
|
serverOnly: plan.serverOnly,
|
|
@@ -2761,6 +3257,7 @@ async function scopedPush(client, root, local, scope, target, flags) {
|
|
|
2761
3257
|
const remote = await client.getServerConfiguration();
|
|
2762
3258
|
const known = await readKnown(root);
|
|
2763
3259
|
const plan = planPush(local, remote, scope, known);
|
|
3260
|
+
const problems = [...await bindingProblems(root, await client.getServerId()), ...planProblems(plan, flags), ...await xmlProblems(root, local)];
|
|
2764
3261
|
const names = new Map(
|
|
2765
3262
|
[...channelsOf(remote), ...channelsOf(local)].map((c) => [String(c["id"]), String(c["name"])])
|
|
2766
3263
|
);
|
|
@@ -2770,7 +3267,7 @@ async function scopedPush(client, root, local, scope, target, flags) {
|
|
|
2770
3267
|
const notDeployed = flags.deploy ? plan.deployIds.filter((id) => !deployed.has(id)) : [];
|
|
2771
3268
|
if (flags.planOnly && flags.json) {
|
|
2772
3269
|
const redeploy = flags.deploy ? { redeploy: toDeploy.map(nameOf2), notRedeployed: notDeployed.map(nameOf2) } : {};
|
|
2773
|
-
reportPlanOnly(flags, plan,
|
|
3270
|
+
reportPlanOnly(flags, plan, problems, { target, mode: "scoped", ...redeploy });
|
|
2774
3271
|
return;
|
|
2775
3272
|
}
|
|
2776
3273
|
if (plan.changes.length === 0) {
|
|
@@ -2796,12 +3293,11 @@ async function scopedPush(client, root, local, scope, target, flags) {
|
|
|
2796
3293
|
`);
|
|
2797
3294
|
}
|
|
2798
3295
|
if (flags.planOnly) {
|
|
2799
|
-
reportPlanOnly(flags, plan,
|
|
3296
|
+
reportPlanOnly(flags, plan, problems, { target, mode: "scoped" });
|
|
2800
3297
|
return;
|
|
2801
3298
|
}
|
|
2802
|
-
if (plan.changes.length === 0) return;
|
|
2803
|
-
const problems = planProblems(plan, flags);
|
|
2804
3299
|
if (problems.length > 0) fail(problems.join("\n"));
|
|
3300
|
+
if (plan.changes.length === 0) return;
|
|
2805
3301
|
if (!flags.yes && !await confirm("Continue?")) {
|
|
2806
3302
|
process.stdout.write("aborted.\n");
|
|
2807
3303
|
return;
|
|
@@ -2814,41 +3310,99 @@ async function scopedPush(client, root, local, scope, target, flags) {
|
|
|
2814
3310
|
pull and try again, or pass --force`);
|
|
2815
3311
|
}
|
|
2816
3312
|
await backupBeforePush(client, flags);
|
|
2817
|
-
const
|
|
3313
|
+
const afterBackup = await client.getServerConfiguration();
|
|
3314
|
+
const changedDuringBackup = changedSince(plan, fresh, afterBackup);
|
|
3315
|
+
if (!flags.force && changedDuringBackup.length) {
|
|
3316
|
+
fail(`changed on the server during backup: ${changedDuringBackup.join(", ")}; pull and try again`);
|
|
3317
|
+
}
|
|
3318
|
+
await assertBinding(client, root);
|
|
3319
|
+
const result = await applyPlan(client, plan, local, afterBackup, scope, { force: flags.force === true });
|
|
3320
|
+
let baselineError;
|
|
3321
|
+
let changedAgain = [];
|
|
3322
|
+
let unverified = [];
|
|
3323
|
+
let after;
|
|
2818
3324
|
try {
|
|
2819
|
-
|
|
2820
|
-
const refreshedLibraries = librariesOf(local).filter((l) => result.touchedIds.has(String(l["id"]))).map((l) => ({ kind: "library", op: "update", id: String(l["id"]), label: String(l["name"]) }));
|
|
2821
|
-
const changedAgain = [...result.applied, ...refreshedLibraries].filter((c) => !savedChangeMatches(c, local, after));
|
|
2822
|
-
if (changedAgain.length > 0) fail(`changed again after saving: ${[...new Set(changedAgain.map((c) => c.label))].join(", ")}; pull and review before retrying`);
|
|
2823
|
-
if (result.touchedIds.size > 0) await refreshRevisions(root, after, result.touchedIds);
|
|
2824
|
-
if (known) await writeKnown(root, knownAfterPush(known, result.applied, result.touchedIds, after));
|
|
3325
|
+
after = await client.getServerConfiguration();
|
|
2825
3326
|
} catch (err) {
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
process.stderr.write(`warning: could not refresh the local sync baseline: ${scrub(message)}
|
|
2829
|
-
`);
|
|
3327
|
+
baselineError = `could not read the server configuration back: ${err instanceof Error ? err.message : String(err)}. ${exportBrokenHint(flags)}`;
|
|
3328
|
+
({ changed: changedAgain, unverified } = await changedAgainSingly(client, result.applied, local));
|
|
2830
3329
|
}
|
|
3330
|
+
if (after) {
|
|
3331
|
+
try {
|
|
3332
|
+
const refreshedLibraries = librariesOf(local).filter((l) => result.touchedIds.has(String(l["id"]))).map((l) => ({ kind: "library", op: "update", id: String(l["id"]), label: String(l["name"]) }));
|
|
3333
|
+
const membershipSent = result.sentLibraries ? { ...local, codeTemplateLibraries: { codeTemplateLibrary: result.sentLibraries } } : local;
|
|
3334
|
+
const saved = after;
|
|
3335
|
+
changedAgain = [...new Set([...result.applied, ...refreshedLibraries].filter((c) => !savedChangeMatches(c, c.kind === "library" ? membershipSent : local, saved)).map((c) => c.label))];
|
|
3336
|
+
if (changedAgain.length === 0) {
|
|
3337
|
+
if (result.touchedIds.size > 0) await refreshRevisions(root, after, result.touchedIds);
|
|
3338
|
+
if (known) await writeKnown(root, knownAfterPush(known, result.applied, result.touchedIds, after));
|
|
3339
|
+
}
|
|
3340
|
+
} catch (err) {
|
|
3341
|
+
baselineError = err instanceof Error ? err.message : String(err);
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
const notRedeployed = toDeploy.length > 0 ? `
|
|
3345
|
+
${toDeploy.length} channel(s) NOT redeployed: ${toDeploy.map(nameOf2).join(", ")}; redeploy them from the Administrator once the server is as intended` : "";
|
|
3346
|
+
const againNote = changedAgain.length > 0 ? `
|
|
3347
|
+
changed again after saving (pull and review before retrying): ${changedAgain.join(", ")}` : "";
|
|
2831
3348
|
if (result.failed) {
|
|
3349
|
+
if (baselineError) process.stderr.write(`warning: could not refresh the local sync baseline: ${scrub(baselineError)}
|
|
3350
|
+
`);
|
|
2832
3351
|
const { change, error } = result.failed;
|
|
2833
|
-
fail(`applied ${result.applied.length} of ${plan.changes.length}; ${change.op} ${change.label} failed: ${error}`);
|
|
3352
|
+
fail(`applied ${result.applied.length} of ${plan.changes.length}; ${change.op} ${change.label} failed: ${error}${againNote}${notRedeployed}`);
|
|
3353
|
+
}
|
|
3354
|
+
if (changedAgain.length > 0) {
|
|
3355
|
+
fail(`applied ${result.applied.length} change(s), but these changed again after saving: ${changedAgain.join(", ")}; pull and review before retrying${notRedeployed}${baselineError ? `
|
|
3356
|
+
${baselineError}` : ""}`);
|
|
2834
3357
|
}
|
|
2835
3358
|
process.stdout.write(`pushed ${result.applied.length} change(s)
|
|
2836
3359
|
`);
|
|
2837
3360
|
if (toDeploy.length > 0) {
|
|
2838
|
-
const failures = await deployChannels(client, toDeploy, nameOf2);
|
|
2839
|
-
process.stdout.write(`deployed ${
|
|
3361
|
+
const { deployed: deployed2, skipped, failures } = await deployChannels(client, toDeploy, nameOf2);
|
|
3362
|
+
process.stdout.write(`deployed ${deployed2.length} of ${toDeploy.length} channel(s)
|
|
3363
|
+
`);
|
|
3364
|
+
if (skipped.length) process.stdout.write(`redeploy skipped (no longer deployed): ${skipped.join(", ")}
|
|
2840
3365
|
`);
|
|
2841
3366
|
for (const f of failures) process.stderr.write(`deploy failed: ${f.name}: ${scrub(f.error)}
|
|
2842
3367
|
`);
|
|
2843
3368
|
if (failures.length > 0) process.exitCode = 1;
|
|
2844
3369
|
}
|
|
3370
|
+
if (baselineError) {
|
|
3371
|
+
const note = unverified.length > 0 ? `
|
|
3372
|
+
not checked after saving (these cannot be read one at a time): ${unverified.join(", ")}` : "";
|
|
3373
|
+
fail(`pushed ${result.applied.length} change(s), but could not refresh the local sync baseline: ${baselineError}${note}`);
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
function exportBrokenHint(flags) {
|
|
3377
|
+
const undo = flags.backup === false ? "" : " (including the undo command above)";
|
|
3378
|
+
return `If the server cannot export its configuration, pull, diff, push and restore${undo} fail until the resource that broke it is fixed in the Administrator; then pull or adopt to refresh the baseline`;
|
|
3379
|
+
}
|
|
3380
|
+
async function changedAgainSingly(client, applied, local) {
|
|
3381
|
+
const changed = [];
|
|
3382
|
+
const unverified = [];
|
|
3383
|
+
for (const c of applied) {
|
|
3384
|
+
if (c.kind !== "channel" && c.kind !== "codeTemplate") {
|
|
3385
|
+
unverified.push(c.label);
|
|
3386
|
+
continue;
|
|
3387
|
+
}
|
|
3388
|
+
try {
|
|
3389
|
+
const current = c.kind === "channel" ? await client.getChannel(c.id) : await client.getCodeTemplate(c.id);
|
|
3390
|
+
const held = current ? [current] : [];
|
|
3391
|
+
const server = c.kind === "channel" ? { channels: { channel: held } } : { codeTemplateLibraries: { codeTemplateLibrary: [{ codeTemplates: { codeTemplate: held } }] } };
|
|
3392
|
+
if (!savedChangeMatches(c, local, server)) changed.push(c.label);
|
|
3393
|
+
} catch {
|
|
3394
|
+
changed.push(`${c.label} (could not be read)`);
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
return { changed, unverified };
|
|
2845
3398
|
}
|
|
2846
3399
|
async function wholeServerPush(client, root, local, target, flags) {
|
|
2847
3400
|
const remote = await client.getServerConfiguration();
|
|
2848
3401
|
const known = await readKnown(root);
|
|
2849
3402
|
const plan = planPush(local, remote, {}, known, { wholeReplace: true });
|
|
3403
|
+
const problems = [...await bindingProblems(root, await client.getServerId()), ...wholeServerProblems(plan, flags), ...await xmlProblems(root, local)];
|
|
2850
3404
|
if (flags.planOnly && flags.json) {
|
|
2851
|
-
reportPlanOnly(flags, plan,
|
|
3405
|
+
reportPlanOnly(flags, plan, problems, { target, mode: "whole-server" });
|
|
2852
3406
|
return;
|
|
2853
3407
|
}
|
|
2854
3408
|
const s = summarize(local);
|
|
@@ -2868,7 +3422,6 @@ async function wholeServerPush(client, root, local, target, flags) {
|
|
|
2868
3422
|
if (replaced.length > 0) process.stdout.write(`also replaced: ${replaced.join(", ")}
|
|
2869
3423
|
`);
|
|
2870
3424
|
if (keptMap) process.stdout.write("configuration map differs but is kept (--overwrite-config-map replaces it)\n");
|
|
2871
|
-
const problems = wholeServerProblems(plan, flags);
|
|
2872
3425
|
if (flags.planOnly) {
|
|
2873
3426
|
reportPlanOnly(flags, plan, problems, { target, mode: "whole-server" });
|
|
2874
3427
|
return;
|
|
@@ -2887,11 +3440,23 @@ async function wholeServerPush(client, root, local, target, flags) {
|
|
|
2887
3440
|
fail("the replace now deletes resources from the server; review the new plan and pass --allow-deletes");
|
|
2888
3441
|
}
|
|
2889
3442
|
await backupBeforePush(client, flags);
|
|
3443
|
+
const afterBackup = await client.getServerConfiguration();
|
|
3444
|
+
if (!sameServerConfig(fresh, afterBackup) && !flags.force) fail("the server changed during backup; pull and try again");
|
|
3445
|
+
const finalPlan = planPush(local, afterBackup, {}, known, { wholeReplace: true });
|
|
3446
|
+
if (!flags.allowDeletes && (finalPlan.serverOnly.length || finalPlan.changes.some((c) => c.op === "delete"))) {
|
|
3447
|
+
fail("the replace now deletes resources from the server; review the new plan and pass --allow-deletes");
|
|
3448
|
+
}
|
|
3449
|
+
await assertBinding(client, root);
|
|
2890
3450
|
await client.putServerConfiguration(local, {
|
|
2891
3451
|
deploy: flags.deploy === true,
|
|
2892
3452
|
overwriteConfigMap: flags.overwriteConfigMap === true
|
|
2893
3453
|
});
|
|
2894
|
-
|
|
3454
|
+
let after;
|
|
3455
|
+
try {
|
|
3456
|
+
after = await client.getServerConfiguration();
|
|
3457
|
+
} catch (err) {
|
|
3458
|
+
fail(`replaced the configuration at ${target}${flags.deploy ? " (Mirth redeploys as part of the replace)" : ""}, but could not read it back: ${err instanceof Error ? err.message : String(err)}. The tree's baseline was not refreshed. ${exportBrokenHint(flags)}`);
|
|
3459
|
+
}
|
|
2895
3460
|
if (planPush(local, after, {}, void 0, { wholeReplace: true }).changes.length > 0) {
|
|
2896
3461
|
fail("applied the whole-server replacement, but resources changed again after saving; pull and review before retrying");
|
|
2897
3462
|
}
|
|
@@ -2906,9 +3471,9 @@ program.name("channelvault").description("Git-style pull/push/diff for Mirth Con
|
|
|
2906
3471
|
addExtractFlag(addEnvFlag(
|
|
2907
3472
|
program.command("explode").description("Explode a Mirth backup XML into a working tree").argument("<backup.xml>", "path to a Mirth backup config XML file").argument("<dir>", "output working-tree directory")
|
|
2908
3473
|
)).action(async (backupPath, dir, flags) => {
|
|
2909
|
-
const config = xml.parse(await
|
|
2910
|
-
const root =
|
|
2911
|
-
await writeTree(root, config, `file:${
|
|
3474
|
+
const config = xml.parse(await readFile6(backupPath, "utf8"));
|
|
3475
|
+
const root = path7.resolve(dir);
|
|
3476
|
+
await writeTree(root, config, `file:${path7.resolve(backupPath)}`, flags);
|
|
2912
3477
|
const s = summarize(config);
|
|
2913
3478
|
process.stdout.write(`exploded ${s.channels} channels, ${s.codeTemplates} code templates -> ${root}
|
|
2914
3479
|
`);
|
|
@@ -2916,27 +3481,81 @@ addExtractFlag(addEnvFlag(
|
|
|
2916
3481
|
addEnvFlag(
|
|
2917
3482
|
program.command("implode").description("Reassemble a working tree into a Mirth backup XML").argument("<dir>", "working-tree directory").argument("<backup.xml>", "output XML path").option("--force", "implode even if the tree was pulled from a live server", false)
|
|
2918
3483
|
).action(async (dir, outPath, flags) => {
|
|
2919
|
-
const root =
|
|
3484
|
+
const root = path7.resolve(dir);
|
|
2920
3485
|
assertTree(root);
|
|
2921
3486
|
const config = await renderedTree(root, flags);
|
|
2922
3487
|
await assertCompatibleOrigin(root, config, "xml", flags.force === true);
|
|
2923
3488
|
const xmlStr = xml.build(config);
|
|
2924
|
-
await
|
|
2925
|
-
process.stdout.write(`imploded ${root} -> ${
|
|
3489
|
+
await writeFile6(outPath, xmlStr, "utf8");
|
|
3490
|
+
process.stdout.write(`imploded ${root} -> ${path7.resolve(outPath)}
|
|
2926
3491
|
`);
|
|
2927
3492
|
});
|
|
2928
3493
|
addExtractFlag(addEnvFlag(addConnectionFlags(
|
|
2929
3494
|
program.command("pull").description("Pull the live server configuration into a working tree").argument("<dir>", "working-tree directory")
|
|
2930
3495
|
))).action(async (dir, flags) => {
|
|
2931
|
-
const root =
|
|
3496
|
+
const root = path7.resolve(dir);
|
|
2932
3497
|
await preflightTree(root, envFilePath(root, flags));
|
|
2933
|
-
const config = await withClient(flags, (client) =>
|
|
3498
|
+
const { config, serverId } = await withClient(flags, async (client) => {
|
|
3499
|
+
const serverId2 = await client.getServerId();
|
|
3500
|
+
const config2 = await client.getServerConfiguration();
|
|
3501
|
+
if (await client.getServerId() !== serverId2) fail("the installation changed while pulling; nothing was written");
|
|
3502
|
+
return { config: config2, serverId: serverId2 };
|
|
3503
|
+
});
|
|
2934
3504
|
const cfg = resolveClientConfig(flags);
|
|
2935
|
-
await writeTree(root, config, `${cfg.https === false ? "http" : "https"}://${cfg.host}:${cfg.port}`, flags);
|
|
3505
|
+
await writeTree(root, config, `${cfg.https === false ? "http" : "https"}://${cfg.host}:${cfg.port}`, flags, serverId);
|
|
2936
3506
|
const s = summarize(config);
|
|
2937
3507
|
process.stdout.write(`pulled ${s.channels} channels, ${s.codeTemplates} code templates -> ${root}
|
|
2938
3508
|
`);
|
|
2939
3509
|
});
|
|
3510
|
+
addJsonFlag(addEnvFlag(addConnectionFlags(
|
|
3511
|
+
program.command("adopt").description("Review and capture this installation as the tree baseline, preserving local content; writes no server resources").argument("<dir>", "working-tree directory").option("--plan-only", "preview the resulting push plan without changing the tree", false).option("-y, --yes", "accept the reviewed destination baseline without a prompt", false)
|
|
3512
|
+
))).action(async (dir, flags) => {
|
|
3513
|
+
const root = path7.resolve(dir);
|
|
3514
|
+
assertTree(root);
|
|
3515
|
+
const previous = await preflightTree(root, envFilePath(root, flags));
|
|
3516
|
+
const stored = await engine.implode({ root });
|
|
3517
|
+
const local = await renderedTree(root, flags);
|
|
3518
|
+
await assertCompatibleOrigin(root, local, "live", false);
|
|
3519
|
+
if (flags.json && !flags.planOnly) fail("--json needs --plan-only");
|
|
3520
|
+
if (!flags.yes && !flags.planOnly && !process.stdin.isTTY) fail("no terminal to confirm on; review with `adopt --plan-only` and pass --yes");
|
|
3521
|
+
const cfg = resolveClientConfig(flags);
|
|
3522
|
+
const target = `${cfg.https === false ? "http" : "https"}://${cfg.host}:${cfg.port}`;
|
|
3523
|
+
await withClient(flags, async (client) => {
|
|
3524
|
+
const serverId = await client.getServerId();
|
|
3525
|
+
const remote = await client.getServerConfiguration();
|
|
3526
|
+
const adopted = adoptTarget(local, remote);
|
|
3527
|
+
const plan = planPush(adopted.config, remote, {}, adopted.known);
|
|
3528
|
+
if (!flags.json) {
|
|
3529
|
+
process.stdout.write(`Adopt ${target} (installation ${serverId}) as this tree's baseline.
|
|
3530
|
+
Local content is preserved; the following differences become reviewed edits for a subsequent push:
|
|
3531
|
+
`);
|
|
3532
|
+
printChanges(plan);
|
|
3533
|
+
if (plan.serverOnly.length) process.stdout.write(`left alone: ${plan.serverOnly.join(", ")}
|
|
3534
|
+
`);
|
|
3535
|
+
if (plan.notPushed.length) process.stdout.write(`not pushed by scoped push: ${plan.notPushed.join(", ")}
|
|
3536
|
+
`);
|
|
3537
|
+
}
|
|
3538
|
+
if (flags.planOnly) {
|
|
3539
|
+
reportPlanOnly(flags, plan, planProblems(plan, {}), { target, mode: "adopt", serverId });
|
|
3540
|
+
return;
|
|
3541
|
+
}
|
|
3542
|
+
if (!flags.yes && !await confirm("Accept this baseline?")) {
|
|
3543
|
+
process.stdout.write("aborted.\n");
|
|
3544
|
+
return;
|
|
3545
|
+
}
|
|
3546
|
+
if (await client.getServerId() !== serverId || !sameServerConfig(remote, await client.getServerConfiguration())) {
|
|
3547
|
+
fail("the target changed while adopting; nothing was written. Review the new baseline and try again");
|
|
3548
|
+
}
|
|
3549
|
+
if (!sameServerConfig(stored, await engine.implode({ root }))) fail("the local tree changed while adopting; nothing was written");
|
|
3550
|
+
await replaceTree(root, envFilePath(root, flags), async (next) => {
|
|
3551
|
+
const rebased = adoptTarget(stored, remote);
|
|
3552
|
+
await engine.explode(rebased.config, { root: next });
|
|
3553
|
+
await writeMeta(next, target, rebased.config, previous, serverId, adopted.known);
|
|
3554
|
+
});
|
|
3555
|
+
process.stdout.write(`adopted installation ${serverId}; review with push --plan-only before writing the server
|
|
3556
|
+
`);
|
|
3557
|
+
});
|
|
3558
|
+
});
|
|
2940
3559
|
addBackupDirFlags(addEnvFlag(addConnectionFlags(
|
|
2941
3560
|
program.command("push").description("Push changed channels, code templates and global scripts to the live server").argument("<dir>", "working-tree directory").option("--channel <name>", "only this channel (name or id); repeatable", collect).option("--library <name>", "only this code template library (name or id); repeatable", collect).option("--global-scripts", "with --channel/--library: also push global scripts").option("--allow-deletes", "delete server resources that are missing from the tree", false).option("--deploy", "redeploy the changed channels and the channels using changed code templates", false).option("--force", "push even if the server changed since the last pull (overwrites the server's version)", false).option("--ignore-origin", "push a tree that was exploded from an XML backup (normally refused)", false).option("--whole-server", "replace the entire server configuration instead (settings, config map, groups too)", false).option("--overwrite-config-map", "with --whole-server: also overwrite the configuration map", false).option("--no-backup", "skip the backup of the server taken before anything changes").option("--plan-only", "show what would be pushed and what would stop it; change nothing (no prompt)", false).option("--json", "with --plan-only: print the plan as one JSON document", false).option("-y, --yes", "skip the confirmation prompt", false)
|
|
2942
3561
|
))).action(
|
|
@@ -2944,7 +3563,8 @@ addBackupDirFlags(addEnvFlag(addConnectionFlags(
|
|
|
2944
3563
|
if (flags.wholeServer && (flags.channel || flags.library || flags.globalScripts)) {
|
|
2945
3564
|
fail("--whole-server replaces everything; it cannot be combined with --channel, --library or --global-scripts");
|
|
2946
3565
|
}
|
|
2947
|
-
|
|
3566
|
+
if (flags.overwriteConfigMap && !flags.wholeServer) fail("--overwrite-config-map needs --whole-server");
|
|
3567
|
+
const root = path7.resolve(dir);
|
|
2948
3568
|
assertTree(root);
|
|
2949
3569
|
const config = await renderedTree(root, flags);
|
|
2950
3570
|
await assertCompatibleOrigin(root, config, "live", flags.ignoreOrigin === true);
|
|
@@ -2970,10 +3590,10 @@ addBackupDirFlags(addConnectionFlags(
|
|
|
2970
3590
|
const file = await withClient(flags, async (client) => {
|
|
2971
3591
|
const text = await client.getServerConfigurationXml();
|
|
2972
3592
|
if (!flags.out) return saveServerBackup(client, text, flags);
|
|
2973
|
-
const out =
|
|
3593
|
+
const out = path7.resolve(flags.out);
|
|
2974
3594
|
parseBackup(text, "the server configuration");
|
|
2975
|
-
if (
|
|
2976
|
-
await
|
|
3595
|
+
if (existsSync6(out)) fail(`${out} already exists; choose another name`);
|
|
3596
|
+
await mkdir5(path7.dirname(out), { recursive: true });
|
|
2977
3597
|
await writePrivate(out, text);
|
|
2978
3598
|
if (gitWouldCommit(out)) {
|
|
2979
3599
|
process.stderr.write(`warning: git does not ignore ${out}, which holds credentials in plain text; add it to .gitignore
|
|
@@ -2997,8 +3617,8 @@ addBackupDirFlags(addConnectionFlags(
|
|
|
2997
3617
|
const serverId = await client.getServerId();
|
|
2998
3618
|
let chosen;
|
|
2999
3619
|
if (file) {
|
|
3000
|
-
chosen =
|
|
3001
|
-
if (!
|
|
3620
|
+
chosen = path7.resolve(file);
|
|
3621
|
+
if (!existsSync6(chosen)) fail(`${chosen} does not exist`);
|
|
3002
3622
|
} else {
|
|
3003
3623
|
const mine = await backupsOf(dir, serverId);
|
|
3004
3624
|
if (mine.length === 0) {
|
|
@@ -3007,8 +3627,10 @@ addBackupDirFlags(addConnectionFlags(
|
|
|
3007
3627
|
}
|
|
3008
3628
|
chosen = mine[mine.length - 1].file;
|
|
3009
3629
|
}
|
|
3010
|
-
const text = await
|
|
3630
|
+
const text = await readFile6(chosen, "utf8");
|
|
3011
3631
|
const backup = parseBackup(text, chosen);
|
|
3632
|
+
const unsafe = await xmlSafetyProblem(backup);
|
|
3633
|
+
if (unsafe) fail(`${chosen} holds ${unsafe}`);
|
|
3012
3634
|
const origin = await originOf(dir, chosen);
|
|
3013
3635
|
if (origin) {
|
|
3014
3636
|
if (origin.serverId !== serverId && !flags.force) {
|
|
@@ -3019,7 +3641,7 @@ addBackupDirFlags(addConnectionFlags(
|
|
|
3019
3641
|
if (fromContent !== "" && fromServer !== "" && fromContent !== fromServer && !flags.force) {
|
|
3020
3642
|
fail(`${chosen} is a backup of ${fromContent}, not ${fromServer}; pass --force to restore it here anyway`);
|
|
3021
3643
|
}
|
|
3022
|
-
process.stderr.write(`warning: ${chosen} is not in ${
|
|
3644
|
+
process.stderr.write(`warning: ${chosen} is not in ${path7.join(dir, MANIFEST)}, so which server it came from cannot be checked
|
|
3023
3645
|
`);
|
|
3024
3646
|
}
|
|
3025
3647
|
const [bv, sv] = [backup["@_version"], current["@_version"]];
|
|
@@ -3054,8 +3676,13 @@ to ${target}, replacing its ENTIRE configuration${flags.deploy ? ", then redeplo
|
|
|
3054
3676
|
fail("the server changed while this restore was being confirmed; nothing was restored. Run it again to review the new state");
|
|
3055
3677
|
}
|
|
3056
3678
|
const undo = await saveServerBackup(client, freshText, flags, chosen);
|
|
3057
|
-
process.stdout.write(`saved the current configuration to ${undo} (undo with:
|
|
3679
|
+
process.stdout.write(`saved the current configuration to ${undo} (undo with: ${undoCommand(undo, flags)})
|
|
3058
3680
|
`);
|
|
3681
|
+
printUndoLimits(flags);
|
|
3682
|
+
const afterBackup = parseBackup(await client.getServerConfigurationXml(), "the server configuration");
|
|
3683
|
+
if (!sameServerConfig(parseBackup(freshText, "the server configuration"), afterBackup)) {
|
|
3684
|
+
fail("the server changed during the undo backup; nothing was restored. Run it again to review the new state");
|
|
3685
|
+
}
|
|
3059
3686
|
await client.putServerConfigurationXml(text, { deploy: flags.deploy === true, overwriteConfigMap: flags.overwriteConfigMap === true });
|
|
3060
3687
|
const after = parseBackup(await client.getServerConfigurationXml(), "the server configuration");
|
|
3061
3688
|
const differ = planPush(backup, after, {}, void 0, { wholeReplace: true }).changes;
|
|
@@ -3073,14 +3700,15 @@ addJsonFlag(addEnvFlag(addConnectionFlags(
|
|
|
3073
3700
|
})
|
|
3074
3701
|
))).action(async (dir, flags) => {
|
|
3075
3702
|
errorExitCode = 2;
|
|
3076
|
-
const root =
|
|
3703
|
+
const root = path7.resolve(dir);
|
|
3077
3704
|
assertTree(root);
|
|
3078
3705
|
const fetched = await withClient(flags, (client) => client.getServerConfiguration());
|
|
3079
3706
|
const tree = await engine.implode({ root });
|
|
3080
3707
|
const { config: templatedRemote, envUpdates, notes } = templatize(fetched, tree, await loadEnv(envFilePath(root, flags)));
|
|
3081
3708
|
const messages = [
|
|
3082
3709
|
...Object.keys(envUpdates).map((name) => `${name} differs between the server and the env file`),
|
|
3083
|
-
...notes
|
|
3710
|
+
...notes,
|
|
3711
|
+
...await xmlProblems(root, tree)
|
|
3084
3712
|
];
|
|
3085
3713
|
const allow = await readAllow(root);
|
|
3086
3714
|
const staleRevisions = newerOnServer(tree, templatedRemote);
|
|
@@ -3095,15 +3723,15 @@ addJsonFlag(addEnvFlag(addConnectionFlags(
|
|
|
3095
3723
|
if (serverView.findings.length > 0) messages.push(`${serverView.findings.length} possible secret(s) on the server are redacted below`);
|
|
3096
3724
|
if (!flags.json) for (const m of messages) process.stderr.write(`note: ${m}
|
|
3097
3725
|
`);
|
|
3098
|
-
const tmp = await mkdtemp(
|
|
3726
|
+
const tmp = await mkdtemp(path7.join(tmpdir(), "channelvault-diff-"));
|
|
3099
3727
|
try {
|
|
3100
|
-
await engine.explode(treeView.config, { root:
|
|
3101
|
-
await engine.explode(serverView.config, { root:
|
|
3102
|
-
await
|
|
3728
|
+
await engine.explode(treeView.config, { root: path7.join(tmp, "tree") });
|
|
3729
|
+
await engine.explode(serverView.config, { root: path7.join(tmp, "server") });
|
|
3730
|
+
await mkdir5(path7.join(tmp, ".empty"));
|
|
3103
3731
|
const chunks = [];
|
|
3104
3732
|
for (const d of MANAGED_DIRS) {
|
|
3105
|
-
const local =
|
|
3106
|
-
const server =
|
|
3733
|
+
const local = existsSync6(path7.join(tmp, "tree", d)) ? `tree/${d}` : ".empty";
|
|
3734
|
+
const server = existsSync6(path7.join(tmp, "server", d)) ? `server/${d}` : ".empty";
|
|
3107
3735
|
if (local === ".empty" && server === ".empty") continue;
|
|
3108
3736
|
const result = spawnSync(
|
|
3109
3737
|
"git",
|
|
@@ -3125,7 +3753,7 @@ addJsonFlag(addEnvFlag(addConnectionFlags(
|
|
|
3125
3753
|
const clean = out === "" && secretDrift.length === 0;
|
|
3126
3754
|
if (!clean) process.exitCode = 1;
|
|
3127
3755
|
if (flags.json) {
|
|
3128
|
-
const files = await changedFiles(
|
|
3756
|
+
const files = await changedFiles(path7.join(tmp, "tree"), path7.join(tmp, "server"));
|
|
3129
3757
|
writeJson2({ clean, files, secretDrift, staleRevisions, notes: messages, patch: out });
|
|
3130
3758
|
} else if (clean) {
|
|
3131
3759
|
process.stdout.write("no differences \u2014 working tree matches the server.\n");
|
|
@@ -3137,44 +3765,43 @@ addJsonFlag(addEnvFlag(addConnectionFlags(
|
|
|
3137
3765
|
}
|
|
3138
3766
|
}
|
|
3139
3767
|
} finally {
|
|
3140
|
-
await
|
|
3768
|
+
await rm4(tmp, RM_OPTS);
|
|
3141
3769
|
}
|
|
3142
3770
|
});
|
|
3143
3771
|
async function changedFiles(treeDir, serverDir) {
|
|
3144
|
-
const
|
|
3145
|
-
const out = [];
|
|
3146
|
-
for (const d of MANAGED_DIRS) {
|
|
3147
|
-
if (!existsSync5(path5.join(base, d))) continue;
|
|
3148
|
-
for (const entry of await readdir4(path5.join(base, d), { recursive: true, withFileTypes: true })) {
|
|
3149
|
-
if (entry.isFile()) out.push(path5.relative(base, path5.join(entry.parentPath, entry.name)).split(path5.sep).join("/"));
|
|
3150
|
-
}
|
|
3151
|
-
}
|
|
3152
|
-
return out;
|
|
3153
|
-
};
|
|
3154
|
-
const [local, remote] = await Promise.all([list2(treeDir), list2(serverDir)]);
|
|
3772
|
+
const [local, remote] = await Promise.all([treeFiles(treeDir), treeFiles(serverDir)]);
|
|
3155
3773
|
const remoteSet = new Set(remote);
|
|
3156
3774
|
const files = [];
|
|
3157
3775
|
for (const p of local) {
|
|
3158
3776
|
if (!remoteSet.has(p)) files.push({ path: p, change: "only-in-tree" });
|
|
3159
|
-
else if (await
|
|
3777
|
+
else if (await readFile6(path7.join(treeDir, p), "utf8") !== await readFile6(path7.join(serverDir, p), "utf8")) files.push({ path: p, change: "modified" });
|
|
3160
3778
|
}
|
|
3161
3779
|
const localSet = new Set(local);
|
|
3162
3780
|
for (const p of remote) if (!localSet.has(p)) files.push({ path: p, change: "only-on-server" });
|
|
3163
3781
|
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
3164
3782
|
}
|
|
3165
|
-
addJsonFlag(
|
|
3783
|
+
addJsonFlag(addEnvFlag(
|
|
3166
3784
|
program.command("status").description("Summarize a working tree").argument("<dir>", "working-tree directory")
|
|
3167
|
-
).action(async (dir, flags) => {
|
|
3168
|
-
const root =
|
|
3785
|
+
)).action(async (dir, flags) => {
|
|
3786
|
+
const root = path7.resolve(dir);
|
|
3169
3787
|
assertTree(root);
|
|
3170
3788
|
const config = await engine.implode({ root });
|
|
3171
3789
|
const s = summarize(config);
|
|
3172
|
-
const metaPath =
|
|
3173
|
-
const meta =
|
|
3790
|
+
const metaPath = path7.join(root, "channelvault.json");
|
|
3791
|
+
const meta = existsSync6(metaPath) ? await readJson(metaPath) : null;
|
|
3174
3792
|
if (flags.json) {
|
|
3175
|
-
writeJson2({
|
|
3793
|
+
writeJson2({
|
|
3794
|
+
root,
|
|
3795
|
+
source: meta?.source ?? null,
|
|
3796
|
+
pulledAt: meta?.pulledAt ?? null,
|
|
3797
|
+
engineVersion: meta?.engineVersion ?? null,
|
|
3798
|
+
counts: s,
|
|
3799
|
+
xmlForbiddenChars: forbiddenXmlChars(config)
|
|
3800
|
+
});
|
|
3176
3801
|
return;
|
|
3177
3802
|
}
|
|
3803
|
+
for (const p of await xmlProblems(root, config)) process.stderr.write(`warning: ${p}
|
|
3804
|
+
`);
|
|
3178
3805
|
if (meta) {
|
|
3179
3806
|
process.stdout.write(`source: ${meta.source}
|
|
3180
3807
|
`);
|
|
@@ -3191,6 +3818,15 @@ code templates: ${s.codeTemplates}
|
|
|
3191
3818
|
`
|
|
3192
3819
|
);
|
|
3193
3820
|
});
|
|
3821
|
+
var unlock;
|
|
3822
|
+
program.hook("preAction", async (_program, command) => {
|
|
3823
|
+
const name = command.name();
|
|
3824
|
+
if (!["explode", "pull", "adopt", "push", "implode", "diff", "status"].includes(name)) return;
|
|
3825
|
+
if (name === "diff") errorExitCode = 2;
|
|
3826
|
+
const root = path7.resolve(String(command.processedArgs[name === "explode" ? 1 : 0]));
|
|
3827
|
+
unlock = await lockTree(root);
|
|
3828
|
+
await recoverTree(root, envFilePath(root, command.opts()));
|
|
3829
|
+
});
|
|
3194
3830
|
program.parseAsync().catch((err) => {
|
|
3195
3831
|
if (err instanceof CommanderError) return;
|
|
3196
3832
|
process.stderr.write(`error: ${scrub(err instanceof Error ? err.message : String(err))}
|
|
@@ -3206,5 +3842,15 @@ program.parseAsync().catch((err) => {
|
|
|
3206
3842
|
`);
|
|
3207
3843
|
}
|
|
3208
3844
|
process.exitCode = errorExitCode;
|
|
3845
|
+
}).finally(async () => {
|
|
3846
|
+
if (unlock) {
|
|
3847
|
+
try {
|
|
3848
|
+
await unlock();
|
|
3849
|
+
} catch (err) {
|
|
3850
|
+
process.stderr.write(`error: could not release working-tree lock: ${scrub(err instanceof Error ? err.message : String(err))}
|
|
3851
|
+
`);
|
|
3852
|
+
process.exitCode = errorExitCode;
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3209
3855
|
});
|
|
3210
3856
|
//# sourceMappingURL=cli.js.map
|