incyclist-services 1.0.42 → 1.0.44

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 (48) hide show
  1. package/lib/api/index.d.ts +2 -0
  2. package/lib/api/index.js +18 -0
  3. package/lib/api/rest/index.d.ts +18 -0
  4. package/lib/api/rest/index.js +79 -0
  5. package/lib/api/rest/types.d.ts +9 -0
  6. package/lib/api/rest/types.js +2 -0
  7. package/lib/base/service.d.ts +11 -0
  8. package/lib/base/service.js +30 -0
  9. package/lib/devices/configuration/service.js +10 -2
  10. package/lib/devices/pairing/service.d.ts +2 -9
  11. package/lib/devices/pairing/service.js +3 -19
  12. package/lib/index.d.ts +2 -0
  13. package/lib/index.js +2 -0
  14. package/lib/routes/base/api/consts.d.ts +9 -0
  15. package/lib/routes/base/api/consts.js +13 -0
  16. package/lib/routes/base/api/index.d.ts +19 -0
  17. package/lib/routes/base/api/index.js +100 -0
  18. package/lib/routes/base/api/types.d.ts +46 -0
  19. package/lib/routes/base/api/types.js +2 -0
  20. package/lib/routes/base/types/index.d.ts +44 -0
  21. package/lib/routes/base/types/index.js +2 -0
  22. package/lib/routes/base/utils/localization.d.ts +2 -0
  23. package/lib/routes/base/utils/localization.js +12 -0
  24. package/lib/routes/base/utils/route.d.ts +4 -0
  25. package/lib/routes/base/utils/route.js +52 -0
  26. package/lib/routes/index.d.ts +1 -0
  27. package/lib/routes/index.js +17 -0
  28. package/lib/routes/list/bindings/mock.d.ts +9 -0
  29. package/lib/routes/list/bindings/mock.js +32 -0
  30. package/lib/routes/list/consts.d.ts +0 -0
  31. package/lib/routes/list/consts.js +0 -0
  32. package/lib/routes/list/index.d.ts +2 -0
  33. package/lib/routes/list/index.js +18 -0
  34. package/lib/routes/list/repository.d.ts +0 -0
  35. package/lib/routes/list/repository.js +0 -0
  36. package/lib/routes/list/service.d.ts +78 -0
  37. package/lib/routes/list/service.js +513 -0
  38. package/lib/routes/list/types.d.ts +83 -0
  39. package/lib/routes/list/types.js +2 -0
  40. package/lib/routes/utils/localization.d.ts +2 -0
  41. package/lib/routes/utils/localization.js +12 -0
  42. package/lib/utils/geo.d.ts +13 -0
  43. package/lib/utils/geo.js +55 -0
  44. package/lib/utils/index.d.ts +2 -0
  45. package/lib/utils/index.js +15 -0
  46. package/lib/utils/math.d.ts +6 -0
  47. package/lib/utils/math.js +28 -0
  48. package/package.json +2 -1
@@ -0,0 +1,2 @@
1
+ export * from './rest/index';
2
+ export * from './rest/types';
@@ -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,9 @@
1
+ export type AppChannel = 'desktop' | 'mobile' | 'web' | 'tv' | 'backend';
2
+ export type ApiClientInitProps = {
3
+ uuid: string;
4
+ apiKey: string;
5
+ version: string;
6
+ appVersion: string;
7
+ requestLog?: boolean;
8
+ channel?: AppChannel;
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 EventEmitter from "events";
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 EventEmitter {
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>;
@@ -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 events_1.default {
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* () {
@@ -268,19 +265,6 @@ class DevicePairingService extends events_1.default {
268
265
  yield this.stopScanning();
269
266
  });
270
267
  }
271
- logEvent(event) {
272
- this.logger.logEvent(event);
273
- this.emit('log', event);
274
- const w = global.window;
275
- if (this.debug || (w === null || w === void 0 ? void 0 : w.SERVICE_DEBUG) || process.env.DEBUG)
276
- console.log('~~~ PAIRING-SVC', event);
277
- }
278
- setDebug(enabled) {
279
- this.debug = enabled;
280
- }
281
- logError(err, fn) {
282
- this.logger.logEvent({ message: 'Error', fn, error: err.message, stack: err.stack });
283
- }
284
268
  getCapability(capability) {
285
269
  const target = typeof capability === 'object' ? capability.capability : capability;
286
270
  const { capabilities = [] } = this.state;
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './devices';
2
2
  export * from './utils';
3
3
  export { useUserSettings, initUserSettings, UserSettingsService, UserSettingsBinding, IUserSettingsBinding } from './settings';
4
+ export * from './api';
5
+ export * from './routes';
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,9 @@
1
+ export declare const ROUTE_API = "ROUTE_API";
2
+ export declare const DEFAULT_ROUTE_API = "https://dlws.incyclist.com/api/v1/routes";
3
+ export declare const NO_CACHE: {
4
+ headers: {
5
+ 'Cache-Control': string;
6
+ Pragma: string;
7
+ Expires: string;
8
+ };
9
+ };
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { RouteInfo } from "../../list/types";
2
+ export declare const getLocalizedData: (data: RouteInfo, language?: string) => RouteInfo;
@@ -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;
@@ -0,0 +1,4 @@
1
+ import { Route } from "../../list";
2
+ import { RouteSegment } from "../types";
3
+ export declare const checkIsLoop: (route: Route) => boolean;
4
+ export declare const getSegments: (route: Route) => Array<RouteSegment>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSegments = exports.checkIsLoop = void 0;
4
+ const geo_1 = require("../../../utils/geo");
5
+ const MAX_LAPMODE_DISTANCE = 50;
6
+ const checkIsLoop = (route) => {
7
+ var _a;
8
+ const { data, details } = route;
9
+ if (!((_a = details === null || details === void 0 ? void 0 : details.points) === null || _a === void 0 ? void 0 : _a.length)) {
10
+ data.isLoop = false;
11
+ return false;
12
+ }
13
+ const points = details.points;
14
+ const maxDistance = MAX_LAPMODE_DISTANCE;
15
+ const p1 = points[0];
16
+ const p2 = points[points.length - 1];
17
+ if (p1 === undefined || p2 === undefined) {
18
+ data.isLoop = false;
19
+ return false;
20
+ }
21
+ const dist = Math.abs((0, geo_1.calculateDistance)(p1.lat, p1.lng, p2.lat, p2.lng));
22
+ data.isLoop = (dist <= maxDistance);
23
+ return data.isLoop;
24
+ };
25
+ exports.checkIsLoop = checkIsLoop;
26
+ const getSegments = (route) => {
27
+ var _a;
28
+ const { data, details } = route;
29
+ if (data === null || data === void 0 ? void 0 : data.segments) {
30
+ return data.segments;
31
+ }
32
+ if ((_a = details === null || details === void 0 ? void 0 : details.video) === null || _a === void 0 ? void 0 : _a.segments) {
33
+ const segments = [];
34
+ details.video.segments.forEach(sx => {
35
+ if (!sx || typeof sx !== 'object')
36
+ return;
37
+ const additional = sx.segment.map(s => {
38
+ const segment = s['$'];
39
+ if (segment.start !== undefined)
40
+ segment.start = parseInt(segment.start);
41
+ if (segment.end !== undefined)
42
+ segment.end = parseInt(segment.end);
43
+ return segment;
44
+ });
45
+ segments.push(...additional);
46
+ });
47
+ if (data)
48
+ data.segments = segments;
49
+ return segments;
50
+ }
51
+ };
52
+ exports.getSegments = getSegments;
@@ -0,0 +1 @@
1
+ export * from './list';