import {z} from 'zod' export type GettyImagesServicesConnectPublicControllersEventsEventDetailFieldValues = 'id' | 'child_event_count' | 'editorial_segments' | 'hero_image' | 'image_count' | 'keywords' | 'location' | 'name' | 'start_date' | 'type'; export type GetApiV3EventsArgs = {'Accept-Language'?: string | undefined, ids?: Array | undefined, fields?: Array | undefined}; export type GetApiV3EventsOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const gettyImagesServicesConnectPublicModelsHeroImageDisplaySize = z.object({name: z.string().nullable().optional(), is_watermarked: z.boolean().optional(), uri: z.string().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsHeroImage = z.object({id: z.string().nullable().optional(), display_sizes: z.array(gettyImagesServicesConnectPublicModelsHeroImageDisplaySize).nullable().optional()}); export const gettyImagesServicesConnectPublicModelsEventsEventKeyword = z.object({keyword_id: z.string().nullable().optional(), text: z.string().nullable().optional(), type: z.string().nullable().optional(), relevance: z.number().int().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsLocationEvent = z.object({city: z.string().nullable().optional(), country: z.string().nullable().optional(), state_province: z.string().nullable().optional(), venue: z.string().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsEventsChildEvent = z.object({editorial_segments: z.array(z.string()).nullable().optional(), hero_image: gettyImagesServicesConnectPublicModelsHeroImage.optional(), id: z.number().int().optional(), image_count: z.number().int().nullable().optional(), keywords: z.array(gettyImagesServicesConnectPublicModelsEventsEventKeyword).nullable().optional(), location: gettyImagesServicesConnectPublicModelsLocationEvent.optional(), name: z.string().nullable().optional(), start_date: z.string().nullable().optional(), type: z.string().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsEventsEvent = z.object({child_event_count: z.number().int().nullable().optional(), child_events: z.array(gettyImagesServicesConnectPublicModelsEventsChildEvent).nullable().optional(), editorial_segments: z.array(z.string()).nullable().optional(), hero_image: gettyImagesServicesConnectPublicModelsHeroImage.optional(), id: z.number().int().optional(), image_count: z.number().int().nullable().optional(), keywords: z.array(gettyImagesServicesConnectPublicModelsEventsEventKeyword).nullable().optional(), location: gettyImagesServicesConnectPublicModelsLocationEvent.optional(), name: z.string().nullable().optional(), start_date: z.string().nullable().optional(), type: z.string().nullable().optional()}); export const gettyImagesServicesConnectPublicModelsEventsEventsResponse = z.object({events: z.array(gettyImagesServicesConnectPublicModelsEventsEvent).nullable().optional(), events_not_found: z.array(z.number().int()).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 }; /** * Get metadata for multiple events * * GET /v3/events * * Also accepts auth: OAuth2 */ export const getApiV3Events = async (args: GetApiV3EventsArgs, options: GetApiV3EventsOptions) => { 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.ids != null) query.append("ids", args.ids.join(',')) if (args.fields != null) query.append("fields", args.fields.join(',')) if (ApiKey !== undefined) headers.set("Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v3/events${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(gettyImagesServicesConnectPublicModelsEventsEventsResponse, await res.json()) };