@serfab/cadre-host 0.8.1 → 0.10.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 (198) hide show
  1. package/dist/auth/index.d.ts +2 -0
  2. package/dist/auth/index.js +1 -0
  3. package/dist/auth/index.js.map +1 -1
  4. package/dist/auth/self-label.d.ts +36 -0
  5. package/dist/auth/self-label.js +57 -0
  6. package/dist/auth/self-label.js.map +1 -0
  7. package/dist/auth/trust-circle.d.ts +36 -9
  8. package/dist/auth/trust-circle.js +40 -20
  9. package/dist/auth/trust-circle.js.map +1 -1
  10. package/dist/auth/types.d.ts +2 -2
  11. package/dist/bin/host.js +291 -54
  12. package/dist/bin/host.js.map +1 -1
  13. package/dist/donation/__tests__/fake-orchestrator.d.ts +103 -0
  14. package/dist/donation/__tests__/fake-orchestrator.js +180 -0
  15. package/dist/donation/__tests__/fake-orchestrator.js.map +1 -0
  16. package/dist/donation/donation-service.d.ts +361 -0
  17. package/dist/donation/donation-service.js +763 -0
  18. package/dist/donation/donation-service.js.map +1 -0
  19. package/dist/donation/donation-store.d.ts +49 -0
  20. package/dist/donation/donation-store.js +148 -0
  21. package/dist/donation/donation-store.js.map +1 -0
  22. package/dist/donation/donation-supervisor.d.ts +167 -0
  23. package/dist/donation/donation-supervisor.js +341 -0
  24. package/dist/donation/donation-supervisor.js.map +1 -0
  25. package/dist/donation/grant-service.d.ts +71 -0
  26. package/dist/donation/grant-service.js +163 -0
  27. package/dist/donation/grant-service.js.map +1 -0
  28. package/dist/donation/grant-store.d.ts +38 -0
  29. package/dist/donation/grant-store.js +135 -0
  30. package/dist/donation/grant-store.js.map +1 -0
  31. package/dist/donation/index.d.ts +20 -0
  32. package/dist/donation/index.js +17 -0
  33. package/dist/donation/index.js.map +1 -0
  34. package/dist/donation/types.d.ts +201 -0
  35. package/dist/donation/types.js +40 -0
  36. package/dist/donation/types.js.map +1 -0
  37. package/dist/index.d.ts +9 -5
  38. package/dist/index.js +7 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/installer/config.d.ts +26 -0
  41. package/dist/installer/config.js +13 -0
  42. package/dist/installer/config.js.map +1 -1
  43. package/dist/installer/index.d.ts +2 -0
  44. package/dist/installer/index.js +3 -0
  45. package/dist/installer/index.js.map +1 -1
  46. package/dist/installer/wizard.d.ts +4 -0
  47. package/dist/installer/wizard.js +5 -1
  48. package/dist/installer/wizard.js.map +1 -1
  49. package/dist/nat/nat-service.d.ts +5 -5
  50. package/dist/nat/nat-service.js +9 -9
  51. package/dist/nat/nat-service.js.map +1 -1
  52. package/dist/nat/types.d.ts +1 -1
  53. package/dist/orchestrator/host-process-orchestrator.d.ts +144 -32
  54. package/dist/orchestrator/host-process-orchestrator.js +397 -128
  55. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  56. package/dist/orchestrator/index.d.ts +3 -3
  57. package/dist/orchestrator/index.js +1 -1
  58. package/dist/orchestrator/index.js.map +1 -1
  59. package/dist/orchestrator/node-identity.d.ts +26 -0
  60. package/dist/orchestrator/node-identity.js +36 -0
  61. package/dist/orchestrator/node-identity.js.map +1 -0
  62. package/dist/orchestrator/port-allocator.d.ts +14 -0
  63. package/dist/orchestrator/port-allocator.js +45 -0
  64. package/dist/orchestrator/port-allocator.js.map +1 -1
  65. package/dist/orchestrator/state-store.d.ts +5 -5
  66. package/dist/orchestrator/state-store.js +2 -2
  67. package/dist/orchestrator/state-store.js.map +1 -1
  68. package/dist/orchestrator/types.d.ts +8 -8
  69. package/dist/owner/index.d.ts +11 -0
  70. package/dist/owner/index.js +11 -0
  71. package/dist/owner/index.js.map +1 -0
  72. package/dist/owner/owner-node-client.d.ts +110 -0
  73. package/dist/{authority/authority-node-client.js → owner/owner-node-client.js} +58 -17
  74. package/dist/owner/owner-node-client.js.map +1 -0
  75. package/dist/server/error-handler.d.ts +22 -1
  76. package/dist/server/error-handler.js +64 -1
  77. package/dist/server/error-handler.js.map +1 -1
  78. package/dist/server/events/types.d.ts +3 -0
  79. package/dist/server/index.d.ts +33 -2
  80. package/dist/server/index.js +43 -16
  81. package/dist/server/index.js.map +1 -1
  82. package/dist/server/routes/grants-admin.d.ts +17 -0
  83. package/dist/server/routes/grants-admin.js +32 -0
  84. package/dist/server/routes/grants-admin.js.map +1 -0
  85. package/dist/server/routes/grants.d.ts +28 -0
  86. package/dist/server/routes/grants.js +182 -0
  87. package/dist/server/routes/grants.js.map +1 -0
  88. package/dist/server/routes/nodes.d.ts +5 -4
  89. package/dist/server/routes/nodes.js +19 -18
  90. package/dist/server/routes/nodes.js.map +1 -1
  91. package/dist/server/routes/settings.d.ts +6 -1
  92. package/dist/server/routes/settings.js +5 -2
  93. package/dist/server/routes/settings.js.map +1 -1
  94. package/dist/server/routes/status.d.ts +8 -4
  95. package/dist/server/routes/status.js +9 -4
  96. package/dist/server/routes/status.js.map +1 -1
  97. package/dist/server/routes/strands.d.ts +20 -0
  98. package/dist/server/routes/strands.js +38 -0
  99. package/dist/server/routes/strands.js.map +1 -0
  100. package/dist/strands/index.d.ts +7 -0
  101. package/dist/strands/index.js +6 -0
  102. package/dist/strands/index.js.map +1 -0
  103. package/dist/strands/strand-service.d.ts +50 -0
  104. package/dist/strands/strand-service.js +103 -0
  105. package/dist/strands/strand-service.js.map +1 -0
  106. package/dist/strands/types.d.ts +93 -0
  107. package/dist/strands/types.js +23 -0
  108. package/dist/strands/types.js.map +1 -0
  109. package/dist/ui/assets/index-BVoqLjyX.css +1 -0
  110. package/dist/ui/assets/index-C-iks41M.js +17 -0
  111. package/dist/ui/assets/index-C-iks41M.js.map +1 -0
  112. package/dist/ui/index.html +2 -2
  113. package/dist/update/release-key.d.ts +1 -1
  114. package/dist/update/release-key.js +8 -6
  115. package/dist/update/release-key.js.map +1 -1
  116. package/package.json +5 -5
  117. package/src/__tests__/build-targets.test.ts +26 -0
  118. package/src/__tests__/global-setup.ts +51 -0
  119. package/src/__tests__/{host-authority.smoke.test.ts → host-owner.smoke.test.ts} +7 -7
  120. package/src/__tests__/orchestrator-env-scrub.test.ts +140 -0
  121. package/src/__tests__/orchestrator-node-identity.test.ts +204 -0
  122. package/src/__tests__/{orchestrator-authority.test.ts → orchestrator-owner.test.ts} +33 -33
  123. package/src/__tests__/orchestrator-pin-keys.test.ts +153 -0
  124. package/src/__tests__/orchestrator-push.test.ts +10 -10
  125. package/src/__tests__/orchestrator.test.ts +387 -6
  126. package/src/auth/__tests__/self-label.test.ts +85 -0
  127. package/src/auth/__tests__/trust-circle-integration.test.ts +152 -147
  128. package/src/auth/__tests__/trust-circle.test.ts +55 -11
  129. package/src/auth/index.ts +2 -0
  130. package/src/auth/self-label.ts +74 -0
  131. package/src/auth/trust-circle.ts +54 -22
  132. package/src/auth/types.ts +2 -2
  133. package/src/bin/host.ts +1299 -1038
  134. package/src/donation/__tests__/donation-service.test.ts +1068 -0
  135. package/src/donation/__tests__/donation-supervisor.test.ts +510 -0
  136. package/src/donation/__tests__/fake-orchestrator.test.ts +168 -0
  137. package/src/donation/__tests__/fake-orchestrator.ts +225 -0
  138. package/src/donation/__tests__/grant-service.test.ts +213 -0
  139. package/src/donation/__tests__/grant-store.test.ts +113 -0
  140. package/src/donation/donation-service.ts +962 -0
  141. package/src/donation/donation-store.ts +171 -0
  142. package/src/donation/donation-supervisor.ts +388 -0
  143. package/src/donation/grant-service.ts +200 -0
  144. package/src/donation/grant-store.ts +152 -0
  145. package/src/donation/index.ts +64 -0
  146. package/src/donation/types.ts +243 -0
  147. package/src/index.ts +51 -5
  148. package/src/installer/__tests__/config.test.ts +27 -1
  149. package/src/installer/__tests__/installer.smoke.test.ts +31 -1
  150. package/src/installer/__tests__/wizard.test.ts +5 -1
  151. package/src/installer/config.ts +34 -0
  152. package/src/installer/index.ts +5 -0
  153. package/src/installer/wizard.ts +12 -1
  154. package/src/nat/__tests__/nat-service.test.ts +5 -5
  155. package/src/nat/nat-service.ts +10 -10
  156. package/src/nat/types.ts +1 -1
  157. package/src/orchestrator/__tests__/node-identity.test.ts +62 -0
  158. package/src/orchestrator/host-process-orchestrator.ts +401 -134
  159. package/src/orchestrator/index.ts +3 -3
  160. package/src/orchestrator/node-identity.ts +40 -0
  161. package/src/orchestrator/port-allocator.ts +48 -0
  162. package/src/orchestrator/state-store.ts +7 -7
  163. package/src/orchestrator/types.ts +8 -8
  164. package/src/{authority/__tests__/authority-node-client.test.ts → owner/__tests__/owner-node-client.test.ts} +45 -17
  165. package/src/owner/index.ts +12 -0
  166. package/src/{authority/authority-node-client.ts → owner/owner-node-client.ts} +83 -23
  167. package/src/server/__tests__/error-handler.test.ts +22 -0
  168. package/src/server/__tests__/grants-admin-route.test.ts +73 -0
  169. package/src/server/__tests__/grants-route.test.ts +263 -0
  170. package/src/server/__tests__/nodes-route.test.ts +25 -25
  171. package/src/server/__tests__/server.smoke.test.ts +75 -0
  172. package/src/server/__tests__/settings-route.test.ts +17 -0
  173. package/src/server/__tests__/status-route.test.ts +21 -0
  174. package/src/server/__tests__/strands-route.test.ts +233 -0
  175. package/src/server/error-handler.ts +67 -1
  176. package/src/server/events/types.ts +1 -0
  177. package/src/server/index.ts +75 -17
  178. package/src/server/routes/grants-admin.ts +41 -0
  179. package/src/server/routes/grants.ts +210 -0
  180. package/src/server/routes/nodes.ts +19 -18
  181. package/src/server/routes/settings.ts +11 -3
  182. package/src/server/routes/status.ts +18 -8
  183. package/src/server/routes/strands.ts +54 -0
  184. package/src/strands/__tests__/strand-service.test.ts +165 -0
  185. package/src/strands/index.ts +14 -0
  186. package/src/strands/strand-service.ts +135 -0
  187. package/src/strands/types.ts +102 -0
  188. package/src/update/__tests__/release-key.test.ts +16 -3
  189. package/src/update/release-key.ts +8 -6
  190. package/dist/authority/authority-node-client.d.ts +0 -77
  191. package/dist/authority/authority-node-client.js.map +0 -1
  192. package/dist/authority/index.d.ts +0 -11
  193. package/dist/authority/index.js +0 -11
  194. package/dist/authority/index.js.map +0 -1
  195. package/dist/ui/assets/index-BlMXQPSw.js +0 -14
  196. package/dist/ui/assets/index-BlMXQPSw.js.map +0 -1
  197. package/dist/ui/assets/index-BwU5mJGF.css +0 -1
  198. package/src/authority/index.ts +0 -12
@@ -3,7 +3,7 @@ import debug from 'debug';
3
3
 
4
4
  import type { CadreInvite } from '@serfab/cadre-core';
5
5
 
6
- import { AuthorityNodeUnavailableError } from '../authority/authority-node-client.js';
6
+ import { OwnerNodeUnavailableError } from '../owner/owner-node-client.js';
7
7
 
8
8
  import type { TrustCircleStore } from './trust-circle-store.js';
9
9
  import type {
@@ -42,10 +42,22 @@ export interface CadreNodeLike {
42
42
  acceptPhone(options: { phonePeerId: string; token?: string }, issuedInvite?: CadreInvite): Promise<void>;
43
43
  removePeer(peerId: string): Promise<void>;
44
44
  encodeInvite(invite: CadreInvite): string;
45
- /** Enumerate the cadre's `CadrePeer` membership (over the admin channel). */
45
+ /**
46
+ * Enumerate the cadre's *addressable* peers (over the admin channel) —
47
+ * anyone with an address record, including devices no owner vouched for.
48
+ * Used only for {@link removeMember}, where "the row exists" is the point.
49
+ */
46
50
  listMembers(): Promise<Array<{ peerId: string; multiaddr: string | null }>>;
47
- /** Probe whether a peer is a `CadrePeer` member (over the admin channel). */
51
+ /** Probe whether a peer is *addressable* (over the admin channel). See {@link listMembers}. */
48
52
  isMember(peerId: string): Promise<boolean>;
53
+ /**
54
+ * Enumerate the cadre's *authorized* membership (over the admin channel) —
55
+ * devices an owner key vouched for. Excludes the node's own self-published
56
+ * row. This is the real membership test the trust-circle listing shows.
57
+ */
58
+ listAuthorizedMembers(): Promise<Array<{ peerId: string; multiaddr: string | null }>>;
59
+ /** Probe whether a peer is *authorized*. See {@link listAuthorizedMembers}. */
60
+ isAuthorizedMember(peerId: string): Promise<boolean>;
49
61
  }
50
62
 
51
63
  /**
@@ -53,9 +65,9 @@ export interface CadreNodeLike {
53
65
  * membership management.
54
66
  *
55
67
  * Membership is canonical in the cadre control DB (`CadrePeer` table),
56
- * reached over the authority node's admin channel; labels and pending tokens
68
+ * reached over the owner node's admin channel; labels and pending tokens
57
69
  * live in the host-local `TrustCircleStore`. When the node is unreachable,
58
- * authority operations surface `node_unavailable` (→ 503) and `list()`
70
+ * owner operations surface `node_unavailable` (→ 503) and `list()`
59
71
  * degrades to the local labels file.
60
72
  */
61
73
  export class TrustCircleService {
@@ -78,7 +90,7 @@ export class TrustCircleService {
78
90
 
79
91
  /**
80
92
  * Issue a new invite. Generates a token, persists a pending row, and
81
- * delegates to cadre-core to embed the host's authority addresses.
93
+ * delegates to cadre-core to embed the host's owner addresses.
82
94
  */
83
95
  async issueInvite(opts: { label: string; ttlMs?: number }): Promise<{
84
96
  encodedInvite: string;
@@ -127,7 +139,7 @@ export class TrustCircleService {
127
139
  *
128
140
  * Crash-safety tradeoff: if the host crashes between `acceptPhone` success
129
141
  * and the durable `removePending`, a retry will dial in fine but the
130
- * authority node's `acceptPhone` will reject the second `CadrePeer` insert
142
+ * owner node's `acceptPhone` will reject the second `CadrePeer` insert
131
143
  * with a PK constraint error (cadre-core does not upsert). That surfaces to
132
144
  * the redeemer as a non-`node_unavailable` failure; the admin can revoke
133
145
  * the lingering pending row. This is a narrower window than the prior
@@ -167,7 +179,7 @@ export class TrustCircleService {
167
179
  // matches by construction) and re-checks expiration.
168
180
  const reconstructed: CadreInvite = {
169
181
  partyId: '',
170
- authorityAddrs: [],
182
+ ownerAddrs: [],
171
183
  token: pending.token,
172
184
  createdAt: new Date(pending.createdAt).getTime(),
173
185
  ...(pending.expiresAt ? { expiresAt: new Date(pending.expiresAt).getTime() } : {}),
@@ -212,6 +224,13 @@ export class TrustCircleService {
212
224
  /**
213
225
  * Remove an authorised member. Deletes the CadrePeer row and the local
214
226
  * label. Throws not_found when the peer is in neither place.
227
+ *
228
+ * NOTE: no special case for the host's own peer ID — the local UI hides the
229
+ * Remove button on the `self` row, but `DELETE /auth/members/<ownPeerId>`
230
+ * (or `cadre-host trust revoke <ownPeerId>`) will delete the node's own
231
+ * `CadrePeer` row. cadre-core re-registers self on node start, so a restart
232
+ * heals it. If that stops being true, or the removal path grows a
233
+ * non-loopback caller, guard `self` rows here.
215
234
  */
216
235
  async removeMember(peerId: string): Promise<void> {
217
236
  const inLocal = this.store.getMember(peerId);
@@ -240,10 +259,15 @@ export class TrustCircleService {
240
259
  }
241
260
 
242
261
  /**
243
- * UI snapshot. Joins the canonical CadrePeer list (fetched over the admin
262
+ * UI snapshot. Joins the *authorized* membership (fetched over the admin
244
263
  * channel) with local labels; prunes any orphan labels (peer is no longer
245
- * authorised). When the authority node is unreachable, degrades to the
246
- * local labels file so listing keeps working while the node is down.
264
+ * authorised). Addressable-but-unauthorized peers — devices that merely
265
+ * published an address record without an owner voucher — are deliberately
266
+ * excluded; this is the listing an operator uses to decide who belongs.
267
+ * The node's own self-published row is spliced back in from the local
268
+ * label, since the authorized set excludes self by design. When the owner
269
+ * node is unreachable, degrades to the local labels file so listing keeps
270
+ * working while the node is down.
247
271
  */
248
272
  async list(): Promise<TrustCircleSnapshot> {
249
273
  const labels = new Map<string, Omit<TrustCircleMember, 'peerId'>>();
@@ -256,17 +280,17 @@ export class TrustCircleService {
256
280
  // Consult the control DB over the admin channel. A node-unavailable error
257
281
  // is non-fatal — fall back to the local labels rather than 503-ing a
258
282
  // read-only listing.
259
- let controlMembers: Array<{ peerId: string }> | null;
283
+ let authorizedMembers: Array<{ peerId: string }> | null;
260
284
  try {
261
- controlMembers = await this.cadreNode.listMembers();
285
+ authorizedMembers = await this.cadreNode.listAuthorizedMembers();
262
286
  } catch (err) {
263
- if (!(err instanceof AuthorityNodeUnavailableError)) throw err;
264
- controlMembers = null;
287
+ if (!(err instanceof OwnerNodeUnavailableError)) throw err;
288
+ authorizedMembers = null;
265
289
  }
266
290
 
267
- if (controlMembers) {
291
+ if (authorizedMembers) {
268
292
  const seenPeerIds = new Set<string>();
269
- for (const { peerId } of controlMembers) {
293
+ for (const { peerId } of authorizedMembers) {
270
294
  seenPeerIds.add(peerId);
271
295
  const label = labels.get(peerId);
272
296
  members.push({
@@ -276,9 +300,17 @@ export class TrustCircleService {
276
300
  ...(label?.self ? { self: true } : {}),
277
301
  });
278
302
  }
279
- // Prune labels for peers that no longer exist in CadrePeer. Only when we
280
- // successfully consulted the node — otherwise a transient outage would
281
- // wipe labels.
303
+ // The authorized set excludes the node's own self-published row —
304
+ // splice it back in from the local label rather than dropping it.
305
+ for (const [peerId, row] of labels) {
306
+ if (row.self && !seenPeerIds.has(peerId)) {
307
+ seenPeerIds.add(peerId);
308
+ members.push({ peerId, ...row });
309
+ }
310
+ }
311
+ // Prune labels for peers that are neither authorized nor self. Only
312
+ // when we successfully consulted the node — otherwise a transient
313
+ // outage would wipe labels.
282
314
  for (const peerId of labels.keys()) {
283
315
  if (!seenPeerIds.has(peerId)) {
284
316
  this.store.removeMember(peerId);
@@ -306,8 +338,8 @@ export class TrustCircleService {
306
338
  * `never` so callers can `.catch(err => this.toDomainError(err))`.
307
339
  */
308
340
  private toDomainError(err: unknown): never {
309
- if (err instanceof AuthorityNodeUnavailableError) {
310
- throw new TrustCircleError('node_unavailable', `Authority node unavailable: ${err.message}`);
341
+ if (err instanceof OwnerNodeUnavailableError) {
342
+ throw new TrustCircleError('node_unavailable', `Owner node unavailable: ${err.message}`);
311
343
  }
312
344
  throw err instanceof Error ? err : new Error(String(err));
313
345
  }
package/src/auth/types.ts CHANGED
@@ -62,7 +62,7 @@ export interface TrustCircleSnapshot {
62
62
  * - `not_found` → 404 (unknown token / unknown peer)
63
63
  * - `expired` → 410 (invite past expiresAt)
64
64
  * - `already_redeemed` → 409 (token was used and is gone)
65
- * - `node_unavailable` → 503 (authority node admin channel down/not ready)
65
+ * - `node_unavailable` → 503 (owner node admin channel down/not ready)
66
66
  * - default → 500
67
67
  */
68
68
  export interface TrustCircleHandlers {
@@ -84,7 +84,7 @@ export type TrustCircleErrorCode =
84
84
  | 'invalid_label'
85
85
  | 'invalid_token'
86
86
  | 'storage_error'
87
- /** The authority node's admin channel is unreachable / not ready. */
87
+ /** The owner node's admin channel is unreachable / not ready. */
88
88
  | 'node_unavailable';
89
89
 
90
90
  /** Typed error carrying a stable `code` for HTTP mapping. */