export type CreateApiInvoicesFromCreditArgs = {body: {clientName?: string | undefined, credit: {amount: number, counterparty?: string | undefined, currency?: string | undefined, date: string, description?: string | undefined, importRef?: string | undefined}, itemName?: string | undefined}}; export type CreateApiInvoicesFromCreditOptions = {baseUrl: string, ApiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create the paid invoice for one bank credit the importer did not book * * POST /invoices/from-credit * * Also accepts auth: FirebaseIdToken */ export const createApiInvoicesFromCredit = async (args: CreateApiInvoicesFromCreditArgs, options: CreateApiInvoicesFromCreditOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ApiKeyHeader !== undefined) headers.set("X-API-Key", ApiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/invoices/from-credit${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };