export type GetApiV1BillsIdPdfArgs = {id: number}; export type GetApiV1BillsIdPdfOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Download PDF version of a bill * * GET /v1/Bills/{id}/pdf */ export const getApiV1BillsIdPdf = async (args: GetApiV1BillsIdPdfArgs, options?: GetApiV1BillsIdPdfOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Bills/${encodeURIComponent(String(args.id))}/pdf${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };