@serfab/cadre-host 1.14.0 → 1.16.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,153 +1,160 @@
1
- /**
2
- * Hosted-node types for cadre-host.
3
- *
4
- * A **hosted node** is a child process the host runs for some cadre. It gets into its
5
- * cadre one of two ways: the host starts it waiting to be claimed and shows its addresses
6
- * and claim secret as a QR code, which the owner's phone scans to claim the node
7
- * (`CadreNode.claimNode`); or the host starts it with a cadre invitation the owner's app
8
- * minted, which the node redeems at a member of the cadre. Either way the host holds no
9
- * owner key and is not an owner of any cadre its nodes serve.
10
- *
11
- * Records live in `<dataDir>/hosted-nodes.json` (`HostedNodeStore`). A record's id is also
12
- * its orchestrator container id and the name of its working directory.
13
- */
14
-
15
- /**
16
- * Lifecycle of one hosted node:
17
- * spawning → the record is written, the child not yet spawned.
18
- * unclaimed → (claim) the child is up with a claim secret, waiting for a phone to claim it.
19
- * joining → (invitation) the child is up, its redemption of the invitation not yet settled.
20
- * joined → in its cadre: claimed, or the invitation accepted by a member.
21
- * error → the supervisor gave up on it, the stuck-`spawning` reap found it, or the
22
- * invitation was refused or no member could be reached (`retryable` says which).
23
- *
24
- * Removal deletes the row; there is no terminal "removed" status. An `error` record keeps
25
- * its working directory (its identity key) until it is removed or reset.
26
- */
27
- export type HostedNodeStatus = 'spawning' | 'unclaimed' | 'joining' | 'joined' | 'error';
28
-
29
- /**
30
- * The node was started with a claim secret and waits for a phone to present it.
31
- */
32
- export interface HostedNodeClaimJoin {
33
- kind: 'claim';
34
- /** The node's one-time claim secret, base64url. Only `claimDetails` ever returns it. */
35
- secret: string;
36
- }
37
-
38
- /**
39
- * The node was started with a cadre invitation and redeems it at a member of the cadre.
40
- * Kept for a respawn while `joining`: the child redeems again, and a member answers a node
41
- * that already got in as accepted.
42
- */
43
- export interface HostedNodeInvitationJoin {
44
- kind: 'invitation';
45
- /**
46
- * The bundle as the owner's app encoded it (`encodeCadreInvitation`). It carries the
47
- * invitation's private key, so it is redacted like the claim secret.
48
- *
49
- * NOTE: kept on disk after the node joins, though nothing reads it then (a joined node is
50
- * respawned without it). An invitation with uses left admits whoever reads it; if
51
- * multi-use invitations get pasted into hosts, drop it at the watcher's `joined` write.
52
- */
53
- encoded: string;
54
- }
55
-
56
- /** How a node gets into its cadre. */
57
- export type HostedNodeJoin = HostedNodeClaimJoin | HostedNodeInvitationJoin;
58
-
59
- /** One hosted node, as persisted in `hosted-nodes.json`. */
60
- export interface HostedNode {
61
- /** `hn_<base64url of 12 random bytes>` — also the orchestrator container id and workdir name. */
62
- id: string;
63
- join: HostedNodeJoin;
64
- /**
65
- * A claim node: `unclaimed` (the placeholder party the child's config names) until the
66
- * claim reports the party; the claimant's party after. An invitation node: the
67
- * invitation's party from the start.
68
- */
69
- partyId: string;
70
- /** Hosted nodes run the `storage` profile: they participate in strands and are dialable. */
71
- profile: 'storage';
72
- status: HostedNodeStatus;
73
- /** Orchestrator handle (opaque `pid:token`), set once the child is spawned. */
74
- dockerId?: string;
75
- /** The child's loopback `/status` URL, from the spawn result. */
76
- statusEndpoint?: string;
77
- /** Read once from `/status`; the claim details need it before the claim. */
78
- peerId?: string;
79
- /**
80
- * Set when the node joins: `/status.node.claimedBy` for a claim, the invitation's issuer
81
- * key for an invitation. The UI shows its first 8 characters.
82
- */
83
- ownerKey?: string;
84
- /** An invitation node, once joined: the member that admitted it, when its address named one. */
85
- memberPeerId?: string;
86
- /** From the last status poll: the node holds at least one control connection. */
87
- connected?: boolean;
88
- /**
89
- * Respawn bookkeeping, owned by the supervisor's backoff. Absent until the first
90
- * respawn attempt. Not secret — it rides along in `HostedNodeView`.
91
- */
92
- respawn?: { attempts: number; lastAttemptAt: string };
93
- createdAt: string;
94
- updatedAt: string;
95
- /** Failure detail when `status === 'error'`. */
96
- error?: string;
97
- /**
98
- * Set with `error` when an invitation failed: whether Retry may start the node again with
99
- * the same invitation (no member could be reached), or the invitation itself was refused.
100
- * Absent on every other `error`.
101
- */
102
- retryable?: boolean;
103
- }
104
-
105
- /** `join` without its secret: what `list`, `get`, the routes and the events carry. */
106
- export type HostedNodeJoinView = { kind: HostedNodeJoin['kind'] };
107
-
108
- /** The wire shape of a hosted node: the record with the claim secret or the invitation stripped. */
109
- export interface HostedNodeView extends Omit<HostedNode, 'join'> {
110
- join: HostedNodeJoinView;
111
- }
112
-
113
- /** On-disk shape of `hosted-nodes.json`. Keyed by node id. */
114
- export interface HostedNodeFile {
115
- version: 1;
116
- nodes: Record<string, Omit<HostedNode, 'id'>>;
117
- }
118
-
119
- /** Error codes thrown by the hosted-node service, mapped to HTTP status by `server/error-handler.ts`. */
120
- export type HostedNodeErrorCode =
121
- | 'not_found' // 404 — no such hosted node
122
- | 'invalid_state' // 409 — the operation does not apply to the node's current status
123
- | 'invalid_request' // 400 — malformed input
124
- | 'node_unavailable' // 503 — the child's /status does not answer yet
125
- | 'orchestrator_error' // 500 — spawn / stop failure
126
- | 'storage_error'; // 500 — hosted-nodes.json read/write failure
127
-
128
- /** Typed hosted-node error carrying a stable `code` for HTTP mapping. */
129
- export class HostedNodeError extends Error {
130
- readonly code: HostedNodeErrorCode;
131
-
132
- constructor(code: HostedNodeErrorCode, message: string) {
133
- super(message);
134
- this.name = 'HostedNodeError';
135
- this.code = code;
136
- }
137
- }
138
-
139
- /**
140
- * What changed about a hosted node: `added` (a join started the node), `claimed` (the
141
- * watcher saw the claim), `joined` (the watcher saw a member accept the invitation),
142
- * `removed`, or `changed` (anything else: a respawn, a liveness change, a refused
143
- * invitation, a retry, a give-up). The server publishes each as the `hosted-nodes-changed`
144
- * SSE event.
145
- */
146
- export type HostedNodeChangeKind = 'added' | 'claimed' | 'joined' | 'removed' | 'changed';
147
-
148
- export interface HostedNodeChange {
149
- kind: HostedNodeChangeKind;
150
- id: string;
151
- }
152
-
153
- export type HostedNodeChangeListener = (change: HostedNodeChange) => void;
1
+ /**
2
+ * Hosted-node types for cadre-host.
3
+ *
4
+ * A **hosted node** is a child process the host runs for some cadre. It gets into its
5
+ * cadre one of two ways: the host starts it waiting to be claimed and shows its addresses
6
+ * and claim secret as a QR code, which the owner's phone scans to claim the node
7
+ * (`CadreNode.claimNode`); or the host starts it with a cadre invitation the owner's app
8
+ * minted, which the node redeems at a member of the cadre. Either way the host holds no
9
+ * owner key and is not an owner of any cadre its nodes serve.
10
+ *
11
+ * Records live in `<dataDir>/hosted-nodes.json` (`HostedNodeStore`). A record's id is also
12
+ * its orchestrator container id and the name of its working directory.
13
+ */
14
+
15
+ /**
16
+ * Lifecycle of one hosted node:
17
+ * spawning → the record is written, the child not yet spawned.
18
+ * unclaimed → (claim) the child is up with a claim secret, waiting for a phone to claim it.
19
+ * joining → (invitation) the child is up, its redemption of the invitation not yet settled.
20
+ * joined → in its cadre: claimed, or the invitation accepted by a member.
21
+ * error → the supervisor gave up on it, the stuck-`spawning` reap found it, the
22
+ * invitation was refused or no member could be reached (`retryable` says which),
23
+ * or an owner removed it from its cadre (`removedByOwner`).
24
+ *
25
+ * Removal deletes the row; there is no terminal "removed" status, and a node an owner removed
26
+ * from its cadre is, to the host, a node that failed and waits for the admin. An `error`
27
+ * record keeps its working directory (its identity key) until it is removed or reset.
28
+ */
29
+ export type HostedNodeStatus = 'spawning' | 'unclaimed' | 'joining' | 'joined' | 'error';
30
+
31
+ /**
32
+ * The node was started with a claim secret and waits for a phone to present it.
33
+ */
34
+ export interface HostedNodeClaimJoin {
35
+ kind: 'claim';
36
+ /** The node's one-time claim secret, base64url. Only `claimDetails` ever returns it. */
37
+ secret: string;
38
+ }
39
+
40
+ /**
41
+ * The node was started with a cadre invitation and redeems it at a member of the cadre.
42
+ * Kept for a respawn while `joining`: the child redeems again, and a member answers a node
43
+ * that already got in as accepted.
44
+ */
45
+ export interface HostedNodeInvitationJoin {
46
+ kind: 'invitation';
47
+ /**
48
+ * The bundle as the owner's app encoded it (`encodeCadreInvitation`). It carries the
49
+ * invitation's private key, so it is redacted like the claim secret.
50
+ *
51
+ * NOTE: kept on disk after the node joins, though nothing reads it then (a joined node is
52
+ * respawned without it). An invitation with uses left admits whoever reads it; if
53
+ * multi-use invitations get pasted into hosts, drop it at the watcher's `joined` write.
54
+ */
55
+ encoded: string;
56
+ }
57
+
58
+ /** How a node gets into its cadre. */
59
+ export type HostedNodeJoin = HostedNodeClaimJoin | HostedNodeInvitationJoin;
60
+
61
+ /** One hosted node, as persisted in `hosted-nodes.json`. */
62
+ export interface HostedNode {
63
+ /** `hn_<base64url of 12 random bytes>` — also the orchestrator container id and workdir name. */
64
+ id: string;
65
+ join: HostedNodeJoin;
66
+ /**
67
+ * A claim node: `unclaimed` (the placeholder party the child's config names) until the
68
+ * claim reports the party; the claimant's party after. An invitation node: the
69
+ * invitation's party from the start.
70
+ */
71
+ partyId: string;
72
+ /** Hosted nodes run the `storage` profile: they participate in strands and are dialable. */
73
+ profile: 'storage';
74
+ status: HostedNodeStatus;
75
+ /** Orchestrator handle (opaque `pid:token`), set once the child is spawned. */
76
+ dockerId?: string;
77
+ /** The child's loopback `/status` URL, from the spawn result. */
78
+ statusEndpoint?: string;
79
+ /** Read once from `/status`; the claim details need it before the claim. */
80
+ peerId?: string;
81
+ /**
82
+ * Set when the node joins: `/status.node.claimedBy` for a claim, the invitation's issuer
83
+ * key for an invitation. The UI shows its first 8 characters.
84
+ */
85
+ ownerKey?: string;
86
+ /** An invitation node, once joined: the member that admitted it, when its address named one. */
87
+ memberPeerId?: string;
88
+ /** From the last status poll: the node holds at least one control connection. */
89
+ connected?: boolean;
90
+ /**
91
+ * Respawn bookkeeping, owned by the supervisor's backoff. Absent until the first
92
+ * respawn attempt. Not secret — it rides along in `HostedNodeView`.
93
+ */
94
+ respawn?: { attempts: number; lastAttemptAt: string };
95
+ createdAt: string;
96
+ updatedAt: string;
97
+ /** Failure detail when `status === 'error'`. */
98
+ error?: string;
99
+ /**
100
+ * Set with `error` when an invitation failed: whether Retry may start the node again with
101
+ * the same invitation (no member could be reached), or the invitation itself was refused.
102
+ * False on a node an owner removed; absent on every other `error`.
103
+ */
104
+ retryable?: boolean;
105
+ /**
106
+ * Set with `error` when the node reported that an owner removed it from its cadre, so the
107
+ * UI words it as a removal rather than a failure to join or to stay up.
108
+ */
109
+ removedByOwner?: true;
110
+ }
111
+
112
+ /** `join` without its secret: what `list`, `get`, the routes and the events carry. */
113
+ export type HostedNodeJoinView = { kind: HostedNodeJoin['kind'] };
114
+
115
+ /** The wire shape of a hosted node: the record with the claim secret or the invitation stripped. */
116
+ export interface HostedNodeView extends Omit<HostedNode, 'join'> {
117
+ join: HostedNodeJoinView;
118
+ }
119
+
120
+ /** On-disk shape of `hosted-nodes.json`. Keyed by node id. */
121
+ export interface HostedNodeFile {
122
+ version: 1;
123
+ nodes: Record<string, Omit<HostedNode, 'id'>>;
124
+ }
125
+
126
+ /** Error codes thrown by the hosted-node service, mapped to HTTP status by `server/error-handler.ts`. */
127
+ export type HostedNodeErrorCode =
128
+ | 'not_found' // 404 — no such hosted node
129
+ | 'invalid_state' // 409 — the operation does not apply to the node's current status
130
+ | 'invalid_request' // 400 — malformed input
131
+ | 'node_unavailable' // 503 — the child's /status does not answer yet
132
+ | 'orchestrator_error' // 500 — spawn / stop failure
133
+ | 'storage_error'; // 500 — hosted-nodes.json read/write failure
134
+
135
+ /** Typed hosted-node error carrying a stable `code` for HTTP mapping. */
136
+ export class HostedNodeError extends Error {
137
+ readonly code: HostedNodeErrorCode;
138
+
139
+ constructor(code: HostedNodeErrorCode, message: string) {
140
+ super(message);
141
+ this.name = 'HostedNodeError';
142
+ this.code = code;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * What changed about a hosted node: `added` (a join started the node), `claimed` (the
148
+ * watcher saw the claim), `joined` (the watcher saw a member accept the invitation),
149
+ * `removed`, or `changed` (anything else: a respawn, a liveness change, a refused
150
+ * invitation, a retry, a give-up). The server publishes each as the `hosted-nodes-changed`
151
+ * SSE event.
152
+ */
153
+ export type HostedNodeChangeKind = 'added' | 'claimed' | 'joined' | 'removed' | 'changed';
154
+
155
+ export interface HostedNodeChange {
156
+ kind: HostedNodeChangeKind;
157
+ id: string;
158
+ }
159
+
160
+ export type HostedNodeChangeListener = (change: HostedNodeChange) => void;