MCPcopy Create free account
hub / github.com/TestSprite/testsprite-cli / makeHttpClient

Function makeHttpClient

src/lib/client-factory.ts:142–175  ·  view source on GitHub ↗
(opts: CommonOptions, deps: ClientFactoryDeps = {})

Source from the content-addressed store, hash-verified

140}
141
142export function makeHttpClient(opts: CommonOptions, deps: ClientFactoryDeps = {}): HttpClient {
143 const stderr = deps.stderr ?? ((line: string) => process.stderr.write(`${line}\n`));
144 const env = deps.env ?? process.env;
145 const requestTimeoutMs = resolveRequestTimeoutMs(opts, env);
146
147 if (opts.dryRun) {
148 emitDryRunBanner(stderr);
149 return new HttpClient({
150 baseUrl: facadeBaseUrl(opts.endpointUrl ?? DRY_RUN_DEFAULT_ENDPOINT),
151 apiKey: DRY_RUN_API_KEY,
152 fetchImpl: deps.fetchImpl ?? createDryRunFetch(),
153 onDebug: opts.debug ? (event: DebugEvent) => stderr(formatDryRunDebug(event)) : undefined,
154 onTransition: opts.verbose ? (msg: string) => stderr(`[verbose] ${msg}`) : undefined,
155 requestTimeoutMs,
156 });
157 }
158
159 const credentialsPath = deps.credentialsPath ?? defaultCredentialsPath();
160 const config = loadConfig({
161 profile: opts.profile,
162 endpointUrl: opts.endpointUrl,
163 env,
164 credentialsPath,
165 });
166 if (!config.apiKey) throw ApiError.authRequired();
167 return new HttpClient({
168 baseUrl: facadeBaseUrl(config.apiUrl),
169 apiKey: config.apiKey,
170 fetchImpl: deps.fetchImpl,
171 onDebug: opts.debug ? (event: DebugEvent) => stderr(formatDebug(event)) : undefined,
172 onTransition: opts.verbose ? (msg: string) => stderr(`[verbose] ${msg}`) : undefined,
173 requestTimeoutMs,
174 });
175}
176
177function formatDebug(event: DebugEvent): string {
178 return `[debug ${new Date().toISOString()}] ${JSON.stringify(event)}`;

Callers 5

makeClientFunction · 0.85
makeClientFunction · 0.85
runWhoamiFunction · 0.85
runUsageFunction · 0.85

Calls 10

resolveRequestTimeoutMsFunction · 0.85
emitDryRunBannerFunction · 0.85
facadeBaseUrlFunction · 0.85
createDryRunFetchFunction · 0.85
stderrFunction · 0.85
formatDryRunDebugFunction · 0.85
defaultCredentialsPathFunction · 0.85
loadConfigFunction · 0.85
formatDebugFunction · 0.85
authRequiredMethod · 0.80

Tested by

no test coverage detected