import {z} from 'zod' export type GetApiApiV1LiveTrackingHeatmapsFloorsArgs = {access_key?: string | undefined}; export type GetApiApiV1LiveTrackingHeatmapsFloorsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const heatmapFloor = z.object({id: z.number().int().optional(), uiMapId: z.number().int().optional(), name: z.string().optional(), default: z.number().int().optional(), ingameMinX: z.number().optional(), ingameMinY: z.number().optional(), ingameMaxX: z.number().optional(), ingameMaxY: z.number().optional()}); export const viewHeatmapFloorsResponse = z.array(heatmapFloor); 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 floor geometry data for all dungeons. Used to map game-world coordinates onto dungeon map images for heatmap rendering. * * GET /api/v1/live-tracking/heatmaps/floors */ export const getApiApiV1LiveTrackingHeatmapsFloors = async (args: GetApiApiV1LiveTrackingHeatmapsFloorsArgs, options?: GetApiApiV1LiveTrackingHeatmapsFloorsOptions) => { 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)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/live-tracking/heatmaps/floors${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(viewHeatmapFloorsResponse, await res.json()) };