@ubercode/channelvault 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +27 -3
- package/dist/cli.js +164 -37
- package/dist/cli.js.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/docs/roadmap.md +8 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@ubercode/channelvault` are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the version follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
4
|
|
|
5
|
+
## [0.2.1] — 2026-09-29
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `diff` compares content: revision numbers and timestamps, which Mirth bumps on any save or restore, no longer count as differences; `diff --json` lists them as `staleRevisions`.
|
|
10
|
+
- Channels whose names collide once made into directory names (`Lab Feed`, `LAB FEED`) keep their directories when the server lists them in another order, as it does after a restore.
|
|
11
|
+
- `push` no longer refuses to update one of two channels that already share a name on the server (Mirth allows `Lab Feed` beside `LAB FEED`); only a new name or a rename is checked.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Tests on a production-shaped synthetic mesh (on real Mirth 4.5.2 too) and on 36 public exports from Mirth 3.0 to OIE 4.6.
|
|
16
|
+
|
|
17
|
+
## [0.2.0] — 2026-09-29
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- `--json` for `status`, `diff` and `push --plan-only`: one JSON document on stdout for scripts, CI and AI agents.
|
|
22
|
+
- `push --plan-only`: the plan and what would stop it, without a prompt, a backup or any change.
|
|
23
|
+
- README: a copy-paste guide for using channelvault with an AI agent.
|
|
24
|
+
|
|
5
25
|
## [0.1.0] — 2026-09-25
|
|
6
26
|
|
|
7
27
|
First release. Tested against Mirth Connect 4.5.2; the offline round trip is also tested on Mirth 3.8 and 4.0.1 exports.
|
|
@@ -15,4 +35,6 @@ First release. Tested against Mirth Connect 4.5.2; the offline round trip is als
|
|
|
15
35
|
- `backup` / `restore`: the server's own configuration XML saved as `.backup/<server>-<UTC time>.xml`, identified by Mirth's server ID, restored with a preview, an undo backup and a version check. `push` backs up first unless `--no-backup`.
|
|
16
36
|
- `diff` exits 0 when the tree matches the server, 1 when it differs, 2 on error.
|
|
17
37
|
|
|
38
|
+
[0.2.1]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.2.1
|
|
39
|
+
[0.2.0]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.2.0
|
|
18
40
|
[0.1.0]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -35,7 +35,8 @@ The exploded tree is a projection, not a re-derivation: config is stored verbati
|
|
|
35
35
|
- `test/xml.test.ts`, `test/xml.robustness.test.ts`: XML parse/build fixed point, entity and whitespace handling, document order, unexpected XML
|
|
36
36
|
- `test/explode.test.ts`, `test/explode.paths.test.ts`: `implode(explode(c))` deep-equals `c`, byte-identical sidecars, file naming
|
|
37
37
|
- `test/e2e.test.ts`: the whole pipeline on a Mirth-exported fixture (`test/fixtures`, synthetic; `test/fixtures.guard.test.ts` rejects real exports)
|
|
38
|
-
- `test/third-party-fixtures.test.ts`: the same pipeline on
|
|
38
|
+
- `test/third-party-fixtures.test.ts` and `test/third-party-corpus.test.ts`: the same pipeline on public exports from Mirth 3.0 to OIE 4.6 (mirthsync, Open Integration Engine, NextGen's FHIR examples and six other projects; `test/fixtures/third-party/<source>/`, each pinned by hash in its `SOURCE.md` with its license)
|
|
39
|
+
- `test/mesh.test.ts`: a synthetic, production-shaped routing mesh (`test/fixtures/serverConfiguration.mesh.xml`: 26 channels, an 18-destination hub, a 10,000-line code template, attachment handlers), generated by `scripts/fixtures/generate-mesh.ts` and exported by Mirth after every channel deployed (`node scripts/fixtures/build-mesh.mjs`)
|
|
39
40
|
|
|
40
41
|
## Layout produced by `explode` / `pull`
|
|
41
42
|
|
|
@@ -74,7 +75,13 @@ channelvault restore [file] # backup -> live server (default: ne
|
|
|
74
75
|
|
|
75
76
|
`channelvault <command> --help` lists the flags. Server connection comes from flags or `MIRTH_HOST`, `MIRTH_PORT`, `MIRTH_USER`, `MIRTH_PASS`; prefer the env var over `--pass`, which shows up in process listings. Mirth's default certificate is self-signed; `--insecure` accepts it by turning verification off.
|
|
76
77
|
|
|
77
|
-
`diff` exits 0 when the tree matches the server, 1 when they differ, and 2 on any error (including a bad flag), so a scheduled drift check can tell drift from an outage.
|
|
78
|
+
`diff` exits 0 when the tree matches the server, 1 when they differ, and 2 on any error (including a bad flag), so a scheduled drift check can tell drift from an outage. It compares content: Mirth bumps revision numbers and timestamps on any save (even an unchanged one in the Administrator) and on a restore, so those are reported as a note ("pull to update the tree's baseline") and don't count as differences.
|
|
79
|
+
|
|
80
|
+
For scripts, CI and AI agents, `status`, `diff` and `push --plan-only` take `--json` and print one JSON document on stdout; errors still go to stderr with the usual exit code.
|
|
81
|
+
|
|
82
|
+
- `status --json`: `{ root, source, pulledAt, engineVersion, counts }`.
|
|
83
|
+
- `diff --json`: `{ clean, files: [{ path, change }], secretDrift, staleRevisions, notes, patch }`, where `change` is `modified`, `only-in-tree` or `only-on-server` and `patch` is the redacted unified diff.
|
|
84
|
+
- `push --plan-only --json`: `{ target, mode, changes: [{ kind, op, id, label }], conflicts, serverOnly, notPushed, wouldStop }` (plus `redeploy` and `notRedeployed` with `--deploy`). `wouldStop` lists what would refuse a real push with the same flags, such as unconfirmed deletions or conflicts.
|
|
78
85
|
|
|
79
86
|
`pull` and `explode` replace `server/`, `channels/`, `codeTemplates/` and `channelGroups/` in `<dir>`, so they refuse a directory that has any of those but no `channelvault.json`, an unreadable `channelvault.json`, or a `--dotenv` file inside one of those directories. All of this is checked before anything is written.
|
|
80
87
|
|
|
@@ -114,6 +121,7 @@ channelvault push ./mirth --library Formatting --deploy # one library, then red
|
|
|
114
121
|
- A tree exploded from an XML backup is refused (its shape differs from the live API's); `--ignore-origin` overrides that.
|
|
115
122
|
- Before it changes anything, `push` backs up the server (see below) and prints the `restore` command that undoes it. `--no-backup` skips that.
|
|
116
123
|
- Without a terminal, `push` needs `--yes`.
|
|
124
|
+
- `--plan-only` shows the plan and what would stop it, and changes nothing: no prompt, no backup, no writes. It works without a terminal.
|
|
117
125
|
|
|
118
126
|
## Backups
|
|
119
127
|
|
|
@@ -139,6 +147,22 @@ channelvault restore .backup/vns-gov-20260925T143012Z.xml --deploy
|
|
|
139
147
|
- If the server changes while you confirm, nothing is restored; run it again to review the new state.
|
|
140
148
|
- `--deploy` redeploys every channel afterwards; `--overwrite-config-map` also replaces the configuration map.
|
|
141
149
|
|
|
150
|
+
## Using channelvault with an AI agent
|
|
151
|
+
|
|
152
|
+
An agent can safely edit a tree and check its work. Pushing, restoring and anything that needs `--force` should stay with a person, who reads the plan first. Paste this into the agent instructions of your configuration repository (`AGENTS.md`, `CLAUDE.md` or similar) and adjust the paths:
|
|
153
|
+
|
|
154
|
+
```markdown
|
|
155
|
+
## Mirth configuration (channelvault)
|
|
156
|
+
|
|
157
|
+
`mirth/` is a channelvault tree of our Mirth Connect server. Channel scripts are the `.js` files under `mirth/channels/<channel>/`, settings are in `channel.json`, and code templates are under `mirth/codeTemplates/<library>/`.
|
|
158
|
+
|
|
159
|
+
- Edit the `.js` and `.json` files; leave `id`, `revision`, `channelvault.json` and the `{"@file": …}` / `{"@ref": …}` markers alone. A new channel or template needs its own new UUID for `id`; a copied directory keeps the old one.
|
|
160
|
+
- Mirth runs these scripts in Rhino, not Node: no `async`/`await`, optional chaining (`?.`), classes, `require`, `import` or shorthand object properties (`{ status }`; write `{ status: status }`). `let`, `const` and arrow functions work.
|
|
161
|
+
- `{{env:NAME}}` is a placeholder for a secret kept outside git. Never replace one with a real value, and never read, print or copy `.env`, `.secrets/` or `.backup/`.
|
|
162
|
+
- Check your work with `channelvault diff mirth --json` (exit 0: matches the server, 1: differs) and `channelvault push mirth --plan-only --json`, which shows what a push would change and `wouldStop` reasons.
|
|
163
|
+
- Do not run `channelvault push` (other than with `--plan-only`), `restore` or `pull`, and never pass `--force`, `--allow-deletes` or `--yes`. Summarise the plan and let a person push.
|
|
164
|
+
```
|
|
165
|
+
|
|
142
166
|
## Local test server
|
|
143
167
|
|
|
144
168
|
```
|
|
@@ -149,7 +173,7 @@ MIRTH_HOST=localhost MIRTH_PORT=8443 MIRTH_USER=admin MIRTH_PASS=admin \
|
|
|
149
173
|
|
|
150
174
|
To try channelvault on a **real** configuration, use `docker compose -f docker-compose.isolated.yml up -d` instead: the same server with no outbound network (a deployed channel cannot reach anything), startup deploy off, and port 8443 on localhost only. `down` deletes it and everything in it.
|
|
151
175
|
|
|
152
|
-
`pnpm test:integration` creates two disposable Mirth 4.5.2 servers on random localhost ports, imports
|
|
176
|
+
`pnpm test:integration` creates two disposable Mirth 4.5.2 servers on random localhost ports and runs two suites. The mesh suite loads the production-shaped mesh and checks that a pull converges (nothing to push, no diff) before and after scoped pushes, a redeploy and a restore. The promotion suite imports the synthetic fixture and drives the CLI through a promotion with different destination credentials and independent revision history. It verifies conflict refusal, an explicit override, preserved tags and unrelated channels, and a clean repeat push. It removes its containers and network on success or failure. Docker is required; unavailable servers fail the command.
|
|
153
177
|
|
|
154
178
|
`test/integration/live.test.ts` is an optional additional suite for a disposable server you manage yourself. It runs when `MIRTH_HOST` is set; connection failures fail the suite. It writes the server configuration, so do not point it at a production or shared server.
|
|
155
179
|
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { spawnSync } from "child_process";
|
|
5
|
-
import { mkdir as mkdir4, mkdtemp, readFile as readFile5, realpath as realpath3, rename as rename3, rm as rm3, writeFile as writeFile5 } from "fs/promises";
|
|
5
|
+
import { mkdir as mkdir4, mkdtemp, readdir as readdir4, readFile as readFile5, realpath as realpath3, rename as rename3, rm as rm3, writeFile as writeFile5 } from "fs/promises";
|
|
6
6
|
import { existsSync as existsSync5 } from "fs";
|
|
7
7
|
import { tmpdir } from "os";
|
|
8
8
|
import { createRequire } from "module";
|
|
@@ -398,12 +398,17 @@ async function splitCollection(parent, containerKey, elementKey, root, serverDir
|
|
|
398
398
|
const wasArray = Array.isArray(raw);
|
|
399
399
|
const elements = asArray(raw);
|
|
400
400
|
const refs = [];
|
|
401
|
+
const byName = (el) => `${slug(el["name"]).toLowerCase()}\0${String(el["id"] ?? "")}`;
|
|
402
|
+
const slugs = /* @__PURE__ */ new Map();
|
|
403
|
+
for (const el of elements.filter(isPlainObject).sort((a, b) => byName(a) < byName(b) ? -1 : byName(a) > byName(b) ? 1 : 0)) {
|
|
404
|
+
slugs.set(el, uniqueSlug(slug(el["name"]), usedSlugs));
|
|
405
|
+
}
|
|
401
406
|
for (const el of elements) {
|
|
402
407
|
if (!isPlainObject(el)) {
|
|
403
408
|
refs.push(el);
|
|
404
409
|
continue;
|
|
405
410
|
}
|
|
406
|
-
const slugName =
|
|
411
|
+
const slugName = slugs.get(el);
|
|
407
412
|
const { jsonFile, resourceDir } = targetFor(el["name"], slugName);
|
|
408
413
|
const transformed = await explodeResource(el, resourceDir);
|
|
409
414
|
await writeJson(jsonFile, transformed);
|
|
@@ -1669,6 +1674,44 @@ function stripVolatile(o) {
|
|
|
1669
1674
|
}
|
|
1670
1675
|
return out;
|
|
1671
1676
|
}
|
|
1677
|
+
var groupsOf = (c) => isObj(c["channelGroups"]) ? list(c["channelGroups"]["channelGroup"]) : [];
|
|
1678
|
+
function withoutVolatile(c) {
|
|
1679
|
+
const out = structuredClone(c);
|
|
1680
|
+
const strip = (o) => {
|
|
1681
|
+
delete o["revision"];
|
|
1682
|
+
delete o["lastModified"];
|
|
1683
|
+
const md = isObj(o["exportData"]) ? o["exportData"]["metadata"] : void 0;
|
|
1684
|
+
if (isObj(md)) {
|
|
1685
|
+
delete md["lastModified"];
|
|
1686
|
+
delete md["userId"];
|
|
1687
|
+
}
|
|
1688
|
+
};
|
|
1689
|
+
for (const ch of channelsOf(out)) strip(ch);
|
|
1690
|
+
for (const lib of librariesOf(out)) {
|
|
1691
|
+
strip(lib);
|
|
1692
|
+
for (const t of templatesOf2(lib)) strip(t);
|
|
1693
|
+
}
|
|
1694
|
+
for (const g of groupsOf(out)) {
|
|
1695
|
+
strip(g);
|
|
1696
|
+
for (const member of isObj(g["channels"]) ? list(g["channels"]["channel"]) : []) delete member["revision"];
|
|
1697
|
+
}
|
|
1698
|
+
return out;
|
|
1699
|
+
}
|
|
1700
|
+
function newerOnServer(tree, server) {
|
|
1701
|
+
const out = [];
|
|
1702
|
+
const compare = (kind, local, remote) => {
|
|
1703
|
+
const mine = new Map(local.map((o) => [idOf(o), revisionOf(o)]));
|
|
1704
|
+
for (const r of remote) {
|
|
1705
|
+
const rev = mine.get(idOf(r));
|
|
1706
|
+
if (rev !== void 0 && revisionOf(r) > rev) out.push(`${kind} "${nameOf(r)}"`);
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
compare("channel", channelsOf(tree), channelsOf(server));
|
|
1710
|
+
compare("library", librariesOf(tree), librariesOf(server));
|
|
1711
|
+
compare("code template", librariesOf(tree).flatMap(templatesOf2), librariesOf(server).flatMap(templatesOf2));
|
|
1712
|
+
compare("channel group", groupsOf(tree), groupsOf(server));
|
|
1713
|
+
return out;
|
|
1714
|
+
}
|
|
1672
1715
|
function libraryShape(lib) {
|
|
1673
1716
|
const out = stripVolatile(lib);
|
|
1674
1717
|
out["codeTemplates"] = templatesOf2(lib).map(idOf);
|
|
@@ -1823,10 +1866,12 @@ function planPush(local, remote, scope = {}, known, opts = {}) {
|
|
|
1823
1866
|
for (const r of channelsOf(remote)) if (!deletedChannels.has(idOf(r))) effective.set(idOf(r), r);
|
|
1824
1867
|
for (const l of channelsOf(local)) if (writtenChannels.has(idOf(l))) effective.set(idOf(l), l);
|
|
1825
1868
|
const nameKey = (c) => nameOf(c).toLowerCase();
|
|
1869
|
+
const remoteNames = new Map(channelsOf(remote).map((c) => [idOf(c), nameKey(c)]));
|
|
1870
|
+
const introducesName = (c) => writtenChannels.has(idOf(c)) && remoteNames.get(idOf(c)) !== nameKey(c);
|
|
1826
1871
|
const during = opts.wholeReplace ? [] : channelsOf(remote);
|
|
1827
1872
|
const holders = [...new Map([...during, ...effective.values()].map((c) => [`${idOf(c)}
|
|
1828
1873
|
${nameKey(c)}`, c])).values()];
|
|
1829
|
-
const clashes = duplicates(holders, nameKey).filter(([, g]) => g.some(
|
|
1874
|
+
const clashes = duplicates(holders, nameKey).filter(([, g]) => g.some(introducesName));
|
|
1830
1875
|
if (clashes.length > 0) {
|
|
1831
1876
|
throw new Error(
|
|
1832
1877
|
`the push would save a channel under a name another channel holds:
|
|
@@ -2360,6 +2405,13 @@ async function withClient(flags, fn) {
|
|
|
2360
2405
|
await client.close().catch(() => void 0);
|
|
2361
2406
|
}
|
|
2362
2407
|
}
|
|
2408
|
+
function addJsonFlag(cmd) {
|
|
2409
|
+
return cmd.option("--json", "print the result as one JSON document on stdout", false);
|
|
2410
|
+
}
|
|
2411
|
+
function writeJson2(value) {
|
|
2412
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
2413
|
+
`);
|
|
2414
|
+
}
|
|
2363
2415
|
function addBackupDirFlags(cmd) {
|
|
2364
2416
|
return cmd.option("--backup-dir <dir>", `where backups are kept (default ./${DEFAULT_BACKUP_DIR})`).option("--keep <n>", `backups kept per server (default ${DEFAULT_KEEP})`);
|
|
2365
2417
|
}
|
|
@@ -2662,9 +2714,10 @@ function printChanges(plan) {
|
|
|
2662
2714
|
for (const c of plan.changes) process.stdout.write(` ${c.op.padEnd(6)} ${`${kindLabel[c.kind]} ${c.label}`.trim()}
|
|
2663
2715
|
`);
|
|
2664
2716
|
}
|
|
2665
|
-
function
|
|
2717
|
+
function planProblems(plan, flags) {
|
|
2718
|
+
const problems = [];
|
|
2666
2719
|
if (plan.conflicts.length > 0 && !flags.force) {
|
|
2667
|
-
|
|
2720
|
+
problems.push(
|
|
2668
2721
|
`changed on the server since the last pull:
|
|
2669
2722
|
${plan.conflicts.join("\n ")}
|
|
2670
2723
|
pull (and merge) first, or pass --force to overwrite the server's version`
|
|
@@ -2672,8 +2725,37 @@ pull (and merge) first, or pass --force to overwrite the server's version`
|
|
|
2672
2725
|
}
|
|
2673
2726
|
const deletes = plan.changes.filter((c) => c.op === "delete").length;
|
|
2674
2727
|
if (deletes > 0 && !flags.allowDeletes) {
|
|
2675
|
-
|
|
2728
|
+
problems.push(`the plan deletes ${deletes} resource(s) from the server; pass --allow-deletes, or narrow with --channel/--library`);
|
|
2676
2729
|
}
|
|
2730
|
+
return problems;
|
|
2731
|
+
}
|
|
2732
|
+
function wholeServerProblems(plan, flags) {
|
|
2733
|
+
const problems = [];
|
|
2734
|
+
if (plan.serverOnly.length > 0 && !flags.force) {
|
|
2735
|
+
problems.push("the replace would delete resources created on the server since the last pull; pull first, or pass --force (and --allow-deletes)");
|
|
2736
|
+
}
|
|
2737
|
+
const deletions = plan.changes.filter((c) => c.op === "delete").length + plan.serverOnly.length;
|
|
2738
|
+
if (deletions > 0 && !flags.allowDeletes) problems.push(`the replace deletes ${deletions} resource(s) from the server; pass --allow-deletes`);
|
|
2739
|
+
if (plan.conflicts.length > 0 && !flags.force) problems.push(...planProblems({ ...plan, changes: [] }, flags));
|
|
2740
|
+
return problems;
|
|
2741
|
+
}
|
|
2742
|
+
function reportPlanOnly(flags, plan, problems, extra) {
|
|
2743
|
+
if (flags.json) {
|
|
2744
|
+
writeJson2({
|
|
2745
|
+
target: extra.target,
|
|
2746
|
+
mode: extra.mode,
|
|
2747
|
+
changes: plan.changes,
|
|
2748
|
+
conflicts: plan.conflicts,
|
|
2749
|
+
serverOnly: plan.serverOnly,
|
|
2750
|
+
notPushed: plan.notPushed,
|
|
2751
|
+
...extra.redeploy ? { redeploy: extra.redeploy, notRedeployed: extra.notRedeployed ?? [] } : {},
|
|
2752
|
+
wouldStop: problems
|
|
2753
|
+
});
|
|
2754
|
+
return;
|
|
2755
|
+
}
|
|
2756
|
+
for (const p of problems) process.stdout.write(`a push would stop: ${p}
|
|
2757
|
+
`);
|
|
2758
|
+
process.stdout.write("plan only: nothing was changed\n");
|
|
2677
2759
|
}
|
|
2678
2760
|
async function scopedPush(client, root, local, scope, target, flags) {
|
|
2679
2761
|
const remote = await client.getServerConfiguration();
|
|
@@ -2686,6 +2768,11 @@ async function scopedPush(client, root, local, scope, target, flags) {
|
|
|
2686
2768
|
const deployed = flags.deploy && plan.deployIds.length > 0 ? await client.getDeployedChannelIds() : /* @__PURE__ */ new Set();
|
|
2687
2769
|
const toDeploy = plan.deployIds.filter((id) => deployed.has(id));
|
|
2688
2770
|
const notDeployed = flags.deploy ? plan.deployIds.filter((id) => !deployed.has(id)) : [];
|
|
2771
|
+
if (flags.planOnly && flags.json) {
|
|
2772
|
+
const redeploy = flags.deploy ? { redeploy: toDeploy.map(nameOf2), notRedeployed: notDeployed.map(nameOf2) } : {};
|
|
2773
|
+
reportPlanOnly(flags, plan, planProblems(plan, flags), { target, mode: "scoped", ...redeploy });
|
|
2774
|
+
return;
|
|
2775
|
+
}
|
|
2689
2776
|
if (plan.changes.length === 0) {
|
|
2690
2777
|
process.stdout.write(`nothing to push: ${target} already matches the tree
|
|
2691
2778
|
`);
|
|
@@ -2708,8 +2795,13 @@ async function scopedPush(client, root, local, scope, target, flags) {
|
|
|
2708
2795
|
process.stdout.write(`left alone (created on the server since the last pull; pull to get them): ${plan.serverOnly.join(", ")}
|
|
2709
2796
|
`);
|
|
2710
2797
|
}
|
|
2798
|
+
if (flags.planOnly) {
|
|
2799
|
+
reportPlanOnly(flags, plan, planProblems(plan, flags), { target, mode: "scoped" });
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2711
2802
|
if (plan.changes.length === 0) return;
|
|
2712
|
-
|
|
2803
|
+
const problems = planProblems(plan, flags);
|
|
2804
|
+
if (problems.length > 0) fail(problems.join("\n"));
|
|
2713
2805
|
if (!flags.yes && !await confirm("Continue?")) {
|
|
2714
2806
|
process.stdout.write("aborted.\n");
|
|
2715
2807
|
return;
|
|
@@ -2755,6 +2847,10 @@ async function wholeServerPush(client, root, local, target, flags) {
|
|
|
2755
2847
|
const remote = await client.getServerConfiguration();
|
|
2756
2848
|
const known = await readKnown(root);
|
|
2757
2849
|
const plan = planPush(local, remote, {}, known, { wholeReplace: true });
|
|
2850
|
+
if (flags.planOnly && flags.json) {
|
|
2851
|
+
reportPlanOnly(flags, plan, wholeServerProblems(plan, flags), { target, mode: "whole-server" });
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2758
2854
|
const s = summarize(local);
|
|
2759
2855
|
process.stdout.write(
|
|
2760
2856
|
`Replace the ENTIRE server configuration at ${target} (${s.channels} channels, ${s.codeTemplates} code templates${flags.deploy ? ", then redeploy all channels" : ""}).
|
|
@@ -2772,14 +2868,12 @@ async function wholeServerPush(client, root, local, target, flags) {
|
|
|
2772
2868
|
if (replaced.length > 0) process.stdout.write(`also replaced: ${replaced.join(", ")}
|
|
2773
2869
|
`);
|
|
2774
2870
|
if (keptMap) process.stdout.write("configuration map differs but is kept (--overwrite-config-map replaces it)\n");
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
if (deletions > 0 && !flags.allowDeletes) {
|
|
2780
|
-
fail(`the replace deletes ${deletions} resource(s) from the server; pass --allow-deletes`);
|
|
2871
|
+
const problems = wholeServerProblems(plan, flags);
|
|
2872
|
+
if (flags.planOnly) {
|
|
2873
|
+
reportPlanOnly(flags, plan, problems, { target, mode: "whole-server" });
|
|
2874
|
+
return;
|
|
2781
2875
|
}
|
|
2782
|
-
|
|
2876
|
+
if (problems.length > 0) fail(problems.join("\n"));
|
|
2783
2877
|
if (!flags.yes && !await confirm("Continue?")) {
|
|
2784
2878
|
process.stdout.write("aborted.\n");
|
|
2785
2879
|
return;
|
|
@@ -2844,7 +2938,7 @@ addExtractFlag(addEnvFlag(addConnectionFlags(
|
|
|
2844
2938
|
`);
|
|
2845
2939
|
});
|
|
2846
2940
|
addBackupDirFlags(addEnvFlag(addConnectionFlags(
|
|
2847
|
-
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("-y, --yes", "skip the confirmation prompt", false)
|
|
2941
|
+
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)
|
|
2848
2942
|
))).action(
|
|
2849
2943
|
async (dir, flags) => {
|
|
2850
2944
|
if (flags.wholeServer && (flags.channel || flags.library || flags.globalScripts)) {
|
|
@@ -2856,8 +2950,9 @@ addBackupDirFlags(addEnvFlag(addConnectionFlags(
|
|
|
2856
2950
|
await assertCompatibleOrigin(root, config, "live", flags.ignoreOrigin === true);
|
|
2857
2951
|
const cfg = resolveClientConfig(flags);
|
|
2858
2952
|
const target = `${cfg.https === false ? "http" : "https"}://${cfg.host}:${cfg.port}`;
|
|
2859
|
-
if (
|
|
2860
|
-
|
|
2953
|
+
if (flags.json && !flags.planOnly) fail("--json needs --plan-only");
|
|
2954
|
+
if (!flags.yes && !flags.planOnly && !process.stdin.isTTY) {
|
|
2955
|
+
fail("no terminal to confirm on; review with `push --plan-only` or `diff`, and pass --yes");
|
|
2861
2956
|
}
|
|
2862
2957
|
if (flags.wholeServer) {
|
|
2863
2958
|
await withClient(flags, (client) => wholeServerPush(client, root, config, target, flags));
|
|
@@ -2971,35 +3066,35 @@ to ${target}, replacing its ENTIRE configuration${flags.deploy ? ", then redeplo
|
|
|
2971
3066
|
`);
|
|
2972
3067
|
});
|
|
2973
3068
|
});
|
|
2974
|
-
addEnvFlag(addConnectionFlags(
|
|
3069
|
+
addJsonFlag(addEnvFlag(addConnectionFlags(
|
|
2975
3070
|
program.command("diff").description("Diff a working tree against the live server configuration (exit 0 = same, 1 = differences, 2 = error)").argument("<dir>", "working-tree directory").exitOverride((err) => {
|
|
2976
3071
|
process.exitCode = err.exitCode === 0 ? 0 : 2;
|
|
2977
3072
|
throw err;
|
|
2978
3073
|
})
|
|
2979
|
-
)).action(async (dir, flags) => {
|
|
3074
|
+
))).action(async (dir, flags) => {
|
|
2980
3075
|
errorExitCode = 2;
|
|
2981
3076
|
const root = path5.resolve(dir);
|
|
2982
3077
|
assertTree(root);
|
|
2983
3078
|
const fetched = await withClient(flags, (client) => client.getServerConfiguration());
|
|
2984
3079
|
const tree = await engine.implode({ root });
|
|
2985
3080
|
const { config: templatedRemote, envUpdates, notes } = templatize(fetched, tree, await loadEnv(envFilePath(root, flags)));
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
for (const note of notes) process.stderr.write(`note: ${note}
|
|
2991
|
-
`);
|
|
3081
|
+
const messages = [
|
|
3082
|
+
...Object.keys(envUpdates).map((name) => `${name} differs between the server and the env file`),
|
|
3083
|
+
...notes
|
|
3084
|
+
];
|
|
2992
3085
|
const allow = await readAllow(root);
|
|
2993
|
-
const
|
|
2994
|
-
|
|
3086
|
+
const staleRevisions = newerOnServer(tree, templatedRemote);
|
|
3087
|
+
if (staleRevisions.length > 0) {
|
|
3088
|
+
messages.push(`${staleRevisions.length} resource(s) have a newer revision on the server; pull to update the tree's baseline`);
|
|
3089
|
+
}
|
|
3090
|
+
const treeView = scanSecrets(redactKnownSecrets(normalizeEolDeep(withoutVolatile(tree))), { mode: "redact", allow });
|
|
3091
|
+
const serverView = scanSecrets(redactKnownSecrets(normalizeEolDeep(withoutVolatile(templatedRemote))), { mode: "redact", allow });
|
|
2995
3092
|
if (treeView.findings.length > 0) {
|
|
2996
|
-
|
|
2997
|
-
`);
|
|
3093
|
+
messages.push(`the tree holds ${treeView.findings.length} unextracted secret(s), redacted below; pull --extract-secrets`);
|
|
2998
3094
|
}
|
|
2999
|
-
if (serverView.findings.length > 0) {
|
|
3000
|
-
|
|
3095
|
+
if (serverView.findings.length > 0) messages.push(`${serverView.findings.length} possible secret(s) on the server are redacted below`);
|
|
3096
|
+
if (!flags.json) for (const m of messages) process.stderr.write(`note: ${m}
|
|
3001
3097
|
`);
|
|
3002
|
-
}
|
|
3003
3098
|
const tmp = await mkdtemp(path5.join(tmpdir(), "channelvault-diff-"));
|
|
3004
3099
|
try {
|
|
3005
3100
|
await engine.explode(treeView.config, { root: path5.join(tmp, "tree") });
|
|
@@ -3027,7 +3122,12 @@ addEnvFlag(addConnectionFlags(
|
|
|
3027
3122
|
}
|
|
3028
3123
|
const out = chunks.join("\n");
|
|
3029
3124
|
const secretDrift = Object.keys(envUpdates);
|
|
3030
|
-
|
|
3125
|
+
const clean = out === "" && secretDrift.length === 0;
|
|
3126
|
+
if (!clean) process.exitCode = 1;
|
|
3127
|
+
if (flags.json) {
|
|
3128
|
+
const files = await changedFiles(path5.join(tmp, "tree"), path5.join(tmp, "server"));
|
|
3129
|
+
writeJson2({ clean, files, secretDrift, staleRevisions, notes: messages, patch: out });
|
|
3130
|
+
} else if (clean) {
|
|
3031
3131
|
process.stdout.write("no differences \u2014 working tree matches the server.\n");
|
|
3032
3132
|
} else {
|
|
3033
3133
|
if (out !== "") process.stdout.write(out + "\n");
|
|
@@ -3035,20 +3135,47 @@ addEnvFlag(addConnectionFlags(
|
|
|
3035
3135
|
process.stdout.write(`secret values differ between the server and the env file: ${secretDrift.join(", ")}
|
|
3036
3136
|
`);
|
|
3037
3137
|
}
|
|
3038
|
-
process.exitCode = 1;
|
|
3039
3138
|
}
|
|
3040
3139
|
} finally {
|
|
3041
3140
|
await rm3(tmp, RM_OPTS);
|
|
3042
3141
|
}
|
|
3043
3142
|
});
|
|
3044
|
-
|
|
3143
|
+
async function changedFiles(treeDir, serverDir) {
|
|
3144
|
+
const list2 = async (base) => {
|
|
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)]);
|
|
3155
|
+
const remoteSet = new Set(remote);
|
|
3156
|
+
const files = [];
|
|
3157
|
+
for (const p of local) {
|
|
3158
|
+
if (!remoteSet.has(p)) files.push({ path: p, change: "only-in-tree" });
|
|
3159
|
+
else if (await readFile5(path5.join(treeDir, p), "utf8") !== await readFile5(path5.join(serverDir, p), "utf8")) files.push({ path: p, change: "modified" });
|
|
3160
|
+
}
|
|
3161
|
+
const localSet = new Set(local);
|
|
3162
|
+
for (const p of remote) if (!localSet.has(p)) files.push({ path: p, change: "only-on-server" });
|
|
3163
|
+
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
3164
|
+
}
|
|
3165
|
+
addJsonFlag(
|
|
3166
|
+
program.command("status").description("Summarize a working tree").argument("<dir>", "working-tree directory")
|
|
3167
|
+
).action(async (dir, flags) => {
|
|
3045
3168
|
const root = path5.resolve(dir);
|
|
3046
3169
|
assertTree(root);
|
|
3047
3170
|
const config = await engine.implode({ root });
|
|
3048
3171
|
const s = summarize(config);
|
|
3049
3172
|
const metaPath = path5.join(root, "channelvault.json");
|
|
3050
|
-
|
|
3051
|
-
|
|
3173
|
+
const meta = existsSync5(metaPath) ? await readJson(metaPath) : null;
|
|
3174
|
+
if (flags.json) {
|
|
3175
|
+
writeJson2({ root, source: meta?.source ?? null, pulledAt: meta?.pulledAt ?? null, engineVersion: meta?.engineVersion ?? null, counts: s });
|
|
3176
|
+
return;
|
|
3177
|
+
}
|
|
3178
|
+
if (meta) {
|
|
3052
3179
|
process.stdout.write(`source: ${meta.source}
|
|
3053
3180
|
`);
|
|
3054
3181
|
process.stdout.write(`pulled: ${meta.pulledAt}
|