@nextgis/ngw-connector 3.0.0-alpha.1 → 3.0.0-alpha.13

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.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.13; 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
@@ -29,7 +329,7 @@ EventEmitter.init = function() {
29
329
  this.domain = null;
30
330
  if (EventEmitter.usingDomains) {
31
331
  // if there is an active domain, then attach to it.
32
- if (domain.active ) ;
332
+ if (domain.active) ;
33
333
  }
34
334
 
35
335
  if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
@@ -471,199 +771,164 @@ 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
- }
774
+ var pkg = {
775
+ name: "@nextgis/ngw-connector",
776
+ version: "3.0.0-alpha.13",
777
+ _priority: 12,
778
+ description: "A lightweight HTTP client optimized for use with NextGIS Web API",
779
+ main: "index.js",
780
+ module: "lib/ngw-connector.esm-bundler.js",
781
+ unpkg: "lib/ngw-connector.global.prod.js",
782
+ jsdelivr: "lib/ngw-connector.global.prod.js",
783
+ types: "lib/index.d.ts",
784
+ dependencies: {
785
+ "@nextgis/cache": "^3.0.0-alpha.13",
786
+ "@nextgis/cancelable-promise": "^3.0.0-alpha.13",
787
+ "@nextgis/utils": "^3.0.0-alpha.13",
788
+ "@types/events": "^3.0.0",
789
+ events: "*",
790
+ "form-data": "^4.0.0"
791
+ },
792
+ devDependencies: {
793
+ "@nextgis/build-tools": "^3.0.0-alpha.13"
794
+ },
795
+ scripts: {
796
+ clean: "rimraf ./lib",
797
+ dev: "node ../build-tools/lib/build.js",
798
+ prod: "npm run dev -- --release",
799
+ lint: "eslint ./src/**/*.ts --fix --c ../../.eslintrc",
800
+ watch: "npm run dev -- --watch",
801
+ "gen:types": "node ./scripts/generator"
802
+ },
803
+ buildOptions: {
804
+ name: "NgwConnector",
805
+ formats: [
806
+ "esm-bundler",
807
+ "esm-browser",
808
+ "cjs",
809
+ "global"
810
+ ]
811
+ },
812
+ keywords: [
813
+ "NextGIS",
814
+ "MAP"
815
+ ],
816
+ author: "NextGIS",
817
+ files: [
818
+ "index.js",
819
+ "lib"
820
+ ],
821
+ license: "MIT",
822
+ homepage: "https://github.com/nextgis/nextgis_frontend/tree/master/packages/ngw-connector#readme",
823
+ repository: {
824
+ type: "git",
825
+ url: "git://github.com/nextgis/nextgis_frontend.git"
826
+ },
827
+ engines: {
828
+ node: ">=18.20.4"
829
+ },
830
+ gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
831
+ };
480
832
 
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
- }
833
+ class AbortError extends Error {
834
+ constructor(message = "AbortError") {
835
+ super(message);
836
+ this.name = "AbortError";
511
837
  }
512
- return true;
513
838
  }
514
839
 
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;
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);
843
+ class NgwError extends Error {
844
+ constructor(er) {
845
+ super();
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");
854
+ Object.assign(this, er);
855
+ Object.setPrototypeOf(this, NgwError.prototype);
856
+ }
525
857
  }
526
858
 
527
- function fixUrlStr(url) {
528
- return url.replace(/([^:]\/)\/+/g, "$1");
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
+ }
529
869
  }
530
870
 
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);
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);
574
881
  }
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
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
589
892
  };
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);
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
597
899
  });
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
900
  }
630
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
+ };
631
906
  }
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));
907
+ }
908
+
909
+ function isError(error) {
910
+ if (isObject$1(error)) {
911
+ return error.status_code && error.exception && error.title;
640
912
  }
641
- };
642
- __publicField$6(_Cache, "instance", {});
643
- let Cache = _Cache;
913
+ return false;
914
+ }
644
915
 
645
- var __defProp$6 = Object.defineProperty;
646
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
647
- var __publicField$5 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
648
- class NgwError extends Error {
649
- constructor(er) {
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, key + "" , value);
919
+ class NetworkError extends Error {
920
+ constructor(url) {
650
921
  super();
651
- __publicField$5(this, "name", "NgwError");
652
- __publicField$5(this, "title");
653
- __publicField$5(this, "message");
654
- __publicField$5(this, "detail");
655
- __publicField$5(this, "exception");
656
- __publicField$5(this, "status_code");
657
- __publicField$5(this, "data");
658
- __publicField$5(this, "guru_meditation");
659
- Object.assign(this, er);
660
- Object.setPrototypeOf(this, NgwError.prototype);
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}`;
661
926
  }
662
927
  }
663
928
 
664
- var __defProp$5 = Object.defineProperty;
665
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
666
- var __publicField$4 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
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);
667
932
  class ResourceNotFoundError extends NgwError {
668
933
  constructor(obj) {
669
934
  super(obj);
@@ -673,53 +938,111 @@ class ResourceNotFoundError extends NgwError {
673
938
  }
674
939
  }
675
940
 
676
- function isObject(val) {
677
- return Object.prototype.toString.call(val) === "[object Object]";
678
- }
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
+ });
679
952
 
680
- function resourceCompare(res1, res2) {
681
- 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
+ }
682
966
  }
683
-
684
- const exclude = ["description"];
685
- function resourceToQuery(resource, prefix = "") {
686
- prefix = prefix ? prefix + "__" : "";
687
- const query = {};
688
- for (const [key, value] of Object.entries(resource)) {
689
- if (exclude.indexOf(key) === -1) {
690
- if (isObject(value)) {
691
- if (key === "owner_user") {
692
- const children = resourceToQuery(value, key);
693
- Object.assign(query, children);
694
- } else if (key === "parent" && "id" in value) {
695
- query.parent_id = value.id;
696
- }
697
- } else if (defined(value)) {
698
- query[prefix + key] = value;
699
- }
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);
700
1003
  }
701
1004
  }
702
- 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
+ }
703
1015
  }
704
1016
 
705
1017
  var __defProp$4 = Object.defineProperty;
706
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
707
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
708
- 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;
709
1021
  var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
710
- var __spreadValues$2 = (a, b) => {
1022
+ var __spreadValues$3 = (a, b) => {
711
1023
  for (var prop in b || (b = {}))
712
- if (__hasOwnProp$2.call(b, prop))
1024
+ if (__hasOwnProp$3.call(b, prop))
713
1025
  __defNormalProp$4(a, prop, b[prop]);
714
- if (__getOwnPropSymbols$2)
715
- for (var prop of __getOwnPropSymbols$2(b)) {
716
- 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))
717
1029
  __defNormalProp$4(a, prop, b[prop]);
718
1030
  }
719
1031
  return a;
720
1032
  };
721
- var __publicField$3 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
722
- 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) => {
723
1046
  return new Promise((resolve, reject) => {
724
1047
  var fulfilled = (value) => {
725
1048
  try {
@@ -739,307 +1062,241 @@ var __async$2 = (__this, __arguments, generator) => {
739
1062
  step((generator = generator.apply(__this, __arguments)).next());
740
1063
  });
741
1064
  };
742
- class ResourcesControl {
743
- constructor({
744
- connector,
745
- cacheId
746
- }) {
747
- __publicField$3(this, "cache");
748
- __publicField$3(this, "connector");
749
- this.connector = connector;
750
- this.cache = new Cache({ namespace: cacheId });
751
- }
752
- // -------------------------------------------------------------------------
753
- // Resource Methods
754
- // -------------------------------------------------------------------------
755
- /**
756
- * Receive resource from NGW by id, keyname or search-object parameter.
757
- * @param resource - Resource id, keyname or search-object
758
- *
759
- * @remarks
760
- * Fetching resource would be cached to speed up next call
761
- */
762
- getOne(resource, requestOptions) {
763
- const opt = __spreadValues$2({}, requestOptions);
764
- if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
765
- if (resource.id !== void 0) {
766
- resource.id;
767
- } else {
768
- if (resource.keyname) {
769
- resource.keyname;
770
- }
771
- if (resource.display_name) {
772
- resource.display_name;
773
- }
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);
774
1117
  }
775
1118
  }
776
- if (typeof resource === "string") {
777
- return this._fetchResourceBy({ keyname: resource }, opt);
778
- } else if (typeof resource === "number") {
779
- return this._fetchResourceById(resource, opt);
780
- } else if (isObject(resource)) {
781
- 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();
782
1128
  }
783
- return Promise.resolve(void 0);
784
- }
785
- getOneOrFail(resource, requestOptions) {
786
- return this.getOne(resource, requestOptions).then((res) => {
787
- if (res) {
788
- return res;
789
- }
790
- throw new ResourceNotFoundError();
791
- });
792
- }
793
- /**
794
- * A fast way to retrieve resource ID for any resource definition.
795
- * @param resource - Any available resource definition
796
- *
797
- * @remarks
798
- * There are situations when exactly the resource id is needed
799
- * (for example, to compose the correct request to the api)
800
- * then this method will come in handy to facilitate the extraction of the identifier
801
- * if the resource is specified through a keyname or other parameters.
802
- */
803
- getId(resource, requestOptions) {
804
- if (typeof resource === "number") {
805
- return Promise.resolve(resource);
806
- } else if (typeof resource === "string" || isObject(resource)) {
807
- return this.getOne(resource, requestOptions).then((res) => {
808
- if (res) {
809
- 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(",")}`);
810
1157
  }
811
- });
1158
+ }
812
1159
  }
813
- return Promise.resolve(void 0);
814
1160
  }
815
- /**
816
- * A fast way to retrieve resource ID for any resource definition.
817
- * @param resource - Any available resource definition
818
- *
819
- * @remarks
820
- * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
821
- * To not make one more checks if the resource is definitely exists
822
- */
823
- getIdOrFail(resource, requestOptions) {
824
- return this.getId(resource, requestOptions).then((resp) => {
825
- if (resp === void 0) {
826
- throw new Error();
827
- }
828
- return resp;
829
- });
1161
+ return result.join("&");
1162
+ }
1163
+ function generateUrl(path, query) {
1164
+ let urlParams = "";
1165
+ if (query !== void 0) {
1166
+ urlParams = "?" + encodeQueryParams(query);
830
1167
  }
831
- getMany(resource, requestOptions) {
832
- return this._resourceCacheFilter(resource).then((items) => {
833
- if (!items.length) {
834
- const query = {};
835
- if (resource.keyname) {
836
- query.keyname = resource.keyname;
837
- } else {
838
- 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;
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
+ if (withCredentials) {
1198
+ opt.credentials = "include";
1199
+ }
1200
+ let useLunkwill = false;
1201
+ if (lunkwill !== void 0) {
1202
+ lunkwill.toHeaders(opt.headers || {});
1203
+ useLunkwill = true;
1204
+ }
1205
+ const lunkwillReturnUrl = !!opt.lunkwillReturnUrl;
1206
+ delete opt.lunkwillReturnUrl;
1207
+ if (json !== void 0) {
1208
+ opt.body = JSON.stringify(json);
1209
+ const headers = opt.headers || {};
1210
+ headers["Content-Type"] = "application/json";
1211
+ opt.headers = headers;
1212
+ }
1213
+ const url = generateUrl(path, query);
1214
+ const makeRequest = () => __async$3(this, null, function* () {
1215
+ let response;
1216
+ try {
1217
+ response = yield fetch(url, opt);
1218
+ } catch (e) {
1219
+ if (opt.signal && opt.signal.aborted) {
1220
+ throw e;
839
1221
  }
840
- return this.connector.get("resource.search", requestOptions, __spreadValues$2({
841
- serialization: "full"
842
- }, query)).then((resources) => {
843
- if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
844
- for (const x of resources) {
845
- this.cache.add("resource.item", Promise.resolve(x), {
846
- id: x.resource.id
847
- });
848
- }
849
- }
850
- return resources;
851
- });
852
- }
853
- return items;
854
- });
855
- }
856
- getParent(resource, requestOptions) {
857
- return this.getOne(resource, requestOptions).then((child) => {
858
- if (child) {
859
- return this.getOne(child.resource.parent.id, requestOptions);
860
- }
861
- return Promise.resolve(void 0);
862
- });
863
- }
864
- getChildrenOf(resource, requestOptions) {
865
- return this.getIdOrFail(resource).then(
866
- (parent) => this._getChildrenOf(parent, requestOptions)
867
- );
868
- }
869
- update(resource, data) {
870
- return this.getId(resource).then((id) => {
871
- if (id !== void 0) {
872
- return this.connector.put("resource.item", { data }, { id });
873
- }
874
- });
875
- }
876
- /**
877
- * Fast way to delete resource from NGW and clean cache.
878
- * @param resource - Resource definition
879
- */
880
- delete(resource) {
881
- return this.getId(resource).then((id) => {
882
- if (id !== void 0) {
883
- return this.connector.delete("resource.item", null, { id }).then(() => {
884
- this._cleanResourceItemCache(id);
885
- return void 0;
886
- });
1222
+ throw new NetworksResponseError();
887
1223
  }
888
- });
889
- }
890
- _getChildrenOf(parent, requestOptions, _items = []) {
891
- return this.connector.get("resource.collection", requestOptions, {
892
- parent
893
- }).then((items) => {
894
- const recursivePromises = [];
895
- for (const item of items) {
896
- if (requestOptions == null ? void 0 : requestOptions.cache) {
897
- this.cache.add("resource.item", Promise.resolve(item), {
898
- id: item.resource.id
899
- });
900
- }
901
- _items.push(item);
902
- if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
903
- recursivePromises.push(
904
- this._getChildrenOf(item.resource.id, requestOptions, _items)
905
- );
1224
+ if (useLunkwill && lunkwillCheckResponse(response)) {
1225
+ const lwRespUrl = yield lunkwillResponseUrl(response);
1226
+ if (lunkwillReturnUrl) {
1227
+ return lwRespUrl;
906
1228
  }
1229
+ response = yield lunkwillFetch(lwRespUrl);
907
1230
  }
908
- if (recursivePromises.length) {
909
- return Promise.all(recursivePromises).then(() => {
910
- return _items;
911
- });
912
- }
913
- return _items;
914
- });
915
- }
916
- _cleanResourceItemCache(id) {
917
- return __async$2(this, null, function* () {
918
- var _a;
919
- const all = this.cache.all();
920
- const toDelete = [];
921
- for (const c of all) {
922
- const cid = (_a = c.props) == null ? void 0 : _a.id;
923
- if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
924
- if (typeof cid === "number") {
925
- if (cid === id) {
926
- toDelete.push(c);
927
- }
928
- } else {
929
- const rid = yield this.getId(cid);
930
- if (rid === id) {
931
- toDelete.push(c);
932
- }
933
- }
1231
+ const respCType = response.headers.get("content-type");
1232
+ const respJSON = respCType && (respCType.includes("application/json") || respCType.includes("application/vnd.lunkwill.request-summary+json"));
1233
+ let body;
1234
+ try {
1235
+ const respMedia = respCType && isMediaContentType(respCType);
1236
+ if (responseType === "blob" || respMedia) {
1237
+ body = yield response.blob();
1238
+ } else if (respJSON) {
1239
+ body = yield response.json();
1240
+ } else {
1241
+ throw new InvalidResponseError();
1242
+ }
1243
+ } catch (e) {
1244
+ if (e.name === "AbortError" || e instanceof InvalidResponseError) {
1245
+ throw e;
934
1246
  }
1247
+ throw new InvalidResponseError();
935
1248
  }
936
- for (const d of toDelete) {
937
- this.cache.delete(d);
1249
+ if (400 <= response.status && response.status <= 599) {
1250
+ throw new ServerResponseError(body);
938
1251
  }
1252
+ return body;
939
1253
  });
940
- }
941
- _fetchResourceById(id, requestOptions) {
942
- return this.connector.get("resource.item", requestOptions, { id });
943
- }
944
- _fetchResourceBy(resource, requestOptions) {
945
- return this.getMany(resource, requestOptions).then((resources) => {
946
- return resources[0];
947
- });
948
- }
949
- _resourceCacheFilter(resource) {
950
- return Promise.all(this.cache.matchAll("resource.item")).then(
951
- (resources) => {
952
- const items = [];
953
- resources.filter((x) => {
954
- if (x) {
955
- if (resource.keyname && x.resource.keyname) {
956
- return resource.keyname === x.resource.keyname;
957
- }
958
- if (defined(resource.id) && defined(x.resource.id)) {
959
- return resource.id === x.resource.id;
960
- }
961
- return resourceCompare(resource, x.resource);
962
- }
963
- });
964
- return items;
965
- }
966
- );
967
- }
968
- }
969
-
970
- const CONNECTORS = [];
971
- function addConnector(connector) {
972
- CONNECTORS.push(connector);
973
- }
974
- function findConnector(options) {
975
- return CONNECTORS.find((x) => {
976
- if (x.options.baseUrl === options.baseUrl) {
977
- if (options.auth) {
978
- if (x.options.auth) {
979
- return objectDeepEqual(x.options.auth, options.auth);
980
- }
981
- } else {
982
- return true;
983
- }
1254
+ if (cacheEngine && cache !== false && ((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
1255
+ const props = cacheProps ? cacheProps : __spreadValues$3({}, objectRemoveEmpty({
1256
+ withCredentials,
1257
+ responseType
1258
+ }));
1259
+ return cacheEngine.add(cacheName || url, makeRequest, {
1260
+ props,
1261
+ expirationTime: cache ? void 0 : 500
1262
+ });
984
1263
  }
1264
+ return makeRequest();
985
1265
  });
986
1266
  }
987
- function removeConnector(connector) {
988
- const index = CONNECTORS.indexOf(connector);
989
- if (index !== -1) {
990
- CONNECTORS.splice(index, 1);
991
- }
992
- }
993
-
994
- class AbortError extends Error {
995
- constructor(message = "AbortError") {
996
- super(message);
997
- this.name = "AbortError";
998
- }
999
- }
1000
1267
 
1001
1268
  var __defProp$3 = Object.defineProperty;
1269
+ var __defProps$2 = Object.defineProperties;
1270
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1271
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1272
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1273
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1002
1274
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1003
- var __publicField$2 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
1004
- class InsufficientPermissionsError extends NgwError {
1005
- constructor(obj) {
1006
- super(obj);
1007
- __publicField$2(this, "name", "InsufficientPermissionsError");
1008
- __publicField$2(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
1009
- Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
1010
- }
1011
- }
1012
-
1013
- const templateRe = /\{ *([\w_-]+) *\}/g;
1014
- function template(str, data) {
1015
- return str.replace(templateRe, (s, key) => {
1016
- let value = data[key];
1017
- if (value === void 0) {
1018
- throw new Error("No value provided for letiable " + s);
1019
- } else if (typeof value === "function") {
1020
- value = value(data);
1021
- }
1022
- return value;
1023
- });
1024
- }
1025
-
1026
- var __defProp$2 = Object.defineProperty;
1027
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1028
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1029
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1030
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1031
- var __spreadValues$1 = (a, b) => {
1275
+ var __spreadValues$2 = (a, b) => {
1032
1276
  for (var prop in b || (b = {}))
1033
- if (__hasOwnProp$1.call(b, prop))
1034
- __defNormalProp$2(a, prop, b[prop]);
1035
- if (__getOwnPropSymbols$1)
1036
- for (var prop of __getOwnPropSymbols$1(b)) {
1037
- if (__propIsEnum$1.call(b, prop))
1038
- __defNormalProp$2(a, prop, b[prop]);
1277
+ if (__hasOwnProp$2.call(b, prop))
1278
+ __defNormalProp$3(a, prop, b[prop]);
1279
+ if (__getOwnPropSymbols$2)
1280
+ for (var prop of __getOwnPropSymbols$2(b)) {
1281
+ if (__propIsEnum$2.call(b, prop))
1282
+ __defNormalProp$3(a, prop, b[prop]);
1039
1283
  }
1040
1284
  return a;
1041
1285
  };
1042
- var __async$1 = (__this, __arguments, generator) => {
1286
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1287
+ var __objRest$1 = (source, exclude) => {
1288
+ var target = {};
1289
+ for (var prop in source)
1290
+ if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
1291
+ target[prop] = source[prop];
1292
+ if (source != null && __getOwnPropSymbols$2)
1293
+ for (var prop of __getOwnPropSymbols$2(source)) {
1294
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
1295
+ target[prop] = source[prop];
1296
+ }
1297
+ return target;
1298
+ };
1299
+ var __async$2 = (__this, __arguments, generator) => {
1043
1300
  return new Promise((resolve, reject) => {
1044
1301
  var fulfilled = (value) => {
1045
1302
  try {
@@ -1059,68 +1316,84 @@ var __async$1 = (__this, __arguments, generator) => {
1059
1316
  step((generator = generator.apply(__this, __arguments)).next());
1060
1317
  });
1061
1318
  };
1062
- function apiRequest(opt) {
1063
- return __async$1(this, null, function* () {
1064
- const { params, name, connector, requestOptions } = opt;
1065
- const apiItems = yield connector.connect();
1066
- let apiItem = apiItems && apiItems[name];
1067
- if (apiItem) {
1068
- apiItem = [...apiItem];
1069
- let url = apiItem.shift();
1070
- if (apiItem.length) {
1071
- const replaceParams = {};
1072
- for (let fry = 0; fry < apiItem.length; fry++) {
1073
- const arg = apiItem[fry];
1074
- replaceParams[fry] = `{${arg}}`;
1075
- if (params[arg] === void 0) {
1076
- throw new Error(`\`${arg}\` URL API argument is not specified`);
1077
- }
1078
- }
1079
- if (url) {
1080
- url = template(url, replaceParams);
1081
- }
1082
- }
1083
- if (params) {
1084
- const paramArray = [];
1085
- const paramList = params.paramList;
1086
- if (Array.isArray(paramList)) {
1087
- paramList.forEach(([key, value]) => {
1088
- paramArray.push(`${key}=${value}`);
1089
- });
1090
- }
1091
- for (const p in params) {
1092
- if (apiItem.indexOf(p) === -1) {
1093
- paramArray.push(`${p}=${params[p]}`);
1094
- }
1095
- }
1096
- if (paramArray.length) {
1097
- url = `${url}?${paramArray.join("&")}`;
1098
- }
1319
+ function routeURL(name, baseUrl, routeData, ...rest) {
1320
+ const [template, ...params] = routeData[name];
1321
+ const first = rest[0];
1322
+ let sub;
1323
+ if (first === void 0) {
1324
+ sub = [];
1325
+ } else if (typeof first === "object" && first !== null) {
1326
+ if (rest.length > 1) {
1327
+ throw new Error("Too many arguments for route(name, object)!");
1328
+ }
1329
+ sub = [];
1330
+ for (const [p, v] of Object.entries(first)) {
1331
+ sub[params.indexOf(p)] = String(v);
1332
+ }
1333
+ } else {
1334
+ sub = rest.map((v) => String(v));
1335
+ }
1336
+ return fixUrlStr(
1337
+ baseUrl + template.replace(/\{(\w+)\}/g, function(m, a) {
1338
+ const idx = parseInt(a);
1339
+ const value = sub[idx];
1340
+ if (value === void 0) {
1341
+ const msg = `Undefined parameter ${idx} in "${template}".`;
1342
+ throw new Error(msg);
1099
1343
  }
1100
- if (url) {
1101
- return connector.makeQuery(url, params, __spreadValues$1({
1102
- cacheName: name
1103
- }, requestOptions));
1104
- } else {
1105
- throw new Error("Request URL is not set");
1344
+ return String(value);
1345
+ })
1346
+ );
1347
+ }
1348
+ function route(name, connector, ...rest) {
1349
+ const result = {
1350
+ url: (opt) => __async$2(this, null, function* () {
1351
+ var _a;
1352
+ const routeData = yield connector.connect();
1353
+ const template = routeURL(
1354
+ name,
1355
+ (_a = connector.options.baseUrl) != null ? _a : "",
1356
+ routeData,
1357
+ ...rest
1358
+ );
1359
+ return generateUrl(template, opt == null ? void 0 : opt.query);
1360
+ })
1361
+ };
1362
+ const methods = ["get", "post", "put", "delete", "patch"];
1363
+ for (const method of methods) {
1364
+ const methodResp = (requestOptions) => {
1365
+ var _b;
1366
+ const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
1367
+ if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
1368
+ throw new AbortError();
1106
1369
  }
1107
- } else {
1108
- return void 0;
1109
- }
1110
- });
1370
+ return connector.connect().then((routeData) => {
1371
+ var _a2;
1372
+ const template = routeURL(
1373
+ name,
1374
+ (_a2 = connector.options.baseUrl) != null ? _a2 : "",
1375
+ routeData,
1376
+ ...rest
1377
+ );
1378
+ const headers = objectRemoveEmpty(__spreadValues$2(__spreadValues$2({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
1379
+ return request(
1380
+ template,
1381
+ __spreadProps$2(__spreadValues$2({
1382
+ headers
1383
+ }, restOpt), {
1384
+ method
1385
+ }),
1386
+ connector.cache
1387
+ );
1388
+ });
1389
+ };
1390
+ result[method] = methodResp;
1391
+ }
1392
+ return result;
1111
1393
  }
1112
1394
 
1113
- var __defProp$1 = Object.defineProperty;
1114
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1115
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
1116
- class NetworkError extends Error {
1117
- constructor(url) {
1118
- super();
1119
- __publicField$1(this, "name", "NetworkError");
1120
- Object.setPrototypeOf(this, NetworkError.prototype);
1121
- this.message = `Unable to request ${url}.
1122
- Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
1123
- }
1395
+ function isObject(val) {
1396
+ return Object.prototype.toString.call(val) === "[object Object]";
1124
1397
  }
1125
1398
 
1126
1399
  let loadData;
@@ -1135,7 +1408,7 @@ let loadData;
1135
1408
  const getResponseText = () => {
1136
1409
  try {
1137
1410
  return JSON.parse(xhr.responseText);
1138
- } catch (er) {
1411
+ } catch (e) {
1139
1412
  return xhr.responseText;
1140
1413
  }
1141
1414
  };
@@ -1181,62 +1454,454 @@ let loadData;
1181
1454
  }
1182
1455
  }
1183
1456
  }
1184
- if (options.withCredentials !== void 0) {
1185
- xhr.withCredentials = options.withCredentials;
1186
- }
1187
- let data;
1188
- if (options.file) {
1189
- data = new FormData();
1190
- data.append("file", options.file);
1191
- if (options.data) {
1192
- for (const d in options.data) {
1193
- data.append(d, data[d]);
1457
+ if (options.withCredentials !== void 0) {
1458
+ xhr.withCredentials = options.withCredentials;
1459
+ }
1460
+ let data;
1461
+ if (options.file) {
1462
+ data = new FormData();
1463
+ data.append("file", options.file);
1464
+ if (options.data) {
1465
+ for (const d in options.data) {
1466
+ data.append(d, data[d]);
1467
+ }
1468
+ }
1469
+ } else {
1470
+ data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
1471
+ }
1472
+ if (onCancel) {
1473
+ onCancel(() => {
1474
+ xhr.abort();
1475
+ });
1476
+ }
1477
+ xhr.send(data);
1478
+ };
1479
+ }
1480
+
1481
+ const CONNECTORS = [];
1482
+ function addConnector(connector) {
1483
+ CONNECTORS.push(connector);
1484
+ }
1485
+ function findConnector(options) {
1486
+ return CONNECTORS.find((x) => {
1487
+ if (x.options.baseUrl === options.baseUrl) {
1488
+ if (options.auth) {
1489
+ if (x.options.auth) {
1490
+ return objectDeepEqual(x.options.auth, options.auth);
1491
+ }
1492
+ } else {
1493
+ return true;
1494
+ }
1495
+ }
1496
+ });
1497
+ }
1498
+ function removeConnector(connector) {
1499
+ const index = CONNECTORS.indexOf(connector);
1500
+ if (index !== -1) {
1501
+ CONNECTORS.splice(index, 1);
1502
+ }
1503
+ }
1504
+
1505
+ var __defProp$2 = Object.defineProperty;
1506
+ var __defProps$1 = Object.defineProperties;
1507
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1508
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1509
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1510
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1511
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1512
+ var __spreadValues$1 = (a, b) => {
1513
+ for (var prop in b || (b = {}))
1514
+ if (__hasOwnProp$1.call(b, prop))
1515
+ __defNormalProp$2(a, prop, b[prop]);
1516
+ if (__getOwnPropSymbols$1)
1517
+ for (var prop of __getOwnPropSymbols$1(b)) {
1518
+ if (__propIsEnum$1.call(b, prop))
1519
+ __defNormalProp$2(a, prop, b[prop]);
1520
+ }
1521
+ return a;
1522
+ };
1523
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1524
+ var __objRest = (source, exclude) => {
1525
+ var target = {};
1526
+ for (var prop in source)
1527
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
1528
+ target[prop] = source[prop];
1529
+ if (source != null && __getOwnPropSymbols$1)
1530
+ for (var prop of __getOwnPropSymbols$1(source)) {
1531
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
1532
+ target[prop] = source[prop];
1533
+ }
1534
+ return target;
1535
+ };
1536
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1537
+ var __async$1 = (__this, __arguments, generator) => {
1538
+ return new Promise((resolve, reject) => {
1539
+ var fulfilled = (value) => {
1540
+ try {
1541
+ step(generator.next(value));
1542
+ } catch (e) {
1543
+ reject(e);
1544
+ }
1545
+ };
1546
+ var rejected = (value) => {
1547
+ try {
1548
+ step(generator.throw(value));
1549
+ } catch (e) {
1550
+ reject(e);
1551
+ }
1552
+ };
1553
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1554
+ step((generator = generator.apply(__this, __arguments)).next());
1555
+ });
1556
+ };
1557
+ let ID = 0;
1558
+ let REQUEST_ID = 0;
1559
+ class NgwConnector {
1560
+ constructor(options) {
1561
+ this.options = options;
1562
+ __publicField$2(this, "id", ID++);
1563
+ __publicField$2(this, "emitter", new EventEmitter());
1564
+ __publicField$2(this, "user");
1565
+ __publicField$2(this, "cache");
1566
+ __publicField$2(this, "withCredentials");
1567
+ __publicField$2(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
1568
+ __publicField$2(this, "routeStr", "/api/component/pyramid/route");
1569
+ __publicField$2(this, "activeRequests", {});
1570
+ __publicField$2(this, "requestTransform");
1571
+ const exist = findConnector(options);
1572
+ this.cache = new Cache({ namespace: options.cacheId });
1573
+ if (exist) {
1574
+ return exist;
1575
+ } else {
1576
+ const { route: route2, requestTransform, withCredentials } = this.options;
1577
+ if (route2) {
1578
+ this.routeStr = route2;
1579
+ }
1580
+ if (requestTransform) {
1581
+ this.requestTransform = requestTransform;
1582
+ }
1583
+ if (withCredentials !== void 0) {
1584
+ this.withCredentials = withCredentials;
1585
+ }
1586
+ addConnector(this);
1587
+ }
1588
+ }
1589
+ /**
1590
+ * Clear the cache.
1591
+ */
1592
+ clearCache() {
1593
+ this.cache.clean();
1594
+ }
1595
+ setRequestTransform(requestTransform) {
1596
+ this.requestTransform = requestTransform;
1597
+ }
1598
+ /**
1599
+ * Fast way to specify the connection address to NextGIS Web.
1600
+ * The current connection will be severed.
1601
+ * @param baseUrl - NGW url
1602
+ */
1603
+ setNgw(baseUrl) {
1604
+ this.logout();
1605
+ this.options.baseUrl = baseUrl;
1606
+ addConnector(this);
1607
+ }
1608
+ /**
1609
+ * Establishing a connection with NextGIS Web to fulfill all other requests.
1610
+ * @remarks
1611
+ * This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
1612
+ * Can be used to check connection.
1613
+ * @example
1614
+ * ```javascript
1615
+ * const connector = new NgwConnector({ baseUrl: 'https://demo.nextgis.com' });
1616
+ * connector.connect()
1617
+ * .then(() => console.log('Ok'))
1618
+ * .catch((er) => console.log('Connection problem', er));
1619
+ * ```
1620
+ */
1621
+ connect() {
1622
+ return __async$1(this, arguments, function* ({
1623
+ signal
1624
+ } = {}) {
1625
+ const auth = this.options.auth;
1626
+ if (auth) {
1627
+ const { login, password } = auth;
1628
+ if (login && password) {
1629
+ yield this._login({ login, password });
1630
+ }
1631
+ }
1632
+ const routeUrl = `${this.routeStr}?client=${this.client}`;
1633
+ return this.makeQuery(
1634
+ routeUrl,
1635
+ {},
1636
+ {
1637
+ cacheName: "route",
1638
+ signal,
1639
+ cache: true,
1640
+ cacheProps: {
1641
+ id: this.id,
1642
+ auth,
1643
+ baseUrl: this.options.baseUrl
1644
+ }
1645
+ }
1646
+ );
1647
+ });
1648
+ }
1649
+ /**
1650
+ * Quick way to change NextGIS Web user.
1651
+ * @param credentials - New user credentials
1652
+ */
1653
+ login(credentials, options) {
1654
+ this.logout();
1655
+ addConnector(this);
1656
+ return this._login(credentials, options);
1657
+ }
1658
+ /**
1659
+ * Disconnecting a user. Aborting all current requests
1660
+ */
1661
+ logout() {
1662
+ this.abort();
1663
+ removeConnector(this);
1664
+ this.options.auth = void 0;
1665
+ this.user = void 0;
1666
+ this.clearCache();
1667
+ this.emitter.emit("logout");
1668
+ }
1669
+ getUserInfo(credentials, options) {
1670
+ return __async$1(this, null, function* () {
1671
+ if (this.user && this.user.id) {
1672
+ return this.user;
1673
+ }
1674
+ if (credentials) {
1675
+ this.options.auth = credentials;
1676
+ }
1677
+ const options_ = __spreadValues$1({
1678
+ headers: this.getAuthorizationHeaders(credentials),
1679
+ cache: true
1680
+ }, options);
1681
+ return this.makeQuery(
1682
+ "/api/component/auth/current_user",
1683
+ {},
1684
+ options_
1685
+ );
1686
+ });
1687
+ }
1688
+ /**
1689
+ * Obtaining the required Headers for authentication of requests in the NGW.
1690
+ */
1691
+ getAuthorizationHeaders(credentials) {
1692
+ const client = this.makeClientId(credentials);
1693
+ if (client) {
1694
+ return {
1695
+ Authorization: `Basic ${client}`
1696
+ };
1697
+ }
1698
+ return {};
1699
+ }
1700
+ makeClientId(credentials) {
1701
+ credentials = credentials || this.options.auth;
1702
+ if (credentials) {
1703
+ const { login, password } = credentials;
1704
+ const encodedStr = [login, password].map(encodeURIComponent).join(":");
1705
+ {
1706
+ return window.btoa(encodedStr);
1707
+ }
1708
+ }
1709
+ }
1710
+ /** Stop all api requests */
1711
+ abort() {
1712
+ for (const abortController of Object.values(this.activeRequests)) {
1713
+ abortController.abort();
1714
+ }
1715
+ this.activeRequests = {};
1716
+ }
1717
+ getActiveApiRequests() {
1718
+ return __spreadValues$1({}, this.activeRequests);
1719
+ }
1720
+ route(name, ...rest) {
1721
+ return route(name, this, ...rest);
1722
+ }
1723
+ /**
1724
+ * Send request to NGW.
1725
+ * @param url - URL address to NGW
1726
+ * @param params - Query params
1727
+ * @param options - Request options
1728
+ */
1729
+ makeQuery(_0, _1) {
1730
+ return __async$1(this, arguments, function* (url, params, options = {}) {
1731
+ var _b;
1732
+ url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1733
+ if (!url) {
1734
+ throw new Error("Empty `url` not allowed");
1735
+ }
1736
+ if (params) {
1737
+ const _a = params, restParams = __objRest(_a, ["paramList"]);
1738
+ url = template(url, restParams);
1739
+ }
1740
+ url = encodeURI(fixUrlStr(url));
1741
+ options = __spreadValues$1({ withCredentials: this.withCredentials }, options);
1742
+ const {
1743
+ cache,
1744
+ signal: externalSignal,
1745
+ method = "GET",
1746
+ headers,
1747
+ cacheName,
1748
+ cacheProps,
1749
+ responseType,
1750
+ withCredentials
1751
+ } = options;
1752
+ const internalAbortController = new AbortController();
1753
+ const internalSignal = internalAbortController.signal;
1754
+ if (externalSignal) {
1755
+ if (externalSignal.aborted) {
1756
+ throw new AbortError();
1757
+ }
1758
+ externalSignal.addEventListener("abort", () => {
1759
+ internalAbortController.abort();
1760
+ });
1761
+ }
1762
+ options.signal = internalSignal;
1763
+ const createPromise = () => __async$1(this, null, function* () {
1764
+ const id = REQUEST_ID++;
1765
+ this.activeRequests[id] = internalAbortController;
1766
+ try {
1767
+ return this._loadData(url, options);
1768
+ } finally {
1769
+ this._cleanActiveRequest(id);
1770
+ }
1771
+ });
1772
+ if (method === "GET") {
1773
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$1({}, objectRemoveEmpty({
1774
+ headers,
1775
+ withCredentials,
1776
+ responseType,
1777
+ baseUrl: this.options.baseUrl,
1778
+ userId: (_b = this.user) == null ? void 0 : _b.id
1779
+ })), {
1780
+ params
1781
+ });
1782
+ return this.cache.add(cacheName || url, createPromise, {
1783
+ props: cacheOptions,
1784
+ expirationTime: cache ? void 0 : 500
1785
+ });
1786
+ }
1787
+ return createPromise();
1788
+ });
1789
+ }
1790
+ _loadData(url, options) {
1791
+ options.responseType = options.responseType || "json";
1792
+ return new Promise((resolve, reject) => {
1793
+ var _a;
1794
+ if (this.user) {
1795
+ options = options || {};
1796
+ options.headers = __spreadValues$1(__spreadValues$1({}, this.getAuthorizationHeaders()), options.headers);
1797
+ }
1798
+ if (this.requestTransform) {
1799
+ const [transUrl, transOptions] = this.requestTransform(url, options);
1800
+ url = transUrl;
1801
+ options = transOptions;
1802
+ }
1803
+ let runOnAbort = void 0;
1804
+ loadData(url, resolve, options, reject, (handler) => {
1805
+ runOnAbort = handler;
1806
+ });
1807
+ (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1808
+ if (runOnAbort !== void 0) {
1809
+ runOnAbort();
1810
+ }
1811
+ reject(new AbortError());
1812
+ });
1813
+ }).catch((httpError) => {
1814
+ if (httpError.name !== "AbortError") {
1815
+ {
1816
+ console.warn("DEV WARN", httpError);
1817
+ }
1818
+ const er = this._handleHttpError(httpError);
1819
+ if (er) {
1820
+ throw er;
1821
+ }
1822
+ }
1823
+ throw httpError;
1824
+ });
1825
+ }
1826
+ _login(credentials, options) {
1827
+ return __async$1(this, null, function* () {
1828
+ try {
1829
+ const data = yield this.getUserInfo(credentials, options);
1830
+ this.user = data;
1831
+ this.emitter.emit("login", data);
1832
+ return data;
1833
+ } catch (er) {
1834
+ this.emitter.emit("login:error", er);
1835
+ throw er;
1836
+ }
1837
+ });
1838
+ }
1839
+ _cleanActiveRequest(requestId) {
1840
+ delete this.activeRequests[requestId];
1841
+ }
1842
+ _handleHttpError(er) {
1843
+ if (er) {
1844
+ if (er instanceof NgwError) {
1845
+ if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
1846
+ throw new ResourceNotFoundError(er);
1847
+ } else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
1848
+ throw new InsufficientPermissionsError(er);
1849
+ }
1850
+ }
1851
+ }
1852
+ return er;
1853
+ }
1854
+ }
1855
+ __publicField$2(NgwConnector, "errors", errors);
1856
+
1857
+ function resourceCompare(res1, res2) {
1858
+ return objectDeepEqual(res1, res2);
1859
+ }
1860
+
1861
+ const exclude = ["description"];
1862
+ function resourceToQuery(resource, prefix = "") {
1863
+ prefix = prefix ? prefix + "__" : "";
1864
+ const query = {};
1865
+ for (const [key, value] of Object.entries(resource)) {
1866
+ if (exclude.indexOf(key) === -1) {
1867
+ if (isObject(value)) {
1868
+ if (key === "owner_user") {
1869
+ const children = resourceToQuery(
1870
+ value,
1871
+ key
1872
+ );
1873
+ Object.assign(query, children);
1874
+ } else if (key === "parent" && "id" in value) {
1875
+ query.parent_id = value.id;
1194
1876
  }
1877
+ } else if (defined(value)) {
1878
+ query[prefix + key] = value;
1195
1879
  }
1196
- } else {
1197
- data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
1198
1880
  }
1199
- if (onCancel) {
1200
- onCancel(() => {
1201
- xhr.abort();
1202
- });
1203
- }
1204
- xhr.send(data);
1205
- };
1881
+ }
1882
+ return query;
1206
1883
  }
1207
1884
 
1208
- var __defProp = Object.defineProperty;
1885
+ var __defProp$1 = Object.defineProperty;
1209
1886
  var __defProps = Object.defineProperties;
1210
1887
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1211
1888
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1212
1889
  var __hasOwnProp = Object.prototype.hasOwnProperty;
1213
1890
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
1214
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1891
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1215
1892
  var __spreadValues = (a, b) => {
1216
1893
  for (var prop in b || (b = {}))
1217
1894
  if (__hasOwnProp.call(b, prop))
1218
- __defNormalProp(a, prop, b[prop]);
1895
+ __defNormalProp$1(a, prop, b[prop]);
1219
1896
  if (__getOwnPropSymbols)
1220
1897
  for (var prop of __getOwnPropSymbols(b)) {
1221
1898
  if (__propIsEnum.call(b, prop))
1222
- __defNormalProp(a, prop, b[prop]);
1899
+ __defNormalProp$1(a, prop, b[prop]);
1223
1900
  }
1224
1901
  return a;
1225
1902
  };
1226
1903
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1227
- var __objRest = (source, exclude) => {
1228
- var target = {};
1229
- for (var prop in source)
1230
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
1231
- target[prop] = source[prop];
1232
- if (source != null && __getOwnPropSymbols)
1233
- for (var prop of __getOwnPropSymbols(source)) {
1234
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
1235
- target[prop] = source[prop];
1236
- }
1237
- return target;
1238
- };
1239
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1904
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1240
1905
  var __async = (__this, __arguments, generator) => {
1241
1906
  return new Promise((resolve, reject) => {
1242
1907
  var fulfilled = (value) => {
@@ -1257,171 +1922,269 @@ var __async = (__this, __arguments, generator) => {
1257
1922
  step((generator = generator.apply(__this, __arguments)).next());
1258
1923
  });
1259
1924
  };
1260
- let ID = 0;
1261
- let REQUEST_ID = 0;
1262
- class NgwConnector {
1263
- constructor(options) {
1264
- this.options = options;
1265
- __publicField(this, "id", ID++);
1266
- __publicField(this, "emitter", new EventEmitter());
1267
- __publicField(this, "user");
1268
- __publicField(this, "resources");
1269
- __publicField(this, "cache");
1270
- __publicField(this, "withCredentials");
1271
- __publicField(this, "routeStr", "/api/component/pyramid/route");
1272
- __publicField(this, "activeRequests", {});
1273
- __publicField(this, "requestTransform");
1274
- const exist = findConnector(options);
1275
- this.cache = new Cache({ namespace: options.cacheId });
1276
- if (exist) {
1277
- return exist;
1278
- } else {
1279
- const { route, requestTransform, withCredentials } = this.options;
1280
- if (route) {
1281
- this.routeStr = route;
1282
- }
1283
- if (requestTransform) {
1284
- this.requestTransform = requestTransform;
1285
- }
1286
- if (withCredentials !== void 0) {
1287
- this.withCredentials = withCredentials;
1925
+ class ResourcesControl {
1926
+ constructor({
1927
+ connector,
1928
+ cacheId
1929
+ }) {
1930
+ __publicField$1(this, "cache");
1931
+ __publicField$1(this, "connector");
1932
+ this.connector = connector;
1933
+ this.cache = new Cache({ namespace: cacheId });
1934
+ }
1935
+ // -------------------------------------------------------------------------
1936
+ // Resource Methods
1937
+ // -------------------------------------------------------------------------
1938
+ /**
1939
+ * Receive resource from NGW by id, keyname or search-object parameter.
1940
+ * @param resource - Resource id, keyname or search-object
1941
+ *
1942
+ * @remarks
1943
+ * Fetching resource would be cached to speed up next call
1944
+ */
1945
+ getOne(resource, requestOptions) {
1946
+ const opt = __spreadValues({}, requestOptions);
1947
+ if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
1948
+ if (resource.id !== void 0) {
1949
+ resource.id;
1950
+ } else {
1951
+ if (resource.keyname) {
1952
+ resource.keyname;
1953
+ }
1954
+ if (resource.display_name) {
1955
+ resource.display_name;
1956
+ }
1288
1957
  }
1289
- this.resources = new ResourcesControl({
1290
- connector: this,
1291
- cacheId: options.cacheId
1292
- });
1293
- addConnector(this);
1294
1958
  }
1959
+ if (typeof resource === "string") {
1960
+ return this._fetchResourceBy({ keyname: resource }, opt);
1961
+ } else if (typeof resource === "number") {
1962
+ return this._fetchResourceById(resource, opt);
1963
+ } else if (isObject(resource)) {
1964
+ return this._fetchResourceBy(resource, opt);
1965
+ }
1966
+ return Promise.resolve(void 0);
1295
1967
  }
1296
- static create(options) {
1297
- return new this(options);
1968
+ getOneOrFail(resource, requestOptions) {
1969
+ return this.getOne(resource, requestOptions).then((res) => {
1970
+ if (res) {
1971
+ return res;
1972
+ }
1973
+ throw new ResourceNotFoundError();
1974
+ });
1298
1975
  }
1299
1976
  /**
1300
- * Clear the cache.
1977
+ * A fast way to retrieve resource ID for any resource definition.
1978
+ * @param resource - Any available resource definition
1979
+ *
1980
+ * @remarks
1981
+ * There are situations when exactly the resource id is needed
1982
+ * (for example, to compose the correct request to the api)
1983
+ * then this method will come in handy to facilitate the extraction of the identifier
1984
+ * if the resource is specified through a keyname or other parameters.
1301
1985
  */
1302
- clearCache() {
1303
- this.cache.clean();
1304
- this.resources.cache.clean();
1305
- }
1306
- setRequestTransform(requestTransform) {
1307
- this.requestTransform = requestTransform;
1986
+ getId(resource, requestOptions) {
1987
+ if (typeof resource === "number") {
1988
+ return Promise.resolve(resource);
1989
+ } else if (typeof resource === "string" || isObject(resource)) {
1990
+ return this.getOne(resource, requestOptions).then((res) => {
1991
+ if (res) {
1992
+ return res.resource.id;
1993
+ }
1994
+ });
1995
+ }
1996
+ return Promise.resolve(void 0);
1308
1997
  }
1309
1998
  /**
1310
- * Fast way to specify the connection address to NextGIS Web.
1311
- * The current connection will be severed.
1312
- * @param baseUrl - NGW url
1999
+ * A fast way to retrieve resource ID for any resource definition.
2000
+ * @param resource - Any available resource definition
2001
+ *
2002
+ * @remarks
2003
+ * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
2004
+ * To not make one more checks if the resource is definitely exists
1313
2005
  */
1314
- setNgw(baseUrl) {
1315
- this.logout();
1316
- this.options.baseUrl = baseUrl;
1317
- addConnector(this);
2006
+ getIdOrFail(resource, requestOptions) {
2007
+ return this.getId(resource, requestOptions).then((resp) => {
2008
+ if (resp === void 0) {
2009
+ throw new Error();
2010
+ }
2011
+ return resp;
2012
+ });
2013
+ }
2014
+ getMany(resource, requestOptions) {
2015
+ return this._resourceCacheFilter(resource).then((items) => {
2016
+ if (!items.length) {
2017
+ const query = {};
2018
+ if (resource.keyname) {
2019
+ query.keyname = resource.keyname;
2020
+ } else {
2021
+ Object.assign(query, resourceToQuery(resource));
2022
+ }
2023
+ return this.connector.route("resource.search").get(__spreadProps(__spreadValues({}, requestOptions), {
2024
+ query: __spreadValues({
2025
+ serialization: "full"
2026
+ }, query)
2027
+ })).then((resources) => {
2028
+ if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
2029
+ for (const x of resources) {
2030
+ this.cache.add("resource.item", Promise.resolve(x), {
2031
+ id: x.resource.id
2032
+ });
2033
+ }
2034
+ }
2035
+ return resources;
2036
+ });
2037
+ }
2038
+ return items;
2039
+ });
2040
+ }
2041
+ getParent(resource, requestOptions) {
2042
+ return this.getOne(resource, requestOptions).then((child) => {
2043
+ var _a, _b;
2044
+ if ((_b = (_a = child == null ? void 0 : child.resource) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) {
2045
+ return this.getOne(child.resource.parent.id, requestOptions);
2046
+ }
2047
+ return Promise.resolve(void 0);
2048
+ });
2049
+ }
2050
+ getChildrenOf(resource, requestOptions) {
2051
+ return this.getIdOrFail(resource).then(
2052
+ (parent) => this._getChildrenOf(parent, requestOptions)
2053
+ );
2054
+ }
2055
+ update(resource, data) {
2056
+ return this.getId(resource).then((id) => {
2057
+ if (id !== void 0) {
2058
+ return this.connector.put("resource.item", { data }, { id });
2059
+ }
2060
+ });
1318
2061
  }
1319
2062
  /**
1320
- * Establishing a connection with NextGIS Web to fulfill all other requests.
1321
- * @remarks
1322
- * This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
1323
- * Can be used to check connection.
1324
- * @example
1325
- * ```javascript
1326
- * const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
1327
- * connector.connect()
1328
- * .then(() => console.log('Ok'))
1329
- * .catch((er) => console.log('Connection problem', er));
1330
- * ```
2063
+ * Fast way to delete resource from NGW and clean cache.
2064
+ * @param resource - Resource definition
1331
2065
  */
1332
- connect() {
1333
- return __async(this, null, function* () {
1334
- const auth = this.options.auth;
1335
- if (auth) {
1336
- const { login, password } = auth;
1337
- if (login && password) {
1338
- yield this._login({ login, password });
2066
+ delete(resource) {
2067
+ return this.getId(resource).then((id) => {
2068
+ if (id !== void 0) {
2069
+ return this.connector.delete("resource.item", null, { id }).then(() => {
2070
+ this._cleanResourceItemCache(id);
2071
+ return void 0;
2072
+ });
2073
+ }
2074
+ });
2075
+ }
2076
+ _getChildrenOf(_0, _1) {
2077
+ return __async(this, arguments, function* (parentDef, requestOptions, _items = []) {
2078
+ let parent = void 0;
2079
+ if (typeof parentDef === "string") {
2080
+ parent = yield this.getId(parentDef, requestOptions);
2081
+ } else if (typeof parentDef === "object") {
2082
+ parent = parentDef.id;
2083
+ } else {
2084
+ parent = parentDef;
2085
+ }
2086
+ const items = yield this.connector.route("resource.collection").get(__spreadProps(__spreadValues({}, requestOptions), {
2087
+ query: {
2088
+ parent
2089
+ }
2090
+ }));
2091
+ const recursivePromises = [];
2092
+ for (const item of items) {
2093
+ if (requestOptions == null ? void 0 : requestOptions.cache) {
2094
+ this.cache.add("resource.item", Promise.resolve(item), {
2095
+ id: item.resource.id
2096
+ });
2097
+ }
2098
+ _items.push(item);
2099
+ if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
2100
+ recursivePromises.push(
2101
+ this._getChildrenOf(item.resource.id, requestOptions, _items)
2102
+ );
1339
2103
  }
1340
2104
  }
1341
- return yield this.makeQuery(
1342
- this.routeStr,
1343
- {},
1344
- {
1345
- cacheName: "route",
1346
- cache: true,
1347
- cacheProps: {
1348
- id: this.id,
1349
- auth,
1350
- baseUrl: this.options.baseUrl
1351
- }
1352
- }
1353
- );
2105
+ if (recursivePromises.length) {
2106
+ return Promise.all(recursivePromises).then(() => {
2107
+ return _items;
2108
+ });
2109
+ }
2110
+ return _items;
1354
2111
  });
1355
2112
  }
1356
- /**
1357
- * Quick way to change NextGIS Web user.
1358
- * @param credentials - New user credentials
1359
- */
1360
- login(credentials, options) {
1361
- this.logout();
1362
- addConnector(this);
1363
- return this._login(credentials, options);
1364
- }
1365
- /**
1366
- * Disconnecting a user. Aborting all current requests
1367
- */
1368
- logout() {
1369
- this.abort();
1370
- removeConnector(this);
1371
- this.options.auth = void 0;
1372
- this.user = void 0;
1373
- this.clearCache();
1374
- this.emitter.emit("logout");
1375
- }
1376
- getUserInfo(credentials, options) {
2113
+ _cleanResourceItemCache(id) {
1377
2114
  return __async(this, null, function* () {
1378
- if (this.user && this.user.id) {
1379
- return this.user;
2115
+ var _a;
2116
+ const all = this.cache.all();
2117
+ const toDelete = [];
2118
+ for (const c of all) {
2119
+ const cid = (_a = c.props) == null ? void 0 : _a.id;
2120
+ if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
2121
+ if (typeof cid === "number") {
2122
+ if (cid === id) {
2123
+ toDelete.push(c);
2124
+ }
2125
+ } else {
2126
+ const rid = yield this.getId(cid);
2127
+ if (rid === id) {
2128
+ toDelete.push(c);
2129
+ }
2130
+ }
2131
+ }
1380
2132
  }
1381
- if (credentials) {
1382
- this.options.auth = credentials;
2133
+ for (const d of toDelete) {
2134
+ this.cache.delete(d);
1383
2135
  }
1384
- const options_ = __spreadValues({
1385
- headers: this.getAuthorizationHeaders(credentials)
1386
- }, options);
1387
- return this.makeQuery(
1388
- "/api/component/auth/current_user",
1389
- {},
1390
- options_
1391
- );
1392
2136
  });
1393
2137
  }
1394
- /**
1395
- * Obtaining the required Headers for authentication of requests in the NGW.
1396
- */
1397
- getAuthorizationHeaders(credentials) {
1398
- const client = this.makeClientId(credentials);
1399
- if (client) {
1400
- return {
1401
- Authorization: `Basic ${client}`
1402
- };
1403
- }
2138
+ _fetchResourceById(id, requestOptions) {
2139
+ return this.connector.route("resource.item", { id }).get(requestOptions);
1404
2140
  }
1405
- makeClientId(credentials) {
1406
- credentials = credentials || this.options.auth;
1407
- if (credentials) {
1408
- const { login, password } = credentials;
1409
- const str = `${login}:${password}`;
1410
- const encodedStr = encodeURIComponent(str);
1411
- {
1412
- return window.btoa(encodedStr);
2141
+ _fetchResourceBy(resource, requestOptions) {
2142
+ return this.getMany(resource, requestOptions).then((resources) => {
2143
+ return resources[0];
2144
+ });
2145
+ }
2146
+ _resourceCacheFilter(resource) {
2147
+ return Promise.all(this.cache.matchAll("resource.item")).then(
2148
+ (resources) => {
2149
+ const items = [];
2150
+ resources.filter((x) => {
2151
+ if (x) {
2152
+ if (resource.keyname && x.resource.keyname) {
2153
+ return resource.keyname === x.resource.keyname;
2154
+ }
2155
+ if (defined(resource.id) && defined(x.resource.id)) {
2156
+ return resource.id === x.resource.id;
2157
+ }
2158
+ return resourceCompare(resource, x.resource);
2159
+ }
2160
+ });
2161
+ return items;
1413
2162
  }
1414
- }
2163
+ );
1415
2164
  }
1416
- /** Stop all api requests */
1417
- abort() {
1418
- for (const abortController of Object.values(this.activeRequests)) {
1419
- abortController.abort();
1420
- }
1421
- this.activeRequests = {};
2165
+ }
2166
+
2167
+ var __defProp = Object.defineProperty;
2168
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2169
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
2170
+ class NgwConnectorExtended extends NgwConnector {
2171
+ constructor(options) {
2172
+ super(options);
2173
+ __publicField(this, "resources");
2174
+ this.resources = new ResourcesControl({
2175
+ connector: this,
2176
+ cacheId: options.cacheId
2177
+ });
1422
2178
  }
1423
- getActiveApiRequests() {
1424
- return __spreadValues({}, this.activeRequests);
2179
+ static create(options) {
2180
+ return new this(options);
2181
+ }
2182
+ /**
2183
+ * Clear the cache.
2184
+ */
2185
+ clearCache() {
2186
+ super.clearCache();
2187
+ this.resources.cache.clean();
1425
2188
  }
1426
2189
  /**
1427
2190
  * Send request to NGW api router.
@@ -1540,75 +2303,6 @@ class NgwConnector {
1540
2303
  options
1541
2304
  );
1542
2305
  }
1543
- /**
1544
- * Send request to NGW.
1545
- * @param url - URL address to NGW
1546
- * @param params - Query params
1547
- * @param options - Request options
1548
- */
1549
- makeQuery(_0, _1) {
1550
- return __async(this, arguments, function* (url, params, options = {}) {
1551
- var _b;
1552
- url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
1553
- if (!url) {
1554
- throw new Error("Empty `url` not allowed");
1555
- }
1556
- if (params) {
1557
- const _a = params, restParams = __objRest(_a, ["paramList"]);
1558
- url = template(url, restParams);
1559
- }
1560
- url = encodeURI(fixUrlStr(url));
1561
- options = __spreadValues({ withCredentials: this.withCredentials }, options);
1562
- const {
1563
- cache,
1564
- signal: externalSignal,
1565
- method = "GET",
1566
- headers,
1567
- cacheName,
1568
- cacheProps,
1569
- responseType,
1570
- withCredentials
1571
- } = options;
1572
- const internalAbortController = new AbortController();
1573
- const internalSignal = internalAbortController.signal;
1574
- if (externalSignal) {
1575
- if (externalSignal.aborted) {
1576
- throw new AbortError();
1577
- }
1578
- externalSignal.addEventListener("abort", () => {
1579
- internalAbortController.abort();
1580
- });
1581
- }
1582
- options.signal = internalSignal;
1583
- const createPromise = () => __async(this, null, function* () {
1584
- const id = REQUEST_ID++;
1585
- this.activeRequests[id] = internalAbortController;
1586
- try {
1587
- return this._loadData(url, options);
1588
- } finally {
1589
- this._cleanActiveRequest(id);
1590
- }
1591
- });
1592
- if (cache && method === "GET") {
1593
- const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues({}, objectRemoveEmpty({
1594
- headers,
1595
- withCredentials,
1596
- responseType,
1597
- baseUrl: this.options.baseUrl,
1598
- userId: (_b = this.user) == null ? void 0 : _b.id
1599
- })), {
1600
- params
1601
- });
1602
- return this.cache.add(
1603
- cacheName || url,
1604
- createPromise,
1605
- cacheOptions,
1606
- false
1607
- );
1608
- }
1609
- return createPromise();
1610
- });
1611
- }
1612
2306
  // -------------------------------------------------------------------------
1613
2307
  // Resource Methods
1614
2308
  // -------------------------------------------------------------------------
@@ -1684,78 +2378,7 @@ class NgwConnector {
1684
2378
  deleteResource(resource) {
1685
2379
  return this.resources.delete(resource);
1686
2380
  }
1687
- /**
1688
- * @internal
1689
- */
1690
- _loadData(url, options) {
1691
- options.responseType = options.responseType || "json";
1692
- return new Promise((resolve, reject) => {
1693
- var _a;
1694
- if (this.user) {
1695
- options = options || {};
1696
- options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
1697
- }
1698
- if (this.requestTransform) {
1699
- const [transUrl, transOptions] = this.requestTransform(url, options);
1700
- url = transUrl;
1701
- options = transOptions;
1702
- }
1703
- let runOnAbort = void 0;
1704
- loadData(url, resolve, options, reject, (handler) => {
1705
- runOnAbort = handler;
1706
- });
1707
- (_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
1708
- if (runOnAbort !== void 0) {
1709
- runOnAbort();
1710
- }
1711
- reject(new AbortError());
1712
- });
1713
- }).catch((httpError) => {
1714
- if (httpError.name !== "AbortError") {
1715
- {
1716
- console.warn("DEV WARN", httpError);
1717
- }
1718
- const er = this._handleHttpError(httpError);
1719
- if (er) {
1720
- throw er;
1721
- }
1722
- }
1723
- throw httpError;
1724
- });
1725
- }
1726
- _login(credentials, options) {
1727
- return __async(this, null, function* () {
1728
- try {
1729
- const data = yield this.getUserInfo(credentials, options);
1730
- this.user = data;
1731
- this.emitter.emit("login", data);
1732
- return data;
1733
- } catch (er) {
1734
- this.emitter.emit("login:error", er);
1735
- throw er;
1736
- }
1737
- });
1738
- }
1739
- _cleanActiveRequest(requestId) {
1740
- delete this.activeRequests[requestId];
1741
- }
1742
- _handleHttpError(er) {
1743
- if (er) {
1744
- if (er instanceof NgwError) {
1745
- if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
1746
- throw new ResourceNotFoundError(er);
1747
- } else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
1748
- throw new InsufficientPermissionsError(er);
1749
- }
1750
- }
1751
- }
1752
- return er;
1753
- }
1754
2381
  }
1755
- __publicField(NgwConnector, "errors", {
1756
- NgwError,
1757
- ResourceNotFoundError
1758
- });
1759
2382
 
1760
- export { NgwConnector as default };
2383
+ export { NgwConnectorExtended as default };
1761
2384
  //# sourceMappingURL=ngw-connector.esm-browser.js.map