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,2082 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
+ import { E as errorMessage, g as invocation } from "../cli.js";
3
+ import { t as writeFileAtomic } from "./atomic-SZUwDtGD.js";
4
+ import { n as readStateFile } from "./config-text-DxMOQQnk.js";
5
+ import { i as parseWorkspaceSettings, l as planConfigMigrations, n as parseServersFile, r as parseTolerant, s as stampConfig } from "./parse-DVMPLUDe.js";
6
+ import { Ft as ddnsConfigSchema, N as logsSchema, W as serverSchema, _ as entryHasJobFields, d as defaultsSchema, g as duplicateWebhookIds, z as notificationsSchema } from "./contracts-CxZ7u1L3.js";
7
+ import { a as mergeDefaults, c as serversFileSchema, l as workspaceSettingsSchema } from "./schema-CZ6f-PHD.js";
8
+ import { a as SEED_SERVERS_FILE, c as EMPTY_MERGE_KEYS, d as SERVER_MERGE_KEYS, f as applyPatch, l as NOTIFICATION_MERGE_KEYS, o as SEED_WORKSPACE_SETTINGS, r as assertSaveable, s as DDNS_MERGE_KEYS, t as ConfigError } from "./settings-CtYDs5PX.js";
9
+ import process from "node:process";
10
+ import path from "node:path";
11
+ import fs from "node:fs";
12
+ import { Buffer } from "node:buffer";
13
+ import { type } from "arktype";
14
+ //#region src/providers/ddns/types.ts
15
+ function succeeded(message, changed) {
16
+ return {
17
+ ok: true,
18
+ changed,
19
+ message
20
+ };
21
+ }
22
+ function failed(error, permanent = false) {
23
+ return {
24
+ ok: false,
25
+ changed: false,
26
+ message: error,
27
+ error,
28
+ ...permanent ? { permanent: true } : {}
29
+ };
30
+ }
31
+ /**
32
+ * The result of a provider's write: a non-ok response is an error with its body, an ok one a change.
33
+ * The message names the record.
34
+ */
35
+ async function wrote(response, record) {
36
+ if (!response.ok) {
37
+ /**
38
+ * 401 and 403 are permanent: the same credential will be rejected again. A 429, 5xx or 404 may be
39
+ * temporary and is retried.
40
+ */
41
+ const rejected = response.status === 401 || response.status === 403;
42
+ return failed(await errorText(response), rejected);
43
+ }
44
+ return succeeded(`set ${record.host} ${record.type} to ${record.ip}`, true);
45
+ }
46
+ function missingFields(credentials, keys) {
47
+ const missing = keys.filter((key) => (credentials?.[key] ?? "").trim().length === 0);
48
+ return missing.length === 0 ? null : `set ${missing.join(", ")}`;
49
+ }
50
+ function basicAuth(user, password) {
51
+ return `Basic ${Buffer.from(`${user}:${password}`, "utf8").toString("base64")}`;
52
+ }
53
+ /** A provider error body is useful, but never worth throwing over. */
54
+ async function errorText(response, limit = 300) {
55
+ try {
56
+ const text = (await response.text()).replace(/\s+/g, " ").trim();
57
+ return text.length === 0 ? `HTTP ${response.status}` : `HTTP ${response.status}: ${text.slice(0, limit)}`;
58
+ } catch {
59
+ return `HTTP ${response.status}`;
60
+ }
61
+ }
62
+ var NORMALIZE_DOTS = /\.$/;
63
+ function normalizeHost(host) {
64
+ return host.trim().toLowerCase().replace(NORMALIZE_DOTS, "");
65
+ }
66
+ //#endregion
67
+ //#region src/providers/ddns/cloudflare.ts
68
+ var API$5 = "https://api.cloudflare.com/client/v4";
69
+ function authHeaders(credentials) {
70
+ const token = (credentials.apiToken ?? "").trim();
71
+ if (token.length > 0) return { Authorization: `Bearer ${token}` };
72
+ const email = (credentials.email ?? "").trim();
73
+ const key = (credentials.apiKey ?? "").trim();
74
+ if (email.length > 0 && key.length > 0) return {
75
+ "X-Auth-Email": email,
76
+ "X-Auth-Key": key
77
+ };
78
+ return null;
79
+ }
80
+ async function call$1(path, headers, context, init = {}) {
81
+ try {
82
+ const response = await context.fetch(`${API$5}${path}`, {
83
+ ...init,
84
+ headers: {
85
+ ...headers,
86
+ "Content-Type": "application/json",
87
+ ...init.headers ?? {}
88
+ },
89
+ signal: context.signal
90
+ });
91
+ const text = await response.text();
92
+ let parsed;
93
+ try {
94
+ parsed = JSON.parse(text);
95
+ } catch {
96
+ return {
97
+ data: null,
98
+ status: response.status,
99
+ error: `cloudflare answered ${response.status}: ${text.slice(0, 200)}`
100
+ };
101
+ }
102
+ if (!response.ok || parsed.success !== true) {
103
+ const detail = (parsed.errors ?? []).map((entry) => `${entry.code} ${entry.message}`).join("; ");
104
+ return {
105
+ data: parsed,
106
+ status: response.status,
107
+ error: detail.length > 0 ? detail : `HTTP ${response.status}`
108
+ };
109
+ }
110
+ return {
111
+ data: parsed,
112
+ status: response.status,
113
+ error: null
114
+ };
115
+ } catch (error) {
116
+ return {
117
+ data: null,
118
+ status: 0,
119
+ error: errorMessage(error)
120
+ };
121
+ }
122
+ }
123
+ /**
124
+ * Walks the host's parents through `GET /zones?name=`; the id is cached. A cached id is confirmed
125
+ * before use, so a stale one (zone deleted, token swapped) falls back to the walk.
126
+ */
127
+ async function resolveZone(host, headers, context, cached) {
128
+ if (cached !== void 0) {
129
+ const confirmed = await call$1(`/zones/${cached}`, headers, context);
130
+ if (confirmed.error === null && confirmed.data !== null) return {
131
+ id: cached,
132
+ name: host
133
+ };
134
+ if (confirmed.status === 0) throw new Error(confirmed.error ?? "could not reach Cloudflare");
135
+ }
136
+ const labels = host.split(".");
137
+ for (let index = 0; index <= labels.length - 2; index++) {
138
+ const candidate = labels.slice(index).join(".");
139
+ const { data, error } = await call$1(`/zones?name=${encodeURIComponent(candidate)}&per_page=1`, headers, context);
140
+ if (error !== null || data === null) throw new Error(error ?? "could not look up the zone");
141
+ const zone = data.result[0];
142
+ if (zone !== void 0) return zone;
143
+ }
144
+ return null;
145
+ }
146
+ async function findRecord(zoneId, record, headers, context, cached) {
147
+ if (cached !== void 0) {
148
+ const fetched = await call$1(`/zones/${zoneId}/dns_records/${cached}`, headers, context);
149
+ if (fetched.error === null && fetched.data !== null) return {
150
+ record: fetched.data.result,
151
+ error: null
152
+ };
153
+ if (fetched.status !== 404 && fetched.status !== 400) return {
154
+ record: null,
155
+ error: fetched.error
156
+ };
157
+ }
158
+ const listed = await call$1(`/zones/${zoneId}/dns_records?type=${record.type}&name=${encodeURIComponent(record.host)}&per_page=100`, headers, context);
159
+ if (listed.error !== null) return {
160
+ record: null,
161
+ error: listed.error
162
+ };
163
+ return {
164
+ record: (listed.data?.result ?? []).find((entry) => entry.id !== void 0) ?? null,
165
+ error: null
166
+ };
167
+ }
168
+ var cloudflareProvider = {
169
+ id: "cloudflare",
170
+ label: "Cloudflare",
171
+ docsUrl: "https://developers.cloudflare.com/api/resources/dns/subresources/records/",
172
+ families: ["A", "AAAA"],
173
+ ttl: true,
174
+ proxied: true,
175
+ fields: [
176
+ {
177
+ key: "apiToken",
178
+ label: "API token",
179
+ hint: "Zone → DNS → Edit (plus Zone → Zone → Read) for your zones. Preferred.",
180
+ optional: true
181
+ },
182
+ {
183
+ key: "email",
184
+ label: "Account email",
185
+ hint: "Only for the legacy Global API Key.",
186
+ optional: true
187
+ },
188
+ {
189
+ key: "apiKey",
190
+ label: "Global API key",
191
+ hint: "Legacy; prefer an API token.",
192
+ optional: true
193
+ }
194
+ ],
195
+ validate(credentials) {
196
+ if (authHeaders(credentials ?? {}) !== null) return null;
197
+ return missingFields(credentials, ["apiToken"]);
198
+ },
199
+ async update(record, context) {
200
+ const headers = authHeaders(context.credentials);
201
+ if (headers === null) return failed("cloudflare needs an API token (or the legacy email + global key)");
202
+ try {
203
+ const zone = await resolveZone(record.host, headers, context, record.cache?.zoneId);
204
+ if (zone === null) return failed(`cloudflare does not have a zone for ${record.host}`);
205
+ const ttl = record.proxied ? 1 : record.ttl;
206
+ const found = await findRecord(zone.id, record, headers, context, record.cache?.recordId);
207
+ if (found.error !== null) return failed(found.error);
208
+ const existing = found.record;
209
+ if (existing !== null && existing.content === record.ip && existing.ttl === ttl && existing.proxied === record.proxied) return {
210
+ ...succeeded(`already ${record.ip}`, false),
211
+ cache: {
212
+ zoneId: zone.id,
213
+ recordId: existing.id
214
+ }
215
+ };
216
+ const cache = {
217
+ zoneId: zone.id,
218
+ recordId: existing?.id
219
+ };
220
+ const body = JSON.stringify({
221
+ type: record.type,
222
+ name: record.host,
223
+ content: record.ip,
224
+ ttl,
225
+ proxied: record.proxied
226
+ });
227
+ const written = existing === null ? await call$1(`/zones/${zone.id}/dns_records`, headers, context, {
228
+ method: "POST",
229
+ body
230
+ }) : await call$1(`/zones/${zone.id}/dns_records/${existing.id}`, headers, context, {
231
+ method: "PATCH",
232
+ body
233
+ });
234
+ if (written.error !== null) return failed(written.error);
235
+ return {
236
+ ...succeeded(`set ${record.host} ${record.type} to ${record.ip}`, true),
237
+ cache: {
238
+ ...cache,
239
+ recordId: written.data?.result?.id ?? existing?.id
240
+ }
241
+ };
242
+ } catch (error) {
243
+ return failed(errorMessage(error));
244
+ }
245
+ },
246
+ /** One `_acme-challenge` TXT record, via per-record endpoints: nothing else in the zone is rewritten. */
247
+ async challenge(record, context) {
248
+ const headers = authHeaders(context.credentials);
249
+ if (headers === null) return {
250
+ ok: false,
251
+ message: "cloudflare needs an API token (or the legacy email + global key)"
252
+ };
253
+ try {
254
+ const zone = await resolveZone(record.fqdn, headers, context, void 0);
255
+ if (zone === null) return {
256
+ ok: false,
257
+ message: `cloudflare does not have a zone for ${record.fqdn}`
258
+ };
259
+ const listed = await call$1(`/zones/${zone.id}/dns_records?type=TXT&name=${encodeURIComponent(record.fqdn)}&per_page=100`, headers, context);
260
+ if (listed.error !== null) return {
261
+ ok: false,
262
+ message: listed.error
263
+ };
264
+ const ours = (listed.data?.result ?? []).filter((entry) => entry.id !== void 0).filter((entry) => entry.content === record.value);
265
+ if (record.action === "present") {
266
+ if (ours.length > 0) return {
267
+ ok: true,
268
+ message: `${record.fqdn} already carries this value`
269
+ };
270
+ const written = await call$1(`/zones/${zone.id}/dns_records`, headers, context, {
271
+ method: "POST",
272
+ body: JSON.stringify({
273
+ type: "TXT",
274
+ name: record.fqdn,
275
+ content: record.value,
276
+ ttl: 1
277
+ })
278
+ });
279
+ if (written.error !== null) return {
280
+ ok: false,
281
+ message: written.error
282
+ };
283
+ return {
284
+ ok: true,
285
+ message: `wrote the TXT record for ${record.fqdn}`
286
+ };
287
+ }
288
+ for (const entry of ours) {
289
+ const removed = await call$1(`/zones/${zone.id}/dns_records/${entry.id}`, headers, context, { method: "DELETE" });
290
+ if (removed.error !== null && removed.status !== 404) return {
291
+ ok: false,
292
+ message: removed.error
293
+ };
294
+ }
295
+ if (ours.length === 0) return {
296
+ ok: true,
297
+ message: `${record.fqdn} had no challenge record to remove`
298
+ };
299
+ return {
300
+ ok: true,
301
+ message: `removed the TXT record for ${record.fqdn}`
302
+ };
303
+ } catch (error) {
304
+ return {
305
+ ok: false,
306
+ message: errorMessage(error)
307
+ };
308
+ }
309
+ }
310
+ };
311
+ //#endregion
312
+ //#region src/providers/ddns/dyndns2.ts
313
+ /**
314
+ * The dyndns2 reply vocabulary, shared by every `…/nic/update` endpoint. A
315
+ * provider that answers something else maps its own text instead.
316
+ */
317
+ var CODES = {
318
+ "good": {
319
+ ok: true,
320
+ changed: true,
321
+ message: "updated",
322
+ permanent: false
323
+ },
324
+ "nochg": {
325
+ ok: true,
326
+ changed: false,
327
+ message: "already current",
328
+ permanent: false
329
+ },
330
+ "nohost": {
331
+ ok: false,
332
+ changed: false,
333
+ message: "the provider does not know this hostname",
334
+ permanent: true
335
+ },
336
+ "notfqdn": {
337
+ ok: false,
338
+ changed: false,
339
+ message: "the provider wants a fully qualified hostname",
340
+ permanent: true
341
+ },
342
+ "numhost": {
343
+ ok: false,
344
+ changed: false,
345
+ message: "too many hostnames for this provider",
346
+ permanent: true
347
+ },
348
+ "badauth": {
349
+ ok: false,
350
+ changed: false,
351
+ message: "the provider rejected the credentials",
352
+ permanent: true
353
+ },
354
+ "badagent": {
355
+ ok: false,
356
+ changed: false,
357
+ message: "the provider rejected this client (User-Agent)",
358
+ permanent: true
359
+ },
360
+ "!donator": {
361
+ ok: false,
362
+ changed: false,
363
+ message: "this feature needs a paid provider plan",
364
+ permanent: true
365
+ },
366
+ "abuse": {
367
+ ok: false,
368
+ changed: false,
369
+ message: "the provider blocked this account for abuse",
370
+ permanent: true
371
+ },
372
+ "dnserr": {
373
+ ok: false,
374
+ changed: false,
375
+ message: "the provider had a DNS error",
376
+ permanent: false
377
+ },
378
+ "servererror": {
379
+ ok: false,
380
+ changed: false,
381
+ message: "the provider had a server error",
382
+ permanent: false
383
+ },
384
+ "911": {
385
+ ok: false,
386
+ changed: false,
387
+ message: "the provider is down; it asks you to wait about 30 minutes",
388
+ permanent: false
389
+ },
390
+ "unknown": {
391
+ ok: false,
392
+ changed: false,
393
+ message: "the provider answered with an unknown error",
394
+ permanent: false
395
+ }
396
+ };
397
+ function parseDyndnsReply(body) {
398
+ const trimmed = body.trim();
399
+ const separator = trimmed.search(/\s/);
400
+ if (separator < 0) return {
401
+ code: trimmed.toLowerCase(),
402
+ detail: ""
403
+ };
404
+ return {
405
+ code: trimmed.slice(0, separator).toLowerCase(),
406
+ detail: trimmed.slice(separator).trim()
407
+ };
408
+ }
409
+ function describeDyndnsReply(body, provider) {
410
+ const { code, detail } = parseDyndnsReply(body);
411
+ const known = CODES[code];
412
+ if (known === void 0) return failed(`${provider} answered "${(body.trim() || "an empty body").slice(0, 120)}"`);
413
+ if (known.ok) return succeeded(`${known.message}${detail.length === 0 ? "" : ` (${detail})`}`, known.changed);
414
+ return failed(`${known.message}${detail.length === 0 ? "" : `: ${detail}`}`, known.permanent);
415
+ }
416
+ /**
417
+ * A 401/400 with a non-dyndns2 body is still an answer worth quoting; a known
418
+ * code wins, because several of these endpoints report errors with HTTP 200.
419
+ */
420
+ function describeDyndnsResponse(response, body, provider) {
421
+ const { code } = parseDyndnsReply(body);
422
+ if (!response.ok && CODES[code] === void 0) {
423
+ const text = body.replace(/\s+/g, " ").trim().slice(0, 160);
424
+ return failed(`${provider} answered HTTP ${response.status}${text.length === 0 ? "" : `: ${text}`}`);
425
+ }
426
+ return describeDyndnsReply(body, provider);
427
+ }
428
+ //#endregion
429
+ //#region src/providers/ddns/desec.ts
430
+ var ENDPOINT$7 = "https://update.dedyn.io/";
431
+ var desecProvider = {
432
+ id: "desec",
433
+ label: "deSEC",
434
+ docsUrl: "https://desec.readthedocs.io/en/latest/dyndns/update-api.html",
435
+ families: ["A", "AAAA"],
436
+ ttl: false,
437
+ proxied: false,
438
+ fields: [{
439
+ key: "token",
440
+ label: "API token",
441
+ hint: "desec.io → Token management; the token must allow the RRset update.",
442
+ optional: false
443
+ }],
444
+ validate(credentials) {
445
+ return missingFields(credentials, ["token"]);
446
+ },
447
+ async update(record, context) {
448
+ const token = (context.credentials.token ?? "").trim();
449
+ if (token.length === 0) return failed("desec needs an API token");
450
+ const family = record.type === "A" ? `myipv4=${encodeURIComponent(record.ip)}` : `myipv6=${encodeURIComponent(record.ip)}`;
451
+ const url = `${ENDPOINT$7}?hostname=${encodeURIComponent(record.host)}&${family}`;
452
+ try {
453
+ const response = await context.fetch(url, {
454
+ headers: { Authorization: basicAuth(record.host, token) },
455
+ signal: context.signal
456
+ });
457
+ return describeDyndnsResponse(response, await response.text(), "desec");
458
+ } catch (error) {
459
+ return failed(errorMessage(error));
460
+ }
461
+ }
462
+ };
463
+ //#endregion
464
+ //#region src/providers/ddns/zone.ts
465
+ /**
466
+ * Public suffixes that take one extra label, so `home.example.co.uk` splits as
467
+ * `home` in `example.co.uk` instead of `home.example` in `co.uk`. A per-domain
468
+ * `zone` overrides this, which is the escape hatch for anything not listed.
469
+ */
470
+ var MULTI_LABEL_SUFFIXES = /* @__PURE__ */ new Set([
471
+ "ac.uk",
472
+ "co.in",
473
+ "co.jp",
474
+ "co.ke",
475
+ "co.kr",
476
+ "co.nz",
477
+ "co.uk",
478
+ "co.za",
479
+ "com.au",
480
+ "com.br",
481
+ "com.cn",
482
+ "com.hk",
483
+ "com.mx",
484
+ "com.sg",
485
+ "com.tr",
486
+ "com.tw",
487
+ "edu.au",
488
+ "gov.uk",
489
+ "net.au",
490
+ "net.uk",
491
+ "org.au",
492
+ "org.uk"
493
+ ]);
494
+ /** Splits a hostname into zone and record name; `zone` short-circuits the heuristic. */
495
+ function splitHost(host, zone) {
496
+ const normalized = normalizeHost(host);
497
+ const override = normalizeHost(zone ?? "");
498
+ const resolved = override.length > 0 ? override : guessZone(normalized);
499
+ if (normalized === resolved) return {
500
+ zone: resolved,
501
+ name: "@"
502
+ };
503
+ return {
504
+ zone: resolved,
505
+ name: normalized.endsWith(`.${resolved}`) ? normalized.slice(0, -(resolved.length + 1)) : normalized
506
+ };
507
+ }
508
+ function guessZone(host) {
509
+ const labels = host.split(".");
510
+ if (labels.length <= 2) return host;
511
+ const lastTwo = labels.slice(-2).join(".");
512
+ const lastThree = labels.slice(-3).join(".");
513
+ return MULTI_LABEL_SUFFIXES.has(lastTwo) ? lastThree : lastTwo;
514
+ }
515
+ //#endregion
516
+ //#region src/providers/ddns/digitalocean.ts
517
+ var API$4 = "https://api.digitalocean.com/v2/domains";
518
+ function oceanTtl(ttl) {
519
+ return Math.max(30, ttl);
520
+ }
521
+ var digitaloceanProvider = {
522
+ id: "digitalocean",
523
+ label: "DigitalOcean",
524
+ docsUrl: "https://docs.digitalocean.com/reference/api/api-reference/#tag/Domain-Records",
525
+ families: ["A", "AAAA"],
526
+ ttl: true,
527
+ proxied: false,
528
+ fields: [{
529
+ key: "token",
530
+ label: "API token",
531
+ hint: "A personal access token with the `domain` scope.",
532
+ optional: false
533
+ }],
534
+ validate(credentials) {
535
+ return missingFields(credentials, ["token"]);
536
+ },
537
+ async update(record, context) {
538
+ const { zone, name } = splitHost(record.host, record.zone);
539
+ const ttl = oceanTtl(record.ttl);
540
+ const headers = {
541
+ "Authorization": `Bearer ${(context.credentials.token ?? "").trim()}`,
542
+ "Content-Type": "application/json"
543
+ };
544
+ const collection = `${API$4}/${encodeURIComponent(zone)}/records`;
545
+ try {
546
+ const listed = await context.fetch(`${collection}?per_page=200`, {
547
+ headers,
548
+ signal: context.signal
549
+ });
550
+ if (!listed.ok) return failed(await errorText(listed));
551
+ const existing = ((await listed.json()).domain_records ?? []).find((entry) => entry.name === name && entry.type === record.type);
552
+ if (existing !== void 0 && existing.data === record.ip) return succeeded(`already ${record.ip}`, false);
553
+ return await wrote(existing === void 0 ? await context.fetch(collection, {
554
+ method: "POST",
555
+ headers,
556
+ body: JSON.stringify({
557
+ type: record.type,
558
+ name,
559
+ data: record.ip,
560
+ ttl
561
+ }),
562
+ signal: context.signal
563
+ }) : await context.fetch(`${collection}/${existing.id}`, {
564
+ method: "PUT",
565
+ headers,
566
+ body: JSON.stringify({
567
+ type: record.type,
568
+ name,
569
+ data: record.ip,
570
+ ttl
571
+ }),
572
+ signal: context.signal
573
+ }), record);
574
+ } catch (error) {
575
+ return failed(errorMessage(error));
576
+ }
577
+ }
578
+ };
579
+ //#endregion
580
+ //#region src/providers/ddns/duckdns.ts
581
+ var ENDPOINT$6 = "https://www.duckdns.org/update";
582
+ /** DuckDNS addresses one subdomain at a time, so the label is the domain. */
583
+ function subdomain(host) {
584
+ const normalized = host.trim().toLowerCase();
585
+ return normalized.endsWith(".duckdns.org") ? normalized.slice(0, -12) : normalized;
586
+ }
587
+ var duckdnsProvider = {
588
+ id: "duckdns",
589
+ label: "DuckDNS",
590
+ docsUrl: "https://www.duckdns.org/spec.jsp",
591
+ families: ["A", "AAAA"],
592
+ ttl: false,
593
+ proxied: false,
594
+ fields: [{
595
+ key: "token",
596
+ label: "Account token",
597
+ hint: "On duckdns.org after signing in. One token covers every subdomain.",
598
+ optional: false
599
+ }],
600
+ validate(credentials) {
601
+ return missingFields(credentials, ["token"]);
602
+ },
603
+ async update(record, context) {
604
+ const token = (context.credentials.token ?? "").trim();
605
+ if (token.length === 0) return failed("duckdns needs the account token");
606
+ const family = record.type === "A" ? `ip=${encodeURIComponent(record.ip)}` : `ipv6=${encodeURIComponent(record.ip)}`;
607
+ const url = `${ENDPOINT$6}?domains=${encodeURIComponent(subdomain(record.host))}&token=${encodeURIComponent(token)}&${family}`;
608
+ try {
609
+ const response = await context.fetch(url, { signal: context.signal });
610
+ const body = (await response.text()).trim();
611
+ if (body.toUpperCase() === "OK") return succeeded(`set ${record.host} ${record.type} to ${record.ip}`, true);
612
+ if (body.toUpperCase() === "KO") return failed("duckdns rejected the token or the domain — check both in the account settings", true);
613
+ return failed(`duckdns answered "${body.slice(0, 120) || `HTTP ${response.status}`}"`);
614
+ } catch (error) {
615
+ return failed(errorMessage(error));
616
+ }
617
+ }
618
+ };
619
+ //#endregion
620
+ //#region src/providers/ddns/dynu.ts
621
+ var ENDPOINT$5 = "https://api.dynu.com/nic/update";
622
+ var dynuProvider = {
623
+ id: "dynu",
624
+ label: "Dynu",
625
+ docsUrl: "https://www.dynu.com/DynamicDNS/IP-Update-Protocol",
626
+ families: ["A", "AAAA"],
627
+ ttl: false,
628
+ proxied: false,
629
+ fields: [{
630
+ key: "username",
631
+ label: "Username",
632
+ hint: "Dynu username; used for HTTP Basic auth.",
633
+ optional: false
634
+ }, {
635
+ key: "password",
636
+ label: "Password",
637
+ hint: "Account password, or its SHA-256 hash.",
638
+ optional: false
639
+ }],
640
+ validate(credentials) {
641
+ return missingFields(credentials, ["username", "password"]);
642
+ },
643
+ async update(record, context) {
644
+ const username = (context.credentials.username ?? "").trim();
645
+ const password = (context.credentials.password ?? "").trim();
646
+ if (username.length === 0 || password.length === 0) return failed("dynu needs the username and password");
647
+ const address = record.type === "A" ? `myip=${encodeURIComponent(record.ip)}` : `myipv6=${encodeURIComponent(record.ip)}`;
648
+ const url = `${ENDPOINT$5}?hostname=${encodeURIComponent(record.host)}&${address}`;
649
+ try {
650
+ const response = await context.fetch(url, {
651
+ headers: { Authorization: basicAuth(username, password) },
652
+ signal: context.signal
653
+ });
654
+ return describeDyndnsResponse(response, await response.text(), "dynu");
655
+ } catch (error) {
656
+ return failed(errorMessage(error));
657
+ }
658
+ }
659
+ };
660
+ //#endregion
661
+ //#region src/providers/ddns/freedns.ts
662
+ var ENDPOINT$4 = "https://freedns.afraid.org/dynamic/update.php";
663
+ /**
664
+ * FreeDNS credentials *are* a URL: the per-record "Direct URL" hash. Both the
665
+ * bare hash and the whole URL are accepted, because that is what people copy.
666
+ */
667
+ function updateToken(credentials) {
668
+ const raw = (credentials.token ?? "").trim();
669
+ if (raw.length === 0) return "";
670
+ return (raw.includes("?") ? raw.slice(raw.indexOf("?") + 1) : raw).replace(/^https?:\/\/[^?]*\?/, "");
671
+ }
672
+ var freednsProvider = {
673
+ id: "freedns",
674
+ label: "FreeDNS (afraid.org)",
675
+ docsUrl: "https://freedns.afraid.org/faq/",
676
+ families: ["A", "AAAA"],
677
+ ttl: false,
678
+ proxied: false,
679
+ fields: [{
680
+ key: "token",
681
+ label: "Direct URL",
682
+ hint: "FreeDNS → Dynamic DNS → the per-record \"Direct URL\". Paste the whole URL or just its hash.",
683
+ optional: false
684
+ }],
685
+ validate(credentials) {
686
+ return missingFields(credentials, ["token"]);
687
+ },
688
+ async update(record, context) {
689
+ const token = updateToken(context.credentials);
690
+ if (token.length === 0) return failed("freedns needs the per-record Direct URL");
691
+ try {
692
+ const response = await context.fetch(`${ENDPOINT$4}?${token}&address=${encodeURIComponent(record.ip)}`, { signal: context.signal });
693
+ const body = (await response.text()).trim();
694
+ if (!response.ok || /^ERROR/i.test(body)) return failed(`freedns answered "${body.slice(0, 160) || `HTTP ${response.status}`}"`);
695
+ return succeeded(`set ${record.host} ${record.type} to ${record.ip}`, true);
696
+ } catch (error) {
697
+ return failed(errorMessage(error));
698
+ }
699
+ }
700
+ };
701
+ //#endregion
702
+ //#region src/providers/ddns/gandi.ts
703
+ var API$3 = "https://api.gandi.net/v5/livedns/domains";
704
+ /** Gandi's documented minimum; `1` (automatic) has no meaning here. */
705
+ function gandiTtl(ttl) {
706
+ return Math.min(2592e3, Math.max(300, ttl));
707
+ }
708
+ /** A Personal Access Token (`pat_…`) is preferred; the legacy API key is still accepted. */
709
+ function authHeader(token) {
710
+ return token.startsWith("pat_") ? `Bearer ${token}` : `Apikey ${token}`;
711
+ }
712
+ var gandiProvider = {
713
+ id: "gandi",
714
+ label: "Gandi",
715
+ docsUrl: "https://api.gandi.net/docs/livedns/",
716
+ families: ["A", "AAAA"],
717
+ ttl: true,
718
+ proxied: false,
719
+ fields: [{
720
+ key: "token",
721
+ label: "Personal access token",
722
+ hint: "A `pat_…` token from admin.gandi.net → Organizations. A legacy API key also works.",
723
+ optional: false
724
+ }],
725
+ validate(credentials) {
726
+ return missingFields(credentials, ["token"]);
727
+ },
728
+ async update(record, context) {
729
+ const token = (context.credentials.token ?? "").trim();
730
+ if (token.length === 0) return failed("gandi needs an API token");
731
+ const { zone, name } = splitHost(record.host, record.zone);
732
+ const ttl = gandiTtl(record.ttl);
733
+ const url = `${API$3}/${encodeURIComponent(zone)}/records/${encodeURIComponent(name)}/${record.type}`;
734
+ const headers = {
735
+ "Authorization": authHeader(token),
736
+ "Content-Type": "application/json"
737
+ };
738
+ try {
739
+ const current = await context.fetch(url, {
740
+ headers,
741
+ signal: context.signal
742
+ });
743
+ if (current.ok) {
744
+ const body = await current.json();
745
+ if (body.rrset_values?.length === 1 && body.rrset_values[0] === record.ip) return succeeded(`already ${record.ip}`, false);
746
+ }
747
+ return await wrote(await context.fetch(url, {
748
+ method: "PUT",
749
+ headers,
750
+ body: JSON.stringify({
751
+ rrset_values: [record.ip],
752
+ rrset_ttl: ttl
753
+ }),
754
+ signal: context.signal
755
+ }), record);
756
+ } catch (error) {
757
+ return failed(errorMessage(error));
758
+ }
759
+ }
760
+ };
761
+ //#endregion
762
+ //#region src/providers/ddns/godaddy.ts
763
+ var API$2 = "https://api.godaddy.com/v1/domains";
764
+ /** GoDaddy's floor; `1` (automatic) has no meaning here. */
765
+ function godaddyTtl(ttl) {
766
+ return Math.min(86400, Math.max(600, ttl));
767
+ }
768
+ var godaddyProvider = {
769
+ id: "godaddy",
770
+ label: "GoDaddy",
771
+ docsUrl: "https://developer.godaddy.com/doc/endpoint/dns",
772
+ families: ["A", "AAAA"],
773
+ ttl: true,
774
+ proxied: false,
775
+ fields: [
776
+ {
777
+ key: "key",
778
+ label: "API key",
779
+ hint: "developer.godaddy.com/keys.",
780
+ optional: false
781
+ },
782
+ {
783
+ key: "secret",
784
+ label: "API secret",
785
+ hint: "Shown once with the key.",
786
+ optional: false
787
+ },
788
+ {
789
+ key: "baseUrl",
790
+ label: "API base URL",
791
+ hint: "Optional; use https://api.ote-godaddy.com to rehearse against the test environment.",
792
+ optional: true
793
+ }
794
+ ],
795
+ validate(credentials) {
796
+ return missingFields(credentials, ["key", "secret"]);
797
+ },
798
+ async update(record, context) {
799
+ const { zone, name } = splitHost(record.host, record.zone);
800
+ const ttl = godaddyTtl(record.ttl);
801
+ const url = `${(context.credentials.baseUrl ?? "").trim() || API$2}/${encodeURIComponent(zone)}/records/${record.type}/${encodeURIComponent(name)}`;
802
+ const headers = {
803
+ "Authorization": `sso-key ${context.credentials.key ?? ""}:${context.credentials.secret ?? ""}`,
804
+ "Content-Type": "application/json"
805
+ };
806
+ try {
807
+ const current = await context.fetch(url, {
808
+ headers,
809
+ signal: context.signal
810
+ });
811
+ if (current.ok) {
812
+ const body = await current.json();
813
+ if (body.length === 1 && body[0]?.data === record.ip) return succeeded(`already ${record.ip}`, false);
814
+ }
815
+ return await wrote(await context.fetch(url, {
816
+ method: "PUT",
817
+ headers,
818
+ body: JSON.stringify([{
819
+ data: record.ip,
820
+ ttl
821
+ }]),
822
+ signal: context.signal
823
+ }), record);
824
+ } catch (error) {
825
+ return failed(errorMessage(error));
826
+ }
827
+ }
828
+ };
829
+ //#endregion
830
+ //#region src/providers/ddns/henet.ts
831
+ var ENDPOINT$3 = "https://dyn.dns.he.net/nic/update";
832
+ /** Hurricane Electric keeps a per-host DDNS key, shown in its DNS panel. */
833
+ var henetProvider = {
834
+ id: "henet",
835
+ label: "Hurricane Electric",
836
+ docsUrl: "https://dns.he.net/docs.html",
837
+ families: ["A", "AAAA"],
838
+ ttl: false,
839
+ proxied: false,
840
+ fields: [{
841
+ key: "key",
842
+ label: "DDNS key",
843
+ hint: "dns.he.net → the key shown next to the host when DDNS is enabled.",
844
+ optional: false
845
+ }],
846
+ validate(credentials) {
847
+ return missingFields(credentials, ["key"]);
848
+ },
849
+ async update(record, context) {
850
+ const key = (context.credentials.key ?? "").trim();
851
+ if (key.length === 0) return failed("hurricane electric needs the per-host DDNS key");
852
+ const url = `${ENDPOINT$3}?hostname=${encodeURIComponent(record.host)}&password=${encodeURIComponent(key)}&myip=${encodeURIComponent(record.ip)}`;
853
+ try {
854
+ const response = await context.fetch(url, { signal: context.signal });
855
+ return describeDyndnsResponse(response, await response.text(), "hurricane electric");
856
+ } catch (error) {
857
+ return failed(errorMessage(error));
858
+ }
859
+ }
860
+ };
861
+ //#endregion
862
+ //#region src/providers/ddns/namecheap.ts
863
+ var ENDPOINT$2 = "https://dynamicdns.park-your-domain.com/update";
864
+ function tag(body, name) {
865
+ return new RegExp(`<${name}>([\\s\\S]*?)</${name}>`, "i").exec(body)?.[1]?.trim() ?? null;
866
+ }
867
+ /**
868
+ * Namecheap's router-style Dynamic DNS: one GET, one A record, HTTP 200 even on
869
+ * failure — the XML `ErrCount` is the only truth.
870
+ */
871
+ var namecheapProvider = {
872
+ id: "namecheap",
873
+ label: "Namecheap",
874
+ docsUrl: "https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-to-dynamically-update-the-hosts-ip-with-an-https-request/",
875
+ families: ["A"],
876
+ ttl: false,
877
+ proxied: false,
878
+ fields: [{
879
+ key: "password",
880
+ label: "Dynamic DNS password",
881
+ hint: "Dashboard → Manage domain → Advanced DNS → Dynamic DNS. Not your account password or API key.",
882
+ optional: false
883
+ }],
884
+ validate(credentials) {
885
+ return missingFields(credentials, ["password"]);
886
+ },
887
+ async update(record, context) {
888
+ const password = (context.credentials.password ?? "").trim();
889
+ if (password.length === 0) return failed("namecheap needs the Dynamic DNS password");
890
+ const { zone, name } = splitHost(record.host, record.zone);
891
+ const host = name === "@" ? "@" : name;
892
+ const url = `${ENDPOINT$2}?host=${encodeURIComponent(host)}&domain=${encodeURIComponent(zone)}&password=${encodeURIComponent(password)}&ip=${encodeURIComponent(record.ip)}`;
893
+ try {
894
+ const body = await (await context.fetch(url, { signal: context.signal })).text();
895
+ const errCount = Number.parseInt(tag(body, "ErrCount") ?? "0", 10);
896
+ const ip = tag(body, "IP");
897
+ if (errCount > 0) {
898
+ const first = tag(body, "Err1");
899
+ return failed(`namecheap rejected the update${first === null ? "" : `: ${first}`}`);
900
+ }
901
+ if (ip === null) return failed(`namecheap answered without an IP: ${body.replace(/\s+/g, " ").slice(0, 160)}`);
902
+ return succeeded(`${host === "@" ? zone : `${host}.${zone}`} now ${ip}`, ip !== record.ip);
903
+ } catch (error) {
904
+ return failed(errorMessage(error));
905
+ }
906
+ }
907
+ };
908
+ //#endregion
909
+ //#region src/providers/ddns/namecheap-api.ts
910
+ /**
911
+ * Namecheap through its XML API, the only way to write a `TXT` record there. `setHosts` replaces the
912
+ * whole record set, so a challenge is a read-modify-write of the zone — a separate provider with its
913
+ * own credentials, so nobody reaches that by accident.
914
+ */
915
+ var ENDPOINT$1 = "https://api.namecheap.com/xml.response";
916
+ /** The most host records one `setHosts` call can carry; a larger zone is refused rather than truncated. */
917
+ var RECORD_LIMIT = 150;
918
+ var CHALLENGE_TTL = 60;
919
+ var XML_ENTITIES = {
920
+ amp: "&",
921
+ lt: "<",
922
+ gt: ">",
923
+ quot: "\"",
924
+ apos: "'"
925
+ };
926
+ /** Values read back must be unescaped, or every rewrite would turn `a&b` into `a&amp;b`. */
927
+ function decodeXml(value) {
928
+ return value.replace(/&(#X?[0-9a-f]+|[a-z]+);/gi, (whole, body) => {
929
+ if (body.startsWith("#")) {
930
+ const hex = body[1] === "x" || body[1] === "X";
931
+ const code = Number.parseInt(hex ? body.slice(2) : body.slice(1), hex ? 16 : 10);
932
+ return Number.isInteger(code) && code >= 0 && code <= 1114111 ? String.fromCodePoint(code) : whole;
933
+ }
934
+ return XML_ENTITIES[body.toLowerCase()] ?? whole;
935
+ });
936
+ }
937
+ function attr(tagText, name) {
938
+ return decodeXml(new RegExp(`${name}="([^"]*)"`, "i").exec(tagText)?.[1] ?? "").trim();
939
+ }
940
+ function parseHosts(body) {
941
+ const records = [];
942
+ const pattern = /<Host\b([^>]*?)(?:\/>|>)/gi;
943
+ let match = pattern.exec(body);
944
+ while (match !== null) {
945
+ const attributes = match[1] ?? "";
946
+ records.push({
947
+ name: attr(attributes, "Name"),
948
+ type: attr(attributes, "Type"),
949
+ address: attr(attributes, "Address"),
950
+ mxPref: attr(attributes, "MXPref") || "10",
951
+ ttl: attr(attributes, "TTL") || "1800"
952
+ });
953
+ match = pattern.exec(body);
954
+ }
955
+ return records;
956
+ }
957
+ /** The errors a failed reply carries, as one sentence, from both `<Error Number>` and `<ErrN>` shapes. */
958
+ function describeErrors(body) {
959
+ const errors = [];
960
+ for (const match of body.matchAll(/<Error[^>]*\sNumber\s*=\s*"([^"]*)"[^>]*>([\s\S]*?)<\/Error>/gi)) {
961
+ const text = (match[2] ?? "").trim();
962
+ if (text.length === 0) continue;
963
+ const code = (match[1] ?? "").trim();
964
+ errors.push(code.length > 0 && !text.includes(code) ? `${text} (error ${code})` : text);
965
+ }
966
+ for (const match of body.matchAll(/<Err\d+>([\s\S]*?)<\/Err\d+>/gi)) {
967
+ const text = (match[1] ?? "").trim();
968
+ if (text.length > 0 && !errors.some((existing) => existing.includes(text))) errors.push(text);
969
+ }
970
+ return errors.length > 0 ? errors.join("; ") : "the API refused the request";
971
+ }
972
+ function credentials(store) {
973
+ const apiUser = (store.apiUser ?? "").trim();
974
+ const apiKey = (store.apiKey ?? "").trim();
975
+ const userName = (store.userName ?? "").trim() || apiUser;
976
+ const clientIp = (store.clientIp ?? "").trim();
977
+ if (apiUser.length === 0 || apiKey.length === 0 || clientIp.length === 0) return null;
978
+ return {
979
+ apiUser,
980
+ apiKey,
981
+ userName,
982
+ clientIp
983
+ };
984
+ }
985
+ /** The numeric codes from `<Error Number="…">` elements (e.g. `1011102`, invalid API key). */
986
+ function errorCodes(body) {
987
+ return [...body.matchAll(/<Error[^>]*\sNumber\s*=\s*"([^"]*)"/gi)].map((match) => (match[1] ?? "").trim()).filter((code) => code.length > 0);
988
+ }
989
+ /** One XML call. Namecheap answers HTTP 200 whatever happened, so the body decides. */
990
+ async function call(command, params, context) {
991
+ const auth = credentials(context.credentials);
992
+ if (auth === null) return {
993
+ message: "namecheap needs the API user, the API key and the whitelisted client IP",
994
+ codes: []
995
+ };
996
+ const query = new URLSearchParams({
997
+ ApiUser: auth.apiUser,
998
+ ApiKey: auth.apiKey,
999
+ UserName: auth.userName,
1000
+ ClientIp: auth.clientIp,
1001
+ Command: command,
1002
+ ...params
1003
+ });
1004
+ try {
1005
+ const response = await context.fetch(`${ENDPOINT$1}?${query.toString()}`, { signal: context.signal });
1006
+ const body = await response.text();
1007
+ if (!response.ok && !body.includes("<ApiResponse")) return {
1008
+ message: `namecheap answered HTTP ${response.status}`,
1009
+ codes: []
1010
+ };
1011
+ const status = /<ApiResponse[^>]*Status="([^"]*)"/i.exec(body)?.[1] ?? "";
1012
+ if (status.toUpperCase() !== "OK") return {
1013
+ message: describeErrors(body),
1014
+ codes: errorCodes(body)
1015
+ };
1016
+ return {
1017
+ status,
1018
+ errors: [],
1019
+ body
1020
+ };
1021
+ } catch (error) {
1022
+ return {
1023
+ message: errorMessage(error),
1024
+ codes: []
1025
+ };
1026
+ }
1027
+ }
1028
+ function apexParts(zone) {
1029
+ const apex = normalizeHost(zone);
1030
+ const dot = apex.indexOf(".");
1031
+ if (dot < 0) return {
1032
+ SLD: apex,
1033
+ TLD: ""
1034
+ };
1035
+ return {
1036
+ SLD: apex.slice(0, dot),
1037
+ TLD: apex.slice(dot + 1)
1038
+ };
1039
+ }
1040
+ var isFailure = (reply) => typeof reply === "object" && reply !== null && "message" in reply;
1041
+ /** A failed call as a challenge result, with Namecheap's error number in the sentence. */
1042
+ function refuse(failure) {
1043
+ return {
1044
+ ok: false,
1045
+ message: failure.message
1046
+ };
1047
+ }
1048
+ async function readHosts(zone, context) {
1049
+ const reply = await call("namecheap.domains.dns.getHosts", { ...apexParts(zone) }, context);
1050
+ if (isFailure(reply)) return reply;
1051
+ return { records: parseHosts(reply.body) };
1052
+ }
1053
+ async function writeHosts(zone, records, context) {
1054
+ const params = { ...apexParts(zone) };
1055
+ records.forEach((record, index) => {
1056
+ const at = index + 1;
1057
+ params[`HostName${at}`] = record.name;
1058
+ params[`RecordType${at}`] = record.type;
1059
+ params[`Address${at}`] = record.address;
1060
+ params[`TTL${at}`] = record.ttl;
1061
+ params[`MXPref${at}`] = record.mxPref;
1062
+ });
1063
+ const reply = await call("namecheap.domains.dns.setHosts", params, context);
1064
+ return isFailure(reply) ? reply : null;
1065
+ }
1066
+ function challengeName(fqdn, zone) {
1067
+ const normalized = normalizeHost(fqdn);
1068
+ const apex = normalizeHost(zone);
1069
+ if (normalized === apex) return "@";
1070
+ return normalized.endsWith(`.${apex}`) ? normalized.slice(0, -(apex.length + 1)) : normalized;
1071
+ }
1072
+ var namecheapApiProvider = {
1073
+ id: "namecheap-api",
1074
+ label: "Namecheap (API)",
1075
+ docsUrl: "https://www.namecheap.com/support/api/methods/domains-dns/set-hosts/",
1076
+ families: ["A"],
1077
+ ttl: true,
1078
+ proxied: false,
1079
+ fields: [
1080
+ {
1081
+ key: "apiUser",
1082
+ label: "API user",
1083
+ hint: "Dashboard → Profile → Tools → Namecheap API Access. Usually your account name.",
1084
+ optional: false
1085
+ },
1086
+ {
1087
+ key: "apiKey",
1088
+ label: "API key",
1089
+ hint: "Shown once when API access is enabled.",
1090
+ optional: false
1091
+ },
1092
+ {
1093
+ key: "userName",
1094
+ label: "User name",
1095
+ hint: "Leave empty unless the API user differs from the account.",
1096
+ optional: true
1097
+ },
1098
+ {
1099
+ key: "clientIp",
1100
+ label: "Whitelisted IP",
1101
+ hint: "The public IPv4 this panel calls from. It must be whitelisted under API Access, and error 1017105 means it is not.",
1102
+ optional: false
1103
+ }
1104
+ ],
1105
+ validate(store) {
1106
+ if (credentials(store ?? {}) !== null) return null;
1107
+ const missing = [
1108
+ "apiUser",
1109
+ "apiKey",
1110
+ "clientIp"
1111
+ ].filter((key) => (store?.[key] ?? "").trim().length === 0);
1112
+ return missing.length === 0 ? null : `set ${missing.join(", ")}`;
1113
+ },
1114
+ /** `setHosts` replaces everything, so this is a read-modify-write of the whole zone. */
1115
+ async challenge(record, context) {
1116
+ const { zone } = splitHost(record.fqdn);
1117
+ const read = await readHosts(zone, context);
1118
+ if (isFailure(read)) return refuse(read);
1119
+ const hosts = read.records;
1120
+ const name = challengeName(record.fqdn, zone);
1121
+ const isChallenge = (host) => host.type.toUpperCase() === "TXT" && host.name.toLowerCase() === name.toLowerCase();
1122
+ const isOurs = (host) => isChallenge(host) && host.address === record.value;
1123
+ if (record.action === "present") {
1124
+ if (hosts.some(isOurs)) return {
1125
+ ok: true,
1126
+ message: `${record.fqdn} already carries this value`
1127
+ };
1128
+ if (hosts.length >= RECORD_LIMIT) return {
1129
+ ok: false,
1130
+ message: `namecheap's setHosts takes at most ${RECORD_LIMIT} host records per call and ${zone} has ${hosts.length}, so the panel cannot rewrite this zone to add a challenge record`
1131
+ };
1132
+ const failure = await writeHosts(zone, [...hosts, {
1133
+ name,
1134
+ type: "TXT",
1135
+ address: record.value,
1136
+ mxPref: "10",
1137
+ ttl: String(CHALLENGE_TTL)
1138
+ }], context);
1139
+ if (failure !== null) return refuse(failure);
1140
+ return {
1141
+ ok: true,
1142
+ message: `added a TXT record for ${record.fqdn} (rewrote ${hosts.length} others)`
1143
+ };
1144
+ }
1145
+ const kept = hosts.filter((host) => !isOurs(host));
1146
+ if (kept.length === hosts.length) return {
1147
+ ok: true,
1148
+ message: `${record.fqdn} had no challenge record to remove`
1149
+ };
1150
+ const failure = await writeHosts(zone, kept, context);
1151
+ if (failure !== null) return refuse(failure);
1152
+ return {
1153
+ ok: true,
1154
+ message: `removed the TXT record for ${record.fqdn} (rewrote ${kept.length} others)`
1155
+ };
1156
+ }
1157
+ };
1158
+ //#endregion
1159
+ //#region src/providers/ddns/noip.ts
1160
+ var ENDPOINT = "https://dynupdate.no-ip.com/nic/update";
1161
+ /** No-IP rate-limits clients whose User-Agent it does not recognise. */
1162
+ var DEFAULT_AGENT = "home-hosted/1.0 (+https://github.com/NamesMT/home-hosted)";
1163
+ var noipProvider = {
1164
+ id: "noip",
1165
+ label: "No-IP",
1166
+ docsUrl: "https://www.noip.com/integrate/request",
1167
+ families: ["A", "AAAA"],
1168
+ ttl: false,
1169
+ proxied: false,
1170
+ fields: [
1171
+ {
1172
+ key: "username",
1173
+ label: "Email",
1174
+ hint: "Your No-IP account email.",
1175
+ optional: false
1176
+ },
1177
+ {
1178
+ key: "password",
1179
+ label: "Password",
1180
+ hint: "Your No-IP account password.",
1181
+ optional: false
1182
+ },
1183
+ {
1184
+ key: "userAgent",
1185
+ label: "User-Agent override",
1186
+ hint: "No-IP only guarantees updates for recognised clients; set an approved agent here if yours is registered.",
1187
+ optional: true
1188
+ }
1189
+ ],
1190
+ validate(credentials) {
1191
+ return missingFields(credentials, ["username", "password"]);
1192
+ },
1193
+ async update(record, context) {
1194
+ const username = (context.credentials.username ?? "").trim();
1195
+ const password = (context.credentials.password ?? "").trim();
1196
+ if (username.length === 0 || password.length === 0) return failed("no-ip needs the account email and password");
1197
+ const address = record.type === "A" ? `myip=${encodeURIComponent(record.ip)}` : `myipv6=${encodeURIComponent(record.ip)}`;
1198
+ const url = `${ENDPOINT}?hostname=${encodeURIComponent(record.host)}&${address}`;
1199
+ try {
1200
+ const response = await context.fetch(url, {
1201
+ headers: {
1202
+ "Authorization": basicAuth(username, password),
1203
+ "User-Agent": (context.credentials.userAgent ?? "").trim() || DEFAULT_AGENT
1204
+ },
1205
+ signal: context.signal
1206
+ });
1207
+ return describeDyndnsResponse(response, await response.text(), "no-ip");
1208
+ } catch (error) {
1209
+ return failed(errorMessage(error));
1210
+ }
1211
+ }
1212
+ };
1213
+ //#endregion
1214
+ //#region src/providers/ddns/porkbun.ts
1215
+ var API$1 = "https://api.porkbun.com/api/json/v3";
1216
+ /** Porkbun's documented floor; `1` (automatic) maps onto it. */
1217
+ function porkbunTtl(ttl) {
1218
+ return Math.max(600, ttl);
1219
+ }
1220
+ async function post(path, context, body) {
1221
+ try {
1222
+ const response = await context.fetch(`${API$1}${path}`, {
1223
+ method: "POST",
1224
+ headers: {
1225
+ "Content-Type": "application/json",
1226
+ "X-API-Key": context.credentials.apikey ?? "",
1227
+ "X-Secret-API-Key": context.credentials.secretapikey ?? ""
1228
+ },
1229
+ body: JSON.stringify(body),
1230
+ signal: context.signal
1231
+ });
1232
+ const parsed = JSON.parse(await response.text());
1233
+ if (parsed.status !== "SUCCESS") return {
1234
+ data: parsed,
1235
+ error: parsed.message ?? `HTTP ${response.status}`,
1236
+ code: parsed.code ?? null
1237
+ };
1238
+ return {
1239
+ data: parsed,
1240
+ error: null,
1241
+ code: null
1242
+ };
1243
+ } catch (error) {
1244
+ return {
1245
+ data: null,
1246
+ error: errorMessage(error),
1247
+ code: null
1248
+ };
1249
+ }
1250
+ }
1251
+ var porkbunProvider = {
1252
+ id: "porkbun",
1253
+ label: "Porkbun",
1254
+ docsUrl: "https://porkbun.com/api/json/v3/documentation",
1255
+ families: ["A", "AAAA"],
1256
+ ttl: true,
1257
+ proxied: false,
1258
+ fields: [{
1259
+ key: "apikey",
1260
+ label: "API key",
1261
+ hint: "porkbun.com/account/api — starts with pk1_.",
1262
+ optional: false
1263
+ }, {
1264
+ key: "secretapikey",
1265
+ label: "Secret API key",
1266
+ hint: "Shown once when the key is created.",
1267
+ optional: false
1268
+ }],
1269
+ validate(credentials) {
1270
+ return missingFields(credentials, ["apikey", "secretapikey"]);
1271
+ },
1272
+ async update(record, context) {
1273
+ const { zone, name: rawName } = splitHost(record.host, record.zone);
1274
+ const name = rawName === "@" ? "" : rawName;
1275
+ const ttl = porkbunTtl(record.ttl);
1276
+ const existing = (await post(`/dns/retrieveByNameType/${encodeURIComponent(zone)}/${record.type}/${encodeURIComponent(name)}`, context, {})).data?.records?.[0];
1277
+ if (existing !== void 0 && existing.content === record.ip && Number.parseInt(existing.ttl, 10) === ttl) return succeeded(`already ${record.ip}`, false);
1278
+ const written = await post(`/dns/editByNameType/${encodeURIComponent(zone)}/${record.type}/${encodeURIComponent(name)}`, context, {
1279
+ content: record.ip,
1280
+ ttl
1281
+ });
1282
+ if (written.error !== null) {
1283
+ /** The two documented codes for a wrong credential: retrying cannot fix either. */
1284
+ const rejected = written.code === "INVALID_API_KEYS_001" || written.code === "INVALID_USER";
1285
+ return failed(rejected ? `${written.error} (${written.code})` : written.error, rejected);
1286
+ }
1287
+ const warnings = written.data?.warnings ?? [];
1288
+ const note = warnings.length > 0 ? ` — porkbun warns: ${warnings.join("; ")}` : "";
1289
+ return succeeded(`set ${record.host} ${record.type} to ${record.ip}${note}`, true);
1290
+ }
1291
+ };
1292
+ //#endregion
1293
+ //#region src/providers/ddns/spaceship.ts
1294
+ var API = "https://spaceship.dev/api/v1/dns/records";
1295
+ var PAGE_SIZE = 500;
1296
+ function spaceshipTtl(ttl) {
1297
+ return Math.min(3600, Math.max(60, ttl));
1298
+ }
1299
+ //#endregion
1300
+ //#region src/providers/ddns/index.ts
1301
+ /** Registry order is what the settings page offers. */
1302
+ var DDNS_PROVIDERS = [
1303
+ cloudflareProvider,
1304
+ namecheapProvider,
1305
+ namecheapApiProvider,
1306
+ {
1307
+ id: "spaceship",
1308
+ label: "Spaceship",
1309
+ docsUrl: "https://docs.spaceship.dev/",
1310
+ families: ["A", "AAAA"],
1311
+ ttl: true,
1312
+ proxied: false,
1313
+ fields: [{
1314
+ key: "apiKey",
1315
+ label: "API key",
1316
+ hint: "spaceship.com → API Manager; needs the `dnsrecords:read`/`write` scopes.",
1317
+ optional: false
1318
+ }, {
1319
+ key: "apiSecret",
1320
+ label: "API secret",
1321
+ hint: "Shown once with the key.",
1322
+ optional: false
1323
+ }],
1324
+ validate(credentials) {
1325
+ return missingFields(credentials, ["apiKey", "apiSecret"]);
1326
+ },
1327
+ async update(record, context) {
1328
+ const { zone, name } = splitHost(record.host, record.zone);
1329
+ const headers = {
1330
+ "X-API-Key": (context.credentials.apiKey ?? "").trim(),
1331
+ "X-API-Secret": (context.credentials.apiSecret ?? "").trim(),
1332
+ "Content-Type": "application/json"
1333
+ };
1334
+ try {
1335
+ let found;
1336
+ for (let skip = 0; skip < PAGE_SIZE * 5; skip += PAGE_SIZE) {
1337
+ const listed = await context.fetch(`${API}/${encodeURIComponent(zone)}?take=${PAGE_SIZE}&skip=${skip}`, {
1338
+ headers,
1339
+ signal: context.signal
1340
+ });
1341
+ if (!listed.ok) return failed(await errorText(listed));
1342
+ const body = await listed.json();
1343
+ const items = Array.isArray(body) ? body : body.items ?? [];
1344
+ found = items.find((entry) => entry.name === name && entry.type === record.type);
1345
+ if (found !== void 0 || items.length < PAGE_SIZE) break;
1346
+ }
1347
+ if (found?.address === record.ip) return succeeded(`already ${record.ip}`, false);
1348
+ return await wrote(await context.fetch(`${API}/${encodeURIComponent(zone)}`, {
1349
+ method: "PUT",
1350
+ headers,
1351
+ body: JSON.stringify({
1352
+ force: true,
1353
+ items: [{
1354
+ type: record.type,
1355
+ name,
1356
+ ttl: spaceshipTtl(record.ttl),
1357
+ address: record.ip
1358
+ }]
1359
+ }),
1360
+ signal: context.signal
1361
+ }), record);
1362
+ } catch (error) {
1363
+ return failed(errorMessage(error));
1364
+ }
1365
+ }
1366
+ },
1367
+ porkbunProvider,
1368
+ godaddyProvider,
1369
+ gandiProvider,
1370
+ digitaloceanProvider,
1371
+ desecProvider,
1372
+ duckdnsProvider,
1373
+ noipProvider,
1374
+ dynuProvider,
1375
+ henetProvider,
1376
+ freednsProvider
1377
+ ];
1378
+ var BY_ID = new Map(DDNS_PROVIDERS.map((provider) => [provider.id, provider]));
1379
+ function ddnsProvider(id) {
1380
+ return BY_ID.get(id) ?? null;
1381
+ }
1382
+ function ddnsProviderInfos() {
1383
+ return DDNS_PROVIDERS.map((provider) => ({
1384
+ id: provider.id,
1385
+ label: provider.label,
1386
+ docsUrl: provider.docsUrl,
1387
+ families: provider.families,
1388
+ fields: provider.fields,
1389
+ ttl: provider.ttl,
1390
+ proxied: provider.proxied,
1391
+ txt: provider.challenge !== void 0
1392
+ }));
1393
+ }
1394
+ /**
1395
+ * Cross-field problems ArkType cannot see. Credentials are not required: a missing secret is
1396
+ * reported per record instead of blocking the save.
1397
+ */
1398
+ function validateDdnsConfig(config) {
1399
+ const errors = [];
1400
+ const seenAccounts = /* @__PURE__ */ new Set();
1401
+ for (const account of config.accounts) {
1402
+ if (seenAccounts.has(account.id)) {
1403
+ errors.push(`account "${account.id}" is declared twice`);
1404
+ continue;
1405
+ }
1406
+ seenAccounts.add(account.id);
1407
+ if (ddnsProvider(account.provider) === null) errors.push(`account "${account.id}" uses an unknown provider "${account.provider}"`);
1408
+ }
1409
+ const seenRecords = /* @__PURE__ */ new Set();
1410
+ for (const domain of config.domains) {
1411
+ const account = config.accounts.find((entry) => entry.id === domain.account);
1412
+ if (account === void 0) {
1413
+ errors.push(`"${domain.host}" points at unknown account "${domain.account}"`);
1414
+ continue;
1415
+ }
1416
+ const zone = domain.zone?.trim().toLowerCase();
1417
+ if (zone !== void 0 && zone.length > 0 && domain.host.toLowerCase() !== zone && !domain.host.toLowerCase().endsWith(`.${zone}`)) errors.push(`"${domain.host}" has zone "${domain.zone}", which it is not inside — a zone is the registered domain the record lives in`);
1418
+ const provider = ddnsProvider(account.provider);
1419
+ if (provider !== null) for (const recordType of domain.types) {
1420
+ if (!provider.families.includes(recordType)) errors.push(`${account.label || provider.label} cannot manage ${recordType} records ("${domain.host}")`);
1421
+ const key = `${domain.host.toLowerCase()}|${recordType}`;
1422
+ if (seenRecords.has(key)) errors.push(`"${domain.host}" asks for ${recordType} twice`);
1423
+ seenRecords.add(key);
1424
+ }
1425
+ }
1426
+ return errors;
1427
+ }
1428
+ //#endregion
1429
+ //#region src/helpers/env-file.ts
1430
+ /** `KEY=value` files, with optional `export `, `#` comments and quoted values. */
1431
+ function parseEnvFile(text) {
1432
+ const env = {};
1433
+ for (const raw of text.split("\n")) {
1434
+ const line = raw.trim();
1435
+ if (line.length === 0 || line.startsWith("#")) continue;
1436
+ const assignment = line.startsWith("export ") ? line.slice(7) : line;
1437
+ const separator = assignment.indexOf("=");
1438
+ if (separator <= 0) continue;
1439
+ const key = assignment.slice(0, separator).trim();
1440
+ let value = assignment.slice(separator + 1).trim();
1441
+ if (value.length > 1 && (value.startsWith("\"") && value.endsWith("\"") || value.startsWith("'") && value.endsWith("'"))) value = value.slice(1, -1);
1442
+ env[key] = value;
1443
+ }
1444
+ return env;
1445
+ }
1446
+ /**
1447
+ * Missing files are not an error: an env file is an optional override layer. Read through
1448
+ * `readStateFile` because a person writes it, often with a Windows BOM or UTF-16.
1449
+ */
1450
+ function loadEnvFile(file) {
1451
+ try {
1452
+ return {
1453
+ env: parseEnvFile(readStateFile(file)),
1454
+ path: file,
1455
+ error: null
1456
+ };
1457
+ } catch (error) {
1458
+ if (error.code === "ENOENT") return {
1459
+ env: {},
1460
+ path: file,
1461
+ error: null
1462
+ };
1463
+ return {
1464
+ env: {},
1465
+ path: file,
1466
+ error: errorMessage(error)
1467
+ };
1468
+ }
1469
+ }
1470
+ var VARIABLE = /\$\{([A-Z_]\w*)\}/gi;
1471
+ function expandEnv(value, vars) {
1472
+ return value.replace(VARIABLE, (match, name) => vars[name] ?? match);
1473
+ }
1474
+ function expandEnvRecord(record, vars) {
1475
+ return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, expandEnv(value, vars)]));
1476
+ }
1477
+ function expandEnvList(values, vars) {
1478
+ return values.map((value) => expandEnv(value, vars));
1479
+ }
1480
+ function resolveEnvFilePath(file, cwd) {
1481
+ if (path.isAbsolute(file)) return file;
1482
+ return path.resolve(cwd, file);
1483
+ }
1484
+ //#endregion
1485
+ //#region src/providers/webhook.ts
1486
+ /** The JSON body for one event. */
1487
+ function webhookPayload(event, now = Date.now()) {
1488
+ const text = `${event.title}\n${event.message}`;
1489
+ return {
1490
+ text,
1491
+ content: text,
1492
+ title: event.title,
1493
+ message: event.message,
1494
+ reason: event.reason,
1495
+ server: event.serverId.length > 0 ? event.serverId : null,
1496
+ label: event.label.length > 0 ? event.label : null,
1497
+ ...event.workspaceId === void 0 ? {} : { workspaceId: event.workspaceId },
1498
+ at: now
1499
+ };
1500
+ }
1501
+ /**
1502
+ * What `Headers` will refuse (a name with a space or non-ASCII, a value above `0xFF` such as an
1503
+ * emoji), decided here so the refusal quotes the line.
1504
+ */
1505
+ function headerProblem(name, value) {
1506
+ if (!/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(name)) return `"${name}" is not a valid header name`;
1507
+ for (const char of value) if (char.codePointAt(0) > 255) return `the "${name}" value holds a character a header cannot carry (${char}) — headers are bytes, so encode it (ntfy reads \`=?UTF-8?B?…?=\`) or use format: json, which carries text in the body`;
1508
+ return null;
1509
+ }
1510
+ /**
1511
+ * `Name: value` lines into a header map; only the first colon separates. `vars` expands `${ENV}` in
1512
+ * the values; an undefined name is left as written and listed in `unexpanded`.
1513
+ */
1514
+ function parseHeaders(text, vars = process.env) {
1515
+ const headers = {};
1516
+ const errors = [];
1517
+ const unexpanded = [];
1518
+ for (const line of text.split("\n")) {
1519
+ const trimmed = line.trim();
1520
+ if (trimmed.length === 0 || trimmed.startsWith("#")) continue;
1521
+ const at = trimmed.indexOf(":");
1522
+ if (at <= 0) {
1523
+ errors.push(`"${trimmed}" is not a "Name: value" header`);
1524
+ continue;
1525
+ }
1526
+ const name = trimmed.slice(0, at).trim();
1527
+ const value = expandEnv(trimmed.slice(at + 1).trim(), vars);
1528
+ if (value.includes("${")) unexpanded.push(name);
1529
+ else {
1530
+ const problem = headerProblem(name, value);
1531
+ if (problem !== null) {
1532
+ errors.push(problem);
1533
+ continue;
1534
+ }
1535
+ }
1536
+ headers[name] = value;
1537
+ }
1538
+ return {
1539
+ headers,
1540
+ errors,
1541
+ unexpanded
1542
+ };
1543
+ }
1544
+ function targetProblem(target, options = {}) {
1545
+ const url = target.url.trim();
1546
+ if (url.length === 0) return options.requireUrl === false ? null : "no URL configured";
1547
+ let parsed;
1548
+ try {
1549
+ parsed = new URL(url);
1550
+ } catch {
1551
+ return "the URL is not valid";
1552
+ }
1553
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return `the URL must be http or https, not ${parsed.protocol}`;
1554
+ const { errors, unexpanded } = parseHeaders(target.headers);
1555
+ const problems = [...errors, ...unexpanded.length > 0 ? [`the ${unexpanded.map((name) => `"${name}"`).join(", ")} header still holds an unexpanded placeholder — an environment variable in it is not set`] : []];
1556
+ return problems.length > 0 ? problems.join("; ") : null;
1557
+ }
1558
+ async function sendWebhook(target, event, fetchImpl) {
1559
+ const problem = targetProblem(target);
1560
+ if (problem !== null) return {
1561
+ ok: false,
1562
+ error: problem
1563
+ };
1564
+ const { headers, errors } = parseHeaders(target.headers);
1565
+ if (errors.length > 0) return {
1566
+ ok: false,
1567
+ error: errors.join("; ")
1568
+ };
1569
+ const payload = webhookPayload(event);
1570
+ const asText = target.format === "text";
1571
+ const body = asText ? payload.message : JSON.stringify(payload);
1572
+ const configured = target.url.trim();
1573
+ const url = expandEnv(configured, process.env);
1574
+ if (url.includes("${")) return {
1575
+ ok: false,
1576
+ error: `the URL still holds an unexpanded placeholder: ${configured}`
1577
+ };
1578
+ const sent = { "content-type": asText ? "text/plain; charset=utf-8" : "application/json" };
1579
+ for (const [name, value] of Object.entries(headers)) {
1580
+ const key = name.toLowerCase();
1581
+ for (const existing of Object.keys(sent)) if (existing.toLowerCase() === key) delete sent[existing];
1582
+ sent[name] = value;
1583
+ }
1584
+ try {
1585
+ const response = await (fetchImpl ?? fetch)(url, {
1586
+ method: target.method,
1587
+ headers: sent,
1588
+ body,
1589
+ signal: AbortSignal.timeout(1e4),
1590
+ redirect: "manual"
1591
+ });
1592
+ if (response.status >= 300 && response.status < 400) {
1593
+ const location = response.headers.get("location");
1594
+ return {
1595
+ ok: false,
1596
+ error: `answered ${response.status}, a redirect${location === null ? "" : ` to ${location.slice(0, 200)}`} — not followed; set the URL to the final address`
1597
+ };
1598
+ }
1599
+ if (!response.ok) {
1600
+ const trimmed = (await response.text().catch(() => "")).trim().slice(0, 200);
1601
+ return {
1602
+ ok: false,
1603
+ error: `answered ${response.status}${trimmed.length > 0 ? `: ${trimmed}` : ""}`
1604
+ };
1605
+ }
1606
+ return { ok: true };
1607
+ } catch (error) {
1608
+ return {
1609
+ ok: false,
1610
+ error: errorMessage(error).replaceAll(url, configured)
1611
+ };
1612
+ }
1613
+ }
1614
+ //#endregion
1615
+ //#region src/config/store.ts
1616
+ var store_exports = /* @__PURE__ */ __exportAll({
1617
+ ConfigError: () => ConfigError,
1618
+ WorkspaceStore: () => WorkspaceStore
1619
+ });
1620
+ function readFile(file) {
1621
+ let text;
1622
+ try {
1623
+ text = readStateFile(file);
1624
+ } catch (error) {
1625
+ if (error.code === "ENOENT") return {
1626
+ text: null,
1627
+ parsed: null,
1628
+ missing: true,
1629
+ parseError: null
1630
+ };
1631
+ return {
1632
+ text: null,
1633
+ parsed: null,
1634
+ missing: false,
1635
+ parseError: error.message
1636
+ };
1637
+ }
1638
+ try {
1639
+ return {
1640
+ text,
1641
+ parsed: JSON.parse(text),
1642
+ missing: false,
1643
+ parseError: null
1644
+ };
1645
+ } catch (error) {
1646
+ return {
1647
+ text,
1648
+ parsed: null,
1649
+ missing: false,
1650
+ parseError: error.message
1651
+ };
1652
+ }
1653
+ }
1654
+ /**
1655
+ * One workspace's settings file and servers file. Reads are tolerant (unknown keys are reported,
1656
+ * not fatal), and a revision that cannot be parsed never replaces what is already running.
1657
+ */
1658
+ var WorkspaceStore = class {
1659
+ workspaceId;
1660
+ settingsFile;
1661
+ serversFile;
1662
+ seedSettings;
1663
+ seedServers;
1664
+ rawSettings = {};
1665
+ rawServers = {};
1666
+ liveSettings = null;
1667
+ liveServers = null;
1668
+ /** The last revision that parsed. */
1669
+ liveSettingsText = null;
1670
+ liveServersText = null;
1671
+ /** The bytes a save patches, and so may replace. */
1672
+ trustedSettingsText = null;
1673
+ trustedServersText = null;
1674
+ /** The bytes last looked at, so an unchanged file (ours, or a broken edit) is not re-read. */
1675
+ seenSettingsText = null;
1676
+ seenServersText = null;
1677
+ resolvedConfig;
1678
+ /** A JSON parse failure, kept apart from a schema problem so `apply()` cannot clear it. */
1679
+ settingsParseError = null;
1680
+ serversParseError = null;
1681
+ settingsError = null;
1682
+ serversError = null;
1683
+ warnings = [];
1684
+ settingsSchemaVersion = 1;
1685
+ serversSchemaVersion = 1;
1686
+ listeners = /* @__PURE__ */ new Set();
1687
+ conflictListeners = /* @__PURE__ */ new Set();
1688
+ constructor(workspaceId, settingsFile, serversFile, seedSettings = SEED_WORKSPACE_SETTINGS, seedServers = SEED_SERVERS_FILE) {
1689
+ this.workspaceId = workspaceId;
1690
+ this.settingsFile = settingsFile;
1691
+ this.serversFile = serversFile;
1692
+ this.seedSettings = seedSettings;
1693
+ this.seedServers = seedServers;
1694
+ }
1695
+ get id() {
1696
+ return this.workspaceId;
1697
+ }
1698
+ get path() {
1699
+ return this.serversFile;
1700
+ }
1701
+ get settingsPath() {
1702
+ return this.settingsFile;
1703
+ }
1704
+ get config() {
1705
+ return this.resolvedConfig;
1706
+ }
1707
+ get servers() {
1708
+ return this.resolvedConfig.servers;
1709
+ }
1710
+ get defaults() {
1711
+ return this.resolvedConfig.defaults;
1712
+ }
1713
+ get logs() {
1714
+ return this.resolvedConfig.logs;
1715
+ }
1716
+ get notifications() {
1717
+ return this.resolvedConfig.notifications;
1718
+ }
1719
+ get ddns() {
1720
+ return this.resolvedConfig.ddns;
1721
+ }
1722
+ get configError() {
1723
+ return [this.settingsParseError ?? this.settingsError, this.serversParseError ?? this.serversError].filter((error) => error !== null).join("; ") || null;
1724
+ }
1725
+ /** The files behind `configError`, so a refusal can name the one to edit. */
1726
+ get brokenConfigFiles() {
1727
+ const broken = [];
1728
+ if (this.settingsParseError !== null || this.settingsError !== null) broken.push(this.settingsFile);
1729
+ if (this.serversParseError !== null || this.serversError !== null) broken.push(this.serversFile);
1730
+ return broken;
1731
+ }
1732
+ get configWarnings() {
1733
+ return [...this.warnings];
1734
+ }
1735
+ get configSchemaVersion() {
1736
+ return Math.max(this.settingsSchemaVersion, this.serversSchemaVersion);
1737
+ }
1738
+ /**
1739
+ * Pending steps for both files, each planned from its own schema version. A file that cannot be
1740
+ * parsed is not a candidate: it belongs in `configError` alone.
1741
+ */
1742
+ get pendingMigrations() {
1743
+ if (this.settingsParseError !== null || this.serversParseError !== null) return [];
1744
+ return [.../* @__PURE__ */ new Set([...planConfigMigrations(this.settingsSchemaVersion, { kind: "workspace-settings" }).steps, ...planConfigMigrations(this.serversSchemaVersion, { kind: "servers" }).steps])].sort((a, b) => a.to - b.to);
1745
+ }
1746
+ onChange(listener) {
1747
+ this.listeners.add(listener);
1748
+ return () => this.listeners.delete(listener);
1749
+ }
1750
+ /** Told when a save was refused because a file changed on disk, so its owner can reload it. */
1751
+ onConflict(listener) {
1752
+ this.conflictListeners.add(listener);
1753
+ return () => this.conflictListeners.delete(listener);
1754
+ }
1755
+ get listenerCount() {
1756
+ return this.listeners.size;
1757
+ }
1758
+ getServer(id) {
1759
+ return this.servers.find((server) => server.id === id);
1760
+ }
1761
+ /** Reads both files, seeding a missing one; `{ write: false }` reads a missing file as its seed without creating it. */
1762
+ load(options = {}) {
1763
+ this.read(options.write !== false);
1764
+ this.apply();
1765
+ this.notify();
1766
+ }
1767
+ /** Re-reads only when the bytes changed. An unparseable revision is reported while the running config is kept. */
1768
+ reloadFromDisk() {
1769
+ const settings = readFile(this.settingsFile);
1770
+ const servers = readFile(this.serversFile);
1771
+ if (settings.missing || servers.missing) {
1772
+ this.markGone(settings.missing ? this.settingsFile : this.serversFile);
1773
+ return {
1774
+ changed: false,
1775
+ applied: false,
1776
+ error: this.configError
1777
+ };
1778
+ }
1779
+ let changed = false;
1780
+ let applied = false;
1781
+ for (const side of ["settings", "servers"]) {
1782
+ const read = side === "settings" ? settings : servers;
1783
+ const seen = side === "settings" ? this.seenSettingsText : this.seenServersText;
1784
+ const file = side === "settings" ? this.settingsFile : this.serversFile;
1785
+ if (read.text === seen) continue;
1786
+ changed = true;
1787
+ if (side === "settings") this.seenSettingsText = read.text;
1788
+ else this.seenServersText = read.text;
1789
+ if (read.parseError !== null) {
1790
+ const message = `cannot parse ${path.basename(file)}: ${read.parseError}`;
1791
+ if (side === "settings") this.settingsParseError = message;
1792
+ else this.serversParseError = message;
1793
+ continue;
1794
+ }
1795
+ if (side === "settings") {
1796
+ this.settingsParseError = null;
1797
+ this.liveSettings = read.parsed;
1798
+ this.liveSettingsText = read.text;
1799
+ } else {
1800
+ this.serversParseError = null;
1801
+ this.liveServers = read.parsed;
1802
+ this.liveServersText = read.text;
1803
+ }
1804
+ applied = true;
1805
+ }
1806
+ if (!changed && !applied && this.configError === null) return {
1807
+ changed: false,
1808
+ applied: false,
1809
+ error: null
1810
+ };
1811
+ this.apply();
1812
+ this.notify();
1813
+ return {
1814
+ changed,
1815
+ applied,
1816
+ error: this.configError
1817
+ };
1818
+ }
1819
+ markGone(file) {
1820
+ const message = `${path.basename(file)} is gone`;
1821
+ if (file === this.settingsFile) this.settingsError = message;
1822
+ else this.serversError = message;
1823
+ }
1824
+ read(write = true) {
1825
+ let settings = readFile(this.settingsFile);
1826
+ if (settings.missing) {
1827
+ const seed = stampConfig(structuredClone(this.seedSettings));
1828
+ const text = `${JSON.stringify(seed, null, 2)}\n`;
1829
+ if (write) writeFileAtomic(this.settingsFile, text);
1830
+ settings = {
1831
+ text,
1832
+ parsed: seed,
1833
+ missing: false,
1834
+ parseError: null
1835
+ };
1836
+ }
1837
+ let servers = readFile(this.serversFile);
1838
+ if (servers.missing) {
1839
+ const seed = stampConfig(structuredClone(this.seedServers));
1840
+ const text = `${JSON.stringify(seed, null, 2)}\n`;
1841
+ if (write) writeFileAtomic(this.serversFile, text);
1842
+ servers = {
1843
+ text,
1844
+ parsed: seed,
1845
+ missing: false,
1846
+ parseError: null
1847
+ };
1848
+ }
1849
+ this.seenSettingsText = settings.text;
1850
+ this.seenServersText = servers.text;
1851
+ this.settingsParseError = settings.parseError === null ? null : `cannot parse ${path.basename(this.settingsFile)}: ${settings.parseError}`;
1852
+ this.serversParseError = servers.parseError === null ? null : `cannot parse ${path.basename(this.serversFile)}: ${servers.parseError}`;
1853
+ if (settings.parseError === null) {
1854
+ this.liveSettings = settings.parsed;
1855
+ this.liveSettingsText = settings.text;
1856
+ }
1857
+ if (servers.parseError === null) {
1858
+ this.liveServers = servers.parsed;
1859
+ this.liveServersText = servers.text;
1860
+ }
1861
+ }
1862
+ notify() {
1863
+ for (const listener of this.listeners) listener();
1864
+ }
1865
+ updateServer(id, patch) {
1866
+ const index = (this.rawServers.servers ?? []).findIndex((entry) => entry.id === id);
1867
+ if (index < 0) throw new ConfigError(`unknown server "${id}"`, "UNKNOWN_SERVER");
1868
+ const draft = structuredClone(this.rawServers);
1869
+ const entry = draft.servers[index];
1870
+ applyPatch(entry, patch, SERVER_MERGE_KEYS);
1871
+ const validated = this.validateServer(entry, `servers[${index}]`);
1872
+ this.commitServers(draft);
1873
+ return validated;
1874
+ }
1875
+ updateDefaults(patch) {
1876
+ const draft = structuredClone(this.rawSettings);
1877
+ draft.defaults = { ...draft.defaults ?? {} };
1878
+ applyPatch(draft.defaults, patch, SERVER_MERGE_KEYS);
1879
+ const defaults = this.parseGroup(defaultsSchema, draft.defaults, "defaults");
1880
+ this.commitSettings(draft);
1881
+ return defaults;
1882
+ }
1883
+ updateLogs(patch) {
1884
+ const draft = structuredClone(this.rawSettings);
1885
+ draft.logs = { ...draft.logs ?? {} };
1886
+ applyPatch(draft.logs, patch, EMPTY_MERGE_KEYS);
1887
+ const logs = this.parseGroup(logsSchema, draft.logs, "logs");
1888
+ this.commitSettings(draft);
1889
+ return logs;
1890
+ }
1891
+ updateNotifications(patch) {
1892
+ const draft = structuredClone(this.rawSettings);
1893
+ const notifications = this.draftNotifications(draft, patch);
1894
+ this.commitSettings(draft);
1895
+ return notifications;
1896
+ }
1897
+ /**
1898
+ * `defaults`, `logs` and `notifications` in one write: every group is validated before any is saved,
1899
+ * so a refusal changes nothing.
1900
+ */
1901
+ updateSettingsGroups(patch) {
1902
+ const draft = structuredClone(this.rawSettings);
1903
+ if (patch.defaults !== void 0) {
1904
+ draft.defaults = { ...draft.defaults ?? {} };
1905
+ applyPatch(draft.defaults, patch.defaults, SERVER_MERGE_KEYS);
1906
+ this.parseGroup(defaultsSchema, draft.defaults, "defaults");
1907
+ }
1908
+ if (patch.logs !== void 0) {
1909
+ draft.logs = { ...draft.logs ?? {} };
1910
+ applyPatch(draft.logs, patch.logs, EMPTY_MERGE_KEYS);
1911
+ this.parseGroup(logsSchema, draft.logs, "logs");
1912
+ }
1913
+ if (patch.notifications !== void 0) this.draftNotifications(draft, patch.notifications);
1914
+ this.commitSettings(draft);
1915
+ }
1916
+ draftNotifications(draft, patch) {
1917
+ draft.notifications = { ...draft.notifications ?? {} };
1918
+ applyPatch(draft.notifications, patch, NOTIFICATION_MERGE_KEYS);
1919
+ const notifications = this.parseGroup(notificationsSchema, draft.notifications, "notifications");
1920
+ const duplicates = duplicateWebhookIds(notifications.destinations);
1921
+ if (duplicates.length > 0) throw new ConfigError(`notifications: duplicate webhook id ${duplicates.map((id) => `"${id}"`).join(", ")}`);
1922
+ for (const target of notifications.destinations) {
1923
+ if (target.kind !== "webhook") continue;
1924
+ const problem = targetProblem(target, { requireUrl: true });
1925
+ if (problem !== null) throw new ConfigError(`notifications: webhook "${target.id}" ${problem}`);
1926
+ }
1927
+ return notifications;
1928
+ }
1929
+ /** Merges the nested groups and replaces the `accounts` and `domains` lists whole. */
1930
+ updateDdns(patch) {
1931
+ const draft = structuredClone(this.rawSettings);
1932
+ draft.ddns = { ...draft.ddns ?? {} };
1933
+ applyPatch(draft.ddns, patch, DDNS_MERGE_KEYS);
1934
+ const parsed = this.parseGroup(ddnsConfigSchema, draft.ddns, "ddns");
1935
+ const problems = validateDdnsConfig(parsed);
1936
+ if (problems.length > 0) throw new ConfigError(`ddns: ${problems.join("; ")}`);
1937
+ this.commitSettings(draft);
1938
+ return parsed;
1939
+ }
1940
+ addServer(input) {
1941
+ const draft = structuredClone(this.rawServers);
1942
+ const list = draft.servers ?? (draft.servers = []);
1943
+ if (list.some((entry) => entry.id === input.id)) throw new ConfigError(`server "${String(input.id)}" already exists`);
1944
+ const index = list.length;
1945
+ list.push(structuredClone(input));
1946
+ const validated = this.validateServer(list[index], `servers[${index}]`);
1947
+ this.commitServers(draft);
1948
+ return validated;
1949
+ }
1950
+ /** Creates the entry, or replaces a same-id one outright; `created` lets the route answer 201 or 200. */
1951
+ putServer(input) {
1952
+ const draft = structuredClone(this.rawServers);
1953
+ const list = draft.servers ?? (draft.servers = []);
1954
+ const index = list.findIndex((entry) => entry.id === input.id);
1955
+ const created = index < 0;
1956
+ if (created) list.push(structuredClone(input));
1957
+ else list[index] = structuredClone(input);
1958
+ const validated = this.validateServer(list[created ? list.length - 1 : index], `servers[${created ? list.length - 1 : index}]`);
1959
+ this.commitServers(draft);
1960
+ return {
1961
+ server: validated,
1962
+ created
1963
+ };
1964
+ }
1965
+ removeServer(id) {
1966
+ const draft = structuredClone(this.rawServers);
1967
+ const list = draft.servers ?? [];
1968
+ const before = list.length;
1969
+ draft.servers = list.filter((entry) => entry.id !== id);
1970
+ if (draft.servers.length === before) throw new ConfigError(`unknown server "${id}"`, "UNKNOWN_SERVER");
1971
+ this.commitServers(draft);
1972
+ }
1973
+ /** Writes both JSON schemas beside this store's own files, never under a module-level default. */
1974
+ writeJsonSchema() {
1975
+ this.writeSchema(path.join(path.dirname(this.settingsFile), "settings.schema.json"), workspaceSettingsSchema);
1976
+ this.writeSchema(path.join(path.dirname(this.serversFile), `${path.basename(this.serversFile, ".json")}.schema.json`), serversFileSchema);
1977
+ }
1978
+ writeSchema(file, schema) {
1979
+ const text = JSON.stringify(schema.toJsonSchema(), null, 2);
1980
+ if ((fs.existsSync(file) ? fs.readFileSync(file, "utf8") : null) !== text) writeFileAtomic(file, text);
1981
+ }
1982
+ parseGroup(schema, value, label) {
1983
+ const parsed = parseTolerant(value, schema, label, []);
1984
+ if (parsed.error !== null) throw new ConfigError(`${label}: ${parsed.error}`);
1985
+ return parsed.value;
1986
+ }
1987
+ /** One entry against the schema and `serverKindProblems`, which sees the entry's own keys before defaults merge in. */
1988
+ validateServer(entry, label) {
1989
+ const parsed = serverSchema(mergeDefaults(this.defaults, entry));
1990
+ if (parsed instanceof type.errors) throw new ConfigError(`${label}: ${parsed.summary}`);
1991
+ const server = {
1992
+ ...parsed,
1993
+ port: parsed.port ?? null
1994
+ };
1995
+ const leftover = entryHasJobFields(entry, invocation());
1996
+ if (leftover !== null) throw new ConfigError(`${label}: ${leftover}`);
1997
+ return server;
1998
+ }
1999
+ commitSettings(draft) {
2000
+ assertSaveable(this.settingsFile, {
2001
+ trusted: this.trustedSettingsText,
2002
+ seen: this.seenSettingsText,
2003
+ unusable: this.settingsParseError ?? this.settingsError
2004
+ }, this.conflictListeners);
2005
+ const stamped = stampConfig(draft);
2006
+ const text = `${JSON.stringify(stamped, null, 2)}\n`;
2007
+ writeFileAtomic(this.settingsFile, text);
2008
+ this.seenSettingsText = text;
2009
+ this.liveSettingsText = text;
2010
+ this.liveSettings = stamped;
2011
+ this.settingsParseError = null;
2012
+ this.apply();
2013
+ this.notify();
2014
+ }
2015
+ commitServers(draft) {
2016
+ assertSaveable(this.serversFile, {
2017
+ trusted: this.trustedServersText,
2018
+ seen: this.seenServersText,
2019
+ unusable: this.serversParseError ?? this.serversError
2020
+ }, this.conflictListeners);
2021
+ const stamped = stampConfig(draft);
2022
+ const text = `${JSON.stringify(stamped, null, 2)}\n`;
2023
+ writeFileAtomic(this.serversFile, text);
2024
+ this.seenServersText = text;
2025
+ this.liveServersText = text;
2026
+ this.liveServers = stamped;
2027
+ this.serversParseError = null;
2028
+ this.apply();
2029
+ this.notify();
2030
+ }
2031
+ apply() {
2032
+ const settings = parseWorkspaceSettings(this.liveSettings);
2033
+ const haveResolved = this.resolvedConfig !== void 0;
2034
+ const defaults = settings.config?.defaults ?? (haveResolved ? this.resolvedConfig.defaults : void 0);
2035
+ const servers = parseServersFile(this.liveServers, defaults ?? {});
2036
+ this.settingsError = this.settingsParseError ?? (settings.errors.length > 0 ? settings.errors.join("; ") : null);
2037
+ this.serversError = this.serversParseError ?? (servers.errors.length > 0 ? servers.errors.join("; ") : null);
2038
+ this.settingsSchemaVersion = settings.schemaVersion;
2039
+ this.serversSchemaVersion = servers.schemaVersion;
2040
+ this.warnings = [
2041
+ ...settings.warnings,
2042
+ ...servers.warnings,
2043
+ ...settings.unknownKeys.length === 0 && servers.unknownKeys.length === 0 ? [] : [`this workspace carries ${settings.unknownKeys.length + servers.unknownKeys.length} unrecognized key(s) this release ignores: ${[...settings.unknownKeys, ...servers.unknownKeys].join(", ")}`]
2044
+ ];
2045
+ const settingsConfig = settings.config ?? (haveResolved ? {
2046
+ defaults: this.resolvedConfig.defaults,
2047
+ logs: this.resolvedConfig.logs,
2048
+ notifications: this.resolvedConfig.notifications,
2049
+ ddns: this.resolvedConfig.ddns
2050
+ } : this.resolveSettingsFallback());
2051
+ const nextServers = servers.errors.length === 0 ? servers.servers : haveResolved ? this.resolvedConfig.servers : [];
2052
+ this.resolvedConfig = {
2053
+ ...settingsConfig,
2054
+ servers: nextServers
2055
+ };
2056
+ if (settings.config !== null) {
2057
+ this.rawSettings = structuredClone(this.liveSettings);
2058
+ this.trustedSettingsText = this.liveSettingsText;
2059
+ }
2060
+ if (servers.errors.length === 0) {
2061
+ this.rawServers = structuredClone(this.liveServers);
2062
+ this.trustedServersText = this.liveServersText;
2063
+ }
2064
+ }
2065
+ resolveSettingsFallback() {
2066
+ const defaults = defaultsSchema({});
2067
+ const logs = logsSchema({});
2068
+ const notifications = notificationsSchema({});
2069
+ const ddns = ddnsConfigSchema({});
2070
+ if (defaults instanceof type.errors || logs instanceof type.errors || notifications instanceof type.errors || ddns instanceof type.errors) throw new ConfigError("internal: default workspace settings failed validation");
2071
+ return {
2072
+ defaults,
2073
+ logs,
2074
+ notifications,
2075
+ ddns
2076
+ };
2077
+ }
2078
+ };
2079
+ //#endregion
2080
+ export { expandEnv as a, loadEnvFile as c, ddnsProviderInfos as d, validateDdnsConfig as f, targetProblem as i, resolveEnvFilePath as l, normalizeHost as m, store_exports as n, expandEnvList as o, splitHost as p, sendWebhook as r, expandEnvRecord as s, WorkspaceStore as t, ddnsProvider as u };
2081
+
2082
+ //# sourceMappingURL=store-Bs_Lljjm.js.map