home-hosted 0.13.0 → 0.20.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 (485) hide show
  1. package/README.md +117 -322
  2. package/bin/home-hosted.mjs +41 -0
  3. package/dist/chunks/account-DiLrSyww.js +359 -0
  4. package/dist/chunks/account-DiLrSyww.js.map +1 -0
  5. package/dist/chunks/add-DEIYVkNK.js +183 -0
  6. package/dist/chunks/add-DEIYVkNK.js.map +1 -0
  7. package/dist/chunks/{archive-DP-XQR8X.js → archive-DFi3qK1c.js} +25 -73
  8. package/dist/chunks/archive-DFi3qK1c.js.map +1 -0
  9. package/dist/chunks/{atomic-C1PfJpE7.js → atomic-SZUwDtGD.js} +3 -6
  10. package/dist/chunks/atomic-SZUwDtGD.js.map +1 -0
  11. package/dist/chunks/{backup-CZcVca2a.js → backup-DnyxIzw0.js} +110 -190
  12. package/dist/chunks/backup-DnyxIzw0.js.map +1 -0
  13. package/dist/chunks/backups-BrrN6cwW.js +2203 -0
  14. package/dist/chunks/backups-BrrN6cwW.js.map +1 -0
  15. package/dist/chunks/bind-DIxrnUst.js +43 -0
  16. package/dist/chunks/bind-DIxrnUst.js.map +1 -0
  17. package/dist/chunks/config-text-DxMOQQnk.js +34 -0
  18. package/dist/chunks/config-text-DxMOQQnk.js.map +1 -0
  19. package/dist/chunks/{contracts-CMBD1TF9.js → contracts-CxZ7u1L3.js} +1239 -1454
  20. package/dist/chunks/contracts-CxZ7u1L3.js.map +1 -0
  21. package/dist/chunks/daemon-BAAYUYQC.js +211 -0
  22. package/dist/chunks/daemon-BAAYUYQC.js.map +1 -0
  23. package/dist/chunks/daemon-log-Ccu-69vB.js +179 -0
  24. package/dist/chunks/daemon-log-Ccu-69vB.js.map +1 -0
  25. package/dist/chunks/deploy-CggSOEkq.js +144 -0
  26. package/dist/chunks/deploy-CggSOEkq.js.map +1 -0
  27. package/dist/chunks/{docker-Cy9Lyvda.js → docker--Un0uLfF.js} +32 -68
  28. package/dist/chunks/docker--Un0uLfF.js.map +1 -0
  29. package/dist/chunks/{down-pKbGCW9d.js → down-CpIN7LEQ.js} +34 -94
  30. package/dist/chunks/down-CpIN7LEQ.js.map +1 -0
  31. package/dist/chunks/exposure-CDJNvOCK.js +229 -0
  32. package/dist/chunks/exposure-CDJNvOCK.js.map +1 -0
  33. package/dist/chunks/import-Bd4VZH0f.js +205 -0
  34. package/dist/chunks/import-Bd4VZH0f.js.map +1 -0
  35. package/dist/chunks/import-plan--fDS_l5r.js +147 -0
  36. package/dist/chunks/import-plan--fDS_l5r.js.map +1 -0
  37. package/dist/chunks/import-write-BTfbeV26.js +42 -0
  38. package/dist/chunks/import-write-BTfbeV26.js.map +1 -0
  39. package/dist/chunks/{init-BZ7hK9Vf.js → init-Bv3oH65x.js} +14 -50
  40. package/dist/chunks/init-Bv3oH65x.js.map +1 -0
  41. package/dist/chunks/job-CYOdN6Ub.js +341 -0
  42. package/dist/chunks/job-CYOdN6Ub.js.map +1 -0
  43. package/dist/chunks/jobs-BX4ahcfh.js +489 -0
  44. package/dist/chunks/jobs-BX4ahcfh.js.map +1 -0
  45. package/dist/chunks/last-stop-DD3lHwo_.js +42 -0
  46. package/dist/chunks/last-stop-DD3lHwo_.js.map +1 -0
  47. package/dist/chunks/layout-D0ysDNav.js +18 -0
  48. package/dist/chunks/layout-D0ysDNav.js.map +1 -0
  49. package/dist/chunks/lazy-kfcBNeqj.js +48 -0
  50. package/dist/chunks/lazy-kfcBNeqj.js.map +1 -0
  51. package/dist/chunks/log-buffer-B7jmn7ts.js +110 -0
  52. package/dist/chunks/log-buffer-B7jmn7ts.js.map +1 -0
  53. package/dist/chunks/log-files-CZL2UhuE.js +488 -0
  54. package/dist/chunks/log-files-CZL2UhuE.js.map +1 -0
  55. package/dist/chunks/{logger-B5U4GD3j.js → logger-BnrKTBHQ.js} +2 -6
  56. package/dist/chunks/logger-BnrKTBHQ.js.map +1 -0
  57. package/dist/chunks/{logs---TI_bxM.js → logs-DxKI6OW2.js} +23 -73
  58. package/dist/chunks/logs-DxKI6OW2.js.map +1 -0
  59. package/dist/chunks/ls-BseUHy_m.js +128 -0
  60. package/dist/chunks/ls-BseUHy_m.js.map +1 -0
  61. package/dist/chunks/migrate-D4w_dXDm.js +268 -0
  62. package/dist/chunks/migrate-D4w_dXDm.js.map +1 -0
  63. package/dist/chunks/{nanny-B-Eu0sFW.js → nanny-BWh7nuvv.js} +21 -14
  64. package/dist/chunks/nanny-BWh7nuvv.js.map +1 -0
  65. package/dist/chunks/{nanny-ChMtq1Zl.js → nanny-BjF2-1pv.js} +3 -3
  66. package/dist/chunks/{nanny-ChMtq1Zl.js.map → nanny-BjF2-1pv.js.map} +1 -1
  67. package/dist/chunks/nanny-DGTXVq5d.js +806 -0
  68. package/dist/chunks/nanny-DGTXVq5d.js.map +1 -0
  69. package/dist/chunks/{nanny-sweep-DErnlPY1.js → nanny-sweep-hjmZ_p7S.js} +14 -24
  70. package/dist/chunks/nanny-sweep-hjmZ_p7S.js.map +1 -0
  71. package/dist/chunks/{nearest-6KgQEDUe.js → nearest-DOx4jySJ.js} +2 -10
  72. package/dist/chunks/nearest-DOx4jySJ.js.map +1 -0
  73. package/dist/chunks/{parse-DhmG26fI.js → parse-DVMPLUDe.js} +47 -72
  74. package/dist/chunks/parse-DVMPLUDe.js.map +1 -0
  75. package/dist/chunks/password-policy-Clq6PGE-.js +9 -0
  76. package/dist/chunks/password-policy-Clq6PGE-.js.map +1 -0
  77. package/dist/chunks/{paths-CGlGDrOU.js → paths-C34-TJLh.js} +32 -56
  78. package/dist/chunks/paths-C34-TJLh.js.map +1 -0
  79. package/dist/chunks/{port-B8WBTRMk.js → port-CnsrxKNR.js} +27 -71
  80. package/dist/chunks/port-CnsrxKNR.js.map +1 -0
  81. package/dist/chunks/process-CboOFPU_.js +192 -0
  82. package/dist/chunks/process-CboOFPU_.js.map +1 -0
  83. package/dist/chunks/{restart-Des4DrAN.js → restart-C0J8dZ2L.js} +11 -29
  84. package/dist/chunks/restart-C0J8dZ2L.js.map +1 -0
  85. package/dist/chunks/run-deploy-DoNDvwT4.js +91 -0
  86. package/dist/chunks/run-deploy-DoNDvwT4.js.map +1 -0
  87. package/dist/chunks/{schema-B240VXcV.js → schema-CZ6f-PHD.js} +7 -20
  88. package/dist/chunks/schema-CZ6f-PHD.js.map +1 -0
  89. package/dist/chunks/secret-MY397r90.js +219 -0
  90. package/dist/chunks/secret-MY397r90.js.map +1 -0
  91. package/dist/chunks/secrets-CG5N4lwY.js +1061 -0
  92. package/dist/chunks/secrets-CG5N4lwY.js.map +1 -0
  93. package/dist/chunks/server-Dm_dXfTW.js +255 -0
  94. package/dist/chunks/server-Dm_dXfTW.js.map +1 -0
  95. package/dist/chunks/server-attention-UQwYXqKe.js +10 -0
  96. package/dist/chunks/server-attention-UQwYXqKe.js.map +1 -0
  97. package/dist/chunks/server-create-D7nvhgBd.js +96 -0
  98. package/dist/chunks/server-create-D7nvhgBd.js.map +1 -0
  99. package/dist/chunks/server-ids-BEQD2rFz.js +23 -0
  100. package/dist/chunks/server-ids-BEQD2rFz.js.map +1 -0
  101. package/dist/chunks/server-vars-DMYmHutL.js +27 -0
  102. package/dist/chunks/server-vars-DMYmHutL.js.map +1 -0
  103. package/dist/chunks/service-C8l-ewNA.js +585 -0
  104. package/dist/chunks/service-C8l-ewNA.js.map +1 -0
  105. package/dist/chunks/{settings-xu-XTfWg.js → settings-CtYDs5PX.js} +62 -78
  106. package/dist/chunks/settings-CtYDs5PX.js.map +1 -0
  107. package/dist/chunks/{setup-temp-CAN4_bA-.js → setup-temp-TAtDmMMU.js} +43 -37
  108. package/dist/chunks/setup-temp-TAtDmMMU.js.map +1 -0
  109. package/dist/chunks/shape-CDGeYl_J.js +9 -0
  110. package/dist/chunks/shape-CDGeYl_J.js.map +1 -0
  111. package/dist/chunks/{src-BtWMFmzZ.js → src-BnzkVy_M.js} +12548 -10576
  112. package/dist/chunks/src-BnzkVy_M.js.map +1 -0
  113. package/dist/chunks/{status-DT1EsA-B.js → status-efbbfYZQ.js} +53 -26
  114. package/dist/chunks/status-efbbfYZQ.js.map +1 -0
  115. package/dist/chunks/store-Bs_Lljjm.js +2082 -0
  116. package/dist/chunks/store-Bs_Lljjm.js.map +1 -0
  117. package/dist/chunks/template-xan58bJh.js +28 -0
  118. package/dist/chunks/template-xan58bJh.js.map +1 -0
  119. package/dist/chunks/token-DDeWfZA4.js +142 -0
  120. package/dist/chunks/token-DDeWfZA4.js.map +1 -0
  121. package/dist/chunks/{ui-D562aqw5.js → ui-BcIAtyxE.js} +68 -79
  122. package/dist/chunks/ui-BcIAtyxE.js.map +1 -0
  123. package/dist/chunks/{ui-dir-CsU3uLNV.js → ui-dir-ClCzVRc3.js} +3 -7
  124. package/dist/chunks/ui-dir-ClCzVRc3.js.map +1 -0
  125. package/dist/chunks/ui-format-CDvvqOoi.js +53 -0
  126. package/dist/chunks/ui-format-CDvvqOoi.js.map +1 -0
  127. package/dist/chunks/{ui-release-DKzVvlLd.js → ui-release-XbJ85pYI.js} +36 -38
  128. package/dist/chunks/ui-release-XbJ85pYI.js.map +1 -0
  129. package/dist/chunks/{ui-revert-EkBBwRTt.js → ui-revert-Dgawq7ze.js} +4 -4
  130. package/dist/chunks/ui-revert-Dgawq7ze.js.map +1 -0
  131. package/dist/chunks/{ui-switch-BnZTdMDd.js → ui-switch-CfQMbZ0g.js} +31 -38
  132. package/dist/chunks/ui-switch-CfQMbZ0g.js.map +1 -0
  133. package/dist/chunks/{ui-update-_xryLYxw.js → ui-update-B3PPivUm.js} +30 -48
  134. package/dist/chunks/ui-update-B3PPivUm.js.map +1 -0
  135. package/dist/chunks/ui-update-CAiH2tFb.js +109 -0
  136. package/dist/chunks/ui-update-CAiH2tFb.js.map +1 -0
  137. package/dist/chunks/{up-Pdz-l6IH.js → up-BQSnYxYd.js} +47 -53
  138. package/dist/chunks/up-BQSnYxYd.js.map +1 -0
  139. package/dist/chunks/{usage-DFrCVXpT.js → usage-KG8TeOio.js} +7 -20
  140. package/dist/chunks/usage-KG8TeOio.js.map +1 -0
  141. package/dist/chunks/{workspaces-DYcfvKV_.js → workspaces-D9akpzU8.js} +80 -68
  142. package/dist/chunks/workspaces-D9akpzU8.js.map +1 -0
  143. package/dist/chunks/{wsl-temperature-BiCI4iK6.js → wsl-temperature-D-_d4Yk1.js} +47 -42
  144. package/dist/chunks/wsl-temperature-D-_d4Yk1.js.map +1 -0
  145. package/dist/cli.js +306 -238
  146. package/dist/cli.js.map +1 -1
  147. package/dist/client.js +76 -29
  148. package/dist/client.js.map +1 -1
  149. package/dist/types/api/acme.d.ts +3 -7
  150. package/dist/types/api/auth/$.routes.d.ts +107 -16
  151. package/dist/types/api/backups.d.ts +5 -5
  152. package/dist/types/api/control.d.ts +747 -38
  153. package/dist/types/api/ddns.d.ts +13 -18
  154. package/dist/types/api/events.d.ts +9 -3
  155. package/dist/types/api/health.d.ts +2 -4
  156. package/dist/types/api/jobs.d.ts +438 -0
  157. package/dist/types/api/logs.d.ts +20 -0
  158. package/dist/types/api/metrics.d.ts +2 -5
  159. package/dist/types/api/notifications.d.ts +3 -6
  160. package/dist/types/api/proxy.d.ts +63 -23
  161. package/dist/types/api/server-ops.d.ts +17 -0
  162. package/dist/types/api/servers/$.routes.d.ts +418 -186
  163. package/dist/types/api/session-required.d.ts +16 -0
  164. package/dist/types/api/settings.d.ts +7 -7
  165. package/dist/types/api/state.d.ts +100 -10
  166. package/dist/types/api/static.d.ts +2 -2
  167. package/dist/types/api/tls.d.ts +2 -5
  168. package/dist/types/api/workspaces/$.routes.d.ts +186 -12
  169. package/dist/types/api/wsl-temperature.d.ts +4 -10
  170. package/dist/types/app.d.ts +4511 -2778
  171. package/dist/types/cli/account.d.ts +23 -0
  172. package/dist/types/cli/add.d.ts +96 -0
  173. package/dist/types/cli/args.d.ts +24 -35
  174. package/dist/types/cli/backup-offline.d.ts +2 -8
  175. package/dist/types/cli/backup.d.ts +12 -21
  176. package/dist/types/cli/down.d.ts +15 -41
  177. package/dist/types/cli/import-plan.d.ts +55 -0
  178. package/dist/types/cli/import-write.d.ts +5 -0
  179. package/dist/types/cli/import.d.ts +86 -0
  180. package/dist/types/cli/io.d.ts +26 -35
  181. package/dist/types/cli/job.d.ts +99 -0
  182. package/dist/types/cli/logs.d.ts +1 -10
  183. package/dist/types/cli/ls.d.ts +57 -0
  184. package/dist/types/cli/migrate.d.ts +31 -8
  185. package/dist/types/cli/nearest.d.ts +1 -9
  186. package/dist/types/cli/run-deploy.d.ts +36 -0
  187. package/dist/types/cli/secret.d.ts +90 -0
  188. package/dist/types/cli/server.d.ts +6 -15
  189. package/dist/types/cli/service.d.ts +135 -0
  190. package/dist/types/cli/setup-temp.d.ts +17 -13
  191. package/dist/types/cli/status.d.ts +7 -1
  192. package/dist/types/cli/token.d.ts +6 -0
  193. package/dist/types/cli/ui-switch.d.ts +3 -14
  194. package/dist/types/cli/ui-update.d.ts +3 -16
  195. package/dist/types/cli/up.d.ts +9 -22
  196. package/dist/types/cli/usage.d.ts +2 -6
  197. package/dist/types/cli.d.ts +1 -10
  198. package/dist/types/client.d.ts +4099 -1142
  199. package/dist/types/config/accounts.d.ts +16 -0
  200. package/dist/types/config/jobs.d.ts +68 -0
  201. package/dist/types/config/layout.d.ts +2 -8
  202. package/dist/types/config/migrations.d.ts +9 -41
  203. package/dist/types/config/parse.d.ts +8 -13
  204. package/dist/types/config/patch.d.ts +1 -6
  205. package/dist/types/config/schema.d.ts +16 -18
  206. package/dist/types/config/secret-parts.d.ts +6 -27
  207. package/dist/types/config/secrets.d.ts +167 -88
  208. package/dist/types/config/seed.d.ts +1 -6
  209. package/dist/types/config/server-ids.d.ts +2 -11
  210. package/dist/types/config/settings.d.ts +13 -49
  211. package/dist/types/config/store.d.ts +17 -54
  212. package/dist/types/config/workspaces.d.ts +24 -56
  213. package/dist/types/helpers/action-result.d.ts +18 -32
  214. package/dist/types/helpers/atomic.d.ts +1 -4
  215. package/dist/types/helpers/backoff.d.ts +0 -1
  216. package/dist/types/helpers/bind.d.ts +3 -11
  217. package/dist/types/helpers/config-text.d.ts +4 -19
  218. package/dist/types/helpers/cookies.d.ts +2 -7
  219. package/dist/types/helpers/copy-tree.d.ts +4 -12
  220. package/dist/types/helpers/daemon-log.d.ts +8 -33
  221. package/dist/types/helpers/daemon.d.ts +20 -70
  222. package/dist/types/helpers/deferred.d.ts +2 -4
  223. package/dist/types/helpers/env-file.d.ts +2 -7
  224. package/dist/types/helpers/error.d.ts +3 -14
  225. package/dist/types/helpers/event-stream.d.ts +18 -10
  226. package/dist/types/helpers/factory.d.ts +2 -3
  227. package/dist/types/helpers/last-stop.d.ts +5 -12
  228. package/dist/types/helpers/logger.d.ts +1 -5
  229. package/dist/types/helpers/open.d.ts +0 -1
  230. package/dist/types/helpers/openapi.d.ts +19 -5
  231. package/dist/types/helpers/paths.d.ts +18 -53
  232. package/dist/types/helpers/restore-lock.d.ts +2 -17
  233. package/dist/types/helpers/runtime.d.ts +3 -13
  234. package/dist/types/helpers/secret-compare.d.ts +2 -10
  235. package/dist/types/helpers/server-create.d.ts +15 -0
  236. package/dist/types/helpers/shell.d.ts +2 -16
  237. package/dist/types/helpers/sse.d.ts +8 -6
  238. package/dist/types/helpers/ui-dir.d.ts +1 -5
  239. package/dist/types/helpers/utf8-chunks.d.ts +2 -8
  240. package/dist/types/helpers/validate.d.ts +2 -4
  241. package/dist/types/helpers/validator.d.ts +8 -4
  242. package/dist/types/helpers/version.d.ts +1 -6
  243. package/dist/types/helpers/workspace.d.ts +24 -16
  244. package/dist/types/index.d.ts +2 -3
  245. package/dist/types/middleware/auth.d.ts +8 -27
  246. package/dist/types/middleware/body-limit.d.ts +10 -0
  247. package/dist/types/middleware/host.d.ts +4 -23
  248. package/dist/types/middleware/loopback.d.ts +1 -8
  249. package/dist/types/middleware/token-scope.d.ts +34 -0
  250. package/dist/types/node-compat.d.ts +43 -0
  251. package/dist/types/openapi-reference.d.ts +4 -19
  252. package/dist/types/openapi.d.ts +5 -8
  253. package/dist/types/providers/archive.d.ts +8 -25
  254. package/dist/types/providers/backup-hook.d.ts +4 -19
  255. package/dist/types/providers/ddns/dyndns2.d.ts +0 -3
  256. package/dist/types/providers/ddns/index.d.ts +2 -3
  257. package/dist/types/providers/ddns/ip.d.ts +2 -12
  258. package/dist/types/providers/ddns/namecheap-api.d.ts +3 -2
  259. package/dist/types/providers/ddns/types.d.ts +6 -32
  260. package/dist/types/providers/ddns/zone.d.ts +1 -4
  261. package/dist/types/providers/docker.d.ts +18 -45
  262. package/dist/types/providers/entry-state.d.ts +4 -9
  263. package/dist/types/providers/health-check.d.ts +1 -5
  264. package/dist/types/providers/host.d.ts +33 -108
  265. package/dist/types/providers/identity.d.ts +9 -34
  266. package/dist/types/providers/log-tail.d.ts +14 -24
  267. package/dist/types/providers/nanny-sweep.d.ts +8 -25
  268. package/dist/types/providers/nanny.d.ts +16 -58
  269. package/dist/types/providers/port.d.ts +28 -83
  270. package/dist/types/providers/proc.d.ts +22 -80
  271. package/dist/types/providers/process.d.ts +12 -36
  272. package/dist/types/providers/proxy/admin.d.ts +11 -0
  273. package/dist/types/providers/proxy/types.d.ts +4 -16
  274. package/dist/types/providers/telegram.d.ts +1 -17
  275. package/dist/types/providers/ui-release.d.ts +15 -25
  276. package/dist/types/providers/webhook.d.ts +8 -29
  277. package/dist/types/providers/wsl-temperature.d.ts +13 -22
  278. package/dist/types/services/acme-challenge.d.ts +2 -16
  279. package/dist/types/services/auth.d.ts +65 -80
  280. package/dist/types/services/backups/archive-safety.d.ts +30 -0
  281. package/dist/types/services/backups/paths.d.ts +31 -0
  282. package/dist/types/services/backups.d.ts +61 -271
  283. package/dist/types/services/config-watch.d.ts +3 -15
  284. package/dist/types/services/control-server.d.ts +6 -10
  285. package/dist/types/services/ddns.d.ts +12 -13
  286. package/dist/types/services/dependencies.d.ts +3 -14
  287. package/dist/types/services/deploy.d.ts +34 -0
  288. package/dist/types/services/events.d.ts +15 -9
  289. package/dist/types/services/exposure.d.ts +13 -63
  290. package/dist/types/services/history.d.ts +5 -14
  291. package/dist/types/services/host-monitor.d.ts +6 -11
  292. package/dist/types/services/init.d.ts +5 -35
  293. package/dist/types/services/job-ledger.d.ts +27 -0
  294. package/dist/types/services/jobs.d.ts +113 -0
  295. package/dist/types/services/log-buffer.d.ts +7 -8
  296. package/dist/types/services/log-files.d.ts +12 -42
  297. package/dist/types/services/log-relay.d.ts +3 -13
  298. package/dist/types/services/nanny.d.ts +3 -10
  299. package/dist/types/services/notifications.d.ts +31 -61
  300. package/dist/types/services/panel.d.ts +32 -78
  301. package/dist/types/services/proxy-certificates/certificates.d.ts +31 -69
  302. package/dist/types/services/proxy-config.d.ts +15 -36
  303. package/dist/types/services/proxy-dns01.d.ts +14 -0
  304. package/dist/types/services/proxy.d.ts +73 -254
  305. package/dist/types/services/scheduler.d.ts +46 -0
  306. package/dist/types/services/state.d.ts +17 -8
  307. package/dist/types/services/supervisor/compose.d.ts +2 -6
  308. package/dist/types/services/supervisor/entry.d.ts +29 -32
  309. package/dist/types/services/supervisor/health.d.ts +8 -31
  310. package/dist/types/services/supervisor/job-run.d.ts +36 -0
  311. package/dist/types/services/supervisor/output.d.ts +13 -77
  312. package/dist/types/services/supervisor/persistent.d.ts +5 -11
  313. package/dist/types/services/supervisor/port-preflight.d.ts +4 -10
  314. package/dist/types/services/supervisor/records.d.ts +27 -60
  315. package/dist/types/services/supervisor/restart-required.d.ts +13 -0
  316. package/dist/types/services/supervisor/spawn.d.ts +3 -5
  317. package/dist/types/services/supervisor/view.d.ts +3 -1
  318. package/dist/types/services/supervisor.d.ts +31 -43
  319. package/dist/types/services/tls.d.ts +6 -17
  320. package/dist/types/services/ui-update.d.ts +19 -17
  321. package/dist/types/services/ui.d.ts +10 -19
  322. package/dist/types/shared/action-outcome.d.ts +2 -7
  323. package/dist/types/shared/api-client.d.ts +133 -177
  324. package/dist/types/shared/api-scopes.d.ts +17 -0
  325. package/dist/types/shared/backup-scope.d.ts +16 -90
  326. package/dist/types/shared/clone.d.ts +2 -11
  327. package/dist/types/shared/contracts/accounts.d.ts +99 -0
  328. package/dist/types/shared/contracts/backups.d.ts +219 -0
  329. package/dist/types/shared/contracts/ddns.d.ts +208 -0
  330. package/dist/types/shared/contracts/frames.d.ts +1395 -0
  331. package/dist/types/shared/contracts/index.d.ts +3 -0
  332. package/dist/types/shared/contracts/logs.d.ts +107 -0
  333. package/dist/types/shared/contracts/proxy.d.ts +303 -0
  334. package/dist/types/shared/contracts.d.ts +852 -1982
  335. package/dist/types/shared/cpu-scale.d.ts +3 -19
  336. package/dist/types/shared/crash-cause.d.ts +8 -0
  337. package/dist/types/shared/cron.d.ts +70 -0
  338. package/dist/types/shared/ddns-form.d.ts +9 -43
  339. package/dist/types/shared/endpoint.d.ts +1 -7
  340. package/dist/types/shared/error-codes.d.ts +438 -0
  341. package/dist/types/shared/error-message.d.ts +1 -7
  342. package/dist/types/shared/fields.d.ts +7 -17
  343. package/dist/types/shared/form-repair.d.ts +1 -5
  344. package/dist/types/shared/generated.d.ts +3 -19
  345. package/dist/types/shared/host-readings.d.ts +25 -128
  346. package/dist/types/shared/lazy.d.ts +1 -1
  347. package/dist/types/shared/live-frames.d.ts +2 -8
  348. package/dist/types/shared/live-series.d.ts +2 -8
  349. package/dist/types/shared/live-store.d.ts +4 -8
  350. package/dist/types/shared/log-download.d.ts +6 -0
  351. package/dist/types/shared/meta.d.ts +6 -0
  352. package/dist/types/shared/password-policy.d.ts +10 -0
  353. package/dist/types/shared/patch-diff.d.ts +13 -72
  354. package/dist/types/shared/port-reading.d.ts +18 -0
  355. package/dist/types/shared/probe-latency.d.ts +3 -21
  356. package/dist/types/shared/proxy-form.d.ts +33 -74
  357. package/dist/types/shared/proxy-validate.d.ts +11 -0
  358. package/dist/types/shared/query-params.d.ts +8 -0
  359. package/dist/types/shared/server-attention.d.ts +2 -27
  360. package/dist/types/shared/server-form.d.ts +15 -54
  361. package/dist/types/shared/server-key.d.ts +1 -12
  362. package/dist/types/shared/server-readings.d.ts +7 -32
  363. package/dist/types/shared/server-url.d.ts +9 -31
  364. package/dist/types/shared/shape.d.ts +1 -16
  365. package/dist/types/shared/stream-access.d.ts +2 -8
  366. package/dist/types/shared/ui-format.d.ts +25 -65
  367. package/docs/API.md +315 -107
  368. package/docs/BACKUPS.md +61 -56
  369. package/docs/CLI.md +255 -49
  370. package/docs/DDNS.md +35 -49
  371. package/docs/JOBS.md +129 -0
  372. package/docs/NOTIFICATIONS.md +58 -90
  373. package/docs/REVERSE_PROXY.md +116 -188
  374. package/docs/SECURITY.md +126 -44
  375. package/docs/SERVERS.md +282 -409
  376. package/docs/UI_CREATION.md +90 -47
  377. package/docs/demo/blank-host-restore.sh +31 -7
  378. package/package.json +15 -6
  379. package/scripts/prepare.mjs +47 -0
  380. package/uis/stock/dist/assets/CopyButton-8mliL0xi.js +1 -0
  381. package/uis/stock/dist/assets/GlobalSettingsView-BINXY77E.js +1 -0
  382. package/uis/stock/dist/assets/LogViewer-kiSnTwdY.js +1 -0
  383. package/uis/stock/dist/assets/LogsView-DDXf_ONs.js +1 -0
  384. package/uis/stock/dist/assets/Modal-lrUuViF2.js +39 -0
  385. package/uis/stock/dist/assets/ProxyView-uXMaJdSQ.js +1 -0
  386. package/uis/stock/dist/assets/ServerDetailView-CW0Vb_c0.js +4 -0
  387. package/uis/stock/dist/assets/SettingsShell-B135xWjJ.js +1 -0
  388. package/uis/stock/dist/assets/SettingsView-BLtWxVkl.js +2 -0
  389. package/uis/stock/dist/assets/de-BIoTrHBQ.js +1 -0
  390. package/uis/stock/dist/assets/es-x4-ih8lH.js +1 -0
  391. package/uis/stock/dist/assets/fr-DatqBBkO.js +1 -0
  392. package/uis/stock/dist/assets/index-CnojaKcA.css +2 -0
  393. package/uis/stock/dist/assets/index-D-CiZReu.js +16 -0
  394. package/uis/stock/dist/assets/ja-CW1703Gw.js +1 -0
  395. package/uis/stock/dist/assets/ko-wFbT4XtK.js +1 -0
  396. package/uis/stock/dist/assets/ru-C1p5C4VN.js +1 -0
  397. package/uis/stock/dist/assets/useUnsavedGuard-BcsXsfCC.js +9 -0
  398. package/uis/stock/dist/assets/vi-CDqr0uie.js +1 -0
  399. package/uis/stock/dist/assets/zh-CN-BJ7iit-X.js +1 -0
  400. package/uis/stock/dist/index.html +4 -3
  401. package/uis/stock/dist/ui.json +3 -3
  402. package/dist/chunks/archive-DP-XQR8X.js.map +0 -1
  403. package/dist/chunks/atomic-C1PfJpE7.js.map +0 -1
  404. package/dist/chunks/backup-CZcVca2a.js.map +0 -1
  405. package/dist/chunks/backups-CFRaWe_m.js +0 -4691
  406. package/dist/chunks/backups-CFRaWe_m.js.map +0 -1
  407. package/dist/chunks/config-text-DifCHhnz.js +0 -50
  408. package/dist/chunks/config-text-DifCHhnz.js.map +0 -1
  409. package/dist/chunks/contracts-CMBD1TF9.js.map +0 -1
  410. package/dist/chunks/daemon-log-BVj8cDEo.js +0 -241
  411. package/dist/chunks/daemon-log-BVj8cDEo.js.map +0 -1
  412. package/dist/chunks/daemon-qKVECISl.js +0 -247
  413. package/dist/chunks/daemon-qKVECISl.js.map +0 -1
  414. package/dist/chunks/docker-Cy9Lyvda.js.map +0 -1
  415. package/dist/chunks/down-pKbGCW9d.js.map +0 -1
  416. package/dist/chunks/init-BZ7hK9Vf.js.map +0 -1
  417. package/dist/chunks/last-stop-C-BXz_XI.js +0 -53
  418. package/dist/chunks/last-stop-C-BXz_XI.js.map +0 -1
  419. package/dist/chunks/layout-DwTtmund.js +0 -24
  420. package/dist/chunks/layout-DwTtmund.js.map +0 -1
  421. package/dist/chunks/lazy-Ce5zEAq1.js +0 -66
  422. package/dist/chunks/lazy-Ce5zEAq1.js.map +0 -1
  423. package/dist/chunks/log-buffer-Dy9HHDMD.js +0 -414
  424. package/dist/chunks/log-buffer-Dy9HHDMD.js.map +0 -1
  425. package/dist/chunks/logger-B5U4GD3j.js.map +0 -1
  426. package/dist/chunks/logs---TI_bxM.js.map +0 -1
  427. package/dist/chunks/migrate-Cfoq-Vgh.js +0 -155
  428. package/dist/chunks/migrate-Cfoq-Vgh.js.map +0 -1
  429. package/dist/chunks/nanny-B-Eu0sFW.js.map +0 -1
  430. package/dist/chunks/nanny-BtWfy0QH.js +0 -1167
  431. package/dist/chunks/nanny-BtWfy0QH.js.map +0 -1
  432. package/dist/chunks/nanny-sweep-DErnlPY1.js.map +0 -1
  433. package/dist/chunks/nearest-6KgQEDUe.js.map +0 -1
  434. package/dist/chunks/parse-DhmG26fI.js.map +0 -1
  435. package/dist/chunks/paths-CGlGDrOU.js.map +0 -1
  436. package/dist/chunks/port-B8WBTRMk.js.map +0 -1
  437. package/dist/chunks/restart-Des4DrAN.js.map +0 -1
  438. package/dist/chunks/schema-B240VXcV.js.map +0 -1
  439. package/dist/chunks/secrets-BieELnZh.js +0 -562
  440. package/dist/chunks/secrets-BieELnZh.js.map +0 -1
  441. package/dist/chunks/server-Bge2r2qQ.js +0 -169
  442. package/dist/chunks/server-Bge2r2qQ.js.map +0 -1
  443. package/dist/chunks/server-ids-DRuNLVCV.js +0 -32
  444. package/dist/chunks/server-ids-DRuNLVCV.js.map +0 -1
  445. package/dist/chunks/set-password-D5vZqqSX.js +0 -43
  446. package/dist/chunks/set-password-D5vZqqSX.js.map +0 -1
  447. package/dist/chunks/set-token-obPiEJYk.js +0 -78
  448. package/dist/chunks/set-token-obPiEJYk.js.map +0 -1
  449. package/dist/chunks/settings-xu-XTfWg.js.map +0 -1
  450. package/dist/chunks/setup-temp-CAN4_bA-.js.map +0 -1
  451. package/dist/chunks/shape-DnTKzjQ2.js +0 -24
  452. package/dist/chunks/shape-DnTKzjQ2.js.map +0 -1
  453. package/dist/chunks/src-BtWMFmzZ.js.map +0 -1
  454. package/dist/chunks/status-DT1EsA-B.js.map +0 -1
  455. package/dist/chunks/ui-D562aqw5.js.map +0 -1
  456. package/dist/chunks/ui-dir-CsU3uLNV.js.map +0 -1
  457. package/dist/chunks/ui-release-DKzVvlLd.js.map +0 -1
  458. package/dist/chunks/ui-revert-EkBBwRTt.js.map +0 -1
  459. package/dist/chunks/ui-switch-BnZTdMDd.js.map +0 -1
  460. package/dist/chunks/ui-update-_xryLYxw.js.map +0 -1
  461. package/dist/chunks/up-Pdz-l6IH.js.map +0 -1
  462. package/dist/chunks/usage-DFrCVXpT.js.map +0 -1
  463. package/dist/chunks/workspaces-DYcfvKV_.js.map +0 -1
  464. package/dist/chunks/wsl-temperature-BiCI4iK6.js.map +0 -1
  465. package/dist/types/cli/set-password.d.ts +0 -14
  466. package/dist/types/cli/set-token.d.ts +0 -21
  467. package/uis/stock/dist/assets/CopyButton-BUBKRJyY.js +0 -1
  468. package/uis/stock/dist/assets/GlobalSettingsView-yYMcRWvt.js +0 -1
  469. package/uis/stock/dist/assets/LogViewer-DIliXy62.js +0 -1
  470. package/uis/stock/dist/assets/LogsView-B7Z-7RNg.js +0 -1
  471. package/uis/stock/dist/assets/Modal-DmKa5Qpp.js +0 -39
  472. package/uis/stock/dist/assets/ProxyView-DvZiNkwb.js +0 -1
  473. package/uis/stock/dist/assets/ServerDetailView-6idGT_EX.js +0 -2
  474. package/uis/stock/dist/assets/SettingsShell-CeGtleYI.js +0 -1
  475. package/uis/stock/dist/assets/SettingsView-BrhJIrmk.js +0 -2
  476. package/uis/stock/dist/assets/de-BRITeb0H.js +0 -1
  477. package/uis/stock/dist/assets/es-B2zIEssV.js +0 -1
  478. package/uis/stock/dist/assets/fr-s0ZOBEqh.js +0 -1
  479. package/uis/stock/dist/assets/index-C1MehbKy.css +0 -2
  480. package/uis/stock/dist/assets/index-CnBN54wF.js +0 -15
  481. package/uis/stock/dist/assets/ja-CU7MR85V.js +0 -1
  482. package/uis/stock/dist/assets/ko-tL5Me6d-.js +0 -1
  483. package/uis/stock/dist/assets/ru-92yrvkNJ.js +0 -1
  484. package/uis/stock/dist/assets/vi-CzvY16k2.js +0 -1
  485. package/uis/stock/dist/assets/zh-CN-DDwFW_uW.js +0 -1
@@ -0,0 +1,1061 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
+ import { D as API_TOKEN_SCOPES, E as errorMessage, O as PANEL_WIDE_SCOPES } from "../cli.js";
3
+ import { t as writeFileAtomic } from "./atomic-SZUwDtGD.js";
4
+ import { n as readStateFile } from "./config-text-DxMOQQnk.js";
5
+ import { t as logger } from "./logger-BnrKTBHQ.js";
6
+ import { t as passwordLength } from "./password-policy-Clq6PGE-.js";
7
+ import { t as isRecord } from "./shape-CDGeYl_J.js";
8
+ import process from "node:process";
9
+ import fs from "node:fs";
10
+ import { Buffer } from "node:buffer";
11
+ import crypto from "node:crypto";
12
+ //#region src/config/accounts.ts
13
+ /** An account id: typable, and safe in a URL path and a `Bearer <id>:<secret>` header. */
14
+ var ACCOUNT_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,39}$/;
15
+ function accountIdProblem(id) {
16
+ if (id.length === 0) return "an account needs an id";
17
+ if (!ACCOUNT_ID_PATTERN.test(id)) return `an account id is lowercase letters, digits, - and _, starting with a letter or digit, at most 40 characters — "${id}" is not`;
18
+ return null;
19
+ }
20
+ /** Visible head, so a person can tell a generated secret from one they chose. */
21
+ var ACCOUNT_SECRET_PREFIX = "hh_";
22
+ var ACCOUNT_SECRET_BYTES = 32;
23
+ /** 32 bytes of randomness: the whole point of a generated secret is that nothing needs to stretch it. */
24
+ function generateAccountSecret() {
25
+ return `${ACCOUNT_SECRET_PREFIX}${crypto.randomBytes(ACCOUNT_SECRET_BYTES).toString("base64url")}`;
26
+ }
27
+ /** scrypt when a person chose the secret, sha256 when the panel generated it; `algo` records which. */
28
+ function credentialFields(secret, generated) {
29
+ if (generated) return {
30
+ algo: "sha256",
31
+ hash: hashApiToken(secret),
32
+ ...passwordLength(secret) < 12 ? { short: true } : {}
33
+ };
34
+ const record = hashPassword(secret);
35
+ return {
36
+ algo: "scrypt",
37
+ hash: record.hash,
38
+ salt: record.salt,
39
+ keylen: record.keylen,
40
+ cost: record.cost,
41
+ ...record.short === true ? { short: true } : {}
42
+ };
43
+ }
44
+ /**
45
+ * The accounts, read tolerantly. A record with no scopes means `read`, an absent `enabled` means
46
+ * enabled (a pre-0.15 account could not be disabled), and a duplicate id keeps the first.
47
+ */
48
+ function readAccounts(value) {
49
+ if (!Array.isArray(value)) return [];
50
+ const accounts = [];
51
+ const seen = /* @__PURE__ */ new Set();
52
+ for (const entry of value) {
53
+ if (!isRecord(entry) || typeof entry.id !== "string" || entry.id.length === 0 || typeof entry.hash !== "string") continue;
54
+ if (seen.has(entry.id)) continue;
55
+ seen.add(entry.id);
56
+ const scopes = Array.isArray(entry.scopes) ? entry.scopes.filter((scope) => typeof scope === "string" && API_TOKEN_SCOPES.includes(scope)) : [];
57
+ const workspaces = Array.isArray(entry.workspaces) ? entry.workspaces.filter((id) => typeof id === "string" && id.length > 0) : void 0;
58
+ const algo = entry.algo === "scrypt" ? "scrypt" : "sha256";
59
+ const createdAt = typeof entry.createdAt === "number" ? entry.createdAt : typeof entry.updatedAt === "number" ? entry.updatedAt : 0;
60
+ accounts.push({
61
+ id: entry.id,
62
+ label: typeof entry.label === "string" && entry.label.length > 0 ? entry.label : entry.id,
63
+ algo,
64
+ hash: entry.hash,
65
+ ...algo === "scrypt" && typeof entry.salt === "string" ? { salt: entry.salt } : {},
66
+ ...algo === "scrypt" && typeof entry.keylen === "number" ? { keylen: entry.keylen } : {},
67
+ ...algo === "scrypt" && isRecord(entry.cost) ? { cost: {
68
+ N: Number(entry.cost.N),
69
+ r: Number(entry.cost.r),
70
+ p: Number(entry.cost.p)
71
+ } } : {},
72
+ scopes: scopes.length === 0 ? ["read"] : scopes,
73
+ enabled: entry.enabled !== false,
74
+ ...workspaces === void 0 || workspaces.length === 0 ? {} : { workspaces },
75
+ ...entry.isDefault === true ? { isDefault: true } : {},
76
+ ...typeof entry.initial === "string" ? { initial: entry.initial } : {},
77
+ ...entry.short === true ? { short: true } : {},
78
+ createdAt,
79
+ updatedAt: typeof entry.updatedAt === "number" ? entry.updatedAt : createdAt,
80
+ ...typeof entry.lastUsedAt === "number" ? { lastUsedAt: entry.lastUsedAt } : {}
81
+ });
82
+ }
83
+ return accounts;
84
+ }
85
+ /**
86
+ * The accounts a pre-0.15 file implies, so an upgrade removes no access: `default` carries the password,
87
+ * and every other token becomes an account with the same id and scopes.
88
+ */
89
+ function migrateLegacyAccounts(contents) {
90
+ const accounts = [];
91
+ const taken = /* @__PURE__ */ new Set();
92
+ const createdAt = contents.password?.updatedAt ?? Date.now();
93
+ if (contents.password !== null) {
94
+ const password = contents.password;
95
+ accounts.push({
96
+ id: "default",
97
+ label: "default",
98
+ algo: "scrypt",
99
+ hash: password.hash,
100
+ salt: password.salt,
101
+ keylen: password.keylen,
102
+ cost: password.cost,
103
+ scopes: [...API_TOKEN_SCOPES],
104
+ enabled: true,
105
+ ...password.isDefault === true ? { isDefault: true } : {},
106
+ ...typeof password.initial === "string" ? { initial: password.initial } : {},
107
+ ...password.short === true ? { short: true } : {},
108
+ createdAt,
109
+ updatedAt: password.updatedAt
110
+ });
111
+ taken.add("default");
112
+ }
113
+ for (const token of contents.apiTokens) {
114
+ if (taken.has(token.id)) continue;
115
+ taken.add(token.id);
116
+ accounts.push({
117
+ id: token.id,
118
+ label: token.name,
119
+ algo: "sha256",
120
+ hash: token.hash,
121
+ scopes: token.scopes.length === 0 ? [...API_TOKEN_SCOPES] : token.scopes,
122
+ enabled: true,
123
+ ...token.workspaces === void 0 ? {} : { workspaces: token.workspaces },
124
+ createdAt: token.updatedAt,
125
+ updatedAt: token.updatedAt,
126
+ ...token.lastUsedAt === void 0 ? {} : { lastUsedAt: token.lastUsedAt }
127
+ });
128
+ }
129
+ if (contents.apiToken !== null && !taken.has("default")) accounts.push({
130
+ id: "default",
131
+ label: "default",
132
+ algo: "sha256",
133
+ hash: contents.apiToken.hash,
134
+ scopes: [...API_TOKEN_SCOPES],
135
+ enabled: true,
136
+ createdAt: contents.apiToken.updatedAt,
137
+ updatedAt: contents.apiToken.updatedAt
138
+ });
139
+ return accounts;
140
+ }
141
+ //#endregion
142
+ //#region src/config/secrets.ts
143
+ var secrets_exports = /* @__PURE__ */ __exportAll({
144
+ API_TOKEN_SCOPES: () => API_TOKEN_SCOPES,
145
+ AccountError: () => AccountError,
146
+ DEFAULT_DDNS_SECRET: () => "hh",
147
+ LEGACY_TELEGRAM_ID: () => LEGACY_TELEGRAM_ID,
148
+ PANEL_WIDE_SCOPES: () => PANEL_WIDE_SCOPES,
149
+ SecretsStore: () => SecretsStore,
150
+ accountIdProblem: () => accountIdProblem,
151
+ apiTokenRecord: () => apiTokenRecord,
152
+ generateAccountSecret: () => generateAccountSecret,
153
+ generateApiToken: () => generateApiToken,
154
+ generateInitialPassword: () => generateInitialPassword,
155
+ hashApiToken: () => hashApiToken,
156
+ hashPassword: () => hashPassword,
157
+ scopeCatalogue: () => scopeCatalogue,
158
+ verifyApiToken: () => verifyApiToken,
159
+ verifyPassword: () => verifyPassword
160
+ });
161
+ /** Node's scrypt defaults, pinned so a hash stays verifiable across versions. */
162
+ var COST = {
163
+ N: 16384,
164
+ r: 8,
165
+ p: 1
166
+ };
167
+ var KEYLEN = 64;
168
+ var SALT_BYTES = 16;
169
+ /** Carries only what a UI must not re-decide: which scopes a workspace limit can narrow. */
170
+ function scopeCatalogue() {
171
+ return API_TOKEN_SCOPES.map((scope) => ({
172
+ scope,
173
+ workspaceLimited: !PANEL_WIDE_SCOPES.includes(scope)
174
+ }));
175
+ }
176
+ /** Owned by this release; `version` is retired and dropped on the next write. */
177
+ var KNOWN_SECRET_KEYS = /* @__PURE__ */ new Set([
178
+ "accounts",
179
+ "password",
180
+ "apiToken",
181
+ "apiTokens",
182
+ "telegram",
183
+ "ddns",
184
+ "ddnsKdf",
185
+ "serverEnv",
186
+ "jobEnv",
187
+ "version"
188
+ ]);
189
+ function unknownTopLevel(parsed) {
190
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {};
191
+ return Object.fromEntries(Object.entries(parsed).filter(([key]) => !KNOWN_SECRET_KEYS.has(key)));
192
+ }
193
+ /** The id the config migration gives a pre-list Telegram destination. */
194
+ var LEGACY_TELEGRAM_ID = "telegram";
195
+ var DDNS_KEYLEN = 32;
196
+ var DDNS_IV_BYTES = 12;
197
+ var DDNS_AAD_PREFIX = "hh-ddns-v1:";
198
+ var DDNS_SEALED_ALGO = "aes-256-gcm";
199
+ function deriveKey(password, salt, cost, keylen) {
200
+ return crypto.scryptSync(password.normalize("NFKC"), salt, keylen, { ...cost });
201
+ }
202
+ function hashPassword(password, options = {}) {
203
+ const salt = crypto.randomBytes(SALT_BYTES);
204
+ return {
205
+ algo: "scrypt",
206
+ salt: salt.toString("base64"),
207
+ hash: deriveKey(password, salt, COST, KEYLEN).toString("base64"),
208
+ keylen: KEYLEN,
209
+ cost: { ...COST },
210
+ updatedAt: options.now ?? Date.now(),
211
+ ...options.isDefault === true ? { isDefault: true } : {},
212
+ ...options.isDefault === true && options.initial === true ? { initial: password } : {},
213
+ ...passwordLength(password) < 12 ? { short: true } : {}
214
+ };
215
+ }
216
+ /** The pre-0.12 boot password. Still recognised, never created. */
217
+ var LEGACY_DEFAULT_PASSWORD = "hh";
218
+ /** A random first-run password: 12 characters from an unambiguous alphabet, ~60 bits. */
219
+ function generateInitialPassword() {
220
+ const alphabet = "abcdefghjkmnpqrstuvwxyz23456789";
221
+ const chars = [...crypto.randomBytes(12)].map((byte) => alphabet[byte % 31]);
222
+ return [
223
+ chars.slice(0, 4),
224
+ chars.slice(4, 8),
225
+ chars.slice(8)
226
+ ].map((group) => group.join("")).join("-");
227
+ }
228
+ function verifyPassword(password, record) {
229
+ const expected = Buffer.from(record.hash, "base64");
230
+ let actual;
231
+ try {
232
+ actual = deriveKey(password, Buffer.from(record.salt, "base64"), record.cost, record.keylen);
233
+ } catch {
234
+ return false;
235
+ }
236
+ if (actual.length !== expected.length) return false;
237
+ return crypto.timingSafeEqual(actual, expected);
238
+ }
239
+ /** One throwaway scrypt, so "no such account" costs what "wrong secret" costs (no enumeration oracle). Keep in step with `verifyPassword`. */
240
+ function spendVerifyWork(secret) {
241
+ try {
242
+ const salt = crypto.createHash("sha256").update(secret, "utf8").digest().subarray(0, SALT_BYTES);
243
+ deriveKey(secret.length === 0 ? "x" : secret, salt, COST, KEYLEN);
244
+ } catch {}
245
+ }
246
+ var API_TOKEN_PREFIX = "hh_";
247
+ var API_TOKEN_BYTES = 32;
248
+ var API_TOKEN_HINT_CHARS = 8;
249
+ function generateApiToken() {
250
+ return `${API_TOKEN_PREFIX}${crypto.randomBytes(API_TOKEN_BYTES).toString("base64url")}`;
251
+ }
252
+ function hashApiToken(token) {
253
+ return crypto.createHash("sha256").update(token, "utf8").digest("base64");
254
+ }
255
+ function verifyApiToken(token, record) {
256
+ if (token.length === 0) return false;
257
+ const expected = Buffer.from(record.hash, "base64");
258
+ const actual = Buffer.from(hashApiToken(token), "base64");
259
+ if (actual.length !== expected.length) return false;
260
+ return crypto.timingSafeEqual(actual, expected);
261
+ }
262
+ function apiTokenRecord(token, now = Date.now()) {
263
+ return {
264
+ algo: "sha256",
265
+ hash: hashApiToken(token),
266
+ hint: token.slice(0, API_TOKEN_HINT_CHARS),
267
+ updatedAt: now
268
+ };
269
+ }
270
+ function readDdnsValues(value) {
271
+ if (!isRecord(value)) return {};
272
+ const out = {};
273
+ for (const [key, field] of Object.entries(value)) if (typeof field === "string" && field.length > 0) out[key] = field;
274
+ return out;
275
+ }
276
+ function isSealedDdns(value) {
277
+ return isRecord(value) && value.algo === DDNS_SEALED_ALGO && typeof value.iv === "string" && typeof value.tag === "string" && typeof value.data === "string";
278
+ }
279
+ function isPlainDdns(value) {
280
+ return "plain" in value;
281
+ }
282
+ /** The bot tokens by destination id; also reads the pre-list `{ botToken }` singleton. */
283
+ function readTelegramTokens(value) {
284
+ if (!isRecord(value)) return {};
285
+ if (typeof value.botToken === "string") return value.botToken.trim().length > 0 ? { [LEGACY_TELEGRAM_ID]: value.botToken.trim() } : {};
286
+ const tokens = {};
287
+ for (const [id, token] of Object.entries(value)) if (typeof token === "string" && token.trim().length > 0) tokens[id] = token.trim();
288
+ return tokens;
289
+ }
290
+ /** Sealed, or `{ provider, values }` awaiting the sealing write. A bare field map no longer reads. */
291
+ function readStoredDdns(value) {
292
+ if (!isRecord(value)) return {};
293
+ const out = {};
294
+ for (const [accountId, entry] of Object.entries(value)) {
295
+ if (isSealedDdns(entry)) {
296
+ out[accountId] = entry;
297
+ continue;
298
+ }
299
+ if (!isRecord(entry) || typeof entry.provider !== "string" || entry.provider.length === 0) continue;
300
+ const values = readDdnsValues(entry.values);
301
+ if (Object.keys(values).length === 0) continue;
302
+ out[accountId] = {
303
+ plain: true,
304
+ provider: entry.provider,
305
+ values
306
+ };
307
+ }
308
+ return out;
309
+ }
310
+ /** Read tolerantly; the legacy single `apiToken` becomes `default`/`admin` so an upgrade removes no access. */
311
+ function readNamedTokens(value) {
312
+ if (!Array.isArray(value)) return [];
313
+ const tokens = [];
314
+ const seen = /* @__PURE__ */ new Set();
315
+ for (const entry of value) {
316
+ if (!isRecord(entry) || typeof entry.hash !== "string" || typeof entry.id !== "string" || typeof entry.name !== "string") continue;
317
+ if (seen.has(entry.id)) continue;
318
+ seen.add(entry.id);
319
+ const scopes = Array.isArray(entry.scopes) ? entry.scopes.filter((scope) => typeof scope === "string" && API_TOKEN_SCOPES.includes(scope)) : [];
320
+ const workspaces = Array.isArray(entry.workspaces) ? entry.workspaces.filter((id) => typeof id === "string" && id.length > 0) : void 0;
321
+ tokens.push({
322
+ algo: "sha256",
323
+ id: entry.id,
324
+ name: entry.name,
325
+ hash: entry.hash,
326
+ hint: typeof entry.hint === "string" ? entry.hint : "",
327
+ scopes: scopes.length === 0 ? ["read"] : scopes,
328
+ updatedAt: typeof entry.updatedAt === "number" ? entry.updatedAt : 0,
329
+ ...workspaces === void 0 || workspaces.length === 0 ? {} : { workspaces },
330
+ ...typeof entry.lastUsedAt === "number" ? { lastUsedAt: entry.lastUsedAt } : {}
331
+ });
332
+ }
333
+ return tokens;
334
+ }
335
+ /** Read tolerantly: anything not `{ serverId: { NAME: string } }` is dropped, not a reason to refuse the file. */
336
+ function readServerEnv(value) {
337
+ if (!isRecord(value)) return {};
338
+ const out = {};
339
+ for (const [serverId, entry] of Object.entries(value)) {
340
+ if (!isRecord(entry)) continue;
341
+ const names = {};
342
+ for (const [name, raw] of Object.entries(entry)) if (typeof raw === "string") names[name] = raw;
343
+ if (Object.keys(names).length > 0) out[serverId] = names;
344
+ }
345
+ return out;
346
+ }
347
+ function readDdnsKdf(value) {
348
+ if (!isRecord(value) || value.algo !== "scrypt" || typeof value.salt !== "string") return null;
349
+ const cost = isRecord(value.cost) ? value.cost : {};
350
+ const N = Number(cost.N);
351
+ const r = Number(cost.r);
352
+ const p = Number(cost.p);
353
+ if (!Number.isInteger(N) || !Number.isInteger(r) || !Number.isInteger(p) || N < 2 || r < 1 || p < 1) return null;
354
+ return {
355
+ algo: "scrypt",
356
+ cost: {
357
+ N,
358
+ r,
359
+ p
360
+ },
361
+ salt: value.salt
362
+ };
363
+ }
364
+ function newDdnsKdf() {
365
+ return {
366
+ algo: "scrypt",
367
+ cost: { ...COST },
368
+ salt: crypto.randomBytes(SALT_BYTES).toString("base64")
369
+ };
370
+ }
371
+ /** The account id is the AAD, so a sealed entry cannot be moved to another account. */
372
+ function ddnsAad(accountId) {
373
+ return Buffer.from(`${DDNS_AAD_PREFIX}${accountId}`, "utf8");
374
+ }
375
+ function sealDdns(accountId, record, key) {
376
+ const iv = crypto.randomBytes(DDNS_IV_BYTES);
377
+ const cipher = crypto.createCipheriv(DDNS_SEALED_ALGO, key, iv);
378
+ cipher.setAAD(ddnsAad(accountId));
379
+ const data = Buffer.concat([cipher.update(JSON.stringify(record), "utf8"), cipher.final()]);
380
+ return {
381
+ algo: DDNS_SEALED_ALGO,
382
+ iv: iv.toString("base64"),
383
+ tag: cipher.getAuthTag().toString("base64"),
384
+ data: data.toString("base64")
385
+ };
386
+ }
387
+ /** Null when the tag does not verify: a different secret, or a file somebody edited. */
388
+ function openDdns(accountId, sealed, key) {
389
+ try {
390
+ const decipher = crypto.createDecipheriv(DDNS_SEALED_ALGO, key, Buffer.from(sealed.iv, "base64"));
391
+ decipher.setAAD(ddnsAad(accountId));
392
+ decipher.setAuthTag(Buffer.from(sealed.tag, "base64"));
393
+ const plain = Buffer.concat([decipher.update(Buffer.from(sealed.data, "base64")), decipher.final()]).toString("utf8");
394
+ const parsed = JSON.parse(plain);
395
+ if (typeof parsed?.provider !== "string") return null;
396
+ const values = readDdnsValues(parsed.values);
397
+ return Object.keys(values).length === 0 ? null : {
398
+ provider: parsed.provider,
399
+ values
400
+ };
401
+ } catch {
402
+ return null;
403
+ }
404
+ }
405
+ var AccountError = class extends Error {
406
+ code;
407
+ constructor(message, code) {
408
+ super(message);
409
+ this.code = code;
410
+ this.name = "AccountError";
411
+ }
412
+ };
413
+ /** Secrets outside the config, in a 0600 file. DDNS credentials are replayed to a third party, so they are sealed with AES-256-GCM under `HHOSTED_DDNS_SECRET`. */
414
+ var SecretsStore = class {
415
+ file;
416
+ scope;
417
+ cache = null;
418
+ cacheKey = "";
419
+ error = null;
420
+ ddnsKeyCache = null;
421
+ warnedAccounts = /* @__PURE__ */ new Set();
422
+ warnedDefaultSecret = false;
423
+ ddnsSecret;
424
+ constructor(file, ddnsSecret, scope = "all") {
425
+ this.file = file;
426
+ this.scope = scope;
427
+ const candidate = (ddnsSecret ?? process.env.HHOSTED_DDNS_SECRET ?? "").trim();
428
+ this.ddnsSecret = candidate.length > 0 ? candidate : "hh";
429
+ }
430
+ /** Whether the DDNS credentials are sealed under the built-in key (`hh`), which anyone with the file can open. */
431
+ get usingDefaultDdnsSecret() {
432
+ return this.ddnsSecret === "hh";
433
+ }
434
+ get path() {
435
+ return this.file;
436
+ }
437
+ /** Re-reads whenever the file changes on disk, so another process's write takes effect without a restart. */
438
+ load() {
439
+ const key = this.statKey();
440
+ if (this.cache !== null && key === this.cacheKey) return this.cache;
441
+ this.cache = this.read();
442
+ this.cacheKey = key;
443
+ return this.cache;
444
+ }
445
+ statKey() {
446
+ try {
447
+ const stats = fs.statSync(this.file);
448
+ return `${stats.mtimeMs}:${stats.size}`;
449
+ } catch {
450
+ return "missing";
451
+ }
452
+ }
453
+ /** The `default` account's password-shaped record, when it still has one. */
454
+ get password() {
455
+ const record = this.account("default");
456
+ if (record === null || record.algo !== "scrypt") return null;
457
+ if (record.salt === void 0 || record.cost === void 0 || record.keylen === void 0) return null;
458
+ return {
459
+ algo: "scrypt",
460
+ salt: record.salt,
461
+ hash: record.hash,
462
+ keylen: record.keylen,
463
+ cost: record.cost,
464
+ updatedAt: record.updatedAt,
465
+ ...record.isDefault === true ? { isDefault: true } : {},
466
+ ...typeof record.initial === "string" ? { initial: record.initial } : {},
467
+ ...record.short === true ? { short: true } : {}
468
+ };
469
+ }
470
+ get passwordUpdatedAt() {
471
+ return this.account("default")?.updatedAt ?? null;
472
+ }
473
+ /** Whether any account can sign in. */
474
+ get passwordSet() {
475
+ return this.anyAccountEnabled;
476
+ }
477
+ get usingDefaultPassword() {
478
+ return this.accounts.some((entry) => entry.isDefault === true);
479
+ }
480
+ /** An account's secret is too short to expose the panel behind; see `AccountRecord.short`. */
481
+ get passwordTooShort() {
482
+ return this.accounts.some((entry) => entry.short === true);
483
+ }
484
+ /** The first configured token, whichever release wrote it. */
485
+ get apiToken() {
486
+ const contents = this.load();
487
+ if (contents.apiToken !== null) return contents.apiToken;
488
+ return this.apiTokens[0] ?? null;
489
+ }
490
+ get apiTokenSet() {
491
+ return this.apiToken !== null || this.apiTokens.length > 0;
492
+ }
493
+ get apiTokenHint() {
494
+ return this.apiToken?.hint ?? this.apiTokens[0]?.hint ?? null;
495
+ }
496
+ telegramToken(id) {
497
+ const token = this.load().telegram[id] ?? "";
498
+ return token.length > 0 ? token : null;
499
+ }
500
+ telegramTokenSet(id) {
501
+ return this.telegramToken(id) !== null;
502
+ }
503
+ /** Every destination id a token is stored for — including one the config no longer declares. */
504
+ get telegramTokenIds() {
505
+ return Object.keys(this.load().telegram).sort();
506
+ }
507
+ /** The named tokens, with the pre-0.14 single token migrated in (persisted by the next write). */
508
+ get apiTokens() {
509
+ const contents = this.load();
510
+ if (contents.apiToken === null) return contents.apiTokens;
511
+ if (contents.apiTokens.some((entry) => entry.name === "default")) return contents.apiTokens;
512
+ return [{
513
+ ...contents.apiToken,
514
+ id: "default",
515
+ name: "default",
516
+ scopes: ["admin"]
517
+ }, ...contents.apiTokens];
518
+ }
519
+ listApiTokens() {
520
+ return this.apiTokens.map(({ hash: _hash, algo: _algo, updatedAt, hint: _hint, ...rest }) => ({
521
+ ...rest,
522
+ createdAt: updatedAt
523
+ }));
524
+ }
525
+ /** Constant-time against every stored hash: every candidate is compared, so timing does not reveal which matched. */
526
+ findApiToken(token) {
527
+ if (token.length === 0) return null;
528
+ let found = null;
529
+ for (const candidate of this.apiTokens) if (verifyApiToken(token, candidate)) found = candidate;
530
+ return found;
531
+ }
532
+ /** Returns the token once. The id is slugged from the name, and a duplicate name is refused. */
533
+ createApiToken(input, now = Date.now()) {
534
+ const name = input.name.trim();
535
+ if (name.length === 0) throw new Error("a token needs a name");
536
+ if (input.scopes.length === 0) throw new Error("a token needs at least one scope");
537
+ const existing = this.apiTokens;
538
+ if (existing.some((entry) => entry.name === name)) throw new Error(`a token named "${name}" already exists`);
539
+ const token = generateApiToken();
540
+ const base = apiTokenRecord(token, now);
541
+ const baseId = name.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "token";
542
+ let id = baseId;
543
+ let index = 2;
544
+ while (existing.some((entry) => entry.id === id)) id = `${baseId}-${index++}`;
545
+ const record = {
546
+ ...base,
547
+ id,
548
+ name,
549
+ scopes: [...new Set(input.scopes)],
550
+ ...input.workspaces === void 0 || input.workspaces.length === 0 ? {} : { workspaces: [...new Set(input.workspaces)] }
551
+ };
552
+ this.save({
553
+ ...this.load(),
554
+ apiToken: null,
555
+ apiTokens: [...existing, record]
556
+ });
557
+ return {
558
+ token,
559
+ record
560
+ };
561
+ }
562
+ /** `false` when no such id. */
563
+ revokeApiToken(id) {
564
+ const existing = this.apiTokens;
565
+ const next = existing.filter((entry) => entry.id !== id);
566
+ if (next.length === existing.length) return false;
567
+ this.save({
568
+ ...this.load(),
569
+ apiToken: null,
570
+ apiTokens: next
571
+ });
572
+ return true;
573
+ }
574
+ markApiTokenUsed(id, now = Date.now()) {
575
+ const existing = this.apiTokens;
576
+ const index = existing.findIndex((entry) => entry.id === id);
577
+ if (index === -1) return;
578
+ const next = [...existing];
579
+ next[index] = {
580
+ ...next[index],
581
+ lastUsedAt: now
582
+ };
583
+ this.save({
584
+ ...this.load(),
585
+ apiToken: null,
586
+ apiTokens: next
587
+ });
588
+ }
589
+ /** Writes the legacy single-token field. Test-only: the migration still has to read that shape. */
590
+ setApiToken(token) {
591
+ const record = apiTokenRecord(token);
592
+ const existing = this.apiTokens;
593
+ const index = existing.findIndex((entry) => entry.id === "default");
594
+ const named = index === -1 ? {
595
+ ...record,
596
+ id: "default",
597
+ name: "default",
598
+ scopes: ["admin"]
599
+ } : {
600
+ ...record,
601
+ id: "default",
602
+ name: existing[index].name,
603
+ scopes: existing[index].scopes,
604
+ ...existing[index].workspaces === void 0 ? {} : { workspaces: existing[index].workspaces }
605
+ };
606
+ const next = index === -1 ? [...existing, named] : existing.map((entry, at) => at === index ? named : entry);
607
+ this.save({
608
+ ...this.load(),
609
+ apiToken: null,
610
+ apiTokens: next
611
+ });
612
+ return record;
613
+ }
614
+ clearApiToken() {
615
+ this.save({
616
+ ...this.load(),
617
+ apiToken: null,
618
+ apiTokens: this.apiTokens.filter((entry) => entry.id !== "default")
619
+ });
620
+ }
621
+ /** Every account, with the legacy credential models migrated in on read. */
622
+ get accounts() {
623
+ const contents = this.load();
624
+ if (contents.accounts.length > 0) return contents.accounts;
625
+ return migrateLegacyAccounts(contents);
626
+ }
627
+ listAccounts() {
628
+ return this.accounts.map(({ hash: _hash, algo: _algo, salt: _salt, keylen: _keylen, cost: _cost, initial: _initial, ...rest }) => ({
629
+ ...rest,
630
+ isDefault: rest.isDefault === true,
631
+ short: rest.short === true
632
+ }));
633
+ }
634
+ account(id) {
635
+ return this.accounts.find((entry) => entry.id === id) ?? null;
636
+ }
637
+ /** Returns the secret once. Generated (sha256) by default; a typed `secret` is scrypt-stretched. */
638
+ createAccount(input, now = Date.now()) {
639
+ const id = input.id.trim();
640
+ const problem = accountIdProblem(id);
641
+ if (problem !== null) throw new AccountError(problem, "INVALID_ACCOUNT");
642
+ if (input.scopes.length === 0) throw new AccountError("an account needs at least one scope", "INVALID_ACCOUNT");
643
+ const existing = this.accounts;
644
+ if (existing.some((entry) => entry.id === id)) throw new AccountError(`an account with the id "${id}" already exists`, "ACCOUNT_EXISTS");
645
+ const secret = input.secret ?? generateAccountSecret();
646
+ const record = {
647
+ id,
648
+ label: input.label?.trim() || id,
649
+ scopes: [...new Set(input.scopes)],
650
+ enabled: input.enabled !== false,
651
+ createdAt: now,
652
+ updatedAt: now,
653
+ ...input.workspaces === void 0 || input.workspaces.length === 0 ? {} : { workspaces: [...new Set(input.workspaces)] },
654
+ ...credentialFields(secret, input.secret === void 0),
655
+ ...input.isDefault === true ? { isDefault: true } : {},
656
+ ...input.isDefault === true && input.keepInitial === true ? { initial: secret } : {}
657
+ };
658
+ this.writeAccounts([...existing, record]);
659
+ return {
660
+ account: this.listAccounts().find((entry) => entry.id === id),
661
+ secret
662
+ };
663
+ }
664
+ setAccountSecret(id, secret, now = Date.now()) {
665
+ const existing = this.accounts;
666
+ const index = existing.findIndex((entry) => entry.id === id);
667
+ if (index === -1) return null;
668
+ const record = {
669
+ ...existing[index],
670
+ ...credentialFields(secret, false),
671
+ updatedAt: now
672
+ };
673
+ delete record.isDefault;
674
+ delete record.initial;
675
+ if (credentialFields(secret, false).short !== true) delete record.short;
676
+ const next = [...existing];
677
+ next[index] = record;
678
+ this.writeAccounts(next);
679
+ return record;
680
+ }
681
+ /** A failed answer always spends one scrypt, so timing does not reveal which ids exist. */
682
+ verifyAccountSecret(id, secret) {
683
+ const record = this.account(id);
684
+ if (record === null || record.enabled !== true || secret.length === 0) {
685
+ spendVerifyWork(secret);
686
+ return false;
687
+ }
688
+ if (record.algo === "scrypt") {
689
+ if (record.salt === void 0 || record.cost === void 0 || record.keylen === void 0) {
690
+ spendVerifyWork(secret);
691
+ return false;
692
+ }
693
+ return verifyPassword(secret, {
694
+ algo: "scrypt",
695
+ salt: record.salt,
696
+ hash: record.hash,
697
+ keylen: record.keylen,
698
+ cost: record.cost,
699
+ updatedAt: record.updatedAt
700
+ });
701
+ }
702
+ if (verifyApiToken(secret, {
703
+ algo: "sha256",
704
+ hash: record.hash,
705
+ hint: "",
706
+ updatedAt: record.updatedAt
707
+ })) return true;
708
+ spendVerifyWork(secret);
709
+ return false;
710
+ }
711
+ /** `false` when no such id. */
712
+ revokeAccount(id) {
713
+ const existing = this.accounts;
714
+ const next = existing.filter((entry) => entry.id !== id);
715
+ if (next.length === existing.length) return false;
716
+ this.writeAccounts(next);
717
+ return true;
718
+ }
719
+ /** Returns `null` for an unknown id. */
720
+ updateAccount(id, patch, now = Date.now()) {
721
+ const existing = this.accounts;
722
+ const index = existing.findIndex((entry) => entry.id === id);
723
+ if (index === -1) return null;
724
+ const current = existing[index];
725
+ const next = {
726
+ ...current,
727
+ updatedAt: now
728
+ };
729
+ if (patch.label !== void 0) next.label = patch.label.trim() || current.id;
730
+ if (patch.scopes !== void 0) {
731
+ if (patch.scopes.length === 0) throw new AccountError("an account needs at least one scope", "INVALID_ACCOUNT");
732
+ next.scopes = [...new Set(patch.scopes)];
733
+ }
734
+ if (patch.workspaces !== void 0) {
735
+ if (patch.workspaces === null || patch.workspaces.length === 0) delete next.workspaces;
736
+ else next.workspaces = [...new Set(patch.workspaces)];
737
+ }
738
+ if (patch.enabled !== void 0) next.enabled = patch.enabled;
739
+ const list = [...existing];
740
+ list[index] = next;
741
+ this.writeAccounts(list);
742
+ return next;
743
+ }
744
+ markAccountUsed(id, now = Date.now()) {
745
+ const existing = this.accounts;
746
+ const index = existing.findIndex((entry) => entry.id === id);
747
+ if (index === -1) return;
748
+ const next = [...existing];
749
+ next[index] = {
750
+ ...next[index],
751
+ lastUsedAt: now
752
+ };
753
+ this.writeAccounts(next, { touchUpdatedAt: false });
754
+ }
755
+ get initialAccount() {
756
+ return this.accounts.find((entry) => entry.isDefault === true && typeof entry.initial === "string" && entry.initial.length > 0) ?? null;
757
+ }
758
+ get initialPassword() {
759
+ const record = this.accounts.find((entry) => entry.isDefault === true);
760
+ if (record === void 0) return null;
761
+ if (typeof record.initial === "string" && record.initial.length > 0) return record.initial;
762
+ return this.verifyAccountSecret(record.id, LEGACY_DEFAULT_PASSWORD) ? LEGACY_DEFAULT_PASSWORD : null;
763
+ }
764
+ get accountCount() {
765
+ return this.accounts.length;
766
+ }
767
+ get anyAccountEnabled() {
768
+ return this.accounts.some((entry) => entry.enabled);
769
+ }
770
+ /** One writer for every mutation, clearing the legacy fields so a migration cannot resurrect a revoked credential. */
771
+ writeAccounts(accounts, options = {}) {
772
+ this.save({
773
+ ...this.load(),
774
+ accounts,
775
+ password: null,
776
+ apiToken: null,
777
+ apiTokens: []
778
+ });
779
+ }
780
+ setTelegramToken(id, token) {
781
+ const trimmed = token?.trim() ?? "";
782
+ const current = { ...this.load().telegram };
783
+ if (trimmed.length > 0) current[id] = trimmed;
784
+ else delete current[id];
785
+ this.save({
786
+ ...this.load(),
787
+ telegram: current
788
+ });
789
+ }
790
+ /** Drops every token whose destination is gone, so a deleted target leaves nothing behind. */
791
+ forgetTelegramTokens(keep) {
792
+ const allowed = new Set(keep);
793
+ const current = this.load().telegram;
794
+ const next = Object.fromEntries(Object.entries(current).filter(([id]) => allowed.has(id)));
795
+ if (Object.keys(next).length !== Object.keys(current).length) this.save({
796
+ ...this.load(),
797
+ telegram: next
798
+ });
799
+ }
800
+ get ddnsAccountIds() {
801
+ return Object.keys(this.load().ddns);
802
+ }
803
+ /** Null when nothing is stored, the provider differs, or the secret cannot open it. */
804
+ getDdnsCredentials(accountId, provider) {
805
+ const stored = this.load().ddns[accountId];
806
+ if (stored === void 0) return null;
807
+ const record = this.openStored(accountId, stored);
808
+ if (record === null) return null;
809
+ return record.provider === provider ? record : null;
810
+ }
811
+ /** One server's secret environment, for the spawn only; a view uses `serverEnvNames()`. */
812
+ serverEnv(serverId) {
813
+ return { ...this.load().serverEnv[serverId] ?? {} };
814
+ }
815
+ /** One job's secret environment, a separate map from a server's. */
816
+ jobEnv(jobId) {
817
+ return { ...this.load().jobEnv[jobId] ?? {} };
818
+ }
819
+ /** The names that have a value — all a view may show. Sorted. */
820
+ serverEnvNames(serverId) {
821
+ return Object.keys(this.load().serverEnv[serverId] ?? {}).sort();
822
+ }
823
+ /** A replacement, not a merge. Names are validated again here, the last point before a child's env is built. */
824
+ setServerEnv(serverId, values) {
825
+ this.setEnvOf("serverEnv", "a server", serverId, values);
826
+ }
827
+ setJobEnv(jobId, values) {
828
+ this.setEnvOf("jobEnv", "a job", jobId, values);
829
+ }
830
+ unsetServerEnv(serverId, names) {
831
+ this.unsetEnvOf("serverEnv", serverId, names);
832
+ }
833
+ unsetJobEnv(jobId, names) {
834
+ this.unsetEnvOf("jobEnv", jobId, names);
835
+ }
836
+ forgetServerEnv(serverId) {
837
+ this.forgetEnvOf("serverEnv", serverId);
838
+ }
839
+ forgetJobEnv(jobId) {
840
+ this.forgetEnvOf("jobEnv", jobId);
841
+ }
842
+ renameServerEnv(from, to) {
843
+ this.renameEnvOf("serverEnv", from, to);
844
+ }
845
+ setEnvOf(map, what, id, values) {
846
+ if (this.scope === "global") throw new Error(`${what}'s secret environment belongs to its workspace — a global secrets file cannot hold one`);
847
+ const clean = {};
848
+ for (const [name, value] of Object.entries(values)) {
849
+ if (!/^[A-Z_]\w*$/i.test(name)) throw new Error(`"${name}" is not an environment-variable name: a letter or underscore, then letters, digits or underscores`);
850
+ clean[name] = value;
851
+ }
852
+ const current = this.load();
853
+ this.save({
854
+ ...current,
855
+ [map]: {
856
+ ...current[map],
857
+ [id]: clean
858
+ }
859
+ });
860
+ }
861
+ unsetEnvOf(map, id, names) {
862
+ const current = this.load();
863
+ const existing = { ...current[map][id] ?? {} };
864
+ for (const name of names) delete existing[name];
865
+ const next = { ...current[map] };
866
+ if (Object.keys(existing).length === 0) delete next[id];
867
+ else next[id] = existing;
868
+ this.save({
869
+ ...current,
870
+ [map]: next
871
+ });
872
+ }
873
+ forgetEnvOf(map, id) {
874
+ const current = this.load();
875
+ if (current[map][id] === void 0) return;
876
+ const next = { ...current[map] };
877
+ delete next[id];
878
+ this.save({
879
+ ...current,
880
+ [map]: next
881
+ });
882
+ }
883
+ renameEnvOf(map, from, to) {
884
+ const current = this.load();
885
+ const values = current[map][from];
886
+ if (values === void 0) return;
887
+ const next = { ...current[map] };
888
+ delete next[from];
889
+ next[to] = values;
890
+ this.save({
891
+ ...current,
892
+ [map]: next
893
+ });
894
+ }
895
+ /** An empty field is dropped, so clearing every field forgets the account. */
896
+ setDdnsCredentials(accountId, provider, credentials) {
897
+ const current = this.load();
898
+ const values = readDdnsValues(credentials);
899
+ const ddns = { ...current.ddns };
900
+ if (Object.keys(values).length === 0) delete ddns[accountId];
901
+ else ddns[accountId] = {
902
+ plain: true,
903
+ provider,
904
+ values
905
+ };
906
+ this.save({
907
+ ...current,
908
+ ddns
909
+ });
910
+ }
911
+ clearDdnsCredentials(accountId) {
912
+ const current = this.load();
913
+ if (current.ddns[accountId] === void 0) return;
914
+ const ddns = { ...current.ddns };
915
+ delete ddns[accountId];
916
+ this.save({
917
+ ...current,
918
+ ddns
919
+ });
920
+ }
921
+ /** Keeps only the accounts a config still declares; returns how many were dropped. */
922
+ pruneDdnsCredentials(keep) {
923
+ const wanted = new Set(keep);
924
+ const current = this.load();
925
+ const removed = Object.keys(current.ddns).filter((id) => !wanted.has(id));
926
+ if (removed.length === 0) return 0;
927
+ const ddns = { ...current.ddns };
928
+ for (const id of removed) delete ddns[id];
929
+ this.save({
930
+ ...current,
931
+ ddns
932
+ });
933
+ return removed.length;
934
+ }
935
+ openStored(accountId, stored) {
936
+ if (isPlainDdns(stored)) return {
937
+ provider: stored.provider,
938
+ values: stored.values
939
+ };
940
+ const kdf = this.load().ddnsKdf;
941
+ if (kdf === null) {
942
+ this.warnOnce(accountId, "the file carries no key parameters");
943
+ return null;
944
+ }
945
+ const record = openDdns(accountId, stored, this.ddnsKey(kdf));
946
+ if (record === null) this.warnOnce(accountId, `the entry could not be opened — is HHOSTED_DDNS_SECRET still the one it was sealed with?`);
947
+ return record;
948
+ }
949
+ ddnsKey(kdf) {
950
+ if (this.ddnsKeyCache?.salt === kdf.salt) return this.ddnsKeyCache.key;
951
+ const key = deriveKey(this.ddnsSecret, Buffer.from(kdf.salt, "base64"), kdf.cost, DDNS_KEYLEN);
952
+ this.ddnsKeyCache = {
953
+ salt: kdf.salt,
954
+ key
955
+ };
956
+ return key;
957
+ }
958
+ warnOnce(accountId, reason) {
959
+ if (this.warnedAccounts.has(accountId)) return;
960
+ this.warnedAccounts.add(accountId);
961
+ logger.warn(`ddns: cannot read the credentials for "${accountId}" — ${reason}`);
962
+ }
963
+ /** A file that exists but cannot be parsed; read as absent, a truncated file would be overwritten with defaults. */
964
+ get configError() {
965
+ this.load();
966
+ return this.error;
967
+ }
968
+ read() {
969
+ this.error = null;
970
+ const empty = {
971
+ accounts: [],
972
+ password: null,
973
+ apiToken: null,
974
+ apiTokens: [],
975
+ telegram: {},
976
+ ddns: {},
977
+ ddnsKdf: null,
978
+ serverEnv: {},
979
+ jobEnv: {}
980
+ };
981
+ if (!fs.existsSync(this.file)) return this.inScope(empty);
982
+ let text;
983
+ try {
984
+ text = readStateFile(this.file);
985
+ } catch (error) {
986
+ this.error = `cannot read ${this.file}: ${errorMessage(error)}`;
987
+ return this.inScope(empty);
988
+ }
989
+ try {
990
+ const parsed = JSON.parse(text);
991
+ return this.inScope({
992
+ password: parsed?.password ?? null,
993
+ accounts: readAccounts(parsed?.accounts),
994
+ apiToken: parsed?.apiToken?.hash ? parsed.apiToken : null,
995
+ apiTokens: readNamedTokens(parsed?.apiTokens),
996
+ telegram: readTelegramTokens(parsed?.telegram),
997
+ ddns: readStoredDdns(parsed?.ddns),
998
+ ddnsKdf: readDdnsKdf(parsed?.ddnsKdf),
999
+ serverEnv: readServerEnv(parsed?.serverEnv),
1000
+ jobEnv: readServerEnv(parsed?.jobEnv),
1001
+ extra: unknownTopLevel(parsed)
1002
+ });
1003
+ } catch (error) {
1004
+ this.error = `${this.file} is not readable JSON (${errorMessage(error)}) — it was left untouched`;
1005
+ return this.inScope(empty);
1006
+ }
1007
+ }
1008
+ inScope(contents) {
1009
+ if (this.scope === "global") return {
1010
+ ...contents,
1011
+ telegram: {},
1012
+ ddns: {},
1013
+ ddnsKdf: null,
1014
+ serverEnv: {},
1015
+ jobEnv: {}
1016
+ };
1017
+ if (this.scope === "workspace") return {
1018
+ ...contents,
1019
+ accounts: [],
1020
+ password: null,
1021
+ apiToken: null,
1022
+ apiTokens: []
1023
+ };
1024
+ return contents;
1025
+ }
1026
+ save(contents) {
1027
+ if (this.configError !== null) throw new Error(`refusing to write ${this.file}: ${this.error}`);
1028
+ const sealed = this.sealStored(this.inScope(contents));
1029
+ const { extra, ...known } = sealed;
1030
+ writeFileAtomic(this.file, `${JSON.stringify({
1031
+ ...known,
1032
+ ...extra
1033
+ }, null, 2)}\n`, { mode: 384 });
1034
+ this.cache = sealed;
1035
+ }
1036
+ /** Any write seals the entries still sitting in the clear, so the file never keeps both. */
1037
+ sealStored(contents) {
1038
+ const plain = Object.entries(contents.ddns).filter((entry) => isPlainDdns(entry[1]));
1039
+ if (plain.length === 0) return contents;
1040
+ if (this.usingDefaultDdnsSecret && !this.warnedDefaultSecret) {
1041
+ this.warnedDefaultSecret = true;
1042
+ logger.warn(`ddns: credentials are sealed under the built-in key — set HHOSTED_DDNS_SECRET to protect them if this state directory is ever copied or committed (docs/DDNS.md)`);
1043
+ }
1044
+ const kdf = contents.ddnsKdf ?? newDdnsKdf();
1045
+ const key = this.ddnsKey(kdf);
1046
+ const ddns = { ...contents.ddns };
1047
+ for (const [accountId, record] of plain) ddns[accountId] = sealDdns(accountId, {
1048
+ provider: record.provider,
1049
+ values: record.values
1050
+ }, key);
1051
+ return {
1052
+ ...contents,
1053
+ ddns,
1054
+ ddnsKdf: kdf
1055
+ };
1056
+ }
1057
+ };
1058
+ //#endregion
1059
+ export { scopeCatalogue as a, generateAccountSecret as c, generateInitialPassword as i, LEGACY_TELEGRAM_ID as n, secrets_exports as o, SecretsStore as r, accountIdProblem as s, AccountError as t };
1060
+
1061
+ //# sourceMappingURL=secrets-CG5N4lwY.js.map