import {z} from 'zod' export type LoLItemID = number; export type GetApiLolItemsLolItemIdArgs = {lol_item_id: LoLItemID}; export type GetApiLolItemsLolItemIdOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const loLItemID = z.number().int().gte(1); export const loLItemName = z.string(); export const videogameVersion = z.string(); export const videogameVersions = z.array(videogameVersion); export const loLItem = z.object({flat_armor_mod: z.number().int().gte(0).nullable(), flat_crit_chance_mod: z.number().int().gte(0).nullable(), flat_hp_pool_mod: z.number().int().gte(0).nullable(), flat_hp_regen_mod: z.number().int().gte(0).nullable(), flat_magic_damage_mod: z.number().int().gte(0).nullable(), flat_movement_speed_mod: z.number().int().gte(0).nullable(), flat_mp_pool_mod: z.number().int().gte(0).nullable(), flat_mp_regen_mod: z.number().int().gte(0).nullable(), flat_physical_damage_mod: z.number().int().gte(0).nullable(), flat_spell_block_mod: z.number().int().gte(0).nullable(), gold_base: z.number().int().gte(0).nullable(), gold_purchasable: z.boolean().nullable(), gold_sell: z.number().int().gte(0).nullable(), gold_total: z.number().int().gte(0).nullable(), id: loLItemID, image_url: z.string().nullable(), is_trinket: z.boolean().nullable(), name: loLItemName, percent_attack_speed_mod: z.number().int().gte(0).nullable(), percent_life_steal_mod: z.number().int().gte(0).nullable(), percent_movement_speed_mod: z.number().int().gte(0).nullable(), videogame_versions: videogameVersions}); 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 }; /** * Get an item * * GET /lol/items/{lol_item_id} * * Also accepts auth: QueryToken */ export const getApiLolItemsLolItemId = async (args: GetApiLolItemsLolItemIdArgs, options?: GetApiLolItemsLolItemIdOptions) => { const {baseUrl = "https://api.pandascore.co", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/lol/items/${encodeURIComponent(String(args.lol_item_id))}${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(loLItem, await res.json()) };