import {z} from 'zod' export type GetApiV3ImagesIdDownloadhistoryArgs = {'Accept-Language'?: string | undefined, id: string, company_downloads?: boolean | undefined}; export type GetApiV3ImagesIdDownloadhistoryOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; 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 gettyImagesServicesConnectPublicModelsAssetDownloadHistoryAssetDownload = z.object({agreement_name: z.string().nullable().optional(), asset_type: z.string().nullable().optional(), date_downloaded: z.string().optional(), download_notes: z.string().nullable().optional(), download_source: z.string().nullable().optional(), product_id: z.number().int().optional(), product_type: z.string().nullable().optional(), project_code: z.string().nullable().optional(), thumb_uri: z.string().nullable().optional(), user: gettyImagesServicesConnectPublicModelsDownloadsUser.optional()}); export const gettyImagesServicesConnectPublicModelsAssetDownloadHistoryAssetDownloadHistoryResponse = z.object({id: z.string().nullable().optional(), downloads: z.array(gettyImagesServicesConnectPublicModelsAssetDownloadHistoryAssetDownload).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 download history for a specific asset * * GET /v3/images/{id}/downloadhistory * * Also accepts auth: OAuth2 */ export const getApiV3ImagesIdDownloadhistory = async (args: GetApiV3ImagesIdDownloadhistoryArgs, options: GetApiV3ImagesIdDownloadhistoryOptions) => { 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.company_downloads != null) query.append("company_downloads", String(args.company_downloads)) if (ApiKey !== undefined) headers.set("Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v3/images/${encodeURIComponent(String(args.id))}/downloadhistory${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(gettyImagesServicesConnectPublicModelsAssetDownloadHistoryAssetDownloadHistoryResponse, await res.json()) };