import {z} from 'zod' export type DeleteApiV2CatalogCollectionsCollectionIdItemsArgs = {collection_id: string, body: {items: Array<{id: string}>}}; export type DeleteApiV2CatalogCollectionsCollectionIdItemsOptions = {baseUrl?: string | undefined, customerAccessCode?: string | undefined, fetch?: typeof fetch | undefined}; export const deleteApiV2CatalogCollectionsCollectionIdItemsResponse = z.object({id: z.string(), name: z.string(), cover_asset: z.object({id: z.string(), asset: z.object({id: z.string().optional(), type: z.enum(["image", "video", "audio", "editorial-image", "editorial-video"]), name: z.string().optional()}), created_time: z.string(), collection_ids: z.array(z.string()).optional()}).optional(), total_item_count: z.number(), created_time: z.string(), updated_time: z.string(), visibility: z.enum(["private", "public"]), role_assignments: z.object({collection_id: z.string(), roles: z.object({owners: z.array(z.object({id: z.string(), type: z.literal("USER"), email: z.string()})).optional(), editors: z.array(z.object({id: z.string(), type: z.literal("USER"), email: z.string()})).optional(), viewers: z.array(z.object({id: z.string(), type: z.literal("USER"), email: z.string()})).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 }; /** * Remove items from catalog collection * * DELETE /v2/catalog/collections/{collection_id}/items */ export const deleteApiV2CatalogCollectionsCollectionIdItems = async (args: DeleteApiV2CatalogCollectionsCollectionIdItemsArgs, options?: DeleteApiV2CatalogCollectionsCollectionIdItemsOptions) => { const {baseUrl = "https://api.shutterstock.com", fetch: fetchFn = fetch, customerAccessCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (customerAccessCode !== undefined) headers.set('authorization', `Bearer ${customerAccessCode}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/catalog/collections/${encodeURIComponent(String(args.collection_id))}/items${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", 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(deleteApiV2CatalogCollectionsCollectionIdItemsResponse, await res.json()) };