import {z} from 'zod' export type AssetUpdate = {alt_text?: (string | null) | undefined, content_page_id?: (string | null) | undefined, in_gallery: boolean, tags: Array}; export type UpdateApiApiV1AssetsPropertiesPropertyIdAssetIdArgs = {property_id: string, asset_id: string, body: AssetUpdate}; export type UpdateApiApiV1AssetsPropertiesPropertyIdAssetIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const assetKind = z.enum(["IMAGE", "DESIGN_PDF", "PANORAMA"]); export const assetSource = z.enum(["UPLOAD", "WEBSITE", "PMS"]); export const panoramaTiles = z.object({width: z.number().int(), cols: z.number().int(), rows: z.number().int(), base_url: z.string(), tile_url_template: z.string()}); export const assetRead = z.object({id: z.string(), property_id: z.string(), kind: assetKind, source: assetSource, s3_key: z.string(), public_url: z.string().nullable(), content_type: z.string(), filename: z.string(), file_size: z.number().int().nullable(), alt_text: z.string().nullable(), source_url: z.string().nullable(), source_removed_at: z.string().nullable(), tags: z.array(z.string()), content_page_id: z.string().nullable(), display_order: z.number().int(), in_gallery: z.boolean(), room_type_ids: z.array(z.string()).optional(), panorama_tiles: panoramaTiles.nullable()}); 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 Asset * * PUT /api/v1/assets/properties/{property_id}/{asset_id} */ export const updateApiApiV1AssetsPropertiesPropertyIdAssetId = async (args: UpdateApiApiV1AssetsPropertiesPropertyIdAssetIdArgs, options: UpdateApiApiV1AssetsPropertiesPropertyIdAssetIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/assets/properties/${encodeURIComponent(String(args.property_id))}/${encodeURIComponent(String(args.asset_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(assetRead, await res.json()) };