import {z} from 'zod' export type GetApiV2ContributorsContributorIdCollectionsIdArgs = {contributor_id: string, id: string}; export type GetApiV2ContributorsContributorIdCollectionsIdOptions = {baseUrl?: string | undefined, customerAccessCode?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2ContributorsContributorIdCollectionsIdResponse = z.object({cover_item: z.object({added_time: z.string().optional(), id: z.string(), media_type: z.string().optional()}).optional(), created_time: z.string().optional(), id: z.string(), items_updated_time: z.string().optional(), name: z.string(), share_code: z.string().optional(), share_url: z.string().optional(), total_item_count: z.number().int(), updated_time: 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 }; /** * Get details about contributors' collections * * GET /v2/contributors/{contributor_id}/collections/{id} * * Also accepts auth: basic */ export const getApiV2ContributorsContributorIdCollectionsId = async (args: GetApiV2ContributorsContributorIdCollectionsIdArgs, options?: GetApiV2ContributorsContributorIdCollectionsIdOptions) => { const {baseUrl = "https://api.shutterstock.com", fetch: fetchFn = fetch, customerAccessCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (customerAccessCode !== undefined) headers.set('authorization', `Bearer ${customerAccessCode}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/contributors/${encodeURIComponent(String(args.contributor_id))}/collections/${encodeURIComponent(String(args.id))}${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(getApiV2ContributorsContributorIdCollectionsIdResponse, await res.json()) };