import {z} from 'zod' export type GetApiV2MarketsArgs = {category?: (string | null) | undefined, sport?: (string | null) | undefined, competition?: (string | null) | undefined, location?: (string | null) | undefined, asset?: (string | null) | undefined, indicator?: (string | null) | undefined, basis?: (string | null) | undefined, institution?: (string | null) | undefined, league?: (string | null) | undefined, status?: (string | null) | undefined, signal?: (string | null) | undefined, sort?: (string | null) | undefined, include?: (string | null) | undefined, market_type?: (string | null) | undefined, game_id?: (string | null) | undefined, has_history?: boolean | undefined, page?: number | undefined, limit?: number | undefined, authorization?: string | undefined}; export type GetApiV2MarketsOptions = {baseUrl?: string | undefined, bearerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2MarketsResponse = z.unknown(); 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 }; /** * Matched cross-venue catalog (v2) * * GET /v2/markets */ export const getApiV2Markets = async (args: GetApiV2MarketsArgs, options?: GetApiV2MarketsOptions) => { const {baseUrl = "https://api.dino.markets", fetch: fetchFn = fetch, bearerApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.category != null) query.append("category", String(args.category)) if (args.sport != null) query.append("sport", String(args.sport)) if (args.competition != null) query.append("competition", String(args.competition)) if (args.location != null) query.append("location", String(args.location)) if (args.asset != null) query.append("asset", String(args.asset)) if (args.indicator != null) query.append("indicator", String(args.indicator)) if (args.basis != null) query.append("basis", String(args.basis)) if (args.institution != null) query.append("institution", String(args.institution)) if (args.league != null) query.append("league", String(args.league)) if (args.status != null) query.append("status", String(args.status)) if (args.signal != null) query.append("signal", String(args.signal)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.include != null) query.append("include", String(args.include)) if (args.market_type != null) query.append("market_type", String(args.market_type)) if (args.game_id != null) query.append("game_id", String(args.game_id)) if (args.has_history != null) query.append("has_history", String(args.has_history)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) if (bearerApiKey !== undefined) headers.set('authorization', `Bearer ${bearerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/markets${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(getApiV2MarketsResponse, await res.json()) };