incyclist-services 1.7.73 → 1.7.75

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.
@@ -65,6 +65,7 @@ let IncyclistBindings = (() => {
65
65
  logging;
66
66
  serial;
67
67
  crypto;
68
+ fetch;
68
69
  ant;
69
70
  ble;
70
71
  wifi;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -197,7 +197,7 @@ let RidePageService = (() => {
197
197
  onMenuClose() {
198
198
  try {
199
199
  const state = this.getRideDisplay().getState();
200
- if (state === 'Finished' || this.menuProps.finished) {
200
+ if (state === 'Finished' || this.menuProps?.finished) {
201
201
  this.moveToPreviousPage();
202
202
  this.closePage();
203
203
  return;
@@ -206,7 +206,7 @@ let RidePageService = (() => {
206
206
  this.updatePageDisplay();
207
207
  }
208
208
  catch (err) {
209
- this.logError(err, 'onMenuOpen');
209
+ this.logError(err, 'onMenuClose');
210
210
  }
211
211
  }
212
212
  onPause() {
@@ -158,6 +158,8 @@ let FreeRideService = (() => {
158
158
  if (!opts?.length && from != null) {
159
159
  opts = this.addLastSegmentReverse(opts, from);
160
160
  }
161
+ if (!from)
162
+ return opts ?? [];
161
163
  opts = this.filterOptions(opts, from);
162
164
  opts = this.sortOptions(opts, from);
163
165
  return opts;
@@ -108,6 +108,14 @@ let OverpassApi = (() => {
108
108
  };
109
109
  }
110
110
  async post(url, data, conf) {
111
+ const fetchBinding = this.getBindings()?.fetch;
112
+ if (fetchBinding) {
113
+ try {
114
+ return await this.postViaFetchBinding(fetchBinding, url, data);
115
+ }
116
+ catch {
117
+ }
118
+ }
111
119
  try {
112
120
  const https = require('https');
113
121
  return await this.postViaNodeHttps(https, url, data);
@@ -121,6 +129,23 @@ let OverpassApi = (() => {
121
129
  return await super.post(url, data, config);
122
130
  }
123
131
  }
132
+ async postViaFetchBinding(fetchBinding, url, data) {
133
+ const headers = this.getOverpassHeaders();
134
+ const body = typeof data === 'string' ? data : JSON.stringify(data);
135
+ const res = await fetchBinding.fetch(url, {
136
+ method: 'POST',
137
+ headers,
138
+ body,
139
+ referrerPolicy: 'unsafe-url'
140
+ });
141
+ return {
142
+ data: res.data,
143
+ status: res.status,
144
+ statusText: res.statusText,
145
+ headers: res.headers,
146
+ config: {}
147
+ };
148
+ }
124
149
  async postViaNodeHttps(https, url, data) {
125
150
  return new Promise((resolve, reject) => {
126
151
  const reqUrl = new URL(url);
@@ -203,9 +228,17 @@ let OverpassApi = (() => {
203
228
  const promises = [];
204
229
  this.mirrors.forEach(mirror => {
205
230
  promises.push(this.post(mirror, query)
206
- .then((res) => res?.data)
231
+ .then((res) => {
232
+ if (res?.status >= 400) {
233
+ const err = Object.assign(new Error(`HTTP ${res.status}`), { response: res });
234
+ errors.push(this.extractErrorInfo(err, mirror));
235
+ throw err;
236
+ }
237
+ return res?.data;
238
+ })
207
239
  .catch(err => {
208
- errors.push(this.extractErrorInfo(err, mirror));
240
+ if (!errors.find(e => e.mirror === mirror))
241
+ errors.push(this.extractErrorInfo(err, mirror));
209
242
  throw err;
210
243
  }));
211
244
  });
@@ -237,6 +270,9 @@ let OverpassApi = (() => {
237
270
  }
238
271
  try {
239
272
  const res = await this.post(mirror, query);
273
+ if (res?.status >= 400) {
274
+ throw Object.assign(new Error(`HTTP ${res.status}`), { response: res });
275
+ }
240
276
  return res?.data;
241
277
  }
242
278
  catch (err) {
@@ -62,6 +62,7 @@ let IncyclistBindings = (() => {
62
62
  logging;
63
63
  serial;
64
64
  crypto;
65
+ fetch;
65
66
  ant;
66
67
  ble;
67
68
  wifi;
@@ -0,0 +1 @@
1
+ export {};
@@ -194,7 +194,7 @@ let RidePageService = (() => {
194
194
  onMenuClose() {
195
195
  try {
196
196
  const state = this.getRideDisplay().getState();
197
- if (state === 'Finished' || this.menuProps.finished) {
197
+ if (state === 'Finished' || this.menuProps?.finished) {
198
198
  this.moveToPreviousPage();
199
199
  this.closePage();
200
200
  return;
@@ -203,7 +203,7 @@ let RidePageService = (() => {
203
203
  this.updatePageDisplay();
204
204
  }
205
205
  catch (err) {
206
- this.logError(err, 'onMenuOpen');
206
+ this.logError(err, 'onMenuClose');
207
207
  }
208
208
  }
209
209
  onPause() {
@@ -152,6 +152,8 @@ let FreeRideService = (() => {
152
152
  if (!opts?.length && from != null) {
153
153
  opts = this.addLastSegmentReverse(opts, from);
154
154
  }
155
+ if (!from)
156
+ return opts ?? [];
155
157
  opts = this.filterOptions(opts, from);
156
158
  opts = this.sortOptions(opts, from);
157
159
  return opts;
@@ -102,6 +102,14 @@ let OverpassApi = (() => {
102
102
  };
103
103
  }
104
104
  async post(url, data, conf) {
105
+ const fetchBinding = this.getBindings()?.fetch;
106
+ if (fetchBinding) {
107
+ try {
108
+ return await this.postViaFetchBinding(fetchBinding, url, data);
109
+ }
110
+ catch {
111
+ }
112
+ }
105
113
  try {
106
114
  const https = require('https');
107
115
  return await this.postViaNodeHttps(https, url, data);
@@ -115,6 +123,23 @@ let OverpassApi = (() => {
115
123
  return await super.post(url, data, config);
116
124
  }
117
125
  }
126
+ async postViaFetchBinding(fetchBinding, url, data) {
127
+ const headers = this.getOverpassHeaders();
128
+ const body = typeof data === 'string' ? data : JSON.stringify(data);
129
+ const res = await fetchBinding.fetch(url, {
130
+ method: 'POST',
131
+ headers,
132
+ body,
133
+ referrerPolicy: 'unsafe-url'
134
+ });
135
+ return {
136
+ data: res.data,
137
+ status: res.status,
138
+ statusText: res.statusText,
139
+ headers: res.headers,
140
+ config: {}
141
+ };
142
+ }
118
143
  async postViaNodeHttps(https, url, data) {
119
144
  return new Promise((resolve, reject) => {
120
145
  const reqUrl = new URL(url);
@@ -197,9 +222,17 @@ let OverpassApi = (() => {
197
222
  const promises = [];
198
223
  this.mirrors.forEach(mirror => {
199
224
  promises.push(this.post(mirror, query)
200
- .then((res) => res?.data)
225
+ .then((res) => {
226
+ if (res?.status >= 400) {
227
+ const err = Object.assign(new Error(`HTTP ${res.status}`), { response: res });
228
+ errors.push(this.extractErrorInfo(err, mirror));
229
+ throw err;
230
+ }
231
+ return res?.data;
232
+ })
201
233
  .catch(err => {
202
- errors.push(this.extractErrorInfo(err, mirror));
234
+ if (!errors.find(e => e.mirror === mirror))
235
+ errors.push(this.extractErrorInfo(err, mirror));
203
236
  throw err;
204
237
  }));
205
238
  });
@@ -231,6 +264,9 @@ let OverpassApi = (() => {
231
264
  }
232
265
  try {
233
266
  const res = await this.post(mirror, query);
267
+ if (res?.status >= 400) {
268
+ throw Object.assign(new Error(`HTTP ${res.status}`), { response: res });
269
+ }
234
270
  return res?.data;
235
271
  }
236
272
  catch (err) {
@@ -11,6 +11,7 @@ import type { IVideoProcessor } from '../video';
11
11
  import type { ISecretBinding } from '../secret';
12
12
  import type { ISerialBinding } from '../serial/types';
13
13
  import type { ICryptoBinding } from '../crypto/types';
14
+ import type { IFetchBinding } from '../fetch/types';
14
15
  export interface IUserSettingsBinding {
15
16
  getAll(): Promise<any>;
16
17
  set(key: string, value: any): Promise<boolean>;
@@ -33,6 +34,7 @@ export declare class IncyclistBindings {
33
34
  logging: ILogBinding;
34
35
  serial: ISerialBinding;
35
36
  crypto: ICryptoBinding;
37
+ fetch?: IFetchBinding;
36
38
  ant: any;
37
39
  ble: any;
38
40
  wifi: any;
@@ -0,0 +1,16 @@
1
+ export interface IFetchRequestInit {
2
+ method?: string;
3
+ headers?: Record<string, string>;
4
+ body?: string;
5
+ referrerPolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
6
+ }
7
+ export interface IFetchResponse {
8
+ ok: boolean;
9
+ status: number;
10
+ statusText: string;
11
+ headers: Record<string, string>;
12
+ data: string;
13
+ }
14
+ export interface IFetchBinding {
15
+ fetch(url: string, init?: IFetchRequestInit): Promise<IFetchResponse>;
16
+ }
@@ -4,4 +4,5 @@ export type * from './repository/types';
4
4
  export type * from './path';
5
5
  export type * from './video';
6
6
  export type * from './crypto/types';
7
+ export type * from './fetch/types';
7
8
  export type * from './bindings/types';
@@ -2,6 +2,7 @@ import { AppApiBase } from '../../apps/base/api/base';
2
2
  import { EventLogger } from 'gd-eventlog';
3
3
  import { UserSettingsService } from '../../settings';
4
4
  import { AxiosResponse } from 'axios';
5
+ import type { IFetchBinding } from '../../api/fetch/types';
5
6
  export declare const OVERPASS_URL_DEFAULT = "https://overpass.kumi.systems/api/interpreter";
6
7
  export declare class OverpassApi extends AppApiBase {
7
8
  protected url: string;
@@ -15,6 +16,7 @@ export declare class OverpassApi extends AppApiBase {
15
16
  Referer: string;
16
17
  };
17
18
  protected post(url: string, data?: object | string, conf?: object): Promise<AxiosResponse>;
19
+ protected postViaFetchBinding(fetchBinding: IFetchBinding, url: string, data?: object | string): Promise<AxiosResponse>;
18
20
  protected postViaNodeHttps(https: any, url: string, data?: object | string): Promise<any>;
19
21
  query(queryOL: string, timeout?: number): Promise<JSON | string | undefined>;
20
22
  singleQuery(queryOL: string): Promise<JSON | string>;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.7.73",
3
+ "version": "1.7.75",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },
7
7
  "dependencies": {
8
8
  "@garmin/fitsdk": "^21.200.0",
9
9
  "axios": "^1.15.2",
10
- "incyclist-devices": "^3.0.22",
10
+ "incyclist-devices": "^3.0.23",
11
11
  "promise.any": "^2.0.6",
12
12
  "semver": "^7.7.4",
13
13
  "tcx-builder": "^1.1.1",