import {z} from 'zod' export type GetApiV2PropertiesPropertyIdUnitsUnitIdArgs = {property_id: number, unit_id: string}; export type GetApiV2PropertiesPropertyIdUnitsUnitIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({street_address: z.string(), unit_number: z.string().optional(), city: z.string(), state: z.string(), postal_code: z.string(), country: z.string().optional()}); export const unitLeasingStatus = z.enum(["available", "application_hold", "leased", "on_notice", "not_available", "notice_application_hold", "notice_leased"]); export const unitStatus = z.enum(["ready", "renovating", "make_ready", "occupied", "model", "offline"]); export const unitV2 = z.object({id: z.string(), property_id: z.string(), unit_number: z.string(), building_id: z.string().optional(), address: address, bedrooms: z.number().int().gte(0), bathrooms: z.number().gte(0), square_feet: z.number().int().gt(0).optional(), floor: z.number().int().gte(0).optional(), building_name: z.string().optional(), floor_plan: z.string().optional(), floor_plan_id: z.string().optional(), unit_leasing_status: unitLeasingStatus.optional(), unit_status: unitStatus.optional(), available_date: z.string().optional(), market_rent: z.number().optional(), asking_rent: z.number().optional(), created_at: z.string(), updated_at: z.string()}); 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 }; /** * Retrieve a unit * * GET /v2/properties/{property_id}/units/{unit_id} */ export const getApiV2PropertiesPropertyIdUnitsUnitId = async (args: GetApiV2PropertiesPropertyIdUnitsUnitIdArgs, options?: GetApiV2PropertiesPropertyIdUnitsUnitIdOptions) => { const {baseUrl = "https://api.eliseai.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/properties/${encodeURIComponent(String(args.property_id))}/units/${encodeURIComponent(String(args.unit_id))}${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(unitV2, await res.json()) };