MCPcopy Index your code
hub / github.com/commandoperator/cmdop-sdk / resolveConfig

Function resolveConfig

node/src/config.ts:34–61  ·  view source on GitHub ↗
(opts: Partial<ClientConfig> = {})

Source from the content-addressed store, hash-verified

32 * `CMDOP_API_KEY` independently.
33 */
34export function resolveConfig(opts: Partial<ClientConfig> = {}): ClientConfig {
35 const env = typeof process !== "undefined" && process.env ? process.env : {};
36
37 const token = opts.token ?? env.CMDOP_TOKEN ?? env.CMDOP_API_KEY;
38 if (!token) {
39 throw new Error(
40 "No token. Pass token or set CMDOP_TOKEN (or CMDOP_API_KEY).",
41 );
42 }
43
44 const baseUrl = stripTrailingSlash(
45 opts.baseUrl ?? env.CMDOP_BASE_URL ?? DEFAULT_BASE_URL,
46 );
47
48 const fleetId = opts.fleetId ?? env.CMDOP_FLEET_ID ?? undefined;
49
50 const timeoutMs =
51 opts.timeoutMs ??
52 (env.CMDOP_TIMEOUT_MS ? Number(env.CMDOP_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS);
53
54 const apiKey = opts.apiKey ?? env.CMDOP_API_KEY ?? undefined;
55
56 const apiBaseUrl = stripTrailingSlash(
57 opts.apiBaseUrl ?? env.CMDOP_API_BASE_URL ?? DEFAULT_API_BASE_URL,
58 );
59
60 return { token, baseUrl, fleetId, timeoutMs, apiKey, apiBaseUrl };
61}
62
63function stripTrailingSlash(url: string): string {
64 return url.endsWith("/") ? url.slice(0, -1) : url;

Callers 5

constructorMethod · 0.90
makeTransportFunction · 0.90
skills.test.tsFile · 0.90
makeTransportFunction · 0.90
config.test.tsFile · 0.90

Calls 1

stripTrailingSlashFunction · 0.85

Tested by 2

makeTransportFunction · 0.72
makeTransportFunction · 0.72