import {z} from 'zod' export type GetApiAuthoringV1LayoutsIdArgs = {id: string, fields?: string | undefined, include?: string | undefined, 'If-None-Match'?: string | undefined}; export type GetApiAuthoringV1LayoutsIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiAuthoringV1LayoutsIdResponse = z.object({id: z.string().min(1).optional(), rev: z.string().min(1), name: z.string().min(1), description: z.string().optional(), classification: z.literal("layout").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(), prerender: z.boolean().optional(), tags: z.array(z.string()).optional(), thumbnail: z.object({id: z.string().optional(), path: z.string().optional(), url: z.string().optional()}).optional(), template: z.string().min(1), templateType: z.enum(["handlebars", "angular"]).optional(), urlTemplate: 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 }; /** * Retrieve an existing layout. * * GET /authoring/v1/layouts/{id} */ export const getApiAuthoringV1LayoutsId = async (args: GetApiAuthoringV1LayoutsIdArgs, options: GetApiAuthoringV1LayoutsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.fields != null) query.append("fields", String(args.fields)) if (args.include != null) query.append("include", String(args.include)) if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) const url = `${baseUrl.replace(/\/+$/, '')}/authoring/v1/layouts/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiAuthoringV1LayoutsIdResponse, await res.json()) };