import {z} from 'zod' export type GettyImagesServicesConnectPublicModelsProductTypeForDownloads = 'easyaccess' | 'editorialsubscription' | 'imagepack' | 'premiumaccess' | 'royaltyfreesubscription' | 'creditpack' | 'aigen'; export type GetApiV3DownloadsArgs = {'Accept-Language'?: string | undefined, date_from?: string | undefined, date_to?: string | undefined, use_time?: boolean | undefined, page?: number | undefined, page_size?: number | undefined, product_type?: GettyImagesServicesConnectPublicModelsProductTypeForDownloads | undefined, company_downloads?: boolean | undefined}; export type GetApiV3DownloadsOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const gettyImagesServicesConnectPublicModelsDownloadsDownloadDetails = z.object({download_notes: z.string().nullable().optional(), project_code: z.string().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsDownloadsUser = z.object({username: z.string().nullable().optional(), first_name: z.string().nullable().optional(), middle_name: z.string().nullable().optional(), last_name: z.string().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsDownloadsDimensions = z.object({width: z.number().int().nullable().optional(), height: z.number().int().nullable().optional(), dpi: z.number().int().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsDownloadsHistoricalDownload = z.object({date_downloaded: z.string().optional(), id: z.string().nullable().optional(), asset_type: z.string().nullable().optional(), product_type: z.string().nullable().optional(), thumb_uri: z.string().nullable().optional(), agreement_name: z.string().nullable().optional(), product_id: z.number().int().optional(), download_details: gettyImagesServicesConnectPublicModelsDownloadsDownloadDetails.optional(), download_source: z.string().nullable().optional(), user: gettyImagesServicesConnectPublicModelsDownloadsUser.optional(), size_name: z.string().nullable().optional(), dimensions: gettyImagesServicesConnectPublicModelsDownloadsDimensions.optional(), license_model: z.string().nullable().optional(), generated_asset_id: z.string().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsDownloadsGetDownloadsResponse = z.object({result_count: z.number().int().optional(), downloads: z.array(gettyImagesServicesConnectPublicModelsDownloadsHistoricalDownload).nullable().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 }; /** * Returns information about a customer's downloaded assets. * * GET /v3/downloads * * Also accepts auth: OAuth2 */ export const getApiV3Downloads = async (args: GetApiV3DownloadsArgs, options: GetApiV3DownloadsOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.use_time != null) query.append("use_time", String(args.use_time)) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.product_type != null) query.append("product_type", String(args.product_type)) if (args.company_downloads != null) query.append("company_downloads", String(args.company_downloads)) if (ApiKey !== undefined) headers.set("Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v3/downloads${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(gettyImagesServicesConnectPublicModelsDownloadsGetDownloadsResponse, await res.json()) };