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

Function patched

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

Source from the content-addressed store, hash-verified

155 const originalFetch = globalThis.fetch;
156 const loopback = new URL(server.issuerUrl);
157 const patched: typeof fetch = async (input, init) => {
158 const requestUrl =
159 typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
160 const target = new URL(requestUrl);
161 if (target.hostname === loopback.hostname) {
162 return originalFetch(input as Parameters<typeof fetch>[0], init);
163 }
164 if (target.pathname === "/token") {
165 const bodyText =
166 init?.body instanceof URLSearchParams
167 ? init.body.toString()
168 : typeof init?.body === "string"
169 ? init.body
170 : input instanceof Request
171 ? await input.clone().text()
172 : "";
173 record.push({
174 host: target.hostname,
175 grantType: new URLSearchParams(bodyText).get("grant_type"),
176 });
177 }
178 const rerouted = new URL(loopback.origin);
179 rerouted.pathname = target.pathname;
180 rerouted.search = target.search;
181 return input instanceof Request
182 ? originalFetch(new Request(rerouted.href, input))
183 : originalFetch(rerouted.href, init);
184 };
185 // oxlint-disable-next-line executor/no-raw-fetch -- test boundary: install the doubled fetch (see above).
186 globalThis.fetch = patched;
187 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