import {z} from 'zod' export type GetApiHistoryFlightsIdMapArgs = {id: string, height?: number | undefined, width?: number | undefined, layer_on?: (Array<'US Cities' | 'european country boundaries' | 'asia country boundaries' | 'major airports' | 'country boundaries' | 'US state boundaries' | 'water' | 'US major roads' | 'radar' | 'track' | 'flights' | 'airports'>) | undefined, layer_off?: (Array<'US Cities' | 'european country boundaries' | 'asia country boundaries' | 'major airports' | 'country boundaries' | 'US state boundaries' | 'water' | 'US major roads' | 'radar' | 'track' | 'flights' | 'airports'>) | undefined, show_data_block?: boolean | undefined, airports_expand_view?: boolean | undefined, show_airports?: boolean | undefined, bounding_box?: Array | undefined}; export type GetApiHistoryFlightsIdMapOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiHistoryFlightsIdMapResponse = z.object({map: z.string()}); 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 image of a historical flight's track on a map * * GET /history/flights/{id}/map */ export const getApiHistoryFlightsIdMap = async (args: GetApiHistoryFlightsIdMapArgs, options?: GetApiHistoryFlightsIdMapOptions) => { const {baseUrl = "https://aeroapi.flightaware.com/aeroapi", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json; charset=UTF-8") if (args.height != null) query.append("height", String(args.height)) if (args.width != null) query.append("width", String(args.width)) for (const item of args.layer_on ?? []) query.append("layer_on", String(item)) for (const item of args.layer_off ?? []) query.append("layer_off", String(item)) if (args.show_data_block != null) query.append("show_data_block", String(args.show_data_block)) if (args.airports_expand_view != null) query.append("airports_expand_view", String(args.airports_expand_view)) if (args.show_airports != null) query.append("show_airports", String(args.show_airports)) for (const item of args.bounding_box ?? []) query.append("bounding_box", String(item)) if (ApiKeyAuth !== undefined) headers.set("x-apikey", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/history/flights/${encodeURIComponent(String(args.id))}/map${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(getApiHistoryFlightsIdMapResponse, await res.json()) };