import {z} from 'zod' export type DomainListingAdminServiceV1ModelAuction = {dateTime?: string | undefined, location?: string | undefined, url?: string | undefined}; export type DomainListingAdminServiceV1ModelParkingDetails = {parkingType?: ('onSite' | 'onStreet' | 'noParking' | 'garage' | 'carport' | 'outdoor') | undefined, numberOfSpaces?: number | undefined}; export type DomainListingAdminServiceV1ModelParkingInfo = {details?: Array | 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 DomainListingAdminServiceV1ModelLandArea = {unit?: ('squareMetres' | 'acres' | 'hectares' | 'squareFeet' | 'squareYards' | 'squares') | undefined, value?: number | undefined, from?: number | undefined, to?: number | undefined}; export type DomainListingAdminServiceV1ModelResidentialProperty = {propertyType?: (Array<'acreageSemiRural' | 'apartmentUnitFlat' | 'aquaculture' | 'blockOfUnits' | 'carSpace' | 'dairyFarming' | 'developmentSite' | 'duplex' | 'farm' | 'fishingForestry' | 'newHomeDesigns' | 'house' | 'newHouseLand' | 'irrigationServices' | 'newLand' | 'livestock' | 'newApartments' | 'penthouse' | 'retirement' | 'rural' | 'semiDetached' | 'specialistFarm' | 'studio' | 'terrace' | 'townhouse' | 'vacantLand' | 'villa' | 'cropping' | 'viticulture' | 'mixedFarming' | 'grazing' | 'horticulture' | 'equine' | 'farmlet' | 'orchard' | 'ruralLifestyle'>) | undefined, bedRooms?: number | undefined, bathRooms?: number | undefined, parkingInfo?: DomainListingAdminServiceV1ModelParkingInfo | undefined, energyEfficiencyRating?: number | undefined, pdfs?: Array | undefined, isMarkedForLiveability?: boolean | undefined, propertyName?: string | undefined, location?: string | undefined, images?: Array | undefined, address?: DomainListingAdminServiceV1ModelAddress | undefined, area?: DomainListingAdminServiceV1ModelArea | undefined, landArea?: DomainListingAdminServiceV1ModelLandArea | undefined}; export type DomainListingAdminServiceV1ModelBasicPrice = {from?: number | undefined, to?: number | undefined}; export type DomainListingAdminServiceV1ModelPastSaleAddress = {state?: ('nsw' | 'vic' | 'act' | 'sa' | 'wa' | 'tas' | 'qld' | 'nt') | undefined, unitNumber?: string | undefined, streetNumber?: string | undefined, street?: string | undefined, suburb?: string | undefined, postcode?: string | undefined}; export type DomainListingAdminServiceV1ModelPastSaleData = {address?: DomainListingAdminServiceV1ModelPastSaleAddress | undefined, dateOfSale?: string | undefined, soldPrice?: number | undefined}; export type DomainListingAdminServiceV1ModelComparableData = {comparableProperty?: Array | undefined, declarationText?: string | undefined}; export type DomainListingAdminServiceV1ModelMedianPriceData = {priceType?: ('house' | 'apartmentUnitFlat' | 'vacantLand') | undefined, suburb?: string | undefined, postcode?: string | undefined, medianPrice?: number | undefined, source?: string | undefined, sourceDateFrom?: string | undefined, sourceDateTo?: string | undefined, declarationText?: string | undefined}; export type DomainListingAdminServiceV1ModelStatementOfInformation = {estimatedPrice?: DomainListingAdminServiceV1ModelBasicPrice | undefined, comparableData?: DomainListingAdminServiceV1ModelComparableData | undefined, suburbMedianPrice?: DomainListingAdminServiceV1ModelMedianPriceData | undefined, documentationUrl?: string | undefined}; export type DomainListingAdminServiceV1ModelPrice = {displayText?: string | undefined, from?: number | undefined, to?: number | undefined}; export type DomainListingAdminServiceV1ModelListingProject = {id?: number | undefined, order?: 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 DomainListingAdminServiceV1ModelResidentialListing = {lifeStyleType?: ('firstHome' | 'investment' | 'retirement' | 'seaChange' | 'treeChange' | 'youngFamilies') | undefined, listingAction?: ('sale' | 'rent' | 'saleAndLease') | undefined, contactPreference?: 'byPhone' | undefined, underOfferOrContract?: boolean | undefined, auction?: DomainListingAdminServiceV1ModelAuction | undefined, bond?: number | undefined, availableFrom?: string | undefined, propertyDetails?: DomainListingAdminServiceV1ModelResidentialProperty | undefined, isNewDevelopment?: boolean | undefined, statementOfInformation?: DomainListingAdminServiceV1ModelStatementOfInformation | undefined, price?: DomainListingAdminServiceV1ModelPrice | undefined, project?: DomainListingAdminServiceV1ModelListingProject | 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 UpdateApiV1ListingsResidentialArgs = {body: DomainListingAdminServiceV1ModelResidentialListing}; export type UpdateApiV1ListingsResidentialOptions = {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 residential listing * * PUT /v1/listings/residential * * Also accepts auth: oauth2 */ export const updateApiV1ListingsResidential = async (args: UpdateApiV1ListingsResidentialArgs, options?: UpdateApiV1ListingsResidentialOptions) => { 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/residential${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()) };