@selvajs/selva 4.20.1-beta.4 → 4.21.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/adapter-node.js +1 -1
- package/build/client/_app/immutable/assets/0.CqqJCiiV.css +2 -0
- package/build/client/_app/immutable/assets/0.CqqJCiiV.css.br +0 -0
- package/build/client/_app/immutable/assets/0.CqqJCiiV.css.gz +0 -0
- package/build/client/_app/immutable/chunks/{CzfnuBzq.js → BAhtiTKe.js} +1 -1
- package/build/client/_app/immutable/chunks/BAhtiTKe.js.br +0 -0
- package/build/client/_app/immutable/chunks/BAhtiTKe.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{qi43d-TM.js → CKbHmAlc.js} +1 -1
- package/build/client/_app/immutable/chunks/CKbHmAlc.js.br +0 -0
- package/build/client/_app/immutable/chunks/CKbHmAlc.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{C6Y_BUwr.js → CmlXAF26.js} +1 -1
- package/build/client/_app/immutable/chunks/CmlXAF26.js.br +0 -0
- package/build/client/_app/immutable/chunks/CmlXAF26.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Cv7GBWJh.js +2 -0
- package/build/client/_app/immutable/chunks/Cv7GBWJh.js.br +0 -0
- package/build/client/_app/immutable/chunks/Cv7GBWJh.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{BDYCH-_Q.js → D5j4-ZO1.js} +1 -1
- package/build/client/_app/immutable/chunks/D5j4-ZO1.js.br +0 -0
- package/build/client/_app/immutable/chunks/D5j4-ZO1.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js +1 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js.br +0 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{D-uUm_OB.js → DptnDNFA.js} +61 -56
- package/build/client/_app/immutable/chunks/DptnDNFA.js.br +0 -0
- package/build/client/_app/immutable/chunks/{D-uUm_OB.js.gz → DptnDNFA.js.gz} +0 -0
- package/build/client/_app/immutable/chunks/DvJo0Zn0.js +1 -0
- package/build/client/_app/immutable/chunks/DvJo0Zn0.js.br +1 -0
- package/build/client/_app/immutable/chunks/DvJo0Zn0.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{DzxE3j6C.js → qXnHMKD9.js} +1 -1
- package/build/client/_app/immutable/chunks/qXnHMKD9.js.br +0 -0
- package/build/client/_app/immutable/chunks/qXnHMKD9.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.BpT6WkO1.js → app.DPbjEDd3.js} +2 -2
- package/build/client/_app/immutable/entry/app.DPbjEDd3.js.br +0 -0
- package/build/client/_app/immutable/entry/app.DPbjEDd3.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{1.D3kiiIk_.js → 1.DWd6YbcT.js} +1 -1
- package/build/client/_app/immutable/nodes/1.DWd6YbcT.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.DWd6YbcT.js.gz +0 -0
- package/build/client/_app/immutable/nodes/15._hpTnSzc.js +36 -0
- package/build/client/_app/immutable/nodes/15._hpTnSzc.js.br +0 -0
- package/build/client/_app/immutable/nodes/15._hpTnSzc.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{2.CUNbzjI_.js → 2.CS32Eh9m.js} +1 -1
- package/build/client/_app/immutable/nodes/2.CS32Eh9m.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CS32Eh9m.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{20.9OIre0ah.js → 20.CVaxGEhZ.js} +1 -1
- package/build/client/_app/immutable/nodes/20.CVaxGEhZ.js.br +0 -0
- package/build/client/_app/immutable/nodes/20.CVaxGEhZ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.DpKe0-GH.js +1 -0
- package/build/client/_app/immutable/nodes/21.DpKe0-GH.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.DpKe0-GH.js.gz +0 -0
- package/build/client/_app/immutable/nodes/24.DkL5kHzA.js +3 -0
- package/build/client/_app/immutable/nodes/24.DkL5kHzA.js.br +0 -0
- package/build/client/_app/immutable/nodes/24.DkL5kHzA.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{25.DW1_vMxq.js → 25.DiYmTwXC.js} +2 -2
- package/build/client/_app/immutable/nodes/25.DiYmTwXC.js.br +0 -0
- package/build/client/_app/immutable/nodes/25.DiYmTwXC.js.gz +0 -0
- package/build/client/_app/immutable/nodes/26.7nAJpm5P.js +5 -0
- package/build/client/_app/immutable/nodes/26.7nAJpm5P.js.br +0 -0
- package/build/client/_app/immutable/nodes/26.7nAJpm5P.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{3.3Z4QUsQQ.js → 3.Ctd9OGCk.js} +1 -1
- package/build/client/_app/immutable/nodes/3.Ctd9OGCk.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.Ctd9OGCk.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{5.DmA9lTA-.js → 5.Wh_w3RkZ.js} +1 -1
- package/build/client/_app/immutable/nodes/5.Wh_w3RkZ.js.br +2 -0
- package/build/client/_app/immutable/nodes/5.Wh_w3RkZ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{6.D6WLqCgl.js → 6.C-DiUI5R.js} +1 -1
- package/build/client/_app/immutable/nodes/6.C-DiUI5R.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.C-DiUI5R.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{7.CNuRjkv2.js → 7.B8yubYrv.js} +1 -1
- package/build/client/_app/immutable/nodes/7.B8yubYrv.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.B8yubYrv.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/runtime-meta.json +1 -1
- package/build/server/.vite/manifest.json +35 -45
- package/build/server/_app/immutable/assets/_layout.CqqJCiiV.css +2 -0
- package/build/server/chunks/DefinitionCard.js +3 -0
- package/build/server/chunks/DefinitionCard.js.map +1 -1
- package/build/server/chunks/access.js +15 -3
- package/build/server/chunks/access.js.map +1 -1
- package/build/server/chunks/api-errors.js +18 -3
- package/build/server/chunks/api-errors.js.map +1 -1
- package/build/server/chunks/api.js +9 -2
- package/build/server/chunks/api.js.map +1 -1
- package/build/server/chunks/auth-bootstrap.server.js +63 -39
- package/build/server/chunks/auth-bootstrap.server.js.map +1 -1
- package/build/server/chunks/boot.server.js +1 -1
- package/build/server/chunks/bootHealth.server.js +23 -23
- package/build/server/chunks/bootHealth.server.js.map +1 -1
- package/build/server/chunks/computeRateLimit.server.js +2 -2
- package/build/server/chunks/delete-with-blobs.js +1 -1
- package/build/server/chunks/engine.server.js +52 -5
- package/build/server/chunks/engine.server.js.map +1 -1
- package/build/server/chunks/grasshopper.js +217 -162
- package/build/server/chunks/grasshopper.js.map +1 -1
- package/build/server/chunks/handlers.js +70 -60
- package/build/server/chunks/handlers.js.map +1 -1
- package/build/server/chunks/http.js +24 -24
- package/build/server/chunks/http.js.map +1 -1
- package/build/server/chunks/http2.js +1 -1
- package/build/server/chunks/instance.js +3 -3
- package/build/server/chunks/instanceAdmins.server.js +31 -16
- package/build/server/chunks/instanceAdmins.server.js.map +1 -1
- package/build/server/chunks/internal.js +1 -1
- package/build/server/chunks/{abort-Bfrdupaj.js → keepalive-vtcjhAV3.js} +6 -3
- package/build/server/chunks/keepalive-vtcjhAV3.js.map +1 -0
- package/build/server/chunks/liveSolve.server.js +1 -1
- package/build/server/chunks/localeContext.svelte.js +14 -0
- package/build/server/chunks/localeContext.svelte.js.map +1 -1
- package/build/server/chunks/oauth.js +70 -24
- package/build/server/chunks/oauth.js.map +1 -1
- package/build/server/chunks/{outcome-DNrffAXp.js → outcome-D28FgvFK.js} +9 -6
- package/build/server/chunks/outcome-D28FgvFK.js.map +1 -0
- package/build/server/chunks/package.js +2 -1
- package/build/server/chunks/package.js.map +1 -1
- package/build/server/chunks/permissions.server.js +1 -1
- package/build/server/chunks/presets.server.js +1 -1
- package/build/server/chunks/providers.server.js +324 -121
- package/build/server/chunks/providers.server.js.map +1 -1
- package/build/server/chunks/registry.js +1 -1
- package/build/server/chunks/resolve-server.js +1 -1
- package/build/server/chunks/schema-extraction.js +75 -8
- package/build/server/chunks/schema-extraction.js.map +1 -1
- package/build/server/chunks/schema.js +1 -1
- package/build/server/chunks/schema.js.map +1 -1
- package/build/server/chunks/server-config-write.js +6 -6
- package/build/server/chunks/server-config-write.js.map +1 -1
- package/build/server/chunks/server2.js +2 -2
- package/build/server/chunks/server2.js.map +1 -1
- package/build/server/chunks/serverStats.server.js +1 -1
- package/build/server/chunks/signInMaxAge.server.js +1 -1
- package/build/server/chunks/solve.server.js +34 -8
- package/build/server/chunks/solve.server.js.map +1 -1
- package/build/server/chunks/sveltekit.js +4 -5
- package/build/server/chunks/sveltekit.js.map +1 -1
- package/build/server/chunks/update-outcome.js +11 -0
- package/build/server/chunks/update-outcome.js.map +1 -1
- package/build/server/chunks/updateCheck.server.js +24 -12
- package/build/server/chunks/updateCheck.server.js.map +1 -1
- package/build/server/entries/endpoints/.well-known/oauth-authorization-server/_server.ts.js +6 -3
- package/build/server/entries/endpoints/.well-known/oauth-authorization-server/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/.well-known/oauth-protected-resource/_server.ts.js +6 -3
- package/build/server/entries/endpoints/.well-known/oauth-protected-resource/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/.well-known/oauth-protected-resource/mcp/_server.ts.js +6 -3
- package/build/server/entries/endpoints/.well-known/oauth-protected-resource/mcp/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/compute/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/orgs/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/orgs/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/grants/_grantId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/grants/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/system/health/_server.ts.js +9 -2
- package/build/server/entries/endpoints/api/admin/system/health/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/system/update/_server.ts.js +59 -15
- package/build/server/entries/endpoints/api/admin/system/update/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/users/_id_/_server.ts.js +42 -16
- package/build/server/entries/endpoints/api/admin/users/_id_/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/users/_id_/disable/_server.ts.js +24 -13
- package/build/server/entries/endpoints/api/admin/users/_id_/disable/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/users/_server.ts.js +2 -2
- package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +15 -6
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/compute/schema/_server.ts.js +3 -3
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/image/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/publish/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/schema/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/share-links/_linkId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/share-links/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +5 -4
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_versionId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_versionId_/schema/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/me/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/me/starred/_guid_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/me/token/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/orgs/_orgId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/orgs/_orgId_/members/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/orgs/_orgId_/tokens/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/orgs/_orgId_/tokens/_tokenId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/members/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/members/_userId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/reclaim/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/solve/_solveId_/cancel/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/solve-events/_server.ts.js +1 -1
- package/build/server/entries/endpoints/auth/email/callback/_server.ts.js +2 -2
- package/build/server/entries/endpoints/auth/email/callback/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/auth/supabase/callback/_server.ts.js +2 -2
- package/build/server/entries/endpoints/auth/supabase/callback/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/docs/api/openapi.yaml/_server.ts.js +1 -1
- package/build/server/entries/endpoints/mcp/_server.ts.js +43 -13
- package/build/server/entries/endpoints/mcp/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/oauth/register/_server.ts.js +1 -1
- package/build/server/entries/endpoints/oauth/token/_server.ts.js +1 -1
- package/build/server/entries/hooks.server.js +25 -6
- package/build/server/entries/hooks.server.js.map +1 -1
- package/build/server/entries/pages/admin/compute/_page.server.ts.js +1 -2
- package/build/server/entries/pages/admin/compute/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/admin/system/_page.server.ts.js +8 -3
- package/build/server/entries/pages/admin/system/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/admin/system/_page.svelte.js +18 -2
- package/build/server/entries/pages/admin/system/_page.svelte.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js +198 -99
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.svelte.js +693 -40
- package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
- package/build/server/entries/pages/oauth/authorize/_page.server.ts.js +3 -2
- package/build/server/entries/pages/oauth/authorize/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/oauth/authorize/_page.svelte.js +8 -1
- package/build/server/entries/pages/oauth/authorize/_page.svelte.js.map +1 -1
- package/build/server/entries/pages/projects/_page.svelte.js +2 -0
- package/build/server/entries/pages/projects/_page.svelte.js.map +1 -1
- package/build/server/entries/pages/setup/_page.server.ts.js +62 -8
- package/build/server/entries/pages/setup/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/setup/_page.svelte.js +52 -33
- package/build/server/entries/pages/setup/_page.svelte.js.map +1 -1
- package/build/server/entries/pages/team/tokens/_page.server.ts.js +1 -1
- package/build/server/manifest-full.js +1 -1
- package/build/server/manifest.js +1 -1
- package/build/server/nodes/0.js +2 -2
- package/build/server/nodes/1.js +1 -1
- package/build/server/nodes/15.js +1 -1
- package/build/server/nodes/2.js +1 -1
- package/build/server/nodes/20.js +1 -1
- package/build/server/nodes/21.js +1 -1
- package/build/server/nodes/24.js +1 -1
- package/build/server/nodes/25.js +1 -1
- package/build/server/nodes/26.js +1 -1
- package/build/server/nodes/3.js +1 -1
- package/build/server/nodes/5.js +1 -1
- package/build/server/nodes/6.js +1 -1
- package/build/server/nodes/7.js +1 -1
- package/build/server/server.js +1 -1
- package/package.json +16 -13
- package/templates/.env.example +15 -7
- package/build/client/_app/immutable/assets/0.2jDm0bqh.css +0 -2
- package/build/client/_app/immutable/assets/0.2jDm0bqh.css.br +0 -0
- package/build/client/_app/immutable/assets/0.2jDm0bqh.css.gz +0 -0
- package/build/client/_app/immutable/chunks/BDYCH-_Q.js.br +0 -0
- package/build/client/_app/immutable/chunks/BDYCH-_Q.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C6Y_BUwr.js.br +0 -0
- package/build/client/_app/immutable/chunks/C6Y_BUwr.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CzfnuBzq.js.br +0 -0
- package/build/client/_app/immutable/chunks/CzfnuBzq.js.gz +0 -0
- package/build/client/_app/immutable/chunks/D-uUm_OB.js.br +0 -0
- package/build/client/_app/immutable/chunks/D84F7w9g.js +0 -1
- package/build/client/_app/immutable/chunks/D84F7w9g.js.br +0 -1
- package/build/client/_app/immutable/chunks/D84F7w9g.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DQsP4nZb.js +0 -1
- package/build/client/_app/immutable/chunks/DQsP4nZb.js.br +0 -0
- package/build/client/_app/immutable/chunks/DQsP4nZb.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DzeQucGI.js +0 -2
- package/build/client/_app/immutable/chunks/DzeQucGI.js.br +0 -0
- package/build/client/_app/immutable/chunks/DzeQucGI.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DzxE3j6C.js.br +0 -0
- package/build/client/_app/immutable/chunks/DzxE3j6C.js.gz +0 -0
- package/build/client/_app/immutable/chunks/qi43d-TM.js.br +0 -0
- package/build/client/_app/immutable/chunks/qi43d-TM.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.BpT6WkO1.js.br +0 -0
- package/build/client/_app/immutable/entry/app.BpT6WkO1.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.D3kiiIk_.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.D3kiiIk_.js.gz +0 -0
- package/build/client/_app/immutable/nodes/15.BXIV1QfS.js +0 -32
- package/build/client/_app/immutable/nodes/15.BXIV1QfS.js.br +0 -0
- package/build/client/_app/immutable/nodes/15.BXIV1QfS.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.CUNbzjI_.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CUNbzjI_.js.gz +0 -0
- package/build/client/_app/immutable/nodes/20.9OIre0ah.js.br +0 -0
- package/build/client/_app/immutable/nodes/20.9OIre0ah.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js +0 -1
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js.gz +0 -0
- package/build/client/_app/immutable/nodes/24.CPSunfJJ.js +0 -3
- package/build/client/_app/immutable/nodes/24.CPSunfJJ.js.br +0 -0
- package/build/client/_app/immutable/nodes/24.CPSunfJJ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/25.DW1_vMxq.js.br +0 -0
- package/build/client/_app/immutable/nodes/25.DW1_vMxq.js.gz +0 -0
- package/build/client/_app/immutable/nodes/26.CqaMEm_t.js +0 -6
- package/build/client/_app/immutable/nodes/26.CqaMEm_t.js.br +0 -0
- package/build/client/_app/immutable/nodes/26.CqaMEm_t.js.gz +0 -0
- package/build/client/_app/immutable/nodes/3.3Z4QUsQQ.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.3Z4QUsQQ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/5.DmA9lTA-.js.br +0 -1
- package/build/client/_app/immutable/nodes/5.DmA9lTA-.js.gz +0 -0
- package/build/client/_app/immutable/nodes/6.D6WLqCgl.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.D6WLqCgl.js.gz +0 -0
- package/build/client/_app/immutable/nodes/7.CNuRjkv2.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.CNuRjkv2.js.gz +0 -0
- package/build/server/_app/immutable/assets/_layout.2jDm0bqh.css +0 -2
- package/build/server/chunks/abort-Bfrdupaj.js.map +0 -1
- package/build/server/chunks/computeLimits.js +0 -33
- package/build/server/chunks/computeLimits.js.map +0 -1
- package/build/server/chunks/outcome-DNrffAXp.js.map +0 -1
- /package/build/client/_app/immutable/nodes/{0.CYdyv5To.js → 0.Ds0zeDAg.js} +0 -0
- /package/build/client/_app/immutable/nodes/{0.CYdyv5To.js.br → 0.Ds0zeDAg.js.br} +0 -0
- /package/build/client/_app/immutable/nodes/{0.CYdyv5To.js.gz → 0.Ds0zeDAg.js.gz} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateCheck.server.js","names":[],"sources":["../../../../server/src/ops/semver.ts","../../../src/lib/server/releaseChannel.server.ts","../../../src/lib/server/updateCheck.server.ts"],"sourcesContent":["/**\n * Channel-aware semver comparison for update checks. Understands exactly the\n * two lines Selva publishes under: stable (`x.y.z`, npm `latest`) and beta\n * (`x.y.z-beta.N`, npm `beta`). Deliberately not general semver — no build\n * metadata, no arbitrary pre-release identifiers.\n */\n\n/** Which published line a deployment tracks. */\nexport type ReleaseChannel = 'stable' | 'beta';\n\n/**\n * Parse `x.y.z` plus an optional `-beta.N` counter. `beta` comes back separate\n * from the core so beta-channel comparisons can order successive betas of one\n * core. Null when the string doesn't lead with a numeric core.\n */\nexport function parseSemver(\n\tv: string\n): { core: [number, number, number]; beta: number | null } | null {\n\tconst m = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-beta\\.(\\d+))?/.exec(v.trim());\n\tif (!m) return null;\n\treturn {\n\t\tcore: [Number(m[1]), Number(m[2]), Number(m[3])],\n\t\tbeta: m[4] != null ? Number(m[4]) : null\n\t};\n}\n\n/**\n * Compare two `x.y.z` cores, ignoring pre-release tails. Callers that care\n * about those want `isNewer`, which layers the channel rules on top.\n */\nexport function compareCore(a: string, b: string): number {\n\tconst pa = parseSemver(a);\n\tconst pb = parseSemver(b);\n\tif (!pa || !pb) return 0;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (pa.core[i] > pb.core[i]) return 1;\n\t\tif (pa.core[i] < pb.core[i]) return -1;\n\t}\n\treturn 0;\n}\n\n/**\n * Does `version` satisfy an `engines.node` range?\n *\n * Deliberately narrow: handles the `>=`, `>`, `<=`, `<`, `^`, `~`, `=` and\n * bare-version forms Selva and its dependencies publish, plus `||` alternatives\n * and space-separated conjunctions (`>=18 <21`). Anything it can't parse\n * returns `null` for \"unknown\", never a false \"incompatible\" — a wrong block\n * would strand an operator with no way to override the bad parse.\n *\n * A full `semver` dependency would subsume this, but isn't warranted for the\n * handful of range forms in play.\n */\nexport function satisfiesRange(version: string, range: string): boolean | null {\n\tconst v = parseSemver(version);\n\tif (!v) return null;\n\n\tconst alternatives = range.split('||').map((r) => r.trim());\n\tlet anyParsed = false;\n\n\tfor (const alt of alternatives) {\n\t\tconst clauses = alt.split(/\\s+/).filter(Boolean);\n\t\tif (clauses.length === 0) continue;\n\n\t\tlet all = true;\n\t\tlet altParsed = true;\n\t\tfor (const clause of clauses) {\n\t\t\tconst m = /^(>=|<=|>|<|\\^|~|=)?\\s*v?(\\d+)(?:\\.(\\d+|x|\\*))?(?:\\.(\\d+|x|\\*))?/.exec(clause);\n\t\t\tif (!m) {\n\t\t\t\taltParsed = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst op = m[1] ?? '=';\n\t\t\tconst num = (s: string | undefined) => (s == null || s === 'x' || s === '*' ? 0 : Number(s));\n\t\t\tconst target: [number, number, number] = [Number(m[2]), num(m[3]), num(m[4])];\n\t\t\tconst cmp = (() => {\n\t\t\t\tfor (let i = 0; i < 3; i++) {\n\t\t\t\t\tif (v.core[i] > target[i]) return 1;\n\t\t\t\t\tif (v.core[i] < target[i]) return -1;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t})();\n\n\t\t\tlet ok: boolean;\n\t\t\tswitch (op) {\n\t\t\t\tcase '>=':\n\t\t\t\t\tok = cmp >= 0;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '>':\n\t\t\t\t\tok = cmp > 0;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '<=':\n\t\t\t\t\tok = cmp <= 0;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '<':\n\t\t\t\t\tok = cmp < 0;\n\t\t\t\t\tbreak;\n\t\t\t\t// ^X.Y.Z allows anything up to the next major; ~X.Y.Z up to the next minor.\n\t\t\t\tcase '^':\n\t\t\t\t\tok = cmp >= 0 && v.core[0] === target[0];\n\t\t\t\t\tbreak;\n\t\t\t\tcase '~':\n\t\t\t\t\tok = cmp >= 0 && v.core[0] === target[0] && v.core[1] === target[1];\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\t// A bare version means that exact release, but `18` / `18.x` mean the\n\t\t\t\t\t// whole line — treat omitted segments as wildcards.\n\t\t\t\t\tok =\n\t\t\t\t\t\tv.core[0] === target[0] &&\n\t\t\t\t\t\t(m[3] == null || m[3] === 'x' || m[3] === '*' || v.core[1] === target[1]) &&\n\t\t\t\t\t\t(m[4] == null || m[4] === 'x' || m[4] === '*' || v.core[2] === target[2]);\n\t\t\t}\n\t\t\tif (!ok) {\n\t\t\t\tall = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!altParsed) continue;\n\t\tanyParsed = true;\n\t\tif (all) return true;\n\t}\n\n\treturn anyParsed ? false : null;\n}\n\n/**\n * True when `latest` is strictly newer than `current`.\n *\n * Stable channel (default): pre-release suffixes are ignored, so only stable\n * core bumps surface.\n *\n * Beta channel: pre-releases participate. A higher core wins; on an equal core\n * a higher `-beta.N` wins, and a stable (no suffix) outranks any -beta of that\n * core (4.6.0 > 4.6.0-beta.9). An update UI can then show both \"beta.1 →\n * beta.2\" and the promotion of a beta line to stable.\n *\n * Unparseable versions fall back to inequality: different strings count as\n * newer, so an odd published version still surfaces; identical ones don't.\n */\nexport function isNewer(\n\tlatest: string,\n\tcurrent: string,\n\tchannel: ReleaseChannel = 'stable'\n): boolean {\n\tconst a = parseSemver(latest);\n\tconst b = parseSemver(current);\n\tif (!a || !b) return latest !== current;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (a.core[i] > b.core[i]) return true;\n\t\tif (a.core[i] < b.core[i]) return false;\n\t}\n\tif (channel !== 'beta') return false;\n\t// Stable (beta == null) ranks above any pre-release of the same core.\n\tconst rank = (beta: number | null) => (beta == null ? Infinity : beta);\n\treturn rank(a.beta) > rank(b.beta);\n}\n","// ============================================================================\n// Release channel\n// ============================================================================\n//\n// Which published line of @selvajs/* this deployment tracks: \"stable\" (npm\n// `latest` dist-tag) or \"beta\" (npm `beta` dist-tag). Persisted as a tiny\n// JSON file in the deployment dir (next to package.json / ecosystem.config.cjs)\n// — not a provider store — because both the SvelteKit process and the bash\n// update runner must read it, and the runner can't reach a DB. The file is\n// the single source of truth; absent/invalid resolves to \"stable\".\n//\n// The deployment dir is found the same way the update runner detects it: the\n// dir holding node_modules/@selvajs/selva (probed from cwd upward, or pinned\n// via INSTALL_DIR), so the channel file travels with the deployment and is\n// reachable from the runner's cwd.\n\nimport { existsSync, readFileSync, writeFileSync } from 'fs';\nimport { join } from 'path';\nimport { env } from '#lib/server/env.js';\nimport type { ReleaseChannel } from '@selvajs/server/ops';\n\nexport type { ReleaseChannel };\n\nconst CHANNEL_FILE = 'selva-channel.json';\n\nexport function channelTag(channel: ReleaseChannel): string {\n\treturn channel === 'beta' ? 'beta' : 'latest';\n}\n\nexport function channelRegistryUrl(channel: ReleaseChannel): string {\n\treturn `https://registry.npmjs.org/@selvajs%2Fselva/${channelTag(channel)}`;\n}\n\nfunction isChannel(v: unknown): v is ReleaseChannel {\n\treturn v === 'stable' || v === 'beta';\n}\n\n// Mirrors detectUpdatePlan / readInstalledVersion so the channel file lands\n// where all three agree.\nfunction deploymentDir(): string | null {\n\tconst candidates: string[] = [];\n\tif (env.INSTALL_DIR) candidates.push(env.INSTALL_DIR);\n\tlet dir = process.cwd();\n\tfor (let i = 0; i < 6; i++) {\n\t\tcandidates.push(dir);\n\t\tconst parent = join(dir, '..');\n\t\tif (parent === dir) break;\n\t\tdir = parent;\n\t}\n\tfor (const d of candidates) {\n\t\tif (existsSync(join(d, 'node_modules', '@selvajs', 'selva', 'package.json'))) return d;\n\t}\n\treturn null;\n}\n\n// Falls back to cwd outside a recognizable deployment (dev, tests) so\n// writeChannel never throws for lack of a target.\nfunction channelFilePath(): string {\n\treturn join(deploymentDir() ?? process.cwd(), CHANNEL_FILE);\n}\n\nexport function readChannel(): ReleaseChannel {\n\tconst path = channelFilePath();\n\tif (!existsSync(path)) return 'stable';\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(path, 'utf8')) as { channel?: unknown };\n\t\treturn isChannel(parsed.channel) ? parsed.channel : 'stable';\n\t} catch {\n\t\treturn 'stable';\n\t}\n}\n\nexport function writeChannel(channel: ReleaseChannel): void {\n\tif (!isChannel(channel)) throw new Error(`Invalid release channel: ${channel}`);\n\twriteFileSync(channelFilePath(), JSON.stringify({ channel }, null, 2) + '\\n', 'utf8');\n}\n","// ============================================================================\n// Update availability check\n// ============================================================================\n//\n// Queries the npm registry for the published @selvajs/selva version on the\n// deployment's channel and compares it to the installed version, so the\n// admin System page can show an \"update available\" badge. The registry fetch\n// is injected so it's testable, and every failure path degrades to \"no\n// update available\" rather than throwing — the admin page must never break\n// because npm is slow or unreachable.\n\nimport { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { env } from '#lib/server/env.js';\nimport { isNewer, satisfiesRange } from '@selvajs/server/ops';\nimport { channelRegistryUrl, type ReleaseChannel } from './releaseChannel.server';\n\nexport { isNewer };\n\n/**\n * Whether the host's Node satisfies the target release's `engines.node`.\n *\n * `compatible: null` means we couldn't tell (registry down, no engines field,\n * unparseable range) — the UI must treat that as \"proceed\", not as a block.\n * npm only enforces engines with `engine-strict=true`, which no deployment\n * sets, so a mismatch installs cleanly and `/api/health` still returns 200\n * (it exercises no Node-version-specific path) — hence this pre-flight.\n */\nexport interface NodeCompatibility {\n\tcompatible: boolean | null;\n\t/** The target's `engines.node` range, when the registry reported one. */\n\trequired: string | null;\n\t/** The Node version this deployment is running. */\n\trunning: string;\n}\n\nexport interface UpdateAvailability {\n\tchannel: ReleaseChannel;\n\t/** Installed @selvajs/selva version, or null if it couldn't be read. */\n\tcurrent: string | null;\n\t/** Latest published version on the channel, or null if the registry was unreachable. */\n\tlatest: string | null;\n\t/** True when both versions are known and differ — a forward update OR a stable revert target. */\n\tupdateAvailable: boolean;\n\tnodeCompatibility: NodeCompatibility;\n}\n\n// Probes cwd upward (and an explicit INSTALL_DIR) the same way the update\n// runner detects the deployment dir.\nexport function readInstalledVersion(): string | null {\n\tconst dirs: string[] = [];\n\tif (env.INSTALL_DIR) dirs.push(env.INSTALL_DIR);\n\tlet dir = process.cwd();\n\tfor (let i = 0; i < 6; i++) {\n\t\tdirs.push(dir);\n\t\tconst parent = join(dir, '..');\n\t\tif (parent === dir) break;\n\t\tdir = parent;\n\t}\n\tfor (const d of dirs) {\n\t\tconst pkgPath = join(d, 'node_modules', '@selvajs', 'selva', 'package.json');\n\t\tif (!existsSync(pkgPath)) continue;\n\t\ttry {\n\t\t\tconst pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));\n\t\t\tif (typeof pkg.version === 'string') return pkg.version;\n\t\t} catch {\n\t\t\t// fall through to the next candidate\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * The registry's per-tag manifest carries `engines` alongside `version`, so\n * the Node pre-flight costs no extra request. Uses a short timeout so a slow\n * registry can't hang the caller; returns nulls on any failure.\n */\nexport interface PublishedManifest {\n\tversion: string | null;\n\tenginesNode: string | null;\n}\n\nexport async function fetchLatestManifest(\n\tfetchImpl: typeof fetch,\n\tchannel: ReleaseChannel = 'stable'\n): Promise<PublishedManifest> {\n\tconst ctrl = new AbortController();\n\tconst timer = setTimeout(() => ctrl.abort(), 5000);\n\ttry {\n\t\tconst res = await fetchImpl(channelRegistryUrl(channel), {\n\t\t\theaders: { Accept: 'application/json' },\n\t\t\tsignal: ctrl.signal\n\t\t});\n\t\tif (!res.ok) return { version: null, enginesNode: null };\n\t\tconst body = (await res.json()) as { version?: unknown; engines?: { node?: unknown } };\n\t\treturn {\n\t\t\tversion: typeof body.version === 'string' ? body.version : null,\n\t\t\tenginesNode: typeof body.engines?.node === 'string' ? body.engines.node : null\n\t\t};\n\t} catch {\n\t\treturn { version: null, enginesNode: null };\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\nexport async function fetchLatestVersion(\n\tfetchImpl: typeof fetch,\n\tchannel: ReleaseChannel = 'stable'\n): Promise<string | null> {\n\treturn (await fetchLatestManifest(fetchImpl, channel)).version;\n}\n\nexport async function checkForUpdate(\n\tfetchImpl: typeof fetch,\n\tchannel: ReleaseChannel = 'stable',\n\trunningNode: string = process.versions.node\n): Promise<UpdateAvailability> {\n\tconst current = readInstalledVersion();\n\tconst { version: latest, enginesNode } = await fetchLatestManifest(fetchImpl, channel);\n\t// Any difference between installed and the channel's published version is\n\t// actionable: a forward update (stable→newer, beta→newer beta) OR a revert\n\t// (beta→stable lands on an OLDER stable version, but switching channel is\n\t// exactly what the operator asked for). Same version means nothing to do.\n\tconst updateAvailable = !!(current && latest && latest !== current);\n\treturn {\n\t\tchannel,\n\t\tcurrent,\n\t\tlatest,\n\t\tupdateAvailable,\n\t\tnodeCompatibility: {\n\t\t\tcompatible: enginesNode ? satisfiesRange(runningNode, enginesNode) : null,\n\t\t\trequired: enginesNode,\n\t\t\trunning: runningNode\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,YACf,GACiE;CACjE,MAAM,IAAI,wCAAwC,KAAK,EAAE,KAAK,CAAC;CAC/D,IAAI,CAAC,GAAG,OAAO;CACf,OAAO;EACN,MAAM;GAAC,OAAO,EAAE,EAAE;GAAG,OAAO,EAAE,EAAE;GAAG,OAAO,EAAE,EAAE;EAAC;EAC/C,MAAM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K,YAAY,WAAW,KAAK,UAAU;GAC3D,aAAa,OAAO,KAAK,SAAS,SAAS,WAAW,KAAK,QAAQ,OAAO;EAC3E;CACD,QAAQ;EACP,OAAO;GAAE,SAAS;GAAM,aAAa;EAAK;CAC3C,UAAU;EACT,aAAa,KAAK;CACnB;AACD;AASA,eAAsB,eACrB,WACA,UAA0B,UAC1B,cAAsB,QAAQ,SAAS,MACT;CAC9B,MAAM,UAAU,qBAAqB;CACrC,MAAM,EAAE,SAAS,QAAQ,gBAAgB,MAAM,oBAAoB,WAAW,OAAO;CAMrF,OAAO;EACN;EACA;EACA;EACA,iBAAA,CALwB,EAAE,WAAW,UAAU,WAAW;EAM1D,mBAAmB;GAClB,YAAY,cAAc,eAAe,aAAa,WAAW,IAAI;GACrE,UAAU;GACV,SAAS;EACV;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"updateCheck.server.js","names":[],"sources":["../../../../server/src/ops/semver.ts","../../../src/lib/server/releaseChannel.server.ts","../../../src/lib/server/dataFormat.server.ts","../../../src/lib/server/updateCheck.server.ts"],"sourcesContent":["/**\n * Channel-aware semver comparison for update checks. Understands exactly the\n * two lines Selva publishes under: stable (`x.y.z`, npm `latest`) and beta\n * (`x.y.z-beta.N`, npm `beta`). Deliberately not general semver — no build\n * metadata, no arbitrary pre-release identifiers.\n */\n\n/** Which published line a deployment tracks. */\nexport type ReleaseChannel = 'stable' | 'beta';\n\n/**\n * Parse `x.y.z` plus an optional `-beta.N` counter. `beta` comes back separate\n * from the core so beta-channel comparisons can order successive betas of one\n * core. Null when the string doesn't lead with a numeric core.\n */\nexport function parseSemver(\n\tv: string\n): { core: [number, number, number]; beta: number | null } | null {\n\tconst m = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-beta\\.(\\d+))?/.exec(v.trim());\n\tif (!m) return null;\n\treturn {\n\t\tcore: [Number(m[1]), Number(m[2]), Number(m[3])],\n\t\tbeta: m[4] != null ? Number(m[4]) : null\n\t};\n}\n\n/**\n * Compare two `x.y.z` cores, ignoring pre-release tails. Callers that care\n * about those want `isNewer`, which layers the channel rules on top.\n */\nexport function compareCore(a: string, b: string): number {\n\tconst pa = parseSemver(a);\n\tconst pb = parseSemver(b);\n\tif (!pa || !pb) return 0;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (pa.core[i] > pb.core[i]) return 1;\n\t\tif (pa.core[i] < pb.core[i]) return -1;\n\t}\n\treturn 0;\n}\n\n/**\n * Does `version` satisfy an `engines.node` range?\n *\n * Deliberately narrow: handles the `>=`, `>`, `<=`, `<`, `^`, `~`, `=` and\n * bare-version forms Selva and its dependencies publish, plus `||` alternatives\n * and space-separated conjunctions (`>=18 <21`). Anything it can't parse\n * returns `null` for \"unknown\", never a false \"incompatible\" — a wrong block\n * would strand an operator with no way to override the bad parse.\n *\n * A full `semver` dependency would subsume this, but isn't warranted for the\n * handful of range forms in play.\n */\nexport function satisfiesRange(version: string, range: string): boolean | null {\n\tconst v = parseSemver(version);\n\tif (!v) return null;\n\n\tconst alternatives = range.split('||').map((r) => r.trim());\n\tlet anyParsed = false;\n\n\tfor (const alt of alternatives) {\n\t\tconst clauses = alt.split(/\\s+/).filter(Boolean);\n\t\tif (clauses.length === 0) continue;\n\n\t\tlet all = true;\n\t\tlet altParsed = true;\n\t\tfor (const clause of clauses) {\n\t\t\tconst m = /^(>=|<=|>|<|\\^|~|=)?\\s*v?(\\d+)(?:\\.(\\d+|x|\\*))?(?:\\.(\\d+|x|\\*))?/.exec(clause);\n\t\t\tif (!m) {\n\t\t\t\taltParsed = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst op = m[1] ?? '=';\n\t\t\tconst num = (s: string | undefined) => (s == null || s === 'x' || s === '*' ? 0 : Number(s));\n\t\t\tconst target: [number, number, number] = [Number(m[2]), num(m[3]), num(m[4])];\n\t\t\tconst cmp = (() => {\n\t\t\t\tfor (let i = 0; i < 3; i++) {\n\t\t\t\t\tif (v.core[i] > target[i]) return 1;\n\t\t\t\t\tif (v.core[i] < target[i]) return -1;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t})();\n\n\t\t\tlet ok: boolean;\n\t\t\tswitch (op) {\n\t\t\t\tcase '>=':\n\t\t\t\t\tok = cmp >= 0;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '>':\n\t\t\t\t\tok = cmp > 0;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '<=':\n\t\t\t\t\tok = cmp <= 0;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '<':\n\t\t\t\t\tok = cmp < 0;\n\t\t\t\t\tbreak;\n\t\t\t\t// ^X.Y.Z allows anything up to the next major; ~X.Y.Z up to the next minor.\n\t\t\t\tcase '^':\n\t\t\t\t\tok = cmp >= 0 && v.core[0] === target[0];\n\t\t\t\t\tbreak;\n\t\t\t\tcase '~':\n\t\t\t\t\tok = cmp >= 0 && v.core[0] === target[0] && v.core[1] === target[1];\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\t// A bare version means that exact release, but `18` / `18.x` mean the\n\t\t\t\t\t// whole line — treat omitted segments as wildcards.\n\t\t\t\t\tok =\n\t\t\t\t\t\tv.core[0] === target[0] &&\n\t\t\t\t\t\t(m[3] == null || m[3] === 'x' || m[3] === '*' || v.core[1] === target[1]) &&\n\t\t\t\t\t\t(m[4] == null || m[4] === 'x' || m[4] === '*' || v.core[2] === target[2]);\n\t\t\t}\n\t\t\tif (!ok) {\n\t\t\t\tall = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!altParsed) continue;\n\t\tanyParsed = true;\n\t\tif (all) return true;\n\t}\n\n\treturn anyParsed ? false : null;\n}\n\n/**\n * True when `latest` is strictly newer than `current`.\n *\n * Stable channel (default): pre-release suffixes are ignored, so only stable\n * core bumps surface.\n *\n * Beta channel: pre-releases participate. A higher core wins; on an equal core\n * a higher `-beta.N` wins, and a stable (no suffix) outranks any -beta of that\n * core (4.6.0 > 4.6.0-beta.9). An update UI can then show both \"beta.1 →\n * beta.2\" and the promotion of a beta line to stable.\n *\n * Unparseable versions fall back to inequality: different strings count as\n * newer, so an odd published version still surfaces; identical ones don't.\n */\nexport function isNewer(\n\tlatest: string,\n\tcurrent: string,\n\tchannel: ReleaseChannel = 'stable'\n): boolean {\n\tconst a = parseSemver(latest);\n\tconst b = parseSemver(current);\n\tif (!a || !b) return latest !== current;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (a.core[i] > b.core[i]) return true;\n\t\tif (a.core[i] < b.core[i]) return false;\n\t}\n\tif (channel !== 'beta') return false;\n\t// Stable (beta == null) ranks above any pre-release of the same core.\n\tconst rank = (beta: number | null) => (beta == null ? Infinity : beta);\n\treturn rank(a.beta) > rank(b.beta);\n}\n","// ============================================================================\n// Release channel\n// ============================================================================\n//\n// Which published line of @selvajs/* this deployment tracks: \"stable\" (npm\n// `latest` dist-tag) or \"beta\" (npm `beta` dist-tag). Persisted as a tiny\n// JSON file in the deployment dir (next to package.json / ecosystem.config.cjs)\n// — not a provider store — because both the SvelteKit process and the bash\n// update runner must read it, and the runner can't reach a DB. The file is\n// the single source of truth; absent/invalid resolves to \"stable\".\n//\n// The deployment dir is found the same way the update runner detects it: the\n// dir holding node_modules/@selvajs/selva (probed from cwd upward, or pinned\n// via INSTALL_DIR), so the channel file travels with the deployment and is\n// reachable from the runner's cwd.\n\nimport { existsSync, readFileSync, writeFileSync } from 'fs';\nimport { join } from 'path';\nimport { env } from '#lib/server/env.js';\nimport type { ReleaseChannel } from '@selvajs/server/ops';\n\nexport type { ReleaseChannel };\n\nconst CHANNEL_FILE = 'selva-channel.json';\n\nexport function channelTag(channel: ReleaseChannel): string {\n\treturn channel === 'beta' ? 'beta' : 'latest';\n}\n\n// The update runner installs through npm, which reads this same variable, so\n// the check and the install can never ask two different registries.\nexport function channelRegistryUrl(channel: ReleaseChannel): string {\n\tconst registry = (env.NPM_CONFIG_REGISTRY || 'https://registry.npmjs.org').replace(/\\/+$/, '');\n\treturn `${registry}/@selvajs%2Fselva/${channelTag(channel)}`;\n}\n\nfunction isChannel(v: unknown): v is ReleaseChannel {\n\treturn v === 'stable' || v === 'beta';\n}\n\n// Mirrors detectUpdatePlan / readInstalledVersion so the channel file lands\n// where all three agree.\nfunction deploymentDir(): string | null {\n\tconst candidates: string[] = [];\n\tif (env.INSTALL_DIR) candidates.push(env.INSTALL_DIR);\n\tlet dir = process.cwd();\n\tfor (let i = 0; i < 6; i++) {\n\t\tcandidates.push(dir);\n\t\tconst parent = join(dir, '..');\n\t\tif (parent === dir) break;\n\t\tdir = parent;\n\t}\n\tfor (const d of candidates) {\n\t\tif (existsSync(join(d, 'node_modules', '@selvajs', 'selva', 'package.json'))) return d;\n\t}\n\treturn null;\n}\n\n// Falls back to cwd outside a recognizable deployment (dev, tests) so\n// writeChannel never throws for lack of a target.\nfunction channelFilePath(): string {\n\treturn join(deploymentDir() ?? process.cwd(), CHANNEL_FILE);\n}\n\nexport function readChannel(): ReleaseChannel {\n\tconst path = channelFilePath();\n\tif (!existsSync(path)) return 'stable';\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(path, 'utf8')) as { channel?: unknown };\n\t\treturn isChannel(parsed.channel) ? parsed.channel : 'stable';\n\t} catch {\n\t\treturn 'stable';\n\t}\n}\n\nexport function writeChannel(channel: ReleaseChannel): void {\n\tif (!isChannel(channel)) throw new Error(`Invalid release channel: ${channel}`);\n\twriteFileSync(channelFilePath(), JSON.stringify({ channel }, null, 2) + '\\n', 'utf8');\n}\n","// ============================================================================\n// Data format\n// ============================================================================\n//\n// One number for everything this app persists: data files, database rows,\n// at-rest envelopes. A build with format N writes data that only builds with\n// format >= N can read, so the updater refuses to install a lower one.\n//\n// Bump it in the change that makes an older release unable to read what this\n// one writes, and add a line below. `selva.dataFormat` in package.json must\n// match: the updater reads the target's number from the npm registry, before\n// the target's code is on the host. `pnpm check:downgrade` fails a release\n// that breaks the latest stable's reads without a bump.\n//\n// 1 Through 4.20.0, which declares no number.\n// 2 4.21.0. Boot re-seals Compute API keys as `enc:v3:`, which format 1\n// reports as plaintext and refuses to use.\n// 3 4.21.0. Supabase only: sessions lose every write on `selva` tables and the\n// stores write with the service role. An older build writes as the user,\n// so on the migrated schema each of its writes is refused.\n\nexport const DATA_FORMAT = 3;\n\n/** The format a published `package.json` declares. None means format 1. */\nexport function declaredDataFormat(pkg: unknown): number {\n\tconst value = (pkg as { selva?: { dataFormat?: unknown } } | null)?.selva?.dataFormat;\n\treturn typeof value === 'number' && Number.isInteger(value) && value >= 1 ? value : 1;\n}\n","// ============================================================================\n// Update availability check\n// ============================================================================\n//\n// Queries the npm registry for the published @selvajs/selva version on the\n// deployment's channel and compares it to the installed version, so the\n// admin System page can show an \"update available\" badge. The registry fetch\n// is injected so it's testable, and every failure path degrades to \"no\n// update available\" rather than throwing — the admin page must never break\n// because npm is slow or unreachable.\n\nimport { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { env } from '#lib/server/env.js';\nimport { isNewer, satisfiesRange } from '@selvajs/server/ops';\nimport { channelRegistryUrl, type ReleaseChannel } from './releaseChannel.server';\nimport { DATA_FORMAT, declaredDataFormat } from './dataFormat.server';\n\nexport { isNewer };\n\n/**\n * Whether the host's Node satisfies the target release's `engines.node`.\n *\n * `compatible: null` means we couldn't tell (registry down, no engines field,\n * unparseable range) — the UI must treat that as \"proceed\", not as a block.\n * npm only enforces engines with `engine-strict=true`, which no deployment\n * sets, so a mismatch installs cleanly and `/api/health` still returns 200\n * (it exercises no Node-version-specific path) — hence this pre-flight.\n */\nexport interface NodeCompatibility {\n\tcompatible: boolean | null;\n\t/** The target's `engines.node` range, when the registry reported one. */\n\trequired: string | null;\n\t/** The Node version this deployment is running. */\n\trunning: string;\n}\n\n/**\n * Whether the target release can read what this deployment has stored. Only a\n * lower target format blocks; `compatible: null` means the registry gave no\n * answer, which the UI treats as \"proceed\" (the runner checks again).\n */\nexport interface DataCompatibility {\n\tcompatible: boolean | null;\n\t/** This build's data format. */\n\tinstalled: number;\n\t/** The target's, or null when the registry was unreachable. */\n\ttarget: number | null;\n}\n\nexport interface UpdateAvailability {\n\tchannel: ReleaseChannel;\n\t/** Installed @selvajs/selva version, or null if it couldn't be read. */\n\tcurrent: string | null;\n\t/** Latest published version on the channel, or null if the registry was unreachable. */\n\tlatest: string | null;\n\t/** True when both versions are known and differ — a forward update OR a stable revert target. */\n\tupdateAvailable: boolean;\n\tnodeCompatibility: NodeCompatibility;\n\tdataCompatibility: DataCompatibility;\n}\n\n// Probes cwd upward (and an explicit INSTALL_DIR) the same way the update\n// runner detects the deployment dir.\nexport function readInstalledVersion(): string | null {\n\tconst dirs: string[] = [];\n\tif (env.INSTALL_DIR) dirs.push(env.INSTALL_DIR);\n\tlet dir = process.cwd();\n\tfor (let i = 0; i < 6; i++) {\n\t\tdirs.push(dir);\n\t\tconst parent = join(dir, '..');\n\t\tif (parent === dir) break;\n\t\tdir = parent;\n\t}\n\tfor (const d of dirs) {\n\t\tconst pkgPath = join(d, 'node_modules', '@selvajs', 'selva', 'package.json');\n\t\tif (!existsSync(pkgPath)) continue;\n\t\ttry {\n\t\t\tconst pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));\n\t\t\tif (typeof pkg.version === 'string') return pkg.version;\n\t\t} catch {\n\t\t\t// fall through to the next candidate\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * The registry's per-tag manifest carries `engines` alongside `version`, so\n * the Node pre-flight costs no extra request. Uses a short timeout so a slow\n * registry can't hang the caller; returns nulls on any failure.\n */\nexport interface PublishedManifest {\n\tversion: string | null;\n\tenginesNode: string | null;\n\t/** Null when the manifest could not be read; a manifest that declares none is format 1. */\n\tdataFormat: number | null;\n}\n\nconst UNREADABLE: PublishedManifest = { version: null, enginesNode: null, dataFormat: null };\n\nexport async function fetchLatestManifest(\n\tfetchImpl: typeof fetch,\n\tchannel: ReleaseChannel = 'stable'\n): Promise<PublishedManifest> {\n\tconst ctrl = new AbortController();\n\tconst timer = setTimeout(() => ctrl.abort(), 5000);\n\ttry {\n\t\tconst res = await fetchImpl(channelRegistryUrl(channel), {\n\t\t\theaders: { Accept: 'application/json' },\n\t\t\tsignal: ctrl.signal\n\t\t});\n\t\tif (!res.ok) return UNREADABLE;\n\t\tconst body = (await res.json()) as { version?: unknown; engines?: { node?: unknown } };\n\t\tconst version = typeof body.version === 'string' ? body.version : null;\n\t\treturn {\n\t\t\tversion,\n\t\t\tenginesNode: typeof body.engines?.node === 'string' ? body.engines.node : null,\n\t\t\tdataFormat: version ? declaredDataFormat(body) : null\n\t\t};\n\t} catch {\n\t\treturn UNREADABLE;\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\nexport async function fetchLatestVersion(\n\tfetchImpl: typeof fetch,\n\tchannel: ReleaseChannel = 'stable'\n): Promise<string | null> {\n\treturn (await fetchLatestManifest(fetchImpl, channel)).version;\n}\n\nexport async function checkForUpdate(\n\tfetchImpl: typeof fetch,\n\tchannel: ReleaseChannel = 'stable',\n\trunningNode: string = process.versions.node\n): Promise<UpdateAvailability> {\n\tconst current = readInstalledVersion();\n\tconst {\n\t\tversion: latest,\n\t\tenginesNode,\n\t\tdataFormat\n\t} = await fetchLatestManifest(fetchImpl, channel);\n\t// Any difference between installed and the channel's published version is\n\t// actionable: a forward update (stable→newer, beta→newer beta) OR a revert\n\t// (beta→stable lands on an OLDER stable version, but switching channel is\n\t// exactly what the operator asked for). Same version means nothing to do.\n\tconst updateAvailable = !!(current && latest && latest !== current);\n\treturn {\n\t\tchannel,\n\t\tcurrent,\n\t\tlatest,\n\t\tupdateAvailable,\n\t\tnodeCompatibility: {\n\t\t\tcompatible: enginesNode ? satisfiesRange(runningNode, enginesNode) : null,\n\t\t\trequired: enginesNode,\n\t\t\trunning: runningNode\n\t\t},\n\t\tdataCompatibility: {\n\t\t\tcompatible: dataFormat === null ? null : dataFormat >= DATA_FORMAT,\n\t\t\tinstalled: DATA_FORMAT,\n\t\t\ttarget: dataFormat\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,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,CAER;CACD;CACA,OAAO;AACR;AAcA,IAAM,aAAgC;CAAE,SAAS;CAAM,aAAa;CAAM,YAAY;AAAK;AAE3F,eAAsB,oBACrB,WACA,UAA0B,UACG;CAC7B,MAAM,OAAO,IAAI,gBAAgB;CACjC,MAAM,QAAQ,iBAAiB,KAAK,MAAM,GAAG,GAAI;CACjD,IAAI;EACH,MAAM,MAAM,MAAM,UAAU,mBAAmB,OAAO,GAAG;GACxD,SAAS,EAAE,QAAQ,mBAAmB;GACtC,QAAQ,KAAK;EACd,CAAC;EACD,IAAI,CAAC,IAAI,IAAI,OAAO;EACpB,MAAM,OAAQ,MAAM,IAAI,KAAK;EAC7B,MAAM,UAAU,OAAO,KAAK,YAAY,WAAW,KAAK,UAAU;EAClE,OAAO;GACN;GACA,aAAa,OAAO,KAAK,SAAS,SAAS,WAAW,KAAK,QAAQ,OAAO;GAC1E,YAAY,UAAU,mBAAmB,IAAI,IAAI;EAClD;CACD,QAAQ;EACP,OAAO;CACR,UAAU;EACT,aAAa,KAAK;CACnB;AACD;AASA,eAAsB,eACrB,WACA,UAA0B,UAC1B,cAAsB,QAAQ,SAAS,MACT;CAC9B,MAAM,UAAU,qBAAqB;CACrC,MAAM,EACL,SAAS,QACT,aACA,eACG,MAAM,oBAAoB,WAAW,OAAO;CAMhD,OAAO;EACN;EACA;EACA;EACA,iBAAA,CALwB,EAAE,WAAW,UAAU,WAAW;EAM1D,mBAAmB;GAClB,YAAY,cAAc,eAAe,aAAa,WAAW,IAAI;GACrE,UAAU;GACV,SAAS;EACV;EACA,mBAAmB;GAClB,YAAY,eAAe,OAAO,OAAO,cAAA;GACzC,WAAA;GACA,QAAQ;EACT;CACD;AACD"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { t as DISCOVERY_HEADERS } from "../../../../chunks/server2.js";
|
|
1
|
+
import { a as oauthUnavailable, i as oauthServer, t as DISCOVERY_HEADERS } from "../../../../chunks/server2.js";
|
|
3
2
|
import { t as publicUrl } from "../../../../chunks/origin.js";
|
|
4
3
|
import { json } from "@sveltejs/kit";
|
|
5
4
|
// src/routes/.well-known/oauth-authorization-server/+server.ts
|
|
6
|
-
var GET = ({ url }) =>
|
|
5
|
+
var GET = ({ url }) => {
|
|
6
|
+
const oauth = oauthServer(publicUrl(url).origin);
|
|
7
|
+
if (!oauth) return oauthUnavailable();
|
|
8
|
+
return json(oauth.authorizationServerMetadata(), { headers: DISCOVERY_HEADERS });
|
|
9
|
+
};
|
|
7
10
|
export { GET };
|
|
8
11
|
|
|
9
12
|
//# sourceMappingURL=_server.ts.js.map
|
package/build/server/entries/endpoints/.well-known/oauth-authorization-server/_server.ts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../src/routes/.well-known/oauth-authorization-server/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport {
|
|
1
|
+
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../src/routes/.well-known/oauth-authorization-server/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport { DISCOVERY_HEADERS, oauthServer, oauthUnavailable } from '#lib/server/oauth/server.js';\nimport { publicUrl } from '#lib/server/origin.js';\nimport type { RequestHandler } from './$types';\n\nexport const GET: RequestHandler = ({ url }) => {\n\tconst oauth = oauthServer(publicUrl(url).origin);\n\tif (!oauth) return oauthUnavailable();\n\treturn json(oauth.authorizationServerMetadata(), { headers: DISCOVERY_HEADERS });\n};\n"],"mappings":";;;;AAKA,IAAa,OAAuB,EAAE,UAAU;CAC/C,MAAM,QAAQ,YAAY,UAAU,GAAG,CAAC,CAAC,MAAM;CAC/C,IAAI,CAAC,OAAO,OAAO,iBAAiB;CACpC,OAAO,KAAK,MAAM,4BAA4B,GAAG,EAAE,SAAS,kBAAkB,CAAC;AAChF"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as DISCOVERY_HEADERS } from "../../../../chunks/server2.js";
|
|
1
|
+
import { a as oauthUnavailable, i as oauthServer, t as DISCOVERY_HEADERS } from "../../../../chunks/server2.js";
|
|
3
2
|
import { t as publicUrl } from "../../../../chunks/origin.js";
|
|
4
3
|
import { json } from "@sveltejs/kit";
|
|
5
4
|
// src/routes/.well-known/oauth-protected-resource/+server.ts
|
|
6
|
-
var GET = ({ url }) =>
|
|
5
|
+
var GET = ({ url }) => {
|
|
6
|
+
const oauth = oauthServer(publicUrl(url).origin);
|
|
7
|
+
if (!oauth) return oauthUnavailable();
|
|
8
|
+
return json(oauth.protectedResourceMetadata(), { headers: DISCOVERY_HEADERS });
|
|
9
|
+
};
|
|
7
10
|
export { GET };
|
|
8
11
|
|
|
9
12
|
//# sourceMappingURL=_server.ts.js.map
|
package/build/server/entries/endpoints/.well-known/oauth-protected-resource/_server.ts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../src/routes/.well-known/oauth-protected-resource/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport {
|
|
1
|
+
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../src/routes/.well-known/oauth-protected-resource/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport { DISCOVERY_HEADERS, oauthServer, oauthUnavailable } from '#lib/server/oauth/server.js';\nimport { publicUrl } from '#lib/server/origin.js';\nimport type { RequestHandler } from './$types';\n\n// The bare path is the fallback clients probe when a 401 carries no pointer.\nexport const GET: RequestHandler = ({ url }) => {\n\tconst oauth = oauthServer(publicUrl(url).origin);\n\tif (!oauth) return oauthUnavailable();\n\treturn json(oauth.protectedResourceMetadata(), { headers: DISCOVERY_HEADERS });\n};\n"],"mappings":";;;;AAMA,IAAa,OAAuB,EAAE,UAAU;CAC/C,MAAM,QAAQ,YAAY,UAAU,GAAG,CAAC,CAAC,MAAM;CAC/C,IAAI,CAAC,OAAO,OAAO,iBAAiB;CACpC,OAAO,KAAK,MAAM,0BAA0B,GAAG,EAAE,SAAS,kBAAkB,CAAC;AAC9E"}
|
package/build/server/entries/endpoints/.well-known/oauth-protected-resource/mcp/_server.ts.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as DISCOVERY_HEADERS } from "../../../../../chunks/server2.js";
|
|
1
|
+
import { a as oauthUnavailable, i as oauthServer, t as DISCOVERY_HEADERS } from "../../../../../chunks/server2.js";
|
|
3
2
|
import { t as publicUrl } from "../../../../../chunks/origin.js";
|
|
4
3
|
import { json } from "@sveltejs/kit";
|
|
5
4
|
// src/routes/.well-known/oauth-protected-resource/mcp/+server.ts
|
|
6
|
-
var GET = ({ url }) =>
|
|
5
|
+
var GET = ({ url }) => {
|
|
6
|
+
const oauth = oauthServer(publicUrl(url).origin);
|
|
7
|
+
if (!oauth) return oauthUnavailable();
|
|
8
|
+
return json(oauth.protectedResourceMetadata(), { headers: DISCOVERY_HEADERS });
|
|
9
|
+
};
|
|
7
10
|
export { GET };
|
|
8
11
|
|
|
9
12
|
//# sourceMappingURL=_server.ts.js.map
|
package/build/server/entries/endpoints/.well-known/oauth-protected-resource/mcp/_server.ts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/.well-known/oauth-protected-resource/mcp/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport {
|
|
1
|
+
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/.well-known/oauth-protected-resource/mcp/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport { DISCOVERY_HEADERS, oauthServer, oauthUnavailable } from '#lib/server/oauth/server.js';\nimport { publicUrl } from '#lib/server/origin.js';\nimport type { RequestHandler } from './$types';\n\nexport const GET: RequestHandler = ({ url }) => {\n\tconst oauth = oauthServer(publicUrl(url).origin);\n\tif (!oauth) return oauthUnavailable();\n\treturn json(oauth.protectedResourceMetadata(), { headers: DISCOVERY_HEADERS });\n};\n"],"mappings":";;;;AAKA,IAAa,OAAuB,EAAE,UAAU;CAC/C,MAAM,QAAQ,YAAY,UAAU,GAAG,CAAC,CAAC,MAAM;CAC/C,IAAI,CAAC,OAAO,OAAO,iBAAiB;CACpC,OAAO,KAAK,MAAM,0BAA0B,GAAG,EAAE,SAAS,kBAAkB,CAAC;AAC9E"}
|
|
@@ -6,7 +6,7 @@ import "../../../../../chunks/compute.js";
|
|
|
6
6
|
import { t as apiError } from "../../../../../chunks/api-errors.js";
|
|
7
7
|
import "../../../../../chunks/access2.server.js";
|
|
8
8
|
import { r as noContent, t as apiRoute } from "../../../../../chunks/http2.js";
|
|
9
|
-
import {
|
|
9
|
+
import { c as evictComputeClient } from "../../../../../chunks/engine.server.js";
|
|
10
10
|
import { t as serverResolver } from "../../../../../chunks/serverResolver.server.js";
|
|
11
11
|
import { json } from "@sveltejs/kit";
|
|
12
12
|
// src/lib/server/compute/evictChangedServers.ts
|
|
@@ -4,7 +4,7 @@ import { n as findServerById } from "../../../../../../chunks/utils.js";
|
|
|
4
4
|
import { t as apiError } from "../../../../../../chunks/api-errors.js";
|
|
5
5
|
import "../../../../../../chunks/access2.server.js";
|
|
6
6
|
import { t as apiRoute } from "../../../../../../chunks/http2.js";
|
|
7
|
-
import {
|
|
7
|
+
import { i as clearSolveResultCache, o as definitionByteCacheStats, r as clearDefinitionCache, u as solveCacheStats } from "../../../../../../chunks/engine.server.js";
|
|
8
8
|
import { t as openServerStats } from "../../../../../../chunks/serverStats.server.js";
|
|
9
9
|
import { json } from "@sveltejs/kit";
|
|
10
10
|
// src/routes/api/admin/compute/actions/+server.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as getComputeServerConfigStore } from "../../../../../../chunks/providers.server.js";
|
|
2
2
|
import { k as ApiErrorCode, y as requireManageCompute } from "../../../../../../chunks/access.js";
|
|
3
3
|
import { n as findServerById } from "../../../../../../chunks/utils.js";
|
|
4
|
-
import {
|
|
4
|
+
import { f as classifyProbeFailure } from "../../../../../../chunks/grasshopper.js";
|
|
5
5
|
import { t as apiError } from "../../../../../../chunks/api-errors.js";
|
|
6
6
|
import "../../../../../../chunks/access2.server.js";
|
|
7
7
|
import { t as apiRoute } from "../../../../../../chunks/http2.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { h as getOrganizationProvider, s as getDefinitionMeta, v as getProjectProvider, x as getStorageProvider } from "../../../../../../chunks/providers.server.js";
|
|
2
2
|
import { k as ApiErrorCode, v as requireInstanceAdmin } from "../../../../../../chunks/access.js";
|
|
3
3
|
import { i as ProviderError } from "../../../../../../chunks/context.js";
|
|
4
|
-
import {
|
|
4
|
+
import { U as requireParams, z as parseBody } from "../../../../../../chunks/api.js";
|
|
5
5
|
import { u as UpdateOrgSchema } from "../../../../../../chunks/schemas2.js";
|
|
6
6
|
import { t as apiError } from "../../../../../../chunks/api-errors.js";
|
|
7
7
|
import "../../../../../../chunks/access2.server.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { h as getOrganizationProvider } from "../../../../../chunks/providers.server.js";
|
|
2
2
|
import { k as ApiErrorCode, v as requireInstanceAdmin } from "../../../../../chunks/access.js";
|
|
3
3
|
import { i as ProviderError } from "../../../../../chunks/context.js";
|
|
4
|
-
import {
|
|
4
|
+
import { z as parseBody } from "../../../../../chunks/api.js";
|
|
5
5
|
import { r as CreateOrgSchema } from "../../../../../chunks/schemas2.js";
|
|
6
6
|
import { l as clampPageLimit } from "../../../../../chunks/visibility.js";
|
|
7
7
|
import { t as apiError } from "../../../../../chunks/api-errors.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as getDefinitionMeta, t as flag, v as getProjectProvider, x as getStorageProvider } from "../../../../../../chunks/providers.server.js";
|
|
2
2
|
import { k as ApiErrorCode, v as requireInstanceAdmin } from "../../../../../../chunks/access.js";
|
|
3
3
|
import { t as SYSTEM_CONTEXT } from "../../../../../../chunks/context.js";
|
|
4
|
-
import {
|
|
4
|
+
import { U as requireParams, z as parseBody } from "../../../../../../chunks/api.js";
|
|
5
5
|
import { f as slugify } from "../../../../../../chunks/schemas2.js";
|
|
6
6
|
import { t as apiError } from "../../../../../../chunks/api-errors.js";
|
|
7
7
|
import "../../../../../../chunks/access2.server.js";
|
package/build/server/entries/endpoints/api/admin/projects/_id_/grants/_grantId_/_server.ts.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as getPlatformProjectGrantStore, t as flag } from "../../../../../../../../chunks/providers.server.js";
|
|
2
2
|
import { k as ApiErrorCode, v as requireInstanceAdmin } from "../../../../../../../../chunks/access.js";
|
|
3
3
|
import { t as SYSTEM_CONTEXT } from "../../../../../../../../chunks/context.js";
|
|
4
|
-
import {
|
|
4
|
+
import { U as requireParams } from "../../../../../../../../chunks/api.js";
|
|
5
5
|
import { t as apiError } from "../../../../../../../../chunks/api-errors.js";
|
|
6
6
|
import "../../../../../../../../chunks/access2.server.js";
|
|
7
7
|
import { r as noContent, t as apiRoute } from "../../../../../../../../chunks/http2.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as getUserProfileStore, _ as getPlatformProjectGrantStore, h as getOrganizationProvider, t as flag, v as getProjectProvider } from "../../../../../../../chunks/providers.server.js";
|
|
2
2
|
import { k as ApiErrorCode, v as requireInstanceAdmin } from "../../../../../../../chunks/access.js";
|
|
3
3
|
import { t as SYSTEM_CONTEXT } from "../../../../../../../chunks/context.js";
|
|
4
|
-
import {
|
|
4
|
+
import { U as requireParams, z as parseBody } from "../../../../../../../chunks/api.js";
|
|
5
5
|
import { t as apiError } from "../../../../../../../chunks/api-errors.js";
|
|
6
6
|
import "../../../../../../../chunks/access2.server.js";
|
|
7
7
|
import { n as created, t as apiRoute } from "../../../../../../../chunks/http2.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { h as getOrganizationProvider, t as flag, v as getProjectProvider } from "../../../../../chunks/providers.server.js";
|
|
2
2
|
import { k as ApiErrorCode, v as requireInstanceAdmin } from "../../../../../chunks/access.js";
|
|
3
3
|
import { t as SYSTEM_CONTEXT } from "../../../../../chunks/context.js";
|
|
4
|
-
import {
|
|
4
|
+
import { z as parseBody } from "../../../../../chunks/api.js";
|
|
5
5
|
import { t as apiError } from "../../../../../chunks/api-errors.js";
|
|
6
6
|
import "../../../../../chunks/access2.server.js";
|
|
7
7
|
import { n as created, t as apiRoute } from "../../../../../chunks/http2.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as LocalComputeServerStore, T as providers, a as getComputeServerConfigStore } from "../../../../../../chunks/providers.server.js";
|
|
2
2
|
import { n as env } from "../../../../../../chunks/previous-key.js";
|
|
3
3
|
import { C as requirePermission } from "../../../../../../chunks/access.js";
|
|
4
4
|
import { n as findServerById } from "../../../../../../chunks/utils.js";
|
|
@@ -27,11 +27,12 @@ function atRestSecretsCheck(report) {
|
|
|
27
27
|
};
|
|
28
28
|
const failed = report.failures.map((f) => `"${f.serverLabel}" (${f.reason}${f.cause ? `: ${f.cause}` : ""})`).join(", ");
|
|
29
29
|
const plaintext = report.plaintextFound;
|
|
30
|
+
const newerFormat = report.failures.some((f) => f.reason === "unknown_envelope");
|
|
30
31
|
return {
|
|
31
32
|
...base,
|
|
32
33
|
status: "degraded",
|
|
33
34
|
summary: `${report.failures.length} compute server key(s) could not be loaded: ${failed}.`,
|
|
34
|
-
remediation: plaintext ? "A key is stored in plaintext on disk — re-enter it via /admin/compute so it is encrypted." : "The stored ciphertext does not match the current SELVA_AT_REST_KEY (rotated key or restored backup). Re-enter the affected keys via /admin/compute, or restore the original SELVA_AT_REST_KEY, then run this check again."
|
|
35
|
+
remediation: plaintext ? "A key is stored in plaintext on disk — re-enter it via /admin/compute so it is encrypted." : newerFormat ? "A key was sealed by a newer Selva version than the one running. Upgrade Selva again, or re-enter the affected keys via /admin/compute, then run this check again." : "The stored ciphertext does not match the current SELVA_AT_REST_KEY (rotated key or restored backup). Re-enter the affected keys via /admin/compute, or restore the original SELVA_AT_REST_KEY, then run this check again."
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
function schemaVersionCheck(report) {
|
|
@@ -44,6 +45,12 @@ function schemaVersionCheck(report) {
|
|
|
44
45
|
status: "not_applicable",
|
|
45
46
|
summary: "The active data provider migrates with the app — there is no separate schema to verify."
|
|
46
47
|
};
|
|
48
|
+
if (report.ok && report.message) return {
|
|
49
|
+
...base,
|
|
50
|
+
status: "degraded",
|
|
51
|
+
summary: report.message,
|
|
52
|
+
remediation: "Sync the provider migrations into your Supabase project and run `npx supabase db push`."
|
|
53
|
+
};
|
|
47
54
|
if (report.ok) return {
|
|
48
55
|
...base,
|
|
49
56
|
status: "ok",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_server.ts.js","names":["privateEnv"],"sources":["../../../../../../../../src/routes/api/admin/system/health/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { randomUUID } from 'node:crypto';\nimport { writeFile, unlink, mkdir } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\nimport { env as privateEnv } from '#lib/server/env.js';\nimport { LocalComputeServerStore } from '@selvajs/local-provider';\nimport { openServerStats } from '#lib/server/compute/serverStats.server.js';\nimport {\n\tfindServerById,\n\ttype SchemaVersionReport,\n\ttype SecretVerificationReport\n} from '@selvajs/platform';\nimport { checkDeploymentConfig, type ConfigFinding } from '@selvajs/server/ops';\nimport { providers, getComputeServerConfigStore } from '#lib/server/providers.server.js';\nimport { requirePermission } from '#lib/server/access.server.js';\n\n/**\n * On-demand admin health check. Unlike `/api/health` (which serves the cached\n * BOOT snapshot for load balancers), this re-runs the integrity checks LIVE so\n * the result reflects the current state — an operator who just re-entered a\n * compute apiKey via /admin/compute sees \"ok\" immediately, without restarting.\n *\n * Checks (each reports `not_applicable` rather than a misleading green when\n * it can't run against the active provider):\n * 1. At-rest secret decryption — stored compute API keys decrypt under the\n * current SELVA_AT_REST_KEY (local provider only; the compute-key state\n * that otherwise surfaces as opaque 401/403s from Rhino.Compute).\n * 2. Compute reachability — the default platform server answers its\n * liveness probe. Catches \"key decrypts fine but the server is down\", a\n * gap check #1 can't see: a healthy at-rest key with an unreachable\n * server still fails every solve.\n * 3. Data path writable — for the local provider, a temp file can be\n * written + deleted under DATA_PATH. Catches disk-full / permission\n * regressions before they corrupt a JSON store mid-write.\n * 4. Deployment config — the reverse-proxy and upload-limit vars adapter-node\n * reads. These break a running deployment without failing anything at\n * boot, so a panel that omits them reads as \"all clear\" while every user\n * shares one login rate-limit bucket. Same rules `selva doctor` applies.\n * 5. API token sessions — on Supabase, whether the configured signing key\n * is one the project accepts. A bad key turns API tokens off silently\n * otherwise: they answer 503 while browser sign-in keeps working.\n *\n * Deliberately NOT covered, because the running process cannot answer them\n * honestly — `selva doctor` owns these, and the panel says so:\n * - Host filesystem state (`.env` present, interrupted migration, pm2 boot\n * unit). The app sees its own resolved env, not the files behind it, so a\n * green here would only mean \"something booted me\".\n * - Secret strength (SELVA_HMAC_KEY / SELVA_AT_REST_KEY still the shipped\n * placeholder). Checkable, but it means handling raw signing keys in a\n * request handler to report a fact that cannot change without a restart.\n *\n * `instance_admin` only — this reveals which compute servers failed and why.\n */\n\ntype CheckStatus = 'ok' | 'degraded' | 'not_applicable' | 'error';\n\ninterface HealthCheck {\n\tid: string;\n\tlabel: string;\n\tstatus: CheckStatus;\n\t/** Operator-facing summary. Always set. */\n\tsummary: string;\n\t/** Concrete next step when not ok. */\n\tremediation?: string;\n}\n\nfunction atRestSecretsCheck(report: SecretVerificationReport | null): HealthCheck {\n\tconst base = { id: 'at-rest-secrets', label: 'Compute server secrets' };\n\n\tif (report === null) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary:\n\t\t\t\t'The active data provider does not encrypt secrets at this layer — nothing to verify.'\n\t\t};\n\t}\n\n\tif (report.ok) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'ok',\n\t\t\tsummary: 'All stored compute server API keys decrypt under the current SELVA_AT_REST_KEY.'\n\t\t};\n\t}\n\n\tconst failed = report.failures\n\t\t.map((f) => `\"${f.serverLabel}\" (${f.reason}${f.cause ? `: ${f.cause}` : ''})`)\n\t\t.join(', ');\n\tconst plaintext = report.plaintextFound;\n\treturn {\n\t\t...base,\n\t\tstatus: 'degraded',\n\t\tsummary: `${report.failures.length} compute server key(s) could not be loaded: ${failed}.`,\n\t\tremediation: plaintext\n\t\t\t? 'A key is stored in plaintext on disk — re-enter it via /admin/compute so it is encrypted.'\n\t\t\t: 'The stored ciphertext does not match the current SELVA_AT_REST_KEY (rotated key or ' +\n\t\t\t\t'restored backup). Re-enter the affected keys via /admin/compute, or restore the ' +\n\t\t\t\t'original SELVA_AT_REST_KEY, then run this check again.'\n\t};\n}\n\nfunction schemaVersionCheck(report: SchemaVersionReport | null): HealthCheck {\n\tconst base = { id: 'schema-version', label: 'Database schema' };\n\n\tif (report === null) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary:\n\t\t\t\t'The active data provider migrates with the app — there is no separate schema to verify.'\n\t\t};\n\t}\n\n\tif (report.ok) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'ok',\n\t\t\tsummary: `Database migration head ${report.actual} satisfies the app's expected ${report.expected}.`\n\t\t};\n\t}\n\n\treturn {\n\t\t...base,\n\t\tstatus: 'degraded',\n\t\tsummary:\n\t\t\treport.message ??\n\t\t\t`Database migration head ${report.actual ?? 'unavailable'} is behind the app's expected ${report.expected}.`,\n\t\tremediation:\n\t\t\t'Sync the provider migrations into your Supabase project and run `npx supabase db push`, ' +\n\t\t\t'then restart the app. `selva doctor` runs the same check from the CLI.'\n\t};\n}\n\n/** API tokens on a provider with row security need a signing key Supabase trusts. */\nasync function delegatedSessionCheck(): Promise<HealthCheck> {\n\tconst base = { id: 'api-token-sessions', label: 'API token sessions' };\n\tconst delegated = providers.auth.delegatedSession;\n\tif (!delegated) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary: 'The active auth provider needs no signed sessions for API tokens.'\n\t\t};\n\t}\n\tconst status = await delegated.status();\n\tif (status.ok) {\n\t\treturn { ...base, status: 'ok', summary: 'API tokens can act as their owners.' };\n\t}\n\treturn {\n\t\t...base,\n\t\tstatus: 'degraded',\n\t\tsummary: `API tokens are off: ${status.message}`,\n\t\tremediation:\n\t\t\t'Set SUPABASE_JWT_SIGNING_KEY to the private ES256 JWK your Supabase project signs with ' +\n\t\t\t'(see the Supabase provider docs), then restart. Browser sign-in is unaffected.'\n\t};\n}\n\nconst COMPUTE_PING_TIMEOUT_MS = 8000;\n\n/**\n * Ping the global default compute server's liveness root (`GET /` — the\n * rhino.compute proxy has no `/healthcheck` route). We probe the default\n * specifically because that's the server every solve falls back to;\n * a degraded default breaks the baseline for all orgs. Org-private and\n * non-default platform servers are out of scope here — they have their own\n * per-server status probe at /api/admin/compute/status.\n */\nasync function computeReachabilityCheck(locals: App.Locals): Promise<HealthCheck> {\n\tconst base = { id: 'compute-reachable', label: 'Default compute server' };\n\n\tlet config;\n\ttry {\n\t\tconfig = await getComputeServerConfigStore().getConfig(locals.ctx!);\n\t} catch (err) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'error',\n\t\t\tsummary: `Could not read compute config: ${err instanceof Error ? err.message : String(err)}`\n\t\t};\n\t}\n\n\tconst server = config.defaultServerId\n\t\t? findServerById(config, config.defaultServerId)\n\t\t: undefined;\n\tif (!server) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary: 'No default compute server is configured — nothing to reach.',\n\t\t\tremediation: 'Add a server and set it as default in /admin/compute.'\n\t\t};\n\t}\n\n\tconst apiKey = server.hasApiKey\n\t\t? await getComputeServerConfigStore().getServerApiKey(locals.ctx!, server.id)\n\t\t: undefined;\n\tconst { stats, misconfigured } = openServerStats(server.serverUrl, apiKey ?? undefined);\n\tif (!stats) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'error',\n\t\t\tsummary: `\"${server.label}\" can't be used: ${misconfigured}`,\n\t\t\tremediation: 'Fix the server URL or API key in /admin/compute.'\n\t\t};\n\t}\n\ttry {\n\t\tconst online = await stats.isServerOnline(COMPUTE_PING_TIMEOUT_MS);\n\t\tif (online) {\n\t\t\treturn { ...base, status: 'ok', summary: `\"${server.label}\" is reachable.` };\n\t\t}\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'degraded',\n\t\t\tsummary: `\"${server.label}\" did not respond within ${COMPUTE_PING_TIMEOUT_MS / 1000}s or answered with an error.`,\n\t\t\tremediation: `Confirm the Rhino.Compute host is running, ${server.serverUrl} is correct, and the API key in /admin/compute is valid.`\n\t\t};\n\t} finally {\n\t\tawait stats.dispose();\n\t}\n}\n\n/**\n * Write + delete a temp file under DATA_PATH to prove the local provider can\n * still persist. The JSON stores read-modify-write without a fallback, so a\n * full disk or a permission change (e.g. ownership drift after a restore)\n * corrupts data on the next write — catch it here while it's still just a\n * failed health check.\n */\nasync function dataPathWritableCheck(): Promise<HealthCheck> {\n\tconst base = { id: 'data-path-writable', label: 'Data path writable' };\n\n\t// Only meaningful when a local store is actually backing the deployment.\n\tif (!(providers.data.computeServer instanceof LocalComputeServerStore)) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary: 'The active data provider does not persist to a local DATA_PATH.'\n\t\t};\n\t}\n\n\tconst dataPath = privateEnv.DATA_PATH;\n\tif (!dataPath) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'error',\n\t\t\tsummary: 'DATA_PATH is unset but the local provider is active.',\n\t\t\tremediation: 'Set DATA_PATH in .env and restart.'\n\t\t};\n\t}\n\n\tconst absolute = resolve(dataPath);\n\tconst probe = join(absolute, `.health-probe-${randomUUID()}`);\n\ttry {\n\t\tawait mkdir(absolute, { recursive: true });\n\t\tawait writeFile(probe, 'ok');\n\t\tawait unlink(probe);\n\t\treturn { ...base, status: 'ok', summary: `DATA_PATH (${dataPath}) is writable.` };\n\t} catch (err) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'degraded',\n\t\t\tsummary: `DATA_PATH (${dataPath}) is not writable: ${err instanceof Error ? err.message : String(err)}.`,\n\t\t\tremediation:\n\t\t\t\t'Check free disk space and that the directory is owned by the user running the app ' +\n\t\t\t\t'(`df -h`, `ls -la`).'\n\t\t};\n\t}\n}\n\n/**\n * Deployment-config rules run against the live process env, which is what\n * adapter-node itself read at boot — not a re-parse of `.env`, so a var\n * overridden by the service manager is judged as it actually applies.\n *\n * A `fail` maps to `error` rather than `degraded`: these are the same verdicts\n * that exit `selva doctor` non-zero, and the panel should not soften them.\n */\nfunction deploymentConfigChecks(): HealthCheck[] {\n\treturn checkDeploymentConfig(privateEnv).map((finding: ConfigFinding) => ({\n\t\tid: finding.id,\n\t\tlabel: finding.label,\n\t\tstatus: finding.verdict === 'fail' ? 'error' : finding.verdict === 'warn' ? 'degraded' : 'ok',\n\t\tsummary: finding.summary,\n\t\tremediation: finding.remediation\n\t}));\n}\n\nexport const GET: RequestHandler = async ({ locals }) => {\n\trequirePermission(locals, 'instance_admin');\n\n\tconst checks: HealthCheck[] = [];\n\n\tconst store = providers.data.computeServer;\n\tif (typeof store.verifySecrets === 'function') {\n\t\ttry {\n\t\t\tchecks.push(atRestSecretsCheck(await store.verifySecrets()));\n\t\t} catch (err) {\n\t\t\tchecks.push({\n\t\t\t\tid: 'at-rest-secrets',\n\t\t\t\tlabel: 'Compute server secrets',\n\t\t\t\tstatus: 'error',\n\t\t\t\tsummary: `Verification threw: ${err instanceof Error ? err.message : String(err)}`,\n\t\t\t\tremediation: 'Check server logs (`pm2 logs selva-compute`) for the underlying error.'\n\t\t\t});\n\t\t}\n\t} else {\n\t\tchecks.push(atRestSecretsCheck(null));\n\t}\n\n\t// Live app↔DB schema handshake (audit O3) — unlike boot health this re-runs\n\t// on every request, so an operator sees green right after `db push` without\n\t// restarting first (the boot report itself stays stale by design).\n\tconst data = providers.data;\n\tif (typeof data.verifySchemaVersion === 'function') {\n\t\tchecks.push(schemaVersionCheck(await data.verifySchemaVersion()));\n\t} else {\n\t\tchecks.push(schemaVersionCheck(null));\n\t}\n\n\t// Reachability + writability run in parallel — independent of each other\n\t// and of the at-rest check above. Each self-contains its error handling.\n\tchecks.push(\n\t\t...(await Promise.all([\n\t\t\tcomputeReachabilityCheck(locals),\n\t\t\tdataPathWritableCheck(),\n\t\t\tdelegatedSessionCheck()\n\t\t]))\n\t);\n\n\tchecks.push(...deploymentConfigChecks());\n\n\t// Worst status wins for the overall verdict. `not_applicable` never\n\t// degrades the overall result.\n\tconst rank: Record<CheckStatus, number> = {\n\t\tok: 0,\n\t\tnot_applicable: 0,\n\t\tdegraded: 2,\n\t\terror: 3\n\t};\n\tconst overall = checks.reduce<CheckStatus>(\n\t\t(worst, c) => (rank[c.status] > rank[worst] ? c.status : worst),\n\t\t'ok'\n\t);\n\n\treturn json({ overall, checkedAt: new Date().toISOString(), checks });\n};\n"],"mappings":";;;;;;;;;;;;AAmEA,SAAS,mBAAmB,QAAsD;CACjF,MAAM,OAAO;EAAE,IAAI;EAAmB,OAAO;CAAyB;CAEtE,IAAI,WAAW,MACd,OAAO;EACN,GAAG;EACH,QAAQ;EACR,SACC;CACF;CAGD,IAAI,OAAO,IACV,OAAO;EACN,GAAG;EACH,QAAQ;EACR,SAAS;CACV;CAGD,MAAM,SAAS,OAAO,SACpB,KAAK,MAAM,IAAI,EAAE,YAAY,KAAK,EAAE,SAAS,EAAE,QAAQ,KAAK,EAAE,UAAU,GAAG,EAAE,CAAC,CAC9E,KAAK,IAAI;CACX,MAAM,YAAY,OAAO;CACzB,OAAO;EACN,GAAG;EACH,QAAQ;EACR,SAAS,GAAG,OAAO,SAAS,OAAO,8CAA8C,OAAO;EACxF,aAAa,YACV,8FACA;C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AG;CAAO,CAAC;AACrE"}
|
|
1
|
+
{"version":3,"file":"_server.ts.js","names":["privateEnv"],"sources":["../../../../../../../../src/routes/api/admin/system/health/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { randomUUID } from 'node:crypto';\nimport { writeFile, unlink, mkdir } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\nimport { env as privateEnv } from '#lib/server/env.js';\nimport { LocalComputeServerStore } from '@selvajs/local-provider';\nimport { openServerStats } from '#lib/server/compute/serverStats.server.js';\nimport {\n\tfindServerById,\n\ttype SchemaVersionReport,\n\ttype SecretVerificationReport\n} from '@selvajs/platform';\nimport { checkDeploymentConfig, type ConfigFinding } from '@selvajs/server/ops';\nimport { providers, getComputeServerConfigStore } from '#lib/server/providers.server.js';\nimport { requirePermission } from '#lib/server/access.server.js';\n\n/**\n * On-demand admin health check. Unlike `/api/health` (which serves the cached\n * BOOT snapshot for load balancers), this re-runs the integrity checks LIVE so\n * the result reflects the current state — an operator who just re-entered a\n * compute apiKey via /admin/compute sees \"ok\" immediately, without restarting.\n *\n * Checks (each reports `not_applicable` rather than a misleading green when\n * it can't run against the active provider):\n * 1. At-rest secret decryption — stored compute API keys decrypt under the\n * current SELVA_AT_REST_KEY (local provider only; the compute-key state\n * that otherwise surfaces as opaque 401/403s from Rhino.Compute).\n * 2. Compute reachability — the default platform server answers its\n * liveness probe. Catches \"key decrypts fine but the server is down\", a\n * gap check #1 can't see: a healthy at-rest key with an unreachable\n * server still fails every solve.\n * 3. Data path writable — for the local provider, a temp file can be\n * written + deleted under DATA_PATH. Catches disk-full / permission\n * regressions before they corrupt a JSON store mid-write.\n * 4. Deployment config — the reverse-proxy and upload-limit vars adapter-node\n * reads. These break a running deployment without failing anything at\n * boot, so a panel that omits them reads as \"all clear\" while every user\n * shares one login rate-limit bucket. Same rules `selva doctor` applies.\n * 5. API token sessions — on Supabase, whether the configured signing key\n * is one the project accepts. A bad key turns API tokens off silently\n * otherwise: they answer 503 while browser sign-in keeps working.\n *\n * Deliberately NOT covered, because the running process cannot answer them\n * honestly — `selva doctor` owns these, and the panel says so:\n * - Host filesystem state (`.env` present, interrupted migration, pm2 boot\n * unit). The app sees its own resolved env, not the files behind it, so a\n * green here would only mean \"something booted me\".\n * - Secret strength (SELVA_HMAC_KEY / SELVA_AT_REST_KEY still the shipped\n * placeholder). Checkable, but it means handling raw signing keys in a\n * request handler to report a fact that cannot change without a restart.\n *\n * `instance_admin` only — this reveals which compute servers failed and why.\n */\n\ntype CheckStatus = 'ok' | 'degraded' | 'not_applicable' | 'error';\n\ninterface HealthCheck {\n\tid: string;\n\tlabel: string;\n\tstatus: CheckStatus;\n\t/** Operator-facing summary. Always set. */\n\tsummary: string;\n\t/** Concrete next step when not ok. */\n\tremediation?: string;\n}\n\nfunction atRestSecretsCheck(report: SecretVerificationReport | null): HealthCheck {\n\tconst base = { id: 'at-rest-secrets', label: 'Compute server secrets' };\n\n\tif (report === null) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary:\n\t\t\t\t'The active data provider does not encrypt secrets at this layer — nothing to verify.'\n\t\t};\n\t}\n\n\tif (report.ok) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'ok',\n\t\t\tsummary: 'All stored compute server API keys decrypt under the current SELVA_AT_REST_KEY.'\n\t\t};\n\t}\n\n\tconst failed = report.failures\n\t\t.map((f) => `\"${f.serverLabel}\" (${f.reason}${f.cause ? `: ${f.cause}` : ''})`)\n\t\t.join(', ');\n\tconst plaintext = report.plaintextFound;\n\tconst newerFormat = report.failures.some((f) => f.reason === 'unknown_envelope');\n\treturn {\n\t\t...base,\n\t\tstatus: 'degraded',\n\t\tsummary: `${report.failures.length} compute server key(s) could not be loaded: ${failed}.`,\n\t\tremediation: plaintext\n\t\t\t? 'A key is stored in plaintext on disk — re-enter it via /admin/compute so it is encrypted.'\n\t\t\t: newerFormat\n\t\t\t\t? 'A key was sealed by a newer Selva version than the one running. Upgrade Selva ' +\n\t\t\t\t\t'again, or re-enter the affected keys via /admin/compute, then run this check again.'\n\t\t\t\t: 'The stored ciphertext does not match the current SELVA_AT_REST_KEY (rotated key or ' +\n\t\t\t\t\t'restored backup). Re-enter the affected keys via /admin/compute, or restore the ' +\n\t\t\t\t\t'original SELVA_AT_REST_KEY, then run this check again.'\n\t};\n}\n\nfunction schemaVersionCheck(report: SchemaVersionReport | null): HealthCheck {\n\tconst base = { id: 'schema-version', label: 'Database schema' };\n\n\tif (report === null) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary:\n\t\t\t\t'The active data provider migrates with the app — there is no separate schema to verify.'\n\t\t};\n\t}\n\n\t// Ok with a message: the app runs, and migrations it ships are still to push.\n\tif (report.ok && report.message) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'degraded',\n\t\t\tsummary: report.message,\n\t\t\tremediation:\n\t\t\t\t'Sync the provider migrations into your Supabase project and run `npx supabase db push`.'\n\t\t};\n\t}\n\n\tif (report.ok) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'ok',\n\t\t\tsummary: `Database migration head ${report.actual} satisfies the app's expected ${report.expected}.`\n\t\t};\n\t}\n\n\treturn {\n\t\t...base,\n\t\tstatus: 'degraded',\n\t\tsummary:\n\t\t\treport.message ??\n\t\t\t`Database migration head ${report.actual ?? 'unavailable'} is behind the app's expected ${report.expected}.`,\n\t\tremediation:\n\t\t\t'Sync the provider migrations into your Supabase project and run `npx supabase db push`, ' +\n\t\t\t'then restart the app. `selva doctor` runs the same check from the CLI.'\n\t};\n}\n\n/** API tokens on a provider with row security need a signing key Supabase trusts. */\nasync function delegatedSessionCheck(): Promise<HealthCheck> {\n\tconst base = { id: 'api-token-sessions', label: 'API token sessions' };\n\tconst delegated = providers.auth.delegatedSession;\n\tif (!delegated) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary: 'The active auth provider needs no signed sessions for API tokens.'\n\t\t};\n\t}\n\tconst status = await delegated.status();\n\tif (status.ok) {\n\t\treturn { ...base, status: 'ok', summary: 'API tokens can act as their owners.' };\n\t}\n\treturn {\n\t\t...base,\n\t\tstatus: 'degraded',\n\t\tsummary: `API tokens are off: ${status.message}`,\n\t\tremediation:\n\t\t\t'Set SUPABASE_JWT_SIGNING_KEY to the private ES256 JWK your Supabase project signs with ' +\n\t\t\t'(see the Supabase provider docs), then restart. Browser sign-in is unaffected.'\n\t};\n}\n\nconst COMPUTE_PING_TIMEOUT_MS = 8000;\n\n/**\n * Ping the global default compute server's liveness root (`GET /` — the\n * rhino.compute proxy has no `/healthcheck` route). We probe the default\n * specifically because that's the server every solve falls back to;\n * a degraded default breaks the baseline for all orgs. Org-private and\n * non-default platform servers are out of scope here — they have their own\n * per-server status probe at /api/admin/compute/status.\n */\nasync function computeReachabilityCheck(locals: App.Locals): Promise<HealthCheck> {\n\tconst base = { id: 'compute-reachable', label: 'Default compute server' };\n\n\tlet config;\n\ttry {\n\t\tconfig = await getComputeServerConfigStore().getConfig(locals.ctx!);\n\t} catch (err) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'error',\n\t\t\tsummary: `Could not read compute config: ${err instanceof Error ? err.message : String(err)}`\n\t\t};\n\t}\n\n\tconst server = config.defaultServerId\n\t\t? findServerById(config, config.defaultServerId)\n\t\t: undefined;\n\tif (!server) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary: 'No default compute server is configured — nothing to reach.',\n\t\t\tremediation: 'Add a server and set it as default in /admin/compute.'\n\t\t};\n\t}\n\n\tconst apiKey = server.hasApiKey\n\t\t? await getComputeServerConfigStore().getServerApiKey(locals.ctx!, server.id)\n\t\t: undefined;\n\tconst { stats, misconfigured } = openServerStats(server.serverUrl, apiKey ?? undefined);\n\tif (!stats) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'error',\n\t\t\tsummary: `\"${server.label}\" can't be used: ${misconfigured}`,\n\t\t\tremediation: 'Fix the server URL or API key in /admin/compute.'\n\t\t};\n\t}\n\ttry {\n\t\tconst online = await stats.isServerOnline(COMPUTE_PING_TIMEOUT_MS);\n\t\tif (online) {\n\t\t\treturn { ...base, status: 'ok', summary: `\"${server.label}\" is reachable.` };\n\t\t}\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'degraded',\n\t\t\tsummary: `\"${server.label}\" did not respond within ${COMPUTE_PING_TIMEOUT_MS / 1000}s or answered with an error.`,\n\t\t\tremediation: `Confirm the Rhino.Compute host is running, ${server.serverUrl} is correct, and the API key in /admin/compute is valid.`\n\t\t};\n\t} finally {\n\t\tawait stats.dispose();\n\t}\n}\n\n/**\n * Write + delete a temp file under DATA_PATH to prove the local provider can\n * still persist. The JSON stores read-modify-write without a fallback, so a\n * full disk or a permission change (e.g. ownership drift after a restore)\n * corrupts data on the next write — catch it here while it's still just a\n * failed health check.\n */\nasync function dataPathWritableCheck(): Promise<HealthCheck> {\n\tconst base = { id: 'data-path-writable', label: 'Data path writable' };\n\n\t// Only meaningful when a local store is actually backing the deployment.\n\tif (!(providers.data.computeServer instanceof LocalComputeServerStore)) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'not_applicable',\n\t\t\tsummary: 'The active data provider does not persist to a local DATA_PATH.'\n\t\t};\n\t}\n\n\tconst dataPath = privateEnv.DATA_PATH;\n\tif (!dataPath) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'error',\n\t\t\tsummary: 'DATA_PATH is unset but the local provider is active.',\n\t\t\tremediation: 'Set DATA_PATH in .env and restart.'\n\t\t};\n\t}\n\n\tconst absolute = resolve(dataPath);\n\tconst probe = join(absolute, `.health-probe-${randomUUID()}`);\n\ttry {\n\t\tawait mkdir(absolute, { recursive: true });\n\t\tawait writeFile(probe, 'ok');\n\t\tawait unlink(probe);\n\t\treturn { ...base, status: 'ok', summary: `DATA_PATH (${dataPath}) is writable.` };\n\t} catch (err) {\n\t\treturn {\n\t\t\t...base,\n\t\t\tstatus: 'degraded',\n\t\t\tsummary: `DATA_PATH (${dataPath}) is not writable: ${err instanceof Error ? err.message : String(err)}.`,\n\t\t\tremediation:\n\t\t\t\t'Check free disk space and that the directory is owned by the user running the app ' +\n\t\t\t\t'(`df -h`, `ls -la`).'\n\t\t};\n\t}\n}\n\n/**\n * Deployment-config rules run against the live process env, which is what\n * adapter-node itself read at boot — not a re-parse of `.env`, so a var\n * overridden by the service manager is judged as it actually applies.\n *\n * A `fail` maps to `error` rather than `degraded`: these are the same verdicts\n * that exit `selva doctor` non-zero, and the panel should not soften them.\n */\nfunction deploymentConfigChecks(): HealthCheck[] {\n\treturn checkDeploymentConfig(privateEnv).map((finding: ConfigFinding) => ({\n\t\tid: finding.id,\n\t\tlabel: finding.label,\n\t\tstatus: finding.verdict === 'fail' ? 'error' : finding.verdict === 'warn' ? 'degraded' : 'ok',\n\t\tsummary: finding.summary,\n\t\tremediation: finding.remediation\n\t}));\n}\n\nexport const GET: RequestHandler = async ({ locals }) => {\n\trequirePermission(locals, 'instance_admin');\n\n\tconst checks: HealthCheck[] = [];\n\n\tconst store = providers.data.computeServer;\n\tif (typeof store.verifySecrets === 'function') {\n\t\ttry {\n\t\t\tchecks.push(atRestSecretsCheck(await store.verifySecrets()));\n\t\t} catch (err) {\n\t\t\tchecks.push({\n\t\t\t\tid: 'at-rest-secrets',\n\t\t\t\tlabel: 'Compute server secrets',\n\t\t\t\tstatus: 'error',\n\t\t\t\tsummary: `Verification threw: ${err instanceof Error ? err.message : String(err)}`,\n\t\t\t\tremediation: 'Check server logs (`pm2 logs selva-compute`) for the underlying error.'\n\t\t\t});\n\t\t}\n\t} else {\n\t\tchecks.push(atRestSecretsCheck(null));\n\t}\n\n\t// Live app↔DB schema handshake (audit O3) — unlike boot health this re-runs\n\t// on every request, so an operator sees green right after `db push` without\n\t// restarting first (the boot report itself stays stale by design).\n\tconst data = providers.data;\n\tif (typeof data.verifySchemaVersion === 'function') {\n\t\tchecks.push(schemaVersionCheck(await data.verifySchemaVersion()));\n\t} else {\n\t\tchecks.push(schemaVersionCheck(null));\n\t}\n\n\t// Reachability + writability run in parallel — independent of each other\n\t// and of the at-rest check above. Each self-contains its error handling.\n\tchecks.push(\n\t\t...(await Promise.all([\n\t\t\tcomputeReachabilityCheck(locals),\n\t\t\tdataPathWritableCheck(),\n\t\t\tdelegatedSessionCheck()\n\t\t]))\n\t);\n\n\tchecks.push(...deploymentConfigChecks());\n\n\t// Worst status wins for the overall verdict. `not_applicable` never\n\t// degrades the overall result.\n\tconst rank: Record<CheckStatus, number> = {\n\t\tok: 0,\n\t\tnot_applicable: 0,\n\t\tdegraded: 2,\n\t\terror: 3\n\t};\n\tconst overall = checks.reduce<CheckStatus>(\n\t\t(worst, c) => (rank[c.status] > rank[worst] ? c.status : worst),\n\t\t'ok'\n\t);\n\n\treturn json({ overall, checkedAt: new Date().toISOString(), checks });\n};\n"],"mappings":";;;;;;;;;;;;AAmEA,SAAS,mBAAmB,QAAsD;CACjF,MAAM,OAAO;EAAE,IAAI;EAAmB,OAAO;CAAyB;CAEtE,IAAI,WAAW,MACd,OAAO;EACN,GAAG;EACH,QAAQ;EACR,SACC;CACF;CAGD,IAAI,OAAO,IACV,OAAO;EACN,GAAG;EACH,QAAQ;EACR,SAAS;CACV;CAGD,MAAM,SAAS,OAAO,SACpB,KAAK,MAAM,IAAI,EAAE,YAAY,KAAK,EAAE,SAAS,EAAE,QAAQ,KAAK,EAAE,UAAU,GAAG,EAAE,CAAC,CAC9E,KAAK,IAAI;CACX,MAAM,YAAY,OAAO;CACzB,MAAM,cAAc,OAAO,SAAS,MAAM,MAAM,EAAE,WAAW,kBAAkB;CAC/E,OAAO;EACN,GAAG;EACH,QAAQ;EACR,SAAS,GAAG,OAAO,SAAS,OAAO,8CAA8C,OAAO;EACxF,aAAa,YACV,8FACA,cACC,sKAEA;CAGL;AACD;AAEA,SAAS,mBAAmB,QAAiD;C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AAK;EAAE;EAAS,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;EAAG;CAAO,CAAC;AACrE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { K as actorFrom, l as getErrorReporter, u as getEventSink } from "../../../../../../chunks/providers.server.js";
|
|
2
2
|
import { n as env } from "../../../../../../chunks/previous-key.js";
|
|
3
3
|
import { C as requirePermission } from "../../../../../../chunks/access.js";
|
|
4
4
|
import { n as renderThrown } from "../../../../../../chunks/definitions.js";
|
|
@@ -34,26 +34,36 @@ function buildLauncher(runnerScript, logPath, prelude = []) {
|
|
|
34
34
|
const echoes = prelude.map((line) => `echo ${shellQuote(line)}`).join("\n");
|
|
35
35
|
return `
|
|
36
36
|
LOGFILE=${shellQuote(logPath)}
|
|
37
|
-
RUNNER=/tmp/selva-update-runner.sh
|
|
38
37
|
mkdir -p "$(dirname "$LOGFILE")"
|
|
39
38
|
: > "$LOGFILE"
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
# mktemp, never a fixed name: /tmp is shared, and a file another account left at
|
|
41
|
+
# a known path survives the write below and would run as the app user.
|
|
42
|
+
RUNNER=$(mktemp "\${TMPDIR:-/tmp}/selva-update-runner.XXXXXXXX") || {
|
|
43
|
+
echo "[ERROR] Could not create the update runner in \${TMPDIR:-/tmp}"
|
|
44
|
+
exit 1
|
|
45
|
+
}
|
|
46
|
+
cat > "$RUNNER" <<'__SELVA_RUNNER_EOF__' || { echo "[ERROR] Could not write the update runner"; exit 1; }
|
|
47
|
+
rm -f "$0"
|
|
48
|
+
for _ in $(seq 1 50); do
|
|
49
|
+
kill -0 "$SELVA_RUNNER_SPAWNER" 2>/dev/null || break
|
|
50
|
+
sleep 0.1
|
|
51
|
+
done
|
|
42
52
|
${runnerScript}
|
|
43
53
|
__SELVA_RUNNER_EOF__
|
|
44
|
-
chmod +x "$RUNNER"
|
|
45
54
|
|
|
46
55
|
trap '' PIPE
|
|
47
56
|
exec > >(tee --output-error=warn-nopipe -a "$LOGFILE" 2>/dev/null) 2>&1
|
|
48
57
|
${echoes}
|
|
49
58
|
|
|
50
59
|
# Daemonize the runner so PM2's tree-kill of selva-compute can't reach it.
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
# When the runner calls pm2 stop, pm2 lists the app's descendants and SIGKILLs
|
|
61
|
+
# whatever on that list outlives its kill timeout. A runner still parented to this
|
|
62
|
+
# launcher is on the list: it died mid-update and left the app stopped whenever the
|
|
63
|
+
# registry answered inside the pause below. So it is orphaned before it runs a
|
|
64
|
+
# line: the subshell forks it and exits, and the runner waits for that exit.
|
|
65
|
+
# setsid gives it its own session; its stdio is detached from selva-compute's pipes.
|
|
66
|
+
RUNNER_PID=$( (SELVA_RUNNER_SPAWNER=$BASHPID setsid bash "$RUNNER" </dev/null >>"$LOGFILE" 2>&1 & echo $!) )
|
|
57
67
|
echo "[INFO] Update runner started (PID $RUNNER_PID, log: $LOGFILE)"
|
|
58
68
|
|
|
59
69
|
# Small pause so the runner has time to print its first line before SSE
|
|
@@ -228,6 +238,28 @@ if [ -n "$REQUIRED_NODE" ] && [ -n "$RUNNING_NODE" ]; then
|
|
|
228
238
|
fi
|
|
229
239
|
fi
|
|
230
240
|
|
|
241
|
+
# ---------------------------------------------------------------------------
|
|
242
|
+
# 1c. Data format pre-flight — BEFORE any downtime.
|
|
243
|
+
# ---------------------------------------------------------------------------
|
|
244
|
+
# A release with a lower data format than the installed one cannot read what
|
|
245
|
+
# this deployment has already stored (dataFormat.server.ts). It would boot, fail
|
|
246
|
+
# its health check and roll back: two outages for nothing. Installed by hand it
|
|
247
|
+
# leaves stored Compute API keys unreadable. A release that declares no format
|
|
248
|
+
# is format 1. Skipped when the registry gave no answer: the target is unknown.
|
|
249
|
+
INSTALLED_FORMAT=$(node -p "require('./node_modules/@selvajs/selva/package.json').selva?.dataFormat ?? 1" 2>/dev/null)
|
|
250
|
+
case "$INSTALLED_FORMAT" in ''|*[!0-9]*) INSTALLED_FORMAT=1 ;; esac
|
|
251
|
+
if [ -n "$LATEST" ] && TARGET_FORMAT=$(npm view "@selvajs/selva@$TAG" selva.dataFormat --silent 2>/dev/null); then
|
|
252
|
+
TARGET_FORMAT=$(echo "$TARGET_FORMAT" | tr -d '"' | tr -d "'" | tr -d '[:space:]')
|
|
253
|
+
case "$TARGET_FORMAT" in ''|*[!0-9]*) TARGET_FORMAT=1 ;; esac
|
|
254
|
+
if [ "$TARGET_FORMAT" -lt "$INSTALLED_FORMAT" ]; then
|
|
255
|
+
echo "[FATAL] DATA_FORMAT: @selvajs/selva@$LATEST reads data format $TARGET_FORMAT, but this deployment is on format $INSTALLED_FORMAT."
|
|
256
|
+
echo "[FATAL] It could not read what the installed version has stored, such as Compute API keys."
|
|
257
|
+
echo "[FATAL] Aborting WITHOUT stopping the app — it is still running."
|
|
258
|
+
echo "[FATAL] To go back anyway: docs/self-hosting/deployment/admin.md, 'Going back to an older release'."
|
|
259
|
+
exit 10
|
|
260
|
+
fi
|
|
261
|
+
fi
|
|
262
|
+
|
|
231
263
|
# ---------------------------------------------------------------------------
|
|
232
264
|
# 2. Resync PM2 daemon if its in-memory version drifted from the CLI on disk.
|
|
233
265
|
# ---------------------------------------------------------------------------
|
|
@@ -376,14 +408,17 @@ PORT=$(grep "^PORT=" .env 2>/dev/null \\
|
|
|
376
408
|
PORT=\${PORT:-3000}
|
|
377
409
|
|
|
378
410
|
echo "[STEP] Health-probing the new process on port $PORT"
|
|
411
|
+
# mktemp for the same reason as the runner itself: /tmp is shared. Without one
|
|
412
|
+
# the probe still runs; only the rollback loses the body it names the cause from.
|
|
413
|
+
HEALTH_BODY=$(mktemp "\${TMPDIR:-/tmp}/selva-health.XXXXXXXX") || HEALTH_BODY=
|
|
379
414
|
HEALTHY=0
|
|
380
415
|
for i in $(seq 1 15); do
|
|
381
416
|
sleep 2
|
|
382
|
-
CODE=$(curl -sS -o /
|
|
417
|
+
CODE=$(curl -sS -o "\${HEALTH_BODY:-/dev/null}" -w "%{http_code}" --max-time 5 "http://localhost:$PORT/api/health" 2>/dev/null || echo "000")
|
|
383
418
|
if [ "$CODE" = "200" ]; then
|
|
384
419
|
HEALTHY=1
|
|
385
420
|
echo "[INFO] Health probe passed after \${i} attempt(s)"
|
|
386
|
-
rm -f
|
|
421
|
+
[ -n "$HEALTH_BODY" ] && rm -f "$HEALTH_BODY"
|
|
387
422
|
break
|
|
388
423
|
fi
|
|
389
424
|
echo "[INFO] Probe attempt $i/15: HTTP $CODE — retrying"
|
|
@@ -398,8 +433,8 @@ fi
|
|
|
398
433
|
# 7. Rollback path.
|
|
399
434
|
# ---------------------------------------------------------------------------
|
|
400
435
|
echo "[FATAL] New process failed health check after 30s"
|
|
401
|
-
if [ -
|
|
402
|
-
BODY=$(cat
|
|
436
|
+
if [ -s "$HEALTH_BODY" ]; then
|
|
437
|
+
BODY=$(cat "$HEALTH_BODY")
|
|
403
438
|
echo "[FATAL] Last response body:"
|
|
404
439
|
echo "$BODY"
|
|
405
440
|
|
|
@@ -442,7 +477,7 @@ if [ -f /tmp/selva-health.$$ ]; then
|
|
|
442
477
|
echo "[FATAL] \\\`pm2 logs selva-compute\\\` for what the new version failed on."
|
|
443
478
|
fi
|
|
444
479
|
|
|
445
|
-
rm -f
|
|
480
|
+
rm -f "$HEALTH_BODY"
|
|
446
481
|
fi
|
|
447
482
|
|
|
448
483
|
if [ -z "$BEFORE" ]; then
|
|
@@ -451,6 +486,15 @@ if [ -z "$BEFORE" ]; then
|
|
|
451
486
|
exit 3
|
|
452
487
|
fi
|
|
453
488
|
|
|
489
|
+
# The failed version has already booted, so it may have rewritten stored data in
|
|
490
|
+
# a format $BEFORE cannot read. Rolling back is still the better outcome; say so.
|
|
491
|
+
AFTER_FORMAT=$(node -p "require('./node_modules/@selvajs/selva/package.json').selva?.dataFormat ?? 1" 2>/dev/null)
|
|
492
|
+
case "$AFTER_FORMAT" in ''|*[!0-9]*) AFTER_FORMAT=1 ;; esac
|
|
493
|
+
if [ "$AFTER_FORMAT" -gt "$INSTALLED_FORMAT" ]; then
|
|
494
|
+
echo "[WARN] DATA_FORMAT_ROLLBACK: the failed version stores data format $AFTER_FORMAT; $BEFORE reads format $INSTALLED_FORMAT."
|
|
495
|
+
echo "[WARN] If Compute API keys fail to load after this rollback, re-enter them at /admin/compute."
|
|
496
|
+
fi
|
|
497
|
+
|
|
454
498
|
echo "[STEP] Rolling back @selvajs/selva to $BEFORE"
|
|
455
499
|
"$PM2" stop selva-compute >/dev/null 2>&1 || true
|
|
456
500
|
wait_until_stopped >/dev/null 2>&1
|