import {z} from 'zod' export type GetApiAuthoringV1ImageProfilesArgs = {offset?: number | undefined, limit?: number | undefined, format?: ('feed' | 'array' | 'sequence') | undefined, pageMode?: ('offset' | 'deep') | undefined, order?: ('ascending' | 'descending') | undefined, fields?: string | undefined, include?: string | undefined}; export type GetApiAuthoringV1ImageProfilesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiAuthoringV1ImageProfilesResponse = z.object({offset: z.number().int().optional(), limit: z.number().int().optional(), href: z.string().optional(), next: z.string().optional(), previous: z.string().optional(), items: z.array(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("image-profile"), creatorId: z.string().min(1), creator: z.string().optional(), created: z.string().min(1).optional(), lastModifierId: z.string().min(1).optional(), lastModifier: z.string().optional(), lastModified: z.string().min(1).optional(), tags: z.array(z.string()).optional(), dimensions: z.array(z.object({label: z.string().optional(), key: z.string().optional(), description: z.string().optional(), width: z.number().optional(), height: z.number().optional()})), isSystem: z.boolean().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 }; /** * Retrieve all image profiles in the database. * * GET /authoring/v1/image-profiles */ export const getApiAuthoringV1ImageProfiles = async (args: GetApiAuthoringV1ImageProfilesArgs, options: GetApiAuthoringV1ImageProfilesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.format != null) query.append("format", String(args.format)) if (args.pageMode != null) query.append("pageMode", String(args.pageMode)) if (args.order != null) query.append("order", String(args.order)) if (args.fields != null) query.append("fields", String(args.fields)) if (args.include != null) query.append("include", String(args.include)) const url = `${baseUrl.replace(/\/+$/, '')}/authoring/v1/image-profiles${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(getApiAuthoringV1ImageProfilesResponse, await res.json()) };