import {z} from 'zod' export type UpdateListingCustomFieldsForm = {isConcierge?: (string | null) | undefined, conciergeProjectNumber?: (string | null) | undefined, serviceType?: (string | null) | undefined, listingId?: (string | null) | undefined, comingSoon?: (string | null) | undefined}; export type UpdateApiApiFilesListingsListingGuidCustomFieldsArgs = {listingGuid: unknown, body: UpdateListingCustomFieldsForm}; export type UpdateApiApiFilesListingsListingGuidCustomFieldsOptions = {baseUrl?: string | undefined, OpenIdConnect?: string | undefined, fetch?: typeof fetch | undefined}; export const updateListingCustomFieldsResponse = z.object({listingGuid: z.string().optional(), isConcierge: z.string().nullable().optional(), conciergeProjectNumber: z.string().nullable().optional(), serviceType: z.string().nullable().optional(), listingId: z.string().nullable().optional(), comingSoon: z.string().nullable().optional()}); export const link = z.object({href: z.string().nullable().optional(), rel: z.string().nullable().optional(), method: z.string().nullable().optional()}); export const linkedResponseOfUpdateListingCustomFieldsResponse = z.object({value: updateListingCustomFieldsResponse.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 custom fields * * PUT /api/files/listings/{listingGuid}/customFields */ export const updateApiApiFilesListingsListingGuidCustomFields = async (args: UpdateApiApiFilesListingsListingGuidCustomFieldsArgs, options?: UpdateApiApiFilesListingsListingGuidCustomFieldsOptions) => { 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/files/listings/${encodeURIComponent(String(args.listingGuid))}/customFields${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(linkedResponseOfUpdateListingCustomFieldsResponse, await res.json()) };