import {z} from 'zod' export type GetApiApiV1ClientGuildRivalsArgs = {access_key?: string | undefined, guildId: number, scope?: ('realm' | 'subregion' | 'region' | 'world') | undefined, raid?: string | undefined, difficulty?: ('normal' | 'heroic' | 'mythic') | undefined}; export type GetApiApiV1ClientGuildRivalsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const scope1 = z.enum(["realm", "subregion", "region", "world"]); export const raid = z.object({}); export const difficulty = z.enum(["normal", "heroic", "mythic"]); export const model1 = z.object({difficulty: difficulty, selfRank: z.number().int()}); export const difficulties = z.array(model1); export const model2 = z.object({raid: raid, difficulties: difficulties}); export const activeRaids = z.array(model2); export const scope2 = z.enum(["realm", "subregion", "region", "world"]); export const guild = z.object({}); export const encounter = z.object({}); export const pull = z.object({encounter: encounter, percent: z.number().gte(0).lte(100).nullable(), count: z.number().int().gte(0).nullable()}).nullable(); export const model3 = z.object({rank: z.number().int(), guild: guild, isSelf: z.boolean(), progress: z.number().int().gte(0), pull: pull}); export const entries1 = z.array(model3); export const selected = z.object({raid: raid, difficulty: difficulty, scope: scope2, entries: entries1, fullRankingPath: z.string()}).nullable(); export const guildRivalsResponse = z.object({scope: scope1, guildId: z.number().int(), activeRaids: activeRaids, selected: selected}); 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 }; /** * Active-raid discovery and exact five-row guild leaderboard window for the character Overview dashboard * * GET /api/v1/client/guild-rivals */ export const getApiApiV1ClientGuildRivals = async (args: GetApiApiV1ClientGuildRivalsArgs, options?: GetApiApiV1ClientGuildRivalsOptions) => { 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.guildId != null) query.append("guildId", String(args.guildId)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.raid != null) query.append("raid", String(args.raid)) if (args.difficulty != null) query.append("difficulty", String(args.difficulty)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/client/guild-rivals${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(guildRivalsResponse, await res.json()) };