import {z} from 'zod' export type PaginationRequestSchema = {offset: number, page_size: number}; export type ChannelOption = 'airbnb' | 'vrbo' | 'booking'; export type ListingType = 'entire_place' | 'private_room' | 'shared_room'; export type PriceTier = 'budget' | 'economy' | 'midscale' | 'upscale' | 'luxury'; export type PropertyType = 'apartment' | 'barn' | 'bed_and_breakfast' | 'boat' | 'building' | 'bungalow' | 'bus' | 'cabin' | 'camper_rv' | 'campsite' | 'caravan' | 'casa_particular' | 'castle' | 'cave' | 'chalet' | 'condominium' | 'corporate_apartment' | 'cottage' | 'country_house' | 'cycladic_house' | 'dammuso' | 'dome_house' | 'earth_house' | 'estate' | 'farm_stay' | 'farmhouse' | 'guest_house' | 'guest_suite' | 'holiday_park' | 'house' | 'house_boat' | 'hut' | 'igloo' | 'island' | 'kezhan' | 'lighthouse' | 'loft' | 'mas' | 'mobile_home' | 'nature_lodge' | 'other' | 'place' | 'ranch' | 'riad' | 'serviced_apartment' | 'shepherds_hut' | 'shipping_container' | 'studio' | 'tent' | 'tiny_house' | 'tipi' | 'tower' | 'townhouse' | 'train' | 'treehouse' | 'vacation_home' | 'villa' | 'windmill' | 'yacht' | 'yurt' | null; export type RealEstateType = 'apartment' | 'bed_and_breakfast' | 'house' | 'unique'; export type MarketListingsFilterListSchema = Array<{field: 'accommodates', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'accommodates', type: 'select', value: number} | {field: 'accommodates', type: 'range', value: Array} | {field: 'amenities', type: 'jsonb_boolean', value: {has_aircon?: boolean | undefined, has_breakfast?: boolean | undefined, has_cable_tv?: boolean | undefined, has_dryer?: boolean | undefined, has_elevator?: boolean | undefined, has_gym?: boolean | undefined, has_heating?: boolean | undefined, has_hottub?: boolean | undefined, has_kitchen?: boolean | undefined, has_parking?: boolean | undefined, has_pets_allowed?: boolean | undefined, has_pool?: boolean | undefined, has_smoking?: boolean | undefined, has_tv?: boolean | undefined, has_washer?: boolean | undefined, has_wireless_internet?: boolean | undefined}} | {field: 'bathrooms', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'bathrooms', type: 'select', value: number} | {field: 'bathrooms', type: 'range', value: Array} | {field: 'bedrooms', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'bedrooms', type: 'select', value: number} | {field: 'bedrooms', type: 'range', value: Array} | {field: 'channels', type: 'jsonb_array', value: Array} | {field: 'channels', type: 'jsonb_array_subset', value: Array} | {field: 'channels', type: 'jsonb_array_exact', value: Array} | {field: 'days_available_ltm', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'days_available_ltm', type: 'select', value: number} | {field: 'days_available_ltm', type: 'range', value: Array} | {field: 'instant_book', type: 'select', value: boolean} | {field: 'listing_type', type: 'select', value: 'entire_place' | 'private_room' | 'shared_room'} | {field: 'listing_type', type: 'multi_select', value: Array} | {field: 'occupancy_rate_ltm', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'occupancy_rate_ltm', type: 'select', value: number} | {field: 'occupancy_rate_ltm', type: 'range', value: Array} | {field: 'price_tier', type: 'select', value: 'budget' | 'economy' | 'midscale' | 'upscale' | 'luxury'} | {field: 'price_tier', type: 'multi_select', value: Array} | {field: 'professionally_managed', type: 'select', value: boolean} | {field: 'property_type', type: 'select', value: 'apartment' | 'barn' | 'bed_and_breakfast' | 'boat' | 'building' | 'bungalow' | 'bus' | 'cabin' | 'camper_rv' | 'campsite' | 'caravan' | 'casa_particular' | 'castle' | 'cave' | 'chalet' | 'condominium' | 'corporate_apartment' | 'cottage' | 'country_house' | 'cycladic_house' | 'dammuso' | 'dome_house' | 'earth_house' | 'estate' | 'farm_stay' | 'farmhouse' | 'guest_house' | 'guest_suite' | 'holiday_park' | 'house' | 'house_boat' | 'hut' | 'igloo' | 'island' | 'kezhan' | 'lighthouse' | 'loft' | 'mas' | 'mobile_home' | 'nature_lodge' | 'other' | 'place' | 'ranch' | 'riad' | 'serviced_apartment' | 'shepherds_hut' | 'shipping_container' | 'studio' | 'tent' | 'tiny_house' | 'tipi' | 'tower' | 'townhouse' | 'train' | 'treehouse' | 'vacation_home' | 'villa' | 'windmill' | 'yacht' | 'yurt' | null} | {field: 'property_type', type: 'multi_select', value: Array} | {field: 'ratings', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'ratings', type: 'select', value: number} | {field: 'ratings', type: 'range', value: Array} | {field: 'real_estate_type', type: 'select', value: 'apartment' | 'bed_and_breakfast' | 'house' | 'unique'} | {field: 'real_estate_type', type: 'multi_select', value: Array} | {field: 'reviews_count', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'reviews_count', type: 'select', value: number} | {field: 'reviews_count', type: 'range', value: Array} | {field: 'superhost', type: 'select', value: boolean}>; export type CurrencyISO = 'afn' | 'all' | 'dzd' | 'usd' | 'eur' | 'aoa' | 'xcd' | 'ars' | 'amd' | 'awg' | 'aud' | 'azn' | 'bsd' | 'bhd' | 'bdt' | 'bbd' | 'byn' | 'bzd' | 'xof' | 'bmd' | 'btn' | 'inr' | 'bob' | 'bov' | 'bam' | 'bwp' | 'nok' | 'brl' | 'bnd' | 'bgn' | 'bif' | 'cve' | 'khr' | 'xaf' | 'cad' | 'kyd' | 'clf' | 'clp' | 'cny' | 'cop' | 'cou' | 'kmf' | 'cdf' | 'nzd' | 'crc' | 'hrk' | 'cuc' | 'cup' | 'ang' | 'czk' | 'dkk' | 'djf' | 'dop' | 'egp' | 'svc' | 'ern' | 'etb' | 'fkp' | 'fjd' | 'xpf' | 'gmd' | 'gel' | 'ghs' | 'gip' | 'gtq' | 'gbp' | 'gnf' | 'gyd' | 'htg' | 'hnl' | 'hkd' | 'huf' | 'isk' | 'idr' | 'xdr' | 'irr' | 'iqd' | 'ils' | 'jmd' | 'jpy' | 'jod' | 'kzt' | 'kes' | 'kpw' | 'krw' | 'kwd' | 'kgs' | 'lak' | 'lbp' | 'lsl' | 'zar' | 'lrd' | 'lyd' | 'chf' | 'mop' | 'mga' | 'mwk' | 'myr' | 'mvr' | 'mru' | 'mur' | 'xua' | 'mxn' | 'mxv' | 'mdl' | 'mnt' | 'mad' | 'mzn' | 'mmk' | 'nad' | 'npr' | 'nio' | 'ngn' | 'omr' | 'pkr' | 'pab' | 'pgk' | 'pyg' | 'pen' | 'php' | 'pln' | 'qar' | 'mkd' | 'ron' | 'rub' | 'rwf' | 'shp' | 'wst' | 'stn' | 'sar' | 'rsd' | 'scr' | 'sle' | 'sgd' | 'xsu' | 'sbd' | 'sos' | 'ssp' | 'lkr' | 'sdg' | 'srd' | 'szl' | 'sek' | 'che' | 'chw' | 'syp' | 'twd' | 'tjs' | 'tzs' | 'thb' | 'top' | 'ttd' | 'tnd' | 'try' | 'tmt' | 'ugx' | 'uah' | 'aed' | 'usn' | 'uyi' | 'uyu' | 'uzs' | 'vuv' | 'vef' | 'ved' | 'vnd' | 'yer' | 'zmw' | 'zwl'; export type SortDirection = 'ascending' | 'descending'; export type ListingCompsInAreaRequestAddressSchema = {address: string, radius: number, pagination: PaginationRequestSchema, filters?: MarketListingsFilterListSchema | undefined, currency?: CurrencyISO | undefined, sort_order?: ('proximity' | 'revenue' | 'adr' | 'review_count') | undefined, sort_direction?: SortDirection | undefined}; export type ListingCompsInAreaRequestLatLngSchema = {lat: number, lng: number, radius: number, pagination: PaginationRequestSchema, filters?: MarketListingsFilterListSchema | undefined, currency?: CurrencyISO | undefined, sort_order?: ('proximity' | 'revenue' | 'adr' | 'review_count') | undefined, sort_direction?: SortDirection | undefined}; export type CreateApiListingCompsAreaArgs = {body: ListingCompsInAreaRequestAddressSchema | ListingCompsInAreaRequestLatLngSchema}; export type CreateApiListingCompsAreaOptions = {baseUrl?: string | undefined, headerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const paginationResponseSchema = z.object({total_count: z.number().gte(0), offset: z.number().gte(0), page_size: z.number().gte(1).lte(25)}); export const listingSortOrder = z.enum(["revenue", "occupancy", "adr", "review_count"]); export const sortDirection = z.enum(["ascending", "descending"]); export const geomPoint = z.object({lat: z.number(), lng: z.number()}); export const listingRatings = z.object({overall_rating: z.number().lte(5).nullable(), airbnb_accuracy_rating: z.number().lte(5).nullable(), airbnb_cleanliness_rating: z.number().lte(5).nullable(), airbnb_checkin_rating: z.number().lte(5).nullable(), airbnb_communication_rating: z.number().lte(5).nullable(), airbnb_location_rating: z.number().lte(5).nullable(), airbnb_value_rating: z.number().lte(5).nullable()}); export const listingType = z.enum(["entire_place", "private_room", "shared_room"]); export const propertyType = z.enum(["apartment", "barn", "bed_and_breakfast", "boat", "building", "bungalow", "bus", "cabin", "camper_rv", "campsite", "caravan", "casa_particular", "castle", "cave", "chalet", "condominium", "corporate_apartment", "cottage", "country_house", "cycladic_house", "dammuso", "dome_house", "earth_house", "estate", "farm_stay", "farmhouse", "guest_house", "guest_suite", "holiday_park", "house", "house_boat", "hut", "igloo", "island", "kezhan", "lighthouse", "loft", "mas", "mobile_home", "nature_lodge", "other", "place", "ranch", "riad", "serviced_apartment", "shepherds_hut", "shipping_container", "studio", "tent", "tiny_house", "tipi", "tower", "townhouse", "train", "treehouse", "vacation_home", "villa", "windmill", "yacht", "yurt"]).nullable(); export const cancellationPolicy = z.enum(["flexible", "moderate", "strict", "super_strict", "no refund"]).nullable(); export const amenities = z.object({has_aircon: z.boolean(), has_breakfast: z.boolean(), has_cable_tv: z.boolean(), has_doorman: z.boolean(), has_dryer: z.boolean(), has_elevator: z.boolean(), has_family_friendly: z.boolean(), has_guidebook: z.boolean(), has_gym: z.boolean(), has_handicap_access: z.boolean(), has_heating: z.boolean(), has_hottub: z.boolean(), has_indoor_fireplace: z.boolean(), has_intercom: z.boolean(), has_internet: z.boolean(), has_kitchen: z.boolean(), has_parking: z.boolean(), has_pets_allowed: z.boolean(), has_pool: z.boolean(), has_smoking: z.boolean(), has_suitable_for_events: z.boolean(), has_tv: z.boolean(), has_washer: z.boolean(), has_wireless_internet: z.boolean()}); export const hostSize = z.enum(["1", "2-5", "6-20", "21+"]); export const currencyISO = z.enum(["afn", "all", "dzd", "usd", "eur", "aoa", "xcd", "ars", "amd", "awg", "aud", "azn", "bsd", "bhd", "bdt", "bbd", "byn", "bzd", "xof", "bmd", "btn", "inr", "bob", "bov", "bam", "bwp", "nok", "brl", "bnd", "bgn", "bif", "cve", "khr", "xaf", "cad", "kyd", "clf", "clp", "cny", "cop", "cou", "kmf", "cdf", "nzd", "crc", "hrk", "cuc", "cup", "ang", "czk", "dkk", "djf", "dop", "egp", "svc", "ern", "etb", "fkp", "fjd", "xpf", "gmd", "gel", "ghs", "gip", "gtq", "gbp", "gnf", "gyd", "htg", "hnl", "hkd", "huf", "isk", "idr", "xdr", "irr", "iqd", "ils", "jmd", "jpy", "jod", "kzt", "kes", "kpw", "krw", "kwd", "kgs", "lak", "lbp", "lsl", "zar", "lrd", "lyd", "chf", "mop", "mga", "mwk", "myr", "mvr", "mru", "mur", "xua", "mxn", "mxv", "mdl", "mnt", "mad", "mzn", "mmk", "nad", "npr", "nio", "ngn", "omr", "pkr", "pab", "pgk", "pyg", "pen", "php", "pln", "qar", "mkd", "ron", "rub", "rwf", "shp", "wst", "stn", "sar", "rsd", "scr", "sle", "sgd", "xsu", "sbd", "sos", "ssp", "lkr", "sdg", "srd", "szl", "sek", "che", "chw", "syp", "twd", "tjs", "tzs", "thb", "top", "ttd", "tnd", "try", "tmt", "ugx", "uah", "aed", "usn", "uyi", "uyu", "uzs", "vuv", "vef", "ved", "vnd", "yer", "zmw", "zwl"]); export const listingCompsInAreaResponseSchema = z.object({page_info: paginationResponseSchema, sort_order: listingSortOrder, sort_direction: sortDirection, listings: z.array(z.object({property_id: z.string(), airbnb_host_id: z.string().nullable(), airbnb_property_id: z.string(), airbnb_property_url: z.string().nullable(), vrbo_property_id: z.string(), vrbo_property_url: z.string().nullable(), booking_property_id: z.string().nullable(), booking_property_url: z.string().nullable(), market_id: z.string(), market_name: z.string(), country_name: z.string(), city_name: z.string(), state_name: z.string().nullable(), zipcode: z.string().nullable(), msa_name: z.string().nullable(), location: geomPoint, exact_location: z.boolean().nullable(), title: z.string(), bedrooms: z.number().int(), bathrooms: z.number(), accommodates: z.number().int(), rating: z.number().lte(5).nullable(), ratings: listingRatings, listing_type: listingType, property_type: propertyType, instant_book: z.boolean(), superhost: z.boolean(), cancellation_policy: cancellationPolicy, amenities: amenities, host_size: hostSize, property_manager_name: z.string(), professionally_managed: z.boolean(), reviews: z.number().int().nullable(), revenue_ltm: z.number().int(), revenue_potential_ltm: z.number().int(), occupancy_rate_ltm: z.number(), average_daily_rate_ltm: z.number(), days_available_ltm: z.number().int(), days_blocked_ltm: z.number().int(), days_reserved_ltm: z.number().int(), num_reservations_ltm: z.number().int(), cleaning_fee: z.number().nullable(), created_date: z.string(), last_calendar_update: z.string(), last_scraped_date: z.string(), license: z.string().nullable(), minimum_stay: z.number().int().gte(1), response_rate: z.number().lte(100).nullable(), response_time: z.number().nullable(), currency: currencyISO, distance: z.number().nullable()}))}); export const status = z.object({type: z.enum(["success", "error"]), response_id: z.string(), message: z.string()}); export const createApiListingCompsAreaResponse = z.object({payload: listingCompsInAreaResponseSchema, status: status}); 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 }; /** * Explore Listings Within a Given Radius * * POST /listing/comps/area */ export const createApiListingCompsArea = async (args: CreateApiListingCompsAreaArgs, options?: CreateApiListingCompsAreaOptions) => { const {baseUrl = "https://api.airdna.co/api/enterprise/v2", fetch: fetchFn = fetch, headerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (headerAuth !== undefined) headers.set('authorization', `Bearer ${headerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/listing/comps/area${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiListingCompsAreaResponse, await res.json()) };