import {z} from 'zod' export type SolarSystemID = number; export type RouteConnection = {from: SolarSystemID, to: SolarSystemID}; export type RouteRequestBody = {avoid_systems?: Array | undefined, connections?: Array | undefined, preference?: ('Shorter' | 'Safer' | 'LessSecure') | undefined, security_penalty?: number | undefined}; export type CreateApiRouteOriginSystemIdDestinationSystemIdArgs = {origin_system_id: SolarSystemID, destination_system_id: SolarSystemID, '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, body: RouteRequestBody}; export type CreateApiRouteOriginSystemIdDestinationSystemIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const solarSystemID = z.number().int(); export const route = z.object({route: z.array(solarSystemID)}); 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 route between two systems * * POST /route/{origin_system_id}/{destination_system_id} */ export const createApiRouteOriginSystemIdDestinationSystemId = async (args: CreateApiRouteOriginSystemIdDestinationSystemIdArgs, options?: CreateApiRouteOriginSystemIdDestinationSystemIdOptions) => { const {baseUrl = "https://esi.evetech.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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'])) const url = `${baseUrl.replace(/\/+$/, '')}/route/${encodeURIComponent(String(args.origin_system_id))}/${encodeURIComponent(String(args.destination_system_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(route, await res.json()) };