incyclist-services 1.7.135 → 1.7.136

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.
@@ -96,23 +96,7 @@ let Countries = (() => {
96
96
  return countries.map(c => this.getIsoFromCountry(c, locale));
97
97
  }
98
98
  async getIsoFromLatLng(point) {
99
- const { lat, lng } = point;
100
- const query = `[out:json][timeout:10];is_in(${lat},${lng})->.a;rel(pivot.a)['admin_level'='2']['boundary'='administrative'];out tags;`;
101
- try {
102
- const result = await this.getOverpassApi().query(query);
103
- if (!result?.elements)
104
- return undefined;
105
- const isos = result.elements
106
- .map(el => el.tags['ISO3166-1:alpha2'])
107
- .filter((iso) => !!iso)
108
- .map(iso => iso.toUpperCase());
109
- if (isos.length < 2)
110
- return isos[0];
111
- return isos.find(iso => this.getList().countries[iso] !== undefined);
112
- }
113
- catch {
114
- return undefined;
115
- }
99
+ return;
116
100
  }
117
101
  getOverpassApi() {
118
102
  return (0, services_1.useOverpassApi)();
@@ -33,12 +33,8 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
33
33
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
34
  done = true;
35
35
  };
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
36
  Object.defineProperty(exports, "__esModule", { value: true });
40
37
  exports.useOverpassApi = exports.OverpassApi = exports.OVERPASS_URL_DEFAULT = void 0;
41
- const promise_any_1 = __importDefault(require("promise.any"));
42
38
  const types_1 = require("../../base/types");
43
39
  const sleep_1 = require("../../utils/sleep");
44
40
  const base_1 = require("../../apps/base/api/base");
@@ -47,9 +43,10 @@ const decorators_1 = require("../../base/decorators");
47
43
  const api_1 = require("../../api");
48
44
  const settings_1 = require("../../settings");
49
45
  const OVERPASS_URL_PRIMARY = 'https://overpass-api.de/api/interpreter';
50
- const OVERPASS_URL_ALT1 = 'https://overpass.kumi.systems/api/interpreter';
51
- const OVERPASS_URL_ALT2 = 'https://overpass.openstreetmap.fr/api/interpreter';
46
+ const OVERPASS_URL_ALT2 = 'https://lz4.overpass-api.de/api/interpreter';
47
+ const OVERPASS_URL_ALT3 = 'https://maps.mail.ru/osm/tools/overpass/api/interpreter';
52
48
  exports.OVERPASS_URL_DEFAULT = OVERPASS_URL_PRIMARY;
49
+ const DEFAULT_MIRRORS = [OVERPASS_URL_PRIMARY, OVERPASS_URL_ALT2, OVERPASS_URL_ALT3];
53
50
  let OverpassApi = (() => {
54
51
  let _classDecorators = [types_1.Singleton];
55
52
  let _classDescriptor;
@@ -77,7 +74,7 @@ let OverpassApi = (() => {
77
74
  logger;
78
75
  constructor(props) {
79
76
  super();
80
- this.mirrors = [OVERPASS_URL_PRIMARY, OVERPASS_URL_ALT1, OVERPASS_URL_ALT2];
77
+ this.mirrors = DEFAULT_MIRRORS;
81
78
  this.url = props?.url ?? this.mirrors[0];
82
79
  this.logger = new gd_eventlog_1.EventLogger('Overpass');
83
80
  if (props?.url) {
@@ -128,25 +125,19 @@ let OverpassApi = (() => {
128
125
  async postViaFetchBinding(fetchBinding, url, data) {
129
126
  const headers = this.getOverpassHeaders();
130
127
  const body = typeof data === 'string' ? data : JSON.stringify(data);
131
- try {
132
- const res = await fetchBinding.fetch(url, {
133
- method: 'POST',
134
- headers,
135
- body,
136
- referrerPolicy: 'unsafe-url'
137
- });
138
- return {
139
- data: res.data,
140
- status: res.status,
141
- statusText: res.statusText,
142
- headers: res.headers,
143
- config: {}
144
- };
145
- }
146
- catch (err) {
147
- this.logger.logEvent({ message: 'fetch error', url, data, error: err.message });
148
- throw err;
149
- }
128
+ const res = await fetchBinding.fetch(url, {
129
+ method: 'POST',
130
+ headers,
131
+ body,
132
+ referrerPolicy: 'unsafe-url'
133
+ });
134
+ return {
135
+ data: res.data,
136
+ status: res.status,
137
+ statusText: res.statusText,
138
+ headers: res.headers,
139
+ config: {}
140
+ };
150
141
  }
151
142
  async postViaNodeHttps(https, url, data) {
152
143
  return new Promise((resolve, reject) => {
@@ -245,10 +236,12 @@ let OverpassApi = (() => {
245
236
  }));
246
237
  });
247
238
  if (timeout !== undefined && timeout !== null) {
248
- promises.push((0, sleep_1.sleep)(timeout).then(() => 'timeout'));
239
+ promises.push((0, sleep_1.sleep)(timeout).then(() => {
240
+ return 'timeout';
241
+ }));
249
242
  }
250
243
  try {
251
- const res = await (0, promise_any_1.default)(promises);
244
+ const res = await Promise.any(promises);
252
245
  if (res === 'timeout') {
253
246
  return undefined;
254
247
  }
@@ -289,7 +282,7 @@ let OverpassApi = (() => {
289
282
  throw lastError;
290
283
  }
291
284
  reset() {
292
- this.mirrors = [OVERPASS_URL_PRIMARY, OVERPASS_URL_ALT1, OVERPASS_URL_ALT2];
285
+ this.mirrors = DEFAULT_MIRRORS;
293
286
  this.url = this.mirrors[0];
294
287
  }
295
288
  getAppVersion() {
@@ -90,23 +90,7 @@ let Countries = (() => {
90
90
  return countries.map(c => this.getIsoFromCountry(c, locale));
91
91
  }
92
92
  async getIsoFromLatLng(point) {
93
- const { lat, lng } = point;
94
- const query = `[out:json][timeout:10];is_in(${lat},${lng})->.a;rel(pivot.a)['admin_level'='2']['boundary'='administrative'];out tags;`;
95
- try {
96
- const result = await this.getOverpassApi().query(query);
97
- if (!result?.elements)
98
- return undefined;
99
- const isos = result.elements
100
- .map(el => el.tags['ISO3166-1:alpha2'])
101
- .filter((iso) => !!iso)
102
- .map(iso => iso.toUpperCase());
103
- if (isos.length < 2)
104
- return isos[0];
105
- return isos.find(iso => this.getList().countries[iso] !== undefined);
106
- }
107
- catch {
108
- return undefined;
109
- }
93
+ return;
110
94
  }
111
95
  getOverpassApi() {
112
96
  return useOverpassApi();
@@ -32,7 +32,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
32
32
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
33
  done = true;
34
34
  };
35
- import any from 'promise.any';
36
35
  import { Singleton } from '../../base/types';
37
36
  import { sleep } from '../../utils/sleep';
38
37
  import { AppApiBase } from '../../apps/base/api/base';
@@ -41,9 +40,10 @@ import { Injectable } from '../../base/decorators';
41
40
  import { getBindings } from '../../api';
42
41
  import { useUserSettings } from '../../settings';
43
42
  const OVERPASS_URL_PRIMARY = 'https://overpass-api.de/api/interpreter';
44
- const OVERPASS_URL_ALT1 = 'https://overpass.kumi.systems/api/interpreter';
45
- const OVERPASS_URL_ALT2 = 'https://overpass.openstreetmap.fr/api/interpreter';
43
+ const OVERPASS_URL_ALT2 = 'https://lz4.overpass-api.de/api/interpreter';
44
+ const OVERPASS_URL_ALT3 = 'https://maps.mail.ru/osm/tools/overpass/api/interpreter';
46
45
  export const OVERPASS_URL_DEFAULT = OVERPASS_URL_PRIMARY;
46
+ const DEFAULT_MIRRORS = [OVERPASS_URL_PRIMARY, OVERPASS_URL_ALT2, OVERPASS_URL_ALT3];
47
47
  let OverpassApi = (() => {
48
48
  let _classDecorators = [Singleton];
49
49
  let _classDescriptor;
@@ -71,7 +71,7 @@ let OverpassApi = (() => {
71
71
  logger;
72
72
  constructor(props) {
73
73
  super();
74
- this.mirrors = [OVERPASS_URL_PRIMARY, OVERPASS_URL_ALT1, OVERPASS_URL_ALT2];
74
+ this.mirrors = DEFAULT_MIRRORS;
75
75
  this.url = props?.url ?? this.mirrors[0];
76
76
  this.logger = new EventLogger('Overpass');
77
77
  if (props?.url) {
@@ -122,25 +122,19 @@ let OverpassApi = (() => {
122
122
  async postViaFetchBinding(fetchBinding, url, data) {
123
123
  const headers = this.getOverpassHeaders();
124
124
  const body = typeof data === 'string' ? data : JSON.stringify(data);
125
- try {
126
- const res = await fetchBinding.fetch(url, {
127
- method: 'POST',
128
- headers,
129
- body,
130
- referrerPolicy: 'unsafe-url'
131
- });
132
- return {
133
- data: res.data,
134
- status: res.status,
135
- statusText: res.statusText,
136
- headers: res.headers,
137
- config: {}
138
- };
139
- }
140
- catch (err) {
141
- this.logger.logEvent({ message: 'fetch error', url, data, error: err.message });
142
- throw err;
143
- }
125
+ const res = await fetchBinding.fetch(url, {
126
+ method: 'POST',
127
+ headers,
128
+ body,
129
+ referrerPolicy: 'unsafe-url'
130
+ });
131
+ return {
132
+ data: res.data,
133
+ status: res.status,
134
+ statusText: res.statusText,
135
+ headers: res.headers,
136
+ config: {}
137
+ };
144
138
  }
145
139
  async postViaNodeHttps(https, url, data) {
146
140
  return new Promise((resolve, reject) => {
@@ -239,10 +233,12 @@ let OverpassApi = (() => {
239
233
  }));
240
234
  });
241
235
  if (timeout !== undefined && timeout !== null) {
242
- promises.push(sleep(timeout).then(() => 'timeout'));
236
+ promises.push(sleep(timeout).then(() => {
237
+ return 'timeout';
238
+ }));
243
239
  }
244
240
  try {
245
- const res = await any(promises);
241
+ const res = await Promise.any(promises);
246
242
  if (res === 'timeout') {
247
243
  return undefined;
248
244
  }
@@ -283,7 +279,7 @@ let OverpassApi = (() => {
283
279
  throw lastError;
284
280
  }
285
281
  reset() {
286
- this.mirrors = [OVERPASS_URL_PRIMARY, OVERPASS_URL_ALT1, OVERPASS_URL_ALT2];
282
+ this.mirrors = DEFAULT_MIRRORS;
287
283
  this.url = this.mirrors[0];
288
284
  }
289
285
  getAppVersion() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.7.135",
3
+ "version": "1.7.136",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },