import {z} from 'zod' export type GetApiApiV1LiveTrackingMythicPlusCurrentDungeonArgs = {access_key?: string | undefined, season: 'season-mn-2' | 'season-mn-2-tr' | 'season-mn-1' | 'season-mn-1-cutoffs' | 'season-mn-1-break-the-meta' | 'season-mn-1-tr' | 'season-mn-2-ptr' | 'season-tww-3' | 'season-tww-3-cutoffs' | 'season-mn-1-beta' | 'season-tww-3-legion-remix' | 'season-tww-3-legion-remix-1-player' | 'season-tww-3-break-the-meta' | 'season-tww-3-tr' | 'season-tww-2' | 'season-tww-2-break-the-meta' | 'season-tww-2-meta-vs-meta' | 'season-tww-2-tr' | 'season-tww-1' | 'season-tww-3-ptr' | 'season-tww-1-post' | 'season-tww-1-cutoffs' | 'season-tww-1-break-the-meta' | 'season-tww-1-tr' | 'season-tww-2-ptr' | 'season-df-4' | 'season-df-4-post' | 'season-df-4-cutoffs' | 'season-df-4-break-the-meta' | 'season-tww-1-beta' | 'season-df-4-tr' | 'season-df-3' | 'season-df-4-ptr' | 'season-df-3-meta-vs-meta' | 'season-df-3-break-the-meta' | 'season-df-3-tr' | 'season-df-2' | 'season-df-2-post' | 'season-df-2-cutoffs' | 'season-df-3-ptr' | 'season-df-2-break-the-meta' | 'season-df-2-tgp' | 'season-df-2-post-1017' | 'season-df-2-post-1015' | 'season-df-1' | 'season-df-1-post' | 'season-df-1-cutoffs' | 'season-df-1-break-the-meta' | 'season-sl-4' | 'season-sl-4-post' | 'season-sl-4-patch-10-0' | 'season-sl-4-break-the-meta' | 'season-sl-4-legion-timewalking' | 'season-sl-3' | 'season-sl-3-post-925' | 'season-sl-3-legion-timewalking' | 'season-sl-2' | 'season-sl-2-post' | 'season-sl-2-tormented-hero' | 'season-sl-2-post-915' | 'season-sl-2-legion-timewalking' | 'season-sl-1' | 'season-sl-1-post' | 'season-bfa-4-post' | 'season-bfa-4' | 'season-bfa-3-post' | 'season-bfa-3' | 'season-bfa-2-post' | 'season-bfa-2' | 'season-bfa-1' | 'season-pre-bfa' | 'season-post-legion' | 'season-7.3.2' | 'season-7.3.0' | 'season-7.2.5' | 'season-7.2.0', teamId?: number | undefined, platoonId?: number | undefined}; export type GetApiApiV1LiveTrackingMythicPlusCurrentDungeonOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const dungeon = z.object({id: z.number().int().optional(), name: z.string().optional(), slug: z.string().optional(), short_name: z.string().optional()}).nullable(); export const viewCurrentDungeonResponse = z.object({dungeon: dungeon.optional(), startedAt: z.string().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 }; /** * Retrieve the dungeon a Mythic+ team or platoon is currently running, if any. Returns null dungeon when no active run is detected. * * GET /api/v1/live-tracking/mythic-plus/current-dungeon */ export const getApiApiV1LiveTrackingMythicPlusCurrentDungeon = async (args: GetApiApiV1LiveTrackingMythicPlusCurrentDungeonArgs, options?: GetApiApiV1LiveTrackingMythicPlusCurrentDungeonOptions) => { 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.teamId != null) query.append("teamId", String(args.teamId)) if (args.platoonId != null) query.append("platoonId", String(args.platoonId)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/live-tracking/mythic-plus/current-dungeon${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(viewCurrentDungeonResponse, await res.json()) };