import {z} from 'zod' export type ListingAdminV2CommercialPrice = {priceUnitType?: ('totalAmount' | 'perSqm') | undefined, priceType?: ('gross' | 'net') | undefined, gstOptionType?: ('nA' | 'inc' | 'ex') | undefined, priceReduction?: boolean | undefined, displayText?: string | undefined, depositTaken?: boolean | undefined, from: number, to: number}; export type ListingAdminV2Lease = {termOfLeaseFrom?: number | undefined, termOfLeaseTo?: number | undefined, leaseOutgoings?: number | undefined}; export type ListingAdminV2EOI = {address?: string | undefined, endDate: string, recipientName?: string | undefined}; export type ListingAdminV2Tenant = {leaseStart?: string | undefined, leaseEnd?: string | undefined, name?: string | undefined, rentalDetails?: string | undefined, leaseOptions?: string | undefined, tenantInfoTermOfLeaseFrom?: number | undefined, tenantInfoTermOfLeaseTo?: number | undefined, leaseDateVariable?: boolean | undefined}; export type ListingAdminV2Tender = {recipientName?: string | undefined, address?: string | undefined, endDate?: string | undefined}; export type ListingAdminV2SpecificUnitDetail = {name?: string | undefined, size?: number | undefined, price?: number | undefined, notes?: string | undefined, isSoldOrLeased?: boolean | undefined, occupancy?: ('tenanted' | 'vacant') | undefined, priceUnit?: ('totalAmount' | 'perSqm') | undefined, leasePriceForSaleorLease?: number | undefined}; export type ListingAdminV2CommercialAuction = {auctionTerms?: string | undefined, dateTime: string, location?: string | undefined, url?: string | undefined}; export type ListingAdminV2Parking = {parkingType?: ('onSite' | 'onStreet' | 'noParking') | undefined, numberOnSite?: number | undefined, information?: string | undefined}; export type ListingAdminV2PropertyPdf = {url: string, type?: ('commercialPdf' | 'newDevBrochurePdf' | 'floorplanPdf' | 'devProjectPdf' | 'devProjectMasterplanPdf') | undefined, description?: string | undefined}; export type ListingAdminV2PropertyMedia = {resourceType?: ('photograph' | 'floorPlan' | 'video' | 'virtualTour' | 'webLink') | undefined, url: string}; export type ListingAdminV2GeoLocation = {latitude?: number | undefined, longitude?: number | undefined}; export type ListingAdminV2Address = {unitNumber?: string | undefined, street: string, displayOption?: ('unspecified' | 'fullAddress' | 'streetAndSuburb' | 'suburbOnly' | 'regionOnly' | 'areaOnly' | 'stateOnly') | undefined, suggestedGeoLocation?: ListingAdminV2GeoLocation | undefined, streetNumber?: string | undefined, suburb: string, postcode: string, state: 'nsw' | 'vic' | 'act' | 'sa' | 'wa' | 'tas' | 'qld' | 'nt'}; export type ListingAdminV2Area = {value?: number | undefined, from?: number | undefined, to?: number | undefined, unit?: ('squareMetres' | 'acres' | 'hectares' | 'squareFeet' | 'squareYards' | 'squares') | undefined}; export type ListingAdminV2LandArea = {unit: 'squareMetres' | 'acres' | 'hectares' | 'squareFeet' | 'squareYards' | 'squares', value?: number | undefined, from?: number | undefined, to?: number | undefined}; export type ListingAdminV2CommercialProperty = {propertyType: Array<'aquaculture' | 'dairyFarming' | 'developmentLand' | 'fishingForestry' | 'hotelLeisure' | 'industrialWarehouse' | 'irrigationServices' | 'livestock' | 'internationalCommercial' | 'medicalConsulting' | 'offices' | 'parkingCarSpace' | 'retail' | 'ruralCommercialFarming' | 'showroomsBulkyGoods' | 'servicedOffices' | 'other' | 'cropping' | 'viticulture' | 'mixedFarming' | 'grazing' | 'horticulture' | 'equine' | 'farmlet' | 'orchard' | 'ruralLifestyle'>, buildingType?: ('whole' | 'part' | 'nA') | undefined, parking?: ListingAdminV2Parking | undefined, pdfs?: Array | undefined, propertyName?: string | undefined, location?: string | undefined, images?: Array | undefined, address: ListingAdminV2Address, area?: ListingAdminV2Area | undefined, landArea?: ListingAdminV2LandArea | undefined}; export type ListingAdminV2AgentContact = {agencyId: number, 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 ListingAdminV2Inspection = {from: string, to: string, repeat?: boolean | undefined}; export type ListingAdminV2InspectionDetails = {inspectionDescription?: string | undefined, inspections?: Array | undefined}; export type ListingAdminV2Contact = {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 ListingAdminV2SupplementaryMetadata = {name: string, description?: string | undefined, measurement?: number | undefined, measurementUnit?: ('squareMetres' | 'hectares' | 'millimetres' | 'dse') | undefined}; export type ListingAdminV2ListingSupplementary = {name: string, description?: string | undefined, types?: Array | undefined, metadata?: Array | undefined}; export type ListingAdminV2CommercialListingV2 = {salePrice?: ListingAdminV2CommercialPrice | undefined, leasePrice?: ListingAdminV2CommercialPrice | undefined, lease?: ListingAdminV2Lease | undefined, eoi?: ListingAdminV2EOI | undefined, tenant?: ListingAdminV2Tenant | undefined, tender?: ListingAdminV2Tender | undefined, occupancyType?: ('tenanted' | 'vacant') | undefined, annualReturn?: number | undefined, unitsOffered?: number | undefined, unitDetails?: Array | undefined, nabers?: number | undefined, saleTerms?: string | undefined, auction?: ListingAdminV2CommercialAuction | undefined, propertyDetails: ListingAdminV2CommercialProperty, conjunctionAgents?: Array | undefined, highlights?: Array | undefined, underOfferOrContract?: boolean | undefined, domainAdId?: number | undefined, listingProvider?: string | undefined, domainAgencyID: number, providerAdId: string, features?: string | undefined, description?: string | undefined, summary?: string | undefined, inspectionDetails?: ListingAdminV2InspectionDetails | undefined, media?: Array | undefined, listingAction: 'sale' | 'rent' | 'saleAndLease', contactPreference?: 'byPhone' | undefined, contacts?: Array | undefined, otherEnquiryEmail?: string | undefined, receiveEmailsToDefaultAddress?: boolean | undefined, isRural?: boolean | undefined, supplementary?: Array | undefined}; export type UpdateApiV2ListingsCommercialArgs = {body: ListingAdminV2CommercialListingV2}; export type UpdateApiV2ListingsCommercialOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; export const listingAdminV2ListingResponse = z.object({id: z.string().optional(), agencyId: z.number().int().optional(), providerId: z.string().optional(), providerAdId: z.string().optional(), versionId: z.string().optional(), processStatus: z.enum(["queued", "processing", "processed", "searchable", "failed", "error"]).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 a commercial listing. * * PUT /v2/listings/commercial * * Also accepts auth: oauth2 */ export const updateApiV2ListingsCommercial = async (args: UpdateApiV2ListingsCommercialArgs, options?: UpdateApiV2ListingsCommercialOptions) => { 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(/\/+$/, '')}/v2/listings/commercial${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(listingAdminV2ListingResponse, await res.json()) };