incyclist-services 1.2.3 → 1.3.1
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/activities/base/api/fitconvert.js +2 -2
- package/lib/activities/base/repo/db.js +3 -3
- package/lib/activities/index.d.ts +1 -0
- package/lib/activities/index.js +1 -0
- package/lib/activities/ride/service.js +8 -9
- package/lib/activities/upload/index.d.ts +2 -0
- package/lib/activities/upload/index.js +18 -0
- package/lib/activities/upload/types.d.ts +8 -0
- package/lib/activities/upload/types.js +2 -0
- package/lib/activities/upload/velohero.d.ts +25 -0
- package/lib/activities/upload/velohero.js +231 -0
- package/lib/api/appInfo/index.d.ts +3 -0
- package/lib/api/bindings/index.d.ts +4 -0
- package/lib/api/bindings/secret/index.d.ts +3 -0
- package/lib/api/bindings/secret/index.js +2 -0
- package/lib/api/form/index.d.ts +6 -0
- package/lib/api/form/index.js +2 -0
- package/lib/api/rest/ApiClient.d.ts +18 -0
- package/lib/api/rest/ApiClient.js +77 -0
- package/lib/api/rest/IncyclistRestApiClient.d.ts +5 -0
- package/lib/api/rest/IncyclistRestApiClient.js +87 -0
- package/lib/api/rest/RestApiClient.d.ts +7 -0
- package/lib/api/rest/RestApiClient.js +15 -0
- package/lib/api/rest/api.d.ts +15 -0
- package/lib/api/rest/api.js +69 -0
- package/lib/api/rest/incyclist.d.ts +7 -0
- package/lib/api/rest/incyclist.js +36 -0
- package/lib/api/rest/index.d.ts +3 -18
- package/lib/api/rest/index.js +16 -76
- package/lib/api/rest/types.d.ts +1 -1
- package/lib/apps/base/api/base.d.ts +12 -0
- package/lib/apps/base/api/base.js +56 -0
- package/lib/apps/base/api/index.d.ts +1 -0
- package/lib/apps/base/api/index.js +17 -0
- package/lib/apps/base/api/strava/api.d.ts +4 -0
- package/lib/apps/base/api/strava/api.js +16 -0
- package/lib/apps/base/api/strava/index.d.ts +1 -0
- package/lib/apps/base/api/strava/index.js +17 -0
- package/lib/apps/base/api/velohero/api.d.ts +12 -0
- package/lib/apps/base/api/velohero/api.js +94 -0
- package/lib/apps/base/api/velohero/index.d.ts +2 -0
- package/lib/apps/base/api/velohero/index.js +18 -0
- package/lib/apps/base/api/velohero/types.d.ts +12 -0
- package/lib/apps/base/api/velohero/types.js +2 -0
- package/lib/devices/access/service.js +11 -11
- package/lib/devices/configuration/service.js +1 -1
- package/lib/devices/pairing/service.js +9 -9
- package/lib/devices/ride/service.js +4 -4
- package/lib/i18n/countries/index.js +1 -1
- package/lib/routes/base/api/index.js +2 -2
- package/lib/routes/base/model/route.d.ts +1 -0
- package/lib/routes/base/model/route.js +4 -0
- package/lib/routes/base/parsers/gpx.js +1 -1
- package/lib/routes/base/parsers/xml.js +3 -3
- package/lib/routes/base/utils/route.d.ts +1 -1
- package/lib/routes/base/utils/route.js +3 -2
- package/lib/routes/download/service.js +1 -1
- package/lib/routes/list/cards/RouteCard.js +1 -1
- package/lib/routes/list/loaders/DBLoader.js +1 -1
- package/lib/routes/list/loaders/api.js +2 -2
- package/lib/routes/list/loaders/db.js +3 -3
- package/lib/routes/list/service.js +2 -2
- package/lib/workouts/base/api/index.js +1 -1
- package/lib/workouts/list/cards/WorkoutCard.js +2 -2
- package/lib/workouts/list/loaders/db.js +2 -2
- package/package.json +6 -4
|
@@ -11,9 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.IncyclistFitConvertApi = void 0;
|
|
13
13
|
const settings_1 = require("../../../settings");
|
|
14
|
-
const api_1 = require("../../../api");
|
|
15
14
|
const consts_1 = require("./consts");
|
|
16
15
|
const utils_1 = require("../../../utils");
|
|
16
|
+
const api_1 = require("../../../api");
|
|
17
17
|
class IncyclistFitConvertApi {
|
|
18
18
|
convertToFit(data) {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -38,7 +38,7 @@ class IncyclistFitConvertApi {
|
|
|
38
38
|
}
|
|
39
39
|
getApi() {
|
|
40
40
|
if (!this.api) {
|
|
41
|
-
this.api = api_1.
|
|
41
|
+
this.api = api_1.IncyclistRestApiClient.getClient();
|
|
42
42
|
return this.api;
|
|
43
43
|
}
|
|
44
44
|
return this.api;
|
|
@@ -74,8 +74,8 @@ let ActivitiesRepository = (() => {
|
|
|
74
74
|
stopLoad() {
|
|
75
75
|
this.emitDone();
|
|
76
76
|
}
|
|
77
|
-
save(
|
|
78
|
-
return __awaiter(this,
|
|
77
|
+
save(activity_1) {
|
|
78
|
+
return __awaiter(this, arguments, void 0, function* (activity, writeDetails = true) {
|
|
79
79
|
const stringify = (json) => { try {
|
|
80
80
|
JSON.stringify(json);
|
|
81
81
|
}
|
|
@@ -321,8 +321,8 @@ let ActivitiesRepository = (() => {
|
|
|
321
321
|
});
|
|
322
322
|
}
|
|
323
323
|
scanForNewActivities() {
|
|
324
|
-
var _a;
|
|
325
324
|
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
var _a;
|
|
326
326
|
try {
|
|
327
327
|
let names = yield this.listActivities();
|
|
328
328
|
if (!names)
|
package/lib/activities/index.js
CHANGED
|
@@ -257,7 +257,7 @@ let ActivityRideService = (() => {
|
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
259
|
this.current.route.details.points = points;
|
|
260
|
-
(0, route_1.validateRoute)(this.current.route
|
|
260
|
+
(0, route_1.validateRoute)(this.current.route);
|
|
261
261
|
this.current.route.details.distance = points[points.length - 1].routeDistance;
|
|
262
262
|
(0, route_1.addDetails)(this.current.route, this.current.route.details);
|
|
263
263
|
}
|
|
@@ -379,7 +379,7 @@ let ActivityRideService = (() => {
|
|
|
379
379
|
break;
|
|
380
380
|
case 'Route':
|
|
381
381
|
{
|
|
382
|
-
(0, route_1.validateRoute)(selectedRoute
|
|
382
|
+
(0, route_1.validateRoute)(selectedRoute);
|
|
383
383
|
const s = startSettings;
|
|
384
384
|
startPos = s.startPos;
|
|
385
385
|
realityFactor = s.realityFactor;
|
|
@@ -423,7 +423,7 @@ let ActivityRideService = (() => {
|
|
|
423
423
|
return activity;
|
|
424
424
|
}
|
|
425
425
|
updateActivityState() {
|
|
426
|
-
var _a;
|
|
426
|
+
var _a, _b;
|
|
427
427
|
if (this.state !== 'active')
|
|
428
428
|
return;
|
|
429
429
|
const tsNow = Date.now();
|
|
@@ -436,8 +436,9 @@ let ActivityRideService = (() => {
|
|
|
436
436
|
this.activity.distance += distance;
|
|
437
437
|
this.current.routeDistance += distance;
|
|
438
438
|
if (distance !== 0) {
|
|
439
|
-
const
|
|
440
|
-
this.current.position
|
|
439
|
+
const prev = this.current.position;
|
|
440
|
+
const position = (_b = (0, route_1.getNextPosition)(this.current.route, { distance, prev: this.current.position })) !== null && _b !== void 0 ? _b : (0, route_1.getNextPosition)(this.current.route, { routeDistance: this.current.routeDistance });
|
|
441
|
+
this.current.position = position !== null && position !== void 0 ? position : prev;
|
|
441
442
|
if (this.activity.realityFactor > 0) {
|
|
442
443
|
const gain = (0, route_1.getElevationGainAt)(this.current.route, this.current.routeDistance);
|
|
443
444
|
const prevGain = this.current.elevationGainAtPos;
|
|
@@ -487,12 +488,10 @@ let ActivityRideService = (() => {
|
|
|
487
488
|
}
|
|
488
489
|
update() {
|
|
489
490
|
var _a, _b;
|
|
490
|
-
if (this.state !== 'active')
|
|
491
|
-
return;
|
|
492
491
|
const prev = Math.floor(this.activity.time);
|
|
493
492
|
this.updateActivityState();
|
|
494
493
|
const time = Math.floor(this.activity.time);
|
|
495
|
-
if (time !== prev) {
|
|
494
|
+
if (time !== prev && this.state === 'active') {
|
|
496
495
|
const distance = this.current.routeDistance - ((_b = (_a = this.prevEmit) === null || _a === void 0 ? void 0 : _a.routeDistance) !== null && _b !== void 0 ? _b : 0);
|
|
497
496
|
const data = {
|
|
498
497
|
time: this.activity.time,
|
|
@@ -524,10 +523,10 @@ let ActivityRideService = (() => {
|
|
|
524
523
|
title,
|
|
525
524
|
points
|
|
526
525
|
};
|
|
527
|
-
(0, route_1.validateRoute)(details);
|
|
528
526
|
const info = { id, title, hasGpx: true };
|
|
529
527
|
const route = new route_2.Route(info);
|
|
530
528
|
(0, route_1.addDetails)(route, details);
|
|
529
|
+
(0, route_1.validateRoute)(route);
|
|
531
530
|
return route;
|
|
532
531
|
}
|
|
533
532
|
getMode(routeType) {
|
|
@@ -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("./velohero"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IncyclistService } from "../../base/service";
|
|
2
|
+
import { ActivityDetails } from "../base";
|
|
3
|
+
import { VeloHeroAuth } from "./types";
|
|
4
|
+
import { VeloHeroApi } from "../../apps/base/api";
|
|
5
|
+
export declare class VeloHeroUpload extends IncyclistService {
|
|
6
|
+
protected isInitialized: any;
|
|
7
|
+
protected username: any;
|
|
8
|
+
protected password: any;
|
|
9
|
+
protected api: VeloHeroApi;
|
|
10
|
+
protected _isConnecting: any;
|
|
11
|
+
constructor();
|
|
12
|
+
init(): boolean;
|
|
13
|
+
isConnected(): boolean;
|
|
14
|
+
isConnecting(): any;
|
|
15
|
+
login(username: string, password: string): Promise<boolean>;
|
|
16
|
+
disconnect(): void;
|
|
17
|
+
upload(activity: ActivityDetails, format?: string): Promise<boolean>;
|
|
18
|
+
protected getUuid(): any;
|
|
19
|
+
protected getCredentials(): any;
|
|
20
|
+
protected saveCredentials(): any;
|
|
21
|
+
protected encrypt(): VeloHeroAuth;
|
|
22
|
+
protected decrypt(auth: VeloHeroAuth): any;
|
|
23
|
+
protected getUserSettings(): import("../../settings").UserSettingsService;
|
|
24
|
+
protected getApi(): VeloHeroApi;
|
|
25
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
46
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
47
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.VeloHeroUpload = void 0;
|
|
54
|
+
const service_1 = require("../../base/service");
|
|
55
|
+
const types_1 = require("../../base/types");
|
|
56
|
+
const settings_1 = require("../../settings");
|
|
57
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
58
|
+
const valid_1 = require("../../utils/valid");
|
|
59
|
+
const api_1 = require("../../apps/base/api");
|
|
60
|
+
let VeloHeroUpload = (() => {
|
|
61
|
+
let _classDecorators = [types_1.Singleton];
|
|
62
|
+
let _classDescriptor;
|
|
63
|
+
let _classExtraInitializers = [];
|
|
64
|
+
let _classThis;
|
|
65
|
+
let _classSuper = service_1.IncyclistService;
|
|
66
|
+
var VeloHeroUpload = _classThis = class extends _classSuper {
|
|
67
|
+
constructor() {
|
|
68
|
+
super('VeloHeroUpload');
|
|
69
|
+
this.isInitialized = false;
|
|
70
|
+
this.init();
|
|
71
|
+
}
|
|
72
|
+
init() {
|
|
73
|
+
if (this.isInitialized)
|
|
74
|
+
return true;
|
|
75
|
+
try {
|
|
76
|
+
const auth = this.getCredentials();
|
|
77
|
+
if (auth) {
|
|
78
|
+
if (auth.username && auth.password) {
|
|
79
|
+
this.username = auth.username;
|
|
80
|
+
this.password = auth.password;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const user = this.decrypt(auth);
|
|
84
|
+
this.username = user.username;
|
|
85
|
+
this.password = user.password;
|
|
86
|
+
}
|
|
87
|
+
this.logger.logEvent({ message: 'VeloHero init done', hasCredentials: true });
|
|
88
|
+
}
|
|
89
|
+
this.isInitialized = true;
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
this.logger.logEvent({ message: 'error', error: err.message, fn: 'init', stack: err.stack });
|
|
93
|
+
this.isInitialized = false;
|
|
94
|
+
}
|
|
95
|
+
this.on('login-start', () => { this._isConnecting = true; });
|
|
96
|
+
this.on('login-success', () => { this._isConnecting = false; });
|
|
97
|
+
this.on('login-failure', () => { this._isConnecting = false; });
|
|
98
|
+
return this.isInitialized;
|
|
99
|
+
}
|
|
100
|
+
isConnected() {
|
|
101
|
+
return ((0, valid_1.valid)(this.username) && (0, valid_1.valid)(this.password));
|
|
102
|
+
}
|
|
103
|
+
isConnecting() {
|
|
104
|
+
return this._isConnecting;
|
|
105
|
+
}
|
|
106
|
+
login(username, password) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
this.logger.logEvent({ message: 'VeloHero Login' });
|
|
109
|
+
this.emit('login-start');
|
|
110
|
+
try {
|
|
111
|
+
yield this.getApi().login(username, password);
|
|
112
|
+
this.logger.logEvent({ message: 'VeloHero Login success' });
|
|
113
|
+
this.username = username;
|
|
114
|
+
this.password = password;
|
|
115
|
+
this.isInitialized = true;
|
|
116
|
+
const auth = yield this.saveCredentials();
|
|
117
|
+
this.emit('login-success', auth);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
this.logger.logEvent({ message: 'VeloHero Login failed', error: err.message });
|
|
122
|
+
this.emit('login-failure');
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
disconnect() {
|
|
128
|
+
this.username = undefined;
|
|
129
|
+
this.password = undefined;
|
|
130
|
+
this.getUserSettings().set('user.auth.velohero', null);
|
|
131
|
+
}
|
|
132
|
+
upload(activity_1) {
|
|
133
|
+
return __awaiter(this, arguments, void 0, function* (activity, format = 'TCX') {
|
|
134
|
+
try {
|
|
135
|
+
if (!this.isInitialized) {
|
|
136
|
+
const ok = this.init();
|
|
137
|
+
if (!ok)
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
this.logger.logEvent({ message: 'VeloHero Upload', format });
|
|
141
|
+
const username = this.username;
|
|
142
|
+
const password = this.password;
|
|
143
|
+
const fileName = activity[`${format}FileName`];
|
|
144
|
+
yield this.getApi().upload(fileName, { username, password });
|
|
145
|
+
this.logger.logEvent({ message: 'VeloHero Upload success' });
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
this.logger.logEvent({ message: 'VeloHero Upload failure', error: err.message });
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
getUuid() {
|
|
155
|
+
const userSettings = this.getUserSettings();
|
|
156
|
+
try {
|
|
157
|
+
const uuid = userSettings.get('uuid', null);
|
|
158
|
+
return uuid;
|
|
159
|
+
}
|
|
160
|
+
catch (_a) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
getCredentials() {
|
|
165
|
+
const userSettings = this.getUserSettings();
|
|
166
|
+
try {
|
|
167
|
+
return userSettings.get('user.auth.velohero', null);
|
|
168
|
+
}
|
|
169
|
+
catch (_a) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
saveCredentials() {
|
|
174
|
+
this.logger.logEvent({ message: 'VeloHero Save Credentials' });
|
|
175
|
+
let auth;
|
|
176
|
+
try {
|
|
177
|
+
auth = this.encrypt();
|
|
178
|
+
this.getUserSettings().set('user.auth.velohero', auth);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
this.logger.logEvent({ message: 'error', fn: 'saveCredentials', error: err.message, stack: err.stack });
|
|
182
|
+
}
|
|
183
|
+
this.logger.logEvent({ message: 'VeloHero Save Credentials done' });
|
|
184
|
+
return auth;
|
|
185
|
+
}
|
|
186
|
+
encrypt() {
|
|
187
|
+
const iv = crypto_1.default.randomBytes(16);
|
|
188
|
+
const uuid = this.getUuid();
|
|
189
|
+
const key = `${uuid.substring(0, 32)}`;
|
|
190
|
+
const cipher = crypto_1.default.createCipheriv('aes256', key, iv);
|
|
191
|
+
const text = JSON.stringify({ username: this.username, password: this.password });
|
|
192
|
+
let ciphered = cipher.update(text, 'utf8', 'hex');
|
|
193
|
+
ciphered += cipher.final('hex');
|
|
194
|
+
const auth = {
|
|
195
|
+
id: iv.toString('hex'),
|
|
196
|
+
authKey: ciphered
|
|
197
|
+
};
|
|
198
|
+
return auth;
|
|
199
|
+
}
|
|
200
|
+
decrypt(auth) {
|
|
201
|
+
const { id, authKey } = auth;
|
|
202
|
+
const iv = Buffer.from(id, 'hex');
|
|
203
|
+
const uuid = this.getUuid();
|
|
204
|
+
const key = `${uuid.substring(0, 32)}`;
|
|
205
|
+
const cipher = crypto_1.default.createDecipheriv('aes256', key, iv);
|
|
206
|
+
let text = cipher.update(authKey, 'hex', 'utf8');
|
|
207
|
+
text += cipher.final('utf8');
|
|
208
|
+
const user = JSON.parse(text);
|
|
209
|
+
return user;
|
|
210
|
+
}
|
|
211
|
+
getUserSettings() {
|
|
212
|
+
return (0, settings_1.useUserSettings)();
|
|
213
|
+
}
|
|
214
|
+
getApi() {
|
|
215
|
+
if (!this.api)
|
|
216
|
+
this.api = new api_1.VeloHeroApi();
|
|
217
|
+
return this.api;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
__setFunctionName(_classThis, "VeloHeroUpload");
|
|
221
|
+
(() => {
|
|
222
|
+
var _a;
|
|
223
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
|
|
224
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
225
|
+
VeloHeroUpload = _classThis = _classDescriptor.value;
|
|
226
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
227
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
228
|
+
})();
|
|
229
|
+
return VeloHeroUpload = _classThis;
|
|
230
|
+
})();
|
|
231
|
+
exports.VeloHeroUpload = VeloHeroUpload;
|
|
@@ -3,11 +3,14 @@ export type OSInfo = {
|
|
|
3
3
|
arch: string;
|
|
4
4
|
release: string;
|
|
5
5
|
};
|
|
6
|
+
export type AppChannel = 'desktop' | 'mobile' | 'web' | 'tv' | 'backend';
|
|
6
7
|
export interface IAppInfo {
|
|
7
8
|
getOS(): OSInfo;
|
|
8
9
|
getAppVersion(): string;
|
|
10
|
+
getUIVersion(): string;
|
|
9
11
|
getAppDir(): string;
|
|
10
12
|
getSourceDir(): string;
|
|
11
13
|
getTempDir(): string;
|
|
12
14
|
isApp(): boolean;
|
|
15
|
+
getChannel(): AppChannel;
|
|
13
16
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { IAppInfo } from '../appInfo';
|
|
2
2
|
import { IDownloadManager } from '../download';
|
|
3
|
+
import { IFormPostBinding } from '../form';
|
|
3
4
|
import { IFileSystem } from '../fs';
|
|
4
5
|
import { IPathBinding } from '../path';
|
|
5
6
|
import { IFileLoader, IJsonRepositoryBinding } from '../repository';
|
|
6
7
|
import { IVideoProcessor } from '../video';
|
|
8
|
+
import { ISecretBinding } from './secret';
|
|
7
9
|
export declare class IncyclistBindings {
|
|
8
10
|
path?: IPathBinding;
|
|
9
11
|
db: IJsonRepositoryBinding;
|
|
@@ -12,5 +14,7 @@ export declare class IncyclistBindings {
|
|
|
12
14
|
appInfo?: IAppInfo;
|
|
13
15
|
fs?: IFileSystem;
|
|
14
16
|
downloadManager?: IDownloadManager;
|
|
17
|
+
form?: IFormPostBinding;
|
|
18
|
+
secret?: ISecretBinding;
|
|
15
19
|
}
|
|
16
20
|
export declare const getBindings: () => IncyclistBindings;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { EventLogger } from 'gd-eventlog';
|
|
3
|
+
import { ApiClientInitProps } from './types';
|
|
4
|
+
import { RestApiClient } from './RestApiClient';
|
|
5
|
+
export declare class ApiClient {
|
|
6
|
+
static _instance: any;
|
|
7
|
+
protected axios: AxiosInstance;
|
|
8
|
+
protected logger: EventLogger;
|
|
9
|
+
protected requests: Array<{
|
|
10
|
+
tid: string;
|
|
11
|
+
ts: number;
|
|
12
|
+
}>;
|
|
13
|
+
static getInstance(): RestApiClient;
|
|
14
|
+
init(props: ApiClientInitProps): void;
|
|
15
|
+
client(): AxiosInstance;
|
|
16
|
+
protected onRequest(req: any): any;
|
|
17
|
+
protected onResponse(res: any): any;
|
|
18
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
const RestApiClient_1 = require("./RestApiClient");
|
|
11
|
+
class ApiClient {
|
|
12
|
+
static getInstance() {
|
|
13
|
+
if (!RestApiClient_1.RestApiClient._instance) {
|
|
14
|
+
RestApiClient_1.RestApiClient._instance = new RestApiClient_1.RestApiClient();
|
|
15
|
+
}
|
|
16
|
+
return RestApiClient_1.RestApiClient._instance;
|
|
17
|
+
}
|
|
18
|
+
init(props) {
|
|
19
|
+
const { uuid, apiKey, requestLog = true, version, appVersion, channel = 'desktop' } = props;
|
|
20
|
+
const headers = {
|
|
21
|
+
"X-uuid": uuid,
|
|
22
|
+
"X-API-Key": apiKey,
|
|
23
|
+
"x-app-channel": channel,
|
|
24
|
+
"x-app-version": appVersion,
|
|
25
|
+
"x-react-version": version
|
|
26
|
+
};
|
|
27
|
+
this.axios = axios_1.default.create({ headers });
|
|
28
|
+
if (requestLog) {
|
|
29
|
+
this.logger = new gd_eventlog_1.EventLogger('API');
|
|
30
|
+
this.requests = [];
|
|
31
|
+
this.axios.interceptors.request.use((req) => this.onRequest(req));
|
|
32
|
+
this.axios.interceptors.response.use((res) => this.onResponse(res));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
client() {
|
|
36
|
+
if (!this.axios)
|
|
37
|
+
this.axios = axios_1.default;
|
|
38
|
+
return this.axios;
|
|
39
|
+
}
|
|
40
|
+
onRequest(req) {
|
|
41
|
+
if (!req)
|
|
42
|
+
return;
|
|
43
|
+
try {
|
|
44
|
+
const ts = Date.now();
|
|
45
|
+
const tid = (0, uuid_1.v4)();
|
|
46
|
+
req.headers['x-transaction-id'] = tid;
|
|
47
|
+
this.requests.push({ tid, ts });
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
this.logger.logEvent({ message: 'error', fn: 'onRequest()', error: err.message || err, stack: err.stack });
|
|
51
|
+
}
|
|
52
|
+
return req;
|
|
53
|
+
}
|
|
54
|
+
onResponse(res) {
|
|
55
|
+
if (!res)
|
|
56
|
+
return;
|
|
57
|
+
try {
|
|
58
|
+
const { config, status } = res || {};
|
|
59
|
+
const { headers = {}, url, method, params } = config;
|
|
60
|
+
const tid = headers['x-transaction-id'];
|
|
61
|
+
if (!tid)
|
|
62
|
+
return res;
|
|
63
|
+
const idx = this.requests.findIndex(r => r.tid === tid);
|
|
64
|
+
if (idx !== -1) {
|
|
65
|
+
const tsStart = this.requests[idx].ts;
|
|
66
|
+
this.requests.splice(idx, 1);
|
|
67
|
+
this.logger.logEvent({ message: 'api call', method, url, tid, status, duration: Date.now() - tsStart, params });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
this.logger.logEvent({ message: 'error', fn: 'onResponse', error: err.message || err, stack: err.stack });
|
|
72
|
+
}
|
|
73
|
+
return res;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.ApiClient = ApiClient;
|
|
77
|
+
ApiClient._instance = null;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.IncyclistRestApiClient = void 0;
|
|
42
|
+
const types_1 = require("../../base/types");
|
|
43
|
+
const bindings_1 = require("../bindings");
|
|
44
|
+
const settings_1 = require("../../settings");
|
|
45
|
+
const api_1 = require("./api");
|
|
46
|
+
let IncyclistRestApiClient = (() => {
|
|
47
|
+
let _classDecorators = [types_1.Singleton];
|
|
48
|
+
let _classDescriptor;
|
|
49
|
+
let _classExtraInitializers = [];
|
|
50
|
+
let _classThis;
|
|
51
|
+
let _classSuper = api_1.ApiClient;
|
|
52
|
+
var IncyclistRestApiClient = _classThis = class extends _classSuper {
|
|
53
|
+
static getClient(requestLog) {
|
|
54
|
+
const appInfo = (0, bindings_1.getBindings)().appInfo;
|
|
55
|
+
let uuid;
|
|
56
|
+
let apiKey;
|
|
57
|
+
try {
|
|
58
|
+
uuid = (0, settings_1.useUserSettings)().get('uuid', null);
|
|
59
|
+
}
|
|
60
|
+
catch (_a) {
|
|
61
|
+
uuid = null;
|
|
62
|
+
}
|
|
63
|
+
const props = {
|
|
64
|
+
channel: appInfo.getChannel(),
|
|
65
|
+
appVersion: appInfo.getAppVersion(),
|
|
66
|
+
version: appInfo.getUIVersion(),
|
|
67
|
+
requestLog: requestLog !== null && requestLog !== void 0 ? requestLog : true,
|
|
68
|
+
apiKey,
|
|
69
|
+
uuid
|
|
70
|
+
};
|
|
71
|
+
const api = new IncyclistRestApiClient();
|
|
72
|
+
api.init(props);
|
|
73
|
+
return api.client();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
__setFunctionName(_classThis, "IncyclistRestApiClient");
|
|
77
|
+
(() => {
|
|
78
|
+
var _a;
|
|
79
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
|
|
80
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
81
|
+
IncyclistRestApiClient = _classThis = _classDescriptor.value;
|
|
82
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
83
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
84
|
+
})();
|
|
85
|
+
return IncyclistRestApiClient = _classThis;
|
|
86
|
+
})();
|
|
87
|
+
exports.IncyclistRestApiClient = IncyclistRestApiClient;
|