incyclist-services 1.9.34 → 1.9.36

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 (228) hide show
  1. package/lib/cjs/api/localLink/types.js +2 -0
  2. package/lib/cjs/api/loopbackPipe/types.js +2 -0
  3. package/lib/cjs/api/secureStorage/types.js +2 -0
  4. package/lib/cjs/apps/base/api/oauth.js +7 -1
  5. package/lib/cjs/apps/base/api/trainingpeaks/api.js +56 -0
  6. package/lib/cjs/apps/base/app/OAuthAppConnection.js +14 -13
  7. package/lib/cjs/apps/komoot/KomootAppConnection.js +7 -8
  8. package/lib/cjs/apps/trainingpeaks/TrainingPeaksAppConnection.js +4 -2
  9. package/lib/cjs/base/pages/service.js +2 -1
  10. package/lib/cjs/devices/access/service.js +24 -4
  11. package/lib/cjs/devices/index.js +1 -0
  12. package/lib/cjs/devices/known-names/index.js +22 -0
  13. package/lib/cjs/devices/known-names/known-device-names.js +55 -0
  14. package/lib/cjs/devices/known-names/matching.js +26 -0
  15. package/lib/cjs/devices/known-names/service.js +9 -0
  16. package/lib/cjs/devices/known-names/types.js +2 -0
  17. package/lib/cjs/devices/page/base/service.js +19 -1
  18. package/lib/cjs/devices/page/base/visit-log.js +6 -0
  19. package/lib/cjs/devices/page/mobile/statemachine.js +116 -24
  20. package/lib/cjs/devices/pairing/service.js +141 -52
  21. package/lib/cjs/devices/ride/service.js +150 -31
  22. package/lib/cjs/link/auth.js +129 -0
  23. package/lib/cjs/link/channel.js +70 -0
  24. package/lib/cjs/link/client/browse.js +78 -0
  25. package/lib/cjs/link/client/connection.js +278 -0
  26. package/lib/cjs/link/client/consts.js +26 -0
  27. package/lib/cjs/link/client/index.js +21 -0
  28. package/lib/cjs/link/client/media.js +78 -0
  29. package/lib/cjs/link/client/native-requirements.js +30 -0
  30. package/lib/cjs/link/client/pairing.js +230 -0
  31. package/lib/cjs/link/client/recovery.js +32 -0
  32. package/lib/cjs/link/client/service.js +1121 -0
  33. package/lib/cjs/link/client/store.js +108 -0
  34. package/lib/cjs/link/client/types.js +2 -0
  35. package/lib/cjs/link/client/watch.js +133 -0
  36. package/lib/cjs/link/consts.js +29 -0
  37. package/lib/cjs/link/envelope.js +49 -0
  38. package/lib/cjs/link/framing.js +105 -0
  39. package/lib/cjs/link/host/consts.js +39 -0
  40. package/lib/cjs/link/host/index.js +18 -0
  41. package/lib/cjs/link/host/pairing.js +195 -0
  42. package/lib/cjs/link/host/rate-limit.js +35 -0
  43. package/lib/cjs/link/host/service.js +842 -0
  44. package/lib/cjs/link/host/types.js +2 -0
  45. package/lib/cjs/link/host/utils.js +58 -0
  46. package/lib/cjs/link/index.js +24 -0
  47. package/lib/cjs/link/types.js +2 -0
  48. package/lib/cjs/link/utils.js +77 -0
  49. package/lib/cjs/link/version.js +41 -0
  50. package/lib/cjs/ride/display/service.js +66 -1
  51. package/lib/cjs/ride/route/RouteDisplayService.js +1 -1
  52. package/lib/cjs/routes/sharing/catalog.js +113 -0
  53. package/lib/cjs/routes/sharing/client/consts.js +18 -0
  54. package/lib/cjs/routes/sharing/client/descriptor.js +42 -0
  55. package/lib/cjs/routes/sharing/client/index.js +23 -0
  56. package/lib/cjs/routes/sharing/client/markers.js +68 -0
  57. package/lib/cjs/routes/sharing/client/repo.js +129 -0
  58. package/lib/cjs/routes/sharing/client/resolver.js +351 -0
  59. package/lib/cjs/routes/sharing/client/routes.js +125 -0
  60. package/lib/cjs/routes/sharing/client/service.js +759 -0
  61. package/lib/cjs/routes/sharing/client/types.js +2 -0
  62. package/lib/cjs/routes/sharing/consts.js +7 -0
  63. package/lib/cjs/routes/sharing/copy/index.js +17 -0
  64. package/lib/cjs/routes/sharing/copy/service.js +357 -0
  65. package/lib/cjs/routes/sharing/copy/types.js +2 -0
  66. package/lib/cjs/routes/sharing/descriptor.js +28 -0
  67. package/lib/cjs/routes/sharing/index.js +24 -0
  68. package/lib/cjs/routes/sharing/service.js +414 -0
  69. package/lib/cjs/routes/sharing/types.js +2 -0
  70. package/lib/cjs/routes/thumbnails/consts.js +10 -0
  71. package/lib/cjs/routes/thumbnails/index.js +17 -0
  72. package/lib/cjs/routes/thumbnails/keys.js +29 -0
  73. package/lib/cjs/routes/thumbnails/service.js +251 -0
  74. package/lib/cjs/routes/thumbnails/types.js +2 -0
  75. package/lib/cjs/utils/scrub.js +63 -0
  76. package/lib/esm/api/localLink/types.js +1 -0
  77. package/lib/esm/api/loopbackPipe/types.js +1 -0
  78. package/lib/esm/api/secureStorage/types.js +1 -0
  79. package/lib/esm/apps/base/api/oauth.js +7 -1
  80. package/lib/esm/apps/base/api/trainingpeaks/api.js +56 -0
  81. package/lib/esm/apps/base/app/OAuthAppConnection.js +14 -13
  82. package/lib/esm/apps/komoot/KomootAppConnection.js +7 -8
  83. package/lib/esm/apps/trainingpeaks/TrainingPeaksAppConnection.js +4 -2
  84. package/lib/esm/base/pages/service.js +2 -1
  85. package/lib/esm/devices/access/service.js +24 -4
  86. package/lib/esm/devices/index.js +1 -0
  87. package/lib/esm/devices/known-names/index.js +2 -0
  88. package/lib/esm/devices/known-names/known-device-names.js +52 -0
  89. package/lib/esm/devices/known-names/matching.js +20 -0
  90. package/lib/esm/devices/known-names/service.js +5 -0
  91. package/lib/esm/devices/known-names/types.js +1 -0
  92. package/lib/esm/devices/page/base/service.js +19 -1
  93. package/lib/esm/devices/page/base/visit-log.js +6 -0
  94. package/lib/esm/devices/page/mobile/statemachine.js +116 -24
  95. package/lib/esm/devices/pairing/service.js +141 -52
  96. package/lib/esm/devices/ride/service.js +150 -31
  97. package/lib/esm/link/auth.js +117 -0
  98. package/lib/esm/link/channel.js +64 -0
  99. package/lib/esm/link/client/browse.js +73 -0
  100. package/lib/esm/link/client/connection.js +273 -0
  101. package/lib/esm/link/client/consts.js +23 -0
  102. package/lib/esm/link/client/index.js +3 -0
  103. package/lib/esm/link/client/media.js +74 -0
  104. package/lib/esm/link/client/native-requirements.js +23 -0
  105. package/lib/esm/link/client/pairing.js +226 -0
  106. package/lib/esm/link/client/recovery.js +28 -0
  107. package/lib/esm/link/client/service.js +1116 -0
  108. package/lib/esm/link/client/store.js +102 -0
  109. package/lib/esm/link/client/types.js +1 -0
  110. package/lib/esm/link/client/watch.js +129 -0
  111. package/lib/esm/link/consts.js +26 -0
  112. package/lib/esm/link/envelope.js +41 -0
  113. package/lib/esm/link/framing.js +99 -0
  114. package/lib/esm/link/host/consts.js +36 -0
  115. package/lib/esm/link/host/index.js +2 -0
  116. package/lib/esm/link/host/pairing.js +191 -0
  117. package/lib/esm/link/host/rate-limit.js +31 -0
  118. package/lib/esm/link/host/service.js +837 -0
  119. package/lib/esm/link/host/types.js +1 -0
  120. package/lib/esm/link/host/utils.js +44 -0
  121. package/lib/esm/link/index.js +8 -0
  122. package/lib/esm/link/types.js +1 -0
  123. package/lib/esm/link/utils.js +66 -0
  124. package/lib/esm/link/version.js +33 -0
  125. package/lib/esm/ride/display/service.js +66 -1
  126. package/lib/esm/ride/route/RouteDisplayService.js +1 -1
  127. package/lib/esm/routes/sharing/catalog.js +105 -0
  128. package/lib/esm/routes/sharing/client/consts.js +15 -0
  129. package/lib/esm/routes/sharing/client/descriptor.js +36 -0
  130. package/lib/esm/routes/sharing/client/index.js +4 -0
  131. package/lib/esm/routes/sharing/client/markers.js +63 -0
  132. package/lib/esm/routes/sharing/client/repo.js +123 -0
  133. package/lib/esm/routes/sharing/client/resolver.js +347 -0
  134. package/lib/esm/routes/sharing/client/routes.js +121 -0
  135. package/lib/esm/routes/sharing/client/service.js +753 -0
  136. package/lib/esm/routes/sharing/client/types.js +1 -0
  137. package/lib/esm/routes/sharing/consts.js +4 -0
  138. package/lib/esm/routes/sharing/copy/index.js +1 -0
  139. package/lib/esm/routes/sharing/copy/service.js +353 -0
  140. package/lib/esm/routes/sharing/copy/types.js +1 -0
  141. package/lib/esm/routes/sharing/descriptor.js +24 -0
  142. package/lib/esm/routes/sharing/index.js +4 -0
  143. package/lib/esm/routes/sharing/service.js +410 -0
  144. package/lib/esm/routes/sharing/types.js +1 -0
  145. package/lib/esm/routes/thumbnails/consts.js +7 -0
  146. package/lib/esm/routes/thumbnails/index.js +1 -0
  147. package/lib/esm/routes/thumbnails/keys.js +23 -0
  148. package/lib/esm/routes/thumbnails/service.js +247 -0
  149. package/lib/esm/routes/thumbnails/types.js +1 -0
  150. package/lib/esm/utils/scrub.js +58 -0
  151. package/lib/types/api/localLink/types.d.ts +178 -0
  152. package/lib/types/api/loopbackPipe/types.d.ts +10 -0
  153. package/lib/types/api/secureStorage/types.d.ts +5 -0
  154. package/lib/types/apps/base/api/oauth.d.ts +3 -1
  155. package/lib/types/apps/base/api/trainingpeaks/api.d.ts +10 -0
  156. package/lib/types/apps/base/api/trainingpeaks/types.d.ts +6 -2
  157. package/lib/types/apps/base/app/OAuthAppConnection.d.ts +1 -0
  158. package/lib/types/apps/trainingpeaks/types.d.ts +3 -1
  159. package/lib/types/devices/access/model.d.ts +4 -0
  160. package/lib/types/devices/access/service.d.ts +9 -2
  161. package/lib/types/devices/index.d.ts +1 -0
  162. package/lib/types/devices/known-names/index.d.ts +3 -0
  163. package/lib/types/devices/known-names/known-device-names.d.ts +2 -0
  164. package/lib/types/devices/known-names/matching.d.ts +3 -0
  165. package/lib/types/devices/known-names/service.d.ts +2 -0
  166. package/lib/types/devices/known-names/types.d.ts +4 -0
  167. package/lib/types/devices/page/base/service.d.ts +3 -0
  168. package/lib/types/devices/page/base/visit-log.d.ts +4 -0
  169. package/lib/types/devices/page/mobile/statemachine.d.ts +24 -4
  170. package/lib/types/devices/pairing/model.d.ts +18 -0
  171. package/lib/types/devices/pairing/service.d.ts +23 -8
  172. package/lib/types/devices/ride/service.d.ts +17 -1
  173. package/lib/types/devices/ride/types.d.ts +11 -0
  174. package/lib/types/devices/types.d.ts +1 -0
  175. package/lib/types/link/auth.d.ts +13 -0
  176. package/lib/types/link/channel.d.ts +23 -0
  177. package/lib/types/link/client/browse.d.ts +22 -0
  178. package/lib/types/link/client/connection.d.ts +69 -0
  179. package/lib/types/link/client/consts.d.ts +23 -0
  180. package/lib/types/link/client/index.d.ts +4 -0
  181. package/lib/types/link/client/media.d.ts +23 -0
  182. package/lib/types/link/client/native-requirements.d.ts +3 -0
  183. package/lib/types/link/client/pairing.d.ts +46 -0
  184. package/lib/types/link/client/recovery.d.ts +10 -0
  185. package/lib/types/link/client/service.d.ts +177 -0
  186. package/lib/types/link/client/store.d.ts +20 -0
  187. package/lib/types/link/client/types.d.ts +139 -0
  188. package/lib/types/link/client/watch.d.ts +32 -0
  189. package/lib/types/link/consts.d.ts +16 -0
  190. package/lib/types/link/envelope.d.ts +6 -0
  191. package/lib/types/link/framing.d.ts +17 -0
  192. package/lib/types/link/host/consts.d.ts +34 -0
  193. package/lib/types/link/host/index.d.ts +3 -0
  194. package/lib/types/link/host/pairing.d.ts +53 -0
  195. package/lib/types/link/host/rate-limit.d.ts +14 -0
  196. package/lib/types/link/host/service.d.ts +121 -0
  197. package/lib/types/link/host/types.d.ts +87 -0
  198. package/lib/types/link/host/utils.d.ts +17 -0
  199. package/lib/types/link/index.d.ts +8 -0
  200. package/lib/types/link/types.d.ts +220 -0
  201. package/lib/types/link/utils.d.ts +9 -0
  202. package/lib/types/link/version.d.ts +6 -0
  203. package/lib/types/ride/display/service.d.ts +7 -0
  204. package/lib/types/routes/sharing/catalog.d.ts +27 -0
  205. package/lib/types/routes/sharing/client/consts.d.ts +15 -0
  206. package/lib/types/routes/sharing/client/descriptor.d.ts +13 -0
  207. package/lib/types/routes/sharing/client/index.d.ts +5 -0
  208. package/lib/types/routes/sharing/client/markers.d.ts +25 -0
  209. package/lib/types/routes/sharing/client/repo.d.ts +22 -0
  210. package/lib/types/routes/sharing/client/resolver.d.ts +41 -0
  211. package/lib/types/routes/sharing/client/routes.d.ts +28 -0
  212. package/lib/types/routes/sharing/client/service.d.ts +99 -0
  213. package/lib/types/routes/sharing/client/types.d.ts +99 -0
  214. package/lib/types/routes/sharing/consts.d.ts +4 -0
  215. package/lib/types/routes/sharing/copy/index.d.ts +2 -0
  216. package/lib/types/routes/sharing/copy/service.d.ts +55 -0
  217. package/lib/types/routes/sharing/copy/types.d.ts +17 -0
  218. package/lib/types/routes/sharing/descriptor.d.ts +4 -0
  219. package/lib/types/routes/sharing/index.d.ts +4 -0
  220. package/lib/types/routes/sharing/service.d.ts +57 -0
  221. package/lib/types/routes/sharing/types.d.ts +84 -0
  222. package/lib/types/routes/thumbnails/consts.d.ts +7 -0
  223. package/lib/types/routes/thumbnails/index.d.ts +2 -0
  224. package/lib/types/routes/thumbnails/keys.d.ts +4 -0
  225. package/lib/types/routes/thumbnails/service.d.ts +38 -0
  226. package/lib/types/routes/thumbnails/types.d.ts +9 -0
  227. package/lib/types/utils/scrub.d.ts +2 -0
  228. package/package.json +6 -6
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -46,7 +46,7 @@ class OAuthAppApiBase extends base_1.AppApiBase {
46
46
  ...config
47
47
  };
48
48
  try {
49
- return await this.getApi().request(request);
49
+ return await this.send(request);
50
50
  }
51
51
  catch (err) {
52
52
  if (options.checkRevoked !== false)
@@ -54,6 +54,9 @@ class OAuthAppApiBase extends base_1.AppApiBase {
54
54
  throw err;
55
55
  }
56
56
  }
57
+ async send(request) {
58
+ return await this.getApi().request(request);
59
+ }
57
60
  async checkRevoked(err) {
58
61
  const { refreshPath, authCheckPath, name } = this.props;
59
62
  if (refreshPath || !authCheckPath || this.authFailed || err?.response?.status !== 401)
@@ -135,6 +138,7 @@ class OAuthAppApiBase extends base_1.AppApiBase {
135
138
  this.config.accessToken = data.access_token;
136
139
  this.config.refreshToken = data.refresh_token;
137
140
  this.config.expiration = this.getExpiration(data);
141
+ this.applyRefreshResponse(data);
138
142
  this.logger.logEvent({ message: `${name} refresh token result`, status: 'success' });
139
143
  this.observer.emit('token.updated', this.config);
140
144
  }
@@ -144,6 +148,8 @@ class OAuthAppApiBase extends base_1.AppApiBase {
144
148
  throw err;
145
149
  }
146
150
  }
151
+ applyRefreshResponse(_data) {
152
+ }
147
153
  getSetting(key, defValue) {
148
154
  try {
149
155
  const settings = this.getUserSettings();
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TrainingPeaksApi = void 0;
4
+ const api_1 = require("../../../../api");
4
5
  const sleep_1 = require("../../../../utils/sleep");
5
6
  const xml_1 = require("../../../../utils/xml");
6
7
  const utils_1 = require("../../utils");
@@ -10,6 +11,8 @@ const types_1 = require("./types");
10
11
  const APP_URL = 'https://app.trainingpeaks.com';
11
12
  const SANDBOX_APP_URL = 'https://app.sandbox.trainingpeaks.com';
12
13
  const UPLOAD_CLIENT = 'Incyclist';
14
+ const DEFAULT_USER_AGENT = 'Incyclist/1.0.0';
15
+ const VALID_USER_AGENT = /^[A-Za-z0-9._-]{1,32}\/[A-Za-z0-9._+-]{1,32}$/;
13
16
  const MAX_WORKOUT_RANGE_DAYS = 45;
14
17
  const UPLOAD_POLL_INTERVAL = 2000;
15
18
  const UPLOAD_TIMEOUT = 60000;
@@ -129,6 +132,59 @@ class TrainingPeaksApi extends oauth_1.OAuthAppApiBase {
129
132
  return new Error('File format is not supported by TrainingPeaks');
130
133
  return this.mapUploadRejection(err);
131
134
  }
135
+ getAuthHeaders() {
136
+ return { ...super.getAuthHeaders(), 'User-Agent': this.getUserAgent() };
137
+ }
138
+ getUserAgent() {
139
+ const received = this.config?.userAgent;
140
+ return this.isValidUserAgent(received) ? received : DEFAULT_USER_AGENT;
141
+ }
142
+ isValidUserAgent(value) {
143
+ return typeof value === 'string' && VALID_USER_AGENT.test(value);
144
+ }
145
+ applyRefreshResponse(data) {
146
+ if (this.isValidUserAgent(data.user_agent))
147
+ this.config.userAgent = data.user_agent;
148
+ }
149
+ getBindings() {
150
+ return (0, api_1.getBindings)();
151
+ }
152
+ async send(request) {
153
+ const binding = this.getBindings()?.fetch;
154
+ if (!binding)
155
+ return await super.send(request);
156
+ return await this.sendViaFetchBinding(binding, request);
157
+ }
158
+ async sendViaFetchBinding(binding, request) {
159
+ const headers = { Accept: 'application/json, text/plain, */*', ...request.headers };
160
+ let body;
161
+ if (request.data !== undefined) {
162
+ body = typeof request.data === 'string' ? request.data : JSON.stringify(request.data);
163
+ headers['Content-Type'] ??= 'application/json';
164
+ }
165
+ const res = await binding.fetch(request.url, { method: (request.method ?? 'get').toUpperCase(), headers, body });
166
+ const response = {
167
+ data: request.responseType === 'text' ? res.data : this.parseBody(res.data),
168
+ status: res.status,
169
+ statusText: res.statusText,
170
+ headers: res.headers,
171
+ config: request
172
+ };
173
+ if (!res.ok)
174
+ throw Object.assign(new Error(`Request failed with status code ${res.status}`), { response });
175
+ return response;
176
+ }
177
+ parseBody(text) {
178
+ const trimmed = text?.trim();
179
+ if (!trimmed?.startsWith('{') && !trimmed?.startsWith('['))
180
+ return text;
181
+ try {
182
+ return JSON.parse(trimmed);
183
+ }
184
+ catch {
185
+ return text;
186
+ }
187
+ }
132
188
  getExpiration(data) {
133
189
  const expiresIn = Number(data.expires_in);
134
190
  if (Number.isFinite(expiresIn))
@@ -4,13 +4,14 @@ exports.OAuthAppConnection = void 0;
4
4
  const valid_1 = require("../../../utils/valid");
5
5
  const ConnectedAppService_1 = require("./ConnectedAppService");
6
6
  class OAuthAppConnection extends ConnectedAppService_1.ConnectedAppService {
7
+ initLogShown;
7
8
  async connect(credentials) {
8
9
  this.ensureInitialized();
9
- this.logEvent({ message: `Connect with ${this.appName}` });
10
+ this.logEvent({ message: 'Connect with app', externalApp: this.appName });
10
11
  try {
11
12
  const config = this.createConfig(credentials);
12
13
  if (!(0, valid_1.valid)(config?.accessToken)) {
13
- this.logEvent({ message: `Connect with ${this.appName} failed`, reason: 'no access token' });
14
+ this.logEvent({ message: 'Connect with app failed', externalApp: this.appName, reason: 'no access token' });
14
15
  return false;
15
16
  }
16
17
  if (this.isConnected()) {
@@ -20,11 +21,11 @@ class OAuthAppConnection extends ConnectedAppService_1.ConnectedAppService {
20
21
  this.initApi(config);
21
22
  }
22
23
  this.saveCredentials(config);
23
- this.logEvent({ message: `Connect with ${this.appName} success` });
24
+ this.logEvent({ message: 'Connect with app success', externalApp: this.appName });
24
25
  return true;
25
26
  }
26
27
  catch (err) {
27
- this.logError(err, 'connect');
28
+ this.logError(err, 'connect', { externalApp: this.appName });
28
29
  throw err;
29
30
  }
30
31
  }
@@ -38,7 +39,7 @@ class OAuthAppConnection extends ConnectedAppService_1.ConnectedAppService {
38
39
  this.saveCredentials();
39
40
  }
40
41
  catch (err) {
41
- this.logError(err, 'disconnect');
42
+ this.logError(err, 'disconnect', { externalApp: this.appName });
42
43
  }
43
44
  }
44
45
  isConnected() {
@@ -66,7 +67,10 @@ class OAuthAppConnection extends ConnectedAppService_1.ConnectedAppService {
66
67
  initAuth() {
67
68
  try {
68
69
  const auth = this.getCredentials();
69
- this.logEvent({ message: `${this.appName} init done`, hasCredentials: Boolean(auth) });
70
+ if (!this.initLogShown) {
71
+ this.logEvent({ message: 'external app init done', externalApp: this.appName, hasCredentials: Boolean(auth) });
72
+ this.initLogShown = true;
73
+ }
70
74
  const config = auth ? this.createConfig(auth) : undefined;
71
75
  if ((0, valid_1.valid)(config?.accessToken)) {
72
76
  this.config = config;
@@ -81,8 +85,7 @@ class OAuthAppConnection extends ConnectedAppService_1.ConnectedAppService {
81
85
  }
82
86
  }
83
87
  updateConfig(config) {
84
- const { accessToken, refreshToken, expiration } = config;
85
- this.config = { ...this.config, accessToken, refreshToken, expiration };
88
+ this.config = { ...this.config, ...config };
86
89
  this.saveCredentials();
87
90
  }
88
91
  saveCredentials(config) {
@@ -90,18 +93,16 @@ class OAuthAppConnection extends ConnectedAppService_1.ConnectedAppService {
90
93
  this.config = config;
91
94
  try {
92
95
  if (!this.isConnected()) {
93
- this.logEvent({ message: `${this.appName} Delete Credentials` });
96
+ this.logEvent({ message: 'Delete Credentials', externalApp: this.appName });
94
97
  this.getUserSettings().set(this.getSettingsKey(), null);
95
98
  return;
96
99
  }
97
- this.logEvent({ message: `${this.appName} Save Credentials` });
98
100
  this.getUserSettings().set(this.getSettingsKey(), this.createCredentials(this.config));
99
101
  }
100
102
  catch (err) {
101
- this.logEvent({ message: 'error', fn: 'saveCredentials', error: err.message, stack: err.stack });
103
+ this.logError(err, 'saveCredentials', { externalApp: this.appName });
102
104
  return;
103
105
  }
104
- this.logEvent({ message: `${this.appName} Save Credentials done` });
105
106
  }
106
107
  initApi(config) {
107
108
  const observer = this.getApi().init(config);
@@ -111,7 +112,7 @@ class OAuthAppConnection extends ConnectedAppService_1.ConnectedAppService {
111
112
  }
112
113
  const onToken = (updated) => { this.updateConfig(updated); };
113
114
  const onFailed = () => {
114
- this.logEvent({ message: `${this.appName} authentication failed, credentials removed (reconnect required)` });
115
+ this.logEvent({ message: 'authentication failed, credentials removed (reconnect required)', externalApp: this.appName });
115
116
  this.disconnect();
116
117
  this.emit('auth.failed');
117
118
  };
@@ -68,13 +68,13 @@ let KomootAppConnection = (() => {
68
68
  }
69
69
  async connect(credentials) {
70
70
  this.ensureInitialized();
71
- this.logEvent({ message: 'Komoot Login' });
71
+ this.logEvent({ message: 'Connect with app', externalApp: 'Komoot' });
72
72
  this.emit('login-start');
73
73
  try {
74
74
  const { username, password, userid } = credentials;
75
75
  const { authenticated, error } = await this.getApi().login(username, password, userid);
76
76
  if (authenticated) {
77
- this.logEvent({ message: 'Komoot Login success' });
77
+ this.logEvent({ message: 'Connect with app success', externalApp: 'Komoot' });
78
78
  this.credentials = credentials;
79
79
  this.isInitialized = true;
80
80
  const auth = this.saveCredentials();
@@ -86,7 +86,7 @@ let KomootAppConnection = (() => {
86
86
  }
87
87
  }
88
88
  catch (err) {
89
- this.logEvent({ message: 'Komoot Login failed', error: err.message });
89
+ this.logEvent({ message: 'Connect with app failed', externalApp: 'Komoot', reason: err.message });
90
90
  this.emit('login-failure', err.message);
91
91
  throw err;
92
92
  }
@@ -139,11 +139,12 @@ let KomootAppConnection = (() => {
139
139
  credentials = this.decrypt(CRYPT_ALGO, auth);
140
140
  }
141
141
  }
142
- this.logEvent({ message: 'Komoot init done', hasCredentials: ((0, valid_1.valid)(credentials?.username) && (0, valid_1.valid)(credentials?.password)) });
142
+ if (!this.isInitialized)
143
+ this.logEvent({ message: 'external app init done', externalApp: 'Komoot', hasCredentials: ((0, valid_1.valid)(credentials?.username) && (0, valid_1.valid)(credentials?.password)) });
143
144
  isInitialized = true;
144
145
  }
145
146
  catch (err) {
146
- this.logEvent({ message: 'error', error: err.message, fn: 'init', stack: err.stack });
147
+ this.logError(err, 'init', { externaApp: 'Komoot' });
147
148
  isInitialized = false;
148
149
  }
149
150
  this.setupEventListeners();
@@ -173,16 +174,14 @@ let KomootAppConnection = (() => {
173
174
  }
174
175
  }
175
176
  saveCredentials() {
176
- this.logger.logEvent({ message: 'Komoot Save Credentials' });
177
177
  let auth;
178
178
  try {
179
179
  auth = this.encrypt(CRYPT_ALGO);
180
180
  this.getUserSettings().set('user.auth.komoot', auth);
181
181
  }
182
182
  catch (err) {
183
- this.logEvent({ message: 'error', fn: 'saveCredentials', error: err.message, stack: err.stack });
183
+ this.logError(err, 'saveCredentials', { externalApp: 'Komoot' });
184
184
  }
185
- this.logEvent({ message: 'Komoot Save Credentials done' });
186
185
  return auth;
187
186
  }
188
187
  getSecret(key) {
@@ -74,7 +74,8 @@ let TrainingPeaksAppConnection = (() => {
74
74
  id: credentials?.id === undefined ? undefined : String(credentials.id),
75
75
  accessToken: credentials?.accesstoken,
76
76
  refreshToken: credentials?.refreshtoken,
77
- expiration: (0, utils_1.parseExpiration)(credentials?.expiration)
77
+ expiration: (0, utils_1.parseExpiration)(credentials?.expiration),
78
+ ...(credentials?.useragent ? { userAgent: credentials.useragent } : {})
78
79
  };
79
80
  }
80
81
  createCredentials(config) {
@@ -82,7 +83,8 @@ let TrainingPeaksAppConnection = (() => {
82
83
  id: config.id,
83
84
  accesstoken: config.accessToken,
84
85
  refreshtoken: config.refreshToken,
85
- expiration: config.expiration?.toISOString()
86
+ expiration: config.expiration?.toISOString(),
87
+ ...(config.userAgent ? { useragent: config.userAgent } : {})
86
88
  };
87
89
  }
88
90
  };
@@ -78,7 +78,8 @@ let IncyclistPageService = (() => {
78
78
  return this.pageObserver;
79
79
  }
80
80
  closePage() {
81
- delete IncyclistPageService.currentPage;
81
+ if (IncyclistPageService.currentPage === this)
82
+ delete IncyclistPageService.currentPage;
82
83
  this.getAppState().setState('prevPage', this.name);
83
84
  this.getAppState().setState('currentPage', null);
84
85
  this.getAppState().setState('currentPageService', null);
@@ -70,6 +70,7 @@ let DeviceAccessService = (() => {
70
70
  }
71
71
  interfaces = (__runInitializers(this, _instanceExtraInitializers), {});
72
72
  scanState;
73
+ scanPromise;
73
74
  defaultProps;
74
75
  constructor() {
75
76
  super('DeviceAccess');
@@ -271,14 +272,18 @@ let DeviceAccessService = (() => {
271
272
  this.emit('interface-changed', ifaceName, { ...this.interfaces[ifaceName] });
272
273
  return disconnected;
273
274
  }
274
- async pauseBackgroundActivity() {
275
- const promises = Object.keys(this.interfaces).map((name) => this.getInterface(name)?.pauseBackgroundActivity?.());
275
+ async pauseBackgroundActivity(reason, ifaceNames) {
276
+ const promises = this.getBackgroundInterfaces(ifaceNames).map((name) => this.getInterface(name)?.pauseBackgroundActivity?.(reason));
276
277
  await Promise.allSettled(promises);
277
278
  }
278
- async resumeBackgroundActivity() {
279
- const promises = Object.keys(this.interfaces).map((name) => this.getInterface(name)?.resumeBackgroundActivity?.());
279
+ async resumeBackgroundActivity(reason, ifaceNames) {
280
+ const promises = this.getBackgroundInterfaces(ifaceNames).map((name) => this.getInterface(name)?.resumeBackgroundActivity?.(reason));
280
281
  await Promise.allSettled(promises);
281
282
  }
283
+ getBackgroundInterfaces(ifaceNames) {
284
+ const all = Object.keys(this.interfaces);
285
+ return ifaceNames ? all.filter(name => ifaceNames.includes(name)) : all;
286
+ }
282
287
  async terminate(ifaceName) {
283
288
  await this.disconnect(ifaceName);
284
289
  if (!ifaceName) {
@@ -290,6 +295,21 @@ let DeviceAccessService = (() => {
290
295
  await impl.terminate();
291
296
  }
292
297
  async scan(filter = {}, props = {}) {
298
+ if (this.scanPromise !== undefined) {
299
+ this.logEvent({ message: 'scan joined', requestedBy: 'scan' });
300
+ return this.scanPromise;
301
+ }
302
+ const promise = this.runScan(filter, props);
303
+ this.scanPromise = promise;
304
+ try {
305
+ return await promise;
306
+ }
307
+ finally {
308
+ if (this.scanPromise === promise)
309
+ delete this.scanPromise;
310
+ }
311
+ }
312
+ async runScan(filter = {}, props = {}) {
293
313
  this.logEvent({ message: 'device scan start', filter, props });
294
314
  const detected = [];
295
315
  const onDataHandlers = {};
@@ -19,3 +19,4 @@ __exportStar(require("./access"), exports);
19
19
  __exportStar(require("./ride"), exports);
20
20
  __exportStar(require("./pairing"), exports);
21
21
  __exportStar(require("./page"), exports);
22
+ __exportStar(require("./known-names"), exports);
@@ -0,0 +1,22 @@
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
+ exports.matchesNamePart = exports.getNameParts = exports.isKnownDeviceName = void 0;
18
+ __exportStar(require("./service"), exports);
19
+ var matching_1 = require("./matching");
20
+ Object.defineProperty(exports, "isKnownDeviceName", { enumerable: true, get: function () { return matching_1.isKnownDeviceName; } });
21
+ Object.defineProperty(exports, "getNameParts", { enumerable: true, get: function () { return matching_1.getNameParts; } });
22
+ Object.defineProperty(exports, "matchesNamePart", { enumerable: true, get: function () { return matching_1.matchesNamePart; } });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KNOWN_DEVICE_NAMES = void 0;
4
+ exports.KNOWN_DEVICE_NAMES = {
5
+ version: 1,
6
+ names: [
7
+ '808s',
8
+ 'amazfit',
9
+ 'assioma*',
10
+ 'bk6*',
11
+ 'bkool*',
12
+ 'bryton',
13
+ 'cad',
14
+ 'cog',
15
+ 'coros',
16
+ 'cycplus',
17
+ 'd500v2',
18
+ 'direto',
19
+ 'fenix',
20
+ 'fit3',
21
+ 'forerunner',
22
+ 'g1mplus*',
23
+ 'h6m',
24
+ 'hammer',
25
+ 'hr50',
26
+ 'hrm*',
27
+ 'hw9',
28
+ 'iconsole',
29
+ 'jficcycle',
30
+ 'kickr',
31
+ 'kwikwi',
32
+ 'mrk',
33
+ 'neo',
34
+ 'polar',
35
+ 'spd',
36
+ 'stryd*',
37
+ 'suito',
38
+ 'tacx',
39
+ 'think',
40
+ 'tickr',
41
+ 'toputure',
42
+ 'trackr',
43
+ 'tuo',
44
+ 'vanrysel',
45
+ 'victory',
46
+ 'voactiv',
47
+ 'volt',
48
+ 'wahoo',
49
+ 'whoop',
50
+ 'xoss',
51
+ 'yesoul',
52
+ 'zwift',
53
+ 'zycle*',
54
+ ],
55
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isKnownDeviceName = exports.matchesNamePart = exports.getNameParts = void 0;
4
+ const known_device_names_1 = require("./known-device-names");
5
+ const isDeviceId = (part) => /^\d+$/.test(part) || (/^[\da-f]+$/.test(part) && /\d/.test(part));
6
+ const cutSerialNumber = (part) => {
7
+ const start = part.search(/\d{4}/);
8
+ return start < 0 ? part : part.slice(0, start);
9
+ };
10
+ const getNameParts = (name) => {
11
+ if (!name || typeof name !== 'string')
12
+ return [];
13
+ return name
14
+ .toLowerCase()
15
+ .split(/[^a-z0-9]+/)
16
+ .map(cutSerialNumber)
17
+ .filter(part => part.length >= 3 && !isDeviceId(part));
18
+ };
19
+ exports.getNameParts = getNameParts;
20
+ const matchesNamePart = (entry, part) => entry.endsWith('*') ? part.startsWith(entry.slice(0, -1)) : part === entry;
21
+ exports.matchesNamePart = matchesNamePart;
22
+ const isKnownDeviceName = (name, entries = known_device_names_1.KNOWN_DEVICE_NAMES.names) => {
23
+ const parts = (0, exports.getNameParts)(name);
24
+ return parts.some(part => entries.some(entry => (0, exports.matchesNamePart)(entry, part)));
25
+ };
26
+ exports.isKnownDeviceName = isKnownDeviceName;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getKnownDeviceNames = void 0;
4
+ const known_device_names_1 = require("./known-device-names");
5
+ const getKnownDeviceNames = () => ({
6
+ version: known_device_names_1.KNOWN_DEVICE_NAMES.version,
7
+ names: [...known_device_names_1.KNOWN_DEVICE_NAMES.names],
8
+ });
9
+ exports.getKnownDeviceNames = getKnownDeviceNames;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -68,6 +68,8 @@ let PairingPageService = (() => {
68
68
  isPairingForRide = false;
69
69
  isVisitOpen = false;
70
70
  handingOffToRide = false;
71
+ isOpen = false;
72
+ closeIgnoredLogged = false;
71
73
  guidance;
72
74
  onPairingStateHandler = this.onPairingState.bind(this);
73
75
  onExclusionRevertedHandler = this.onExclusionReverted.bind(this);
@@ -96,6 +98,8 @@ let PairingPageService = (() => {
96
98
  this.logEvent({ message: 'page shown', page: 'Pairing', forRide });
97
99
  this.isPairingForRide = forRide ?? false;
98
100
  this.handingOffToRide = false;
101
+ this.isOpen = true;
102
+ this.closeIgnoredLogged = false;
99
103
  this.openVisit();
100
104
  this.listenToPairingState(true);
101
105
  gd_eventlog_1.EventLogger.setGlobalConfig('page', 'Pairing');
@@ -125,6 +129,14 @@ let PairingPageService = (() => {
125
129
  return this.getPageObserver();
126
130
  }
127
131
  closePage() {
132
+ if (!this.isOpen) {
133
+ if (!this.closeIgnoredLogged) {
134
+ this.closeIgnoredLogged = true;
135
+ this.logEvent({ message: 'page close ignored', page: 'Pairing' });
136
+ }
137
+ return;
138
+ }
139
+ this.isOpen = false;
128
140
  try {
129
141
  this.logEvent({ message: 'page closed', page: 'Pairing' });
130
142
  this.isVisitOpen = false;
@@ -549,9 +561,15 @@ let PairingPageService = (() => {
549
561
  g.openVisit({ visitId, platform: this.getPlatform(), forRide: this.isPairingForRide });
550
562
  g.setDeviceListOpen(this.openedCapability !== undefined);
551
563
  }, 'openVisit');
552
- this.trackVisit(t => t.setExitFields(() => ({ ...this.guidance.getExitFields() })), 'openVisit');
564
+ this.trackVisit(t => t.setExitFields(() => ({ ...this.guidance.getExitFields(), inFlight: this.getInFlight() })), 'openVisit');
553
565
  this.isVisitOpen = true;
554
566
  }
567
+ getInFlight() {
568
+ const activity = this.getDevicePairing().getActivity?.();
569
+ if (activity?.pairing)
570
+ return 'pairing';
571
+ return activity?.scanning ? 'scanning' : 'none';
572
+ }
555
573
  closeVisit(via) {
556
574
  this.commitConflictStep('left_page');
557
575
  delete this.cardChoices;
@@ -140,6 +140,12 @@ class PairingVisitTracker {
140
140
  last: { ...last, closed: true, via, canStartRide, backgroundMs, backgroundedAt: undefined, closedAt: now },
141
141
  });
142
142
  }
143
+ getLastExit() {
144
+ const last = this.deps.store.get()?.last;
145
+ if (!last?.closed || !last.via || last.closedAt === undefined || last.sessionId !== this.deps.sessionId)
146
+ return undefined;
147
+ return { via: last.via, ageMs: this.deps.now() - last.closedAt };
148
+ }
143
149
  onAppExit(canStartRide) {
144
150
  this.closeVisit('app_exit', { canStartRide });
145
151
  }