import {z} from 'zod' export type UpdateApiPublishingV1SiteRevisionsDefaultArgs = {body: {name: Record, description?: Record | undefined, links?: ({self?: ({href: string, methods: Array<'GET' | 'POST' | 'PUT' | 'DELETE'>, name?: Record | undefined}) | undefined}) | undefined, id: string, rev: string, created?: string | undefined, creator?: {id: string} | undefined, lastModified?: string | undefined, lastModifier?: {id: string} | undefined, state?: ('READY' | 'BUILDING' | 'PENDING') | undefined, autoPublishEnabled?: boolean | undefined, lastSucceeded?: string | undefined, active?: boolean | undefined, job?: {id: string} | undefined}}; export type UpdateApiPublishingV1SiteRevisionsDefaultOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const updateApiPublishingV1SiteRevisionsDefaultResponse = z.object({links: z.object({self: z.object({href: z.string().max(1024), methods: z.array(z.enum(["GET", "POST", "PUT", "DELETE"])), name: z.object({}).optional()})}).optional(), id: z.string().max(64), rev: z.string().max(64), created: z.string(), creator: z.object({id: z.string().max(64)}), lastModified: z.string(), lastModifier: z.object({id: z.string().max(64)}), description: z.object({}).optional(), name: z.object({}), docs: z.object({content: z.object({created: z.array(z.string()).optional(), updated: z.array(z.string()).optional(), deleted: z.array(z.string()).optional()}).optional(), page: z.object({created: z.array(z.string()).optional(), updated: z.array(z.string()).optional(), deleted: z.array(z.string()).optional()}).optional(), site: z.object({created: z.array(z.string()).optional(), updated: z.array(z.string()).optional(), deleted: z.array(z.string()).optional()}).optional(), asset: z.object({created: z.array(z.string()).optional(), updated: z.array(z.string()).optional(), deleted: z.array(z.string()).optional()}).optional(), category: z.object({created: z.array(z.string()).optional(), updated: z.array(z.string()).optional(), deleted: z.array(z.string()).optional()}).optional(), resource: z.object({created: z.array(z.string()).optional(), updated: z.array(z.string()).optional(), deleted: z.array(z.string()).optional()}).optional()}).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 the default site revision * * PUT /publishing/v1/site-revisions/default */ export const updateApiPublishingV1SiteRevisionsDefault = async (args: UpdateApiPublishingV1SiteRevisionsDefaultArgs, options: UpdateApiPublishingV1SiteRevisionsDefaultOptions) => { 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(/\/+$/, '')}/publishing/v1/site-revisions/default${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(updateApiPublishingV1SiteRevisionsDefaultResponse, await res.json()) };