@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.
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +1 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/self-label.d.ts +36 -0
- package/dist/auth/self-label.js +57 -0
- package/dist/auth/self-label.js.map +1 -0
- package/dist/auth/trust-circle.d.ts +36 -9
- package/dist/auth/trust-circle.js +40 -20
- package/dist/auth/trust-circle.js.map +1 -1
- package/dist/auth/types.d.ts +2 -2
- package/dist/bin/host.js +291 -54
- package/dist/bin/host.js.map +1 -1
- package/dist/donation/__tests__/fake-orchestrator.d.ts +103 -0
- package/dist/donation/__tests__/fake-orchestrator.js +180 -0
- package/dist/donation/__tests__/fake-orchestrator.js.map +1 -0
- package/dist/donation/donation-service.d.ts +361 -0
- package/dist/donation/donation-service.js +763 -0
- package/dist/donation/donation-service.js.map +1 -0
- package/dist/donation/donation-store.d.ts +49 -0
- package/dist/donation/donation-store.js +148 -0
- package/dist/donation/donation-store.js.map +1 -0
- package/dist/donation/donation-supervisor.d.ts +167 -0
- package/dist/donation/donation-supervisor.js +341 -0
- package/dist/donation/donation-supervisor.js.map +1 -0
- package/dist/donation/grant-service.d.ts +71 -0
- package/dist/donation/grant-service.js +163 -0
- package/dist/donation/grant-service.js.map +1 -0
- package/dist/donation/grant-store.d.ts +38 -0
- package/dist/donation/grant-store.js +135 -0
- package/dist/donation/grant-store.js.map +1 -0
- package/dist/donation/index.d.ts +20 -0
- package/dist/donation/index.js +17 -0
- package/dist/donation/index.js.map +1 -0
- package/dist/donation/types.d.ts +201 -0
- package/dist/donation/types.js +40 -0
- package/dist/donation/types.js.map +1 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/installer/config.d.ts +26 -0
- package/dist/installer/config.js +13 -0
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/index.d.ts +2 -0
- package/dist/installer/index.js +3 -0
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/wizard.d.ts +4 -0
- package/dist/installer/wizard.js +5 -1
- package/dist/installer/wizard.js.map +1 -1
- package/dist/nat/nat-service.d.ts +5 -5
- package/dist/nat/nat-service.js +9 -9
- package/dist/nat/nat-service.js.map +1 -1
- package/dist/nat/types.d.ts +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +144 -32
- package/dist/orchestrator/host-process-orchestrator.js +397 -128
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/orchestrator/index.d.ts +3 -3
- package/dist/orchestrator/index.js +1 -1
- package/dist/orchestrator/index.js.map +1 -1
- package/dist/orchestrator/node-identity.d.ts +26 -0
- package/dist/orchestrator/node-identity.js +36 -0
- package/dist/orchestrator/node-identity.js.map +1 -0
- package/dist/orchestrator/port-allocator.d.ts +14 -0
- package/dist/orchestrator/port-allocator.js +45 -0
- package/dist/orchestrator/port-allocator.js.map +1 -1
- package/dist/orchestrator/state-store.d.ts +5 -5
- package/dist/orchestrator/state-store.js +2 -2
- package/dist/orchestrator/state-store.js.map +1 -1
- package/dist/orchestrator/types.d.ts +8 -8
- package/dist/owner/index.d.ts +11 -0
- package/dist/owner/index.js +11 -0
- package/dist/owner/index.js.map +1 -0
- package/dist/owner/owner-node-client.d.ts +110 -0
- package/dist/{authority/authority-node-client.js → owner/owner-node-client.js} +58 -17
- package/dist/owner/owner-node-client.js.map +1 -0
- package/dist/server/error-handler.d.ts +22 -1
- package/dist/server/error-handler.js +64 -1
- package/dist/server/error-handler.js.map +1 -1
- package/dist/server/events/types.d.ts +3 -0
- package/dist/server/index.d.ts +33 -2
- package/dist/server/index.js +43 -16
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes/grants-admin.d.ts +17 -0
- package/dist/server/routes/grants-admin.js +32 -0
- package/dist/server/routes/grants-admin.js.map +1 -0
- package/dist/server/routes/grants.d.ts +28 -0
- package/dist/server/routes/grants.js +182 -0
- package/dist/server/routes/grants.js.map +1 -0
- package/dist/server/routes/nodes.d.ts +5 -4
- package/dist/server/routes/nodes.js +19 -18
- package/dist/server/routes/nodes.js.map +1 -1
- package/dist/server/routes/settings.d.ts +6 -1
- package/dist/server/routes/settings.js +5 -2
- package/dist/server/routes/settings.js.map +1 -1
- package/dist/server/routes/status.d.ts +8 -4
- package/dist/server/routes/status.js +9 -4
- package/dist/server/routes/status.js.map +1 -1
- package/dist/server/routes/strands.d.ts +20 -0
- package/dist/server/routes/strands.js +38 -0
- package/dist/server/routes/strands.js.map +1 -0
- package/dist/strands/index.d.ts +7 -0
- package/dist/strands/index.js +6 -0
- package/dist/strands/index.js.map +1 -0
- package/dist/strands/strand-service.d.ts +50 -0
- package/dist/strands/strand-service.js +103 -0
- package/dist/strands/strand-service.js.map +1 -0
- package/dist/strands/types.d.ts +93 -0
- package/dist/strands/types.js +23 -0
- package/dist/strands/types.js.map +1 -0
- package/dist/ui/assets/index-BVoqLjyX.css +1 -0
- package/dist/ui/assets/index-C-iks41M.js +17 -0
- package/dist/ui/assets/index-C-iks41M.js.map +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/update/release-key.d.ts +1 -1
- package/dist/update/release-key.js +8 -6
- package/dist/update/release-key.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/build-targets.test.ts +26 -0
- package/src/__tests__/global-setup.ts +51 -0
- package/src/__tests__/{host-authority.smoke.test.ts → host-owner.smoke.test.ts} +7 -7
- package/src/__tests__/orchestrator-env-scrub.test.ts +140 -0
- package/src/__tests__/orchestrator-node-identity.test.ts +204 -0
- package/src/__tests__/{orchestrator-authority.test.ts → orchestrator-owner.test.ts} +33 -33
- package/src/__tests__/orchestrator-pin-keys.test.ts +153 -0
- package/src/__tests__/orchestrator-push.test.ts +10 -10
- package/src/__tests__/orchestrator.test.ts +387 -6
- package/src/auth/__tests__/self-label.test.ts +85 -0
- package/src/auth/__tests__/trust-circle-integration.test.ts +152 -147
- package/src/auth/__tests__/trust-circle.test.ts +55 -11
- package/src/auth/index.ts +2 -0
- package/src/auth/self-label.ts +74 -0
- package/src/auth/trust-circle.ts +54 -22
- package/src/auth/types.ts +2 -2
- package/src/bin/host.ts +1299 -1038
- package/src/donation/__tests__/donation-service.test.ts +1068 -0
- package/src/donation/__tests__/donation-supervisor.test.ts +510 -0
- package/src/donation/__tests__/fake-orchestrator.test.ts +168 -0
- package/src/donation/__tests__/fake-orchestrator.ts +225 -0
- package/src/donation/__tests__/grant-service.test.ts +213 -0
- package/src/donation/__tests__/grant-store.test.ts +113 -0
- package/src/donation/donation-service.ts +962 -0
- package/src/donation/donation-store.ts +171 -0
- package/src/donation/donation-supervisor.ts +388 -0
- package/src/donation/grant-service.ts +200 -0
- package/src/donation/grant-store.ts +152 -0
- package/src/donation/index.ts +64 -0
- package/src/donation/types.ts +243 -0
- package/src/index.ts +51 -5
- package/src/installer/__tests__/config.test.ts +27 -1
- package/src/installer/__tests__/installer.smoke.test.ts +31 -1
- package/src/installer/__tests__/wizard.test.ts +5 -1
- package/src/installer/config.ts +34 -0
- package/src/installer/index.ts +5 -0
- package/src/installer/wizard.ts +12 -1
- package/src/nat/__tests__/nat-service.test.ts +5 -5
- package/src/nat/nat-service.ts +10 -10
- package/src/nat/types.ts +1 -1
- package/src/orchestrator/__tests__/node-identity.test.ts +62 -0
- package/src/orchestrator/host-process-orchestrator.ts +401 -134
- package/src/orchestrator/index.ts +3 -3
- package/src/orchestrator/node-identity.ts +40 -0
- package/src/orchestrator/port-allocator.ts +48 -0
- package/src/orchestrator/state-store.ts +7 -7
- package/src/orchestrator/types.ts +8 -8
- package/src/{authority/__tests__/authority-node-client.test.ts → owner/__tests__/owner-node-client.test.ts} +45 -17
- package/src/owner/index.ts +12 -0
- package/src/{authority/authority-node-client.ts → owner/owner-node-client.ts} +83 -23
- package/src/server/__tests__/error-handler.test.ts +22 -0
- package/src/server/__tests__/grants-admin-route.test.ts +73 -0
- package/src/server/__tests__/grants-route.test.ts +263 -0
- package/src/server/__tests__/nodes-route.test.ts +25 -25
- package/src/server/__tests__/server.smoke.test.ts +75 -0
- package/src/server/__tests__/settings-route.test.ts +17 -0
- package/src/server/__tests__/status-route.test.ts +21 -0
- package/src/server/__tests__/strands-route.test.ts +233 -0
- package/src/server/error-handler.ts +67 -1
- package/src/server/events/types.ts +1 -0
- package/src/server/index.ts +75 -17
- package/src/server/routes/grants-admin.ts +41 -0
- package/src/server/routes/grants.ts +210 -0
- package/src/server/routes/nodes.ts +19 -18
- package/src/server/routes/settings.ts +11 -3
- package/src/server/routes/status.ts +18 -8
- package/src/server/routes/strands.ts +54 -0
- package/src/strands/__tests__/strand-service.test.ts +165 -0
- package/src/strands/index.ts +14 -0
- package/src/strands/strand-service.ts +135 -0
- package/src/strands/types.ts +102 -0
- package/src/update/__tests__/release-key.test.ts +16 -3
- package/src/update/release-key.ts +8 -6
- package/dist/authority/authority-node-client.d.ts +0 -77
- package/dist/authority/authority-node-client.js.map +0 -1
- package/dist/authority/index.d.ts +0 -11
- package/dist/authority/index.js +0 -11
- package/dist/authority/index.js.map +0 -1
- package/dist/ui/assets/index-BlMXQPSw.js +0 -14
- package/dist/ui/assets/index-BlMXQPSw.js.map +0 -1
- package/dist/ui/assets/index-BwU5mJGF.css +0 -1
- package/src/authority/index.ts +0 -12
package/src/auth/trust-circle.ts
CHANGED
|
@@ -3,7 +3,7 @@ import debug from 'debug';
|
|
|
3
3
|
|
|
4
4
|
import type { CadreInvite } from '@serfab/cadre-core';
|
|
5
5
|
|
|
6
|
-
import {
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
|
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).
|
|
246
|
-
*
|
|
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
|
|
283
|
+
let authorizedMembers: Array<{ peerId: string }> | null;
|
|
260
284
|
try {
|
|
261
|
-
|
|
285
|
+
authorizedMembers = await this.cadreNode.listAuthorizedMembers();
|
|
262
286
|
} catch (err) {
|
|
263
|
-
if (!(err instanceof
|
|
264
|
-
|
|
287
|
+
if (!(err instanceof OwnerNodeUnavailableError)) throw err;
|
|
288
|
+
authorizedMembers = null;
|
|
265
289
|
}
|
|
266
290
|
|
|
267
|
-
if (
|
|
291
|
+
if (authorizedMembers) {
|
|
268
292
|
const seenPeerIds = new Set<string>();
|
|
269
|
-
for (const { peerId } of
|
|
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
|
-
//
|
|
280
|
-
//
|
|
281
|
-
|
|
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
|
|
310
|
-
throw new TrustCircleError('node_unavailable', `
|
|
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 (
|
|
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
|
|
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. */
|