@volant-autonomy/via-sdk 1.3583.1 → 1.3619.1

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/dist/direct.d.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import createFetcher from './fetch';
2
- import { bodyOf, queryOf, pathOf } from './types';
2
+ import { bodyOf, queryOf, pathOf, schemas, PathingTaskState } from './types';
3
3
  import type { paths } from './volant-schema';
4
4
  type requestOptions = {
5
5
  abortKey?: string;
6
6
  fetch?: typeof globalThis.fetch;
7
7
  };
8
+ type PathingTaskEvent = {
9
+ state: PathingTaskState;
10
+ terminated: boolean;
11
+ };
8
12
  export type getAllFlightplans = paths['/flightplans/']['get'];
9
13
  export type createDraftFlightplan = paths['/flightplans/']['post'];
10
14
  export type modifyDraftFlightplan = paths['/flightplans/{flightplan_id}']['put'];
@@ -22,6 +26,7 @@ export type modifyAirspaceConstraint = paths['/airspace_constraints/{airspace_co
22
26
  export type changeAirspaceConstraintState = paths['/airspace_constraints/{airspace_constraints_id}/state']['post'];
23
27
  export type createPathingTask = paths['/pathing_tasks/']['post'];
24
28
  export type getPathingTask = paths['/pathing_tasks/{pathing_task_id}']['get'];
29
+ export type getPathingTaskStateStream = paths['/pathing_tasks/{pathing_task_id}/state']['get'];
25
30
  export type getAllCharts = paths['/charts/']['get'];
26
31
  export type getChart = paths['/charts/{chart_id}']['get'];
27
32
  export type getSailV2_5 = paths['/risk_assessment/sora/v2.5/sail']['get'];
@@ -55,6 +60,10 @@ export type getAllGeocages = paths['/geocages/']['get'];
55
60
  export type createGeocage = paths['/geocages/']['post'];
56
61
  export type updateGeocage = paths['/geocages/{geocage_id}']['put'];
57
62
  export type deleteGeocage = paths['/geocages/{geocage_id}']['delete'];
63
+ export type getCostDataset = paths['/cost_datasets/{cost_dataset_id}']['get'];
64
+ export type getAllCostDatasets = paths['/cost_datasets/']['get'];
65
+ export type createCostDataset = paths['/cost_datasets/']['post'];
66
+ export type deleteCostDataset = paths['/cost_datasets/{cost_dataset_id}']['delete'];
58
67
  export declare class Direct {
59
68
  private fetcher;
60
69
  constructor(fetcher: ReturnType<typeof createFetcher<paths>>);
@@ -218,7 +227,7 @@ export declare class Direct {
218
227
  * Retrieve Flightplan Statistics
219
228
  * @description Retrieve statistics for the specified flightplan, including the nominal time and cost.
220
229
  */
221
- getFlightplanStatistics<Opts extends requestOptions = {}>(id: pathOf<getFlightplanStatistics>['flightplan_id'], opts?: Opts | requestOptions): Promise<{
230
+ getFlightplanStatistics<Opts extends requestOptions = {}>(id: pathOf<getFlightplanStatistics>['flightplan_id'], args: queryOf<getFlightplanStatistics>, opts?: Opts | requestOptions): Promise<{
222
231
  data?: never;
223
232
  error: {
224
233
  errors: {
@@ -590,6 +599,16 @@ export declare class Direct {
590
599
  response: Response;
591
600
  aborted: false;
592
601
  }>;
602
+ /**
603
+ * Receive state change updates for a pathing task
604
+ * @description Opens a persistent connection that sends real-time updates about changes in a pathing task's state using Server-Sent
605
+ * Events (SSE).
606
+ *
607
+ * Provides an event stream that can be connected to that will provide updates when the state of the specified pathing
608
+ * task changes. Once it has reached it's final state, the last update is pushed and the stream is automatically
609
+ * closed.
610
+ */
611
+ getPathingTaskStateStream(id: pathOf<getPathingTaskStateStream>['pathing_task_id'], onMessage?: (payload: PathingTaskEvent) => void, onFail?: () => void): Promise<PathingTaskEvent>;
593
612
  /**
594
613
  * List all available Charts
595
614
  * @description List user's charts, including chart id and bounds.
@@ -1533,6 +1552,130 @@ export declare class Direct {
1533
1552
  response: Response;
1534
1553
  aborted: false;
1535
1554
  }>;
1555
+ /**
1556
+ * Get a Cost Dataset
1557
+ * @description Get a Cost Dataset
1558
+ */
1559
+ getCostDataset<Opts extends requestOptions = {}>(id: pathOf<getCostDataset>['cost_dataset_id'], opts?: Opts | requestOptions): Promise<{
1560
+ data?: never;
1561
+ error: {
1562
+ errors: {
1563
+ detail: string;
1564
+ status: "401" | "400" | "422" | "404";
1565
+ }[];
1566
+ status: "401" | "400" | "422" | "404";
1567
+ };
1568
+ response: Response;
1569
+ aborted: false;
1570
+ } | (keyof Opts extends never ? never : Opts["abortKey"] extends undefined ? never : Opts["abortKey"] extends string | undefined ? {
1571
+ data?: never;
1572
+ error?: never;
1573
+ response?: never;
1574
+ aborted: true;
1575
+ } : never) | {
1576
+ data: {
1577
+ id: string;
1578
+ type?: "cost_dataset";
1579
+ attributes: import("./volant-schema").components["schemas"]["CostDatasetAttributes"];
1580
+ };
1581
+ error?: never;
1582
+ response: Response;
1583
+ aborted: false;
1584
+ }>;
1585
+ /**
1586
+ * List Cost Datasets
1587
+ * @description Get a list of Cost Datasets, ordered by last time updated
1588
+ */
1589
+ getAllCostDatasets<Opts extends requestOptions = {}>(args: queryOf<getAllCostDatasets>, opts?: Opts | requestOptions): Promise<{
1590
+ data?: never;
1591
+ error: {
1592
+ errors: {
1593
+ detail: string;
1594
+ status: "401" | "400" | "422";
1595
+ }[];
1596
+ status: "401" | "400" | "422";
1597
+ };
1598
+ response: Response;
1599
+ aborted: false;
1600
+ } | (keyof Opts extends never ? never : Opts["abortKey"] extends undefined ? never : Opts["abortKey"] extends string | undefined ? {
1601
+ data?: never;
1602
+ error?: never;
1603
+ response?: never;
1604
+ aborted: true;
1605
+ } : never) | {
1606
+ data: {
1607
+ id: string;
1608
+ type?: "cost_dataset";
1609
+ attributes: import("./volant-schema").components["schemas"]["CostDatasetAttributes"];
1610
+ }[];
1611
+ error?: never;
1612
+ response: Response;
1613
+ aborted: false;
1614
+ }>;
1615
+ /**
1616
+ * Create a Cost Dataset
1617
+ * @description Create a Cost Dataset
1618
+ */
1619
+ createCostDataset<Opts extends requestOptions = {}>(args: {
1620
+ chart_id: string;
1621
+ valid_time_ranges: schemas['RasterValidityTime'][];
1622
+ geotiff: Blob;
1623
+ }, opts?: Opts | requestOptions): Promise<{
1624
+ data?: never;
1625
+ error: {
1626
+ errors: {
1627
+ detail: string;
1628
+ status: "401" | "400" | "422" | "403";
1629
+ }[];
1630
+ status: "401" | "400" | "422" | "403";
1631
+ };
1632
+ response: Response;
1633
+ aborted: false;
1634
+ } | ("contentType" | keyof Opts extends never ? never : (Opts & {
1635
+ contentType: "none";
1636
+ })["abortKey"] extends undefined ? never : (Opts & {
1637
+ contentType: "none";
1638
+ })["abortKey"] extends string | undefined ? {
1639
+ data?: never;
1640
+ error?: never;
1641
+ response?: never;
1642
+ aborted: true;
1643
+ } : never) | {
1644
+ data: {
1645
+ id: string;
1646
+ type?: "cost_dataset";
1647
+ attributes: import("./volant-schema").components["schemas"]["CostDatasetAttributes"];
1648
+ };
1649
+ error?: never;
1650
+ response: Response;
1651
+ aborted: false;
1652
+ }>;
1653
+ /**
1654
+ * Delete a Cost Dataset
1655
+ * @description Delete a Cost Dataset.
1656
+ */
1657
+ deleteCostDataset<Opts extends requestOptions = {}>(id: pathOf<deleteCostDataset>['cost_dataset_id'], opts?: Opts | requestOptions): Promise<{
1658
+ data?: never;
1659
+ error: {
1660
+ errors: {
1661
+ detail: string;
1662
+ status: "401" | "400" | "422" | "404";
1663
+ }[];
1664
+ status: "401" | "400" | "422" | "404";
1665
+ };
1666
+ response: Response;
1667
+ aborted: false;
1668
+ } | (keyof Opts extends never ? never : Opts["abortKey"] extends undefined ? never : Opts["abortKey"] extends string | undefined ? {
1669
+ data?: never;
1670
+ error?: never;
1671
+ response?: never;
1672
+ aborted: true;
1673
+ } : never) | {
1674
+ data: boolean;
1675
+ error?: never;
1676
+ response: Response;
1677
+ aborted: false;
1678
+ }>;
1536
1679
  /**
1537
1680
  * Generate a raster pattern
1538
1681
  * @description Generate a raster pattern that covers a specified search polygon
package/dist/fetch.d.ts CHANGED
@@ -5,6 +5,7 @@ type requestOptions = {
5
5
  abortKey?: string;
6
6
  fetch?: typeof globalThis.fetch;
7
7
  parseAs?: ParseAs;
8
+ contentType?: 'application/json' | 'none';
8
9
  };
9
10
  /**
10
11
  * Get the types of the parameters of an endpoint but if it does not have any
@@ -30,7 +31,7 @@ type BodyOption<Endpoint> = Endpoint extends {
30
31
  } : {
31
32
  body: bodyOf<Endpoint>;
32
33
  } : {
33
- body?: Record<string, unknown>;
34
+ body?: Record<string, unknown> | BodyInit;
34
35
  };
35
36
  /**
36
37
  * Combines the body and other parameters into one type, with stuff being optional
package/dist/index.cjs.js CHANGED
@@ -76,8 +76,8 @@ class Composite {
76
76
  await sleep(50);
77
77
  continue;
78
78
  case 'successful':
79
- if ((_a = data.attributes) === null || _a === undefined ? undefined : _a.waypoints) {
80
- return { data: (_b = data.attributes) === null || _b === undefined ? undefined : _b.waypoints };
79
+ if ((_a = data.attributes) === null || _a === void 0 ? void 0 : _a.waypoints) {
80
+ return { data: (_b = data.attributes) === null || _b === void 0 ? void 0 : _b.waypoints };
81
81
  }
82
82
  else {
83
83
  throw new Error(`endpoint did not return waypoints ${data}`); // TODO:
@@ -133,8 +133,8 @@ class Direct {
133
133
  }
134
134
  return resp;
135
135
  }
136
- async getFlightplanStatistics(id, opts) {
137
- const resp = await this.fetcher.GET('/flightplans/{flightplan_id}/statistics', { path: { flightplan_id: id } }, opts);
136
+ async getFlightplanStatistics(id, args, opts) {
137
+ const resp = await this.fetcher.GET('/flightplans/{flightplan_id}/statistics', { path: { flightplan_id: id }, query: args }, opts);
138
138
  if (resp.error === undefined && !resp.aborted) {
139
139
  return Object.assign(Object.assign({}, resp), { data: resp.data.data });
140
140
  }
@@ -221,6 +221,30 @@ class Direct {
221
221
  }
222
222
  return resp;
223
223
  }
224
+ getPathingTaskStateStream(id, onMessage, onFail) {
225
+ return new Promise((resolve, reject) => {
226
+ const eventSource = new EventSource(`/api/v1.0/pathing_tasks/${id}/state`);
227
+ eventSource.onmessage = (event) => {
228
+ const data = JSON.parse(event.data);
229
+ if (data.error === true) {
230
+ onFail === null || onFail === void 0 ? void 0 : onFail();
231
+ eventSource.close();
232
+ reject(new Error(`Task stream returned error: ${data.payload}`));
233
+ return;
234
+ }
235
+ if (data.payload.terminated) {
236
+ eventSource.close();
237
+ resolve(data.payload);
238
+ }
239
+ onMessage === null || onMessage === void 0 ? void 0 : onMessage(data.payload);
240
+ };
241
+ eventSource.onerror = (err) => {
242
+ eventSource.close();
243
+ onFail === null || onFail === void 0 ? void 0 : onFail();
244
+ reject(err);
245
+ };
246
+ });
247
+ }
224
248
  /// charts
225
249
  async getAllCharts(opts) {
226
250
  const resp = await this.fetcher.GET('/charts/', {}, opts);
@@ -456,6 +480,43 @@ class Direct {
456
480
  }
457
481
  return resp;
458
482
  }
483
+ /// cost datasets
484
+ async getCostDataset(id, opts) {
485
+ const resp = await this.fetcher.GET('/cost_datasets/{cost_dataset_id}', { path: { cost_dataset_id: id } }, opts);
486
+ if (resp.error === undefined && !resp.aborted) {
487
+ return Object.assign(Object.assign({}, resp), { data: resp.data.data });
488
+ }
489
+ return resp;
490
+ }
491
+ async getAllCostDatasets(args, opts) {
492
+ const resp = await this.fetcher.GET('/cost_datasets/', { query: args }, opts);
493
+ if (resp.error === undefined && !resp.aborted) {
494
+ return Object.assign(Object.assign({}, resp), { data: resp.data.data.map((x) => x.data) });
495
+ }
496
+ return resp;
497
+ }
498
+ async createCostDataset(args, opts) {
499
+ const formData = new FormData();
500
+ formData.append('chart_id', args.chart_id);
501
+ formData.append('valid_time_ranges', JSON.stringify(args.valid_time_ranges));
502
+ formData.append('geotiff', args.geotiff);
503
+ const resp = await this.fetcher.POST('/cost_datasets/', { body: formData }, Object.assign(Object.assign({}, opts), {
504
+ // when sending a FormData object the browser will automatically
505
+ // set the Content-Type header to the correct value, if (and only if)
506
+ // you don't set it yourself
507
+ contentType: 'none' }));
508
+ if (resp.error === undefined && !resp.aborted) {
509
+ return Object.assign(Object.assign({}, resp), { data: resp.data.data });
510
+ }
511
+ return resp;
512
+ }
513
+ async deleteCostDataset(id, opts) {
514
+ const resp = await this.fetcher.DELETE('/cost_datasets/{cost_dataset_id}', { path: { cost_dataset_id: id } }, opts);
515
+ if (resp.error === undefined && !resp.aborted) {
516
+ return Object.assign(Object.assign({}, resp), { data: true });
517
+ }
518
+ return resp;
519
+ }
459
520
  /// flight patterns
460
521
  async createRasterPattern(args, opts) {
461
522
  const resp = await this.fetcher.POST('/flight_patterns/raster', { body: args }, opts);
@@ -666,17 +727,19 @@ function defaultPathSerializer(pathname, pathParams) {
666
727
  return nextURL;
667
728
  }
668
729
 
730
+ var version = "1.3619.1";
731
+
669
732
  const querySerializer = createQuerySerializer();
670
733
  class Fetcher {
671
734
  constructor(args) {
672
735
  var _a, _b, _c, _d;
673
736
  this.opts = {
674
- url: (_a = args.url) !== null && _a !== undefined ? _a : 'https://via.volantautonomy.com/api/v1.0',
675
- fetchFn: (_b = args.fetchFn) !== null && _b !== undefined ? _b : undefined,
676
- authFetchFn: (_c = args.authFetchFn) !== null && _c !== undefined ? _c : undefined,
737
+ url: (_a = args.url) !== null && _a !== void 0 ? _a : 'https://via.volantautonomy.com/api/v1.0',
738
+ fetchFn: (_b = args.fetchFn) !== null && _b !== void 0 ? _b : undefined,
739
+ authFetchFn: (_c = args.authFetchFn) !== null && _c !== void 0 ? _c : undefined,
677
740
  username: args.username,
678
741
  password: args.password,
679
- ignoreAuth: (_d = args.ignoreAuth) !== null && _d !== undefined ? _d : false
742
+ ignoreAuth: (_d = args.ignoreAuth) !== null && _d !== void 0 ? _d : false
680
743
  };
681
744
  this.aborts = {};
682
745
  this.accessToken = undefined;
@@ -688,7 +751,7 @@ class Fetcher {
688
751
  if (this.opts.username === undefined || this.opts.password === undefined) {
689
752
  throw new UnauthenticatedError('ignoreAuth is not true and either username or password is missing');
690
753
  }
691
- const authFetchFn = (_a = this.opts.authFetchFn) !== null && _a !== undefined ? _a : globalThis.fetch;
754
+ const authFetchFn = (_a = this.opts.authFetchFn) !== null && _a !== void 0 ? _a : globalThis.fetch;
692
755
  const resp = await authFetchFn(this.opts.url + '/login', {
693
756
  body: JSON.stringify({
694
757
  username: this.opts.username,
@@ -696,7 +759,7 @@ class Fetcher {
696
759
  }),
697
760
  redirect: 'follow',
698
761
  method: 'post',
699
- headers: { 'Content-Type': 'application/json' }
762
+ headers: { 'Content-Type': 'application/json', 'X-Via-Sdk-Version': version }
700
763
  });
701
764
  if (resp.ok) {
702
765
  const data = (await resp.json());
@@ -711,7 +774,7 @@ class Fetcher {
711
774
  handleAbortKey(abortKey) {
712
775
  var _a;
713
776
  if (abortKey) {
714
- (_a = this.aborts[abortKey]) === null || _a === undefined ? undefined : _a.abort();
777
+ (_a = this.aborts[abortKey]) === null || _a === void 0 ? void 0 : _a.abort();
715
778
  const abortController = new AbortController();
716
779
  this.aborts[abortKey] = abortController;
717
780
  return abortController.signal;
@@ -723,7 +786,7 @@ class Fetcher {
723
786
  var _a;
724
787
  const error = (await response.json());
725
788
  // NOTE: throws away the status codes inside of the individual errors
726
- if (((_a = error === null || error === undefined ? undefined : error.errors) === null || _a === undefined ? undefined : _a.length) === 0) {
789
+ if (((_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.length) === 0) {
727
790
  return {
728
791
  status: String(response.status),
729
792
  errors: [
@@ -737,7 +800,7 @@ class Fetcher {
737
800
  else {
738
801
  return {
739
802
  status: String(response.status),
740
- errors: error === null || error === undefined ? undefined : error.errors.map((err) => {
803
+ errors: error === null || error === void 0 ? void 0 : error.errors.map((err) => {
741
804
  return {
742
805
  status: String(err.status),
743
806
  detail: err.detail
@@ -750,10 +813,10 @@ class Fetcher {
750
813
  createFinalURL(path, options) {
751
814
  var _a;
752
815
  let finalURL = `${this.opts.url}${path}`;
753
- if (options === null || options === undefined ? undefined : options.path) {
816
+ if (options === null || options === void 0 ? void 0 : options.path) {
754
817
  finalURL = defaultPathSerializer(finalURL, options.path);
755
818
  }
756
- const search = querySerializer((_a = options.query) !== null && _a !== undefined ? _a : {});
819
+ const search = querySerializer((_a = options.query) !== null && _a !== void 0 ? _a : {});
757
820
  if (search) {
758
821
  finalURL += `?${search}`;
759
822
  }
@@ -761,19 +824,25 @@ class Fetcher {
761
824
  }
762
825
  /** The actual fetch wrapper. It is type inference blind, beyond the parseAs type */
763
826
  async fetcher(method, path, data, opts) {
764
- var _a, _b, _c;
827
+ var _a, _b, _c, _d;
765
828
  if (!this.opts.ignoreAuth) {
766
829
  if (!this.accessToken || this.expiry <= Date.now()) {
767
830
  await this.doAuth();
768
831
  }
769
832
  }
770
- const fetchFn = (_b = (_a = opts === null || opts === undefined ? undefined : opts.fetch) !== null && _a !== undefined ? _a : this.opts.fetchFn) !== null && _b !== undefined ? _b : globalThis.fetch;
771
- const parseAs = (_c = opts === null || opts === undefined ? undefined : opts.parseAs) !== null && _c !== undefined ? _c : 'json';
772
- const request = new Request(this.createFinalURL(path, { query: data === null || data === undefined ? undefined : data.query, path: data === null || data === undefined ? undefined : data.path }), {
833
+ const fetchFn = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.fetch) !== null && _a !== void 0 ? _a : this.opts.fetchFn) !== null && _b !== void 0 ? _b : globalThis.fetch;
834
+ const parseAs = (_c = opts === null || opts === void 0 ? void 0 : opts.parseAs) !== null && _c !== void 0 ? _c : 'json';
835
+ const contentType = (_d = opts === null || opts === void 0 ? void 0 : opts.contentType) !== null && _d !== void 0 ? _d : 'application/json';
836
+ const body = contentType === 'application/json' ? JSON.stringify(data === null || data === void 0 ? void 0 : data.body) : data === null || data === void 0 ? void 0 : data.body;
837
+ const headers = { 'X-Via-Sdk-Version': version };
838
+ if (contentType !== 'none') {
839
+ headers['Content-Type'] = contentType;
840
+ }
841
+ const request = new Request(this.createFinalURL(path, { query: data === null || data === void 0 ? void 0 : data.query, path: data === null || data === void 0 ? void 0 : data.path }), {
773
842
  redirect: 'follow',
774
- signal: this.handleAbortKey(opts === null || opts === undefined ? undefined : opts.abortKey),
775
- body: JSON.stringify(data === null || data === undefined ? undefined : data.body),
776
- headers: Object.assign({ 'Content-Type': 'application/json' }, data === null || data === undefined ? undefined : data.header),
843
+ signal: this.handleAbortKey(opts === null || opts === void 0 ? void 0 : opts.abortKey),
844
+ body,
845
+ headers: Object.assign(Object.assign({}, headers), data === null || data === void 0 ? void 0 : data.header),
777
846
  method
778
847
  });
779
848
  if (!this.opts.ignoreAuth) {