@volant-autonomy/via-sdk 1.3595.1 → 1.3622.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/index.esm.js CHANGED
@@ -74,8 +74,8 @@ class Composite {
74
74
  await sleep(50);
75
75
  continue;
76
76
  case 'successful':
77
- if ((_a = data.attributes) === null || _a === undefined ? undefined : _a.waypoints) {
78
- return { data: (_b = data.attributes) === null || _b === undefined ? undefined : _b.waypoints };
77
+ if ((_a = data.attributes) === null || _a === void 0 ? void 0 : _a.waypoints) {
78
+ return { data: (_b = data.attributes) === null || _b === void 0 ? void 0 : _b.waypoints };
79
79
  }
80
80
  else {
81
81
  throw new Error(`endpoint did not return waypoints ${data}`); // TODO:
@@ -219,6 +219,30 @@ class Direct {
219
219
  }
220
220
  return resp;
221
221
  }
222
+ getPathingTaskStateStream(id, onMessage, onFail) {
223
+ return new Promise((resolve, reject) => {
224
+ const eventSource = new EventSource(`/api/v1.0/pathing_tasks/${id}/state`);
225
+ eventSource.onmessage = (event) => {
226
+ const data = JSON.parse(event.data);
227
+ if (data.error === true) {
228
+ onFail === null || onFail === void 0 ? void 0 : onFail();
229
+ eventSource.close();
230
+ reject(new Error(`Task stream returned error: ${data.payload}`));
231
+ return;
232
+ }
233
+ if (data.payload.terminated) {
234
+ eventSource.close();
235
+ resolve(data.payload);
236
+ }
237
+ onMessage === null || onMessage === void 0 ? void 0 : onMessage(data.payload);
238
+ };
239
+ eventSource.onerror = (err) => {
240
+ eventSource.close();
241
+ onFail === null || onFail === void 0 ? void 0 : onFail();
242
+ reject(err);
243
+ };
244
+ });
245
+ }
222
246
  /// charts
223
247
  async getAllCharts(opts) {
224
248
  const resp = await this.fetcher.GET('/charts/', {}, opts);
@@ -454,6 +478,43 @@ class Direct {
454
478
  }
455
479
  return resp;
456
480
  }
481
+ /// cost datasets
482
+ async getCostDataset(id, opts) {
483
+ const resp = await this.fetcher.GET('/cost_datasets/{cost_dataset_id}', { path: { cost_dataset_id: id } }, opts);
484
+ if (resp.error === undefined && !resp.aborted) {
485
+ return Object.assign(Object.assign({}, resp), { data: resp.data.data });
486
+ }
487
+ return resp;
488
+ }
489
+ async getAllCostDatasets(args, opts) {
490
+ const resp = await this.fetcher.GET('/cost_datasets/', { query: args }, opts);
491
+ if (resp.error === undefined && !resp.aborted) {
492
+ return Object.assign(Object.assign({}, resp), { data: resp.data.data.map((x) => x.data) });
493
+ }
494
+ return resp;
495
+ }
496
+ async createCostDataset(args, opts) {
497
+ const formData = new FormData();
498
+ formData.append('chart_id', args.chart_id);
499
+ formData.append('valid_time_ranges', JSON.stringify(args.valid_time_ranges));
500
+ formData.append('geotiff', args.geotiff);
501
+ const resp = await this.fetcher.POST('/cost_datasets/', { body: formData }, Object.assign(Object.assign({}, opts), {
502
+ // when sending a FormData object the browser will automatically
503
+ // set the Content-Type header to the correct value, if (and only if)
504
+ // you don't set it yourself
505
+ contentType: 'none' }));
506
+ if (resp.error === undefined && !resp.aborted) {
507
+ return Object.assign(Object.assign({}, resp), { data: resp.data.data });
508
+ }
509
+ return resp;
510
+ }
511
+ async deleteCostDataset(id, opts) {
512
+ const resp = await this.fetcher.DELETE('/cost_datasets/{cost_dataset_id}', { path: { cost_dataset_id: id } }, opts);
513
+ if (resp.error === undefined && !resp.aborted) {
514
+ return Object.assign(Object.assign({}, resp), { data: true });
515
+ }
516
+ return resp;
517
+ }
457
518
  /// flight patterns
458
519
  async createRasterPattern(args, opts) {
459
520
  const resp = await this.fetcher.POST('/flight_patterns/raster', { body: args }, opts);
@@ -664,19 +725,19 @@ function defaultPathSerializer(pathname, pathParams) {
664
725
  return nextURL;
665
726
  }
666
727
 
667
- var version = "1.3595.1";
728
+ var version = "1.3622.1";
668
729
 
669
730
  const querySerializer = createQuerySerializer();
670
731
  class Fetcher {
671
732
  constructor(args) {
672
733
  var _a, _b, _c, _d;
673
734
  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,
735
+ url: (_a = args.url) !== null && _a !== void 0 ? _a : 'https://via.volantautonomy.com/api/v1.0',
736
+ fetchFn: (_b = args.fetchFn) !== null && _b !== void 0 ? _b : undefined,
737
+ authFetchFn: (_c = args.authFetchFn) !== null && _c !== void 0 ? _c : undefined,
677
738
  username: args.username,
678
739
  password: args.password,
679
- ignoreAuth: (_d = args.ignoreAuth) !== null && _d !== undefined ? _d : false
740
+ ignoreAuth: (_d = args.ignoreAuth) !== null && _d !== void 0 ? _d : false
680
741
  };
681
742
  this.aborts = {};
682
743
  this.accessToken = undefined;
@@ -688,7 +749,7 @@ class Fetcher {
688
749
  if (this.opts.username === undefined || this.opts.password === undefined) {
689
750
  throw new UnauthenticatedError('ignoreAuth is not true and either username or password is missing');
690
751
  }
691
- const authFetchFn = (_a = this.opts.authFetchFn) !== null && _a !== undefined ? _a : globalThis.fetch;
752
+ const authFetchFn = (_a = this.opts.authFetchFn) !== null && _a !== void 0 ? _a : globalThis.fetch;
692
753
  const resp = await authFetchFn(this.opts.url + '/login', {
693
754
  body: JSON.stringify({
694
755
  username: this.opts.username,
@@ -711,7 +772,7 @@ class Fetcher {
711
772
  handleAbortKey(abortKey) {
712
773
  var _a;
713
774
  if (abortKey) {
714
- (_a = this.aborts[abortKey]) === null || _a === undefined ? undefined : _a.abort();
775
+ (_a = this.aborts[abortKey]) === null || _a === void 0 ? void 0 : _a.abort();
715
776
  const abortController = new AbortController();
716
777
  this.aborts[abortKey] = abortController;
717
778
  return abortController.signal;
@@ -723,7 +784,7 @@ class Fetcher {
723
784
  var _a;
724
785
  const error = (await response.json());
725
786
  // 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) {
787
+ if (((_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.length) === 0) {
727
788
  return {
728
789
  status: String(response.status),
729
790
  errors: [
@@ -737,7 +798,7 @@ class Fetcher {
737
798
  else {
738
799
  return {
739
800
  status: String(response.status),
740
- errors: error === null || error === undefined ? undefined : error.errors.map((err) => {
801
+ errors: error === null || error === void 0 ? void 0 : error.errors.map((err) => {
741
802
  return {
742
803
  status: String(err.status),
743
804
  detail: err.detail
@@ -750,10 +811,10 @@ class Fetcher {
750
811
  createFinalURL(path, options) {
751
812
  var _a;
752
813
  let finalURL = `${this.opts.url}${path}`;
753
- if (options === null || options === undefined ? undefined : options.path) {
814
+ if (options === null || options === void 0 ? void 0 : options.path) {
754
815
  finalURL = defaultPathSerializer(finalURL, options.path);
755
816
  }
756
- const search = querySerializer((_a = options.query) !== null && _a !== undefined ? _a : {});
817
+ const search = querySerializer((_a = options.query) !== null && _a !== void 0 ? _a : {});
757
818
  if (search) {
758
819
  finalURL += `?${search}`;
759
820
  }
@@ -761,19 +822,25 @@ class Fetcher {
761
822
  }
762
823
  /** The actual fetch wrapper. It is type inference blind, beyond the parseAs type */
763
824
  async fetcher(method, path, data, opts) {
764
- var _a, _b, _c;
825
+ var _a, _b, _c, _d;
765
826
  if (!this.opts.ignoreAuth) {
766
827
  if (!this.accessToken || this.expiry <= Date.now()) {
767
828
  await this.doAuth();
768
829
  }
769
830
  }
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 }), {
831
+ 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;
832
+ const parseAs = (_c = opts === null || opts === void 0 ? void 0 : opts.parseAs) !== null && _c !== void 0 ? _c : 'json';
833
+ const contentType = (_d = opts === null || opts === void 0 ? void 0 : opts.contentType) !== null && _d !== void 0 ? _d : 'application/json';
834
+ 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;
835
+ const headers = { 'X-Via-Sdk-Version': version };
836
+ if (contentType !== 'none') {
837
+ headers['Content-Type'] = contentType;
838
+ }
839
+ 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
840
  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', 'X-Via-Sdk-Version': version }, data === null || data === undefined ? undefined : data.header),
841
+ signal: this.handleAbortKey(opts === null || opts === void 0 ? void 0 : opts.abortKey),
842
+ body,
843
+ headers: Object.assign(Object.assign({}, headers), data === null || data === void 0 ? void 0 : data.header),
777
844
  method
778
845
  });
779
846
  if (!this.opts.ignoreAuth) {