import {z} from 'zod' export type UpdateApiAuthoringV1LayoutMappingsIdArgs = {id: string, forceOverride?: boolean | undefined, body: {id?: string | undefined, rev: string, name: string, classification?: 'layout-mapping' | undefined, creatorId?: string | undefined, creator?: string | undefined, created?: string | undefined, lastModifierId?: string | undefined, lastModifier?: string | undefined, lastModified?: string | undefined, path?: string | undefined, tags?: Array | undefined, type: {id?: string | undefined, name?: string | undefined}, mappings: Array<{defaultLayout: {id: string, name?: string | undefined}, layouts: Array<{id: string, name?: string | undefined}>}>, isSystem?: boolean | undefined}}; export type UpdateApiAuthoringV1LayoutMappingsIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const updateApiAuthoringV1LayoutMappingsIdResponse = z.object({id: z.string().min(1).optional(), rev: z.string().min(1), name: z.string().min(1), classification: z.literal("layout-mapping").optional(), creatorId: z.string().optional(), creator: z.string().optional(), created: z.string().optional(), lastModifierId: z.string().optional(), lastModifier: z.string().optional(), lastModified: z.string().optional(), path: z.string().optional(), tags: z.array(z.string()).optional(), type: z.object({id: z.string().min(1).optional(), name: z.string().optional()}), mappings: z.array(z.object({defaultLayout: z.object({id: z.string().min(1), name: z.string().optional()}), layouts: z.array(z.object({id: z.string().min(1), name: z.string().optional()}))})), isSystem: z.boolean().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 an existing layout mapping. * * PUT /authoring/v1/layout-mappings/{id} */ export const updateApiAuthoringV1LayoutMappingsId = async (args: UpdateApiAuthoringV1LayoutMappingsIdArgs, options: UpdateApiAuthoringV1LayoutMappingsIdOptions) => { 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") if (args.forceOverride != null) query.append("forceOverride", String(args.forceOverride)) const url = `${baseUrl.replace(/\/+$/, '')}/authoring/v1/layout-mappings/${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(updateApiAuthoringV1LayoutMappingsIdResponse, await res.json()) };