@nextgis/ngw-connector 1.16.1 → 1.16.2

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.2; author: NextGIS */
2
2
  var NgwConnector = (function () {
3
3
  'use strict';
4
4
 
@@ -1370,6 +1370,65 @@ var NgwConnector = (function () {
1370
1370
  });
1371
1371
  }
1372
1372
 
1373
+ function apiRequest(opt) {
1374
+ var params = opt.params;
1375
+ return new CancelablePromise(function (resolve, reject) {
1376
+ opt.connector
1377
+ .connect()
1378
+ .then(function (apiItems) {
1379
+ var apiItem = apiItems && apiItems[opt.name];
1380
+ if (apiItem) {
1381
+ apiItem = __spreadArray([], apiItem, true);
1382
+ var url = apiItem.shift();
1383
+ if (apiItem.length) {
1384
+ var replaceParams = {};
1385
+ for (var fry = 0; fry < apiItem.length; fry++) {
1386
+ var arg = apiItem[fry];
1387
+ replaceParams[fry] = '{' + arg + '}';
1388
+ if (params[arg] === undefined) {
1389
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
1390
+ }
1391
+ }
1392
+ if (url) {
1393
+ url = template(url, replaceParams);
1394
+ }
1395
+ }
1396
+ // Transfer part of the parameters from `params` to the URL string
1397
+ if (params) {
1398
+ var paramArray_1 = [];
1399
+ var paramList = params.paramList;
1400
+ if (Array.isArray(paramList)) {
1401
+ delete params.paramList;
1402
+ paramList.forEach(function (x) {
1403
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1404
+ });
1405
+ }
1406
+ for (var p in params) {
1407
+ if (apiItem.indexOf(p) === -1) {
1408
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
1409
+ }
1410
+ }
1411
+ if (paramArray_1.length) {
1412
+ url = url + '?' + paramArray_1.join('&');
1413
+ }
1414
+ }
1415
+ if (url) {
1416
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1417
+ }
1418
+ else {
1419
+ reject(new Error('request url is not set'));
1420
+ }
1421
+ }
1422
+ else {
1423
+ resolve(undefined);
1424
+ }
1425
+ })
1426
+ .catch(function (er) {
1427
+ reject(er);
1428
+ });
1429
+ });
1430
+ }
1431
+
1373
1432
  /**
1374
1433
  * Thrown when ...
1375
1434
  */
@@ -1735,65 +1794,6 @@ var NgwConnector = (function () {
1735
1794
  return ResourcesControl;
1736
1795
  }());
1737
1796
 
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
1797
  var ID = 0;
1798
1798
  var NgwConnector$1 = /** @class */ (function () {
1799
1799
  function NgwConnector(options) {
@@ -1864,9 +1864,9 @@ var NgwConnector = (function () {
1864
1864
  if (auth) {
1865
1865
  var login = auth.login, password = auth.password;
1866
1866
  if (login && password) {
1867
- return _this.getUserInfo({ login: login, password: password })
1867
+ return _this._login({ login: login, password: password })
1868
1868
  .then(function () {
1869
- makeQuery();
1869
+ return makeQuery();
1870
1870
  })
1871
1871
  .catch(function (er) { return reject(er); });
1872
1872
  }
@@ -1884,10 +1884,10 @@ var NgwConnector = (function () {
1884
1884
  * Quick way to change NextGIS Web user.
1885
1885
  * @param credentials - New user credentials
1886
1886
  */
1887
- NgwConnector.prototype.login = function (credentials) {
1887
+ NgwConnector.prototype.login = function (credentials, options) {
1888
1888
  this.logout();
1889
1889
  addConnector(this);
1890
- return this.getUserInfo(credentials);
1890
+ return this._login(credentials, options);
1891
1891
  };
1892
1892
  /**
1893
1893
  * Disconnecting a user. Aborting all current requests
@@ -1900,29 +1900,16 @@ var NgwConnector = (function () {
1900
1900
  this.emitter.emit('logout');
1901
1901
  this.resources.cache.clean();
1902
1902
  };
1903
- NgwConnector.prototype.getUserInfo = function (credentials) {
1904
- var _this = this;
1903
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
1905
1904
  if (this.user && this.user.id) {
1906
1905
  return CancelablePromise.resolve(this.user);
1907
1906
  }
1908
1907
  if (credentials) {
1909
1908
  this.options.auth = credentials;
1910
1909
  }
1911
- var options = {
1912
- headers: this.getAuthorizationHeaders(credentials),
1913
- // withCredentials: true
1914
- };
1910
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
1915
1911
  // 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
- });
1912
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
1926
1913
  };
1927
1914
  /**
1928
1915
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -1988,6 +1975,7 @@ var NgwConnector = (function () {
1988
1975
  */
1989
1976
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
1990
1977
  var _this = this;
1978
+ var _a;
1991
1979
  if (params_ === void 0) { params_ = {}; }
1992
1980
  if (requestOptions === void 0) { requestOptions = {}; }
1993
1981
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -2002,7 +1990,7 @@ var NgwConnector = (function () {
2002
1990
  withCredentials: withCredentials,
2003
1991
  responseType: responseType,
2004
1992
  baseUrl: this.options.baseUrl,
2005
- auth: this.options.auth,
1993
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
2006
1994
  })));
2007
1995
  }
2008
1996
  return makeApiRequest();
@@ -2211,6 +2199,19 @@ var NgwConnector = (function () {
2211
2199
  this.activeRequests.push(request);
2212
2200
  return request;
2213
2201
  };
2202
+ NgwConnector.prototype._login = function (credentials, options) {
2203
+ var _this = this;
2204
+ return this.getUserInfo(credentials, options)
2205
+ .then(function (data) {
2206
+ _this.user = data;
2207
+ _this.emitter.emit('login', data);
2208
+ return data;
2209
+ })
2210
+ .catch(function (er) {
2211
+ _this.emitter.emit('login:error', er);
2212
+ throw er;
2213
+ });
2214
+ };
2214
2215
  NgwConnector.prototype._cleanActiveRequests = function (request) {
2215
2216
  var activeRequestIndex = this.activeRequests.indexOf(request);
2216
2217
  if (activeRequestIndex !== -1) {