@selvajs/selva 4.20.1-beta.1 → 4.20.1-beta.3

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 (73) 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/server/.vite/manifest.json +9 -2
  18. package/build/server/chunks/access.js +0 -3
  19. package/build/server/chunks/access.js.map +1 -1
  20. package/build/server/chunks/definitions.js +178 -1
  21. package/build/server/chunks/definitions.js.map +1 -1
  22. package/build/server/chunks/handlers.js +4 -5
  23. package/build/server/chunks/handlers.js.map +1 -1
  24. package/build/server/chunks/instance.js +3 -3
  25. package/build/server/chunks/internal.js +1 -1
  26. package/build/server/chunks/package.js +1 -1
  27. package/build/server/chunks/package.js.map +1 -1
  28. package/build/server/chunks/providers.server.js +112 -189
  29. package/build/server/chunks/providers.server.js.map +1 -1
  30. package/build/server/chunks/registry.js +3 -3
  31. package/build/server/chunks/registry.js.map +1 -1
  32. package/build/server/chunks/resolve.server.js +1 -1
  33. package/build/server/chunks/server-config-write.js +13 -1
  34. package/build/server/chunks/server-config-write.js.map +1 -1
  35. package/build/server/chunks/solve.server.js +8 -3
  36. package/build/server/chunks/solve.server.js.map +1 -1
  37. package/build/server/entries/endpoints/api/admin/compute/_server.ts.js +30 -48
  38. package/build/server/entries/endpoints/api/admin/compute/_server.ts.js.map +1 -1
  39. package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js +3 -2
  40. package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js.map +1 -1
  41. package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js +3 -2
  42. package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js.map +1 -1
  43. package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js +3 -2
  44. package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js.map +1 -1
  45. package/build/server/entries/endpoints/api/admin/users/_server.ts.js +6 -2
  46. package/build/server/entries/endpoints/api/admin/users/_server.ts.js.map +1 -1
  47. package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js +8 -8
  48. package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js.map +1 -1
  49. package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +1 -1
  50. package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +1 -1
  51. package/build/server/entries/endpoints/docs/api/openapi.yaml/_server.ts.js +1 -1
  52. package/build/server/entries/hooks.server.js +13 -1
  53. package/build/server/entries/hooks.server.js.map +1 -1
  54. package/build/server/entries/pages/accept-invite/_page.server.ts.js +19 -1
  55. package/build/server/entries/pages/accept-invite/_page.server.ts.js.map +1 -1
  56. package/build/server/entries/pages/library/_guid_/_page.server.ts.js +16 -3
  57. package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
  58. package/build/server/entries/pages/library/_guid_/_page.svelte.js +132 -89
  59. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  60. package/build/server/manifest-full.js +1 -1
  61. package/build/server/manifest.js +1 -1
  62. package/build/server/nodes/21.js +1 -1
  63. package/build/server/server.js +1 -1
  64. package/package.json +10 -10
  65. package/build/client/_app/immutable/chunks/D-SwRD80.js.br +0 -0
  66. package/build/client/_app/immutable/chunks/Dvq2vJj6.js +0 -1
  67. package/build/client/_app/immutable/chunks/Dvq2vJj6.js.br +0 -1
  68. package/build/client/_app/immutable/chunks/Dvq2vJj6.js.gz +0 -0
  69. package/build/client/_app/immutable/entry/app.hg2qyLJU.js.br +0 -0
  70. package/build/client/_app/immutable/entry/app.hg2qyLJU.js.gz +0 -0
  71. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js +0 -1
  72. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js.br +0 -1
  73. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js.gz +0 -0
@@ -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":";;;;;;;;;;;;;;;;;;;AAaA,SAAgB,oBACf,MACA,MACO;CACP,sBAAK,MAAM,MAAM,kBAAkB;AACpC;;ACuBA,IAAa,MAAsB,OAAO,EAAE,aAAa;CACxD,qBAAqB,MAAM;CAC3B,IAAI;EACH,MAAM,SAAS,MAAM,4BAA4B,CAAC,CAAC,UAAU,OAAO,GAAI;EACxE,MAAM,UAAU,gBAAgB,MAAM,CAAC,CAAC,KACtC,EAAE,QAAQ,SAAS,WAAW,GAAG,YAA2B;GAC5D,GAAG;GACH,WAAW,CAAC,CAAC;EACd,EACD;EACA,OAAO,KAAK;GACX;GACA,iBAAiB,OAAO;EACzB,CAAC;CACF,SAAS,KAAK;EACb,OAAO,IAAI,MAAM,iCAAiC;GACjD,WAAW;GACX,KAAK,aAAa,GAAG;EACtB,CAAC;EACD,SAAS,KAAK,aAAa,UAAU,+BAA+B;CACrE;AACD;AAOA,IAAa,MAAsB,OAAO,EAAE,SAAS,aAAa;CACjE,qBAAqB,MAAM;CAC3B,MAAM,OAAO,MAAM,QAAQ,KAAK,CAAC,CAAC,YAAY,IAAI;CAClD,IAAI,CAAC,QAAQ,OAAO,SAAS,UAC5B,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,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,C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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,IA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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,MAAM;CAE3B,MAAM,WAAW,IAAI,aAAa,IAAI,UAAU;CAChD,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,OAEJ,OAAO,YAAY;EAClB,WAAW;EACX,eAAe;EACf,gBAAgB;CACjB,CAAC;CAEF,IAAI;EAEH,MAAM,QAAQ,MAAM,MAAM,YAAY;EACtC,IAAI,CAAC,MAAM,QAAQ;GAClB,MAAM,UAAU,qBAAqB,KAAK;GAC1C,OAAO,YAAY;IAKlB,WAAW,SAAS,aAAa;IACjC,eAAe,SAAS,WAAW;IACnC,gBAAgB,SAAS,WAAW;GACrC,CAAC;EACF;EAIA,MAAM,CAAC,SAAS,SAAS,gBAAgB,iBAAiB,UAAU,MAAM,QAAQ,IAAI;GACrF,MAAM,WAAW;GACjB,MAAM,oBAAoB,IAAI;GAC9B,MAAM,kBAAkB,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"}
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\tlimits: null\n\t\t\t});\n\t\t} finally {\n\t\t\tawait stats.dispose();\n\t\t}\n\t}\n);\n"],"mappings":";;;;;;;;;;;AAWA,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,SAClC,wCACA,OAAO,EAAE,KAAK,aAAa;CAC1B,qBAAqB,MAAM;CAE3B,MAAM,WAAW,IAAI,aAAa,IAAI,UAAU;CAChD,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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ectProvider, 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\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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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getAuthProvider, u as getEventSink } from "../../../../../chunks/providers.server.js";
1
+ import { U as actorFrom, g as getPermissionStore, h as getOrganizationProvider, o as getDataProvider, r as getAuthProvider, u as getEventSink } from "../../../../../chunks/providers.server.js";
2
2
  import { b as requireManageInstanceUsers, k as ApiErrorCode, r as assertCanGrantPlatformPermissions } from "../../../../../chunks/access.js";
3
3
  import { t as SYSTEM_CONTEXT } from "../../../../../chunks/context.js";
4
4
  import { R as parseBody } from "../../../../../chunks/api.js";
@@ -49,7 +49,7 @@ var POST = apiRoute("Failed to create user", async ({ request, locals }) => {
49
49
  userId: user.id,
50
50
  actorId: actorFrom(locals.ctx)
51
51
  });
52
- if (platform.length > 0) await setUserPlatformPermissions(locals.ctx, user.id, platform);
52
+ await getDataProvider().ensureUser(SYSTEM_CONTEXT, user.id);
53
53
  const orgId = locals.ctx?.actingOrgId;
54
54
  if (orgId) {
55
55
  const joinedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -64,6 +64,10 @@ var POST = apiRoute("Failed to create user", async ({ request, locals }) => {
64
64
  deletedAt: null
65
65
  });
66
66
  }
67
+ if (platform.length > 0) {
68
+ const granted = await setUserPlatformPermissions(locals.ctx, user.id, platform);
69
+ if (granted !== "ok") apiError(500, ApiErrorCode.INTERNAL, `The user was created, but their platform permissions were not granted (${granted}). Grant them from the user list.`);
70
+ }
67
71
  return created(user);
68
72
  });
69
73
  export { GET, POST };
@@ -1 +1 @@
1
- {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/api/admin/users/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { z } from 'zod';\nimport { getAuthProvider } from '#lib/server/providers.server.js';\nimport {\n\tgetEventSink,\n\tgetOrganizationProvider,\n\tgetPermissionStore\n} from '#lib/server/providers.server.js';\nimport {\n\tassertCanGrantPlatformPermissions,\n\trequireManageInstanceUsers\n} from '#lib/server/access.server.js';\nimport { listAllOrgMembers } from '@selvajs/server/organizations';\nimport { setUserPlatformPermissions } from '#lib/server/permissions.server.js';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { apiRoute, created, parseBody } from '#lib/server/api/http.js';\nimport {\n\tPlatformPermissionSchema,\n\tSYSTEM_CONTEXT,\n\tactorFrom,\n\ttype OrgMember\n} from '@selvajs/platform';\n// `password` is deliberately absent: an admin never sets another user's\n// credential. A stale client may still send one — Zod strips unknown keys, so it\n// is dropped rather than rejected.\n//\n// Platform scope only — a new user joins the active org as a bare `member`, and\n// their org permissions are granted at /team/members under manage_org_members.\nconst CreateUserBody = z.object({\n\temail: z.string().email('Valid email is required'),\n\tpermissions: z.array(PlatformPermissionSchema)\n});\n\n// GET — list all users with their platform permissions and acting-org membership.\nexport const GET: RequestHandler = apiRoute('Failed to list users', async ({ locals }) => {\n\trequireManageInstanceUsers(locals);\n\tconst page = await getAuthProvider().listUsers({ limit: 200 });\n\tif (page === null) {\n\t\tapiError(\n\t\t\t501,\n\t\t\tApiErrorCode.INTERNAL,\n\t\t\t'User management is not supported by the current auth provider. Configure DATA_PATH (local provider) or check your provider wiring.'\n\t\t);\n\t}\n\n\tconst orgId = locals.ctx?.actingOrgId;\n\tconst orgs = getOrganizationProvider();\n\t// Single batch read for platform permissions instead of N round-trips.\n\tconst userIds = page.items.map((u) => u.id);\n\tconst platformByUser = await getPermissionStore().getForBatch(locals.ctx!, userIds);\n\t// One membership listing instead of a getOrgMember round-trip per user.\n\tconst memberByUserId = new Map<string, OrgMember>();\n\tif (orgId) {\n\t\tfor (const m of await listAllOrgMembers(orgs, orgId, locals.log))\n\t\t\tmemberByUserId.set(m.userId, m);\n\t}\n\tconst users = page.items.map((u) => {\n\t\tconst member = memberByUserId.get(u.id);\n\t\treturn {\n\t\t\t...u,\n\t\t\tplatformPermissions: platformByUser.get(u.id) ?? [],\n\t\t\torgRole: member?.role,\n\t\t\torgPermissions: member ? [...member.permissions] : []\n\t\t};\n\t});\n\treturn json({ users });\n});\n\n// POST — create a user + attach to default org with split permissions.\nexport const POST: RequestHandler = apiRoute(\n\t'Failed to create user',\n\tasync ({ request, locals }) => {\n\t\trequireManageInstanceUsers(locals);\n\t\tconst auth = getAuthProvider();\n\n\t\tconst { email, permissions: platform } = await parseBody(request, CreateUserBody);\n\n\t\tassertCanGrantPlatformPermissions(locals.ctx!, platform);\n\n\t\tlet user;\n\t\tif (auth.createUser) {\n\t\t\t// No password branch: a provider that owns credentials admits users by\n\t\t\t// invite, so nobody but the account holder ever chooses the password.\n\t\t\t// `createUser` is the allowlist path — under header-auth it is the only\n\t\t\t// way in, since the IdP holds the credential and Selva never sees one.\n\t\t\tuser = await auth.createUser(email);\n\t\t} else {\n\t\t\tapiError(\n\t\t\t\t501,\n\t\t\t\tApiErrorCode.INTERNAL,\n\t\t\t\t`${auth.name} cannot create a user directly. Send an invite instead — the recipient sets their own password.`\n\t\t\t);\n\t\t}\n\n\t\tawait getEventSink().emit({\n\t\t\ttype: 'user.created',\n\t\t\tuserId: user.id,\n\t\t\tactorId: actorFrom(locals.ctx!)\n\t\t});\n\n\t\t// Grant platform permissions out-of-band via the data-layer store.\n\t\tif (platform.length > 0) {\n\t\t\tawait setUserPlatformPermissions(locals.ctx!, user.id, platform);\n\t\t}\n\n\t\t// Attach to the active org as a bare member. Under header-auth this is the\n\t\t// only way in — the IdP holds the credential, so there is no invite to\n\t\t// accept. Org permissions are granted separately at /team/members.\n\t\tconst orgId = locals.ctx?.actingOrgId;\n\t\tif (orgId) {\n\t\t\tconst joinedAt = new Date().toISOString();\n\t\t\tawait getOrganizationProvider().addOrgMember(SYSTEM_CONTEXT, {\n\t\t\t\torgId,\n\t\t\t\tuserId: user.id,\n\t\t\t\trole: 'member',\n\t\t\t\tpermissions: [],\n\t\t\t\tjoinedAt,\n\t\t\t\tupdatedAt: joinedAt,\n\t\t\t\tupdatedBy: locals.user?.id ?? user.id,\n\t\t\t\tdeletedAt: null\n\t\t\t});\n\t\t}\n\n\t\treturn created(user);\n\t}\n);\n"],"m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,WAAW,KAAK;MAElC,SACC,KACA,aAAa,UACb,GAAG,KAAK,KAAK,gGACd;CAGD,MAAM,aAAa,CAAC,CAAC,KAAK;EACzB,MAAM;EACN,QAAQ,KAAK;EACb,SAAS,UAAU,OAAO,GAAI;CAC/B,CAAC;CAGD,IAAI,SAAS,SAAS,GACrB,MAAM,2BAA2B,OAAO,KAAM,KAAK,IAAI,QAAQ;CAMhE,MAAM,QAAQ,OAAO,KAAK;CAC1B,IAAI,OAAO;EACV,MAAM,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;EACxC,MAAM,wBAAwB,CAAC,CAAC,aAAa,gBAAgB;GAC5D;GACA,QAAQ,KAAK;GACb,MAAM;GACN,aAAa,CAAC;GACd;GACA,WAAW;GACX,WAAW,OAAO,MAAM,MAAM,KAAK;GACnC,WAAW;EACZ,CAAC;CACF;CAEA,OAAO,QAAQ,IAAI;AACpB,CACD"}
1
+ {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/api/admin/users/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { z } from 'zod';\nimport { getAuthProvider } from '#lib/server/providers.server.js';\nimport {\n\tgetDataProvider,\n\tgetEventSink,\n\tgetOrganizationProvider,\n\tgetPermissionStore\n} from '#lib/server/providers.server.js';\nimport {\n\tassertCanGrantPlatformPermissions,\n\trequireManageInstanceUsers\n} from '#lib/server/access.server.js';\nimport { listAllOrgMembers } from '@selvajs/server/organizations';\nimport { setUserPlatformPermissions } from '#lib/server/permissions.server.js';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { apiRoute, created, parseBody } from '#lib/server/api/http.js';\nimport {\n\tPlatformPermissionSchema,\n\tSYSTEM_CONTEXT,\n\tactorFrom,\n\ttype OrgMember\n} from '@selvajs/platform';\n// `password` is deliberately absent: an admin never sets another user's\n// credential. A stale client may still send one — Zod strips unknown keys, so it\n// is dropped rather than rejected.\n//\n// Platform scope only — a new user joins the active org as a bare `member`, and\n// their org permissions are granted at /team/members under manage_org_members.\nconst CreateUserBody = z.object({\n\temail: z.string().email('Valid email is required'),\n\tpermissions: z.array(PlatformPermissionSchema)\n});\n\n// GET — list all users with their platform permissions and acting-org membership.\nexport const GET: RequestHandler = apiRoute('Failed to list users', async ({ locals }) => {\n\trequireManageInstanceUsers(locals);\n\tconst page = await getAuthProvider().listUsers({ limit: 200 });\n\tif (page === null) {\n\t\tapiError(\n\t\t\t501,\n\t\t\tApiErrorCode.INTERNAL,\n\t\t\t'User management is not supported by the current auth provider. Configure DATA_PATH (local provider) or check your provider wiring.'\n\t\t);\n\t}\n\n\tconst orgId = locals.ctx?.actingOrgId;\n\tconst orgs = getOrganizationProvider();\n\t// Single batch read for platform permissions instead of N round-trips.\n\tconst userIds = page.items.map((u) => u.id);\n\tconst platformByUser = await getPermissionStore().getForBatch(locals.ctx!, userIds);\n\t// One membership listing instead of a getOrgMember round-trip per user.\n\tconst memberByUserId = new Map<string, OrgMember>();\n\tif (orgId) {\n\t\tfor (const m of await listAllOrgMembers(orgs, orgId, locals.log))\n\t\t\tmemberByUserId.set(m.userId, m);\n\t}\n\tconst users = page.items.map((u) => {\n\t\tconst member = memberByUserId.get(u.id);\n\t\treturn {\n\t\t\t...u,\n\t\t\tplatformPermissions: platformByUser.get(u.id) ?? [],\n\t\t\torgRole: member?.role,\n\t\t\torgPermissions: member ? [...member.permissions] : []\n\t\t};\n\t});\n\treturn json({ users });\n});\n\n// POST — create a user + attach to default org with split permissions.\nexport const POST: RequestHandler = apiRoute(\n\t'Failed to create user',\n\tasync ({ request, locals }) => {\n\t\trequireManageInstanceUsers(locals);\n\t\tconst auth = getAuthProvider();\n\n\t\tconst { email, permissions: platform } = await parseBody(request, CreateUserBody);\n\n\t\tassertCanGrantPlatformPermissions(locals.ctx!, platform);\n\n\t\tlet user;\n\t\tif (auth.createUser) {\n\t\t\t// No password branch: a provider that owns credentials admits users by\n\t\t\t// invite, so nobody but the account holder ever chooses the password.\n\t\t\t// `createUser` is the allowlist path — under header-auth it is the only\n\t\t\t// way in, since the IdP holds the credential and Selva never sees one.\n\t\t\tuser = await auth.createUser(email);\n\t\t} else {\n\t\t\tapiError(\n\t\t\t\t501,\n\t\t\t\tApiErrorCode.INTERNAL,\n\t\t\t\t`${auth.name} cannot create a user directly. Send an invite instead — the recipient sets their own password.`\n\t\t\t);\n\t\t}\n\n\t\tawait getEventSink().emit({\n\t\t\ttype: 'user.created',\n\t\t\tuserId: user.id,\n\t\t\tactorId: actorFrom(locals.ctx!)\n\t\t});\n\n\t\t// The permission store writes to the data-layer row, which the hook seeds\n\t\t// only on the user's first request.\n\t\tawait getDataProvider().ensureUser(SYSTEM_CONTEXT, user.id);\n\n\t\t// Attach to the active org as a bare member. Under header-auth this is the\n\t\t// only way in — the IdP holds the credential, so there is no invite to\n\t\t// accept. Org permissions are granted separately at /team/members.\n\t\tconst orgId = locals.ctx?.actingOrgId;\n\t\tif (orgId) {\n\t\t\tconst joinedAt = new Date().toISOString();\n\t\t\tawait getOrganizationProvider().addOrgMember(SYSTEM_CONTEXT, {\n\t\t\t\torgId,\n\t\t\t\tuserId: user.id,\n\t\t\t\trole: 'member',\n\t\t\t\tpermissions: [],\n\t\t\t\tjoinedAt,\n\t\t\t\tupdatedAt: joinedAt,\n\t\t\t\tupdatedBy: locals.user?.id ?? user.id,\n\t\t\t\tdeletedAt: null\n\t\t\t});\n\t\t}\n\n\t\t// Last, so a refused grant leaves an admitted user the admin can grant again from the list.\n\t\tif (platform.length > 0) {\n\t\t\tconst granted = await setUserPlatformPermissions(locals.ctx!, user.id, platform);\n\t\t\tif (granted !== 'ok') {\n\t\t\t\tapiError(\n\t\t\t\t\t500,\n\t\t\t\t\tApiErrorCode.INTERNAL,\n\t\t\t\t\t`The user was created, but their platform permissions were not granted (${granted}). Grant them from the user list.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn created(user);\n\t}\n);\n"],"mappings":";;;;;;;;;;;;;AA8BA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ACA,aAAa,UACb,GAAG,KAAK,KAAK,gGACd;CAGD,MAAM,aAAa,CAAC,CAAC,KAAK;EACzB,MAAM;EACN,QAAQ,KAAK;EACb,SAAS,UAAU,OAAO,GAAI;CAC/B,CAAC;CAID,MAAM,gBAAgB,CAAC,CAAC,WAAW,gBAAgB,KAAK,EAAE;CAK1D,MAAM,QAAQ,OAAO,KAAK;CAC1B,IAAI,OAAO;EACV,MAAM,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;EACxC,MAAM,wBAAwB,CAAC,CAAC,aAAa,gBAAgB;GAC5D;GACA,QAAQ,KAAK;GACb,MAAM;GACN,aAAa,CAAC;GACd;GACA,WAAW;GACX,WAAW,OAAO,MAAM,MAAM,KAAK;GACnC,WAAW;EACZ,CAAC;CACF;CAGA,IAAI,SAAS,SAAS,GAAG;EACxB,MAAM,UAAU,MAAM,2BAA2B,OAAO,KAAM,KAAK,IAAI,QAAQ;EAC/E,IAAI,YAAY,MACf,SACC,KACA,aAAa,UACb,0EAA0E,QAAQ,kCACnF;CAEF;CAEA,OAAO,QAAQ,IAAI;AACpB,CACD"}
@@ -1,9 +1,11 @@
1
- import { B as classifyAssetPath, G as definitionPaths, s as getDefinitionMeta, x as getStorageProvider } from "../../../../../chunks/providers.server.js";
2
- import { E as scoped, g as requireCanViewProject, k as ApiErrorCode } from "../../../../../chunks/access.js";
1
+ import { B as classifyAssetPath, G as definitionPaths, x as getStorageProvider } from "../../../../../chunks/providers.server.js";
2
+ import { k as ApiErrorCode, n as accessDepsFromConfig } from "../../../../../chunks/access.js";
3
3
  import { t as COVER_IMAGE_CONTENT_TYPES } from "../../../../../chunks/types2.js";
4
4
  import { r as GuidSchema } from "../../../../../chunks/schemas.js";
5
+ import { n as getVisibleDefinition } from "../../../../../chunks/visibility.js";
6
+ import "../../../../../chunks/definitions.js";
5
7
  import { t as apiError } from "../../../../../chunks/api-errors.js";
6
- import { t as asHttpError } from "../../../../../chunks/access2.server.js";
8
+ import "../../../../../chunks/access2.server.js";
7
9
  // src/routes/api/files/[...path]/+server.ts
8
10
  /**
9
11
  * Authenticated/­public blob proxy. The set of servable paths is the closed
@@ -14,8 +16,8 @@ import { t as asHttpError } from "../../../../../chunks/access2.server.js";
14
16
  * - `public` (org branding — logo/favicon): served to anyone, incl.
15
17
  * logged-out visitors, with no auth. Cacheable. The bytes are always a
16
18
  * rasterized WebP, so there is no XSS surface to gate.
17
- * - `project` (definition covers): `requireCanViewProject(projectId)` — the
18
- * M5 hardening, unchanged.
19
+ * - `project` (definition covers): the caller must be able to view the
20
+ * definition's project, by the same rule as definition reads.
19
21
  *
20
22
  * Anything that classifies to no asset class 404s. New blob types are opt-in:
21
23
  * add a registry entry with the right visibility — never a generic
@@ -45,9 +47,7 @@ var GET = async ({ params, locals }) => {
45
47
  const guid = match.scopeId;
46
48
  const guidParsed = GuidSchema.safeParse(guid);
47
49
  if (!guidParsed.success) apiError(404, ApiErrorCode.NOT_FOUND, "File not found");
48
- const record = await getDefinitionMeta().get(locals.ctx, guidParsed.data);
49
- if (!record) apiError(404, ApiErrorCode.NOT_FOUND, "File not found");
50
- await asHttpError(() => requireCanViewProject(scoped(locals), record.projectId));
50
+ if (!await getVisibleDefinition(locals.ctx, guidParsed.data, accessDepsFromConfig(locals.providers))) apiError(404, ApiErrorCode.NOT_FOUND, "File not found");
51
51
  canonicalPath = definitionPaths.image(guidParsed.data);
52
52
  break;
53
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/api/files/[...path]/+server.ts"],"sourcesContent":["import type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport {\n\tGuidSchema,\n\tdefinitionPaths,\n\tclassifyAssetPath,\n\tCOVER_IMAGE_CONTENT_TYPES\n} from '@selvajs/platform';\nimport { getDefinitionMeta, getStorageProvider } from '#lib/server/providers.server.js';\nimport { asHttpError, requireCanViewProject, scoped } from '#lib/server/access.server.js';\n\n/**\n * Authenticated/­public blob proxy. The set of servable paths is the closed\n * asset-class registry (`classifyAssetPath` / `ASSET_CLASSES` in\n * `@selvajs/platform`). Each class declares a visibility; this route maps that\n * visibility to an authorization check:\n *\n * - `public` (org branding — logo/favicon): served to anyone, incl.\n * logged-out visitors, with no auth. Cacheable. The bytes are always a\n * rasterized WebP, so there is no XSS surface to gate.\n * - `project` (definition covers): `requireCanViewProject(projectId)` — the\n * M5 hardening, unchanged.\n *\n * Anything that classifies to no asset class 404s. New blob types are opt-in:\n * add a registry entry with the right visibility — never a generic\n * \"is the extension allowed\" fallthrough. Authorization lives here (the route),\n * not in the storage layer, per `IStorageProvider`'s contract.\n *\n * Why a single proxy: with the registry, the route is no longer a\n * pile of per-shape branches — it classifies once and dispatches on visibility,\n * so the cover-only contract that this route used to pin now generalizes\n * without re-opening the M5 hole.\n */\n\n// Content types we set on served blobs. Image types are reused from the\n// canonical `COVER_IMAGE_CONTENT_TYPES` so cover/branding stay in lockstep with\n// the upload validation. Deliberately NO `image/svg+xml`: no\n// registered class serves SVG (branding is always rasterized WebP), and\n// serving raw SVG would reintroduce the XSS surface the transcoder removes.\n// Anything not listed falls back to `application/octet-stream` (download, not\n// inline-render).\nconst CONTENT_TYPE_BY_EXT: Record<string, string> = COVER_IMAGE_CONTENT_TYPES;\n\nfunction contentTypeFor(storagePath: string): string {\n\tconst dot = storagePath.lastIndexOf('.');\n\tconst ext = dot === -1 ? '' : storagePath.slice(dot).toLowerCase();\n\treturn CONTENT_TYPE_BY_EXT[ext] ?? 'application/octet-stream';\n}\n\nexport const GET: RequestHandler = async ({ params, locals }) => {\n\tconst storagePath = params.path;\n\tif (!storagePath) apiError(400, ApiErrorCode.VALIDATION_FAILED, 'Missing path');\n\n\t// 1. Classify against the closed registry. No match → unservable → 404.\n\tconst match = classifyAssetPath(storagePath);\n\tif (!match) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t// 2. Authorize per the class's visibility, and resolve the canonical\n\t// storage path to read from. For `project` we re-derive the path from\n\t// `definitionPaths` rather than echoing the request — eliminates any\n\t// chance the matched path resolves to something else after decoding.\n\tlet canonicalPath = storagePath;\n\n\tswitch (match.class.visibility) {\n\t\tcase 'public':\n\t\t\t// No auth — branding is world-readable. The registry's anchored,\n\t\t\t// safe-alphabet pattern is the only gate the path needs.\n\t\t\tbreak;\n\n\t\tcase 'project': {\n\t\t\tif (!locals.ctx) apiError(401, ApiErrorCode.UNAUTHORIZED, 'Unauthorized');\n\t\t\tconst guid = match.scopeId;\n\t\t\tconst guidParsed = GuidSchema.safeParse(guid);\n\t\t\tif (!guidParsed.success) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t\t\tconst record = await getDefinitionMeta().get(locals.ctx, guidParsed.data);\n\t\t\tif (!record) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\t\t\tawait asHttpError(() => requireCanViewProject(scoped(locals), record.projectId));\n\n\t\t\tcanonicalPath = definitionPaths.image(guidParsed.data);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t// 3. Stream the bytes.\n\tconst bytes = await getStorageProvider().get(canonicalPath);\n\tif (!bytes) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t// Public branding is CDN-cacheable; everything else is per-user private.\n\tconst cacheControl =\n\t\tmatch.class.visibility === 'public' ? 'public, max-age=3600' : 'private, max-age=3600';\n\n\treturn new Response(Buffer.from(bytes), {\n\t\theaders: {\n\t\t\t'Content-Type': contentTypeFor(canonicalPath),\n\t\t\t'Cache-Control': cacheControl\n\t\t}\n\t});\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAM,sBAA8C;AAEpD,SAAS,eAAe,aAA6B;CACpD,MAAM,MAAM,YAAY,YAAY,GAAG;CAEvC,OAAO,oBADK,QAAQ,KAAK,KAAK,YAAY,MAAM,GAAG,CAAC,CAAC,YAAY,MAC9B;AACpC;AAEA,IAAa,MAAsB,OAAO,EAAE,QAAQ,aAAa;CAChE,MAAM,cAAc,OAAO;CAC3B,IAAI,CAAC,aAAa,SAAS,KAAK,aAAa,mBAAmB,cAAc;CAG9E,MAAM,QAAQ,kBAAkB,WAAW;CAC3C,IAAI,CAAC,OAAO,SAAS,KAAK,aAAa,WAAW,gBAAgB;CAMlE,IAAI,gBAAgB;CAEpB,QAAQ,MAAM,MAAM,YAApB;EACC,KAAK,UAGJ;EAED,KAAK,WAAW;GACf,IAAI,CAAC,OAAO,KAAK,SAAS,KAAK,aAAa,cAAc,cAAc;GACxE,MAAM,OAAO,MAAM;GACnB,MAAM,aAAa,WAAW,UAAU,IAAI;GAC5C,IAAI,CAAC,WAAW,SAAS,SAAS,KAAK,aAAa,WAAW,gBAAgB;GAE/E,MAAM,SAAS,MAAM,kBAAkB,CAAC,CAAC,IAAI,OAAO,KAAK,WAAW,IAAI;GACxE,IAAI,CAAC,QAAQ,SAAS,KAAK,aAAa,WAAW,gBAAgB;GACnE,MAAM,kBAAkB,sBAAsB,OAAO,MAAM,GAAG,OAAO,SAAS,CAAC;GAE/E,gBAAgB,gBAAgB,MAAM,WAAW,IAAI;GACrD;EACD;CACD;CAGA,MAAM,QAAQ,MAAM,mBAAmB,CAAC,CAAC,IAAI,aAAa;CAC1D,IAAI,CAAC,OAAO,SAAS,KAAK,aAAa,WAAW,gBAAgB;CAGlE,MAAM,eACL,MAAM,MAAM,eAAe,WAAW,yBAAyB;CAEhE,OAAO,IAAI,SAAS,OAAO,KAAK,KAAK,GAAG,EACvC,SAAS;EACR,gBAAgB,eAAe,aAAa;EAC5C,iBAAiB;CAClB,EACD,CAAC;AACF"}
1
+ {"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/api/files/[...path]/+server.ts"],"sourcesContent":["import type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport {\n\tGuidSchema,\n\tdefinitionPaths,\n\tclassifyAssetPath,\n\tCOVER_IMAGE_CONTENT_TYPES\n} from '@selvajs/platform';\nimport { getVisibleDefinition } from '@selvajs/server/definitions';\nimport { getStorageProvider } from '#lib/server/providers.server.js';\nimport { accessDepsFromConfig } from '#lib/server/access.server.js';\n\n/**\n * Authenticated/­public blob proxy. The set of servable paths is the closed\n * asset-class registry (`classifyAssetPath` / `ASSET_CLASSES` in\n * `@selvajs/platform`). Each class declares a visibility; this route maps that\n * visibility to an authorization check:\n *\n * - `public` (org branding — logo/favicon): served to anyone, incl.\n * logged-out visitors, with no auth. Cacheable. The bytes are always a\n * rasterized WebP, so there is no XSS surface to gate.\n * - `project` (definition covers): the caller must be able to view the\n * definition's project, by the same rule as definition reads.\n *\n * Anything that classifies to no asset class 404s. New blob types are opt-in:\n * add a registry entry with the right visibility — never a generic\n * \"is the extension allowed\" fallthrough. Authorization lives here (the route),\n * not in the storage layer, per `IStorageProvider`'s contract.\n *\n * Why a single proxy: with the registry, the route is no longer a\n * pile of per-shape branches — it classifies once and dispatches on visibility,\n * so the cover-only contract that this route used to pin now generalizes\n * without re-opening the M5 hole.\n */\n\n// Content types we set on served blobs. Image types are reused from the\n// canonical `COVER_IMAGE_CONTENT_TYPES` so cover/branding stay in lockstep with\n// the upload validation. Deliberately NO `image/svg+xml`: no\n// registered class serves SVG (branding is always rasterized WebP), and\n// serving raw SVG would reintroduce the XSS surface the transcoder removes.\n// Anything not listed falls back to `application/octet-stream` (download, not\n// inline-render).\nconst CONTENT_TYPE_BY_EXT: Record<string, string> = COVER_IMAGE_CONTENT_TYPES;\n\nfunction contentTypeFor(storagePath: string): string {\n\tconst dot = storagePath.lastIndexOf('.');\n\tconst ext = dot === -1 ? '' : storagePath.slice(dot).toLowerCase();\n\treturn CONTENT_TYPE_BY_EXT[ext] ?? 'application/octet-stream';\n}\n\nexport const GET: RequestHandler = async ({ params, locals }) => {\n\tconst storagePath = params.path;\n\tif (!storagePath) apiError(400, ApiErrorCode.VALIDATION_FAILED, 'Missing path');\n\n\t// 1. Classify against the closed registry. No match → unservable → 404.\n\tconst match = classifyAssetPath(storagePath);\n\tif (!match) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t// 2. Authorize per the class's visibility, and resolve the canonical\n\t// storage path to read from. For `project` we re-derive the path from\n\t// `definitionPaths` rather than echoing the request — eliminates any\n\t// chance the matched path resolves to something else after decoding.\n\tlet canonicalPath = storagePath;\n\n\tswitch (match.class.visibility) {\n\t\tcase 'public':\n\t\t\t// No auth — branding is world-readable. The registry's anchored,\n\t\t\t// safe-alphabet pattern is the only gate the path needs.\n\t\t\tbreak;\n\n\t\tcase 'project': {\n\t\t\tif (!locals.ctx) apiError(401, ApiErrorCode.UNAUTHORIZED, 'Unauthorized');\n\t\t\tconst guid = match.scopeId;\n\t\t\tconst guidParsed = GuidSchema.safeParse(guid);\n\t\t\tif (!guidParsed.success) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t\t\t// 404, not 403, for a cover the caller can't view: a 403 would confirm the guid exists.\n\t\t\tconst record = await getVisibleDefinition(\n\t\t\t\tlocals.ctx,\n\t\t\t\tguidParsed.data,\n\t\t\t\taccessDepsFromConfig(locals.providers)\n\t\t\t);\n\t\t\tif (!record) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t\t\tcanonicalPath = definitionPaths.image(guidParsed.data);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t// 3. Stream the bytes.\n\tconst bytes = await getStorageProvider().get(canonicalPath);\n\tif (!bytes) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t// Public branding is CDN-cacheable; everything else is per-user private.\n\tconst cacheControl =\n\t\tmatch.class.visibility === 'public' ? 'public, max-age=3600' : 'private, max-age=3600';\n\n\treturn new Response(Buffer.from(bytes), {\n\t\theaders: {\n\t\t\t'Content-Type': contentTypeFor(canonicalPath),\n\t\t\t'Cache-Control': cacheControl\n\t\t}\n\t});\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAM,sBAA8C;AAEpD,SAAS,eAAe,aAA6B;CACpD,MAAM,MAAM,YAAY,YAAY,GAAG;CAEvC,OAAO,oBADK,QAAQ,KAAK,KAAK,YAAY,MAAM,GAAG,CAAC,CAAC,YAAY,MAC9B;AACpC;AAEA,IAAa,MAAsB,OAAO,EAAE,QAAQ,aAAa;CAChE,MAAM,cAAc,OAAO;CAC3B,IAAI,CAAC,aAAa,SAAS,KAAK,aAAa,mBAAmB,cAAc;CAG9E,MAAM,QAAQ,kBAAkB,WAAW;CAC3C,IAAI,CAAC,OAAO,SAAS,KAAK,aAAa,WAAW,gBAAgB;CAMlE,IAAI,gBAAgB;CAEpB,QAAQ,MAAM,MAAM,YAApB;EACC,KAAK,UAGJ;EAED,KAAK,WAAW;GACf,IAAI,CAAC,OAAO,KAAK,SAAS,KAAK,aAAa,cAAc,cAAc;GACxE,MAAM,OAAO,MAAM;GACnB,MAAM,aAAa,WAAW,UAAU,IAAI;GAC5C,IAAI,CAAC,WAAW,SAAS,SAAS,KAAK,aAAa,WAAW,gBAAgB;GAQ/E,IAAI,CAAC,MALgB,qBACpB,OAAO,KACP,WAAW,MACX,qBAAqB,OAAO,SAAS,CACtC,GACa,SAAS,KAAK,aAAa,WAAW,gBAAgB;GAEnE,gBAAgB,gBAAgB,MAAM,WAAW,IAAI;GACrD;EACD;CACD;CAGA,MAAM,QAAQ,MAAM,mBAAmB,CAAC,CAAC,IAAI,aAAa;CAC1D,IAAI,CAAC,OAAO,SAAS,KAAK,aAAa,WAAW,gBAAgB;CAGlE,MAAM,eACL,MAAM,MAAM,eAAe,WAAW,yBAAyB;CAEhE,OAAO,IAAI,SAAS,OAAO,KAAK,KAAK,GAAG,EACvC,SAAS;EACR,gBAAgB,eAAe,aAAa;EAC5C,iBAAiB;CAClB,EACD,CAAC;AACF"}
@@ -2,7 +2,7 @@ import { k as ApiErrorCode } from "../../../../../chunks/access.js";
2
2
  import { t as apiError } from "../../../../../chunks/api-errors.js";
3
3
  import { n as COMPUTE_REQUEST_MAX_BYTES } from "../../../../../chunks/computeLimits.js";
4
4
  import { l as requireMaxBodySize } from "../../../../../chunks/admin-auth.server.js";
5
- import { t as tryResolveShareToken } from "../../../../../chunks/resolve.server.js";
5
+ import { n as tryResolveShareToken } from "../../../../../chunks/resolve.server.js";
6
6
  import { n as runSolve, t as mapSolveError } from "../../../../../chunks/solve.server.js";
7
7
  // src/routes/api/v1/compute/+server.ts
8
8
  var POST = async ({ request, locals, url }) => {
@@ -3,8 +3,8 @@ import { k as ApiErrorCode } from "../../../../../../../chunks/access.js";
3
3
  import { C as readIdempotencyKey, H as requireParams, R as parseBody, S as idempotencyCallerId, T as runIdempotent, h as SolveBodySchema, w as requestFingerprint, x as createApiIdempotencyStore } from "../../../../../../../chunks/api.js";
4
4
  import { r as withApiRateLimit } from "../../../../../../../chunks/sveltekit.js";
5
5
  import { n as handleApiError, t as apiError } from "../../../../../../../chunks/api-errors.js";
6
- import { n as COMPUTE_REQUEST_MAX_BYTES } from "../../../../../../../chunks/computeLimits.js";
7
6
  import { i as requireCaller } from "../../../../../../../chunks/http2.js";
7
+ import { n as COMPUTE_REQUEST_MAX_BYTES } from "../../../../../../../chunks/computeLimits.js";
8
8
  import { l as requireMaxBodySize } from "../../../../../../../chunks/admin-auth.server.js";
9
9
  import { n as runSolve, t as mapSolveError } from "../../../../../../../chunks/solve.server.js";
10
10
  var solveIdempotencyStore = createApiIdempotencyStore(3e5);