incyclist-services 1.0.41 → 1.0.43
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/api/index.d.ts +2 -0
- package/lib/api/index.js +18 -0
- package/lib/api/rest/index.d.ts +18 -0
- package/lib/api/rest/index.js +79 -0
- package/lib/api/rest/types.d.ts +9 -0
- package/lib/api/rest/types.js +2 -0
- package/lib/base/service.d.ts +11 -0
- package/lib/base/service.js +30 -0
- package/lib/devices/configuration/service.js +10 -2
- package/lib/devices/pairing/service.d.ts +3 -10
- package/lib/devices/pairing/service.js +12 -27
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/routes/base/api/consts.d.ts +9 -0
- package/lib/routes/base/api/consts.js +13 -0
- package/lib/routes/base/api/index.d.ts +19 -0
- package/lib/routes/base/api/index.js +100 -0
- package/lib/routes/base/api/types.d.ts +46 -0
- package/lib/routes/base/api/types.js +2 -0
- package/lib/routes/base/types/index.d.ts +44 -0
- package/lib/routes/base/types/index.js +2 -0
- package/lib/routes/base/utils/localization.d.ts +2 -0
- package/lib/routes/base/utils/localization.js +12 -0
- package/lib/routes/base/utils/route.d.ts +4 -0
- package/lib/routes/base/utils/route.js +52 -0
- package/lib/routes/index.d.ts +1 -0
- package/lib/routes/index.js +17 -0
- package/lib/routes/list/bindings/mock.d.ts +9 -0
- package/lib/routes/list/bindings/mock.js +32 -0
- package/lib/routes/list/consts.d.ts +0 -0
- package/lib/routes/list/consts.js +0 -0
- package/lib/routes/list/index.d.ts +2 -0
- package/lib/routes/list/index.js +18 -0
- package/lib/routes/list/repository.d.ts +0 -0
- package/lib/routes/list/repository.js +0 -0
- package/lib/routes/list/service.d.ts +78 -0
- package/lib/routes/list/service.js +513 -0
- package/lib/routes/list/types.d.ts +83 -0
- package/lib/routes/list/types.js +2 -0
- package/lib/routes/utils/localization.d.ts +2 -0
- package/lib/routes/utils/localization.js +12 -0
- package/lib/utils/geo.d.ts +13 -0
- package/lib/utils/geo.js +55 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +15 -0
- package/lib/utils/math.d.ts +6 -0
- package/lib/utils/math.js +28 -0
- package/package.json +2 -1
package/lib/api/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
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]; } };
|
|
7
|
+
}
|
|
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);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./rest/index"), exports);
|
|
18
|
+
__exportStar(require("./rest/types"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { EventLogger } from 'gd-eventlog';
|
|
3
|
+
import { ApiClientInitProps } from './types';
|
|
4
|
+
export declare class ApiClient {
|
|
5
|
+
static _instance: any;
|
|
6
|
+
protected axios: AxiosInstance;
|
|
7
|
+
protected logger: EventLogger;
|
|
8
|
+
protected requests: Array<{
|
|
9
|
+
tid: string;
|
|
10
|
+
ts: number;
|
|
11
|
+
}>;
|
|
12
|
+
static getInstance(): ApiClient;
|
|
13
|
+
static getClient(): AxiosInstance;
|
|
14
|
+
init(props: ApiClientInitProps): void;
|
|
15
|
+
client(): AxiosInstance;
|
|
16
|
+
protected onRequest(req: any): any;
|
|
17
|
+
protected onResponse(res: any): any;
|
|
18
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ApiClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
9
|
+
const uuid_1 = require("uuid");
|
|
10
|
+
class ApiClient {
|
|
11
|
+
static getInstance() {
|
|
12
|
+
if (!ApiClient._instance) {
|
|
13
|
+
ApiClient._instance = new ApiClient();
|
|
14
|
+
}
|
|
15
|
+
return ApiClient._instance;
|
|
16
|
+
}
|
|
17
|
+
static getClient() {
|
|
18
|
+
return ApiClient.getInstance().client();
|
|
19
|
+
}
|
|
20
|
+
init(props) {
|
|
21
|
+
const { uuid, apiKey, requestLog = true, version, appVersion, channel = 'desktop' } = props;
|
|
22
|
+
const headers = {
|
|
23
|
+
"X-uuid": uuid,
|
|
24
|
+
"X-API-Key": apiKey,
|
|
25
|
+
"x-app-channel": channel,
|
|
26
|
+
"x-app-version": appVersion,
|
|
27
|
+
"x-react-version": version
|
|
28
|
+
};
|
|
29
|
+
this.axios = axios_1.default.create({ headers });
|
|
30
|
+
if (requestLog) {
|
|
31
|
+
this.logger = new gd_eventlog_1.EventLogger('API');
|
|
32
|
+
this.requests = [];
|
|
33
|
+
this.axios.interceptors.request.use((req) => this.onRequest(req));
|
|
34
|
+
this.axios.interceptors.response.use((res) => this.onResponse(res));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
client() {
|
|
38
|
+
if (this.axios)
|
|
39
|
+
return this.axios;
|
|
40
|
+
return axios_1.default;
|
|
41
|
+
}
|
|
42
|
+
onRequest(req) {
|
|
43
|
+
if (!req)
|
|
44
|
+
return;
|
|
45
|
+
try {
|
|
46
|
+
const ts = Date.now();
|
|
47
|
+
const tid = (0, uuid_1.v4)();
|
|
48
|
+
req.headers['x-transaction-id'] = tid;
|
|
49
|
+
this.requests.push({ tid, ts });
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
this.logger.logEvent({ message: 'error', fn: 'onRequest()', error: err.message || err, stack: err.stack });
|
|
53
|
+
}
|
|
54
|
+
return req;
|
|
55
|
+
}
|
|
56
|
+
onResponse(res) {
|
|
57
|
+
if (!res)
|
|
58
|
+
return;
|
|
59
|
+
try {
|
|
60
|
+
const { config, status } = res || {};
|
|
61
|
+
const { headers = {}, url, method, params } = config;
|
|
62
|
+
const tid = headers['x-transaction-id'];
|
|
63
|
+
if (!tid)
|
|
64
|
+
return res;
|
|
65
|
+
const idx = this.requests.findIndex(r => r.tid === tid);
|
|
66
|
+
if (idx !== -1) {
|
|
67
|
+
const tsStart = this.requests[idx].ts;
|
|
68
|
+
this.requests.splice(idx, 1);
|
|
69
|
+
this.logger.logEvent({ message: 'api call', method, url, tid, status, duration: Date.now() - tsStart, params });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
this.logger.logEvent({ message: 'error', fn: 'onResponse', error: err.message || err, stack: err.stack });
|
|
74
|
+
}
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.ApiClient = ApiClient;
|
|
79
|
+
ApiClient._instance = null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import { EventLogger } from 'gd-eventlog';
|
|
4
|
+
export declare class IncyclistService extends EventEmitter {
|
|
5
|
+
protected logger: EventLogger;
|
|
6
|
+
protected debug: any;
|
|
7
|
+
constructor(serviceName: string);
|
|
8
|
+
protected logEvent(event: any): void;
|
|
9
|
+
protected setDebug(enabled: boolean): void;
|
|
10
|
+
protected logError(err: Error, fn: string, args?: any): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IncyclistService = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
9
|
+
class IncyclistService extends events_1.default {
|
|
10
|
+
constructor(serviceName) {
|
|
11
|
+
super();
|
|
12
|
+
this.logger = new gd_eventlog_1.EventLogger(serviceName);
|
|
13
|
+
this.debug = false;
|
|
14
|
+
}
|
|
15
|
+
logEvent(event) {
|
|
16
|
+
this.logger.logEvent(event);
|
|
17
|
+
this.emit('log', event);
|
|
18
|
+
const w = global.window;
|
|
19
|
+
if (this.debug || (w === null || w === void 0 ? void 0 : w.SERVICE_DEBUG) || process.env.DEBUG)
|
|
20
|
+
console.log(`~~~ ${this.logger.getName().toUpperCase()}-SVC`, event);
|
|
21
|
+
}
|
|
22
|
+
setDebug(enabled) {
|
|
23
|
+
this.debug = enabled;
|
|
24
|
+
}
|
|
25
|
+
logError(err, fn, args) {
|
|
26
|
+
const logInfo = args || {};
|
|
27
|
+
this.logger.logEvent(Object.assign(Object.assign({ message: 'Error', fn }, logInfo), { error: err.message, stack: err.stack }));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.IncyclistService = IncyclistService;
|
|
@@ -105,19 +105,27 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
105
105
|
verifyCapabilitySettings() {
|
|
106
106
|
const { capabilities } = this.settings;
|
|
107
107
|
const isNewUi = this.isNewUi();
|
|
108
|
+
const bikeCapIdx = capabilities.findIndex(c => c.capability === 'bike');
|
|
108
109
|
if (isNewUi) {
|
|
109
|
-
const bikeCapIdx = capabilities.findIndex(c => c.capability === 'bike');
|
|
110
110
|
if (bikeCapIdx !== -1) {
|
|
111
111
|
capabilities.splice(bikeCapIdx, 1);
|
|
112
112
|
}
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
|
+
else {
|
|
116
|
+
if (bikeCapIdx === -1) {
|
|
117
|
+
const control = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control && c.selected !== undefined);
|
|
118
|
+
const bike = Object.assign({}, control);
|
|
119
|
+
bike.capability = 'bike';
|
|
120
|
+
capabilities.push(bike);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const bikeCap = capabilities.find(c => c.capability === 'bike');
|
|
115
124
|
for (const capability of ['bike', incyclist_devices_1.IncyclistCapability.Control]) {
|
|
116
125
|
const info = capabilities.find(c => c.capability === capability);
|
|
117
126
|
if (info && info.devices.length > 0 && info.selected === undefined)
|
|
118
127
|
this.select(info.devices[0], capability);
|
|
119
128
|
}
|
|
120
|
-
const bikeCap = capabilities.find(c => c.capability === 'bike');
|
|
121
129
|
if (bikeCap && bikeCap.selected) {
|
|
122
130
|
const bike = bikeCap.selected;
|
|
123
131
|
const power = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Power && c.selected !== undefined);
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { DeviceAccessService } from "../access/service";
|
|
3
2
|
import { AdapterInfo, CapabilityInformation, DeviceConfigurationInfo, DeviceConfigurationService, IncyclistDeviceSettings, InterfaceSetting } from "../configuration";
|
|
4
3
|
import { CapabilityData, DevicePairingData, DevicePairingStatus, DeviceSelectState, InternalPairingState, PairingProps, PairingSettings, PairingState } from "./model";
|
|
5
|
-
import { EventLogger } from 'gd-eventlog';
|
|
6
4
|
import { DeviceData, IncyclistCapability, IncyclistDeviceAdapter } from "incyclist-devices";
|
|
7
5
|
import { AdapterStateInfo, DeviceRideService } from "../ride";
|
|
8
|
-
import
|
|
6
|
+
import { IncyclistService } from "../../base/service";
|
|
9
7
|
export declare const mappedCapability: (c: CapabilityInformation) => CapabilityData;
|
|
10
8
|
export declare const mappedCapabilities: (capabilities: DeviceConfigurationInfo) => Array<CapabilityData>;
|
|
11
9
|
export interface Services {
|
|
@@ -13,13 +11,11 @@ export interface Services {
|
|
|
13
11
|
access?: DeviceAccessService;
|
|
14
12
|
ride?: DeviceRideService;
|
|
15
13
|
}
|
|
16
|
-
export declare class DevicePairingService extends
|
|
14
|
+
export declare class DevicePairingService extends IncyclistService {
|
|
17
15
|
protected static _instance: DevicePairingService;
|
|
18
16
|
protected configuration: DeviceConfigurationService;
|
|
19
17
|
protected access: DeviceAccessService;
|
|
20
18
|
protected rideService: DeviceRideService;
|
|
21
|
-
protected logger: EventLogger;
|
|
22
|
-
protected debug: any;
|
|
23
19
|
protected settings: PairingSettings;
|
|
24
20
|
protected state: InternalPairingState;
|
|
25
21
|
protected deviceSelectState: DeviceSelectState | null;
|
|
@@ -45,9 +41,6 @@ export declare class DevicePairingService extends EventEmitter {
|
|
|
45
41
|
changeInterfaceSettings(name: string, settings: InterfaceSetting): Promise<void>;
|
|
46
42
|
private restart;
|
|
47
43
|
protected _stop(): Promise<void>;
|
|
48
|
-
protected logEvent(event: any): void;
|
|
49
|
-
protected setDebug(enabled: boolean): void;
|
|
50
|
-
protected logError(err: Error, fn: string): void;
|
|
51
44
|
protected getCapability(capability: IncyclistCapability | CapabilityData): CapabilityData;
|
|
52
45
|
protected getCapabilityDevice(capability: IncyclistCapability | CapabilityData, udid?: string): DevicePairingData;
|
|
53
46
|
protected onConfigLoaded(capabilitiesLoaded: DeviceConfigurationInfo, interfacesLoaded: Array<InterfaceSetting>): Promise<void>;
|
|
@@ -59,7 +52,7 @@ export declare class DevicePairingService extends EventEmitter {
|
|
|
59
52
|
protected onConfigurationUpdate(newCapabilities: DeviceConfigurationInfo): void;
|
|
60
53
|
protected onInterfaceStateChanged(ifName: any, ifDetails: any, interfacesNew?: any): Promise<any>;
|
|
61
54
|
protected isInterfaceEnabled(target: string | InterfaceSetting): boolean;
|
|
62
|
-
protected logCapabilities(capabilities
|
|
55
|
+
protected logCapabilities(capabilities?: Array<CapabilityData>): CapabilityData[];
|
|
63
56
|
protected initPairingCallbacks(): void;
|
|
64
57
|
protected removePairingCallbacks(): void;
|
|
65
58
|
protected initScanningCallbacks(): void;
|
|
@@ -15,12 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.useDevicePairing = exports.DevicePairingService = exports.mappedCapabilities = exports.mappedCapability = void 0;
|
|
16
16
|
const service_1 = require("../access/service");
|
|
17
17
|
const configuration_1 = require("../configuration");
|
|
18
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
19
18
|
const incyclist_devices_1 = require("incyclist-devices");
|
|
20
19
|
const ride_1 = require("../ride");
|
|
21
20
|
const clone_1 = __importDefault(require("../../utils/clone"));
|
|
22
|
-
const events_1 = __importDefault(require("events"));
|
|
23
21
|
const utils_1 = require("incyclist-devices/lib/utils/utils");
|
|
22
|
+
const service_2 = require("../../base/service");
|
|
24
23
|
const Units = [
|
|
25
24
|
{ capability: incyclist_devices_1.IncyclistCapability.HeartRate, unit: 'bpm', value: 'heartrate', decimals: 0 },
|
|
26
25
|
{ capability: incyclist_devices_1.IncyclistCapability.Power, unit: 'W', value: 'power', decimals: 0 },
|
|
@@ -54,14 +53,14 @@ const getInterfaceSettings = (ifName, v) => {
|
|
|
54
53
|
return {};
|
|
55
54
|
return v.find(i => i.name === ifName);
|
|
56
55
|
};
|
|
57
|
-
class DevicePairingService extends
|
|
56
|
+
class DevicePairingService extends service_2.IncyclistService {
|
|
58
57
|
static getInstance() {
|
|
59
58
|
if (!DevicePairingService._instance)
|
|
60
59
|
DevicePairingService._instance = new DevicePairingService();
|
|
61
60
|
return DevicePairingService._instance;
|
|
62
61
|
}
|
|
63
62
|
constructor(services) {
|
|
64
|
-
super();
|
|
63
|
+
super('Pairing');
|
|
65
64
|
this.settings = {};
|
|
66
65
|
this.state = { initialized: false };
|
|
67
66
|
this.deviceSelectState = null;
|
|
@@ -79,8 +78,6 @@ class DevicePairingService extends events_1.default {
|
|
|
79
78
|
this.rideService = services.ride;
|
|
80
79
|
}
|
|
81
80
|
this.state.initialized = false;
|
|
82
|
-
this.logger = new gd_eventlog_1.EventLogger('Pairing');
|
|
83
|
-
this.debug = false;
|
|
84
81
|
}
|
|
85
82
|
start(onStateChanged) {
|
|
86
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -97,6 +94,7 @@ class DevicePairingService extends events_1.default {
|
|
|
97
94
|
this.state.canStartRide = this.configuration.canStartRide();
|
|
98
95
|
this.state.stopRequested = false;
|
|
99
96
|
this.state.stopped = false;
|
|
97
|
+
this.logCapabilities();
|
|
100
98
|
this.state.interfaces.forEach(i => {
|
|
101
99
|
if (!this.isInterfaceEnabled(i.name))
|
|
102
100
|
this.disableAdaptersOnInterface(i.name);
|
|
@@ -267,19 +265,6 @@ class DevicePairingService extends events_1.default {
|
|
|
267
265
|
yield this.stopScanning();
|
|
268
266
|
});
|
|
269
267
|
}
|
|
270
|
-
logEvent(event) {
|
|
271
|
-
this.logger.logEvent(event);
|
|
272
|
-
this.emit('log', event);
|
|
273
|
-
const w = global.window;
|
|
274
|
-
if (this.debug || (w === null || w === void 0 ? void 0 : w.SERVICE_DEBUG) || process.env.DEBUG)
|
|
275
|
-
console.log('~~~ PAIRING-SVC', event);
|
|
276
|
-
}
|
|
277
|
-
setDebug(enabled) {
|
|
278
|
-
this.debug = enabled;
|
|
279
|
-
}
|
|
280
|
-
logError(err, fn) {
|
|
281
|
-
this.logger.logEvent({ message: 'Error', fn, error: err.message, stack: err.stack });
|
|
282
|
-
}
|
|
283
268
|
getCapability(capability) {
|
|
284
269
|
const target = typeof capability === 'object' ? capability.capability : capability;
|
|
285
270
|
const { capabilities = [] } = this.state;
|
|
@@ -316,16 +301,16 @@ class DevicePairingService extends events_1.default {
|
|
|
316
301
|
this.onScanningDataHandler = this.rideService.onData.bind(this.rideService);
|
|
317
302
|
this.configuration = this.configuration || (0, configuration_1.useDeviceConfiguration)();
|
|
318
303
|
if (this.configuration.isInitialized()) {
|
|
319
|
-
this.logCapabilities(this.state.capabilities);
|
|
320
304
|
this.state.initialized = true;
|
|
321
305
|
return done();
|
|
322
306
|
}
|
|
323
|
-
|
|
324
|
-
this.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
307
|
+
else {
|
|
308
|
+
this.configuration.once('initialized', (capabilitiesLoaded, interfacesLoaded) => {
|
|
309
|
+
this.onConfigLoaded(capabilitiesLoaded, interfacesLoaded);
|
|
310
|
+
done();
|
|
311
|
+
});
|
|
312
|
+
this.configuration.init();
|
|
313
|
+
}
|
|
329
314
|
});
|
|
330
315
|
}
|
|
331
316
|
getExternaState(toEmit) {
|
|
@@ -452,7 +437,7 @@ class DevicePairingService extends events_1.default {
|
|
|
452
437
|
return interfaces.find(i => i.name === name && i.enabled && i.state !== 'unavailable') !== undefined;
|
|
453
438
|
}
|
|
454
439
|
logCapabilities(capabilities) {
|
|
455
|
-
const ci = capabilities ||
|
|
440
|
+
const ci = capabilities || this.state.capabilities;
|
|
456
441
|
ci.forEach(c => {
|
|
457
442
|
var _a;
|
|
458
443
|
const { devices = [], disabled } = c;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -22,3 +22,5 @@ Object.defineProperty(exports, "useUserSettings", { enumerable: true, get: funct
|
|
|
22
22
|
Object.defineProperty(exports, "initUserSettings", { enumerable: true, get: function () { return settings_1.initUserSettings; } });
|
|
23
23
|
Object.defineProperty(exports, "UserSettingsService", { enumerable: true, get: function () { return settings_1.UserSettingsService; } });
|
|
24
24
|
Object.defineProperty(exports, "UserSettingsBinding", { enumerable: true, get: function () { return settings_1.UserSettingsBinding; } });
|
|
25
|
+
__exportStar(require("./api"), exports);
|
|
26
|
+
__exportStar(require("./routes"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NO_CACHE = exports.DEFAULT_ROUTE_API = exports.ROUTE_API = void 0;
|
|
4
|
+
const DEFAULT_ROUTE_API_PROD = 'https://dlws.incyclist.com/api/v1/routes';
|
|
5
|
+
exports.ROUTE_API = 'ROUTE_API';
|
|
6
|
+
exports.DEFAULT_ROUTE_API = DEFAULT_ROUTE_API_PROD;
|
|
7
|
+
exports.NO_CACHE = {
|
|
8
|
+
headers: {
|
|
9
|
+
'Cache-Control': 'no-cache',
|
|
10
|
+
'Pragma': 'no-cache',
|
|
11
|
+
'Expires': '0',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventLogger } from 'gd-eventlog';
|
|
2
|
+
import { RouteApiDescription, RouteApiDetail, RouteDescriptionQuery } from "./types";
|
|
3
|
+
import { AxiosInstance } from "axios";
|
|
4
|
+
import { RoutePoint } from '../types';
|
|
5
|
+
export default class IncyclistRoutesApi {
|
|
6
|
+
protected static _instance: any;
|
|
7
|
+
static getInstance(): IncyclistRoutesApi;
|
|
8
|
+
protected logger: EventLogger;
|
|
9
|
+
protected api: AxiosInstance;
|
|
10
|
+
constructor();
|
|
11
|
+
protected logError(err: Error, fn: string, logInfo?: any): void;
|
|
12
|
+
protected getApi(): AxiosInstance;
|
|
13
|
+
protected getBaseUrl(): any;
|
|
14
|
+
getRouteDescriptions(query: RouteDescriptionQuery): Promise<Array<RouteApiDescription>>;
|
|
15
|
+
fixMissingRouteDistances(points: Array<RoutePoint>): void;
|
|
16
|
+
getRouteDetails(routeId: string): Promise<RouteApiDetail>;
|
|
17
|
+
reload(): Promise<any>;
|
|
18
|
+
protected _get(url: string, ...args: any[]): Promise<import("axios").AxiosResponse<any, any>>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
13
|
+
const consts_1 = require("./consts");
|
|
14
|
+
const api_1 = require("../../../api");
|
|
15
|
+
const settings_1 = require("../../../settings");
|
|
16
|
+
class IncyclistRoutesApi {
|
|
17
|
+
static getInstance() {
|
|
18
|
+
if (!IncyclistRoutesApi._instance)
|
|
19
|
+
IncyclistRoutesApi._instance = new IncyclistRoutesApi();
|
|
20
|
+
return IncyclistRoutesApi._instance;
|
|
21
|
+
}
|
|
22
|
+
constructor() {
|
|
23
|
+
this.logger = new gd_eventlog_1.EventLogger('RouteListApi');
|
|
24
|
+
}
|
|
25
|
+
logError(err, fn, logInfo) {
|
|
26
|
+
const args = logInfo || {};
|
|
27
|
+
this.logger.logEvent(Object.assign({ message: 'Error', error: err.message, fn }, args));
|
|
28
|
+
console.log(err);
|
|
29
|
+
}
|
|
30
|
+
getApi() {
|
|
31
|
+
if (!this.api) {
|
|
32
|
+
this.api = api_1.ApiClient.getClient();
|
|
33
|
+
return this.api;
|
|
34
|
+
}
|
|
35
|
+
return this.api;
|
|
36
|
+
}
|
|
37
|
+
getBaseUrl() {
|
|
38
|
+
return (0, settings_1.useUserSettings)().get(consts_1.ROUTE_API, consts_1.DEFAULT_ROUTE_API);
|
|
39
|
+
}
|
|
40
|
+
getRouteDescriptions(query) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const { type = 'gpx', category } = query;
|
|
43
|
+
let url = (type === 'gpx') ? `?private=false` : `/?type=${type}`;
|
|
44
|
+
if (category)
|
|
45
|
+
url += "&category=${category}";
|
|
46
|
+
try {
|
|
47
|
+
const res = yield this._get(url, consts_1.NO_CACHE);
|
|
48
|
+
return res.data;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
this.logError(err, 'getRouteDescriptions', { query });
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
fixMissingRouteDistances(points) {
|
|
57
|
+
let routeDistance = 0;
|
|
58
|
+
points.forEach((p) => {
|
|
59
|
+
if (!p.routeDistance)
|
|
60
|
+
p.routeDistance = routeDistance;
|
|
61
|
+
routeDistance = p.routeDistance + p['distance'];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
getRouteDetails(routeId) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
try {
|
|
67
|
+
const res = yield this._get(`/${routeId}`);
|
|
68
|
+
if (res.data['decoded']) {
|
|
69
|
+
res.data.points = res.data['decoded'];
|
|
70
|
+
delete res.data['decoded'];
|
|
71
|
+
this.fixMissingRouteDistances(res.data.points);
|
|
72
|
+
}
|
|
73
|
+
return res.data;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
this.logError(err, 'getRouteDetails', { routeId });
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
reload() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
try {
|
|
84
|
+
this._get(`/reload`);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
this.logError(err, 'reload');
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
_get(url, ...args) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const api = this.getApi();
|
|
95
|
+
const baseUrl = this.getBaseUrl();
|
|
96
|
+
return yield api.get(baseUrl + url, ...args);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.default = IncyclistRoutesApi;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { LocalizedText } from "../../list";
|
|
2
|
+
import { RouteCategory, RoutePoint, RouteProvider, RouteType, VideoDescription } from "../types";
|
|
3
|
+
export type RouteDescriptionQuery = {
|
|
4
|
+
category?: string;
|
|
5
|
+
categories?: Array<string>;
|
|
6
|
+
type: RouteType;
|
|
7
|
+
};
|
|
8
|
+
export type RouteApiDescription = {
|
|
9
|
+
id: string;
|
|
10
|
+
routeId?: string;
|
|
11
|
+
hash?: string;
|
|
12
|
+
routeHash?: string;
|
|
13
|
+
title: string;
|
|
14
|
+
private?: boolean;
|
|
15
|
+
country?: string;
|
|
16
|
+
distance?: number;
|
|
17
|
+
elevation?: number;
|
|
18
|
+
points?: {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
version?: string;
|
|
22
|
+
category?: RouteCategory;
|
|
23
|
+
provider?: RouteProvider;
|
|
24
|
+
video?: VideoDescription;
|
|
25
|
+
type?: RouteType;
|
|
26
|
+
localizedTitle?: LocalizedText;
|
|
27
|
+
};
|
|
28
|
+
export type RouteApiDetail = {
|
|
29
|
+
id: string;
|
|
30
|
+
routeId?: string;
|
|
31
|
+
hash?: string;
|
|
32
|
+
routeHash?: string;
|
|
33
|
+
title: string;
|
|
34
|
+
private?: boolean;
|
|
35
|
+
country?: string;
|
|
36
|
+
distance?: number;
|
|
37
|
+
elevation?: number;
|
|
38
|
+
points?: Array<RoutePoint>;
|
|
39
|
+
downloadUrl?: string;
|
|
40
|
+
downloadType: string;
|
|
41
|
+
version?: string;
|
|
42
|
+
category?: RouteCategory;
|
|
43
|
+
provider?: RouteProvider;
|
|
44
|
+
video?: VideoDescription;
|
|
45
|
+
localizedTitle?: LocalizedText;
|
|
46
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type RouteType = 'gpx' | 'video';
|
|
2
|
+
export type RouteCategory = 'Free' | 'Demo';
|
|
3
|
+
export type RouteState = 'prepared' | 'loading' | 'loaded' | 'error';
|
|
4
|
+
export type RouteProvider = {
|
|
5
|
+
name: string;
|
|
6
|
+
url: string;
|
|
7
|
+
logo: string;
|
|
8
|
+
};
|
|
9
|
+
export type VideoMapping = {
|
|
10
|
+
videoSpeed: number;
|
|
11
|
+
time: number;
|
|
12
|
+
frame: number;
|
|
13
|
+
distance: number;
|
|
14
|
+
};
|
|
15
|
+
export type RouteInfoText = {
|
|
16
|
+
distance: number;
|
|
17
|
+
localizedText: any;
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
export type VideoDescription = {
|
|
21
|
+
file: string;
|
|
22
|
+
url: string;
|
|
23
|
+
framerate: number;
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
segments: any;
|
|
27
|
+
informations: any;
|
|
28
|
+
mappings: VideoMapping;
|
|
29
|
+
format: string;
|
|
30
|
+
selectableSegments: any;
|
|
31
|
+
infoTexts: RouteInfoText;
|
|
32
|
+
};
|
|
33
|
+
export type RoutePoint = {
|
|
34
|
+
lat: number;
|
|
35
|
+
lng: number;
|
|
36
|
+
routeDistance: number;
|
|
37
|
+
elevation: number;
|
|
38
|
+
slope: number;
|
|
39
|
+
};
|
|
40
|
+
export type RouteSegment = {
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
name: string;
|
|
44
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocalizedData = void 0;
|
|
4
|
+
const getLocalizedData = (data, language = 'en') => {
|
|
5
|
+
const updated = Object.assign({}, data);
|
|
6
|
+
if (language && data.localizedTitle) {
|
|
7
|
+
updated.title = data.localizedTitle[language];
|
|
8
|
+
delete updated.localizedTitle;
|
|
9
|
+
}
|
|
10
|
+
return updated;
|
|
11
|
+
};
|
|
12
|
+
exports.getLocalizedData = getLocalizedData;
|