@sharpapi/sharpapi-node-airports 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,464 @@
1
+ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Node.js Client")
2
+
3
+ # Airports Database & Flight Duration Calculator API for Node.js
4
+
5
+ ## ✈️ Access global airports database and calculate flight durations — powered by SharpAPI.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@sharpapi/sharpapi-node-airports.svg)](https://www.npmjs.com/package/@sharpapi/sharpapi-node-airports)
8
+ [![License](https://img.shields.io/npm/l/@sharpapi/sharpapi-node-airports.svg)](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
9
+
10
+ **SharpAPI Airports Database** provides access to nearly 30,000 airports worldwide with comprehensive filtering, search capabilities, and flight duration calculations. Perfect for travel applications, booking systems, and aviation tools.
11
+
12
+ ---
13
+
14
+ ## 📋 Table of Contents
15
+
16
+ 1. [Requirements](#requirements)
17
+ 2. [Installation](#installation)
18
+ 3. [Usage](#usage)
19
+ 4. [API Documentation](#api-documentation)
20
+ 5. [Response Format](#response-format)
21
+ 6. [Examples](#examples)
22
+ 7. [License](#license)
23
+
24
+ ---
25
+
26
+ ## Requirements
27
+
28
+ - Node.js >= 16.x
29
+ - npm or yarn
30
+
31
+ ---
32
+
33
+ ## Installation
34
+
35
+ ### Step 1. Install the package via npm:
36
+
37
+ ```bash
38
+ npm install @sharpapi/sharpapi-node-airports
39
+ ```
40
+
41
+ ### Step 2. Get your API key
42
+
43
+ Visit [SharpAPI.com](https://sharpapi.com/) to get your API key.
44
+
45
+ ---
46
+
47
+ ## Usage
48
+
49
+ ```javascript
50
+ const { SharpApiAirportsService } = require('@sharpapi/sharpapi-node-airports');
51
+
52
+ const apiKey = process.env.SHARP_API_KEY;
53
+ const service = new SharpApiAirportsService(apiKey);
54
+
55
+ async function searchAirports() {
56
+ try {
57
+ // Search airports by city
58
+ const airports = await service.getAirports({
59
+ city: 'New York',
60
+ per_page: 10,
61
+ iata_assigned: true
62
+ });
63
+
64
+ console.log(`Found ${airports.data.length} airports:`);
65
+ airports.data.forEach(airport => {
66
+ console.log(`${airport.name} (${airport.iata}) - ${airport.city}, ${airport.country}`);
67
+ });
68
+
69
+ // Get specific airport by IATA code
70
+ const jfk = await service.getAirportByIata('JFK');
71
+ console.log('\nJFK Airport:', jfk);
72
+
73
+ // Calculate flight duration
74
+ const duration = await service.calculateFlightDuration('JFK', 'LAX');
75
+ console.log('\nFlight JFK → LAX:', duration);
76
+ } catch (error) {
77
+ console.error('Error:', error.message);
78
+ }
79
+ }
80
+
81
+ searchAirports();
82
+ ```
83
+
84
+ ---
85
+
86
+ ## API Documentation
87
+
88
+ ### Methods
89
+
90
+ #### `getAirports(filters?: object): Promise<object>`
91
+
92
+ Get paginated list of airports with optional filters.
93
+
94
+ **Filters:**
95
+ - `per_page` (number): Results per page (max 100, default: 25)
96
+ - `iata_assigned` (boolean): Only airports with IATA codes
97
+ - `icao_assigned` (boolean): Only airports with ICAO codes
98
+ - `lid_assigned` (boolean): Only airports with LID codes
99
+ - `country` (string): Filter by 2-letter country code
100
+ - `timezone` (string): Filter by timezone
101
+ - `name` (string): Filter by airport name (partial match)
102
+ - `city` (string): Filter by city name (partial match)
103
+
104
+ **Returns:**
105
+ - Paginated list of airports with metadata
106
+
107
+ #### `getAirportByIata(iataCode: string): Promise<object>`
108
+
109
+ Get airport information by IATA code.
110
+
111
+ **Parameters:**
112
+ - `iataCode` (string): Three-letter IATA code (e.g., 'JFK')
113
+
114
+ #### `getAirportByIcao(icaoCode: string): Promise<object>`
115
+
116
+ Get airport information by ICAO code.
117
+
118
+ **Parameters:**
119
+ - `icaoCode` (string): Four-letter ICAO code (e.g., 'KJFK')
120
+
121
+ #### `getAirportByUuid(uuid: string): Promise<object>`
122
+
123
+ Get airport information by UUID.
124
+
125
+ #### `getNearbyAirports(latitude: number, longitude: number, radius?: number, limit?: number): Promise<object>`
126
+
127
+ Find airports near a location.
128
+
129
+ **Parameters:**
130
+ - `latitude` (number): Latitude coordinate
131
+ - `longitude` (number): Longitude coordinate
132
+ - `radius` (number, optional): Search radius in kilometers (default: 100)
133
+ - `limit` (number, optional): Maximum results (default: 10)
134
+
135
+ #### `calculateFlightDuration(fromIata: string, toIata: string): Promise<object>`
136
+
137
+ Calculate flight duration between two airports.
138
+
139
+ **Parameters:**
140
+ - `fromIata` (string): Departure airport IATA code
141
+ - `toIata` (string): Arrival airport IATA code
142
+
143
+ #### `getCountries(): Promise<object>`
144
+
145
+ Get list of all countries with airports.
146
+
147
+ #### `getCitiesByCountry(countryCode: string): Promise<object>`
148
+
149
+ Get cities with airports in a specific country.
150
+
151
+ ---
152
+
153
+ ## Response Format
154
+
155
+ ### Airport List Response
156
+
157
+ ```json
158
+ {
159
+ "data": [
160
+ {
161
+ "id": "1ef266de-5a6c-67d6-86a1-06bb2780ed98",
162
+ "icao": "KJFK",
163
+ "iata": "JFK",
164
+ "lid": "",
165
+ "name": "John F Kennedy International Airport",
166
+ "city": "New York",
167
+ "subdivision": "New York",
168
+ "country": "US",
169
+ "timezone": "America/New_York",
170
+ "elevation": 13,
171
+ "latitude": 40.6398,
172
+ "longitude": -73.7789
173
+ }
174
+ ],
175
+ "links": {
176
+ "first": "https://sharpapi.com/api/v1/airports?page=1",
177
+ "last": "https://sharpapi.com/api/v1/airports?page=1128",
178
+ "prev": null,
179
+ "next": "https://sharpapi.com/api/v1/airports?page=2"
180
+ },
181
+ "meta": {
182
+ "current_page": 1,
183
+ "from": 1,
184
+ "last_page": 1128,
185
+ "per_page": 25,
186
+ "to": 25,
187
+ "total": 28186
188
+ }
189
+ }
190
+ ```
191
+
192
+ ### Single Airport Response
193
+
194
+ ```json
195
+ {
196
+ "id": "1ef266de-5a6c-67d6-86a1-06bb2780ed98",
197
+ "icao": "KJFK",
198
+ "iata": "JFK",
199
+ "lid": "",
200
+ "name": "John F Kennedy International Airport",
201
+ "city": "New York",
202
+ "subdivision": "New York",
203
+ "country": "US",
204
+ "timezone": "America/New_York",
205
+ "elevation": 13,
206
+ "latitude": 40.6398,
207
+ "longitude": -73.7789
208
+ }
209
+ ```
210
+
211
+ ---
212
+
213
+ ## Examples
214
+
215
+ ### Search Airports by Country
216
+
217
+ ```javascript
218
+ const { SharpApiAirportsService } = require('@sharpapi/sharpapi-node-airports');
219
+
220
+ const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
221
+
222
+ async function getUKAirports() {
223
+ const airports = await service.getAirports({
224
+ country: 'GB',
225
+ iata_assigned: true,
226
+ per_page: 50
227
+ });
228
+
229
+ console.log(`Found ${airports.meta.total} UK airports`);
230
+
231
+ airports.data.forEach(airport => {
232
+ console.log(`${airport.iata} - ${airport.name}, ${airport.city}`);
233
+ });
234
+ }
235
+
236
+ getUKAirports();
237
+ ```
238
+
239
+ ### Flight Search Application
240
+
241
+ ```javascript
242
+ const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
243
+
244
+ async function searchFlights(departure, arrival) {
245
+ // Get departure airport
246
+ const depAirport = await service.getAirportByIata(departure);
247
+ console.log(`Departure: ${depAirport.name}, ${depAirport.city}`);
248
+
249
+ // Get arrival airport
250
+ const arrAirport = await service.getAirportByIata(arrival);
251
+ console.log(`Arrival: ${arrAirport.name}, ${arrAirport.city}`);
252
+
253
+ // Calculate flight duration
254
+ const duration = await service.calculateFlightDuration(departure, arrival);
255
+ console.log(`Estimated Duration: ${duration.hours}h ${duration.minutes}m`);
256
+ console.log(`Distance: ${duration.distance} km`);
257
+
258
+ return {
259
+ from: depAirport,
260
+ to: arrAirport,
261
+ duration: duration
262
+ };
263
+ }
264
+
265
+ searchFlights('LHR', 'JFK').then(result => {
266
+ console.log('Flight Details:', result);
267
+ });
268
+ ```
269
+
270
+ ### Travel App Integration
271
+
272
+ ```javascript
273
+ const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
274
+
275
+ async function buildDestinationSelector(countryCode) {
276
+ // Get all cities with airports in the country
277
+ const cities = await service.getCitiesByCountry(countryCode);
278
+
279
+ const destinations = await Promise.all(
280
+ cities.map(async (city) => {
281
+ const airports = await service.getAirports({
282
+ country: countryCode,
283
+ city: city,
284
+ iata_assigned: true,
285
+ per_page: 10
286
+ });
287
+
288
+ return {
289
+ city: city,
290
+ airports: airports.data.map(a => ({
291
+ code: a.iata,
292
+ name: a.name,
293
+ timezone: a.timezone
294
+ }))
295
+ };
296
+ })
297
+ );
298
+
299
+ return destinations;
300
+ }
301
+
302
+ const usDestinations = await buildDestinationSelector('US');
303
+ console.log('US Destinations:', usDestinations);
304
+ ```
305
+
306
+ ### Nearby Airports Finder
307
+
308
+ ```javascript
309
+ const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
310
+
311
+ async function findNearestAirport(latitude, longitude) {
312
+ const nearby = await service.getNearbyAirports(latitude, longitude, 50, 5);
313
+
314
+ console.log(`Airports within 50km of (${latitude}, ${longitude}):`);
315
+
316
+ nearby.forEach((airport, index) => {
317
+ console.log(`${index + 1}. ${airport.name} (${airport.iata})`);
318
+ console.log(` Distance: ${airport.distance} km`);
319
+ console.log(` City: ${airport.city}, ${airport.country}`);
320
+ });
321
+
322
+ return nearby[0]; // Return closest airport
323
+ }
324
+
325
+ // Find airports near San Francisco
326
+ findNearestAirport(37.7749, -122.4194);
327
+ ```
328
+
329
+ ### Multi-City Trip Planner
330
+
331
+ ```javascript
332
+ const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
333
+
334
+ async function planMultiCityTrip(cities) {
335
+ const itinerary = [];
336
+
337
+ for (let i = 0; i < cities.length - 1; i++) {
338
+ const fromCity = cities[i];
339
+ const toCity = cities[i + 1];
340
+
341
+ // Find airports in each city
342
+ const fromAirports = await service.getAirports({
343
+ city: fromCity,
344
+ iata_assigned: true,
345
+ per_page: 1
346
+ });
347
+
348
+ const toAirports = await service.getAirports({
349
+ city: toCity,
350
+ iata_assigned: true,
351
+ per_page: 1
352
+ });
353
+
354
+ if (fromAirports.data.length === 0 || toAirports.data.length === 0) {
355
+ console.log(`No airports found for ${fromCity} or ${toCity}`);
356
+ continue;
357
+ }
358
+
359
+ const fromAirport = fromAirports.data[0];
360
+ const toAirport = toAirports.data[0];
361
+
362
+ // Calculate duration
363
+ const duration = await service.calculateFlightDuration(
364
+ fromAirport.iata,
365
+ toAirport.iata
366
+ );
367
+
368
+ itinerary.push({
369
+ leg: i + 1,
370
+ from: {
371
+ city: fromCity,
372
+ airport: fromAirport.name,
373
+ code: fromAirport.iata
374
+ },
375
+ to: {
376
+ city: toCity,
377
+ airport: toAirport.name,
378
+ code: toAirport.iata
379
+ },
380
+ duration: duration
381
+ });
382
+ }
383
+
384
+ return itinerary;
385
+ }
386
+
387
+ const cities = ['London', 'Paris', 'Rome', 'Barcelona'];
388
+ const trip = await planMultiCityTrip(cities);
389
+
390
+ console.log('Multi-City Itinerary:');
391
+ trip.forEach(leg => {
392
+ console.log(`\nLeg ${leg.leg}: ${leg.from.city} → ${leg.to.city}`);
393
+ console.log(` ${leg.from.code} to ${leg.to.code}`);
394
+ console.log(` Duration: ${leg.duration.hours}h ${leg.duration.minutes}m`);
395
+ });
396
+ ```
397
+
398
+ ---
399
+
400
+ ## Use Cases
401
+
402
+ - **Travel Booking Platforms**: Airport search and selection
403
+ - **Flight Search Engines**: Calculate durations and distances
404
+ - **Travel Itinerary Planners**: Multi-city trip planning
405
+ - **Mobile Travel Apps**: Nearby airport finder
406
+ - **Aviation Analytics**: Airport database analysis
407
+ - **Route Planning**: Optimize flight routes
408
+ - **Travel Comparison Sites**: Compare flight options
409
+ - **Tourism Applications**: Destination discovery
410
+
411
+ ---
412
+
413
+ ## Database Coverage
414
+
415
+ - **Total Airports**: ~30,000 worldwide
416
+ - **Coverage**: All continents and major aviation hubs
417
+ - **Code Systems**: IATA, ICAO, and LID codes
418
+ - **Data Fields**: Name, city, country, timezone, elevation, coordinates
419
+ - **Updates**: Regular database maintenance
420
+
421
+ ---
422
+
423
+ ## API Features
424
+
425
+ - **Synchronous**: Instant responses, no polling required
426
+ - **Paginated Results**: Efficient data retrieval
427
+ - **Flexible Filtering**: Multiple filter options
428
+ - **Geographic Search**: Find airports by location
429
+ - **Duration Calculation**: Estimate flight times
430
+ - **Global Coverage**: Worldwide airport database
431
+
432
+ ---
433
+
434
+ ## API Endpoint
435
+
436
+ **GET** `/airports`
437
+
438
+ For detailed API specifications, refer to:
439
+ - [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsW2)
440
+ - [Product Page](https://sharpapi.com/en/catalog/utility/airports-database-flight-duration-calculator)
441
+
442
+ ---
443
+
444
+ ## Related Packages
445
+
446
+ - [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
447
+
448
+ ---
449
+
450
+ ## License
451
+
452
+ This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
453
+
454
+ ---
455
+
456
+ ## Support
457
+
458
+ - **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
459
+ - **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
460
+ - **Email**: contact@sharpapi.com
461
+
462
+ ---
463
+
464
+ **Powered by [SharpAPI](https://sharpapi.com/) - AI-Powered API Workflow Automation**
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@sharpapi/sharpapi-node-airports",
3
+ "version": "1.0.0",
4
+ "description": "SharpAPI.com Node.js SDK for Airports Database & Flight Duration Calculator",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "keywords": [
10
+ "sharpapi",
11
+ "api",
12
+ "api integration",
13
+ "restful api",
14
+ "nodejs",
15
+ "software development",
16
+ "airports",
17
+ "flight duration",
18
+ "travel",
19
+ "tourism"
20
+ ],
21
+ "author": "Dawid Makowski <contact@sharpapi.com>",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@sharpapi/sharpapi-node-core": "file:../sharpapi-node-core"
25
+ },
26
+ "devDependencies": {
27
+ "jest": "^29.7.0"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/sharpapi/sharpapi-node-airports.git"
35
+ }
36
+ }
@@ -0,0 +1,106 @@
1
+ const { SharpApiCoreService } = require('@sharpapi/sharpapi-node-core');
2
+
3
+ /**
4
+ * Service for accessing Airports Database & Flight Duration Calculator API using SharpAPI.com
5
+ */
6
+ class SharpApiAirportsService extends SharpApiCoreService {
7
+ /**
8
+ * Get list of airports with optional filters
9
+ *
10
+ * @param {object} [filters={}] - Filter options
11
+ * @param {number} [filters.per_page=25] - Results per page (max 100)
12
+ * @param {boolean} [filters.iata_assigned] - Filter by IATA code assignment
13
+ * @param {boolean} [filters.icao_assigned] - Filter by ICAO code assignment
14
+ * @param {string} [filters.country] - Filter by country
15
+ * @param {string} [filters.name] - Filter by airport name
16
+ * @param {string} [filters.city] - Filter by city
17
+ * @returns {Promise<object>} - List of airports
18
+ */
19
+ async getAirports(filters = {}) {
20
+ const response = await this.makeRequest('GET', '/airports', filters);
21
+ return response.data;
22
+ }
23
+
24
+ /**
25
+ * Get airport information by IATA code
26
+ *
27
+ * @param {string} iataCode - The IATA code of the airport
28
+ * @returns {Promise<object>} - Airport information
29
+ */
30
+ async getAirportByIata(iataCode) {
31
+ const response = await this.makeRequest('GET', `/airports/iata/${iataCode}`);
32
+ return response.data;
33
+ }
34
+
35
+ /**
36
+ * Get airport information by ICAO code
37
+ *
38
+ * @param {string} icaoCode - The ICAO code of the airport
39
+ * @returns {Promise<object>} - Airport information
40
+ */
41
+ async getAirportByIcao(icaoCode) {
42
+ const response = await this.makeRequest('GET', `/airports/icao/${icaoCode}`);
43
+ return response.data;
44
+ }
45
+
46
+ /**
47
+ * Get airport information by UUID
48
+ *
49
+ * @param {string} uuid - The UUID of the airport
50
+ * @returns {Promise<object>} - Airport information
51
+ */
52
+ async getAirportByUuid(uuid) {
53
+ const response = await this.makeRequest('GET', `/airports/${uuid}`);
54
+ return response.data;
55
+ }
56
+
57
+ /**
58
+ * Get airports near a specific location
59
+ *
60
+ * @param {number} latitude - Latitude of the location
61
+ * @param {number} longitude - Longitude of the location
62
+ * @param {number} [radius=100] - Radius in kilometers
63
+ * @param {number} [limit=10] - Maximum number of results to return
64
+ * @returns {Promise<object>} - Nearby airports
65
+ */
66
+ async getNearbyAirports(latitude, longitude, radius = 100, limit = 10) {
67
+ const data = { latitude, longitude, radius, limit };
68
+ const response = await this.makeRequest('GET', '/utility/airports/nearby', data);
69
+ return response.data;
70
+ }
71
+
72
+ /**
73
+ * Calculate flight duration between two airports
74
+ *
75
+ * @param {string} fromIata - IATA code of departure airport
76
+ * @param {string} toIata - IATA code of arrival airport
77
+ * @returns {Promise<object>} - Flight duration information
78
+ */
79
+ async calculateFlightDuration(fromIata, toIata) {
80
+ const response = await this.makeRequest('GET', `/utility/flight-duration/${fromIata}/${toIata}`);
81
+ return response.data;
82
+ }
83
+
84
+ /**
85
+ * Get all countries with airports
86
+ *
87
+ * @returns {Promise<object>} - List of countries
88
+ */
89
+ async getCountries() {
90
+ const response = await this.makeRequest('GET', '/utility/airports/countries');
91
+ return response.data;
92
+ }
93
+
94
+ /**
95
+ * Get all cities with airports in a specific country
96
+ *
97
+ * @param {string} countryCode - ISO country code
98
+ * @returns {Promise<object>} - List of cities
99
+ */
100
+ async getCitiesByCountry(countryCode) {
101
+ const response = await this.makeRequest('GET', `/utility/airports/cities/${countryCode}`);
102
+ return response.data;
103
+ }
104
+ }
105
+
106
+ module.exports = { SharpApiAirportsService };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // sharpapi-node-airports/src/index.js
2
+ const { SharpApiAirportsService } = require('./SharpApiAirportsService');
3
+
4
+ module.exports = {
5
+ SharpApiAirportsService,
6
+ };