@serfab/cadre-host 1.13.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 +347 -423
- package/dist/bin/host.d.ts +6 -3
- package/dist/bin/host.js +332 -524
- package/dist/bin/host.js.map +1 -1
- package/dist/bin/join-output.d.ts +56 -0
- package/dist/bin/join-output.js +92 -0
- package/dist/bin/join-output.js.map +1 -0
- package/dist/bin/nat-output.d.ts +54 -0
- package/dist/bin/nat-output.js +138 -0
- package/dist/bin/nat-output.js.map +1 -0
- 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 +66 -0
- package/dist/hosted/claim-details.js +60 -0
- package/dist/hosted/claim-details.js.map +1 -0
- package/dist/hosted/hosted-node-service.d.ts +325 -0
- package/dist/hosted/hosted-node-service.js +678 -0
- package/dist/hosted/hosted-node-service.js.map +1 -0
- package/dist/hosted/hosted-node-store.d.ts +40 -0
- package/dist/hosted/hosted-node-store.js +126 -0
- package/dist/hosted/hosted-node-store.js.map +1 -0
- package/dist/{donation/donation-supervisor.d.ts → hosted/hosted-node-supervisor.d.ts} +70 -53
- package/dist/hosted/hosted-node-supervisor.js +396 -0
- package/dist/hosted/hosted-node-supervisor.js.map +1 -0
- package/dist/hosted/hosted-node-watcher.d.ts +95 -0
- package/dist/hosted/hosted-node-watcher.js +260 -0
- package/dist/hosted/hosted-node-watcher.js.map +1 -0
- package/dist/hosted/index.d.ts +16 -0
- package/dist/hosted/index.js +13 -0
- package/dist/hosted/index.js.map +1 -0
- package/dist/hosted/node-status.d.ts +51 -0
- package/dist/hosted/node-status.js +77 -0
- package/dist/hosted/node-status.js.map +1 -0
- package/dist/hosted/types.d.ts +141 -0
- package/dist/hosted/types.js +22 -0
- package/dist/hosted/types.js.map +1 -0
- package/dist/index.d.ts +12 -24
- package/dist/index.js +9 -19
- package/dist/index.js.map +1 -1
- package/dist/installer/config.d.ts +27 -34
- package/dist/installer/config.js +46 -15
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/index.d.ts +9 -19
- package/dist/installer/index.js +21 -85
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/paths.d.ts +0 -2
- package/dist/installer/paths.js +0 -4
- package/dist/installer/paths.js.map +1 -1
- package/dist/installer/wizard.d.ts +12 -9
- package/dist/installer/wizard.js +15 -14
- package/dist/installer/wizard.js.map +1 -1
- package/dist/nat/address-resolver.d.ts +18 -17
- package/dist/nat/address-resolver.js +79 -25
- package/dist/nat/address-resolver.js.map +1 -1
- package/dist/nat/address-watch.d.ts +37 -0
- package/dist/nat/address-watch.js +84 -0
- package/dist/nat/address-watch.js.map +1 -0
- package/dist/nat/ddns/duckdns.d.ts +2 -1
- package/dist/nat/ddns/duckdns.js +5 -1
- package/dist/nat/ddns/duckdns.js.map +1 -1
- package/dist/nat/ddns/index.d.ts +6 -0
- package/dist/nat/ddns/index.js.map +1 -1
- package/dist/nat/index.d.ts +13 -9
- package/dist/nat/index.js +7 -5
- package/dist/nat/index.js.map +1 -1
- package/dist/nat/nat-service.d.ts +220 -77
- package/dist/nat/nat-service.js +653 -239
- package/dist/nat/nat-service.js.map +1 -1
- package/dist/nat/nat-store.d.ts +12 -5
- package/dist/nat/nat-store.js +124 -29
- 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/port-mapper.d.ts +83 -79
- package/dist/nat/port-mapper.js +148 -189
- package/dist/nat/port-mapper.js.map +1 -1
- package/dist/nat/reachability.d.ts +32 -15
- package/dist/nat/reachability.js +110 -22
- package/dist/nat/reachability.js.map +1 -1
- package/dist/nat/types.d.ts +98 -27
- package/dist/nat/types.js +8 -5
- package/dist/nat/types.js.map +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +32 -74
- package/dist/orchestrator/host-process-orchestrator.js +84 -233
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/{installer/identity.d.ts → orchestrator/identity-file.d.ts} +5 -5
- package/dist/{installer/identity.js → orchestrator/identity-file.js} +6 -6
- package/dist/orchestrator/identity-file.js.map +1 -0
- package/dist/orchestrator/index.d.ts +2 -3
- package/dist/orchestrator/index.js +1 -1
- package/dist/orchestrator/index.js.map +1 -1
- package/dist/orchestrator/node-identity.d.ts +6 -6
- package/dist/orchestrator/node-identity.js +7 -7
- package/dist/orchestrator/node-identity.js.map +1 -1
- package/dist/orchestrator/port-allocator.d.ts +5 -6
- package/dist/orchestrator/port-allocator.js +9 -11
- package/dist/orchestrator/port-allocator.js.map +1 -1
- package/dist/orchestrator/state-store.d.ts +3 -5
- package/dist/orchestrator/state-store.js +2 -10
- package/dist/orchestrator/state-store.js.map +1 -1
- package/dist/orchestrator/types.d.ts +33 -22
- package/dist/orchestrator/types.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/error-handler.d.ts +5 -25
- package/dist/server/error-handler.js +11 -74
- package/dist/server/error-handler.js.map +1 -1
- package/dist/server/events/types.d.ts +7 -11
- package/dist/server/events/types.js +2 -1
- package/dist/server/events/types.js.map +1 -1
- package/dist/server/index.d.ts +11 -37
- package/dist/server/index.js +30 -48
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes/hosted-nodes.d.ts +28 -0
- package/dist/server/routes/hosted-nodes.js +68 -0
- package/dist/server/routes/hosted-nodes.js.map +1 -0
- package/dist/server/routes/nat.d.ts +4 -1
- package/dist/server/routes/nat.js +13 -2
- package/dist/server/routes/nat.js.map +1 -1
- package/dist/server/routes/nodes.d.ts +6 -20
- package/dist/server/routes/nodes.js +7 -86
- package/dist/server/routes/nodes.js.map +1 -1
- package/dist/server/routes/settings.d.ts +3 -7
- package/dist/server/routes/settings.js +18 -8
- package/dist/server/routes/settings.js.map +1 -1
- package/dist/server/routes/status.d.ts +2 -25
- package/dist/server/routes/status.js +3 -43
- package/dist/server/routes/status.js.map +1 -1
- package/dist/server/server.js +8 -8
- package/dist/server/settings-store.d.ts +2 -2
- package/dist/server/settings-store.js +2 -2
- package/dist/server/static.js +1 -2
- package/dist/server/static.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-Ccr2GjPT.js.map +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/update/index.d.ts +2 -2
- package/dist/update/index.js +2 -2
- package/dist/update/store.d.ts +1 -1
- package/dist/update/store.js +1 -1
- package/dist/update/types.d.ts +1 -1
- package/dist/update/types.js +1 -1
- package/package.json +5 -7
- package/src/__tests__/cli-nat.smoke.test.ts +219 -212
- package/src/__tests__/cli.smoke.test.ts +2 -2
- package/src/__tests__/global-setup.ts +2 -3
- package/src/__tests__/orchestrator-claim-secret.test.ts +111 -0
- package/src/__tests__/orchestrator-env-scrub.test.ts +160 -163
- package/src/__tests__/orchestrator-handle-contract.ts +134 -134
- package/src/__tests__/orchestrator-node-identity.test.ts +177 -203
- package/src/__tests__/orchestrator-ports.test.ts +124 -143
- package/src/__tests__/orchestrator-push.test.ts +138 -146
- package/src/__tests__/orchestrator.test.ts +1017 -1063
- package/src/__tests__/ui-access.test.ts +30 -0
- package/src/bin/host.ts +397 -572
- package/src/bin/join-output.ts +120 -0
- package/src/bin/nat-output.ts +188 -0
- package/src/bin/ui-access.ts +50 -0
- package/src/{donation → hosted}/__tests__/fake-orchestrator.test.ts +172 -173
- package/src/{donation → hosted}/__tests__/fake-orchestrator.ts +43 -23
- package/src/hosted/__tests__/hosted-node-service.test.ts +708 -0
- package/src/hosted/__tests__/hosted-node-supervisor.test.ts +475 -0
- package/src/hosted/__tests__/test-invitation.ts +33 -0
- package/src/hosted/claim-details.ts +103 -0
- package/src/hosted/hosted-node-service.ts +814 -0
- package/src/hosted/hosted-node-store.ts +144 -0
- package/src/hosted/hosted-node-supervisor.ts +439 -0
- package/src/hosted/hosted-node-watcher.ts +288 -0
- package/src/hosted/index.ts +53 -0
- package/src/hosted/node-status.ts +97 -0
- package/src/hosted/types.ts +160 -0
- package/src/index.ts +72 -91
- package/src/installer/__tests__/config.test.ts +15 -40
- package/src/installer/__tests__/installer.smoke.test.ts +184 -263
- package/src/installer/__tests__/wizard.test.ts +25 -13
- package/src/installer/config.ts +201 -175
- package/src/installer/index.ts +252 -327
- package/src/installer/paths.ts +104 -109
- package/src/installer/wizard.ts +24 -26
- package/src/nat/__tests__/address-resolver.test.ts +107 -82
- package/src/nat/__tests__/nat-service.test.ts +608 -515
- package/src/nat/__tests__/nat-store.test.ts +49 -12
- package/src/nat/__tests__/network-mode.test.ts +38 -0
- package/src/nat/__tests__/port-mapper.test.ts +30 -191
- package/src/nat/__tests__/reachability.test.ts +96 -13
- package/src/nat/address-resolver.ts +94 -52
- package/src/nat/address-watch.ts +92 -0
- package/src/nat/ddns/duckdns.ts +5 -1
- package/src/nat/ddns/index.ts +6 -0
- package/src/nat/index.ts +33 -13
- package/src/nat/nat-service.ts +942 -501
- package/src/nat/nat-store.ts +126 -31
- package/src/nat/network-mode.ts +36 -0
- package/src/nat/port-mapper.ts +241 -329
- package/src/nat/reachability.ts +155 -34
- package/src/nat/types.ts +110 -37
- package/src/{installer/__tests__/identity.test.ts → orchestrator/__tests__/identity-file.test.ts} +34 -34
- package/src/orchestrator/__tests__/node-identity.test.ts +62 -62
- package/src/orchestrator/host-process-orchestrator.ts +1089 -1260
- package/src/{installer/identity.ts → orchestrator/identity-file.ts} +56 -56
- package/src/orchestrator/index.ts +9 -10
- package/src/orchestrator/node-identity.ts +41 -41
- package/src/orchestrator/port-allocator.ts +71 -73
- package/src/orchestrator/state-store.ts +76 -90
- package/src/orchestrator/types.ts +34 -23
- package/src/package-version.ts +4 -0
- package/src/server/__tests__/bus.test.ts +38 -38
- package/src/server/__tests__/error-handler.test.ts +81 -118
- package/src/server/__tests__/fakes.ts +15 -18
- package/src/server/__tests__/hosted-nodes-route.test.ts +161 -0
- package/src/server/__tests__/nodes-route.test.ts +114 -283
- package/src/server/__tests__/publishers.test.ts +193 -180
- package/src/server/__tests__/server.smoke.test.ts +134 -223
- package/src/server/__tests__/settings-route.test.ts +210 -195
- package/src/server/__tests__/sse-route.test.ts +119 -119
- package/src/server/__tests__/status-route.test.ts +82 -121
- package/src/server/error-handler.ts +112 -178
- package/src/server/events/types.ts +20 -24
- package/src/server/index.ts +223 -267
- package/src/server/routes/hosted-nodes.ts +83 -0
- package/src/server/routes/nat.ts +75 -63
- package/src/server/routes/nodes.ts +96 -188
- package/src/server/routes/settings.ts +20 -15
- package/src/server/routes/status.ts +5 -67
- package/src/server/server.ts +8 -8
- package/src/server/settings-store.ts +2 -2
- package/src/server/static.ts +1 -2
- package/src/update/index.ts +2 -2
- package/src/update/store.ts +1 -1
- package/src/update/types.ts +1 -1
- package/dist/auth/duration.d.ts +0 -1
- package/dist/auth/duration.js +0 -32
- package/dist/auth/duration.js.map +0 -1
- package/dist/auth/index.d.ts +0 -11
- package/dist/auth/index.js +0 -9
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/self-label.d.ts +0 -36
- package/dist/auth/self-label.js +0 -57
- package/dist/auth/self-label.js.map +0 -1
- package/dist/auth/trust-circle-store.d.ts +0 -26
- package/dist/auth/trust-circle-store.js +0 -129
- package/dist/auth/trust-circle-store.js.map +0 -1
- package/dist/auth/trust-circle.d.ts +0 -156
- package/dist/auth/trust-circle.js +0 -307
- package/dist/auth/trust-circle.js.map +0 -1
- package/dist/auth/types.d.ts +0 -84
- package/dist/auth/types.js +0 -24
- package/dist/auth/types.js.map +0 -1
- package/dist/donation/donation-service.d.ts +0 -389
- package/dist/donation/donation-service.js +0 -828
- package/dist/donation/donation-service.js.map +0 -1
- package/dist/donation/donation-store.d.ts +0 -51
- package/dist/donation/donation-store.js +0 -152
- package/dist/donation/donation-store.js.map +0 -1
- package/dist/donation/donation-supervisor.js +0 -364
- package/dist/donation/donation-supervisor.js.map +0 -1
- package/dist/donation/grant-service.d.ts +0 -80
- package/dist/donation/grant-service.js +0 -210
- package/dist/donation/grant-service.js.map +0 -1
- package/dist/donation/grant-store.d.ts +0 -38
- package/dist/donation/grant-store.js +0 -135
- package/dist/donation/grant-store.js.map +0 -1
- package/dist/donation/index.d.ts +0 -20
- package/dist/donation/index.js +0 -17
- package/dist/donation/index.js.map +0 -1
- package/dist/donation/types.d.ts +0 -224
- package/dist/donation/types.js +0 -40
- package/dist/donation/types.js.map +0 -1
- package/dist/installer/identity.js.map +0 -1
- package/dist/owner/index.d.ts +0 -11
- package/dist/owner/index.js +0 -11
- package/dist/owner/index.js.map +0 -1
- package/dist/owner/owner-node-client.d.ts +0 -110
- package/dist/owner/owner-node-client.js +0 -184
- package/dist/owner/owner-node-client.js.map +0 -1
- package/dist/server/routes/bootstrap-node-validation.d.ts +0 -115
- package/dist/server/routes/bootstrap-node-validation.js +0 -197
- package/dist/server/routes/bootstrap-node-validation.js.map +0 -1
- package/dist/server/routes/grants-admin.d.ts +0 -29
- package/dist/server/routes/grants-admin.js +0 -58
- package/dist/server/routes/grants-admin.js.map +0 -1
- package/dist/server/routes/grants.d.ts +0 -28
- package/dist/server/routes/grants.js +0 -165
- package/dist/server/routes/grants.js.map +0 -1
- package/dist/server/routes/provision-request-validation.d.ts +0 -45
- package/dist/server/routes/provision-request-validation.js +0 -97
- package/dist/server/routes/provision-request-validation.js.map +0 -1
- package/dist/server/routes/strands.d.ts +0 -20
- package/dist/server/routes/strands.js +0 -38
- package/dist/server/routes/strands.js.map +0 -1
- package/dist/server/routes/trust-circle.d.ts +0 -17
- package/dist/server/routes/trust-circle.js +0 -35
- package/dist/server/routes/trust-circle.js.map +0 -1
- package/dist/strands/index.d.ts +0 -7
- package/dist/strands/index.js +0 -6
- package/dist/strands/index.js.map +0 -1
- package/dist/strands/strand-service.d.ts +0 -50
- package/dist/strands/strand-service.js +0 -103
- package/dist/strands/strand-service.js.map +0 -1
- package/dist/strands/types.d.ts +0 -93
- package/dist/strands/types.js +0 -23
- package/dist/strands/types.js.map +0 -1
- package/dist/ui/assets/index-C6nELNfC.js +0 -23
- package/dist/ui/assets/index-C6nELNfC.js.map +0 -1
- package/dist/ui/assets/index-TtIYSeZO.css +0 -1
- package/src/__tests__/cli-invite.smoke.test.ts +0 -192
- package/src/__tests__/host-owner.smoke.test.ts +0 -123
- package/src/__tests__/orchestrator-owner.test.ts +0 -234
- package/src/__tests__/orchestrator-pin-keys.test.ts +0 -152
- package/src/auth/__tests__/duration.test.ts +0 -28
- package/src/auth/__tests__/self-label.test.ts +0 -85
- package/src/auth/__tests__/trust-circle-integration.test.ts +0 -152
- package/src/auth/__tests__/trust-circle-store.test.ts +0 -115
- package/src/auth/__tests__/trust-circle.test.ts +0 -445
- package/src/auth/duration.ts +0 -33
- package/src/auth/index.ts +0 -21
- package/src/auth/self-label.ts +0 -74
- package/src/auth/trust-circle-store.ts +0 -155
- package/src/auth/trust-circle.ts +0 -395
- package/src/auth/types.ts +0 -99
- package/src/donation/__tests__/donation-service.test.ts +0 -1193
- package/src/donation/__tests__/donation-supervisor.test.ts +0 -548
- package/src/donation/__tests__/grant-service.test.ts +0 -213
- package/src/donation/__tests__/grant-store.test.ts +0 -113
- package/src/donation/donation-service.ts +0 -1033
- package/src/donation/donation-store.ts +0 -176
- package/src/donation/donation-supervisor.ts +0 -411
- package/src/donation/grant-service.ts +0 -252
- package/src/donation/grant-store.ts +0 -152
- package/src/donation/index.ts +0 -65
- package/src/donation/types.ts +0 -260
- package/src/owner/__tests__/owner-node-client.test.ts +0 -194
- package/src/owner/index.ts +0 -12
- package/src/owner/owner-node-client.ts +0 -259
- package/src/server/__tests__/bootstrap-node-validation.test.ts +0 -138
- package/src/server/__tests__/grants-admin-route.test.ts +0 -171
- package/src/server/__tests__/grants-route.test.ts +0 -394
- package/src/server/__tests__/strands-route.test.ts +0 -234
- package/src/server/routes/bootstrap-node-validation.ts +0 -206
- package/src/server/routes/grants-admin.ts +0 -74
- package/src/server/routes/grants.ts +0 -193
- package/src/server/routes/provision-request-validation.ts +0 -105
- package/src/server/routes/strands.ts +0 -54
- package/src/server/routes/trust-circle.ts +0 -49
- package/src/strands/__tests__/strand-service.test.ts +0 -165
- package/src/strands/index.ts +0 -14
- package/src/strands/strand-service.ts +0 -135
- package/src/strands/types.ts +0 -102
package/src/server/server.ts
CHANGED
|
@@ -124,14 +124,14 @@ export function buildFastify(): FastifyInstance {
|
|
|
124
124
|
* request with no body (`request.body === undefined`), instead of Fastify's
|
|
125
125
|
* default `400 FST_ERR_CTP_EMPTY_JSON_BODY`.
|
|
126
126
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* and the prototype-poisoning checks are unchanged (`'error'` is Fastify's
|
|
134
|
-
* for both).
|
|
127
|
+
* Sending the JSON content type on every request, body or not, is a common
|
|
128
|
+
* client habit (`POST /api/hosted-nodes` takes no body today, and a body-less
|
|
129
|
+
* `DELETE` is the norm), and a refused request here is a node left running.
|
|
130
|
+
* Every route that reads a body already reads `request.body ?? {}`, so a route
|
|
131
|
+
* that needs a field still answers its own `invalid_request` naming it. A
|
|
132
|
+
* non-empty body goes to Fastify's own parser, so malformed JSON is still a 400
|
|
133
|
+
* and the prototype-poisoning checks are unchanged (`'error'` is Fastify's
|
|
134
|
+
* default for both).
|
|
135
135
|
*/
|
|
136
136
|
function acceptEmptyJsonBodies(app: FastifyInstance): void {
|
|
137
137
|
// NOTE: 'error', 'error' mirrors Fastify's defaults for proto/constructor poisoning; if
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Settings store — read-write facade around `host.config.json` for the
|
|
3
3
|
* /api/settings route.
|
|
4
4
|
*
|
|
5
|
-
* The installer (`6.4.1`) owns the schema (`HostConfigFile`
|
|
5
|
+
* The installer (`6.4.1`) owns the schema (`HostConfigFile` v3). This module
|
|
6
6
|
* just delegates load/persist to that file's helpers; it exists so route
|
|
7
7
|
* handlers can read/write without each one re-resolving `configPath(dataDir)`.
|
|
8
8
|
*
|
|
@@ -29,7 +29,7 @@ export class HostSettingsStore {
|
|
|
29
29
|
// /api/settings answers 500 code "internal" with the read message passed through.
|
|
30
30
|
// Fine while the UI just surfaces the text; if it ever needs to tell "your config
|
|
31
31
|
// file is unreadable" apart from a genuine server bug, give this a typed error.
|
|
32
|
-
/** Read the current host.config.json. Throws if absent, malformed, or not version
|
|
32
|
+
/** Read the current host.config.json. Throws if absent, malformed, or not version 3. */
|
|
33
33
|
read(): HostConfigFile {
|
|
34
34
|
return readHostConfig(this.configPath);
|
|
35
35
|
}
|
package/src/server/static.ts
CHANGED
|
@@ -65,7 +65,6 @@ export function registerStaticMount(app: FastifyInstance, opts: StaticMountOptio
|
|
|
65
65
|
// Don't try to serve API paths as static.
|
|
66
66
|
if (
|
|
67
67
|
request.url.startsWith('/api') ||
|
|
68
|
-
request.url.startsWith('/auth') ||
|
|
69
68
|
request.url.startsWith('/nat') ||
|
|
70
69
|
request.url.startsWith('/update')
|
|
71
70
|
) {
|
|
@@ -198,7 +197,7 @@ function placeholderHtml(): string {
|
|
|
198
197
|
<li><span class="endpoint">GET /api/nodes</span></li>
|
|
199
198
|
<li><span class="endpoint">GET /api/settings</span></li>
|
|
200
199
|
<li><span class="endpoint">GET /api/events</span> (Server-Sent Events)</li>
|
|
201
|
-
<li><span class="endpoint">/
|
|
200
|
+
<li><span class="endpoint">/nat/*</span>, <span class="endpoint">/update/*</span></li>
|
|
202
201
|
</ul>
|
|
203
202
|
<p>See <a href="https://github.com/gotchoices/sereus/blob/master/docs/cadre-host.md">docs/cadre-host.md</a>.</p>
|
|
204
203
|
</body>
|
package/src/update/index.ts
CHANGED
|
@@ -305,8 +305,8 @@ export class UpdateService {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
/**
|
|
308
|
-
* Typed handler facade —
|
|
309
|
-
*
|
|
308
|
+
* Typed handler facade — same shape as `createNatHandlers`. The local-UI
|
|
309
|
+
* server consumes these.
|
|
310
310
|
*/
|
|
311
311
|
export function createUpdateHandlers(service: UpdateService): UpdateHandlers {
|
|
312
312
|
return {
|
package/src/update/store.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Atomic JSON store for `<dataDir>/update-state.json`.
|
|
3
3
|
*
|
|
4
|
-
* Mirrors `
|
|
4
|
+
* Mirrors `NatStore`: load on demand, write to
|
|
5
5
|
* `<path>.tmp` then rename. Single-writer assumption — only one cadre-host
|
|
6
6
|
* process owns a given dataDir.
|
|
7
7
|
*/
|
package/src/update/types.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - apply.ts — invoke `npm install -g` + rollback on failure.
|
|
9
9
|
* - index.ts — composes the above (UpdateService).
|
|
10
10
|
*
|
|
11
|
-
* Mirrors the typed-handler pattern used by
|
|
11
|
+
* Mirrors the typed-handler pattern used by NAT (handlers
|
|
12
12
|
* throw `UpdateError` whose `.code` the local-UI maps to HTTP status).
|
|
13
13
|
*/
|
|
14
14
|
|
package/dist/auth/duration.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function parseDuration(input: string): number;
|
package/dist/auth/duration.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tiny duration parser for invite TTLs.
|
|
3
|
-
*
|
|
4
|
-
* Accepts a single value+unit token: `30s`, `5m`, `24h`, `7d`, `2w`.
|
|
5
|
-
* Whitespace is allowed around it. Bare numbers are treated as milliseconds.
|
|
6
|
-
*
|
|
7
|
-
* Returns the duration in milliseconds. Throws on unparseable input.
|
|
8
|
-
*/
|
|
9
|
-
const UNIT_MULTIPLIERS = {
|
|
10
|
-
ms: 1,
|
|
11
|
-
s: 1000,
|
|
12
|
-
m: 60 * 1000,
|
|
13
|
-
h: 60 * 60 * 1000,
|
|
14
|
-
d: 24 * 60 * 60 * 1000,
|
|
15
|
-
w: 7 * 24 * 60 * 60 * 1000,
|
|
16
|
-
};
|
|
17
|
-
const DURATION_RE = /^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d|w)?$/;
|
|
18
|
-
export function parseDuration(input) {
|
|
19
|
-
const trimmed = input.trim();
|
|
20
|
-
const match = DURATION_RE.exec(trimmed);
|
|
21
|
-
if (!match) {
|
|
22
|
-
throw new Error(`Invalid duration: ${JSON.stringify(input)} (expected e.g. "24h", "7d", "30m")`);
|
|
23
|
-
}
|
|
24
|
-
const value = parseFloat(match[1]);
|
|
25
|
-
const unit = match[2] ?? 'ms';
|
|
26
|
-
const multiplier = UNIT_MULTIPLIERS[unit];
|
|
27
|
-
if (multiplier === undefined) {
|
|
28
|
-
throw new Error(`Unknown duration unit: ${unit}`);
|
|
29
|
-
}
|
|
30
|
-
return Math.round(value * multiplier);
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=duration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../src/auth/duration.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,EAAE,EAAE,CAAC;IACL,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,EAAE,GAAG,IAAI;IACZ,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACjB,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACtB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;CAC3B,CAAC;AAEF,MAAM,WAAW,GAAG,qCAAqC,CAAC;AAE1D,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACnG,CAAC;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC9B,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/auth/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Trust-circle auth for cadre-host. See ./trust-circle.ts and ./types.ts.
|
|
3
|
-
*/
|
|
4
|
-
export { TrustCircleService, createTrustCircleHandlers, DEFAULT_INVITE_TTL_MS } from './trust-circle.js';
|
|
5
|
-
export type { TrustCircleServiceOptions, CadreNodeLike } from './trust-circle.js';
|
|
6
|
-
export { TrustCircleStore } from './trust-circle-store.js';
|
|
7
|
-
export { ensureSelfLabel, SELF_LABEL } from './self-label.js';
|
|
8
|
-
export type { EnsureSelfLabelOptions } from './self-label.js';
|
|
9
|
-
export { parseDuration } from './duration.js';
|
|
10
|
-
export { TrustCircleError, } from './types.js';
|
|
11
|
-
export type { TrustCircleMember, PendingInvite, TrustCircleFile, TrustCircleSnapshot, TrustCircleHandlers, TrustCircleErrorCode, } from './types.js';
|
package/dist/auth/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Trust-circle auth for cadre-host. See ./trust-circle.ts and ./types.ts.
|
|
3
|
-
*/
|
|
4
|
-
export { TrustCircleService, createTrustCircleHandlers, DEFAULT_INVITE_TTL_MS } from './trust-circle.js';
|
|
5
|
-
export { TrustCircleStore } from './trust-circle-store.js';
|
|
6
|
-
export { ensureSelfLabel, SELF_LABEL } from './self-label.js';
|
|
7
|
-
export { parseDuration } from './duration.js';
|
|
8
|
-
export { TrustCircleError, } from './types.js';
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/dist/auth/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAEzG,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EACL,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Self-labelling for the trust-circle listing.
|
|
3
|
-
*
|
|
4
|
-
* `TrustCircleService.list()` shows the cadre's *authorized* membership, which
|
|
5
|
-
* deliberately excludes the node's own self-published row — a node's own
|
|
6
|
-
* address record isn't something an owner key vouched for. To keep the owner's
|
|
7
|
-
* own device visible in the listing, cadre-host records a local
|
|
8
|
-
* `self: true` label for it and `list()` splices that row back in.
|
|
9
|
-
*
|
|
10
|
-
* Writing that label is this module's job. Kept out of `bin/host.ts` so it is
|
|
11
|
-
* unit-testable without standing up the CLI.
|
|
12
|
-
*/
|
|
13
|
-
import type { TrustCircleStore } from './trust-circle-store.js';
|
|
14
|
-
/** Label written for the owner's own device when none exists yet. */
|
|
15
|
-
export declare const SELF_LABEL = "This device";
|
|
16
|
-
export interface EnsureSelfLabelOptions {
|
|
17
|
-
/** Local labels store to write into. */
|
|
18
|
-
store: TrustCircleStore;
|
|
19
|
-
/** Resolves the owner node's peer ID; '' when the node isn't ready yet. */
|
|
20
|
-
getPeerId: () => Promise<string>;
|
|
21
|
-
/** Clock override for tests. */
|
|
22
|
-
now?: () => Date;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Record the owner node's own peer ID as a `self: true` local label.
|
|
26
|
-
*
|
|
27
|
-
* Idempotent: an existing row for that peer ID is left alone, so an admin's
|
|
28
|
-
* rename survives restarts. Stale `self` rows (a different peer ID — the node
|
|
29
|
-
* identity was replaced) are dropped, since `list()` splices every `self` row
|
|
30
|
-
* in unconditionally and would otherwise show a device that no longer exists.
|
|
31
|
-
*
|
|
32
|
-
* Returns the peer ID that is now labelled, or `undefined` when the node
|
|
33
|
-
* wasn't ready. Throws whatever `getPeerId` throws — callers treat a failure
|
|
34
|
-
* as best-effort (the next start heals it).
|
|
35
|
-
*/
|
|
36
|
-
export declare function ensureSelfLabel(opts: EnsureSelfLabelOptions): Promise<string | undefined>;
|
package/dist/auth/self-label.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Self-labelling for the trust-circle listing.
|
|
3
|
-
*
|
|
4
|
-
* `TrustCircleService.list()` shows the cadre's *authorized* membership, which
|
|
5
|
-
* deliberately excludes the node's own self-published row — a node's own
|
|
6
|
-
* address record isn't something an owner key vouched for. To keep the owner's
|
|
7
|
-
* own device visible in the listing, cadre-host records a local
|
|
8
|
-
* `self: true` label for it and `list()` splices that row back in.
|
|
9
|
-
*
|
|
10
|
-
* Writing that label is this module's job. Kept out of `bin/host.ts` so it is
|
|
11
|
-
* unit-testable without standing up the CLI.
|
|
12
|
-
*/
|
|
13
|
-
import debug from 'debug';
|
|
14
|
-
const log = debug('cadre:host:trust-circle-self');
|
|
15
|
-
/** Label written for the owner's own device when none exists yet. */
|
|
16
|
-
export const SELF_LABEL = 'This device';
|
|
17
|
-
/**
|
|
18
|
-
* Record the owner node's own peer ID as a `self: true` local label.
|
|
19
|
-
*
|
|
20
|
-
* Idempotent: an existing row for that peer ID is left alone, so an admin's
|
|
21
|
-
* rename survives restarts. Stale `self` rows (a different peer ID — the node
|
|
22
|
-
* identity was replaced) are dropped, since `list()` splices every `self` row
|
|
23
|
-
* in unconditionally and would otherwise show a device that no longer exists.
|
|
24
|
-
*
|
|
25
|
-
* Returns the peer ID that is now labelled, or `undefined` when the node
|
|
26
|
-
* wasn't ready. Throws whatever `getPeerId` throws — callers treat a failure
|
|
27
|
-
* as best-effort (the next start heals it).
|
|
28
|
-
*/
|
|
29
|
-
export async function ensureSelfLabel(opts) {
|
|
30
|
-
const { store, getPeerId } = opts;
|
|
31
|
-
const now = opts.now ?? (() => new Date());
|
|
32
|
-
const peerId = await getPeerId();
|
|
33
|
-
if (!peerId) {
|
|
34
|
-
log('owner node not ready — no self label written');
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
for (const member of store.listMembers()) {
|
|
38
|
-
if (member.self && member.peerId !== peerId) {
|
|
39
|
-
log('dropping stale self label for %s (current identity is %s)', member.peerId, peerId);
|
|
40
|
-
store.removeMember(member.peerId);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const existing = store.getMember(peerId);
|
|
44
|
-
if (!existing) {
|
|
45
|
-
store.addMember({ peerId, label: SELF_LABEL, addedAt: now().toISOString(), self: true });
|
|
46
|
-
log('labelled own device %s as "%s"', peerId, SELF_LABEL);
|
|
47
|
-
}
|
|
48
|
-
else if (!existing.self) {
|
|
49
|
-
// Row predates self-labelling (or was written by a redemption). Stamp the
|
|
50
|
-
// flag, keeping the label: without it `list()` prunes the row, since the
|
|
51
|
-
// authorized set never contains self.
|
|
52
|
-
store.addMember({ ...existing, self: true });
|
|
53
|
-
log('stamped existing label for own device %s as self', peerId);
|
|
54
|
-
}
|
|
55
|
-
return peerId;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=self-label.js.map
|
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AAC;QACzF,GAAG,CAAC,gCAAgC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC5D,CAAC;SAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC1B,0EAA0E;QAC1E,yEAAyE;QACzE,sCAAsC;QACtC,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7C,GAAG,CAAC,kDAAkD,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { PendingInvite, TrustCircleFile, TrustCircleMember } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Atomic JSON store for trust-circle.json. Mirrors the pattern in
|
|
4
|
-
* `orchestrator/state-store.ts`: write to `<path>.tmp`, then rename.
|
|
5
|
-
*
|
|
6
|
-
* Concurrency assumption: only one cadre-host process owns a given rootDir
|
|
7
|
-
* (the orchestrator already enforces this). No file-locking primitives.
|
|
8
|
-
*/
|
|
9
|
-
export declare class TrustCircleStore {
|
|
10
|
-
private readonly path;
|
|
11
|
-
private cache;
|
|
12
|
-
constructor(rootDir: string);
|
|
13
|
-
filePath(): string;
|
|
14
|
-
/** Load (with caching). A missing file returns an empty store. */
|
|
15
|
-
load(): TrustCircleFile;
|
|
16
|
-
/** Persist the current state atomically (write then rename). */
|
|
17
|
-
save(state: TrustCircleFile): void;
|
|
18
|
-
addMember(member: TrustCircleMember): void;
|
|
19
|
-
removeMember(peerId: string): boolean;
|
|
20
|
-
getMember(peerId: string): TrustCircleMember | undefined;
|
|
21
|
-
listMembers(): TrustCircleMember[];
|
|
22
|
-
addPending(invite: PendingInvite): void;
|
|
23
|
-
removePending(token: string): boolean;
|
|
24
|
-
getPending(token: string): PendingInvite | undefined;
|
|
25
|
-
listPending(): PendingInvite[];
|
|
26
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
import debug from 'debug';
|
|
4
|
-
import { TrustCircleError } from './types.js';
|
|
5
|
-
const log = debug('cadre:host:trust-circle-store');
|
|
6
|
-
const FILE_VERSION = 1;
|
|
7
|
-
/**
|
|
8
|
-
* Atomic JSON store for trust-circle.json. Mirrors the pattern in
|
|
9
|
-
* `orchestrator/state-store.ts`: write to `<path>.tmp`, then rename.
|
|
10
|
-
*
|
|
11
|
-
* Concurrency assumption: only one cadre-host process owns a given rootDir
|
|
12
|
-
* (the orchestrator already enforces this). No file-locking primitives.
|
|
13
|
-
*/
|
|
14
|
-
export class TrustCircleStore {
|
|
15
|
-
constructor(rootDir) {
|
|
16
|
-
this.cache = null;
|
|
17
|
-
mkdirSync(rootDir, { recursive: true });
|
|
18
|
-
this.path = join(rootDir, 'trust-circle.json');
|
|
19
|
-
}
|
|
20
|
-
filePath() {
|
|
21
|
-
return this.path;
|
|
22
|
-
}
|
|
23
|
-
/** Load (with caching). A missing file returns an empty store. */
|
|
24
|
-
load() {
|
|
25
|
-
if (this.cache)
|
|
26
|
-
return this.cache;
|
|
27
|
-
if (!existsSync(this.path)) {
|
|
28
|
-
this.cache = emptyFile();
|
|
29
|
-
return this.cache;
|
|
30
|
-
}
|
|
31
|
-
let raw;
|
|
32
|
-
try {
|
|
33
|
-
raw = readFileSync(this.path, 'utf8');
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
throw new TrustCircleError('storage_error', `failed to read trust-circle file at ${this.path}: ${err.message}`);
|
|
37
|
-
}
|
|
38
|
-
let parsed;
|
|
39
|
-
try {
|
|
40
|
-
parsed = JSON.parse(raw);
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
throw new TrustCircleError('storage_error', `trust-circle file at ${this.path} is not valid JSON: ${err.message}`);
|
|
44
|
-
}
|
|
45
|
-
if (!isTrustCircleFile(parsed)) {
|
|
46
|
-
throw new TrustCircleError('storage_error', `trust-circle file at ${this.path} has unexpected shape`);
|
|
47
|
-
}
|
|
48
|
-
this.cache = parsed;
|
|
49
|
-
return this.cache;
|
|
50
|
-
}
|
|
51
|
-
/** Persist the current state atomically (write then rename). */
|
|
52
|
-
save(state) {
|
|
53
|
-
mkdirSync(dirname(this.path), { recursive: true });
|
|
54
|
-
const payload = JSON.stringify({ ...state, version: FILE_VERSION }, null, 2);
|
|
55
|
-
const tmp = `${this.path}.tmp`;
|
|
56
|
-
writeFileSync(tmp, payload, { encoding: 'utf8' });
|
|
57
|
-
renameSync(tmp, this.path);
|
|
58
|
-
this.cache = { ...state, version: FILE_VERSION };
|
|
59
|
-
log('saved trust-circle (%d members, %d pending) to %s', Object.keys(state.members).length, Object.keys(state.pendingInvites).length, this.path);
|
|
60
|
-
}
|
|
61
|
-
// --- Member ops ---
|
|
62
|
-
addMember(member) {
|
|
63
|
-
const state = this.load();
|
|
64
|
-
const { peerId, ...rest } = member;
|
|
65
|
-
state.members[peerId] = rest;
|
|
66
|
-
this.save(state);
|
|
67
|
-
}
|
|
68
|
-
removeMember(peerId) {
|
|
69
|
-
const state = this.load();
|
|
70
|
-
if (!(peerId in state.members))
|
|
71
|
-
return false;
|
|
72
|
-
delete state.members[peerId];
|
|
73
|
-
this.save(state);
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
getMember(peerId) {
|
|
77
|
-
const state = this.load();
|
|
78
|
-
const row = state.members[peerId];
|
|
79
|
-
if (!row)
|
|
80
|
-
return undefined;
|
|
81
|
-
return { peerId, ...row };
|
|
82
|
-
}
|
|
83
|
-
listMembers() {
|
|
84
|
-
const state = this.load();
|
|
85
|
-
return Object.entries(state.members).map(([peerId, row]) => ({ peerId, ...row }));
|
|
86
|
-
}
|
|
87
|
-
// --- Pending invite ops ---
|
|
88
|
-
addPending(invite) {
|
|
89
|
-
const state = this.load();
|
|
90
|
-
const { token, ...rest } = invite;
|
|
91
|
-
state.pendingInvites[token] = rest;
|
|
92
|
-
this.save(state);
|
|
93
|
-
}
|
|
94
|
-
removePending(token) {
|
|
95
|
-
const state = this.load();
|
|
96
|
-
if (!(token in state.pendingInvites))
|
|
97
|
-
return false;
|
|
98
|
-
delete state.pendingInvites[token];
|
|
99
|
-
this.save(state);
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
getPending(token) {
|
|
103
|
-
const state = this.load();
|
|
104
|
-
const row = state.pendingInvites[token];
|
|
105
|
-
if (!row)
|
|
106
|
-
return undefined;
|
|
107
|
-
return { token, ...row };
|
|
108
|
-
}
|
|
109
|
-
listPending() {
|
|
110
|
-
const state = this.load();
|
|
111
|
-
return Object.entries(state.pendingInvites).map(([token, row]) => ({ token, ...row }));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function emptyFile() {
|
|
115
|
-
return { version: FILE_VERSION, members: {}, pendingInvites: {} };
|
|
116
|
-
}
|
|
117
|
-
function isTrustCircleFile(v) {
|
|
118
|
-
if (!v || typeof v !== 'object')
|
|
119
|
-
return false;
|
|
120
|
-
const obj = v;
|
|
121
|
-
if (obj.version !== FILE_VERSION)
|
|
122
|
-
return false;
|
|
123
|
-
if (!obj.members || typeof obj.members !== 'object')
|
|
124
|
-
return false;
|
|
125
|
-
if (!obj.pendingInvites || typeof obj.pendingInvites !== 'object')
|
|
126
|
-
return false;
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=trust-circle-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trust-circle-store.js","sourceRoot":"","sources":["../../src/auth/trust-circle-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,MAAM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,OAAO,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAClE,IAAI,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,GAAG,CAAC,cAAc,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAChF,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import type { CadreInvite } from '@serfab/cadre-core';
|
|
2
|
-
import type { TrustCircleStore } from './trust-circle-store.js';
|
|
3
|
-
import type { TrustCircleHandlers, TrustCircleSnapshot } from './types.js';
|
|
4
|
-
/** Default invite lifetime: 24 hours. */
|
|
5
|
-
export declare const DEFAULT_INVITE_TTL_MS: number;
|
|
6
|
-
/** Constructor options. */
|
|
7
|
-
export interface TrustCircleServiceOptions {
|
|
8
|
-
/** The host's cadre node — provides createInvite / acceptPhone / removePeer. */
|
|
9
|
-
cadreNode: CadreNodeLike;
|
|
10
|
-
/** Local labels + pending-invites store. */
|
|
11
|
-
store: TrustCircleStore;
|
|
12
|
-
/** Clock override for tests. */
|
|
13
|
-
now?: () => Date;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Minimal slice of CadreNode that the service uses. Defined as an interface
|
|
17
|
-
* (rather than reaching into CadreNode directly) so unit tests can inject
|
|
18
|
-
* a mock without standing up a real libp2p node.
|
|
19
|
-
*/
|
|
20
|
-
export interface CadreNodeLike {
|
|
21
|
-
createInvite(token?: string, expiresIn?: number): Promise<{
|
|
22
|
-
invite: CadreInvite;
|
|
23
|
-
encodedInvite: string;
|
|
24
|
-
}>;
|
|
25
|
-
acceptPhone(options: {
|
|
26
|
-
phonePeerId: string;
|
|
27
|
-
token?: string;
|
|
28
|
-
}, issuedInvite?: CadreInvite): Promise<void>;
|
|
29
|
-
removePeer(peerId: string): Promise<void>;
|
|
30
|
-
encodeInvite(invite: CadreInvite): string;
|
|
31
|
-
/**
|
|
32
|
-
* Enumerate the cadre's *addressable* peers (over the admin channel) —
|
|
33
|
-
* anyone with an address record, including devices no owner vouched for.
|
|
34
|
-
* Used only for {@link removeMember}, where "the row exists" is the point.
|
|
35
|
-
*/
|
|
36
|
-
listMembers(): Promise<Array<{
|
|
37
|
-
peerId: string;
|
|
38
|
-
multiaddr: string | null;
|
|
39
|
-
}>>;
|
|
40
|
-
/** Probe whether a peer is *addressable* (over the admin channel). See {@link listMembers}. */
|
|
41
|
-
isMember(peerId: string): Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* Enumerate the cadre's *authorized* membership (over the admin channel) —
|
|
44
|
-
* devices an owner key vouched for. Excludes the node's own self-published
|
|
45
|
-
* row. This is the real membership test the trust-circle listing shows.
|
|
46
|
-
*/
|
|
47
|
-
listAuthorizedMembers(): Promise<Array<{
|
|
48
|
-
peerId: string;
|
|
49
|
-
multiaddr: string | null;
|
|
50
|
-
}>>;
|
|
51
|
-
/** Probe whether a peer is *authorized*. See {@link listAuthorizedMembers}. */
|
|
52
|
-
isAuthorizedMember(peerId: string): Promise<boolean>;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* TrustCircleService — orchestrates invite issuance, redemption, and
|
|
56
|
-
* membership management.
|
|
57
|
-
*
|
|
58
|
-
* Membership is canonical in the cadre control DB (`CadrePeer` table),
|
|
59
|
-
* reached over the owner node's admin channel; labels and pending tokens
|
|
60
|
-
* live in the host-local `TrustCircleStore`. When the node is unreachable,
|
|
61
|
-
* owner operations surface `node_unavailable` (→ 503) and `list()`
|
|
62
|
-
* degrades to the local labels file.
|
|
63
|
-
*/
|
|
64
|
-
export declare class TrustCircleService {
|
|
65
|
-
private readonly cadreNode;
|
|
66
|
-
private readonly store;
|
|
67
|
-
private readonly now;
|
|
68
|
-
/**
|
|
69
|
-
* In-flight redemption claims (by token). Serialises concurrent redeems
|
|
70
|
-
* for the same token without burning the durable pending row before
|
|
71
|
-
* `acceptPhone` succeeds. Intra-process only — the orchestrator enforces
|
|
72
|
-
* single-process ownership of a given rootDir, so no file lock is needed.
|
|
73
|
-
*/
|
|
74
|
-
private readonly inFlightRedemptions;
|
|
75
|
-
constructor(opts: TrustCircleServiceOptions);
|
|
76
|
-
/**
|
|
77
|
-
* Issue a new invite. Generates a token, persists a pending row, and
|
|
78
|
-
* delegates to cadre-core to embed the host's owner addresses.
|
|
79
|
-
*/
|
|
80
|
-
issueInvite(opts: {
|
|
81
|
-
label: string;
|
|
82
|
-
ttlMs?: number;
|
|
83
|
-
}): Promise<{
|
|
84
|
-
encodedInvite: string;
|
|
85
|
-
invite: CadreInvite;
|
|
86
|
-
token: string;
|
|
87
|
-
expiresAt?: Date;
|
|
88
|
-
}>;
|
|
89
|
-
/**
|
|
90
|
-
* Redeem an invite for an incoming peer ID. On success:
|
|
91
|
-
* - cadre-core authorizes the peer (inserts CadrePeer row).
|
|
92
|
-
* - The pending row is consumed (one-time enforcement).
|
|
93
|
-
* - A labelled member row is written locally.
|
|
94
|
-
*
|
|
95
|
-
* Ordering: the synchronous *claim* against `inFlightRedemptions` serialises
|
|
96
|
-
* concurrent redeems for the same token (second concurrent caller rejects
|
|
97
|
-
* synchronously before its first await). The durable `removePending` only
|
|
98
|
-
* runs *after* `acceptPhone` succeeds — so a transient `node_unavailable`
|
|
99
|
-
* leaves the token re-redeemable rather than permanently burning it.
|
|
100
|
-
*
|
|
101
|
-
* Crash-safety tradeoff: if the host crashes between `acceptPhone` success
|
|
102
|
-
* and the durable `removePending`, a retry will dial in fine but the
|
|
103
|
-
* owner node's `acceptPhone` will reject the second `CadrePeer` insert
|
|
104
|
-
* with a PK constraint error (cadre-core does not upsert). That surfaces to
|
|
105
|
-
* the redeemer as a non-`node_unavailable` failure; the admin can revoke
|
|
106
|
-
* the lingering pending row. This is a narrower window than the prior
|
|
107
|
-
* behaviour, where *any* transient node outage burned the token.
|
|
108
|
-
*/
|
|
109
|
-
redeemInvite(opts: {
|
|
110
|
-
token: string;
|
|
111
|
-
peerId: string;
|
|
112
|
-
}): Promise<{
|
|
113
|
-
peerId: string;
|
|
114
|
-
label: string;
|
|
115
|
-
}>;
|
|
116
|
-
/** Revoke a pending invite by token. No-op if not found. */
|
|
117
|
-
revokePending(token: string): Promise<void>;
|
|
118
|
-
/**
|
|
119
|
-
* Remove an authorised member. Deletes the CadrePeer row and the local
|
|
120
|
-
* label. Throws not_found when the peer is in neither place.
|
|
121
|
-
*
|
|
122
|
-
* NOTE: no special case for the host's own peer ID — the local UI hides the
|
|
123
|
-
* Remove button on the `self` row, but `DELETE /auth/members/<ownPeerId>`
|
|
124
|
-
* (or `cadre-host trust revoke <ownPeerId>`) will delete the node's own
|
|
125
|
-
* `CadrePeer` row. cadre-core re-registers self on node start, so a restart
|
|
126
|
-
* heals it. If that stops being true, or the removal path grows a
|
|
127
|
-
* non-loopback caller, guard `self` rows here.
|
|
128
|
-
*/
|
|
129
|
-
removeMember(peerId: string): Promise<void>;
|
|
130
|
-
/** Whether the peer is present in the cadre's CadrePeer table. */
|
|
131
|
-
isMember(peerId: string): Promise<boolean>;
|
|
132
|
-
/**
|
|
133
|
-
* UI snapshot. Joins the *authorized* membership (fetched over the admin
|
|
134
|
-
* channel) with local labels; prunes any orphan labels (peer is no longer
|
|
135
|
-
* authorised). Addressable-but-unauthorized peers — devices that merely
|
|
136
|
-
* published an address record without an owner voucher — are deliberately
|
|
137
|
-
* excluded; this is the listing an operator uses to decide who belongs.
|
|
138
|
-
* The node's own self-published row is spliced back in from the local
|
|
139
|
-
* label, since the authorized set excludes self by design. When the owner
|
|
140
|
-
* node is unreachable, degrades to the local labels file so listing keeps
|
|
141
|
-
* working while the node is down.
|
|
142
|
-
*/
|
|
143
|
-
list(): Promise<TrustCircleSnapshot>;
|
|
144
|
-
/**
|
|
145
|
-
* Translate an admin-channel transport failure into a `node_unavailable`
|
|
146
|
-
* TrustCircleError (→ 503). Re-throws anything else unchanged. Returns
|
|
147
|
-
* `never` so callers can `.catch(err => this.toDomainError(err))`.
|
|
148
|
-
*/
|
|
149
|
-
private toDomainError;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Wrap a TrustCircleService into the typed handler shape consumed by
|
|
153
|
-
* `cadre-host-local-ui`. Errors propagate as TrustCircleError; the UI ticket
|
|
154
|
-
* maps `.code` → HTTP status.
|
|
155
|
-
*/
|
|
156
|
-
export declare function createTrustCircleHandlers(service: TrustCircleService): TrustCircleHandlers;
|