import {z} from 'zod' export type GetApiFestivalsFestivalSeriesIdArgs = {festivalSeriesId: string}; export type GetApiFestivalsFestivalSeriesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const request = z.object({endpoint: z.string().optional(), method: z.string().optional(), params: z.array(z.unknown()).optional(), ip: z.union([z.string(), z.string()]).optional(), userAgent: z.string().optional()}); export const getApiFestivalsFestivalSeriesIdResponse = z.object({success: z.boolean().optional(), festivalSeries: z.object({"@type": z.string().optional(), identifier: z.string().optional(), name: z.string().optional(), url: z.string().optional(), image: z.string().optional(), "x-officialSite": z.string().optional(), "x-editionCount": z.number().int().optional(), "x-firstYear": z.number().int().optional(), "x-latestYear": z.number().int().optional(), "x-nextEditionDate": z.string().optional(), "x-distinctArtists": z.number().int().optional(), location: z.object({"@type": z.string().optional(), address: z.object({"@type": z.string().optional(), addressLocality: z.string().optional(), addressRegion: z.string().optional(), addressCountry: z.string().optional()}).optional()}).optional(), "x-archiveUrl": z.string().optional()}).optional(), events: z.array(z.object({"@type": z.string().optional(), identifier: z.string().optional(), name: z.string().optional(), startDate: z.string().optional(), location: z.object({"@type": z.string().optional(), name: z.string().optional(), address: z.object({"@type": z.string().optional(), addressLocality: z.string().optional(), addressRegion: z.string().optional(), addressCountry: z.string().optional()}).optional()}).optional(), "x-isUpcoming": z.boolean().optional(), "x-lineupCount": z.number().int().optional(), "x-headliners": z.array(z.string()).optional()})).optional(), historyLocked: z.boolean().optional(), historyInfo: z.string().optional(), request: request.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 Festival Series * * GET /festivals/{festivalSeriesId} */ export const getApiFestivalsFestivalSeriesId = async (args: GetApiFestivalsFestivalSeriesIdArgs, options?: GetApiFestivalsFestivalSeriesIdOptions) => { const {baseUrl = "https://api.data.jambase.com/v3", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/festivals/${encodeURIComponent(String(args.festivalSeriesId))}${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(getApiFestivalsFestivalSeriesIdResponse, await res.json()) };