import {z} from 'zod' export type GetApiApiV1RaidingProgressionArgs = {raid: 'the-unbinding-of-kithix' | 'the-venomous-abyss' | 'the-tidebound-grotto' | 'sporefall' | 'tier-mn-1' | 'manaforge-omega' | 'liberation-of-undermine' | 'nerubar-palace' | 'blackrock-depths' | 'awakened-amirdrassil-the-dreams-hope' | 'awakened-aberrus-the-shadowed-crucible' | 'awakened-vault-of-the-incarnates' | 'amirdrassil-the-dreams-hope' | 'aberrus-the-shadowed-crucible' | 'vault-of-the-incarnates' | 'fated-sepulcher-of-the-first-ones' | 'fated-sanctum-of-domination' | 'fated-castle-nathria' | 'sepulcher-of-the-first-ones' | 'sanctum-of-domination' | 'castle-nathria' | 'nyalotha-the-waking-city' | 'the-eternal-palace' | 'crucible-of-storms' | 'battle-of-dazaralor' | 'uldir' | 'antorus-the-burning-throne' | 'tomb-of-sargeras' | 'the-nighthold' | 'trial-of-valor' | 'the-emerald-nightmare', difficulty: 'mythic' | 'heroic' | 'normal', region: 'us' | 'eu' | 'tw' | 'kr' | 'cn' | 'world'}; export type GetApiApiV1RaidingProgressionOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const faction = z.enum(["horde", "alliance"]); export const realmSummary = z.object({id: z.number().int(), connectedRealmId: z.number().int(), wowRealmId: z.number().int().nullable(), wowConnectedRealmId: z.number().int().nullable(), name: z.string(), altName: z.string().nullable(), slug: z.string(), altSlug: z.string(), locale: z.string().nullable(), isConnected: z.boolean(), realmType: z.string()}); export const regionSummary = z.object({name: z.string(), short_name: z.string(), slug: z.string()}); export const guildSummary = z.object({id: z.number().int(), name: z.string(), faction: faction, realm: realmSummary.optional(), region: regionSummary.optional(), path: z.string(), logo: z.string().optional(), isDefaultLogo: z.boolean().optional(), color: z.string().optional(), displayName: z.string(), alt_name: z.string().optional()}); export const guildDefeatEntry = z.object({defeatedAt: z.string(), guild: guildSummary.optional()}); export const guilds1 = z.array(guildDefeatEntry); export const raidRaceProgressionEntry = z.object({progress: z.number().int().gte(1), totalGuilds: z.number().int().gte(0), guilds: guilds1.optional()}); export const progression = z.array(raidRaceProgressionEntry); export const viewRaidProgressionResponse = z.object({progression: progression.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 details of raiding progression for a raid, showing how many guilds have reached each boss kill milestone * * GET /api/v1/raiding/progression */ export const getApiApiV1RaidingProgression = async (args: GetApiApiV1RaidingProgressionArgs, options?: GetApiApiV1RaidingProgressionOptions) => { const {baseUrl = "http://raider.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.raid != null) query.append("raid", String(args.raid)) if (args.difficulty != null) query.append("difficulty", String(args.difficulty)) if (args.region != null) query.append("region", String(args.region)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/raiding/progression${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(viewRaidProgressionResponse, await res.json()) };