import {z} from 'zod' export type GetApiApiV1RaidingRaidRankingsArgs = {access_key?: string | undefined, 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: string, realm?: string | undefined, guilds?: string | undefined, limit?: number | undefined, page?: number | undefined}; export type GetApiApiV1RaidingRaidRankingsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const fullRealm = z.object({id: z.number().int().optional(), name: z.string().optional(), slug: z.string().optional(), altName: z.string().nullable().optional(), altSlug: z.string().optional(), locale: z.string().optional(), isConnected: z.boolean().optional(), connectedRealmId: z.number().int().optional(), realmType: z.string().optional(), wowRealmId: z.number().int().optional(), wowConnectedRealmId: z.number().int().optional()}); export const regionSummary = z.object({name: z.string(), short_name: z.string(), slug: z.string()}); export const raidingGuild = z.object({id: z.number().int().optional(), name: z.string().optional(), faction: z.string().optional(), realm: fullRealm.optional(), region: regionSummary.optional(), path: z.string().optional(), logo: z.string().nullable().optional(), color: z.string().optional(), isDefaultLogo: z.boolean().optional(), displayName: z.string().optional()}); export const raidRankingEncounter = z.object({id: z.number().int().optional(), slug: z.string().optional(), isDefeated: z.boolean().optional(), numPulls: z.number().int().optional(), pullStartedAt: z.string().optional(), bestPercent: z.number().nullable().optional(), bossPercent: z.number().nullable().optional(), phase: z.number().nullable().optional(), phaseLabel: z.string().nullable().optional(), progressDisplay: z.string().nullable().optional()}); export const encountersPulled = z.array(raidRankingEncounter); export const encounterDefeated = z.object({slug: z.string().optional(), firstDefeated: z.string().nullable().optional(), lastDefeated: z.string().nullable().optional()}); export const encountersDefeated = z.array(encounterDefeated); export const guildPrivacy = z.object({raidPulls: z.boolean().optional(), raidPercents: z.boolean().optional(), raidComps: z.boolean().optional(), wereRaidPullsRestricted: z.boolean().optional(), wereRaidPercentsRestricted: z.boolean().optional(), wereRaidCompsRestricted: z.boolean().optional(), shareRaidUntil: z.string().nullable().optional()}); export const raidRankingEntry = z.object({guild: raidingGuild.optional(), rank: z.number().int().optional(), regionRank: z.number().int().nullable().optional(), encountersPulled: encountersPulled.optional(), encountersDefeated: encountersDefeated.optional(), guildPrivacy: guildPrivacy.optional()}); export const raidRankings = z.array(raidRankingEntry); export const viewRaidRankingsResponse = z.object({raidRankings: raidRankings.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 raid rankings for a given raid and region * * GET /api/v1/raiding/raid-rankings */ export const getApiApiV1RaidingRaidRankings = async (args: GetApiApiV1RaidingRaidRankingsArgs, options?: GetApiApiV1RaidingRaidRankingsOptions) => { 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.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)) if (args.realm != null) query.append("realm", String(args.realm)) if (args.guilds != null) query.append("guilds", String(args.guilds)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/raiding/raid-rankings${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(viewRaidRankingsResponse, await res.json()) };