export type GetApiEstimatePdfArgs = {cif: string, seriesname: string, number: string}; export type GetApiEstimatePdfOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Descarcare proforma PDF * * GET /estimate/pdf */ export const getApiEstimatePdf = async (args: GetApiEstimatePdfArgs, options?: GetApiEstimatePdfOptions) => { 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(/\/+$/, '')}/estimate/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() };