import {z} from 'zod' export type GetApiLookupsVenueDataSourcesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const success = z.boolean(); export const enumUrlType = z.enum(["officialSite", "facebook", "twitter", "instagram", "youtube", "musicbrainz", "spotify", "androidApp", "iosApp"]); export const uRL = z.object({"@type": z.literal("URL").optional(), identifier: enumUrlType.optional(), url: z.string().optional()}); export const organization = z.object({"@type": z.literal("Organization").optional(), identifier: z.string(), disambiguatingDescription: z.string(), name: z.string(), url: z.string().optional(), image: z.string().optional(), sameAs: z.array(uRL).optional(), datePublished: z.string(), dateModified: z.string()}); export const getApiLookupsVenueDataSourcesResponse = z.object({success: success.optional(), dataSources: z.array(organization).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 Venue Data Sources * * GET /lookups/venue-data-sources */ export const getApiLookupsVenueDataSources = async (options?: GetApiLookupsVenueDataSourcesOptions) => { 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(/\/+$/, '')}/lookups/venue-data-sources${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(getApiLookupsVenueDataSourcesResponse, await res.json()) };