Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
refactor(control-api): extract discoveryHttpStatus to a shared module
Diego Zacariasf91ef126b098
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex aa041be5d..07501440f 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.605",+ "version": "0.1.606","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.605",+ "version": "0.1.606","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex adeb0d846..0f2f7f103 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.605",+ "version": "0.1.606","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/oauth/discoveryHttpStatus.ts b/control-api/src/oauth/discoveryHttpStatus.tsnew file mode 100644index 000000000..ae99210ec--- /dev/null+++ b/control-api/src/oauth/discoveryHttpStatus.ts@@ -0,0 +1,35 @@+import type { DiscoveryError } from './discovery.js'++/**+ * Map a discovery failure to an HTTP status for the OAuth discovery admin endpoints+ * (remote `POST /admin/mcp-servers/remote/discover` and generic+ * `POST /admin/oauth/discover`). Extracted here (H-5) so both share ONE mapping.+ *+ * `fetch_failed` and `content_encoding_rejected` are upstream transport failures —+ * the AS never returned a usable HTTP response — so they surface as 502, the same+ * way the callback maps provider fetch failures (`provider_token_exchange_failed` /+ * `provider_response_invalid` → 502). Every other kind is either bad operator input+ * (`kernel_rejected`) or a reachable-but-incompatible/misconfigured AS: retrying will+ * not help, and the returned `detail.kind` tells the operator what to fix, so 400 is+ * the operator-actionable signal. The switch is exhaustive over `DiscoveryError` so a+ * newly added kind fails to compile until its status is decided here.+ */+export function discoveryHttpStatus(error: DiscoveryError): number {+ switch (error.kind) {+ case 'fetch_failed':+ case 'content_encoding_rejected':+ return 502+ case 'kernel_rejected':+ case 'invalid_metadata':+ case 'no_s256':+ case 'no_authorization_server':+ case 'redirect_blocked':+ case 'prm_resource_mismatch':+ case 'issuer_mismatch':+ return 400+ default: {+ const _exhaustive: never = error+ return 400+ }+ }+}diff --git a/control-api/src/routes/admin/remoteMcp.ts b/control-api/src/routes/admin/remoteMcp.tsindex 9a87a9826..cc62bf39e 100644--- a/control-api/src/routes/admin/remoteMcp.ts+++ b/control-api/src/routes/admin/remoteMcp.ts@@ -17,11 +17,8 @@ import {registerDynamicClient,} from '../../oauth/dcr.js'import { bestEffortRfc7592Delete } from '../../oauth/dcrCleanup.js'-import {- type DiscoveryError,- type DiscoveryResult,- discoverRemoteOAuth,-} from '../../oauth/discovery.js'+import { type DiscoveryResult, discoverRemoteOAuth } from '../../oauth/discovery.js'+import { discoveryHttpStatus } from '../../oauth/discoveryHttpStatus.js'import {type DynamicClientKey,deleteDynamicClient,@@ -63,37 +60,10 @@ const BASE = '/admin/mcp-servers/remote'const log = rootLogger.child({ module: 'admin-remote-mcp' })-/**- * Map a discovery failure to an HTTP status for the remote-OAuth admin endpoints.- *- * `fetch_failed` and `content_encoding_rejected` are upstream transport failures —- * the AS never returned a usable HTTP response — so they surface as 502, the same- * way the callback maps provider fetch failures (`provider_token_exchange_failed` /- * `provider_response_invalid` → 502). Every other kind is either bad operator input- * (`kernel_rejected`) or a reachable-but-incompatible/misconfigured AS: retrying will- * not help, and the returned `detail.kind` tells the operator what to fix, so 400 is- * the operator-actionable signal. The switch is exhaustive over `DiscoveryError` so a- * newly added kind fails to compile until its status is decided here.- */-export function discoveryHttpStatus(error: DiscoveryError): number {- switch (error.kind) {- case 'fetch_failed':- case 'content_encoding_rejected':- return 502- case 'kernel_rejected':- case 'invalid_metadata':- case 'no_s256':- case 'no_authorization_server':- case 'redirect_blocked':- case 'prm_resource_mismatch':- case 'issuer_mismatch':- return 400- default: {- const _exhaustive: never = error- return 400- }- }-}+// `discoveryHttpStatus` moved to `oauth/discoveryHttpStatus.js` (H-5) so the remote+// and generic discover endpoints share one mapping. Re-exported here so existing+// importers (and the mapping's own test) keep resolving it from this module.+export { discoveryHttpStatus }const discoverBodySchema = z.object({baseUrl: z.string().min(1),