@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.
Files changed (352) hide show
  1. package/README.md +347 -423
  2. package/dist/bin/host.d.ts +6 -3
  3. package/dist/bin/host.js +332 -524
  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 +54 -0
  9. package/dist/bin/nat-output.js +138 -0
  10. package/dist/bin/nat-output.js.map +1 -0
  11. package/dist/bin/ui-access.d.ts +22 -0
  12. package/dist/bin/ui-access.js +44 -0
  13. package/dist/bin/ui-access.js.map +1 -0
  14. package/dist/hosted/claim-details.d.ts +66 -0
  15. package/dist/hosted/claim-details.js +60 -0
  16. package/dist/hosted/claim-details.js.map +1 -0
  17. package/dist/hosted/hosted-node-service.d.ts +325 -0
  18. package/dist/hosted/hosted-node-service.js +678 -0
  19. package/dist/hosted/hosted-node-service.js.map +1 -0
  20. package/dist/hosted/hosted-node-store.d.ts +40 -0
  21. package/dist/hosted/hosted-node-store.js +126 -0
  22. package/dist/hosted/hosted-node-store.js.map +1 -0
  23. package/dist/{donation/donation-supervisor.d.ts → hosted/hosted-node-supervisor.d.ts} +70 -53
  24. package/dist/hosted/hosted-node-supervisor.js +396 -0
  25. package/dist/hosted/hosted-node-supervisor.js.map +1 -0
  26. package/dist/hosted/hosted-node-watcher.d.ts +95 -0
  27. package/dist/hosted/hosted-node-watcher.js +260 -0
  28. package/dist/hosted/hosted-node-watcher.js.map +1 -0
  29. package/dist/hosted/index.d.ts +16 -0
  30. package/dist/hosted/index.js +13 -0
  31. package/dist/hosted/index.js.map +1 -0
  32. package/dist/hosted/node-status.d.ts +51 -0
  33. package/dist/hosted/node-status.js +77 -0
  34. package/dist/hosted/node-status.js.map +1 -0
  35. package/dist/hosted/types.d.ts +141 -0
  36. package/dist/hosted/types.js +22 -0
  37. package/dist/hosted/types.js.map +1 -0
  38. package/dist/index.d.ts +12 -24
  39. package/dist/index.js +9 -19
  40. package/dist/index.js.map +1 -1
  41. package/dist/installer/config.d.ts +27 -34
  42. package/dist/installer/config.js +46 -15
  43. package/dist/installer/config.js.map +1 -1
  44. package/dist/installer/index.d.ts +9 -19
  45. package/dist/installer/index.js +21 -85
  46. package/dist/installer/index.js.map +1 -1
  47. package/dist/installer/paths.d.ts +0 -2
  48. package/dist/installer/paths.js +0 -4
  49. package/dist/installer/paths.js.map +1 -1
  50. package/dist/installer/wizard.d.ts +12 -9
  51. package/dist/installer/wizard.js +15 -14
  52. package/dist/installer/wizard.js.map +1 -1
  53. package/dist/nat/address-resolver.d.ts +18 -17
  54. package/dist/nat/address-resolver.js +79 -25
  55. package/dist/nat/address-resolver.js.map +1 -1
  56. package/dist/nat/address-watch.d.ts +37 -0
  57. package/dist/nat/address-watch.js +84 -0
  58. package/dist/nat/address-watch.js.map +1 -0
  59. package/dist/nat/ddns/duckdns.d.ts +2 -1
  60. package/dist/nat/ddns/duckdns.js +5 -1
  61. package/dist/nat/ddns/duckdns.js.map +1 -1
  62. package/dist/nat/ddns/index.d.ts +6 -0
  63. package/dist/nat/ddns/index.js.map +1 -1
  64. package/dist/nat/index.d.ts +13 -9
  65. package/dist/nat/index.js +7 -5
  66. package/dist/nat/index.js.map +1 -1
  67. package/dist/nat/nat-service.d.ts +220 -77
  68. package/dist/nat/nat-service.js +653 -239
  69. package/dist/nat/nat-service.js.map +1 -1
  70. package/dist/nat/nat-store.d.ts +12 -5
  71. package/dist/nat/nat-store.js +124 -29
  72. package/dist/nat/nat-store.js.map +1 -1
  73. package/dist/nat/network-mode.d.ts +19 -0
  74. package/dist/nat/network-mode.js +32 -0
  75. package/dist/nat/network-mode.js.map +1 -0
  76. package/dist/nat/port-mapper.d.ts +83 -79
  77. package/dist/nat/port-mapper.js +148 -189
  78. package/dist/nat/port-mapper.js.map +1 -1
  79. package/dist/nat/reachability.d.ts +32 -15
  80. package/dist/nat/reachability.js +110 -22
  81. package/dist/nat/reachability.js.map +1 -1
  82. package/dist/nat/types.d.ts +98 -27
  83. package/dist/nat/types.js +8 -5
  84. package/dist/nat/types.js.map +1 -1
  85. package/dist/orchestrator/host-process-orchestrator.d.ts +32 -74
  86. package/dist/orchestrator/host-process-orchestrator.js +84 -233
  87. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  88. package/dist/{installer/identity.d.ts → orchestrator/identity-file.d.ts} +5 -5
  89. package/dist/{installer/identity.js → orchestrator/identity-file.js} +6 -6
  90. package/dist/orchestrator/identity-file.js.map +1 -0
  91. package/dist/orchestrator/index.d.ts +2 -3
  92. package/dist/orchestrator/index.js +1 -1
  93. package/dist/orchestrator/index.js.map +1 -1
  94. package/dist/orchestrator/node-identity.d.ts +6 -6
  95. package/dist/orchestrator/node-identity.js +7 -7
  96. package/dist/orchestrator/node-identity.js.map +1 -1
  97. package/dist/orchestrator/port-allocator.d.ts +5 -6
  98. package/dist/orchestrator/port-allocator.js +9 -11
  99. package/dist/orchestrator/port-allocator.js.map +1 -1
  100. package/dist/orchestrator/state-store.d.ts +3 -5
  101. package/dist/orchestrator/state-store.js +2 -10
  102. package/dist/orchestrator/state-store.js.map +1 -1
  103. package/dist/orchestrator/types.d.ts +33 -22
  104. package/dist/orchestrator/types.js.map +1 -1
  105. package/dist/package-version.d.ts +1 -0
  106. package/dist/package-version.js +4 -0
  107. package/dist/package-version.js.map +1 -0
  108. package/dist/server/error-handler.d.ts +5 -25
  109. package/dist/server/error-handler.js +11 -74
  110. package/dist/server/error-handler.js.map +1 -1
  111. package/dist/server/events/types.d.ts +7 -11
  112. package/dist/server/events/types.js +2 -1
  113. package/dist/server/events/types.js.map +1 -1
  114. package/dist/server/index.d.ts +11 -37
  115. package/dist/server/index.js +30 -48
  116. package/dist/server/index.js.map +1 -1
  117. package/dist/server/routes/hosted-nodes.d.ts +28 -0
  118. package/dist/server/routes/hosted-nodes.js +68 -0
  119. package/dist/server/routes/hosted-nodes.js.map +1 -0
  120. package/dist/server/routes/nat.d.ts +4 -1
  121. package/dist/server/routes/nat.js +13 -2
  122. package/dist/server/routes/nat.js.map +1 -1
  123. package/dist/server/routes/nodes.d.ts +6 -20
  124. package/dist/server/routes/nodes.js +7 -86
  125. package/dist/server/routes/nodes.js.map +1 -1
  126. package/dist/server/routes/settings.d.ts +3 -7
  127. package/dist/server/routes/settings.js +18 -8
  128. package/dist/server/routes/settings.js.map +1 -1
  129. package/dist/server/routes/status.d.ts +2 -25
  130. package/dist/server/routes/status.js +3 -43
  131. package/dist/server/routes/status.js.map +1 -1
  132. package/dist/server/server.js +8 -8
  133. package/dist/server/settings-store.d.ts +2 -2
  134. package/dist/server/settings-store.js +2 -2
  135. package/dist/server/static.js +1 -2
  136. package/dist/server/static.js.map +1 -1
  137. package/dist/ui/assets/index-BHd8CWZA.css +1 -0
  138. package/dist/ui/assets/index-Ccr2GjPT.js +23 -0
  139. package/dist/ui/assets/index-Ccr2GjPT.js.map +1 -0
  140. package/dist/ui/index.html +2 -2
  141. package/dist/update/index.d.ts +2 -2
  142. package/dist/update/index.js +2 -2
  143. package/dist/update/store.d.ts +1 -1
  144. package/dist/update/store.js +1 -1
  145. package/dist/update/types.d.ts +1 -1
  146. package/dist/update/types.js +1 -1
  147. package/package.json +5 -7
  148. package/src/__tests__/cli-nat.smoke.test.ts +219 -212
  149. package/src/__tests__/cli.smoke.test.ts +2 -2
  150. package/src/__tests__/global-setup.ts +2 -3
  151. package/src/__tests__/orchestrator-claim-secret.test.ts +111 -0
  152. package/src/__tests__/orchestrator-env-scrub.test.ts +160 -163
  153. package/src/__tests__/orchestrator-handle-contract.ts +134 -134
  154. package/src/__tests__/orchestrator-node-identity.test.ts +177 -203
  155. package/src/__tests__/orchestrator-ports.test.ts +124 -143
  156. package/src/__tests__/orchestrator-push.test.ts +138 -146
  157. package/src/__tests__/orchestrator.test.ts +1017 -1063
  158. package/src/__tests__/ui-access.test.ts +30 -0
  159. package/src/bin/host.ts +397 -572
  160. package/src/bin/join-output.ts +120 -0
  161. package/src/bin/nat-output.ts +188 -0
  162. package/src/bin/ui-access.ts +50 -0
  163. package/src/{donation → hosted}/__tests__/fake-orchestrator.test.ts +172 -173
  164. package/src/{donation → hosted}/__tests__/fake-orchestrator.ts +43 -23
  165. package/src/hosted/__tests__/hosted-node-service.test.ts +708 -0
  166. package/src/hosted/__tests__/hosted-node-supervisor.test.ts +475 -0
  167. package/src/hosted/__tests__/test-invitation.ts +33 -0
  168. package/src/hosted/claim-details.ts +103 -0
  169. package/src/hosted/hosted-node-service.ts +814 -0
  170. package/src/hosted/hosted-node-store.ts +144 -0
  171. package/src/hosted/hosted-node-supervisor.ts +439 -0
  172. package/src/hosted/hosted-node-watcher.ts +288 -0
  173. package/src/hosted/index.ts +53 -0
  174. package/src/hosted/node-status.ts +97 -0
  175. package/src/hosted/types.ts +160 -0
  176. package/src/index.ts +72 -91
  177. package/src/installer/__tests__/config.test.ts +15 -40
  178. package/src/installer/__tests__/installer.smoke.test.ts +184 -263
  179. package/src/installer/__tests__/wizard.test.ts +25 -13
  180. package/src/installer/config.ts +201 -175
  181. package/src/installer/index.ts +252 -327
  182. package/src/installer/paths.ts +104 -109
  183. package/src/installer/wizard.ts +24 -26
  184. package/src/nat/__tests__/address-resolver.test.ts +107 -82
  185. package/src/nat/__tests__/nat-service.test.ts +608 -515
  186. package/src/nat/__tests__/nat-store.test.ts +49 -12
  187. package/src/nat/__tests__/network-mode.test.ts +38 -0
  188. package/src/nat/__tests__/port-mapper.test.ts +30 -191
  189. package/src/nat/__tests__/reachability.test.ts +96 -13
  190. package/src/nat/address-resolver.ts +94 -52
  191. package/src/nat/address-watch.ts +92 -0
  192. package/src/nat/ddns/duckdns.ts +5 -1
  193. package/src/nat/ddns/index.ts +6 -0
  194. package/src/nat/index.ts +33 -13
  195. package/src/nat/nat-service.ts +942 -501
  196. package/src/nat/nat-store.ts +126 -31
  197. package/src/nat/network-mode.ts +36 -0
  198. package/src/nat/port-mapper.ts +241 -329
  199. package/src/nat/reachability.ts +155 -34
  200. package/src/nat/types.ts +110 -37
  201. package/src/{installer/__tests__/identity.test.ts → orchestrator/__tests__/identity-file.test.ts} +34 -34
  202. package/src/orchestrator/__tests__/node-identity.test.ts +62 -62
  203. package/src/orchestrator/host-process-orchestrator.ts +1089 -1260
  204. package/src/{installer/identity.ts → orchestrator/identity-file.ts} +56 -56
  205. package/src/orchestrator/index.ts +9 -10
  206. package/src/orchestrator/node-identity.ts +41 -41
  207. package/src/orchestrator/port-allocator.ts +71 -73
  208. package/src/orchestrator/state-store.ts +76 -90
  209. package/src/orchestrator/types.ts +34 -23
  210. package/src/package-version.ts +4 -0
  211. package/src/server/__tests__/bus.test.ts +38 -38
  212. package/src/server/__tests__/error-handler.test.ts +81 -118
  213. package/src/server/__tests__/fakes.ts +15 -18
  214. package/src/server/__tests__/hosted-nodes-route.test.ts +161 -0
  215. package/src/server/__tests__/nodes-route.test.ts +114 -283
  216. package/src/server/__tests__/publishers.test.ts +193 -180
  217. package/src/server/__tests__/server.smoke.test.ts +134 -223
  218. package/src/server/__tests__/settings-route.test.ts +210 -195
  219. package/src/server/__tests__/sse-route.test.ts +119 -119
  220. package/src/server/__tests__/status-route.test.ts +82 -121
  221. package/src/server/error-handler.ts +112 -178
  222. package/src/server/events/types.ts +20 -24
  223. package/src/server/index.ts +223 -267
  224. package/src/server/routes/hosted-nodes.ts +83 -0
  225. package/src/server/routes/nat.ts +75 -63
  226. package/src/server/routes/nodes.ts +96 -188
  227. package/src/server/routes/settings.ts +20 -15
  228. package/src/server/routes/status.ts +5 -67
  229. package/src/server/server.ts +8 -8
  230. package/src/server/settings-store.ts +2 -2
  231. package/src/server/static.ts +1 -2
  232. package/src/update/index.ts +2 -2
  233. package/src/update/store.ts +1 -1
  234. package/src/update/types.ts +1 -1
  235. package/dist/auth/duration.d.ts +0 -1
  236. package/dist/auth/duration.js +0 -32
  237. package/dist/auth/duration.js.map +0 -1
  238. package/dist/auth/index.d.ts +0 -11
  239. package/dist/auth/index.js +0 -9
  240. package/dist/auth/index.js.map +0 -1
  241. package/dist/auth/self-label.d.ts +0 -36
  242. package/dist/auth/self-label.js +0 -57
  243. package/dist/auth/self-label.js.map +0 -1
  244. package/dist/auth/trust-circle-store.d.ts +0 -26
  245. package/dist/auth/trust-circle-store.js +0 -129
  246. package/dist/auth/trust-circle-store.js.map +0 -1
  247. package/dist/auth/trust-circle.d.ts +0 -156
  248. package/dist/auth/trust-circle.js +0 -307
  249. package/dist/auth/trust-circle.js.map +0 -1
  250. package/dist/auth/types.d.ts +0 -84
  251. package/dist/auth/types.js +0 -24
  252. package/dist/auth/types.js.map +0 -1
  253. package/dist/donation/donation-service.d.ts +0 -389
  254. package/dist/donation/donation-service.js +0 -828
  255. package/dist/donation/donation-service.js.map +0 -1
  256. package/dist/donation/donation-store.d.ts +0 -51
  257. package/dist/donation/donation-store.js +0 -152
  258. package/dist/donation/donation-store.js.map +0 -1
  259. package/dist/donation/donation-supervisor.js +0 -364
  260. package/dist/donation/donation-supervisor.js.map +0 -1
  261. package/dist/donation/grant-service.d.ts +0 -80
  262. package/dist/donation/grant-service.js +0 -210
  263. package/dist/donation/grant-service.js.map +0 -1
  264. package/dist/donation/grant-store.d.ts +0 -38
  265. package/dist/donation/grant-store.js +0 -135
  266. package/dist/donation/grant-store.js.map +0 -1
  267. package/dist/donation/index.d.ts +0 -20
  268. package/dist/donation/index.js +0 -17
  269. package/dist/donation/index.js.map +0 -1
  270. package/dist/donation/types.d.ts +0 -224
  271. package/dist/donation/types.js +0 -40
  272. package/dist/donation/types.js.map +0 -1
  273. package/dist/installer/identity.js.map +0 -1
  274. package/dist/owner/index.d.ts +0 -11
  275. package/dist/owner/index.js +0 -11
  276. package/dist/owner/index.js.map +0 -1
  277. package/dist/owner/owner-node-client.d.ts +0 -110
  278. package/dist/owner/owner-node-client.js +0 -184
  279. package/dist/owner/owner-node-client.js.map +0 -1
  280. package/dist/server/routes/bootstrap-node-validation.d.ts +0 -115
  281. package/dist/server/routes/bootstrap-node-validation.js +0 -197
  282. package/dist/server/routes/bootstrap-node-validation.js.map +0 -1
  283. package/dist/server/routes/grants-admin.d.ts +0 -29
  284. package/dist/server/routes/grants-admin.js +0 -58
  285. package/dist/server/routes/grants-admin.js.map +0 -1
  286. package/dist/server/routes/grants.d.ts +0 -28
  287. package/dist/server/routes/grants.js +0 -165
  288. package/dist/server/routes/grants.js.map +0 -1
  289. package/dist/server/routes/provision-request-validation.d.ts +0 -45
  290. package/dist/server/routes/provision-request-validation.js +0 -97
  291. package/dist/server/routes/provision-request-validation.js.map +0 -1
  292. package/dist/server/routes/strands.d.ts +0 -20
  293. package/dist/server/routes/strands.js +0 -38
  294. package/dist/server/routes/strands.js.map +0 -1
  295. package/dist/server/routes/trust-circle.d.ts +0 -17
  296. package/dist/server/routes/trust-circle.js +0 -35
  297. package/dist/server/routes/trust-circle.js.map +0 -1
  298. package/dist/strands/index.d.ts +0 -7
  299. package/dist/strands/index.js +0 -6
  300. package/dist/strands/index.js.map +0 -1
  301. package/dist/strands/strand-service.d.ts +0 -50
  302. package/dist/strands/strand-service.js +0 -103
  303. package/dist/strands/strand-service.js.map +0 -1
  304. package/dist/strands/types.d.ts +0 -93
  305. package/dist/strands/types.js +0 -23
  306. package/dist/strands/types.js.map +0 -1
  307. package/dist/ui/assets/index-C6nELNfC.js +0 -23
  308. package/dist/ui/assets/index-C6nELNfC.js.map +0 -1
  309. package/dist/ui/assets/index-TtIYSeZO.css +0 -1
  310. package/src/__tests__/cli-invite.smoke.test.ts +0 -192
  311. package/src/__tests__/host-owner.smoke.test.ts +0 -123
  312. package/src/__tests__/orchestrator-owner.test.ts +0 -234
  313. package/src/__tests__/orchestrator-pin-keys.test.ts +0 -152
  314. package/src/auth/__tests__/duration.test.ts +0 -28
  315. package/src/auth/__tests__/self-label.test.ts +0 -85
  316. package/src/auth/__tests__/trust-circle-integration.test.ts +0 -152
  317. package/src/auth/__tests__/trust-circle-store.test.ts +0 -115
  318. package/src/auth/__tests__/trust-circle.test.ts +0 -445
  319. package/src/auth/duration.ts +0 -33
  320. package/src/auth/index.ts +0 -21
  321. package/src/auth/self-label.ts +0 -74
  322. package/src/auth/trust-circle-store.ts +0 -155
  323. package/src/auth/trust-circle.ts +0 -395
  324. package/src/auth/types.ts +0 -99
  325. package/src/donation/__tests__/donation-service.test.ts +0 -1193
  326. package/src/donation/__tests__/donation-supervisor.test.ts +0 -548
  327. package/src/donation/__tests__/grant-service.test.ts +0 -213
  328. package/src/donation/__tests__/grant-store.test.ts +0 -113
  329. package/src/donation/donation-service.ts +0 -1033
  330. package/src/donation/donation-store.ts +0 -176
  331. package/src/donation/donation-supervisor.ts +0 -411
  332. package/src/donation/grant-service.ts +0 -252
  333. package/src/donation/grant-store.ts +0 -152
  334. package/src/donation/index.ts +0 -65
  335. package/src/donation/types.ts +0 -260
  336. package/src/owner/__tests__/owner-node-client.test.ts +0 -194
  337. package/src/owner/index.ts +0 -12
  338. package/src/owner/owner-node-client.ts +0 -259
  339. package/src/server/__tests__/bootstrap-node-validation.test.ts +0 -138
  340. package/src/server/__tests__/grants-admin-route.test.ts +0 -171
  341. package/src/server/__tests__/grants-route.test.ts +0 -394
  342. package/src/server/__tests__/strands-route.test.ts +0 -234
  343. package/src/server/routes/bootstrap-node-validation.ts +0 -206
  344. package/src/server/routes/grants-admin.ts +0 -74
  345. package/src/server/routes/grants.ts +0 -193
  346. package/src/server/routes/provision-request-validation.ts +0 -105
  347. package/src/server/routes/strands.ts +0 -54
  348. package/src/server/routes/trust-circle.ts +0 -49
  349. package/src/strands/__tests__/strand-service.test.ts +0 -165
  350. package/src/strands/index.ts +0 -14
  351. package/src/strands/strand-service.ts +0 -135
  352. package/src/strands/types.ts +0 -102
@@ -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
- * `/grants` is served to other people's clients, and sending the JSON content
128
- * type on every request, body or not, is a common client habit — the phone app
129
- * did it, and the refused body-less `DELETE /grants/:id` left the loan and its
130
- * node running. Every route that reads a body already reads `request.body ?? {}`,
131
- * so a route that needs a field still answers its own `invalid_request` naming it.
132
- * A 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 default
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` v2). This module
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 2. */
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
  }
@@ -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">/auth/*</span>, <span class="endpoint">/nat/*</span>, <span class="endpoint">/update/*</span></li>
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>
@@ -305,8 +305,8 @@ export class UpdateService {
305
305
  }
306
306
 
307
307
  /**
308
- * Typed handler facade — mirrors `createTrustCircleHandlers` /
309
- * `createNatHandlers`. The local-UI ticket consumes these.
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 {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Atomic JSON store for `<dataDir>/update-state.json`.
3
3
  *
4
- * Mirrors `TrustCircleStore` / `NatStore`: load on demand, write to
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
  */
@@ -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 trust-circle and NAT (handlers
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
 
@@ -1 +0,0 @@
1
- export declare function parseDuration(input: string): number;
@@ -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"}
@@ -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';
@@ -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
@@ -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>;
@@ -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
@@ -1 +0,0 @@
1
- {"version":3,"file":"self-label.js","sourceRoot":"","sources":["../../src/auth/self-label.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,GAAG,GAAG,KAAK,CAAC,8BAA8B,CAAC,CAAC;AAElD,qEAAqE;AACrE,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AAWxC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAA4B;IAChE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IAE3C,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;IACjC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,GAAG,CAAC,8CAA8C,CAAC,CAAC;QACpD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;QACzC,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC5C,GAAG,CAAC,2DAA2D,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACxF,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;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,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AC;IAC9C,MAAM,GAAG,GAAG,CAA4B,CAAC;IACzC,IAAI,GAAG,CAAC,OAAO,KAAK,YAAY;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,OAAO,GAAG,CAAC,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;