incyclist-services 1.9.21 → 1.9.23

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/base/repo/db.js +8 -2
  2. package/lib/cjs/activities/base/utils/helpers.js +26 -11
  3. package/lib/cjs/activities/upload/index.js +1 -0
  4. package/lib/cjs/activities/upload/komoot.js +166 -0
  5. package/lib/cjs/apps/base/api/komoot/api.js +35 -0
  6. package/lib/cjs/apps/komoot/KomootAppConnection.js +6 -4
  7. package/lib/cjs/apps/service.js +1 -1
  8. package/lib/cjs/devices/page/base/guidance/guidance.js +277 -16
  9. package/lib/cjs/devices/page/base/service.js +245 -16
  10. package/lib/cjs/devices/page/desktop/matrix.js +2 -1
  11. package/lib/cjs/devices/page/desktop/service.js +4 -11
  12. package/lib/cjs/devices/page/mobile/service.js +1 -0
  13. package/lib/cjs/devices/pairing/conflict.js +47 -0
  14. package/lib/cjs/devices/pairing/guidance.js +40 -4
  15. package/lib/cjs/devices/pairing/helper.js +3 -1
  16. package/lib/cjs/devices/pairing/index.js +1 -0
  17. package/lib/cjs/devices/pairing/service.js +228 -35
  18. package/lib/cjs/devices/pairing/status.js +1 -0
  19. package/lib/cjs/devices/ride/service.js +20 -4
  20. package/lib/cjs/devices/ride/timeouts.js +9 -0
  21. package/lib/cjs/ride/display/service.js +2 -2
  22. package/lib/cjs/routes/base/api/api.js +1 -0
  23. package/lib/esm/activities/base/repo/db.js +8 -2
  24. package/lib/esm/activities/base/utils/helpers.js +24 -10
  25. package/lib/esm/activities/upload/index.js +1 -0
  26. package/lib/esm/activities/upload/komoot.js +163 -0
  27. package/lib/esm/apps/base/api/komoot/api.js +35 -0
  28. package/lib/esm/apps/komoot/KomootAppConnection.js +6 -4
  29. package/lib/esm/apps/service.js +1 -1
  30. package/lib/esm/devices/page/base/guidance/guidance.js +276 -15
  31. package/lib/esm/devices/page/base/service.js +246 -17
  32. package/lib/esm/devices/page/desktop/matrix.js +2 -1
  33. package/lib/esm/devices/page/desktop/service.js +4 -11
  34. package/lib/esm/devices/page/mobile/service.js +1 -0
  35. package/lib/esm/devices/pairing/conflict.js +9 -4
  36. package/lib/esm/devices/pairing/guidance.js +40 -4
  37. package/lib/esm/devices/pairing/helper.js +1 -0
  38. package/lib/esm/devices/pairing/index.js +1 -0
  39. package/lib/esm/devices/pairing/service.js +228 -35
  40. package/lib/esm/devices/pairing/status.js +1 -0
  41. package/lib/esm/devices/ride/service.js +20 -4
  42. package/lib/esm/ride/display/service.js +2 -2
  43. package/lib/esm/routes/base/api/api.js +1 -0
  44. package/lib/types/activities/base/model/index.d.ts +1 -5
  45. package/lib/types/activities/base/repo/db.d.ts +2 -1
  46. package/lib/types/activities/base/utils/helpers.d.ts +2 -1
  47. package/lib/types/activities/upload/index.d.ts +1 -0
  48. package/lib/types/activities/upload/komoot.d.ts +20 -0
  49. package/lib/types/apps/base/api/komoot/api.d.ts +2 -1
  50. package/lib/types/apps/base/api/komoot/types.d.ts +1 -0
  51. package/lib/types/apps/komoot/KomootAppConnection.d.ts +1 -1
  52. package/lib/types/devices/page/base/guidance/guidance.d.ts +49 -2
  53. package/lib/types/devices/page/base/guidance/types.d.ts +20 -2
  54. package/lib/types/devices/page/base/service.d.ts +36 -2
  55. package/lib/types/devices/page/base/types.d.ts +31 -0
  56. package/lib/types/devices/page/desktop/service.d.ts +1 -2
  57. package/lib/types/devices/pairing/conflict.d.ts +4 -1
  58. package/lib/types/devices/pairing/guidance.d.ts +9 -4
  59. package/lib/types/devices/pairing/helper.d.ts +1 -0
  60. package/lib/types/devices/pairing/index.d.ts +1 -0
  61. package/lib/types/devices/pairing/model.d.ts +1 -0
  62. package/lib/types/devices/pairing/service.d.ts +43 -4
  63. package/lib/types/devices/pairing/status.d.ts +2 -1
  64. package/lib/types/devices/ride/service.d.ts +1 -0
  65. package/package.json +2 -2
@@ -45,7 +45,7 @@ const routes_1 = require("../../../routes");
45
45
  const factory_1 = require("./migration/factory");
46
46
  const Injection_1 = require("../../../base/decorators/Injection");
47
47
  const i18n_1 = require("../../../i18n");
48
- exports.DB_VERSION = '5';
48
+ exports.DB_VERSION = '6';
49
49
  exports.DB_NAME = 'db';
50
50
  const SHORT_RIDE_FILTER_CUTOFF = new Date('2026-08-28').getTime();
51
51
  let ActivitiesRepository = (() => {
@@ -365,7 +365,9 @@ let ActivitiesRepository = (() => {
365
365
  if (this.isDirty && (this.tsLastWrite === undefined || Date.now() - this.tsLastWrite >= 1000)) {
366
366
  this.isDirty = false;
367
367
  this.tsLastWrite = Date.now();
368
- this.writeRepo().catch(err => { this.logError(err, 'write'); });
368
+ this.writeRepo().catch(err => {
369
+ this.logWarning(err, 'write');
370
+ });
369
371
  }
370
372
  if (this.isDirty && Date.now() - this.tsLastWrite < 1000) {
371
373
  setTimeout(() => { this.write(); }, this.tsLastWrite + 1000 - Date.now());
@@ -519,6 +521,10 @@ let ActivitiesRepository = (() => {
519
521
  const props = logProps ?? {};
520
522
  this.logger.logEvent({ message: 'error', fn, error: err.message, ...props, stack: err.stack });
521
523
  }
524
+ logWarning(err, fn, logProps) {
525
+ const props = logProps ?? {};
526
+ this.logger.logEvent({ message: 'warning', fn, error: err.message, ...props });
527
+ }
522
528
  getRepo() {
523
529
  if (!this.repo)
524
530
  this.repo = api_1.JsonRepository.create('activities');
@@ -14,7 +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
- exports.getActivityTotalElevation = exports.buildSummary = void 0;
17
+ exports.getActivityTotalElevation = exports.buildUploadStatus = exports.buildSummary = void 0;
18
18
  __exportStar(require("./activity"), exports);
19
19
  const model_1 = require("../model");
20
20
  const buildSummary = (activity, proposedName) => {
@@ -34,24 +34,39 @@ const buildSummary = (activity, proposedName) => {
34
34
  else if (activity.route)
35
35
  title = activity.route.name ?? title;
36
36
  }
37
- if (name === undefined && fileName !== undefined) {
38
- const parts = fileName.split(/[/\\]/);
39
- const last = parts.at(-1);
40
- if (last?.endsWith('.json'))
41
- name = last.slice(0, -5);
42
- }
37
+ name = verifyName(name, fileName);
43
38
  let startTime;
44
39
  if (startTimeUTC)
45
40
  startTime = (new Date(startTimeUTC)).getTime();
46
- const uploadStatus = [];
47
- if (links?.strava) {
48
- uploadStatus.push({ service: 'strava', status: 'success' });
49
- }
41
+ const uploadStatus = (0, exports.buildUploadStatus)(links);
50
42
  return {
51
43
  id, title, name, routeId, routeHash, previewImage, startTime, rideTime, distance, totalElevation, startPos, endPos, realityFactor, smoothingLevel, uploadStatus, laps
52
44
  };
53
45
  };
54
46
  exports.buildSummary = buildSummary;
47
+ const buildUploadStatus = (links) => {
48
+ const uploadStatus = [];
49
+ if (links) {
50
+ const services = Object.keys(links);
51
+ for (const service of services) {
52
+ if (links[service]) {
53
+ const status = links[service];
54
+ uploadStatus.push({ service, status: status.error ? 'failed' : 'success' });
55
+ }
56
+ }
57
+ }
58
+ return uploadStatus;
59
+ };
60
+ exports.buildUploadStatus = buildUploadStatus;
61
+ const verifyName = (name, fileName) => {
62
+ if (name === undefined && fileName !== undefined) {
63
+ const parts = fileName.split(/[/\\]/);
64
+ const last = parts.at(-1);
65
+ if (last?.endsWith('.json'))
66
+ name = last.slice(0, -5);
67
+ }
68
+ return name;
69
+ };
55
70
  const getActivityTotalElevation = (activity) => {
56
71
  const { logs = [] } = activity;
57
72
  let elevation = 0;
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./strava"), exports);
18
18
  __exportStar(require("./intervals"), exports);
19
+ __exportStar(require("./komoot"), exports);
19
20
  __exportStar(require("./types"), exports);
20
21
  __exportStar(require("./factory"), exports);
@@ -0,0 +1,166 @@
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.KomootUpload = void 0;
38
+ const service_1 = require("../../base/service");
39
+ const types_1 = require("../../base/types");
40
+ const Injection_1 = require("../../base/decorators/Injection");
41
+ const factory_1 = require("./factory");
42
+ const komoot_1 = require("../../apps/komoot");
43
+ const api_1 = require("../../api");
44
+ let KomootUpload = (() => {
45
+ let _classDecorators = [types_1.Singleton];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ let _classSuper = service_1.IncyclistService;
50
+ let _instanceExtraInitializers = [];
51
+ let _getKomootAppConnection_decorators;
52
+ var KomootUpload = class extends _classSuper {
53
+ static { _classThis = this; }
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
56
+ _getKomootAppConnection_decorators = [Injection_1.Injectable];
57
+ __esDecorate(this, null, _getKomootAppConnection_decorators, { kind: "method", name: "getKomootAppConnection", static: false, private: false, access: { has: obj => "getKomootAppConnection" in obj, get: obj => obj.getKomootAppConnection }, metadata: _metadata }, null, _instanceExtraInitializers);
58
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
59
+ KomootUpload = _classThis = _classDescriptor.value;
60
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
+ __runInitializers(_classThis, _classExtraInitializers);
62
+ }
63
+ isInitialized = __runInitializers(this, _instanceExtraInitializers);
64
+ connection = new komoot_1.KomootAppConnection();
65
+ constructor() {
66
+ super('KomootUpload');
67
+ this.isInitialized = false;
68
+ this.init();
69
+ }
70
+ init() {
71
+ if (this.isInitialized)
72
+ return true;
73
+ this.isInitialized = this.getKomootAppConnection().init();
74
+ return this.isInitialized;
75
+ }
76
+ isConnected() {
77
+ return this.getKomootAppConnection().isConnected();
78
+ }
79
+ async upload(activity, format = 'FIT') {
80
+ try {
81
+ const ok = this.ensureInitialized();
82
+ if (!ok) {
83
+ this.logEvent({ message: 'Komoot Upload skipped', reason: 'not initialized' });
84
+ return false;
85
+ }
86
+ if (!this.isConnected())
87
+ return false;
88
+ const lcFormat = format.toLowerCase();
89
+ const ucFormat = format.toUpperCase();
90
+ const uploadFormat = this.getKomootFormat(lcFormat);
91
+ const sport = 'racebike';
92
+ this.logEvent({ message: 'Komoot Upload', requestedFormat: ucFormat, uploadFormat });
93
+ if (!activity.links)
94
+ activity.links = {};
95
+ const fileName = activity[`${uploadFormat}FileName`];
96
+ if (!fileName) {
97
+ throw new Error(`data not exported to ${uploadFormat.toUpperCase()}`);
98
+ }
99
+ const data = await this.readFile(fileName);
100
+ if (!data) {
101
+ throw new Error(`file could not be read: ${fileName}`);
102
+ }
103
+ const res = await this.getApi().uploadTour(Buffer.from(data), uploadFormat, sport, activity.title);
104
+ this.logEvent({ message: 'Komoot Upload success', activityId: res.id });
105
+ activity.links.komoot = {
106
+ activity_id: res.id.toString(),
107
+ url: this.getUrl(res.id.toString())
108
+ };
109
+ return true;
110
+ }
111
+ catch (err) {
112
+ this.logEvent({ message: 'Komoot Upload failure', error: err.message });
113
+ activity.links.komoot = {
114
+ error: err.message
115
+ };
116
+ return false;
117
+ }
118
+ }
119
+ getUrl(activityId) {
120
+ return `https://www.komoot.com/tour/${activityId}`;
121
+ }
122
+ getKomootFormat(format) {
123
+ switch (format.toLowerCase()) {
124
+ case 'tcx':
125
+ return 'fit';
126
+ case 'fit':
127
+ return 'fit';
128
+ case 'gpx':
129
+ return 'gpx';
130
+ default:
131
+ return null;
132
+ }
133
+ }
134
+ ensureInitialized() {
135
+ if (!this.isInitialized)
136
+ this.init();
137
+ return this.isInitialized;
138
+ }
139
+ async readFile(fileName) {
140
+ try {
141
+ const fs = this.getFS();
142
+ const exists = await fs.existsFile(fileName);
143
+ if (!exists)
144
+ return null;
145
+ const content = await fs.readFile(fileName);
146
+ return content || null;
147
+ }
148
+ catch (err) {
149
+ this.logError(err, 'readFile');
150
+ }
151
+ }
152
+ getKomootAppConnection() {
153
+ return this.connection;
154
+ }
155
+ getApi() {
156
+ return this.getKomootAppConnection().getApi();
157
+ }
158
+ getFS() {
159
+ return (0, api_1.getBindings)().fs;
160
+ }
161
+ };
162
+ return KomootUpload = _classThis;
163
+ })();
164
+ exports.KomootUpload = KomootUpload;
165
+ const factory = new factory_1.ActivityUploadFactory();
166
+ factory.add('komoot', new KomootUpload());
@@ -110,6 +110,41 @@ class KomootApi extends base_1.AppApiBase {
110
110
  throw (err);
111
111
  }
112
112
  }
113
+ async uploadTour(data, format, sport, name) {
114
+ const tsStart = Date.now();
115
+ try {
116
+ const auth = this.getBasicAuthCredentials();
117
+ if (!this.userid) {
118
+ this.logger.logEvent({ message: 'uploadTour failed', reason: 'invalid credentials' });
119
+ throw new Error('invalid credentials');
120
+ }
121
+ const contentType = format === 'gpx' ? 'application/gpx+xml' : 'application/octet-stream';
122
+ const params = new URLSearchParams({ data_type: format, sport, name });
123
+ const response = await this.getApi().request({
124
+ method: 'post',
125
+ url: `${this.getBaseUrl()}/tours/?${params.toString()}`,
126
+ auth,
127
+ headers: { 'Content-Type': contentType },
128
+ data,
129
+ validateStatus: () => true
130
+ });
131
+ if (response.status >= 400) {
132
+ this.logger.logEvent({
133
+ message: 'uploadTour failed',
134
+ status: response.status,
135
+ body: JSON.stringify(response.data),
136
+ duration: Date.now() - tsStart
137
+ });
138
+ throw new Error(`HTTP ${response.status}: ${JSON.stringify(response.data)}`);
139
+ }
140
+ this.logger.logEvent({ message: 'uploadTour success', id: response.data?.id, duration: Date.now() - tsStart });
141
+ return response.data;
142
+ }
143
+ catch (err) {
144
+ this.logger.logEvent({ message: 'uploadTour failed', reason: err.message, duration: Date.now() - tsStart });
145
+ throw err;
146
+ }
147
+ }
113
148
  applyFilter(tours, filters) {
114
149
  if (!filters)
115
150
  return tours;
@@ -65,7 +65,6 @@ let KomootAppConnection = (() => {
65
65
  constructor() {
66
66
  super('KomootAppConnection', 'komoot');
67
67
  this.api = new api_2.KomootApi();
68
- this.iniAuth();
69
68
  }
70
69
  async connect(credentials) {
71
70
  this.ensureInitialized();
@@ -110,9 +109,9 @@ let KomootAppConnection = (() => {
110
109
  getApi() {
111
110
  return this.api;
112
111
  }
113
- iniAuth() {
112
+ initAuth() {
114
113
  const api = this.getApi();
115
- if (this.credentials) {
114
+ if (this.credentials && api) {
116
115
  api.setAuth(this.credentials);
117
116
  return true;
118
117
  }
@@ -142,7 +141,10 @@ let KomootAppConnection = (() => {
142
141
  isInitialized = false;
143
142
  }
144
143
  this.setupEventListeners();
145
- this.credentials = { ...credentials };
144
+ if (isInitialized) {
145
+ this.credentials = { ...credentials };
146
+ this.initAuth();
147
+ }
146
148
  return isInitialized;
147
149
  }
148
150
  getAuthConfig() {
@@ -66,7 +66,7 @@ let AppsService = (() => {
66
66
  __runInitializers(_classThis, _classExtraInitializers);
67
67
  }
68
68
  services = (__runInitializers(this, _instanceExtraInitializers), {
69
- ActivityUpload: ['strava', 'intervals'],
69
+ ActivityUpload: ['strava', 'intervals', 'komoot'],
70
70
  WorkoutUpload: [],
71
71
  WorkoutDownload: ['intervals'],
72
72
  ActivityDownload: [],