@selvajs/selva 4.20.1-beta.2 → 4.20.1-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/build/adapter-node.js +1 -1
  2. package/build/client/_app/immutable/chunks/{D-SwRD80.js → D-uUm_OB.js} +43 -43
  3. package/build/client/_app/immutable/chunks/D-uUm_OB.js.br +0 -0
  4. package/build/client/_app/immutable/chunks/{D-SwRD80.js.gz → D-uUm_OB.js.gz} +0 -0
  5. package/build/client/_app/immutable/chunks/D84F7w9g.js +1 -0
  6. package/build/client/_app/immutable/chunks/D84F7w9g.js.br +1 -0
  7. package/build/client/_app/immutable/chunks/D84F7w9g.js.gz +0 -0
  8. package/build/client/_app/immutable/entry/{app.hg2qyLJU.js → app.BpT6WkO1.js} +2 -2
  9. package/build/client/_app/immutable/entry/app.BpT6WkO1.js.br +0 -0
  10. package/build/client/_app/immutable/entry/app.BpT6WkO1.js.gz +0 -0
  11. package/build/client/_app/immutable/nodes/21.BkNlRItr.js +1 -0
  12. package/build/client/_app/immutable/nodes/21.BkNlRItr.js.br +0 -0
  13. package/build/client/_app/immutable/nodes/21.BkNlRItr.js.gz +0 -0
  14. package/build/client/_app/version.json +1 -1
  15. package/build/client/_app/version.json.br +0 -0
  16. package/build/client/_app/version.json.gz +0 -0
  17. package/build/runtime-meta.json +1 -1
  18. package/build/server/.vite/manifest.json +9 -2
  19. package/build/server/chunks/access.js +0 -3
  20. package/build/server/chunks/access.js.map +1 -1
  21. package/build/server/chunks/definitions.js +178 -1
  22. package/build/server/chunks/definitions.js.map +1 -1
  23. package/build/server/chunks/handlers.js +4 -5
  24. package/build/server/chunks/handlers.js.map +1 -1
  25. package/build/server/chunks/instance.js +3 -3
  26. package/build/server/chunks/internal.js +1 -1
  27. package/build/server/chunks/package.js +1 -1
  28. package/build/server/chunks/package.js.map +1 -1
  29. package/build/server/chunks/providers.server.js +111 -202
  30. package/build/server/chunks/providers.server.js.map +1 -1
  31. package/build/server/chunks/registry.js +3 -3
  32. package/build/server/chunks/registry.js.map +1 -1
  33. package/build/server/chunks/resolve.server.js +1 -1
  34. package/build/server/chunks/server-config-write.js +13 -1
  35. package/build/server/chunks/server-config-write.js.map +1 -1
  36. package/build/server/entries/endpoints/api/admin/compute/_server.ts.js +30 -48
  37. package/build/server/entries/endpoints/api/admin/compute/_server.ts.js.map +1 -1
  38. package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js +3 -2
  39. package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js.map +1 -1
  40. package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js +3 -2
  41. package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js.map +1 -1
  42. package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js +3 -2
  43. package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js.map +1 -1
  44. package/build/server/entries/endpoints/api/admin/users/_server.ts.js +6 -2
  45. package/build/server/entries/endpoints/api/admin/users/_server.ts.js.map +1 -1
  46. package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js +8 -8
  47. package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js.map +1 -1
  48. package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +1 -1
  49. package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +1 -1
  50. package/build/server/entries/endpoints/docs/api/openapi.yaml/_server.ts.js +1 -1
  51. package/build/server/entries/hooks.server.js +34 -10
  52. package/build/server/entries/hooks.server.js.map +1 -1
  53. package/build/server/entries/pages/library/_guid_/_page.server.ts.js +16 -3
  54. package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
  55. package/build/server/entries/pages/library/_guid_/_page.svelte.js +132 -89
  56. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  57. package/build/server/manifest-full.js +1 -1
  58. package/build/server/manifest.js +1 -1
  59. package/build/server/nodes/21.js +1 -1
  60. package/build/server/server.js +1 -1
  61. package/package.json +11 -11
  62. package/build/client/_app/immutable/chunks/D-SwRD80.js.br +0 -0
  63. package/build/client/_app/immutable/chunks/Dvq2vJj6.js +0 -1
  64. package/build/client/_app/immutable/chunks/Dvq2vJj6.js.br +0 -1
  65. package/build/client/_app/immutable/chunks/Dvq2vJj6.js.gz +0 -0
  66. package/build/client/_app/immutable/entry/app.hg2qyLJU.js.br +0 -0
  67. package/build/client/_app/immutable/entry/app.hg2qyLJU.js.gz +0 -0
  68. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js +0 -1
  69. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js.br +0 -1
  70. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js.gz +0 -0
@@ -452,7 +452,7 @@ var V1_ENDPOINTS = [
452
452
  method: "GET",
453
453
  path: "/orgs/{orgId}/invites",
454
454
  scope: "read",
455
- summary: "List pending invites.",
455
+ summary: "List pending invites. Browser session only: an API key gets 403.",
456
456
  response: "collection",
457
457
  errors: [403]
458
458
  },
@@ -460,7 +460,7 @@ var V1_ENDPOINTS = [
460
460
  method: "POST",
461
461
  path: "/orgs/{orgId}/invites",
462
462
  scope: "write",
463
- summary: "Invite someone to the org. The accept URL is returned once.",
463
+ summary: "Invite someone to the org. The accept URL is returned once. Browser session only: an API key gets 403.",
464
464
  response: "object",
465
465
  status: 201,
466
466
  requestBody: CreateInviteBodySchema,
@@ -482,7 +482,7 @@ var V1_ENDPOINTS = [
482
482
  method: "POST",
483
483
  path: "/orgs/{orgId}/invites/{id}/resend",
484
484
  scope: "write",
485
- summary: "Re-send an invite. Issues a replacement and revokes the original, so the previous link stops working.",
485
+ summary: "Re-send an invite. Issues a replacement and revokes the original, so the previous link stops working. Browser session only: an API key gets 403.",
486
486
  response: "object",
487
487
  status: 201,
488
488
  errors: [
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","names":[],"sources":["../../../src/lib/server/api/v1/registry.ts"],"sourcesContent":["/**\n * The v1 contract as data: one entry per method+path, naming its body validator,\n * response shape, and whether it's public or internal.\n *\n * Both the OpenAPI generator and the conformance test read this file. The test\n * walks `routes/api/v1/**` against this table and fails if either side has an\n * entry the other doesn't — a route with no registry entry is undocumented, a\n * registry entry with no route is a spec promising something that 404s.\n *\n * Request schemas are Zod values imported from `@selvajs/server/api`, not\n * transcribed, so a renamed field changes the spec on the next generate\n * instead of silently disagreeing with the validator.\n */\n\nimport {\n\ttype Endpoint,\n\ttype HttpMethod,\n\tSolveBodySchema,\n\tUpdateDefinitionBodySchema,\n\tPublishVersionBodySchema,\n\tCreateShareLinkBodySchema,\n\tCreateProjectBodySchema,\n\tUpdateProjectBodySchema,\n\tAddProjectMemberBodySchema,\n\tUpdateProjectMemberBodySchema,\n\tCreateInviteBodySchema,\n\tUpdateOrgMemberBodySchema,\n\tOrgComputePatchBodySchema,\n\tCreateApiTokenBodySchema\n} from '@selvajs/server/api';\n\nexport type { Endpoint, HttpMethod };\n\nconst solveErrors = [400, 401, 404, 429, 503];\n\nexport const V1_ENDPOINTS: Endpoint[] = [\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/openapi.json',\n\t\tscope: 'read',\n\t\tsummary: 'This document, as JSON.',\n\t\tresponse: 'object'\n\t},\n\n\t// ==========================================================================\n\t// Me\n\t// ==========================================================================\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/me',\n\t\tscope: 'read',\n\t\tsummary:\n\t\t\t'The calling identity, its acting org, its effective permissions, and for a token its id, scopes and expiry.',\n\t\tresponse: 'object',\n\t\treturns:\n\t\t\t'`apiToken: { id, scopes, expiresAt }` is present only when the caller is an API token. `capabilities.createProjects` says whether `POST /projects` would accept this caller, narrowed to the key; `orgPermissions` is the owner’s and is not.'\n\t},\n\t// Every key may call it, whatever its scopes; `read` is the action every key holds.\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/me/token',\n\t\tscope: 'read',\n\t\tsummary:\n\t\t\t'Revoke the API token that sent this request. A key can revoke itself and nothing else; a browser session gets 400.',\n\t\tresponse: 'empty',\n\t\terrors: [400, 503]\n\t},\n\t{\n\t\tmethod: 'PUT',\n\t\tpath: '/me/starred/{guid}',\n\t\tscope: 'write',\n\t\tsummary: 'Star a definition. Idempotent.',\n\t\tresponse: 'empty',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/me/starred/{guid}',\n\t\tscope: 'write',\n\t\tsummary: 'Unstar a definition. Idempotent.',\n\t\tresponse: 'empty'\n\t},\n\n\t// ==========================================================================\n\t// Definitions\n\t// ==========================================================================\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions',\n\t\tscope: 'read',\n\t\tsummary: 'List definitions the caller can see.',\n\t\tresponse: 'collection',\n\t\treturns:\n\t\t\t'Each item has `sourceDocumentId`: the Grasshopper document GUID the definition was last uploaded from, or null.',\n\t\tquery: [\n\t\t\t{ name: 'projectId', description: 'Restrict to one project.' },\n\t\t\t{ name: 'status', description: 'One of `draft`, `published`, `archived`.' },\n\t\t\t{\n\t\t\t\tname: 'documentId',\n\t\t\t\tdescription:\n\t\t\t\t\t'A Grasshopper document GUID. Returns only definitions last uploaded from that document which the caller can upload a new version of. Not a GUID: 400.'\n\t\t\t}\n\t\t],\n\t\terrors: [400]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions',\n\t\tscope: 'upload',\n\t\tidempotent: true,\n\t\tsummary: 'Create a definition from a Grasshopper file.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\tmultipart: [\n\t\t\t{ field: 'file', required: true, description: 'The `.gh` or `.ghx` file.' },\n\t\t\t{ field: 'projectId', required: true, description: 'Owning project.' },\n\t\t\t{ field: 'displayName', required: true, description: 'Human-readable name.' },\n\t\t\t{ field: 'description', required: false, description: 'Long description.' },\n\t\t\t{ field: 'category', required: false, description: 'Grouping label.' },\n\t\t\t{ field: 'tags', required: false, description: 'Comma-separated tags.' },\n\t\t\t{ field: 'image', required: false, description: 'Cover image.' },\n\t\t\t{ field: 'computeServerId', required: false, description: 'Pin to a compute server.' }\n\t\t],\n\t\terrors: [400, 403, 422, 503]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}',\n\t\tscope: 'read',\n\t\tsummary: 'Definition record plus its live and draft version summaries.',\n\t\tresponse: 'object',\n\t\treturns:\n\t\t\t'`canEdit` is true when the caller can upload a version and make one live; for an API token that includes its scopes. `sourceDocumentId` is the Grasshopper document GUID it was last uploaded from, or null.',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/definitions/{guid}',\n\t\tscope: 'write',\n\t\tsummary: 'Update definition metadata.',\n\t\tresponse: 'empty',\n\t\trequestBody: UpdateDefinitionBodySchema,\n\t\terrors: [400, 404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/definitions/{guid}',\n\t\tscope: 'write',\n\t\tsummary: 'Soft-delete a definition.',\n\t\tresponse: 'empty',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/solve',\n\t\tscope: 'solve',\n\t\tidempotent: true,\n\t\tsummary: 'Solve a definition. The primary action of the API.',\n\t\tresponse: 'object',\n\t\trequestBody: SolveBodySchema,\n\t\terrors: solveErrors\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/schema',\n\t\tscope: 'read',\n\t\tsummary: \"The live version's UI schema. 404 when nothing is published.\",\n\t\tresponse: 'object',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/versions',\n\t\tscope: 'read',\n\t\tsummary: 'List versions, newest first.',\n\t\tresponse: 'collection',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/versions',\n\t\tscope: 'upload',\n\t\tidempotent: true,\n\t\tsummary: 'Upload a new version.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\tmultipart: [\n\t\t\t{ field: 'file', required: true, description: 'The `.gh` or `.ghx` file.' },\n\t\t\t{ field: 'changeNote', required: false, description: 'Truncated to 1000 characters.' }\n\t\t],\n\t\terrors: [400, 404, 422, 503]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/versions/{versionId}',\n\t\tscope: 'read',\n\t\tsummary: 'One version, without its cached schema.',\n\t\tresponse: 'object',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/definitions/{guid}/versions/{versionId}',\n\t\tscope: 'write',\n\t\tsummary: 'Delete a version. 409 when it is the live or draft pointer.',\n\t\tresponse: 'empty',\n\t\terrors: [404, 409]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/versions/{versionId}/schema',\n\t\tscope: 'read',\n\t\tsummary: \"That version's cached UI schema. No compute round-trip.\",\n\t\tresponse: 'object',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/publish',\n\t\tscope: 'upload',\n\t\tsummary: 'Promote a version to live.',\n\t\tresponse: 'object',\n\t\trequestBody: PublishVersionBodySchema,\n\t\terrors: [400, 404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/image',\n\t\tscope: 'write',\n\t\tsummary: 'Upload a cover image.',\n\t\tresponse: 'object',\n\t\tmultipart: [{ field: 'image', required: true, description: 'PNG, JPEG, WebP or GIF.' }],\n\t\terrors: [400, 404]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/share-links',\n\t\tscope: 'read',\n\t\tsummary: 'List share links. 404 when sharing is disabled on the instance.',\n\t\tresponse: 'collection',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/share-links',\n\t\tscope: 'write',\n\t\tidempotent: true,\n\t\tsummary: 'Create a share link. The raw token is returned once and never again.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: CreateShareLinkBodySchema,\n\t\terrors: [400, 404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/definitions/{guid}/share-links/{linkId}',\n\t\tscope: 'write',\n\t\tsummary: 'Revoke a share link.',\n\t\tresponse: 'empty',\n\t\terrors: [404]\n\t},\n\n\t// ==========================================================================\n\t// Projects\n\t// ==========================================================================\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/projects',\n\t\tscope: 'read',\n\t\tsummary: 'List projects the caller can view.',\n\t\tresponse: 'collection',\n\t\treturns:\n\t\t\t'Each item has `canCreateDefinitions`: whether `POST /definitions` would accept this project from the caller, scopes included for an API token.'\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/projects',\n\t\tscope: 'create_projects',\n\t\tidempotent: true,\n\t\tsummary:\n\t\t\t'Create a project. A key with `create_projects` but not `write` may create private projects only, with `autoJoinOnUpload` off.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: CreateProjectBodySchema,\n\t\terrors: [400, 403, 409]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/projects/{id}',\n\t\tscope: 'read',\n\t\tsummary: \"Project record plus the caller's effective role and capabilities.\",\n\t\tresponse: 'object',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/projects/{id}',\n\t\tscope: 'write',\n\t\tsummary: 'Update project settings. Owner-only.',\n\t\tresponse: 'empty',\n\t\trequestBody: UpdateProjectBodySchema,\n\t\terrors: [400, 403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/projects/{id}',\n\t\tscope: 'write',\n\t\tsummary: 'Delete a project.',\n\t\tresponse: 'empty',\n\t\terrors: [403, 404]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/projects/{id}/members',\n\t\tscope: 'read',\n\t\tsummary: 'List project members.',\n\t\tresponse: 'collection',\n\t\terrors: [403, 404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/projects/{id}/members',\n\t\tscope: 'write',\n\t\tsummary: 'Add a member. The target must already belong to the org.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: AddProjectMemberBodySchema,\n\t\terrors: [400, 403, 404]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/projects/{id}/members/{userId}',\n\t\tscope: 'write',\n\t\tsummary: 'Change a member role.',\n\t\tresponse: 'empty',\n\t\trequestBody: UpdateProjectMemberBodySchema,\n\t\terrors: [400, 403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/projects/{id}/members/{userId}',\n\t\tscope: 'write',\n\t\tsummary: 'Remove a member. Idempotent.',\n\t\tresponse: 'empty',\n\t\tquery: [\n\t\t\t{\n\t\t\t\tname: 'confirm',\n\t\t\t\tdescription: 'Set to `true` to remove a co-owner; without it the call returns 409.'\n\t\t\t}\n\t\t],\n\t\terrors: [403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/projects/{id}/reclaim',\n\t\tscope: 'write',\n\t\tsummary: 'Claim ownership of an unowned project.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\terrors: [403, 404, 409]\n\t},\n\n\t// ==========================================================================\n\t// Orgs\n\t// ==========================================================================\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}',\n\t\tscope: 'read',\n\t\tsummary: \"Org record. The org must be the caller's acting org.\",\n\t\tresponse: 'object',\n\t\terrors: [403, 404]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}/members',\n\t\tscope: 'read',\n\t\tsummary: 'List org members.',\n\t\tresponse: 'collection',\n\t\terrors: [403]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/orgs/{orgId}/members/{userId}',\n\t\tscope: 'write',\n\t\tsummary: 'Change an org role or permission set. The sole owner cannot be demoted.',\n\t\tresponse: 'empty',\n\t\trequestBody: UpdateOrgMemberBodySchema,\n\t\terrors: [400, 403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/orgs/{orgId}/members/{userId}',\n\t\tscope: 'write',\n\t\tsummary: 'Remove an org member. The sole owner cannot be removed.',\n\t\tresponse: 'empty',\n\t\terrors: [403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}/invites',\n\t\tscope: 'read',\n\t\tsummary: 'List pending invites.',\n\t\tresponse: 'collection',\n\t\terrors: [403]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/orgs/{orgId}/invites',\n\t\tscope: 'write',\n\t\tsummary: 'Invite someone to the org. The accept URL is returned once.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: CreateInviteBodySchema,\n\t\terrors: [400, 403, 409]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/orgs/{orgId}/invites/{id}',\n\t\tscope: 'write',\n\t\tsummary: 'Revoke an invite.',\n\t\tresponse: 'empty',\n\t\terrors: [403, 404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/orgs/{orgId}/invites/{id}/resend',\n\t\tscope: 'write',\n\t\tsummary:\n\t\t\t'Re-send an invite. Issues a replacement and revokes the original, so the previous link stops working.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\terrors: [403, 404, 409]\n\t},\n\t// Internal and session-only: a key can never manage keys.\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}/tokens',\n\t\tscope: 'read',\n\t\tsummary: 'Your API tokens in this org, revoked and expired included.',\n\t\tinternal: true,\n\t\tresponse: 'collection',\n\t\tquery: [\n\t\t\t{ name: 'all', description: \"`true` for every member's tokens. Needs `manage_org_members`.\" }\n\t\t],\n\t\terrors: [403, 503]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/orgs/{orgId}/tokens',\n\t\tscope: 'write',\n\t\tsummary: 'Create an API token acting as you. The raw key is returned once, as `secret`.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: CreateApiTokenBodySchema,\n\t\terrors: [400, 403, 503]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/orgs/{orgId}/tokens/{tokenId}',\n\t\tscope: 'write',\n\t\tsummary: 'Revoke an API token: your own, or any in the org with `manage_org_members`.',\n\t\tinternal: true,\n\t\tresponse: 'empty',\n\t\terrors: [403, 404, 503]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}/compute',\n\t\tscope: 'read',\n\t\tsummary: 'Org compute-server overrides and the shared catalog.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\terrors: [403]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/orgs/{orgId}/compute',\n\t\tscope: 'write',\n\t\tsummary: 'Replace the org compute-server overrides.',\n\t\tinternal: true,\n\t\tresponse: 'empty',\n\t\trequestBody: OrgComputePatchBodySchema,\n\t\terrors: [400, 403]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/orgs/{orgId}/assets/{kind}',\n\t\tscope: 'write',\n\t\tsummary: 'Upload an org branding asset.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\tmultipart: [{ field: 'image', required: true, description: 'PNG, JPEG, WebP, GIF or SVG.' }],\n\t\terrors: [400, 403, 404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/orgs/{orgId}/assets/{kind}',\n\t\tscope: 'write',\n\t\tsummary: 'Remove an org branding asset.',\n\t\tinternal: true,\n\t\tresponse: 'empty',\n\t\terrors: [403, 404]\n\t},\n\n\t// ==========================================================================\n\t// Compute\n\t// ==========================================================================\n\t//\n\t// Internal: accepts a remote `definitionUrl` and the anonymous share-token\n\t// flow, neither part of the public contract. Public callers solve through\n\t// `/definitions/{guid}/solve`.\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/compute',\n\t\tscope: 'solve',\n\t\tsummary: 'Generic solve, including remote definition URLs and share-token access.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\terrors: solveErrors\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/compute/schema',\n\t\tscope: 'upload',\n\t\tsummary: 'Extract UI schemas from an uploaded file before it becomes a definition.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\tmultipart: [{ field: 'file', required: true, description: 'The `.gh` or `.ghx` file.' }],\n\t\tquery: [\n\t\t\t{ name: 'projectId', description: 'Project the file will belong to.' },\n\t\t\t{ name: 'computeServerId', description: 'Pin to a compute server.' }\n\t\t],\n\t\terrors: [400, 403, 422, 503]\n\t},\n\n\t// ==========================================================================\n\t// Live solve events\n\t// ==========================================================================\n\t//\n\t// Internal: the browser's live channel and the plugin's callback into it. Both\n\t// are shaped by the Selva plugin and web app, not by the public contract.\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/solve-events',\n\t\tscope: 'read',\n\t\tsummary: \"The tab's live event stream (SSE). Solves that name its `streamId` report here.\",\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\tquery: [{ name: 'streamId', description: 'Minted by the tab, 16-64 URL-safe characters.' }],\n\t\terrors: [400, 401, 409]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/solve-events/{solveId}',\n\t\tscope: 'write',\n\t\tsummary: \"The plugin's callback from inside a Compute solve. The reply carries `abort`.\",\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\terrors: [400, 401, 410]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/solve/{solveId}/cancel',\n\t\tscope: 'solve',\n\t\tsummary: 'Ask a running solve to abort. Cooperative: it stops at the next component.',\n\t\tinternal: true,\n\t\tresponse: 'empty',\n\t\terrors: [401, 404]\n\t}\n];\n\n/** `/definitions/{guid}` → the SvelteKit directory form `definitions/[guid]`. */\nexport function toRoutePath(openApiPath: string): string {\n\treturn openApiPath.replace(/^\\//, '').replace(/\\{(\\w+)\\}/g, '[$1]');\n}\n\nexport function endpointKey(method: HttpMethod, path: string): string {\n\treturn `${method} ${path}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiCA,IAAM,cAAc;CAAC;CAAK;CAAK;CAAK;CAAK;AAAG;AAE5C,IAAa,eAA2B;CACvC;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;CACX;CAKA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SACC;EACD,UAAU;EACV,SACC;CACF;CAEA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SACC;EACD,UAAU;EACV,QAAQ,CAAC,KAAK,GAAG;CAClB;CACA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,QAAQ,CAAC,GAAG;CACb;CACA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;CACX;CAKA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,SACC;EACD,OAAO;GACN;IAAE,MAAM;IAAa,aAAa;GAA2B;GAC7D;IAAE,MAAM;IAAU,aAAa;GAA2C;GAC1E;IACC,MAAM;IACN,aACC;GACF;EACD;EACA,QAAQ,CAAC,GAAG;CACb;CACA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,YAAY;EACZ,SAAS;EACT,UAAU;EACV,QAAQ;EACR,WAAW;GACV;IAAE,OAAO;IAAQ,UAAU;IAAM,aAAa;GAA4B;GAC1E;IAAE,OAAO;IAAa,UAAU;IAAM,aAAa;GAAkB;GACrE;IAAE,OAAO;IAAe,UAAU;IAAM,aAAa;GAAuB;GAC5E;IAAE,OAAO;IAAe,UAAU;IAAO,aAAa;GAAoB;GAC1E;IAAE,OAAO;IAAY,UAAU;IAAO,aAAa;GAAkB;GACrE;IAAE,OAAO;IAAQ,UAAU;IAAO,aAAa;GAAwB;GACvE;IAAE,OAAO;IAA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AAE,MAAM;GAAa,aAAa;EAAmC,GACrE;GAAE,MAAM;GAAmB,aAAa;EAA2B,CACpE;EACA,QAAQ;GAAC;GAAK;GAAK;GAAK;EAAG;CAC5B;CAQA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,UAAU;EACV,OAAO,CAAC;GAAE,MAAM;GAAY,aAAa;EAAgD,CAAC;EAC1F,QAAQ;GAAC;GAAK;GAAK;EAAG;CACvB;CACA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,UAAU;EACV,QAAQ;GAAC;GAAK;GAAK;EAAG;CACvB;CACA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,UAAU;EACV,QAAQ,CAAC,KAAK,GAAG;CAClB;AACD"}
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../../../src/lib/server/api/v1/registry.ts"],"sourcesContent":["/**\n * The v1 contract as data: one entry per method+path, naming its body validator,\n * response shape, and whether it's public or internal.\n *\n * Both the OpenAPI generator and the conformance test read this file. The test\n * walks `routes/api/v1/**` against this table and fails if either side has an\n * entry the other doesn't — a route with no registry entry is undocumented, a\n * registry entry with no route is a spec promising something that 404s.\n *\n * Request schemas are Zod values imported from `@selvajs/server/api`, not\n * transcribed, so a renamed field changes the spec on the next generate\n * instead of silently disagreeing with the validator.\n */\n\nimport {\n\ttype Endpoint,\n\ttype HttpMethod,\n\tSolveBodySchema,\n\tUpdateDefinitionBodySchema,\n\tPublishVersionBodySchema,\n\tCreateShareLinkBodySchema,\n\tCreateProjectBodySchema,\n\tUpdateProjectBodySchema,\n\tAddProjectMemberBodySchema,\n\tUpdateProjectMemberBodySchema,\n\tCreateInviteBodySchema,\n\tUpdateOrgMemberBodySchema,\n\tOrgComputePatchBodySchema,\n\tCreateApiTokenBodySchema\n} from '@selvajs/server/api';\n\nexport type { Endpoint, HttpMethod };\n\nconst solveErrors = [400, 401, 404, 429, 503];\n\nexport const V1_ENDPOINTS: Endpoint[] = [\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/openapi.json',\n\t\tscope: 'read',\n\t\tsummary: 'This document, as JSON.',\n\t\tresponse: 'object'\n\t},\n\n\t// ==========================================================================\n\t// Me\n\t// ==========================================================================\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/me',\n\t\tscope: 'read',\n\t\tsummary:\n\t\t\t'The calling identity, its acting org, its effective permissions, and for a token its id, scopes and expiry.',\n\t\tresponse: 'object',\n\t\treturns:\n\t\t\t'`apiToken: { id, scopes, expiresAt }` is present only when the caller is an API token. `capabilities.createProjects` says whether `POST /projects` would accept this caller, narrowed to the key; `orgPermissions` is the owner’s and is not.'\n\t},\n\t// Every key may call it, whatever its scopes; `read` is the action every key holds.\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/me/token',\n\t\tscope: 'read',\n\t\tsummary:\n\t\t\t'Revoke the API token that sent this request. A key can revoke itself and nothing else; a browser session gets 400.',\n\t\tresponse: 'empty',\n\t\terrors: [400, 503]\n\t},\n\t{\n\t\tmethod: 'PUT',\n\t\tpath: '/me/starred/{guid}',\n\t\tscope: 'write',\n\t\tsummary: 'Star a definition. Idempotent.',\n\t\tresponse: 'empty',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/me/starred/{guid}',\n\t\tscope: 'write',\n\t\tsummary: 'Unstar a definition. Idempotent.',\n\t\tresponse: 'empty'\n\t},\n\n\t// ==========================================================================\n\t// Definitions\n\t// ==========================================================================\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions',\n\t\tscope: 'read',\n\t\tsummary: 'List definitions the caller can see.',\n\t\tresponse: 'collection',\n\t\treturns:\n\t\t\t'Each item has `sourceDocumentId`: the Grasshopper document GUID the definition was last uploaded from, or null.',\n\t\tquery: [\n\t\t\t{ name: 'projectId', description: 'Restrict to one project.' },\n\t\t\t{ name: 'status', description: 'One of `draft`, `published`, `archived`.' },\n\t\t\t{\n\t\t\t\tname: 'documentId',\n\t\t\t\tdescription:\n\t\t\t\t\t'A Grasshopper document GUID. Returns only definitions last uploaded from that document which the caller can upload a new version of. Not a GUID: 400.'\n\t\t\t}\n\t\t],\n\t\terrors: [400]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions',\n\t\tscope: 'upload',\n\t\tidempotent: true,\n\t\tsummary: 'Create a definition from a Grasshopper file.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\tmultipart: [\n\t\t\t{ field: 'file', required: true, description: 'The `.gh` or `.ghx` file.' },\n\t\t\t{ field: 'projectId', required: true, description: 'Owning project.' },\n\t\t\t{ field: 'displayName', required: true, description: 'Human-readable name.' },\n\t\t\t{ field: 'description', required: false, description: 'Long description.' },\n\t\t\t{ field: 'category', required: false, description: 'Grouping label.' },\n\t\t\t{ field: 'tags', required: false, description: 'Comma-separated tags.' },\n\t\t\t{ field: 'image', required: false, description: 'Cover image.' },\n\t\t\t{ field: 'computeServerId', required: false, description: 'Pin to a compute server.' }\n\t\t],\n\t\terrors: [400, 403, 422, 503]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}',\n\t\tscope: 'read',\n\t\tsummary: 'Definition record plus its live and draft version summaries.',\n\t\tresponse: 'object',\n\t\treturns:\n\t\t\t'`canEdit` is true when the caller can upload a version and make one live; for an API token that includes its scopes. `sourceDocumentId` is the Grasshopper document GUID it was last uploaded from, or null.',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/definitions/{guid}',\n\t\tscope: 'write',\n\t\tsummary: 'Update definition metadata.',\n\t\tresponse: 'empty',\n\t\trequestBody: UpdateDefinitionBodySchema,\n\t\terrors: [400, 404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/definitions/{guid}',\n\t\tscope: 'write',\n\t\tsummary: 'Soft-delete a definition.',\n\t\tresponse: 'empty',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/solve',\n\t\tscope: 'solve',\n\t\tidempotent: true,\n\t\tsummary: 'Solve a definition. The primary action of the API.',\n\t\tresponse: 'object',\n\t\trequestBody: SolveBodySchema,\n\t\terrors: solveErrors\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/schema',\n\t\tscope: 'read',\n\t\tsummary: \"The live version's UI schema. 404 when nothing is published.\",\n\t\tresponse: 'object',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/versions',\n\t\tscope: 'read',\n\t\tsummary: 'List versions, newest first.',\n\t\tresponse: 'collection',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/versions',\n\t\tscope: 'upload',\n\t\tidempotent: true,\n\t\tsummary: 'Upload a new version.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\tmultipart: [\n\t\t\t{ field: 'file', required: true, description: 'The `.gh` or `.ghx` file.' },\n\t\t\t{ field: 'changeNote', required: false, description: 'Truncated to 1000 characters.' }\n\t\t],\n\t\terrors: [400, 404, 422, 503]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/versions/{versionId}',\n\t\tscope: 'read',\n\t\tsummary: 'One version, without its cached schema.',\n\t\tresponse: 'object',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/definitions/{guid}/versions/{versionId}',\n\t\tscope: 'write',\n\t\tsummary: 'Delete a version. 409 when it is the live or draft pointer.',\n\t\tresponse: 'empty',\n\t\terrors: [404, 409]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/versions/{versionId}/schema',\n\t\tscope: 'read',\n\t\tsummary: \"That version's cached UI schema. No compute round-trip.\",\n\t\tresponse: 'object',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/publish',\n\t\tscope: 'upload',\n\t\tsummary: 'Promote a version to live.',\n\t\tresponse: 'object',\n\t\trequestBody: PublishVersionBodySchema,\n\t\terrors: [400, 404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/image',\n\t\tscope: 'write',\n\t\tsummary: 'Upload a cover image.',\n\t\tresponse: 'object',\n\t\tmultipart: [{ field: 'image', required: true, description: 'PNG, JPEG, WebP or GIF.' }],\n\t\terrors: [400, 404]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/definitions/{guid}/share-links',\n\t\tscope: 'read',\n\t\tsummary: 'List share links. 404 when sharing is disabled on the instance.',\n\t\tresponse: 'collection',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/definitions/{guid}/share-links',\n\t\tscope: 'write',\n\t\tidempotent: true,\n\t\tsummary: 'Create a share link. The raw token is returned once and never again.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: CreateShareLinkBodySchema,\n\t\terrors: [400, 404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/definitions/{guid}/share-links/{linkId}',\n\t\tscope: 'write',\n\t\tsummary: 'Revoke a share link.',\n\t\tresponse: 'empty',\n\t\terrors: [404]\n\t},\n\n\t// ==========================================================================\n\t// Projects\n\t// ==========================================================================\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/projects',\n\t\tscope: 'read',\n\t\tsummary: 'List projects the caller can view.',\n\t\tresponse: 'collection',\n\t\treturns:\n\t\t\t'Each item has `canCreateDefinitions`: whether `POST /definitions` would accept this project from the caller, scopes included for an API token.'\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/projects',\n\t\tscope: 'create_projects',\n\t\tidempotent: true,\n\t\tsummary:\n\t\t\t'Create a project. A key with `create_projects` but not `write` may create private projects only, with `autoJoinOnUpload` off.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: CreateProjectBodySchema,\n\t\terrors: [400, 403, 409]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/projects/{id}',\n\t\tscope: 'read',\n\t\tsummary: \"Project record plus the caller's effective role and capabilities.\",\n\t\tresponse: 'object',\n\t\terrors: [404]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/projects/{id}',\n\t\tscope: 'write',\n\t\tsummary: 'Update project settings. Owner-only.',\n\t\tresponse: 'empty',\n\t\trequestBody: UpdateProjectBodySchema,\n\t\terrors: [400, 403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/projects/{id}',\n\t\tscope: 'write',\n\t\tsummary: 'Delete a project.',\n\t\tresponse: 'empty',\n\t\terrors: [403, 404]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/projects/{id}/members',\n\t\tscope: 'read',\n\t\tsummary: 'List project members.',\n\t\tresponse: 'collection',\n\t\terrors: [403, 404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/projects/{id}/members',\n\t\tscope: 'write',\n\t\tsummary: 'Add a member. The target must already belong to the org.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: AddProjectMemberBodySchema,\n\t\terrors: [400, 403, 404]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/projects/{id}/members/{userId}',\n\t\tscope: 'write',\n\t\tsummary: 'Change a member role.',\n\t\tresponse: 'empty',\n\t\trequestBody: UpdateProjectMemberBodySchema,\n\t\terrors: [400, 403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/projects/{id}/members/{userId}',\n\t\tscope: 'write',\n\t\tsummary: 'Remove a member. Idempotent.',\n\t\tresponse: 'empty',\n\t\tquery: [\n\t\t\t{\n\t\t\t\tname: 'confirm',\n\t\t\t\tdescription: 'Set to `true` to remove a co-owner; without it the call returns 409.'\n\t\t\t}\n\t\t],\n\t\terrors: [403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/projects/{id}/reclaim',\n\t\tscope: 'write',\n\t\tsummary: 'Claim ownership of an unowned project.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\terrors: [403, 404, 409]\n\t},\n\n\t// ==========================================================================\n\t// Orgs\n\t// ==========================================================================\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}',\n\t\tscope: 'read',\n\t\tsummary: \"Org record. The org must be the caller's acting org.\",\n\t\tresponse: 'object',\n\t\terrors: [403, 404]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}/members',\n\t\tscope: 'read',\n\t\tsummary: 'List org members.',\n\t\tresponse: 'collection',\n\t\terrors: [403]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/orgs/{orgId}/members/{userId}',\n\t\tscope: 'write',\n\t\tsummary: 'Change an org role or permission set. The sole owner cannot be demoted.',\n\t\tresponse: 'empty',\n\t\trequestBody: UpdateOrgMemberBodySchema,\n\t\terrors: [400, 403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/orgs/{orgId}/members/{userId}',\n\t\tscope: 'write',\n\t\tsummary: 'Remove an org member. The sole owner cannot be removed.',\n\t\tresponse: 'empty',\n\t\terrors: [403, 404, 409]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}/invites',\n\t\tscope: 'read',\n\t\tsummary: 'List pending invites. Browser session only: an API key gets 403.',\n\t\tresponse: 'collection',\n\t\terrors: [403]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/orgs/{orgId}/invites',\n\t\tscope: 'write',\n\t\tsummary:\n\t\t\t'Invite someone to the org. The accept URL is returned once. Browser session only: an API key gets 403.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: CreateInviteBodySchema,\n\t\terrors: [400, 403, 409]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/orgs/{orgId}/invites/{id}',\n\t\tscope: 'write',\n\t\tsummary: 'Revoke an invite.',\n\t\tresponse: 'empty',\n\t\terrors: [403, 404]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/orgs/{orgId}/invites/{id}/resend',\n\t\tscope: 'write',\n\t\tsummary:\n\t\t\t'Re-send an invite. Issues a replacement and revokes the original, so the previous link stops working. Browser session only: an API key gets 403.',\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\terrors: [403, 404, 409]\n\t},\n\t// Internal and session-only: a key can never manage keys.\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}/tokens',\n\t\tscope: 'read',\n\t\tsummary: 'Your API tokens in this org, revoked and expired included.',\n\t\tinternal: true,\n\t\tresponse: 'collection',\n\t\tquery: [\n\t\t\t{ name: 'all', description: \"`true` for every member's tokens. Needs `manage_org_members`.\" }\n\t\t],\n\t\terrors: [403, 503]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/orgs/{orgId}/tokens',\n\t\tscope: 'write',\n\t\tsummary: 'Create an API token acting as you. The raw key is returned once, as `secret`.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\tstatus: 201,\n\t\trequestBody: CreateApiTokenBodySchema,\n\t\terrors: [400, 403, 503]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/orgs/{orgId}/tokens/{tokenId}',\n\t\tscope: 'write',\n\t\tsummary: 'Revoke an API token: your own, or any in the org with `manage_org_members`.',\n\t\tinternal: true,\n\t\tresponse: 'empty',\n\t\terrors: [403, 404, 503]\n\t},\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/orgs/{orgId}/compute',\n\t\tscope: 'read',\n\t\tsummary: 'Org compute-server overrides and the shared catalog.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\terrors: [403]\n\t},\n\t{\n\t\tmethod: 'PATCH',\n\t\tpath: '/orgs/{orgId}/compute',\n\t\tscope: 'write',\n\t\tsummary: 'Replace the org compute-server overrides.',\n\t\tinternal: true,\n\t\tresponse: 'empty',\n\t\trequestBody: OrgComputePatchBodySchema,\n\t\terrors: [400, 403]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/orgs/{orgId}/assets/{kind}',\n\t\tscope: 'write',\n\t\tsummary: 'Upload an org branding asset.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\tmultipart: [{ field: 'image', required: true, description: 'PNG, JPEG, WebP, GIF or SVG.' }],\n\t\terrors: [400, 403, 404]\n\t},\n\t{\n\t\tmethod: 'DELETE',\n\t\tpath: '/orgs/{orgId}/assets/{kind}',\n\t\tscope: 'write',\n\t\tsummary: 'Remove an org branding asset.',\n\t\tinternal: true,\n\t\tresponse: 'empty',\n\t\terrors: [403, 404]\n\t},\n\n\t// ==========================================================================\n\t// Compute\n\t// ==========================================================================\n\t//\n\t// Internal: accepts a remote `definitionUrl` and the anonymous share-token\n\t// flow, neither part of the public contract. Public callers solve through\n\t// `/definitions/{guid}/solve`.\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/compute',\n\t\tscope: 'solve',\n\t\tsummary: 'Generic solve, including remote definition URLs and share-token access.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\terrors: solveErrors\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/compute/schema',\n\t\tscope: 'upload',\n\t\tsummary: 'Extract UI schemas from an uploaded file before it becomes a definition.',\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\tmultipart: [{ field: 'file', required: true, description: 'The `.gh` or `.ghx` file.' }],\n\t\tquery: [\n\t\t\t{ name: 'projectId', description: 'Project the file will belong to.' },\n\t\t\t{ name: 'computeServerId', description: 'Pin to a compute server.' }\n\t\t],\n\t\terrors: [400, 403, 422, 503]\n\t},\n\n\t// ==========================================================================\n\t// Live solve events\n\t// ==========================================================================\n\t//\n\t// Internal: the browser's live channel and the plugin's callback into it. Both\n\t// are shaped by the Selva plugin and web app, not by the public contract.\n\t{\n\t\tmethod: 'GET',\n\t\tpath: '/solve-events',\n\t\tscope: 'read',\n\t\tsummary: \"The tab's live event stream (SSE). Solves that name its `streamId` report here.\",\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\tquery: [{ name: 'streamId', description: 'Minted by the tab, 16-64 URL-safe characters.' }],\n\t\terrors: [400, 401, 409]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/solve-events/{solveId}',\n\t\tscope: 'write',\n\t\tsummary: \"The plugin's callback from inside a Compute solve. The reply carries `abort`.\",\n\t\tinternal: true,\n\t\tresponse: 'object',\n\t\terrors: [400, 401, 410]\n\t},\n\t{\n\t\tmethod: 'POST',\n\t\tpath: '/solve/{solveId}/cancel',\n\t\tscope: 'solve',\n\t\tsummary: 'Ask a running solve to abort. Cooperative: it stops at the next component.',\n\t\tinternal: true,\n\t\tresponse: 'empty',\n\t\terrors: [401, 404]\n\t}\n];\n\n/** `/definitions/{guid}` → the SvelteKit directory form `definitions/[guid]`. */\nexport function toRoutePath(openApiPath: string): string {\n\treturn openApiPath.replace(/^\\//, '').replace(/\\{(\\w+)\\}/g, '[$1]');\n}\n\nexport function endpointKey(method: HttpMethod, path: string): string {\n\treturn `${method} ${path}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiCA,IAAM,cAAc;CAAC;CAAK;CAAK;CAAK;CAAK;AAAG;AAE5C,IAAa,eAA2B;CACvC;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;CACX;CAKA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SACC;EACD,UAAU;EACV,SACC;CACF;CAEA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SACC;EACD,UAAU;EACV,QAAQ,CAAC,KAAK,GAAG;CAClB;CACA;EACC,QAAQ;EACR,MAAM;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,QAAQ,CAAC,GAAG;CACb;CACA;EACC,QAAQ;EACR,MAAM;EACN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, requestedDefinitionId, request
52
52
  }
53
53
  };
54
54
  }
55
- export { tryResolveShareToken as t };
55
+ export { tryResolveShareToken as n, readShareToken as t };
56
56
 
57
57
  //# sourceMappingURL=resolve.server.js.map
@@ -146,6 +146,18 @@ function resolveApiKey(submitted, storedKey) {
146
146
  function storedKeysById(scopedServers) {
147
147
  return new Map(scopedServers.map((s) => [s.id, s.apiKey]));
148
148
  }
149
- export { validateIncomingServers as a, storedKeysById as i, assertStoredKeysReadable as n, evictChangedServers as o, resolveApiKey as r, assertKeyNotRetargeted as t };
149
+ /**
150
+ * The whole apiKey merge for one scope's write: refuses an unreadable or
151
+ * retargeted key with 409, then returns the key to store for each submitted id.
152
+ * `scopedStored` must be read with `includeApiKeys` and hold only the caller's
153
+ * scope.
154
+ */
155
+ function mergeApiKeys(incoming, scopedStored) {
156
+ assertStoredKeysReadable(incoming, scopedStored);
157
+ assertKeyNotRetargeted(incoming, scopedStored);
158
+ const stored = storedKeysById(scopedStored);
159
+ return new Map(incoming.map((s) => [s.id, resolveApiKey(s.apiKey, stored.get(s.id))]));
160
+ }
161
+ export { validateIncomingServers as n, evictChangedServers as r, mergeApiKeys as t };
150
162
 
151
163
  //# sourceMappingURL=server-config-write.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-config-write.js","names":[],"sources":["../../../../server/src/compute/evict-changed-servers.ts","../../../../server/src/compute/server-config-write.ts"],"sourcesContent":["/**\n * A warm compute client caches on server `id`, so a rotated `serverUrl`/`apiKey`\n * keeps the same cache key with stale connection details — it never ages out on\n * its own. The config-write path has to evict explicitly.\n *\n * The eviction sink is a parameter rather than an import: which cache holds the\n * warm clients is the host's decision, and importing one would drag a whole\n * solve engine into every consumer that only wants the diff.\n */\n\n/** The connection-identifying fields — a change in either makes the warm client stale. */\nexport interface ServerConnection {\n\tid: string;\n\tserverUrl: string;\n\tapiKey?: string;\n}\n\n/**\n * Drop the warm client for every server that was removed or whose connection\n * details changed. `prev` and `next` are the scoped server sets before and\n * after the write; unchanged servers are left alone.\n */\nexport function evictChangedServers(\n\tprev: readonly ServerConnection[],\n\tnext: readonly ServerConnection[],\n\tevict: (id: string) => void\n): void {\n\tconst nextById = new Map(next.map((s) => [s.id, s]));\n\n\t// Removed: no longer in `next`.\n\tfor (const before of prev) {\n\t\tif (!nextById.has(before.id)) evict(before.id);\n\t}\n\n\t// Rotated: same id, different URL or key.\n\tconst prevById = new Map(prev.map((s) => [s.id, s]));\n\tfor (const after of next) {\n\t\tconst before = prevById.get(after.id);\n\t\tif (before && (before.serverUrl !== after.serverUrl || before.apiKey !== after.apiKey)) {\n\t\t\tevict(after.id);\n\t\t}\n\t}\n}\n","/**\n * Shared write-path rules for compute server config.\n *\n * Two routes accept a server set: `/api/admin/compute` (platform scope,\n * `manage_compute`) and `/api/v1/orgs/{orgId}/compute` (org scope,\n * `manage_org_compute`). They differ in who may call them, what extra fields\n * they carry (`sharedWith` vs `ownerOrgId`), and how they validate the default\n * selection — but the field validation and the apiKey merge below must behave\n * identically in both, so they live here rather than in either handler.\n *\n * The apiKey merge is why this file exists: if the two copies disagree, a\n * stored credential silently gets cleared or leaked, and nothing fails at\n * build time.\n */\n\nimport { GuidSchema, trimTrailing } from '@selvajs/platform';\nimport { isEncryptedSecret } from '@selvajs/platform/computeServer';\nimport { isLinkLocalUrl } from './safe-url.js';\nimport { apiError, ApiErrorCode } from '../api/errors.js';\n\n/**\n * A stored `serverUrl` is fetched server-side on every status probe, every\n * purge/shutdown action, and every solve, so an unfiltered one is an SSRF\n * primitive handed to whoever holds `manage_compute`. Two rules:\n *\n * - Scheme allowlist: `http`/`https`. `file:`, `gopher:` and friends are never\n * a Rhino.Compute endpoint.\n * - Link-local (`169.254.0.0/16`) is refused. That range carries the cloud\n * metadata service at `169.254.169.254`, which hands out the host's own IAM\n * credentials to anything running on the box.\n *\n * **Loopback and RFC1918 are deliberately allowed.** Running compute on\n * `localhost:6500` or a LAN box is the ordinary self-hosted layout, not an\n * attack — most deployments reach their compute server over exactly those\n * addresses. Blocking them by default would break those instances on upgrade\n * and push every operator toward an opt-out flag, and a guard that everyone\n * disables protects nobody. So the check is narrowed to the range where no\n * legitimate compute server ever lives.\n *\n * What this does not stop: a privileged admin pointing the app at an internal\n * host to probe it. That is a real but much weaker concern than credential\n * theft, it needs `manage_compute` already, and it is inseparable from the\n * legitimate case. Revisit if `manage_org_compute` is ever delegated widely on\n * a multi-tenant instance.\n *\n * `isLinkLocalUrl` is reused rather than hand-rolled because a string compare\n * against `169.254.169.254` misses the encodings that reach the same address:\n * `http://2852039166/`, `http://0xa9fea9fe/`, `http://0251.0376.0251.0376/`.\n */\nfunction assertUsableServerUrl(serverUrl: string): void {\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(serverUrl);\n\t} catch {\n\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `Invalid serverUrl: ${serverUrl}`);\n\t}\n\tif (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `serverUrl must use http or https: ${serverUrl}`);\n\t}\n\tif (isLinkLocalUrl(serverUrl)) {\n\t\tapiError(\n\t\t\t400,\n\t\t\tApiErrorCode.VALIDATION_FAILED,\n\t\t\t`serverUrl points at the link-local range, which carries the cloud metadata service: ${serverUrl}`\n\t\t);\n\t}\n}\n\n/** The fields every incoming server carries, whatever its scope. */\nexport interface IncomingServerBase {\n\tid: string;\n\tlabel: string;\n\tserverUrl: string;\n\t/**\n\t * `undefined` → preserve the stored key; `null` → clear it;\n\t * non-empty string → replace it. See {@link resolveApiKey}.\n\t */\n\tapiKey?: string | null;\n}\n\n/**\n * Validates the scope-independent fields of every submitted server. Throws the\n * first failure as a 400; scope-specific fields (`sharedWith`, `ownerOrgId`)\n * are the caller's business.\n */\nexport function validateIncomingServers(servers: readonly IncomingServerBase[]): void {\n\tconst seen = new Set<string>();\n\tfor (const s of servers) {\n\t\tif (!s.id || typeof s.id !== 'string')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Each server needs an id');\n\t\tif (!GuidSchema.safeParse(s.id).success)\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `Server id must be a UUID: ${s.id}`);\n\t\tif (seen.has(s.id))\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `Server id appears more than once: ${s.id}`);\n\t\tseen.add(s.id);\n\t\tif (!s.label || typeof s.label !== 'string')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Each server needs a label');\n\t\tif (!s.serverUrl || typeof s.serverUrl !== 'string')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Each server needs a serverUrl');\n\t\tassertUsableServerUrl(s.serverUrl);\n\t\tif (s.apiKey !== undefined && s.apiKey !== null && typeof s.apiKey !== 'string')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'apiKey must be a string, null, or omitted');\n\t\t// Clients never receive stored keys, so an envelope here is someone else's\n\t\t// ciphertext being replayed against a URL they control.\n\t\tif (s.apiKey && isEncryptedSecret(s.apiKey))\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'apiKey must be a plaintext key');\n\t}\n}\n\n/**\n * A key that failed to decrypt reads as `hasApiKey` with no `apiKey`. Saving with\n * the field omitted would write `undefined` over the ciphertext, destroying the\n * key the logs tell the operator to recover by restoring `SELVA_AT_REST_KEY`.\n * Replacing or clearing it is a decision, so those pass.\n */\nexport function assertStoredKeysReadable(\n\tincoming: readonly Pick<IncomingServerBase, 'id' | 'apiKey'>[],\n\tstored: readonly { id: string; apiKey?: string; hasApiKey?: boolean }[]\n): void {\n\tconst unreadable = new Set(stored.filter((s) => s.hasApiKey && !s.apiKey).map((s) => s.id));\n\tfor (const s of incoming) {\n\t\tif (unreadable.has(s.id) && (s.apiKey === undefined || s.apiKey === '')) {\n\t\t\tapiError(\n\t\t\t\t409,\n\t\t\t\tApiErrorCode.CONFLICT,\n\t\t\t\t`The stored key for server ${s.id} cannot be decrypted. Restore the original SELVA_AT_REST_KEY, or re-enter the key.`\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * An omitted key is kept, so without this check anyone who may save the config\n * could point a server at their own host and have the next solve send them the\n * stored key, which they never saw. Moving a server needs the key re-entered or\n * cleared.\n */\nexport function assertKeyNotRetargeted(\n\tincoming: readonly Pick<IncomingServerBase, 'id' | 'serverUrl' | 'apiKey'>[],\n\tstored: readonly { id: string; serverUrl: string; apiKey?: string; hasApiKey?: boolean }[]\n): void {\n\tconst byId = new Map(stored.map((s) => [s.id, s]));\n\tfor (const s of incoming) {\n\t\tconst prev = byId.get(s.id);\n\t\tif (!prev || !(prev.hasApiKey || prev.apiKey)) continue;\n\t\tif (s.apiKey === null || (typeof s.apiKey === 'string' && s.apiKey !== '')) continue;\n\t\tif (sameServerUrl(prev.serverUrl, s.serverUrl)) continue;\n\t\tapiError(\n\t\t\t409,\n\t\t\tApiErrorCode.CONFLICT,\n\t\t\t`Server ${s.id} has a new URL. Re-enter its API key, or clear it, to save.`\n\t\t);\n\t}\n}\n\nfunction sameServerUrl(a: string, b: string): boolean {\n\tconst normalize = (u: string) => {\n\t\ttry {\n\t\t\treturn trimTrailing(new URL(u.trim()).href, '/');\n\t\t} catch {\n\t\t\treturn trimTrailing(u.trim(), '/');\n\t\t}\n\t};\n\treturn normalize(a) === normalize(b);\n}\n\n/**\n * The UI never receives stored keys — it sends back `hasApiKey` and omits the\n * field for servers the operator didn't touch. So \"omitted\" cannot mean \"clear\":\n * it has to preserve, or every save through the settings form would wipe the\n * keys of every server the operator left alone. Clearing is explicit (`null`);\n * an empty string is treated as \"not provided\" since that's what an untouched\n * password input submits.\n */\nexport function resolveApiKey(\n\tsubmitted: string | null | undefined,\n\tstoredKey: string | undefined\n): string | undefined {\n\tif (submitted === null) return undefined;\n\treturn submitted ? submitted : storedKey;\n}\n\n/**\n * Builds the id → stored-key lookup the merge reads. The caller passes only the\n * servers in its own scope, so one scope's write can never resolve a key from\n * another's rows.\n */\nexport function storedKeysById(\n\tscopedServers: readonly { id: string; apiKey?: string }[]\n): Map<string, string | undefined> {\n\treturn new Map(scopedServers.map((s) => [s.id, s.apiKey]));\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,oBACf,MACA,MACA,OACO;CACP,MAAM,WAAW,IAAI,IAAI,KAAK,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;CAGnD,KAAK,MAAM,UAAU,MACpB,IAAI,CAAC,SAAS,IAAI,OAAO,EAAE,GAAG,MAAM,OAAO,EAAE;CAI9C,MAAM,WAAW,IAAI,IAAI,KAAK,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;CACnD,KAAK,MAAM,SAAS,MAAM;EACzB,MAAM,SAAS,SAAS,IAAI,MAAM,EAAE;EACpC,IAAI,WAAW,OAAO,cAAc,MAAM,aAAa,OAAO,WAAW,MAAM,SAC9E,MAAM,MAAM,EAAE;CAEhB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACOA,SAAS,sBAAsB,WAAyB;CACvD,IAAI;CACJ,IAAI;EACH,SAAS,IAAI,IAAI,SAAS;CAC3B,QAAQ;EACP,SAAS,KAAK,aAAa,mBAAmB,sBAAsB,WAAW;CAChF;CACA,IAAI,OAAO,aAAa,WAAW,OAAO,aAAa,UACtD,SAAS,KAAK,aAAa,mBAAmB,qCAAqC,WAAW;CAE/F,IAAI,eAAe,SAAS,GAC3B,SACC,KACA,aAAa,mBACb,uFAAuF,WACxF;AAEF;;;;;;AAmBA,SAAgB,wBAAwB,SAA8C;CACrF,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,KAAK,SAAS;EACxB,IAAI,CAAC,EAAE,MAAM,OAAO,EAAE,OAAO,UAC5B,SAAS,KAAK,aAAa,mBAAmB,yBAAyB;EACxE,IAAI,CAAC,WAAW,UAAU,EAAE,EAAE,CAAC,CAAC,SAC/B,SAAS,KAAK,aAAa,mBAAmB,6BAA6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AAS,GAAG;EAChD,SACC,KACA,aAAa,UACb,UAAU,EAAE,GAAG,4DAChB;CACD;AACD;AAEA,SAAS,cAAc,GAAW,GAAoB;CACrD,MAAM,aAAa,MAAc;EAChC,IAAI;GACH,OAAO,aAAa,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG;EAChD,QAAQ;GACP,OAAO,aAAa,EAAE,KAAK,GAAG,GAAG;EAClC;CACD;CACA,OAAO,UAAU,CAAC,MAAM,UAAU,CAAC;AACpC;;;;;;;;;AAUA,SAAgB,cACf,WACA,WACqB;CACrB,IAAI,cAAc,MAAM,OAAO,KAAA;CAC/B,OAAO,YAAY,YAAY;AAChC;;;;;;AAOA,SAAgB,eACf,eACkC;CAClC,OAAO,IAAI,IAAI,cAAc,KAAK,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAC1D"}
1
+ {"version":3,"file":"server-config-write.js","names":[],"sources":["../../../../server/src/compute/evict-changed-servers.ts","../../../../server/src/compute/server-config-write.ts"],"sourcesContent":["/**\n * A warm compute client caches on server `id`, so a rotated `serverUrl`/`apiKey`\n * keeps the same cache key with stale connection details — it never ages out on\n * its own. The config-write path has to evict explicitly.\n *\n * The eviction sink is a parameter rather than an import: which cache holds the\n * warm clients is the host's decision, and importing one would drag a whole\n * solve engine into every consumer that only wants the diff.\n */\n\n/** The connection-identifying fields — a change in either makes the warm client stale. */\nexport interface ServerConnection {\n\tid: string;\n\tserverUrl: string;\n\tapiKey?: string;\n}\n\n/**\n * Drop the warm client for every server that was removed or whose connection\n * details changed. `prev` and `next` are the scoped server sets before and\n * after the write; unchanged servers are left alone.\n */\nexport function evictChangedServers(\n\tprev: readonly ServerConnection[],\n\tnext: readonly ServerConnection[],\n\tevict: (id: string) => void\n): void {\n\tconst nextById = new Map(next.map((s) => [s.id, s]));\n\n\t// Removed: no longer in `next`.\n\tfor (const before of prev) {\n\t\tif (!nextById.has(before.id)) evict(before.id);\n\t}\n\n\t// Rotated: same id, different URL or key.\n\tconst prevById = new Map(prev.map((s) => [s.id, s]));\n\tfor (const after of next) {\n\t\tconst before = prevById.get(after.id);\n\t\tif (before && (before.serverUrl !== after.serverUrl || before.apiKey !== after.apiKey)) {\n\t\t\tevict(after.id);\n\t\t}\n\t}\n}\n","/**\n * Shared write-path rules for compute server config.\n *\n * Two routes accept a server set: `/api/admin/compute` (platform scope,\n * `manage_compute`) and `/api/v1/orgs/{orgId}/compute` (org scope,\n * `manage_org_compute`). They differ in who may call them, what extra fields\n * they carry (`sharedWith` vs `ownerOrgId`), and how they validate the default\n * selection — but the field validation and the apiKey merge below must behave\n * identically in both, so they live here rather than in either handler.\n *\n * The apiKey merge is why this file exists: if the two copies disagree, a\n * stored credential silently gets cleared or leaked, and nothing fails at\n * build time.\n */\n\nimport { GuidSchema, trimTrailing } from '@selvajs/platform';\nimport { isEncryptedSecret } from '@selvajs/platform/computeServer';\nimport { isLinkLocalUrl } from './safe-url.js';\nimport { apiError, ApiErrorCode } from '../api/errors.js';\n\n/**\n * A stored `serverUrl` is fetched server-side on every status probe, every\n * purge/shutdown action, and every solve, so an unfiltered one is an SSRF\n * primitive handed to whoever holds `manage_compute`. Two rules:\n *\n * - Scheme allowlist: `http`/`https`. `file:`, `gopher:` and friends are never\n * a Rhino.Compute endpoint.\n * - Link-local (`169.254.0.0/16`) is refused. That range carries the cloud\n * metadata service at `169.254.169.254`, which hands out the host's own IAM\n * credentials to anything running on the box.\n *\n * **Loopback and RFC1918 are deliberately allowed.** Running compute on\n * `localhost:6500` or a LAN box is the ordinary self-hosted layout, not an\n * attack — most deployments reach their compute server over exactly those\n * addresses. Blocking them by default would break those instances on upgrade\n * and push every operator toward an opt-out flag, and a guard that everyone\n * disables protects nobody. So the check is narrowed to the range where no\n * legitimate compute server ever lives.\n *\n * What this does not stop: a privileged admin pointing the app at an internal\n * host to probe it. That is a real but much weaker concern than credential\n * theft, it needs `manage_compute` already, and it is inseparable from the\n * legitimate case. Revisit if `manage_org_compute` is ever delegated widely on\n * a multi-tenant instance.\n *\n * `isLinkLocalUrl` is reused rather than hand-rolled because a string compare\n * against `169.254.169.254` misses the encodings that reach the same address:\n * `http://2852039166/`, `http://0xa9fea9fe/`, `http://0251.0376.0251.0376/`.\n */\nfunction assertUsableServerUrl(serverUrl: string): void {\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(serverUrl);\n\t} catch {\n\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `Invalid serverUrl: ${serverUrl}`);\n\t}\n\tif (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `serverUrl must use http or https: ${serverUrl}`);\n\t}\n\tif (isLinkLocalUrl(serverUrl)) {\n\t\tapiError(\n\t\t\t400,\n\t\t\tApiErrorCode.VALIDATION_FAILED,\n\t\t\t`serverUrl points at the link-local range, which carries the cloud metadata service: ${serverUrl}`\n\t\t);\n\t}\n}\n\n/** The fields every incoming server carries, whatever its scope. */\nexport interface IncomingServerBase {\n\tid: string;\n\tlabel: string;\n\tserverUrl: string;\n\t/**\n\t * `undefined` → preserve the stored key; `null` → clear it;\n\t * non-empty string → replace it. See {@link resolveApiKey}.\n\t */\n\tapiKey?: string | null;\n}\n\n/**\n * Validates the scope-independent fields of every submitted server. Throws the\n * first failure as a 400; scope-specific fields (`sharedWith`, `ownerOrgId`)\n * are the caller's business.\n */\nexport function validateIncomingServers(servers: readonly IncomingServerBase[]): void {\n\tconst seen = new Set<string>();\n\tfor (const s of servers) {\n\t\tif (!s.id || typeof s.id !== 'string')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Each server needs an id');\n\t\tif (!GuidSchema.safeParse(s.id).success)\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `Server id must be a UUID: ${s.id}`);\n\t\tif (seen.has(s.id))\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `Server id appears more than once: ${s.id}`);\n\t\tseen.add(s.id);\n\t\tif (!s.label || typeof s.label !== 'string')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Each server needs a label');\n\t\tif (!s.serverUrl || typeof s.serverUrl !== 'string')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Each server needs a serverUrl');\n\t\tassertUsableServerUrl(s.serverUrl);\n\t\tif (s.apiKey !== undefined && s.apiKey !== null && typeof s.apiKey !== 'string')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'apiKey must be a string, null, or omitted');\n\t\t// Clients never receive stored keys, so an envelope here is someone else's\n\t\t// ciphertext being replayed against a URL they control.\n\t\tif (s.apiKey && isEncryptedSecret(s.apiKey))\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'apiKey must be a plaintext key');\n\t}\n}\n\n/**\n * A key that failed to decrypt reads as `hasApiKey` with no `apiKey`. Saving with\n * the field omitted would write `undefined` over the ciphertext, destroying the\n * key the logs tell the operator to recover by restoring `SELVA_AT_REST_KEY`.\n * Replacing or clearing it is a decision, so those pass.\n */\nexport function assertStoredKeysReadable(\n\tincoming: readonly Pick<IncomingServerBase, 'id' | 'apiKey'>[],\n\tstored: readonly { id: string; apiKey?: string; hasApiKey?: boolean }[]\n): void {\n\tconst unreadable = new Set(stored.filter((s) => s.hasApiKey && !s.apiKey).map((s) => s.id));\n\tfor (const s of incoming) {\n\t\tif (unreadable.has(s.id) && (s.apiKey === undefined || s.apiKey === '')) {\n\t\t\tapiError(\n\t\t\t\t409,\n\t\t\t\tApiErrorCode.CONFLICT,\n\t\t\t\t`The stored key for server ${s.id} cannot be decrypted. Restore the original SELVA_AT_REST_KEY, or re-enter the key.`\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * An omitted key is kept, so without this check anyone who may save the config\n * could point a server at their own host and have the next solve send them the\n * stored key, which they never saw. Moving a server needs the key re-entered or\n * cleared.\n */\nexport function assertKeyNotRetargeted(\n\tincoming: readonly Pick<IncomingServerBase, 'id' | 'serverUrl' | 'apiKey'>[],\n\tstored: readonly { id: string; serverUrl: string; apiKey?: string; hasApiKey?: boolean }[]\n): void {\n\tconst byId = new Map(stored.map((s) => [s.id, s]));\n\tfor (const s of incoming) {\n\t\tconst prev = byId.get(s.id);\n\t\tif (!prev || !(prev.hasApiKey || prev.apiKey)) continue;\n\t\tif (s.apiKey === null || (typeof s.apiKey === 'string' && s.apiKey !== '')) continue;\n\t\tif (sameServerUrl(prev.serverUrl, s.serverUrl)) continue;\n\t\tapiError(\n\t\t\t409,\n\t\t\tApiErrorCode.CONFLICT,\n\t\t\t`Server ${s.id} has a new URL. Re-enter its API key, or clear it, to save.`\n\t\t);\n\t}\n}\n\nfunction sameServerUrl(a: string, b: string): boolean {\n\tconst normalize = (u: string) => {\n\t\ttry {\n\t\t\treturn trimTrailing(new URL(u.trim()).href, '/');\n\t\t} catch {\n\t\t\treturn trimTrailing(u.trim(), '/');\n\t\t}\n\t};\n\treturn normalize(a) === normalize(b);\n}\n\n/**\n * The UI never receives stored keys — it sends back `hasApiKey` and omits the\n * field for servers the operator didn't touch. So \"omitted\" cannot mean \"clear\":\n * it has to preserve, or every save through the settings form would wipe the\n * keys of every server the operator left alone. Clearing is explicit (`null`);\n * an empty string is treated as \"not provided\" since that's what an untouched\n * password input submits.\n */\nexport function resolveApiKey(\n\tsubmitted: string | null | undefined,\n\tstoredKey: string | undefined\n): string | undefined {\n\tif (submitted === null) return undefined;\n\treturn submitted ? submitted : storedKey;\n}\n\n/**\n * Builds the id → stored-key lookup the merge reads. The caller passes only the\n * servers in its own scope, so one scope's write can never resolve a key from\n * another's rows.\n */\nexport function storedKeysById(\n\tscopedServers: readonly { id: string; apiKey?: string }[]\n): Map<string, string | undefined> {\n\treturn new Map(scopedServers.map((s) => [s.id, s.apiKey]));\n}\n\n/**\n * The whole apiKey merge for one scope's write: refuses an unreadable or\n * retargeted key with 409, then returns the key to store for each submitted id.\n * `scopedStored` must be read with `includeApiKeys` and hold only the caller's\n * scope.\n */\nexport function mergeApiKeys(\n\tincoming: readonly Pick<IncomingServerBase, 'id' | 'serverUrl' | 'apiKey'>[],\n\tscopedStored: readonly { id: string; serverUrl: string; apiKey?: string; hasApiKey?: boolean }[]\n): Map<string, string | undefined> {\n\tassertStoredKeysReadable(incoming, scopedStored);\n\tassertKeyNotRetargeted(incoming, scopedStored);\n\tconst stored = storedKeysById(scopedStored);\n\treturn new Map(incoming.map((s) => [s.id, resolveApiKey(s.apiKey, stored.get(s.id))]));\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,oBACf,MACA,MACA,OACO;CACP,MAAM,WAAW,IAAI,IAAI,KAAK,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;CAGnD,KAAK,MAAM,UAAU,MACpB,IAAI,CAAC,SAAS,IAAI,OAAO,EAAE,GAAG,MAAM,OAAO,EAAE;CAI9C,MAAM,WAAW,IAAI,IAAI,KAAK,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;CACnD,KAAK,MAAM,SAAS,MAAM;EACzB,MAAM,SAAS,SAAS,IAAI,MAAM,EAAE;EACpC,IAAI,WAAW,OAAO,cAAc,MAAM,aAAa,OAAO,WAAW,MAAM,SAC9E,MAAM,MAAM,EAAE;CAEhB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACOA,SAAS,sBAAsB,WAAyB;CACvD,IAAI;CACJ,IAAI;EACH,SAAS,IAAI,IAAI,SAAS;CAC3B,QAAQ;EACP,SAAS,KAAK,aAAa,mBAAmB,sBAAsB,WAAW;CAChF;CACA,IAAI,OAAO,aAAa,WAAW,OAAO,aAAa,UACtD,SAAS,KAAK,aAAa,mBAAmB,qCAAqC,WAAW;CAE/F,IAAI,eAAe,SAAS,GAC3B,SACC,KACA,aAAa,mBACb,uFAAuF,WACxF;AAEF;;;;;;AAmBA,SAAgB,wBAAwB,SAA8C;CACrF,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAA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MAAM,OAAO,KAAK,IAAI,EAAE,EAAE;EAC1B,IAAI,CAAC,QAAQ,EAAE,KAAK,aAAa,KAAK,SAAS;EAC/C,IAAI,EAAE,WAAW,QAAS,OAAO,EAAE,WAAW,YAAY,EAAE,WAAW,IAAK;EAC5E,IAAI,cAAc,KAAK,WAAW,EAAE,SAAS,GAAG;EAChD,SACC,KACA,aAAa,UACb,UAAU,EAAE,GAAG,4DAChB;CACD;AACD;AAEA,SAAS,cAAc,GAAW,GAAoB;CACrD,MAAM,aAAa,MAAc;EAChC,IAAI;GACH,OAAO,aAAa,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG;EAChD,QAAQ;GACP,OAAO,aAAa,EAAE,KAAK,GAAG,GAAG;EAClC;CACD;CACA,OAAO,UAAU,CAAC,MAAM,UAAU,CAAC;AACpC;;;;;;;;;AAUA,SAAgB,cACf,WACA,WACqB;CACrB,IAAI,cAAc,MAAM,OAAO,KAAA;CAC/B,OAAO,YAAY,YAAY;AAChC;;;;;;AAOA,SAAgB,eACf,eACkC;CAClC,OAAO,IAAI,IAAI,cAAc,KAAK,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAC1D;;;;;;;AAQA,SAAgB,aACf,UACA,cACkC;CAClC,yBAAyB,UAAU,YAAY;CAC/C,uBAAuB,UAAU,YAAY;CAC7C,MAAM,SAAS,eAAe,YAAY;CAC1C,OAAO,IAAI,IAAI,SAAS,KAAK,MAAM,CAAC,EAAE,IAAI,cAAc,EAAE,QAAQ,OAAO,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACtF"}
@@ -1,11 +1,11 @@
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 { i as platformServers } from "../../../../../chunks/utils.js";
4
- import { a as validateIncomingServers, i as storedKeysById, n as assertStoredKeysReadable, o as evictChangedServers$1, r as resolveApiKey, t as assertKeyNotRetargeted } from "../../../../../chunks/server-config-write.js";
4
+ import { n as validateIncomingServers, r as evictChangedServers$1, t as mergeApiKeys } from "../../../../../chunks/server-config-write.js";
5
5
  import "../../../../../chunks/compute.js";
6
- import { n as renderThrown } from "../../../../../chunks/definitions.js";
7
6
  import { t as apiError } from "../../../../../chunks/api-errors.js";
8
7
  import "../../../../../chunks/access2.server.js";
8
+ import { r as noContent, t as apiRoute } from "../../../../../chunks/http2.js";
9
9
  import { s 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";
@@ -21,27 +21,19 @@ function evictChangedServers(prev, next) {
21
21
  evictChangedServers$1(prev, next, evictComputeClient);
22
22
  }
23
23
  // src/routes/api/admin/compute/+server.ts
24
- var GET = async ({ locals }) => {
24
+ var GET = apiRoute("Failed to load compute config", async ({ locals }) => {
25
25
  requireManageCompute(locals);
26
- try {
27
- const config = await getComputeServerConfigStore().getConfig(locals.ctx);
28
- const servers = platformServers(config).map(({ apiKey: _apiKey, hasApiKey, ...rest }) => ({
29
- ...rest,
30
- hasApiKey: !!hasApiKey
31
- }));
32
- return json({
33
- servers,
34
- defaultServerId: config.defaultServerId
35
- });
36
- } catch (err) {
37
- locals.log.error("Failed to load compute config", {
38
- component: "Compute GET",
39
- err: renderThrown(err)
40
- });
41
- apiError(500, ApiErrorCode.INTERNAL, "Failed to load compute config");
42
- }
43
- };
44
- var PUT = async ({ request, locals }) => {
26
+ const config = await getComputeServerConfigStore().getConfig(locals.ctx);
27
+ const servers = platformServers(config).map(({ apiKey: _apiKey, hasApiKey, ...rest }) => ({
28
+ ...rest,
29
+ hasApiKey: !!hasApiKey
30
+ }));
31
+ return json({
32
+ servers,
33
+ defaultServerId: config.defaultServerId
34
+ });
35
+ });
36
+ var PUT = apiRoute("Failed to save compute config", async ({ request, locals }) => {
45
37
  requireManageCompute(locals);
46
38
  const body = await request.json().catch(() => null);
47
39
  if (!body || typeof body !== "object") apiError(400, ApiErrorCode.VALIDATION_FAILED, "Invalid request body");
@@ -55,32 +47,22 @@ var PUT = async ({ request, locals }) => {
55
47
  if (incoming.defaultServerId) {
56
48
  if (!incoming.servers.find((s) => s.id === incoming.defaultServerId)) apiError(400, ApiErrorCode.VALIDATION_FAILED, "defaultServerId must reference one of the submitted servers");
57
49
  }
58
- try {
59
- const provider = getComputeServerConfigStore();
60
- const existing = await provider.getConfig(locals.ctx, { includeApiKeys: true });
61
- assertStoredKeysReadable(incoming.servers, platformServers(existing));
62
- assertKeyNotRetargeted(incoming.servers, platformServers(existing));
63
- const storedKeys = storedKeysById(platformServers(existing));
64
- const next = incoming.servers.map(({ id, label, serverUrl, apiKey, sharedWith }) => ({
65
- id,
66
- label,
67
- serverUrl,
68
- scope: "platform",
69
- sharedWith: sharedWith === "all" ? "all" : [...sharedWith],
70
- apiKey: resolveApiKey(apiKey, storedKeys.get(id))
71
- }));
72
- await provider.savePlatformServers(locals.ctx, next, incoming.defaultServerId);
73
- serverResolver.forget();
74
- evictChangedServers(platformServers(existing), next);
75
- return new Response(null, { status: 204 });
76
- } catch (err) {
77
- locals.log.error("Failed to save compute config", {
78
- component: "Compute PUT",
79
- err: renderThrown(err)
80
- });
81
- apiError(500, ApiErrorCode.INTERNAL, "Failed to save compute config");
82
- }
83
- };
50
+ const provider = getComputeServerConfigStore();
51
+ const existing = await provider.getConfig(locals.ctx, { includeApiKeys: true });
52
+ const apiKeys = mergeApiKeys(incoming.servers, platformServers(existing));
53
+ const next = incoming.servers.map(({ id, label, serverUrl, sharedWith }) => ({
54
+ id,
55
+ label,
56
+ serverUrl,
57
+ scope: "platform",
58
+ sharedWith: sharedWith === "all" ? "all" : [...sharedWith],
59
+ apiKey: apiKeys.get(id)
60
+ }));
61
+ await provider.savePlatformServers(locals.ctx, next, incoming.defaultServerId);
62
+ serverResolver.forget();
63
+ evictChangedServers(platformServers(existing), next);
64
+ return noContent();
65
+ });
84
66
  export { GET, PUT };
85
67
 
86
68
  //# sourceMappingURL=_server.ts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/lib/server/compute/evictChangedServers.ts","../../../../../../../src/routes/api/admin/compute/+server.ts"],"sourcesContent":["/**\n * This app's binding for the shared eviction diff.\n *\n * The diff moved to `@selvajs/server/compute`, which takes the eviction sink as\n * a parameter so it names no cache. Here the sink is the solve engine's warm\n * client cache, which is what makes this file app-specific.\n */\n\nimport { evictChangedServers as diff, type ServerConnection } from '@selvajs/server/compute';\nimport { evictComputeClient } from './engine.server';\n\nexport type { ServerConnection };\n\nexport function evictChangedServers(\n\tprev: readonly ServerConnection[],\n\tnext: readonly ServerConnection[]\n): void {\n\tdiff(prev, next, evictComputeClient);\n}\n","import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { getComputeServerConfigStore } from '#lib/server/providers.server.js';\nimport { requireManageCompute } from '#lib/server/access.server.js';\nimport {\n\tplatformServers,\n\ttype ComputeServerConfig,\n\ttype PlatformComputeServer\n} from '@selvajs/platform';\nimport { evictChangedServers } from '#lib/server/compute/evictChangedServers.js';\nimport { serverResolver } from '#lib/server/compute/serverResolver.server.js';\nimport {\n\tassertStoredKeysReadable,\n\tassertKeyNotRetargeted,\n\tvalidateIncomingServers,\n\tresolveApiKey,\n\tstoredKeysById,\n\ttype IncomingServerBase\n} from '@selvajs/server/compute';\nimport { renderThrown } from '@selvajs/server/logging';\n\n/**\n * Admin platform-server endpoint. `manage_compute` only. Reads/writes the\n * platform-scope rows + the global `defaultServerId`. Org-private rows and\n * `orgDefaults` are handled by `/api/v1/orgs/[orgId]/compute`.\n */\n\ntype ServerPayload = Omit<PlatformComputeServer, 'apiKey' | 'hasApiKey'> & { hasApiKey: boolean };\n\ninterface IncomingServer extends IncomingServerBase {\n\tsharedWith: 'all' | string[];\n}\n\ninterface IncomingConfig {\n\tservers: IncomingServer[];\n\tdefaultServerId?: string;\n}\n\n// GET — return platform servers + global default. API keys are stripped and\n// replaced with a `hasApiKey` flag.\nexport const GET: RequestHandler = async ({ locals }) => {\n\trequireManageCompute(locals);\n\ttry {\n\t\tconst config = await getComputeServerConfigStore().getConfig(locals.ctx!);\n\t\tconst servers = platformServers(config).map(\n\t\t\t({ apiKey: _apiKey, hasApiKey, ...rest }): ServerPayload => ({\n\t\t\t\t...rest,\n\t\t\t\thasApiKey: !!hasApiKey\n\t\t\t})\n\t\t);\n\t\treturn json({\n\t\t\tservers,\n\t\t\tdefaultServerId: config.defaultServerId\n\t\t});\n\t} catch (err) {\n\t\tlocals.log.error('Failed to load compute config', {\n\t\t\tcomponent: 'Compute GET',\n\t\t\terr: renderThrown(err)\n\t\t});\n\t\tapiError(500, ApiErrorCode.INTERNAL, 'Failed to load compute config');\n\t}\n};\n\n// PUT — replace the full set of platform servers + global default.\n// apiKey field semantics:\n// omitted / undefined → preserve the currently stored key (matched by id)\n// null → explicitly clear the key\n// non-empty string → replace with new value\nexport const PUT: RequestHandler = async ({ request, locals }) => {\n\trequireManageCompute(locals);\n\tconst body = await request.json().catch(() => null);\n\tif (!body || typeof body !== 'object')\n\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Invalid request body');\n\n\tconst incoming = body as IncomingConfig;\n\tif (!Array.isArray(incoming.servers))\n\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'servers must be an array');\n\n\tvalidateIncomingServers(incoming.servers);\n\n\t// Platform-only: org servers have an owner instead of a share list.\n\tfor (const s of incoming.servers) {\n\t\tif (s.sharedWith !== 'all' && !Array.isArray(s.sharedWith)) {\n\t\t\tapiError(\n\t\t\t\t400,\n\t\t\t\tApiErrorCode.VALIDATION_FAILED,\n\t\t\t\t'sharedWith must be \"all\" or an array of org ids'\n\t\t\t);\n\t\t}\n\t\tif (Array.isArray(s.sharedWith) && s.sharedWith.some((x) => typeof x !== 'string')) {\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'sharedWith array must contain strings');\n\t\t}\n\t}\n\n\tif (incoming.defaultServerId) {\n\t\tconst found = incoming.servers.find((s) => s.id === incoming.defaultServerId);\n\t\tif (!found)\n\t\t\tapiError(\n\t\t\t\t400,\n\t\t\t\tApiErrorCode.VALIDATION_FAILED,\n\t\t\t\t'defaultServerId must reference one of the submitted servers'\n\t\t\t);\n\t}\n\n\ttry {\n\t\tconst provider = getComputeServerConfigStore();\n\t\t// One of the few reads that genuinely needs every key: unchanged servers\n\t\t// keep their stored key, and `evictChangedServers` diffs on key rotation.\n\t\tconst existing = await provider.getConfig(locals.ctx!, { includeApiKeys: true });\n\t\tassertStoredKeysReadable(incoming.servers, platformServers(existing));\n\t\tassertKeyNotRetargeted(incoming.servers, platformServers(existing));\n\t\tconst storedKeys = storedKeysById(platformServers(existing));\n\n\t\tconst next: ComputeServerConfig[] = incoming.servers.map(\n\t\t\t// Named fields only: anything else in the body would be written to the store as-is.\n\t\t\t({ id, label, serverUrl, apiKey, sharedWith }): PlatformComputeServer => ({\n\t\t\t\tid,\n\t\t\t\tlabel,\n\t\t\t\tserverUrl,\n\t\t\t\tscope: 'platform',\n\t\t\t\tsharedWith: sharedWith === 'all' ? 'all' : [...sharedWith],\n\t\t\t\tapiKey: resolveApiKey(apiKey, storedKeys.get(id))\n\t\t\t})\n\t\t);\n\n\t\tawait provider.savePlatformServers(locals.ctx!, next, incoming.defaultServerId);\n\t\tserverResolver.forget();\n\t\t// Drop warm clients for servers whose URL/key rotated or that were removed —\n\t\t// keyed on `id`, they wouldn't age out on their own (ADR 0004).\n\t\tevictChangedServers(platformServers(existing), next);\n\t\treturn new Response(null, { status: 204 });\n\t} catch (err) {\n\t\tlocals.log.error('Failed to save compute config', {\n\t\t\tcomponent: 'Compute PUT',\n\t\t\terr: renderThrown(err)\n\t\t});\n\t\tapiError(500, ApiErrorCode.INTERNAL, 'Failed to save compute config');\n\t}\n};\n"],"mappings":";;;;;;;;;;;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,SACC,KACA,aAAa,mBACb,6DACD;CAAA;CAGF,IAAI;EACH,MAAM,WAAW,4BAA4B;EAG7C,MAAM,WAAW,MAAM,SAAS,UAAU,OAAO,KAAM,EAAE,gBAAgB,KAAK,CAAC;EAC/E,yBAAyB,SAAS,SAAS,gBAAgB,QAAQ,CAAC;EACpE,uBAAuB,SAAS,SAAS,gBAAgB,QAAQ,CAAC;EAClE,MAAM,aAAa,eAAe,gBAAgB,QAAQ,CAAC;EAE3D,MAAM,OAA8B,SAAS,QAAQ,KAEnD,EAAE,IAAI,OAAO,WAAW,QAAQ,kBAAyC;GACzE;GACA;GACA;GACA,OAAO;GACP,YAAY,eAAe,QAAQ,QAAQ,CAAC,GAAG,UAAU;GACzD,QAAQ,cAAc,QAAQ,WAAW,IAAI,EAAE,CAAC;EACjD,EACD;EAEA,MAAM,SAAS,oBAAoB,OAAO,KAAM,MAAM,SAAS,eAAe;EAC9E,eAAe,OAAO;EAGtB,oBAAoB,gBAAgB,QAAQ,GAAG,IAAI;EACnD,OAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAI,CAAC;CAC1C,SAAS,KAAK;EACb,OAAO,IAAI,MAAM,iCAAiC;GACjD,WAAW;GACX,KAAK,aAAa,GAAG;EACtB,CAAC;EACD,SAAS,KAAK,aAAa,UAAU,+BAA+B;CACrE;AACD"}
1
+ {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/lib/server/compute/evictChangedServers.ts","../../../../../../../src/routes/api/admin/compute/+server.ts"],"sourcesContent":["/**\n * This app's binding for the shared eviction diff.\n *\n * The diff moved to `@selvajs/server/compute`, which takes the eviction sink as\n * a parameter so it names no cache. Here the sink is the solve engine's warm\n * client cache, which is what makes this file app-specific.\n */\n\nimport { evictChangedServers as diff, type ServerConnection } from '@selvajs/server/compute';\nimport { evictComputeClient } from './engine.server';\n\nexport type { ServerConnection };\n\nexport function evictChangedServers(\n\tprev: readonly ServerConnection[],\n\tnext: readonly ServerConnection[]\n): void {\n\tdiff(prev, next, evictComputeClient);\n}\n","import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { getComputeServerConfigStore } from '#lib/server/providers.server.js';\nimport { requireManageCompute } from '#lib/server/access.server.js';\nimport {\n\tplatformServers,\n\ttype ComputeServerConfig,\n\ttype PlatformComputeServer\n} from '@selvajs/platform';\nimport { apiRoute, noContent } from '#lib/server/api/http.js';\nimport { evictChangedServers } from '#lib/server/compute/evictChangedServers.js';\nimport { serverResolver } from '#lib/server/compute/serverResolver.server.js';\nimport {\n\tmergeApiKeys,\n\tvalidateIncomingServers,\n\ttype IncomingServerBase\n} from '@selvajs/server/compute';\n\n/**\n * Admin platform-server endpoint. `manage_compute` only. Reads/writes the\n * platform-scope rows + the global `defaultServerId`. Org-private rows and\n * `orgDefaults` are handled by `/api/v1/orgs/[orgId]/compute`.\n */\n\ntype ServerPayload = Omit<PlatformComputeServer, 'apiKey' | 'hasApiKey'> & { hasApiKey: boolean };\n\ninterface IncomingServer extends IncomingServerBase {\n\tsharedWith: 'all' | string[];\n}\n\ninterface IncomingConfig {\n\tservers: IncomingServer[];\n\tdefaultServerId?: string;\n}\n\n// GET — return platform servers + global default. API keys are stripped and\n// replaced with a `hasApiKey` flag.\nexport const GET: RequestHandler = apiRoute('Failed to load compute config', async ({ locals }) => {\n\trequireManageCompute(locals);\n\tconst config = await getComputeServerConfigStore().getConfig(locals.ctx!);\n\tconst servers = platformServers(config).map(\n\t\t({ apiKey: _apiKey, hasApiKey, ...rest }): ServerPayload => ({\n\t\t\t...rest,\n\t\t\thasApiKey: !!hasApiKey\n\t\t})\n\t);\n\treturn json({\n\t\tservers,\n\t\tdefaultServerId: config.defaultServerId\n\t});\n});\n\n// PUT — replace the full set of platform servers + global default.\n// apiKey field semantics:\n// omitted / undefined → preserve the currently stored key (matched by id)\n// null → explicitly clear the key\n// non-empty string → replace with new value\nexport const PUT: RequestHandler = apiRoute(\n\t'Failed to save compute config',\n\tasync ({ request, locals }) => {\n\t\trequireManageCompute(locals);\n\t\tconst body = await request.json().catch(() => null);\n\t\tif (!body || typeof body !== 'object')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Invalid request body');\n\n\t\tconst incoming = body as IncomingConfig;\n\t\tif (!Array.isArray(incoming.servers))\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'servers must be an array');\n\n\t\tvalidateIncomingServers(incoming.servers);\n\n\t\t// Platform-only: org servers have an owner instead of a share list.\n\t\tfor (const s of incoming.servers) {\n\t\t\tif (s.sharedWith !== 'all' && !Array.isArray(s.sharedWith)) {\n\t\t\t\tapiError(\n\t\t\t\t\t400,\n\t\t\t\t\tApiErrorCode.VALIDATION_FAILED,\n\t\t\t\t\t'sharedWith must be \"all\" or an array of org ids'\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (Array.isArray(s.sharedWith) && s.sharedWith.some((x) => typeof x !== 'string')) {\n\t\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'sharedWith array must contain strings');\n\t\t\t}\n\t\t}\n\n\t\tif (incoming.defaultServerId) {\n\t\t\tconst found = incoming.servers.find((s) => s.id === incoming.defaultServerId);\n\t\t\tif (!found)\n\t\t\t\tapiError(\n\t\t\t\t\t400,\n\t\t\t\t\tApiErrorCode.VALIDATION_FAILED,\n\t\t\t\t\t'defaultServerId must reference one of the submitted servers'\n\t\t\t\t);\n\t\t}\n\n\t\tconst provider = getComputeServerConfigStore();\n\t\t// One of the few reads that genuinely needs every key: unchanged servers\n\t\t// keep their stored key, and `evictChangedServers` diffs on key rotation.\n\t\tconst existing = await provider.getConfig(locals.ctx!, { includeApiKeys: true });\n\t\tconst apiKeys = mergeApiKeys(incoming.servers, platformServers(existing));\n\n\t\tconst next: ComputeServerConfig[] = incoming.servers.map(\n\t\t\t// Named fields only: anything else in the body would be written to the store as-is.\n\t\t\t({ id, label, serverUrl, sharedWith }): PlatformComputeServer => ({\n\t\t\t\tid,\n\t\t\t\tlabel,\n\t\t\t\tserverUrl,\n\t\t\t\tscope: 'platform',\n\t\t\t\tsharedWith: sharedWith === 'all' ? 'all' : [...sharedWith],\n\t\t\t\tapiKey: apiKeys.get(id)\n\t\t\t})\n\t\t);\n\n\t\tawait provider.savePlatformServers(locals.ctx!, next, incoming.defaultServerId);\n\t\tserverResolver.forget();\n\t\t// Drop warm clients for servers whose URL or key rotated, or that were\n\t\t// removed: keyed on `id`, they wouldn't age out on their own.\n\t\tevictChangedServers(platformServers(existing), next);\n\t\treturn noContent();\n\t}\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAaA,SAAgB,oBACf,MACA,MACO;CACP,sBAAK,MAAM,MAAM,kBAAkB;AACpC;;ACoBA,IAAa,MAAsB,SAAS,iCAAiC,OAAO,EAAE,aAAa;CAClG,qBAAqB,MAAM;CAC3B,MAAM,SAAS,MAAM,4BAA4B,CAAC,CAAC,UAAU,OAAO,GAAI;CACxE,MAAM,UAAU,gBAAgB,MAAM,CAAC,CAAC,KACtC,EAAE,QAAQ,SAAS,WAAW,GAAG,YAA2B;EAC5D,GAAG;EACH,WAAW,CAAC,CAAC;CACd,EACD;CACA,OAAO,KAAK;EACX;EACA,iBAAiB,OAAO;CACzB,CAAC;AACF,CAAC;AAOD,IAAa,MAAsB,SAClC,iCACA,OAAO,EAAE,SAAS,aAAa;CAC9B,qBAAqB,MAAM;CAC3B,MAAM,OAAO,MAAM,QAAQ,KAAK,CAAC,CAAC,YAAY,IAAI;CAClD,IAAI,CAAC,QAAQ,OAAO,SAAS,UAC5B,SAAS,KAAK,aAAa,mBAAmB,sBAAsB;CAErE,MAAM,WAAW;CACjB,IAAI,CAAC,MAAM,QAAQ,SAAS,OAAO,GAClC,SAAS,KAAK,aAAa,mBAAmB,0BAA0B;CAEzE,wBAAwB,SAAS,OAAO;CAGxC,KAAK,MAAM,KAAK,SAAS,SAAS;EACjC,IAAI,EAAE,eAAe,SAAS,CAAC,MAAM,QAAQ,EAAE,UAAU,GACxD,SACC,KACA,aAAa,mBACb,mDACD;EAED,IAAI,MAAM,QAAQ,EAAE,UAAU,KAAK,EAAE,WAAW,MAAM,MAAM,OAAO,MAAM,QAAQ,GAChF,SAAS,KAAK,aAAa,mBAAmB,uCAAuC;CAEvF;CAEA,IAAI,SAAS,iBAER;MAAA,CADU,SAAS,QAAQ,MAAM,MAAM,EAAE,OAAO,SAAS,eACxD,GACJ,SACC,KACA,aAAa,mBACb,6DACD;CAAA;CAGF,MAAM,WAAW,4BAA4B;CAG7C,MAAM,WAAW,MAAM,SAAS,UAAU,OAAO,KAAM,EAAE,gBAAgB,KAAK,CAAC;CAC/E,MAAM,UAAU,aAAa,SAAS,SAAS,gBAAgB,QAAQ,CAAC;CAExE,MAAM,OAA8B,SAAS,QAAQ,KAEnD,EAAE,IAAI,OAAO,WAAW,kBAAyC;EACjE;EACA;EACA;EACA,OAAO;EACP,YAAY,eAAe,QAAQ,QAAQ,CAAC,GAAG,UAAU;EACzD,QAAQ,QAAQ,IAAI,EAAE;CACvB,EACD;CAEA,MAAM,SAAS,oBAAoB,OAAO,KAAM,MAAM,SAAS,eAAe;CAC9E,eAAe,OAAO;CAGtB,oBAAoB,gBAAgB,QAAQ,GAAG,IAAI;CACnD,OAAO,UAAU;AAClB,CACD"}
@@ -3,6 +3,7 @@ import { k as ApiErrorCode, y as requireManageCompute } from "../../../../../../
3
3
  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
+ import { t as apiRoute } from "../../../../../../chunks/http2.js";
6
7
  import { a as definitionByteCacheStats, i as clearSolveResultCache, l as solveCacheStats, r as clearDefinitionCache } from "../../../../../../chunks/engine.server.js";
7
8
  import { t as openServerStats } from "../../../../../../chunks/serverStats.server.js";
8
9
  import { json } from "@sveltejs/kit";
@@ -13,7 +14,7 @@ var ACTIONS = [
13
14
  "clear-solve-cache",
14
15
  "clear-definition-cache"
15
16
  ];
16
- var POST = async ({ request, locals }) => {
17
+ var POST = apiRoute("Failed to run compute action", async ({ request, locals }) => {
17
18
  requireManageCompute(locals);
18
19
  const body = await request.json().catch(() => null);
19
20
  if (!body || typeof body !== "object") apiError(400, ApiErrorCode.VALIDATION_FAILED, "Invalid request body");
@@ -63,7 +64,7 @@ var POST = async ({ request, locals }) => {
63
64
  } finally {
64
65
  await stats.dispose();
65
66
  }
66
- };
67
+ });
67
68
  export { POST };
68
69
 
69
70
  //# sourceMappingURL=_server.ts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../../src/routes/api/admin/compute/actions/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { getComputeServerConfigStore } from '#lib/server/providers.server.js';\nimport { findServerById } from '@selvajs/platform';\nimport { requireManageCompute } from '#lib/server/access.server.js';\nimport { openServerStats } from '#lib/server/compute/serverStats.server.js';\nimport {\n\tclearSolveResultCache,\n\tclearDefinitionCache,\n\tsolveCacheStats,\n\tdefinitionByteCacheStats\n} from '#lib/server/compute/engine.server.js';\n\n/**\n * Admin compute actions — `manage_compute` only. Operator-initiated, mutating\n * cache/fleet controls that the read-only `/status` route deliberately omits.\n *\n * Targeting a single platform server by `serverId`:\n *\n * action: 'purge' → best-effort fleet-wide cache purge (purgeAllChildren)\n * action: 'shutdown' → graceful shutdown of all child processes (shutdownChildren)\n *\n * Process-wide, no `serverId` — these clear Selva's own in-memory caches, the\n * layer in front of Rhino.Compute that `purge` never reaches:\n *\n * action: 'clear-solve-cache' → cached solve results on every warm client\n * action: 'clear-definition-cache' → retained `.gh` bytes\n *\n * All are POST (not GET) so they can't be triggered by a stray prefetch — they\n * wake/drain real processes or throw away work already paid for.\n */\n\ntype Action = 'purge' | 'shutdown' | 'clear-solve-cache' | 'clear-definition-cache';\n\nconst ACTIONS: Action[] = ['purge', 'shutdown', 'clear-solve-cache', 'clear-definition-cache'];\n\ninterface ActionBody {\n\tserverId?: string;\n\taction?: Action;\n}\n\nexport const POST: RequestHandler = async ({ request, locals }) => {\n\trequireManageCompute(locals);\n\n\tconst body = (await request.json().catch(() => null)) as ActionBody | null;\n\tif (!body || typeof body !== 'object')\n\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Invalid request body');\n\n\tconst { serverId, action } = body;\n\tif (!action || !ACTIONS.includes(action))\n\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `action must be one of: ${ACTIONS.join(', ')}`);\n\n\t// Selva's own in-memory caches — process-wide, so no server to target. Report\n\t// what was dropped by reading the counters before clearing.\n\tif (action === 'clear-solve-cache') {\n\t\tconst { entries, bytes } = solveCacheStats();\n\t\tclearSolveResultCache();\n\t\treturn json({ action, entries, bytes });\n\t}\n\n\tif (action === 'clear-definition-cache') {\n\t\tconst { entries, bytes } = definitionByteCacheStats();\n\t\tclearDefinitionCache();\n\t\treturn json({ action, entries, bytes });\n\t}\n\n\tif (!serverId) apiError(400, ApiErrorCode.VALIDATION_FAILED, 'serverId required');\n\n\t// Admin route — read the full config; admin can act on any server. Only the\n\t// targeted server's key is decrypted.\n\tconst store = getComputeServerConfigStore();\n\tconst config = await store.getConfig(locals.ctx!);\n\tconst server = findServerById(config, serverId);\n\tif (!server) apiError(404, ApiErrorCode.NOT_FOUND, 'Server not found');\n\n\tconst apiKey = server.hasApiKey ? await store.getServerApiKey(locals.ctx!, server.id) : undefined;\n\tconst { stats, misconfigured } = openServerStats(server.serverUrl, apiKey);\n\tif (!stats) apiError(422, ApiErrorCode.UNPROCESSABLE, misconfigured);\n\ttry {\n\t\tif (action === 'purge') {\n\t\t\tconst result = await stats.purgeAllChildren();\n\t\t\tif (result === null)\n\t\t\t\tapiError(502, ApiErrorCode.INTERNAL, 'Could not reach the server to purge its cache');\n\t\t\treturn json({ action, ...result });\n\t\t}\n\n\t\t// action === 'shutdown' — no port filter, so the server shuts down every child.\n\t\tconst result = await stats.shutdownChildren();\n\t\tif (result === null)\n\t\t\tapiError(502, ApiErrorCode.INTERNAL, 'Could not reach the server to shut down its children');\n\t\treturn json({ action, ...result });\n\t} finally {\n\t\tawait stats.dispose();\n\t}\n};\n"],"mappings":";;;;;;;;;AAmCA,IAAM,UAAoB;CAAC;CAAS;CAAY;CAAqB;AAAwB;AAO7F,IAAa,OAAuB,OAAO,EAAE,SAAS,aAAa;CAClE,qBAAqB,MAAM;CAE3B,MAAM,OAAQ,MAAM,QAAQ,KAAK,CAAC,CAAC,YAAY,IAAI;CACnD,IAAI,CAAC,QAAQ,OAAO,SAAS,UAC5B,SAAS,KAAK,aAAa,mBAAmB,sBAAsB;CAErE,MAAM,EAAE,UAAU,WAAW;CAC7B,IAAI,CAAC,UAAU,CAAC,QAAQ,SAAS,MAAM,GACtC,SAAS,KAAK,aAAa,mBAAmB,0BAA0B,QAAQ,KAAK,IAAI,GAAG;CAI7F,IAAI,WAAW,qBAAqB;EACnC,MAAM,EAAE,SAAS,UAAU,gBAAgB;EAC3C,sBAAsB;EACtB,OAAO,KAAK;GAAE;GAAQ;GAAS;EAAM,CAAC;CACvC;CAEA,IAAI,WAAW,0BAA0B;EACxC,MAAM,EAAE,SAAS,UAAU,yBAAyB;EACpD,qBAAqB;EACrB,OAAO,KAAK;GAAE;GAAQ;GAAS;EAAM,CAAC;CACvC;CAEA,IAAI,CAAC,UAAU,SAAS,KAAK,aAAa,mBAAmB,mBAAmB;CAIhF,MAAM,QAAQ,4BAA4B;CAC1C,MAAM,SAAS,MAAM,MAAM,UAAU,OAAO,GAAI;CAChD,MAAM,SAAS,eAAe,QAAQ,QAAQ;CAC9C,IAAI,CAAC,QAAQ,SAAS,KAAK,aAAa,WAAW,kBAAkB;CAErE,MAAM,SAAS,OAAO,YAAY,MAAM,MAAM,gBAAgB,OAAO,KAAM,OAAO,EAAE,IAAI,KAAA;CACxF,MAAM,EAAE,OAAO,kBAAkB,gBAAgB,OAAO,WAAW,MAAM;CACzE,IAAI,CAAC,OAAO,SAAS,KAAK,aAAa,eAAe,aAAa;CACnE,IAAI;EACH,IAAI,WAAW,SAAS;GACvB,MAAM,SAAS,MAAM,MAAM,iBAAiB;GAC5C,IAAI,WAAW,MACd,SAAS,KAAK,aAAa,UAAU,+CAA+C;GACrF,OAAO,KAAK;IAAE;IAAQ,GAAG;GAAO,CAAC;EAClC;EAGA,MAAM,SAAS,MAAM,MAAM,iBAAiB;EAC5C,IAAI,WAAW,MACd,SAAS,KAAK,aAAa,UAAU,sDAAsD;EAC5F,OAAO,KAAK;GAAE;GAAQ,GAAG;EAAO,CAAC;CAClC,UAAU;EACT,MAAM,MAAM,QAAQ;CACrB;AACD"}
1
+ {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../../src/routes/api/admin/compute/actions/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { getComputeServerConfigStore } from '#lib/server/providers.server.js';\nimport { findServerById } from '@selvajs/platform';\nimport { requireManageCompute } from '#lib/server/access.server.js';\nimport { apiRoute } from '#lib/server/api/http.js';\nimport { openServerStats } from '#lib/server/compute/serverStats.server.js';\nimport {\n\tclearSolveResultCache,\n\tclearDefinitionCache,\n\tsolveCacheStats,\n\tdefinitionByteCacheStats\n} from '#lib/server/compute/engine.server.js';\n\n/**\n * Admin compute actions — `manage_compute` only. Operator-initiated, mutating\n * cache/fleet controls that the read-only `/status` route deliberately omits.\n *\n * Targeting a single platform server by `serverId`:\n *\n * action: 'purge' → best-effort fleet-wide cache purge (purgeAllChildren)\n * action: 'shutdown' → graceful shutdown of all child processes (shutdownChildren)\n *\n * Process-wide, no `serverId` — these clear Selva's own in-memory caches, the\n * layer in front of Rhino.Compute that `purge` never reaches:\n *\n * action: 'clear-solve-cache' → cached solve results on every warm client\n * action: 'clear-definition-cache' → retained `.gh` bytes\n *\n * All are POST (not GET) so they can't be triggered by a stray prefetch — they\n * wake/drain real processes or throw away work already paid for.\n */\n\ntype Action = 'purge' | 'shutdown' | 'clear-solve-cache' | 'clear-definition-cache';\n\nconst ACTIONS: Action[] = ['purge', 'shutdown', 'clear-solve-cache', 'clear-definition-cache'];\n\ninterface ActionBody {\n\tserverId?: string;\n\taction?: Action;\n}\n\nexport const POST: RequestHandler = apiRoute(\n\t'Failed to run compute action',\n\tasync ({ request, locals }) => {\n\t\trequireManageCompute(locals);\n\n\t\tconst body = (await request.json().catch(() => null)) as ActionBody | null;\n\t\tif (!body || typeof body !== 'object')\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, 'Invalid request body');\n\n\t\tconst { serverId, action } = body;\n\t\tif (!action || !ACTIONS.includes(action))\n\t\t\tapiError(400, ApiErrorCode.VALIDATION_FAILED, `action must be one of: ${ACTIONS.join(', ')}`);\n\n\t\t// Selva's own in-memory caches — process-wide, so no server to target. Report\n\t\t// what was dropped by reading the counters before clearing.\n\t\tif (action === 'clear-solve-cache') {\n\t\t\tconst { entries, bytes } = solveCacheStats();\n\t\t\tclearSolveResultCache();\n\t\t\treturn json({ action, entries, bytes });\n\t\t}\n\n\t\tif (action === 'clear-definition-cache') {\n\t\t\tconst { entries, bytes } = definitionByteCacheStats();\n\t\t\tclearDefinitionCache();\n\t\t\treturn json({ action, entries, bytes });\n\t\t}\n\n\t\tif (!serverId) apiError(400, ApiErrorCode.VALIDATION_FAILED, 'serverId required');\n\n\t\t// Admin route — read the full config; admin can act on any server. Only the\n\t\t// targeted server's key is decrypted.\n\t\tconst store = getComputeServerConfigStore();\n\t\tconst config = await store.getConfig(locals.ctx!);\n\t\tconst server = findServerById(config, serverId);\n\t\tif (!server) apiError(404, ApiErrorCode.NOT_FOUND, 'Server not found');\n\n\t\tconst apiKey = server.hasApiKey\n\t\t\t? await store.getServerApiKey(locals.ctx!, server.id)\n\t\t\t: undefined;\n\t\tconst { stats, misconfigured } = openServerStats(server.serverUrl, apiKey);\n\t\tif (!stats) apiError(422, ApiErrorCode.UNPROCESSABLE, misconfigured);\n\t\ttry {\n\t\t\tif (action === 'purge') {\n\t\t\t\tconst result = await stats.purgeAllChildren();\n\t\t\t\tif (result === null)\n\t\t\t\t\tapiError(502, ApiErrorCode.INTERNAL, 'Could not reach the server to purge its cache');\n\t\t\t\treturn json({ action, ...result });\n\t\t\t}\n\n\t\t\t// action === 'shutdown' — no port filter, so the server shuts down every child.\n\t\t\tconst result = await stats.shutdownChildren();\n\t\t\tif (result === null)\n\t\t\t\tapiError(\n\t\t\t\t\t502,\n\t\t\t\t\tApiErrorCode.INTERNAL,\n\t\t\t\t\t'Could not reach the server to shut down its children'\n\t\t\t\t);\n\t\t\treturn json({ action, ...result });\n\t\t} finally {\n\t\t\tawait stats.dispose();\n\t\t}\n\t}\n);\n"],"mappings":";;;;;;;;;;AAoCA,IAAM,UAAoB;CAAC;CAAS;CAAY;CAAqB;AAAwB;AAO7F,IAAa,OAAuB,SACnC,gCACA,OAAO,EAAE,SAAS,aAAa;CAC9B,qBAAqB,MAAM;CAE3B,MAAM,OAAQ,MAAM,QAAQ,KAAK,CAAC,CAAC,YAAY,IAAI;CACnD,IAAI,CAAC,QAAQ,OAAO,SAAS,UAC5B,SAAS,KAAK,aAAa,mBAAmB,sBAAsB;CAErE,MAAM,EAAE,UAAU,WAAW;CAC7B,IAAI,CAAC,UAAU,CAAC,QAAQ,SAAS,MAAM,GACtC,SAAS,KAAK,aAAa,mBAAmB,0BAA0B,QAAQ,KAAK,IAAI,GAAG;CAI7F,IAAI,WAAW,qBAAqB;EACnC,MAAM,EAAE,SAAS,UAAU,gBAAgB;EAC3C,sBAAsB;EACtB,OAAO,KAAK;GAAE;GAAQ;GAAS;EAAM,CAAC;CACvC;CAEA,IAAI,WAAW,0BAA0B;EACxC,MAAM,EAAE,SAAS,UAAU,yBAAyB;EACpD,qBAAqB;EACrB,OAAO,KAAK;GAAE;GAAQ;GAAS;EAAM,CAAC;CACvC;CAEA,IAAI,CAAC,UAAU,SAAS,KAAK,aAAa,mBAAmB,mBAAmB;CAIhF,MAAM,QAAQ,4BAA4B;CAC1C,MAAM,SAAS,MAAM,MAAM,UAAU,OAAO,GAAI;CAChD,MAAM,SAAS,eAAe,QAAQ,QAAQ;CAC9C,IAAI,CAAC,QAAQ,SAAS,KAAK,aAAa,WAAW,kBAAkB;CAErE,MAAM,SAAS,OAAO,YACnB,MAAM,MAAM,gBAAgB,OAAO,KAAM,OAAO,EAAE,IAClD,KAAA;CACH,MAAM,EAAE,OAAO,kBAAkB,gBAAgB,OAAO,WAAW,MAAM;CACzE,IAAI,CAAC,OAAO,SAAS,KAAK,aAAa,eAAe,aAAa;CACnE,IAAI;EACH,IAAI,WAAW,SAAS;GACvB,MAAM,SAAS,MAAM,MAAM,iBAAiB;GAC5C,IAAI,WAAW,MACd,SAAS,KAAK,aAAa,UAAU,+CAA+C;GACrF,OAAO,KAAK;IAAE;IAAQ,GAAG;GAAO,CAAC;EAClC;EAGA,MAAM,SAAS,MAAM,MAAM,iBAAiB;EAC5C,IAAI,WAAW,MACd,SACC,KACA,aAAa,UACb,sDACD;EACD,OAAO,KAAK;GAAE;GAAQ,GAAG;EAAO,CAAC;CAClC,UAAU;EACT,MAAM,MAAM,QAAQ;CACrB;AACD,CACD"}
@@ -4,6 +4,7 @@ import { n as findServerById } from "../../../../../../chunks/utils.js";
4
4
  import { u 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
+ import { t as apiRoute } from "../../../../../../chunks/http2.js";
7
8
  import { t as openServerStats } from "../../../../../../chunks/serverStats.server.js";
8
9
  import { json } from "@sveltejs/kit";
9
10
  // src/routes/api/admin/compute/status/+server.ts
@@ -23,7 +24,7 @@ function unreachable(failure) {
23
24
  limits: null
24
25
  });
25
26
  }
26
- var GET = async ({ url, locals }) => {
27
+ var GET = apiRoute("Failed to read compute server status", async ({ url, locals }) => {
27
28
  requireManageCompute(locals);
28
29
  const serverId = url.searchParams.get("serverId");
29
30
  if (!serverId) apiError(400, ApiErrorCode.VALIDATION_FAILED, "serverId required");
@@ -92,7 +93,7 @@ var GET = async ({ url, locals }) => {
92
93
  } finally {
93
94
  await stats.dispose();
94
95
  }
95
- };
96
+ });
96
97
  export { GET };
97
98
 
98
99
  //# sourceMappingURL=_server.ts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../../src/routes/api/admin/compute/status/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { getComputeServerConfigStore } from '#lib/server/providers.server.js';\nimport { findServerById } from '@selvajs/platform';\nimport { requireManageCompute } from '#lib/server/access.server.js';\nimport { classifyProbeFailure } from '@selvajs/compute/core';\nimport { openServerStats } from '#lib/server/compute/serverStats.server.js';\n\n/** The response for a server that can't be read, whatever stopped it. */\nfunction unreachable(failure: {\n\tretryable: boolean;\n\tfailureReason: string | null;\n\tfailureSummary: string | null;\n}) {\n\treturn json({\n\t\treachable: false,\n\t\tready: false,\n\t\t...failure,\n\t\trhinoVersion: null,\n\t\tcomputeVersion: null,\n\t\tselvaInstalled: false,\n\t\tselvaVersion: null,\n\t\tplugins: {},\n\t\tactiveChildren: null,\n\t\tidleSpanSeconds: null,\n\t\tlimits: null\n\t});\n}\n\nexport const GET: RequestHandler = async ({ url, locals }) => {\n\trequireManageCompute(locals);\n\n\tconst serverId = url.searchParams.get('serverId');\n\tif (!serverId) apiError(400, ApiErrorCode.VALIDATION_FAILED, 'serverId required');\n\n\t// Admin route — read the full config; admin can probe any server. Only the\n\t// probed server's key is decrypted.\n\tconst store = getComputeServerConfigStore();\n\tconst config = await store.getConfig(locals.ctx!);\n\tconst server = findServerById(config, serverId);\n\tif (!server) apiError(404, ApiErrorCode.NOT_FOUND, 'Server not found');\n\n\tconst apiKey = server.hasApiKey ? await store.getServerApiKey(locals.ctx!, server.id) : undefined;\n\tconst { stats, misconfigured } = openServerStats(server.serverUrl, apiKey);\n\tif (!stats) {\n\t\t// Retrying can't help: the stored URL or key has to change first.\n\t\treturn unreachable({\n\t\t\tretryable: false,\n\t\t\tfailureReason: 'misconfigured',\n\t\t\tfailureSummary: misconfigured\n\t\t});\n\t}\n\ttry {\n\t\t// Probe liveness first; only fan out to version/plugins when reachable.\n\t\tconst probe = await stats.probeServer();\n\t\tif (!probe.online) {\n\t\t\tconst failure = classifyProbeFailure(probe);\n\t\t\treturn unreachable({\n\t\t\t\t// `retryable: false` is the client's cue to stop polling: a refused\n\t\t\t\t// connection or a rejected key cannot resolve itself, and retrying it\n\t\t\t\t// for the full window leaves the operator staring at a spinner that\n\t\t\t\t// was never going to turn green.\n\t\t\t\tretryable: failure?.retryable ?? true,\n\t\t\t\tfailureReason: failure?.verdict ?? null,\n\t\t\t\tfailureSummary: failure?.summary ?? null\n\t\t\t});\n\t\t}\n\n\t\t// `initialize: false` keeps this a passive read — never spawn children just\n\t\t// to count them, or the status probe would wake (and bill) an idle server.\n\t\tconst [version, plugins, activeChildren, idleSpanSeconds, limits] = await Promise.all([\n\t\t\tstats.getVersion(),\n\t\t\tstats.getInstalledPlugins('gh'),\n\t\t\tstats.getActiveChildren({ initialize: false }),\n\t\t\tstats.getIdleSpan(),\n\t\t\tstats.getLimits()\n\t\t]);\n\n\t\t// The proxy answers `/` (reachable) well before a child finishes loading\n\t\t// Grasshopper add-ons, so a fresh boot briefly reports no Selva. Distinguish\n\t\t// \"still loading\" from \"genuinely not installed\" using the plugin inventory:\n\t\t// - plugins === null → `/plugins/gh/installed` couldn't be read (no child\n\t\t// up yet, or it errored) → not ready, the client should keep retrying.\n\t\t// - plugins === {} → same story: a child that has finished enumerating\n\t\t// add-ons always reports at least the ambient ones, so an empty map means\n\t\t// the inventory isn't populated yet → not ready.\n\t\t// - plugins populated → Grasshopper has enumerated its add-ons. Whether or\n\t\t// not Selva is among them is now authoritative → ready.\n\t\tconst inventoryLoaded = plugins !== null && Object.keys(plugins).length > 0;\n\t\tconst installed = plugins ?? {};\n\t\tconst selvaVersion: string | null = installed['Selva'] ?? null;\n\n\t\treturn json({\n\t\t\treachable: true,\n\t\t\t// `ready` gates the client's retry loop: once the inventory has loaded we\n\t\t\t// trust `selvaInstalled` (true or false); until then we're still booting.\n\t\t\tready: inventoryLoaded,\n\t\t\t// A reachable server is always worth another poll — it may still be\n\t\t\t// enumerating add-ons, and `activeChildren` climbing is the feedback the\n\t\t\t// operator is watching for.\n\t\t\tretryable: true,\n\t\t\tfailureReason: null,\n\t\t\tfailureSummary: null,\n\t\t\trhinoVersion: version?.rhino ?? null,\n\t\t\tcomputeVersion: version?.compute ?? null,\n\t\t\tselvaInstalled: selvaVersion !== null,\n\t\t\tselvaVersion,\n\t\t\tplugins: installed,\n\t\t\tactiveChildren,\n\t\t\tidleSpanSeconds,\n\t\t\tlimits\n\t\t});\n\t} catch {\n\t\treturn json({\n\t\t\treachable: false,\n\t\t\tready: false,\n\t\t\t// An unclassified throw is not evidence the server is permanently down.\n\t\t\tretryable: true,\n\t\t\tfailureReason: null,\n\t\t\tfailureSummary: null,\n\t\t\trhinoVersion: null,\n\t\t\tcomputeVersion: null,\n\t\t\tselvaInstalled: false,\n\t\t\tselvaVersion: null,\n\t\t\tplugins: {},\n\t\t\tactiveChildren: null,\n\t\t\tidleSpanSeconds: null,\n\t\t\tlimits: null\n\t\t});\n\t} finally {\n\t\tawait stats.dispose();\n\t}\n};\n"],"mappings":";;;;;;;;;;AAUA,SAAS,YAAY,SAIlB;CACF,OAAO,KAAK;EACX,WAAW;EACX,OAAO;EACP,GAAG;EACH,cAAc;EACd,gBAAgB;EAChB,gBAAgB;EAChB,cAAc;EACd,SAAS,CAAC;EACV,gBAAgB;EAChB,iBAAiB;EACjB,QAAQ;CACT,CAAC;AACF;AAEA,IAAa,MAAsB,OAAO,EAAE,KAAK,aAAa;CAC7D,qBAAqB,MAA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;GACjC;GACA,SAAS;GACT;GACA;GACA;EACD,CAAC;CACF,QAAQ;EACP,OAAO,KAAK;GACX,WAAW;GACX,OAAO;GAEP,WAAW;GACX,eAAe;GACf,gBAAgB;GAChB,cAAc;GACd,gBAAgB;GAChB,gBAAgB;GAChB,cAAc;GACd,SAAS,CAAC;GACV,gBAAgB;GAChB,iBAAiB;GACjB,QAAQ;EACT,CAAC;CACF,UAAU;EACT,MAAM,MAAM,QAAQ;CACrB;AACD"}
1
+ {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../../src/routes/api/admin/compute/status/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { getComputeServerConfigStore } from '#lib/server/providers.server.js';\nimport { findServerById } from '@selvajs/platform';\nimport { requireManageCompute } from '#lib/server/access.server.js';\nimport { apiRoute } from '#lib/server/api/http.js';\nimport { classifyProbeFailure } from '@selvajs/compute/core';\nimport { openServerStats } from '#lib/server/compute/serverStats.server.js';\n\n/** The response for a server that can't be read, whatever stopped it. */\nfunction unreachable(failure: {\n\tretryable: boolean;\n\tfailureReason: string | null;\n\tfailureSummary: string | null;\n}) {\n\treturn json({\n\t\treachable: false,\n\t\tready: false,\n\t\t...failure,\n\t\trhinoVersion: null,\n\t\tcomputeVersion: null,\n\t\tselvaInstalled: false,\n\t\tselvaVersion: null,\n\t\tplugins: {},\n\t\tactiveChildren: null,\n\t\tidleSpanSeconds: null,\n\t\tlimits: null\n\t});\n}\n\nexport const GET: RequestHandler = apiRoute(\n\t'Failed to read compute server status',\n\tasync ({ url, locals }) => {\n\t\trequireManageCompute(locals);\n\n\t\tconst serverId = url.searchParams.get('serverId');\n\t\tif (!serverId) apiError(400, ApiErrorCode.VALIDATION_FAILED, 'serverId required');\n\n\t\t// Admin route — read the full config; admin can probe any server. Only the\n\t\t// probed server's key is decrypted.\n\t\tconst store = getComputeServerConfigStore();\n\t\tconst config = await store.getConfig(locals.ctx!);\n\t\tconst server = findServerById(config, serverId);\n\t\tif (!server) apiError(404, ApiErrorCode.NOT_FOUND, 'Server not found');\n\n\t\tconst apiKey = server.hasApiKey\n\t\t\t? await store.getServerApiKey(locals.ctx!, server.id)\n\t\t\t: undefined;\n\t\tconst { stats, misconfigured } = openServerStats(server.serverUrl, apiKey);\n\t\tif (!stats) {\n\t\t\t// Retrying can't help: the stored URL or key has to change first.\n\t\t\treturn unreachable({\n\t\t\t\tretryable: false,\n\t\t\t\tfailureReason: 'misconfigured',\n\t\t\t\tfailureSummary: misconfigured\n\t\t\t});\n\t\t}\n\t\ttry {\n\t\t\t// Probe liveness first; only fan out to version/plugins when reachable.\n\t\t\tconst probe = await stats.probeServer();\n\t\t\tif (!probe.online) {\n\t\t\t\tconst failure = classifyProbeFailure(probe);\n\t\t\t\treturn unreachable({\n\t\t\t\t\t// `retryable: false` is the client's cue to stop polling: a refused\n\t\t\t\t\t// connection or a rejected key cannot resolve itself, and retrying it\n\t\t\t\t\t// for the full window leaves the operator staring at a spinner that\n\t\t\t\t\t// was never going to turn green.\n\t\t\t\t\tretryable: failure?.retryable ?? true,\n\t\t\t\t\tfailureReason: failure?.verdict ?? null,\n\t\t\t\t\tfailureSummary: failure?.summary ?? null\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// `initialize: false` keeps this a passive read — never spawn children just\n\t\t\t// to count them, or the status probe would wake (and bill) an idle server.\n\t\t\tconst [version, plugins, activeChildren, idleSpanSeconds, limits] = await Promise.all([\n\t\t\t\tstats.getVersion(),\n\t\t\t\tstats.getInstalledPlugins('gh'),\n\t\t\t\tstats.getActiveChildren({ initialize: false }),\n\t\t\t\tstats.getIdleSpan(),\n\t\t\t\tstats.getLimits()\n\t\t\t]);\n\n\t\t\t// The proxy answers `/` (reachable) well before a child finishes loading\n\t\t\t// Grasshopper add-ons, so a fresh boot briefly reports no Selva. Distinguish\n\t\t\t// \"still loading\" from \"genuinely not installed\" using the plugin inventory:\n\t\t\t// - plugins === null → `/plugins/gh/installed` couldn't be read (no child\n\t\t\t// up yet, or it errored) → not ready, the client should keep retrying.\n\t\t\t// - plugins === {} → same story: a child that has finished enumerating\n\t\t\t// add-ons always reports at least the ambient ones, so an empty map means\n\t\t\t// the inventory isn't populated yet → not ready.\n\t\t\t// - plugins populated → Grasshopper has enumerated its add-ons. Whether or\n\t\t\t// not Selva is among them is now authoritative → ready.\n\t\t\tconst inventoryLoaded = plugins !== null && Object.keys(plugins).length > 0;\n\t\t\tconst installed = plugins ?? {};\n\t\t\tconst selvaVersion: string | null = installed['Selva'] ?? null;\n\n\t\t\treturn json({\n\t\t\t\treachable: true,\n\t\t\t\t// `ready` gates the client's retry loop: once the inventory has loaded we\n\t\t\t\t// trust `selvaInstalled` (true or false); until then we're still booting.\n\t\t\t\tready: inventoryLoaded,\n\t\t\t\t// A reachable server is always worth another poll — it may still be\n\t\t\t\t// enumerating add-ons, and `activeChildren` climbing is the feedback the\n\t\t\t\t// operator is watching for.\n\t\t\t\tretryable: true,\n\t\t\t\tfailureReason: null,\n\t\t\t\tfailureSummary: null,\n\t\t\t\trhinoVersion: version?.rhino ?? null,\n\t\t\t\tcomputeVersion: version?.compute ?? null,\n\t\t\t\tselvaInstalled: selvaVersion !== null,\n\t\t\t\tselvaVersion,\n\t\t\t\tplugins: installed,\n\t\t\t\tactiveChildren,\n\t\t\t\tidleSpanSeconds,\n\t\t\t\tlimits\n\t\t\t});\n\t\t} catch {\n\t\t\treturn json({\n\t\t\t\treachable: false,\n\t\t\t\tready: false,\n\t\t\t\t// An unclassified throw is not evidence the server is permanently down.\n\t\t\t\tretryable: true,\n\t\t\t\tfailureReason: null,\n\t\t\t\tfailureSummary: null,\n\t\t\t\trhinoVersion: null,\n\t\t\t\tcomputeVersion: null,\n\t\t\t\tselvaInstalled: false,\n\t\t\t\tselvaVersion: null,\n\t\t\t\tplugins: {},\n\t\t\t\tactiveChildren: null,\n\t\t\t\tidleSpanSeconds: null,\n\t\t\t\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BAAkB,EAAE,YAAY,MAAM,CAAC;GAC7C,MAAM,YAAY;GAClB,MAAM,UAAU;EACjB,CAAC;EAYD,MAAM,kBAAkB,YAAY,QAAQ,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS;EAC1E,MAAM,YAAY,WAAW,CAAC;EAC9B,MAAM,eAA8B,UAAU,YAAY;EAE1D,OAAO,KAAK;GACX,WAAW;GAGX,OAAO;GAIP,WAAW;GACX,eAAe;GACf,gBAAgB;GAChB,cAAc,SAAS,SAAS;GAChC,gBAAgB,SAAS,WAAW;GACpC,gBAAgB,iBAAiB;GACjC;GACA,SAAS;GACT;GACA;GACA;EACD,CAAC;CACF,QAAQ;EACP,OAAO,KAAK;GACX,WAAW;GACX,OAAO;GAEP,WAAW;GACX,eAAe;GACf,gBAAgB;GAChB,cAAc;GACd,gBAAgB;GAChB,gBAAgB;GAChB,cAAc;GACd,SAAS,CAAC;GACV,gBAAgB;GAChB,iBAAiB;GACjB,QAAQ;EACT,CAAC;CACF,UAAU;EACT,MAAM,MAAM,QAAQ;CACrB;AACD,CACD"}
@@ -1,4 +1,4 @@
1
- import { s as getDefinitionMeta, v as getProjectProvider, x as getStorageProvider } from "../../../../../../chunks/providers.server.js";
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
4
  import { H as requireParams, R as parseBody } from "../../../../../../chunks/api.js";
@@ -15,6 +15,7 @@ var UpdatePlatformProjectBody = z.object({
15
15
  description: z.string().max(2e3).nullish()
16
16
  }).partial();
17
17
  async function loadPlatformProjectOr404(id) {
18
+ if (!flag("ENABLE_PLATFORM_PROJECTS")) apiError(404, ApiErrorCode.NOT_FOUND, "Not found");
18
19
  const project = await getProjectProvider().getProject(SYSTEM_CONTEXT, id);
19
20
  if (!project || project.visibility !== "platform") apiError(404, ApiErrorCode.NOT_FOUND, "Platform project not found");
20
21
  return project;
@@ -27,8 +28,8 @@ var GET = apiRoute("Failed to load platform project", async ({ params, locals })
27
28
  var PATCH = apiRoute("Failed to update platform project", async ({ params, request, locals }) => {
28
29
  requireInstanceAdmin(locals);
29
30
  const { id } = requireParams(params, "id");
30
- const input = await parseBody(request, UpdatePlatformProjectBody);
31
31
  await loadPlatformProjectOr404(id);
32
+ const input = await parseBody(request, UpdatePlatformProjectBody);
32
33
  const patch = {};
33
34
  if (input.name !== void 0) {
34
35
  patch.name = input.name;
@@ -1 +1 @@
1
- {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../../src/routes/api/admin/projects/[id]/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { z } from 'zod';\nimport {\n\tgetDefinitionMeta,\n\tgetProjectProvider,\n\tgetStorageProvider\n} from '#lib/server/providers.server.js';\nimport { deleteProjectWithBlobs } from '@selvajs/server/projects';\nimport { requireInstanceAdmin } from '#lib/server/access.server.js';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { apiRoute, noContent, parseBody, requireParams } from '#lib/server/api/http.js';\nimport { slugify } from '@selvajs/platform';\nimport { SYSTEM_CONTEXT } from '@selvajs/platform';\n\nconst UpdatePlatformProjectBody = z\n\t.object({\n\t\tname: z.string().min(1).max(128).trim(),\n\t\tdescription: z.string().max(2000).nullish()\n\t})\n\t.partial();\n\nasync function loadPlatformProjectOr404(id: string) {\n\tconst project = await getProjectProvider().getProject(SYSTEM_CONTEXT, id);\n\tif (!project || project.visibility !== 'platform') {\n\t\tapiError(404, ApiErrorCode.NOT_FOUND, 'Platform project not found');\n\t}\n\treturn project;\n}\n\nexport const GET: RequestHandler = apiRoute(\n\t'Failed to load platform project',\n\tasync ({ params, locals }) => {\n\t\trequireInstanceAdmin(locals);\n\t\tconst { id } = requireParams(params, 'id');\n\t\treturn json(await loadPlatformProjectOr404(id));\n\t}\n);\n\nexport const PATCH: RequestHandler = apiRoute(\n\t'Failed to update platform project',\n\tasync ({ params, request, locals }) => {\n\t\trequireInstanceAdmin(locals);\n\t\tconst { id } = requireParams(params, 'id');\n\n\t\tconst input = await parseBody(request, UpdatePlatformProjectBody);\n\t\tawait loadPlatformProjectOr404(id);\n\n\t\tconst patch: { name?: string; slug?: string; description?: string } = {};\n\t\tif (input.name !== undefined) {\n\t\t\tpatch.name = input.name;\n\t\t\t// A name with no usable letters yields '', which keeps the current slug.\n\t\t\tconst slug = slugify(input.name);\n\t\t\tif (slug) patch.slug = slug;\n\t\t}\n\t\tif (input.description !== undefined) {\n\t\t\tpatch.description = input.description ?? undefined;\n\t\t}\n\n\t\tawait getProjectProvider().updateProject(SYSTEM_CONTEXT, id, patch);\n\t\treturn noContent();\n\t}\n);\n\nexport const DELETE: RequestHandler = apiRoute(\n\t'Failed to delete platform project',\n\tasync ({ params, locals }) => {\n\t\trequireInstanceAdmin(locals);\n\t\tconst { id } = requireParams(params, 'id');\n\n\t\tawait loadPlatformProjectOr404(id);\n\t\tawait deleteProjectWithBlobs(\n\t\t\t{\n\t\t\t\tprojects: getProjectProvider(),\n\t\t\t\tdefinitions: getDefinitionMeta(),\n\t\t\t\tstorage: getStorageProvider()\n\t\t\t},\n\t\t\tSYSTEM_CONTEXT,\n\t\t\tid\n\t\t);\n\t\treturn noContent();\n\t}\n);\n"],"mappings":";;;;;;;;;;;;AAeA,IAAM,4BAA4B,EAChC,OAAO;CACP,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK;CACtC,aAAa,EAAE,OAAO,CAAC,CAAC,IAAI,GAAI,CAAC,CAAC,QAAQ;AAC3C,CAAC,CAAC,CACD,QAAQ;AAEV,eAAe,yBAAyB,IAAY;CACnD,MAAM,UAAU,MAAM,mBAAmB,CAAC,CAAC,WAAW,gBAAgB,EAAE;CACxE,IAAI,CAAC,WAAW,QAAQ,eAAe,YACtC,SAAS,KAAK,aAAa,WAAW,4BAA4B;CAEnE,OAAO;AACR;AAEA,IAAa,MAAsB,SAClC,mCACA,OAAO,EAAE,QAAQ,aAAa;CAC7B,qBAAqB,MAAM;CAC3B,MAAM,EAAE,OAAO,cAAc,QAAQ,IAAI;CACzC,OAAO,KAAK,MAAM,yBAAyB,EAAE,CAAC;AAC/C,CACD;AAEA,IAAa,QAAwB,SACpC,qCACA,OAAO,EAAE,QAAQ,SAAS,aAAa;CACtC,qBAAqB,MAAM;CAC3B,MAAM,EAAE,OAAO,cAAc,QAAQ,IAAI;CAEzC,MAAM,QAAQ,MAAM,UAAU,SAAS,yBAAyB;CAChE,MAAM,yBAAyB,EAAE;CAEjC,MAAM,QAAgE,CAAC;CACvE,IAAI,MAAM,SAAS,KAAA,GAAW;EAC7B,MAAM,OAAO,MAAM;EAEnB,MAAM,OAAO,QAAQ,MAAM,IAAI;EAC/B,IAAI,MAAM,MAAM,OAAO;CACxB;CACA,IAAI,MAAM,gBAAgB,KAAA,GACzB,MAAM,cAAc,MAAM,eAAe,KAAA;CAG1C,MAAM,mBAAmB,CAAC,CAAC,cAAc,gBAAgB,IAAI,KAAK;CAClE,OAAO,UAAU;AAClB,CACD;AAEA,IAAa,SAAyB,SACrC,qCACA,OAAO,EAAE,QAAQ,aAAa;CAC7B,qBAAqB,MAAM;CAC3B,MAAM,EAAE,OAAO,cAAc,QAAQ,IAAI;CAEzC,MAAM,yBAAyB,EAAE;CACjC,MAAM,uBACL;EACC,UAAU,mBAAmB;EAC7B,aAAa,kBAAkB;EAC/B,SAAS,mBAAmB;CAC7B,GACA,gBACA,EACD;CACA,OAAO,UAAU;AAClB,CACD"}
1
+ {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../../src/routes/api/admin/projects/[id]/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { z } from 'zod';\nimport {\n\tflag,\n\tgetDefinitionMeta,\n\tgetProjectProvider,\n\tgetStorageProvider\n} from '#lib/server/providers.server.js';\nimport { deleteProjectWithBlobs } from '@selvajs/server/projects';\nimport { requireInstanceAdmin } from '#lib/server/access.server.js';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { apiRoute, noContent, parseBody, requireParams } from '#lib/server/api/http.js';\nimport { slugify } from '@selvajs/platform';\nimport { SYSTEM_CONTEXT } from '@selvajs/platform';\n\nconst UpdatePlatformProjectBody = z\n\t.object({\n\t\tname: z.string().min(1).max(128).trim(),\n\t\tdescription: z.string().max(2000).nullish()\n\t})\n\t.partial();\n\nasync function loadPlatformProjectOr404(id: string) {\n\tif (!flag('ENABLE_PLATFORM_PROJECTS')) apiError(404, ApiErrorCode.NOT_FOUND, 'Not found');\n\tconst project = await getProjectProvider().getProject(SYSTEM_CONTEXT, id);\n\tif (!project || project.visibility !== 'platform') {\n\t\tapiError(404, ApiErrorCode.NOT_FOUND, 'Platform project not found');\n\t}\n\treturn project;\n}\n\nexport const GET: RequestHandler = apiRoute(\n\t'Failed to load platform project',\n\tasync ({ params, locals }) => {\n\t\trequireInstanceAdmin(locals);\n\t\tconst { id } = requireParams(params, 'id');\n\t\treturn json(await loadPlatformProjectOr404(id));\n\t}\n);\n\nexport const PATCH: RequestHandler = apiRoute(\n\t'Failed to update platform project',\n\tasync ({ params, request, locals }) => {\n\t\trequireInstanceAdmin(locals);\n\t\tconst { id } = requireParams(params, 'id');\n\n\t\tawait loadPlatformProjectOr404(id);\n\t\tconst input = await parseBody(request, UpdatePlatformProjectBody);\n\n\t\tconst patch: { name?: string; slug?: string; description?: string } = {};\n\t\tif (input.name !== undefined) {\n\t\t\tpatch.name = input.name;\n\t\t\t// A name with no usable letters yields '', which keeps the current slug.\n\t\t\tconst slug = slugify(input.name);\n\t\t\tif (slug) patch.slug = slug;\n\t\t}\n\t\tif (input.description !== undefined) {\n\t\t\tpatch.description = input.description ?? undefined;\n\t\t}\n\n\t\tawait getProjectProvider().updateProject(SYSTEM_CONTEXT, id, patch);\n\t\treturn noContent();\n\t}\n);\n\nexport const DELETE: RequestHandler = apiRoute(\n\t'Failed to delete platform project',\n\tasync ({ params, locals }) => {\n\t\trequireInstanceAdmin(locals);\n\t\tconst { id } = requireParams(params, 'id');\n\n\t\tawait loadPlatformProjectOr404(id);\n\t\tawait deleteProjectWithBlobs(\n\t\t\t{\n\t\t\t\tprojects: getProjectProvider(),\n\t\t\t\tdefinitions: getDefinitionMeta(),\n\t\t\t\tstorage: getStorageProvider()\n\t\t\t},\n\t\t\tSYSTEM_CONTEXT,\n\t\t\tid\n\t\t);\n\t\treturn noContent();\n\t}\n);\n"],"mappings":";;;;;;;;;;;;AAgBA,IAAM,4BAA4B,EAChC,OAAO;CACP,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK;CACtC,aAAa,EAAE,OAAO,CAAC,CAAC,IAAI,GAAI,CAAC,CAAC,QAAQ;AAC3C,CAAC,CAAC,CACD,QAAQ;AAEV,eAAe,yBAAyB,IAAY;CACnD,IAAI,CAAC,KAAK,0BAA0B,GAAG,SAAS,KAAK,aAAa,WAAW,WAAW;CACxF,MAAM,UAAU,MAAM,mBAAmB,CAAC,CAAC,WAAW,gBAAgB,EAAE;CACxE,IAAI,CAAC,WAAW,QAAQ,eAAe,YACtC,SAAS,KAAK,aAAa,WAAW,4BAA4B;CAEnE,OAAO;AACR;AAEA,IAAa,MAAsB,SAClC,mCACA,OAAO,EAAE,QAAQ,aAAa;CAC7B,qBAAqB,MAAM;CAC3B,MAAM,EAAE,OAAO,cAAc,QAAQ,IAAI;CACzC,OAAO,KAAK,MAAM,yBAAyB,EAAE,CAAC;AAC/C,CACD;AAEA,IAAa,QAAwB,SACpC,qCACA,OAAO,EAAE,QAAQ,SAAS,aAAa;CACtC,qBAAqB,MAAM;CAC3B,MAAM,EAAE,OAAO,cAAc,QAAQ,IAAI;CAEzC,MAAM,yBAAyB,EAAE;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