import {z} from 'zod' export type GetApiApiV1LiveTrackingCharacterLoadoutArgs = {access_key?: string | undefined, region: 'us' | 'eu' | 'tw' | 'kr' | 'cn', realm: string, name: string}; export type GetApiApiV1LiveTrackingCharacterLoadoutOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const items1 = z.object({}); export const gear = z.object({item_level_equipped: z.number().optional(), item_level_total: z.number().optional(), artifact_traits: z.number().optional(), items: items1.optional()}); export const viewCharacterLoadoutResponse = z.object({wow_character_id: z.number().int().optional(), name: z.string().optional(), race: z.string().optional(), class: z.string().optional(), active_spec_name: z.string().nullable().optional(), active_spec_role: z.string().nullable().optional(), gender: z.number().int().optional(), faction: z.string().optional(), achievement_points: z.number().int().optional(), thumbnail_url: z.string().optional(), region: z.string().optional(), realm: z.string().optional(), last_crawled_at: z.string().nullable().optional(), profile_url: z.string().optional(), gear: gear.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 character loadout snapshot from combat log data, including equipped gear, spec, and basic profile info. * * GET /api/v1/live-tracking/character/loadout */ export const getApiApiV1LiveTrackingCharacterLoadout = async (args: GetApiApiV1LiveTrackingCharacterLoadoutArgs, options?: GetApiApiV1LiveTrackingCharacterLoadoutOptions) => { 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)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/live-tracking/character/loadout${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(viewCharacterLoadoutResponse, await res.json()) };