MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / buildHeaderPresets

Function buildHeaderPresets

packages/plugins/openapi/src/sdk/preview.ts:338–400  ·  view source on GitHub ↗
(
  schemes: readonly SecurityScheme[],
  strategies: readonly AuthStrategy[],
)

Source from the content-addressed store, hash-verified

336// ---------------------------------------------------------------------------
337
338const buildHeaderPresets = (
339 schemes: readonly SecurityScheme[],
340 strategies: readonly AuthStrategy[],
341): HeaderPreset[] => {
342 const schemeMap = new Map(schemes.map((s) => [s.name, s]));
343
344 return strategies.flatMap((strategy) => {
345 const resolved = strategy.schemes
346 .map((name) => schemeMap.get(name))
347 .filter(Predicate.isNotUndefined);
348
349 if (resolved.length === 0) return [];
350
351 const headers: Record<string, string | null> = {};
352 const secretHeaders: string[] = [];
353 const secretQueryParams: string[] = [];
354 const labelParts: string[] = [];
355
356 for (const scheme of resolved) {
357 if (scheme.type === "http" && Option.getOrElse(scheme.scheme, () => "") === "bearer") {
358 headers["Authorization"] = null;
359 secretHeaders.push("Authorization");
360 labelParts.push("Bearer Token");
361 } else if (scheme.type === "http" && Option.getOrElse(scheme.scheme, () => "") === "basic") {
362 headers["Authorization"] = null;
363 secretHeaders.push("Authorization");
364 labelParts.push("Basic Auth");
365 } else if (scheme.type === "apiKey" && Option.getOrElse(scheme.in, () => "") === "header") {
366 const headerName = Option.getOrElse(scheme.headerName, () => scheme.name);
367 headers[headerName] = null;
368 secretHeaders.push(headerName);
369 labelParts.push(scheme.name);
370 } else if (scheme.type === "apiKey" && Option.getOrElse(scheme.in, () => "") === "query") {
371 secretQueryParams.push(Option.getOrElse(scheme.headerName, () => scheme.name));
372 labelParts.push(`${scheme.name} (query)`);
373 } else if (scheme.type === "apiKey") {
374 // Cookie (and unknown) locations are not renderable as a stored
375 // method — auth placements carry header|query — and a cookie scheme
376 // is usually the vendor console's own session, not a mintable
377 // credential. Contributing a label here used to produce a method
378 // with zero placements: an empty, unfillable card in the add flow.
379 continue;
380 } else if (scheme.type === "oauth2" || scheme.type === "openIdConnect") {
381 return [];
382 } else {
383 labelParts.push(scheme.name);
384 }
385 }
386
387 // A strategy in which nothing is renderable (cookie-only, or an exotic
388 // scheme type) yields no preset rather than an empty one.
389 if (secretHeaders.length === 0 && secretQueryParams.length === 0) return [];
390
391 return [
392 HeaderPreset.make({
393 label: labelParts.join(" + "),
394 headers,
395 secretHeaders,

Callers 1

preview.tsFile · 0.85

Calls 2

pushMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected