import fetch from 'node-fetch'; import type {Response} from 'node-fetch/@types'; // See simple-fetch.ts for why this function exists. It is used in // node contexts (tests, CLI invocation). export function simpleFetch( method: string, url: string, body: string | null, headers: Record, ): Promise { return fetch(url, { method, body, headers, }); } // mustSimpleFetch throws on non-200 responses. export async function mustSimpleFetch( method: string, url: string, body: string | null, headers: Record, ): Promise { const resp = await simpleFetch(method, url, body, headers); if (!resp.ok) { throw new Error(`Got ${resp.status} fetching ${url}: ${await resp.text()}`); } return resp; }