export type GetApiInvoicePdfArgs = {cif: string, seriesname: string, number: string}; export type GetApiInvoicePdfOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Descarcare factura PDF * * GET /invoice/pdf */ export const getApiInvoicePdf = async (args: GetApiInvoicePdfArgs, options?: GetApiInvoicePdfOptions) => { const {baseUrl = "https://ws.smartbill.ro/SBORO/api", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") if (args.cif != null) query.append("cif", String(args.cif)) if (args.seriesname != null) query.append("seriesname", String(args.seriesname)) if (args.number != null) query.append("number", String(args.number)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/invoice/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 res.blob() };