import {z} from 'zod' export type GetApiApiV1LiveTrackingGuildLootArgs = {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', region: 'us' | 'eu' | 'tw' | 'kr' | 'cn', realm: string, guild: string, duration_minutes?: number | undefined, start_time?: string | undefined, end_time?: string | undefined, count?: number | undefined, item_types?: string | undefined}; export type GetApiApiV1LiveTrackingGuildLootOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const item = z.object({}); export const itemLink = z.object({}); export const items2 = z.array(z.number().int()); export const model8 = z.object({id: z.number().int().optional(), name: z.string().optional(), slug: z.string().optional()}); export const classes = z.array(model8); export const tierToken = z.object({items: items2.optional(), classes: classes.optional()}).nullable(); export const guildLootItem = z.object({id: z.number().int().optional(), item: item.optional(), itemLink: itemLink.optional(), isTierItem: z.boolean().optional(), tierToken: tierToken.optional(), itemLevel: z.number().int().optional(), lootedAt: z.string().optional(), createdAt: z.string().optional()}); export const items3 = z.array(guildLootItem); export const viewGuildLootResponse = z.object({items: items3.optional(), widgetVersion: z.number().int().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 recent loot drops for a guild from combat log data. Filterable by time range and item type. * * GET /api/v1/live-tracking/guild/loot */ export const getApiApiV1LiveTrackingGuildLoot = async (args: GetApiApiV1LiveTrackingGuildLootArgs, options?: GetApiApiV1LiveTrackingGuildLootOptions) => { 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.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.duration_minutes != null) query.append("duration_minutes", String(args.duration_minutes)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.count != null) query.append("count", String(args.count)) if (args.item_types != null) query.append("item_types", String(args.item_types)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/live-tracking/guild/loot${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(viewGuildLootResponse, await res.json()) };