-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathendpoints.ts
More file actions
45 lines (40 loc) · 1.78 KB
/
Copy pathendpoints.ts
File metadata and controls
45 lines (40 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Central resolver for the managed (Atlas) backend base URL.
*
* The public client ships with a NEUTRAL default host — no internal
* deployment codename is ever baked into a public default string. Self-hosters
* and dev stacks override it via env. Every hardcoded backend URL in the CLI
* routes through here so there is a single seam between the open client and the
* closed backend.
*
* Resolution order (first non-empty wins):
* OPENSCIENCE_API_BASE — the current CLI override
* SYNSC_API_BASE — the historical CLI override (kept for back-compat)
* MANAGED_API_BASE — managed-backend override
* ATLAS_BASE_URL — alias for MANAGED_API_BASE
* THESIS_BASE_URL — legacy alias (kept so existing exports keep working)
* <neutral default> — the public managed host
*/
/** Neutral public default. Contains no internal codename. */
export const DEFAULT_MANAGED_API_BASE = "https://app.syntheticsciences.ai"
function stripTrailingSlashes(url: string): string {
return url.replace(/\/+$/, "")
}
/** Env var names that override the managed base URL, highest precedence first. */
export const MANAGED_API_BASE_ENV_KEYS = [
"OPENSCIENCE_API_BASE",
"SYNSC_API_BASE",
"MANAGED_API_BASE",
"ATLAS_BASE_URL",
"THESIS_BASE_URL",
] as const
/**
* Resolve the managed backend base URL from the given environment, falling back
* to the neutral default. Pure + parameterized so it stays unit-testable.
*/
export function managedApiBase(env: NodeJS.ProcessEnv = process.env): string {
const override = MANAGED_API_BASE_ENV_KEYS.map((key) => env[key]).find((value) => !!value)
return stripTrailingSlashes(override || DEFAULT_MANAGED_API_BASE)
}
/** The resolved managed base URL for this process. */
export const MANAGED_API_BASE = managedApiBase()