import {z} from 'zod' export type PatchedapiV1SimplifiedInvoiceLineItem = {account?: string | undefined, cost_center?: string | undefined, created_ts?: string | undefined, description?: string | undefined, discount?: (number | null) | undefined, id?: string | undefined, item?: string | undefined, item_unit_of_measure?: (string | null) | undefined, legacy_id?: string | undefined, line_amount?: number | undefined, modified_ts?: string | undefined, order?: number | undefined, quantity?: number | undefined, tax_amount?: number | undefined, tax_rate?: string | undefined, unit_amount?: number | undefined}; export type PatchApiSimplifiedInvoicesInvoiceIdLineItemsIdArgs = {'X-Wafeq-Idempotency-Key'?: string | undefined, expand?: string | undefined, invoice_id: string, id: string, body: PatchedapiV1SimplifiedInvoiceLineItem}; export type PatchApiSimplifiedInvoicesInvoiceIdLineItemsIdOptions = {baseUrl?: string | undefined, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiV1SimplifiedInvoiceLineItem = z.object({account: z.string(), cost_center: z.string().optional(), created_ts: z.string(), description: z.string(), discount: z.number().gte(0).lt(10000000000000000).nullable().optional(), id: z.string(), item: z.string().optional(), item_unit_of_measure: z.string().nullable().optional(), legacy_id: z.string(), line_amount: z.number().gt(-10000000000000000).lt(10000000000000000), modified_ts: z.string(), order: z.number().int().optional(), quantity: z.number().gt(-10000000000000000).lt(10000000000000000), tax_amount: z.number().gt(-10000000000000000).lt(10000000000000000), tax_rate: z.string().optional(), unit_amount: z.number().gt(-10000000000000000).lt(10000000000000000)}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Partial update simplified invoice line item * * PATCH /simplified-invoices/{invoice_id}/line-items/{id}/ */ export const patchApiSimplifiedInvoicesInvoiceIdLineItemsId = async (args: PatchApiSimplifiedInvoicesInvoiceIdLineItemsIdArgs, options?: PatchApiSimplifiedInvoicesInvoiceIdLineItemsIdOptions) => { const {baseUrl = "https://api.wafeq.com/v1", fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Wafeq-Idempotency-Key'] != null) headers.set("X-Wafeq-Idempotency-Key", String(args['X-Wafeq-Idempotency-Key'])) if (args.expand != null) query.append("expand", String(args.expand)) if (APIKeyAuth !== undefined) headers.set("Authorization", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/simplified-invoices/${encodeURIComponent(String(args.invoice_id))}/line-items/${encodeURIComponent(String(args.id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 validateResponse(apiV1SimplifiedInvoiceLineItem, await res.json()) };