@aeroswarm/client 0.1.12 → 0.1.14
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 +73 -18
- package/dist/index-ByNBpjNk.d.ts +75 -0
- package/dist/index-CyxVoJXL.d.ts +733 -0
- package/dist/index.d.ts +18 -688
- package/dist/index.js +436 -16
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +24 -3
- package/dist/react/index.js +439 -35
- package/dist/react/index.js.map +1 -1
- package/dist/sdk/index.d.ts +1 -2
- package/dist/sdk/index.js +96 -12
- package/dist/sdk/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import * as _aeroswarm_core_types from '@aeroswarm/core/types';
|
|
2
|
+
import { FlightPlan, CurrentTrack, SourceStatus, AeroConnectionStatus, AeroRecoverableError, Bbox } from '@aeroswarm/core/types';
|
|
3
|
+
import * as _trpc_client from '@trpc/client';
|
|
4
|
+
|
|
5
|
+
interface SourceRow {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
sourceToken: string;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
/** Airport this source's data belongs to. When set, anything that
|
|
12
|
+
* authenticates with this source's token (WS live/replay, tRPC calls)
|
|
13
|
+
* is scoped to this airport automatically. */
|
|
14
|
+
airportId?: string | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A flight plan plus the live track it currently correlates with (null = not on radar). */
|
|
18
|
+
type FlightPlanRow = FlightPlan & {
|
|
19
|
+
trackId: string | null;
|
|
20
|
+
};
|
|
21
|
+
/** One raw AFTN message from the live log (newest first, capped by the service). */
|
|
22
|
+
interface AftnMessageRow {
|
|
23
|
+
id: string;
|
|
24
|
+
receivedAt: number;
|
|
25
|
+
airportId: string | null;
|
|
26
|
+
feedId: string | null;
|
|
27
|
+
callsign: string | null;
|
|
28
|
+
type: string;
|
|
29
|
+
adep?: string;
|
|
30
|
+
ades?: string;
|
|
31
|
+
raw: string;
|
|
32
|
+
}
|
|
33
|
+
declare class AeroRestClient {
|
|
34
|
+
private readonly endpoint;
|
|
35
|
+
private readonly token;
|
|
36
|
+
constructor(endpoint: string, token: string);
|
|
37
|
+
private req;
|
|
38
|
+
createSource(body: Record<string, unknown>): Promise<{
|
|
39
|
+
ok: boolean;
|
|
40
|
+
data: {
|
|
41
|
+
sourceId: string;
|
|
42
|
+
sourceToken: string;
|
|
43
|
+
airportId?: string | null;
|
|
44
|
+
};
|
|
45
|
+
}>;
|
|
46
|
+
listSources(): Promise<{
|
|
47
|
+
ok: boolean;
|
|
48
|
+
data: {
|
|
49
|
+
sources: SourceRow[];
|
|
50
|
+
};
|
|
51
|
+
}>;
|
|
52
|
+
deleteSource(id: string): Promise<{
|
|
53
|
+
ok: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
createWebhook(body: {
|
|
56
|
+
url: string;
|
|
57
|
+
events: string[];
|
|
58
|
+
secret?: string;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
webhookId: string;
|
|
61
|
+
}>;
|
|
62
|
+
getTracksCurrent(params?: {
|
|
63
|
+
bbox?: [number, number, number, number];
|
|
64
|
+
minConfidence?: number;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
tracks: unknown[];
|
|
67
|
+
count: number;
|
|
68
|
+
}>;
|
|
69
|
+
/** Flight plans received from AFTN feeds (FPL/CHG/DLA/DEP/ARR/CNL folded per flight). */
|
|
70
|
+
listFlightPlans(params?: {
|
|
71
|
+
airportId?: string;
|
|
72
|
+
status?: string;
|
|
73
|
+
callsign?: string;
|
|
74
|
+
limit?: number;
|
|
75
|
+
}): Promise<{
|
|
76
|
+
ok: boolean;
|
|
77
|
+
data: {
|
|
78
|
+
flightPlans: FlightPlanRow[];
|
|
79
|
+
count: number;
|
|
80
|
+
};
|
|
81
|
+
}>;
|
|
82
|
+
getFlightPlan(id: string): Promise<{
|
|
83
|
+
ok: boolean;
|
|
84
|
+
data: {
|
|
85
|
+
flightPlan: FlightPlan;
|
|
86
|
+
};
|
|
87
|
+
}>;
|
|
88
|
+
/** Raw AFTN messages (every parsed ATS message, newest first — the input
|
|
89
|
+
* side of the flight-plan pipeline). */
|
|
90
|
+
listAftnMessages(params?: {
|
|
91
|
+
airportId?: string;
|
|
92
|
+
limit?: number;
|
|
93
|
+
}): Promise<{
|
|
94
|
+
ok: boolean;
|
|
95
|
+
data: {
|
|
96
|
+
messages: AftnMessageRow[];
|
|
97
|
+
count: number;
|
|
98
|
+
};
|
|
99
|
+
}>;
|
|
100
|
+
health(): Promise<{
|
|
101
|
+
status: string;
|
|
102
|
+
}>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type WsEncoding = "json" | "msgpack";
|
|
106
|
+
interface SubscribeOptions {
|
|
107
|
+
bbox?: [number, number, number, number];
|
|
108
|
+
/** Scope the stream to tracks stamped with this ICAO airport code, e.g. "WARR" */
|
|
109
|
+
airportId?: string;
|
|
110
|
+
source?: "fused" | "normalized";
|
|
111
|
+
minConfidence?: number;
|
|
112
|
+
maxTracks?: number;
|
|
113
|
+
mode?: "delta" | "full";
|
|
114
|
+
maxUpdateHz?: number;
|
|
115
|
+
encoding?: WsEncoding;
|
|
116
|
+
staleAfterMs?: number;
|
|
117
|
+
removeAfterMs?: number;
|
|
118
|
+
}
|
|
119
|
+
/** Envelope fields that ride along with a track message. */
|
|
120
|
+
interface StreamMeta {
|
|
121
|
+
/** The server's clock when it sent the message (ms). Lets a client align its own clock with `lastSeenAt`. */
|
|
122
|
+
serverTime: number;
|
|
123
|
+
seq: number;
|
|
124
|
+
}
|
|
125
|
+
interface TrackCallbacks {
|
|
126
|
+
onTrackUpdate?: (track: CurrentTrack, meta?: StreamMeta) => void;
|
|
127
|
+
onTrackRemoved?: (event: {
|
|
128
|
+
trackId: string;
|
|
129
|
+
reason: string;
|
|
130
|
+
}) => void;
|
|
131
|
+
onSnapshot?: (tracks: CurrentTrack[], meta?: StreamMeta) => void;
|
|
132
|
+
onSourceStatus?: (event: {
|
|
133
|
+
sourceId: string;
|
|
134
|
+
status: SourceStatus;
|
|
135
|
+
}) => void;
|
|
136
|
+
onStatusChange?: (status: AeroConnectionStatus) => void;
|
|
137
|
+
onError?: (err: AeroRecoverableError) => void;
|
|
138
|
+
onDegraded?: (reason: string) => void;
|
|
139
|
+
}
|
|
140
|
+
declare class AeroWsClient {
|
|
141
|
+
private readonly url;
|
|
142
|
+
private readonly token;
|
|
143
|
+
private readonly maxReconnectDelay;
|
|
144
|
+
private readonly heartbeatTimeoutMs;
|
|
145
|
+
private ws;
|
|
146
|
+
private attempt;
|
|
147
|
+
private stopped;
|
|
148
|
+
private lastSubscribe;
|
|
149
|
+
private callbacks;
|
|
150
|
+
private lastSeq;
|
|
151
|
+
private lastHeartbeat;
|
|
152
|
+
private heartbeatTimer;
|
|
153
|
+
private reconnectTimer;
|
|
154
|
+
private status;
|
|
155
|
+
constructor(url: string, token: string, maxReconnectDelay?: number, heartbeatTimeoutMs?: number);
|
|
156
|
+
connect(opts: SubscribeOptions, callbacks: TrackCallbacks): void;
|
|
157
|
+
updateFilter(opts: Partial<Pick<SubscribeOptions, 'bbox' | 'minConfidence' | 'maxUpdateHz' | 'maxTracks'>>): void;
|
|
158
|
+
disconnect(): void;
|
|
159
|
+
/**
|
|
160
|
+
* Force a fresh connection now, skipping any backoff wait. Re-subscribes with
|
|
161
|
+
* the last `connect()` options (the server then sends a new snapshot).
|
|
162
|
+
* Also resumes after `disconnect()`. No-op if `connect()` was never called.
|
|
163
|
+
* Returns false in that no-op case.
|
|
164
|
+
*/
|
|
165
|
+
reconnect(): boolean;
|
|
166
|
+
getStatus(): AeroConnectionStatus;
|
|
167
|
+
private _setStatus;
|
|
168
|
+
/** Close the current socket without letting its onclose schedule a reconnect. */
|
|
169
|
+
private _dropSocket;
|
|
170
|
+
private _connect;
|
|
171
|
+
private _handleRaw;
|
|
172
|
+
private _requestSnapshot;
|
|
173
|
+
private _resetHeartbeatTimer;
|
|
174
|
+
private _clearHeartbeatTimer;
|
|
175
|
+
private _scheduleReconnect;
|
|
176
|
+
private _clearReconnectTimer;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Server-paced WS replay client for `/ws/tracks/replay`.
|
|
181
|
+
*
|
|
182
|
+
* The server streams historical `fused_tracks` events at `speed`× real
|
|
183
|
+
* time (paced server-side against a wall-clock anchor), so the client
|
|
184
|
+
* receives replay frames exactly like live traffic: a `snapshot`
|
|
185
|
+
* envelope with the state at `from`, then `track.updated` /
|
|
186
|
+
* `track.removed` envelopes, plus `replay.progress` heartbeats and a
|
|
187
|
+
* final `replay.done`.
|
|
188
|
+
*
|
|
189
|
+
* The wire protocol is plain JSON, so consumers that don't use this SDK
|
|
190
|
+
* can speak it manually:
|
|
191
|
+
*
|
|
192
|
+
* → connect wss://host/ws/tracks/replay?token=TOKEN[&airportId=WARR][&sessionId=ID]
|
|
193
|
+
* → send { "type": "replay.start", "from": ISO, "to": ISO, "speed": 2 }
|
|
194
|
+
* → send { "type": "replay.pause" } · { "type": "replay.resume" }
|
|
195
|
+
* → send { "type": "replay.seek", "at": ISO }
|
|
196
|
+
* → send { "type": "replay.stop" }
|
|
197
|
+
* ← recv { "type": "snapshot", "payload": { "tracks": [...], "sessionId": ID } }
|
|
198
|
+
* ← recv { "type": "track.updated", "payload": { "track": {...} } }
|
|
199
|
+
* ← recv { "type": "track.removed", "payload": { "trackId": ID, "reason": "dropped" } }
|
|
200
|
+
* ← recv { "type": "replay.progress", "payload": { "at": ISO, "pct": 0-100, "sessionId": ID } }
|
|
201
|
+
* ← recv { "type": "replay.done", "payload": { "sessionId": ID } }
|
|
202
|
+
*
|
|
203
|
+
* Reconnecting with the same `sessionId` (within 1 h) resumes a replay
|
|
204
|
+
* from its last saved position.
|
|
205
|
+
*/
|
|
206
|
+
interface ReplayStreamOptions {
|
|
207
|
+
from: Date | string;
|
|
208
|
+
to: Date | string;
|
|
209
|
+
/** Playback speed multiplier (1 = realtime). Default 1. */
|
|
210
|
+
speed?: number;
|
|
211
|
+
/** Which airport to replay. Federated airports (with a historyEndpoint)
|
|
212
|
+
* are resolved by AeroSwarm.replay.stream to their own backend; against
|
|
213
|
+
* AeroSwarm's own endpoint this is a row filter on the local DB. */
|
|
214
|
+
airportId?: string;
|
|
215
|
+
/** Resume a previous session instead of starting fresh. */
|
|
216
|
+
sessionId?: string;
|
|
217
|
+
}
|
|
218
|
+
interface ReplayProgress {
|
|
219
|
+
/** Replay-time position (ISO timestamp) */
|
|
220
|
+
at: string;
|
|
221
|
+
/** 0–100 within the requested range */
|
|
222
|
+
pct: number;
|
|
223
|
+
sessionId: string;
|
|
224
|
+
}
|
|
225
|
+
interface ReplayCallbacks {
|
|
226
|
+
/** State at `from` — arrives once per start/seek. */
|
|
227
|
+
onSnapshot?: (tracks: CurrentTrack[], sessionId: string) => void;
|
|
228
|
+
onTrackUpdate?: (track: CurrentTrack) => void;
|
|
229
|
+
onTrackRemoved?: (event: {
|
|
230
|
+
trackId: string;
|
|
231
|
+
reason: string;
|
|
232
|
+
}) => void;
|
|
233
|
+
onProgress?: (progress: ReplayProgress) => void;
|
|
234
|
+
onDone?: (sessionId: string) => void;
|
|
235
|
+
onError?: (error: Error) => void;
|
|
236
|
+
}
|
|
237
|
+
interface ReplayHandle {
|
|
238
|
+
readonly sessionId: string | null;
|
|
239
|
+
pause(): void;
|
|
240
|
+
resume(): void;
|
|
241
|
+
/** Jump to a replay-time position; the server restarts the paced stream there. */
|
|
242
|
+
seek(at: Date | string): void;
|
|
243
|
+
/** End the replay and close the socket. */
|
|
244
|
+
stop(): void;
|
|
245
|
+
}
|
|
246
|
+
declare class AeroReplayClient {
|
|
247
|
+
private readonly wsBase;
|
|
248
|
+
private readonly token;
|
|
249
|
+
/** Default "/ws/tracks/replay" (AeroSwarm's own endpoint). A federated
|
|
250
|
+
* airport backend running @aeroswarm/replay-server's default mount
|
|
251
|
+
* uses "/replay" instead — see AeroSwarm.replay.stream's endpoint
|
|
252
|
+
* resolution. */
|
|
253
|
+
private readonly wsPath;
|
|
254
|
+
constructor(wsBase: string, token: string,
|
|
255
|
+
/** Default "/ws/tracks/replay" (AeroSwarm's own endpoint). A federated
|
|
256
|
+
* airport backend running @aeroswarm/replay-server's default mount
|
|
257
|
+
* uses "/replay" instead — see AeroSwarm.replay.stream's endpoint
|
|
258
|
+
* resolution. */
|
|
259
|
+
wsPath?: string);
|
|
260
|
+
/** Open a replay stream. Returns a handle for transport control. */
|
|
261
|
+
stream(opts: ReplayStreamOptions, callbacks: ReplayCallbacks): ReplayHandle;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
declare function createAeroTrpcClient(endpoint: string, token: string): _trpc_client.TRPCClient<any>;
|
|
265
|
+
type AeroTrpcClient = ReturnType<typeof createAeroTrpcClient>;
|
|
266
|
+
|
|
267
|
+
declare class AeroGraphQLClient {
|
|
268
|
+
private readonly endpoint;
|
|
269
|
+
private readonly token;
|
|
270
|
+
constructor(endpoint: string, token: string);
|
|
271
|
+
query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Callsign-label category of a track, in priority order:
|
|
276
|
+
* LOST (track status "lost") > GROUND_VEHICLE > ARRIVAL / DEPARTURE > UNKNOWN.
|
|
277
|
+
* ARRIVAL/DEPARTURE come from the correlated flight plan, relative to the
|
|
278
|
+
* track's airport (`track.flightPlan.phase`).
|
|
279
|
+
*/
|
|
280
|
+
type LabelCategory = "ARRIVAL" | "DEPARTURE" | "GROUND_VEHICLE" | "LOST" | "UNKNOWN";
|
|
281
|
+
declare const LABEL_COLORS: Readonly<Record<LabelCategory, string>>;
|
|
282
|
+
/** A track as the client exposes it: the server's track plus derived label fields. */
|
|
283
|
+
type LabeledTrack = CurrentTrack & {
|
|
284
|
+
labelCategory: LabelCategory;
|
|
285
|
+
labelColor: string;
|
|
286
|
+
};
|
|
287
|
+
declare function getLabelCategory(track: Pick<CurrentTrack, "status" | "targetType" | "flightPlan">): LabelCategory;
|
|
288
|
+
/**
|
|
289
|
+
* Attach `labelCategory` / `labelColor`. Always call this on the *merged*
|
|
290
|
+
* track: a delta without `flightPlan` must not downgrade a known category
|
|
291
|
+
* (that is what makes labels flicker).
|
|
292
|
+
*/
|
|
293
|
+
declare function withLabel(track: CurrentTrack): LabeledTrack;
|
|
294
|
+
|
|
295
|
+
type Listener<T> = (payload: T) => void;
|
|
296
|
+
declare class TypedEmitter<T extends Record<string, unknown>> {
|
|
297
|
+
private listeners;
|
|
298
|
+
on<K extends keyof T>(event: K, fn: Listener<T[K]>): () => void;
|
|
299
|
+
emit<K extends keyof T>(event: K, payload: T[K]): void;
|
|
300
|
+
}
|
|
301
|
+
declare class TrackCache extends TypedEmitter<{
|
|
302
|
+
update: LabeledTrack;
|
|
303
|
+
removed: {
|
|
304
|
+
trackId: string;
|
|
305
|
+
};
|
|
306
|
+
snapshot: LabeledTrack[];
|
|
307
|
+
status: AeroConnectionStatus;
|
|
308
|
+
degraded: {
|
|
309
|
+
reason: string;
|
|
310
|
+
};
|
|
311
|
+
error: AeroRecoverableError;
|
|
312
|
+
"source.status": {
|
|
313
|
+
sourceId: string;
|
|
314
|
+
status: SourceStatus;
|
|
315
|
+
};
|
|
316
|
+
}> {
|
|
317
|
+
private tracks;
|
|
318
|
+
/** Merges into the cached track and returns the labeled result. A "lost"
|
|
319
|
+
* track is evicted from the cache but still returned (labelCategory LOST). */
|
|
320
|
+
applyUpdate(track: CurrentTrack): LabeledTrack;
|
|
321
|
+
applyRemoved(ev: {
|
|
322
|
+
trackId: string;
|
|
323
|
+
}): void;
|
|
324
|
+
applySnapshot(tracks: CurrentTrack[]): LabeledTrack[];
|
|
325
|
+
getAll(): LabeledTrack[];
|
|
326
|
+
get(id: string): LabeledTrack | undefined;
|
|
327
|
+
get size(): number;
|
|
328
|
+
clear(): void;
|
|
329
|
+
getRenderable(): (LabeledTrack & {
|
|
330
|
+
lat: number;
|
|
331
|
+
lon: number;
|
|
332
|
+
})[];
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Mirrors `API_ERROR_CODES` in @aeroswarm/core/api. A server may send codes this client does not know. */
|
|
336
|
+
type ApiErrorCode = "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "BAD_REQUEST" | "CONFLICT" | "RATE_LIMITED" | "UNAVAILABLE" | "INTERNAL";
|
|
337
|
+
/** The code for an HTTP status when the server sent none. */
|
|
338
|
+
declare function codeForStatus(status: number): ApiErrorCode;
|
|
339
|
+
interface ApiErrorInit {
|
|
340
|
+
status: number;
|
|
341
|
+
code: string;
|
|
342
|
+
message: string;
|
|
343
|
+
recoverable: boolean;
|
|
344
|
+
details?: unknown;
|
|
345
|
+
}
|
|
346
|
+
/** A REST call failed. `code` is stable and meant for `switch`; `message` is for people. */
|
|
347
|
+
declare class AeroApiError extends Error {
|
|
348
|
+
readonly status: number;
|
|
349
|
+
readonly code: string;
|
|
350
|
+
/** Retrying later may succeed (rate limit, server busy or failing). */
|
|
351
|
+
readonly recoverable: boolean;
|
|
352
|
+
readonly details?: unknown;
|
|
353
|
+
constructor(init: ApiErrorInit);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* The parsed JSON of a response, untouched. Throws `AeroApiError` for a non-2xx status
|
|
357
|
+
* and for a 2xx that carries `{ ok: false }`. For endpoints whose callers read the
|
|
358
|
+
* envelope themselves (`r.data.x`).
|
|
359
|
+
*/
|
|
360
|
+
declare function readApiBody(res: Response, label?: string): Promise<unknown>;
|
|
361
|
+
/**
|
|
362
|
+
* The data of a response: unwrapped from `{ ok, data }`, or the body as it is for servers
|
|
363
|
+
* that answer with bare data. Throws `AeroApiError` on failure.
|
|
364
|
+
*/
|
|
365
|
+
declare function parseApiResponse<T>(res: Response, label?: string): Promise<T>;
|
|
366
|
+
|
|
367
|
+
interface AeroSwarmOptions {
|
|
368
|
+
endpoint: string;
|
|
369
|
+
token: string;
|
|
370
|
+
wsEndpoint?: string;
|
|
371
|
+
reconnect?: boolean;
|
|
372
|
+
maxReconnectDelay?: number;
|
|
373
|
+
encoding?: "json" | "msgpack";
|
|
374
|
+
staleAfterMs?: number;
|
|
375
|
+
removeAfterMs?: number;
|
|
376
|
+
onTokenExpired?: () => Promise<string>;
|
|
377
|
+
}
|
|
378
|
+
/** Live callbacks: tracks arrive merged with previous state and carry
|
|
379
|
+
* `status`, `labelCategory` and `labelColor`. */
|
|
380
|
+
interface LiveTrackCallbacks extends Omit<TrackCallbacks, "onTrackUpdate" | "onSnapshot"> {
|
|
381
|
+
/** `meta.serverTime` is the server's clock; pass it to `createTrackMotion().update()`. */
|
|
382
|
+
onTrackUpdate?: (track: LabeledTrack, meta?: StreamMeta) => void;
|
|
383
|
+
onSnapshot?: (tracks: LabeledTrack[], meta?: StreamMeta) => void;
|
|
384
|
+
}
|
|
385
|
+
interface UseAeroTracksResult {
|
|
386
|
+
tracks: CurrentTrack[];
|
|
387
|
+
status: AeroConnectionStatus;
|
|
388
|
+
sourceStatus: Record<string, string>;
|
|
389
|
+
lastUpdateAt: number | null;
|
|
390
|
+
error: AeroRecoverableError | null;
|
|
391
|
+
}
|
|
392
|
+
interface TrackHistoryPoint {
|
|
393
|
+
t: number;
|
|
394
|
+
lat: number | null;
|
|
395
|
+
lon: number | null;
|
|
396
|
+
altFt: number | null;
|
|
397
|
+
speedKt: number | null;
|
|
398
|
+
headingDeg: number | null;
|
|
399
|
+
}
|
|
400
|
+
interface DayAvailability {
|
|
401
|
+
day: string;
|
|
402
|
+
eventCount: number;
|
|
403
|
+
trackCount: number;
|
|
404
|
+
firstAt: string | null;
|
|
405
|
+
lastAt: string | null;
|
|
406
|
+
}
|
|
407
|
+
declare class AeroSwarm {
|
|
408
|
+
private readonly opts;
|
|
409
|
+
readonly trpc: AeroTrpcClient;
|
|
410
|
+
readonly rest: AeroRestClient;
|
|
411
|
+
readonly graphql: AeroGraphQLClient;
|
|
412
|
+
readonly cache: TrackCache;
|
|
413
|
+
private readonly wsClient;
|
|
414
|
+
private _status;
|
|
415
|
+
private _lastUpdateAt;
|
|
416
|
+
private _error;
|
|
417
|
+
private _sourceStatus;
|
|
418
|
+
private airportsCache;
|
|
419
|
+
private static readonly AIRPORTS_CACHE_TTL_MS;
|
|
420
|
+
/** Resolves which base URL (if any) should serve a federated call.
|
|
421
|
+
* Returns null to mean "use AeroSwarm's own endpoint" — the normal,
|
|
422
|
+
* unfederated path, which is also what a lookup failure falls back to
|
|
423
|
+
* (a broken airports.list() call must never brick replay/history for
|
|
424
|
+
* everyone else). */
|
|
425
|
+
private resolveHistoryEndpoint;
|
|
426
|
+
private federatedFetch;
|
|
427
|
+
constructor(opts: AeroSwarmOptions);
|
|
428
|
+
readonly tracks: {
|
|
429
|
+
subscribe: (opts: SubscribeOptions, callbacks: LiveTrackCallbacks) => (() => void);
|
|
430
|
+
updateFilter: (opts: Partial<SubscribeOptions>) => void;
|
|
431
|
+
/** Drop the live socket and reconnect immediately (no backoff wait),
|
|
432
|
+
* re-subscribing with the last options. Returns false if nothing has
|
|
433
|
+
* been subscribed yet. */
|
|
434
|
+
reconnect: () => boolean;
|
|
435
|
+
stream: (opts: SubscribeOptions) => AsyncIterable<LabeledTrack>;
|
|
436
|
+
snapshot: (input?: {
|
|
437
|
+
airportId?: string;
|
|
438
|
+
bbox?: Bbox;
|
|
439
|
+
source?: "fused" | "normalized";
|
|
440
|
+
minConfidence?: number;
|
|
441
|
+
limit?: number;
|
|
442
|
+
offset?: number;
|
|
443
|
+
}) => any;
|
|
444
|
+
/** Persisted position history for one track. If the airport has a
|
|
445
|
+
* `historyEndpoint` (or `endpoint` is passed explicitly), this calls
|
|
446
|
+
* that backend's `@aeroswarm/replay-server` instead of AeroSwarm's
|
|
447
|
+
* own local database — see docs/development/federation/003-*.md. */
|
|
448
|
+
history: (input: {
|
|
449
|
+
trackId: string;
|
|
450
|
+
airportId?: string;
|
|
451
|
+
limit?: number;
|
|
452
|
+
endpoint?: string;
|
|
453
|
+
}) => Promise<TrackHistoryPoint[]>;
|
|
454
|
+
};
|
|
455
|
+
/** Flight plans received from AFTN feeds. Live tracks that correlate with a
|
|
456
|
+
* plan (Mode-S address, else callsign) also carry `track.flightPlan`. */
|
|
457
|
+
readonly flightPlans: {
|
|
458
|
+
list: (input?: {
|
|
459
|
+
airportId?: string;
|
|
460
|
+
status?: string;
|
|
461
|
+
callsign?: string;
|
|
462
|
+
limit?: number;
|
|
463
|
+
}) => Promise<FlightPlanRow[]>;
|
|
464
|
+
get: (id: string) => Promise<_aeroswarm_core_types.FlightPlan>;
|
|
465
|
+
};
|
|
466
|
+
/** Raw AFTN/ATS messages received by AFTN feeds — the input side of the
|
|
467
|
+
* flight-plan pipeline (newest first, capped by the service). */
|
|
468
|
+
readonly aftn: {
|
|
469
|
+
messages: (input?: {
|
|
470
|
+
airportId?: string;
|
|
471
|
+
limit?: number;
|
|
472
|
+
}) => Promise<AftnMessageRow[]>;
|
|
473
|
+
};
|
|
474
|
+
readonly sources: {
|
|
475
|
+
/** Registers a source and returns its token, tied to `airportId` — a
|
|
476
|
+
* source is a sensor physically at one airport, so this is required.
|
|
477
|
+
* Anything that later authenticates with the returned token (WS
|
|
478
|
+
* live/replay, tRPC calls) is scoped to that airport automatically,
|
|
479
|
+
* with no need to keep passing `airportId` on every subsequent call.
|
|
480
|
+
* For access spanning multiple airports, use the viewer/dashboard
|
|
481
|
+
* token instead — it's never auto-scoped. */
|
|
482
|
+
create: (body: {
|
|
483
|
+
name: string;
|
|
484
|
+
airportId: string;
|
|
485
|
+
sourceType?: string;
|
|
486
|
+
location?: {
|
|
487
|
+
lat: number;
|
|
488
|
+
lon: number;
|
|
489
|
+
};
|
|
490
|
+
config?: Record<string, unknown>;
|
|
491
|
+
}) => Promise<{
|
|
492
|
+
ok: boolean;
|
|
493
|
+
data: {
|
|
494
|
+
sourceId: string;
|
|
495
|
+
sourceToken: string;
|
|
496
|
+
airportId?: string | null;
|
|
497
|
+
};
|
|
498
|
+
}>;
|
|
499
|
+
health: (sourceId: string) => any;
|
|
500
|
+
list: (input?: {
|
|
501
|
+
airportId?: string;
|
|
502
|
+
}) => any;
|
|
503
|
+
/** Reassigning `airportId` (including to `null` to clear it) re-caches
|
|
504
|
+
* the source's token immediately, so the new scoping takes effect
|
|
505
|
+
* without waiting out the token cache's TTL. */
|
|
506
|
+
update: (input: {
|
|
507
|
+
id: string;
|
|
508
|
+
name?: string;
|
|
509
|
+
airportId?: string | null;
|
|
510
|
+
location?: {
|
|
511
|
+
lat: number;
|
|
512
|
+
lon: number;
|
|
513
|
+
};
|
|
514
|
+
config?: Record<string, unknown>;
|
|
515
|
+
}) => any;
|
|
516
|
+
delete: (id: string) => any;
|
|
517
|
+
};
|
|
518
|
+
/** Airport registry (multi-airport tenancy). */
|
|
519
|
+
readonly airports: {
|
|
520
|
+
list: () => Promise<{
|
|
521
|
+
airports: {
|
|
522
|
+
id: string;
|
|
523
|
+
name: string;
|
|
524
|
+
city: string | null;
|
|
525
|
+
lat: number;
|
|
526
|
+
lon: number;
|
|
527
|
+
bbox: [number, number, number, number];
|
|
528
|
+
timezone: string;
|
|
529
|
+
/** Set = this airport serves its own replay/history (federated —
|
|
530
|
+
* see docs/development/federation/003-*.md); `replay.*`/
|
|
531
|
+
* `tracks.history` calls for it connect there directly instead of
|
|
532
|
+
* AeroSwarm's own endpoint. null = AeroSwarm serves it (default). */
|
|
533
|
+
historyEndpoint: string | null;
|
|
534
|
+
}[];
|
|
535
|
+
}>;
|
|
536
|
+
create: (input: {
|
|
537
|
+
id: string;
|
|
538
|
+
name: string;
|
|
539
|
+
city?: string;
|
|
540
|
+
lat: number;
|
|
541
|
+
lon: number;
|
|
542
|
+
bbox: [number, number, number, number];
|
|
543
|
+
timezone?: string;
|
|
544
|
+
historyEndpoint?: string;
|
|
545
|
+
}) => Promise<{
|
|
546
|
+
ok: boolean;
|
|
547
|
+
id: string;
|
|
548
|
+
}>;
|
|
549
|
+
update: (input: {
|
|
550
|
+
id: string;
|
|
551
|
+
name?: string;
|
|
552
|
+
city?: string;
|
|
553
|
+
lat?: number;
|
|
554
|
+
lon?: number;
|
|
555
|
+
bbox?: [number, number, number, number];
|
|
556
|
+
timezone?: string;
|
|
557
|
+
/** null clears it (reverts to AeroSwarm's own replay); omit to leave unchanged. */
|
|
558
|
+
historyEndpoint?: string | null;
|
|
559
|
+
}) => Promise<{
|
|
560
|
+
ok: boolean;
|
|
561
|
+
}>;
|
|
562
|
+
delete: (input: {
|
|
563
|
+
id: string;
|
|
564
|
+
}) => Promise<{
|
|
565
|
+
ok: boolean;
|
|
566
|
+
}>;
|
|
567
|
+
/** Surface geometry (runway/taxiway/apron GeoJSON) for the map. */
|
|
568
|
+
surface: (input: {
|
|
569
|
+
id: string;
|
|
570
|
+
}) => Promise<{
|
|
571
|
+
surface: unknown | null;
|
|
572
|
+
}>;
|
|
573
|
+
setSurface: (input: {
|
|
574
|
+
id: string;
|
|
575
|
+
surface: Record<string, unknown>;
|
|
576
|
+
}) => Promise<{
|
|
577
|
+
ok: boolean;
|
|
578
|
+
}>;
|
|
579
|
+
};
|
|
580
|
+
readonly replay: {
|
|
581
|
+
/** Data-availability calendar: which days have recorded tracks.
|
|
582
|
+
* Use this to populate/validate replay date pickers — days not in
|
|
583
|
+
* the list have no data. Federates to the airport's own backend when
|
|
584
|
+
* it has a `historyEndpoint` (or `endpoint` is passed explicitly) —
|
|
585
|
+
* see docs/development/federation/003-*.md. */
|
|
586
|
+
days: (input?: {
|
|
587
|
+
airportId?: string;
|
|
588
|
+
lookbackDays?: number;
|
|
589
|
+
endpoint?: string;
|
|
590
|
+
}) => Promise<{
|
|
591
|
+
days: DayAvailability[];
|
|
592
|
+
}>;
|
|
593
|
+
range: (input: {
|
|
594
|
+
from: string;
|
|
595
|
+
to: string;
|
|
596
|
+
airportId?: string;
|
|
597
|
+
endpoint?: string;
|
|
598
|
+
}) => Promise<{
|
|
599
|
+
earliest: string | null;
|
|
600
|
+
latest: string | null;
|
|
601
|
+
eventCount: number;
|
|
602
|
+
trackCount: number;
|
|
603
|
+
from: string;
|
|
604
|
+
to: string;
|
|
605
|
+
}>;
|
|
606
|
+
/** Server-paced WS playback: streams historical tracks at `speed`× in
|
|
607
|
+
* the same envelope format as the live stream. Returns a transport
|
|
608
|
+
* handle (pause/resume/seek/stop) — a Promise, since resolving which
|
|
609
|
+
* backend serves this airport (see docs/development/federation/003-*.md)
|
|
610
|
+
* is async. See `AeroReplayClient` for the raw wire protocol if you
|
|
611
|
+
* want to speak WS manually instead. */
|
|
612
|
+
stream: (opts: ReplayStreamOptions & {
|
|
613
|
+
endpoint?: string;
|
|
614
|
+
}, callbacks: ReplayCallbacks) => Promise<ReplayHandle>;
|
|
615
|
+
};
|
|
616
|
+
/** Movement analytics: takeoffs/landings per hour + peak hour, recorded
|
|
617
|
+
* by the pipeline's movement detector. */
|
|
618
|
+
readonly analytics: {
|
|
619
|
+
movements: (input?: {
|
|
620
|
+
airportId?: string;
|
|
621
|
+
day?: string;
|
|
622
|
+
}) => Promise<{
|
|
623
|
+
day: string;
|
|
624
|
+
hours: {
|
|
625
|
+
hour: string;
|
|
626
|
+
takeoffs: number;
|
|
627
|
+
landings: number;
|
|
628
|
+
}[];
|
|
629
|
+
totals: {
|
|
630
|
+
takeoffs: number;
|
|
631
|
+
landings: number;
|
|
632
|
+
};
|
|
633
|
+
peak: {
|
|
634
|
+
hour: string;
|
|
635
|
+
count: number;
|
|
636
|
+
} | null;
|
|
637
|
+
}>;
|
|
638
|
+
};
|
|
639
|
+
/** Route conformance: pre-defined ground routes + live track clearances.
|
|
640
|
+
* Assign a route to a track and the safety engine can detect when it
|
|
641
|
+
* strays beyond the route's corridor. */
|
|
642
|
+
readonly routes: {
|
|
643
|
+
list: (input?: {
|
|
644
|
+
airportId?: string;
|
|
645
|
+
}) => Promise<{
|
|
646
|
+
routes: {
|
|
647
|
+
routeId: string;
|
|
648
|
+
airportId: string;
|
|
649
|
+
name: string;
|
|
650
|
+
kind: string;
|
|
651
|
+
points: [number, number][];
|
|
652
|
+
maxDeviationM: number;
|
|
653
|
+
enabled: boolean;
|
|
654
|
+
}[];
|
|
655
|
+
}>;
|
|
656
|
+
create: (input: {
|
|
657
|
+
airportId: string;
|
|
658
|
+
name: string;
|
|
659
|
+
kind?: "taxi" | "departure" | "arrival";
|
|
660
|
+
points: [number, number][];
|
|
661
|
+
maxDeviationM?: number;
|
|
662
|
+
}) => Promise<{
|
|
663
|
+
id: string;
|
|
664
|
+
}>;
|
|
665
|
+
delete: (input: {
|
|
666
|
+
id: string;
|
|
667
|
+
}) => Promise<{
|
|
668
|
+
ok: boolean;
|
|
669
|
+
}>;
|
|
670
|
+
assign: (input: {
|
|
671
|
+
trackId: string;
|
|
672
|
+
routeId: string;
|
|
673
|
+
}) => Promise<{
|
|
674
|
+
ok: boolean;
|
|
675
|
+
}>;
|
|
676
|
+
unassign: (input: {
|
|
677
|
+
trackId: string;
|
|
678
|
+
}) => Promise<{
|
|
679
|
+
ok: boolean;
|
|
680
|
+
}>;
|
|
681
|
+
assignments: () => Promise<{
|
|
682
|
+
assignments: {
|
|
683
|
+
trackId: string;
|
|
684
|
+
routeId: string;
|
|
685
|
+
assignedAt: number;
|
|
686
|
+
}[];
|
|
687
|
+
}>;
|
|
688
|
+
};
|
|
689
|
+
readonly webhooks: {
|
|
690
|
+
list: () => any;
|
|
691
|
+
create: (body: {
|
|
692
|
+
url: string;
|
|
693
|
+
events: string[];
|
|
694
|
+
secret?: string;
|
|
695
|
+
}) => Promise<{
|
|
696
|
+
ok: boolean;
|
|
697
|
+
webhookId: string;
|
|
698
|
+
}>;
|
|
699
|
+
delete: (input: {
|
|
700
|
+
id: string;
|
|
701
|
+
}) => any;
|
|
702
|
+
};
|
|
703
|
+
readonly system: {
|
|
704
|
+
stats: () => any;
|
|
705
|
+
infraHealth: () => any;
|
|
706
|
+
ingestHistory: () => any;
|
|
707
|
+
getConfig: () => Promise<{
|
|
708
|
+
key: string;
|
|
709
|
+
value: string;
|
|
710
|
+
updatedAt: string;
|
|
711
|
+
}[]>;
|
|
712
|
+
setConfig: (input: {
|
|
713
|
+
key: string;
|
|
714
|
+
value: string;
|
|
715
|
+
}) => Promise<{
|
|
716
|
+
ok: boolean;
|
|
717
|
+
}>;
|
|
718
|
+
clearTable: (input: {
|
|
719
|
+
table: "fused_tracks" | "source_health";
|
|
720
|
+
mode: "all" | "range";
|
|
721
|
+
from?: string;
|
|
722
|
+
to?: string;
|
|
723
|
+
}) => any;
|
|
724
|
+
};
|
|
725
|
+
getStatus(): AeroConnectionStatus;
|
|
726
|
+
getLastUpdateAt(): number | null;
|
|
727
|
+
getError(): AeroRecoverableError | null;
|
|
728
|
+
getSourceStatus(): Record<string, string>;
|
|
729
|
+
disconnect(): void;
|
|
730
|
+
reconnect(): boolean;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
export { AeroApiError as A, type DayAvailability as D, type FlightPlanRow as F, LABEL_COLORS as L, type ReplayCallbacks as R, type SourceRow as S, TrackCache as T, type UseAeroTracksResult as U, AeroReplayClient as a, AeroSwarm as b, type AeroSwarmOptions as c, AeroWsClient as d, type AftnMessageRow as e, type ApiErrorCode as f, type ApiErrorInit as g, type LabelCategory as h, type LabeledTrack as i, type LiveTrackCallbacks as j, type ReplayHandle as k, type ReplayProgress as l, type ReplayStreamOptions as m, type StreamMeta as n, type SubscribeOptions as o, type TrackCallbacks as p, type TrackHistoryPoint as q, codeForStatus as r, getLabelCategory as s, parseApiResponse as t, readApiBody as u, withLabel as w };
|