import {z} from 'zod' export type GetApiBucketsSlugObjectsObjectIdRevisionsRevisionIdArgs = {read_key?: string | undefined, preview_token?: string | undefined, props?: string | undefined, useCache?: boolean | undefined, pretty?: boolean | undefined}; export type GetApiBucketsSlugObjectsObjectIdRevisionsRevisionIdOptions = {baseUrl?: string | undefined, readKey?: string | undefined, fetch?: typeof fetch | undefined}; export const metadata = z.record(z.string(), z.unknown()); export const revision = z.object({id: z.string().optional(), object_id: z.string().optional(), type: z.string().optional(), title: z.string().optional(), slug: z.string().optional(), status: z.enum(["published", "draft"]).optional(), content: z.string().nullable().optional(), metadata: metadata.optional(), bucket: z.string().optional(), thumbnail: z.string().nullable().optional(), locale: z.string().nullable().optional(), created_at: z.string().optional(), created_by: z.string().optional(), modified_at: z.string().optional(), published_at: z.string().nullable().optional()}).and(z.record(z.string(), z.unknown())); export const revisionResponse = z.object({revision: revision}); 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 }; /** * Get a single revision * * GET /buckets/{slug}/objects/{object_id}/revisions/{revision_id} */ export const getApiBucketsSlugObjectsObjectIdRevisionsRevisionId = async (args: GetApiBucketsSlugObjectsObjectIdRevisionsRevisionIdArgs, options?: GetApiBucketsSlugObjectsObjectIdRevisionsRevisionIdOptions) => { const {baseUrl = "https://api.cosmicjs.com/v3", fetch: fetchFn = fetch, readKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.read_key != null) query.append("read_key", String(args.read_key)) if (args.preview_token != null) query.append("preview_token", String(args.preview_token)) if (args.props != null) query.append("props", String(args.props)) if (args.useCache != null) query.append("useCache", String(args.useCache)) if (args.pretty != null) query.append("pretty", String(args.pretty)) if (readKey !== undefined) query.set("read_key", readKey) const url = `${baseUrl.replace(/\/+$/, '')}/buckets/${encodeURIComponent(String(args.slug))}/objects/${encodeURIComponent(String(args.object_id))}/revisions/${encodeURIComponent(String(args.revision_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(revisionResponse, await res.json()) };