@selvajs/selva 4.20.0-beta.28 → 4.20.0-beta.29

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 (158) hide show
  1. package/build/adapter-node.js +1 -1
  2. package/build/client/_app/immutable/assets/0.DwB0QWdx.css +2 -0
  3. package/build/client/_app/immutable/assets/0.DwB0QWdx.css.br +0 -0
  4. package/build/client/_app/immutable/assets/0.DwB0QWdx.css.gz +0 -0
  5. package/build/client/_app/immutable/assets/21.CZQvs3vE.css +1 -0
  6. package/build/client/_app/immutable/assets/21.CZQvs3vE.css.br +0 -0
  7. package/build/client/_app/immutable/assets/21.CZQvs3vE.css.gz +0 -0
  8. package/build/client/_app/immutable/chunks/6oDkMEbX.js +6056 -0
  9. package/build/client/_app/immutable/chunks/6oDkMEbX.js.br +0 -0
  10. package/build/client/_app/immutable/chunks/6oDkMEbX.js.gz +0 -0
  11. package/build/client/_app/immutable/chunks/B9IvNrzX.js +1 -0
  12. package/build/client/_app/immutable/chunks/B9IvNrzX.js.br +1 -0
  13. package/build/client/_app/immutable/chunks/B9IvNrzX.js.gz +0 -0
  14. package/build/client/_app/immutable/chunks/{B8sELCD1.js → C6Y_BUwr.js} +1 -1
  15. package/build/client/_app/immutable/chunks/C6Y_BUwr.js.br +0 -0
  16. package/build/client/_app/immutable/chunks/C6Y_BUwr.js.gz +0 -0
  17. package/build/client/_app/immutable/chunks/{CV8nlyG8.js → CzfnuBzq.js} +1 -1
  18. package/build/client/_app/immutable/chunks/CzfnuBzq.js.br +0 -0
  19. package/build/client/_app/immutable/chunks/CzfnuBzq.js.gz +0 -0
  20. package/build/client/_app/immutable/chunks/DQsP4nZb.js +1 -0
  21. package/build/client/_app/immutable/chunks/DQsP4nZb.js.br +0 -0
  22. package/build/client/_app/immutable/chunks/DQsP4nZb.js.gz +0 -0
  23. package/build/client/_app/immutable/chunks/{B54S3nTL.js → DVcao28H.js} +1 -1
  24. package/build/client/_app/immutable/chunks/DVcao28H.js.br +0 -0
  25. package/build/client/_app/immutable/chunks/DVcao28H.js.gz +0 -0
  26. package/build/client/_app/immutable/chunks/{DNn0nzek.js → DbTdXFSI.js} +1 -1
  27. package/build/client/_app/immutable/chunks/DbTdXFSI.js.br +0 -0
  28. package/build/client/_app/immutable/chunks/DbTdXFSI.js.gz +0 -0
  29. package/build/client/_app/immutable/chunks/DnJObvmm.js +1 -0
  30. package/build/client/_app/immutable/chunks/DnJObvmm.js.br +0 -0
  31. package/build/client/_app/immutable/chunks/DnJObvmm.js.gz +0 -0
  32. package/build/client/_app/immutable/chunks/{jZMNULqI.js → DyqtDkQe.js} +1 -1
  33. package/build/client/_app/immutable/chunks/DyqtDkQe.js.br +0 -0
  34. package/build/client/_app/immutable/chunks/DyqtDkQe.js.gz +0 -0
  35. package/build/client/_app/immutable/entry/app.q5GmHZh7.js +2 -0
  36. package/build/client/_app/immutable/entry/app.q5GmHZh7.js.br +0 -0
  37. package/build/client/_app/immutable/entry/app.q5GmHZh7.js.gz +0 -0
  38. package/build/client/_app/immutable/nodes/{1.DFtA_OEY.js → 1.D3kiiIk_.js} +1 -1
  39. package/build/client/_app/immutable/nodes/1.D3kiiIk_.js.br +0 -0
  40. package/build/client/_app/immutable/nodes/1.D3kiiIk_.js.gz +0 -0
  41. package/build/client/_app/immutable/nodes/{2.CkTe-0F-.js → 2.c6X0ddnS.js} +1 -1
  42. package/build/client/_app/immutable/nodes/2.c6X0ddnS.js.br +0 -0
  43. package/build/client/_app/immutable/nodes/2.c6X0ddnS.js.gz +0 -0
  44. package/build/client/_app/immutable/nodes/{20.ClCOkXtk.js → 20.CyrNl6i7.js} +1 -1
  45. package/build/client/_app/immutable/nodes/20.CyrNl6i7.js.br +0 -0
  46. package/build/client/_app/immutable/nodes/20.CyrNl6i7.js.gz +0 -0
  47. package/build/client/_app/immutable/nodes/21._AcAMXtP.js +1 -0
  48. package/build/client/_app/immutable/nodes/21._AcAMXtP.js.br +0 -0
  49. package/build/client/_app/immutable/nodes/21._AcAMXtP.js.gz +0 -0
  50. package/build/client/_app/immutable/nodes/{22.3c2Ar-_L.js → 22.q4pJo1Ec.js} +4 -4
  51. package/build/client/_app/immutable/nodes/22.q4pJo1Ec.js.br +0 -0
  52. package/build/client/_app/immutable/nodes/22.q4pJo1Ec.js.gz +0 -0
  53. package/build/client/_app/immutable/nodes/{25.C-dvoLm5.js → 25.DW1_vMxq.js} +1 -1
  54. package/build/client/_app/immutable/nodes/25.DW1_vMxq.js.br +0 -0
  55. package/build/client/_app/immutable/nodes/25.DW1_vMxq.js.gz +0 -0
  56. package/build/client/_app/immutable/nodes/{3.CLRvY4Pw.js → 3.3Z4QUsQQ.js} +1 -1
  57. package/build/client/_app/immutable/nodes/3.3Z4QUsQQ.js.br +0 -0
  58. package/build/client/_app/immutable/nodes/3.3Z4QUsQQ.js.gz +0 -0
  59. package/build/client/_app/immutable/nodes/{5.Ce6v0yql.js → 5.Ck6I7GRI.js} +1 -1
  60. package/build/client/_app/immutable/nodes/5.Ck6I7GRI.js.br +0 -0
  61. package/build/client/_app/immutable/nodes/5.Ck6I7GRI.js.gz +0 -0
  62. package/build/client/_app/immutable/nodes/{6.TFeDtO3j.js → 6.BiSiWLjz.js} +1 -1
  63. package/build/client/_app/immutable/nodes/6.BiSiWLjz.js.br +0 -0
  64. package/build/client/_app/immutable/nodes/6.BiSiWLjz.js.gz +0 -0
  65. package/build/client/_app/immutable/nodes/{7.CTdUnooR.js → 7.OTA16TkX.js} +1 -1
  66. package/build/client/_app/immutable/nodes/7.OTA16TkX.js.br +0 -0
  67. package/build/client/_app/immutable/nodes/7.OTA16TkX.js.gz +0 -0
  68. package/build/client/_app/version.json +1 -1
  69. package/build/client/_app/version.json.br +0 -0
  70. package/build/client/_app/version.json.gz +0 -0
  71. package/build/server/.vite/manifest.json +2 -2
  72. package/build/server/_app/immutable/assets/_layout.DwB0QWdx.css +2 -0
  73. package/build/server/_app/immutable/assets/_page.BLIssNhc.css +1 -0
  74. package/build/server/chunks/handlers.js +3 -1
  75. package/build/server/chunks/handlers.js.map +1 -1
  76. package/build/server/chunks/instance.js +3 -3
  77. package/build/server/chunks/internal.js +1 -1
  78. package/build/server/chunks/localeContext.svelte.js +6 -0
  79. package/build/server/chunks/localeContext.svelte.js.map +1 -1
  80. package/build/server/chunks/package.js +1 -1
  81. package/build/server/chunks/package.js.map +1 -1
  82. package/build/server/chunks/providers.server.js +23 -3
  83. package/build/server/chunks/providers.server.js.map +1 -1
  84. package/build/server/chunks/server-config-write.js +27 -1
  85. package/build/server/chunks/server-config-write.js.map +1 -1
  86. package/build/server/entries/endpoints/api/admin/compute/_server.ts.js +2 -1
  87. package/build/server/entries/endpoints/api/admin/compute/_server.ts.js.map +1 -1
  88. package/build/server/entries/pages/library/_guid_/_page.svelte.js +6521 -6124
  89. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  90. package/build/server/manifest-full.js +1 -1
  91. package/build/server/manifest.js +1 -1
  92. package/build/server/nodes/0.js +2 -2
  93. package/build/server/nodes/1.js +1 -1
  94. package/build/server/nodes/2.js +1 -1
  95. package/build/server/nodes/20.js +1 -1
  96. package/build/server/nodes/21.js +2 -2
  97. package/build/server/nodes/22.js +1 -1
  98. package/build/server/nodes/25.js +1 -1
  99. package/build/server/nodes/3.js +1 -1
  100. package/build/server/nodes/5.js +1 -1
  101. package/build/server/nodes/6.js +1 -1
  102. package/build/server/nodes/7.js +1 -1
  103. package/build/server/server.js +1 -1
  104. package/package.json +6 -6
  105. package/build/client/_app/immutable/assets/0.EoCnujqq.css +0 -2
  106. package/build/client/_app/immutable/assets/0.EoCnujqq.css.br +0 -0
  107. package/build/client/_app/immutable/assets/0.EoCnujqq.css.gz +0 -0
  108. package/build/client/_app/immutable/assets/21.Dy4MSSQ0.css +0 -1
  109. package/build/client/_app/immutable/assets/21.Dy4MSSQ0.css.br +0 -0
  110. package/build/client/_app/immutable/assets/21.Dy4MSSQ0.css.gz +0 -0
  111. package/build/client/_app/immutable/chunks/B54S3nTL.js.br +0 -0
  112. package/build/client/_app/immutable/chunks/B54S3nTL.js.gz +0 -0
  113. package/build/client/_app/immutable/chunks/B8sELCD1.js.br +0 -0
  114. package/build/client/_app/immutable/chunks/B8sELCD1.js.gz +0 -0
  115. package/build/client/_app/immutable/chunks/CV8nlyG8.js.br +0 -0
  116. package/build/client/_app/immutable/chunks/CV8nlyG8.js.gz +0 -0
  117. package/build/client/_app/immutable/chunks/CY_Y3bcW.js +0 -1
  118. package/build/client/_app/immutable/chunks/CY_Y3bcW.js.br +0 -0
  119. package/build/client/_app/immutable/chunks/CY_Y3bcW.js.gz +0 -0
  120. package/build/client/_app/immutable/chunks/DNn0nzek.js.br +0 -0
  121. package/build/client/_app/immutable/chunks/DNn0nzek.js.gz +0 -0
  122. package/build/client/_app/immutable/chunks/DkJKKB94.js +0 -1
  123. package/build/client/_app/immutable/chunks/DkJKKB94.js.br +0 -1
  124. package/build/client/_app/immutable/chunks/DkJKKB94.js.gz +0 -0
  125. package/build/client/_app/immutable/chunks/XiGvLmZI.js +0 -5906
  126. package/build/client/_app/immutable/chunks/XiGvLmZI.js.br +0 -0
  127. package/build/client/_app/immutable/chunks/XiGvLmZI.js.gz +0 -0
  128. package/build/client/_app/immutable/chunks/jZMNULqI.js.br +0 -0
  129. package/build/client/_app/immutable/chunks/jZMNULqI.js.gz +0 -0
  130. package/build/client/_app/immutable/entry/app.C4Xhz1j-.js +0 -2
  131. package/build/client/_app/immutable/entry/app.C4Xhz1j-.js.br +0 -0
  132. package/build/client/_app/immutable/entry/app.C4Xhz1j-.js.gz +0 -0
  133. package/build/client/_app/immutable/nodes/1.DFtA_OEY.js.br +0 -0
  134. package/build/client/_app/immutable/nodes/1.DFtA_OEY.js.gz +0 -0
  135. package/build/client/_app/immutable/nodes/2.CkTe-0F-.js.br +0 -0
  136. package/build/client/_app/immutable/nodes/2.CkTe-0F-.js.gz +0 -0
  137. package/build/client/_app/immutable/nodes/20.ClCOkXtk.js.br +0 -0
  138. package/build/client/_app/immutable/nodes/20.ClCOkXtk.js.gz +0 -0
  139. package/build/client/_app/immutable/nodes/21.j2ZNmKE0.js +0 -1
  140. package/build/client/_app/immutable/nodes/21.j2ZNmKE0.js.br +0 -1
  141. package/build/client/_app/immutable/nodes/21.j2ZNmKE0.js.gz +0 -0
  142. package/build/client/_app/immutable/nodes/22.3c2Ar-_L.js.br +0 -0
  143. package/build/client/_app/immutable/nodes/22.3c2Ar-_L.js.gz +0 -0
  144. package/build/client/_app/immutable/nodes/25.C-dvoLm5.js.br +0 -0
  145. package/build/client/_app/immutable/nodes/25.C-dvoLm5.js.gz +0 -0
  146. package/build/client/_app/immutable/nodes/3.CLRvY4Pw.js.br +0 -0
  147. package/build/client/_app/immutable/nodes/3.CLRvY4Pw.js.gz +0 -0
  148. package/build/client/_app/immutable/nodes/5.Ce6v0yql.js.br +0 -0
  149. package/build/client/_app/immutable/nodes/5.Ce6v0yql.js.gz +0 -0
  150. package/build/client/_app/immutable/nodes/6.TFeDtO3j.js.br +0 -0
  151. package/build/client/_app/immutable/nodes/6.TFeDtO3j.js.gz +0 -0
  152. package/build/client/_app/immutable/nodes/7.CTdUnooR.js.br +0 -0
  153. package/build/client/_app/immutable/nodes/7.CTdUnooR.js.gz +0 -0
  154. package/build/server/_app/immutable/assets/_layout.EoCnujqq.css +0 -2
  155. package/build/server/_app/immutable/assets/_page.BD9df-LS.css +0 -1
  156. /package/build/client/_app/immutable/nodes/{0.DTKs7-tx.js → 0.CC0wt5QB.js} +0 -0
  157. /package/build/client/_app/immutable/nodes/{0.DTKs7-tx.js.br → 0.CC0wt5QB.js.br} +0 -0
  158. /package/build/client/_app/immutable/nodes/{0.DTKs7-tx.js.gz → 0.CC0wt5QB.js.gz} +0 -0
@@ -100,6 +100,32 @@ function assertStoredKeysReadable(incoming, stored) {
100
100
  for (const s of incoming) if (unreadable.has(s.id) && (s.apiKey === void 0 || s.apiKey === "")) apiError(409, ApiErrorCode.CONFLICT, `The stored key for server ${s.id} cannot be decrypted. Restore the original SELVA_AT_REST_KEY, or re-enter the key.`);
101
101
  }
102
102
  /**
103
+ * An omitted key is kept, so without this check anyone who may save the config
104
+ * could point a server at their own host and have the next solve send them the
105
+ * stored key, which they never saw. Moving a server needs the key re-entered or
106
+ * cleared.
107
+ */
108
+ function assertKeyNotRetargeted(incoming, stored) {
109
+ const byId = new Map(stored.map((s) => [s.id, s]));
110
+ for (const s of incoming) {
111
+ const prev = byId.get(s.id);
112
+ if (!prev || !(prev.hasApiKey || prev.apiKey)) continue;
113
+ if (s.apiKey === null || typeof s.apiKey === "string" && s.apiKey !== "") continue;
114
+ if (sameServerUrl(prev.serverUrl, s.serverUrl)) continue;
115
+ apiError(409, ApiErrorCode.CONFLICT, `Server ${s.id} has a new URL. Re-enter its API key, or clear it, to save.`);
116
+ }
117
+ }
118
+ function sameServerUrl(a, b) {
119
+ const normalize = (u) => {
120
+ try {
121
+ return new URL(u.trim()).href.replace(/\/+$/, "");
122
+ } catch {
123
+ return u.trim().replace(/\/+$/, "");
124
+ }
125
+ };
126
+ return normalize(a) === normalize(b);
127
+ }
128
+ /**
103
129
  * The UI never receives stored keys — it sends back `hasApiKey` and omits the
104
130
  * field for servers the operator didn't touch. So "omitted" cannot mean "clear":
105
131
  * it has to preserve, or every save through the settings form would wipe the
@@ -119,6 +145,6 @@ function resolveApiKey(submitted, storedKey) {
119
145
  function storedKeysById(scopedServers) {
120
146
  return new Map(scopedServers.map((s) => [s.id, s.apiKey]));
121
147
  }
122
- export { evictChangedServers as a, validateIncomingServers as i, resolveApiKey as n, storedKeysById as r, assertStoredKeysReadable as t };
148
+ export { validateIncomingServers as a, storedKeysById as i, assertStoredKeysReadable as n, evictChangedServers as o, resolveApiKey as r, assertKeyNotRetargeted as t };
123
149
 
124
150
  //# 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 } 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 * 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;C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E,SAAS,KAAK,aAAa,mBAAmB,2CAA2C;EAG1F,IAAI,EAAE,UAAU,kBAAkB,EAAE,MAAM,GACzC,SAAS,KAAK,aAAa,mBAAmB,gCAAgC;CAChF;AACD;;;;;;;AAQA,SAAgB,yBACf,UACA,QACO;CACP,MAAM,aAAa,IAAI,IAAI,OAAO,QAAQ,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE,CAAC;CAC1F,KAAK,MAAM,KAAK,UACf,IAAI,WAAW,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,KAAA,KAAa,EAAE,WAAW,KACnE,SACC,KACA,aAAa,UACb,6BAA6B,EAAE,GAAG,mFACnC;AAGH;;;;;;;;;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 } 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 new URL(u.trim()).href.replace(/\\/+$/, '');\n\t\t} catch {\n\t\t\treturn u.trim().replace(/\\/+$/, '');\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.api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AW,GAAoB;CACrD,MAAM,aAAa,MAAc;EAChC,IAAI;GACH,OAAO,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,QAAQ,EAAE;EACjD,QAAQ;GACP,OAAO,EAAE,KAAK,CAAC,CAAC,QAAQ,QAAQ,EAAE;EACnC;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,7 +1,7 @@
1
1
  import { a as getComputeServerConfigStore } from "../../../../../chunks/providers.server.js";
2
2
  import { k as ApiErrorCode, y as requireManageCompute } from "../../../../../chunks/access.js";
3
3
  import { i as platformServers } from "../../../../../chunks/utils.js";
4
- import { a as evictChangedServers$1, i as validateIncomingServers, n as resolveApiKey, r as storedKeysById, t as assertStoredKeysReadable } from "../../../../../chunks/server-config-write.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";
5
5
  import "../../../../../chunks/compute.js";
6
6
  import { n as renderThrown } from "../../../../../chunks/definitions.js";
7
7
  import { t as apiError } from "../../../../../chunks/api-errors.js";
@@ -59,6 +59,7 @@ var PUT = async ({ request, locals }) => {
59
59
  const provider = getComputeServerConfigStore();
60
60
  const existing = await provider.getConfig(locals.ctx, { includeApiKeys: true });
61
61
  assertStoredKeysReadable(incoming.servers, platformServers(existing));
62
+ assertKeyNotRetargeted(incoming.servers, platformServers(existing));
62
63
  const storedKeys = storedKeysById(platformServers(existing));
63
64
  const next = incoming.servers.map(({ id, label, serverUrl, apiKey, sharedWith }) => ({
64
65
  id,
@@ -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\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\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;;ACsBA,IAAa,MAAsB,OAAO,E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AAU,OAAO,KAAM,EAAE,gBAAgB,KAAK,CAAC;EAC/E,yBAAyB,SAAS,SAAS,gBAAgB,QAAQ,CAAC;EACpE,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 { 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,M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