incyclist-services 1.9.32 → 1.9.34
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/README.MD +72 -0
- package/lib/cjs/activities/upload/factory.js +9 -2
- package/lib/cjs/activities/upload/intervals.js +0 -2
- package/lib/cjs/activities/upload/komoot.js +0 -2
- package/lib/cjs/activities/upload/ridewithgps.js +0 -2
- package/lib/cjs/activities/upload/strava.js +0 -3
- package/lib/cjs/activities/upload/trainerday.js +0 -2
- package/lib/cjs/activities/upload/trainingpeaks.js +0 -2
- package/lib/cjs/api/rest/api.js +109 -4
- package/lib/cjs/api/rest/types.js +2 -0
- package/lib/cjs/apps/service.js +3 -0
- package/lib/cjs/devices/ride/service.js +103 -1
- package/lib/cjs/devices/ride/timeouts.js +2 -1
- package/lib/cjs/ride/base/base.js +3 -0
- package/lib/cjs/ride/display/service.js +333 -10
- package/lib/cjs/ride/page/service.js +16 -0
- package/lib/cjs/ride/route/FreeRideDisplayService.js +6 -0
- package/lib/cjs/ride/route/GpxDisplayService.js +22 -0
- package/lib/cjs/ride/route/MapillaryRide.js +551 -0
- package/lib/cjs/ride/route/RLVDisplayService.js +15 -0
- package/lib/cjs/routes/base/api/api.js +18 -3
- package/lib/cjs/routes/base/api/factory.js +12 -2
- package/lib/cjs/routes/base/api/unconfigured.js +24 -0
- package/lib/cjs/routes/base/parsers/utils.js +12 -1
- package/lib/cjs/routes/imagery/index.js +17 -0
- package/lib/cjs/routes/imagery/mapillary/api.js +113 -0
- package/lib/cjs/routes/imagery/mapillary/codec.js +123 -0
- package/lib/cjs/routes/imagery/mapillary/frame.js +165 -0
- package/lib/cjs/routes/imagery/mapillary/index.js +24 -0
- package/lib/cjs/routes/imagery/mapillary/resolve.js +16 -0
- package/lib/cjs/routes/imagery/mapillary/service.js +709 -0
- package/lib/cjs/routes/imagery/mapillary/source.js +48 -0
- package/lib/cjs/routes/imagery/mapillary/store.js +196 -0
- package/lib/cjs/routes/imagery/mapillary/types.js +2 -0
- package/lib/cjs/routes/index.js +1 -0
- package/lib/cjs/routes/list/cards/RouteCard.js +9 -10
- package/lib/cjs/routes/list/loaders/api.js +202 -39
- package/lib/cjs/routes/list/service.js +217 -26
- package/lib/cjs/routes/servers/errors.js +14 -0
- package/lib/cjs/routes/servers/index.js +15 -0
- package/lib/cjs/routes/servers/known-servers.json +1 -0
- package/lib/cjs/routes/servers/known.js +11 -0
- package/lib/cjs/routes/servers/messages.js +35 -0
- package/lib/cjs/routes/servers/page/base/service.js +708 -0
- package/lib/cjs/routes/servers/page/base/types.js +2 -0
- package/lib/cjs/routes/servers/page/base/utils.js +34 -0
- package/lib/cjs/routes/servers/page/desktop/service.js +10 -0
- package/lib/cjs/routes/servers/page/index.js +28 -0
- package/lib/cjs/routes/servers/page/mobile/service.js +69 -0
- package/lib/cjs/routes/servers/page/types.js +2 -0
- package/lib/cjs/routes/servers/probe.js +72 -0
- package/lib/cjs/routes/servers/status.js +97 -0
- package/lib/cjs/routes/servers/types.js +2 -0
- package/lib/cjs/routes/servers/validator.js +209 -0
- package/lib/cjs/routes/sync/base/provider.js +15 -5
- package/lib/cjs/routes/sync/komoot/provider.js +5 -4
- package/lib/cjs/routes/sync/ridewithgps/provider.js +9 -8
- package/lib/cjs/routes/sync/strava/provider.js +3 -3
- package/lib/cjs/settings/display/index.js +1 -0
- package/lib/cjs/settings/display/routeservers/index.js +21 -0
- package/lib/cjs/settings/display/routeservers/service.js +709 -0
- package/lib/cjs/settings/display/routeservers/types.js +2 -0
- package/lib/cjs/settings/display/routeservers/utils.js +34 -0
- package/lib/cjs/utils/string.js +8 -1
- package/lib/cjs/workouts/calendar/sync/base/provider.js +6 -1
- package/lib/cjs/workouts/calendar/sync/intervals/provider.js +5 -2
- package/lib/esm/activities/upload/factory.js +9 -2
- package/lib/esm/activities/upload/intervals.js +0 -2
- package/lib/esm/activities/upload/komoot.js +0 -2
- package/lib/esm/activities/upload/ridewithgps.js +0 -2
- package/lib/esm/activities/upload/strava.js +0 -3
- package/lib/esm/activities/upload/trainerday.js +0 -2
- package/lib/esm/activities/upload/trainingpeaks.js +0 -2
- package/lib/esm/api/rest/api.js +76 -1
- package/lib/esm/api/rest/types.js +1 -1
- package/lib/esm/apps/service.js +3 -0
- package/lib/esm/devices/ride/service.js +104 -2
- package/lib/esm/devices/ride/timeouts.js +1 -0
- package/lib/esm/ride/base/base.js +3 -0
- package/lib/esm/ride/display/service.js +333 -10
- package/lib/esm/ride/page/service.js +16 -0
- package/lib/esm/ride/route/FreeRideDisplayService.js +6 -0
- package/lib/esm/ride/route/GpxDisplayService.js +22 -0
- package/lib/esm/ride/route/MapillaryRide.js +682 -0
- package/lib/esm/ride/route/RLVDisplayService.js +15 -0
- package/lib/esm/routes/base/api/api.js +18 -3
- package/lib/esm/routes/base/api/factory.js +11 -1
- package/lib/esm/routes/base/api/unconfigured.js +20 -0
- package/lib/esm/routes/base/parsers/utils.js +10 -0
- package/lib/esm/routes/imagery/index.js +1 -0
- package/lib/esm/routes/imagery/mapillary/api.js +109 -0
- package/lib/esm/routes/imagery/mapillary/codec.js +114 -0
- package/lib/esm/routes/imagery/mapillary/frame.js +156 -0
- package/lib/esm/routes/imagery/mapillary/index.js +8 -0
- package/lib/esm/routes/imagery/mapillary/resolve.js +12 -0
- package/lib/esm/routes/imagery/mapillary/service.js +757 -0
- package/lib/esm/routes/imagery/mapillary/source.js +44 -0
- package/lib/esm/routes/imagery/mapillary/store.js +193 -0
- package/lib/esm/routes/imagery/mapillary/types.js +1 -0
- package/lib/esm/routes/imagery/mapillary/windows.js +152 -0
- package/lib/esm/routes/index.js +1 -0
- package/lib/esm/routes/list/cards/RouteCard.js +3 -4
- package/lib/esm/routes/list/loaders/api.js +202 -39
- package/lib/esm/routes/list/service.js +211 -20
- package/lib/esm/routes/servers/errors.js +10 -0
- package/lib/esm/routes/servers/index.js +4 -0
- package/lib/esm/routes/servers/known-servers.json +1 -0
- package/lib/esm/routes/servers/known.js +4 -0
- package/lib/esm/routes/servers/messages.js +32 -0
- package/lib/esm/routes/servers/page/base/service.js +705 -0
- package/lib/esm/routes/servers/page/base/types.js +1 -0
- package/lib/esm/routes/servers/page/base/utils.js +29 -0
- package/lib/esm/routes/servers/page/desktop/service.js +6 -0
- package/lib/esm/routes/servers/page/index.js +19 -0
- package/lib/esm/routes/servers/page/mobile/service.js +66 -0
- package/lib/esm/routes/servers/page/types.js +1 -0
- package/lib/esm/routes/servers/probe.js +63 -0
- package/lib/esm/routes/servers/status.js +93 -0
- package/lib/esm/routes/servers/types.js +1 -0
- package/lib/esm/routes/servers/validator.js +199 -0
- package/lib/esm/routes/sync/base/provider.js +15 -5
- package/lib/esm/routes/sync/komoot/provider.js +5 -4
- package/lib/esm/routes/sync/ridewithgps/provider.js +9 -8
- package/lib/esm/routes/sync/strava/provider.js +3 -3
- package/lib/esm/settings/display/index.js +1 -0
- package/lib/esm/settings/display/routeservers/index.js +2 -0
- package/lib/esm/settings/display/routeservers/service.js +705 -0
- package/lib/esm/settings/display/routeservers/types.js +1 -0
- package/lib/esm/settings/display/routeservers/utils.js +29 -0
- package/lib/esm/utils/string.js +6 -0
- package/lib/esm/workouts/calendar/sync/base/provider.js +6 -1
- package/lib/esm/workouts/calendar/sync/intervals/provider.js +5 -2
- package/lib/types/api/fs/index.d.ts +3 -0
- package/lib/types/api/rest/api.d.ts +6 -1
- package/lib/types/api/rest/types.d.ts +7 -0
- package/lib/types/apps/service.d.ts +4 -0
- package/lib/types/devices/ride/service.d.ts +9 -1
- package/lib/types/devices/ride/timeouts.d.ts +1 -0
- package/lib/types/devices/ride/types.d.ts +1 -0
- package/lib/types/ride/base/base.d.ts +2 -1
- package/lib/types/ride/base/types.d.ts +27 -0
- package/lib/types/ride/display/service.d.ts +53 -1
- package/lib/types/ride/page/service.d.ts +2 -0
- package/lib/types/ride/page/types.d.ts +2 -0
- package/lib/types/ride/route/FreeRideDisplayService.d.ts +2 -1
- package/lib/types/ride/route/GpxDisplayService.d.ts +3 -1
- package/lib/types/ride/route/MapillaryRide.d.ts +217 -0
- package/lib/types/ride/route/RLVDisplayService.d.ts +4 -1
- package/lib/types/routes/base/api/api.d.ts +9 -0
- package/lib/types/routes/base/api/factory.d.ts +2 -0
- package/lib/types/routes/base/api/unconfigured.d.ts +10 -0
- package/lib/types/routes/base/parsers/utils.d.ts +1 -0
- package/lib/types/routes/imagery/index.d.ts +1 -0
- package/lib/types/routes/imagery/mapillary/api.d.ts +17 -0
- package/lib/types/routes/imagery/mapillary/codec.d.ts +17 -0
- package/lib/types/routes/imagery/mapillary/frame.d.ts +16 -0
- package/lib/types/routes/imagery/mapillary/index.d.ts +8 -0
- package/lib/types/routes/imagery/mapillary/resolve.d.ts +12 -0
- package/lib/types/routes/imagery/mapillary/service.d.ts +130 -0
- package/lib/types/routes/imagery/mapillary/source.d.ts +26 -0
- package/lib/types/routes/imagery/mapillary/store.d.ts +36 -0
- package/lib/types/routes/imagery/mapillary/types.d.ts +175 -0
- package/lib/types/routes/imagery/mapillary/windows.d.ts +43 -0
- package/lib/types/routes/index.d.ts +1 -0
- package/lib/types/routes/list/loaders/api.d.ts +35 -3
- package/lib/types/routes/list/service.d.ts +43 -2
- package/lib/types/routes/list/types.d.ts +1 -0
- package/lib/types/routes/servers/errors.d.ts +6 -0
- package/lib/types/routes/servers/index.d.ts +5 -0
- package/lib/types/routes/servers/known.d.ts +2 -0
- package/lib/types/routes/servers/messages.d.ts +31 -0
- package/lib/types/routes/servers/page/base/service.d.ts +103 -0
- package/lib/types/routes/servers/page/base/types.d.ts +77 -0
- package/lib/types/routes/servers/page/base/utils.d.ts +2 -0
- package/lib/types/routes/servers/page/desktop/service.d.ts +4 -0
- package/lib/types/routes/servers/page/index.d.ts +9 -0
- package/lib/types/routes/servers/page/mobile/service.d.ts +6 -0
- package/lib/types/routes/servers/page/types.d.ts +1 -0
- package/lib/types/routes/servers/probe.d.ts +7 -0
- package/lib/types/routes/servers/status.d.ts +15 -0
- package/lib/types/routes/servers/types.d.ts +56 -0
- package/lib/types/routes/servers/validator.d.ts +8 -0
- package/lib/types/routes/sync/base/provider.d.ts +1 -0
- package/lib/types/settings/display/index.d.ts +1 -0
- package/lib/types/settings/display/routeservers/index.d.ts +3 -0
- package/lib/types/settings/display/routeservers/service.d.ts +102 -0
- package/lib/types/settings/display/routeservers/types.d.ts +76 -0
- package/lib/types/settings/display/routeservers/utils.d.ts +2 -0
- package/lib/types/utils/string.d.ts +1 -0
- package/lib/types/workouts/calendar/sync/base/provider.d.ts +4 -3
- package/lib/types/workouts/calendar/sync/trainerday/provider.d.ts +1 -1
- package/lib/types/workouts/calendar/sync/trainingpeaks/provider.d.ts +1 -1
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -110,6 +110,78 @@ import { useDeviceConfiguration, initUserSettings } from 'incyclist-services'
|
|
|
110
110
|
|
|
111
111
|
`useXXX()` returns a service singleton, and `initXXX()` initializes one where needed.
|
|
112
112
|
|
|
113
|
+
## Route servers
|
|
114
|
+
|
|
115
|
+
Besides the built-in Incyclist route server, the app can load routes from additional route
|
|
116
|
+
servers. Each route remembers the server it came from, and that server's name is its *Source*
|
|
117
|
+
in the route list filter. A route supplied by an external server stays attributed to that
|
|
118
|
+
server: an Incyclist route with the same id will not replace it.
|
|
119
|
+
|
|
120
|
+
### Adding a route server as a user
|
|
121
|
+
|
|
122
|
+
In the app, open **Settings › Routes** (or the **Import Routes** dialog) and choose
|
|
123
|
+
**Add route server**. Pick a server from the known list, or enter an address and a name:
|
|
124
|
+
|
|
125
|
+
- The address must be `https://`. Plain `http://` is accepted only for servers on your home
|
|
126
|
+
network (`localhost`, private IP addresses, `*.local` names and single-label names such as
|
|
127
|
+
`nas`), and not on devices that don't allow it (currently Android).
|
|
128
|
+
- The address is the plain base URL of the server: it must not contain a query string (`?...`).
|
|
129
|
+
- The name (up to 24 letters, numbers, spaces or dashes) is the label shown in the route list.
|
|
130
|
+
It must not clash with an existing source such as `Local`, `Incyclist` or a connected app.
|
|
131
|
+
|
|
132
|
+
The server is checked before it is saved. Servers are stored in the user settings under
|
|
133
|
+
`routes.servers.<name>`, so a server can also be added by hand in `settings.json`. Entries
|
|
134
|
+
written there are not validated by the app and keep loading as they are.
|
|
135
|
+
|
|
136
|
+
### Adding a server to the known list (maintainers)
|
|
137
|
+
|
|
138
|
+
The known list is the data file [`src/routes/servers/known-servers.json`](./src/routes/servers/known-servers.json).
|
|
139
|
+
It ships empty. While it is empty, the add screen only offers manual entry. To list a server,
|
|
140
|
+
add an entry. No code change is needed:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
[
|
|
144
|
+
{
|
|
145
|
+
"id": "alpine-video-club",
|
|
146
|
+
"name": "Alpine Videos",
|
|
147
|
+
"url": "https://videos.example.org/api/v1/routes",
|
|
148
|
+
"description": "Alps & Dolomites, 40+ climbs",
|
|
149
|
+
"operator": "Alpine Video Club"
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
| Field | Rules |
|
|
155
|
+
|---|---|
|
|
156
|
+
| `id` | Required, stable and unique. Used for logging. |
|
|
157
|
+
| `name` | Required. Same rules as a user-entered name (see above). Becomes the source name. |
|
|
158
|
+
| `url` | Required. `https://` only. The server's routes API base URL. |
|
|
159
|
+
| `description` | Required. One short line, about 40 characters. |
|
|
160
|
+
| `operator` | Optional. Shown as "by ...". |
|
|
161
|
+
|
|
162
|
+
Test the server against Incyclist before listing it. A unit test checks every entry against
|
|
163
|
+
the name and URL rules and for unique ids and URLs, so run `npm test -- src/routes/servers`
|
|
164
|
+
after editing the file. The list is part of the UI bundle, so a change reaches users with the
|
|
165
|
+
next bundle release.
|
|
166
|
+
|
|
167
|
+
### What a route server must provide
|
|
168
|
+
|
|
169
|
+
A route server is a plain HTTPS service. Incyclist checks a server by requesting
|
|
170
|
+
`<base-url>?type=video`, which must answer with a JSON array of
|
|
171
|
+
[`RouteApiDescription`](./src/routes/base/api/types.ts#L11) objects. Route details are then
|
|
172
|
+
requested from `<base-url>/<route-id>`, which must answer with a
|
|
173
|
+
[`RouteApiDetail`](./src/routes/base/api/types.ts#L51). A reachable server that answers
|
|
174
|
+
something else, such as an HTML page or a 404, is rejected as "not a route server". Redirects
|
|
175
|
+
that would lead to a URL the app would not accept (for example from `https://` to `http://`)
|
|
176
|
+
are rejected too: a server on the internet can never send the app to a host on the home network.
|
|
177
|
+
Requests to a server are given up after 30 seconds. The server then counts as unreachable.
|
|
178
|
+
A route can only be updated by the server it belongs to: a server that offers the id of an
|
|
179
|
+
Incyclist route (or of a route of another server) does not replace it.
|
|
180
|
+
|
|
181
|
+
GPX routes are optional. The app also requests `<base-url>?type=route` for them, with the same
|
|
182
|
+
kind of response. A server that does not support this request is still loaded normally and keeps
|
|
183
|
+
its video routes.
|
|
184
|
+
|
|
113
185
|
## Using this library in your own app
|
|
114
186
|
|
|
115
187
|
The library never calls platform APIs directly. File access, settings storage, secrets,
|
|
@@ -79,9 +79,16 @@ let ActivityUploadFactory = (() => {
|
|
|
79
79
|
this.uploaders.forEach(ui => {
|
|
80
80
|
const { service, uploader } = ui;
|
|
81
81
|
if (uploader.isConnected() && this.getAppsService().isEnabled(service, 'ActivityUpload')) {
|
|
82
|
+
this.getAppsService().logEvent({ message: 'start activity upload', externalApp: service });
|
|
82
83
|
const promise = uploader.upload(activity, format)
|
|
83
|
-
.then(success =>
|
|
84
|
-
.
|
|
84
|
+
.then(success => {
|
|
85
|
+
this.getAppsService().logEvent({ message: 'activity upload finished', externalApp: service });
|
|
86
|
+
return { service, success };
|
|
87
|
+
})
|
|
88
|
+
.catch(err => {
|
|
89
|
+
this.getAppsService().logEvent({ message: 'activity upload failed', externalApp: service, reason: err.message });
|
|
90
|
+
return { service, success: false, error: err.message };
|
|
91
|
+
});
|
|
85
92
|
uploads.push({ service, promise, status: undefined });
|
|
86
93
|
}
|
|
87
94
|
});
|
|
@@ -79,7 +79,6 @@ let IntervalsUpload = (() => {
|
|
|
79
79
|
try {
|
|
80
80
|
const ok = this.ensureInitialized();
|
|
81
81
|
if (!ok) {
|
|
82
|
-
this.logEvent({ message: 'Intervals.icu Upload skipped', reason: 'not initialized' });
|
|
83
82
|
return false;
|
|
84
83
|
}
|
|
85
84
|
if (!this.isConnected())
|
|
@@ -103,7 +102,6 @@ let IntervalsUpload = (() => {
|
|
|
103
102
|
return true;
|
|
104
103
|
}
|
|
105
104
|
catch (err) {
|
|
106
|
-
this.logEvent({ message: 'Intervals.icu Upload failure', error: err.message });
|
|
107
105
|
activity.links.intervals = {
|
|
108
106
|
error: err.message
|
|
109
107
|
};
|
|
@@ -80,7 +80,6 @@ let KomootUpload = (() => {
|
|
|
80
80
|
try {
|
|
81
81
|
const ok = this.ensureInitialized();
|
|
82
82
|
if (!ok) {
|
|
83
|
-
this.logEvent({ message: 'Komoot Upload skipped', reason: 'not initialized' });
|
|
84
83
|
return false;
|
|
85
84
|
}
|
|
86
85
|
if (!this.isConnected())
|
|
@@ -109,7 +108,6 @@ let KomootUpload = (() => {
|
|
|
109
108
|
return true;
|
|
110
109
|
}
|
|
111
110
|
catch (err) {
|
|
112
|
-
this.logEvent({ message: 'Komoot Upload failure', error: err.message });
|
|
113
111
|
activity.links.komoot = {
|
|
114
112
|
error: err.message
|
|
115
113
|
};
|
|
@@ -80,7 +80,6 @@ let RideWithGpsUpload = (() => {
|
|
|
80
80
|
}
|
|
81
81
|
async upload(activity, format = 'TCX') {
|
|
82
82
|
if (!this.ensureInitialized()) {
|
|
83
|
-
this.logEvent({ message: 'RideWithGPS Upload skipped', reason: 'not initialized' });
|
|
84
83
|
return false;
|
|
85
84
|
}
|
|
86
85
|
if (!this.isConnected())
|
|
@@ -93,7 +92,6 @@ let RideWithGpsUpload = (() => {
|
|
|
93
92
|
}
|
|
94
93
|
catch (err) {
|
|
95
94
|
const error = err?.message ?? String(err);
|
|
96
|
-
this.logEvent({ message: 'RideWithGPS Upload failure', error });
|
|
97
95
|
this.setLink(activity, { error });
|
|
98
96
|
return false;
|
|
99
97
|
}
|
|
@@ -80,7 +80,6 @@ let StravaUpload = (() => {
|
|
|
80
80
|
try {
|
|
81
81
|
const ok = this.ensureInitialized();
|
|
82
82
|
if (!ok) {
|
|
83
|
-
this.logEvent({ message: 'Strava Upload skipped', reason: 'not initialized' });
|
|
84
83
|
return false;
|
|
85
84
|
}
|
|
86
85
|
if (!this.isConnected())
|
|
@@ -105,14 +104,12 @@ let StravaUpload = (() => {
|
|
|
105
104
|
}
|
|
106
105
|
catch (err) {
|
|
107
106
|
if (err instanceof strava_1.DuplicateError) {
|
|
108
|
-
this.logEvent({ message: 'Strava Upload failure', error: 'duplicate', activityId: err.stravaId });
|
|
109
107
|
activity.links.strava = {
|
|
110
108
|
activity_id: err.stravaId,
|
|
111
109
|
url: this.getUrl(err.stravaId)
|
|
112
110
|
};
|
|
113
111
|
}
|
|
114
112
|
else {
|
|
115
|
-
this.logEvent({ message: 'Strava Upload failure', error: err.message });
|
|
116
113
|
activity.links.strava = {
|
|
117
114
|
error: err.message
|
|
118
115
|
};
|
|
@@ -85,7 +85,6 @@ let TrainerDayUpload = (() => {
|
|
|
85
85
|
}
|
|
86
86
|
async upload(activity, format = 'TCX') {
|
|
87
87
|
if (!this.ensureInitialized()) {
|
|
88
|
-
this.logEvent({ message: 'TrainerDay Upload skipped', reason: 'not initialized' });
|
|
89
88
|
return false;
|
|
90
89
|
}
|
|
91
90
|
if (!this.isConnected())
|
|
@@ -112,7 +111,6 @@ let TrainerDayUpload = (() => {
|
|
|
112
111
|
}
|
|
113
112
|
catch (err) {
|
|
114
113
|
const error = err?.message ?? String(err);
|
|
115
|
-
this.logEvent({ message: 'TrainerDay Upload failure', error });
|
|
116
114
|
this.setLink(activity, { error });
|
|
117
115
|
return false;
|
|
118
116
|
}
|
|
@@ -85,7 +85,6 @@ let TrainingPeaksUpload = (() => {
|
|
|
85
85
|
}
|
|
86
86
|
async upload(activity, format = 'TCX') {
|
|
87
87
|
if (!this.ensureInitialized()) {
|
|
88
|
-
this.logEvent({ message: 'TrainingPeaks Upload skipped', reason: 'not initialized' });
|
|
89
88
|
return false;
|
|
90
89
|
}
|
|
91
90
|
if (!this.isConnected())
|
|
@@ -108,7 +107,6 @@ let TrainingPeaksUpload = (() => {
|
|
|
108
107
|
catch (err) {
|
|
109
108
|
if (err instanceof trainingpeaks_1.TrainingPeaksDuplicateError)
|
|
110
109
|
return await this.onDuplicate(activity);
|
|
111
|
-
this.logEvent({ message: 'TrainingPeaks Upload failure', error: err.message });
|
|
112
110
|
this.setLink(activity, { error: err.message });
|
|
113
111
|
return false;
|
|
114
112
|
}
|
package/lib/cjs/api/rest/api.js
CHANGED
|
@@ -1,16 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
5
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
36
|
exports.ApiClient = void 0;
|
|
7
|
-
const axios_1 =
|
|
37
|
+
const axios_1 = __importStar(require("axios"));
|
|
8
38
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
9
39
|
const uuid_1 = require("uuid");
|
|
40
|
+
const types_1 = require("./types");
|
|
41
|
+
const getResponseUrl = (res) => {
|
|
42
|
+
return res?.request?.res?.responseUrl ?? res?.request?.responseURL;
|
|
43
|
+
};
|
|
44
|
+
const getRequestUrl = (config) => {
|
|
45
|
+
try {
|
|
46
|
+
return axios_1.default.getUri(config);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return config.url;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const getRedirectUrl = (options) => {
|
|
53
|
+
if (typeof options?.href === 'string')
|
|
54
|
+
return options.href;
|
|
55
|
+
if (!options?.protocol || !(options.host ?? options.hostname))
|
|
56
|
+
return undefined;
|
|
57
|
+
return `${options.protocol}//${options.host ?? options.hostname}${options.path ?? ''}`;
|
|
58
|
+
};
|
|
59
|
+
const redirectNotAllowed = (message, config, request, response) => {
|
|
60
|
+
return new axios_1.AxiosError(message, types_1.REDIRECT_NOT_ALLOWED, config, request, response);
|
|
61
|
+
};
|
|
10
62
|
class ApiClient {
|
|
11
63
|
axios;
|
|
12
64
|
logger;
|
|
13
65
|
requests;
|
|
66
|
+
redirectSkipLogged = false;
|
|
14
67
|
requestInterceptorId;
|
|
15
68
|
responseInterceptorId;
|
|
16
69
|
constructor() {
|
|
@@ -34,10 +87,62 @@ class ApiClient {
|
|
|
34
87
|
headers['X-API-Key'] = props['apiKey'];
|
|
35
88
|
}
|
|
36
89
|
this.axios = axios_1.default.create({ headers });
|
|
90
|
+
this.registerRedirectPolicy(this.axios);
|
|
37
91
|
if (requestLog) {
|
|
38
92
|
this.enableLogging();
|
|
39
93
|
}
|
|
40
94
|
}
|
|
95
|
+
registerRedirectPolicy(client) {
|
|
96
|
+
client.interceptors.request.use((config) => this.onRedirectPolicyRequest(config));
|
|
97
|
+
client.interceptors.response.use((res) => this.onRedirectPolicyResponse(res), (err) => this.onRedirectPolicyError(err));
|
|
98
|
+
}
|
|
99
|
+
onRedirectPolicyRequest(config) {
|
|
100
|
+
const policy = config?.redirectPolicy;
|
|
101
|
+
if (!policy)
|
|
102
|
+
return config;
|
|
103
|
+
const origin = getRequestUrl(config);
|
|
104
|
+
const previous = config.beforeRedirect;
|
|
105
|
+
config.beforeRedirect = (options, responseDetails, requestDetails) => {
|
|
106
|
+
previous?.(options, responseDetails, requestDetails);
|
|
107
|
+
const target = getRedirectUrl(options);
|
|
108
|
+
if (target && !policy(target, origin)) {
|
|
109
|
+
this.logger.logEvent({ message: 'redirect refused', stage: 'before redirect' });
|
|
110
|
+
throw redirectNotAllowed('redirect not allowed', config);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return config;
|
|
114
|
+
}
|
|
115
|
+
onRedirectPolicyResponse(res) {
|
|
116
|
+
const config = res?.config;
|
|
117
|
+
const policy = config?.redirectPolicy;
|
|
118
|
+
if (!policy)
|
|
119
|
+
return res;
|
|
120
|
+
const origin = getRequestUrl(config);
|
|
121
|
+
const finalUrl = getResponseUrl(res);
|
|
122
|
+
if (!finalUrl) {
|
|
123
|
+
if (!this.redirectSkipLogged) {
|
|
124
|
+
this.redirectSkipLogged = true;
|
|
125
|
+
this.logger.logEvent({ message: 'redirect check skipped', reason: 'final url not available' });
|
|
126
|
+
}
|
|
127
|
+
return res;
|
|
128
|
+
}
|
|
129
|
+
if (finalUrl === origin)
|
|
130
|
+
return res;
|
|
131
|
+
if (!policy(finalUrl, origin)) {
|
|
132
|
+
this.logger.logEvent({ message: 'redirect refused', stage: 'response' });
|
|
133
|
+
throw redirectNotAllowed('redirect not allowed', config, res.request, res);
|
|
134
|
+
}
|
|
135
|
+
return res;
|
|
136
|
+
}
|
|
137
|
+
onRedirectPolicyError(err) {
|
|
138
|
+
let cause = err?.cause;
|
|
139
|
+
for (let depth = 0; cause && depth < 5 && err?.code !== types_1.REDIRECT_NOT_ALLOWED; depth++) {
|
|
140
|
+
if (cause.code === types_1.REDIRECT_NOT_ALLOWED)
|
|
141
|
+
err.code = types_1.REDIRECT_NOT_ALLOWED;
|
|
142
|
+
cause = cause.cause;
|
|
143
|
+
}
|
|
144
|
+
return Promise.reject(err);
|
|
145
|
+
}
|
|
41
146
|
enableLogging() {
|
|
42
147
|
const client = this.client();
|
|
43
148
|
if (this.requestInterceptorId !== undefined)
|
package/lib/cjs/apps/service.js
CHANGED
|
@@ -173,6 +173,9 @@ let AppsService = (() => {
|
|
|
173
173
|
});
|
|
174
174
|
return supported;
|
|
175
175
|
}
|
|
176
|
+
getApps() {
|
|
177
|
+
return this.getServiceMap().map(({ key, name }) => ({ key, name }));
|
|
178
|
+
}
|
|
176
179
|
getName(key) {
|
|
177
180
|
const found = this.getServiceMap().find(r => r.key === key);
|
|
178
181
|
return found ? found.name : key;
|
|
@@ -85,6 +85,10 @@ let DeviceRideService = (() => {
|
|
|
85
85
|
rideAdapters;
|
|
86
86
|
healthChecks = new Set();
|
|
87
87
|
startPromises;
|
|
88
|
+
startAttempts = new Map();
|
|
89
|
+
inFlightStarts = new Set();
|
|
90
|
+
retryPromises = new Map();
|
|
91
|
+
retryCounts = new Map();
|
|
88
92
|
startedCapabilities = new Map();
|
|
89
93
|
data = {};
|
|
90
94
|
simulatorEnforced;
|
|
@@ -596,8 +600,21 @@ let DeviceRideService = (() => {
|
|
|
596
600
|
ai.isStarted = false;
|
|
597
601
|
this.logEvent({ message: `${startType} ${sType} request`, ...logProps });
|
|
598
602
|
this.subscribeModeReplaced(ai.adapter);
|
|
603
|
+
const attempt = startType === 'start' ? this.beginStartAttempt(ai.udid) : undefined;
|
|
604
|
+
if (attempt !== undefined)
|
|
605
|
+
this.inFlightStarts.add(ai.udid);
|
|
606
|
+
const isSuperseded = () => attempt !== undefined && this.startAttempts.get(ai.udid) !== attempt;
|
|
607
|
+
const settle = () => {
|
|
608
|
+
if (attempt !== undefined && !isSuperseded())
|
|
609
|
+
this.inFlightStarts.delete(ai.udid);
|
|
610
|
+
};
|
|
599
611
|
return ai.adapter.start(startProps)
|
|
600
612
|
.then(async (success) => {
|
|
613
|
+
settle();
|
|
614
|
+
if (isSuperseded()) {
|
|
615
|
+
this.logEvent({ message: `${startType} ${sType} result dropped`, ...logProps, reason: 'superseded by a newer attempt' });
|
|
616
|
+
return success;
|
|
617
|
+
}
|
|
601
618
|
if (success) {
|
|
602
619
|
await this.handleStartSuccess(startType, ai, duplicates, sType, logProps);
|
|
603
620
|
return true;
|
|
@@ -606,10 +623,20 @@ let DeviceRideService = (() => {
|
|
|
606
623
|
return false;
|
|
607
624
|
})
|
|
608
625
|
.catch(async (err) => {
|
|
626
|
+
settle();
|
|
627
|
+
if (isSuperseded()) {
|
|
628
|
+
this.logEvent({ message: `${startType} ${sType} result dropped`, ...logProps, reason: 'superseded by a newer attempt' });
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
609
631
|
await this.handleStartRejection(startType, sType, logProps, err, ai, duplicates);
|
|
610
632
|
return false;
|
|
611
633
|
});
|
|
612
634
|
}
|
|
635
|
+
beginStartAttempt(udid) {
|
|
636
|
+
const attempt = (this.startAttempts.get(udid) ?? 0) + 1;
|
|
637
|
+
this.startAttempts.set(udid, attempt);
|
|
638
|
+
return attempt;
|
|
639
|
+
}
|
|
613
640
|
resumeLoggingForStart(ai) {
|
|
614
641
|
try {
|
|
615
642
|
ai.adapter.resumeLogging();
|
|
@@ -999,10 +1026,85 @@ let DeviceRideService = (() => {
|
|
|
999
1026
|
return;
|
|
1000
1027
|
return this.startAdapters(adapters, 'start', props);
|
|
1001
1028
|
}
|
|
1029
|
+
async retryStartDevice(udid, props) {
|
|
1030
|
+
await this.lazyInit();
|
|
1031
|
+
const ai = this.getRideAdapters()?.find(a => a.udid === udid);
|
|
1032
|
+
if (!ai) {
|
|
1033
|
+
this.logEvent({ message: 'start device retry skipped', udid, reason: 'unknown device' });
|
|
1034
|
+
return false;
|
|
1035
|
+
}
|
|
1036
|
+
const tsStart = Date.now();
|
|
1037
|
+
const retryAttempt = (this.retryCounts.get(udid) ?? 0) + 1;
|
|
1038
|
+
this.retryCounts.set(udid, retryAttempt);
|
|
1039
|
+
const token = this.beginStartAttempt(udid);
|
|
1040
|
+
const promise = this.runDeviceRetry(ai, props, token);
|
|
1041
|
+
this.retryPromises.set(udid, promise);
|
|
1042
|
+
let retryResult;
|
|
1043
|
+
try {
|
|
1044
|
+
retryResult = await promise;
|
|
1045
|
+
}
|
|
1046
|
+
finally {
|
|
1047
|
+
if (this.retryPromises.get(udid) === promise)
|
|
1048
|
+
this.retryPromises.delete(udid);
|
|
1049
|
+
}
|
|
1050
|
+
this.logEvent({
|
|
1051
|
+
message: 'start device retry result',
|
|
1052
|
+
device: ai.adapter.getUniqueName(),
|
|
1053
|
+
deviceRole: ai.isControl ? 'trainer' : 'sensor',
|
|
1054
|
+
retryResult,
|
|
1055
|
+
retryDurationMs: Date.now() - tsStart,
|
|
1056
|
+
retryAttempt
|
|
1057
|
+
});
|
|
1058
|
+
return retryResult === 'started';
|
|
1059
|
+
}
|
|
1060
|
+
async runDeviceRetry(ai, props, token) {
|
|
1061
|
+
const udid = ai.udid;
|
|
1062
|
+
try {
|
|
1063
|
+
if (ai.adapter.isStarted()) {
|
|
1064
|
+
this.emit('start-success', this.getAdapterStateInfo(ai));
|
|
1065
|
+
return 'started';
|
|
1066
|
+
}
|
|
1067
|
+
if (this.inFlightStarts.has(udid)) {
|
|
1068
|
+
const stopped = await this.stopWithTimeout(ai, timeouts_1.DEVICE_RETRY_STOP_TIMEOUT_MS);
|
|
1069
|
+
if (this.startAttempts.get(udid) !== token)
|
|
1070
|
+
return 'cancelled';
|
|
1071
|
+
if (!stopped) {
|
|
1072
|
+
this.emit('start-error', this.getAdapterStateInfo(ai), new Error('stop timeout'));
|
|
1073
|
+
return 'stop-timeout';
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
const success = await this.startSingleAdapter(ai, [], props, 'start');
|
|
1077
|
+
if (this.startAttempts.get(udid) !== token + 1)
|
|
1078
|
+
return 'cancelled';
|
|
1079
|
+
return success ? 'started' : 'failed';
|
|
1080
|
+
}
|
|
1081
|
+
catch (err) {
|
|
1082
|
+
this.logError(err, 'retryStartDevice');
|
|
1083
|
+
if (this.startAttempts.get(udid) === token || this.startAttempts.get(udid) === token + 1)
|
|
1084
|
+
this.emit('start-error', this.getAdapterStateInfo(ai), err);
|
|
1085
|
+
return 'failed';
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
stopWithTimeout(ai, timeout) {
|
|
1089
|
+
return new Promise(resolve => {
|
|
1090
|
+
const timer = setTimeout(() => { resolve(false); }, timeout);
|
|
1091
|
+
const done = () => { clearTimeout(timer); resolve(true); };
|
|
1092
|
+
try {
|
|
1093
|
+
ai.adapter.stop().then(done, done);
|
|
1094
|
+
}
|
|
1095
|
+
catch {
|
|
1096
|
+
done();
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1002
1100
|
async cancelStart() {
|
|
1003
|
-
if (!this.startPromises)
|
|
1101
|
+
if (!this.startPromises && this.retryPromises.size === 0)
|
|
1004
1102
|
return;
|
|
1005
1103
|
this.logEvent({ message: 'cancel start' });
|
|
1104
|
+
this.retryPromises.forEach((_p, udid) => {
|
|
1105
|
+
this.beginStartAttempt(udid);
|
|
1106
|
+
this.inFlightStarts.delete(udid);
|
|
1107
|
+
});
|
|
1006
1108
|
const adapters = this.getRideAdapters();
|
|
1007
1109
|
const promises = [];
|
|
1008
1110
|
adapters?.forEach(ai => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPairingStartTimeout = void 0;
|
|
3
|
+
exports.DEVICE_RETRY_STOP_TIMEOUT_MS = exports.getPairingStartTimeout = void 0;
|
|
4
4
|
const PAIRING_START_TIMEOUT_MS = 10 * 1000;
|
|
5
5
|
const BLE_PAIRING_START_TIMEOUT_MS = 30 * 1000;
|
|
6
6
|
const getPairingStartTimeout = (adapter) => {
|
|
7
7
|
return adapter?.getSettings?.()?.interface === 'ble' ? BLE_PAIRING_START_TIMEOUT_MS : PAIRING_START_TIMEOUT_MS;
|
|
8
8
|
};
|
|
9
9
|
exports.getPairingStartTimeout = getPairingStartTimeout;
|
|
10
|
+
exports.DEVICE_RETRY_STOP_TIMEOUT_MS = 5 * 1000;
|