@nextgis/geocoder 3.0.0-alpha.0 → 3.0.0-alpha.12
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/lib/geocoder.cjs.js +91 -82
- package/lib/geocoder.cjs.js.map +1 -1
- package/lib/geocoder.cjs.prod.js +1 -1
- package/lib/geocoder.cjs.prod.js.map +1 -1
- package/lib/geocoder.esm-browser.js +1445 -817
- package/lib/geocoder.esm-browser.js.map +1 -1
- package/lib/geocoder.esm-browser.prod.js +1 -1
- package/lib/geocoder.esm-browser.prod.js.map +1 -1
- package/lib/geocoder.esm-bundler.js +91 -82
- package/lib/geocoder.esm-bundler.js.map +1 -1
- package/lib/geocoder.esm-bundler.prod.js +1 -1
- package/lib/geocoder.esm-bundler.prod.js.map +1 -1
- package/lib/geocoder.global.js +1445 -817
- package/lib/geocoder.global.js.map +1 -1
- package/lib/geocoder.global.prod.js +1 -1
- package/lib/geocoder.global.prod.js.map +1 -1
- package/lib/index.d.ts +25 -6
- package/package.json +7 -7
package/lib/geocoder.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 3.0.0-alpha.9; author: NextGIS */
|
|
2
2
|
var Geocoder = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -107,28 +107,28 @@ var Geocoder = (function (exports) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
var __defProp$
|
|
111
|
-
var __defProps$
|
|
112
|
-
var __getOwnPropDescs$
|
|
113
|
-
var __getOwnPropSymbols$
|
|
114
|
-
var __hasOwnProp$
|
|
115
|
-
var __propIsEnum$
|
|
110
|
+
var __defProp$i = Object.defineProperty;
|
|
111
|
+
var __defProps$5 = Object.defineProperties;
|
|
112
|
+
var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
|
|
113
|
+
var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
|
|
114
|
+
var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
|
|
115
|
+
var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
|
|
116
116
|
var __knownSymbol$2 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
117
|
-
var __defNormalProp$
|
|
118
|
-
var __spreadValues$
|
|
117
|
+
var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
118
|
+
var __spreadValues$8 = (a, b) => {
|
|
119
119
|
for (var prop in b || (b = {}))
|
|
120
|
-
if (__hasOwnProp$
|
|
121
|
-
__defNormalProp$
|
|
122
|
-
if (__getOwnPropSymbols$
|
|
123
|
-
for (var prop of __getOwnPropSymbols$
|
|
124
|
-
if (__propIsEnum$
|
|
125
|
-
__defNormalProp$
|
|
120
|
+
if (__hasOwnProp$8.call(b, prop))
|
|
121
|
+
__defNormalProp$i(a, prop, b[prop]);
|
|
122
|
+
if (__getOwnPropSymbols$8)
|
|
123
|
+
for (var prop of __getOwnPropSymbols$8(b)) {
|
|
124
|
+
if (__propIsEnum$8.call(b, prop))
|
|
125
|
+
__defNormalProp$i(a, prop, b[prop]);
|
|
126
126
|
}
|
|
127
127
|
return a;
|
|
128
128
|
};
|
|
129
|
-
var __spreadProps$
|
|
130
|
-
var __publicField$
|
|
131
|
-
var __async$
|
|
129
|
+
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
130
|
+
var __publicField$d = (obj, key, value) => __defNormalProp$i(obj, key + "" , value);
|
|
131
|
+
var __async$7 = (__this, __arguments, generator) => {
|
|
132
132
|
return new Promise((resolve, reject) => {
|
|
133
133
|
var fulfilled = (value) => {
|
|
134
134
|
try {
|
|
@@ -168,7 +168,7 @@ var Geocoder = (function (exports) {
|
|
|
168
168
|
class Geocoder extends BaseGeocoder {
|
|
169
169
|
constructor(options) {
|
|
170
170
|
super(options);
|
|
171
|
-
__publicField$
|
|
171
|
+
__publicField$d(this, "providers", []);
|
|
172
172
|
if (options && options.providers) {
|
|
173
173
|
this.providers = options.providers;
|
|
174
174
|
}
|
|
@@ -192,7 +192,7 @@ var Geocoder = (function (exports) {
|
|
|
192
192
|
for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
|
|
193
193
|
const r = temp.value;
|
|
194
194
|
allProvidersFailed = false;
|
|
195
|
-
yield __spreadProps$
|
|
195
|
+
yield __spreadProps$5(__spreadValues$8({}, r), { provider, _id: ID$1++ });
|
|
196
196
|
}
|
|
197
197
|
} catch (temp) {
|
|
198
198
|
error = [temp];
|
|
@@ -206,7 +206,7 @@ var Geocoder = (function (exports) {
|
|
|
206
206
|
}
|
|
207
207
|
} catch (err) {
|
|
208
208
|
const er = err;
|
|
209
|
-
if (er.name !== "
|
|
209
|
+
if (er.name !== "AbortError") {
|
|
210
210
|
errors.push(er);
|
|
211
211
|
}
|
|
212
212
|
}
|
|
@@ -235,7 +235,7 @@ var Geocoder = (function (exports) {
|
|
|
235
235
|
try {
|
|
236
236
|
for (var iter = __forAwait(results), more, temp, error; more = !(temp = yield new __await$2(iter.next())).done; more = false) {
|
|
237
237
|
const r = temp.value;
|
|
238
|
-
yield __spreadProps$
|
|
238
|
+
yield __spreadProps$5(__spreadValues$8({}, r), { provider, _id: ID$1++ });
|
|
239
239
|
}
|
|
240
240
|
} catch (temp) {
|
|
241
241
|
error = [temp];
|
|
@@ -259,7 +259,7 @@ var Geocoder = (function (exports) {
|
|
|
259
259
|
* @returns A promise that resolves to the first reverse geocoding result, or undefined if no results are found.
|
|
260
260
|
*/
|
|
261
261
|
reverseGeocodeFirstResult(coordinates) {
|
|
262
|
-
return __async$
|
|
262
|
+
return __async$7(this, null, function* () {
|
|
263
263
|
for (const provider of this.providers) {
|
|
264
264
|
if (typeof provider.reverse === "function") {
|
|
265
265
|
try {
|
|
@@ -288,9 +288,9 @@ var Geocoder = (function (exports) {
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
var __defProp$
|
|
292
|
-
var __defNormalProp$
|
|
293
|
-
var __publicField$
|
|
291
|
+
var __defProp$h = Object.defineProperty;
|
|
292
|
+
var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
293
|
+
var __publicField$c = (obj, key, value) => __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
294
294
|
class BaseProvider extends BaseGeocoder {
|
|
295
295
|
constructor() {
|
|
296
296
|
super(...arguments);
|
|
@@ -298,12 +298,12 @@ var Geocoder = (function (exports) {
|
|
|
298
298
|
* URL endpoint for the search service.
|
|
299
299
|
* This is where queries will be sent to obtain search results.
|
|
300
300
|
*/
|
|
301
|
-
__publicField$
|
|
301
|
+
__publicField$c(this, "searchUrl");
|
|
302
302
|
/**
|
|
303
303
|
* Label to represent the provider.
|
|
304
304
|
* Useful for user interfaces to display the source of search results.
|
|
305
305
|
*/
|
|
306
|
-
__publicField$
|
|
306
|
+
__publicField$c(this, "label");
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
|
@@ -337,7 +337,7 @@ var Geocoder = (function (exports) {
|
|
|
337
337
|
this.domain = null;
|
|
338
338
|
if (EventEmitter.usingDomains) {
|
|
339
339
|
// if there is an active domain, then attach to it.
|
|
340
|
-
if (domain.active
|
|
340
|
+
if (domain.active) ;
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
|
|
@@ -779,12 +779,12 @@ var Geocoder = (function (exports) {
|
|
|
779
779
|
return ret;
|
|
780
780
|
}
|
|
781
781
|
|
|
782
|
-
var __defProp$
|
|
783
|
-
var __defNormalProp$
|
|
784
|
-
var __publicField$
|
|
782
|
+
var __defProp$g = Object.defineProperty;
|
|
783
|
+
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
784
|
+
var __publicField$b = (obj, key, value) => __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
785
785
|
const _Cache = class _Cache {
|
|
786
786
|
constructor(options = {}) {
|
|
787
|
-
__publicField$
|
|
787
|
+
__publicField$b(this, "cache", []);
|
|
788
788
|
var _a;
|
|
789
789
|
const namespace = (_a = options.namespace) != null ? _a : "default";
|
|
790
790
|
if (_Cache.instance[namespace]) {
|
|
@@ -820,10 +820,23 @@ var Geocoder = (function (exports) {
|
|
|
820
820
|
* });
|
|
821
821
|
* ```
|
|
822
822
|
*/
|
|
823
|
-
addFull(key, valueToSet,
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
823
|
+
addFull(key, valueToSet, propsOrOptions, expirationTime) {
|
|
824
|
+
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
825
|
+
propsOrOptions.onlyFull = true;
|
|
826
|
+
}
|
|
827
|
+
return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
|
|
828
|
+
}
|
|
829
|
+
add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
|
|
830
|
+
let opt;
|
|
831
|
+
let props;
|
|
832
|
+
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
833
|
+
opt = propsOrOptions;
|
|
834
|
+
onlyFull = opt.onlyFull;
|
|
835
|
+
expirationTime = opt.expirationTime;
|
|
836
|
+
props = opt.props;
|
|
837
|
+
} else {
|
|
838
|
+
props = propsOrOptions;
|
|
839
|
+
}
|
|
827
840
|
const exist = this._find(key, props);
|
|
828
841
|
if (!exist) {
|
|
829
842
|
let value;
|
|
@@ -833,10 +846,12 @@ var Geocoder = (function (exports) {
|
|
|
833
846
|
value = valueToSet;
|
|
834
847
|
}
|
|
835
848
|
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
849
|
+
expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
|
|
836
850
|
const cacheItem = {
|
|
837
851
|
key,
|
|
838
852
|
value,
|
|
839
|
-
props: nonEmptyProps
|
|
853
|
+
props: nonEmptyProps,
|
|
854
|
+
expirationTime
|
|
840
855
|
};
|
|
841
856
|
if (onlyFull && !full(value)) {
|
|
842
857
|
return value;
|
|
@@ -863,9 +878,19 @@ var Geocoder = (function (exports) {
|
|
|
863
878
|
}
|
|
864
879
|
match(key, props) {
|
|
865
880
|
const cacheRecord = this._find(key, props);
|
|
881
|
+
if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
|
|
882
|
+
this.delete(cacheRecord);
|
|
883
|
+
return void 0;
|
|
884
|
+
}
|
|
866
885
|
return cacheRecord == null ? void 0 : cacheRecord.value;
|
|
867
886
|
}
|
|
868
887
|
matchAll(key, props) {
|
|
888
|
+
const now = Date.now();
|
|
889
|
+
this.cache.forEach((item) => {
|
|
890
|
+
if (item.expirationTime && now > item.expirationTime) {
|
|
891
|
+
this.delete(item);
|
|
892
|
+
}
|
|
893
|
+
});
|
|
869
894
|
if (key) {
|
|
870
895
|
return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
|
|
871
896
|
}
|
|
@@ -890,31 +915,159 @@ var Geocoder = (function (exports) {
|
|
|
890
915
|
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
891
916
|
}
|
|
892
917
|
};
|
|
893
|
-
__publicField$
|
|
918
|
+
__publicField$b(_Cache, "instance", {});
|
|
894
919
|
let Cache = _Cache;
|
|
895
920
|
|
|
896
|
-
var
|
|
897
|
-
|
|
898
|
-
|
|
921
|
+
var pkg = {
|
|
922
|
+
name: "@nextgis/ngw-connector",
|
|
923
|
+
version: "3.0.0-alpha.8",
|
|
924
|
+
_priority: 12,
|
|
925
|
+
description: "A lightweight HTTP client optimized for use with NextGIS Web API",
|
|
926
|
+
main: "index.js",
|
|
927
|
+
module: "lib/ngw-connector.esm-bundler.js",
|
|
928
|
+
unpkg: "lib/ngw-connector.global.prod.js",
|
|
929
|
+
jsdelivr: "lib/ngw-connector.global.prod.js",
|
|
930
|
+
types: "lib/index.d.ts",
|
|
931
|
+
dependencies: {
|
|
932
|
+
"@nextgis/cache": "^3.0.0-alpha.7",
|
|
933
|
+
"@nextgis/cancelable-promise": "^3.0.0-alpha.5",
|
|
934
|
+
"@nextgis/utils": "^3.0.0-alpha.5",
|
|
935
|
+
"@types/events": "^3.0.0",
|
|
936
|
+
events: "*",
|
|
937
|
+
"form-data": "^4.0.0"
|
|
938
|
+
},
|
|
939
|
+
devDependencies: {
|
|
940
|
+
"@nextgis/build-tools": "^3.0.0-alpha.5"
|
|
941
|
+
},
|
|
942
|
+
scripts: {
|
|
943
|
+
clean: "rimraf ./lib",
|
|
944
|
+
dev: "node ../build-tools/lib/build.js",
|
|
945
|
+
prod: "npm run dev -- --release",
|
|
946
|
+
lint: "eslint ./src/**/*.ts --fix --c ../../.eslintrc",
|
|
947
|
+
watch: "npm run dev -- --watch",
|
|
948
|
+
"gen:types": "node ./scripts/generator"
|
|
949
|
+
},
|
|
950
|
+
buildOptions: {
|
|
951
|
+
name: "NgwConnector",
|
|
952
|
+
formats: [
|
|
953
|
+
"esm-bundler",
|
|
954
|
+
"esm-browser",
|
|
955
|
+
"cjs",
|
|
956
|
+
"global"
|
|
957
|
+
]
|
|
958
|
+
},
|
|
959
|
+
keywords: [
|
|
960
|
+
"NextGIS",
|
|
961
|
+
"MAP"
|
|
962
|
+
],
|
|
963
|
+
author: "NextGIS",
|
|
964
|
+
files: [
|
|
965
|
+
"index.js",
|
|
966
|
+
"lib"
|
|
967
|
+
],
|
|
968
|
+
license: "MIT",
|
|
969
|
+
homepage: "https://github.com/nextgis/nextgis_frontend/tree/master/packages/ngw-connector#readme",
|
|
970
|
+
repository: {
|
|
971
|
+
type: "git",
|
|
972
|
+
url: "git://github.com/nextgis/nextgis_frontend.git"
|
|
973
|
+
},
|
|
974
|
+
engines: {
|
|
975
|
+
node: ">=18.20.4"
|
|
976
|
+
},
|
|
977
|
+
gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
const CONNECTORS = [];
|
|
981
|
+
function addConnector(connector) {
|
|
982
|
+
CONNECTORS.push(connector);
|
|
983
|
+
}
|
|
984
|
+
function findConnector(options) {
|
|
985
|
+
return CONNECTORS.find((x) => {
|
|
986
|
+
if (x.options.baseUrl === options.baseUrl) {
|
|
987
|
+
if (options.auth) {
|
|
988
|
+
if (x.options.auth) {
|
|
989
|
+
return objectDeepEqual(x.options.auth, options.auth);
|
|
990
|
+
}
|
|
991
|
+
} else {
|
|
992
|
+
return true;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
function removeConnector(connector) {
|
|
998
|
+
const index = CONNECTORS.indexOf(connector);
|
|
999
|
+
if (index !== -1) {
|
|
1000
|
+
CONNECTORS.splice(index, 1);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
class AbortError extends Error {
|
|
1005
|
+
constructor(message = "AbortError") {
|
|
1006
|
+
super(message);
|
|
1007
|
+
this.name = "AbortError";
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
var __defProp$f = Object.defineProperty;
|
|
1012
|
+
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1013
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
899
1014
|
class NgwError extends Error {
|
|
900
1015
|
constructor(er) {
|
|
901
1016
|
super();
|
|
902
|
-
__publicField$
|
|
903
|
-
__publicField$
|
|
904
|
-
__publicField$
|
|
905
|
-
__publicField$
|
|
906
|
-
__publicField$
|
|
907
|
-
__publicField$
|
|
908
|
-
__publicField$
|
|
909
|
-
__publicField$
|
|
1017
|
+
__publicField$a(this, "name", "NgwError");
|
|
1018
|
+
__publicField$a(this, "title");
|
|
1019
|
+
__publicField$a(this, "message");
|
|
1020
|
+
__publicField$a(this, "detail");
|
|
1021
|
+
__publicField$a(this, "exception");
|
|
1022
|
+
__publicField$a(this, "status_code");
|
|
1023
|
+
__publicField$a(this, "data");
|
|
1024
|
+
__publicField$a(this, "guru_meditation");
|
|
910
1025
|
Object.assign(this, er);
|
|
911
1026
|
Object.setPrototypeOf(this, NgwError.prototype);
|
|
912
1027
|
}
|
|
913
1028
|
}
|
|
914
1029
|
|
|
915
|
-
var __defProp$
|
|
916
|
-
var __defNormalProp$
|
|
917
|
-
var __publicField$
|
|
1030
|
+
var __defProp$e = Object.defineProperty;
|
|
1031
|
+
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1032
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1033
|
+
class InsufficientPermissionsError extends NgwError {
|
|
1034
|
+
constructor(obj) {
|
|
1035
|
+
super(obj);
|
|
1036
|
+
__publicField$9(this, "name", "InsufficientPermissionsError");
|
|
1037
|
+
__publicField$9(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
|
|
1038
|
+
Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
var __defProp$d = Object.defineProperty;
|
|
1043
|
+
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1044
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$d(obj, key + "" , value);
|
|
1045
|
+
class NetworkError extends Error {
|
|
1046
|
+
constructor(url) {
|
|
1047
|
+
super();
|
|
1048
|
+
__publicField$8(this, "name", "NetworkError");
|
|
1049
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
1050
|
+
this.message = `Unable to request ${url}.
|
|
1051
|
+
Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
var __defProp$c = Object.defineProperty;
|
|
1056
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1057
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1058
|
+
let NetworksResponseError$1 = class NetworksResponseError extends NgwError {
|
|
1059
|
+
constructor(obj) {
|
|
1060
|
+
super(obj);
|
|
1061
|
+
__publicField$7(this, "message", "There is no response from the server or problem connecting to server.");
|
|
1062
|
+
__publicField$7(this, "title", "Network error");
|
|
1063
|
+
__publicField$7(this, "detail", "Check network connectivity and try again later.");
|
|
1064
|
+
Object.setPrototypeOf(this, NetworksResponseError.prototype);
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
var __defProp$b = Object.defineProperty;
|
|
1069
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1070
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
918
1071
|
class ResourceNotFoundError extends NgwError {
|
|
919
1072
|
constructor(obj) {
|
|
920
1073
|
super(obj);
|
|
@@ -924,53 +1077,143 @@ var Geocoder = (function (exports) {
|
|
|
924
1077
|
}
|
|
925
1078
|
}
|
|
926
1079
|
|
|
927
|
-
function
|
|
928
|
-
|
|
1080
|
+
function isError(error) {
|
|
1081
|
+
if (isObject$1(error)) {
|
|
1082
|
+
return error.status_code && error.exception && error.title;
|
|
1083
|
+
}
|
|
1084
|
+
return false;
|
|
929
1085
|
}
|
|
930
1086
|
|
|
931
|
-
function
|
|
932
|
-
|
|
1087
|
+
function extractError(error) {
|
|
1088
|
+
if (isObject$1(error)) {
|
|
1089
|
+
if (error.name && error.message && error.title) {
|
|
1090
|
+
return {
|
|
1091
|
+
title: error.title,
|
|
1092
|
+
message: error.message,
|
|
1093
|
+
detail: error.detail || null,
|
|
1094
|
+
data: error.data && error.data.data ? error.data.data : null
|
|
1095
|
+
};
|
|
1096
|
+
} else if (error.exception) {
|
|
1097
|
+
if (error.status === void 0 || error.status === 0 || error.data === void 0) {
|
|
1098
|
+
return new NetworksResponseError$1({
|
|
1099
|
+
title: error.title,
|
|
1100
|
+
status_code: error.status_code,
|
|
1101
|
+
exception: error.exception
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return {
|
|
1106
|
+
title: typeof error.title === "string" ? error.title : "Unexpected error",
|
|
1107
|
+
message: typeof error.message === "string" ? error.message : "Something went wrong."
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
933
1110
|
}
|
|
934
1111
|
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1112
|
+
var errors = /*#__PURE__*/Object.freeze({
|
|
1113
|
+
__proto__: null,
|
|
1114
|
+
AbortError: AbortError,
|
|
1115
|
+
InsufficientPermissionsError: InsufficientPermissionsError,
|
|
1116
|
+
NetworkError: NetworkError,
|
|
1117
|
+
NetworksResponseError: NetworksResponseError$1,
|
|
1118
|
+
NgwError: NgwError,
|
|
1119
|
+
ResourceNotFoundError: ResourceNotFoundError,
|
|
1120
|
+
extractError: extractError,
|
|
1121
|
+
isError: isError
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
var __defProp$a = Object.defineProperty;
|
|
1125
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1126
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1127
|
+
class BaseAPIError extends Error {
|
|
1128
|
+
constructor(message) {
|
|
1129
|
+
super(message || "Something went wrong.");
|
|
1130
|
+
__publicField$5(this, "title");
|
|
1131
|
+
this.name = "BaseAPIError";
|
|
1132
|
+
this.title = "Unknown API error";
|
|
1133
|
+
if (Error.captureStackTrace) {
|
|
1134
|
+
Error.captureStackTrace(this, BaseAPIError);
|
|
951
1135
|
}
|
|
952
1136
|
}
|
|
953
|
-
|
|
1137
|
+
}
|
|
1138
|
+
class NetworksResponseError extends BaseAPIError {
|
|
1139
|
+
// prettier-ignore
|
|
1140
|
+
constructor(message) {
|
|
1141
|
+
super(message || "There is no response from the server or problem connecting to server.");
|
|
1142
|
+
__publicField$5(this, "detail");
|
|
1143
|
+
this.title = "Network error";
|
|
1144
|
+
this.detail = "Check network connectivity and try again later.";
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
class InvalidResponseError extends BaseAPIError {
|
|
1148
|
+
constructor(message) {
|
|
1149
|
+
super(message || "Something went wrong.");
|
|
1150
|
+
this.title = "Unexpected server response";
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
class ServerResponseError extends BaseAPIError {
|
|
1154
|
+
constructor(data) {
|
|
1155
|
+
super(data.message);
|
|
1156
|
+
__publicField$5(this, "detail");
|
|
1157
|
+
__publicField$5(this, "data");
|
|
1158
|
+
this.title = data.title || this.title;
|
|
1159
|
+
this.detail = data.detail || null;
|
|
1160
|
+
this.data = data;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
class LunkwillError extends Error {
|
|
1164
|
+
// prettier-ignore
|
|
1165
|
+
constructor(message, data = {}) {
|
|
1166
|
+
super(message || "Unexpected error while processing long-running request.");
|
|
1167
|
+
__publicField$5(this, "title");
|
|
1168
|
+
__publicField$5(this, "data");
|
|
1169
|
+
this.name = "LunkwillError";
|
|
1170
|
+
this.title = "Long-running request error";
|
|
1171
|
+
this.data = data;
|
|
1172
|
+
if (Error.captureStackTrace) {
|
|
1173
|
+
Error.captureStackTrace(this, LunkwillError);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
class LunkwillRequestCancelled extends LunkwillError {
|
|
1178
|
+
constructor(data) {
|
|
1179
|
+
super("Long-running request was cancelled.", data);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
class LunkwillRequestFailed extends LunkwillError {
|
|
1183
|
+
constructor(data) {
|
|
1184
|
+
super(void 0, data);
|
|
1185
|
+
}
|
|
954
1186
|
}
|
|
955
1187
|
|
|
956
|
-
var __defProp$
|
|
957
|
-
var __getOwnPropSymbols$
|
|
958
|
-
var __hasOwnProp$
|
|
959
|
-
var __propIsEnum$
|
|
960
|
-
var __defNormalProp$
|
|
961
|
-
var __spreadValues$
|
|
1188
|
+
var __defProp$9 = Object.defineProperty;
|
|
1189
|
+
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
1190
|
+
var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
|
|
1191
|
+
var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
|
|
1192
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1193
|
+
var __spreadValues$7 = (a, b) => {
|
|
962
1194
|
for (var prop in b || (b = {}))
|
|
963
|
-
if (__hasOwnProp$
|
|
964
|
-
__defNormalProp$
|
|
965
|
-
if (__getOwnPropSymbols$
|
|
966
|
-
for (var prop of __getOwnPropSymbols$
|
|
967
|
-
if (__propIsEnum$
|
|
968
|
-
__defNormalProp$
|
|
1195
|
+
if (__hasOwnProp$7.call(b, prop))
|
|
1196
|
+
__defNormalProp$9(a, prop, b[prop]);
|
|
1197
|
+
if (__getOwnPropSymbols$7)
|
|
1198
|
+
for (var prop of __getOwnPropSymbols$7(b)) {
|
|
1199
|
+
if (__propIsEnum$7.call(b, prop))
|
|
1200
|
+
__defNormalProp$9(a, prop, b[prop]);
|
|
969
1201
|
}
|
|
970
1202
|
return a;
|
|
971
1203
|
};
|
|
972
|
-
var
|
|
973
|
-
|
|
1204
|
+
var __objRest$2 = (source, exclude) => {
|
|
1205
|
+
var target = {};
|
|
1206
|
+
for (var prop in source)
|
|
1207
|
+
if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1208
|
+
target[prop] = source[prop];
|
|
1209
|
+
if (source != null && __getOwnPropSymbols$7)
|
|
1210
|
+
for (var prop of __getOwnPropSymbols$7(source)) {
|
|
1211
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
|
|
1212
|
+
target[prop] = source[prop];
|
|
1213
|
+
}
|
|
1214
|
+
return target;
|
|
1215
|
+
};
|
|
1216
|
+
var __async$6 = (__this, __arguments, generator) => {
|
|
974
1217
|
return new Promise((resolve, reject) => {
|
|
975
1218
|
var fulfilled = (value) => {
|
|
976
1219
|
try {
|
|
@@ -990,94 +1233,935 @@ var Geocoder = (function (exports) {
|
|
|
990
1233
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
991
1234
|
});
|
|
992
1235
|
};
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1236
|
+
function lunkwillCheckResponse(lwResp) {
|
|
1237
|
+
const ct = lwResp.headers.get("content-type");
|
|
1238
|
+
return ct !== void 0 && ct !== null && ct.includes("application/vnd.lunkwill.request-summary+json");
|
|
1239
|
+
}
|
|
1240
|
+
function responseJson(response) {
|
|
1241
|
+
return __async$6(this, null, function* () {
|
|
1242
|
+
try {
|
|
1243
|
+
return response.json();
|
|
1244
|
+
} catch (e) {
|
|
1245
|
+
throw new Error();
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
function lunkwillResponseUrl(lwResp) {
|
|
1250
|
+
return __async$6(this, null, function* () {
|
|
1251
|
+
const lwData = yield responseJson(lwResp);
|
|
1252
|
+
let delay = lwData.delay_ms;
|
|
1253
|
+
const retry = lwData.retry_ms !== void 0 ? lwData.retry_ms : 2e3;
|
|
1254
|
+
const sum = `/api/lunkwill/${lwData.id}/summary`;
|
|
1255
|
+
const res = `/api/lunkwill/${lwData.id}/response`;
|
|
1256
|
+
const sleep = (msec) => new Promise((resolve) => setTimeout(resolve, msec));
|
|
1257
|
+
let failed = false;
|
|
1258
|
+
let ready = false;
|
|
1259
|
+
while (!ready) {
|
|
1260
|
+
yield sleep(failed ? retry : delay);
|
|
1261
|
+
failed = false;
|
|
1262
|
+
let lwResp2;
|
|
1263
|
+
let lwData2;
|
|
1264
|
+
try {
|
|
1265
|
+
lwResp2 = yield fetch(sum, { credentials: "same-origin" });
|
|
1266
|
+
lwData2 = yield lwResp2.json();
|
|
1267
|
+
} catch (e) {
|
|
1268
|
+
failed = true;
|
|
1269
|
+
continue;
|
|
1270
|
+
}
|
|
1271
|
+
switch (lwData2.status) {
|
|
1272
|
+
case void 0:
|
|
1273
|
+
throw new LunkwillError(void 0, lwData2);
|
|
1274
|
+
case "ready":
|
|
1275
|
+
ready = true;
|
|
1276
|
+
break;
|
|
1277
|
+
case "cancelled":
|
|
1278
|
+
throw new LunkwillRequestCancelled(lwData2);
|
|
1279
|
+
case "failed":
|
|
1280
|
+
throw new LunkwillRequestFailed(lwData2);
|
|
1281
|
+
case "spooled":
|
|
1282
|
+
case "processing":
|
|
1283
|
+
case "buffering":
|
|
1284
|
+
delay = lwData2.delay_ms;
|
|
1285
|
+
break;
|
|
1286
|
+
default:
|
|
1287
|
+
throw new LunkwillError(void 0, lwData2);
|
|
1025
1288
|
}
|
|
1026
1289
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1290
|
+
return res;
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
function lunkwillFetch(lwRespUrl) {
|
|
1294
|
+
return __async$6(this, null, function* () {
|
|
1295
|
+
try {
|
|
1296
|
+
return yield window.fetch(lwRespUrl, { credentials: "same-origin" });
|
|
1297
|
+
} catch (e) {
|
|
1298
|
+
throw new NetworksResponseError();
|
|
1033
1299
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
if (
|
|
1060
|
-
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
const mediaContentTypes = [
|
|
1303
|
+
"application/pdf",
|
|
1304
|
+
"image/png",
|
|
1305
|
+
"image/jpeg",
|
|
1306
|
+
"image/tiff",
|
|
1307
|
+
"text/csv"
|
|
1308
|
+
];
|
|
1309
|
+
const mediaContentTypesRegex = new RegExp(mediaContentTypes.join("|"));
|
|
1310
|
+
function isMediaContentType(contentType) {
|
|
1311
|
+
return mediaContentTypesRegex.test(contentType);
|
|
1312
|
+
}
|
|
1313
|
+
function encodeQueryParams(value) {
|
|
1314
|
+
const result = [];
|
|
1315
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1316
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
1317
|
+
result.push(`${k}=${encodeURIComponent(v)}`);
|
|
1318
|
+
} else if (Array.isArray(v)) {
|
|
1319
|
+
result.push(`${k}=${v.map(encodeURIComponent).join(",")}`);
|
|
1320
|
+
} else {
|
|
1321
|
+
for (const [sk, sv] of Object.entries(v)) {
|
|
1322
|
+
const ske = `${k}[${encodeURIComponent(sk)}]`;
|
|
1323
|
+
if (typeof sv === "string" || typeof sv === "number" || typeof sv === "boolean") {
|
|
1324
|
+
result.push(`${ske}=${encodeURIComponent(sv)}`);
|
|
1325
|
+
} else if (Array.isArray(sv)) {
|
|
1326
|
+
const sve = sv.map(encodeURIComponent);
|
|
1327
|
+
result.push(`${ske}=${sve.join(",")}`);
|
|
1061
1328
|
}
|
|
1062
|
-
}
|
|
1329
|
+
}
|
|
1063
1330
|
}
|
|
1064
|
-
return Promise.resolve(void 0);
|
|
1065
1331
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1332
|
+
return result.join("&");
|
|
1333
|
+
}
|
|
1334
|
+
function generateUrl(path, query) {
|
|
1335
|
+
let urlParams = "";
|
|
1336
|
+
if (query !== void 0) {
|
|
1337
|
+
urlParams = "?" + encodeQueryParams(query);
|
|
1338
|
+
}
|
|
1339
|
+
return path + urlParams;
|
|
1340
|
+
}
|
|
1341
|
+
function request(path, options, cacheEngine) {
|
|
1342
|
+
return __async$6(this, null, function* () {
|
|
1343
|
+
var _b;
|
|
1344
|
+
const defaults = {
|
|
1345
|
+
method: "GET",
|
|
1346
|
+
credentials: "same-origin",
|
|
1347
|
+
headers: {}
|
|
1348
|
+
};
|
|
1349
|
+
const _a = __spreadValues$7(__spreadValues$7({}, defaults), options), {
|
|
1350
|
+
withCredentials,
|
|
1351
|
+
responseType,
|
|
1352
|
+
cacheProps,
|
|
1353
|
+
cacheName,
|
|
1354
|
+
lunkwill,
|
|
1355
|
+
cache,
|
|
1356
|
+
query,
|
|
1357
|
+
json
|
|
1358
|
+
} = _a, opt = __objRest$2(_a, [
|
|
1359
|
+
"withCredentials",
|
|
1360
|
+
"responseType",
|
|
1361
|
+
"cacheProps",
|
|
1362
|
+
"cacheName",
|
|
1363
|
+
"lunkwill",
|
|
1364
|
+
"cache",
|
|
1365
|
+
"query",
|
|
1366
|
+
"json"
|
|
1367
|
+
]);
|
|
1368
|
+
if (withCredentials) {
|
|
1369
|
+
opt.credentials = "include";
|
|
1370
|
+
}
|
|
1371
|
+
let useLunkwill = false;
|
|
1372
|
+
if (lunkwill !== void 0) {
|
|
1373
|
+
lunkwill.toHeaders(opt.headers || {});
|
|
1374
|
+
useLunkwill = true;
|
|
1375
|
+
}
|
|
1376
|
+
const lunkwillReturnUrl = !!opt.lunkwillReturnUrl;
|
|
1377
|
+
delete opt.lunkwillReturnUrl;
|
|
1378
|
+
if (json !== void 0) {
|
|
1379
|
+
opt.body = JSON.stringify(json);
|
|
1380
|
+
const headers = opt.headers || {};
|
|
1381
|
+
headers["Content-Type"] = "application/json";
|
|
1382
|
+
opt.headers = headers;
|
|
1383
|
+
}
|
|
1384
|
+
const url = generateUrl(path, query);
|
|
1385
|
+
const makeRequest = () => __async$6(this, null, function* () {
|
|
1386
|
+
let response;
|
|
1387
|
+
try {
|
|
1388
|
+
response = yield fetch(url, opt);
|
|
1389
|
+
} catch (e) {
|
|
1390
|
+
if (opt.signal && opt.signal.aborted) {
|
|
1391
|
+
throw e;
|
|
1392
|
+
}
|
|
1393
|
+
throw new NetworksResponseError();
|
|
1394
|
+
}
|
|
1395
|
+
if (useLunkwill && lunkwillCheckResponse(response)) {
|
|
1396
|
+
const lwRespUrl = yield lunkwillResponseUrl(response);
|
|
1397
|
+
if (lunkwillReturnUrl) {
|
|
1398
|
+
return lwRespUrl;
|
|
1399
|
+
}
|
|
1400
|
+
response = yield lunkwillFetch(lwRespUrl);
|
|
1401
|
+
}
|
|
1402
|
+
const respCType = response.headers.get("content-type");
|
|
1403
|
+
const respJSON = respCType && (respCType.includes("application/json") || respCType.includes("application/vnd.lunkwill.request-summary+json"));
|
|
1404
|
+
let body;
|
|
1405
|
+
try {
|
|
1406
|
+
const respMedia = respCType && isMediaContentType(respCType);
|
|
1407
|
+
if (responseType === "blob" || respMedia) {
|
|
1408
|
+
body = yield response.blob();
|
|
1409
|
+
} else if (respJSON) {
|
|
1410
|
+
body = yield response.json();
|
|
1411
|
+
} else {
|
|
1412
|
+
throw new InvalidResponseError();
|
|
1413
|
+
}
|
|
1414
|
+
} catch (e) {
|
|
1415
|
+
if (e.name === "AbortError" || e instanceof InvalidResponseError) {
|
|
1416
|
+
throw e;
|
|
1417
|
+
}
|
|
1418
|
+
throw new InvalidResponseError();
|
|
1419
|
+
}
|
|
1420
|
+
if (400 <= response.status && response.status <= 599) {
|
|
1421
|
+
throw new ServerResponseError(body);
|
|
1422
|
+
}
|
|
1423
|
+
return body;
|
|
1424
|
+
});
|
|
1425
|
+
if (cacheEngine && ((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
|
|
1426
|
+
const props = cacheProps ? cacheProps : __spreadValues$7({}, objectRemoveEmpty({
|
|
1427
|
+
withCredentials,
|
|
1428
|
+
responseType
|
|
1429
|
+
}));
|
|
1430
|
+
return cacheEngine.add(cacheName || url, makeRequest, {
|
|
1431
|
+
props,
|
|
1432
|
+
expirationTime: cache ? void 0 : 500
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
return makeRequest();
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
var __defProp$8 = Object.defineProperty;
|
|
1440
|
+
var __defProps$4 = Object.defineProperties;
|
|
1441
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
1442
|
+
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
1443
|
+
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
1444
|
+
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
1445
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1446
|
+
var __spreadValues$6 = (a, b) => {
|
|
1447
|
+
for (var prop in b || (b = {}))
|
|
1448
|
+
if (__hasOwnProp$6.call(b, prop))
|
|
1449
|
+
__defNormalProp$8(a, prop, b[prop]);
|
|
1450
|
+
if (__getOwnPropSymbols$6)
|
|
1451
|
+
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
1452
|
+
if (__propIsEnum$6.call(b, prop))
|
|
1453
|
+
__defNormalProp$8(a, prop, b[prop]);
|
|
1454
|
+
}
|
|
1455
|
+
return a;
|
|
1456
|
+
};
|
|
1457
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
1458
|
+
var __objRest$1 = (source, exclude) => {
|
|
1459
|
+
var target = {};
|
|
1460
|
+
for (var prop in source)
|
|
1461
|
+
if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1462
|
+
target[prop] = source[prop];
|
|
1463
|
+
if (source != null && __getOwnPropSymbols$6)
|
|
1464
|
+
for (var prop of __getOwnPropSymbols$6(source)) {
|
|
1465
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
|
|
1466
|
+
target[prop] = source[prop];
|
|
1467
|
+
}
|
|
1468
|
+
return target;
|
|
1469
|
+
};
|
|
1470
|
+
var __async$5 = (__this, __arguments, generator) => {
|
|
1471
|
+
return new Promise((resolve, reject) => {
|
|
1472
|
+
var fulfilled = (value) => {
|
|
1473
|
+
try {
|
|
1474
|
+
step(generator.next(value));
|
|
1475
|
+
} catch (e) {
|
|
1476
|
+
reject(e);
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
var rejected = (value) => {
|
|
1480
|
+
try {
|
|
1481
|
+
step(generator.throw(value));
|
|
1482
|
+
} catch (e) {
|
|
1483
|
+
reject(e);
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
1487
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
1488
|
+
});
|
|
1489
|
+
};
|
|
1490
|
+
function routeURL(name, baseUrl, routeData, ...rest) {
|
|
1491
|
+
const [template, ...params] = routeData[name];
|
|
1492
|
+
const first = rest[0];
|
|
1493
|
+
let sub;
|
|
1494
|
+
if (first === void 0) {
|
|
1495
|
+
sub = [];
|
|
1496
|
+
} else if (typeof first === "object" && first !== null) {
|
|
1497
|
+
if (rest.length > 1) {
|
|
1498
|
+
throw new Error("Too many arguments for route(name, object)!");
|
|
1499
|
+
}
|
|
1500
|
+
sub = [];
|
|
1501
|
+
for (const [p, v] of Object.entries(first)) {
|
|
1502
|
+
sub[params.indexOf(p)] = String(v);
|
|
1503
|
+
}
|
|
1504
|
+
} else {
|
|
1505
|
+
sub = rest.map((v) => String(v));
|
|
1506
|
+
}
|
|
1507
|
+
return fixUrlStr(
|
|
1508
|
+
baseUrl + template.replace(/\{(\w+)\}/g, function(m, a) {
|
|
1509
|
+
const idx = parseInt(a);
|
|
1510
|
+
const value = sub[idx];
|
|
1511
|
+
if (value === void 0) {
|
|
1512
|
+
const msg = `Undefined parameter ${idx} in "${template}".`;
|
|
1513
|
+
throw new Error(msg);
|
|
1514
|
+
}
|
|
1515
|
+
return String(value);
|
|
1516
|
+
})
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
function route(name, connector, ...rest) {
|
|
1520
|
+
const result = {
|
|
1521
|
+
url: (opt) => __async$5(this, null, function* () {
|
|
1522
|
+
var _a;
|
|
1523
|
+
const routeData = yield connector.connect();
|
|
1524
|
+
const template = routeURL(
|
|
1525
|
+
name,
|
|
1526
|
+
(_a = connector.options.baseUrl) != null ? _a : "",
|
|
1527
|
+
routeData,
|
|
1528
|
+
...rest
|
|
1529
|
+
);
|
|
1530
|
+
return generateUrl(template, opt == null ? void 0 : opt.query);
|
|
1531
|
+
})
|
|
1532
|
+
};
|
|
1533
|
+
const methods = ["get", "post", "put", "delete", "patch"];
|
|
1534
|
+
for (const method of methods) {
|
|
1535
|
+
const methodResp = (requestOptions) => __async$5(this, null, function* () {
|
|
1536
|
+
var _b;
|
|
1537
|
+
const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
|
|
1538
|
+
const routeData = yield connector.connect();
|
|
1539
|
+
const template = routeURL(
|
|
1540
|
+
name,
|
|
1541
|
+
(_b = connector.options.baseUrl) != null ? _b : "",
|
|
1542
|
+
routeData,
|
|
1543
|
+
...rest
|
|
1544
|
+
);
|
|
1545
|
+
const headers = objectRemoveEmpty(__spreadValues$6(__spreadValues$6({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
|
|
1546
|
+
return request(
|
|
1547
|
+
template,
|
|
1548
|
+
__spreadProps$4(__spreadValues$6({
|
|
1549
|
+
headers
|
|
1550
|
+
}, restOpt), {
|
|
1551
|
+
method
|
|
1552
|
+
}),
|
|
1553
|
+
connector.cache
|
|
1554
|
+
);
|
|
1555
|
+
});
|
|
1556
|
+
result[method] = methodResp;
|
|
1557
|
+
}
|
|
1558
|
+
return result;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
function isObject(val) {
|
|
1562
|
+
return Object.prototype.toString.call(val) === "[object Object]";
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
let loadData;
|
|
1566
|
+
{
|
|
1567
|
+
loadData = (url, callback, options = {}, error, onCancel) => {
|
|
1568
|
+
options.method = options.method || "GET";
|
|
1569
|
+
const xhr = new XMLHttpRequest();
|
|
1570
|
+
xhr.open(options.method || "GET", url, true);
|
|
1571
|
+
if (options.responseType === "blob") {
|
|
1572
|
+
xhr.responseType = options.responseType;
|
|
1573
|
+
}
|
|
1574
|
+
const getResponseText = () => {
|
|
1575
|
+
try {
|
|
1576
|
+
return JSON.parse(xhr.responseText);
|
|
1577
|
+
} catch (er) {
|
|
1578
|
+
return xhr.responseText;
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
const processingResponse = (forError = false) => {
|
|
1582
|
+
const cb = forError ? error : callback;
|
|
1583
|
+
if (options.responseType === "blob") {
|
|
1584
|
+
cb(xhr.response);
|
|
1585
|
+
} else {
|
|
1586
|
+
if (xhr.responseText) {
|
|
1587
|
+
cb(getResponseText());
|
|
1588
|
+
} else {
|
|
1589
|
+
error({ message: "" });
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
xhr.onload = () => {
|
|
1594
|
+
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1595
|
+
error(new NgwError(getResponseText()));
|
|
1596
|
+
}
|
|
1597
|
+
processingResponse();
|
|
1598
|
+
};
|
|
1599
|
+
xhr.onerror = (er) => {
|
|
1600
|
+
if (xhr.status === 0) {
|
|
1601
|
+
error(new NetworkError(url));
|
|
1602
|
+
} else {
|
|
1603
|
+
error(er);
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
xhr.upload.onprogress = function(e) {
|
|
1607
|
+
if (e.lengthComputable) {
|
|
1608
|
+
const percentComplete = e.loaded / e.total * 100;
|
|
1609
|
+
if (options.onProgress) {
|
|
1610
|
+
options.onProgress(percentComplete, e);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
const headers = options.headers;
|
|
1615
|
+
if (headers) {
|
|
1616
|
+
for (const h in headers) {
|
|
1617
|
+
const header = headers[h];
|
|
1618
|
+
if (typeof header === "string") {
|
|
1619
|
+
xhr.setRequestHeader(h, header);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
if (options.withCredentials !== void 0) {
|
|
1624
|
+
xhr.withCredentials = options.withCredentials;
|
|
1625
|
+
}
|
|
1626
|
+
let data;
|
|
1627
|
+
if (options.file) {
|
|
1628
|
+
data = new FormData();
|
|
1629
|
+
data.append("file", options.file);
|
|
1630
|
+
if (options.data) {
|
|
1631
|
+
for (const d in options.data) {
|
|
1632
|
+
data.append(d, data[d]);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
} else {
|
|
1636
|
+
data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
|
|
1637
|
+
}
|
|
1638
|
+
if (onCancel) {
|
|
1639
|
+
onCancel(() => {
|
|
1640
|
+
xhr.abort();
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
xhr.send(data);
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
const templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1648
|
+
function template(str, data) {
|
|
1649
|
+
return str.replace(templateRe, (s, key) => {
|
|
1650
|
+
let value = data[key];
|
|
1651
|
+
if (value === void 0) {
|
|
1652
|
+
throw new Error("No value provided for letiable " + s);
|
|
1653
|
+
} else if (typeof value === "function") {
|
|
1654
|
+
value = value(data);
|
|
1655
|
+
}
|
|
1656
|
+
return value;
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
var __defProp$7 = Object.defineProperty;
|
|
1661
|
+
var __defProps$3 = Object.defineProperties;
|
|
1662
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
1663
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
1664
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
1665
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
1666
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1667
|
+
var __spreadValues$5 = (a, b) => {
|
|
1668
|
+
for (var prop in b || (b = {}))
|
|
1669
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
1670
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
1671
|
+
if (__getOwnPropSymbols$5)
|
|
1672
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
1673
|
+
if (__propIsEnum$5.call(b, prop))
|
|
1674
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
1675
|
+
}
|
|
1676
|
+
return a;
|
|
1677
|
+
};
|
|
1678
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
1679
|
+
var __objRest = (source, exclude) => {
|
|
1680
|
+
var target = {};
|
|
1681
|
+
for (var prop in source)
|
|
1682
|
+
if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1683
|
+
target[prop] = source[prop];
|
|
1684
|
+
if (source != null && __getOwnPropSymbols$5)
|
|
1685
|
+
for (var prop of __getOwnPropSymbols$5(source)) {
|
|
1686
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
|
|
1687
|
+
target[prop] = source[prop];
|
|
1688
|
+
}
|
|
1689
|
+
return target;
|
|
1690
|
+
};
|
|
1691
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1692
|
+
var __async$4 = (__this, __arguments, generator) => {
|
|
1693
|
+
return new Promise((resolve, reject) => {
|
|
1694
|
+
var fulfilled = (value) => {
|
|
1695
|
+
try {
|
|
1696
|
+
step(generator.next(value));
|
|
1697
|
+
} catch (e) {
|
|
1698
|
+
reject(e);
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
var rejected = (value) => {
|
|
1702
|
+
try {
|
|
1703
|
+
step(generator.throw(value));
|
|
1704
|
+
} catch (e) {
|
|
1705
|
+
reject(e);
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
1709
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
1710
|
+
});
|
|
1711
|
+
};
|
|
1712
|
+
let ID = 0;
|
|
1713
|
+
let REQUEST_ID = 0;
|
|
1714
|
+
class NgwConnector {
|
|
1715
|
+
constructor(options) {
|
|
1716
|
+
this.options = options;
|
|
1717
|
+
__publicField$4(this, "id", ID++);
|
|
1718
|
+
__publicField$4(this, "emitter", new EventEmitter());
|
|
1719
|
+
__publicField$4(this, "user");
|
|
1720
|
+
__publicField$4(this, "cache");
|
|
1721
|
+
__publicField$4(this, "withCredentials");
|
|
1722
|
+
__publicField$4(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
|
|
1723
|
+
__publicField$4(this, "routeStr", "/api/component/pyramid/route");
|
|
1724
|
+
__publicField$4(this, "activeRequests", {});
|
|
1725
|
+
__publicField$4(this, "requestTransform");
|
|
1726
|
+
const exist = findConnector(options);
|
|
1727
|
+
this.cache = new Cache({ namespace: options.cacheId });
|
|
1728
|
+
if (exist) {
|
|
1729
|
+
return exist;
|
|
1730
|
+
} else {
|
|
1731
|
+
const { route: route2, requestTransform, withCredentials } = this.options;
|
|
1732
|
+
if (route2) {
|
|
1733
|
+
this.routeStr = route2;
|
|
1734
|
+
}
|
|
1735
|
+
if (requestTransform) {
|
|
1736
|
+
this.requestTransform = requestTransform;
|
|
1737
|
+
}
|
|
1738
|
+
if (withCredentials !== void 0) {
|
|
1739
|
+
this.withCredentials = withCredentials;
|
|
1740
|
+
}
|
|
1741
|
+
addConnector(this);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
/**
|
|
1745
|
+
* Clear the cache.
|
|
1746
|
+
*/
|
|
1747
|
+
clearCache() {
|
|
1748
|
+
this.cache.clean();
|
|
1749
|
+
}
|
|
1750
|
+
setRequestTransform(requestTransform) {
|
|
1751
|
+
this.requestTransform = requestTransform;
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Fast way to specify the connection address to NextGIS Web.
|
|
1755
|
+
* The current connection will be severed.
|
|
1756
|
+
* @param baseUrl - NGW url
|
|
1757
|
+
*/
|
|
1758
|
+
setNgw(baseUrl) {
|
|
1759
|
+
this.logout();
|
|
1760
|
+
this.options.baseUrl = baseUrl;
|
|
1761
|
+
addConnector(this);
|
|
1762
|
+
}
|
|
1763
|
+
/**
|
|
1764
|
+
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
1765
|
+
* @remarks
|
|
1766
|
+
* This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
|
|
1767
|
+
* Can be used to check connection.
|
|
1768
|
+
* @example
|
|
1769
|
+
* ```javascript
|
|
1770
|
+
* const connector = new NgwConnector({ baseUrl: 'https://demo.nextgis.com' });
|
|
1771
|
+
* connector.connect()
|
|
1772
|
+
* .then(() => console.log('Ok'))
|
|
1773
|
+
* .catch((er) => console.log('Connection problem', er));
|
|
1774
|
+
* ```
|
|
1775
|
+
*/
|
|
1776
|
+
connect() {
|
|
1777
|
+
return __async$4(this, null, function* () {
|
|
1778
|
+
const auth = this.options.auth;
|
|
1779
|
+
if (auth) {
|
|
1780
|
+
const { login, password } = auth;
|
|
1781
|
+
if (login && password) {
|
|
1782
|
+
yield this._login({ login, password });
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
const routeUrl = `${this.routeStr}?client=${this.client}`;
|
|
1786
|
+
return yield this.makeQuery(
|
|
1787
|
+
routeUrl,
|
|
1788
|
+
{},
|
|
1789
|
+
{
|
|
1790
|
+
cacheName: "route",
|
|
1791
|
+
cache: true,
|
|
1792
|
+
cacheProps: {
|
|
1793
|
+
id: this.id,
|
|
1794
|
+
auth,
|
|
1795
|
+
baseUrl: this.options.baseUrl
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
);
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
/**
|
|
1802
|
+
* Quick way to change NextGIS Web user.
|
|
1803
|
+
* @param credentials - New user credentials
|
|
1804
|
+
*/
|
|
1805
|
+
login(credentials, options) {
|
|
1806
|
+
this.logout();
|
|
1807
|
+
addConnector(this);
|
|
1808
|
+
return this._login(credentials, options);
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Disconnecting a user. Aborting all current requests
|
|
1812
|
+
*/
|
|
1813
|
+
logout() {
|
|
1814
|
+
this.abort();
|
|
1815
|
+
removeConnector(this);
|
|
1816
|
+
this.options.auth = void 0;
|
|
1817
|
+
this.user = void 0;
|
|
1818
|
+
this.clearCache();
|
|
1819
|
+
this.emitter.emit("logout");
|
|
1820
|
+
}
|
|
1821
|
+
getUserInfo(credentials, options) {
|
|
1822
|
+
return __async$4(this, null, function* () {
|
|
1823
|
+
if (this.user && this.user.id) {
|
|
1824
|
+
return this.user;
|
|
1825
|
+
}
|
|
1826
|
+
if (credentials) {
|
|
1827
|
+
this.options.auth = credentials;
|
|
1828
|
+
}
|
|
1829
|
+
const options_ = __spreadValues$5({
|
|
1830
|
+
headers: this.getAuthorizationHeaders(credentials),
|
|
1831
|
+
cache: true
|
|
1832
|
+
}, options);
|
|
1833
|
+
return this.makeQuery(
|
|
1834
|
+
"/api/component/auth/current_user",
|
|
1835
|
+
{},
|
|
1836
|
+
options_
|
|
1837
|
+
);
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
1842
|
+
*/
|
|
1843
|
+
getAuthorizationHeaders(credentials) {
|
|
1844
|
+
const client = this.makeClientId(credentials);
|
|
1845
|
+
if (client) {
|
|
1846
|
+
return {
|
|
1847
|
+
Authorization: `Basic ${client}`
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
return {};
|
|
1851
|
+
}
|
|
1852
|
+
makeClientId(credentials) {
|
|
1853
|
+
credentials = credentials || this.options.auth;
|
|
1854
|
+
if (credentials) {
|
|
1855
|
+
const { login, password } = credentials;
|
|
1856
|
+
const encodedStr = [login, password].map(encodeURIComponent).join(":");
|
|
1857
|
+
{
|
|
1858
|
+
return window.btoa(encodedStr);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
/** Stop all api requests */
|
|
1863
|
+
abort() {
|
|
1864
|
+
for (const abortController of Object.values(this.activeRequests)) {
|
|
1865
|
+
abortController.abort();
|
|
1866
|
+
}
|
|
1867
|
+
this.activeRequests = {};
|
|
1868
|
+
}
|
|
1869
|
+
getActiveApiRequests() {
|
|
1870
|
+
return __spreadValues$5({}, this.activeRequests);
|
|
1871
|
+
}
|
|
1872
|
+
route(name, ...rest) {
|
|
1873
|
+
return route(name, this, ...rest);
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Send request to NGW.
|
|
1877
|
+
* @param url - URL address to NGW
|
|
1878
|
+
* @param params - Query params
|
|
1879
|
+
* @param options - Request options
|
|
1880
|
+
*/
|
|
1881
|
+
makeQuery(_0, _1) {
|
|
1882
|
+
return __async$4(this, arguments, function* (url, params, options = {}) {
|
|
1883
|
+
var _b;
|
|
1884
|
+
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1885
|
+
if (!url) {
|
|
1886
|
+
throw new Error("Empty `url` not allowed");
|
|
1887
|
+
}
|
|
1888
|
+
if (params) {
|
|
1889
|
+
const _a = params, restParams = __objRest(_a, ["paramList"]);
|
|
1890
|
+
url = template(url, restParams);
|
|
1891
|
+
}
|
|
1892
|
+
url = encodeURI(fixUrlStr(url));
|
|
1893
|
+
options = __spreadValues$5({ withCredentials: this.withCredentials }, options);
|
|
1894
|
+
const {
|
|
1895
|
+
cache,
|
|
1896
|
+
signal: externalSignal,
|
|
1897
|
+
method = "GET",
|
|
1898
|
+
headers,
|
|
1899
|
+
cacheName,
|
|
1900
|
+
cacheProps,
|
|
1901
|
+
responseType,
|
|
1902
|
+
withCredentials
|
|
1903
|
+
} = options;
|
|
1904
|
+
const internalAbortController = new AbortController();
|
|
1905
|
+
const internalSignal = internalAbortController.signal;
|
|
1906
|
+
if (externalSignal) {
|
|
1907
|
+
if (externalSignal.aborted) {
|
|
1908
|
+
throw new AbortError();
|
|
1909
|
+
}
|
|
1910
|
+
externalSignal.addEventListener("abort", () => {
|
|
1911
|
+
internalAbortController.abort();
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
options.signal = internalSignal;
|
|
1915
|
+
const createPromise = () => __async$4(this, null, function* () {
|
|
1916
|
+
const id = REQUEST_ID++;
|
|
1917
|
+
this.activeRequests[id] = internalAbortController;
|
|
1918
|
+
try {
|
|
1919
|
+
return this._loadData(url, options);
|
|
1920
|
+
} finally {
|
|
1921
|
+
this._cleanActiveRequest(id);
|
|
1922
|
+
}
|
|
1923
|
+
});
|
|
1924
|
+
if (method === "GET") {
|
|
1925
|
+
const cacheOptions = cacheProps ? cacheProps : __spreadProps$3(__spreadValues$5({}, objectRemoveEmpty({
|
|
1926
|
+
headers,
|
|
1927
|
+
withCredentials,
|
|
1928
|
+
responseType,
|
|
1929
|
+
baseUrl: this.options.baseUrl,
|
|
1930
|
+
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1931
|
+
})), {
|
|
1932
|
+
params
|
|
1933
|
+
});
|
|
1934
|
+
return this.cache.add(cacheName || url, createPromise, {
|
|
1935
|
+
props: cacheOptions,
|
|
1936
|
+
expirationTime: cache ? void 0 : 500
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
return createPromise();
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
_loadData(url, options) {
|
|
1943
|
+
options.responseType = options.responseType || "json";
|
|
1944
|
+
return new Promise((resolve, reject) => {
|
|
1945
|
+
var _a;
|
|
1946
|
+
if (this.user) {
|
|
1947
|
+
options = options || {};
|
|
1948
|
+
options.headers = __spreadValues$5(__spreadValues$5({}, this.getAuthorizationHeaders()), options.headers);
|
|
1949
|
+
}
|
|
1950
|
+
if (this.requestTransform) {
|
|
1951
|
+
const [transUrl, transOptions] = this.requestTransform(url, options);
|
|
1952
|
+
url = transUrl;
|
|
1953
|
+
options = transOptions;
|
|
1954
|
+
}
|
|
1955
|
+
let runOnAbort = void 0;
|
|
1956
|
+
loadData(url, resolve, options, reject, (handler) => {
|
|
1957
|
+
runOnAbort = handler;
|
|
1958
|
+
});
|
|
1959
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
1960
|
+
if (runOnAbort !== void 0) {
|
|
1961
|
+
runOnAbort();
|
|
1962
|
+
}
|
|
1963
|
+
reject(new AbortError());
|
|
1964
|
+
});
|
|
1965
|
+
}).catch((httpError) => {
|
|
1966
|
+
if (httpError.name !== "AbortError") {
|
|
1967
|
+
{
|
|
1968
|
+
console.warn("DEV WARN", httpError);
|
|
1969
|
+
}
|
|
1970
|
+
const er = this._handleHttpError(httpError);
|
|
1971
|
+
if (er) {
|
|
1972
|
+
throw er;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
throw httpError;
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
_login(credentials, options) {
|
|
1979
|
+
return __async$4(this, null, function* () {
|
|
1980
|
+
try {
|
|
1981
|
+
const data = yield this.getUserInfo(credentials, options);
|
|
1982
|
+
this.user = data;
|
|
1983
|
+
this.emitter.emit("login", data);
|
|
1984
|
+
return data;
|
|
1985
|
+
} catch (er) {
|
|
1986
|
+
this.emitter.emit("login:error", er);
|
|
1987
|
+
throw er;
|
|
1988
|
+
}
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
_cleanActiveRequest(requestId) {
|
|
1992
|
+
delete this.activeRequests[requestId];
|
|
1993
|
+
}
|
|
1994
|
+
_handleHttpError(er) {
|
|
1995
|
+
if (er) {
|
|
1996
|
+
if (er instanceof NgwError) {
|
|
1997
|
+
if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
|
|
1998
|
+
throw new ResourceNotFoundError(er);
|
|
1999
|
+
} else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
|
|
2000
|
+
throw new InsufficientPermissionsError(er);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
return er;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
__publicField$4(NgwConnector, "errors", errors);
|
|
2008
|
+
|
|
2009
|
+
function resourceCompare(res1, res2) {
|
|
2010
|
+
return objectDeepEqual(res1, res2);
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
const exclude = ["description"];
|
|
2014
|
+
function resourceToQuery(resource, prefix = "") {
|
|
2015
|
+
prefix = prefix ? prefix + "__" : "";
|
|
2016
|
+
const query = {};
|
|
2017
|
+
for (const [key, value] of Object.entries(resource)) {
|
|
2018
|
+
if (exclude.indexOf(key) === -1) {
|
|
2019
|
+
if (isObject(value)) {
|
|
2020
|
+
if (key === "owner_user") {
|
|
2021
|
+
const children = resourceToQuery(
|
|
2022
|
+
value,
|
|
2023
|
+
key
|
|
2024
|
+
);
|
|
2025
|
+
Object.assign(query, children);
|
|
2026
|
+
} else if (key === "parent" && "id" in value) {
|
|
2027
|
+
query.parent_id = value.id;
|
|
2028
|
+
}
|
|
2029
|
+
} else if (defined(value)) {
|
|
2030
|
+
query[prefix + key] = value;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
return query;
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
var __defProp$6 = Object.defineProperty;
|
|
2038
|
+
var __defProps$2 = Object.defineProperties;
|
|
2039
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
2040
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
2041
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
2042
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
2043
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2044
|
+
var __spreadValues$4 = (a, b) => {
|
|
2045
|
+
for (var prop in b || (b = {}))
|
|
2046
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
2047
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
2048
|
+
if (__getOwnPropSymbols$4)
|
|
2049
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
2050
|
+
if (__propIsEnum$4.call(b, prop))
|
|
2051
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
2052
|
+
}
|
|
2053
|
+
return a;
|
|
2054
|
+
};
|
|
2055
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
2056
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2057
|
+
var __async$3 = (__this, __arguments, generator) => {
|
|
2058
|
+
return new Promise((resolve, reject) => {
|
|
2059
|
+
var fulfilled = (value) => {
|
|
2060
|
+
try {
|
|
2061
|
+
step(generator.next(value));
|
|
2062
|
+
} catch (e) {
|
|
2063
|
+
reject(e);
|
|
2064
|
+
}
|
|
2065
|
+
};
|
|
2066
|
+
var rejected = (value) => {
|
|
2067
|
+
try {
|
|
2068
|
+
step(generator.throw(value));
|
|
2069
|
+
} catch (e) {
|
|
2070
|
+
reject(e);
|
|
2071
|
+
}
|
|
2072
|
+
};
|
|
2073
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2074
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
2075
|
+
});
|
|
2076
|
+
};
|
|
2077
|
+
class ResourcesControl {
|
|
2078
|
+
constructor({
|
|
2079
|
+
connector,
|
|
2080
|
+
cacheId
|
|
2081
|
+
}) {
|
|
2082
|
+
__publicField$3(this, "cache");
|
|
2083
|
+
__publicField$3(this, "connector");
|
|
2084
|
+
this.connector = connector;
|
|
2085
|
+
this.cache = new Cache({ namespace: cacheId });
|
|
2086
|
+
}
|
|
2087
|
+
// -------------------------------------------------------------------------
|
|
2088
|
+
// Resource Methods
|
|
2089
|
+
// -------------------------------------------------------------------------
|
|
2090
|
+
/**
|
|
2091
|
+
* Receive resource from NGW by id, keyname or search-object parameter.
|
|
2092
|
+
* @param resource - Resource id, keyname or search-object
|
|
2093
|
+
*
|
|
2094
|
+
* @remarks
|
|
2095
|
+
* Fetching resource would be cached to speed up next call
|
|
2096
|
+
*/
|
|
2097
|
+
getOne(resource, requestOptions) {
|
|
2098
|
+
const opt = __spreadValues$4({}, requestOptions);
|
|
2099
|
+
if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
|
|
2100
|
+
if (resource.id !== void 0) {
|
|
2101
|
+
resource.id;
|
|
2102
|
+
} else {
|
|
2103
|
+
if (resource.keyname) {
|
|
2104
|
+
resource.keyname;
|
|
2105
|
+
}
|
|
2106
|
+
if (resource.display_name) {
|
|
2107
|
+
resource.display_name;
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
if (typeof resource === "string") {
|
|
2112
|
+
return this._fetchResourceBy({ keyname: resource }, opt);
|
|
2113
|
+
} else if (typeof resource === "number") {
|
|
2114
|
+
return this._fetchResourceById(resource, opt);
|
|
2115
|
+
} else if (isObject(resource)) {
|
|
2116
|
+
return this._fetchResourceBy(resource, opt);
|
|
2117
|
+
}
|
|
2118
|
+
return Promise.resolve(void 0);
|
|
2119
|
+
}
|
|
2120
|
+
getOneOrFail(resource, requestOptions) {
|
|
2121
|
+
return this.getOne(resource, requestOptions).then((res) => {
|
|
2122
|
+
if (res) {
|
|
2123
|
+
return res;
|
|
2124
|
+
}
|
|
2125
|
+
throw new ResourceNotFoundError();
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* A fast way to retrieve resource ID for any resource definition.
|
|
2130
|
+
* @param resource - Any available resource definition
|
|
2131
|
+
*
|
|
2132
|
+
* @remarks
|
|
2133
|
+
* There are situations when exactly the resource id is needed
|
|
2134
|
+
* (for example, to compose the correct request to the api)
|
|
2135
|
+
* then this method will come in handy to facilitate the extraction of the identifier
|
|
2136
|
+
* if the resource is specified through a keyname or other parameters.
|
|
2137
|
+
*/
|
|
2138
|
+
getId(resource, requestOptions) {
|
|
2139
|
+
if (typeof resource === "number") {
|
|
2140
|
+
return Promise.resolve(resource);
|
|
2141
|
+
} else if (typeof resource === "string" || isObject(resource)) {
|
|
2142
|
+
return this.getOne(resource, requestOptions).then((res) => {
|
|
2143
|
+
if (res) {
|
|
2144
|
+
return res.resource.id;
|
|
2145
|
+
}
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
return Promise.resolve(void 0);
|
|
2149
|
+
}
|
|
2150
|
+
/**
|
|
2151
|
+
* A fast way to retrieve resource ID for any resource definition.
|
|
2152
|
+
* @param resource - Any available resource definition
|
|
2153
|
+
*
|
|
2154
|
+
* @remarks
|
|
2155
|
+
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
2156
|
+
* To not make one more checks if the resource is definitely exists
|
|
2157
|
+
*/
|
|
2158
|
+
getIdOrFail(resource, requestOptions) {
|
|
2159
|
+
return this.getId(resource, requestOptions).then((resp) => {
|
|
2160
|
+
if (resp === void 0) {
|
|
2161
|
+
throw new Error();
|
|
2162
|
+
}
|
|
2163
|
+
return resp;
|
|
2164
|
+
});
|
|
1081
2165
|
}
|
|
1082
2166
|
getMany(resource, requestOptions) {
|
|
1083
2167
|
return this._resourceCacheFilter(resource).then((items) => {
|
|
@@ -1088,9 +2172,11 @@ var Geocoder = (function (exports) {
|
|
|
1088
2172
|
} else {
|
|
1089
2173
|
Object.assign(query, resourceToQuery(resource));
|
|
1090
2174
|
}
|
|
1091
|
-
return this.connector.
|
|
1092
|
-
|
|
1093
|
-
|
|
2175
|
+
return this.connector.route("resource.search").get(__spreadProps$2(__spreadValues$4({}, requestOptions), {
|
|
2176
|
+
query: __spreadValues$4({
|
|
2177
|
+
serialization: "full"
|
|
2178
|
+
}, query)
|
|
2179
|
+
})).then((resources) => {
|
|
1094
2180
|
if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
|
|
1095
2181
|
for (const x of resources) {
|
|
1096
2182
|
this.cache.add("resource.item", Promise.resolve(x), {
|
|
@@ -1106,7 +2192,8 @@ var Geocoder = (function (exports) {
|
|
|
1106
2192
|
}
|
|
1107
2193
|
getParent(resource, requestOptions) {
|
|
1108
2194
|
return this.getOne(resource, requestOptions).then((child) => {
|
|
1109
|
-
|
|
2195
|
+
var _a, _b;
|
|
2196
|
+
if ((_b = (_a = child == null ? void 0 : child.resource) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) {
|
|
1110
2197
|
return this.getOne(child.resource.parent.id, requestOptions);
|
|
1111
2198
|
}
|
|
1112
2199
|
return Promise.resolve(void 0);
|
|
@@ -1138,10 +2225,21 @@ var Geocoder = (function (exports) {
|
|
|
1138
2225
|
}
|
|
1139
2226
|
});
|
|
1140
2227
|
}
|
|
1141
|
-
_getChildrenOf(
|
|
1142
|
-
return this
|
|
1143
|
-
parent
|
|
1144
|
-
|
|
2228
|
+
_getChildrenOf(_0, _1) {
|
|
2229
|
+
return __async$3(this, arguments, function* (parentDef, requestOptions, _items = []) {
|
|
2230
|
+
let parent = void 0;
|
|
2231
|
+
if (typeof parentDef === "string") {
|
|
2232
|
+
parent = yield this.getId(parentDef, requestOptions);
|
|
2233
|
+
} else if (typeof parentDef === "object") {
|
|
2234
|
+
parent = parentDef.id;
|
|
2235
|
+
} else {
|
|
2236
|
+
parent = parentDef;
|
|
2237
|
+
}
|
|
2238
|
+
const items = yield this.connector.route("resource.collection").get(__spreadProps$2(__spreadValues$4({}, requestOptions), {
|
|
2239
|
+
query: {
|
|
2240
|
+
parent
|
|
2241
|
+
}
|
|
2242
|
+
}));
|
|
1145
2243
|
const recursivePromises = [];
|
|
1146
2244
|
for (const item of items) {
|
|
1147
2245
|
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
@@ -1165,7 +2263,7 @@ var Geocoder = (function (exports) {
|
|
|
1165
2263
|
});
|
|
1166
2264
|
}
|
|
1167
2265
|
_cleanResourceItemCache(id) {
|
|
1168
|
-
return __async$
|
|
2266
|
+
return __async$3(this, null, function* () {
|
|
1169
2267
|
var _a;
|
|
1170
2268
|
const all = this.cache.all();
|
|
1171
2269
|
const toDelete = [];
|
|
@@ -1190,7 +2288,7 @@ var Geocoder = (function (exports) {
|
|
|
1190
2288
|
});
|
|
1191
2289
|
}
|
|
1192
2290
|
_fetchResourceById(id, requestOptions) {
|
|
1193
|
-
return this.connector.
|
|
2291
|
+
return this.connector.route("resource.item", { id }).get(requestOptions);
|
|
1194
2292
|
}
|
|
1195
2293
|
_fetchResourceBy(resource, requestOptions) {
|
|
1196
2294
|
return this.getMany(resource, requestOptions).then((resources) => {
|
|
@@ -1211,86 +2309,30 @@ var Geocoder = (function (exports) {
|
|
|
1211
2309
|
}
|
|
1212
2310
|
return resourceCompare(resource, x.resource);
|
|
1213
2311
|
}
|
|
1214
|
-
});
|
|
1215
|
-
return items;
|
|
1216
|
-
}
|
|
1217
|
-
);
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
const CONNECTORS = [];
|
|
1222
|
-
function addConnector(connector) {
|
|
1223
|
-
CONNECTORS.push(connector);
|
|
1224
|
-
}
|
|
1225
|
-
function findConnector(options) {
|
|
1226
|
-
return CONNECTORS.find((x) => {
|
|
1227
|
-
if (x.options.baseUrl === options.baseUrl) {
|
|
1228
|
-
if (options.auth) {
|
|
1229
|
-
if (x.options.auth) {
|
|
1230
|
-
return objectDeepEqual(x.options.auth, options.auth);
|
|
1231
|
-
}
|
|
1232
|
-
} else {
|
|
1233
|
-
return true;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
});
|
|
1237
|
-
}
|
|
1238
|
-
function removeConnector(connector) {
|
|
1239
|
-
const index = CONNECTORS.indexOf(connector);
|
|
1240
|
-
if (index !== -1) {
|
|
1241
|
-
CONNECTORS.splice(index, 1);
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
class AbortError extends Error {
|
|
1246
|
-
constructor(message = "AbortError") {
|
|
1247
|
-
super(message);
|
|
1248
|
-
this.name = "AbortError";
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
var __defProp$7 = Object.defineProperty;
|
|
1253
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1254
|
-
var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1255
|
-
class InsufficientPermissionsError extends NgwError {
|
|
1256
|
-
constructor(obj) {
|
|
1257
|
-
super(obj);
|
|
1258
|
-
__publicField$4(this, "name", "InsufficientPermissionsError");
|
|
1259
|
-
__publicField$4(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
|
|
1260
|
-
Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
const templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1265
|
-
function template(str, data) {
|
|
1266
|
-
return str.replace(templateRe, (s, key) => {
|
|
1267
|
-
let value = data[key];
|
|
1268
|
-
if (value === void 0) {
|
|
1269
|
-
throw new Error("No value provided for letiable " + s);
|
|
1270
|
-
} else if (typeof value === "function") {
|
|
1271
|
-
value = value(data);
|
|
1272
|
-
}
|
|
1273
|
-
return value;
|
|
1274
|
-
});
|
|
2312
|
+
});
|
|
2313
|
+
return items;
|
|
2314
|
+
}
|
|
2315
|
+
);
|
|
2316
|
+
}
|
|
1275
2317
|
}
|
|
1276
2318
|
|
|
1277
|
-
var __defProp$
|
|
1278
|
-
var __getOwnPropSymbols$
|
|
1279
|
-
var __hasOwnProp$
|
|
1280
|
-
var __propIsEnum$
|
|
1281
|
-
var __defNormalProp$
|
|
1282
|
-
var __spreadValues$
|
|
2319
|
+
var __defProp$5 = Object.defineProperty;
|
|
2320
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
2321
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
2322
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
2323
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2324
|
+
var __spreadValues$3 = (a, b) => {
|
|
1283
2325
|
for (var prop in b || (b = {}))
|
|
1284
|
-
if (__hasOwnProp$
|
|
1285
|
-
__defNormalProp$
|
|
1286
|
-
if (__getOwnPropSymbols$
|
|
1287
|
-
for (var prop of __getOwnPropSymbols$
|
|
1288
|
-
if (__propIsEnum$
|
|
1289
|
-
__defNormalProp$
|
|
2326
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
2327
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
2328
|
+
if (__getOwnPropSymbols$3)
|
|
2329
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
2330
|
+
if (__propIsEnum$3.call(b, prop))
|
|
2331
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
1290
2332
|
}
|
|
1291
2333
|
return a;
|
|
1292
2334
|
};
|
|
1293
|
-
var __async$
|
|
2335
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
1294
2336
|
return new Promise((resolve, reject) => {
|
|
1295
2337
|
var fulfilled = (value) => {
|
|
1296
2338
|
try {
|
|
@@ -1311,7 +2353,7 @@ var Geocoder = (function (exports) {
|
|
|
1311
2353
|
});
|
|
1312
2354
|
};
|
|
1313
2355
|
function apiRequest(opt) {
|
|
1314
|
-
return __async$
|
|
2356
|
+
return __async$2(this, null, function* () {
|
|
1315
2357
|
const { params, name, connector, requestOptions } = opt;
|
|
1316
2358
|
const apiItems = yield connector.connect();
|
|
1317
2359
|
let apiItem = apiItems && apiItems[name];
|
|
@@ -1340,334 +2382,48 @@ var Geocoder = (function (exports) {
|
|
|
1340
2382
|
});
|
|
1341
2383
|
}
|
|
1342
2384
|
for (const p in params) {
|
|
1343
|
-
if (apiItem.indexOf(p) === -1) {
|
|
1344
|
-
paramArray.push(`${p}=${params[p]}`);
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
if (paramArray.length) {
|
|
1348
|
-
url = `${url}?${paramArray.join("&")}`;
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
if (url) {
|
|
1352
|
-
return connector.makeQuery(url, params, __spreadValues$4({
|
|
1353
|
-
cacheName: name
|
|
1354
|
-
}, requestOptions));
|
|
1355
|
-
} else {
|
|
1356
|
-
throw new Error("Request URL is not set");
|
|
1357
|
-
}
|
|
1358
|
-
} else {
|
|
1359
|
-
return void 0;
|
|
1360
|
-
}
|
|
1361
|
-
});
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
var __defProp$5 = Object.defineProperty;
|
|
1365
|
-
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1366
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, key + "" , value);
|
|
1367
|
-
class NetworkError extends Error {
|
|
1368
|
-
constructor(url) {
|
|
1369
|
-
super();
|
|
1370
|
-
__publicField$3(this, "name", "NetworkError");
|
|
1371
|
-
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
1372
|
-
this.message = `Unable to request ${url}.
|
|
1373
|
-
Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
let loadData;
|
|
1378
|
-
{
|
|
1379
|
-
loadData = (url, callback, options = {}, error, onCancel) => {
|
|
1380
|
-
options.method = options.method || "GET";
|
|
1381
|
-
const xhr = new XMLHttpRequest();
|
|
1382
|
-
xhr.open(options.method || "GET", url, true);
|
|
1383
|
-
if (options.responseType === "blob") {
|
|
1384
|
-
xhr.responseType = options.responseType;
|
|
1385
|
-
}
|
|
1386
|
-
const getResponseText = () => {
|
|
1387
|
-
try {
|
|
1388
|
-
return JSON.parse(xhr.responseText);
|
|
1389
|
-
} catch (er) {
|
|
1390
|
-
return xhr.responseText;
|
|
1391
|
-
}
|
|
1392
|
-
};
|
|
1393
|
-
const processingResponse = (forError = false) => {
|
|
1394
|
-
const cb = forError ? error : callback;
|
|
1395
|
-
if (options.responseType === "blob") {
|
|
1396
|
-
cb(xhr.response);
|
|
1397
|
-
} else {
|
|
1398
|
-
if (xhr.responseText) {
|
|
1399
|
-
cb(getResponseText());
|
|
1400
|
-
} else {
|
|
1401
|
-
error({ message: "" });
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
};
|
|
1405
|
-
xhr.onload = () => {
|
|
1406
|
-
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1407
|
-
error(new NgwError(getResponseText()));
|
|
1408
|
-
}
|
|
1409
|
-
processingResponse();
|
|
1410
|
-
};
|
|
1411
|
-
xhr.onerror = (er) => {
|
|
1412
|
-
if (xhr.status === 0) {
|
|
1413
|
-
error(new NetworkError(url));
|
|
1414
|
-
} else {
|
|
1415
|
-
error(er);
|
|
1416
|
-
}
|
|
1417
|
-
};
|
|
1418
|
-
xhr.upload.onprogress = function(e) {
|
|
1419
|
-
if (e.lengthComputable) {
|
|
1420
|
-
const percentComplete = e.loaded / e.total * 100;
|
|
1421
|
-
if (options.onProgress) {
|
|
1422
|
-
options.onProgress(percentComplete, e);
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
};
|
|
1426
|
-
const headers = options.headers;
|
|
1427
|
-
if (headers) {
|
|
1428
|
-
for (const h in headers) {
|
|
1429
|
-
const header = headers[h];
|
|
1430
|
-
if (typeof header === "string") {
|
|
1431
|
-
xhr.setRequestHeader(h, header);
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
if (options.withCredentials !== void 0) {
|
|
1436
|
-
xhr.withCredentials = options.withCredentials;
|
|
1437
|
-
}
|
|
1438
|
-
let data;
|
|
1439
|
-
if (options.file) {
|
|
1440
|
-
data = new FormData();
|
|
1441
|
-
data.append("file", options.file);
|
|
1442
|
-
if (options.data) {
|
|
1443
|
-
for (const d in options.data) {
|
|
1444
|
-
data.append(d, data[d]);
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
} else {
|
|
1448
|
-
data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
|
|
1449
|
-
}
|
|
1450
|
-
if (onCancel) {
|
|
1451
|
-
onCancel(() => {
|
|
1452
|
-
xhr.abort();
|
|
1453
|
-
});
|
|
1454
|
-
}
|
|
1455
|
-
xhr.send(data);
|
|
1456
|
-
};
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
var __defProp$4 = Object.defineProperty;
|
|
1460
|
-
var __defProps$2 = Object.defineProperties;
|
|
1461
|
-
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
1462
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
1463
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
1464
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
1465
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1466
|
-
var __spreadValues$3 = (a, b) => {
|
|
1467
|
-
for (var prop in b || (b = {}))
|
|
1468
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
1469
|
-
__defNormalProp$4(a, prop, b[prop]);
|
|
1470
|
-
if (__getOwnPropSymbols$3)
|
|
1471
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
1472
|
-
if (__propIsEnum$3.call(b, prop))
|
|
1473
|
-
__defNormalProp$4(a, prop, b[prop]);
|
|
1474
|
-
}
|
|
1475
|
-
return a;
|
|
1476
|
-
};
|
|
1477
|
-
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
1478
|
-
var __objRest = (source, exclude) => {
|
|
1479
|
-
var target = {};
|
|
1480
|
-
for (var prop in source)
|
|
1481
|
-
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1482
|
-
target[prop] = source[prop];
|
|
1483
|
-
if (source != null && __getOwnPropSymbols$3)
|
|
1484
|
-
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
1485
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
1486
|
-
target[prop] = source[prop];
|
|
1487
|
-
}
|
|
1488
|
-
return target;
|
|
1489
|
-
};
|
|
1490
|
-
var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1491
|
-
var __async$2 = (__this, __arguments, generator) => {
|
|
1492
|
-
return new Promise((resolve, reject) => {
|
|
1493
|
-
var fulfilled = (value) => {
|
|
1494
|
-
try {
|
|
1495
|
-
step(generator.next(value));
|
|
1496
|
-
} catch (e) {
|
|
1497
|
-
reject(e);
|
|
1498
|
-
}
|
|
1499
|
-
};
|
|
1500
|
-
var rejected = (value) => {
|
|
1501
|
-
try {
|
|
1502
|
-
step(generator.throw(value));
|
|
1503
|
-
} catch (e) {
|
|
1504
|
-
reject(e);
|
|
1505
|
-
}
|
|
1506
|
-
};
|
|
1507
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
1508
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
1509
|
-
});
|
|
1510
|
-
};
|
|
1511
|
-
let ID = 0;
|
|
1512
|
-
let REQUEST_ID = 0;
|
|
1513
|
-
class NgwConnector {
|
|
1514
|
-
constructor(options) {
|
|
1515
|
-
this.options = options;
|
|
1516
|
-
__publicField$2(this, "id", ID++);
|
|
1517
|
-
__publicField$2(this, "emitter", new EventEmitter());
|
|
1518
|
-
__publicField$2(this, "user");
|
|
1519
|
-
__publicField$2(this, "resources");
|
|
1520
|
-
__publicField$2(this, "cache");
|
|
1521
|
-
__publicField$2(this, "routeStr", "/api/component/pyramid/route");
|
|
1522
|
-
__publicField$2(this, "activeRequests", {});
|
|
1523
|
-
__publicField$2(this, "requestTransform");
|
|
1524
|
-
const exist = findConnector(options);
|
|
1525
|
-
this.cache = new Cache({ namespace: options.cacheId });
|
|
1526
|
-
if (exist) {
|
|
1527
|
-
return exist;
|
|
1528
|
-
} else {
|
|
1529
|
-
if (this.options.route) {
|
|
1530
|
-
this.routeStr = this.options.route;
|
|
1531
|
-
}
|
|
1532
|
-
if (this.options.requestTransform) {
|
|
1533
|
-
this.requestTransform = this.options.requestTransform;
|
|
1534
|
-
}
|
|
1535
|
-
this.resources = new ResourcesControl({
|
|
1536
|
-
connector: this,
|
|
1537
|
-
cacheId: options.cacheId
|
|
1538
|
-
});
|
|
1539
|
-
addConnector(this);
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
static create(options) {
|
|
1543
|
-
return new this(options);
|
|
1544
|
-
}
|
|
1545
|
-
/**
|
|
1546
|
-
* Clear the cache.
|
|
1547
|
-
*/
|
|
1548
|
-
clearCache() {
|
|
1549
|
-
this.cache.clean();
|
|
1550
|
-
this.resources.cache.clean();
|
|
1551
|
-
}
|
|
1552
|
-
setRequestTransform(requestTransform) {
|
|
1553
|
-
this.requestTransform = requestTransform;
|
|
1554
|
-
}
|
|
1555
|
-
/**
|
|
1556
|
-
* Fast way to specify the connection address to NextGIS Web.
|
|
1557
|
-
* The current connection will be severed.
|
|
1558
|
-
* @param baseUrl - NGW url
|
|
1559
|
-
*/
|
|
1560
|
-
setNgw(baseUrl) {
|
|
1561
|
-
this.logout();
|
|
1562
|
-
this.options.baseUrl = baseUrl;
|
|
1563
|
-
addConnector(this);
|
|
1564
|
-
}
|
|
1565
|
-
/**
|
|
1566
|
-
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
1567
|
-
* @remarks
|
|
1568
|
-
* This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
|
|
1569
|
-
* Can be used to check connection.
|
|
1570
|
-
* @example
|
|
1571
|
-
* ```javascript
|
|
1572
|
-
* const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
|
|
1573
|
-
* connector.connect()
|
|
1574
|
-
* .then(() => console.log('Ok'))
|
|
1575
|
-
* .catch((er) => console.log('Connection problem', er));
|
|
1576
|
-
* ```
|
|
1577
|
-
*/
|
|
1578
|
-
connect() {
|
|
1579
|
-
return __async$2(this, null, function* () {
|
|
1580
|
-
const auth = this.options.auth;
|
|
1581
|
-
if (auth) {
|
|
1582
|
-
const { login, password } = auth;
|
|
1583
|
-
if (login && password) {
|
|
1584
|
-
yield this._login({ login, password });
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
return yield this.makeQuery(
|
|
1588
|
-
this.routeStr,
|
|
1589
|
-
{},
|
|
1590
|
-
{
|
|
1591
|
-
cacheName: "route",
|
|
1592
|
-
cache: true,
|
|
1593
|
-
cacheProps: {
|
|
1594
|
-
id: this.id,
|
|
1595
|
-
auth,
|
|
1596
|
-
baseUrl: this.options.baseUrl
|
|
2385
|
+
if (apiItem.indexOf(p) === -1) {
|
|
2386
|
+
paramArray.push(`${p}=${params[p]}`);
|
|
1597
2387
|
}
|
|
1598
2388
|
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
/**
|
|
1603
|
-
* Quick way to change NextGIS Web user.
|
|
1604
|
-
* @param credentials - New user credentials
|
|
1605
|
-
*/
|
|
1606
|
-
login(credentials, options) {
|
|
1607
|
-
this.logout();
|
|
1608
|
-
addConnector(this);
|
|
1609
|
-
return this._login(credentials, options);
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Disconnecting a user. Aborting all current requests
|
|
1613
|
-
*/
|
|
1614
|
-
logout() {
|
|
1615
|
-
this.abort();
|
|
1616
|
-
removeConnector(this);
|
|
1617
|
-
this.options.auth = void 0;
|
|
1618
|
-
this.user = void 0;
|
|
1619
|
-
this.clearCache();
|
|
1620
|
-
this.emitter.emit("logout");
|
|
1621
|
-
}
|
|
1622
|
-
getUserInfo(credentials, options) {
|
|
1623
|
-
return __async$2(this, null, function* () {
|
|
1624
|
-
if (this.user && this.user.id) {
|
|
1625
|
-
return this.user;
|
|
2389
|
+
if (paramArray.length) {
|
|
2390
|
+
url = `${url}?${paramArray.join("&")}`;
|
|
2391
|
+
}
|
|
1626
2392
|
}
|
|
1627
|
-
if (
|
|
1628
|
-
|
|
2393
|
+
if (url) {
|
|
2394
|
+
return connector.makeQuery(url, params, __spreadValues$3({
|
|
2395
|
+
cacheName: name
|
|
2396
|
+
}, requestOptions));
|
|
2397
|
+
} else {
|
|
2398
|
+
throw new Error("Request URL is not set");
|
|
1629
2399
|
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
2400
|
+
} else {
|
|
2401
|
+
return void 0;
|
|
2402
|
+
}
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
var __defProp$4 = Object.defineProperty;
|
|
2407
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2408
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$4(obj, key + "" , value);
|
|
2409
|
+
class NgwConnectorExtended extends NgwConnector {
|
|
2410
|
+
constructor(options) {
|
|
2411
|
+
super(options);
|
|
2412
|
+
__publicField$2(this, "resources");
|
|
2413
|
+
this.resources = new ResourcesControl({
|
|
2414
|
+
connector: this,
|
|
2415
|
+
cacheId: options.cacheId
|
|
1638
2416
|
});
|
|
1639
2417
|
}
|
|
2418
|
+
static create(options) {
|
|
2419
|
+
return new this(options);
|
|
2420
|
+
}
|
|
1640
2421
|
/**
|
|
1641
|
-
*
|
|
2422
|
+
* Clear the cache.
|
|
1642
2423
|
*/
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
return {
|
|
1647
|
-
Authorization: `Basic ${client}`
|
|
1648
|
-
};
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
makeClientId(credentials) {
|
|
1652
|
-
credentials = credentials || this.options.auth;
|
|
1653
|
-
if (credentials) {
|
|
1654
|
-
const { login, password } = credentials;
|
|
1655
|
-
const str = `${login}:${password}`;
|
|
1656
|
-
const encodedStr = encodeURIComponent(str);
|
|
1657
|
-
{
|
|
1658
|
-
return window.btoa(encodedStr);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
/** Stop all api requests */
|
|
1663
|
-
abort() {
|
|
1664
|
-
for (const abortController of Object.values(this.activeRequests)) {
|
|
1665
|
-
abortController.abort();
|
|
1666
|
-
}
|
|
1667
|
-
this.activeRequests = {};
|
|
1668
|
-
}
|
|
1669
|
-
getActiveApiRequests() {
|
|
1670
|
-
return __spreadValues$3({}, this.activeRequests);
|
|
2424
|
+
clearCache() {
|
|
2425
|
+
super.clearCache();
|
|
2426
|
+
this.resources.cache.clean();
|
|
1671
2427
|
}
|
|
1672
2428
|
/**
|
|
1673
2429
|
* Send request to NGW api router.
|
|
@@ -1786,74 +2542,6 @@ var Geocoder = (function (exports) {
|
|
|
1786
2542
|
options
|
|
1787
2543
|
);
|
|
1788
2544
|
}
|
|
1789
|
-
/**
|
|
1790
|
-
* Send request to NGW.
|
|
1791
|
-
* @param url - URL address to NGW
|
|
1792
|
-
* @param params - Query params
|
|
1793
|
-
* @param options - Request options
|
|
1794
|
-
*/
|
|
1795
|
-
makeQuery(_0, _1) {
|
|
1796
|
-
return __async$2(this, arguments, function* (url, params, options = {}) {
|
|
1797
|
-
var _b;
|
|
1798
|
-
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1799
|
-
if (!url) {
|
|
1800
|
-
throw new Error("Empty `url` not allowed");
|
|
1801
|
-
}
|
|
1802
|
-
if (params) {
|
|
1803
|
-
const _a = params, restParams = __objRest(_a, ["paramList"]);
|
|
1804
|
-
url = template(url, restParams);
|
|
1805
|
-
}
|
|
1806
|
-
url = encodeURI(fixUrlStr(url));
|
|
1807
|
-
const {
|
|
1808
|
-
cache,
|
|
1809
|
-
signal: externalSignal,
|
|
1810
|
-
method = "GET",
|
|
1811
|
-
headers,
|
|
1812
|
-
cacheName,
|
|
1813
|
-
cacheProps,
|
|
1814
|
-
responseType,
|
|
1815
|
-
withCredentials
|
|
1816
|
-
} = options;
|
|
1817
|
-
const internalAbortController = new AbortController();
|
|
1818
|
-
const internalSignal = internalAbortController.signal;
|
|
1819
|
-
if (externalSignal) {
|
|
1820
|
-
if (externalSignal.aborted) {
|
|
1821
|
-
throw new AbortError();
|
|
1822
|
-
}
|
|
1823
|
-
externalSignal.addEventListener("abort", () => {
|
|
1824
|
-
internalAbortController.abort();
|
|
1825
|
-
});
|
|
1826
|
-
}
|
|
1827
|
-
options.signal = internalSignal;
|
|
1828
|
-
const createPromise = () => __async$2(this, null, function* () {
|
|
1829
|
-
const id = REQUEST_ID++;
|
|
1830
|
-
this.activeRequests[id] = internalAbortController;
|
|
1831
|
-
try {
|
|
1832
|
-
return this._loadData(url, options);
|
|
1833
|
-
} finally {
|
|
1834
|
-
this._cleanActiveRequest(id);
|
|
1835
|
-
}
|
|
1836
|
-
});
|
|
1837
|
-
if (cache && method === "GET") {
|
|
1838
|
-
const cacheOptions = cacheProps ? cacheProps : __spreadProps$2(__spreadValues$3({}, objectRemoveEmpty({
|
|
1839
|
-
headers,
|
|
1840
|
-
withCredentials,
|
|
1841
|
-
responseType,
|
|
1842
|
-
baseUrl: this.options.baseUrl,
|
|
1843
|
-
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1844
|
-
})), {
|
|
1845
|
-
params
|
|
1846
|
-
});
|
|
1847
|
-
return this.cache.add(
|
|
1848
|
-
cacheName || url,
|
|
1849
|
-
createPromise,
|
|
1850
|
-
cacheOptions,
|
|
1851
|
-
false
|
|
1852
|
-
);
|
|
1853
|
-
}
|
|
1854
|
-
return createPromise();
|
|
1855
|
-
});
|
|
1856
|
-
}
|
|
1857
2545
|
// -------------------------------------------------------------------------
|
|
1858
2546
|
// Resource Methods
|
|
1859
2547
|
// -------------------------------------------------------------------------
|
|
@@ -1929,78 +2617,7 @@ var Geocoder = (function (exports) {
|
|
|
1929
2617
|
deleteResource(resource) {
|
|
1930
2618
|
return this.resources.delete(resource);
|
|
1931
2619
|
}
|
|
1932
|
-
/**
|
|
1933
|
-
* @internal
|
|
1934
|
-
*/
|
|
1935
|
-
_loadData(url, options) {
|
|
1936
|
-
options.responseType = options.responseType || "json";
|
|
1937
|
-
return new Promise((resolve, reject) => {
|
|
1938
|
-
var _a;
|
|
1939
|
-
if (this.user) {
|
|
1940
|
-
options = options || {};
|
|
1941
|
-
options.headers = __spreadValues$3(__spreadValues$3({}, this.getAuthorizationHeaders()), options.headers);
|
|
1942
|
-
}
|
|
1943
|
-
if (this.requestTransform) {
|
|
1944
|
-
const [transUrl, transOptions] = this.requestTransform(url, options);
|
|
1945
|
-
url = transUrl;
|
|
1946
|
-
options = transOptions;
|
|
1947
|
-
}
|
|
1948
|
-
let runOnAbort = void 0;
|
|
1949
|
-
loadData(url, resolve, options, reject, (handler) => {
|
|
1950
|
-
runOnAbort = handler;
|
|
1951
|
-
});
|
|
1952
|
-
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
1953
|
-
if (runOnAbort !== void 0) {
|
|
1954
|
-
runOnAbort();
|
|
1955
|
-
}
|
|
1956
|
-
reject(new AbortError());
|
|
1957
|
-
});
|
|
1958
|
-
}).catch((httpError) => {
|
|
1959
|
-
if (httpError.name !== "AbortError") {
|
|
1960
|
-
{
|
|
1961
|
-
console.warn("DEV WARN", httpError);
|
|
1962
|
-
}
|
|
1963
|
-
const er = this._handleHttpError(httpError);
|
|
1964
|
-
if (er) {
|
|
1965
|
-
throw er;
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
throw httpError;
|
|
1969
|
-
});
|
|
1970
|
-
}
|
|
1971
|
-
_login(credentials, options) {
|
|
1972
|
-
return __async$2(this, null, function* () {
|
|
1973
|
-
try {
|
|
1974
|
-
const data = yield this.getUserInfo(credentials, options);
|
|
1975
|
-
this.user = data;
|
|
1976
|
-
this.emitter.emit("login", data);
|
|
1977
|
-
return data;
|
|
1978
|
-
} catch (er) {
|
|
1979
|
-
this.emitter.emit("login:error", er);
|
|
1980
|
-
throw er;
|
|
1981
|
-
}
|
|
1982
|
-
});
|
|
1983
|
-
}
|
|
1984
|
-
_cleanActiveRequest(requestId) {
|
|
1985
|
-
delete this.activeRequests[requestId];
|
|
1986
|
-
}
|
|
1987
|
-
_handleHttpError(er) {
|
|
1988
|
-
if (er) {
|
|
1989
|
-
if (er instanceof NgwError) {
|
|
1990
|
-
if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
|
|
1991
|
-
throw new ResourceNotFoundError(er);
|
|
1992
|
-
} else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
|
|
1993
|
-
throw new InsufficientPermissionsError(er);
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
}
|
|
1997
|
-
return er;
|
|
1998
|
-
}
|
|
1999
2620
|
}
|
|
2000
|
-
__publicField$2(NgwConnector, "errors", {
|
|
2001
|
-
NgwError,
|
|
2002
|
-
ResourceNotFoundError
|
|
2003
|
-
});
|
|
2004
2621
|
|
|
2005
2622
|
function reEscape(s) {
|
|
2006
2623
|
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
@@ -2072,6 +2689,10 @@ var Geocoder = (function (exports) {
|
|
|
2072
2689
|
return logic === "any" ? filters_.some(filterFunction) : filters_.every(filterFunction);
|
|
2073
2690
|
}
|
|
2074
2691
|
|
|
2692
|
+
const config = {
|
|
2693
|
+
defaultRequestLimit: 7e3
|
|
2694
|
+
};
|
|
2695
|
+
|
|
2075
2696
|
var __defProp$3 = Object.defineProperty;
|
|
2076
2697
|
var __defProps$1 = Object.defineProperties;
|
|
2077
2698
|
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
@@ -2117,15 +2738,12 @@ var Geocoder = (function (exports) {
|
|
|
2117
2738
|
};
|
|
2118
2739
|
function updateItemRequestParam(params, options) {
|
|
2119
2740
|
const { extensions, geom, fields, srs, ilike, like } = options;
|
|
2120
|
-
|
|
2121
|
-
if (
|
|
2122
|
-
params.
|
|
2123
|
-
}
|
|
2124
|
-
if (fields !== void 0) {
|
|
2125
|
-
params.fields = Array.isArray(fields) ? fields.join(",") : "";
|
|
2741
|
+
params.extensions = extensions ? extensions : [];
|
|
2742
|
+
if (fields) {
|
|
2743
|
+
params.fields = fields;
|
|
2126
2744
|
}
|
|
2127
2745
|
if (geom !== void 0) {
|
|
2128
|
-
params.geom = geom
|
|
2746
|
+
params.geom = geom;
|
|
2129
2747
|
if (!geom) {
|
|
2130
2748
|
delete params.srs;
|
|
2131
2749
|
delete params.geom_format;
|
|
@@ -2140,6 +2758,15 @@ var Geocoder = (function (exports) {
|
|
|
2140
2758
|
params.srs = srs;
|
|
2141
2759
|
}
|
|
2142
2760
|
}
|
|
2761
|
+
function paramListToQuery(paramList) {
|
|
2762
|
+
return paramList.reduce(
|
|
2763
|
+
(acc, [key, value]) => {
|
|
2764
|
+
acc[key] = value;
|
|
2765
|
+
return acc;
|
|
2766
|
+
},
|
|
2767
|
+
{}
|
|
2768
|
+
);
|
|
2769
|
+
}
|
|
2143
2770
|
function createFeatureFieldFilterQueries(opt) {
|
|
2144
2771
|
return __async$1(this, null, function* () {
|
|
2145
2772
|
const queries = getQueries(opt);
|
|
@@ -2240,6 +2867,7 @@ var Geocoder = (function (exports) {
|
|
|
2240
2867
|
const params = __spreadValues$2({}, FEATURE_REQUEST_PARAMS);
|
|
2241
2868
|
const {
|
|
2242
2869
|
limit,
|
|
2870
|
+
query,
|
|
2243
2871
|
cache,
|
|
2244
2872
|
signal,
|
|
2245
2873
|
offset,
|
|
@@ -2250,12 +2878,10 @@ var Geocoder = (function (exports) {
|
|
|
2250
2878
|
intersects,
|
|
2251
2879
|
resourceId
|
|
2252
2880
|
} = options;
|
|
2253
|
-
if (limit) {
|
|
2254
|
-
|
|
2255
|
-
params.limit = limit;
|
|
2256
|
-
}
|
|
2881
|
+
if (limit && limit !== Number.POSITIVE_INFINITY) {
|
|
2882
|
+
params.limit = limit;
|
|
2257
2883
|
} else {
|
|
2258
|
-
params.limit =
|
|
2884
|
+
params.limit = config.defaultRequestLimit;
|
|
2259
2885
|
}
|
|
2260
2886
|
if (offset) {
|
|
2261
2887
|
params.offset = offset;
|
|
@@ -2274,16 +2900,9 @@ var Geocoder = (function (exports) {
|
|
|
2274
2900
|
params.intersects = intersects;
|
|
2275
2901
|
}
|
|
2276
2902
|
if (paramList) {
|
|
2277
|
-
params
|
|
2278
|
-
}
|
|
2279
|
-
|
|
2280
|
-
id: resourceId
|
|
2281
|
-
}, params);
|
|
2282
|
-
return connector.get(
|
|
2283
|
-
"feature_layer.feature.collection",
|
|
2284
|
-
{ cache, signal },
|
|
2285
|
-
reqParams
|
|
2286
|
-
);
|
|
2903
|
+
Object.assign(params, paramListToQuery(paramList));
|
|
2904
|
+
}
|
|
2905
|
+
return connector.route("feature_layer.feature.collection", { id: Number(resourceId) }).get({ query: __spreadValues$2(__spreadValues$2({}, params), query), cache, signal });
|
|
2287
2906
|
}
|
|
2288
2907
|
|
|
2289
2908
|
function prepareNgwFieldsToPropertiesFilter(fields) {
|
|
@@ -2436,7 +3055,7 @@ var Geocoder = (function (exports) {
|
|
|
2436
3055
|
"The `searchUrl` of `connectorOptions.baseUrl` are required"
|
|
2437
3056
|
);
|
|
2438
3057
|
}
|
|
2439
|
-
this.connector = options.connector || new
|
|
3058
|
+
this.connector = options.connector || new NgwConnectorExtended(__spreadValues({
|
|
2440
3059
|
baseUrl: this.searchUrl
|
|
2441
3060
|
}, options.connectorOptions));
|
|
2442
3061
|
this.searchResources = options.searchResources;
|
|
@@ -2485,7 +3104,7 @@ var Geocoder = (function (exports) {
|
|
|
2485
3104
|
yield item;
|
|
2486
3105
|
}
|
|
2487
3106
|
} catch (er) {
|
|
2488
|
-
if (er && "name" in er && er.name !== "
|
|
3107
|
+
if (er && "name" in er && er.name !== "AbortError") {
|
|
2489
3108
|
console.warn(er);
|
|
2490
3109
|
}
|
|
2491
3110
|
}
|
|
@@ -2494,14 +3113,10 @@ var Geocoder = (function (exports) {
|
|
|
2494
3113
|
}
|
|
2495
3114
|
result(item) {
|
|
2496
3115
|
const signal = this._makeSignal();
|
|
2497
|
-
const req = this.connector.
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
id: item.resourceId,
|
|
2502
|
-
fid: item.featureId
|
|
2503
|
-
}
|
|
2504
|
-
).then((x) => {
|
|
3116
|
+
const req = this.connector.route("feature_layer.feature.item_extent", {
|
|
3117
|
+
id: item.resourceId,
|
|
3118
|
+
fid: item.featureId
|
|
3119
|
+
}).get({ signal }).then((x) => {
|
|
2505
3120
|
const e = x.extent;
|
|
2506
3121
|
return {
|
|
2507
3122
|
text: item.text,
|
|
@@ -2588,56 +3203,69 @@ var Geocoder = (function (exports) {
|
|
|
2588
3203
|
};
|
|
2589
3204
|
class NominatimProvider extends BaseProvider {
|
|
2590
3205
|
constructor(options) {
|
|
2591
|
-
super(
|
|
3206
|
+
super();
|
|
3207
|
+
this.options = options;
|
|
2592
3208
|
__publicField(this, "searchUrl", "https://nominatim.openstreetmap.org");
|
|
2593
|
-
__publicField(this, "
|
|
3209
|
+
__publicField(this, "_abortControllers", []);
|
|
2594
3210
|
if (options && options.searchUrl) {
|
|
2595
3211
|
this.searchUrl = options.searchUrl;
|
|
2596
3212
|
}
|
|
2597
3213
|
}
|
|
2598
3214
|
abort() {
|
|
2599
|
-
this.
|
|
2600
|
-
|
|
3215
|
+
this._abortControllers.forEach((controller) => {
|
|
3216
|
+
controller.abort();
|
|
3217
|
+
});
|
|
3218
|
+
this._abortControllers = [];
|
|
2601
3219
|
}
|
|
2602
3220
|
search(val) {
|
|
2603
3221
|
return __asyncGenerator(this, null, function* () {
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
xhr.open("GET", url, true);
|
|
2611
|
-
xhr.onload = () => {
|
|
2612
|
-
try {
|
|
2613
|
-
const geojson = JSON.parse(xhr.responseText);
|
|
2614
|
-
const features = geojson.features.map((x) => {
|
|
2615
|
-
return {
|
|
2616
|
-
geom: x,
|
|
2617
|
-
extent: x.bbox,
|
|
2618
|
-
text: x.properties && x.properties.display_name,
|
|
2619
|
-
query: val
|
|
2620
|
-
};
|
|
2621
|
-
});
|
|
2622
|
-
resolve(features);
|
|
2623
|
-
} catch (er) {
|
|
2624
|
-
reject(er);
|
|
2625
|
-
}
|
|
2626
|
-
};
|
|
2627
|
-
xhr.onerror = (er) => {
|
|
2628
|
-
reject(er);
|
|
2629
|
-
};
|
|
2630
|
-
this._abort.push(xhr.abort);
|
|
2631
|
-
xhr.send();
|
|
2632
|
-
}).catch((er) => {
|
|
2633
|
-
if (er.name === "CancelError") ;
|
|
2634
|
-
throw er;
|
|
3222
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3223
|
+
const params = new URLSearchParams({
|
|
3224
|
+
format: "geojson",
|
|
3225
|
+
polygon_geojson: "1",
|
|
3226
|
+
q: val,
|
|
3227
|
+
limit: ((_b = (_a = this.options) == null ? void 0 : _a.limit) == null ? void 0 : _b.toString()) || "10"
|
|
2635
3228
|
});
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
3229
|
+
if ((_c = this.options) == null ? void 0 : _c.countrycodes) {
|
|
3230
|
+
params.append("countrycodes", this.options.countrycodes);
|
|
3231
|
+
}
|
|
3232
|
+
if ((_d = this.options) == null ? void 0 : _d.addressdetails) {
|
|
3233
|
+
params.append("addressdetails", "1");
|
|
3234
|
+
}
|
|
3235
|
+
if ((_e = this.options) == null ? void 0 : _e.language) {
|
|
3236
|
+
params.append("accept-language", this.options.language);
|
|
3237
|
+
}
|
|
3238
|
+
if ((_f = this.options) == null ? void 0 : _f.bounded) {
|
|
3239
|
+
params.append("bounded", "1");
|
|
3240
|
+
}
|
|
3241
|
+
if ((_g = this.options) == null ? void 0 : _g.viewbox) {
|
|
3242
|
+
const [minLon, minLat, maxLon, maxLat] = this.options.viewbox;
|
|
3243
|
+
params.append("viewbox", `${minLon},${minLat},${maxLon},${maxLat}`);
|
|
3244
|
+
}
|
|
3245
|
+
const url = fixUrlStr(`${this.searchUrl}/search?${params.toString()}`);
|
|
3246
|
+
const controller = new AbortController();
|
|
3247
|
+
this._abortControllers.push(controller);
|
|
3248
|
+
try {
|
|
3249
|
+
const response = yield new __await(fetch(url, { signal: controller.signal }));
|
|
3250
|
+
if (!response.ok) {
|
|
3251
|
+
throw new Error(`Network response was not ok: ${response.statusText}`);
|
|
3252
|
+
}
|
|
3253
|
+
const geojson = yield new __await(response.json());
|
|
3254
|
+
const features = geojson.features.map((x) => {
|
|
3255
|
+
return {
|
|
3256
|
+
geom: x,
|
|
3257
|
+
extent: x.bbox,
|
|
3258
|
+
text: x.properties && x.properties.display_name,
|
|
3259
|
+
query: val
|
|
3260
|
+
};
|
|
3261
|
+
});
|
|
3262
|
+
for (const item of features) {
|
|
3263
|
+
item.result = () => this.result(item);
|
|
3264
|
+
yield item;
|
|
3265
|
+
}
|
|
3266
|
+
} catch (error) {
|
|
3267
|
+
if (error.name === "AbortError") ; else {
|
|
3268
|
+
throw error;
|
|
2641
3269
|
}
|
|
2642
3270
|
}
|
|
2643
3271
|
});
|
|
@@ -2651,41 +3279,41 @@ var Geocoder = (function (exports) {
|
|
|
2651
3279
|
}
|
|
2652
3280
|
reverse(coordinates) {
|
|
2653
3281
|
return __asyncGenerator(this, null, function* () {
|
|
3282
|
+
var _a, _b;
|
|
2654
3283
|
const [lng, lat] = coordinates;
|
|
2655
|
-
const
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
const xhr = new XMLHttpRequest();
|
|
2660
|
-
xhr.open("GET", url, true);
|
|
2661
|
-
xhr.onload = () => {
|
|
2662
|
-
try {
|
|
2663
|
-
const geojson = JSON.parse(xhr.responseText);
|
|
2664
|
-
const feature = geojson.features[0];
|
|
2665
|
-
const result = {
|
|
2666
|
-
geom: feature,
|
|
2667
|
-
extent: feature.bbox,
|
|
2668
|
-
text: feature.properties && feature.properties.display_name,
|
|
2669
|
-
query: `${lat}, ${lng}`
|
|
2670
|
-
};
|
|
2671
|
-
resolve(result);
|
|
2672
|
-
} catch (er) {
|
|
2673
|
-
reject(er);
|
|
2674
|
-
}
|
|
2675
|
-
};
|
|
2676
|
-
xhr.onerror = (er) => {
|
|
2677
|
-
reject(er);
|
|
2678
|
-
};
|
|
2679
|
-
this._abort.push(xhr.abort);
|
|
2680
|
-
xhr.send();
|
|
2681
|
-
}).catch((er) => {
|
|
2682
|
-
if (er.name === "CancelError") ;
|
|
2683
|
-
throw er;
|
|
3284
|
+
const params = new URLSearchParams({
|
|
3285
|
+
format: "geojson",
|
|
3286
|
+
lat: lat.toString(),
|
|
3287
|
+
lon: lng.toString()
|
|
2684
3288
|
});
|
|
2685
|
-
|
|
2686
|
-
|
|
3289
|
+
if ((_a = this.options) == null ? void 0 : _a.addressdetails) {
|
|
3290
|
+
params.append("addressdetails", "1");
|
|
3291
|
+
}
|
|
3292
|
+
if ((_b = this.options) == null ? void 0 : _b.language) {
|
|
3293
|
+
params.append("accept-language", this.options.language);
|
|
3294
|
+
}
|
|
3295
|
+
const url = fixUrlStr(`${this.searchUrl}/reverse?${params.toString()}`);
|
|
3296
|
+
const controller = new AbortController();
|
|
3297
|
+
this._abortControllers.push(controller);
|
|
3298
|
+
try {
|
|
3299
|
+
const response = yield new __await(fetch(url, { signal: controller.signal }));
|
|
3300
|
+
if (!response.ok) {
|
|
3301
|
+
throw new Error(`Network response was not ok: ${response.statusText}`);
|
|
3302
|
+
}
|
|
3303
|
+
const geojson = yield new __await(response.json());
|
|
3304
|
+
const feature = geojson.features[0];
|
|
3305
|
+
const item = {
|
|
3306
|
+
geom: feature,
|
|
3307
|
+
extent: feature.bbox,
|
|
3308
|
+
text: feature.properties && feature.properties.display_name,
|
|
3309
|
+
query: `${lat}, ${lng}`
|
|
3310
|
+
};
|
|
2687
3311
|
item.result = () => this.result(item);
|
|
2688
3312
|
yield item;
|
|
3313
|
+
} catch (error) {
|
|
3314
|
+
if (error.name === "AbortError") ; else {
|
|
3315
|
+
throw error;
|
|
3316
|
+
}
|
|
2689
3317
|
}
|
|
2690
3318
|
});
|
|
2691
3319
|
}
|