import {z} from 'zod' export type Address = string; export type ChallengeId = string; export type GetApiGetReportableBenchmarkIdsArgs = {round: number, player_id: Address, challenge_id: ChallengeId}; export type GetApiGetReportableBenchmarkIdsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mD5 = z.string(); export const getReportableBenchmarkIdsResponse = z.object({benchmark_ids: z.array(mD5).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 all benchmark ids by a specific player for a specific challenge in a specific round * * GET /get-reportable-benchmark-ids */ export const getApiGetReportableBenchmarkIds = async (args: GetApiGetReportableBenchmarkIdsArgs, options?: GetApiGetReportableBenchmarkIdsOptions) => { const {baseUrl = "https://mainnet-api.tig.foundation", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.round != null) query.append("round", String(args.round)) if (args.player_id != null) query.append("player_id", String(args.player_id)) if (args.challenge_id != null) query.append("challenge_id", String(args.challenge_id)) const url = `${baseUrl.replace(/\/+$/, '')}/get-reportable-benchmark-ids${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(getReportableBenchmarkIdsResponse, await res.json()) };