@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.
Files changed (107) hide show
  1. package/README.md +19 -4
  2. package/dist/bin/host.js +32 -20
  3. package/dist/bin/host.js.map +1 -1
  4. package/dist/bin/nat-output.d.ts +5 -0
  5. package/dist/bin/nat-output.js +12 -1
  6. package/dist/bin/nat-output.js.map +1 -1
  7. package/dist/bin/ui-access.d.ts +22 -0
  8. package/dist/bin/ui-access.js +44 -0
  9. package/dist/bin/ui-access.js.map +1 -0
  10. package/dist/hosted/claim-details.d.ts +25 -3
  11. package/dist/hosted/claim-details.js +31 -37
  12. package/dist/hosted/claim-details.js.map +1 -1
  13. package/dist/hosted/hosted-node-service.d.ts +7 -0
  14. package/dist/hosted/hosted-node-service.js +16 -4
  15. package/dist/hosted/hosted-node-service.js.map +1 -1
  16. package/dist/hosted/hosted-node-watcher.d.ts +16 -4
  17. package/dist/hosted/hosted-node-watcher.js +45 -9
  18. package/dist/hosted/hosted-node-watcher.js.map +1 -1
  19. package/dist/hosted/node-status.d.ts +19 -3
  20. package/dist/hosted/node-status.js +21 -5
  21. package/dist/hosted/node-status.js.map +1 -1
  22. package/dist/hosted/types.d.ts +12 -5
  23. package/dist/hosted/types.js.map +1 -1
  24. package/dist/installer/config.d.ts +23 -0
  25. package/dist/installer/config.js +46 -0
  26. package/dist/installer/config.js.map +1 -1
  27. package/dist/installer/index.d.ts +2 -0
  28. package/dist/installer/index.js +7 -16
  29. package/dist/installer/index.js.map +1 -1
  30. package/dist/installer/wizard.d.ts +12 -2
  31. package/dist/installer/wizard.js +15 -7
  32. package/dist/installer/wizard.js.map +1 -1
  33. package/dist/nat/index.d.ts +2 -1
  34. package/dist/nat/index.js +1 -0
  35. package/dist/nat/index.js.map +1 -1
  36. package/dist/nat/nat-service.d.ts +22 -5
  37. package/dist/nat/nat-service.js +75 -26
  38. package/dist/nat/nat-service.js.map +1 -1
  39. package/dist/nat/nat-store.js +11 -0
  40. package/dist/nat/nat-store.js.map +1 -1
  41. package/dist/nat/network-mode.d.ts +19 -0
  42. package/dist/nat/network-mode.js +32 -0
  43. package/dist/nat/network-mode.js.map +1 -0
  44. package/dist/nat/reachability.d.ts +5 -4
  45. package/dist/nat/reachability.js +19 -6
  46. package/dist/nat/reachability.js.map +1 -1
  47. package/dist/nat/types.d.ts +26 -6
  48. package/dist/nat/types.js.map +1 -1
  49. package/dist/orchestrator/host-process-orchestrator.d.ts +3 -3
  50. package/dist/orchestrator/host-process-orchestrator.js +6 -15
  51. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  52. package/dist/package-version.d.ts +1 -0
  53. package/dist/package-version.js +4 -0
  54. package/dist/package-version.js.map +1 -0
  55. package/dist/server/routes/settings.d.ts +1 -0
  56. package/dist/server/routes/settings.js +15 -1
  57. package/dist/server/routes/settings.js.map +1 -1
  58. package/dist/server/routes/status.js +2 -32
  59. package/dist/server/routes/status.js.map +1 -1
  60. package/dist/ui/assets/index-BHd8CWZA.css +1 -0
  61. package/dist/ui/assets/index-Ccr2GjPT.js +23 -0
  62. package/dist/ui/assets/{index-4FWuU8ye.js.map → index-Ccr2GjPT.js.map} +1 -1
  63. package/dist/ui/index.html +2 -2
  64. package/package.json +4 -5
  65. package/src/__tests__/cli.smoke.test.ts +1 -1
  66. package/src/__tests__/orchestrator-claim-secret.test.ts +1 -2
  67. package/src/__tests__/orchestrator-env-scrub.test.ts +160 -163
  68. package/src/__tests__/orchestrator-handle-contract.ts +1 -1
  69. package/src/__tests__/orchestrator-node-identity.test.ts +0 -5
  70. package/src/__tests__/orchestrator-push.test.ts +3 -3
  71. package/src/__tests__/orchestrator.test.ts +3 -5
  72. package/src/__tests__/ui-access.test.ts +30 -0
  73. package/src/bin/host.ts +30 -20
  74. package/src/bin/nat-output.ts +12 -1
  75. package/src/bin/ui-access.ts +50 -0
  76. package/src/hosted/__tests__/fake-orchestrator.test.ts +0 -1
  77. package/src/hosted/__tests__/fake-orchestrator.ts +263 -265
  78. package/src/hosted/__tests__/hosted-node-service.test.ts +708 -609
  79. package/src/hosted/__tests__/hosted-node-supervisor.test.ts +475 -474
  80. package/src/hosted/claim-details.ts +44 -37
  81. package/src/hosted/hosted-node-service.ts +23 -4
  82. package/src/hosted/hosted-node-watcher.ts +288 -250
  83. package/src/hosted/node-status.ts +31 -5
  84. package/src/hosted/types.ts +160 -153
  85. package/src/installer/__tests__/installer.smoke.test.ts +184 -182
  86. package/src/installer/__tests__/wizard.test.ts +76 -56
  87. package/src/installer/config.ts +66 -0
  88. package/src/installer/index.ts +252 -259
  89. package/src/installer/wizard.ts +101 -87
  90. package/src/nat/__tests__/nat-service.test.ts +608 -540
  91. package/src/nat/__tests__/nat-store.test.ts +130 -127
  92. package/src/nat/__tests__/network-mode.test.ts +38 -0
  93. package/src/nat/index.ts +91 -87
  94. package/src/nat/nat-service.ts +79 -26
  95. package/src/nat/nat-store.ts +249 -237
  96. package/src/nat/network-mode.ts +36 -0
  97. package/src/nat/reachability.ts +155 -143
  98. package/src/nat/types.ts +232 -209
  99. package/src/orchestrator/host-process-orchestrator.ts +1089 -1098
  100. package/src/package-version.ts +4 -0
  101. package/src/server/__tests__/fakes.ts +41 -40
  102. package/src/server/__tests__/hosted-nodes-route.test.ts +161 -160
  103. package/src/server/__tests__/settings-route.test.ts +31 -0
  104. package/src/server/routes/settings.ts +128 -115
  105. package/src/server/routes/status.ts +72 -102
  106. package/dist/ui/assets/index-4FWuU8ye.js +0 -19
  107. package/dist/ui/assets/index-Di9Q4d01.css +0 -1
@@ -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
- export interface WizardAnswers {
21
- dataDir: string;
22
- uiPort: number;
23
- upnpEnabled: boolean;
24
- configureDdns: boolean;
25
- }
26
-
27
- export const DEFAULT_UI_PORT = 8765;
28
-
29
- export function defaultsForPlatform(platform: SupportedPlatform): WizardDefaults {
30
- return {
31
- dataDir: defaultDataDir(platform),
32
- uiPort: DEFAULT_UI_PORT,
33
- upnpEnabled: true,
34
- };
35
- }
36
-
37
- /**
38
- * Drive the wizard with a function that returns the next user answer for
39
- * a prompt. Used both by the readline-backed `runWizard` and by tests.
40
- */
41
- export async function runWizardWith(
42
- defaults: WizardDefaults,
43
- ask: (label: string, fallback: string) => Promise<string>,
44
- ): Promise<WizardAnswers> {
45
- const dataDir = (await ask('Data directory', defaults.dataDir)).trim() || defaults.dataDir;
46
- const uiPort = parsePort(await ask('UI port (localhost only)', String(defaults.uiPort)), defaults.uiPort);
47
- const upnpEnabled = parseBool(
48
- await ask('Attempt UPnP port mapping on this network? [Y/n]', defaults.upnpEnabled ? 'Y' : 'n'),
49
- defaults.upnpEnabled,
50
- );
51
- const configureDdns = parseBool(await ask('Configure DDNS now? [y/N]', 'N'), false);
52
- return { dataDir, uiPort, upnpEnabled, configureDdns };
53
- }
54
-
55
- /** Production entrypoint — drives the wizard over stdin/stdout. */
56
- export async function runWizard(defaults: WizardDefaults): Promise<WizardAnswers> {
57
- const rl = createInterface({ input: process.stdin, output: process.stdout });
58
- try {
59
- return await runWizardWith(defaults, async (label, fallback) => prompt(rl, label, fallback));
60
- } finally {
61
- rl.close();
62
- }
63
- }
64
-
65
- function prompt(rl: ReadlineInterface, label: string, fallback: string): Promise<string> {
66
- return new Promise<string>((resolve) => {
67
- rl.question(`${label} [${fallback}]: `, (answer) => resolve(answer));
68
- });
69
- }
70
-
71
- function parsePort(input: string, fallback: number): number {
72
- const trimmed = input.trim();
73
- if (!trimmed) return fallback;
74
- const n = Number(trimmed);
75
- if (!Number.isInteger(n) || n <= 0 || n > 65535) {
76
- throw new Error(`Invalid port: ${input}`);
77
- }
78
- return n;
79
- }
80
-
81
- function parseBool(input: string, fallback: boolean): boolean {
82
- const trimmed = input.trim().toLowerCase();
83
- if (!trimmed) return fallback;
84
- if (['y', 'yes', 'true', '1'].includes(trimmed)) return true;
85
- if (['n', 'no', 'false', '0'].includes(trimmed)) return false;
86
- throw new Error(`Invalid yes/no answer: ${input}`);
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
+ }