import {z} from 'zod' export type GetApiApiV1MythicPlusCutoffAnalysisArgs = {access_key?: string | undefined, season: string, region: 'us' | 'eu' | 'tw' | 'kr' | 'cn' | 'world', faction?: ('all' | 'horde' | 'alliance') | undefined, category: 'overall' | 'roles' | 'classes' | 'specs' | 'class_roles', percentile?: number | undefined, percentiles?: string | undefined, cohort?: string | undefined, targetDate?: string | undefined, density?: boolean | undefined, forecastHistory?: boolean | undefined}; export type GetApiApiV1MythicPlusCutoffAnalysisOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1MythicPlusCutoffAnalysisResponse = z.string(); 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 }; /** * Retrieve cached Mythic+ cohort cutoff history and forecasts * * GET /api/v1/mythic-plus/cutoff-analysis */ export const getApiApiV1MythicPlusCutoffAnalysis = async (args: GetApiApiV1MythicPlusCutoffAnalysisArgs, options?: GetApiApiV1MythicPlusCutoffAnalysisOptions) => { const {baseUrl = "http://raider.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.access_key != null) query.append("access_key", String(args.access_key)) if (args.season != null) query.append("season", String(args.season)) if (args.region != null) query.append("region", String(args.region)) if (args.faction != null) query.append("faction", String(args.faction)) if (args.category != null) query.append("category", String(args.category)) if (args.percentile != null) query.append("percentile", String(args.percentile)) if (args.percentiles != null) query.append("percentiles", String(args.percentiles)) if (args.cohort != null) query.append("cohort", String(args.cohort)) if (args.targetDate != null) query.append("targetDate", String(args.targetDate)) if (args.density != null) query.append("density", String(args.density)) if (args.forecastHistory != null) query.append("forecastHistory", String(args.forecastHistory)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/mythic-plus/cutoff-analysis${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(getApiApiV1MythicPlusCutoffAnalysisResponse, await res.json()) };