@serfab/cadre-host 1.13.0 → 1.14.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 (337) hide show
  1. package/README.md +332 -423
  2. package/dist/bin/host.d.ts +6 -3
  3. package/dist/bin/host.js +301 -505
  4. package/dist/bin/host.js.map +1 -1
  5. package/dist/bin/join-output.d.ts +56 -0
  6. package/dist/bin/join-output.js +92 -0
  7. package/dist/bin/join-output.js.map +1 -0
  8. package/dist/bin/nat-output.d.ts +49 -0
  9. package/dist/bin/nat-output.js +127 -0
  10. package/dist/bin/nat-output.js.map +1 -0
  11. package/dist/hosted/claim-details.d.ts +44 -0
  12. package/dist/hosted/claim-details.js +66 -0
  13. package/dist/hosted/claim-details.js.map +1 -0
  14. package/dist/hosted/hosted-node-service.d.ts +318 -0
  15. package/dist/hosted/hosted-node-service.js +666 -0
  16. package/dist/hosted/hosted-node-service.js.map +1 -0
  17. package/dist/hosted/hosted-node-store.d.ts +40 -0
  18. package/dist/hosted/hosted-node-store.js +126 -0
  19. package/dist/hosted/hosted-node-store.js.map +1 -0
  20. package/dist/{donation/donation-supervisor.d.ts → hosted/hosted-node-supervisor.d.ts} +70 -53
  21. package/dist/hosted/hosted-node-supervisor.js +396 -0
  22. package/dist/hosted/hosted-node-supervisor.js.map +1 -0
  23. package/dist/hosted/hosted-node-watcher.d.ts +83 -0
  24. package/dist/hosted/hosted-node-watcher.js +224 -0
  25. package/dist/hosted/hosted-node-watcher.js.map +1 -0
  26. package/dist/hosted/index.d.ts +16 -0
  27. package/dist/hosted/index.js +13 -0
  28. package/dist/hosted/index.js.map +1 -0
  29. package/dist/hosted/node-status.d.ts +35 -0
  30. package/dist/hosted/node-status.js +61 -0
  31. package/dist/hosted/node-status.js.map +1 -0
  32. package/dist/hosted/types.d.ts +134 -0
  33. package/dist/hosted/types.js +22 -0
  34. package/dist/hosted/types.js.map +1 -0
  35. package/dist/index.d.ts +12 -24
  36. package/dist/index.js +9 -19
  37. package/dist/index.js.map +1 -1
  38. package/dist/installer/config.d.ts +4 -34
  39. package/dist/installer/config.js +3 -18
  40. package/dist/installer/config.js.map +1 -1
  41. package/dist/installer/index.d.ts +7 -19
  42. package/dist/installer/index.js +14 -69
  43. package/dist/installer/index.js.map +1 -1
  44. package/dist/installer/paths.d.ts +0 -2
  45. package/dist/installer/paths.js +0 -4
  46. package/dist/installer/paths.js.map +1 -1
  47. package/dist/installer/wizard.d.ts +0 -7
  48. package/dist/installer/wizard.js +1 -8
  49. package/dist/installer/wizard.js.map +1 -1
  50. package/dist/nat/address-resolver.d.ts +18 -17
  51. package/dist/nat/address-resolver.js +79 -25
  52. package/dist/nat/address-resolver.js.map +1 -1
  53. package/dist/nat/address-watch.d.ts +37 -0
  54. package/dist/nat/address-watch.js +84 -0
  55. package/dist/nat/address-watch.js.map +1 -0
  56. package/dist/nat/ddns/duckdns.d.ts +2 -1
  57. package/dist/nat/ddns/duckdns.js +5 -1
  58. package/dist/nat/ddns/duckdns.js.map +1 -1
  59. package/dist/nat/ddns/index.d.ts +6 -0
  60. package/dist/nat/ddns/index.js.map +1 -1
  61. package/dist/nat/index.d.ts +12 -9
  62. package/dist/nat/index.js +6 -5
  63. package/dist/nat/index.js.map +1 -1
  64. package/dist/nat/nat-service.d.ts +203 -77
  65. package/dist/nat/nat-service.js +602 -237
  66. package/dist/nat/nat-service.js.map +1 -1
  67. package/dist/nat/nat-store.d.ts +12 -5
  68. package/dist/nat/nat-store.js +114 -30
  69. package/dist/nat/nat-store.js.map +1 -1
  70. package/dist/nat/port-mapper.d.ts +83 -79
  71. package/dist/nat/port-mapper.js +148 -189
  72. package/dist/nat/port-mapper.js.map +1 -1
  73. package/dist/nat/reachability.d.ts +31 -15
  74. package/dist/nat/reachability.js +97 -22
  75. package/dist/nat/reachability.js.map +1 -1
  76. package/dist/nat/types.d.ts +78 -27
  77. package/dist/nat/types.js +8 -5
  78. package/dist/nat/types.js.map +1 -1
  79. package/dist/orchestrator/host-process-orchestrator.d.ts +29 -71
  80. package/dist/orchestrator/host-process-orchestrator.js +78 -218
  81. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  82. package/dist/{installer/identity.d.ts → orchestrator/identity-file.d.ts} +5 -5
  83. package/dist/{installer/identity.js → orchestrator/identity-file.js} +6 -6
  84. package/dist/orchestrator/identity-file.js.map +1 -0
  85. package/dist/orchestrator/index.d.ts +2 -3
  86. package/dist/orchestrator/index.js +1 -1
  87. package/dist/orchestrator/index.js.map +1 -1
  88. package/dist/orchestrator/node-identity.d.ts +6 -6
  89. package/dist/orchestrator/node-identity.js +7 -7
  90. package/dist/orchestrator/node-identity.js.map +1 -1
  91. package/dist/orchestrator/port-allocator.d.ts +5 -6
  92. package/dist/orchestrator/port-allocator.js +9 -11
  93. package/dist/orchestrator/port-allocator.js.map +1 -1
  94. package/dist/orchestrator/state-store.d.ts +3 -5
  95. package/dist/orchestrator/state-store.js +2 -10
  96. package/dist/orchestrator/state-store.js.map +1 -1
  97. package/dist/orchestrator/types.d.ts +33 -22
  98. package/dist/orchestrator/types.js.map +1 -1
  99. package/dist/server/error-handler.d.ts +5 -25
  100. package/dist/server/error-handler.js +11 -74
  101. package/dist/server/error-handler.js.map +1 -1
  102. package/dist/server/events/types.d.ts +7 -11
  103. package/dist/server/events/types.js +2 -1
  104. package/dist/server/events/types.js.map +1 -1
  105. package/dist/server/index.d.ts +11 -37
  106. package/dist/server/index.js +30 -48
  107. package/dist/server/index.js.map +1 -1
  108. package/dist/server/routes/hosted-nodes.d.ts +28 -0
  109. package/dist/server/routes/hosted-nodes.js +68 -0
  110. package/dist/server/routes/hosted-nodes.js.map +1 -0
  111. package/dist/server/routes/nat.d.ts +4 -1
  112. package/dist/server/routes/nat.js +13 -2
  113. package/dist/server/routes/nat.js.map +1 -1
  114. package/dist/server/routes/nodes.d.ts +6 -20
  115. package/dist/server/routes/nodes.js +7 -86
  116. package/dist/server/routes/nodes.js.map +1 -1
  117. package/dist/server/routes/settings.d.ts +2 -7
  118. package/dist/server/routes/settings.js +3 -7
  119. package/dist/server/routes/settings.js.map +1 -1
  120. package/dist/server/routes/status.d.ts +2 -25
  121. package/dist/server/routes/status.js +1 -11
  122. package/dist/server/routes/status.js.map +1 -1
  123. package/dist/server/server.js +8 -8
  124. package/dist/server/settings-store.d.ts +2 -2
  125. package/dist/server/settings-store.js +2 -2
  126. package/dist/server/static.js +1 -2
  127. package/dist/server/static.js.map +1 -1
  128. package/dist/ui/assets/index-4FWuU8ye.js +19 -0
  129. package/dist/ui/assets/index-4FWuU8ye.js.map +1 -0
  130. package/dist/ui/assets/index-Di9Q4d01.css +1 -0
  131. package/dist/ui/index.html +2 -2
  132. package/dist/update/index.d.ts +2 -2
  133. package/dist/update/index.js +2 -2
  134. package/dist/update/store.d.ts +1 -1
  135. package/dist/update/store.js +1 -1
  136. package/dist/update/types.d.ts +1 -1
  137. package/dist/update/types.js +1 -1
  138. package/package.json +5 -6
  139. package/src/__tests__/cli-nat.smoke.test.ts +219 -212
  140. package/src/__tests__/cli.smoke.test.ts +1 -1
  141. package/src/__tests__/global-setup.ts +2 -3
  142. package/src/__tests__/orchestrator-claim-secret.test.ts +112 -0
  143. package/src/__tests__/orchestrator-handle-contract.ts +134 -134
  144. package/src/__tests__/orchestrator-node-identity.test.ts +182 -203
  145. package/src/__tests__/orchestrator-ports.test.ts +124 -143
  146. package/src/__tests__/orchestrator-push.test.ts +138 -146
  147. package/src/__tests__/orchestrator.test.ts +1019 -1063
  148. package/src/bin/host.ts +368 -553
  149. package/src/bin/join-output.ts +120 -0
  150. package/src/bin/nat-output.ts +177 -0
  151. package/src/{donation → hosted}/__tests__/fake-orchestrator.test.ts +173 -173
  152. package/src/{donation → hosted}/__tests__/fake-orchestrator.ts +265 -243
  153. package/src/hosted/__tests__/hosted-node-service.test.ts +609 -0
  154. package/src/hosted/__tests__/hosted-node-supervisor.test.ts +474 -0
  155. package/src/hosted/__tests__/test-invitation.ts +33 -0
  156. package/src/hosted/claim-details.ts +96 -0
  157. package/src/hosted/hosted-node-service.ts +795 -0
  158. package/src/hosted/hosted-node-store.ts +144 -0
  159. package/src/hosted/hosted-node-supervisor.ts +439 -0
  160. package/src/hosted/hosted-node-watcher.ts +250 -0
  161. package/src/hosted/index.ts +53 -0
  162. package/src/hosted/node-status.ts +71 -0
  163. package/src/hosted/types.ts +153 -0
  164. package/src/index.ts +72 -91
  165. package/src/installer/__tests__/config.test.ts +15 -40
  166. package/src/installer/__tests__/installer.smoke.test.ts +5 -86
  167. package/src/installer/__tests__/wizard.test.ts +56 -64
  168. package/src/installer/config.ts +135 -175
  169. package/src/installer/index.ts +15 -83
  170. package/src/installer/paths.ts +104 -109
  171. package/src/installer/wizard.ts +87 -103
  172. package/src/nat/__tests__/address-resolver.test.ts +107 -82
  173. package/src/nat/__tests__/nat-service.test.ts +433 -408
  174. package/src/nat/__tests__/nat-store.test.ts +127 -93
  175. package/src/nat/__tests__/port-mapper.test.ts +30 -191
  176. package/src/nat/__tests__/reachability.test.ts +96 -13
  177. package/src/nat/address-resolver.ts +94 -52
  178. package/src/nat/address-watch.ts +92 -0
  179. package/src/nat/ddns/duckdns.ts +5 -1
  180. package/src/nat/ddns/index.ts +6 -0
  181. package/src/nat/index.ts +87 -71
  182. package/src/nat/nat-service.ts +889 -501
  183. package/src/nat/nat-store.ts +237 -154
  184. package/src/nat/port-mapper.ts +241 -329
  185. package/src/nat/reachability.ts +134 -25
  186. package/src/nat/types.ts +209 -159
  187. package/src/{installer/__tests__/identity.test.ts → orchestrator/__tests__/identity-file.test.ts} +34 -34
  188. package/src/orchestrator/__tests__/node-identity.test.ts +62 -62
  189. package/src/orchestrator/host-process-orchestrator.ts +81 -243
  190. package/src/{installer/identity.ts → orchestrator/identity-file.ts} +56 -56
  191. package/src/orchestrator/index.ts +9 -10
  192. package/src/orchestrator/node-identity.ts +41 -41
  193. package/src/orchestrator/port-allocator.ts +71 -73
  194. package/src/orchestrator/state-store.ts +76 -90
  195. package/src/orchestrator/types.ts +34 -23
  196. package/src/server/__tests__/bus.test.ts +38 -38
  197. package/src/server/__tests__/error-handler.test.ts +81 -118
  198. package/src/server/__tests__/fakes.ts +40 -44
  199. package/src/server/__tests__/hosted-nodes-route.test.ts +160 -0
  200. package/src/server/__tests__/nodes-route.test.ts +114 -283
  201. package/src/server/__tests__/publishers.test.ts +193 -180
  202. package/src/server/__tests__/server.smoke.test.ts +134 -223
  203. package/src/server/__tests__/settings-route.test.ts +179 -195
  204. package/src/server/__tests__/sse-route.test.ts +119 -119
  205. package/src/server/__tests__/status-route.test.ts +82 -121
  206. package/src/server/error-handler.ts +112 -178
  207. package/src/server/events/types.ts +20 -24
  208. package/src/server/index.ts +223 -267
  209. package/src/server/routes/hosted-nodes.ts +83 -0
  210. package/src/server/routes/nat.ts +75 -63
  211. package/src/server/routes/nodes.ts +96 -188
  212. package/src/server/routes/settings.ts +115 -123
  213. package/src/server/routes/status.ts +102 -134
  214. package/src/server/server.ts +8 -8
  215. package/src/server/settings-store.ts +2 -2
  216. package/src/server/static.ts +1 -2
  217. package/src/update/index.ts +2 -2
  218. package/src/update/store.ts +1 -1
  219. package/src/update/types.ts +1 -1
  220. package/dist/auth/duration.d.ts +0 -1
  221. package/dist/auth/duration.js +0 -32
  222. package/dist/auth/duration.js.map +0 -1
  223. package/dist/auth/index.d.ts +0 -11
  224. package/dist/auth/index.js +0 -9
  225. package/dist/auth/index.js.map +0 -1
  226. package/dist/auth/self-label.d.ts +0 -36
  227. package/dist/auth/self-label.js +0 -57
  228. package/dist/auth/self-label.js.map +0 -1
  229. package/dist/auth/trust-circle-store.d.ts +0 -26
  230. package/dist/auth/trust-circle-store.js +0 -129
  231. package/dist/auth/trust-circle-store.js.map +0 -1
  232. package/dist/auth/trust-circle.d.ts +0 -156
  233. package/dist/auth/trust-circle.js +0 -307
  234. package/dist/auth/trust-circle.js.map +0 -1
  235. package/dist/auth/types.d.ts +0 -84
  236. package/dist/auth/types.js +0 -24
  237. package/dist/auth/types.js.map +0 -1
  238. package/dist/donation/donation-service.d.ts +0 -389
  239. package/dist/donation/donation-service.js +0 -828
  240. package/dist/donation/donation-service.js.map +0 -1
  241. package/dist/donation/donation-store.d.ts +0 -51
  242. package/dist/donation/donation-store.js +0 -152
  243. package/dist/donation/donation-store.js.map +0 -1
  244. package/dist/donation/donation-supervisor.js +0 -364
  245. package/dist/donation/donation-supervisor.js.map +0 -1
  246. package/dist/donation/grant-service.d.ts +0 -80
  247. package/dist/donation/grant-service.js +0 -210
  248. package/dist/donation/grant-service.js.map +0 -1
  249. package/dist/donation/grant-store.d.ts +0 -38
  250. package/dist/donation/grant-store.js +0 -135
  251. package/dist/donation/grant-store.js.map +0 -1
  252. package/dist/donation/index.d.ts +0 -20
  253. package/dist/donation/index.js +0 -17
  254. package/dist/donation/index.js.map +0 -1
  255. package/dist/donation/types.d.ts +0 -224
  256. package/dist/donation/types.js +0 -40
  257. package/dist/donation/types.js.map +0 -1
  258. package/dist/installer/identity.js.map +0 -1
  259. package/dist/owner/index.d.ts +0 -11
  260. package/dist/owner/index.js +0 -11
  261. package/dist/owner/index.js.map +0 -1
  262. package/dist/owner/owner-node-client.d.ts +0 -110
  263. package/dist/owner/owner-node-client.js +0 -184
  264. package/dist/owner/owner-node-client.js.map +0 -1
  265. package/dist/server/routes/bootstrap-node-validation.d.ts +0 -115
  266. package/dist/server/routes/bootstrap-node-validation.js +0 -197
  267. package/dist/server/routes/bootstrap-node-validation.js.map +0 -1
  268. package/dist/server/routes/grants-admin.d.ts +0 -29
  269. package/dist/server/routes/grants-admin.js +0 -58
  270. package/dist/server/routes/grants-admin.js.map +0 -1
  271. package/dist/server/routes/grants.d.ts +0 -28
  272. package/dist/server/routes/grants.js +0 -165
  273. package/dist/server/routes/grants.js.map +0 -1
  274. package/dist/server/routes/provision-request-validation.d.ts +0 -45
  275. package/dist/server/routes/provision-request-validation.js +0 -97
  276. package/dist/server/routes/provision-request-validation.js.map +0 -1
  277. package/dist/server/routes/strands.d.ts +0 -20
  278. package/dist/server/routes/strands.js +0 -38
  279. package/dist/server/routes/strands.js.map +0 -1
  280. package/dist/server/routes/trust-circle.d.ts +0 -17
  281. package/dist/server/routes/trust-circle.js +0 -35
  282. package/dist/server/routes/trust-circle.js.map +0 -1
  283. package/dist/strands/index.d.ts +0 -7
  284. package/dist/strands/index.js +0 -6
  285. package/dist/strands/index.js.map +0 -1
  286. package/dist/strands/strand-service.d.ts +0 -50
  287. package/dist/strands/strand-service.js +0 -103
  288. package/dist/strands/strand-service.js.map +0 -1
  289. package/dist/strands/types.d.ts +0 -93
  290. package/dist/strands/types.js +0 -23
  291. package/dist/strands/types.js.map +0 -1
  292. package/dist/ui/assets/index-C6nELNfC.js +0 -23
  293. package/dist/ui/assets/index-C6nELNfC.js.map +0 -1
  294. package/dist/ui/assets/index-TtIYSeZO.css +0 -1
  295. package/src/__tests__/cli-invite.smoke.test.ts +0 -192
  296. package/src/__tests__/host-owner.smoke.test.ts +0 -123
  297. package/src/__tests__/orchestrator-owner.test.ts +0 -234
  298. package/src/__tests__/orchestrator-pin-keys.test.ts +0 -152
  299. package/src/auth/__tests__/duration.test.ts +0 -28
  300. package/src/auth/__tests__/self-label.test.ts +0 -85
  301. package/src/auth/__tests__/trust-circle-integration.test.ts +0 -152
  302. package/src/auth/__tests__/trust-circle-store.test.ts +0 -115
  303. package/src/auth/__tests__/trust-circle.test.ts +0 -445
  304. package/src/auth/duration.ts +0 -33
  305. package/src/auth/index.ts +0 -21
  306. package/src/auth/self-label.ts +0 -74
  307. package/src/auth/trust-circle-store.ts +0 -155
  308. package/src/auth/trust-circle.ts +0 -395
  309. package/src/auth/types.ts +0 -99
  310. package/src/donation/__tests__/donation-service.test.ts +0 -1193
  311. package/src/donation/__tests__/donation-supervisor.test.ts +0 -548
  312. package/src/donation/__tests__/grant-service.test.ts +0 -213
  313. package/src/donation/__tests__/grant-store.test.ts +0 -113
  314. package/src/donation/donation-service.ts +0 -1033
  315. package/src/donation/donation-store.ts +0 -176
  316. package/src/donation/donation-supervisor.ts +0 -411
  317. package/src/donation/grant-service.ts +0 -252
  318. package/src/donation/grant-store.ts +0 -152
  319. package/src/donation/index.ts +0 -65
  320. package/src/donation/types.ts +0 -260
  321. package/src/owner/__tests__/owner-node-client.test.ts +0 -194
  322. package/src/owner/index.ts +0 -12
  323. package/src/owner/owner-node-client.ts +0 -259
  324. package/src/server/__tests__/bootstrap-node-validation.test.ts +0 -138
  325. package/src/server/__tests__/grants-admin-route.test.ts +0 -171
  326. package/src/server/__tests__/grants-route.test.ts +0 -394
  327. package/src/server/__tests__/strands-route.test.ts +0 -234
  328. package/src/server/routes/bootstrap-node-validation.ts +0 -206
  329. package/src/server/routes/grants-admin.ts +0 -74
  330. package/src/server/routes/grants.ts +0 -193
  331. package/src/server/routes/provision-request-validation.ts +0 -105
  332. package/src/server/routes/strands.ts +0 -54
  333. package/src/server/routes/trust-circle.ts +0 -49
  334. package/src/strands/__tests__/strand-service.test.ts +0 -165
  335. package/src/strands/index.ts +0 -14
  336. package/src/strands/strand-service.ts +0 -135
  337. package/src/strands/types.ts +0 -102
@@ -1,224 +0,0 @@
1
- /**
2
- * Donation grant-token types for cadre-host.
3
- *
4
- * A **grant token** is a high-entropy base64url secret the host admin issues,
5
- * out-of-band (QR / copy-paste), to one *grantee* — a friend or family member
6
- * whose cadre authority (their phone) may then ask this host to spawn donated
7
- * nodes. The grantee presents the token as `Authorization: Bearer <grant-token>`
8
- * on every donation request (the grantee-facing surface lands in the
9
- * `2-donation-service` ticket).
10
- *
11
- * This module owns the grant's identity, expiry, and per-grantee quota. The
12
- * *live-node tally* it checks the quota against is owned by the donation
13
- * service, not by the grant layer — see `GrantValidator.validateForProvision`.
14
- *
15
- * **Grant ≠ trust-circle membership.** A trust-circle invite (`auth/`)
16
- * authorises a device to join *the host's own* cadre. A donation grant
17
- * authorises an external cadre authority to ask the host to spawn a node that
18
- * joins *the grantee's* cadre. The two token flows are deliberately separate
19
- * modules; this one reuses the *shape* of the trust-circle store (atomic
20
- * write-then-rename JSON, token-keyed rows) but with grant — not invite —
21
- * semantics: a grant is long-lived and reusable up to a quota, never
22
- * one-time-redeemed.
23
- */
24
- /** A grant the host admin issued to one grantee (friend/family). */
25
- export interface Grant {
26
- /** base64url secret; also the bearer credential. The store key. */
27
- token: string;
28
- /** Human label chosen by the admin, e.g. "Alice's cadre". Display-only. */
29
- label: string;
30
- /** Max concurrently-live donated nodes this grant may hold. */
31
- maxNodes: number;
32
- /** ISO timestamp when the grant was issued. */
33
- createdAt: string;
34
- /** ISO expiry; absent = no expiry. */
35
- expiresAt?: string;
36
- /** Set when the admin revokes; a revoked grant validates as denied. */
37
- revokedAt?: string;
38
- }
39
- /** One grant as the admin list reports it: the grant plus what is running under it. */
40
- export interface GrantListing extends Grant {
41
- /** Donations counting against `maxNodes` (provisioning / awaiting_seed / seeded). */
42
- liveNodes: number;
43
- /** Every donation under this grant that is not `terminated` — what revoke would tear down. */
44
- donations: Array<{
45
- id: string;
46
- status: DonationStatus;
47
- }>;
48
- }
49
- /** Why a presented grant token was denied. */
50
- export type GrantDenyReason = 'unknown_token' | 'expired' | 'revoked' | 'quota_exceeded';
51
- /** Result of validating a presented bearer token. */
52
- export interface GrantValidation {
53
- ok: boolean;
54
- /** The matched grant, when the token names one (present even on some denials). */
55
- grant?: Grant;
56
- /** Set when `ok` is false. */
57
- reason?: GrantDenyReason;
58
- }
59
- /**
60
- * The slice `2-donation-service` depends on. Keeps that ticket decoupled from
61
- * the store implementation: it holds a `GrantValidator`, not a `GrantStore`.
62
- *
63
- * Both methods are pure functions of the store state (and, for provision, the
64
- * caller-supplied count) — they never throw for a bad token, they return a
65
- * denial. Issuance/revocation (which mutate) live on `GrantService`.
66
- */
67
- export interface GrantValidator {
68
- /**
69
- * Validate a presented bearer token for a *new* provision request.
70
- *
71
- * `liveNodeCount(token)` is supplied by the donation service — the grant
72
- * layer owns identity/expiry/revocation; the donation service owns the
73
- * authoritative live-node tally (it holds the grant→node records). The count
74
- * is only consulted once identity/expiry/revocation have passed, so an
75
- * unknown or dead token never invokes it.
76
- */
77
- validateForProvision(token: string, liveNodeCount: (token: string) => number): GrantValidation;
78
- /**
79
- * Validate for a non-provisioning op (peer/seed/terminate): identity + not
80
- * expired/revoked. No quota check.
81
- */
82
- validate(token: string): GrantValidation;
83
- }
84
- /** On-disk shape of `grants.json`. */
85
- export interface GrantFile {
86
- version: 1;
87
- /** keyed by token. */
88
- grants: Record<string, Omit<Grant, 'token'>>;
89
- }
90
- /**
91
- * Typed handlers exposed to the loopback management server for the **admin**
92
- * grant surface (`/grants-admin`). Distinct from the grantee-facing `/grants`
93
- * provisioning surface: the admin surface is loopback, no bearer — same-machine
94
- * admin, matching cadre-host's local-UI "no login" posture.
95
- *
96
- * Handlers throw a `GrantError` (or, for donation teardown, a `DonationError`)
97
- * whose `.code` the server maps to an HTTP status (see `server/error-handler.ts`).
98
- */
99
- export interface GrantAdminHandlers {
100
- postGrant(body: {
101
- label: string;
102
- maxNodes?: number;
103
- ttlMs?: number;
104
- }): Promise<{
105
- grant: Grant;
106
- }>;
107
- listGrants(): Promise<{
108
- grants: GrantListing[];
109
- }>;
110
- /**
111
- * Revoke a grant and, unless `keepNodes`, terminate every donated node under
112
- * it. Resolves with the ids of the donations terminated.
113
- */
114
- deleteGrant(token: string, opts: {
115
- keepNodes: boolean;
116
- }): Promise<{
117
- terminated: string[];
118
- }>;
119
- /**
120
- * Terminate one donated node by id, whatever state its grant is in. Absent
121
- * when no donation service is wired — there are then no donated nodes to end.
122
- */
123
- terminateDonation?(id: string): Promise<void>;
124
- }
125
- /**
126
- * Lifecycle of one donated node:
127
- * provisioning → the child process is being spawned.
128
- * awaiting_seed → spawned + reachable; waiting for the requester to present
129
- * its phone-signed seed (`PUT /grants/:id/seed`).
130
- * seeded → the seed was applied; the node has joined the requester's cadre.
131
- * error → provisioning failed (orchestrator resources reclaimed).
132
- * terminated → stopped + removed (kept in the store for audit).
133
- *
134
- * A donation is "live" (counts against a grant's `maxNodes` quota) while it is
135
- * `provisioning`, `awaiting_seed`, or `seeded` — see `DonationStore.liveNodeCount`.
136
- */
137
- export type DonationStatus = 'provisioning' | 'awaiting_seed' | 'seeded' | 'error' | 'terminated';
138
- /**
139
- * One donated node, tracked host-side and persisted to `donations.json`.
140
- *
141
- * The host contributes capacity only: `partyId` is the REQUESTER's cadre (a
142
- * foreign party), and `seedToken` gates the node's own `POST /seed` — it is
143
- * minted host-side, persisted here (so a host restart in the request→seed gap
144
- * can still present the seed), and NEVER returned to the grantee.
145
- *
146
- * The record also carries every input the original spawn consumed
147
- * (`partyId` + `profile` + `bootstrapNodes` + `ownerKeys`), so a crashed node can
148
- * be re-spawned from the record alone — see `DonationService.respawn`. Records
149
- * written before those two fields existed have neither; such a record is NOT
150
- * respawnable and is skipped (never crashes a sweep).
151
- */
152
- export interface Donation {
153
- /** "grn_<nanoid>" — also the donated node's orchestrator containerId. */
154
- id: string;
155
- /** The grant token that authorized this donation (the quota key). */
156
- grantToken: string;
157
- /** The REQUESTER's cadre (a foreign party this host merely hosts a node for). */
158
- partyId: string;
159
- /**
160
- * Requester control-network bootstrap multiaddrs — replayed on respawn. Empty when
161
- * the requester dials the node itself (see `DonationProvisionRequest.bootstrapNodes`).
162
- * Absent on records written before respawn support; those are not respawnable.
163
- */
164
- bootstrapNodes?: string[];
165
- /**
166
- * Requester owner public key(s), base64url — replayed as the node's pinned
167
- * seed-trust anchors (`CADRE_OWNER_KEYS`) on respawn. Absent on records written
168
- * before respawn support; those are not respawnable.
169
- */
170
- ownerKeys?: string[];
171
- /**
172
- * Respawn bookkeeping, owned by the supervisor's backoff. Absent until the
173
- * first respawn attempt. Not secret — it rides along in `DonationView` so the
174
- * borrower's `GET /grants/:id` shows the counters for free.
175
- */
176
- respawn?: {
177
- attempts: number;
178
- lastAttemptAt: string;
179
- };
180
- /** Node profile. Defaults to `storage` so the node participates and is dialable. */
181
- profile: 'storage' | 'transaction';
182
- status: DonationStatus;
183
- /** Orchestrator handle (opaque `pid:token`), set once the child is spawned. */
184
- dockerId?: string;
185
- /**
186
- * Reserved: a donation's live peer identity is read fresh from the node's
187
- * `/status` on each `getPeer` call and is NOT persisted here — this field is
188
- * currently never written. Kept for a future cache if `/status` fan-out ever
189
- * shows up as hot.
190
- */
191
- peerId?: string;
192
- /** The node's loopback `POST /seed` URL. Host-internal — stripped from the wire view. */
193
- seedEndpoint?: string;
194
- /** Host↔node bearer gating `POST /seed`. Persisted; NEVER leaves the host. */
195
- seedToken?: string;
196
- createdAt: string;
197
- updatedAt: string;
198
- /** Failure detail when `status === 'error'`. */
199
- error?: string;
200
- }
201
- /**
202
- * Redacted wire shape returned to the grantee: the host-only secrets
203
- * (`seedToken`) and host-internal loopback URL (`seedEndpoint`) are stripped.
204
- */
205
- export type DonationView = Omit<Donation, 'seedToken' | 'seedEndpoint'>;
206
- /** On-disk shape of `donations.json`. Keyed by donation id. */
207
- export interface DonationFile {
208
- version: 1;
209
- donations: Record<string, Omit<Donation, 'id'>>;
210
- }
211
- /** Error codes thrown by the donation service / grantee-facing routes. */
212
- export type DonationErrorCode = 'unauthorized' | 'forbidden' | 'quota_exceeded' | 'invalid_request' | 'not_found' | 'invalid_state' | 'seed_failed' | 'peer_unavailable' | 'orchestrator_error' | 'storage_error';
213
- /** Typed donation error carrying a stable `code` for HTTP mapping. */
214
- export declare class DonationError extends Error {
215
- readonly code: DonationErrorCode;
216
- constructor(code: DonationErrorCode, message: string);
217
- }
218
- /** Error codes thrown by GrantStore / GrantService. */
219
- export type GrantErrorCode = 'not_found' | 'invalid_label' | 'invalid_max_nodes' | 'invalid_ttl' | 'storage_error';
220
- /** Typed error carrying a stable `code` for HTTP mapping. */
221
- export declare class GrantError extends Error {
222
- readonly code: GrantErrorCode;
223
- constructor(code: GrantErrorCode, message: string);
224
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * Donation grant-token types for cadre-host.
3
- *
4
- * A **grant token** is a high-entropy base64url secret the host admin issues,
5
- * out-of-band (QR / copy-paste), to one *grantee* — a friend or family member
6
- * whose cadre authority (their phone) may then ask this host to spawn donated
7
- * nodes. The grantee presents the token as `Authorization: Bearer <grant-token>`
8
- * on every donation request (the grantee-facing surface lands in the
9
- * `2-donation-service` ticket).
10
- *
11
- * This module owns the grant's identity, expiry, and per-grantee quota. The
12
- * *live-node tally* it checks the quota against is owned by the donation
13
- * service, not by the grant layer — see `GrantValidator.validateForProvision`.
14
- *
15
- * **Grant ≠ trust-circle membership.** A trust-circle invite (`auth/`)
16
- * authorises a device to join *the host's own* cadre. A donation grant
17
- * authorises an external cadre authority to ask the host to spawn a node that
18
- * joins *the grantee's* cadre. The two token flows are deliberately separate
19
- * modules; this one reuses the *shape* of the trust-circle store (atomic
20
- * write-then-rename JSON, token-keyed rows) but with grant — not invite —
21
- * semantics: a grant is long-lived and reusable up to a quota, never
22
- * one-time-redeemed.
23
- */
24
- /** Typed donation error carrying a stable `code` for HTTP mapping. */
25
- export class DonationError extends Error {
26
- constructor(code, message) {
27
- super(message);
28
- this.name = 'DonationError';
29
- this.code = code;
30
- }
31
- }
32
- /** Typed error carrying a stable `code` for HTTP mapping. */
33
- export class GrantError extends Error {
34
- constructor(code, message) {
35
- super(message);
36
- this.name = 'GrantError';
37
- this.code = code;
38
- }
39
- }
40
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/donation/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAiNH,sEAAsE;AACtE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAGtC,YAAY,IAAuB,EAAE,OAAe;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAUD,6DAA6D;AAC7D,MAAM,OAAO,UAAW,SAAQ,KAAK;IAGnC,YAAY,IAAoB,EAAE,OAAe;QAC/C,KAAK,CAAC,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CAAC,KAAK,CAAC,CAAC,CAAC;IACjE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;AAC7E,CAAC"}
@@ -1,11 +0,0 @@
1
- /**
2
- * Owner-node delegation surface for cadre-host.
3
- *
4
- * The manager process spawns the admin's owner cadre node (via
5
- * `HostProcessOrchestrator`) and delegates owner/membership/identity
6
- * operations to it over the loopback admin channel using
7
- * {@link OwnerNodeClient}. See `docs/cadre-host.md` § Control-plane
8
- * separation.
9
- */
10
- export { OwnerNodeClient, OwnerNodeUnavailableError } from './owner-node-client.js';
11
- export type { OwnerNodeClientOptions } from './owner-node-client.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Owner-node delegation surface for cadre-host.
3
- *
4
- * The manager process spawns the admin's owner cadre node (via
5
- * `HostProcessOrchestrator`) and delegates owner/membership/identity
6
- * operations to it over the loopback admin channel using
7
- * {@link OwnerNodeClient}. See `docs/cadre-host.md` § Control-plane
8
- * separation.
9
- */
10
- export { OwnerNodeClient, OwnerNodeUnavailableError } from './owner-node-client.js';
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/owner/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1,110 +0,0 @@
1
- /**
2
- * HTTP client for the owner node's loopback admin channel (the 6.6
3
- * `cadre-node-admin-channel` contract).
4
- *
5
- * cadre-host's manager process holds no in-process `CadreNode`; it spawns the
6
- * admin's owner node as a managed child (see `HostProcessOrchestrator`)
7
- * and delegates all owner/membership/identity operations to it over this
8
- * client. The client implements **all three** trimmed `CadreNodeLike`
9
- * interfaces — the trust-circle one (`auth/trust-circle.ts`), the NAT one
10
- * (`nat/nat-service.ts`), and the strand one (`strands/strand-service.ts`) —
11
- * plus `pushInviteAddresses` and `addDrone` (the node-donation requester side).
12
- *
13
- * Transport: `Authorization: Bearer <token>` against
14
- * `http://127.0.0.1:<adminPort>`. Every response uses the cadre-provider
15
- * envelope `{ ok: true, data }` / `{ ok: false, error: { code, message } }`.
16
- * A refused connection, a transport error, or any non-2xx response surfaces
17
- * as {@link OwnerNodeUnavailableError}; the trust-circle / NAT services
18
- * translate that into a `node_unavailable` domain error so the management API
19
- * returns a clear 503 rather than a raw 500.
20
- */
21
- import type { CadreInvite, DroneInitResult } from '@serfab/cadre-core';
22
- import type { OwnerAdminEndpoint } from '../orchestrator/index.js';
23
- import type { CadreNodeLike as TrustCircleCadreNodeLike } from '../auth/trust-circle.js';
24
- import type { CadreNodeLike as NatCadreNodeLike } from '../nat/nat-service.js';
25
- import type { CadreNodeLike as StrandCadreNodeLike } from '../strands/strand-service.js';
26
- import type { StrandListSnapshot, StrandRemovalResult } from '../strands/types.js';
27
- /**
28
- * Raised when the owner node's admin channel can't be reached or returns
29
- * a non-success response. Carries the node's stable error `code` when one was
30
- * present in the envelope (e.g. `not_ready`, `not_authorized`).
31
- */
32
- export declare class OwnerNodeUnavailableError extends Error {
33
- /** The admin-channel error code, when the node answered with an envelope. */
34
- readonly nodeCode?: string;
35
- constructor(message: string, nodeCode?: string);
36
- }
37
- /** Endpoint provided directly or via a getter (so it tracks re-spawns). */
38
- type EndpointSource = OwnerAdminEndpoint | (() => OwnerAdminEndpoint | undefined) | undefined;
39
- export interface OwnerNodeClientOptions {
40
- /** Fetch override for tests. Defaults to the global `fetch`. */
41
- fetch?: typeof fetch;
42
- }
43
- export declare class OwnerNodeClient implements TrustCircleCadreNodeLike, NatCadreNodeLike, StrandCadreNodeLike {
44
- private readonly endpointSource;
45
- private readonly fetchImpl;
46
- /**
47
- * @param endpoint Either a fixed `{ baseUrl, token }` or a getter returning
48
- * the current endpoint (pass `orchestrator.getOwnerAdminEndpoint`
49
- * bound, so a restart's new bearer token is picked up automatically).
50
- */
51
- constructor(endpoint: EndpointSource, opts?: OwnerNodeClientOptions);
52
- createInvite(token?: string, expiresInMs?: number): Promise<{
53
- invite: CadreInvite;
54
- encodedInvite: string;
55
- }>;
56
- acceptPhone(options: {
57
- phonePeerId: string;
58
- token?: string;
59
- }, issuedInvite?: CadreInvite): Promise<void>;
60
- removePeer(peerId: string): Promise<void>;
61
- /**
62
- * Encode an invite for out-of-band delivery. The admin contract has no
63
- * encode route (the mint route already returns `encodedInvite`), so this
64
- * mirrors cadre-core's encoding (`base64url(JSON.stringify(invite))`).
65
- */
66
- encodeInvite(invite: CadreInvite): string;
67
- listMembers(): Promise<Array<{
68
- peerId: string;
69
- multiaddr: string | null;
70
- }>>;
71
- isMember(peerId: string): Promise<boolean>;
72
- /** Authorized-membership surface (excludes self) — see {@link listMembers} for the addressable one. */
73
- listAuthorizedMembers(): Promise<Array<{
74
- peerId: string;
75
- multiaddr: string | null;
76
- }>>;
77
- isAuthorizedMember(peerId: string): Promise<boolean>;
78
- getPeerId(): Promise<string>;
79
- getMultiaddrs(): Promise<string[]>;
80
- /** This party's strands plus the node's current control-connection count. */
81
- listStrands(): Promise<StrandListSnapshot>;
82
- /**
83
- * Remove this party's participation in one strand.
84
- *
85
- * `?confirm=1` is appended **only** when the caller asked for it. The node
86
- * refuses an unconfirmed closed-strand removal with `confirmation_required`;
87
- * that refusal is surfaced, never retried with the flag added — the row holds
88
- * this party's membership key for the strand and nothing else does.
89
- */
90
- removeStrand(strandId: string, opts: {
91
- confirm: boolean;
92
- }): Promise<StrandRemovalResult>;
93
- /**
94
- * Mint a seed authorizing a drone — a provider-hosted / donated node — to join
95
- * this node's cadre. The node signs the seed with its own authority key; only
96
- * the signed, public `encodedSeed` is returned (the private key never leaves
97
- * the node). This is the requester ("phone") side of the node-donation flow:
98
- * the donor host presents the returned seed to the donated node's `POST /seed`.
99
- */
100
- addDrone(options: {
101
- dronePeerId: string;
102
- droneMultiaddrs: string[];
103
- }): Promise<DroneInitResult>;
104
- /** Push the NAT-resolved addresses the node should embed in future invites. */
105
- pushInviteAddresses(addresses: string[]): Promise<void>;
106
- private resolveEndpoint;
107
- private request;
108
- private parseEnvelope;
109
- }
110
- export {};
@@ -1,184 +0,0 @@
1
- /**
2
- * HTTP client for the owner node's loopback admin channel (the 6.6
3
- * `cadre-node-admin-channel` contract).
4
- *
5
- * cadre-host's manager process holds no in-process `CadreNode`; it spawns the
6
- * admin's owner node as a managed child (see `HostProcessOrchestrator`)
7
- * and delegates all owner/membership/identity operations to it over this
8
- * client. The client implements **all three** trimmed `CadreNodeLike`
9
- * interfaces — the trust-circle one (`auth/trust-circle.ts`), the NAT one
10
- * (`nat/nat-service.ts`), and the strand one (`strands/strand-service.ts`) —
11
- * plus `pushInviteAddresses` and `addDrone` (the node-donation requester side).
12
- *
13
- * Transport: `Authorization: Bearer <token>` against
14
- * `http://127.0.0.1:<adminPort>`. Every response uses the cadre-provider
15
- * envelope `{ ok: true, data }` / `{ ok: false, error: { code, message } }`.
16
- * A refused connection, a transport error, or any non-2xx response surfaces
17
- * as {@link OwnerNodeUnavailableError}; the trust-circle / NAT services
18
- * translate that into a `node_unavailable` domain error so the management API
19
- * returns a clear 503 rather than a raw 500.
20
- */
21
- import debug from 'debug';
22
- const log = debug('cadre:host:owner-client');
23
- /**
24
- * Raised when the owner node's admin channel can't be reached or returns
25
- * a non-success response. Carries the node's stable error `code` when one was
26
- * present in the envelope (e.g. `not_ready`, `not_authorized`).
27
- */
28
- export class OwnerNodeUnavailableError extends Error {
29
- constructor(message, nodeCode) {
30
- super(message);
31
- this.name = 'OwnerNodeUnavailableError';
32
- if (nodeCode !== undefined)
33
- this.nodeCode = nodeCode;
34
- }
35
- }
36
- export class OwnerNodeClient {
37
- /**
38
- * @param endpoint Either a fixed `{ baseUrl, token }` or a getter returning
39
- * the current endpoint (pass `orchestrator.getOwnerAdminEndpoint`
40
- * bound, so a restart's new bearer token is picked up automatically).
41
- */
42
- constructor(endpoint, opts = {}) {
43
- this.endpointSource = endpoint;
44
- this.fetchImpl = opts.fetch ?? fetch;
45
- }
46
- // --- trust-circle CadreNodeLike ---
47
- async createInvite(token, expiresInMs) {
48
- const body = {};
49
- if (token !== undefined)
50
- body.token = token;
51
- if (expiresInMs !== undefined)
52
- body.expiresInMs = expiresInMs;
53
- return await this.request('POST', '/admin/invites', body);
54
- }
55
- async acceptPhone(options, issuedInvite) {
56
- const body = { phonePeerId: options.phonePeerId };
57
- if (options.token !== undefined)
58
- body.token = options.token;
59
- if (issuedInvite !== undefined)
60
- body.issuedInvite = issuedInvite;
61
- await this.request('POST', '/admin/accept-phone', body);
62
- }
63
- async removePeer(peerId) {
64
- await this.request('DELETE', `/admin/members/${encodeURIComponent(peerId)}`);
65
- }
66
- /**
67
- * Encode an invite for out-of-band delivery. The admin contract has no
68
- * encode route (the mint route already returns `encodedInvite`), so this
69
- * mirrors cadre-core's encoding (`base64url(JSON.stringify(invite))`).
70
- */
71
- encodeInvite(invite) {
72
- return Buffer.from(JSON.stringify(invite), 'utf8').toString('base64url');
73
- }
74
- async listMembers() {
75
- const data = await this.request('GET', '/admin/members');
76
- return data.members;
77
- }
78
- async isMember(peerId) {
79
- const data = await this.request('GET', `/admin/members/${encodeURIComponent(peerId)}`);
80
- return data.member;
81
- }
82
- /** Authorized-membership surface (excludes self) — see {@link listMembers} for the addressable one. */
83
- async listAuthorizedMembers() {
84
- const data = await this.request('GET', '/admin/authorized-members');
85
- return data.members;
86
- }
87
- async isAuthorizedMember(peerId) {
88
- const data = await this.request('GET', `/admin/authorized-members/${encodeURIComponent(peerId)}`);
89
- return data.member;
90
- }
91
- // --- NAT CadreNodeLike ---
92
- async getPeerId() {
93
- const data = await this.request('GET', '/admin/identity');
94
- return data.peerId ?? '';
95
- }
96
- async getMultiaddrs() {
97
- const data = await this.request('GET', '/admin/multiaddrs');
98
- return data.multiaddrs;
99
- }
100
- // --- strand CadreNodeLike ---
101
- /** This party's strands plus the node's current control-connection count. */
102
- async listStrands() {
103
- return await this.request('GET', '/admin/strands');
104
- }
105
- /**
106
- * Remove this party's participation in one strand.
107
- *
108
- * `?confirm=1` is appended **only** when the caller asked for it. The node
109
- * refuses an unconfirmed closed-strand removal with `confirmation_required`;
110
- * that refusal is surfaced, never retried with the flag added — the row holds
111
- * this party's membership key for the strand and nothing else does.
112
- */
113
- async removeStrand(strandId, opts) {
114
- const query = opts.confirm ? '?confirm=1' : '';
115
- return await this.request('DELETE', `/admin/strands/${encodeURIComponent(strandId)}${query}`);
116
- }
117
- // --- drone seeding (node-donation requester side) ---
118
- /**
119
- * Mint a seed authorizing a drone — a provider-hosted / donated node — to join
120
- * this node's cadre. The node signs the seed with its own authority key; only
121
- * the signed, public `encodedSeed` is returned (the private key never leaves
122
- * the node). This is the requester ("phone") side of the node-donation flow:
123
- * the donor host presents the returned seed to the donated node's `POST /seed`.
124
- */
125
- async addDrone(options) {
126
- return await this.request('POST', '/admin/add-drone', {
127
- dronePeerId: options.dronePeerId,
128
- droneMultiaddrs: options.droneMultiaddrs,
129
- });
130
- }
131
- // --- push-model invite addresses ---
132
- /** Push the NAT-resolved addresses the node should embed in future invites. */
133
- async pushInviteAddresses(addresses) {
134
- await this.request('PUT', '/admin/invite-addresses', { addresses });
135
- }
136
- // --- internals ---
137
- resolveEndpoint() {
138
- const ep = typeof this.endpointSource === 'function' ? this.endpointSource() : this.endpointSource;
139
- if (!ep) {
140
- throw new OwnerNodeUnavailableError('Owner node admin endpoint is not available');
141
- }
142
- return ep;
143
- }
144
- async request(method, path, body) {
145
- const ep = this.resolveEndpoint();
146
- const headers = { authorization: `Bearer ${ep.token}` };
147
- const init = { method, headers };
148
- if (body !== undefined) {
149
- headers['content-type'] = 'application/json';
150
- init.body = JSON.stringify(body);
151
- }
152
- let res;
153
- try {
154
- res = await this.fetchImpl(`${ep.baseUrl}${path}`, init);
155
- }
156
- catch (err) {
157
- const message = err instanceof Error ? err.message : String(err);
158
- log('admin %s %s transport error: %s', method, path, message);
159
- throw new OwnerNodeUnavailableError(`Owner node unreachable: ${message}`);
160
- }
161
- const envelope = await this.parseEnvelope(res);
162
- if (!res.ok || !envelope.ok) {
163
- const code = envelope.error?.code;
164
- const message = envelope.error?.message ?? `admin ${method} ${path} → HTTP ${res.status}`;
165
- log('admin %s %s failed: [%s] %s', method, path, code ?? res.status, message);
166
- throw new OwnerNodeUnavailableError(message, code);
167
- }
168
- return envelope.data;
169
- }
170
- async parseEnvelope(res) {
171
- try {
172
- const parsed = await res.json();
173
- if (parsed && typeof parsed === 'object') {
174
- return parsed;
175
- }
176
- }
177
- catch {
178
- // Non-JSON body — fall through to an empty envelope; status drives the
179
- // ok/non-ok decision in the caller.
180
- }
181
- return {};
182
- }
183
- }
184
- //# sourceMappingURL=owner-node-client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"owner-node-client.js","sourceRoot":"","sources":["../../src/owner/owner-node-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,MAAM,GAAG,GAAG,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAE7C;;;;GAIG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAIlD,YAAY,OAAe,EAAE,QAAiB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACvD,CAAC;CACF;AAaD,MAAM,OAAO,eAAe;IAK1B;;;;OAIG;IACH,YAAY,QAAwB,EAAE,OAA+B,EAAE;QACrE,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;IACvC,CAAC;IAED,qCAAqC;IAErC,KAAK,CAAC,YAAY,CAChB,KAAc,EACd,WAAoB;QAEpB,MAAM,IAAI,GAA4B,EAAE,CAAC;QACzC,IAAI,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