incyclist-services 1.9.26 → 1.9.27

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 (65) hide show
  1. package/lib/cjs/activities/upload/index.js +1 -0
  2. package/lib/cjs/activities/upload/trainingpeaks.js +220 -0
  3. package/lib/cjs/api/rest/api.js +21 -1
  4. package/lib/cjs/apps/base/api/index.js +1 -0
  5. package/lib/cjs/apps/base/api/trainingpeaks/api.js +255 -0
  6. package/lib/cjs/apps/base/api/trainingpeaks/index.js +18 -0
  7. package/lib/cjs/apps/base/api/trainingpeaks/types.js +10 -0
  8. package/lib/cjs/apps/base/api/trainingpeaks/utils.js +20 -0
  9. package/lib/cjs/apps/base/app/ConnectedAppService.js +116 -0
  10. package/lib/cjs/apps/base/app/OAuthAppConnection.js +106 -0
  11. package/lib/cjs/apps/base/app/index.js +14 -112
  12. package/lib/cjs/apps/base/utils.js +19 -0
  13. package/lib/cjs/apps/index.js +1 -0
  14. package/lib/cjs/apps/service.js +37 -17
  15. package/lib/cjs/apps/strava/StravaAppConnection.js +3 -2
  16. package/lib/cjs/apps/trainingpeaks/TrainingPeaksAppConnection.js +91 -0
  17. package/lib/cjs/apps/trainingpeaks/index.js +18 -0
  18. package/lib/cjs/apps/trainingpeaks/types.js +2 -0
  19. package/lib/cjs/workouts/calendar/sync/index.js +1 -0
  20. package/lib/cjs/workouts/calendar/sync/trainingpeaks/provider.js +254 -0
  21. package/lib/esm/activities/upload/index.js +1 -0
  22. package/lib/esm/activities/upload/trainingpeaks.js +217 -0
  23. package/lib/esm/api/rest/api.js +21 -1
  24. package/lib/esm/apps/base/api/index.js +1 -0
  25. package/lib/esm/apps/base/api/trainingpeaks/api.js +251 -0
  26. package/lib/esm/apps/base/api/trainingpeaks/index.js +2 -0
  27. package/lib/esm/apps/base/api/trainingpeaks/types.js +6 -0
  28. package/lib/esm/apps/base/api/trainingpeaks/utils.js +15 -0
  29. package/lib/esm/apps/base/app/ConnectedAppService.js +113 -0
  30. package/lib/esm/apps/base/app/OAuthAppConnection.js +102 -0
  31. package/lib/esm/apps/base/app/index.js +2 -113
  32. package/lib/esm/apps/base/utils.js +15 -0
  33. package/lib/esm/apps/index.js +1 -0
  34. package/lib/esm/apps/service.js +37 -17
  35. package/lib/esm/apps/strava/StravaAppConnection.js +3 -2
  36. package/lib/esm/apps/trainingpeaks/TrainingPeaksAppConnection.js +88 -0
  37. package/lib/esm/apps/trainingpeaks/index.js +2 -0
  38. package/lib/esm/apps/trainingpeaks/types.js +1 -0
  39. package/lib/esm/workouts/calendar/sync/index.js +1 -0
  40. package/lib/esm/workouts/calendar/sync/trainingpeaks/provider.js +251 -0
  41. package/lib/types/activities/upload/index.d.ts +1 -0
  42. package/lib/types/activities/upload/trainingpeaks.d.ts +31 -0
  43. package/lib/types/api/rest/api.d.ts +1 -0
  44. package/lib/types/apps/base/api/index.d.ts +1 -0
  45. package/lib/types/apps/base/api/trainingpeaks/api.d.ts +39 -0
  46. package/lib/types/apps/base/api/trainingpeaks/index.d.ts +2 -0
  47. package/lib/types/apps/base/api/trainingpeaks/types.d.ts +56 -0
  48. package/lib/types/apps/base/api/trainingpeaks/utils.d.ts +2 -0
  49. package/lib/types/apps/base/app/ConnectedAppService.d.ts +23 -0
  50. package/lib/types/apps/base/app/OAuthAppConnection.d.ts +32 -0
  51. package/lib/types/apps/base/app/index.d.ts +2 -23
  52. package/lib/types/apps/base/index.d.ts +1 -0
  53. package/lib/types/apps/base/types.d.ts +6 -0
  54. package/lib/types/apps/base/utils.d.ts +1 -0
  55. package/lib/types/apps/index.d.ts +1 -0
  56. package/lib/types/apps/intervals/types.d.ts +2 -6
  57. package/lib/types/apps/service.d.ts +3 -2
  58. package/lib/types/apps/strava/types.d.ts +2 -6
  59. package/lib/types/apps/trainingpeaks/TrainingPeaksAppConnection.d.ts +13 -0
  60. package/lib/types/apps/trainingpeaks/index.d.ts +2 -0
  61. package/lib/types/apps/trainingpeaks/types.d.ts +2 -0
  62. package/lib/types/apps/types.d.ts +1 -1
  63. package/lib/types/workouts/calendar/sync/index.d.ts +1 -0
  64. package/lib/types/workouts/calendar/sync/trainingpeaks/provider.d.ts +31 -0
  65. package/package.json +1 -1
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.ConnectedAppService = void 0;
38
+ const decorators_1 = require("../../../base/decorators");
39
+ const service_1 = require("../../../base/service");
40
+ const settings_1 = require("../../../settings");
41
+ let instanceCnt = 0;
42
+ let ConnectedAppService = (() => {
43
+ let _classSuper = service_1.IncyclistService;
44
+ let _instanceExtraInitializers = [];
45
+ let _getUserSettings_decorators;
46
+ return class ConnectedAppService extends _classSuper {
47
+ static {
48
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
49
+ _getUserSettings_decorators = [decorators_1.Injectable];
50
+ __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
51
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
52
+ }
53
+ service = __runInitializers(this, _instanceExtraInitializers);
54
+ appKey;
55
+ isInitialized;
56
+ id;
57
+ credentials;
58
+ constructor(service, appKey) {
59
+ super(service);
60
+ this.service = service;
61
+ this.appKey = appKey;
62
+ this.id = instanceCnt++;
63
+ this.isInitialized = false;
64
+ this.init();
65
+ }
66
+ init() {
67
+ if (this.isInitialized)
68
+ return true;
69
+ if (!this.getUserSettings().isInitialized)
70
+ return false;
71
+ try {
72
+ this.isInitialized = this.checkAuth();
73
+ }
74
+ catch {
75
+ this.isInitialized = this.initAuth();
76
+ }
77
+ return this.isInitialized;
78
+ }
79
+ connect(credentials) {
80
+ throw new Error('method not implemented');
81
+ }
82
+ disconnect() {
83
+ throw new Error('method not implemented');
84
+ }
85
+ isConnected() {
86
+ throw new Error('method not implemented');
87
+ }
88
+ getCredentials() {
89
+ throw new Error('method not implemented');
90
+ }
91
+ getAppKey() {
92
+ return this.appKey;
93
+ }
94
+ initAuth() {
95
+ throw new Error('method not implemented');
96
+ }
97
+ checkAuth() {
98
+ throw new Error('method not implemented');
99
+ }
100
+ ensureInitialized() {
101
+ if (!this.isInitialized)
102
+ this.init();
103
+ return this.isInitialized;
104
+ }
105
+ getSupportedOperations() {
106
+ return [];
107
+ }
108
+ getDefaultOperations() {
109
+ return [];
110
+ }
111
+ getUserSettings() {
112
+ return (0, settings_1.useUserSettings)();
113
+ }
114
+ };
115
+ })();
116
+ exports.ConnectedAppService = ConnectedAppService;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuthAppConnection = void 0;
4
+ const valid_1 = require("../../../utils/valid");
5
+ const ConnectedAppService_1 = require("./ConnectedAppService");
6
+ class OAuthAppConnection extends ConnectedAppService_1.ConnectedAppService {
7
+ async connect(credentials) {
8
+ this.ensureInitialized();
9
+ this.logEvent({ message: `Connect with ${this.appName}` });
10
+ try {
11
+ const config = this.createConfig(credentials);
12
+ if (this.isConnected()) {
13
+ this.getApi().update(config);
14
+ }
15
+ else {
16
+ this.initApi(config);
17
+ }
18
+ this.saveCredentials(config);
19
+ this.logEvent({ message: `Connect with ${this.appName} success` });
20
+ return true;
21
+ }
22
+ catch (err) {
23
+ this.logError(err, 'connect');
24
+ throw err;
25
+ }
26
+ }
27
+ isConnecting() {
28
+ return false;
29
+ }
30
+ disconnect() {
31
+ try {
32
+ this.config = undefined;
33
+ this.getApi().init(undefined);
34
+ this.saveCredentials();
35
+ }
36
+ catch (err) {
37
+ this.logError(err, 'disconnect');
38
+ }
39
+ }
40
+ isConnected() {
41
+ if (!this.isInitialized) {
42
+ this.init();
43
+ }
44
+ return (0, valid_1.valid)(this.config);
45
+ }
46
+ getCredentials() {
47
+ try {
48
+ return this.getUserSettings().get(this.getSettingsKey(), null);
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ getApi() {
55
+ if (!this.api)
56
+ this.api = this.createApi();
57
+ return this.api;
58
+ }
59
+ getSettingsKey() {
60
+ return `user.auth.${this.appKey}`;
61
+ }
62
+ initAuth() {
63
+ try {
64
+ const auth = this.getCredentials();
65
+ this.logEvent({ message: `${this.appName} init done`, hasCredentials: Boolean(auth) });
66
+ if (auth) {
67
+ this.config = this.createConfig(auth);
68
+ this.initApi(this.config);
69
+ }
70
+ return true;
71
+ }
72
+ catch (err) {
73
+ this.logEvent({ message: 'error', error: err.message, fn: 'init', stack: err.stack });
74
+ delete this.config;
75
+ return false;
76
+ }
77
+ }
78
+ updateConfig(config) {
79
+ const { accessToken, refreshToken, expiration } = config;
80
+ this.config = { ...this.config, accessToken, refreshToken, expiration };
81
+ this.saveCredentials();
82
+ }
83
+ saveCredentials(config) {
84
+ if (config)
85
+ this.config = config;
86
+ try {
87
+ if (!this.isConnected()) {
88
+ this.logEvent({ message: `${this.appName} Delete Credentials` });
89
+ this.getUserSettings().set(this.getSettingsKey(), null);
90
+ return;
91
+ }
92
+ this.logEvent({ message: `${this.appName} Save Credentials` });
93
+ this.getUserSettings().set(this.getSettingsKey(), this.createCredentials(this.config));
94
+ }
95
+ catch (err) {
96
+ this.logEvent({ message: 'error', fn: 'saveCredentials', error: err.message, stack: err.stack });
97
+ return;
98
+ }
99
+ this.logEvent({ message: `${this.appName} Save Credentials done` });
100
+ }
101
+ initApi(config) {
102
+ const observer = this.getApi().init(config);
103
+ observer.on('token.updated', (updated) => { this.updateConfig(updated); });
104
+ }
105
+ }
106
+ exports.OAuthAppConnection = OAuthAppConnection;
@@ -1,116 +1,18 @@
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);
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
7
  }
7
- return useValue ? value : void 0;
8
- };
9
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
- var _, done = false;
15
- for (var i = decorators.length - 1; i >= 0; i--) {
16
- var context = {};
17
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
- if (kind === "accessor") {
22
- if (result === void 0) continue;
23
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
- if (_ = accept(result.get)) descriptor.get = _;
25
- if (_ = accept(result.set)) descriptor.set = _;
26
- if (_ = accept(result.init)) initializers.unshift(_);
27
- }
28
- else if (_ = accept(result)) {
29
- if (kind === "field") initializers.unshift(_);
30
- else descriptor[key] = _;
31
- }
32
- }
33
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
- done = true;
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
35
15
  };
36
16
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.ConnectedAppService = void 0;
38
- const decorators_1 = require("../../../base/decorators");
39
- const service_1 = require("../../../base/service");
40
- const settings_1 = require("../../../settings");
41
- let instanceCnt = 0;
42
- let ConnectedAppService = (() => {
43
- let _classSuper = service_1.IncyclistService;
44
- let _instanceExtraInitializers = [];
45
- let _getUserSettings_decorators;
46
- return class ConnectedAppService extends _classSuper {
47
- static {
48
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
49
- _getUserSettings_decorators = [decorators_1.Injectable];
50
- __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
51
- if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
52
- }
53
- service = __runInitializers(this, _instanceExtraInitializers);
54
- appKey;
55
- isInitialized;
56
- id;
57
- credentials;
58
- constructor(service, appKey) {
59
- super(service);
60
- this.service = service;
61
- this.appKey = appKey;
62
- this.id = instanceCnt++;
63
- this.isInitialized = false;
64
- this.init();
65
- }
66
- init() {
67
- if (this.isInitialized)
68
- return true;
69
- if (!this.getUserSettings().isInitialized)
70
- return false;
71
- try {
72
- this.isInitialized = this.checkAuth();
73
- }
74
- catch {
75
- this.isInitialized = this.initAuth();
76
- }
77
- return this.isInitialized;
78
- }
79
- connect(credentials) {
80
- throw new Error('method not implemented');
81
- }
82
- disconnect() {
83
- throw new Error('method not implemented');
84
- }
85
- isConnected() {
86
- throw new Error('method not implemented');
87
- }
88
- getCredentials() {
89
- throw new Error('method not implemented');
90
- }
91
- getAppKey() {
92
- return this.appKey;
93
- }
94
- initAuth() {
95
- throw new Error('method not implemented');
96
- }
97
- checkAuth() {
98
- throw new Error('method not implemented');
99
- }
100
- ensureInitialized() {
101
- if (!this.isInitialized)
102
- this.init();
103
- return this.isInitialized;
104
- }
105
- getSupportedOperations() {
106
- return [];
107
- }
108
- getDefaultOperations() {
109
- return [];
110
- }
111
- getUserSettings() {
112
- return (0, settings_1.useUserSettings)();
113
- }
114
- };
115
- })();
116
- exports.ConnectedAppService = ConnectedAppService;
17
+ __exportStar(require("./ConnectedAppService"), exports);
18
+ __exportStar(require("./OAuthAppConnection"), exports);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseExpiration = void 0;
4
+ const MAX_EPOCH_SECONDS = 1e11;
5
+ const parseExpiration = (expiration) => {
6
+ if (expiration === undefined || expiration === null || expiration === '')
7
+ return undefined;
8
+ const isEpoch = typeof expiration === 'number' || /^\d+$/.test(expiration);
9
+ let date;
10
+ if (isEpoch) {
11
+ const value = Number(expiration);
12
+ date = new Date(value < MAX_EPOCH_SECONDS ? value * 1000 : value);
13
+ }
14
+ else {
15
+ date = new Date(expiration);
16
+ }
17
+ return Number.isNaN(date.valueOf()) ? undefined : date;
18
+ };
19
+ exports.parseExpiration = parseExpiration;
@@ -18,3 +18,4 @@ __exportStar(require("./base"), exports);
18
18
  __exportStar(require("./googleMaps"), exports);
19
19
  __exportStar(require("./service"), exports);
20
20
  __exportStar(require("./strava"), exports);
21
+ __exportStar(require("./trainingpeaks"), exports);
@@ -43,6 +43,7 @@ const settings_1 = require("../settings");
43
43
  const base_1 = require("./base");
44
44
  const IntervalsAppConnection_1 = require("./intervals/IntervalsAppConnection");
45
45
  const komoot_1 = require("./komoot");
46
+ const trainingpeaks_1 = require("./trainingpeaks");
46
47
  let AppsService = (() => {
47
48
  let _classDecorators = [types_1.Singleton];
48
49
  let _classDescriptor;
@@ -66,16 +67,16 @@ let AppsService = (() => {
66
67
  __runInitializers(_classThis, _classExtraInitializers);
67
68
  }
68
69
  serviceMap = (__runInitializers(this, _instanceExtraInitializers), [
69
- { name: 'Strava', key: 'strava', iconUrl: 'https://static.cdnlogo.com/logos/s/42/strava-wordmark.svg', connection: new base_1.StravaAppConnection() },
70
- { name: 'Komoot', key: 'komoot', iconUrl: 'https://www.komoot.com/assets/4d8ae313eec53e6e.svg', connection: new komoot_1.KomootAppConnection() },
71
- { name: 'Intervals.icu', key: 'intervals', iconUrl: 'images/intervals.png', connection: new IntervalsAppConnection_1.IntervalsAppConnection() },
70
+ { name: 'Strava', key: 'strava', connection: new base_1.StravaAppConnection() },
71
+ { name: 'Komoot', key: 'komoot', connection: new komoot_1.KomootAppConnection() },
72
+ { name: 'Intervals.icu', key: 'intervals', connection: new IntervalsAppConnection_1.IntervalsAppConnection() },
72
73
  ]);
73
74
  constructor() {
74
75
  super('AppsService');
75
76
  }
76
77
  openSettings() {
77
78
  try {
78
- const apps = this.serviceMap.map(as => this.getAppDisplayProps(as.key));
79
+ const apps = this.getServiceMap().map(as => this.getAppDisplayProps(as.key));
79
80
  return apps;
80
81
  }
81
82
  catch (err) {
@@ -89,7 +90,7 @@ let AppsService = (() => {
89
90
  return { isConnected, operations };
90
91
  }
91
92
  async connect(app, credentials) {
92
- const entry = this.serviceMap.find(e => e.key === app);
93
+ const entry = this.getServiceMap().find(e => e.key === app);
93
94
  if (!entry?.connection)
94
95
  return false;
95
96
  const success = await entry.connection.connect(credentials);
@@ -99,13 +100,13 @@ let AppsService = (() => {
99
100
  return success;
100
101
  }
101
102
  isConnected(app) {
102
- const entry = this.serviceMap.find(e => e.key === app);
103
+ const entry = this.getServiceMap().find(e => e.key === app);
103
104
  if (!entry?.connection)
104
105
  return false;
105
106
  return entry.connection.isConnected();
106
107
  }
107
108
  disconnect(app) {
108
- const entry = this.serviceMap.find(e => e.key === app);
109
+ const entry = this.getServiceMap().find(e => e.key === app);
109
110
  if (!entry?.connection)
110
111
  return;
111
112
  entry.connection.disconnect();
@@ -150,10 +151,10 @@ let AppsService = (() => {
150
151
  .filter(s => s.connected);
151
152
  const enabled = connected
152
153
  .filter(s => factory.isUploadEnabled(s.key));
153
- return this.serviceMap.filter(s => enabled.find(c => c.key === s.key));
154
+ return this.getServiceMap().filter(s => enabled.find(c => c.key === s.key));
154
155
  }
155
156
  else if (operation === 'WorkoutDownload') {
156
- return this.serviceMap.filter(s => available.includes(s.key) && s.connection.isConnected());
157
+ return this.getServiceMap().filter(s => available.includes(s.key) && s.connection.isConnected());
157
158
  }
158
159
  return [];
159
160
  }
@@ -168,13 +169,32 @@ let AppsService = (() => {
168
169
  return supported;
169
170
  }
170
171
  getName(key) {
171
- const found = this.serviceMap.find(r => r.key === key);
172
+ const found = this.getServiceMap().find(r => r.key === key);
172
173
  return found ? found.name : key;
173
174
  }
174
175
  getKey(name) {
175
- const found = this.serviceMap.find(r => r.name === name);
176
+ const found = this.getServiceMap().find(r => r.name === name);
176
177
  return found ? found.key : name;
177
178
  }
179
+ getServiceMap() {
180
+ this.addOptionalApps();
181
+ return this.serviceMap;
182
+ }
183
+ addOptionalApps() {
184
+ const isAdded = this.serviceMap.some(a => a.key === 'trainingpeaks');
185
+ if (isAdded || !this.isEnabledInSettings('TP_INTEGRATION'))
186
+ return;
187
+ this.serviceMap.push({ name: 'TrainingPeaks', key: 'trainingpeaks', connection: new trainingpeaks_1.TrainingPeaksAppConnection() });
188
+ }
189
+ isEnabledInSettings(key) {
190
+ try {
191
+ const settings = this.getUserSettings();
192
+ return settings.isInitialized && Boolean(settings.getValue(key, false));
193
+ }
194
+ catch {
195
+ return false;
196
+ }
197
+ }
178
198
  hasSettings(app) {
179
199
  const settings = this.getUserSettings().getValue(`preferences.${app}`, null);
180
200
  return settings !== null;
@@ -193,19 +213,19 @@ let AppsService = (() => {
193
213
  }
194
214
  }
195
215
  getServiceIDs() {
196
- return this.serviceMap.map(m => m.key);
216
+ return this.getServiceMap().map(m => m.key);
197
217
  }
198
218
  getAppConnections() {
199
- return this.serviceMap.map(m => m.connection);
219
+ return this.getServiceMap().map(m => m.connection);
200
220
  }
201
221
  getAppConnection(serviceKey) {
202
- return this.serviceMap.find(m => serviceKey === m.key)?.connection;
222
+ return this.getServiceMap().find(m => serviceKey === m.key)?.connection;
203
223
  }
204
224
  getAppDisplayProps(key) {
205
- const entry = this.serviceMap.find(e => e.key === key);
206
- const { name, iconUrl } = entry;
225
+ const entry = this.getServiceMap().find(e => e.key === key);
226
+ const { name } = entry;
207
227
  const isConnected = this.isConnected(key);
208
- return { name, key, iconUrl, isConnected };
228
+ return { name, key, isConnected };
209
229
  }
210
230
  getSettings(key, defValue) {
211
231
  try {
@@ -40,6 +40,7 @@ const decorators_1 = require("../../base/decorators");
40
40
  const valid_1 = require("../../utils/valid");
41
41
  const api_2 = require("../base/api");
42
42
  const app_1 = require("../base/app");
43
+ const utils_1 = require("../base/utils");
43
44
  let StravaAppConnection = (() => {
44
45
  let _classDecorators = [decorators_1.Singleton];
45
46
  let _classDescriptor;
@@ -76,8 +77,8 @@ let StravaAppConnection = (() => {
76
77
  }
77
78
  else {
78
79
  this.initApi(config);
79
- this.saveCredentials(config);
80
80
  }
81
+ this.saveCredentials(config);
81
82
  this.logEvent({ message: 'Connect with Strava success' });
82
83
  return true;
83
84
  }
@@ -181,7 +182,7 @@ let StravaAppConnection = (() => {
181
182
  clientSecret: this.getSecret('STRAVA_CLIENT_SECRET'),
182
183
  accessToken: credentials?.accesstoken,
183
184
  refreshToken: credentials?.refreshtoken,
184
- expiration: credentials?.expiration ? new Date(credentials.expiration) : undefined
185
+ expiration: (0, utils_1.parseExpiration)(credentials?.expiration)
185
186
  };
186
187
  }
187
188
  initApi(config) {
@@ -0,0 +1,91 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.TrainingPeaksAppConnection = void 0;
38
+ const decorators_1 = require("../../base/decorators");
39
+ const api_1 = require("../base/api");
40
+ const app_1 = require("../base/app");
41
+ const utils_1 = require("../base/utils");
42
+ let TrainingPeaksAppConnection = (() => {
43
+ let _classDecorators = [decorators_1.Singleton];
44
+ let _classDescriptor;
45
+ let _classExtraInitializers = [];
46
+ let _classThis;
47
+ let _classSuper = app_1.OAuthAppConnection;
48
+ var TrainingPeaksAppConnection = class extends _classSuper {
49
+ static { _classThis = this; }
50
+ static {
51
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
52
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
53
+ TrainingPeaksAppConnection = _classThis = _classDescriptor.value;
54
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
55
+ __runInitializers(_classThis, _classExtraInitializers);
56
+ }
57
+ constructor() {
58
+ super('TrainingPeaksAppConnection', 'trainingpeaks');
59
+ }
60
+ getSupportedOperations() {
61
+ return ['ActivityUpload', 'WorkoutDownload'];
62
+ }
63
+ getDefaultOperations() {
64
+ return ['ActivityUpload', 'WorkoutDownload'];
65
+ }
66
+ get appName() {
67
+ return 'TrainingPeaks';
68
+ }
69
+ createApi() {
70
+ return new api_1.TrainingPeaksApi();
71
+ }
72
+ createConfig(credentials) {
73
+ return {
74
+ id: credentials?.id === undefined ? undefined : String(credentials.id),
75
+ accessToken: credentials?.accesstoken,
76
+ refreshToken: credentials?.refreshtoken,
77
+ expiration: (0, utils_1.parseExpiration)(credentials?.expiration)
78
+ };
79
+ }
80
+ createCredentials(config) {
81
+ return {
82
+ id: config.id,
83
+ accesstoken: config.accessToken,
84
+ refreshtoken: config.refreshToken,
85
+ expiration: config.expiration?.toISOString()
86
+ };
87
+ }
88
+ };
89
+ return TrainingPeaksAppConnection = _classThis;
90
+ })();
91
+ exports.TrainingPeaksAppConnection = TrainingPeaksAppConnection;
@@ -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("./TrainingPeaksAppConnection"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./factory"), exports);
18
18
  __exportStar(require("./intervals/provider"), exports);
19
+ __exportStar(require("./trainingpeaks/provider"), exports);