import {z} from 'zod' export type GetApiV2EditorialLivefeedsIdItemsArgs = {id: string, country: unknown}; export type GetApiV2EditorialLivefeedsIdItemsOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const getApiV2EditorialLivefeedsIdItemsResponse = z.object({data: z.array(z.object({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(), special_instructions: z.string().optional(), title: z.string().optional()})).optional(), errors: z.array(z.object({statusCode: z.number().optional(), code: z.string().optional(), data: z.string().optional(), items: z.array(z.object({})).optional(), message: z.string(), path: z.string().optional()})).optional(), message: z.string().optional(), page: z.number().int().optional(), per_page: z.number().int().optional(), total_count: z.number().int().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 }; /** * (Deprecated) Get editorial livefeed items * * GET /v2/editorial/livefeeds/{id}/items * * Also accepts auth: customer_accessCode */ export const getApiV2EditorialLivefeedsIdItems = async (args: GetApiV2EditorialLivefeedsIdItemsArgs, options?: GetApiV2EditorialLivefeedsIdItemsOptions) => { 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.country != null) query.append("country", String(args.country)) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/editorial/livefeeds/${encodeURIComponent(String(args.id))}/items${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(getApiV2EditorialLivefeedsIdItemsResponse, await res.json()) };