import {z} from 'zod' export type GetApiV2EditorialImagesUpdatedArgs = {type: 'edit' | 'addition', date_updated_start: string, date_updated_end: string, date_taken_start?: string | undefined, date_taken_end?: string | undefined, cursor?: string | undefined, sort?: ('newest' | 'oldest') | undefined, supplier_code?: Array | undefined, country: unknown, per_page?: number | undefined}; export type GetApiV2EditorialImagesUpdatedOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const getApiV2EditorialImagesUpdatedResponse = z.object({data: z.array(z.object({commercial_status: z.object({status: z.string().optional(), reason: z.string().optional()}).optional(), aspect: z.number().optional(), assets: z.object({original: z.object({display_name: z.string().optional(), dpi: z.number().int().optional(), file_size: z.number().int().optional(), format: z.string().optional(), height: z.number().int().optional(), is_licensable: z.boolean().optional(), width: z.number().int().optional()}).optional(), thumb_170: z.object({height: z.number().int(), url: z.string(), width: z.number().int()}).optional(), thumb_220: z.object({height: z.number().int(), url: z.string(), width: z.number().int()}).optional(), watermark_450: z.object({height: z.number().int(), url: z.string(), width: z.number().int()}).optional(), watermark_1500: z.object({height: z.number().int(), url: z.string(), width: z.number().int()}).optional(), small_jpg: z.object({display_name: z.string().optional(), dpi: z.number().int().optional(), file_size: z.number().int().optional(), format: z.string().optional(), height: z.number().int().optional(), is_licensable: z.boolean().optional(), width: z.number().int().optional()}).optional(), medium_jpg: z.object({display_name: z.string().optional(), dpi: z.number().int().optional(), file_size: z.number().int().optional(), format: z.string().optional(), height: z.number().int().optional(), is_licensable: z.boolean().optional(), width: z.number().int().optional()}).optional()}).optional(), byline: z.string().optional(), caption: z.string().optional(), categories: z.array(z.object({name: z.string().optional()})).optional(), date_taken: z.string().optional(), description: z.string().optional(), id: z.string(), keywords: z.array(z.string()).optional(), title: z.string().optional(), updated_time: z.string().optional(), created_time: z.string().optional(), rights: z.object({countries: z.string().optional()}).optional(), updates: z.array(z.string()).optional(), supplier_code: z.string().optional(), special_instructions: z.string().optional()})), message: z.string().optional(), next: z.string().optional(), per_page: z.number().int().optional(), prev: 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 }; /** * List updated content * * GET /v2/editorial/images/updated * * Also accepts auth: customer_accessCode */ export const getApiV2EditorialImagesUpdated = async (args: GetApiV2EditorialImagesUpdatedArgs, options?: GetApiV2EditorialImagesUpdatedOptions) => { const {baseUrl = "https://api.shutterstock.com", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.date_updated_start != null) query.append("date_updated_start", String(args.date_updated_start)) if (args.date_updated_end != null) query.append("date_updated_end", String(args.date_updated_end)) if (args.date_taken_start != null) query.append("date_taken_start", String(args.date_taken_start)) if (args.date_taken_end != null) query.append("date_taken_end", String(args.date_taken_end)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.sort != null) query.append("sort", String(args.sort)) for (const item of args.supplier_code ?? []) query.append("supplier_code", String(item)) if (args.country != null) query.append("country", String(args.country)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/editorial/images/updated${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(getApiV2EditorialImagesUpdatedResponse, await res.json()) };