@nextgis/geocoder 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/geocoder; version: 1.16.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.16.5; 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.5; author: NextGIS */
2
2
  var Geocoder = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -366,8 +366,9 @@ var Geocoder = (function (exports) {
366
366
  if (er instanceof _this.CancelError) {
367
367
  for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
368
368
  var v = values_1[_i];
369
- if ('cancel' in v) {
370
- v.cancel();
369
+ var v_ = v;
370
+ if ('cancel' in v_) {
371
+ v_.cancel();
371
372
  }
372
373
  }
373
374
  }
@@ -1530,6 +1531,65 @@ var Geocoder = (function (exports) {
1530
1531
  });
1531
1532
  }
1532
1533
 
1534
+ function apiRequest(opt) {
1535
+ var params = opt.params;
1536
+ return new CancelablePromise(function (resolve, reject) {
1537
+ opt.connector
1538
+ .connect()
1539
+ .then(function (apiItems) {
1540
+ var apiItem = apiItems && apiItems[opt.name];
1541
+ if (apiItem) {
1542
+ apiItem = __spreadArray([], apiItem, true);
1543
+ var url = apiItem.shift();
1544
+ if (apiItem.length) {
1545
+ var replaceParams = {};
1546
+ for (var fry = 0; fry < apiItem.length; fry++) {
1547
+ var arg = apiItem[fry];
1548
+ replaceParams[fry] = '{' + arg + '}';
1549
+ if (params[arg] === undefined) {
1550
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
1551
+ }
1552
+ }
1553
+ if (url) {
1554
+ url = template(url, replaceParams);
1555
+ }
1556
+ }
1557
+ // Transfer part of the parameters from `params` to the URL string
1558
+ if (params) {
1559
+ var paramArray_1 = [];
1560
+ var paramList = params.paramList;
1561
+ if (Array.isArray(paramList)) {
1562
+ delete params.paramList;
1563
+ paramList.forEach(function (x) {
1564
+ paramArray_1.push("".concat(x[0], "=").concat(x[1]));
1565
+ });
1566
+ }
1567
+ for (var p in params) {
1568
+ if (apiItem.indexOf(p) === -1) {
1569
+ paramArray_1.push("".concat(p, "=").concat(params[p]));
1570
+ }
1571
+ }
1572
+ if (paramArray_1.length) {
1573
+ url = url + '?' + paramArray_1.join('&');
1574
+ }
1575
+ }
1576
+ if (url) {
1577
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
1578
+ }
1579
+ else {
1580
+ reject(new Error('request url is not set'));
1581
+ }
1582
+ }
1583
+ else {
1584
+ resolve(undefined);
1585
+ }
1586
+ })
1587
+ .catch(function (er) {
1588
+ reject(er);
1589
+ });
1590
+ });
1591
+ }
1592
+
1533
1593
  /**
1534
1594
  * Thrown when ...
1535
1595
  */
@@ -1895,65 +1955,6 @@ var Geocoder = (function (exports) {
1895
1955
  return ResourcesControl;
1896
1956
  }());
1897
1957
 
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
1958
  var ID = 0;
1958
1959
  var NgwConnector$1 = /** @class */ (function () {
1959
1960
  function NgwConnector(options) {
@@ -2024,9 +2025,9 @@ var Geocoder = (function (exports) {
2024
2025
  if (auth) {
2025
2026
  var login = auth.login, password = auth.password;
2026
2027
  if (login && password) {
2027
- return _this.getUserInfo({ login: login, password: password })
2028
+ return _this._login({ login: login, password: password })
2028
2029
  .then(function () {
2029
- makeQuery();
2030
+ return makeQuery();
2030
2031
  })
2031
2032
  .catch(function (er) { return reject(er); });
2032
2033
  }
@@ -2044,10 +2045,10 @@ var Geocoder = (function (exports) {
2044
2045
  * Quick way to change NextGIS Web user.
2045
2046
  * @param credentials - New user credentials
2046
2047
  */
2047
- NgwConnector.prototype.login = function (credentials) {
2048
+ NgwConnector.prototype.login = function (credentials, options) {
2048
2049
  this.logout();
2049
2050
  addConnector(this);
2050
- return this.getUserInfo(credentials);
2051
+ return this._login(credentials, options);
2051
2052
  };
2052
2053
  /**
2053
2054
  * Disconnecting a user. Aborting all current requests
@@ -2060,29 +2061,16 @@ var Geocoder = (function (exports) {
2060
2061
  this.emitter.emit('logout');
2061
2062
  this.resources.cache.clean();
2062
2063
  };
2063
- NgwConnector.prototype.getUserInfo = function (credentials) {
2064
- var _this = this;
2064
+ NgwConnector.prototype.getUserInfo = function (credentials, options) {
2065
2065
  if (this.user && this.user.id) {
2066
2066
  return CancelablePromise.resolve(this.user);
2067
2067
  }
2068
2068
  if (credentials) {
2069
2069
  this.options.auth = credentials;
2070
2070
  }
2071
- var options = {
2072
- headers: this.getAuthorizationHeaders(credentials),
2073
- // withCredentials: true
2074
- };
2071
+ var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
2075
2072
  // 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
- });
2073
+ return this.makeQuery('/api/component/auth/current_user', {}, options_);
2086
2074
  };
2087
2075
  /**
2088
2076
  * Obtaining the required Headers for authentication of requests in the NGW.
@@ -2148,6 +2136,7 @@ var Geocoder = (function (exports) {
2148
2136
  */
2149
2137
  NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
2150
2138
  var _this = this;
2139
+ var _a;
2151
2140
  if (params_ === void 0) { params_ = {}; }
2152
2141
  if (requestOptions === void 0) { requestOptions = {}; }
2153
2142
  var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
@@ -2162,7 +2151,7 @@ var Geocoder = (function (exports) {
2162
2151
  withCredentials: withCredentials,
2163
2152
  responseType: responseType,
2164
2153
  baseUrl: this.options.baseUrl,
2165
- auth: this.options.auth,
2154
+ userId: (_a = this.user) === null || _a === void 0 ? void 0 : _a.id,
2166
2155
  })));
2167
2156
  }
2168
2157
  return makeApiRequest();
@@ -2371,6 +2360,19 @@ var Geocoder = (function (exports) {
2371
2360
  this.activeRequests.push(request);
2372
2361
  return request;
2373
2362
  };
2363
+ NgwConnector.prototype._login = function (credentials, options) {
2364
+ var _this = this;
2365
+ return this.getUserInfo(credentials, options)
2366
+ .then(function (data) {
2367
+ _this.user = data;
2368
+ _this.emitter.emit('login', data);
2369
+ return data;
2370
+ })
2371
+ .catch(function (er) {
2372
+ _this.emitter.emit('login:error', er);
2373
+ throw er;
2374
+ });
2375
+ };
2374
2376
  NgwConnector.prototype._cleanActiveRequests = function (request) {
2375
2377
  var activeRequestIndex = this.activeRequests.indexOf(request);
2376
2378
  if (activeRequestIndex !== -1) {