import {z} from 'zod' export type GetApiApiFestivalListArgs = {'code2s[]'?: Array | undefined, 'genreIds[]'?: Array | undefined, sortColumn?: ('rank' | 'score' | 'festivalName' | 'startDate' | 'numberOfDays' | 'eventSize' | 'totalEditions') | undefined, sortOrderDesc?: boolean | undefined, nameSearch?: string | undefined, limit?: number | undefined, offset?: number | undefined, 'eventSizes[]'?: (Array<'small' | 'medium' | 'large' | 'mega'>) | undefined}; export type GetApiApiFestivalListOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiFestivalListResponse = z.object({obj: z.array(z.object({id: z.number().int().gte(0).lte(2147483647).nullable(), name: z.string().nullable(), date: z.string().nullable(), numberOfDays: z.number().int().nullable(), city: z.string().nullable(), country: z.string().nullable(), performersCount: z.number().int().nullable(), popularityRank: z.number().int().nullable(), eventSize: z.string(), topGenres: z.array(z.object({id: z.number().int().gte(0).lte(2147483647), name: z.string()})), links: z.object({jambase: z.string().nullable().optional(), songkick: z.string().nullable().optional(), seatgeek: z.string().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 }; /** * Festival List * * GET /api/festival/list */ export const getApiApiFestivalList = async (args: GetApiApiFestivalListArgs, options?: GetApiApiFestivalListOptions) => { const {baseUrl = "https://api.chartmetric.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args['code2s[]'] ?? []) query.append("code2s[]", String(item)) for (const item of args['genreIds[]'] ?? []) query.append("genreIds[]", String(item)) if (args.sortColumn != null) query.append("sortColumn", String(args.sortColumn)) if (args.sortOrderDesc != null) query.append("sortOrderDesc", String(args.sortOrderDesc)) if (args.nameSearch != null) query.append("nameSearch", String(args.nameSearch)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) for (const item of args['eventSizes[]'] ?? []) query.append("eventSizes[]", String(item)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/festival/list${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(getApiApiFestivalListResponse, await res.json()) };