import {z} from 'zod' export type GetApiApiV1CharactersProfileArgs = {access_key?: string | undefined, region: 'us' | 'eu' | 'tw' | 'kr' | 'cn', realm: string, name: string, fields?: string | undefined}; export type GetApiApiV1CharactersProfileOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const faction = z.enum(["horde", "alliance"]); export const region = z.enum(["us", "eu", "tw", "kr", "cn"]); export const characterGear = z.object({item_level_equipped: z.number(), item_level_total: z.number(), artifact_traits: z.number()}); export const raidProgression = z.object({summary: z.string(), expansion_id: z.number().int(), total_bosses: z.number().int().gte(1), normal_bosses_killed: z.number().int().gte(0), heroic_bosses_killed: z.number().int().gte(0), mythic_bosses_killed: z.number().int().gte(0)}); export const overallRaidProgression = z.object({"the-unbinding-of-kithix": raidProgression.optional(), "the-venomous-abyss": raidProgression.optional(), "the-tidebound-grotto": raidProgression.optional(), sporefall: raidProgression.optional(), "tier-mn-1": raidProgression.optional(), "manaforge-omega": raidProgression.optional(), "liberation-of-undermine": raidProgression.optional(), "nerubar-palace": raidProgression.optional(), "blackrock-depths": raidProgression.optional(), "awakened-amirdrassil-the-dreams-hope": raidProgression.optional(), "awakened-aberrus-the-shadowed-crucible": raidProgression.optional(), "awakened-vault-of-the-incarnates": raidProgression.optional(), "amirdrassil-the-dreams-hope": raidProgression.optional(), "aberrus-the-shadowed-crucible": raidProgression.optional(), "vault-of-the-incarnates": raidProgression.optional(), "fated-sepulcher-of-the-first-ones": raidProgression.optional(), "fated-sanctum-of-domination": raidProgression.optional(), "fated-castle-nathria": raidProgression.optional(), "sepulcher-of-the-first-ones": raidProgression.optional(), "sanctum-of-domination": raidProgression.optional(), "castle-nathria": raidProgression.optional(), "nyalotha-the-waking-city": raidProgression.optional(), "the-eternal-palace": raidProgression.optional(), "crucible-of-storms": raidProgression.optional(), "battle-of-dazaralor": raidProgression.optional(), uldir: raidProgression.optional(), "antorus-the-burning-throne": raidProgression.optional(), "tomb-of-sargeras": raidProgression.optional(), "the-nighthold": raidProgression.optional(), "trial-of-valor": raidProgression.optional(), "the-emerald-nightmare": raidProgression.optional()}); export const mythicPlusScores = z.object({all: z.number(), dps: z.number(), healer: z.number(), tank: z.number(), spec_0: z.number(), spec_1: z.number(), spec_2: z.number(), spec_3: z.number()}); export const scoreColorSegment = z.object({score: z.number(), color: z.string()}); export const mythicPlusSegments = z.object({all: scoreColorSegment, dps: scoreColorSegment, healer: scoreColorSegment, tank: scoreColorSegment, spec_0: scoreColorSegment, spec_1: scoreColorSegment, spec_2: scoreColorSegment, spec_3: scoreColorSegment}); export const mythicPlusScoresBySeason = z.object({season: z.string(), scores: mythicPlusScores, segments: mythicPlusSegments}); export const ranks = z.object({world: z.number().int(), region: z.number().int(), realm: z.number().int()}); export const mythicPlusRoleRanks = z.object({overall: ranks, tank: ranks, healer: ranks, dps: ranks, class: ranks, class_tank: ranks, class_healer: ranks, class_dps: ranks}); export const affix = z.object({id: z.number().int(), name: z.string(), description: z.string(), icon: z.string(), icon_url: z.string(), wowhead_url: z.string()}); export const affixes = z.array(affix); export const spec = z.object({id: z.number().optional(), name: z.string().optional(), slug: z.string().optional(), role: z.string().optional(), class_id: z.number().int().optional(), is_melee: z.boolean().optional(), ordinal: z.number().int().optional(), patch: z.string().optional()}).nullable(); export const role = z.enum(["tank", "healer", "dps"]).nullable(); export const keystoneRun = z.object({dungeon: z.string(), short_name: z.string(), mythic_level: z.number().int().gte(2), keystone_run_id: z.number().int(), completed_at: z.string(), clear_time_ms: z.number().int().gte(1), par_time_ms: z.number().int().gte(1), num_keystone_upgrades: z.number().int().gte(0), map_challenge_mode_id: z.number().int(), zone_id: z.number().int(), zone_expansion_id: z.number().int(), icon_url: z.string(), background_image_url: z.string(), score: z.number(), url: z.string(), affixes: affixes, spec: spec, role: role}); export const keystoneRunList = z.array(keystoneRun); export const mythicPlusDungeonRunCounts = z.object({zone_id: z.number().int(), dungeon: z.string(), short_name: z.string(), season_runs_total: z.number().int().gte(0), season_runs_timed: z.number().int().gte(0)}); export const mythicPlusDungeonRunCountsList = z.array(mythicPlusDungeonRunCounts); export const viewCharacterProfileResponse = z.object({name: z.string(), race: z.string(), class: z.string(), active_spec_name: z.string(), active_spec_role: z.string(), gender: z.string(), faction: faction, achievement_points: z.number().int(), thumbnail_url: z.string(), region: region, realm: z.string(), last_crawled_at: z.string(), profile_url: z.string(), profile_banner: z.string(), use_animated_banner: z.boolean().optional(), gear: characterGear.optional(), raid_progression: overallRaidProgression.optional(), mythic_plus_scores_by_season: mythicPlusScoresBySeason.optional(), mythic_plus_ranks: mythicPlusRoleRanks.optional(), previous_mythic_plus_ranks: mythicPlusRoleRanks.optional(), mythic_plus_recent_runs: keystoneRunList.optional(), mythic_plus_best_runs: keystoneRunList.optional(), mythic_plus_alternate_runs: keystoneRunList.optional(), mythic_plus_dungeon_run_counts: mythicPlusDungeonRunCountsList.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 information about a character. * * GET /api/v1/characters/profile */ export const getApiApiV1CharactersProfile = async (args: GetApiApiV1CharactersProfileArgs, options?: GetApiApiV1CharactersProfileOptions) => { 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.region != null) query.append("region", String(args.region)) if (args.realm != null) query.append("realm", String(args.realm)) if (args.name != null) query.append("name", String(args.name)) if (args.fields != null) query.append("fields", String(args.fields)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/characters/profile${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(viewCharacterProfileResponse, await res.json()) };