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

Function extractFlows

packages/plugins/openapi/src/sdk/preview.ts:251–300  ·  view source on GitHub ↗
(rawFlows: unknown)

Source from the content-addressed store, hash-verified

249};
250
251const extractFlows = (rawFlows: unknown): Option.Option<OAuth2Flows> => {
252 if (!rawFlows || typeof rawFlows !== "object") return Option.none();
253 const flows = rawFlows as Record<string, unknown>;
254
255 const parseFlow = <K extends "authorizationCode" | "clientCredentials">(key: K): unknown =>
256 flows[key];
257
258 let authorizationCode: Option.Option<OAuth2AuthorizationCodeFlow> = Option.none();
259 const authCodeRaw = parseFlow("authorizationCode");
260 if (authCodeRaw && typeof authCodeRaw === "object") {
261 const f = authCodeRaw as Record<string, unknown>;
262 const authUrl = typeof f.authorizationUrl === "string" ? f.authorizationUrl : null;
263 const tokenUrl = typeof f.tokenUrl === "string" ? f.tokenUrl : null;
264 if (authUrl && tokenUrl) {
265 authorizationCode = Option.some(
266 OAuth2AuthorizationCodeFlow.make({
267 authorizationUrl: authUrl,
268 tokenUrl,
269 refreshUrl: Option.fromNullishOr(
270 typeof f.refreshUrl === "string" ? f.refreshUrl : undefined,
271 ),
272 scopes: stringRecord(f.scopes),
273 }),
274 );
275 }
276 }
277
278 let clientCredentials: Option.Option<OAuth2ClientCredentialsFlow> = Option.none();
279 const ccRaw = parseFlow("clientCredentials");
280 if (ccRaw && typeof ccRaw === "object") {
281 const f = ccRaw as Record<string, unknown>;
282 const tokenUrl = typeof f.tokenUrl === "string" ? f.tokenUrl : null;
283 if (tokenUrl) {
284 clientCredentials = Option.some(
285 OAuth2ClientCredentialsFlow.make({
286 tokenUrl,
287 refreshUrl: Option.fromNullishOr(
288 typeof f.refreshUrl === "string" ? f.refreshUrl : undefined,
289 ),
290 scopes: stringRecord(f.scopes),
291 }),
292 );
293 }
294 }
295
296 if (Option.isNone(authorizationCode) && Option.isNone(clientCredentials)) {
297 return Option.none();
298 }
299 return Option.some(OAuth2Flows.make({ authorizationCode, clientCredentials }));
300};
301
302const extractSecuritySchemes = (
303 rawSchemes: Record<string, unknown>,

Callers 1

extractSecuritySchemesFunction · 0.85

Calls 2

parseFlowFunction · 0.85
stringRecordFunction · 0.85

Tested by

no test coverage detected