vault-cortex 0.7.0 → 0.9.0-beta.43
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/README.md +82 -5
- package/dist/configure.js +70 -0
- package/dist/docker.js +91 -13
- package/dist/env.js +9 -11
- package/dist/get-sync-token.js +8 -5
- package/dist/init.js +59 -11
- package/dist/lifecycle.js +204 -0
- package/dist/main.js +20 -0
- package/dist/messages.js +71 -12
- package/dist/optional-settings.js +233 -0
- package/dist/program.js +30 -0
- package/dist/prompts.js +3 -0
- package/dist/scaffold.js +17 -0
- package/dist/upgrade.js +14 -49
- package/package.json +1 -1
package/dist/scaffold.js
CHANGED
|
@@ -8,6 +8,8 @@ const ENV_PORT_LINE = /^PORT=(\d+)\s*$/m;
|
|
|
8
8
|
const ENV_VAULT_PATH_LINE = /^VAULT_PATH=(.+)\s*$/m;
|
|
9
9
|
/** Matches an active (uncommented) PUBLIC_URL line. */
|
|
10
10
|
const ENV_PUBLIC_URL_LINE = /^PUBLIC_URL=/m;
|
|
11
|
+
/** Matches an active (uncommented) PUBLIC_URL line, capturing a non-empty value. */
|
|
12
|
+
const ENV_PUBLIC_URL_VALUE_LINE = /^PUBLIC_URL=(.+)\s*$/m;
|
|
11
13
|
/** Matches an active (uncommented) OBSIDIAN_AUTH_TOKEN line. */
|
|
12
14
|
const OBSIDIAN_AUTH_TOKEN_LINE = /^OBSIDIAN_AUTH_TOKEN=/m;
|
|
13
15
|
export const buildFilesToWrite = (envContent) => [
|
|
@@ -46,6 +48,21 @@ export const hasEnvPublicUrl = (envFilePath) => {
|
|
|
46
48
|
return false;
|
|
47
49
|
return ENV_PUBLIC_URL_LINE.test(readFileSync(envFilePath, "utf8"));
|
|
48
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Reads the public URL value from a .env file. Returns undefined when the
|
|
53
|
+
* file is missing or has no uncommented, non-empty PUBLIC_URL line —
|
|
54
|
+
* deliberately stricter than hasEnvPublicUrl, whose job is old-compose
|
|
55
|
+
* detection and so matches an empty `PUBLIC_URL=` line too.
|
|
56
|
+
*/
|
|
57
|
+
export const readEnvPublicUrl = (envFilePath) => {
|
|
58
|
+
if (!existsSync(envFilePath))
|
|
59
|
+
return undefined;
|
|
60
|
+
const match = ENV_PUBLIC_URL_VALUE_LINE.exec(readFileSync(envFilePath, "utf8"));
|
|
61
|
+
// A whitespace-only line matches the regex and trims to "" — normalize to
|
|
62
|
+
// undefined so the non-empty contract holds ("" is never a legitimate URL).
|
|
63
|
+
const publicUrlValue = match?.[1].trim();
|
|
64
|
+
return publicUrlValue || undefined;
|
|
65
|
+
};
|
|
49
66
|
/**
|
|
50
67
|
* Detects the deployment mode from a .env file. Remote mode requires
|
|
51
68
|
* OBSIDIAN_AUTH_TOKEN (absent from local). Returns undefined when the
|
package/dist/upgrade.js
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { LOCAL_IMAGE, REMOTE_IMAGE } from "./docker.js";
|
|
2
|
+
import { ensureDaemonRunning, recreateContainer, resolveDeployment, } from "./lifecycle.js";
|
|
3
|
+
/**
|
|
4
|
+
* Pulls the latest image, re-creates the container, and verifies health.
|
|
5
|
+
* The only lifecycle command that contacts the registry — restart re-creates
|
|
6
|
+
* from the image already on disk.
|
|
7
|
+
*/
|
|
6
8
|
export const runUpgrade = async (flags, deps) => {
|
|
7
9
|
const { prompts, docker, fetchFn } = deps;
|
|
8
10
|
prompts.intro("vault-cortex upgrade");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const mode = detectMode(envFilePath);
|
|
12
|
-
if (!mode) {
|
|
13
|
-
prompts.error(`No .env found in ${targetDir} — run \`npx vault-cortex init\` first.`);
|
|
11
|
+
const deployment = resolveDeployment(flags.dir, prompts);
|
|
12
|
+
if (!deployment)
|
|
14
13
|
return 1;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const vaultPath = mode === "local" ? readEnvVaultPath(envFilePath) : undefined;
|
|
18
|
-
if (mode === "local" && !vaultPath) {
|
|
19
|
-
prompts.error(`VAULT_PATH is empty or missing in ${targetDir}/.env — cannot start the container.`);
|
|
20
|
-
return 1;
|
|
21
|
-
}
|
|
22
|
-
if (mode === "local" && !hasEnvPublicUrl(envFilePath)) {
|
|
23
|
-
prompts.error(`PUBLIC_URL not found in ${targetDir}/.env — the server requires it.\n` +
|
|
24
|
-
`Add this line to your .env:\n PUBLIC_URL=http://localhost:${port}`);
|
|
25
|
-
return 1;
|
|
26
|
-
}
|
|
27
|
-
const image = mode === "local" ? LOCAL_IMAGE : REMOTE_IMAGE;
|
|
28
|
-
if (!docker.isDaemonRunning()) {
|
|
29
|
-
prompts.error("Container runtime not running — start Docker Desktop, Colima,\n" +
|
|
30
|
-
"OrbStack, or another Docker-compatible runtime.");
|
|
14
|
+
const image = deployment.mode === "local" ? LOCAL_IMAGE : REMOTE_IMAGE;
|
|
15
|
+
if (!ensureDaemonRunning(docker, prompts))
|
|
31
16
|
return 1;
|
|
32
|
-
}
|
|
33
17
|
const spinner = prompts.spinner();
|
|
34
18
|
spinner.start(`Pulling ${image}`);
|
|
35
19
|
const imagePulled = docker.pullImage(image);
|
|
@@ -38,28 +22,9 @@ export const runUpgrade = async (flags, deps) => {
|
|
|
38
22
|
return 1;
|
|
39
23
|
}
|
|
40
24
|
spinner.stop("Image pulled.");
|
|
41
|
-
docker
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
mode,
|
|
45
|
-
envFilePath,
|
|
46
|
-
port,
|
|
47
|
-
vaultPath,
|
|
48
|
-
});
|
|
49
|
-
if (!containerStarted) {
|
|
50
|
-
prompts.error("docker run failed — see output above.");
|
|
51
|
-
return 1;
|
|
52
|
-
}
|
|
53
|
-
spinner.start("Waiting for the server to come up");
|
|
54
|
-
const healthy = await pollHealth({
|
|
55
|
-
url: `http://127.0.0.1:${port}/healthz`,
|
|
56
|
-
timeoutMs: deps.healthTimeoutMs,
|
|
57
|
-
}, fetchFn);
|
|
58
|
-
if (!healthy) {
|
|
59
|
-
spinner.stop(`Server did not respond within 2 minutes — check: docker logs ${CONTAINER_NAME}`);
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
spinner.stop("Server is up — health check passed.");
|
|
25
|
+
const exitCode = await recreateContainer({ deployment, healthTimeoutMs: deps.healthTimeoutMs }, { prompts, docker, fetchFn });
|
|
26
|
+
if (exitCode !== 0)
|
|
27
|
+
return exitCode;
|
|
63
28
|
prompts.log("Your vault data, search index, and settings are preserved.");
|
|
64
29
|
prompts.outro("Upgrade complete.");
|
|
65
30
|
return 0;
|