import {z} from 'zod' export type CommercialLeaseDTO2 = {size?: (number | null) | undefined, sizeType?: (string | null) | undefined}; export type UpdateListingsForm = {mlsNumber?: (string | null) | undefined, representationType?: (string | null) | undefined, sourceId: number, otherSource?: (string | null) | undefined, listingDate?: (string | null) | undefined, isOfficeLead?: (boolean | null) | undefined, expirationDate: string, listingPrice: number, coListingAgentGuid?: (unknown | null) | undefined, fileID?: (string | null) | undefined, realPropertySubtypeId?: (number | null) | undefined, realPropertyTypeId?: (number | null) | undefined, commercialLease?: (CommercialLeaseDTO2 | null) | undefined}; export type UpdateApiApiV2FilesListingsListingGuidArgs = {listingGuid: unknown, body: UpdateListingsForm}; export type UpdateApiApiV2FilesListingsListingGuidOptions = {baseUrl?: string | undefined, OpenIdConnect?: string | undefined, fetch?: typeof fetch | undefined}; export const updateListingResponse = z.object({}); export const link = z.object({href: z.string().nullable().optional(), rel: z.string().nullable().optional(), method: z.string().nullable().optional()}); export const linkedResponseOfUpdateListingResponse = z.object({value: updateListingResponse.nullable().optional(), warnings: z.array(z.string()).nullable().optional(), links: z.array(link).nullable().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 }; /** * Update listing (V2) * * PUT /api/v2/files/listings/{listingGuid} */ export const updateApiApiV2FilesListingsListingGuid = async (args: UpdateApiApiV2FilesListingsListingGuidArgs, options?: UpdateApiApiV2FilesListingsListingGuidOptions) => { const {baseUrl = "https://api.skyslope.com", fetch: fetchFn = fetch, OpenIdConnect} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OpenIdConnect !== undefined) headers.set('authorization', `Bearer ${OpenIdConnect}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/files/listings/${encodeURIComponent(String(args.listingGuid))}${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(linkedResponseOfUpdateListingResponse, await res.json()) };