@serfab/cadre-host 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -4
- package/dist/bin/host.js +32 -20
- package/dist/bin/host.js.map +1 -1
- package/dist/bin/nat-output.d.ts +5 -0
- package/dist/bin/nat-output.js +12 -1
- package/dist/bin/nat-output.js.map +1 -1
- package/dist/bin/ui-access.d.ts +22 -0
- package/dist/bin/ui-access.js +44 -0
- package/dist/bin/ui-access.js.map +1 -0
- package/dist/hosted/claim-details.d.ts +25 -3
- package/dist/hosted/claim-details.js +31 -37
- package/dist/hosted/claim-details.js.map +1 -1
- package/dist/hosted/hosted-node-service.d.ts +7 -0
- package/dist/hosted/hosted-node-service.js +16 -4
- package/dist/hosted/hosted-node-service.js.map +1 -1
- package/dist/hosted/hosted-node-watcher.d.ts +16 -4
- package/dist/hosted/hosted-node-watcher.js +45 -9
- package/dist/hosted/hosted-node-watcher.js.map +1 -1
- package/dist/hosted/node-status.d.ts +19 -3
- package/dist/hosted/node-status.js +21 -5
- package/dist/hosted/node-status.js.map +1 -1
- package/dist/hosted/types.d.ts +12 -5
- package/dist/hosted/types.js.map +1 -1
- package/dist/installer/config.d.ts +23 -0
- package/dist/installer/config.js +46 -0
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/index.d.ts +2 -0
- package/dist/installer/index.js +7 -16
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/wizard.d.ts +12 -2
- package/dist/installer/wizard.js +15 -7
- package/dist/installer/wizard.js.map +1 -1
- package/dist/nat/index.d.ts +2 -1
- package/dist/nat/index.js +1 -0
- package/dist/nat/index.js.map +1 -1
- package/dist/nat/nat-service.d.ts +22 -5
- package/dist/nat/nat-service.js +75 -26
- package/dist/nat/nat-service.js.map +1 -1
- package/dist/nat/nat-store.js +11 -0
- package/dist/nat/nat-store.js.map +1 -1
- package/dist/nat/network-mode.d.ts +19 -0
- package/dist/nat/network-mode.js +32 -0
- package/dist/nat/network-mode.js.map +1 -0
- package/dist/nat/reachability.d.ts +5 -4
- package/dist/nat/reachability.js +19 -6
- package/dist/nat/reachability.js.map +1 -1
- package/dist/nat/types.d.ts +26 -6
- package/dist/nat/types.js.map +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +3 -3
- package/dist/orchestrator/host-process-orchestrator.js +6 -15
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/package-version.d.ts +1 -0
- package/dist/package-version.js +4 -0
- package/dist/package-version.js.map +1 -0
- package/dist/server/routes/settings.d.ts +1 -0
- package/dist/server/routes/settings.js +15 -1
- package/dist/server/routes/settings.js.map +1 -1
- package/dist/server/routes/status.js +2 -32
- package/dist/server/routes/status.js.map +1 -1
- package/dist/ui/assets/index-BHd8CWZA.css +1 -0
- package/dist/ui/assets/index-Ccr2GjPT.js +23 -0
- package/dist/ui/assets/{index-4FWuU8ye.js.map → index-Ccr2GjPT.js.map} +1 -1
- package/dist/ui/index.html +2 -2
- package/package.json +4 -5
- package/src/__tests__/cli.smoke.test.ts +1 -1
- package/src/__tests__/orchestrator-claim-secret.test.ts +1 -2
- package/src/__tests__/orchestrator-env-scrub.test.ts +160 -163
- package/src/__tests__/orchestrator-handle-contract.ts +1 -1
- package/src/__tests__/orchestrator-node-identity.test.ts +0 -5
- package/src/__tests__/orchestrator-push.test.ts +3 -3
- package/src/__tests__/orchestrator.test.ts +3 -5
- package/src/__tests__/ui-access.test.ts +30 -0
- package/src/bin/host.ts +30 -20
- package/src/bin/nat-output.ts +12 -1
- package/src/bin/ui-access.ts +50 -0
- package/src/hosted/__tests__/fake-orchestrator.test.ts +0 -1
- package/src/hosted/__tests__/fake-orchestrator.ts +263 -265
- package/src/hosted/__tests__/hosted-node-service.test.ts +708 -609
- package/src/hosted/__tests__/hosted-node-supervisor.test.ts +475 -474
- package/src/hosted/claim-details.ts +44 -37
- package/src/hosted/hosted-node-service.ts +23 -4
- package/src/hosted/hosted-node-watcher.ts +288 -250
- package/src/hosted/node-status.ts +31 -5
- package/src/hosted/types.ts +160 -153
- package/src/installer/__tests__/installer.smoke.test.ts +184 -182
- package/src/installer/__tests__/wizard.test.ts +76 -56
- package/src/installer/config.ts +66 -0
- package/src/installer/index.ts +252 -259
- package/src/installer/wizard.ts +101 -87
- package/src/nat/__tests__/nat-service.test.ts +608 -540
- package/src/nat/__tests__/nat-store.test.ts +130 -127
- package/src/nat/__tests__/network-mode.test.ts +38 -0
- package/src/nat/index.ts +91 -87
- package/src/nat/nat-service.ts +79 -26
- package/src/nat/nat-store.ts +249 -237
- package/src/nat/network-mode.ts +36 -0
- package/src/nat/reachability.ts +155 -143
- package/src/nat/types.ts +232 -209
- package/src/orchestrator/host-process-orchestrator.ts +1089 -1098
- package/src/package-version.ts +4 -0
- package/src/server/__tests__/fakes.ts +41 -40
- package/src/server/__tests__/hosted-nodes-route.test.ts +161 -160
- package/src/server/__tests__/settings-route.test.ts +31 -0
- package/src/server/routes/settings.ts +128 -115
- package/src/server/routes/status.ts +72 -102
- package/dist/ui/assets/index-4FWuU8ye.js +0 -19
- package/dist/ui/assets/index-Di9Q4d01.css +0 -1
package/src/installer/wizard.ts
CHANGED
|
@@ -1,87 +1,101 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interactive install wizard.
|
|
3
|
-
*
|
|
4
|
-
* Pure readline — no extra deps. Each prompt is decomposed into a small
|
|
5
|
-
* `Prompt` so the test can drive the wizard with a scripted Iterable of
|
|
6
|
-
* answers. Production code wires the prompts to stdin.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { createInterface, type Interface as ReadlineInterface } from 'node:readline';
|
|
10
|
-
|
|
11
|
-
import { defaultDataDir } from './paths.js';
|
|
12
|
-
import type { SupportedPlatform } from './platform.js';
|
|
13
|
-
|
|
14
|
-
export interface WizardDefaults {
|
|
15
|
-
dataDir: string;
|
|
16
|
-
uiPort: number;
|
|
17
|
-
upnpEnabled: boolean;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Interactive install wizard.
|
|
3
|
+
*
|
|
4
|
+
* Pure readline — no extra deps. Each prompt is decomposed into a small
|
|
5
|
+
* `Prompt` so the test can drive the wizard with a scripted Iterable of
|
|
6
|
+
* answers. Production code wires the prompts to stdin.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createInterface, type Interface as ReadlineInterface } from 'node:readline';
|
|
10
|
+
|
|
11
|
+
import { defaultDataDir } from './paths.js';
|
|
12
|
+
import type { SupportedPlatform } from './platform.js';
|
|
13
|
+
|
|
14
|
+
export interface WizardDefaults {
|
|
15
|
+
dataDir: string;
|
|
16
|
+
uiPort: number;
|
|
17
|
+
upnpEnabled: boolean;
|
|
18
|
+
/** Values a command-line flag already supplied: the wizard does not ask for them again. */
|
|
19
|
+
given?: { dataDir?: boolean; uiPort?: boolean; upnpEnabled?: boolean };
|
|
20
|
+
/**
|
|
21
|
+
* The public IPv4 an interface holds (`publicInterfaceAddress`), when one does: the machine is
|
|
22
|
+
* reached directly (a VPS), so there is no router to ask about UPnP.
|
|
23
|
+
*/
|
|
24
|
+
publicInterfaceIp?: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface WizardAnswers {
|
|
28
|
+
dataDir: string;
|
|
29
|
+
uiPort: number;
|
|
30
|
+
upnpEnabled: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const DEFAULT_UI_PORT = 8765;
|
|
34
|
+
|
|
35
|
+
export function defaultsForPlatform(platform: SupportedPlatform): WizardDefaults {
|
|
36
|
+
return {
|
|
37
|
+
dataDir: defaultDataDir(platform),
|
|
38
|
+
uiPort: DEFAULT_UI_PORT,
|
|
39
|
+
upnpEnabled: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Drive the wizard with a function that returns the next user answer for
|
|
45
|
+
* a prompt. Used both by the readline-backed `runWizard` and by tests.
|
|
46
|
+
*/
|
|
47
|
+
export async function runWizardWith(
|
|
48
|
+
defaults: WizardDefaults,
|
|
49
|
+
ask: (label: string, fallback: string) => Promise<string>,
|
|
50
|
+
say: (line: string) => void = () => {},
|
|
51
|
+
): Promise<WizardAnswers> {
|
|
52
|
+
const given = defaults.given ?? {};
|
|
53
|
+
const dataDir = given.dataDir ? defaults.dataDir : (await ask('Data directory', defaults.dataDir)).trim() || defaults.dataDir;
|
|
54
|
+
const uiPort = given.uiPort
|
|
55
|
+
? defaults.uiPort
|
|
56
|
+
: parsePort(await ask('UI port (localhost only)', String(defaults.uiPort)), defaults.uiPort);
|
|
57
|
+
let upnpEnabled = defaults.upnpEnabled;
|
|
58
|
+
if (defaults.publicInterfaceIp) {
|
|
59
|
+
say(`This machine has a public IP address (${defaults.publicInterfaceIp}), so it is reached directly: no router, no UPnP.`);
|
|
60
|
+
} else if (!given.upnpEnabled) {
|
|
61
|
+
upnpEnabled = parseBool(
|
|
62
|
+
await ask('This machine is behind a router. Ask it to map ports automatically (UPnP)? [Y/n]', defaults.upnpEnabled ? 'Y' : 'n'),
|
|
63
|
+
defaults.upnpEnabled,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return { dataDir, uiPort, upnpEnabled };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Production entrypoint — drives the wizard over stdin/stdout. */
|
|
70
|
+
export async function runWizard(defaults: WizardDefaults): Promise<WizardAnswers> {
|
|
71
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
72
|
+
try {
|
|
73
|
+
return await runWizardWith(defaults, async (label, fallback) => prompt(rl, label, fallback), (line) => console.log(line));
|
|
74
|
+
} finally {
|
|
75
|
+
rl.close();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function prompt(rl: ReadlineInterface, label: string, fallback: string): Promise<string> {
|
|
80
|
+
return new Promise<string>((resolve) => {
|
|
81
|
+
rl.question(`${label} [${fallback}]: `, (answer) => resolve(answer));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function parsePort(input: string, fallback: number): number {
|
|
86
|
+
const trimmed = input.trim();
|
|
87
|
+
if (!trimmed) return fallback;
|
|
88
|
+
const n = Number(trimmed);
|
|
89
|
+
if (!Number.isInteger(n) || n <= 0 || n > 65535) {
|
|
90
|
+
throw new Error(`Invalid port: ${input}`);
|
|
91
|
+
}
|
|
92
|
+
return n;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function parseBool(input: string, fallback: boolean): boolean {
|
|
96
|
+
const trimmed = input.trim().toLowerCase();
|
|
97
|
+
if (!trimmed) return fallback;
|
|
98
|
+
if (['y', 'yes', 'true', '1'].includes(trimmed)) return true;
|
|
99
|
+
if (['n', 'no', 'false', '0'].includes(trimmed)) return false;
|
|
100
|
+
throw new Error(`Invalid yes/no answer: ${input}`);
|
|
101
|
+
}
|