import {z} from 'zod' export type AuthoritiesV1Address = {country: string, number: string, postcode: string, state: string, street: string, suburb: string}; export type AuthoritiesV1CrmDetails = {type: string, id: string}; export type AuthoritiesV1AuthorityResponse = {id: string, address: AuthoritiesV1Address, marketingCampaigns?: (Array<{advertising?: unknown | undefined, campaignType: string, marketingCampaignItems?: (Array<{itemId?: string | undefined, finalPrice?: unknown | undefined, vendorPrice?: unknown | undefined, description?: (string | null) | undefined, selected?: boolean | undefined, hidden?: boolean | undefined, id: string}>) | undefined, comments?: unknown | undefined, commentsFallback?: string | undefined, discountAmount?: (unknown | null) | undefined, discountPercent?: (unknown | null) | undefined, expense?: (string | null) | undefined, other?: unknown | undefined, payableOn?: (string | null) | undefined, total?: unknown | undefined, realhubQuoteId?: (string | null) | undefined, id: string}>) | undefined, vendors?: (Array<{id: string, contact: {id: string, address: AuthoritiesV1Address, dateOfBirth?: (string | null) | undefined, email: string, firstName: string, lastName: string, middleName?: string | undefined, mobile: string, phoneNumber: string, title?: string | undefined, type?: string | undefined}, contactRepresented?: ({id: string, address: AuthoritiesV1Address, email: string, name?: string | undefined, phoneNumber?: string | undefined, fax?: string | undefined, abn?: string | undefined, acn?: string | undefined, gstRegistered?: (boolean | null) | undefined, type?: string | undefined}) | undefined, conciergeOptedIn?: (boolean | null) | undefined, nature: string, trust?: (string | null) | undefined, order: number, authorityAttachments?: Array | undefined}>) | undefined, agents?: (Array<{id: string, name: string, email: string, user?: string | undefined, mobile?: string | undefined, officeNumber?: string | undefined, licenseNumber?: string | undefined}>) | undefined, bathrooms: number, bedrooms: number, parking: number, propertyType: string, created?: string | undefined, modified?: string | undefined, status?: string | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, administrationFee?: string | undefined, agentDetailsDate?: string | undefined, auctionDate?: string | undefined, auctionType?: string | undefined, chattelsExcluded?: string | undefined, chattelsIncluded?: Array | undefined, continuingPeriod?: number | undefined, espRangeHigher?: number | undefined, espRangeLower?: number | undefined, exclusivePeriod?: number | undefined, exclusivePeriodStartDate?: string | undefined, exclusiveSoldAs?: (string | null) | undefined, isOwnersCorporationManaged?: boolean | undefined, isPropertyTenanted?: boolean | undefined, occupationState?: (string | null) | undefined, optOutInformation?: boolean | undefined, payableIn?: Array | undefined, paymentMethod?: (string | null) | undefined, paymentSum?: number | undefined, reservePrice?: number | undefined, salePriceGstType?: string | undefined, saleSignPermission?: boolean | undefined, searchCriteriaAmount?: number | undefined, searchCriteriaPriceType?: string | undefined, transactionType?: string | undefined, type: string, vendorMktPriceNa?: boolean | undefined, waivedCoolingOff?: boolean | undefined, lot?: string | undefined, plan?: string | undefined, titleReference?: string | undefined, certificateOfTitleType?: string | undefined, certificateOfTitleFolio?: string | undefined, certificateOfTitleVolume?: string | undefined, improvedLand?: boolean | undefined, crmDetails?: AuthoritiesV1CrmDetails | undefined}; export type UpdateApiV1AuthoritiesIdArgs = {id: string, body: AuthoritiesV1AuthorityResponse}; export type UpdateApiV1AuthoritiesIdOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; export const authoritiesV1Address = z.object({country: z.string(), number: z.string(), postcode: z.string(), state: z.string(), street: z.string(), suburb: z.string()}); export const authoritiesV1CrmDetails = z.object({type: z.string(), id: z.string()}); export const authoritiesV1AuthorityResponse = z.object({id: z.string(), address: authoritiesV1Address, marketingCampaigns: z.array(z.object({advertising: z.string().optional(), campaignType: z.string(), marketingCampaignItems: z.array(z.object({itemId: z.string().optional(), finalPrice: z.string().optional(), vendorPrice: z.string().optional(), description: z.string().nullable().optional(), selected: z.boolean().optional(), hidden: z.boolean().optional(), id: z.string()})).optional(), comments: z.string().optional(), commentsFallback: z.string().optional(), discountAmount: z.string().nullable().optional(), discountPercent: z.string().nullable().optional(), expense: z.string().nullable().optional(), other: z.string().optional(), payableOn: z.string().nullable().optional(), total: z.string().optional(), realhubQuoteId: z.string().nullable().optional(), id: z.string()})).optional(), vendors: z.array(z.object({id: z.string(), contact: z.object({id: z.string(), address: authoritiesV1Address, dateOfBirth: z.string().nullable().optional(), email: z.string(), firstName: z.string(), lastName: z.string(), middleName: z.string().optional(), mobile: z.string(), phoneNumber: z.string(), title: z.string().optional(), type: z.string().optional()}), contactRepresented: z.object({id: z.string(), address: authoritiesV1Address, email: z.string(), name: z.string().optional(), phoneNumber: z.string().optional(), fax: z.string().optional(), abn: z.string().optional(), acn: z.string().optional(), gstRegistered: z.boolean().nullable().optional(), type: z.string().optional()}).optional(), conciergeOptedIn: z.boolean().nullable().optional(), nature: z.string(), trust: z.string().nullable().optional(), order: z.number().int(), authorityAttachments: z.array(z.string()).optional()})).optional(), agents: z.array(z.object({id: z.string(), name: z.string(), email: z.string(), user: z.string().optional(), mobile: z.string().optional(), officeNumber: z.string().optional(), licenseNumber: z.string().optional()})).optional(), bathrooms: z.number().int(), bedrooms: z.number().int(), parking: z.number().int(), propertyType: z.string(), created: z.string().optional(), modified: z.string().optional(), status: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), administrationFee: z.string().optional(), agentDetailsDate: z.string().optional(), auctionDate: z.string().optional(), auctionType: z.string().optional(), chattelsExcluded: z.string().optional(), chattelsIncluded: z.array(z.string()).optional(), continuingPeriod: z.number().optional(), espRangeHigher: z.number().optional(), espRangeLower: z.number().optional(), exclusivePeriod: z.number().optional(), exclusivePeriodStartDate: z.string().optional(), exclusiveSoldAs: z.string().nullable().optional(), isOwnersCorporationManaged: z.boolean().optional(), isPropertyTenanted: z.boolean().optional(), occupationState: z.string().nullable().optional(), optOutInformation: z.boolean().optional(), payableIn: z.array(z.string()).optional(), paymentMethod: z.string().nullable().optional(), paymentSum: z.number().optional(), reservePrice: z.number().optional(), salePriceGstType: z.string().optional(), saleSignPermission: z.boolean().optional(), searchCriteriaAmount: z.number().optional(), searchCriteriaPriceType: z.string().optional(), transactionType: z.string().optional(), type: z.string(), vendorMktPriceNa: z.boolean().optional(), waivedCoolingOff: z.boolean().optional(), lot: z.string().max(32).optional(), plan: z.string().max(32).optional(), titleReference: z.string().max(32).optional(), certificateOfTitleType: z.string().optional(), certificateOfTitleFolio: z.string().optional(), certificateOfTitleVolume: z.string().optional(), improvedLand: z.boolean().optional(), crmDetails: authoritiesV1CrmDetails.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 }; /** * full update an existing authority. * * PUT /v1/authorities/{id} * * Also accepts auth: oauth2 */ export const updateApiV1AuthoritiesId = async (args: UpdateApiV1AuthoritiesIdArgs, options?: UpdateApiV1AuthoritiesIdOptions) => { 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/vnd.realtimeagent.authorities.v1+json") headers.set('accept', "application/vnd.realtimeagent.authorities.v1+json") if (apikey !== undefined) headers.set("x-api-key", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/authorities/${encodeURIComponent(String(args.id))}${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(authoritiesV1AuthorityResponse, await res.json()) };