import {z} from 'zod' export type ISlice = Array; export type DailyChange = {date?: string | undefined, price?: number | undefined, rules?: ISlice | undefined}; export type DBInterfaceMap = unknown; export type NoticeResponse = {guest_acknowledgement_text?: string | undefined, guest_need_to_acknowledge?: boolean | undefined, guest_user_text?: string | undefined, host_acknowledgement_text?: string | undefined, host_help_url?: string | undefined, host_need_to_acknowledge?: boolean | undefined, host_user_text?: string | undefined, id?: number | undefined, name?: string | undefined}; export type Proposal = {action?: string | undefined, booking_id?: number | undefined, created?: string | undefined, daily_changes?: Array | undefined, details?: DBInterfaceMap | undefined, dry_create?: boolean | undefined, future_booking: unknown, id?: number | undefined, note?: string | undefined, object_id?: number | undefined, object_type?: string | undefined, owner_acknowledged?: string | undefined, owner_id?: number | undefined, renter_acknowledged?: string | undefined, renter_dismissed?: string | undefined, status?: string | undefined, updated?: string | undefined, user_notice_events?: Array | undefined, user_notices_acknowledged?: Array | undefined}; export type PatchApiBookingsBookingIdProposalsIdArgs = {booking_id: number, id: number, body: Proposal}; export type PatchApiBookingsBookingIdProposalsIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const iSlice = z.array(z.unknown()); export const dailyChange = z.object({date: z.string().optional(), price: z.number().int().optional(), rules: iSlice.optional()}); export const dBInterfaceMap = z.unknown(); export const noticeResponse = z.object({guest_acknowledgement_text: z.string().optional(), guest_need_to_acknowledge: z.boolean().optional(), guest_user_text: z.string().optional(), host_acknowledgement_text: z.string().optional(), host_help_url: z.string().optional(), host_need_to_acknowledge: z.boolean().optional(), host_user_text: z.string().optional(), id: z.number().int().optional(), name: z.string().optional()}); export const proposal = z.object({action: z.string().optional(), booking_id: z.number().int().optional(), created: z.string().optional(), daily_changes: z.array(dailyChange).optional(), details: dBInterfaceMap.optional(), dry_create: z.boolean().optional(), future_booking: z.unknown(), id: z.number().int().optional(), note: z.string().optional(), object_id: z.number().int().optional(), object_type: z.string().optional(), owner_acknowledged: z.string().optional(), owner_id: z.number().int().optional(), renter_acknowledged: z.string().optional(), renter_dismissed: z.string().optional(), status: z.string().optional(), updated: z.string().optional(), user_notice_events: z.array(noticeResponse).optional(), user_notices_acknowledged: z.array(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 a proposal * * PATCH /bookings/{booking_id}/proposals/{id} * * Also accepts auth: API-Key */ export const patchApiBookingsBookingIdProposalsId = async (args: PatchApiBookingsBookingIdProposalsIdArgs, options: PatchApiBookingsBookingIdProposalsIdOptions) => { 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(/\/+$/, '')}/bookings/${encodeURIComponent(String(args.booking_id))}/proposals/${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(proposal, await res.json()) };