incyclist-services 1.9.7 → 1.9.8

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.
Files changed (55) hide show
  1. package/lib/cjs/api/rest/api.js +7 -3
  2. package/lib/cjs/api/rest/external.js +26 -0
  3. package/lib/cjs/apps/googleMaps/service.js +2 -0
  4. package/lib/cjs/apps/service.js +4 -1
  5. package/lib/cjs/devices/pairing/service.js +0 -1
  6. package/lib/cjs/i18n/countries/service.js +2 -2
  7. package/lib/cjs/routes/base/api/api.js +196 -0
  8. package/lib/cjs/routes/base/api/factory.js +93 -0
  9. package/lib/cjs/routes/base/api/index.js +14 -184
  10. package/lib/cjs/routes/base/parsers/tacx/TacxParser.js +1 -1
  11. package/lib/cjs/routes/free-ride/service.js +41 -0
  12. package/lib/cjs/routes/list/loaders/DBLoader.js +0 -1
  13. package/lib/cjs/routes/list/loaders/api.js +270 -176
  14. package/lib/cjs/routes/list/service.js +401 -357
  15. package/lib/cjs/ui/service.js +1 -2
  16. package/lib/cjs/utils/string.js +21 -1
  17. package/lib/esm/api/rest/api.js +7 -3
  18. package/lib/esm/api/rest/external.js +22 -0
  19. package/lib/esm/api/rest/incyclist copy.js +33 -0
  20. package/lib/esm/apps/googleMaps/service.js +2 -0
  21. package/lib/esm/apps/service.js +4 -1
  22. package/lib/esm/devices/configuration/model/add/index.js +1 -0
  23. package/lib/esm/devices/configuration/model/exclusion/index.js +1 -0
  24. package/lib/esm/devices/pairing/capability.js +1 -0
  25. package/lib/esm/devices/pairing/service.js +0 -1
  26. package/lib/esm/i18n/countries/service.js +2 -2
  27. package/lib/esm/routes/base/api/api.js +194 -0
  28. package/lib/esm/routes/base/api/factory.js +86 -0
  29. package/lib/esm/routes/base/api/index.js +2 -186
  30. package/lib/esm/routes/base/parsers/tacx/TacxParser.js +1 -1
  31. package/lib/esm/routes/free-ride/service.js +41 -0
  32. package/lib/esm/routes/list/loaders/DBLoader.js +0 -1
  33. package/lib/esm/routes/list/loaders/api.js +272 -174
  34. package/lib/esm/routes/list/service.js +401 -357
  35. package/lib/esm/ui/service.js +2 -3
  36. package/lib/esm/utils/string.js +18 -0
  37. package/lib/types/api/rest/api.d.ts +2 -2
  38. package/lib/types/api/rest/external.d.ts +7 -0
  39. package/lib/types/api/rest/incyclist copy.d.ts +7 -0
  40. package/lib/types/api/rest/types.d.ts +5 -3
  41. package/lib/types/apps/service.d.ts +1 -0
  42. package/lib/types/devices/configuration/model/add/index.d.ts +10 -0
  43. package/lib/types/devices/configuration/model/exclusion/index.d.ts +19 -0
  44. package/lib/types/devices/pairing/capability.d.ts +10 -0
  45. package/lib/types/routes/base/api/api.d.ts +23 -0
  46. package/lib/types/routes/base/api/factory.d.ts +7 -0
  47. package/lib/types/routes/base/api/index.d.ts +2 -26
  48. package/lib/types/routes/base/api/types.d.ts +10 -0
  49. package/lib/types/routes/base/parsers/tacx/TacxParser.d.ts +1 -1
  50. package/lib/types/routes/base/types/index.d.ts +1 -0
  51. package/lib/types/routes/free-ride/service.d.ts +6 -0
  52. package/lib/types/routes/list/loaders/api.d.ts +6 -3
  53. package/lib/types/routes/list/service.d.ts +37 -29
  54. package/lib/types/utils/string.d.ts +2 -0
  55. package/package.json +1 -1
@@ -488,10 +488,9 @@ let UserInterfaceServcie = (() => {
488
488
  const freeRide = (0, routes_1.useFreeRideService)();
489
489
  const workouts = (0, workouts_1.useWorkoutList)();
490
490
  const activities = (0, activities_1.useActivityList)();
491
- const activeRides = (0, activities_1.useActiveRides)();
492
491
  const promises = [
493
492
  routes.preload().wait(),
494
- freeRide.selectStartPosition(),
493
+ freeRide.init(),
495
494
  workouts.preload().wait(),
496
495
  activities.preload().wait()
497
496
  ];
@@ -1,8 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ignoreEmpty = void 0;
3
+ exports.pascalCase = exports.camelCase = exports.ignoreEmpty = void 0;
4
4
  const ignoreEmpty = (str) => {
5
5
  if (str?.length)
6
6
  return str;
7
7
  };
8
8
  exports.ignoreEmpty = ignoreEmpty;
9
+ const camelCase = (str) => {
10
+ if (!str?.length)
11
+ return str;
12
+ return str
13
+ .toLowerCase()
14
+ .split(/[^a-z0-9]+/)
15
+ .map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))
16
+ .join('');
17
+ };
18
+ exports.camelCase = camelCase;
19
+ const pascalCase = (str) => {
20
+ if (!str?.length)
21
+ return str;
22
+ return str
23
+ .toLowerCase()
24
+ .replace(new RegExp(/[-_ ]+/, 'g'), ' ')
25
+ .replace(/(?:^\w|\b\w)/g, letter => letter.toUpperCase())
26
+ .replaceAll(' ', '');
27
+ };
28
+ exports.pascalCase = pascalCase;
@@ -6,10 +6,8 @@ export class ApiClient {
6
6
  logger;
7
7
  requests;
8
8
  init(props) {
9
- const { uuid, apiKey, requestLog = true, version, appVersion, channel = 'desktop', platform } = props;
9
+ const { requestLog = true, version, appVersion, channel = 'desktop', platform } = props;
10
10
  const headers = {
11
- "X-uuid": uuid,
12
- "X-API-Key": apiKey,
13
11
  "x-app-channel": channel,
14
12
  "x-app-version": appVersion,
15
13
  "x-react-version": version
@@ -17,6 +15,12 @@ export class ApiClient {
17
15
  if (platform) {
18
16
  headers['x-app-platform'] = platform;
19
17
  }
18
+ if (props['uuid']) {
19
+ headers['X-uuid'] = props['uuid'];
20
+ }
21
+ if (props['apiKey']) {
22
+ headers['X-API-Key'] = props['apiKey'];
23
+ }
20
24
  this.axios = axios.create({ headers });
21
25
  if (requestLog) {
22
26
  this.logger = new EventLogger('API');
@@ -0,0 +1,22 @@
1
+ import { getBindings } from '../bindings';
2
+ import { ApiClient } from './api';
3
+ export class IncyclistExternalRestApiClient {
4
+ static _api;
5
+ static getClient(requestLog) {
6
+ const appInfo = getBindings().appInfo;
7
+ const props = {
8
+ channel: appInfo?.getChannel(),
9
+ appVersion: appInfo?.getAppVersion(),
10
+ version: appInfo?.getUIVersion(),
11
+ platform: appInfo?.getOS()?.platform,
12
+ requestLog: requestLog ?? true
13
+ };
14
+ this.api().init(props);
15
+ return this.api().client();
16
+ }
17
+ static api() {
18
+ if (!this._api)
19
+ this._api = new ApiClient();
20
+ return this._api;
21
+ }
22
+ }
@@ -0,0 +1,33 @@
1
+ import { getBindings } from '../bindings';
2
+ import { useUserSettings } from '../../settings';
3
+ import { ApiClient } from './api';
4
+ export class IncyclistRestApiClient {
5
+ static _api;
6
+ static getClient(requestLog) {
7
+ const appInfo = getBindings().appInfo;
8
+ let uuid;
9
+ const apiKey = getBindings().secret?.getSecret('INCYCLIST_API_KEY');
10
+ try {
11
+ uuid = useUserSettings().get('uuid', null);
12
+ }
13
+ catch {
14
+ uuid = null;
15
+ }
16
+ const props = {
17
+ channel: appInfo?.getChannel(),
18
+ appVersion: appInfo?.getAppVersion(),
19
+ version: appInfo?.getUIVersion(),
20
+ platform: appInfo?.getOS()?.platform,
21
+ requestLog: requestLog ?? true,
22
+ apiKey,
23
+ uuid
24
+ };
25
+ this.api().init(props);
26
+ return this.api().client();
27
+ }
28
+ static api() {
29
+ if (!this._api)
30
+ this._api = new ApiClient();
31
+ return this._api;
32
+ }
33
+ }
@@ -63,6 +63,8 @@ let GoogleMapsService = (() => {
63
63
  api = __runInitializers(this, _instanceExtraInitializers);
64
64
  constructor() {
65
65
  super('GoogleMaps');
66
+ const observer = this.getUserSettings().requestNotifyOnChange?.('maps', 'GOOGLE_MAPS_API_KEY');
67
+ observer?.on('changed', this.onPersonalApiKeySet.bind(this));
66
68
  }
67
69
  setApi(api) {
68
70
  this.api = api;
@@ -140,7 +140,7 @@ let AppsService = (() => {
140
140
  return operations;
141
141
  }
142
142
  getConnectedServices(operation) {
143
- const available = this.services[operation];
143
+ const available = this.getAvailableServices(operation);
144
144
  if (operation === 'ActivityUpload') {
145
145
  const factory = this.getActivityUploadFactory();
146
146
  const uploaders = available.map(a => factory.get(a));
@@ -155,6 +155,9 @@ let AppsService = (() => {
155
155
  }
156
156
  return [];
157
157
  }
158
+ getAvailableServices(operation) {
159
+ return this.services[operation];
160
+ }
158
161
  getName(key) {
159
162
  const found = this.serviceMap.find(r => r.key === key);
160
163
  return found ? found.name : key;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export const isCapabilityActive = (c) => Boolean(c?.selected) && !c?.disabled && !c?.excluded;
@@ -472,7 +472,6 @@ let DevicePairingService = (() => {
472
472
  delete state.deleted;
473
473
  delete state.waiting;
474
474
  state.interfaces = state.interfaces?.filter(i => !i.invisible);
475
- const oldState = this.state ?? {};
476
475
  return state;
477
476
  }
478
477
  emitStateChange(newState) {
@@ -35,7 +35,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
35
35
  import { IncyclistService } from "../../base/service";
36
36
  import { Singleton } from "../../base/types";
37
37
  import defaultList from './countries.json';
38
- import IncyclistRoutesApi from "../../routes/base/api";
38
+ import { useIncyclistRoutesApi } from "../../routes/base/api/factory";
39
39
  let Countries = (() => {
40
40
  let _classDecorators = [Singleton];
41
41
  let _classDescriptor;
@@ -85,7 +85,7 @@ let Countries = (() => {
85
85
  return countries.map(c => this.getIsoFromCountry(c, locale));
86
86
  }
87
87
  async getIsoFromLatLng(point) {
88
- const api = IncyclistRoutesApi.getInstance();
88
+ const api = useIncyclistRoutesApi().create();
89
89
  return api.getCountry(point);
90
90
  }
91
91
  };
@@ -0,0 +1,194 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import { EventLogger } from 'gd-eventlog';
36
+ import { DEFAULT_DOMAIN, NO_CACHE, ROUTE_API } from './consts';
37
+ import { IncyclistRestApiClient } from '../../../api';
38
+ import { useUserSettings } from '../../../settings';
39
+ import { Injectable } from '../../../base/decorators';
40
+ import { IncyclistExternalRestApiClient } from '../../../api/rest/external';
41
+ const fixMissingRouteDistances = (points) => {
42
+ let routeDistance = 0;
43
+ points.forEach((p) => {
44
+ if (!p.routeDistance)
45
+ p.routeDistance = routeDistance;
46
+ routeDistance = p.routeDistance + p['distance'];
47
+ });
48
+ };
49
+ const verify = (route) => {
50
+ if (route['decoded']) {
51
+ route.points = route['decoded'];
52
+ delete route['decoded'];
53
+ fixMissingRouteDistances(route.points);
54
+ }
55
+ };
56
+ let IncyclistRoutesApi = (() => {
57
+ let _instanceExtraInitializers = [];
58
+ let _getUserSettings_decorators;
59
+ return class IncyclistRoutesApi {
60
+ static {
61
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
62
+ _getUserSettings_decorators = [Injectable];
63
+ __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
64
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
65
+ }
66
+ logger = __runInitializers(this, _instanceExtraInitializers);
67
+ api;
68
+ baseUrl;
69
+ isExternal;
70
+ source;
71
+ constructor(baseUrl) {
72
+ this.logger = new EventLogger('RouteListApi');
73
+ this.baseUrl = baseUrl;
74
+ if (baseUrl) {
75
+ this.isExternal = true;
76
+ }
77
+ }
78
+ setSource(source) {
79
+ this.source = source;
80
+ }
81
+ logError(err, fn, logInfo) {
82
+ const args = logInfo ?? {};
83
+ this.logger.logEvent({ message: 'Error', error: err.message, fn, ...args });
84
+ }
85
+ getApi() {
86
+ if (!this.api) {
87
+ this.api = this.baseUrl ?
88
+ IncyclistExternalRestApiClient.getClient() :
89
+ IncyclistRestApiClient.getClient();
90
+ return this.api;
91
+ }
92
+ return this.api;
93
+ }
94
+ getBaseUrl() {
95
+ if (this.baseUrl)
96
+ return this.baseUrl;
97
+ const domain = this.getUserSettings().getValue('DOMAIN', DEFAULT_DOMAIN);
98
+ const defaultUrl = `https://dlws.${domain}/api/v1/routes`;
99
+ const baseUrl = this.getUserSettings().getValue(ROUTE_API, defaultUrl);
100
+ return baseUrl;
101
+ }
102
+ async getRouteDescriptions(query, throws = false) {
103
+ const { type = 'gpx', category } = query;
104
+ let url = (type === 'gpx') ? `?private=false` : `/?type=${type}`;
105
+ if (category)
106
+ url += `&category=${category}`;
107
+ try {
108
+ const res = await this._get(url, NO_CACHE);
109
+ if (this.isExternal && Array.isArray(res.data)) {
110
+ res.data.forEach(route => {
111
+ route.apiServer = this.source;
112
+ });
113
+ }
114
+ return res.data;
115
+ }
116
+ catch (err) {
117
+ if (throws)
118
+ throw (err);
119
+ this.logError(err, 'getRouteDescriptions', { query });
120
+ return undefined;
121
+ }
122
+ }
123
+ async getRouteDetails(routeId) {
124
+ try {
125
+ const res = await this._get(`/${routeId}`);
126
+ verify(res.data);
127
+ return res.data;
128
+ }
129
+ catch {
130
+ return undefined;
131
+ }
132
+ }
133
+ async getRoutePreview(routeId) {
134
+ try {
135
+ const res = await this._get(`/${routeId}/preview`);
136
+ return res.data?.url;
137
+ }
138
+ catch {
139
+ return undefined;
140
+ }
141
+ }
142
+ async getCountry(query) {
143
+ if (this.isExternal)
144
+ return;
145
+ if (!query)
146
+ return;
147
+ let url;
148
+ if (Array.isArray(query)) {
149
+ const points = query.slice(0, 100).map((p) => `${p.lat},${p.lng}`).join(';');
150
+ url = `/country?points=${points}`;
151
+ }
152
+ else {
153
+ const { lat, lng } = query;
154
+ url = `/country?lat=${lat}&lng=${lng}`;
155
+ }
156
+ try {
157
+ const conf = {};
158
+ conf.validateStatus = (status) => {
159
+ return (status >= 200 && status < 300) || status == 404 || status == 429;
160
+ };
161
+ const res = await this._get(url, conf);
162
+ if (res.status === 404)
163
+ return;
164
+ if (res.status === 429) {
165
+ this.logger.logEvent({ message: 'getCountry hit rate limit', query });
166
+ return;
167
+ }
168
+ return res.data.country?.toUpperCase();
169
+ }
170
+ catch (err) {
171
+ this.logError(err, 'getCountry');
172
+ }
173
+ }
174
+ async reload() {
175
+ if (this.isExternal)
176
+ return;
177
+ try {
178
+ await this._get(`/reload`);
179
+ }
180
+ catch (err) {
181
+ this.logError(err, 'reload');
182
+ }
183
+ }
184
+ async _get(url, ...args) {
185
+ const api = this.getApi();
186
+ const baseUrl = this.getBaseUrl();
187
+ return await api.get(baseUrl + url, ...args);
188
+ }
189
+ getUserSettings() {
190
+ return useUserSettings();
191
+ }
192
+ };
193
+ })();
194
+ export default IncyclistRoutesApi;
@@ -0,0 +1,86 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import IncyclistRoutesApi from "./api";
36
+ import { Injectable, Singleton } from "../../../base/decorators";
37
+ import { useUserSettings } from "../../../settings";
38
+ let IncyclistRoutesApiFactory = (() => {
39
+ let _classDecorators = [Singleton];
40
+ let _classDescriptor;
41
+ let _classExtraInitializers = [];
42
+ let _classThis;
43
+ let _instanceExtraInitializers = [];
44
+ let _getUserSettings_decorators;
45
+ var IncyclistRoutesApiFactory = class {
46
+ static { _classThis = this; }
47
+ static {
48
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
49
+ _getUserSettings_decorators = [Injectable];
50
+ __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
51
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
52
+ IncyclistRoutesApiFactory = _classThis = _classDescriptor.value;
53
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
54
+ __runInitializers(_classThis, _classExtraInitializers);
55
+ }
56
+ apis = (__runInitializers(this, _instanceExtraInitializers), new Map());
57
+ create(key = 'default') {
58
+ if (this.apis.has(key))
59
+ return this.apis.get(key);
60
+ const ROUTE_API = this.getUserSettings().getValue('ROUTE_API', undefined);
61
+ if (key === 'default' && ROUTE_API === undefined) {
62
+ const api = new IncyclistRoutesApi();
63
+ this.apis.set('default', api);
64
+ return api;
65
+ }
66
+ else if (key === 'default' && ROUTE_API !== undefined) {
67
+ const api = new IncyclistRoutesApi(ROUTE_API);
68
+ this.apis.set('default', api);
69
+ return api;
70
+ }
71
+ else {
72
+ const baseUrl = this.getUserSettings().getValue(`routes.servers.${key}`, null);
73
+ const api = new IncyclistRoutesApi(baseUrl ?? key);
74
+ api.setSource(key);
75
+ this.apis.set(key, api);
76
+ return api;
77
+ }
78
+ }
79
+ getUserSettings() {
80
+ return useUserSettings();
81
+ }
82
+ };
83
+ return IncyclistRoutesApiFactory = _classThis;
84
+ })();
85
+ export { IncyclistRoutesApiFactory };
86
+ export const useIncyclistRoutesApi = () => new IncyclistRoutesApiFactory();
@@ -1,186 +1,2 @@
1
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
- var useValue = arguments.length > 2;
3
- for (var i = 0; i < initializers.length; i++) {
4
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
- }
6
- return useValue ? value : void 0;
7
- };
8
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
- var _, done = false;
14
- for (var i = decorators.length - 1; i >= 0; i--) {
15
- var context = {};
16
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
- if (kind === "accessor") {
21
- if (result === void 0) continue;
22
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
- if (_ = accept(result.get)) descriptor.get = _;
24
- if (_ = accept(result.set)) descriptor.set = _;
25
- if (_ = accept(result.init)) initializers.unshift(_);
26
- }
27
- else if (_ = accept(result)) {
28
- if (kind === "field") initializers.unshift(_);
29
- else descriptor[key] = _;
30
- }
31
- }
32
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
- done = true;
34
- };
35
- import { EventLogger } from 'gd-eventlog';
36
- import { DEFAULT_DOMAIN, NO_CACHE, ROUTE_API } from './consts';
37
- import { IncyclistRestApiClient } from '../../../api';
38
- import { useUserSettings } from '../../../settings';
39
- import { Injectable } from '../../../base/decorators';
40
- let IncyclistRoutesApi = (() => {
41
- let _instanceExtraInitializers = [];
42
- let _getUserSettings_decorators;
43
- return class IncyclistRoutesApi {
44
- static {
45
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
46
- _getUserSettings_decorators = [Injectable];
47
- __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
48
- if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
49
- }
50
- static _instance;
51
- static getInstance() {
52
- IncyclistRoutesApi._instance = IncyclistRoutesApi._instance ?? new IncyclistRoutesApi();
53
- return IncyclistRoutesApi._instance;
54
- }
55
- logger = __runInitializers(this, _instanceExtraInitializers);
56
- api;
57
- constructor() {
58
- this.logger = new EventLogger('RouteListApi');
59
- }
60
- logError(err, fn, logInfo) {
61
- const args = logInfo ?? {};
62
- this.logger.logEvent({ message: 'Error', error: err.message, fn, ...args });
63
- }
64
- getApi() {
65
- if (!this.api) {
66
- this.api = IncyclistRestApiClient.getClient();
67
- return this.api;
68
- }
69
- return this.api;
70
- }
71
- getBaseUrl() {
72
- const domain = this.getSetting('DOMAIN', DEFAULT_DOMAIN);
73
- const defaultUrl = `https://dlws.${domain}/api/v1/routes`;
74
- const baseUrl = this.getSetting(ROUTE_API, defaultUrl);
75
- return baseUrl;
76
- }
77
- async getRouteDescriptions(query, throws = false) {
78
- const { type = 'gpx', category } = query;
79
- let url = (type === 'gpx') ? `?private=false` : `/?type=${type}`;
80
- if (category)
81
- url += "&category=${category}";
82
- try {
83
- const res = await this._get(url, NO_CACHE);
84
- return res.data;
85
- }
86
- catch (err) {
87
- if (throws)
88
- throw (err);
89
- this.logError(err, 'getRouteDescriptions', { query });
90
- return undefined;
91
- }
92
- }
93
- static verify(route) {
94
- if (route['decoded']) {
95
- route.points = route['decoded'];
96
- delete route['decoded'];
97
- IncyclistRoutesApi.fixMissingRouteDistances(route.points);
98
- }
99
- }
100
- static fixMissingRouteDistances(points) {
101
- let routeDistance = 0;
102
- points.forEach((p) => {
103
- if (!p.routeDistance)
104
- p.routeDistance = routeDistance;
105
- routeDistance = p.routeDistance + p['distance'];
106
- });
107
- }
108
- async getRouteDetails(routeId) {
109
- try {
110
- const res = await this._get(`/${routeId}`);
111
- IncyclistRoutesApi.verify(res.data);
112
- return res.data;
113
- }
114
- catch {
115
- return undefined;
116
- }
117
- }
118
- async getRoutePreview(routeId) {
119
- try {
120
- const res = await this._get(`/${routeId}/preview`);
121
- return res.data?.url;
122
- }
123
- catch {
124
- return undefined;
125
- }
126
- }
127
- async getCountry(query) {
128
- if (!query)
129
- return;
130
- let url;
131
- if (Array.isArray(query)) {
132
- const points = query.slice(0, 100).map((p) => `${p.lat},${p.lng}`).join(';');
133
- url = `/country?points=${points}`;
134
- }
135
- else {
136
- const { lat, lng } = query;
137
- url = `/country?lat=${lat}&lng=${lng}`;
138
- }
139
- try {
140
- const conf = {};
141
- conf.validateStatus = (status) => {
142
- return (status >= 200 && status < 300) || status == 404 || status == 429;
143
- };
144
- const res = await this._get(url, conf);
145
- if (res.status === 404)
146
- return;
147
- if (res.status === 429) {
148
- this.logger.logEvent({ message: 'getCountry hit rate limit', query });
149
- return;
150
- }
151
- return res.data.country?.toUpperCase();
152
- }
153
- catch (err) {
154
- this.logError(err, 'getCountry');
155
- }
156
- }
157
- async reload() {
158
- try {
159
- await this._get(`/reload`);
160
- }
161
- catch (err) {
162
- this.logError(err, 'reload');
163
- }
164
- }
165
- async _get(url, ...args) {
166
- const api = this.getApi();
167
- const baseUrl = this.getBaseUrl();
168
- return await api.get(baseUrl + url, ...args);
169
- }
170
- _reset() {
171
- IncyclistRoutesApi._instance = undefined;
172
- }
173
- getSetting(key, def) {
174
- try {
175
- return this.getUserSettings().get(key, def);
176
- }
177
- catch {
178
- return def;
179
- }
180
- }
181
- getUserSettings() {
182
- return useUserSettings();
183
- }
184
- };
185
- })();
186
- export default IncyclistRoutesApi;
1
+ export * from './api';
2
+ export * from './factory';
@@ -54,7 +54,7 @@ let TacxParser = (() => {
54
54
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
55
55
  }
56
56
  logger = (__runInitializers(this, _instanceExtraInitializers), new EventLogger('TacxParser'));
57
- async import(file, data) {
57
+ async import(file, _data) {
58
58
  const context = this.buildContext(file);
59
59
  await this.parseRlv(context);
60
60
  await this.parsePgmf(context);