import {z} from 'zod' export type GetApiListingsRentalLongTermArgs = {address?: string | undefined, city?: string | undefined, state?: string | undefined, zipCode?: string | undefined, latitude?: number | undefined, longitude?: number | undefined, radius?: number | undefined, propertyType?: ('Single Family' | 'Condo' | 'Townhouse' | 'Manufactured' | 'Multi-Family' | 'Apartment') | undefined, bedrooms?: string | undefined, bathrooms?: string | undefined, squareFootage?: string | undefined, lotSize?: string | undefined, yearBuilt?: string | undefined, status?: ('Active' | 'Inactive') | undefined, price?: string | undefined, daysOld?: string | undefined, limit?: number | undefined, offset?: number | undefined, includeTotalCount?: boolean | undefined}; export type GetApiListingsRentalLongTermOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiListingsRentalLongTermResponse = z.array(z.object({id: z.string().optional(), formattedAddress: z.string().optional(), addressLine1: z.string().optional(), addressLine2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), stateFips: z.string().optional(), zipCode: z.string().optional(), county: z.string().optional(), countyFips: z.string().optional(), latitude: z.number().optional(), longitude: z.number().optional(), propertyType: z.string().optional(), bedrooms: z.number().optional(), bathrooms: z.number().optional(), squareFootage: z.number().optional(), lotSize: z.number().optional(), yearBuilt: z.number().optional(), hoa: z.object({fee: z.number().optional()}).optional(), status: z.string().optional(), price: z.number().optional(), listingType: z.string().optional(), listedDate: z.string().optional(), removedDate: z.string().optional(), createdDate: z.string().optional(), lastSeenDate: z.string().optional(), daysOnMarket: z.number().optional(), mlsName: z.string().optional(), mlsNumber: z.string().optional(), listingAgent: z.object({name: z.string().optional(), phone: z.string().optional(), email: z.string().optional(), website: z.string().optional()}).optional(), listingOffice: z.object({name: z.string().optional(), phone: z.string().optional(), email: z.string().optional(), website: z.string().optional()}).optional(), history: z.object({"2024-09-18": z.object({event: z.string().optional(), price: z.number().optional(), listingType: z.string().optional(), listedDate: z.string().optional(), removedDate: z.string().optional(), daysOnMarket: z.number().optional()}).optional()}).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 }; /** * Rental Listings * * GET /listings/rental/long-term */ export const getApiListingsRentalLongTerm = async (args: GetApiListingsRentalLongTermArgs, options?: GetApiListingsRentalLongTermOptions) => { const {baseUrl = "https://api.rentcast.io/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.address != null) query.append("address", String(args.address)) if (args.city != null) query.append("city", String(args.city)) if (args.state != null) query.append("state", String(args.state)) if (args.zipCode != null) query.append("zipCode", String(args.zipCode)) if (args.latitude != null) query.append("latitude", String(args.latitude)) if (args.longitude != null) query.append("longitude", String(args.longitude)) if (args.radius != null) query.append("radius", String(args.radius)) if (args.propertyType != null) query.append("propertyType", String(args.propertyType)) if (args.bedrooms != null) query.append("bedrooms", String(args.bedrooms)) if (args.bathrooms != null) query.append("bathrooms", String(args.bathrooms)) if (args.squareFootage != null) query.append("squareFootage", String(args.squareFootage)) if (args.lotSize != null) query.append("lotSize", String(args.lotSize)) if (args.yearBuilt != null) query.append("yearBuilt", String(args.yearBuilt)) if (args.status != null) query.append("status", String(args.status)) if (args.price != null) query.append("price", String(args.price)) if (args.daysOld != null) query.append("daysOld", String(args.daysOld)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.includeTotalCount != null) query.append("includeTotalCount", String(args.includeTotalCount)) if (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/listings/rental/long-term${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(getApiListingsRentalLongTermResponse, await res.json()) };