incyclist-services 1.4.16 → 1.4.18
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/ride/service.d.ts +1 -1
- package/lib/activities/upload/index.js +0 -6
- package/lib/activities/upload/strava.d.ts +6 -17
- package/lib/activities/upload/strava.js +13 -135
- package/lib/activities/upload/types.d.ts +0 -7
- package/lib/activities/upload/velohero.d.ts +5 -18
- package/lib/activities/upload/velohero.js +23 -166
- package/lib/apps/base/api/base.d.ts +1 -0
- package/lib/apps/base/api/base.js +9 -0
- package/lib/apps/base/api/index.d.ts +1 -0
- package/lib/apps/base/api/index.js +1 -0
- package/lib/apps/base/api/komoot/api.d.ts +19 -0
- package/lib/apps/base/api/komoot/api.js +126 -0
- package/lib/apps/base/api/komoot/index.d.ts +2 -0
- package/lib/apps/base/api/komoot/index.js +18 -0
- package/lib/apps/base/api/komoot/types.d.ts +93 -0
- package/lib/apps/base/api/komoot/types.js +2 -0
- package/lib/apps/base/api/strava/api.d.ts +14 -1
- package/lib/apps/base/api/strava/api.js +46 -3
- package/lib/apps/base/api/strava/types.d.ts +65 -0
- package/lib/apps/base/app/index.d.ts +18 -0
- package/lib/apps/base/app/index.js +97 -0
- package/lib/apps/base/index.d.ts +2 -0
- package/lib/apps/base/index.js +2 -0
- package/lib/apps/base/types.d.ts +2 -0
- package/lib/apps/base/types.js +2 -0
- package/lib/apps/index.d.ts +2 -0
- package/lib/apps/index.js +2 -0
- package/lib/apps/komoot/KomootAppConnection.d.ts +25 -0
- package/lib/apps/komoot/KomootAppConnection.js +265 -0
- package/lib/apps/komoot/index.d.ts +2 -0
- package/lib/apps/komoot/index.js +18 -0
- package/lib/apps/komoot/types.d.ts +10 -0
- package/lib/apps/komoot/types.js +2 -0
- package/lib/apps/service.d.ts +28 -1
- package/lib/apps/service.js +118 -14
- package/lib/apps/strava/StravaAppConnection.d.ts +28 -0
- package/lib/apps/strava/StravaAppConnection.js +211 -0
- package/lib/apps/strava/index.d.ts +2 -0
- package/lib/apps/strava/index.js +18 -0
- package/lib/apps/strava/types.d.ts +6 -0
- package/lib/apps/strava/types.js +2 -0
- package/lib/apps/types.d.ts +8 -1
- package/lib/apps/velohero/VeloHeroAppConnection.d.ts +25 -0
- package/lib/apps/velohero/VeloHeroAppConnection.js +254 -0
- package/lib/apps/velohero/index.d.ts +2 -0
- package/lib/apps/velohero/index.js +18 -0
- package/lib/apps/velohero/types.d.ts +9 -0
- package/lib/apps/velohero/types.js +2 -0
- package/lib/base/cardlist/index.d.ts +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/routes/base/model/route.d.ts +1 -1
- package/lib/routes/base/model/route.js +105 -56
- package/lib/routes/base/types/index.d.ts +3 -1
- package/lib/routes/download/service.d.ts +6 -0
- package/lib/routes/download/service.js +47 -14
- package/lib/routes/index.d.ts +1 -0
- package/lib/routes/index.js +1 -0
- package/lib/routes/list/RouteListObserver.d.ts +1 -1
- package/lib/routes/list/cards/ActiveImportCard.js +7 -4
- package/lib/routes/list/cards/RouteCard.d.ts +5 -4
- package/lib/routes/list/cards/RouteCard.js +29 -11
- package/lib/routes/list/cards/base.d.ts +1 -1
- package/lib/routes/list/cards/base.js +1 -1
- package/lib/routes/list/lists/alternatives.js +12 -4
- package/lib/routes/list/loaders/DBLoader.js +2 -9
- package/lib/routes/list/loaders/StravaActivityLoader.d.ts +45 -0
- package/lib/routes/list/loaders/StravaActivityLoader.js +309 -0
- package/lib/routes/list/loaders/db.d.ts +1 -0
- package/lib/routes/list/loaders/db.js +22 -4
- package/lib/routes/list/loaders/types.d.ts +1 -2
- package/lib/routes/list/service.d.ts +67 -4
- package/lib/routes/list/service.js +315 -59
- package/lib/routes/list/types.d.ts +8 -0
- package/lib/routes/sync/factory.d.ts +14 -0
- package/lib/routes/sync/factory.js +135 -0
- package/lib/routes/sync/index.d.ts +2 -0
- package/lib/routes/sync/index.js +18 -0
- package/lib/routes/sync/komoot/provider.d.ts +40 -0
- package/lib/routes/sync/komoot/provider.js +348 -0
- package/lib/routes/sync/types.d.ts +11 -0
- package/lib/routes/sync/types.js +2 -0
- package/package.json +1 -1
|
@@ -157,7 +157,7 @@ export declare class ActivityRideService extends IncyclistService {
|
|
|
157
157
|
protected getTotalElevation(): number;
|
|
158
158
|
protected update(): void;
|
|
159
159
|
protected createFreeRide(settings: FreeRideStartSettings): Route;
|
|
160
|
-
protected getMode(routeType: ActivityRouteType): "video" | "
|
|
160
|
+
protected getMode(routeType: ActivityRouteType): "video" | "follow route" | "free ride";
|
|
161
161
|
protected updateActivityTime(): void;
|
|
162
162
|
getRideProps(): any;
|
|
163
163
|
protected logActivityUpdateMessage(): void;
|
|
@@ -14,13 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const factory_1 = require("./factory");
|
|
18
|
-
const strava_1 = require("./strava");
|
|
19
|
-
const velohero_1 = require("./velohero");
|
|
20
17
|
__exportStar(require("./velohero"), exports);
|
|
21
18
|
__exportStar(require("./strava"), exports);
|
|
22
19
|
__exportStar(require("./types"), exports);
|
|
23
20
|
__exportStar(require("./factory"), exports);
|
|
24
|
-
const factory = new factory_1.ActivityUploadFactory();
|
|
25
|
-
factory.add('strava', new strava_1.StravaUpload());
|
|
26
|
-
factory.add('velohero', new velohero_1.VeloHeroUpload());
|
|
@@ -1,29 +1,18 @@
|
|
|
1
1
|
import { IncyclistService } from "../../base/service";
|
|
2
2
|
import { ActivityDetails } from "../base";
|
|
3
|
-
import {
|
|
4
|
-
import { IActivityUpload
|
|
3
|
+
import { StravaFormat } from "../../apps/base/api/strava";
|
|
4
|
+
import { IActivityUpload } from "./types";
|
|
5
|
+
import { StravaAppConnection } from "../../apps/strava/StravaAppConnection";
|
|
5
6
|
export declare class StravaUpload extends IncyclistService implements IActivityUpload {
|
|
6
7
|
protected isInitialized: any;
|
|
7
|
-
protected
|
|
8
|
-
protected config: StravaConfig;
|
|
9
|
-
protected _isConnecting: any;
|
|
10
|
-
protected tokenUpdateHandler: any;
|
|
8
|
+
protected connection: StravaAppConnection;
|
|
11
9
|
constructor();
|
|
12
10
|
init(): boolean;
|
|
13
11
|
isConnected(): boolean;
|
|
14
|
-
isConnecting(): boolean;
|
|
15
|
-
connect(accessToken: string, refreshToken: string, expiration?: Date): Promise<boolean>;
|
|
16
|
-
disconnect(): void;
|
|
17
12
|
upload(activity: ActivityDetails, format?: string): Promise<boolean>;
|
|
18
13
|
getUrl(activityId: string): string;
|
|
19
14
|
protected getStravaFormat(format: string): StravaFormat;
|
|
20
15
|
protected ensureInitialized(): any;
|
|
21
|
-
protected
|
|
22
|
-
protected
|
|
23
|
-
protected updateConfig(config: StravaConfig): void;
|
|
24
|
-
protected initApi(config: StravaConfig): void;
|
|
25
|
-
protected getSecret(key: string): string;
|
|
26
|
-
getSecretBindings(): import("../../api/bindings/secret").ISecretBinding;
|
|
27
|
-
protected getUserSettings(): import("../../settings").UserSettingsService;
|
|
28
|
-
protected getApi(): StravaApi;
|
|
16
|
+
protected getStravaAppConnection(): StravaAppConnection;
|
|
17
|
+
protected getApi(): import("../../apps/base/api/strava").StravaApi;
|
|
29
18
|
}
|
|
@@ -50,11 +50,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
50
50
|
exports.StravaUpload = void 0;
|
|
51
51
|
const service_1 = require("../../base/service");
|
|
52
52
|
const types_1 = require("../../base/types");
|
|
53
|
-
const settings_1 = require("../../settings");
|
|
54
|
-
const valid_1 = require("../../utils/valid");
|
|
55
53
|
const strava_1 = require("../../apps/base/api/strava");
|
|
56
|
-
const api_1 = require("../../api");
|
|
57
54
|
const Injection_1 = require("../../base/decorators/Injection");
|
|
55
|
+
const factory_1 = require("./factory");
|
|
56
|
+
const StravaAppConnection_1 = require("../../apps/strava/StravaAppConnection");
|
|
58
57
|
let StravaUpload = (() => {
|
|
59
58
|
let _classDecorators = [types_1.Singleton];
|
|
60
59
|
let _classDescriptor;
|
|
@@ -62,93 +61,23 @@ let StravaUpload = (() => {
|
|
|
62
61
|
let _classThis;
|
|
63
62
|
let _classSuper = service_1.IncyclistService;
|
|
64
63
|
let _instanceExtraInitializers = [];
|
|
65
|
-
let
|
|
66
|
-
let _getUserSettings_decorators;
|
|
67
|
-
let _getApi_decorators;
|
|
64
|
+
let _getStravaAppConnection_decorators;
|
|
68
65
|
var StravaUpload = _classThis = class extends _classSuper {
|
|
69
66
|
constructor() {
|
|
70
67
|
super('StravaUpload');
|
|
71
68
|
this.isInitialized = __runInitializers(this, _instanceExtraInitializers);
|
|
72
|
-
this.
|
|
69
|
+
this.connection = new StravaAppConnection_1.StravaAppConnection();
|
|
73
70
|
this.isInitialized = false;
|
|
74
71
|
this.init();
|
|
75
72
|
}
|
|
76
73
|
init() {
|
|
77
74
|
if (this.isInitialized)
|
|
78
75
|
return true;
|
|
79
|
-
|
|
80
|
-
return false;
|
|
81
|
-
try {
|
|
82
|
-
const clientId = this.getSecret('STRAVA_CLIENT_ID');
|
|
83
|
-
const clientSecret = this.getSecret('STRAVA_CLIENT_SECRET');
|
|
84
|
-
const auth = this.getCredentials();
|
|
85
|
-
if (clientId && clientSecret && auth) {
|
|
86
|
-
this.logEvent({ message: 'Strava init done', hasCredentials: true });
|
|
87
|
-
this.config = {
|
|
88
|
-
clientId, clientSecret,
|
|
89
|
-
accessToken: auth.accesstoken,
|
|
90
|
-
refreshToken: auth.refreshtoken,
|
|
91
|
-
expiration: new Date(auth.expiration)
|
|
92
|
-
};
|
|
93
|
-
this.initApi(this.config);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
this.logEvent({ message: 'Strava init done', hasCredentials: false });
|
|
97
|
-
}
|
|
98
|
-
this.isInitialized = true;
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
this.logEvent({ message: 'error', error: err.message, fn: 'init', stack: err.stack });
|
|
102
|
-
this.isInitialized = false;
|
|
103
|
-
delete this.config;
|
|
104
|
-
}
|
|
76
|
+
this.isInitialized = this.getStravaAppConnection().init();
|
|
105
77
|
return this.isInitialized;
|
|
106
78
|
}
|
|
107
79
|
isConnected() {
|
|
108
|
-
|
|
109
|
-
this.init();
|
|
110
|
-
}
|
|
111
|
-
return ((0, valid_1.valid)(this.config));
|
|
112
|
-
}
|
|
113
|
-
isConnecting() {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
connect(accessToken, refreshToken, expiration) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
this.ensureInitialized();
|
|
119
|
-
this.logEvent({ message: 'Connect with Strava' });
|
|
120
|
-
try {
|
|
121
|
-
const isConnected = this.isConnected();
|
|
122
|
-
const config = {
|
|
123
|
-
clientId: this.getSecret('STRAVA_CLIENT_ID'),
|
|
124
|
-
clientSecret: this.getSecret('STRAVA_CLIENT_SECRET'),
|
|
125
|
-
accessToken, refreshToken, expiration
|
|
126
|
-
};
|
|
127
|
-
if (isConnected) {
|
|
128
|
-
this.getApi().update(config);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
this.initApi(config);
|
|
132
|
-
this.saveCredentials(config);
|
|
133
|
-
}
|
|
134
|
-
this.logEvent({ message: 'Connect with Strava success' });
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
catch (err) {
|
|
138
|
-
this.logError(err, 'connect');
|
|
139
|
-
throw err;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
disconnect() {
|
|
144
|
-
try {
|
|
145
|
-
this.config = undefined;
|
|
146
|
-
this.saveCredentials();
|
|
147
|
-
this.getApi().init(undefined);
|
|
148
|
-
}
|
|
149
|
-
catch (err) {
|
|
150
|
-
this.logError(err, 'disconnect');
|
|
151
|
-
}
|
|
80
|
+
return this.getStravaAppConnection().isConnected();
|
|
152
81
|
}
|
|
153
82
|
upload(activity_1) {
|
|
154
83
|
return __awaiter(this, arguments, void 0, function* (activity, format = 'TCX') {
|
|
@@ -216,72 +145,19 @@ let StravaUpload = (() => {
|
|
|
216
145
|
this.init();
|
|
217
146
|
return this.isInitialized;
|
|
218
147
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
return userSettings.get('user.auth.strava', null);
|
|
223
|
-
}
|
|
224
|
-
catch (_a) {
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
saveCredentials(config) {
|
|
229
|
-
if (config)
|
|
230
|
-
this.config = config;
|
|
231
|
-
try {
|
|
232
|
-
if (!this.isConnected()) {
|
|
233
|
-
this.logEvent({ message: 'Strava Delete Credentials' });
|
|
234
|
-
this.getUserSettings().set('user.auth.strava', null);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
this.logEvent({ message: 'Strava Save Credentials' });
|
|
238
|
-
this.getUserSettings().set('user.auth.strava', {
|
|
239
|
-
accesstoken: this.config.accessToken,
|
|
240
|
-
refreshtoken: this.config.refreshToken,
|
|
241
|
-
expiration: this.config.expiration.toISOString()
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
catch (err) {
|
|
245
|
-
this.logEvent({ message: 'error', fn: 'saveCredentials', error: err.message, stack: err.stack });
|
|
246
|
-
}
|
|
247
|
-
this.logEvent({ message: 'Strava Save Credentials done' });
|
|
248
|
-
}
|
|
249
|
-
updateConfig(config) {
|
|
250
|
-
const { accessToken, refreshToken, expiration } = config;
|
|
251
|
-
this.config = Object.assign(Object.assign({}, this.config), { accessToken, refreshToken, expiration });
|
|
252
|
-
this.saveCredentials();
|
|
253
|
-
}
|
|
254
|
-
initApi(config) {
|
|
255
|
-
const observer = this.getApi().init(config);
|
|
256
|
-
observer.on('token.updated', this.tokenUpdateHandler);
|
|
257
|
-
}
|
|
258
|
-
getSecret(key) {
|
|
259
|
-
var _a;
|
|
260
|
-
return (_a = this.getSecretBindings()) === null || _a === void 0 ? void 0 : _a.getSecret(key);
|
|
261
|
-
}
|
|
262
|
-
getSecretBindings() {
|
|
263
|
-
var _a;
|
|
264
|
-
return (_a = (0, api_1.getBindings)()) === null || _a === void 0 ? void 0 : _a.secret;
|
|
265
|
-
}
|
|
266
|
-
getUserSettings() {
|
|
267
|
-
return (0, settings_1.useUserSettings)();
|
|
148
|
+
getStravaAppConnection() {
|
|
149
|
+
return this.connection;
|
|
268
150
|
}
|
|
269
151
|
getApi() {
|
|
270
|
-
|
|
271
|
-
this.api = new strava_1.StravaApi();
|
|
272
|
-
return this.api;
|
|
152
|
+
return this.getStravaAppConnection().getApi();
|
|
273
153
|
}
|
|
274
154
|
};
|
|
275
155
|
__setFunctionName(_classThis, "StravaUpload");
|
|
276
156
|
(() => {
|
|
277
157
|
var _a;
|
|
278
158
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
_getApi_decorators = [Injection_1.Injectable];
|
|
282
|
-
__esDecorate(_classThis, null, _getSecretBindings_decorators, { kind: "method", name: "getSecretBindings", static: false, private: false, access: { has: obj => "getSecretBindings" in obj, get: obj => obj.getSecretBindings }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
283
|
-
__esDecorate(_classThis, 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);
|
|
284
|
-
__esDecorate(_classThis, null, _getApi_decorators, { kind: "method", name: "getApi", static: false, private: false, access: { has: obj => "getApi" in obj, get: obj => obj.getApi }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
159
|
+
_getStravaAppConnection_decorators = [Injection_1.Injectable];
|
|
160
|
+
__esDecorate(_classThis, null, _getStravaAppConnection_decorators, { kind: "method", name: "getStravaAppConnection", static: false, private: false, access: { has: obj => "getStravaAppConnection" in obj, get: obj => obj.getStravaAppConnection }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
285
161
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
286
162
|
StravaUpload = _classThis = _classDescriptor.value;
|
|
287
163
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
@@ -290,3 +166,5 @@ let StravaUpload = (() => {
|
|
|
290
166
|
return StravaUpload = _classThis;
|
|
291
167
|
})();
|
|
292
168
|
exports.StravaUpload = StravaUpload;
|
|
169
|
+
const factory = new factory_1.ActivityUploadFactory();
|
|
170
|
+
factory.add('strava', new StravaUpload());
|
|
@@ -3,11 +3,6 @@ export interface Credentials {
|
|
|
3
3
|
username?: string;
|
|
4
4
|
password?: string;
|
|
5
5
|
}
|
|
6
|
-
export interface VeloHeroAuth extends Credentials {
|
|
7
|
-
id?: string;
|
|
8
|
-
authKey?: string;
|
|
9
|
-
version?: string;
|
|
10
|
-
}
|
|
11
6
|
export interface StravaAuth {
|
|
12
7
|
accesstoken?: string;
|
|
13
8
|
refreshtoken?: string;
|
|
@@ -25,8 +20,6 @@ export type ActivityUploadResult = {
|
|
|
25
20
|
export interface IActivityUpload {
|
|
26
21
|
init(): boolean;
|
|
27
22
|
isConnected(): boolean;
|
|
28
|
-
isConnecting(): boolean;
|
|
29
|
-
disconnect(): void;
|
|
30
23
|
upload(activity: ActivityDetails, format?: string): Promise<boolean>;
|
|
31
24
|
getUrl(id: string): string;
|
|
32
25
|
}
|
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
import { IncyclistService } from "../../base/service";
|
|
2
2
|
import { ActivityDetails } from "../base";
|
|
3
|
-
import { IActivityUpload
|
|
4
|
-
import {
|
|
3
|
+
import { IActivityUpload } from "./types";
|
|
4
|
+
import { VeloHeroAppConnection } from "../../apps/velohero/VeloHeroAppConnection";
|
|
5
5
|
export declare class VeloHeroUpload extends IncyclistService implements IActivityUpload {
|
|
6
|
+
protected connection: VeloHeroAppConnection;
|
|
6
7
|
protected isInitialized: any;
|
|
7
|
-
protected username: any;
|
|
8
|
-
protected password: any;
|
|
9
|
-
protected api: VeloHeroApi;
|
|
10
|
-
protected _isConnecting: any;
|
|
11
8
|
constructor();
|
|
12
9
|
init(): boolean;
|
|
13
10
|
isConnected(): boolean;
|
|
14
|
-
isConnecting(): boolean;
|
|
15
|
-
login(username: string, password: string): Promise<boolean>;
|
|
16
|
-
disconnect(): void;
|
|
17
11
|
upload(activity: ActivityDetails, format?: string): Promise<boolean>;
|
|
18
12
|
getUrl(id: string): string;
|
|
19
13
|
protected ensureInitialized(): any;
|
|
20
|
-
protected
|
|
21
|
-
protected
|
|
22
|
-
protected saveCredentials(): any;
|
|
23
|
-
protected encrypt(algo: string): VeloHeroAuth;
|
|
24
|
-
protected decrypt(algo: string, auth: VeloHeroAuth): any;
|
|
25
|
-
protected setupEventListeners(): void;
|
|
26
|
-
protected getUserSettings(): any;
|
|
27
|
-
protected getApi(): any;
|
|
28
|
-
protected getCrypto(): any;
|
|
14
|
+
protected getVeloHeroAppConnection(): VeloHeroAppConnection;
|
|
15
|
+
protected getApi(): import("../..").VeloHeroApi;
|
|
29
16
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
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
|
+
};
|
|
2
9
|
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
10
|
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
11
|
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
@@ -26,13 +33,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
26
33
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
34
|
done = true;
|
|
28
35
|
};
|
|
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
36
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
37
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
38
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -46,92 +46,36 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
46
46
|
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
47
47
|
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
48
48
|
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
50
|
exports.VeloHeroUpload = void 0;
|
|
54
51
|
const service_1 = require("../../base/service");
|
|
55
52
|
const types_1 = require("../../base/types");
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const api_1 = require("../../apps/base/api");
|
|
60
|
-
const CRYPT_ALGO = 'aes256';
|
|
53
|
+
const factory_1 = require("./factory");
|
|
54
|
+
const VeloHeroAppConnection_1 = require("../../apps/velohero/VeloHeroAppConnection");
|
|
55
|
+
const decorators_1 = require("../../base/decorators");
|
|
61
56
|
let VeloHeroUpload = (() => {
|
|
62
57
|
let _classDecorators = [types_1.Singleton];
|
|
63
58
|
let _classDescriptor;
|
|
64
59
|
let _classExtraInitializers = [];
|
|
65
60
|
let _classThis;
|
|
66
61
|
let _classSuper = service_1.IncyclistService;
|
|
62
|
+
let _instanceExtraInitializers = [];
|
|
63
|
+
let _getVeloHeroAppConnection_decorators;
|
|
67
64
|
var VeloHeroUpload = _classThis = class extends _classSuper {
|
|
68
65
|
constructor() {
|
|
69
66
|
super('VeloHeroUpload');
|
|
67
|
+
this.connection = (__runInitializers(this, _instanceExtraInitializers), new VeloHeroAppConnection_1.VeloHeroAppConnection());
|
|
70
68
|
this.isInitialized = false;
|
|
71
69
|
this.init();
|
|
72
70
|
}
|
|
73
71
|
init() {
|
|
74
72
|
if (this.isInitialized)
|
|
75
73
|
return true;
|
|
76
|
-
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
const auth = this.getCredentials();
|
|
81
|
-
if (auth) {
|
|
82
|
-
if (auth.username && auth.password) {
|
|
83
|
-
this.username = auth.username;
|
|
84
|
-
this.password = auth.password;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
const user = this.decrypt(CRYPT_ALGO, auth);
|
|
88
|
-
this.username = user.username;
|
|
89
|
-
this.password = user.password;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
this.logEvent({ message: 'VeloHero init done', hasCredentials: ((0, valid_1.valid)(this.username) && (0, valid_1.valid)(this.password)) });
|
|
93
|
-
this.isInitialized = true;
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
this.logEvent({ message: 'error', error: err.message, fn: 'init', stack: err.stack });
|
|
97
|
-
this.isInitialized = false;
|
|
98
|
-
}
|
|
99
|
-
this.setupEventListeners();
|
|
74
|
+
this.isInitialized = this.getVeloHeroAppConnection().init();
|
|
100
75
|
return this.isInitialized;
|
|
101
76
|
}
|
|
102
77
|
isConnected() {
|
|
103
|
-
this.
|
|
104
|
-
return ((0, valid_1.valid)(this.username) && (0, valid_1.valid)(this.password));
|
|
105
|
-
}
|
|
106
|
-
isConnecting() {
|
|
107
|
-
return this._isConnecting;
|
|
108
|
-
}
|
|
109
|
-
login(username, password) {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
this.ensureInitialized();
|
|
112
|
-
this.logEvent({ message: 'VeloHero Login' });
|
|
113
|
-
this.emit('login-start');
|
|
114
|
-
try {
|
|
115
|
-
yield this.getApi().login(username, password);
|
|
116
|
-
this.logEvent({ message: 'VeloHero Login success' });
|
|
117
|
-
this.username = username;
|
|
118
|
-
this.password = password;
|
|
119
|
-
this.isInitialized = true;
|
|
120
|
-
const auth = yield this.saveCredentials();
|
|
121
|
-
this.emit('login-success', auth);
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
catch (err) {
|
|
125
|
-
this.logEvent({ message: 'VeloHero Login failed', error: err.message });
|
|
126
|
-
this.emit('login-failure', err.message);
|
|
127
|
-
throw err;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
disconnect() {
|
|
132
|
-
this.username = undefined;
|
|
133
|
-
this.password = undefined;
|
|
134
|
-
this.getUserSettings().set('user.auth.velohero', null);
|
|
78
|
+
return this.getVeloHeroAppConnection().isConnected();
|
|
135
79
|
}
|
|
136
80
|
upload(activity_1) {
|
|
137
81
|
return __awaiter(this, arguments, void 0, function* (activity, format = 'TCX') {
|
|
@@ -150,8 +94,7 @@ let VeloHeroUpload = (() => {
|
|
|
150
94
|
this.logEvent({ message: 'VeloHero Upload', format: ucFormat });
|
|
151
95
|
if (!activity.links)
|
|
152
96
|
activity.links = {};
|
|
153
|
-
const username = this.
|
|
154
|
-
const password = this.password;
|
|
97
|
+
const { username, password } = this.getVeloHeroAppConnection().getCredentials();
|
|
155
98
|
const fileName = activity[`${lcFormat}FileName`];
|
|
156
99
|
const res = yield this.getApi().upload(fileName, { username, password });
|
|
157
100
|
this.logEvent(Object.assign({ message: 'VeloHero Upload success' }, res));
|
|
@@ -178,107 +121,19 @@ let VeloHeroUpload = (() => {
|
|
|
178
121
|
this.init();
|
|
179
122
|
return this.isInitialized;
|
|
180
123
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
try {
|
|
184
|
-
const uuid = userSettings.get('uuid', null);
|
|
185
|
-
return uuid;
|
|
186
|
-
}
|
|
187
|
-
catch (_a) {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
getCredentials() {
|
|
192
|
-
const userSettings = this.getUserSettings();
|
|
193
|
-
try {
|
|
194
|
-
return userSettings.get('user.auth.velohero', null);
|
|
195
|
-
}
|
|
196
|
-
catch (_a) {
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
saveCredentials() {
|
|
201
|
-
this.logger.logEvent({ message: 'VeloHero Save Credentials' });
|
|
202
|
-
let auth;
|
|
203
|
-
try {
|
|
204
|
-
auth = this.encrypt(CRYPT_ALGO);
|
|
205
|
-
this.getUserSettings().set('user.auth.velohero', auth);
|
|
206
|
-
}
|
|
207
|
-
catch (err) {
|
|
208
|
-
this.logEvent({ message: 'error', fn: 'saveCredentials', error: err.message, stack: err.stack });
|
|
209
|
-
}
|
|
210
|
-
this.logEvent({ message: 'VeloHero Save Credentials done' });
|
|
211
|
-
return auth;
|
|
212
|
-
}
|
|
213
|
-
encrypt(algo) {
|
|
214
|
-
const iv = crypto_1.default.randomBytes(16);
|
|
215
|
-
const uuid = this.getUuid();
|
|
216
|
-
const key = `${uuid.substring(0, 32)}`;
|
|
217
|
-
const cipher = crypto_1.default.createCipheriv(algo, key, iv);
|
|
218
|
-
const text = JSON.stringify({ username: this.username, password: this.password });
|
|
219
|
-
let ciphered;
|
|
220
|
-
ciphered = cipher.update(text, 'utf8', 'hex');
|
|
221
|
-
ciphered += cipher.final('hex');
|
|
222
|
-
const auth = {
|
|
223
|
-
id: iv.toString('hex'),
|
|
224
|
-
authKey: ciphered,
|
|
225
|
-
};
|
|
226
|
-
return auth;
|
|
227
|
-
}
|
|
228
|
-
decrypt(algo, auth) {
|
|
229
|
-
const { id, authKey, version } = auth;
|
|
230
|
-
const iv = Buffer.from(id, 'hex');
|
|
231
|
-
const uuid = this.getUuid();
|
|
232
|
-
const key = `${uuid.substring(0, 32)}`;
|
|
233
|
-
try {
|
|
234
|
-
let text;
|
|
235
|
-
if (algo === 'aes-256-gcm') {
|
|
236
|
-
const cipher = crypto_1.default.createDecipheriv(algo, key, iv);
|
|
237
|
-
const raw = Buffer.from(authKey, "hex");
|
|
238
|
-
const authTagBuff = raw.subarray(raw.length - 16);
|
|
239
|
-
const encTextBuff = raw.subarray(0, raw.length - 16);
|
|
240
|
-
cipher.setAuthTag(authTagBuff);
|
|
241
|
-
text = cipher.update(encTextBuff);
|
|
242
|
-
text += cipher.final('utf8');
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
const cipher = crypto_1.default.createDecipheriv(algo, key, iv);
|
|
246
|
-
text = cipher.update(authKey, 'hex', 'utf8');
|
|
247
|
-
text += cipher.final('utf8');
|
|
248
|
-
}
|
|
249
|
-
const user = JSON.parse(text);
|
|
250
|
-
return user;
|
|
251
|
-
}
|
|
252
|
-
catch (err) {
|
|
253
|
-
this.logError(err, 'decrypt', { algo, id, authKey });
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
setupEventListeners() {
|
|
258
|
-
this.on('login-start', () => { this._isConnecting = true; });
|
|
259
|
-
this.on('login-success', () => { this._isConnecting = false; });
|
|
260
|
-
this.on('login-failure', () => { this._isConnecting = false; });
|
|
261
|
-
}
|
|
262
|
-
getUserSettings() {
|
|
263
|
-
var _a;
|
|
264
|
-
return (_a = this.injected['UserSettings']) !== null && _a !== void 0 ? _a : (0, settings_1.useUserSettings)();
|
|
124
|
+
getVeloHeroAppConnection() {
|
|
125
|
+
return this.connection;
|
|
265
126
|
}
|
|
266
127
|
getApi() {
|
|
267
|
-
|
|
268
|
-
return this.injected['Api'];
|
|
269
|
-
if (!this.api)
|
|
270
|
-
this.api = new api_1.VeloHeroApi();
|
|
271
|
-
return this.api;
|
|
272
|
-
}
|
|
273
|
-
getCrypto() {
|
|
274
|
-
var _a;
|
|
275
|
-
return (_a = this.injected['Crypto']) !== null && _a !== void 0 ? _a : crypto_1.default;
|
|
128
|
+
return this.getVeloHeroAppConnection().getApi();
|
|
276
129
|
}
|
|
277
130
|
};
|
|
278
131
|
__setFunctionName(_classThis, "VeloHeroUpload");
|
|
279
132
|
(() => {
|
|
280
133
|
var _a;
|
|
281
134
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
|
|
135
|
+
_getVeloHeroAppConnection_decorators = [decorators_1.Injectable];
|
|
136
|
+
__esDecorate(_classThis, null, _getVeloHeroAppConnection_decorators, { kind: "method", name: "getVeloHeroAppConnection", static: false, private: false, access: { has: obj => "getVeloHeroAppConnection" in obj, get: obj => obj.getVeloHeroAppConnection }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
282
137
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
283
138
|
VeloHeroUpload = _classThis = _classDescriptor.value;
|
|
284
139
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
@@ -287,3 +142,5 @@ let VeloHeroUpload = (() => {
|
|
|
287
142
|
return VeloHeroUpload = _classThis;
|
|
288
143
|
})();
|
|
289
144
|
exports.VeloHeroUpload = VeloHeroUpload;
|
|
145
|
+
const factory = new factory_1.ActivityUploadFactory();
|
|
146
|
+
factory.add('velohero', new VeloHeroUpload());
|
|
@@ -4,6 +4,7 @@ export declare class AppApiBase {
|
|
|
4
4
|
protected api: AxiosInstance;
|
|
5
5
|
protected getBaseUrl(): string;
|
|
6
6
|
protected get(url: string, config?: object): Promise<AxiosResponse>;
|
|
7
|
+
protected post(url: string, data?: object, config?: object): Promise<AxiosResponse>;
|
|
7
8
|
protected postForm(form: Form): Promise<any>;
|
|
8
9
|
protected createForm(url: string, uploadInfo: object, requestOpts?: {}): Promise<Form>;
|
|
9
10
|
protected getApi(): AxiosInstance;
|
|
@@ -25,6 +25,15 @@ class AppApiBase {
|
|
|
25
25
|
return yield this.getApi().request(request);
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
post(url, data, config) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const props = config !== null && config !== void 0 ? config : {};
|
|
31
|
+
const request = Object.assign({ method: 'post', url: this.getBaseUrl() + url, data, validateStatus: (status) => {
|
|
32
|
+
return (status >= 200 && status < 300) || status === 403;
|
|
33
|
+
} }, props);
|
|
34
|
+
return yield this.getApi().request(request);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
28
37
|
postForm(form) {
|
|
29
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
39
|
var _a, _b;
|
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./velohero"), exports);
|
|
18
18
|
__exportStar(require("./strava"), exports);
|
|
19
|
+
__exportStar(require("./komoot"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AppApiBase } from '../base';
|
|
2
|
+
import { KomootAuthConfig, KomootCoordinate, KomootGetTourRequestFilters, KomootGetTourRequestParams, KomootLoginResponse, KomootTourSummary } from './types';
|
|
3
|
+
export declare class KomootApi extends AppApiBase {
|
|
4
|
+
protected username: string;
|
|
5
|
+
protected password: string;
|
|
6
|
+
protected userid: string;
|
|
7
|
+
protected iid: number;
|
|
8
|
+
constructor();
|
|
9
|
+
login(username: string, password: string, userid: string): Promise<KomootLoginResponse>;
|
|
10
|
+
setAuth(auth: KomootAuthConfig | null): void;
|
|
11
|
+
isAuthenticated(): boolean;
|
|
12
|
+
getTours(params?: KomootGetTourRequestParams, filters?: KomootGetTourRequestFilters): Promise<Array<KomootTourSummary>>;
|
|
13
|
+
getTourCoordinates(id: number): Promise<Array<KomootCoordinate>>;
|
|
14
|
+
protected getBasicAuthCredentials(): {
|
|
15
|
+
username: string;
|
|
16
|
+
password: string;
|
|
17
|
+
};
|
|
18
|
+
protected getBaseUrl(): any;
|
|
19
|
+
}
|