import {z} from 'zod' export type GetApiApiV1LiveTrackingGuildBossAttemptsArgs = {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' | 'latest', boss: 'latest', difficulty: 'mythic' | 'heroic' | 'normal' | 'latest', region: 'us' | 'eu' | 'tw' | 'kr' | 'cn', realm: string, guild: string, period?: string | undefined}; export type GetApiApiV1LiveTrackingGuildBossAttemptsOptions = {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 raidSummary = z.object({id: z.number().int().optional(), slug: z.string().optional(), name: z.string().optional(), short_name: z.string().optional(), icon: z.string().optional(), expansion_id: z.number().int().optional()}); export const raidEncounterSummary = z.object({id: z.number().int().optional(), slug: z.string().optional(), name: z.string().optional(), ordinal: z.number().int().optional()}); export const encounter1 = z.object({durationMs: z.number().int().optional()}); export const bossAttempt = z.object({pullStartedAt: z.string().optional(), overallPercent: z.number().nullable().optional(), isSuccess: z.boolean().optional(), encounter: encounter1.optional()}); export const attempts1 = z.array(bossAttempt); export const viewBossAttemptsResponse = z.object({guild: guildSummary.optional(), raid: raidSummary.optional(), boss: raidEncounterSummary.optional(), attempts: attempts1.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 a simplified timeline of boss attempts with health percentages. Ideal for rendering progress-over-time charts and stream overlays. * * GET /api/v1/live-tracking/guild/boss-attempts */ export const getApiApiV1LiveTrackingGuildBossAttempts = async (args: GetApiApiV1LiveTrackingGuildBossAttemptsArgs, options?: GetApiApiV1LiveTrackingGuildBossAttemptsOptions) => { 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)) if (args.guild != null) query.append("guild", String(args.guild)) if (args.period != null) query.append("period", String(args.period)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/live-tracking/guild/boss-attempts${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(viewBossAttemptsResponse, await res.json()) };