import {z} from 'zod' export type DomainListingAdminServiceV1ModelLandArea = {unit?: ('squareMetres' | 'acres' | 'hectares' | 'squareFeet' | 'squareYards' | 'squares') | undefined, value?: number | undefined, from?: number | undefined, to?: number | undefined}; export type DomainListingAdminServiceV1ModelParking = {parkingType?: ('onSite' | 'onStreet' | 'noParking') | undefined, numberOnSite?: number | undefined, information?: string | undefined}; export type DomainListingAdminServiceV1ModelPropertyPdf = {type?: ('commercialPdf' | 'newDevBrochurePdf' | 'floorplanPdf' | 'devProjectPdf') | undefined, url?: string | undefined, description?: string | undefined}; export type DomainListingAdminServiceV1ModelPropertyMedia = {resourceType?: ('photograph' | 'floorPlan' | 'video' | 'virtualTour' | 'webLink') | undefined, url?: string | undefined}; export type DomainListingAdminServiceV1ModelGeoLocation = {latitude?: number | undefined, longitude?: number | undefined}; export type DomainListingAdminServiceV1ModelAddress = {displayOption?: ('unspecified' | 'fullAddress' | 'streetAndSuburb' | 'suburbOnly' | 'regionOnly' | 'areaOnly' | 'stateOnly') | undefined, state?: ('nsw' | 'vic' | 'act' | 'sa' | 'wa' | 'tas' | 'qld' | 'nt') | undefined, unitNumber?: string | undefined, street?: string | undefined, suggestedGeoLocation?: DomainListingAdminServiceV1ModelGeoLocation | undefined, streetNumber?: string | undefined, suburb?: string | undefined, postcode?: string | undefined}; export type DomainListingAdminServiceV1ModelArea = {unit?: ('squareMetres' | 'acres' | 'hectares' | 'squareFeet' | 'squareYards' | 'squares') | undefined, value?: number | undefined, from?: number | undefined, to?: number | undefined}; export type DomainListingAdminServiceV1ModelBusinessProperty = {propertyType?: (Array<'accessoriesParts' | 'accommodationTourism' | 'accounting' | 'adult' | 'advertisingMarketing' | 'aerial' | 'aeronautical' | 'agedCare' | 'agricultural' | 'air' | 'aircraft' | 'alarms' | 'alcoholLiquor' | 'amusements' | 'animalRelated' | 'aquaculture' | 'aquaticMarineMarinaBerth' | 'artsCrafts' | 'autoElectrical' | 'automotive' | 'backpackerHostel' | 'bakery' | 'barsNightclubs' | 'beautyHealth' | 'beautyProducts' | 'beautySalon' | 'bikeAndMotorcycle' | 'boardingKennels' | 'boatsMarineMarinaBerth' | 'bookkeeping' | 'brokerage' | 'builder' | 'buildingAndConstruction' | 'bus' | 'butcher' | 'cafeCoffeeShop' | 'car' | 'carBusTruck' | 'carDealership' | 'carRental' | 'carWash' | 'caravanPark' | 'carpenter' | 'catering' | 'childCare' | 'civil' | 'cleaning' | 'cleaningAndMaintenance' | 'clinicalPractice' | 'clothingAccessories' | 'clothingFootwear' | 'communication' | 'communications' | 'computerIT' | 'computerAndInternet' | 'construction' | 'convenienceStore' | 'copyLaminate' | 'courier' | 'cropHarvesting' | 'customs' | 'dairyFarming' | 'deli' | 'dental' | 'detailing' | 'distributors' | 'drivingSchools' | 'educationTraining' | 'educational' | 'electrical' | 'employmentRecruitment' | 'entertainment' | 'entertainmentTechnology' | 'export' | 'farming' | 'fertiliser' | 'finance' | 'financialServices' | 'fishingForestry' | 'floristNursery' | 'foodBeverage' | 'foodBeverageHospitality' | 'franchiseBusinessOpportunities' | 'freight' | 'fruitVegFreshProduce' | 'fruitPicking' | 'functionCentre' | 'furnitureTimber' | 'gambling' | 'gardenHousehold' | 'gardenNurseries' | 'gardening' | 'glassCeramic' | 'guestHouseBB' | 'hairdresser' | 'healthBeauty' | 'healthSpa' | 'hire' | 'homeGarden' | 'homeBased' | 'homewareHardware' | 'hospital' | 'hotel' | 'huntingTrap' | 'import' | 'importExportWholesale' | 'industrialManufacturing' | 'insemination' | 'insurance' | 'internet' | 'irrigationServices' | 'juiceBar' | 'landClearing' | 'landscaping' | 'laundryDryCleaning' | 'legal' | 'leisureEntertainment' | 'limousineTaxi' | 'livestock' | 'machinery' | 'machineryMetal' | 'managementRights' | 'manufacturers' | 'manufacturingEngineering' | 'marine' | 'massage' | 'mechanicalRepair' | 'media' | 'medical' | 'medicalPractice' | 'miningEarthMoving' | 'mobileServices' | 'motel' | 'motorcycle' | 'musicRelated' | 'mustering' | 'nails' | 'naturalTherapies' | 'newsagency' | 'nursery' | 'nursingHome' | 'officeSupplies' | 'oilGas' | 'panelBeating' | 'paperPrinting' | 'parkingCarSpace' | 'pestRelated' | 'pharmacies' | 'plastic' | 'plumbing' | 'poolWater' | 'postOffices' | 'printPhoto' | 'professional' | 'propertyRealEstate' | 'rail' | 'recreationSport' | 'recruitment' | 'repair' | 'resort' | 'restaurant' | 'retail' | 'retailer' | 'retirement' | 'retirementVillage' | 'road' | 'rural' | 'scientific' | 'sea' | 'security' | 'serviceStation' | 'services' | 'shearing' | 'sportsComplexGym' | 'supermarket' | 'takeawayFood' | 'taxi' | 'themePark' | 'tours' | 'training' | 'transportDistribution' | 'travel' | 'truck' | 'vending' | 'water' | 'welding' | 'wholesale' | 'wholesalers' | 'woolClassing' | 'wreckers' | 'alcoholGrocery' | 'cafeRestaurants' | 'discountStore' | 'ecoFriendly' | 'green' | 'grocery' | 'specialityRetail' | 'storage' | 'travelAgency' | 'varietyStore' | 'chickenShop' | 'seafoodShop' | 'deliCafe' | 'cropping' | 'viticulture' | 'grazing' | 'horticulture' | 'equine' | 'farmlet' | 'orchard' | 'ruralLifestyle' | 'onlineBusiness'>) | undefined, landArea?: DomainListingAdminServiceV1ModelLandArea | undefined, parking?: DomainListingAdminServiceV1ModelParking | undefined, pdfs?: Array | undefined, isMarkedForLiveability?: boolean | undefined, propertyName?: string | undefined, location?: string | undefined, images?: Array | undefined, address?: DomainListingAdminServiceV1ModelAddress | undefined, area?: DomainListingAdminServiceV1ModelArea | undefined}; export type DomainListingAdminServiceV1ModelLeaseHoldDetail = {leaseholdRentPeriod?: ('perMonth' | 'perAnnum') | undefined, leaseholdPriceUnit?: ('totalAmount' | 'perSqm') | undefined, leaseholdTerm?: number | undefined, leaseholdStart?: string | undefined, leaseholdRent?: number | undefined}; export type DomainListingAdminServiceV1ModelSaleInfo = {annualSales?: number | undefined, annualProfit?: number | undefined, stockValue?: number | undefined}; export type DomainListingAdminServiceV1ModelPrice = {displayText?: string | undefined, from?: number | undefined, to?: number | undefined}; export type DomainListingAdminServiceV1ModelInspection = {from?: string | undefined, to?: string | undefined, repeat?: boolean | undefined}; export type DomainListingAdminServiceV1ModelInspectionDetails = {inspectionDescription?: string | undefined, inspections?: Array | undefined}; export type DomainListingAdminServiceV1ModelContact = {domainAgentId?: number | undefined, firstName?: string | undefined, lastName?: string | undefined, phone?: string | undefined, fax?: string | undefined, mobile?: string | undefined, email?: string | undefined, receiveEmails?: boolean | undefined}; export type DomainListingAdminServiceV1ModelSupplementaryMetadata = {measurementUnit?: ('squareMetres' | 'hectares' | 'millimetres' | 'dse') | undefined, name?: string | undefined, description?: string | undefined, measurement?: number | undefined}; export type DomainListingAdminServiceV1ModelListingSupplementary = {name?: string | undefined, description?: string | undefined, types?: Array | undefined, metadata?: Array | undefined}; export type DomainListingAdminServiceV1ModelBusinessListing = {listingAction?: ('sale' | 'rent' | 'saleAndLease') | undefined, contactPreference?: 'byPhone' | undefined, underOfferOrContract?: boolean | undefined, nabers?: number | undefined, propertyDetails?: DomainListingAdminServiceV1ModelBusinessProperty | undefined, leaseHoldDetails?: DomainListingAdminServiceV1ModelLeaseHoldDetail | undefined, saleInfo?: DomainListingAdminServiceV1ModelSaleInfo | undefined, freeholdCommercialAdId?: number | undefined, price?: DomainListingAdminServiceV1ModelPrice | undefined, domainAdId?: number | undefined, domainAgencyID?: number | undefined, providerAdId?: string | undefined, features?: string | undefined, description?: string | undefined, summary?: string | undefined, inspectionDetails?: DomainListingAdminServiceV1ModelInspectionDetails | undefined, media?: Array | undefined, contacts?: Array | undefined, otherEnquiryEmail?: string | undefined, receiveEmailsToDefaultAddress?: boolean | undefined, isRural?: boolean | undefined, supplementary?: Array | undefined}; export type UpdateApiV1ListingsBusinessArgs = {body: DomainListingAdminServiceV1ModelBusinessListing}; export type UpdateApiV1ListingsBusinessOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; export const domainListingAdminServiceV1ModelListingResponse = z.object({processStatus: z.enum(["queued", "processing", "processed", "searchable", "failed", "error"]).optional(), id: z.string().optional(), agencyId: z.number().int().optional(), providerId: z.string().optional(), providerAdId: z.string().optional(), versionId: z.string().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 }; /** * Creates or updates a business listing * * PUT /v1/listings/business * * Also accepts auth: oauth2 */ export const updateApiV1ListingsBusiness = async (args: UpdateApiV1ListingsBusinessArgs, options?: UpdateApiV1ListingsBusinessOptions) => { const {baseUrl = "https://api.domain.com.au", fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apikey !== undefined) headers.set("x-api-key", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/listings/business${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(domainListingAdminServiceV1ModelListingResponse, await res.json()) };