@nextgis/ngw-connector 1.16.1 → 1.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-connector; version: 1.16.1; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 1.16.5; author: NextGIS */
2
2
  /******************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -803,8 +803,9 @@ var CancelablePromise$1 = /** @class */ (function () {
803
803
  if (er instanceof _this.CancelError) {
804
804
  for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
805
805
  var v = values_1[_i];
806
- if ('cancel' in v) {
807
- v.cancel();
806
+ var v_ = v;
807
+ if ('cancel' in v_) {
808
+ v_.cancel();
808
809
  }
809
810
  }
810
811
  }
@@ -1367,6 +1368,65 @@ function template(str, data) {
1367
1368
  });
1368
1369
  }
1369
1370
 
1371
+ function apiRequest(opt) {
1372
+ var params = opt.params;
1373
+ return new CancelablePromise(function (resolve, reject) {
1374
+ opt.connector
1375
+ .connect()
1376
+ .then(function (apiItems) {
1377
+ var apiItem = apiItems && apiItems[opt.name];
1378
+ if (apiItem) {
1379
+ apiItem = __spreadArray([], apiItem, true);
1380
+ var url = apiItem.shift();
1381
+ if (apiItem.length) {
1382
+ var replaceParams = {};
1383
+ for (var fry = 0; fry < apiItem.length; fry++) {
1384
+ var arg = apiItem[fry];
1385
+ replaceParams[fry] = '{' + arg + '}';
1386
+ if (params[arg] === undefined) {
1387
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
1388
+ }
1389
+ }
1390
+ if (url) {
1391
+ url = template(url, replaceParams);
1392
+ }
1393
+ }
1394
+ // Transfer part of the parameters from `params` to the URL string
1395
+ if (params) {
1396
+ var paramArray_1 = [];
1397
+ var paramList = params.paramList;
1398
+ if (Array.isArray(paramList)) {
1399
+ delete params.paramList;
1400
+ paramList.forEach(function (x) {
1401
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1402
+ });
1403
+ }
1404
+ for (var p in params) {
1405
+ if (apiItem.indexOf(p) === -1) {
1406
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
1407
+ }
1408
+ }
1409
+ if (paramArray_1.length) {
1410
+ url = url + '?' + paramArray_1.join('&');
1411
+ }
1412
+ }
1413
+ if (url) {
1414
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1415
+ }
1416
+ else {
1417
+ reject(new Error('request url is not set'));
1418
+ }
1419
+ }
1420
+ else {
1421
+ resolve(undefined);
1422
+ }
1423
+ })
1424
+ .catch(function (er) {
1425
+ reject(er);
1426
+ });
1427
+ });
1428
+ }
1429
+
1370
1430
  /**
1371
1431
  * Thrown when ...
1372
1432
  */
@@ -1732,65 +1792,6 @@ var ResourcesControl = /** @class */ (function () {
1732
1792
  return ResourcesControl;
1733
1793
  }());
1734
1794
 
1735
- function apiRequest(opt) {
1736
- var params = opt.params;
1737
- return new CancelablePromise(function (resolve, reject) {
1738
- opt.connector
1739
- .connect()
1740
- .then(function (apiItems) {
1741
- var apiItem = apiItems && apiItems[opt.name];
1742
- if (apiItem) {
1743
- apiItem = __spreadArray([], apiItem, true);
1744
- var url = apiItem.shift();
1745
- if (apiItem.length) {
1746
- var replaceParams = {};
1747
- for (var fry = 0; fry < apiItem.length; fry++) {
1748
- var arg = apiItem[fry];
1749
- replaceParams[fry] = '{' + arg + '}';
1750
- if (params[arg] === undefined) {
1751
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
1752
- }
1753
- }
1754
- if (url) {
1755
- url = template(url, replaceParams);
1756
- }
1757
- }
1758
- // Transfer part of the parameters from `params` to the URL string
1759
- if (params) {
1760
- var paramArray_1 = [];
1761
- var paramList = params.paramList;
1762
- if (Array.isArray(paramList)) {
1763
- delete params.paramList;
1764
- paramList.forEach(function (x) {
1765
- paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1766
- });
1767
- }
1768
- for (var p in params) {
1769
- if (apiItem.indexOf(p) === -1) {
1770
- paramArray_1.push("".concat(p, "=").concat(params[p]));
1771
- }
1772
- }
1773
- if (paramArray_1.length) {
1774
- url = url + '?' + paramArray_1.join('&');
1775
- }
1776
- }
1777
- if (url) {
1778
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1779
- }
1780
- else {
1781
- reject(new Error('request url is not set'));
1782
- }
1783
- }
1784
- else {
1785
- resolve(undefined);
1786
- }
1787
- })
1788
- .catch(function (er) {
1789
- reject(er);
1790
- });
1791
- });
1792
- }
1793
-
1794
1795
  var ID = 0;
1795
1796
  var NgwConnector$1 = /** @class */ (function () {
1796
1797
  function NgwConnector(options) {
@@ -1861,9 +1862,9 @@ var NgwConnector$1 = /** @class */ (function () {
1861
1862
  if (auth) {
1862
1863
  var login = auth.login, password = auth.password;
1863
1864
  if (login && password) {
1864
- return _this.getUserInfo({ login: login, password: password })
1865
+ return _this._login({ login: login, password: password })
1865
1866
  .then(function () {
1866
- makeQuery();
1867
+ return makeQuery();
1867
1868
  })
1868
1869
  .catch(function (er) { return reject(er); });
1869
1870
  }
@@ -1881,10 +1882,10 @@ var NgwConnector$1 = /** @class */ (function () {
1881
1882
  * Quick way to change NextGIS Web user.
1882
1883
  * @param credentials - New user credentials
1883
1884
  */
1884
- NgwConnector.prototype.login = function (credentials) {
1885
+ NgwConnector.prototype.login = function (credentials, options) {
1885
1886
  this.logout();
1886
1887
  addConnector(this);
1887
- return this.getUserInfo(credentials);
1888
+ return this._login(credentials, options);
1888
1889
  };
1889
1890
  /**
1890
1891
  * Disconnecting a user. Aborting all current requests
@@ -1897,29 +1898,16 @@ var NgwConnector$1 = /** @class */ (function () {
1897
1898
  this.emitter.emit('logout');
1898
1899
  this.resources.cache.clean();
1899
1900
  };
1900
- NgwConnector.prototype.getUserInfo = function (credentials) {
1901
- var _this = this;
1901
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
1902
1902
  if (this.user && this.user.id) {
1903
1903
  return CancelablePromise.resolve(this.user);
1904
1904
  }
1905
1905
  if (credentials) {
1906
1906
  this.options.auth = credentials;
1907
1907
  }
1908
- var options = {
1909
- headers: this.getAuthorizationHeaders(credentials),
1910
- // withCredentials: true
1911
- };
1908
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
1912
1909
  // Do not use apiRequest('auth.current_user') to avoid circular-references
1913
- return this.makeQuery('/api/component/auth/current_user', {}, options)
1914
- .then(function (data) {
1915
- _this.user = data;
1916
- _this.emitter.emit('login', data);
1917
- return data;
1918
- })
1919
- .catch(function (er) {
1920
- _this.emitter.emit('login:error', er);
1921
- throw er;
1922
- });
1910
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
1923
1911
  };
1924
1912
  /**
1925
1913
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -1985,6 +1973,7 @@ var NgwConnector$1 = /** @class */ (function () {
1985
1973
  */
1986
1974
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
1987
1975
  var _this = this;
1976
+ var _a;
1988
1977
  if (params_ === void 0) { params_ = {}; }
1989
1978
  if (requestOptions === void 0) { requestOptions = {}; }
1990
1979
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -1999,7 +1988,7 @@ var NgwConnector$1 = /** @class */ (function () {
1999
1988
  withCredentials: withCredentials,
2000
1989
  responseType: responseType,
2001
1990
  baseUrl: this.options.baseUrl,
2002
- auth: this.options.auth,
1991
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
2003
1992
  })));
2004
1993
  }
2005
1994
  return makeApiRequest();
@@ -2208,6 +2197,19 @@ var NgwConnector$1 = /** @class */ (function () {
2208
2197
  this.activeRequests.push(request);
2209
2198
  return request;
2210
2199
  };
2200
+ NgwConnector.prototype._login = function (credentials, options) {
2201
+ var _this = this;
2202
+ return this.getUserInfo(credentials, options)
2203
+ .then(function (data) {
2204
+ _this.user = data;
2205
+ _this.emitter.emit('login', data);
2206
+ return data;
2207
+ })
2208
+ .catch(function (er) {
2209
+ _this.emitter.emit('login:error', er);
2210
+ throw er;
2211
+ });
2212
+ };
2211
2213
  NgwConnector.prototype._cleanActiveRequests = function (request) {
2212
2214
  var activeRequestIndex = this.activeRequests.indexOf(request);
2213
2215
  if (activeRequestIndex !== -1) {