import {z} from 'zod' export type GetApiMarketsRegionIdOrdersArgs = {order_type: 'buy' | 'sell' | 'all', page?: number | undefined, region_id: number, type_id?: number | 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 GetApiMarketsRegionIdOrdersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const marketsRegionIdOrdersGet = z.array(z.object({duration: z.number().int(), is_buy_order: z.boolean(), issued: z.string(), location_id: z.number().int(), min_volume: z.number().int(), order_id: z.number().int(), price: z.number(), range: z.enum(["station", "region", "solarsystem", "1", "2", "3", "4", "5", "10", "20", "30", "40"]), system_id: z.number().int(), type_id: z.number().int(), volume_remain: z.number().int(), volume_total: z.number().int()})); 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 }; /** * List orders in a region * * GET /markets/{region_id}/orders */ export const getApiMarketsRegionIdOrders = async (args: GetApiMarketsRegionIdOrdersArgs, options?: GetApiMarketsRegionIdOrdersOptions) => { const {baseUrl = "https://esi.evetech.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.order_type != null) query.append("order_type", String(args.order_type)) if (args.page != null) query.append("page", String(args.page)) if (args.type_id != null) query.append("type_id", String(args.type_id)) 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(/\/+$/, '')}/markets/${encodeURIComponent(String(args.region_id))}/orders${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(marketsRegionIdOrdersGet, await res.json()) };