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