import {z} from 'zod' export type GetApiV1ReservationArgs = {offset?: number | undefined, limit?: number | undefined, status?: string | undefined, trash?: boolean | undefined, propertyId?: number | undefined, periodStart?: string | undefined, periodEnd?: string | undefined, modifiedSince?: string | undefined}; export type GetApiV1ReservationOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const lodgifyApiPublicReservationsModelsV1GuestNameDto = z.object({first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), full_name: z.string().nullable().optional()}); export const lodgifyApiPublicReservationsModelsV1GuestViewModel = z.object({guest_name: lodgifyApiPublicReservationsModelsV1GuestNameDto.optional(), name: z.string().nullable().optional(), external_id: z.string().nullable().optional(), email: z.string().nullable().optional(), phone_numbers: z.array(z.string()).nullable().optional(), phone: z.string().nullable().optional(), locale: z.string().nullable().optional(), street_address1: z.string().nullable().optional(), street_address2: z.string().nullable().optional(), city: z.string().nullable().optional(), country_code: z.string().nullable().optional(), postal_code: z.string().nullable().optional(), state: z.string().nullable().optional(), id: z.string().nullable().optional(), country_name: z.string().nullable().optional()}); export const lodgifyApiPublicReservationsModelsV12GuestBreakdownDto = z.object({adults: z.number().int().gte(0).lte(2147483647).optional(), children: z.number().int().gte(0).lte(2147483647).optional(), infants: z.number().int().gte(0).lte(2147483647).optional(), pets: z.number().int().gte(0).lte(2147483647).optional()}); export const lodgifyApiPublicReservationsModelsV1BookingRoomTypeViewModel = z.object({room_type_id: z.number().int().optional(), guest_breakdown: lodgifyApiPublicReservationsModelsV12GuestBreakdownDto, people: z.number().int().optional(), key_code: z.string().nullable().optional(), name: z.string().nullable().optional()}); export const lodgifyApiPublicReservationsModelsV1CurrencyViewModel = z.object({id: z.number().int().optional(), code: z.string().nullable().optional(), name: z.string().nullable().optional(), euro_forex: z.number().optional(), symbol: z.string().nullable().optional()}); export const lodgifyApiPublicReservationsModelsV1BookingViewModel = z.object({id: z.number().int().optional(), type: z.string().nullable().optional(), booking_type: z.string().nullable().optional(), status: z.string().nullable().optional(), source: z.string().nullable().optional(), source_text: z.string().nullable().optional(), guest: lodgifyApiPublicReservationsModelsV1GuestViewModel.optional(), arrival: z.string().nullable().optional(), departure: z.string().nullable().optional(), people: z.number().int().nullable().optional(), total_guest_breakdown: lodgifyApiPublicReservationsModelsV12GuestBreakdownDto.optional(), property_id: z.number().int().nullable().optional(), property_name: z.string().nullable().optional(), rooms: z.array(lodgifyApiPublicReservationsModelsV1BookingRoomTypeViewModel).nullable().optional(), created_at: z.string().optional(), is_replied: z.boolean().optional(), updated_at: z.string().optional(), is_deleted: z.boolean().optional(), date_deleted: z.string().nullable().optional(), total_amount: z.number().nullable().optional(), total_paid: z.number().optional(), amount_to_pay: z.number().nullable().optional(), thread_uid: z.string().optional(), upgraded_enquiry_id: z.number().int().nullable().optional(), currency: lodgifyApiPublicReservationsModelsV1CurrencyViewModel.optional()}); export const lodgifyApiPublicReservationsModelsV1PagedResult1BookingViewModel = z.object({items: z.array(lodgifyApiPublicReservationsModelsV1BookingViewModel).nullable().optional(), total: z.number().int().optional(), next: z.string().nullable().optional(), previous: z.string().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 }; /** * Retrieves a paginated list of bookings and enquiries from the inbox, with optional filtering. * * GET /v1/reservation */ export const getApiV1Reservation = async (args: GetApiV1ReservationArgs, options?: GetApiV1ReservationOptions) => { const {baseUrl = "https://api.lodgify.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.status != null) query.append("status", String(args.status)) if (args.trash != null) query.append("trash", String(args.trash)) if (args.propertyId != null) query.append("propertyId", String(args.propertyId)) if (args.periodStart != null) query.append("periodStart", String(args.periodStart)) if (args.periodEnd != null) query.append("periodEnd", String(args.periodEnd)) if (args.modifiedSince != null) query.append("modifiedSince", String(args.modifiedSince)) if (ApiKey !== undefined) headers.set("X-ApiKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/reservation${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(lodgifyApiPublicReservationsModelsV1PagedResult1BookingViewModel, await res.json()) };