Skip to content

Commit 096f3c4

Browse files
authored
Merge pull request #64 from Navigraph/feat/airport-info
Add airport information endpoint access
2 parents cabf6ef + d4512f8 commit 096f3c4

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

.changeset/beige-books-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@navigraph/charts": minor
3+
---
4+
5+
Added airport information endpoint access. This endpoint can be used to fetch details such as available fuel, types of repair services etc..
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { navigraphRequest } from "@navigraph/auth";
2+
import getAirportInfo from "./getAirportInfo";
3+
4+
const getSpy = jest.spyOn(navigraphRequest, "get");
5+
const consoleSpy = jest.spyOn(console, "error").mockImplementation();
6+
7+
it("given a valid icao, when no user is authenticated, should return null and log an error", async () => {
8+
getSpy.mockImplementation(() =>
9+
Promise.reject({
10+
message: "Request failed with status code 401",
11+
isAxiosError: true,
12+
response: {
13+
status: 401,
14+
data: "Unauthorized",
15+
},
16+
})
17+
);
18+
19+
const response = await getAirportInfo({ icao: "ESSA" });
20+
21+
expect(response).toEqual(null);
22+
expect(consoleSpy).toHaveBeenCalledWith(
23+
"[Navigraph]",
24+
"Failed to fetch airport information. Reason:",
25+
"Request failed with status code 401"
26+
);
27+
});
28+
29+
// TODO: Figure out how to mock `navigraphRequest` without breaking the interceptors in order to simulate authenticated requests
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Logger } from "@navigraph/app";
2+
import { isAxiosError, navigraphRequest } from "@navigraph/auth";
3+
import { getAirportApiRoot } from "../constants";
4+
import { AirportInfo } from "./types";
5+
6+
/** Fetches general, useful information about an airport such as fuel types, repairs, and more
7+
* @param options.icao - The ICAO code of an airport
8+
* @returns {AirportInfo} An object containing information about the airport
9+
*/
10+
export default async function getAirportInfo({ icao }: { icao: string }): Promise<AirportInfo | null> {
11+
const result = await navigraphRequest
12+
.get<AirportInfo>(`${getAirportApiRoot()}/${icao}`)
13+
.catch((e: unknown) =>
14+
Logger.err("Failed to fetch airport information. Reason:", isAxiosError(e) ? e.message : e)
15+
);
16+
return result?.data || null;
17+
}

packages/charts/src/api/types.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,70 @@ export type Chart = {
8787
export interface ChartsIndexResponse {
8888
charts: Chart[];
8989
}
90+
91+
export type Fuel =
92+
| "73 Octane"
93+
| "80-87 Octane"
94+
| "100 low lead (LL) octane"
95+
| "100-130 octane"
96+
| "115-145 octane"
97+
| "Mogas"
98+
| "JET"
99+
| "JET A"
100+
| "JET A-1"
101+
| "Jet A+"
102+
| "JET B"
103+
| "JET 4"
104+
| "JET 5";
105+
106+
export type OxygenService = "High Pressure" | "Low Pressure" | "High Pressure Bottle" | "Low Pressure Bottle";
107+
108+
export type Repairs = "Minor Engine" | "Major Airframe" | "Major Engine";
109+
110+
export interface AirportInfo {
111+
icao_airport_identifier: string;
112+
iata_airport_designator: string;
113+
longest_runway: number;
114+
latitude: number;
115+
longitude: number;
116+
magnetic_variation: number;
117+
elevation: number;
118+
name: string;
119+
city: string;
120+
state_province_code: string;
121+
state_province_name: string;
122+
country_code: string;
123+
country_name: string;
124+
/** The type of fuel available at the airport or heliport. Empty means unknown. */
125+
fuel_types: Fuel[];
126+
/** The type of oxygen servicing available at the airport or heliport. Empty means unknown. */
127+
oxygen: OxygenService[];
128+
/** The type of fuel available at the airport or heliport. Empty means unknown. */
129+
repairs: Repairs[];
130+
/**
131+
* Indicates if landing fees are charged for private or non-revenue producing aircraft.
132+
*
133+
* **Note:** These fees will vary from no charge for aircraft below certain weight – no charge if fuel purchased – to charges for all landing aircraft.
134+
* This field provides only a true/false indication, no specific details on what aircraft types must pay under what conditions are provided.
135+
*/
136+
landing_fee: boolean;
137+
/** Indicates if the airport/heliport is equipped with JASU and if that equipment is available to a public user of the airport/heliport */
138+
jet_starting_unit: boolean;
139+
/** Indicates if the airport supports precision approaches */
140+
precision_airport: boolean;
141+
/** Indicates if the airport has Beacon Lights. Beacon Lights are normally provided at any airport/heliport intended for use at night. */
142+
beacon: boolean;
143+
/** Indicates the availability of a government customs facility at the airport */
144+
customs: boolean;
145+
airport_type: string;
146+
time_zone: string;
147+
icao_code: string;
148+
daylight_savings: boolean;
149+
/** The Local Horizontal Reference Datum with which the Airport Reference Point (ARP) is associated */
150+
datum_code: string;
151+
revision_date: string;
152+
parsed_cycle: string;
153+
std_charts: boolean;
154+
cao_charts: boolean;
155+
vfr_charts: boolean;
156+
}

packages/charts/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { getDefaultAppDomain } from "@navigraph/app";
22

33
export const getChartsApiRoot = () => `https://api.${getDefaultAppDomain()}/v2/charts`;
4+
export const getAirportApiRoot = () => `https://api.${getDefaultAppDomain()}/v2/airport`;

packages/charts/src/lib/getChartsAPI.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getApp, Logger, NotInitializedError, Scope } from "@navigraph/app";
22
import getChartImage from "../api/getChartImage";
33
import getChartsIndex from "../api/getChartsIndex";
4+
import getAirportInfo from "../api/getAirportInfo";
45

56
/** Grabs a reference to an object containing available Navigraph Charts API functionality */
67
export const getChartsAPI = () => {
@@ -17,5 +18,6 @@ export const getChartsAPI = () => {
1718
return {
1819
getChartsIndex,
1920
getChartImage,
21+
getAirportInfo,
2022
};
2123
};

0 commit comments

Comments
 (0)