import {z} from 'zod' export type CountryCodeParam = 'ad' | 'ae' | 'af' | 'ag' | 'ai' | 'al' | 'am' | 'ao' | 'aq' | 'ar' | 'as' | 'at' | 'au' | 'aw' | 'ax' | 'az' | 'ba' | 'bb' | 'bd' | 'be' | 'bf' | 'bg' | 'bh' | 'bi' | 'bj' | 'bl' | 'bm' | 'bn' | 'bo' | 'bq' | 'br' | 'bs' | 'bt' | 'bv' | 'bw' | 'by' | 'bz' | 'ca' | 'cc' | 'cd' | 'cf' | 'cg' | 'ch' | 'ci' | 'ck' | 'cl' | 'cm' | 'cn' | 'co' | 'cr' | 'cu' | 'cv' | 'cw' | 'cx' | 'cy' | 'cz' | 'de' | 'dj' | 'dk' | 'dm' | 'do' | 'dz' | 'ec' | 'ee' | 'eg' | 'eh' | 'er' | 'es' | 'et' | 'fi' | 'fj' | 'fk' | 'fm' | 'fo' | 'fr' | 'ga' | 'gb' | 'gd' | 'ge' | 'gf' | 'gg' | 'gh' | 'gi' | 'gl' | 'gm' | 'gn' | 'gp' | 'gq' | 'gr' | 'gs' | 'gt' | 'gu' | 'gw' | 'gy' | 'hk' | 'hm' | 'hn' | 'hr' | 'ht' | 'hu' | 'id' | 'ie' | 'il' | 'im' | 'in' | 'io' | 'iq' | 'ir' | 'is' | 'it' | 'je' | 'jm' | 'jo' | 'jp' | 'ke' | 'kg' | 'kh' | 'ki' | 'km' | 'kn' | 'kp' | 'kr' | 'kw' | 'ky' | 'kz' | 'la' | 'lb' | 'lc' | 'li' | 'lk' | 'lr' | 'ls' | 'lt' | 'lu' | 'lv' | 'ly' | 'ma' | 'mc' | 'md' | 'me' | 'mf' | 'mg' | 'mh' | 'mk' | 'ml' | 'mm' | 'mn' | 'mo' | 'mp' | 'mq' | 'mr' | 'ms' | 'mt' | 'mu' | 'mv' | 'mw' | 'mx' | 'my' | 'mz' | 'na' | 'nc' | 'ne' | 'nf' | 'ng' | 'ni' | 'nl' | 'no' | 'np' | 'nr' | 'nu' | 'nz' | 'om' | 'pa' | 'pe' | 'pf' | 'pg' | 'ph' | 'pk' | 'pl' | 'pm' | 'pn' | 'pr' | 'ps' | 'pt' | 'pw' | 'py' | 'qa' | 're' | 'ro' | 'rs' | 'ru' | 'rw' | 'sa' | 'sb' | 'sc' | 'sd' | 'se' | 'sg' | 'sh' | 'si' | 'sj' | 'sk' | 'sl' | 'sm' | 'sn' | 'so' | 'sr' | 'ss' | 'st' | 'sv' | 'sx' | 'sy' | 'sz' | 'tc' | 'td' | 'tf' | 'tg' | 'th' | 'tj' | 'tk' | 'tl' | 'tm' | 'tn' | 'to' | 'tr' | 'tt' | 'tv' | 'tw' | 'tz' | 'ua' | 'ug' | 'um' | 'us' | 'uy' | 'uz' | 'va' | 'vc' | 've' | 'vg' | 'vi' | 'vn' | 'vu' | 'wf' | 'ws' | 'xk' | 'ye' | 'yt' | 'za' | 'zm' | 'zw'; 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 MarketType = 'urban_metro' | 'mountains_lakes' | 'coastal' | 'suburban' | 'rural' | 'mid_size_city'; 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 CountryListingsFilterListSchema = 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: 'investability', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'investability', type: 'select', value: number} | {field: 'investability', type: 'range', value: Array} | {field: 'listing_count', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'listing_count', type: 'select', value: number} | {field: 'listing_count', type: 'range', value: Array} | {field: 'listing_type', type: 'select', value: 'entire_place' | 'private_room' | 'shared_room'} | {field: 'listing_type', type: 'multi_select', value: Array} | {field: 'market_id', type: 'select', value: string} | {field: 'market_id', type: 'multi_select', value: Array} | {field: 'market_type', type: 'select', value: 'urban_metro' | 'mountains_lakes' | 'coastal' | 'suburban' | 'rural' | 'mid_size_city'} | {field: 'market_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: 'regulation', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'regulation', type: 'select', value: number} | {field: 'regulation', type: 'range', value: Array} | {field: 'rental_demand', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'rental_demand', type: 'select', value: number} | {field: 'rental_demand', type: 'range', value: Array} | {field: 'revenue_growth', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'revenue_growth', type: 'select', value: number} | {field: 'revenue_growth', type: 'range', 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: 'seasonality', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'seasonality', type: 'select', value: number} | {field: 'seasonality', 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 ListingSortOrder = 'revenue' | 'occupancy' | 'adr' | 'review_count'; export type CountryListingsRequestSchema = {pagination: PaginationRequestSchema, filters?: CountryListingsFilterListSchema | undefined, currency?: CurrencyISO | undefined, sort_order?: ListingSortOrder | undefined}; export type CreateApiCountryCountryCodeListingsArgs = {countryCode: CountryCodeParam, body: CountryListingsRequestSchema}; export type CreateApiCountryCountryCodeListingsOptions = {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 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 listingSummary = 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, images: z.array(z.string())}); export const countryListingsResponseSchema = z.object({page_info: paginationResponseSchema, sort_order: listingSortOrder, listings: z.array(listingSummary)}); export const status = z.object({type: z.enum(["success", "error"]), response_id: z.string(), message: z.string()}); export const createApiCountryCountryCodeListingsResponse = z.object({payload: countryListingsResponseSchema, 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 Country. * * POST /country/{countryCode}/listings */ export const createApiCountryCountryCodeListings = async (args: CreateApiCountryCountryCodeListingsArgs, options?: CreateApiCountryCountryCodeListingsOptions) => { 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(/\/+$/, '')}/country/${encodeURIComponent(String(args.countryCode))}/listings${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(createApiCountryCountryCodeListingsResponse, await res.json()) };