export type CatalogItem = {catalogItemId?: (string | null) | undefined, details?: ({date: string, from: string, to: string, type: 'HourlyRateDetails'} | null) | undefined, discount?: number | undefined, id?: string | undefined, isCreditNoteItem?: boolean | undefined, name: string, price?: number | undefined, unitBasis?: ({type: 'preset' | 'custom', value: string} | null) | undefined, units?: number | undefined, usageCount?: number | undefined, vatRate?: number | undefined}; export type CreateApiInvoiceItemsArgs = {body: CatalogItem}; export type CreateApiInvoiceItemsOptions = {baseUrl: string, ApiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create invoice item * * POST /invoice-items * * Also accepts auth: FirebaseIdToken */ export const createApiInvoiceItems = async (args: CreateApiInvoiceItemsArgs, options: CreateApiInvoiceItemsOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyHeader !== undefined) headers.set("X-API-Key", ApiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/invoice-items${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 (await res.json()) as unknown };