| 60 | type FetchInput = Parameters<typeof globalThis.fetch>[0]; |
| 61 | |
| 62 | function makeFetch( |
| 63 | handler: (url: string, init: RequestInit) => { status?: number; body: unknown }, |
| 64 | ): typeof globalThis.fetch { |
| 65 | return (async (input: FetchInput, init: RequestInit = {}) => { |
| 66 | const url = |
| 67 | typeof input === 'string' |
| 68 | ? input |
| 69 | : input instanceof URL |
| 70 | ? input.toString() |
| 71 | : (input as { url: string }).url; |
| 72 | const { status = 200, body } = handler(url, init); |
| 73 | return new Response(JSON.stringify(body), { |
| 74 | status, |
| 75 | headers: { 'content-type': 'application/json' }, |
| 76 | }); |
| 77 | }) as typeof globalThis.fetch; |
| 78 | } |
| 79 | |
| 80 | function makeCreds( |
| 81 | apiKey = 'sk-user-test', |