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

Function patched

packages/core/sdk/src/oauth-flow.test.ts:88–115  ·  view source on GitHub ↗
(input, init)

Source from the content-addressed store, hash-verified

86 const originalFetch = globalThis.fetch;
87 const loopback = new URL(server.issuerUrl);
88 const patched: typeof fetch = async (input, init) => {
89 const requestUrl =
90 typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
91 const target = new URL(requestUrl);
92 if (target.hostname === loopback.hostname) {
93 return originalFetch(input as Parameters<typeof fetch>[0], init);
94 }
95 if (target.pathname === "/token") {
96 const bodyText =
97 init?.body instanceof URLSearchParams
98 ? init.body.toString()
99 : typeof init?.body === "string"
100 ? init.body
101 : input instanceof Request
102 ? await input.clone().text()
103 : "";
104 record.push({
105 host: target.hostname,
106 grantType: new URLSearchParams(bodyText).get("grant_type"),
107 });
108 }
109 const rerouted = new URL(loopback.origin);
110 rerouted.pathname = target.pathname;
111 rerouted.search = target.search;
112 return input instanceof Request
113 ? originalFetch(new Request(rerouted.href, input))
114 : originalFetch(rerouted.href, init);
115 };
116 // oxlint-disable-next-line executor/no-raw-fetch -- test boundary: install the doubled fetch (see above).
117 globalThis.fetch = patched;
118 return () => {

Callers

nothing calls this directly

Calls 5

toStringMethod · 0.80
pushMethod · 0.80
textMethod · 0.65
cloneMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected