import {z} from 'zod' export type CollectionInputSchema = {category?: (string | null) | undefined, custom_keyframe?: (string | null) | undefined, custom_poster?: (string | null) | undefined, date_created?: string | undefined, external_id?: (string | null) | undefined, is_root?: boolean | undefined, keyframe_asset_ids?: Array | undefined, parent_id?: (string | null) | undefined, status?: ('ACTIVE' | 'HIDDEN' | 'DELETED') | undefined, storage_id?: (string | null) | undefined, title: string}; export type UpdateApiV1CollectionsCollectionIdArgs = {'App-ID': string, 'Auth-Token': string, collection_id: string, change_parent_mode?: string | undefined, low_priority_indexing?: boolean | undefined, body: CollectionInputSchema}; export type UpdateApiV1CollectionsCollectionIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const collectionSchema = z.object({category: z.string().nullable().optional(), created_by_user: z.string().optional(), custom_keyframe: z.string().nullable().optional(), custom_order_status: z.enum(["DISABLED", "ENABLING", "ENABLED"]).optional(), custom_poster: z.string().nullable().optional(), date_created: z.string().optional(), date_deleted: z.string().optional(), date_modified: z.string().optional(), date_viewed: z.string().optional(), deleted_by_user: z.string().optional(), external_id: z.string().nullable().optional(), favoured: z.boolean().optional(), id: z.string().optional(), in_collections: z.array(z.string()).optional(), is_root: z.boolean().optional(), keyframe_asset_ids: z.array(z.string()).optional(), keyframes: z.array(z.object({})).optional(), metadata: z.object({}).optional(), object_type: z.string().optional(), parent_id: z.string().nullable().optional(), parents: z.array(z.string()).optional(), permissions: z.array(z.string()).optional(), position: z.number().int().gte(-2147483648).lte(2147483647).optional(), project_id: z.string().optional(), status: z.enum(["ACTIVE", "HIDDEN", "DELETED"]).optional(), storage_id: z.string().nullable().optional(), title: z.string()}); 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 collection * * PUT /v1/collections/{collection_id}/ */ export const updateApiV1CollectionsCollectionId = async (args: UpdateApiV1CollectionsCollectionIdArgs, options: UpdateApiV1CollectionsCollectionIdOptions) => { 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['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) if (args.change_parent_mode != null) query.append("change_parent_mode", String(args.change_parent_mode)) if (args.low_priority_indexing != null) query.append("low_priority_indexing", String(args.low_priority_indexing)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/collections/${encodeURIComponent(String(args.collection_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(collectionSchema, await res.json()) };