import {z} from 'zod' export type GetApiApiEntitySynonymsArgs = {entity_type: 'brand' | 'property' | 'league' | 'agency' | 'venue' | 'market' | 'category' | 'subcategory' | 'asset', entity_id?: number | undefined, source?: ('manual' | 'admin_link' | 'queue_approval' | 'auto_link' | 'edgar' | 'podcast_scouting' | 'logo_detection' | 'surface') | undefined, per_page?: number | undefined, page?: number | undefined}; export type GetApiApiEntitySynonymsOptions = {baseUrl: string, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const entitySynonymResource = z.object({id: z.number().int().optional(), entity_type: z.enum(["brand", "property", "league", "agency", "venue", "market", "category", "subcategory", "asset"]).optional(), entity_id: z.number().int().optional(), synonym: z.string().optional(), normalized_synonym: z.string().nullable().optional(), source: z.enum(["manual", "admin_link", "queue_approval", "auto_link", "edgar", "podcast_scouting", "logo_detection", "surface"]).optional(), confidence: z.enum(["high", "medium", "low"]).nullable().optional(), matched_at: z.string().nullable().optional()}); export const getApiApiEntitySynonymsResponse = z.object({data: z.array(entitySynonymResource).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 the synonyms of one entity type * * GET /api/entity-synonyms */ export const getApiApiEntitySynonyms = async (args: GetApiApiEntitySynonymsArgs, options: GetApiApiEntitySynonymsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.entity_type != null) query.append("entity_type", String(args.entity_type)) if (args.entity_id != null) query.append("entity_id", String(args.entity_id)) if (args.source != null) query.append("source", String(args.source)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.page != null) query.append("page", String(args.page)) if (apiKeyAuth !== undefined) headers.set("X-API-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/entity-synonyms${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(getApiApiEntitySynonymsResponse, await res.json()) };