import {z} from 'zod' export type File = {actor_id?: number | undefined, auto_include?: boolean | undefined, booking_id?: number | undefined, created?: string | undefined, created_by_id?: number | undefined, description?: string | undefined, description_location?: string | undefined, description_text?: string | undefined, exif_created?: string | undefined, format?: string | undefined, geo_latitude?: number | undefined, geo_longitude?: number | undefined, guid?: (string | null) | undefined, has_damage?: boolean | undefined, id?: number | undefined, include_esign?: (boolean | null) | undefined, message_id?: number | undefined, name?: string | undefined, out_of_date?: (boolean | null) | undefined, public_id?: string | undefined, rental_id?: number | undefined, shared?: boolean | undefined, signable?: boolean | undefined, signers?: Array | undefined, signing_canceled?: (boolean | null) | undefined, signing_complete?: (boolean | null) | undefined, signing_service_id?: string | undefined, title?: string | undefined, type?: (string | null) | undefined, updated?: string | undefined, url?: string | undefined, user_id?: number | undefined}; export type PatchApiFilesIdArgs = {id: number, body: File}; export type PatchApiFilesIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const file = z.object({actor_id: z.number().int().optional(), auto_include: z.boolean().optional(), booking_id: z.number().int().optional(), created: z.string().optional(), created_by_id: z.number().int().optional(), description: z.string().optional(), description_location: z.string().optional(), description_text: z.string().optional(), exif_created: z.string().optional(), format: z.string().optional(), geo_latitude: z.number().optional(), geo_longitude: z.number().optional(), guid: z.string().nullable().optional(), has_damage: z.boolean().optional(), id: z.number().int().optional(), include_esign: z.boolean().nullable().optional(), message_id: z.number().int().optional(), name: z.string().optional(), out_of_date: z.boolean().nullable().optional(), public_id: z.string().optional(), rental_id: z.number().int().optional(), shared: z.boolean().optional(), signable: z.boolean().optional(), signers: z.array(z.unknown()).optional(), signing_canceled: z.boolean().nullable().optional(), signing_complete: z.boolean().nullable().optional(), signing_service_id: z.string().optional(), title: z.string().optional(), type: z.string().nullable().optional(), updated: z.string().optional(), url: z.string().optional(), user_id: z.number().int().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 }; /** * Update file details * * PATCH /files/{id} * * Also accepts auth: API-Key */ export const patchApiFilesId = async (args: PatchApiFilesIdArgs, options: PatchApiFilesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/files/${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(file, await res.json()) };