import {z} from 'zod' export type GetApiApiVenueArgs = {code2?: string | undefined, cityId?: number | undefined, minCapacity?: number | undefined, maxCapacity?: number | undefined, venueType?: ('stadium' | 'arena' | 'amphitheater' | 'festival' | 'theater' | 'concert_hall' | 'club') | undefined, search?: string | undefined, sortColumn?: ('name' | 'capacity' | 'latestShowDate') | undefined, sortOrderDesc?: boolean | undefined, includeFutureShows?: boolean | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiVenueOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiVenueResponse = z.object({obj: z.object({data: z.array(z.object({id: z.number().int().gte(0).lte(2147483647), name: z.string().nullable(), image_url: z.string().nullable(), city: z.string().nullable(), city_id: z.number().int().gte(0).lte(2147483647).nullable(), country: z.string().nullable(), lat: z.number().nullable(), lng: z.number().nullable(), capacity: z.number().int().nullable(), venue_type: z.enum(["stadium", "arena", "amphitheater", "festival", "theater", "concert_hall", "club"]).nullable(), latest_show: z.object({date: z.string().nullable(), title: z.string().nullable()}).nullable(), biggest_artist: z.object({id: z.number().int().gte(0).lte(2147483647), name: z.string(), image_url: z.string().nullable()}).nullable(), show_count: z.number().int(), show_trend: z.array(z.number().int()), top_artists: z.array(z.object({id: z.number().int().gte(0).lte(2147483647), name: z.string(), image_url: z.string().nullable()}))})), total: 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 }; /** * List Venues * * GET /api/venue */ export const getApiApiVenue = async (args: GetApiApiVenueArgs, options?: GetApiApiVenueOptions) => { const {baseUrl = "https://api.chartmetric.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.code2 != null) query.append("code2", String(args.code2)) if (args.cityId != null) query.append("cityId", String(args.cityId)) if (args.minCapacity != null) query.append("minCapacity", String(args.minCapacity)) if (args.maxCapacity != null) query.append("maxCapacity", String(args.maxCapacity)) if (args.venueType != null) query.append("venueType", String(args.venueType)) if (args.search != null) query.append("search", String(args.search)) if (args.sortColumn != null) query.append("sortColumn", String(args.sortColumn)) if (args.sortOrderDesc != null) query.append("sortOrderDesc", String(args.sortOrderDesc)) if (args.includeFutureShows != null) query.append("includeFutureShows", String(args.includeFutureShows)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/venue${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(getApiApiVenueResponse, await res.json()) };