@nextgis/geocoder 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/geocoder; version: 1.16.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.16.2; author: NextGIS */
2
2
  import CancelablePromise from '@nextgis/cancelable-promise';
3
3
  import { objectAssign, fixUrlStr } from '@nextgis/utils';
4
4
  import NgwConnector from '@nextgis/ngw-connector';
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 1.16.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.16.2; author: NextGIS */
2
2
  var Geocoder = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -1530,6 +1530,65 @@ var Geocoder = (function (exports) {
1530
1530
  });
1531
1531
  }
1532
1532
 
1533
+ function apiRequest(opt) {
1534
+ var params = opt.params;
1535
+ return new CancelablePromise(function (resolve, reject) {
1536
+ opt.connector
1537
+ .connect()
1538
+ .then(function (apiItems) {
1539
+ var apiItem = apiItems && apiItems[opt.name];
1540
+ if (apiItem) {
1541
+ apiItem = __spreadArray([], apiItem, true);
1542
+ var url = apiItem.shift();
1543
+ if (apiItem.length) {
1544
+ var replaceParams = {};
1545
+ for (var fry = 0; fry < apiItem.length; fry++) {
1546
+ var arg = apiItem[fry];
1547
+ replaceParams[fry] = '{' + arg + '}';
1548
+ if (params[arg] === undefined) {
1549
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
1550
+ }
1551
+ }
1552
+ if (url) {
1553
+ url = template(url, replaceParams);
1554
+ }
1555
+ }
1556
+ // Transfer part of the parameters from `params` to the URL string
1557
+ if (params) {
1558
+ var paramArray_1 = [];
1559
+ var paramList = params.paramList;
1560
+ if (Array.isArray(paramList)) {
1561
+ delete params.paramList;
1562
+ paramList.forEach(function (x) {
1563
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1564
+ });
1565
+ }
1566
+ for (var p in params) {
1567
+ if (apiItem.indexOf(p) === -1) {
1568
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
1569
+ }
1570
+ }
1571
+ if (paramArray_1.length) {
1572
+ url = url + '?' + paramArray_1.join('&');
1573
+ }
1574
+ }
1575
+ if (url) {
1576
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1577
+ }
1578
+ else {
1579
+ reject(new Error('request url is not set'));
1580
+ }
1581
+ }
1582
+ else {
1583
+ resolve(undefined);
1584
+ }
1585
+ })
1586
+ .catch(function (er) {
1587
+ reject(er);
1588
+ });
1589
+ });
1590
+ }
1591
+
1533
1592
  /**
1534
1593
  * Thrown when ...
1535
1594
  */
@@ -1895,65 +1954,6 @@ var Geocoder = (function (exports) {
1895
1954
  return ResourcesControl;
1896
1955
  }());
1897
1956
 
1898
- function apiRequest(opt) {
1899
- var params = opt.params;
1900
- return new CancelablePromise(function (resolve, reject) {
1901
- opt.connector
1902
- .connect()
1903
- .then(function (apiItems) {
1904
- var apiItem = apiItems && apiItems[opt.name];
1905
- if (apiItem) {
1906
- apiItem = __spreadArray([], apiItem, true);
1907
- var url = apiItem.shift();
1908
- if (apiItem.length) {
1909
- var replaceParams = {};
1910
- for (var fry = 0; fry < apiItem.length; fry++) {
1911
- var arg = apiItem[fry];
1912
- replaceParams[fry] = '{' + arg + '}';
1913
- if (params[arg] === undefined) {
1914
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
1915
- }
1916
- }
1917
- if (url) {
1918
- url = template(url, replaceParams);
1919
- }
1920
- }
1921
- // Transfer part of the parameters from `params` to the URL string
1922
- if (params) {
1923
- var paramArray_1 = [];
1924
- var paramList = params.paramList;
1925
- if (Array.isArray(paramList)) {
1926
- delete params.paramList;
1927
- paramList.forEach(function (x) {
1928
- paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1929
- });
1930
- }
1931
- for (var p in params) {
1932
- if (apiItem.indexOf(p) === -1) {
1933
- paramArray_1.push("".concat(p, "=").concat(params[p]));
1934
- }
1935
- }
1936
- if (paramArray_1.length) {
1937
- url = url + '?' + paramArray_1.join('&');
1938
- }
1939
- }
1940
- if (url) {
1941
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1942
- }
1943
- else {
1944
- reject(new Error('request url is not set'));
1945
- }
1946
- }
1947
- else {
1948
- resolve(undefined);
1949
- }
1950
- })
1951
- .catch(function (er) {
1952
- reject(er);
1953
- });
1954
- });
1955
- }
1956
-
1957
1957
  var ID = 0;
1958
1958
  var NgwConnector$1 = /** @class */ (function () {
1959
1959
  function NgwConnector(options) {
@@ -2024,9 +2024,9 @@ var Geocoder = (function (exports) {
2024
2024
  if (auth) {
2025
2025
  var login = auth.login, password = auth.password;
2026
2026
  if (login && password) {
2027
- return _this.getUserInfo({ login: login, password: password })
2027
+ return _this._login({ login: login, password: password })
2028
2028
  .then(function () {
2029
- makeQuery();
2029
+ return makeQuery();
2030
2030
  })
2031
2031
  .catch(function (er) { return reject(er); });
2032
2032
  }
@@ -2044,10 +2044,10 @@ var Geocoder = (function (exports) {
2044
2044
  * Quick way to change NextGIS Web user.
2045
2045
  * @param credentials - New user credentials
2046
2046
  */
2047
- NgwConnector.prototype.login = function (credentials) {
2047
+ NgwConnector.prototype.login = function (credentials, options) {
2048
2048
  this.logout();
2049
2049
  addConnector(this);
2050
- return this.getUserInfo(credentials);
2050
+ return this._login(credentials, options);
2051
2051
  };
2052
2052
  /**
2053
2053
  * Disconnecting a user. Aborting all current requests
@@ -2060,29 +2060,16 @@ var Geocoder = (function (exports) {
2060
2060
  this.emitter.emit('logout');
2061
2061
  this.resources.cache.clean();
2062
2062
  };
2063
- NgwConnector.prototype.getUserInfo = function (credentials) {
2064
- var _this = this;
2063
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
2065
2064
  if (this.user && this.user.id) {
2066
2065
  return CancelablePromise.resolve(this.user);
2067
2066
  }
2068
2067
  if (credentials) {
2069
2068
  this.options.auth = credentials;
2070
2069
  }
2071
- var options = {
2072
- headers: this.getAuthorizationHeaders(credentials),
2073
- // withCredentials: true
2074
- };
2070
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
2075
2071
  // Do not use apiRequest('auth.current_user') to avoid circular-references
2076
- return this.makeQuery('/api/component/auth/current_user', {}, options)
2077
- .then(function (data) {
2078
- _this.user = data;
2079
- _this.emitter.emit('login', data);
2080
- return data;
2081
- })
2082
- .catch(function (er) {
2083
- _this.emitter.emit('login:error', er);
2084
- throw er;
2085
- });
2072
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
2086
2073
  };
2087
2074
  /**
2088
2075
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -2148,6 +2135,7 @@ var Geocoder = (function (exports) {
2148
2135
  */
2149
2136
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
2150
2137
  var _this = this;
2138
+ var _a;
2151
2139
  if (params_ === void 0) { params_ = {}; }
2152
2140
  if (requestOptions === void 0) { requestOptions = {}; }
2153
2141
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -2162,7 +2150,7 @@ var Geocoder = (function (exports) {
2162
2150
  withCredentials: withCredentials,
2163
2151
  responseType: responseType,
2164
2152
  baseUrl: this.options.baseUrl,
2165
- auth: this.options.auth,
2153
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
2166
2154
  })));
2167
2155
  }
2168
2156
  return makeApiRequest();
@@ -2371,6 +2359,19 @@ var Geocoder = (function (exports) {
2371
2359
  this.activeRequests.push(request);
2372
2360
  return request;
2373
2361
  };
2362
+ NgwConnector.prototype._login = function (credentials, options) {
2363
+ var _this = this;
2364
+ return this.getUserInfo(credentials, options)
2365
+ .then(function (data) {
2366
+ _this.user = data;
2367
+ _this.emitter.emit('login', data);
2368
+ return data;
2369
+ })
2370
+ .catch(function (er) {
2371
+ _this.emitter.emit('login:error', er);
2372
+ throw er;
2373
+ });
2374
+ };
2374
2375
  NgwConnector.prototype._cleanActiveRequests = function (request) {
2375
2376
  var activeRequestIndex = this.activeRequests.indexOf(request);
2376
2377
  if (activeRequestIndex !== -1) {