import {z} from 'zod' export type Bill = {id?: string | undefined, integration?: string | undefined, vendorId?: string | undefined, vendorName?: (string | null) | undefined, currency?: (string | null) | undefined, balance?: number | undefined, txnDate?: (string | null) | undefined, totalAmount?: number | undefined, apAccountId?: (string | null) | undefined, apAccountName?: (string | null) | undefined, modified?: string | undefined, created?: (string | null) | undefined, srcId?: string | undefined, status?: (string | null) | undefined, identifier?: (string | null) | undefined, referenceNumber?: (string | null) | undefined, dueDate?: (string | null) | undefined, subtotal?: (number | null) | undefined, taxAmount?: (number | null) | undefined}; export type UpdateApiBillsIdArgs = {id: string, body: Bill}; export type UpdateApiBillsIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const bill = z.object({id: z.string().optional(), integration: z.string().optional(), vendorId: z.string().optional(), vendorName: z.string().nullable().optional(), currency: z.string().nullable().optional(), balance: z.number().int().optional(), txnDate: z.string().nullable().optional(), totalAmount: z.number().int().optional(), apAccountId: z.string().nullable().optional(), apAccountName: z.string().nullable().optional(), modified: z.string().optional(), created: z.string().nullable().optional(), srcId: z.string().optional(), status: z.string().nullable().optional(), identifier: z.string().nullable().optional(), referenceNumber: z.string().nullable().optional(), dueDate: z.string().nullable().optional(), subtotal: z.number().int().nullable().optional(), taxAmount: z.number().int().nullable().optional()}); 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 }; /** * Replaces the Bill resource. * * PUT /bills/{id} */ export const updateApiBillsId = async (args: UpdateApiBillsIdArgs, options?: UpdateApiBillsIdOptions) => { const {baseUrl = "https://example.myintranetapps.com/api", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/bills/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(bill, await res.json()) };