@nextgis/ngw-connector 3.0.0-alpha.2 → 3.0.0-alpha.22

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.
@@ -1,4 +1,304 @@
1
- /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.2; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.20; author: NextGIS */
2
+ function defined(val) {
3
+ return val !== void 0 && val !== null;
4
+ }
5
+ function full(val) {
6
+ return typeof val === "string" ? !!val : defined(val);
7
+ }
8
+
9
+ function isEqual(a, b, o, p) {
10
+ if (a instanceof Array) {
11
+ if (!(b instanceof Array)) return false;
12
+ return b.sort().join("") === a.sort().join("");
13
+ } else if (a instanceof Date) {
14
+ if (!(b instanceof Date)) return false;
15
+ return "" + a === "" + b;
16
+ } else if (a instanceof Function) {
17
+ if (!(b instanceof Function)) return false;
18
+ } else if (a instanceof Object) {
19
+ if (!(b instanceof Object)) return false;
20
+ if (a === o) {
21
+ return b === p;
22
+ } else {
23
+ return objectDeepEqual(a, b);
24
+ }
25
+ }
26
+ return a === b;
27
+ }
28
+ function objectDeepEqual(o, p) {
29
+ const keysO = Object.keys(o).sort();
30
+ const keysP = Object.keys(p).sort();
31
+ if (keysO.length !== keysP.length) return false;
32
+ if (keysO.join("") !== keysP.join("")) return false;
33
+ for (let i = 0; i < keysO.length; i++) {
34
+ const oVal = o[keysO[i]];
35
+ const pVal = p[keysP[i]];
36
+ if (!isEqual(oVal, pVal, o, p)) {
37
+ return false;
38
+ }
39
+ }
40
+ return true;
41
+ }
42
+
43
+ function objectRemoveEmpty(obj) {
44
+ const newObj = {};
45
+ Object.keys(obj).forEach((key) => {
46
+ if (!(obj[key] instanceof Array) && obj[key] === Object(obj[key])) {
47
+ newObj[key] = objectRemoveEmpty(obj[key]);
48
+ } else if (obj[key] !== void 0) {
49
+ newObj[key] = obj[key];
50
+ }
51
+ });
52
+ return newObj;
53
+ }
54
+
55
+ function isObject$1(val) {
56
+ return Object.prototype.toString.call(val) === "[object Object]";
57
+ }
58
+
59
+ function fixUrlStr(url) {
60
+ return url.replace(/([^:]\/)\/+/g, "$1");
61
+ }
62
+
63
+ const templateRe = /\{ *([\w_-]+) *\}/g;
64
+ function template(str, data) {
65
+ return str.replace(templateRe, (s, key) => {
66
+ let value = data[key];
67
+ if (value === void 0) {
68
+ throw new Error("No value provided for letiable " + s);
69
+ } else if (typeof value === "function") {
70
+ value = value(data);
71
+ }
72
+ return value;
73
+ });
74
+ }
75
+
76
+ var __defProp$c = Object.defineProperty;
77
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
78
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
79
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
80
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
81
+ var __spreadValues$4 = (a, b) => {
82
+ for (var prop in b || (b = {}))
83
+ if (__hasOwnProp$4.call(b, prop))
84
+ __defNormalProp$c(a, prop, b[prop]);
85
+ if (__getOwnPropSymbols$4)
86
+ for (var prop of __getOwnPropSymbols$4(b)) {
87
+ if (__propIsEnum$4.call(b, prop))
88
+ __defNormalProp$c(a, prop, b[prop]);
89
+ }
90
+ return a;
91
+ };
92
+ var __async$4 = (__this, __arguments, generator) => {
93
+ return new Promise((resolve, reject) => {
94
+ var fulfilled = (value) => {
95
+ try {
96
+ step(generator.next(value));
97
+ } catch (e) {
98
+ reject(e);
99
+ }
100
+ };
101
+ var rejected = (value) => {
102
+ try {
103
+ step(generator.throw(value));
104
+ } catch (e) {
105
+ reject(e);
106
+ }
107
+ };
108
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
109
+ step((generator = generator.apply(__this, __arguments)).next());
110
+ });
111
+ };
112
+ function apiRequest(opt) {
113
+ return __async$4(this, null, function* () {
114
+ const { params, name, connector, requestOptions } = opt;
115
+ const apiItems = yield connector.connect();
116
+ let apiItem = apiItems && apiItems[name];
117
+ if (apiItem) {
118
+ apiItem = [...apiItem];
119
+ let url = apiItem.shift();
120
+ if (apiItem.length) {
121
+ const replaceParams = {};
122
+ for (let fry = 0; fry < apiItem.length; fry++) {
123
+ const arg = apiItem[fry];
124
+ replaceParams[fry] = `{${arg}}`;
125
+ if (params[arg] === void 0) {
126
+ throw new Error(`\`${arg}\` URL API argument is not specified`);
127
+ }
128
+ }
129
+ if (url) {
130
+ url = template(url, replaceParams);
131
+ }
132
+ }
133
+ if (params) {
134
+ const paramArray = [];
135
+ const paramList = params.paramList;
136
+ if (Array.isArray(paramList)) {
137
+ paramList.forEach(([key, value]) => {
138
+ paramArray.push(`${key}=${value}`);
139
+ });
140
+ }
141
+ for (const p in params) {
142
+ if (apiItem.indexOf(p) === -1) {
143
+ paramArray.push(`${p}=${params[p]}`);
144
+ }
145
+ }
146
+ if (paramArray.length) {
147
+ url = `${url}?${paramArray.join("&")}`;
148
+ }
149
+ }
150
+ if (url) {
151
+ return connector.makeQuery(url, params, __spreadValues$4({
152
+ cacheName: name
153
+ }, requestOptions));
154
+ } else {
155
+ throw new Error("Request URL is not set");
156
+ }
157
+ } else {
158
+ return void 0;
159
+ }
160
+ });
161
+ }
162
+
163
+ var __defProp$b = Object.defineProperty;
164
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
165
+ var __publicField$9 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
166
+ const _Cache = class _Cache {
167
+ constructor(options = {}) {
168
+ __publicField$9(this, "cache", []);
169
+ var _a;
170
+ const namespace = (_a = options.namespace) != null ? _a : "default";
171
+ if (_Cache.instance[namespace]) {
172
+ return _Cache.instance[namespace];
173
+ }
174
+ _Cache.instance[namespace] = this;
175
+ return this;
176
+ }
177
+ clean() {
178
+ this.cache.length = 0;
179
+ }
180
+ all() {
181
+ return this.cache;
182
+ }
183
+ /**
184
+ * Caching only a non-empty value.
185
+ *
186
+ * Useful for get or create strategy
187
+ * @example
188
+ * ```javascript
189
+ * const cache = new Cache();
190
+ * const getItemFunc = () => fetch(url).then((data) => {
191
+ * return data.json(); // undefined
192
+ * });
193
+ * const item = await cache.addFull('foo', getItemFunc);
194
+ * if (!item) {
195
+ * await createItem(); // 'New item'
196
+ * }
197
+ *
198
+ * // somewhere else in the code
199
+ * const item = await cache.addFull('foo', getItemFunc).then((resp) => {
200
+ * console.log(resp); // 'New item'
201
+ * });
202
+ * ```
203
+ */
204
+ addFull(key, valueToSet, propsOrOptions, expirationTime) {
205
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
206
+ propsOrOptions.onlyFull = true;
207
+ }
208
+ return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
209
+ }
210
+ add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
211
+ let opt;
212
+ let props;
213
+ if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
214
+ opt = propsOrOptions;
215
+ onlyFull = opt.onlyFull;
216
+ expirationTime = opt.expirationTime;
217
+ props = opt.props;
218
+ } else {
219
+ props = propsOrOptions;
220
+ }
221
+ const exist = this._find(key, props);
222
+ if (!exist) {
223
+ let value;
224
+ if (valueToSet instanceof Function) {
225
+ value = valueToSet();
226
+ } else {
227
+ value = valueToSet;
228
+ }
229
+ const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
230
+ expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
231
+ const cacheItem = {
232
+ key,
233
+ value,
234
+ props: nonEmptyProps,
235
+ expirationTime
236
+ };
237
+ if (onlyFull && !full(value)) {
238
+ return value;
239
+ }
240
+ this.cache.push(cacheItem);
241
+ if (value instanceof Promise) {
242
+ value.catch(() => {
243
+ this.delete(key, props);
244
+ });
245
+ if (onlyFull) {
246
+ value.then((x) => {
247
+ if (!full(x)) {
248
+ this.delete(key, props);
249
+ }
250
+ return x;
251
+ });
252
+ }
253
+ return value;
254
+ }
255
+ return value;
256
+ } else {
257
+ return exist.value;
258
+ }
259
+ }
260
+ match(key, props) {
261
+ const cacheRecord = this._find(key, props);
262
+ if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
263
+ this.delete(cacheRecord);
264
+ return void 0;
265
+ }
266
+ return cacheRecord == null ? void 0 : cacheRecord.value;
267
+ }
268
+ matchAll(key, props) {
269
+ const now = Date.now();
270
+ this.cache.forEach((item) => {
271
+ if (item.expirationTime && now > item.expirationTime) {
272
+ this.delete(item);
273
+ }
274
+ });
275
+ if (key) {
276
+ return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
277
+ }
278
+ return this.cache.map((x) => x.value);
279
+ }
280
+ delete(keyOrItem, props) {
281
+ const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
282
+ for (const item of itemsToDelete) {
283
+ const index = this.cache.indexOf(item);
284
+ if (index !== -1) {
285
+ this.cache.splice(index, 1);
286
+ }
287
+ }
288
+ }
289
+ _find(key, props) {
290
+ return this.cache.find((x) => this._filter(x, key, props));
291
+ }
292
+ _filter(item, key, props) {
293
+ if (item.key !== key) return false;
294
+ if (!props) return true;
295
+ const itemProps = item.props;
296
+ return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
297
+ }
298
+ };
299
+ __publicField$9(_Cache, "instance", {});
300
+ let Cache = _Cache;
301
+
2
302
  var domain;
3
303
 
4
304
  // This constructor is used to store event handlers. Instantiating this is
@@ -471,180 +771,9 @@ function unwrapListeners(arr) {
471
771
  return ret;
472
772
  }
473
773
 
474
- function defined(val) {
475
- return val !== void 0 && val !== null;
476
- }
477
- function full(val) {
478
- return typeof val === "string" ? !!val : defined(val);
479
- }
480
-
481
- function isEqual(a, b, o, p) {
482
- if (a instanceof Array) {
483
- if (!(b instanceof Array)) return false;
484
- return b.sort().join("") === a.sort().join("");
485
- } else if (a instanceof Date) {
486
- if (!(b instanceof Date)) return false;
487
- return "" + a === "" + b;
488
- } else if (a instanceof Function) {
489
- if (!(b instanceof Function)) return false;
490
- } else if (a instanceof Object) {
491
- if (!(b instanceof Object)) return false;
492
- if (a === o) {
493
- return b === p;
494
- } else {
495
- return objectDeepEqual(a, b);
496
- }
497
- }
498
- return a === b;
499
- }
500
- function objectDeepEqual(o, p) {
501
- const keysO = Object.keys(o).sort();
502
- const keysP = Object.keys(p).sort();
503
- if (keysO.length !== keysP.length) return false;
504
- if (keysO.join("") !== keysP.join("")) return false;
505
- for (let i = 0; i < keysO.length; i++) {
506
- const oVal = o[keysO[i]];
507
- const pVal = p[keysP[i]];
508
- if (!isEqual(oVal, pVal, o, p)) {
509
- return false;
510
- }
511
- }
512
- return true;
513
- }
514
-
515
- function objectRemoveEmpty(obj) {
516
- const newObj = {};
517
- Object.keys(obj).forEach((key) => {
518
- if (!(obj[key] instanceof Array) && obj[key] === Object(obj[key])) {
519
- newObj[key] = objectRemoveEmpty(obj[key]);
520
- } else if (obj[key] !== void 0) {
521
- newObj[key] = obj[key];
522
- }
523
- });
524
- return newObj;
525
- }
526
-
527
- function fixUrlStr(url) {
528
- return url.replace(/([^:]\/)\/+/g, "$1");
529
- }
530
-
531
- var __defProp$7 = Object.defineProperty;
532
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
533
- var __publicField$6 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
534
- const _Cache = class _Cache {
535
- constructor(options = {}) {
536
- __publicField$6(this, "cache", []);
537
- var _a;
538
- const namespace = (_a = options.namespace) != null ? _a : "default";
539
- if (_Cache.instance[namespace]) {
540
- return _Cache.instance[namespace];
541
- }
542
- _Cache.instance[namespace] = this;
543
- return this;
544
- }
545
- clean() {
546
- this.cache.length = 0;
547
- }
548
- all() {
549
- return this.cache;
550
- }
551
- /**
552
- * Caching only a non-empty value.
553
- *
554
- * Useful for get or create strategy
555
- * @example
556
- * ```javascript
557
- * const cache = new Cache();
558
- * const getItemFunc = () => fetch(url).then((data) => {
559
- * return data.json(); // undefined
560
- * });
561
- * const item = await cache.addFull('foo', getItemFunc);
562
- * if (!item) {
563
- * await createItem(); // 'New item'
564
- * }
565
- *
566
- * // somewhere else in the code
567
- * const item = await cache.addFull('foo', getItemFunc).then((resp) => {
568
- * console.log(resp); // 'New item'
569
- * });
570
- * ```
571
- */
572
- addFull(key, valueToSet, props) {
573
- return this.add(key, valueToSet, props, true);
574
- }
575
- add(key, valueToSet, props, onlyFull) {
576
- const exist = this._find(key, props);
577
- if (!exist) {
578
- let value;
579
- if (valueToSet instanceof Function) {
580
- value = valueToSet();
581
- } else {
582
- value = valueToSet;
583
- }
584
- const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
585
- const cacheItem = {
586
- key,
587
- value,
588
- props: nonEmptyProps
589
- };
590
- if (onlyFull && !full(value)) {
591
- return value;
592
- }
593
- this.cache.push(cacheItem);
594
- if (value instanceof Promise) {
595
- value.catch((er) => {
596
- this.delete(key, props);
597
- });
598
- if (onlyFull) {
599
- value.then((x) => {
600
- if (!full(x)) {
601
- this.delete(key, props);
602
- }
603
- return x;
604
- });
605
- }
606
- return value;
607
- }
608
- return value;
609
- } else {
610
- return exist.value;
611
- }
612
- }
613
- match(key, props) {
614
- const cacheRecord = this._find(key, props);
615
- return cacheRecord == null ? void 0 : cacheRecord.value;
616
- }
617
- matchAll(key, props) {
618
- if (key) {
619
- return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
620
- }
621
- return this.cache.map((x) => x.value);
622
- }
623
- delete(keyOrItem, props) {
624
- const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
625
- for (const item of itemsToDelete) {
626
- const index = this.cache.indexOf(item);
627
- if (index !== -1) {
628
- this.cache.splice(index, 1);
629
- }
630
- }
631
- }
632
- _find(key, props) {
633
- return this.cache.find((x) => this._filter(x, key, props));
634
- }
635
- _filter(item, key, props) {
636
- if (item.key !== key) return false;
637
- if (!props) return true;
638
- const itemProps = item.props;
639
- return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
640
- }
641
- };
642
- __publicField$6(_Cache, "instance", {});
643
- let Cache = _Cache;
644
-
645
774
  var pkg = {
646
775
  name: "@nextgis/ngw-connector",
647
- version: "3.0.0-alpha.2",
776
+ version: "3.0.0-alpha.20",
648
777
  _priority: 12,
649
778
  description: "A lightweight HTTP client optimized for use with NextGIS Web API",
650
779
  main: "index.js",
@@ -653,15 +782,15 @@ var pkg = {
653
782
  jsdelivr: "lib/ngw-connector.global.prod.js",
654
783
  types: "lib/index.d.ts",
655
784
  dependencies: {
656
- "@nextgis/cache": "^3.0.0-alpha.1",
657
- "@nextgis/cancelable-promise": "^3.0.0-alpha.1",
658
- "@nextgis/utils": "^3.0.0-alpha.1",
785
+ "@nextgis/cache": "3.0.0-alpha.17",
786
+ "@nextgis/cancelable-promise": "3.0.0-alpha.17",
787
+ "@nextgis/utils": "3.0.0-alpha.17",
659
788
  "@types/events": "^3.0.0",
660
789
  events: "*",
661
790
  "form-data": "^4.0.0"
662
791
  },
663
792
  devDependencies: {
664
- "@nextgis/build-tools": "^3.0.0-alpha.1"
793
+ "@nextgis/build-tools": "3.0.0-alpha.17"
665
794
  },
666
795
  scripts: {
667
796
  clean: "rimraf ./lib",
@@ -695,31 +824,111 @@ var pkg = {
695
824
  type: "git",
696
825
  url: "git://github.com/nextgis/nextgis_frontend.git"
697
826
  },
827
+ engines: {
828
+ node: ">=18.20.4"
829
+ },
698
830
  gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
699
831
  };
700
832
 
701
- var __defProp$6 = Object.defineProperty;
702
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
703
- var __publicField$5 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
833
+ class AbortError extends Error {
834
+ constructor(message = "AbortError") {
835
+ super(message);
836
+ this.name = "AbortError";
837
+ }
838
+ }
839
+
840
+ var __defProp$a = Object.defineProperty;
841
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
842
+ var __publicField$8 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
704
843
  class NgwError extends Error {
705
844
  constructor(er) {
706
845
  super();
707
- __publicField$5(this, "name", "NgwError");
708
- __publicField$5(this, "title");
709
- __publicField$5(this, "message");
710
- __publicField$5(this, "detail");
711
- __publicField$5(this, "exception");
712
- __publicField$5(this, "status_code");
713
- __publicField$5(this, "data");
714
- __publicField$5(this, "guru_meditation");
846
+ __publicField$8(this, "name", "NgwError");
847
+ __publicField$8(this, "title");
848
+ __publicField$8(this, "message");
849
+ __publicField$8(this, "detail");
850
+ __publicField$8(this, "exception");
851
+ __publicField$8(this, "status_code");
852
+ __publicField$8(this, "data");
853
+ __publicField$8(this, "guru_meditation");
715
854
  Object.assign(this, er);
716
855
  Object.setPrototypeOf(this, NgwError.prototype);
717
856
  }
718
857
  }
719
858
 
720
- var __defProp$5 = Object.defineProperty;
721
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
722
- var __publicField$4 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
859
+ var __defProp$9 = Object.defineProperty;
860
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
861
+ var __publicField$7 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
862
+ class InsufficientPermissionsError extends NgwError {
863
+ constructor(obj) {
864
+ super(obj);
865
+ __publicField$7(this, "name", "InsufficientPermissionsError");
866
+ __publicField$7(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
867
+ Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
868
+ }
869
+ }
870
+
871
+ var __defProp$8 = Object.defineProperty;
872
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
873
+ var __publicField$6 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
874
+ let NetworksResponseError$1 = class NetworksResponseError extends NgwError {
875
+ constructor(obj) {
876
+ super(obj);
877
+ __publicField$6(this, "message", "There is no response from the server or problem connecting to server.");
878
+ __publicField$6(this, "title", "Network error");
879
+ __publicField$6(this, "detail", "Check network connectivity and try again later.");
880
+ Object.setPrototypeOf(this, NetworksResponseError.prototype);
881
+ }
882
+ };
883
+
884
+ function extractError(error) {
885
+ if (isObject$1(error)) {
886
+ if (error.name && error.message && error.title) {
887
+ return {
888
+ title: error.title,
889
+ message: error.message,
890
+ detail: error.detail || null,
891
+ data: error.data && error.data.data ? error.data.data : null
892
+ };
893
+ } else if (error.exception) {
894
+ if (error.status === void 0 || error.status === 0 || error.data === void 0) {
895
+ return new NetworksResponseError$1({
896
+ title: error.title,
897
+ status_code: error.status_code,
898
+ exception: error.exception
899
+ });
900
+ }
901
+ }
902
+ return {
903
+ title: typeof error.title === "string" ? error.title : "Unexpected error",
904
+ message: typeof error.message === "string" ? error.message : "Something went wrong."
905
+ };
906
+ }
907
+ }
908
+
909
+ function isError(error) {
910
+ if (isObject$1(error)) {
911
+ return error.status_code && error.exception && error.title;
912
+ }
913
+ return false;
914
+ }
915
+
916
+ var __defProp$7 = Object.defineProperty;
917
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
918
+ var __publicField$5 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
919
+ class NetworkError extends Error {
920
+ constructor(url) {
921
+ super();
922
+ __publicField$5(this, "name", "NetworkError");
923
+ Object.setPrototypeOf(this, NetworkError.prototype);
924
+ this.message = `Unable to request ${url}.
925
+ Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
926
+ }
927
+ }
928
+
929
+ var __defProp$6 = Object.defineProperty;
930
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
931
+ var __publicField$4 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
723
932
  class ResourceNotFoundError extends NgwError {
724
933
  constructor(obj) {
725
934
  super(obj);
@@ -729,53 +938,111 @@ class ResourceNotFoundError extends NgwError {
729
938
  }
730
939
  }
731
940
 
732
- function isObject(val) {
733
- return Object.prototype.toString.call(val) === "[object Object]";
734
- }
941
+ var errors = /*#__PURE__*/Object.freeze({
942
+ __proto__: null,
943
+ AbortError: AbortError,
944
+ InsufficientPermissionsError: InsufficientPermissionsError,
945
+ NetworkError: NetworkError,
946
+ NetworksResponseError: NetworksResponseError$1,
947
+ NgwError: NgwError,
948
+ ResourceNotFoundError: ResourceNotFoundError,
949
+ extractError: extractError,
950
+ isError: isError
951
+ });
735
952
 
736
- function resourceCompare(res1, res2) {
737
- return objectDeepEqual(res1, res2);
953
+ var __defProp$5 = Object.defineProperty;
954
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
955
+ var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
956
+ class BaseAPIError extends Error {
957
+ constructor(message) {
958
+ super(message || "Something went wrong.");
959
+ __publicField$3(this, "title");
960
+ this.name = "BaseAPIError";
961
+ this.title = "Unknown API error";
962
+ if (Error.captureStackTrace) {
963
+ Error.captureStackTrace(this, BaseAPIError);
964
+ }
965
+ }
738
966
  }
739
-
740
- const exclude = ["description"];
741
- function resourceToQuery(resource, prefix = "") {
742
- prefix = prefix ? prefix + "__" : "";
743
- const query = {};
744
- for (const [key, value] of Object.entries(resource)) {
745
- if (exclude.indexOf(key) === -1) {
746
- if (isObject(value)) {
747
- if (key === "owner_user") {
748
- const children = resourceToQuery(value, key);
749
- Object.assign(query, children);
750
- } else if (key === "parent" && "id" in value) {
751
- query.parent_id = value.id;
752
- }
753
- } else if (defined(value)) {
754
- query[prefix + key] = value;
755
- }
967
+ class NetworksResponseError extends BaseAPIError {
968
+ // prettier-ignore
969
+ constructor(message) {
970
+ super(message || "There is no response from the server or problem connecting to server.");
971
+ __publicField$3(this, "detail");
972
+ this.title = "Network error";
973
+ this.detail = "Check network connectivity and try again later.";
974
+ }
975
+ }
976
+ class InvalidResponseError extends BaseAPIError {
977
+ constructor(message) {
978
+ super(message || "Something went wrong.");
979
+ this.title = "Unexpected server response";
980
+ }
981
+ }
982
+ class ServerResponseError extends BaseAPIError {
983
+ constructor(data) {
984
+ super(data.message);
985
+ __publicField$3(this, "detail");
986
+ __publicField$3(this, "data");
987
+ this.title = data.title || this.title;
988
+ this.detail = data.detail || null;
989
+ this.data = data;
990
+ }
991
+ }
992
+ class LunkwillError extends Error {
993
+ // prettier-ignore
994
+ constructor(message, data = {}) {
995
+ super(message || "Unexpected error while processing long-running request.");
996
+ __publicField$3(this, "title");
997
+ __publicField$3(this, "data");
998
+ this.name = "LunkwillError";
999
+ this.title = "Long-running request error";
1000
+ this.data = data;
1001
+ if (Error.captureStackTrace) {
1002
+ Error.captureStackTrace(this, LunkwillError);
756
1003
  }
757
1004
  }
758
- return query;
1005
+ }
1006
+ class LunkwillRequestCancelled extends LunkwillError {
1007
+ constructor(data) {
1008
+ super("Long-running request was cancelled.", data);
1009
+ }
1010
+ }
1011
+ class LunkwillRequestFailed extends LunkwillError {
1012
+ constructor(data) {
1013
+ super(void 0, data);
1014
+ }
759
1015
  }
760
1016
 
761
1017
  var __defProp$4 = Object.defineProperty;
762
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
763
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
764
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1018
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1019
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1020
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
765
1021
  var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
766
- var __spreadValues$2 = (a, b) => {
1022
+ var __spreadValues$3 = (a, b) => {
767
1023
  for (var prop in b || (b = {}))
768
- if (__hasOwnProp$2.call(b, prop))
1024
+ if (__hasOwnProp$3.call(b, prop))
769
1025
  __defNormalProp$4(a, prop, b[prop]);
770
- if (__getOwnPropSymbols$2)
771
- for (var prop of __getOwnPropSymbols$2(b)) {
772
- if (__propIsEnum$2.call(b, prop))
1026
+ if (__getOwnPropSymbols$3)
1027
+ for (var prop of __getOwnPropSymbols$3(b)) {
1028
+ if (__propIsEnum$3.call(b, prop))
773
1029
  __defNormalProp$4(a, prop, b[prop]);
774
1030
  }
775
1031
  return a;
776
1032
  };
777
- var __publicField$3 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
778
- var __async$2 = (__this, __arguments, generator) => {
1033
+ var __objRest$2 = (source, exclude) => {
1034
+ var target = {};
1035
+ for (var prop in source)
1036
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
1037
+ target[prop] = source[prop];
1038
+ if (source != null && __getOwnPropSymbols$3)
1039
+ for (var prop of __getOwnPropSymbols$3(source)) {
1040
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
1041
+ target[prop] = source[prop];
1042
+ }
1043
+ return target;
1044
+ };
1045
+ var __async$3 = (__this, __arguments, generator) => {
779
1046
  return new Promise((resolve, reject) => {
780
1047
  var fulfilled = (value) => {
781
1048
  try {
@@ -795,307 +1062,251 @@ var __async$2 = (__this, __arguments, generator) => {
795
1062
  step((generator = generator.apply(__this, __arguments)).next());
796
1063
  });
797
1064
  };
798
- class ResourcesControl {
799
- constructor({
800
- connector,
801
- cacheId
802
- }) {
803
- __publicField$3(this, "cache");
804
- __publicField$3(this, "connector");
805
- this.connector = connector;
806
- this.cache = new Cache({ namespace: cacheId });
807
- }
808
- // -------------------------------------------------------------------------
809
- // Resource Methods
810
- // -------------------------------------------------------------------------
811
- /**
812
- * Receive resource from NGW by id, keyname or search-object parameter.
813
- * @param resource - Resource id, keyname or search-object
814
- *
815
- * @remarks
816
- * Fetching resource would be cached to speed up next call
817
- */
818
- getOne(resource, requestOptions) {
819
- const opt = __spreadValues$2({}, requestOptions);
820
- if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
821
- if (resource.id !== void 0) {
822
- resource.id;
823
- } else {
824
- if (resource.keyname) {
825
- resource.keyname;
826
- }
827
- if (resource.display_name) {
828
- resource.display_name;
829
- }
1065
+ function lunkwillCheckResponse(lwResp) {
1066
+ const ct = lwResp.headers.get("content-type");
1067
+ return ct !== void 0 && ct !== null && ct.includes("application/vnd.lunkwill.request-summary+json");
1068
+ }
1069
+ function responseJson(response) {
1070
+ return __async$3(this, null, function* () {
1071
+ try {
1072
+ return response.json();
1073
+ } catch (e) {
1074
+ throw new Error();
1075
+ }
1076
+ });
1077
+ }
1078
+ function lunkwillResponseUrl(lwResp) {
1079
+ return __async$3(this, null, function* () {
1080
+ const lwData = yield responseJson(lwResp);
1081
+ let delay = lwData.delay_ms;
1082
+ const retry = lwData.retry_ms !== void 0 ? lwData.retry_ms : 2e3;
1083
+ const sum = `/api/lunkwill/${lwData.id}/summary`;
1084
+ const res = `/api/lunkwill/${lwData.id}/response`;
1085
+ const sleep = (msec) => new Promise((resolve) => setTimeout(resolve, msec));
1086
+ let failed = false;
1087
+ let ready = false;
1088
+ while (!ready) {
1089
+ yield sleep(failed ? retry : delay);
1090
+ failed = false;
1091
+ let lwResp2;
1092
+ let lwData2;
1093
+ try {
1094
+ lwResp2 = yield fetch(sum, { credentials: "same-origin" });
1095
+ lwData2 = yield lwResp2.json();
1096
+ } catch (e) {
1097
+ failed = true;
1098
+ continue;
1099
+ }
1100
+ switch (lwData2.status) {
1101
+ case void 0:
1102
+ throw new LunkwillError(void 0, lwData2);
1103
+ case "ready":
1104
+ ready = true;
1105
+ break;
1106
+ case "cancelled":
1107
+ throw new LunkwillRequestCancelled(lwData2);
1108
+ case "failed":
1109
+ throw new LunkwillRequestFailed(lwData2);
1110
+ case "spooled":
1111
+ case "processing":
1112
+ case "buffering":
1113
+ delay = lwData2.delay_ms;
1114
+ break;
1115
+ default:
1116
+ throw new LunkwillError(void 0, lwData2);
830
1117
  }
831
1118
  }
832
- if (typeof resource === "string") {
833
- return this._fetchResourceBy({ keyname: resource }, opt);
834
- } else if (typeof resource === "number") {
835
- return this._fetchResourceById(resource, opt);
836
- } else if (isObject(resource)) {
837
- return this._fetchResourceBy(resource, opt);
1119
+ return res;
1120
+ });
1121
+ }
1122
+ function lunkwillFetch(lwRespUrl) {
1123
+ return __async$3(this, null, function* () {
1124
+ try {
1125
+ return yield window.fetch(lwRespUrl, { credentials: "same-origin" });
1126
+ } catch (e) {
1127
+ throw new NetworksResponseError();
838
1128
  }
839
- return Promise.resolve(void 0);
840
- }
841
- getOneOrFail(resource, requestOptions) {
842
- return this.getOne(resource, requestOptions).then((res) => {
843
- if (res) {
844
- return res;
845
- }
846
- throw new ResourceNotFoundError();
847
- });
848
- }
849
- /**
850
- * A fast way to retrieve resource ID for any resource definition.
851
- * @param resource - Any available resource definition
852
- *
853
- * @remarks
854
- * There are situations when exactly the resource id is needed
855
- * (for example, to compose the correct request to the api)
856
- * then this method will come in handy to facilitate the extraction of the identifier
857
- * if the resource is specified through a keyname or other parameters.
858
- */
859
- getId(resource, requestOptions) {
860
- if (typeof resource === "number") {
861
- return Promise.resolve(resource);
862
- } else if (typeof resource === "string" || isObject(resource)) {
863
- return this.getOne(resource, requestOptions).then((res) => {
864
- if (res) {
865
- return res.resource.id;
1129
+ });
1130
+ }
1131
+ const mediaContentTypes = [
1132
+ "application/pdf",
1133
+ "image/png",
1134
+ "image/jpeg",
1135
+ "image/tiff",
1136
+ "text/csv"
1137
+ ];
1138
+ const mediaContentTypesRegex = new RegExp(mediaContentTypes.join("|"));
1139
+ function isMediaContentType(contentType) {
1140
+ return mediaContentTypesRegex.test(contentType);
1141
+ }
1142
+ function encodeQueryParams(value) {
1143
+ const result = [];
1144
+ for (const [k, v] of Object.entries(value)) {
1145
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
1146
+ result.push(`${k}=${encodeURIComponent(v)}`);
1147
+ } else if (Array.isArray(v)) {
1148
+ result.push(`${k}=${v.map(encodeURIComponent).join(",")}`);
1149
+ } else {
1150
+ for (const [sk, sv] of Object.entries(v)) {
1151
+ const ske = `${k}[${encodeURIComponent(sk)}]`;
1152
+ if (typeof sv === "string" || typeof sv === "number" || typeof sv === "boolean") {
1153
+ result.push(`${ske}=${encodeURIComponent(sv)}`);
1154
+ } else if (Array.isArray(sv)) {
1155
+ const sve = sv.map(encodeURIComponent);
1156
+ result.push(`${ske}=${sve.join(",")}`);
866
1157
  }
867
- });
1158
+ }
868
1159
  }
869
- return Promise.resolve(void 0);
870
1160
  }
871
- /**
872
- * A fast way to retrieve resource ID for any resource definition.
873
- * @param resource - Any available resource definition
874
- *
875
- * @remarks
876
- * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
877
- * To not make one more checks if the resource is definitely exists
878
- */
879
- getIdOrFail(resource, requestOptions) {
880
- return this.getId(resource, requestOptions).then((resp) => {
881
- if (resp === void 0) {
882
- throw new Error();
883
- }
884
- return resp;
885
- });
1161
+ return result.join("&");
1162
+ }
1163
+ function generateUrl(path, query) {
1164
+ let urlParams = "";
1165
+ if (query !== void 0) {
1166
+ urlParams = "?" + encodeQueryParams(query);
886
1167
  }
887
- getMany(resource, requestOptions) {
888
- return this._resourceCacheFilter(resource).then((items) => {
889
- if (!items.length) {
890
- const query = {};
891
- if (resource.keyname) {
892
- query.keyname = resource.keyname;
893
- } else {
894
- Object.assign(query, resourceToQuery(resource));
1168
+ return path + urlParams;
1169
+ }
1170
+ function request(path, options, cacheEngine) {
1171
+ return __async$3(this, null, function* () {
1172
+ var _b, _c;
1173
+ const defaults = {
1174
+ method: "GET",
1175
+ credentials: "same-origin",
1176
+ headers: {}
1177
+ };
1178
+ const _a = __spreadValues$3(__spreadValues$3({}, defaults), options), {
1179
+ withCredentials,
1180
+ responseType,
1181
+ cacheProps,
1182
+ cacheName,
1183
+ lunkwill,
1184
+ cache,
1185
+ query,
1186
+ json
1187
+ } = _a, opt = __objRest$2(_a, [
1188
+ "withCredentials",
1189
+ "responseType",
1190
+ "cacheProps",
1191
+ "cacheName",
1192
+ "lunkwill",
1193
+ "cache",
1194
+ "query",
1195
+ "json"
1196
+ ]);
1197
+ opt.method = (_b = opt.method) == null ? void 0 : _b.toUpperCase();
1198
+ if (withCredentials) {
1199
+ opt.credentials = "include";
1200
+ }
1201
+ let useLunkwill = false;
1202
+ if (lunkwill !== void 0) {
1203
+ lunkwill.toHeaders(opt.headers || {});
1204
+ useLunkwill = true;
1205
+ }
1206
+ const lunkwillReturnUrl = !!opt.lunkwillReturnUrl;
1207
+ delete opt.lunkwillReturnUrl;
1208
+ if (json !== void 0) {
1209
+ opt.body = JSON.stringify(json);
1210
+ const headers = opt.headers || {};
1211
+ headers["Content-Type"] = "application/json";
1212
+ opt.headers = headers;
1213
+ }
1214
+ const url = generateUrl(path, query);
1215
+ const makeRequest = () => __async$3(this, null, function* () {
1216
+ let response;
1217
+ try {
1218
+ response = yield fetch(url, opt);
1219
+ } catch (e) {
1220
+ if (opt.signal && opt.signal.aborted) {
1221
+ throw e;
895
1222
  }
896
- return this.connector.get("resource.search", requestOptions, __spreadValues$2({
897
- serialization: "full"
898
- }, query)).then((resources) => {
899
- if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
900
- for (const x of resources) {
901
- this.cache.add("resource.item", Promise.resolve(x), {
902
- id: x.resource.id
903
- });
904
- }
905
- }
906
- return resources;
907
- });
908
- }
909
- return items;
910
- });
911
- }
912
- getParent(resource, requestOptions) {
913
- return this.getOne(resource, requestOptions).then((child) => {
914
- if (child) {
915
- return this.getOne(child.resource.parent.id, requestOptions);
916
- }
917
- return Promise.resolve(void 0);
918
- });
919
- }
920
- getChildrenOf(resource, requestOptions) {
921
- return this.getIdOrFail(resource).then(
922
- (parent) => this._getChildrenOf(parent, requestOptions)
923
- );
924
- }
925
- update(resource, data) {
926
- return this.getId(resource).then((id) => {
927
- if (id !== void 0) {
928
- return this.connector.put("resource.item", { data }, { id });
929
- }
930
- });
931
- }
932
- /**
933
- * Fast way to delete resource from NGW and clean cache.
934
- * @param resource - Resource definition
935
- */
936
- delete(resource) {
937
- return this.getId(resource).then((id) => {
938
- if (id !== void 0) {
939
- return this.connector.delete("resource.item", null, { id }).then(() => {
940
- this._cleanResourceItemCache(id);
941
- return void 0;
942
- });
1223
+ throw new NetworksResponseError();
943
1224
  }
944
- });
945
- }
946
- _getChildrenOf(parent, requestOptions, _items = []) {
947
- return this.connector.get("resource.collection", requestOptions, {
948
- parent
949
- }).then((items) => {
950
- const recursivePromises = [];
951
- for (const item of items) {
952
- if (requestOptions == null ? void 0 : requestOptions.cache) {
953
- this.cache.add("resource.item", Promise.resolve(item), {
954
- id: item.resource.id
955
- });
1225
+ if (useLunkwill && lunkwillCheckResponse(response)) {
1226
+ const lwRespUrl = yield lunkwillResponseUrl(response);
1227
+ if (lunkwillReturnUrl) {
1228
+ return lwRespUrl;
956
1229
  }
957
- _items.push(item);
958
- if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
959
- recursivePromises.push(
960
- this._getChildrenOf(item.resource.id, requestOptions, _items)
961
- );
962
- }
963
- }
964
- if (recursivePromises.length) {
965
- return Promise.all(recursivePromises).then(() => {
966
- return _items;
967
- });
1230
+ response = yield lunkwillFetch(lwRespUrl);
968
1231
  }
969
- return _items;
970
- });
971
- }
972
- _cleanResourceItemCache(id) {
973
- return __async$2(this, null, function* () {
974
- var _a;
975
- const all = this.cache.all();
976
- const toDelete = [];
977
- for (const c of all) {
978
- const cid = (_a = c.props) == null ? void 0 : _a.id;
979
- if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
980
- if (typeof cid === "number") {
981
- if (cid === id) {
982
- toDelete.push(c);
983
- }
984
- } else {
985
- const rid = yield this.getId(cid);
986
- if (rid === id) {
987
- toDelete.push(c);
988
- }
989
- }
1232
+ const respCType = response.headers.get("content-type");
1233
+ const respJSON = respCType && (respCType.includes("application/json") || respCType.includes("application/vnd.lunkwill.request-summary+json"));
1234
+ let body;
1235
+ try {
1236
+ const respMedia = respCType && isMediaContentType(respCType);
1237
+ if (responseType === "blob" || respMedia) {
1238
+ body = yield response.blob();
1239
+ } else if (respJSON) {
1240
+ body = yield response.json();
1241
+ } else {
1242
+ throw new InvalidResponseError();
1243
+ }
1244
+ } catch (e) {
1245
+ if (e.name === "AbortError" || e instanceof InvalidResponseError) {
1246
+ throw e;
990
1247
  }
1248
+ throw new InvalidResponseError();
991
1249
  }
992
- for (const d of toDelete) {
993
- this.cache.delete(d);
1250
+ if (400 <= response.status && response.status <= 599) {
1251
+ throw new ServerResponseError(body);
994
1252
  }
1253
+ return body;
995
1254
  });
996
- }
997
- _fetchResourceById(id, requestOptions) {
998
- return this.connector.get("resource.item", requestOptions, { id });
999
- }
1000
- _fetchResourceBy(resource, requestOptions) {
1001
- return this.getMany(resource, requestOptions).then((resources) => {
1002
- return resources[0];
1003
- });
1004
- }
1005
- _resourceCacheFilter(resource) {
1006
- return Promise.all(this.cache.matchAll("resource.item")).then(
1007
- (resources) => {
1008
- const items = [];
1009
- resources.filter((x) => {
1010
- if (x) {
1011
- if (resource.keyname && x.resource.keyname) {
1012
- return resource.keyname === x.resource.keyname;
1013
- }
1014
- if (defined(resource.id) && defined(x.resource.id)) {
1015
- return resource.id === x.resource.id;
1016
- }
1017
- return resourceCompare(resource, x.resource);
1018
- }
1019
- });
1020
- return items;
1021
- }
1022
- );
1023
- }
1024
- }
1025
-
1026
- const CONNECTORS = [];
1027
- function addConnector(connector) {
1028
- CONNECTORS.push(connector);
1029
- }
1030
- function findConnector(options) {
1031
- return CONNECTORS.find((x) => {
1032
- if (x.options.baseUrl === options.baseUrl) {
1033
- if (options.auth) {
1034
- if (x.options.auth) {
1035
- return objectDeepEqual(x.options.auth, options.auth);
1255
+ if (cacheEngine) {
1256
+ if (((_c = opt.method) == null ? void 0 : _c.toUpperCase()) === "GET") {
1257
+ if (cache !== false) {
1258
+ const props = cacheProps ? cacheProps : __spreadValues$3({}, objectRemoveEmpty({
1259
+ withCredentials,
1260
+ responseType
1261
+ }));
1262
+ return cacheEngine.add(cacheName || url, makeRequest, {
1263
+ props,
1264
+ expirationTime: cache ? void 0 : 500
1265
+ });
1036
1266
  }
1037
1267
  } else {
1038
- return true;
1268
+ const ignoredForClean = ["api/feature_layer/identify"];
1269
+ if (ignoredForClean.every((part) => !path.includes(part))) {
1270
+ cacheEngine.clean();
1271
+ }
1039
1272
  }
1040
1273
  }
1274
+ return makeRequest();
1041
1275
  });
1042
1276
  }
1043
- function removeConnector(connector) {
1044
- const index = CONNECTORS.indexOf(connector);
1045
- if (index !== -1) {
1046
- CONNECTORS.splice(index, 1);
1047
- }
1048
- }
1049
-
1050
- class AbortError extends Error {
1051
- constructor(message = "AbortError") {
1052
- super(message);
1053
- this.name = "AbortError";
1054
- }
1055
- }
1056
1277
 
1057
1278
  var __defProp$3 = Object.defineProperty;
1279
+ var __defProps$2 = Object.defineProperties;
1280
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1281
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1282
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1283
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1058
1284
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1059
- var __publicField$2 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
1060
- class InsufficientPermissionsError extends NgwError {
1061
- constructor(obj) {
1062
- super(obj);
1063
- __publicField$2(this, "name", "InsufficientPermissionsError");
1064
- __publicField$2(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
1065
- Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
1066
- }
1067
- }
1068
-
1069
- const templateRe = /\{ *([\w_-]+) *\}/g;
1070
- function template(str, data) {
1071
- return str.replace(templateRe, (s, key) => {
1072
- let value = data[key];
1073
- if (value === void 0) {
1074
- throw new Error("No value provided for letiable " + s);
1075
- } else if (typeof value === "function") {
1076
- value = value(data);
1077
- }
1078
- return value;
1079
- });
1080
- }
1081
-
1082
- var __defProp$2 = Object.defineProperty;
1083
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1084
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1085
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1086
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1087
- var __spreadValues$1 = (a, b) => {
1285
+ var __spreadValues$2 = (a, b) => {
1088
1286
  for (var prop in b || (b = {}))
1089
- if (__hasOwnProp$1.call(b, prop))
1090
- __defNormalProp$2(a, prop, b[prop]);
1091
- if (__getOwnPropSymbols$1)
1092
- for (var prop of __getOwnPropSymbols$1(b)) {
1093
- if (__propIsEnum$1.call(b, prop))
1094
- __defNormalProp$2(a, prop, b[prop]);
1287
+ if (__hasOwnProp$2.call(b, prop))
1288
+ __defNormalProp$3(a, prop, b[prop]);
1289
+ if (__getOwnPropSymbols$2)
1290
+ for (var prop of __getOwnPropSymbols$2(b)) {
1291
+ if (__propIsEnum$2.call(b, prop))
1292
+ __defNormalProp$3(a, prop, b[prop]);
1095
1293
  }
1096
1294
  return a;
1097
1295
  };
1098
- var __async$1 = (__this, __arguments, generator) => {
1296
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1297
+ var __objRest$1 = (source, exclude) => {
1298
+ var target = {};
1299
+ for (var prop in source)
1300
+ if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
1301
+ target[prop] = source[prop];
1302
+ if (source != null && __getOwnPropSymbols$2)
1303
+ for (var prop of __getOwnPropSymbols$2(source)) {
1304
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
1305
+ target[prop] = source[prop];
1306
+ }
1307
+ return target;
1308
+ };
1309
+ var __async$2 = (__this, __arguments, generator) => {
1099
1310
  return new Promise((resolve, reject) => {
1100
1311
  var fulfilled = (value) => {
1101
1312
  try {
@@ -1115,68 +1326,84 @@ var __async$1 = (__this, __arguments, generator) => {
1115
1326
  step((generator = generator.apply(__this, __arguments)).next());
1116
1327
  });
1117
1328
  };
1118
- function apiRequest(opt) {
1119
- return __async$1(this, null, function* () {
1120
- const { params, name, connector, requestOptions } = opt;
1121
- const apiItems = yield connector.connect();
1122
- let apiItem = apiItems && apiItems[name];
1123
- if (apiItem) {
1124
- apiItem = [...apiItem];
1125
- let url = apiItem.shift();
1126
- if (apiItem.length) {
1127
- const replaceParams = {};
1128
- for (let fry = 0; fry < apiItem.length; fry++) {
1129
- const arg = apiItem[fry];
1130
- replaceParams[fry] = `{${arg}}`;
1131
- if (params[arg] === void 0) {
1132
- throw new Error(`\`${arg}\` URL API argument is not specified`);
1133
- }
1134
- }
1135
- if (url) {
1136
- url = template(url, replaceParams);
1137
- }
1138
- }
1139
- if (params) {
1140
- const paramArray = [];
1141
- const paramList = params.paramList;
1142
- if (Array.isArray(paramList)) {
1143
- paramList.forEach(([key, value]) => {
1144
- paramArray.push(`${key}=${value}`);
1145
- });
1146
- }
1147
- for (const p in params) {
1148
- if (apiItem.indexOf(p) === -1) {
1149
- paramArray.push(`${p}=${params[p]}`);
1150
- }
1151
- }
1152
- if (paramArray.length) {
1153
- url = `${url}?${paramArray.join("&")}`;
1154
- }
1329
+ function routeURL(name, baseUrl, routeData, ...rest) {
1330
+ const [template, ...params] = routeData[name];
1331
+ const first = rest[0];
1332
+ let sub;
1333
+ if (first === void 0) {
1334
+ sub = [];
1335
+ } else if (typeof first === "object" && first !== null) {
1336
+ if (rest.length > 1) {
1337
+ throw new Error("Too many arguments for route(name, object)!");
1338
+ }
1339
+ sub = [];
1340
+ for (const [p, v] of Object.entries(first)) {
1341
+ sub[params.indexOf(p)] = String(v);
1342
+ }
1343
+ } else {
1344
+ sub = rest.map((v) => String(v));
1345
+ }
1346
+ return fixUrlStr(
1347
+ baseUrl + template.replace(/\{(\w+)\}/g, function(m, a) {
1348
+ const idx = parseInt(a);
1349
+ const value = sub[idx];
1350
+ if (value === void 0) {
1351
+ const msg = `Undefined parameter ${idx} in "${template}".`;
1352
+ throw new Error(msg);
1155
1353
  }
1156
- if (url) {
1157
- return connector.makeQuery(url, params, __spreadValues$1({
1158
- cacheName: name
1159
- }, requestOptions));
1160
- } else {
1161
- throw new Error("Request URL is not set");
1354
+ return String(value);
1355
+ })
1356
+ );
1357
+ }
1358
+ function route(name, connector, ...rest) {
1359
+ const result = {
1360
+ url: (opt) => __async$2(this, null, function* () {
1361
+ var _a;
1362
+ const routeData = yield connector.connect();
1363
+ const template = routeURL(
1364
+ name,
1365
+ (_a = connector.options.baseUrl) != null ? _a : "",
1366
+ routeData,
1367
+ ...rest
1368
+ );
1369
+ return generateUrl(template, opt == null ? void 0 : opt.query);
1370
+ })
1371
+ };
1372
+ const methods = ["get", "post", "put", "delete", "patch"];
1373
+ for (const method of methods) {
1374
+ const methodResp = (requestOptions) => {
1375
+ var _b;
1376
+ const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
1377
+ if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
1378
+ throw new AbortError();
1162
1379
  }
1163
- } else {
1164
- return void 0;
1165
- }
1166
- });
1380
+ return connector.connect().then((routeData) => {
1381
+ var _a2;
1382
+ const template = routeURL(
1383
+ name,
1384
+ (_a2 = connector.options.baseUrl) != null ? _a2 : "",
1385
+ routeData,
1386
+ ...rest
1387
+ );
1388
+ const headers = objectRemoveEmpty(__spreadValues$2(__spreadValues$2({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
1389
+ return request(
1390
+ template,
1391
+ __spreadProps$2(__spreadValues$2({
1392
+ headers
1393
+ }, restOpt), {
1394
+ method
1395
+ }),
1396
+ connector.cache
1397
+ );
1398
+ });
1399
+ };
1400
+ result[method] = methodResp;
1401
+ }
1402
+ return result;
1167
1403
  }
1168
1404
 
1169
- var __defProp$1 = Object.defineProperty;
1170
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1171
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
1172
- class NetworkError extends Error {
1173
- constructor(url) {
1174
- super();
1175
- __publicField$1(this, "name", "NetworkError");
1176
- Object.setPrototypeOf(this, NetworkError.prototype);
1177
- this.message = `Unable to request ${url}.
1178
- Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
1179
- }
1405
+ function isObject(val) {
1406
+ return Object.prototype.toString.call(val) === "[object Object]";
1180
1407
  }
1181
1408
 
1182
1409
  let loadData;
@@ -1191,7 +1418,7 @@ let loadData;
1191
1418
  const getResponseText = () => {
1192
1419
  try {
1193
1420
  return JSON.parse(xhr.responseText);
1194
- } catch (er) {
1421
+ } catch (e) {
1195
1422
  return xhr.responseText;
1196
1423
  }
1197
1424
  };
@@ -1237,62 +1464,449 @@ let loadData;
1237
1464
  }
1238
1465
  }
1239
1466
  }
1240
- if (options.withCredentials !== void 0) {
1241
- xhr.withCredentials = options.withCredentials;
1242
- }
1243
- let data;
1244
- if (options.file) {
1245
- data = new FormData();
1246
- data.append("file", options.file);
1247
- if (options.data) {
1248
- for (const d in options.data) {
1249
- data.append(d, data[d]);
1467
+ if (options.withCredentials !== void 0) {
1468
+ xhr.withCredentials = options.withCredentials;
1469
+ }
1470
+ let data;
1471
+ if (options.file) {
1472
+ data = new FormData();
1473
+ data.append("file", options.file);
1474
+ if (options.data) {
1475
+ for (const d in options.data) {
1476
+ data.append(d, data[d]);
1477
+ }
1478
+ }
1479
+ } else {
1480
+ data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
1481
+ }
1482
+ if (onCancel) {
1483
+ onCancel(() => {
1484
+ xhr.abort();
1485
+ });
1486
+ }
1487
+ xhr.send(data);
1488
+ };
1489
+ }
1490
+
1491
+ const CONNECTORS = [];
1492
+ function addConnector(connector) {
1493
+ CONNECTORS.push(connector);
1494
+ }
1495
+ function findConnector(options) {
1496
+ return CONNECTORS.find((x) => {
1497
+ if (x.options.baseUrl === options.baseUrl) {
1498
+ if (options.auth) {
1499
+ if (x.options.auth) {
1500
+ return objectDeepEqual(x.options.auth, options.auth);
1501
+ }
1502
+ } else {
1503
+ return true;
1504
+ }
1505
+ }
1506
+ });
1507
+ }
1508
+ function removeConnector(connector) {
1509
+ const index = CONNECTORS.indexOf(connector);
1510
+ if (index !== -1) {
1511
+ CONNECTORS.splice(index, 1);
1512
+ }
1513
+ }
1514
+
1515
+ var __defProp$2 = Object.defineProperty;
1516
+ var __defProps$1 = Object.defineProperties;
1517
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1518
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1519
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1520
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1521
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1522
+ var __spreadValues$1 = (a, b) => {
1523
+ for (var prop in b || (b = {}))
1524
+ if (__hasOwnProp$1.call(b, prop))
1525
+ __defNormalProp$2(a, prop, b[prop]);
1526
+ if (__getOwnPropSymbols$1)
1527
+ for (var prop of __getOwnPropSymbols$1(b)) {
1528
+ if (__propIsEnum$1.call(b, prop))
1529
+ __defNormalProp$2(a, prop, b[prop]);
1530
+ }
1531
+ return a;
1532
+ };
1533
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1534
+ var __objRest = (source, exclude) => {
1535
+ var target = {};
1536
+ for (var prop in source)
1537
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
1538
+ target[prop] = source[prop];
1539
+ if (source != null && __getOwnPropSymbols$1)
1540
+ for (var prop of __getOwnPropSymbols$1(source)) {
1541
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
1542
+ target[prop] = source[prop];
1543
+ }
1544
+ return target;
1545
+ };
1546
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1547
+ var __async$1 = (__this, __arguments, generator) => {
1548
+ return new Promise((resolve, reject) => {
1549
+ var fulfilled = (value) => {
1550
+ try {
1551
+ step(generator.next(value));
1552
+ } catch (e) {
1553
+ reject(e);
1554
+ }
1555
+ };
1556
+ var rejected = (value) => {
1557
+ try {
1558
+ step(generator.throw(value));
1559
+ } catch (e) {
1560
+ reject(e);
1561
+ }
1562
+ };
1563
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1564
+ step((generator = generator.apply(__this, __arguments)).next());
1565
+ });
1566
+ };
1567
+ let ID = 0;
1568
+ let REQUEST_ID = 0;
1569
+ class NgwConnector {
1570
+ constructor(options) {
1571
+ this.options = options;
1572
+ __publicField$2(this, "id", ID++);
1573
+ __publicField$2(this, "emitter", new EventEmitter());
1574
+ __publicField$2(this, "user");
1575
+ __publicField$2(this, "cache");
1576
+ __publicField$2(this, "withCredentials");
1577
+ // Dedicated cache for route requests, as these are executed before any other requests.
1578
+ // This cache does not need to be cleared during the session.
1579
+ __publicField$2(this, "routeCache");
1580
+ __publicField$2(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
1581
+ __publicField$2(this, "routeStr", "/api/component/pyramid/route");
1582
+ __publicField$2(this, "activeRequests", {});
1583
+ __publicField$2(this, "requestTransform");
1584
+ const exist = findConnector(options);
1585
+ this.cache = new Cache({ namespace: options.cacheId });
1586
+ this.routeCache = new Cache({ namespace: "routecache" });
1587
+ if (exist) {
1588
+ return exist;
1589
+ } else {
1590
+ const { route: route2, requestTransform, withCredentials } = this.options;
1591
+ if (route2) {
1592
+ this.routeStr = route2;
1593
+ }
1594
+ if (requestTransform) {
1595
+ this.requestTransform = requestTransform;
1596
+ }
1597
+ if (withCredentials !== void 0) {
1598
+ this.withCredentials = withCredentials;
1599
+ }
1600
+ addConnector(this);
1601
+ }
1602
+ }
1603
+ /**
1604
+ * Clear the cache.
1605
+ */
1606
+ clearCache() {
1607
+ this.cache.clean();
1608
+ }
1609
+ setRequestTransform(requestTransform) {
1610
+ this.requestTransform = requestTransform;
1611
+ }
1612
+ /**
1613
+ * Fast way to specify the connection address to NextGIS Web.
1614
+ * The current connection will be severed.
1615
+ * @param baseUrl - NGW url
1616
+ */
1617
+ setNgw(baseUrl) {
1618
+ this.logout();
1619
+ this.options.baseUrl = baseUrl;
1620
+ addConnector(this);
1621
+ }
1622
+ /**
1623
+ * Establishing a connection with NextGIS Web to fulfill all other requests.
1624
+ * @remarks
1625
+ * This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
1626
+ * Can be used to check connection.
1627
+ * @example
1628
+ * ```javascript
1629
+ * const connector = new NgwConnector({ baseUrl: 'https://demo.nextgis.com' });
1630
+ * connector.connect()
1631
+ * .then(() => console.log('Ok'))
1632
+ * .catch((er) => console.log('Connection problem', er));
1633
+ * ```
1634
+ */
1635
+ connect() {
1636
+ return __async$1(this, arguments, function* ({
1637
+ signal
1638
+ } = {}) {
1639
+ const auth = this.options.auth;
1640
+ if (auth) {
1641
+ const { login, password } = auth;
1642
+ if (login && password) {
1643
+ yield this._login({ login, password });
1644
+ }
1645
+ }
1646
+ const routeUrl = `${this.routeStr}?client=${this.client}`;
1647
+ return this.routeCache.add(
1648
+ this.options.baseUrl || String(this.id),
1649
+ () => this.makeQuery(routeUrl, null, { signal, cache: false })
1650
+ );
1651
+ });
1652
+ }
1653
+ /**
1654
+ * Quick way to change NextGIS Web user.
1655
+ * @param credentials - New user credentials
1656
+ */
1657
+ login(credentials, options) {
1658
+ this.logout();
1659
+ addConnector(this);
1660
+ return this._login(credentials, options);
1661
+ }
1662
+ /**
1663
+ * Disconnecting a user. Aborting all current requests
1664
+ */
1665
+ logout() {
1666
+ this.abort();
1667
+ removeConnector(this);
1668
+ this.options.auth = void 0;
1669
+ this.user = void 0;
1670
+ this.routeCache.clean();
1671
+ this.clearCache();
1672
+ this.emitter.emit("logout");
1673
+ }
1674
+ getUserInfo(credentials, options) {
1675
+ return __async$1(this, null, function* () {
1676
+ if (this.user && this.user.id) {
1677
+ return this.user;
1678
+ }
1679
+ if (credentials) {
1680
+ this.options.auth = credentials;
1681
+ }
1682
+ const options_ = __spreadValues$1({
1683
+ headers: this.getAuthorizationHeaders(credentials),
1684
+ cache: true
1685
+ }, options);
1686
+ return this.makeQuery(
1687
+ "/api/component/auth/current_user",
1688
+ {},
1689
+ options_
1690
+ );
1691
+ });
1692
+ }
1693
+ /**
1694
+ * Obtaining the required Headers for authentication of requests in the NGW.
1695
+ */
1696
+ getAuthorizationHeaders(credentials) {
1697
+ const client = this.makeClientId(credentials);
1698
+ if (client) {
1699
+ return {
1700
+ Authorization: `Basic ${client}`
1701
+ };
1702
+ }
1703
+ return {};
1704
+ }
1705
+ makeClientId(credentials) {
1706
+ credentials = credentials || this.options.auth;
1707
+ if (credentials) {
1708
+ const { login, password } = credentials;
1709
+ const encodedStr = [login, password].map(encodeURIComponent).join(":");
1710
+ {
1711
+ return window.btoa(encodedStr);
1712
+ }
1713
+ }
1714
+ }
1715
+ /** Stop all api requests */
1716
+ abort() {
1717
+ for (const abortController of Object.values(this.activeRequests)) {
1718
+ abortController.abort();
1719
+ }
1720
+ this.activeRequests = {};
1721
+ }
1722
+ getActiveApiRequests() {
1723
+ return __spreadValues$1({}, this.activeRequests);
1724
+ }
1725
+ route(name, ...rest) {
1726
+ return route(name, this, ...rest);
1727
+ }
1728
+ /**
1729
+ * Send request to NGW.
1730
+ * @param url - URL address to NGW
1731
+ * @param params - Query params
1732
+ * @param options - Request options
1733
+ */
1734
+ makeQuery(_0, _1) {
1735
+ return __async$1(this, arguments, function* (url, params, options = {}) {
1736
+ var _b;
1737
+ url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1738
+ if (!url) {
1739
+ throw new Error("Empty `url` not allowed");
1740
+ }
1741
+ if (params) {
1742
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
1743
+ url = template(url, restParams);
1744
+ }
1745
+ url = encodeURI(fixUrlStr(url));
1746
+ options = __spreadValues$1({ withCredentials: this.withCredentials }, options);
1747
+ const {
1748
+ cache,
1749
+ signal: externalSignal,
1750
+ method = "GET",
1751
+ headers,
1752
+ cacheName,
1753
+ cacheProps,
1754
+ responseType,
1755
+ withCredentials
1756
+ } = options;
1757
+ const internalAbortController = new AbortController();
1758
+ const internalSignal = internalAbortController.signal;
1759
+ if (externalSignal) {
1760
+ if (externalSignal.aborted) {
1761
+ throw new AbortError();
1762
+ }
1763
+ externalSignal.addEventListener("abort", () => {
1764
+ internalAbortController.abort();
1765
+ });
1766
+ }
1767
+ options.signal = internalSignal;
1768
+ const createPromise = () => __async$1(this, null, function* () {
1769
+ const id = REQUEST_ID++;
1770
+ this.activeRequests[id] = internalAbortController;
1771
+ try {
1772
+ return this._loadData(url, options);
1773
+ } finally {
1774
+ this._cleanActiveRequest(id);
1775
+ }
1776
+ });
1777
+ if (method === "GET" && cache !== false) {
1778
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$1({}, objectRemoveEmpty({
1779
+ headers,
1780
+ withCredentials,
1781
+ responseType,
1782
+ baseUrl: this.options.baseUrl,
1783
+ userId: (_b = this.user) == null ? void 0 : _b.id
1784
+ })), {
1785
+ params
1786
+ });
1787
+ return this.cache.add(cacheName || url, createPromise, {
1788
+ props: cacheOptions,
1789
+ expirationTime: cache ? void 0 : 500
1790
+ });
1791
+ }
1792
+ return createPromise();
1793
+ });
1794
+ }
1795
+ _loadData(url, options) {
1796
+ options.responseType = options.responseType || "json";
1797
+ return new Promise((resolve, reject) => {
1798
+ var _a;
1799
+ if (this.user) {
1800
+ options = options || {};
1801
+ options.headers = __spreadValues$1(__spreadValues$1({}, this.getAuthorizationHeaders()), options.headers);
1802
+ }
1803
+ if (this.requestTransform) {
1804
+ const [transUrl, transOptions] = this.requestTransform(url, options);
1805
+ url = transUrl;
1806
+ options = transOptions;
1807
+ }
1808
+ let runOnAbort = void 0;
1809
+ loadData(url, resolve, options, reject, (handler) => {
1810
+ runOnAbort = handler;
1811
+ });
1812
+ (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1813
+ if (runOnAbort !== void 0) {
1814
+ runOnAbort();
1815
+ }
1816
+ reject(new AbortError());
1817
+ });
1818
+ }).catch((httpError) => {
1819
+ if (httpError.name !== "AbortError") {
1820
+ {
1821
+ console.warn("DEV WARN", httpError);
1822
+ }
1823
+ const er = this._handleHttpError(httpError);
1824
+ if (er) {
1825
+ throw er;
1826
+ }
1827
+ }
1828
+ throw httpError;
1829
+ });
1830
+ }
1831
+ _login(credentials, options) {
1832
+ return __async$1(this, null, function* () {
1833
+ try {
1834
+ const data = yield this.getUserInfo(credentials, options);
1835
+ this.user = data;
1836
+ this.emitter.emit("login", data);
1837
+ return data;
1838
+ } catch (er) {
1839
+ this.emitter.emit("login:error", er);
1840
+ throw er;
1841
+ }
1842
+ });
1843
+ }
1844
+ _cleanActiveRequest(requestId) {
1845
+ delete this.activeRequests[requestId];
1846
+ }
1847
+ _handleHttpError(er) {
1848
+ if (er) {
1849
+ if (er instanceof NgwError) {
1850
+ if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
1851
+ throw new ResourceNotFoundError(er);
1852
+ } else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
1853
+ throw new InsufficientPermissionsError(er);
1854
+ }
1855
+ }
1856
+ }
1857
+ return er;
1858
+ }
1859
+ }
1860
+ __publicField$2(NgwConnector, "errors", errors);
1861
+
1862
+ function resourceCompare(res1, res2) {
1863
+ return objectDeepEqual(res1, res2);
1864
+ }
1865
+
1866
+ const exclude = ["description"];
1867
+ function resourceToQuery(resource, prefix = "") {
1868
+ prefix = prefix ? prefix + "__" : "";
1869
+ const query = {};
1870
+ for (const [key, value] of Object.entries(resource)) {
1871
+ if (exclude.indexOf(key) === -1) {
1872
+ if (isObject(value)) {
1873
+ if (key === "owner_user") {
1874
+ const children = resourceToQuery(
1875
+ value,
1876
+ key
1877
+ );
1878
+ Object.assign(query, children);
1879
+ } else if (key === "parent" && "id" in value) {
1880
+ query.parent_id = value.id;
1250
1881
  }
1882
+ } else if (defined(value)) {
1883
+ query[prefix + key] = value;
1251
1884
  }
1252
- } else {
1253
- data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
1254
- }
1255
- if (onCancel) {
1256
- onCancel(() => {
1257
- xhr.abort();
1258
- });
1259
1885
  }
1260
- xhr.send(data);
1261
- };
1886
+ }
1887
+ return query;
1262
1888
  }
1263
1889
 
1264
- var __defProp = Object.defineProperty;
1890
+ var __defProp$1 = Object.defineProperty;
1265
1891
  var __defProps = Object.defineProperties;
1266
1892
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1267
1893
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1268
1894
  var __hasOwnProp = Object.prototype.hasOwnProperty;
1269
1895
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
1270
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1896
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1271
1897
  var __spreadValues = (a, b) => {
1272
1898
  for (var prop in b || (b = {}))
1273
1899
  if (__hasOwnProp.call(b, prop))
1274
- __defNormalProp(a, prop, b[prop]);
1900
+ __defNormalProp$1(a, prop, b[prop]);
1275
1901
  if (__getOwnPropSymbols)
1276
1902
  for (var prop of __getOwnPropSymbols(b)) {
1277
1903
  if (__propIsEnum.call(b, prop))
1278
- __defNormalProp(a, prop, b[prop]);
1904
+ __defNormalProp$1(a, prop, b[prop]);
1279
1905
  }
1280
1906
  return a;
1281
1907
  };
1282
1908
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1283
- var __objRest = (source, exclude) => {
1284
- var target = {};
1285
- for (var prop in source)
1286
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
1287
- target[prop] = source[prop];
1288
- if (source != null && __getOwnPropSymbols)
1289
- for (var prop of __getOwnPropSymbols(source)) {
1290
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
1291
- target[prop] = source[prop];
1292
- }
1293
- return target;
1294
- };
1295
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1909
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1296
1910
  var __async = (__this, __arguments, generator) => {
1297
1911
  return new Promise((resolve, reject) => {
1298
1912
  var fulfilled = (value) => {
@@ -1313,173 +1927,269 @@ var __async = (__this, __arguments, generator) => {
1313
1927
  step((generator = generator.apply(__this, __arguments)).next());
1314
1928
  });
1315
1929
  };
1316
- let ID = 0;
1317
- let REQUEST_ID = 0;
1318
- class NgwConnector {
1319
- constructor(options) {
1320
- this.options = options;
1321
- __publicField(this, "id", ID++);
1322
- __publicField(this, "emitter", new EventEmitter());
1323
- __publicField(this, "user");
1324
- __publicField(this, "resources");
1325
- __publicField(this, "cache");
1326
- __publicField(this, "withCredentials");
1327
- __publicField(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
1328
- __publicField(this, "routeStr", "/api/component/pyramid/route");
1329
- __publicField(this, "activeRequests", {});
1330
- __publicField(this, "requestTransform");
1331
- const exist = findConnector(options);
1332
- this.cache = new Cache({ namespace: options.cacheId });
1333
- if (exist) {
1334
- return exist;
1335
- } else {
1336
- const { route, requestTransform, withCredentials } = this.options;
1337
- if (route) {
1338
- this.routeStr = route;
1339
- }
1340
- if (requestTransform) {
1341
- this.requestTransform = requestTransform;
1342
- }
1343
- if (withCredentials !== void 0) {
1344
- this.withCredentials = withCredentials;
1930
+ class ResourcesControl {
1931
+ constructor({
1932
+ connector,
1933
+ cacheId
1934
+ }) {
1935
+ __publicField$1(this, "cache");
1936
+ __publicField$1(this, "connector");
1937
+ this.connector = connector;
1938
+ this.cache = new Cache({ namespace: cacheId });
1939
+ }
1940
+ // -------------------------------------------------------------------------
1941
+ // Resource Methods
1942
+ // -------------------------------------------------------------------------
1943
+ /**
1944
+ * Receive resource from NGW by id, keyname or search-object parameter.
1945
+ * @param resource - Resource id, keyname or search-object
1946
+ *
1947
+ * @remarks
1948
+ * Fetching resource would be cached to speed up next call
1949
+ */
1950
+ getOne(resource, requestOptions) {
1951
+ const opt = __spreadValues({}, requestOptions);
1952
+ if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
1953
+ if (resource.id !== void 0) {
1954
+ resource.id;
1955
+ } else {
1956
+ if (resource.keyname) {
1957
+ resource.keyname;
1958
+ }
1959
+ if (resource.display_name) {
1960
+ resource.display_name;
1961
+ }
1345
1962
  }
1346
- this.resources = new ResourcesControl({
1347
- connector: this,
1348
- cacheId: options.cacheId
1349
- });
1350
- addConnector(this);
1351
1963
  }
1964
+ if (typeof resource === "string") {
1965
+ return this._fetchResourceBy({ keyname: resource }, opt);
1966
+ } else if (typeof resource === "number") {
1967
+ return this._fetchResourceById(resource, opt);
1968
+ } else if (isObject(resource)) {
1969
+ return this._fetchResourceBy(resource, opt);
1970
+ }
1971
+ return Promise.resolve(void 0);
1352
1972
  }
1353
- static create(options) {
1354
- return new this(options);
1973
+ getOneOrFail(resource, requestOptions) {
1974
+ return this.getOne(resource, requestOptions).then((res) => {
1975
+ if (res) {
1976
+ return res;
1977
+ }
1978
+ throw new ResourceNotFoundError();
1979
+ });
1355
1980
  }
1356
1981
  /**
1357
- * Clear the cache.
1982
+ * A fast way to retrieve resource ID for any resource definition.
1983
+ * @param resource - Any available resource definition
1984
+ *
1985
+ * @remarks
1986
+ * There are situations when exactly the resource id is needed
1987
+ * (for example, to compose the correct request to the api)
1988
+ * then this method will come in handy to facilitate the extraction of the identifier
1989
+ * if the resource is specified through a keyname or other parameters.
1358
1990
  */
1359
- clearCache() {
1360
- this.cache.clean();
1361
- this.resources.cache.clean();
1362
- }
1363
- setRequestTransform(requestTransform) {
1364
- this.requestTransform = requestTransform;
1991
+ getId(resource, requestOptions) {
1992
+ if (typeof resource === "number") {
1993
+ return Promise.resolve(resource);
1994
+ } else if (typeof resource === "string" || isObject(resource)) {
1995
+ return this.getOne(resource, requestOptions).then((res) => {
1996
+ if (res) {
1997
+ return res.resource.id;
1998
+ }
1999
+ });
2000
+ }
2001
+ return Promise.resolve(void 0);
1365
2002
  }
1366
2003
  /**
1367
- * Fast way to specify the connection address to NextGIS Web.
1368
- * The current connection will be severed.
1369
- * @param baseUrl - NGW url
2004
+ * A fast way to retrieve resource ID for any resource definition.
2005
+ * @param resource - Any available resource definition
2006
+ *
2007
+ * @remarks
2008
+ * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
2009
+ * To not make one more checks if the resource is definitely exists
1370
2010
  */
1371
- setNgw(baseUrl) {
1372
- this.logout();
1373
- this.options.baseUrl = baseUrl;
1374
- addConnector(this);
2011
+ getIdOrFail(resource, requestOptions) {
2012
+ return this.getId(resource, requestOptions).then((resp) => {
2013
+ if (resp === void 0) {
2014
+ throw new Error();
2015
+ }
2016
+ return resp;
2017
+ });
2018
+ }
2019
+ getMany(resource, requestOptions) {
2020
+ return this._resourceCacheFilter(resource).then((items) => {
2021
+ if (!items.length) {
2022
+ const query = {};
2023
+ if (resource.keyname) {
2024
+ query.keyname = resource.keyname;
2025
+ } else {
2026
+ Object.assign(query, resourceToQuery(resource));
2027
+ }
2028
+ return this.connector.route("resource.search").get(__spreadProps(__spreadValues({}, requestOptions), {
2029
+ query: __spreadValues({
2030
+ serialization: "full"
2031
+ }, query)
2032
+ })).then((resources) => {
2033
+ if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
2034
+ for (const x of resources) {
2035
+ this.cache.add("resource.item", Promise.resolve(x), {
2036
+ id: x.resource.id
2037
+ });
2038
+ }
2039
+ }
2040
+ return resources;
2041
+ });
2042
+ }
2043
+ return items;
2044
+ });
2045
+ }
2046
+ getParent(resource, requestOptions) {
2047
+ return this.getOne(resource, requestOptions).then((child) => {
2048
+ var _a, _b;
2049
+ if ((_b = (_a = child == null ? void 0 : child.resource) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) {
2050
+ return this.getOne(child.resource.parent.id, requestOptions);
2051
+ }
2052
+ return Promise.resolve(void 0);
2053
+ });
2054
+ }
2055
+ getChildrenOf(resource, requestOptions) {
2056
+ return this.getIdOrFail(resource).then(
2057
+ (parent) => this._getChildrenOf(parent, requestOptions)
2058
+ );
2059
+ }
2060
+ update(resource, data) {
2061
+ return this.getId(resource).then((id) => {
2062
+ if (id !== void 0) {
2063
+ return this.connector.put("resource.item", { data }, { id });
2064
+ }
2065
+ });
1375
2066
  }
1376
2067
  /**
1377
- * Establishing a connection with NextGIS Web to fulfill all other requests.
1378
- * @remarks
1379
- * This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
1380
- * Can be used to check connection.
1381
- * @example
1382
- * ```javascript
1383
- * const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
1384
- * connector.connect()
1385
- * .then(() => console.log('Ok'))
1386
- * .catch((er) => console.log('Connection problem', er));
1387
- * ```
2068
+ * Fast way to delete resource from NGW and clean cache.
2069
+ * @param resource - Resource definition
1388
2070
  */
1389
- connect() {
1390
- return __async(this, null, function* () {
1391
- const auth = this.options.auth;
1392
- if (auth) {
1393
- const { login, password } = auth;
1394
- if (login && password) {
1395
- yield this._login({ login, password });
2071
+ delete(resource) {
2072
+ return this.getId(resource).then((id) => {
2073
+ if (id !== void 0) {
2074
+ return this.connector.delete("resource.item", null, { id }).then(() => {
2075
+ this._cleanResourceItemCache(id);
2076
+ return void 0;
2077
+ });
2078
+ }
2079
+ });
2080
+ }
2081
+ _getChildrenOf(_0, _1) {
2082
+ return __async(this, arguments, function* (parentDef, requestOptions, _items = []) {
2083
+ let parent = void 0;
2084
+ if (typeof parentDef === "string") {
2085
+ parent = yield this.getId(parentDef, requestOptions);
2086
+ } else if (typeof parentDef === "object") {
2087
+ parent = parentDef.id;
2088
+ } else {
2089
+ parent = parentDef;
2090
+ }
2091
+ const items = yield this.connector.route("resource.collection").get(__spreadProps(__spreadValues({}, requestOptions), {
2092
+ query: {
2093
+ parent
2094
+ }
2095
+ }));
2096
+ const recursivePromises = [];
2097
+ for (const item of items) {
2098
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
2099
+ this.cache.add("resource.item", Promise.resolve(item), {
2100
+ id: item.resource.id
2101
+ });
2102
+ }
2103
+ _items.push(item);
2104
+ if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
2105
+ recursivePromises.push(
2106
+ this._getChildrenOf(item.resource.id, requestOptions, _items)
2107
+ );
1396
2108
  }
1397
2109
  }
1398
- const routeUrl = `${this.routeStr}?client=${this.client}`;
1399
- return yield this.makeQuery(
1400
- routeUrl,
1401
- {},
1402
- {
1403
- cacheName: "route",
1404
- cache: true,
1405
- cacheProps: {
1406
- id: this.id,
1407
- auth,
1408
- baseUrl: this.options.baseUrl
1409
- }
1410
- }
1411
- );
2110
+ if (recursivePromises.length) {
2111
+ return Promise.all(recursivePromises).then(() => {
2112
+ return _items;
2113
+ });
2114
+ }
2115
+ return _items;
1412
2116
  });
1413
2117
  }
1414
- /**
1415
- * Quick way to change NextGIS Web user.
1416
- * @param credentials - New user credentials
1417
- */
1418
- login(credentials, options) {
1419
- this.logout();
1420
- addConnector(this);
1421
- return this._login(credentials, options);
1422
- }
1423
- /**
1424
- * Disconnecting a user. Aborting all current requests
1425
- */
1426
- logout() {
1427
- this.abort();
1428
- removeConnector(this);
1429
- this.options.auth = void 0;
1430
- this.user = void 0;
1431
- this.clearCache();
1432
- this.emitter.emit("logout");
1433
- }
1434
- getUserInfo(credentials, options) {
2118
+ _cleanResourceItemCache(id) {
1435
2119
  return __async(this, null, function* () {
1436
- if (this.user && this.user.id) {
1437
- return this.user;
2120
+ var _a;
2121
+ const all = this.cache.all();
2122
+ const toDelete = [];
2123
+ for (const c of all) {
2124
+ const cid = (_a = c.props) == null ? void 0 : _a.id;
2125
+ if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
2126
+ if (typeof cid === "number") {
2127
+ if (cid === id) {
2128
+ toDelete.push(c);
2129
+ }
2130
+ } else {
2131
+ const rid = yield this.getId(cid);
2132
+ if (rid === id) {
2133
+ toDelete.push(c);
2134
+ }
2135
+ }
2136
+ }
1438
2137
  }
1439
- if (credentials) {
1440
- this.options.auth = credentials;
2138
+ for (const d of toDelete) {
2139
+ this.cache.delete(d);
1441
2140
  }
1442
- const options_ = __spreadValues({
1443
- headers: this.getAuthorizationHeaders(credentials)
1444
- }, options);
1445
- return this.makeQuery(
1446
- "/api/component/auth/current_user",
1447
- {},
1448
- options_
1449
- );
1450
2141
  });
1451
2142
  }
1452
- /**
1453
- * Obtaining the required Headers for authentication of requests in the NGW.
1454
- */
1455
- getAuthorizationHeaders(credentials) {
1456
- const client = this.makeClientId(credentials);
1457
- if (client) {
1458
- return {
1459
- Authorization: `Basic ${client}`
1460
- };
1461
- }
2143
+ _fetchResourceById(id, requestOptions) {
2144
+ return this.connector.route("resource.item", { id }).get(requestOptions);
1462
2145
  }
1463
- makeClientId(credentials) {
1464
- credentials = credentials || this.options.auth;
1465
- if (credentials) {
1466
- const { login, password } = credentials;
1467
- const str = `${login}:${password}`;
1468
- const encodedStr = encodeURIComponent(str);
1469
- {
1470
- return window.btoa(encodedStr);
2146
+ _fetchResourceBy(resource, requestOptions) {
2147
+ return this.getMany(resource, requestOptions).then((resources) => {
2148
+ return resources[0];
2149
+ });
2150
+ }
2151
+ _resourceCacheFilter(resource) {
2152
+ return Promise.all(this.cache.matchAll("resource.item")).then(
2153
+ (resources) => {
2154
+ const items = [];
2155
+ resources.filter((x) => {
2156
+ if (x) {
2157
+ if (resource.keyname && x.resource.keyname) {
2158
+ return resource.keyname === x.resource.keyname;
2159
+ }
2160
+ if (defined(resource.id) && defined(x.resource.id)) {
2161
+ return resource.id === x.resource.id;
2162
+ }
2163
+ return resourceCompare(resource, x.resource);
2164
+ }
2165
+ });
2166
+ return items;
1471
2167
  }
1472
- }
2168
+ );
1473
2169
  }
1474
- /** Stop all api requests */
1475
- abort() {
1476
- for (const abortController of Object.values(this.activeRequests)) {
1477
- abortController.abort();
1478
- }
1479
- this.activeRequests = {};
2170
+ }
2171
+
2172
+ var __defProp = Object.defineProperty;
2173
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2174
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2175
+ class NgwConnectorExtended extends NgwConnector {
2176
+ constructor(options) {
2177
+ super(options);
2178
+ __publicField(this, "resources");
2179
+ this.resources = new ResourcesControl({
2180
+ connector: this,
2181
+ cacheId: options.cacheId
2182
+ });
1480
2183
  }
1481
- getActiveApiRequests() {
1482
- return __spreadValues({}, this.activeRequests);
2184
+ static create(options) {
2185
+ return new this(options);
2186
+ }
2187
+ /**
2188
+ * Clear the cache.
2189
+ */
2190
+ clearCache() {
2191
+ super.clearCache();
2192
+ this.resources.cache.clean();
1483
2193
  }
1484
2194
  /**
1485
2195
  * Send request to NGW api router.
@@ -1598,75 +2308,6 @@ class NgwConnector {
1598
2308
  options
1599
2309
  );
1600
2310
  }
1601
- /**
1602
- * Send request to NGW.
1603
- * @param url - URL address to NGW
1604
- * @param params - Query params
1605
- * @param options - Request options
1606
- */
1607
- makeQuery(_0, _1) {
1608
- return __async(this, arguments, function* (url, params, options = {}) {
1609
- var _b;
1610
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1611
- if (!url) {
1612
- throw new Error("Empty `url` not allowed");
1613
- }
1614
- if (params) {
1615
- const _a = params, restParams = __objRest(_a, ["paramList"]);
1616
- url = template(url, restParams);
1617
- }
1618
- url = encodeURI(fixUrlStr(url));
1619
- options = __spreadValues({ withCredentials: this.withCredentials }, options);
1620
- const {
1621
- cache,
1622
- signal: externalSignal,
1623
- method = "GET",
1624
- headers,
1625
- cacheName,
1626
- cacheProps,
1627
- responseType,
1628
- withCredentials
1629
- } = options;
1630
- const internalAbortController = new AbortController();
1631
- const internalSignal = internalAbortController.signal;
1632
- if (externalSignal) {
1633
- if (externalSignal.aborted) {
1634
- throw new AbortError();
1635
- }
1636
- externalSignal.addEventListener("abort", () => {
1637
- internalAbortController.abort();
1638
- });
1639
- }
1640
- options.signal = internalSignal;
1641
- const createPromise = () => __async(this, null, function* () {
1642
- const id = REQUEST_ID++;
1643
- this.activeRequests[id] = internalAbortController;
1644
- try {
1645
- return this._loadData(url, options);
1646
- } finally {
1647
- this._cleanActiveRequest(id);
1648
- }
1649
- });
1650
- if (cache && method === "GET") {
1651
- const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues({}, objectRemoveEmpty({
1652
- headers,
1653
- withCredentials,
1654
- responseType,
1655
- baseUrl: this.options.baseUrl,
1656
- userId: (_b = this.user) == null ? void 0 : _b.id
1657
- })), {
1658
- params
1659
- });
1660
- return this.cache.add(
1661
- cacheName || url,
1662
- createPromise,
1663
- cacheOptions,
1664
- false
1665
- );
1666
- }
1667
- return createPromise();
1668
- });
1669
- }
1670
2311
  // -------------------------------------------------------------------------
1671
2312
  // Resource Methods
1672
2313
  // -------------------------------------------------------------------------
@@ -1742,78 +2383,7 @@ class NgwConnector {
1742
2383
  deleteResource(resource) {
1743
2384
  return this.resources.delete(resource);
1744
2385
  }
1745
- /**
1746
- * @internal
1747
- */
1748
- _loadData(url, options) {
1749
- options.responseType = options.responseType || "json";
1750
- return new Promise((resolve, reject) => {
1751
- var _a;
1752
- if (this.user) {
1753
- options = options || {};
1754
- options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
1755
- }
1756
- if (this.requestTransform) {
1757
- const [transUrl, transOptions] = this.requestTransform(url, options);
1758
- url = transUrl;
1759
- options = transOptions;
1760
- }
1761
- let runOnAbort = void 0;
1762
- loadData(url, resolve, options, reject, (handler) => {
1763
- runOnAbort = handler;
1764
- });
1765
- (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1766
- if (runOnAbort !== void 0) {
1767
- runOnAbort();
1768
- }
1769
- reject(new AbortError());
1770
- });
1771
- }).catch((httpError) => {
1772
- if (httpError.name !== "AbortError") {
1773
- {
1774
- console.warn("DEV WARN", httpError);
1775
- }
1776
- const er = this._handleHttpError(httpError);
1777
- if (er) {
1778
- throw er;
1779
- }
1780
- }
1781
- throw httpError;
1782
- });
1783
- }
1784
- _login(credentials, options) {
1785
- return __async(this, null, function* () {
1786
- try {
1787
- const data = yield this.getUserInfo(credentials, options);
1788
- this.user = data;
1789
- this.emitter.emit("login", data);
1790
- return data;
1791
- } catch (er) {
1792
- this.emitter.emit("login:error", er);
1793
- throw er;
1794
- }
1795
- });
1796
- }
1797
- _cleanActiveRequest(requestId) {
1798
- delete this.activeRequests[requestId];
1799
- }
1800
- _handleHttpError(er) {
1801
- if (er) {
1802
- if (er instanceof NgwError) {
1803
- if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
1804
- throw new ResourceNotFoundError(er);
1805
- } else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
1806
- throw new InsufficientPermissionsError(er);
1807
- }
1808
- }
1809
- }
1810
- return er;
1811
- }
1812
2386
  }
1813
- __publicField(NgwConnector, "errors", {
1814
- NgwError,
1815
- ResourceNotFoundError
1816
- });
1817
2387
 
1818
- export { NgwConnector as default };
2388
+ export { NgwConnectorExtended as default };
1819
2389
  //# sourceMappingURL=ngw-connector.esm-browser.js.map