import got, { Method } from "got"; type HttpClientMethod = Method; type HttpClientOptions = { method: HttpClientMethod; headers?: Record; body?: string; }; type HttpClient = ( path: string, options: HttpClientOptions ) => Promise<{ statusCode: number; body: Data }>; const createClient = ({ headers }: { headers?: Record }) => { const client = got.extend({ headers: { "Content-Type": "application/json", ...headers, }, retry: 0, resolveBodyOnly: false, throwHttpErrors: false, }); return async (path: string, options: HttpClientOptions) => { const isJsonResponse = (options.headers ?? {})["Accept"] === "application/json"; return client(path, { ...options, // @ts-expect-error responseType: isJsonResponse ? "json" : "buffer", }); }; }; const http = { createClient }; export { http, HttpClient, HttpClientMethod, HttpClientOptions };