import {z} from 'zod' export type GetApiApiV1RaidingBossRankingsArgs = {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', boss: string, difficulty: 'mythic' | 'heroic' | 'normal', region: string, realm?: string | undefined}; export type GetApiApiV1RaidingBossRankingsOptions = {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 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 recruitmentProfile = z.object({activity_type: z.string().optional(), entity_type: z.string().optional(), recruitment_profile_id: z.number().int().optional()}); export const recruitmentProfiles = z.array(recruitmentProfile); export const communityIds = z.array(z.string()); export const stream1 = z.object({is_featured_stream: z.boolean().optional(), activity_record_id: z.number().int().optional(), id: z.string().optional(), name: z.string().optional(), user_id: z.string().optional(), game_id: z.string().optional(), type: z.string().optional(), title: z.string().optional(), community_ids: communityIds.optional(), viewer_count: z.number().int().optional(), started_at: z.string().optional(), language: z.string().optional(), thumbnail_url: z.string().optional()}).nullable(); export const streamers = z.object({count: z.number().int().optional(), stream: stream1.optional()}); export const bossRankingEntry = z.object({guild: raidingGuild.optional(), rank: z.number().int().optional(), regionRank: z.number().int().nullable().optional(), encountersDefeated: encountersDefeated.optional(), isAttemptOnly: z.boolean().optional(), bestPercent: z.number().nullable().optional(), progressDisplay: z.string().nullable().optional(), pullCount: z.number().int().nullable().optional(), lastPulledAt: z.string().nullable().optional(), doesVideoExist: z.boolean().optional(), itemLevelAvg: z.number().nullable().optional(), recruitmentProfiles: recruitmentProfiles.optional(), streamers: streamers.optional()}); export const bossRankings = z.array(bossRankingEntry); export const viewBossRankingsResponse = z.object({bossRankings: bossRankings.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 boss rankings for a given raid and region * * GET /api/v1/raiding/boss-rankings */ export const getApiApiV1RaidingBossRankings = async (args: GetApiApiV1RaidingBossRankingsArgs, options?: GetApiApiV1RaidingBossRankingsOptions) => { 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.boss != null) query.append("boss", String(args.boss)) 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)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/raiding/boss-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(viewBossRankingsResponse, await res.json()) };