@aeroswarm/client 0.1.15 → 0.1.17

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.
@@ -477,6 +477,13 @@ declare function parseApiResponse<T>(res: Response, label?: string): Promise<T>;
477
477
  interface AeroSwarmOptions {
478
478
  endpoint: string;
479
479
  token: string;
480
+ /**
481
+ * Credential for the airport's OWN backend (history, trail, replay days: whatever goes to a
482
+ * `historyEndpoint` or an explicit `endpoint`), when it differs from `token`. Pass a function to
483
+ * have it read on every request, e.g. `() => session.accessToken`, so a login that is refreshed
484
+ * is picked up without rebuilding the client. Defaults to `token`.
485
+ */
486
+ backendToken?: string | (() => string | undefined | Promise<string | undefined>);
480
487
  wsEndpoint?: string;
481
488
  reconnect?: boolean;
482
489
  maxReconnectDelay?: number;
@@ -533,6 +540,8 @@ declare class AeroSwarm {
533
540
  * (a broken airports.list() call must never brick replay/history for
534
541
  * everyone else). */
535
542
  private resolveHistoryEndpoint;
543
+ /** What to present to an airport's own backend: `backendToken` (read now if it is a function), else `token`. */
544
+ private backendCredential;
536
545
  private federatedRequest;
537
546
  private federatedFetch;
538
547
  constructor(opts: AeroSwarmOptions);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AeroApiError, a as AeroReplayClient, b as AeroSwarm, c as AeroSwarmOptions, d as AeroWsClient, e as AftnMessageRow, f as ApiErrorCode, g as ApiErrorInit, h as ApiMetaLike, D as DayAvailability, F as FlightPlanRow, L as LABEL_COLORS, i as LabelCategory, j as LabeledTrack, k as LiveTrackCallbacks, R as ReplayCallbacks, l as ReplayHandle, m as ReplayProgress, n as ReplayStreamOptions, S as SourceRow, o as StreamMeta, p as SubscribeOptions, T as TrackCache, q as TrackCallbacks, r as TrackHistoryPoint, s as TrailFeatureCollection, t as TrailLine, u as TrailMark, v as TrailMeta, w as TrailPoller, x as TrailPollerOptions, y as TrailRequest, z as TrailResult, U as UseAeroTracksResult, B as codeForStatus, C as createTrailPoller, E as getLabelCategory, G as mergeTrail, H as parseApiEnvelope, I as parseApiResponse, J as readApiBody, K as trailEnd, M as withLabel } from './index-CeayQnTp.js';
1
+ export { A as AeroApiError, a as AeroReplayClient, b as AeroSwarm, c as AeroSwarmOptions, d as AeroWsClient, e as AftnMessageRow, f as ApiErrorCode, g as ApiErrorInit, h as ApiMetaLike, D as DayAvailability, F as FlightPlanRow, L as LABEL_COLORS, i as LabelCategory, j as LabeledTrack, k as LiveTrackCallbacks, R as ReplayCallbacks, l as ReplayHandle, m as ReplayProgress, n as ReplayStreamOptions, S as SourceRow, o as StreamMeta, p as SubscribeOptions, T as TrackCache, q as TrackCallbacks, r as TrackHistoryPoint, s as TrailFeatureCollection, t as TrailLine, u as TrailMark, v as TrailMeta, w as TrailPoller, x as TrailPollerOptions, y as TrailRequest, z as TrailResult, U as UseAeroTracksResult, B as codeForStatus, C as createTrailPoller, E as getLabelCategory, G as mergeTrail, H as parseApiEnvelope, I as parseApiResponse, J as readApiBody, K as trailEnd, M as withLabel } from './index-DH3DH1Nj.js';
2
2
  import { CurrentTrack } from '@aeroswarm/core/types';
3
3
  export { AeroConnectionStatus, AeroRecoverableError, Bbox, ConfidenceBudget, CurrentTrack, DataSource, FlightPhase, FlightPlan, FlightPlanStatus, FlightPlanSummary, FusedTrackEvent, Position, Protocol, SourceHealthEvent, SourceStatus, StreamEnvelope, TrackSource, TrackStatus, Velocity } from '@aeroswarm/core/types';
4
4
  export { clamp, haversineKm, isInsideBbox, isRenderableTrack, toCurrentTrack } from '@aeroswarm/core/utils';
package/dist/index.js CHANGED
@@ -634,11 +634,17 @@ var AeroSwarm = class _AeroSwarm {
634
634
  return null;
635
635
  }
636
636
  }
637
+ /** What to present to an airport's own backend: `backendToken` (read now if it is a function), else `token`. */
638
+ async backendCredential() {
639
+ const given = this.opts.backendToken;
640
+ const value = typeof given === "function" ? await given() : given;
641
+ return value || this.opts.token;
642
+ }
637
643
  async federatedRequest(base, path, query) {
638
644
  const url = new URL(`${base}${path}`);
639
645
  for (const [k, v] of Object.entries(query ?? {})) if (v !== void 0) url.searchParams.set(k, v);
640
646
  const res = await fetch(url, {
641
- headers: { Authorization: `Bearer ${this.opts.token}`, [ENVELOPE_HEADER]: "1" }
647
+ headers: { Authorization: `Bearer ${await this.backendCredential()}`, [ENVELOPE_HEADER]: "1" }
642
648
  });
643
649
  return parseApiEnvelope(res, `Federated request ${url.pathname}`);
644
650
  }