import {z} from 'zod' export type CharacterID = number; export type GetApiCharactersCharacterIdSearchArgs = {categories: Array<'agent' | 'alliance' | 'character' | 'constellation' | 'corporation' | 'faction' | 'inventory_type' | 'region' | 'solar_system' | 'station' | 'structure'>, character_id: CharacterID, search: string, strict?: boolean | undefined, 'Accept-Language'?: ('en' | 'de' | 'fr' | 'ja' | 'ru' | 'zh' | 'ko' | 'es') | undefined, 'If-None-Match'?: string | undefined, 'X-Compatibility-Date': '2025-12-16', 'X-Tenant'?: string | undefined, 'If-Modified-Since'?: string | undefined}; export type GetApiCharactersCharacterIdSearchOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const charactersCharacterIdSearchGet = z.object({agent: z.array(z.number().int()).optional(), alliance: z.array(z.number().int()).optional(), character: z.array(z.number().int()).optional(), constellation: z.array(z.number().int()).optional(), corporation: z.array(z.number().int()).optional(), faction: z.array(z.number().int()).optional(), inventory_type: z.array(z.number().int()).optional(), region: z.array(z.number().int()).optional(), solar_system: z.array(z.number().int()).optional(), station: z.array(z.number().int()).optional(), structure: z.array(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 }; /** * Search on a string * * GET /characters/{character_id}/search */ export const getApiCharactersCharacterIdSearch = async (args: GetApiCharactersCharacterIdSearchArgs, options?: GetApiCharactersCharacterIdSearchOptions) => { const {baseUrl = "https://esi.evetech.net", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.categories ?? []) query.append("categories", String(item)) if (args.search != null) query.append("search", String(args.search)) if (args.strict != null) query.append("strict", String(args.strict)) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) if (args['X-Compatibility-Date'] != null) headers.set("X-Compatibility-Date", String(args['X-Compatibility-Date'])) if (args['X-Tenant'] != null) headers.set("X-Tenant", String(args['X-Tenant'])) if (args['If-Modified-Since'] != null) headers.set("If-Modified-Since", String(args['If-Modified-Since'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/characters/${encodeURIComponent(String(args.character_id))}/search${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(charactersCharacterIdSearchGet, await res.json()) };