@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
mjs 54 lines 2.06 KB
Raw
1 /**
2 * Single source of truth for the Composio production API URL used by the docs
3 * toolkit and OpenAPI generators.
4 *
5 * Published docs data must come from production. The "Docs - Update Data"
6 * workflow leaves the base URL unset, and toolkit generation rejects
7 * non-production overrides before making a request. Host rewriting is
8 * retained as defense in depth for staging URLs embedded inside an otherwise
9 * production-sourced payload.
10 *
11 * The guard test deliberately does NOT import from this module: an oracle must
12 * verify against an independently-stated expectation, so a wrong edit here fails
13 * the test instead of silently moving both sides together.
14 */
15
16 export const PRODUCTION_HOST = 'backend.composio.dev';
17 export const PRODUCTION_BASE_URL = `https://${PRODUCTION_HOST}`;
18 export const PRODUCTION_API_V3_URL = `${PRODUCTION_BASE_URL}/api/v3`;
19 export const PRODUCTION_API_V31_URL = `${PRODUCTION_BASE_URL}/api/v3.1`;
20
21 /**
22 * Resolve the API base used to generate publishable docs data.
23 *
24 * An override is accepted only when it normalizes to the production v3 URL.
25 * Failing loudly prevents a local or CI environment variable from silently
26 * turning the checked-in catalog into a staging snapshot.
27 */
28 export function requireProductionApiV3Url(configuredUrl) {
29 const normalized = configuredUrl?.trim().replace(/\/+$/, '') || PRODUCTION_API_V3_URL;
30
31 if (normalized !== PRODUCTION_API_V3_URL) {
32 throw new Error(
33 `Published docs data must be generated from ${PRODUCTION_API_V3_URL}; received ${normalized}`
34 );
35 }
36
37 return PRODUCTION_API_V3_URL;
38 }
39
40 /** Non-production hosts that must never appear in published docs data. */
41 export const STAGING_HOSTS = ['staging-backend.composio.dev', 'staging-apollo.composio.dev'];
42
43 /**
44 * Rewrite any staging host embedded in a serialized JSON string to the
45 * production host.
46 * Operates on the serialized string to avoid disturbing typed data pipelines.
47 */
48 export function stripStagingHosts(text) {
49 let out = text;
50 for (const host of STAGING_HOSTS) {
51 out = out.split(host).join(PRODUCTION_HOST);
52 }
53 return out;
54 }