import {z} from 'zod' export type StringSlice = Array; export type IntSlice = Array; export type NoteToRenters = {applies_to_type?: StringSlice | undefined, created?: string | undefined, description?: string | undefined, id?: number | undefined, location_ids?: IntSlice | undefined, name?: string | undefined, owner_user_id?: number | undefined, position?: number | undefined, rental_id?: number | undefined, updated?: string | undefined}; export type PatchApiNotesToRentersIdArgs = {id: number, body: NoteToRenters}; export type PatchApiNotesToRentersIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const stringSlice = z.array(z.string()); export const intSlice = z.array(z.number().int()); export const noteToRenters = z.object({applies_to_type: stringSlice.optional(), created: z.string().optional(), description: z.string().optional(), id: z.number().int().optional(), location_ids: intSlice.optional(), name: z.string().optional(), owner_user_id: z.number().int().optional(), position: z.number().int().optional(), rental_id: z.number().int().optional(), updated: z.string().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 a note to renters * * PATCH /notes-to-renters/{id} * * Also accepts auth: API-Key */ export const patchApiNotesToRentersId = async (args: PatchApiNotesToRentersIdArgs, options: PatchApiNotesToRentersIdOptions) => { 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(/\/+$/, '')}/notes-to-renters/${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(noteToRenters, await res.json()) };