@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
  var NgwConnector = (function () {
3
3
  'use strict';
4
4
 
@@ -806,8 +806,9 @@ var NgwConnector = (function () {
806
806
  if (er instanceof _this.CancelError) {
807
807
  for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
808
808
  var v = values_1[_i];
809
- if ('cancel' in v) {
810
- v.cancel();
809
+ var v_ = v;
810
+ if ('cancel' in v_) {
811
+ v_.cancel();
811
812
  }
812
813
  }
813
814
  }
@@ -1370,6 +1371,65 @@ var NgwConnector = (function () {
1370
1371
  });
1371
1372
  }
1372
1373
 
1374
+ function apiRequest(opt) {
1375
+ var params = opt.params;
1376
+ return new CancelablePromise(function (resolve, reject) {
1377
+ opt.connector
1378
+ .connect()
1379
+ .then(function (apiItems) {
1380
+ var apiItem = apiItems && apiItems[opt.name];
1381
+ if (apiItem) {
1382
+ apiItem = __spreadArray([], apiItem, true);
1383
+ var url = apiItem.shift();
1384
+ if (apiItem.length) {
1385
+ var replaceParams = {};
1386
+ for (var fry = 0; fry < apiItem.length; fry++) {
1387
+ var arg = apiItem[fry];
1388
+ replaceParams[fry] = '{' + arg + '}';
1389
+ if (params[arg] === undefined) {
1390
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
1391
+ }
1392
+ }
1393
+ if (url) {
1394
+ url = template(url, replaceParams);
1395
+ }
1396
+ }
1397
+ // Transfer part of the parameters from `params` to the URL string
1398
+ if (params) {
1399
+ var paramArray_1 = [];
1400
+ var paramList = params.paramList;
1401
+ if (Array.isArray(paramList)) {
1402
+ delete params.paramList;
1403
+ paramList.forEach(function (x) {
1404
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1405
+ });
1406
+ }
1407
+ for (var p in params) {
1408
+ if (apiItem.indexOf(p) === -1) {
1409
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
1410
+ }
1411
+ }
1412
+ if (paramArray_1.length) {
1413
+ url = url + '?' + paramArray_1.join('&');
1414
+ }
1415
+ }
1416
+ if (url) {
1417
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1418
+ }
1419
+ else {
1420
+ reject(new Error('request url is not set'));
1421
+ }
1422
+ }
1423
+ else {
1424
+ resolve(undefined);
1425
+ }
1426
+ })
1427
+ .catch(function (er) {
1428
+ reject(er);
1429
+ });
1430
+ });
1431
+ }
1432
+
1373
1433
  /**
1374
1434
  * Thrown when ...
1375
1435
  */
@@ -1735,65 +1795,6 @@ var NgwConnector = (function () {
1735
1795
  return ResourcesControl;
1736
1796
  }());
1737
1797
 
1738
- function apiRequest(opt) {
1739
- var params = opt.params;
1740
- return new CancelablePromise(function (resolve, reject) {
1741
- opt.connector
1742
- .connect()
1743
- .then(function (apiItems) {
1744
- var apiItem = apiItems && apiItems[opt.name];
1745
- if (apiItem) {
1746
- apiItem = __spreadArray([], apiItem, true);
1747
- var url = apiItem.shift();
1748
- if (apiItem.length) {
1749
- var replaceParams = {};
1750
- for (var fry = 0; fry < apiItem.length; fry++) {
1751
- var arg = apiItem[fry];
1752
- replaceParams[fry] = '{' + arg + '}';
1753
- if (params[arg] === undefined) {
1754
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
1755
- }
1756
- }
1757
- if (url) {
1758
- url = template(url, replaceParams);
1759
- }
1760
- }
1761
- // Transfer part of the parameters from `params` to the URL string
1762
- if (params) {
1763
- var paramArray_1 = [];
1764
- var paramList = params.paramList;
1765
- if (Array.isArray(paramList)) {
1766
- delete params.paramList;
1767
- paramList.forEach(function (x) {
1768
- paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1769
- });
1770
- }
1771
- for (var p in params) {
1772
- if (apiItem.indexOf(p) === -1) {
1773
- paramArray_1.push("".concat(p, "=").concat(params[p]));
1774
- }
1775
- }
1776
- if (paramArray_1.length) {
1777
- url = url + '?' + paramArray_1.join('&');
1778
- }
1779
- }
1780
- if (url) {
1781
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1782
- }
1783
- else {
1784
- reject(new Error('request url is not set'));
1785
- }
1786
- }
1787
- else {
1788
- resolve(undefined);
1789
- }
1790
- })
1791
- .catch(function (er) {
1792
- reject(er);
1793
- });
1794
- });
1795
- }
1796
-
1797
1798
  var ID = 0;
1798
1799
  var NgwConnector$1 = /** @class */ (function () {
1799
1800
  function NgwConnector(options) {
@@ -1864,9 +1865,9 @@ var NgwConnector = (function () {
1864
1865
  if (auth) {
1865
1866
  var login = auth.login, password = auth.password;
1866
1867
  if (login && password) {
1867
- return _this.getUserInfo({ login: login, password: password })
1868
+ return _this._login({ login: login, password: password })
1868
1869
  .then(function () {
1869
- makeQuery();
1870
+ return makeQuery();
1870
1871
  })
1871
1872
  .catch(function (er) { return reject(er); });
1872
1873
  }
@@ -1884,10 +1885,10 @@ var NgwConnector = (function () {
1884
1885
  * Quick way to change NextGIS Web user.
1885
1886
  * @param credentials - New user credentials
1886
1887
  */
1887
- NgwConnector.prototype.login = function (credentials) {
1888
+ NgwConnector.prototype.login = function (credentials, options) {
1888
1889
  this.logout();
1889
1890
  addConnector(this);
1890
- return this.getUserInfo(credentials);
1891
+ return this._login(credentials, options);
1891
1892
  };
1892
1893
  /**
1893
1894
  * Disconnecting a user. Aborting all current requests
@@ -1900,29 +1901,16 @@ var NgwConnector = (function () {
1900
1901
  this.emitter.emit('logout');
1901
1902
  this.resources.cache.clean();
1902
1903
  };
1903
- NgwConnector.prototype.getUserInfo = function (credentials) {
1904
- var _this = this;
1904
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
1905
1905
  if (this.user && this.user.id) {
1906
1906
  return CancelablePromise.resolve(this.user);
1907
1907
  }
1908
1908
  if (credentials) {
1909
1909
  this.options.auth = credentials;
1910
1910
  }
1911
- var options = {
1912
- headers: this.getAuthorizationHeaders(credentials),
1913
- // withCredentials: true
1914
- };
1911
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
1915
1912
  // Do not use apiRequest('auth.current_user') to avoid circular-references
1916
- return this.makeQuery('/api/component/auth/current_user', {}, options)
1917
- .then(function (data) {
1918
- _this.user = data;
1919
- _this.emitter.emit('login', data);
1920
- return data;
1921
- })
1922
- .catch(function (er) {
1923
- _this.emitter.emit('login:error', er);
1924
- throw er;
1925
- });
1913
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
1926
1914
  };
1927
1915
  /**
1928
1916
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -1988,6 +1976,7 @@ var NgwConnector = (function () {
1988
1976
  */
1989
1977
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
1990
1978
  var _this = this;
1979
+ var _a;
1991
1980
  if (params_ === void 0) { params_ = {}; }
1992
1981
  if (requestOptions === void 0) { requestOptions = {}; }
1993
1982
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -2002,7 +1991,7 @@ var NgwConnector = (function () {
2002
1991
  withCredentials: withCredentials,
2003
1992
  responseType: responseType,
2004
1993
  baseUrl: this.options.baseUrl,
2005
- auth: this.options.auth,
1994
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
2006
1995
  })));
2007
1996
  }
2008
1997
  return makeApiRequest();
@@ -2211,6 +2200,19 @@ var NgwConnector = (function () {
2211
2200
  this.activeRequests.push(request);
2212
2201
  return request;
2213
2202
  };
2203
+ NgwConnector.prototype._login = function (credentials, options) {
2204
+ var _this = this;
2205
+ return this.getUserInfo(credentials, options)
2206
+ .then(function (data) {
2207
+ _this.user = data;
2208
+ _this.emitter.emit('login', data);
2209
+ return data;
2210
+ })
2211
+ .catch(function (er) {
2212
+ _this.emitter.emit('login:error', er);
2213
+ throw er;
2214
+ });
2215
+ };
2214
2216
  NgwConnector.prototype._cleanActiveRequests = function (request) {
2215
2217
  var activeRequestIndex = this.activeRequests.indexOf(request);
2216
2218
  if (activeRequestIndex !== -1) {