@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 +145 -2
- package/dist/fetch.d.ts +2 -1
- package/dist/index.cjs.js +91 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +91 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/types.d.ts +3 -7
- package/dist/volant-schema.d.ts +62 -56
- package/package.json +5 -8
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 ===
|
|
78
|
-
return { data: (_b = data.attributes) === null || _b ===
|
|
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:
|
|
@@ -131,8 +131,8 @@ class Direct {
|
|
|
131
131
|
}
|
|
132
132
|
return resp;
|
|
133
133
|
}
|
|
134
|
-
async getFlightplanStatistics(id, opts) {
|
|
135
|
-
const resp = await this.fetcher.GET('/flightplans/{flightplan_id}/statistics', { path: { flightplan_id: id } }, opts);
|
|
134
|
+
async getFlightplanStatistics(id, args, opts) {
|
|
135
|
+
const resp = await this.fetcher.GET('/flightplans/{flightplan_id}/statistics', { path: { flightplan_id: id }, query: args }, opts);
|
|
136
136
|
if (resp.error === undefined && !resp.aborted) {
|
|
137
137
|
return Object.assign(Object.assign({}, resp), { data: resp.data.data });
|
|
138
138
|
}
|
|
@@ -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,17 +725,19 @@ function defaultPathSerializer(pathname, pathParams) {
|
|
|
664
725
|
return nextURL;
|
|
665
726
|
}
|
|
666
727
|
|
|
728
|
+
var version = "1.3619.1";
|
|
729
|
+
|
|
667
730
|
const querySerializer = createQuerySerializer();
|
|
668
731
|
class Fetcher {
|
|
669
732
|
constructor(args) {
|
|
670
733
|
var _a, _b, _c, _d;
|
|
671
734
|
this.opts = {
|
|
672
|
-
url: (_a = args.url) !== null && _a !==
|
|
673
|
-
fetchFn: (_b = args.fetchFn) !== null && _b !==
|
|
674
|
-
authFetchFn: (_c = args.authFetchFn) !== null && _c !==
|
|
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,
|
|
675
738
|
username: args.username,
|
|
676
739
|
password: args.password,
|
|
677
|
-
ignoreAuth: (_d = args.ignoreAuth) !== null && _d !==
|
|
740
|
+
ignoreAuth: (_d = args.ignoreAuth) !== null && _d !== void 0 ? _d : false
|
|
678
741
|
};
|
|
679
742
|
this.aborts = {};
|
|
680
743
|
this.accessToken = undefined;
|
|
@@ -686,7 +749,7 @@ class Fetcher {
|
|
|
686
749
|
if (this.opts.username === undefined || this.opts.password === undefined) {
|
|
687
750
|
throw new UnauthenticatedError('ignoreAuth is not true and either username or password is missing');
|
|
688
751
|
}
|
|
689
|
-
const authFetchFn = (_a = this.opts.authFetchFn) !== null && _a !==
|
|
752
|
+
const authFetchFn = (_a = this.opts.authFetchFn) !== null && _a !== void 0 ? _a : globalThis.fetch;
|
|
690
753
|
const resp = await authFetchFn(this.opts.url + '/login', {
|
|
691
754
|
body: JSON.stringify({
|
|
692
755
|
username: this.opts.username,
|
|
@@ -694,7 +757,7 @@ class Fetcher {
|
|
|
694
757
|
}),
|
|
695
758
|
redirect: 'follow',
|
|
696
759
|
method: 'post',
|
|
697
|
-
headers: { 'Content-Type': 'application/json' }
|
|
760
|
+
headers: { 'Content-Type': 'application/json', 'X-Via-Sdk-Version': version }
|
|
698
761
|
});
|
|
699
762
|
if (resp.ok) {
|
|
700
763
|
const data = (await resp.json());
|
|
@@ -709,7 +772,7 @@ class Fetcher {
|
|
|
709
772
|
handleAbortKey(abortKey) {
|
|
710
773
|
var _a;
|
|
711
774
|
if (abortKey) {
|
|
712
|
-
(_a = this.aborts[abortKey]) === null || _a ===
|
|
775
|
+
(_a = this.aborts[abortKey]) === null || _a === void 0 ? void 0 : _a.abort();
|
|
713
776
|
const abortController = new AbortController();
|
|
714
777
|
this.aborts[abortKey] = abortController;
|
|
715
778
|
return abortController.signal;
|
|
@@ -721,7 +784,7 @@ class Fetcher {
|
|
|
721
784
|
var _a;
|
|
722
785
|
const error = (await response.json());
|
|
723
786
|
// NOTE: throws away the status codes inside of the individual errors
|
|
724
|
-
if (((_a = error === null || error ===
|
|
787
|
+
if (((_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
725
788
|
return {
|
|
726
789
|
status: String(response.status),
|
|
727
790
|
errors: [
|
|
@@ -735,7 +798,7 @@ class Fetcher {
|
|
|
735
798
|
else {
|
|
736
799
|
return {
|
|
737
800
|
status: String(response.status),
|
|
738
|
-
errors: error === null || error ===
|
|
801
|
+
errors: error === null || error === void 0 ? void 0 : error.errors.map((err) => {
|
|
739
802
|
return {
|
|
740
803
|
status: String(err.status),
|
|
741
804
|
detail: err.detail
|
|
@@ -748,10 +811,10 @@ class Fetcher {
|
|
|
748
811
|
createFinalURL(path, options) {
|
|
749
812
|
var _a;
|
|
750
813
|
let finalURL = `${this.opts.url}${path}`;
|
|
751
|
-
if (options === null || options ===
|
|
814
|
+
if (options === null || options === void 0 ? void 0 : options.path) {
|
|
752
815
|
finalURL = defaultPathSerializer(finalURL, options.path);
|
|
753
816
|
}
|
|
754
|
-
const search = querySerializer((_a = options.query) !== null && _a !==
|
|
817
|
+
const search = querySerializer((_a = options.query) !== null && _a !== void 0 ? _a : {});
|
|
755
818
|
if (search) {
|
|
756
819
|
finalURL += `?${search}`;
|
|
757
820
|
}
|
|
@@ -759,19 +822,25 @@ class Fetcher {
|
|
|
759
822
|
}
|
|
760
823
|
/** The actual fetch wrapper. It is type inference blind, beyond the parseAs type */
|
|
761
824
|
async fetcher(method, path, data, opts) {
|
|
762
|
-
var _a, _b, _c;
|
|
825
|
+
var _a, _b, _c, _d;
|
|
763
826
|
if (!this.opts.ignoreAuth) {
|
|
764
827
|
if (!this.accessToken || this.expiry <= Date.now()) {
|
|
765
828
|
await this.doAuth();
|
|
766
829
|
}
|
|
767
830
|
}
|
|
768
|
-
const fetchFn = (_b = (_a = opts === null || opts ===
|
|
769
|
-
const parseAs = (_c = opts === null || opts ===
|
|
770
|
-
const
|
|
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 }), {
|
|
771
840
|
redirect: 'follow',
|
|
772
|
-
signal: this.handleAbortKey(opts === null || opts ===
|
|
773
|
-
body
|
|
774
|
-
headers: Object.assign({
|
|
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),
|
|
775
844
|
method
|
|
776
845
|
});
|
|
777
846
|
if (!this.opts.ignoreAuth) {
|