import {z} from 'zod' export type UserSimple = {'avatar-thumb-url'?: unknown | undefined, 'created-at'?: unknown | undefined, email: unknown, 'employee-number'?: unknown | undefined, firstname: unknown, fullname?: unknown | undefined, id?: number | undefined, lastname: unknown, login: unknown, 'salesforce-id': unknown, 'updated-at'?: unknown | undefined}; export type ExpenseArtifact = {'created-at'?: unknown | undefined, 'created-by'?: UserSimple | undefined, 'digitization-error'?: unknown | undefined, 'digitization-status'?: unknown | undefined, 'digitized-receipt-content-type'?: unknown | undefined, 'digitized-receipt-file-name'?: unknown | undefined, 'digitized-receipt-file-size'?: number | undefined, 'external-src-ref'?: unknown | undefined, id?: number | undefined, 'image-content-type'?: unknown | undefined, 'image-file-name'?: unknown | undefined, 'image-file-size'?: unknown | undefined, 'image-rotation'?: number | undefined, 'ocr-status'?: unknown | undefined, placeholder?: boolean | undefined, 'source-content-type'?: unknown | undefined, 'source-file-name'?: unknown | undefined, 'source-file-size'?: unknown | undefined, 'updated-at'?: unknown | undefined, 'updated-by'?: UserSimple | undefined, url?: unknown | undefined}; export type PatchApiExpenseLinesExpenseArtifactsIdArgs = {id: number, return_object?: ('limited' | 'shallow' | 'none') | undefined, filter?: string | undefined, body: ExpenseArtifact}; export type PatchApiExpenseLinesExpenseArtifactsIdOptions = {baseUrl?: string | undefined, OAuth2AccessCode?: string | undefined, fetch?: typeof fetch | undefined}; export const userSimple = z.object({"avatar-thumb-url": z.string().optional(), "created-at": z.string().optional(), email: z.string(), "employee-number": z.string().optional(), firstname: z.string(), fullname: z.string().optional(), id: z.number().int().optional(), lastname: z.string(), login: z.string(), "salesforce-id": z.string(), "updated-at": z.string().optional()}); export const expenseArtifact = z.object({"created-at": z.string().optional(), "created-by": userSimple.optional(), "digitization-error": z.string().optional(), "digitization-status": z.string().optional(), "digitized-receipt-content-type": z.string().optional(), "digitized-receipt-file-name": z.string().optional(), "digitized-receipt-file-size": z.number().int().optional(), "external-src-ref": z.string().optional(), id: z.number().int().optional(), "image-content-type": z.string().optional(), "image-file-name": z.string().optional(), "image-file-size": z.string().optional(), "image-rotation": z.number().int().optional(), "ocr-status": z.string().optional(), placeholder: z.boolean().optional(), "source-content-type": z.string().optional(), "source-file-name": z.string().optional(), "source-file-size": z.string().optional(), "updated-at": z.string().optional(), "updated-by": userSimple.optional(), url: z.string().optional()}); export const patchApiExpenseLinesExpenseArtifactsIdResponse = z.array(expenseArtifact); 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 }; /** * Update expense artifact * * PATCH /expense_lines/expense_artifacts/{id} * * Also accepts auth: OAuth2ClientCredential */ export const patchApiExpenseLinesExpenseArtifactsId = async (args: PatchApiExpenseLinesExpenseArtifactsIdArgs, options?: PatchApiExpenseLinesExpenseArtifactsIdOptions) => { const {baseUrl = "https://r38.coupadev.com/api", fetch: fetchFn = fetch, OAuth2AccessCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.return_object != null) query.append("return_object", String(args.return_object)) if (args.filter != null) query.append("filter", String(args.filter)) if (OAuth2AccessCode !== undefined) headers.set('authorization', `Bearer ${OAuth2AccessCode}`) const url = `${baseUrl.replace(/\/+$/, '')}/expense_lines/expense_artifacts/${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(patchApiExpenseLinesExpenseArtifactsIdResponse, await res.json()) };