@nextgis/ngw-connector 3.0.0-alpha.12 → 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,11 +1,111 @@
1
- /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.8; author: NextGIS */
2
- import { objectDeepEqual, isObject as isObject$1, objectRemoveEmpty, fixUrlStr, defined } from '@nextgis/utils';
3
- import { EventEmitter } from 'events';
1
+ /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.13; author: NextGIS */
2
+ import { isObject as isObject$1, objectRemoveEmpty, fixUrlStr, objectDeepEqual, defined } from '@nextgis/utils';
4
3
  import Cache from '@nextgis/cache';
4
+ import { EventEmitter } from 'events';
5
+
6
+ const templateRe = /\{ *([\w_-]+) *\}/g;
7
+ function template(str, data) {
8
+ return str.replace(templateRe, (s, key) => {
9
+ let value = data[key];
10
+ if (value === void 0) {
11
+ throw new Error("No value provided for letiable " + s);
12
+ } else if (typeof value === "function") {
13
+ value = value(data);
14
+ }
15
+ return value;
16
+ });
17
+ }
18
+
19
+ var __defProp$b = Object.defineProperty;
20
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
21
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
22
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
23
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
24
+ var __spreadValues$4 = (a, b) => {
25
+ for (var prop in b || (b = {}))
26
+ if (__hasOwnProp$4.call(b, prop))
27
+ __defNormalProp$b(a, prop, b[prop]);
28
+ if (__getOwnPropSymbols$4)
29
+ for (var prop of __getOwnPropSymbols$4(b)) {
30
+ if (__propIsEnum$4.call(b, prop))
31
+ __defNormalProp$b(a, prop, b[prop]);
32
+ }
33
+ return a;
34
+ };
35
+ var __async$4 = (__this, __arguments, generator) => {
36
+ return new Promise((resolve, reject) => {
37
+ var fulfilled = (value) => {
38
+ try {
39
+ step(generator.next(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var rejected = (value) => {
45
+ try {
46
+ step(generator.throw(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
52
+ step((generator = generator.apply(__this, __arguments)).next());
53
+ });
54
+ };
55
+ function apiRequest(opt) {
56
+ return __async$4(this, null, function* () {
57
+ const { params, name, connector, requestOptions } = opt;
58
+ const apiItems = yield connector.connect();
59
+ let apiItem = apiItems && apiItems[name];
60
+ if (apiItem) {
61
+ apiItem = [...apiItem];
62
+ let url = apiItem.shift();
63
+ if (apiItem.length) {
64
+ const replaceParams = {};
65
+ for (let fry = 0; fry < apiItem.length; fry++) {
66
+ const arg = apiItem[fry];
67
+ replaceParams[fry] = `{${arg}}`;
68
+ if (params[arg] === void 0) {
69
+ throw new Error(`\`${arg}\` URL API argument is not specified`);
70
+ }
71
+ }
72
+ if (url) {
73
+ url = template(url, replaceParams);
74
+ }
75
+ }
76
+ if (params) {
77
+ const paramArray = [];
78
+ const paramList = params.paramList;
79
+ if (Array.isArray(paramList)) {
80
+ paramList.forEach(([key, value]) => {
81
+ paramArray.push(`${key}=${value}`);
82
+ });
83
+ }
84
+ for (const p in params) {
85
+ if (apiItem.indexOf(p) === -1) {
86
+ paramArray.push(`${p}=${params[p]}`);
87
+ }
88
+ }
89
+ if (paramArray.length) {
90
+ url = `${url}?${paramArray.join("&")}`;
91
+ }
92
+ }
93
+ if (url) {
94
+ return connector.makeQuery(url, params, __spreadValues$4({
95
+ cacheName: name
96
+ }, requestOptions));
97
+ } else {
98
+ throw new Error("Request URL is not set");
99
+ }
100
+ } else {
101
+ return void 0;
102
+ }
103
+ });
104
+ }
5
105
 
6
106
  var pkg = {
7
107
  name: "@nextgis/ngw-connector",
8
- version: "3.0.0-alpha.8",
108
+ version: "3.0.0-alpha.13",
9
109
  _priority: 12,
10
110
  description: "A lightweight HTTP client optimized for use with NextGIS Web API",
11
111
  main: "index.js",
@@ -14,15 +114,15 @@ var pkg = {
14
114
  jsdelivr: "lib/ngw-connector.global.prod.js",
15
115
  types: "lib/index.d.ts",
16
116
  dependencies: {
17
- "@nextgis/cache": "^3.0.0-alpha.7",
18
- "@nextgis/cancelable-promise": "^3.0.0-alpha.5",
19
- "@nextgis/utils": "^3.0.0-alpha.5",
117
+ "@nextgis/cache": "^3.0.0-alpha.13",
118
+ "@nextgis/cancelable-promise": "^3.0.0-alpha.13",
119
+ "@nextgis/utils": "^3.0.0-alpha.13",
20
120
  "@types/events": "^3.0.0",
21
121
  events: "*",
22
122
  "form-data": "^4.0.0"
23
123
  },
24
124
  devDependencies: {
25
- "@nextgis/build-tools": "^3.0.0-alpha.5"
125
+ "@nextgis/build-tools": "^3.0.0-alpha.13"
26
126
  },
27
127
  scripts: {
28
128
  clean: "rimraf ./lib",
@@ -62,30 +162,6 @@ var pkg = {
62
162
  gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
63
163
  };
64
164
 
65
- const CONNECTORS = [];
66
- function addConnector(connector) {
67
- CONNECTORS.push(connector);
68
- }
69
- function findConnector(options) {
70
- return CONNECTORS.find((x) => {
71
- if (x.options.baseUrl === options.baseUrl) {
72
- if (options.auth) {
73
- if (x.options.auth) {
74
- return objectDeepEqual(x.options.auth, options.auth);
75
- }
76
- } else {
77
- return true;
78
- }
79
- }
80
- });
81
- }
82
- function removeConnector(connector) {
83
- const index = CONNECTORS.indexOf(connector);
84
- if (index !== -1) {
85
- CONNECTORS.splice(index, 1);
86
- }
87
- }
88
-
89
165
  class AbortError extends Error {
90
166
  constructor(message = "AbortError") {
91
167
  super(message);
@@ -93,9 +169,9 @@ class AbortError extends Error {
93
169
  }
94
170
  }
95
171
 
96
- var __defProp$b = Object.defineProperty;
97
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
98
- var __publicField$8 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
172
+ var __defProp$a = Object.defineProperty;
173
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
174
+ var __publicField$8 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
99
175
  class NgwError extends Error {
100
176
  constructor(er) {
101
177
  super();
@@ -112,9 +188,9 @@ class NgwError extends Error {
112
188
  }
113
189
  }
114
190
 
115
- var __defProp$a = Object.defineProperty;
116
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
117
- var __publicField$7 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
191
+ var __defProp$9 = Object.defineProperty;
192
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
193
+ var __publicField$7 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
118
194
  class InsufficientPermissionsError extends NgwError {
119
195
  constructor(obj) {
120
196
  super(obj);
@@ -124,51 +200,19 @@ class InsufficientPermissionsError extends NgwError {
124
200
  }
125
201
  }
126
202
 
127
- var __defProp$9 = Object.defineProperty;
128
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
129
- var __publicField$6 = (obj, key, value) => __defNormalProp$9(obj, key + "" , value);
130
- class NetworkError extends Error {
131
- constructor(url) {
132
- super();
133
- __publicField$6(this, "name", "NetworkError");
134
- Object.setPrototypeOf(this, NetworkError.prototype);
135
- this.message = `Unable to request ${url}.
136
- Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
137
- }
138
- }
139
-
140
203
  var __defProp$8 = Object.defineProperty;
141
204
  var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
142
- var __publicField$5 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
205
+ var __publicField$6 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
143
206
  let NetworksResponseError$1 = class NetworksResponseError extends NgwError {
144
207
  constructor(obj) {
145
208
  super(obj);
146
- __publicField$5(this, "message", "There is no response from the server or problem connecting to server.");
147
- __publicField$5(this, "title", "Network error");
148
- __publicField$5(this, "detail", "Check network connectivity and try again later.");
209
+ __publicField$6(this, "message", "There is no response from the server or problem connecting to server.");
210
+ __publicField$6(this, "title", "Network error");
211
+ __publicField$6(this, "detail", "Check network connectivity and try again later.");
149
212
  Object.setPrototypeOf(this, NetworksResponseError.prototype);
150
213
  }
151
214
  };
152
215
 
153
- var __defProp$7 = Object.defineProperty;
154
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
155
- var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
156
- class ResourceNotFoundError extends NgwError {
157
- constructor(obj) {
158
- super(obj);
159
- __publicField$4(this, "name", "ResourceNotFoundError");
160
- __publicField$4(this, "exception", "nextgisweb.resource.exception.ResourceNotFound");
161
- Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
162
- }
163
- }
164
-
165
- function isError(error) {
166
- if (isObject$1(error)) {
167
- return error.status_code && error.exception && error.title;
168
- }
169
- return false;
170
- }
171
-
172
216
  function extractError(error) {
173
217
  if (isObject$1(error)) {
174
218
  if (error.name && error.message && error.title) {
@@ -194,6 +238,38 @@ function extractError(error) {
194
238
  }
195
239
  }
196
240
 
241
+ function isError(error) {
242
+ if (isObject$1(error)) {
243
+ return error.status_code && error.exception && error.title;
244
+ }
245
+ return false;
246
+ }
247
+
248
+ var __defProp$7 = Object.defineProperty;
249
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
250
+ var __publicField$5 = (obj, key, value) => __defNormalProp$7(obj, key + "" , value);
251
+ class NetworkError extends Error {
252
+ constructor(url) {
253
+ super();
254
+ __publicField$5(this, "name", "NetworkError");
255
+ Object.setPrototypeOf(this, NetworkError.prototype);
256
+ this.message = `Unable to request ${url}.
257
+ Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
258
+ }
259
+ }
260
+
261
+ var __defProp$6 = Object.defineProperty;
262
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
263
+ var __publicField$4 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
264
+ class ResourceNotFoundError extends NgwError {
265
+ constructor(obj) {
266
+ super(obj);
267
+ __publicField$4(this, "name", "ResourceNotFoundError");
268
+ __publicField$4(this, "exception", "nextgisweb.resource.exception.ResourceNotFound");
269
+ Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
270
+ }
271
+ }
272
+
197
273
  var errors = /*#__PURE__*/Object.freeze({
198
274
  __proto__: null,
199
275
  AbortError: AbortError,
@@ -206,9 +282,9 @@ var errors = /*#__PURE__*/Object.freeze({
206
282
  isError: isError
207
283
  });
208
284
 
209
- var __defProp$6 = Object.defineProperty;
210
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
211
- var __publicField$3 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
285
+ var __defProp$5 = Object.defineProperty;
286
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
287
+ var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
212
288
  class BaseAPIError extends Error {
213
289
  constructor(message) {
214
290
  super(message || "Something went wrong.");
@@ -270,35 +346,35 @@ class LunkwillRequestFailed extends LunkwillError {
270
346
  }
271
347
  }
272
348
 
273
- var __defProp$5 = Object.defineProperty;
274
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
275
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
276
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
277
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
278
- var __spreadValues$4 = (a, b) => {
349
+ var __defProp$4 = Object.defineProperty;
350
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
351
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
352
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
353
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
354
+ var __spreadValues$3 = (a, b) => {
279
355
  for (var prop in b || (b = {}))
280
- if (__hasOwnProp$4.call(b, prop))
281
- __defNormalProp$5(a, prop, b[prop]);
282
- if (__getOwnPropSymbols$4)
283
- for (var prop of __getOwnPropSymbols$4(b)) {
284
- if (__propIsEnum$4.call(b, prop))
285
- __defNormalProp$5(a, prop, b[prop]);
356
+ if (__hasOwnProp$3.call(b, prop))
357
+ __defNormalProp$4(a, prop, b[prop]);
358
+ if (__getOwnPropSymbols$3)
359
+ for (var prop of __getOwnPropSymbols$3(b)) {
360
+ if (__propIsEnum$3.call(b, prop))
361
+ __defNormalProp$4(a, prop, b[prop]);
286
362
  }
287
363
  return a;
288
364
  };
289
365
  var __objRest$2 = (source, exclude) => {
290
366
  var target = {};
291
367
  for (var prop in source)
292
- if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
368
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
293
369
  target[prop] = source[prop];
294
- if (source != null && __getOwnPropSymbols$4)
295
- for (var prop of __getOwnPropSymbols$4(source)) {
296
- if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
370
+ if (source != null && __getOwnPropSymbols$3)
371
+ for (var prop of __getOwnPropSymbols$3(source)) {
372
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
297
373
  target[prop] = source[prop];
298
374
  }
299
375
  return target;
300
376
  };
301
- var __async$4 = (__this, __arguments, generator) => {
377
+ var __async$3 = (__this, __arguments, generator) => {
302
378
  return new Promise((resolve, reject) => {
303
379
  var fulfilled = (value) => {
304
380
  try {
@@ -323,7 +399,7 @@ function lunkwillCheckResponse(lwResp) {
323
399
  return ct !== void 0 && ct !== null && ct.includes("application/vnd.lunkwill.request-summary+json");
324
400
  }
325
401
  function responseJson(response) {
326
- return __async$4(this, null, function* () {
402
+ return __async$3(this, null, function* () {
327
403
  try {
328
404
  return response.json();
329
405
  } catch (e) {
@@ -332,7 +408,7 @@ function responseJson(response) {
332
408
  });
333
409
  }
334
410
  function lunkwillResponseUrl(lwResp) {
335
- return __async$4(this, null, function* () {
411
+ return __async$3(this, null, function* () {
336
412
  const lwData = yield responseJson(lwResp);
337
413
  let delay = lwData.delay_ms;
338
414
  const retry = lwData.retry_ms !== void 0 ? lwData.retry_ms : 2e3;
@@ -376,7 +452,7 @@ function lunkwillResponseUrl(lwResp) {
376
452
  });
377
453
  }
378
454
  function lunkwillFetch(lwRespUrl) {
379
- return __async$4(this, null, function* () {
455
+ return __async$3(this, null, function* () {
380
456
  try {
381
457
  return yield window.fetch(lwRespUrl, { credentials: "same-origin" });
382
458
  } catch (e) {
@@ -424,14 +500,14 @@ function generateUrl(path, query) {
424
500
  return path + urlParams;
425
501
  }
426
502
  function request(path, options, cacheEngine) {
427
- return __async$4(this, null, function* () {
503
+ return __async$3(this, null, function* () {
428
504
  var _b;
429
505
  const defaults = {
430
506
  method: "GET",
431
507
  credentials: "same-origin",
432
508
  headers: {}
433
509
  };
434
- const _a = __spreadValues$4(__spreadValues$4({}, defaults), options), {
510
+ const _a = __spreadValues$3(__spreadValues$3({}, defaults), options), {
435
511
  withCredentials,
436
512
  responseType,
437
513
  cacheProps,
@@ -467,7 +543,7 @@ function request(path, options, cacheEngine) {
467
543
  opt.headers = headers;
468
544
  }
469
545
  const url = generateUrl(path, query);
470
- const makeRequest = () => __async$4(this, null, function* () {
546
+ const makeRequest = () => __async$3(this, null, function* () {
471
547
  let response;
472
548
  try {
473
549
  response = yield fetch(url, opt);
@@ -507,8 +583,8 @@ function request(path, options, cacheEngine) {
507
583
  }
508
584
  return body;
509
585
  });
510
- if (cacheEngine && ((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
511
- const props = cacheProps ? cacheProps : __spreadValues$4({}, objectRemoveEmpty({
586
+ if (cacheEngine && cache !== false && ((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
587
+ const props = cacheProps ? cacheProps : __spreadValues$3({}, objectRemoveEmpty({
512
588
  withCredentials,
513
589
  responseType
514
590
  }));
@@ -521,21 +597,21 @@ function request(path, options, cacheEngine) {
521
597
  });
522
598
  }
523
599
 
524
- var __defProp$4 = Object.defineProperty;
600
+ var __defProp$3 = Object.defineProperty;
525
601
  var __defProps$2 = Object.defineProperties;
526
602
  var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
527
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
528
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
529
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
530
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
531
- var __spreadValues$3 = (a, b) => {
603
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
604
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
605
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
606
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
607
+ var __spreadValues$2 = (a, b) => {
532
608
  for (var prop in b || (b = {}))
533
- if (__hasOwnProp$3.call(b, prop))
534
- __defNormalProp$4(a, prop, b[prop]);
535
- if (__getOwnPropSymbols$3)
536
- for (var prop of __getOwnPropSymbols$3(b)) {
537
- if (__propIsEnum$3.call(b, prop))
538
- __defNormalProp$4(a, prop, b[prop]);
609
+ if (__hasOwnProp$2.call(b, prop))
610
+ __defNormalProp$3(a, prop, b[prop]);
611
+ if (__getOwnPropSymbols$2)
612
+ for (var prop of __getOwnPropSymbols$2(b)) {
613
+ if (__propIsEnum$2.call(b, prop))
614
+ __defNormalProp$3(a, prop, b[prop]);
539
615
  }
540
616
  return a;
541
617
  };
@@ -543,16 +619,16 @@ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
543
619
  var __objRest$1 = (source, exclude) => {
544
620
  var target = {};
545
621
  for (var prop in source)
546
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
622
+ if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
547
623
  target[prop] = source[prop];
548
- if (source != null && __getOwnPropSymbols$3)
549
- for (var prop of __getOwnPropSymbols$3(source)) {
550
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
624
+ if (source != null && __getOwnPropSymbols$2)
625
+ for (var prop of __getOwnPropSymbols$2(source)) {
626
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
551
627
  target[prop] = source[prop];
552
628
  }
553
629
  return target;
554
630
  };
555
- var __async$3 = (__this, __arguments, generator) => {
631
+ var __async$2 = (__this, __arguments, generator) => {
556
632
  return new Promise((resolve, reject) => {
557
633
  var fulfilled = (value) => {
558
634
  try {
@@ -603,7 +679,7 @@ function routeURL(name, baseUrl, routeData, ...rest) {
603
679
  }
604
680
  function route(name, connector, ...rest) {
605
681
  const result = {
606
- url: (opt) => __async$3(this, null, function* () {
682
+ url: (opt) => __async$2(this, null, function* () {
607
683
  var _a;
608
684
  const routeData = yield connector.connect();
609
685
  const template = routeURL(
@@ -617,27 +693,32 @@ function route(name, connector, ...rest) {
617
693
  };
618
694
  const methods = ["get", "post", "put", "delete", "patch"];
619
695
  for (const method of methods) {
620
- const methodResp = (requestOptions) => __async$3(this, null, function* () {
696
+ const methodResp = (requestOptions) => {
621
697
  var _b;
622
698
  const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
623
- const routeData = yield connector.connect();
624
- const template = routeURL(
625
- name,
626
- (_b = connector.options.baseUrl) != null ? _b : "",
627
- routeData,
628
- ...rest
629
- );
630
- const headers = objectRemoveEmpty(__spreadValues$3(__spreadValues$3({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
631
- return request(
632
- template,
633
- __spreadProps$2(__spreadValues$3({
634
- headers
635
- }, restOpt), {
636
- method
637
- }),
638
- connector.cache
639
- );
640
- });
699
+ if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
700
+ throw new AbortError();
701
+ }
702
+ return connector.connect().then((routeData) => {
703
+ var _a2;
704
+ const template = routeURL(
705
+ name,
706
+ (_a2 = connector.options.baseUrl) != null ? _a2 : "",
707
+ routeData,
708
+ ...rest
709
+ );
710
+ const headers = objectRemoveEmpty(__spreadValues$2(__spreadValues$2({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
711
+ return request(
712
+ template,
713
+ __spreadProps$2(__spreadValues$2({
714
+ headers
715
+ }, restOpt), {
716
+ method
717
+ }),
718
+ connector.cache
719
+ );
720
+ });
721
+ };
641
722
  result[method] = methodResp;
642
723
  }
643
724
  return result;
@@ -659,7 +740,7 @@ let loadData;
659
740
  const getResponseText = () => {
660
741
  try {
661
742
  return JSON.parse(xhr.responseText);
662
- } catch (er) {
743
+ } catch (e) {
663
744
  return xhr.responseText;
664
745
  }
665
746
  };
@@ -729,34 +810,45 @@ let loadData;
729
810
  };
730
811
  }
731
812
 
732
- const templateRe = /\{ *([\w_-]+) *\}/g;
733
- function template(str, data) {
734
- return str.replace(templateRe, (s, key) => {
735
- let value = data[key];
736
- if (value === void 0) {
737
- throw new Error("No value provided for letiable " + s);
738
- } else if (typeof value === "function") {
739
- value = value(data);
813
+ const CONNECTORS = [];
814
+ function addConnector(connector) {
815
+ CONNECTORS.push(connector);
816
+ }
817
+ function findConnector(options) {
818
+ return CONNECTORS.find((x) => {
819
+ if (x.options.baseUrl === options.baseUrl) {
820
+ if (options.auth) {
821
+ if (x.options.auth) {
822
+ return objectDeepEqual(x.options.auth, options.auth);
823
+ }
824
+ } else {
825
+ return true;
826
+ }
740
827
  }
741
- return value;
742
828
  });
743
829
  }
830
+ function removeConnector(connector) {
831
+ const index = CONNECTORS.indexOf(connector);
832
+ if (index !== -1) {
833
+ CONNECTORS.splice(index, 1);
834
+ }
835
+ }
744
836
 
745
- var __defProp$3 = Object.defineProperty;
837
+ var __defProp$2 = Object.defineProperty;
746
838
  var __defProps$1 = Object.defineProperties;
747
839
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
748
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
749
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
750
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
751
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
752
- var __spreadValues$2 = (a, b) => {
840
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
841
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
842
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
843
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
844
+ var __spreadValues$1 = (a, b) => {
753
845
  for (var prop in b || (b = {}))
754
- if (__hasOwnProp$2.call(b, prop))
755
- __defNormalProp$3(a, prop, b[prop]);
756
- if (__getOwnPropSymbols$2)
757
- for (var prop of __getOwnPropSymbols$2(b)) {
758
- if (__propIsEnum$2.call(b, prop))
759
- __defNormalProp$3(a, prop, b[prop]);
846
+ if (__hasOwnProp$1.call(b, prop))
847
+ __defNormalProp$2(a, prop, b[prop]);
848
+ if (__getOwnPropSymbols$1)
849
+ for (var prop of __getOwnPropSymbols$1(b)) {
850
+ if (__propIsEnum$1.call(b, prop))
851
+ __defNormalProp$2(a, prop, b[prop]);
760
852
  }
761
853
  return a;
762
854
  };
@@ -764,17 +856,17 @@ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
764
856
  var __objRest = (source, exclude) => {
765
857
  var target = {};
766
858
  for (var prop in source)
767
- if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
859
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
768
860
  target[prop] = source[prop];
769
- if (source != null && __getOwnPropSymbols$2)
770
- for (var prop of __getOwnPropSymbols$2(source)) {
771
- if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
861
+ if (source != null && __getOwnPropSymbols$1)
862
+ for (var prop of __getOwnPropSymbols$1(source)) {
863
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
772
864
  target[prop] = source[prop];
773
865
  }
774
866
  return target;
775
867
  };
776
- var __publicField$2 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
777
- var __async$2 = (__this, __arguments, generator) => {
868
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
869
+ var __async$1 = (__this, __arguments, generator) => {
778
870
  return new Promise((resolve, reject) => {
779
871
  var fulfilled = (value) => {
780
872
  try {
@@ -859,7 +951,9 @@ class NgwConnector {
859
951
  * ```
860
952
  */
861
953
  connect() {
862
- return __async$2(this, null, function* () {
954
+ return __async$1(this, arguments, function* ({
955
+ signal
956
+ } = {}) {
863
957
  const auth = this.options.auth;
864
958
  if (auth) {
865
959
  const { login, password } = auth;
@@ -868,11 +962,12 @@ class NgwConnector {
868
962
  }
869
963
  }
870
964
  const routeUrl = `${this.routeStr}?client=${this.client}`;
871
- return yield this.makeQuery(
965
+ return this.makeQuery(
872
966
  routeUrl,
873
967
  {},
874
968
  {
875
969
  cacheName: "route",
970
+ signal,
876
971
  cache: true,
877
972
  cacheProps: {
878
973
  id: this.id,
@@ -904,14 +999,14 @@ class NgwConnector {
904
999
  this.emitter.emit("logout");
905
1000
  }
906
1001
  getUserInfo(credentials, options) {
907
- return __async$2(this, null, function* () {
1002
+ return __async$1(this, null, function* () {
908
1003
  if (this.user && this.user.id) {
909
1004
  return this.user;
910
1005
  }
911
1006
  if (credentials) {
912
1007
  this.options.auth = credentials;
913
1008
  }
914
- const options_ = __spreadValues$2({
1009
+ const options_ = __spreadValues$1({
915
1010
  headers: this.getAuthorizationHeaders(credentials),
916
1011
  cache: true
917
1012
  }, options);
@@ -952,7 +1047,7 @@ class NgwConnector {
952
1047
  this.activeRequests = {};
953
1048
  }
954
1049
  getActiveApiRequests() {
955
- return __spreadValues$2({}, this.activeRequests);
1050
+ return __spreadValues$1({}, this.activeRequests);
956
1051
  }
957
1052
  route(name, ...rest) {
958
1053
  return route(name, this, ...rest);
@@ -964,7 +1059,7 @@ class NgwConnector {
964
1059
  * @param options - Request options
965
1060
  */
966
1061
  makeQuery(_0, _1) {
967
- return __async$2(this, arguments, function* (url, params, options = {}) {
1062
+ return __async$1(this, arguments, function* (url, params, options = {}) {
968
1063
  var _b;
969
1064
  url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
970
1065
  if (!url) {
@@ -975,7 +1070,7 @@ class NgwConnector {
975
1070
  url = template(url, restParams);
976
1071
  }
977
1072
  url = encodeURI(fixUrlStr(url));
978
- options = __spreadValues$2({ withCredentials: this.withCredentials }, options);
1073
+ options = __spreadValues$1({ withCredentials: this.withCredentials }, options);
979
1074
  const {
980
1075
  cache,
981
1076
  signal: externalSignal,
@@ -997,7 +1092,7 @@ class NgwConnector {
997
1092
  });
998
1093
  }
999
1094
  options.signal = internalSignal;
1000
- const createPromise = () => __async$2(this, null, function* () {
1095
+ const createPromise = () => __async$1(this, null, function* () {
1001
1096
  const id = REQUEST_ID++;
1002
1097
  this.activeRequests[id] = internalAbortController;
1003
1098
  try {
@@ -1007,7 +1102,7 @@ class NgwConnector {
1007
1102
  }
1008
1103
  });
1009
1104
  if (method === "GET") {
1010
- const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$2({}, objectRemoveEmpty({
1105
+ const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$1({}, objectRemoveEmpty({
1011
1106
  headers,
1012
1107
  withCredentials,
1013
1108
  responseType,
@@ -1030,7 +1125,7 @@ class NgwConnector {
1030
1125
  var _a;
1031
1126
  if (this.user) {
1032
1127
  options = options || {};
1033
- options.headers = __spreadValues$2(__spreadValues$2({}, this.getAuthorizationHeaders()), options.headers);
1128
+ options.headers = __spreadValues$1(__spreadValues$1({}, this.getAuthorizationHeaders()), options.headers);
1034
1129
  }
1035
1130
  if (this.requestTransform) {
1036
1131
  const [transUrl, transOptions] = this.requestTransform(url, options);
@@ -1061,7 +1156,7 @@ class NgwConnector {
1061
1156
  });
1062
1157
  }
1063
1158
  _login(credentials, options) {
1064
- return __async$2(this, null, function* () {
1159
+ return __async$1(this, null, function* () {
1065
1160
  try {
1066
1161
  const data = yield this.getUserInfo(credentials, options);
1067
1162
  this.user = data;
@@ -1119,27 +1214,27 @@ function resourceToQuery(resource, prefix = "") {
1119
1214
  return query;
1120
1215
  }
1121
1216
 
1122
- var __defProp$2 = Object.defineProperty;
1217
+ var __defProp$1 = Object.defineProperty;
1123
1218
  var __defProps = Object.defineProperties;
1124
1219
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1125
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1126
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1127
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1128
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1129
- var __spreadValues$1 = (a, b) => {
1220
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1221
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1222
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1223
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1224
+ var __spreadValues = (a, b) => {
1130
1225
  for (var prop in b || (b = {}))
1131
- if (__hasOwnProp$1.call(b, prop))
1132
- __defNormalProp$2(a, prop, b[prop]);
1133
- if (__getOwnPropSymbols$1)
1134
- for (var prop of __getOwnPropSymbols$1(b)) {
1135
- if (__propIsEnum$1.call(b, prop))
1136
- __defNormalProp$2(a, prop, b[prop]);
1226
+ if (__hasOwnProp.call(b, prop))
1227
+ __defNormalProp$1(a, prop, b[prop]);
1228
+ if (__getOwnPropSymbols)
1229
+ for (var prop of __getOwnPropSymbols(b)) {
1230
+ if (__propIsEnum.call(b, prop))
1231
+ __defNormalProp$1(a, prop, b[prop]);
1137
1232
  }
1138
1233
  return a;
1139
1234
  };
1140
1235
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1141
- var __publicField$1 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1142
- var __async$1 = (__this, __arguments, generator) => {
1236
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
1237
+ var __async = (__this, __arguments, generator) => {
1143
1238
  return new Promise((resolve, reject) => {
1144
1239
  var fulfilled = (value) => {
1145
1240
  try {
@@ -1180,7 +1275,7 @@ class ResourcesControl {
1180
1275
  * Fetching resource would be cached to speed up next call
1181
1276
  */
1182
1277
  getOne(resource, requestOptions) {
1183
- const opt = __spreadValues$1({}, requestOptions);
1278
+ const opt = __spreadValues({}, requestOptions);
1184
1279
  if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
1185
1280
  if (resource.id !== void 0) {
1186
1281
  resource.id;
@@ -1257,8 +1352,8 @@ class ResourcesControl {
1257
1352
  } else {
1258
1353
  Object.assign(query, resourceToQuery(resource));
1259
1354
  }
1260
- return this.connector.route("resource.search").get(__spreadProps(__spreadValues$1({}, requestOptions), {
1261
- query: __spreadValues$1({
1355
+ return this.connector.route("resource.search").get(__spreadProps(__spreadValues({}, requestOptions), {
1356
+ query: __spreadValues({
1262
1357
  serialization: "full"
1263
1358
  }, query)
1264
1359
  })).then((resources) => {
@@ -1311,7 +1406,7 @@ class ResourcesControl {
1311
1406
  });
1312
1407
  }
1313
1408
  _getChildrenOf(_0, _1) {
1314
- return __async$1(this, arguments, function* (parentDef, requestOptions, _items = []) {
1409
+ return __async(this, arguments, function* (parentDef, requestOptions, _items = []) {
1315
1410
  let parent = void 0;
1316
1411
  if (typeof parentDef === "string") {
1317
1412
  parent = yield this.getId(parentDef, requestOptions);
@@ -1320,7 +1415,7 @@ class ResourcesControl {
1320
1415
  } else {
1321
1416
  parent = parentDef;
1322
1417
  }
1323
- const items = yield this.connector.route("resource.collection").get(__spreadProps(__spreadValues$1({}, requestOptions), {
1418
+ const items = yield this.connector.route("resource.collection").get(__spreadProps(__spreadValues({}, requestOptions), {
1324
1419
  query: {
1325
1420
  parent
1326
1421
  }
@@ -1348,7 +1443,7 @@ class ResourcesControl {
1348
1443
  });
1349
1444
  }
1350
1445
  _cleanResourceItemCache(id) {
1351
- return __async$1(this, null, function* () {
1446
+ return __async(this, null, function* () {
1352
1447
  var _a;
1353
1448
  const all = this.cache.all();
1354
1449
  const toDelete = [];
@@ -1401,93 +1496,6 @@ class ResourcesControl {
1401
1496
  }
1402
1497
  }
1403
1498
 
1404
- var __defProp$1 = Object.defineProperty;
1405
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1406
- var __hasOwnProp = Object.prototype.hasOwnProperty;
1407
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
1408
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1409
- var __spreadValues = (a, b) => {
1410
- for (var prop in b || (b = {}))
1411
- if (__hasOwnProp.call(b, prop))
1412
- __defNormalProp$1(a, prop, b[prop]);
1413
- if (__getOwnPropSymbols)
1414
- for (var prop of __getOwnPropSymbols(b)) {
1415
- if (__propIsEnum.call(b, prop))
1416
- __defNormalProp$1(a, prop, b[prop]);
1417
- }
1418
- return a;
1419
- };
1420
- var __async = (__this, __arguments, generator) => {
1421
- return new Promise((resolve, reject) => {
1422
- var fulfilled = (value) => {
1423
- try {
1424
- step(generator.next(value));
1425
- } catch (e) {
1426
- reject(e);
1427
- }
1428
- };
1429
- var rejected = (value) => {
1430
- try {
1431
- step(generator.throw(value));
1432
- } catch (e) {
1433
- reject(e);
1434
- }
1435
- };
1436
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1437
- step((generator = generator.apply(__this, __arguments)).next());
1438
- });
1439
- };
1440
- function apiRequest(opt) {
1441
- return __async(this, null, function* () {
1442
- const { params, name, connector, requestOptions } = opt;
1443
- const apiItems = yield connector.connect();
1444
- let apiItem = apiItems && apiItems[name];
1445
- if (apiItem) {
1446
- apiItem = [...apiItem];
1447
- let url = apiItem.shift();
1448
- if (apiItem.length) {
1449
- const replaceParams = {};
1450
- for (let fry = 0; fry < apiItem.length; fry++) {
1451
- const arg = apiItem[fry];
1452
- replaceParams[fry] = `{${arg}}`;
1453
- if (params[arg] === void 0) {
1454
- throw new Error(`\`${arg}\` URL API argument is not specified`);
1455
- }
1456
- }
1457
- if (url) {
1458
- url = template(url, replaceParams);
1459
- }
1460
- }
1461
- if (params) {
1462
- const paramArray = [];
1463
- const paramList = params.paramList;
1464
- if (Array.isArray(paramList)) {
1465
- paramList.forEach(([key, value]) => {
1466
- paramArray.push(`${key}=${value}`);
1467
- });
1468
- }
1469
- for (const p in params) {
1470
- if (apiItem.indexOf(p) === -1) {
1471
- paramArray.push(`${p}=${params[p]}`);
1472
- }
1473
- }
1474
- if (paramArray.length) {
1475
- url = `${url}?${paramArray.join("&")}`;
1476
- }
1477
- }
1478
- if (url) {
1479
- return connector.makeQuery(url, params, __spreadValues({
1480
- cacheName: name
1481
- }, requestOptions));
1482
- } else {
1483
- throw new Error("Request URL is not set");
1484
- }
1485
- } else {
1486
- return void 0;
1487
- }
1488
- });
1489
- }
1490
-
1491
1499
  var __defProp = Object.defineProperty;
1492
1500
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1493
1501
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);