@headwindsimulations/api-client 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 FlyByWire Simulations
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,393 @@
1
+ # <img src="https://raw.githubusercontent.com/flybywiresim/fbw-branding/master/svg/FBW-Logo.svg" placeholder="FlyByWire" width="400"/>
2
+ # FlyByWire Simulations API Client
3
+
4
+ The official JavaScript client for the FBW API.
5
+ The library supports both JavaScript and TypeScript.
6
+
7
+ ## Installation
8
+
9
+ Install the client library using npm:
10
+
11
+ $ npm install --save @flybywiresim/api-client
12
+
13
+ ## Usage
14
+
15
+ ### Initializing the client
16
+ ```ts
17
+ import { NXApi } from '@flybywiresim/api-client';
18
+
19
+ NXApi.url = new URL('http://localhost:3000');
20
+ ```
21
+
22
+ By default, the URL is set to `https://api.flybywiresim.com`. If this is the desired URL this step can be omitted.
23
+
24
+ ### METAR
25
+ ```ts
26
+ import { Metar } from '@flybywiresim/api-client';
27
+
28
+ Metar.get(icao, source)
29
+ .then(data => {
30
+ console.log(data);
31
+ }).catch(err => {
32
+ console.error(err);
33
+ });
34
+ ```
35
+
36
+ - `icao` is a string of the the airport ICAO code to get the METAR for.
37
+ - `source` is the selected datasource for the METAR and is _optional_.
38
+ Valid sources are:
39
+ - vatsim
40
+ - ms
41
+ - ivao
42
+ - pilotedge
43
+
44
+ ### TAF
45
+ ```ts
46
+ import { Taf } from '@flybywiresim/api-client';
47
+
48
+ Taf.get(icao, source)
49
+ .then(data => {
50
+ console.log(data);
51
+ }).catch(err => {
52
+ console.error(err);
53
+ });
54
+ ```
55
+
56
+ - `icao` is a string of the the airport ICAO code to get the TAF for.
57
+ - `source` is the selected datasource for the TAF and is _optional_.
58
+ Valid sources are:
59
+ - aviationweather
60
+ - faa
61
+
62
+ ### ATIS
63
+ ```ts
64
+ import { Atis } from '@flybywiresim/api-client';
65
+
66
+ Atis.get(icao, source)
67
+ .then(data => {
68
+ console.log(data);
69
+ }).catch(err => {
70
+ console.error(err);
71
+ });
72
+ ```
73
+
74
+ - `icao` is a string of the the airport ICAO code to get the ATIS for.
75
+ - `source` is the selected datasource for the ATIS and is _optional_.
76
+ Valid sources are:
77
+ - faa
78
+ - vatsim
79
+ - ivao
80
+ - pilotedge
81
+
82
+ ### Airport
83
+ ```ts
84
+ import { Airport } from '@flybywiresim/api-client';
85
+
86
+ Airport.get(icao)
87
+ .then(data => {
88
+ console.log(data);
89
+ }).catch(err => {
90
+ console.error(err);
91
+ });
92
+ ```
93
+
94
+ - `icao` is a string of the the airport ICAO code to search for.
95
+
96
+
97
+ ### ATC
98
+ ```ts
99
+ import { Atis } from '@flybywiresim/api-client';
100
+
101
+ ATC.get(source)
102
+ .then(data => {
103
+ console.log(data);
104
+ }).catch(err => {
105
+ console.error(err);
106
+ });
107
+ ```
108
+
109
+ - `source` is the selected datasource for the ATC.
110
+ Valid sources are:
111
+ - vatsim
112
+ - ivao
113
+
114
+
115
+ ### TELEX connection handling
116
+
117
+ #### Connect to TELEX system
118
+ ```ts
119
+ import { Telex } from '@flybywiresim/api-client';
120
+
121
+ Telex.connect(status)
122
+ .then(data => {
123
+ console.log(data);
124
+ }).catch(err => {
125
+ console.error(err);
126
+ });
127
+ ```
128
+
129
+ - `status` is of type `AircraftStatus` and contains information about the current flight.
130
+
131
+ The backend might block certain flight numbers from being used for various reasons.
132
+
133
+ #### Update the TELEX status
134
+ ```ts
135
+ import { Telex } from '@flybywiresim/api-client';
136
+
137
+ Telex.update(status)
138
+ .then(data => {
139
+ console.log(data);
140
+ }).catch(err => {
141
+ console.error(err);
142
+ });
143
+ ```
144
+
145
+ - `status` is of type `AircraftStatus` and contains information about the current flight.
146
+
147
+ The status has to updated every 6 minutes for the connection to stay alive.
148
+ It is recommended to update the status every 15 seconds for a usable live map.
149
+ The status can only be updated once a connection has been established.
150
+
151
+ #### Disconnect from TELEX system
152
+ ```ts
153
+ import { Telex } from '@flybywiresim/api-client';
154
+
155
+ Telex.disconnect()
156
+ .then(data => {
157
+ console.log(data);
158
+ }).catch(err => {
159
+ console.error(err);
160
+ });
161
+ ```
162
+
163
+ The connection can only be disconnected once it has been established.
164
+ This releases the flight number for reuse and removes the flight from the live map.
165
+
166
+ ### TELEX message handling
167
+
168
+ #### Sending a message
169
+ ```ts
170
+ import { Telex } from '@flybywiresim/api-client';
171
+
172
+ Telex.sendMessage(recipient, message)
173
+ .then(data => {
174
+ console.log(data);
175
+ }).catch(err => {
176
+ console.error(err);
177
+ });
178
+ ```
179
+
180
+ - `recipient` is a string containing the flight number of the recipient flight.
181
+ - `message` is a string containing the message to send.
182
+
183
+ Messages will be filtered for profanity in the backend.
184
+
185
+ #### Receiving messages
186
+ ```ts
187
+ import { Telex } from '@flybywiresim/api-client';
188
+
189
+ Telex.fetchMessages()
190
+ .then(data => {
191
+ console.log(data);
192
+ }).catch(err => {
193
+ console.error(err);
194
+ });
195
+ ```
196
+
197
+ Messages can only be received once and will be acknowledged by this transaction.
198
+
199
+ ### TELEX Querying
200
+
201
+ #### Fetch a single page of active connections
202
+ ```ts
203
+ import { Telex } from '@flybywiresim/api-client';
204
+
205
+ Telex.fetchConnections(skip, take, bounds)
206
+ .then(data => {
207
+ console.log(data);
208
+ }).catch(err => {
209
+ console.error(err);
210
+ });
211
+ ```
212
+
213
+ - `skip` is a number and tells the backend to skip the first n connections.
214
+ - `take` is a number and tells the backend how many connections to send.
215
+ - `bounds` is an optional bounding box. Query only connections within this area.
216
+
217
+ `take` and `skip` are used to control the pagination. A maximum of 100 entries can be fetched at a time.
218
+
219
+ #### Fetch all active connections
220
+ ```ts
221
+ import { Telex } from '@flybywiresim/api-client';
222
+
223
+ Telex.fetchAllConnections(bounds, callback)
224
+ .then(data => {
225
+ console.log(data);
226
+ }).catch(err => {
227
+ console.error(err);
228
+ });
229
+ ```
230
+
231
+ - `bounds` is an optional bounding box. Query only connections within this area.
232
+ - `callback` gets called after every fetched page.
233
+
234
+ #### Fetch a certain connection
235
+ ```ts
236
+ import { Telex } from '@flybywiresim/api-client';
237
+
238
+ Telex.fetchConnection(id)
239
+ .then(data => {
240
+ console.log(data);
241
+ }).catch(err => {
242
+ console.error(err);
243
+ });
244
+ ```
245
+
246
+ - `id` is the unique identifier of the connection.
247
+
248
+ #### Find all active connections matching a flight number
249
+ ```ts
250
+ import { Telex } from '@flybywiresim/api-client';
251
+
252
+ Telex.findConnection(flight)
253
+ .then(data => {
254
+ console.log(data);
255
+ }).catch(err => {
256
+ console.error(err);
257
+ });
258
+ ```
259
+
260
+ - `flight` is the flight number to search for.
261
+
262
+ #### Count active connections
263
+ ```ts
264
+ import { Telex } from '@flybywiresim/api-client';
265
+
266
+ Telex.countConnections()
267
+ .then(data => {
268
+ console.log(data);
269
+ }).catch(err => {
270
+ console.error(err);
271
+ });
272
+ ```
273
+
274
+ ### Github
275
+
276
+ #### Get the newest commit for a branch
277
+ ```ts
278
+ import { GitVersions } from '@flybywiresim/api-client';
279
+
280
+ GitVersions.getNewestCommit(user, repo, branch)
281
+ .then(data => {
282
+ console.log(data);
283
+ }).catch(err => {
284
+ console.error(err);
285
+ });
286
+ ```
287
+
288
+ - `user` the owner of the repository.
289
+ - `repo` the repository.
290
+ - `branch` the requested branch.
291
+
292
+ #### Get all releases for a repository
293
+ ```ts
294
+ import { GitVersions } from '@flybywiresim/api-client';
295
+
296
+ GitVersions.getReleases(user, repo)
297
+ .then(data => {
298
+ console.log(data);
299
+ }).catch(err => {
300
+ console.error(err);
301
+ });
302
+ ```
303
+
304
+ - `user` the owner of the repository.
305
+ - `repo` the repository.
306
+
307
+ #### Get open pull requests for a repository
308
+ ```ts
309
+ import { GitVersions } from '@flybywiresim/api-client';
310
+
311
+ GitVersions.getPulls(user, repo)
312
+ .then(data => {
313
+ console.log(data);
314
+ }).catch(err => {
315
+ console.error(err);
316
+ });
317
+ ```
318
+
319
+ - `user` the owner of the repository.
320
+ - `repo` the repository.
321
+
322
+ #### Get the artifact URL for a pull request
323
+ ```ts
324
+ import { GitVersions } from '@flybywiresim/api-client';
325
+
326
+ GitVersions.getArtifact(user, repo, pull)
327
+ .then(data => {
328
+ console.log(data);
329
+ }).catch(err => {
330
+ console.error(err);
331
+ });
332
+ ```
333
+
334
+ - `user` the owner of the repository.
335
+ - `repo` the repository.
336
+ - `pull` the number of the pull request.
337
+
338
+
339
+ ### Charts
340
+
341
+ #### Get the charts for an airport
342
+ ```ts
343
+ import { Charts } from '@flybywiresim/api-client';
344
+
345
+ Charts.get(icao, source)
346
+ .then(data => {
347
+ console.log(data);
348
+ }).catch(err => {
349
+ console.error(err);
350
+ });
351
+ ```
352
+
353
+ - `icao` is a string of the the airport ICAO code to search for.
354
+
355
+
356
+ ### GNSS
357
+
358
+ #### Fetch data for all GNSS satellites
359
+ ```ts
360
+ import { Atis } from '@flybywiresim/api-client';
361
+
362
+ GNSS.get()
363
+ .then(data => {
364
+ console.log(data);
365
+ }).catch(err => {
366
+ console.error(err);
367
+ });
368
+ ```
369
+
370
+ ### Hoppie
371
+
372
+ #### Send the request
373
+ ```ts
374
+ import { Hoppie } from '@flybywiresim/api-client';
375
+
376
+ const body {
377
+ logon: 'XXXXXXXXX',
378
+ from: 'TEST0',
379
+ to: 'TEST0',
380
+ type: 'poll'
381
+ }
382
+ Hoppie.post(body)
383
+ .then(data => {
384
+ console.log(data);
385
+ }).catch(err => {
386
+ console.error(err);
387
+ });
388
+ ```
389
+
390
+
391
+ ## License
392
+
393
+ This software is licensed under the [MIT license](https://github.com/flybywiresim/api-client/blob/main/LICENSE).
@@ -0,0 +1,6 @@
1
+ export declare class HoppieResponse {
2
+ response: string;
3
+ }
4
+ export declare class Hoppie {
5
+ static sendRequest(body: any): Promise<HoppieResponse>;
6
+ }
File without changes
@@ -0,0 +1,16 @@
1
+ export declare class AirportResponse {
2
+ icao: string;
3
+ iata: string;
4
+ type: string;
5
+ name: string;
6
+ lat: number;
7
+ lon: number;
8
+ elevation: number;
9
+ continent: string;
10
+ country: string;
11
+ transAlt: number;
12
+ }
13
+ export declare class Airport {
14
+ static get(icao: string): Promise<AirportResponse>;
15
+ static getBatch(icaos: string[]): Promise<AirportResponse[]>;
16
+ }
File without changes
@@ -0,0 +1,22 @@
1
+ export declare enum AtcType {
2
+ UNKNOWN = 0,
3
+ DELIVERY = 1,
4
+ GROUND = 2,
5
+ TOWER = 3,
6
+ DEPARTURE = 4,
7
+ APPROACH = 5,
8
+ RADAR = 6,
9
+ ATIS = 7
10
+ }
11
+ export declare class ATCInfo {
12
+ callsign: string;
13
+ frequency: string;
14
+ visualRange: number;
15
+ textAtis: string[];
16
+ type: AtcType;
17
+ latitude?: number;
18
+ longitude?: number;
19
+ }
20
+ export declare class ATC {
21
+ static get(source: string): Promise<ATCInfo[]>;
22
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export declare class AtisResponse {
2
+ icao: string;
3
+ source: string;
4
+ combined?: string;
5
+ arr?: string;
6
+ dep?: string;
7
+ }
8
+ export declare class Atis {
9
+ static get(icao: string, source?: string): Promise<AtisResponse>;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export declare class Chart {
2
+ url: string;
3
+ name: string;
4
+ }
5
+ export declare class ChartsResponse {
6
+ icao: string;
7
+ charts?: Chart[];
8
+ }
9
+ export declare class Charts {
10
+ static get(icao: string): Promise<ChartsResponse>;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ export declare class CommitInfo {
2
+ sha: string;
3
+ shortSha: string;
4
+ timestamp: Date;
5
+ }
6
+ export declare class ReleaseInfo {
7
+ name: string;
8
+ isPreRelease: boolean;
9
+ publishedAt: Date;
10
+ htmlUrl: string;
11
+ body: string;
12
+ }
13
+ export declare class PullLabel {
14
+ id: string;
15
+ name: string;
16
+ color: string;
17
+ }
18
+ export declare class PullInfo {
19
+ number: number;
20
+ title: string;
21
+ author: string;
22
+ labels: PullLabel[];
23
+ isDraft: boolean;
24
+ }
25
+ export declare class ArtifactInfo {
26
+ artifactUrl: string;
27
+ }
28
+ export declare class GitVersions {
29
+ static getNewestCommit(user: string, repo: string, branch: string): Promise<CommitInfo>;
30
+ static getReleases(user: string, repo: string, includePreReleases?: boolean, skip?: number, take?: number): Promise<ReleaseInfo[]>;
31
+ static getPulls(user: string, repo: string): Promise<PullInfo[]>;
32
+ static getArtifact(user: string, repo: string, pull: string): Promise<ArtifactInfo>;
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ export declare class GNSSResponse {
2
+ name: string;
3
+ id: string;
4
+ epoch: Date;
5
+ meanMotion: number;
6
+ eccentricity: number;
7
+ inclination: number;
8
+ raOfAscNode: number;
9
+ argOfPericenter: number;
10
+ meanAnomaly: number;
11
+ ephemerisType: number;
12
+ classificationType: string;
13
+ noradCatId: number;
14
+ elementSetNo: number;
15
+ revAtEpoch: number;
16
+ bstar: number;
17
+ meanMotionDot: number;
18
+ meanMotionDdot: number;
19
+ }
20
+ export declare class GNSS {
21
+ static get(): Promise<GNSSResponse[]>;
22
+ private static mapResult;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export * from './airport';
2
+ export * from './atc';
3
+ export * from './atis';
4
+ export * from './charts';
5
+ export * from './git-versions';
6
+ export * from './gnss';
7
+ export * from './metar';
8
+ export * from './taf';
9
+ export * from './telex';
10
+ export * from './Hoppie';
@@ -0,0 +1,8 @@
1
+ export declare class MetarResponse {
2
+ icao: string;
3
+ source: string;
4
+ metar: string;
5
+ }
6
+ export declare class Metar {
7
+ static get(icao: string, source?: string): Promise<MetarResponse>;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare class TafResponse {
2
+ icao: string;
3
+ source: string;
4
+ taf: string;
5
+ }
6
+ export declare class Taf {
7
+ static get(icao: string, source?: string): Promise<TafResponse>;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ export declare class TelexConnection {
2
+ id: string;
3
+ isActive: boolean;
4
+ firstContact: Date;
5
+ lastContact: Date;
6
+ flight: string;
7
+ location: {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ trueAltitude: number;
12
+ heading: number;
13
+ freetextEnabled: boolean;
14
+ aircraftType: string;
15
+ origin: string;
16
+ destination: string;
17
+ }
18
+ export declare class SearchResult<T> {
19
+ fullMatch?: T;
20
+ matches: T[];
21
+ }
22
+ export declare class TelexMessage {
23
+ id: string;
24
+ createdAt: Date;
25
+ received: boolean;
26
+ message: string;
27
+ isProfane: boolean;
28
+ from: TelexConnection;
29
+ to?: TelexConnection;
30
+ }
31
+ export declare class Token {
32
+ accessToken: string;
33
+ connection: string;
34
+ flight: string;
35
+ }
36
+ export declare class AircraftStatus {
37
+ location: {
38
+ long: number;
39
+ lat: number;
40
+ };
41
+ trueAltitude: number;
42
+ heading: number;
43
+ origin: string;
44
+ destination: string;
45
+ freetextEnabled: boolean;
46
+ flight: string;
47
+ aircraftType: string;
48
+ }
49
+ export declare class Paginated<T> {
50
+ results: T[];
51
+ count: number;
52
+ total: number;
53
+ }
54
+ export declare class Bounds {
55
+ north: number;
56
+ east: number;
57
+ south: number;
58
+ west: number;
59
+ }
60
+ export declare type StageCallback = (flights: TelexConnection[]) => void;
61
+ export declare class TelexNotConnectedError extends Error {
62
+ constructor();
63
+ }
64
+ export declare class Telex {
65
+ private static accessToken;
66
+ static connect(status: AircraftStatus): Promise<Token>;
67
+ static update(status: AircraftStatus): Promise<TelexConnection>;
68
+ static disconnect(): Promise<void>;
69
+ static sendMessage(recipientFlight: string, message: string): Promise<TelexMessage>;
70
+ static fetchMessages(): Promise<TelexMessage[]>;
71
+ static fetchConnections(skip?: number, take?: number, bounds?: Bounds): Promise<Paginated<TelexConnection>>;
72
+ static fetchAllConnections(bounds?: Bounds, stageCallback?: StageCallback): Promise<TelexConnection[]>;
73
+ static fetchConnection(id: string): Promise<TelexConnection>;
74
+ static findConnections(flightNumber: string): Promise<SearchResult<TelexConnection>>;
75
+ static countConnections(): Promise<number>;
76
+ private static buildBody;
77
+ private static buildToken;
78
+ private static connectionOrThrow;
79
+ private static mapConnection;
80
+ private static mapMessage;
81
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare class NXApi {
2
+ static url: URL;
3
+ }
4
+ export * from './apis';