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