@nativesquare/soma 0.9.3 → 0.10.0
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/dist/client/index.d.ts +96 -33
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +80 -35
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +18 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +43 -9
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/garmin/auth.d.ts +0 -4
- package/dist/component/garmin/auth.d.ts.map +1 -1
- package/dist/component/garmin/auth.js +0 -8
- package/dist/component/garmin/auth.js.map +1 -1
- package/dist/component/garmin/private.d.ts +20 -3
- package/dist/component/garmin/private.d.ts.map +1 -1
- package/dist/component/garmin/private.js +17 -26
- package/dist/component/garmin/private.js.map +1 -1
- package/dist/component/garmin/public.d.ts +4 -4
- package/dist/component/garmin/public.d.ts.map +1 -1
- package/dist/component/garmin/public.js +6 -1
- package/dist/component/garmin/public.js.map +1 -1
- package/dist/component/garmin/webhooks.d.ts +4 -0
- package/dist/component/garmin/webhooks.d.ts.map +1 -1
- package/dist/component/garmin/webhooks.js +23 -18
- package/dist/component/garmin/webhooks.js.map +1 -1
- package/dist/component/schema.d.ts +2 -2
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +5 -3
- package/dist/component/schema.js.map +1 -1
- package/dist/{strava → component/strava}/auth.d.ts +15 -48
- package/dist/component/strava/auth.d.ts.map +1 -0
- package/dist/{strava → component/strava}/auth.js +4 -39
- package/dist/component/strava/auth.js.map +1 -0
- package/dist/component/strava/client.d.ts +8 -0
- package/dist/component/strava/client.d.ts.map +1 -0
- package/dist/component/strava/client.js +18 -0
- package/dist/component/strava/client.js.map +1 -0
- package/dist/component/strava/private.d.ts +19 -0
- package/dist/component/strava/private.d.ts.map +1 -1
- package/dist/component/strava/private.js +52 -2
- package/dist/component/strava/private.js.map +1 -1
- package/dist/component/strava/public.d.ts +87 -12
- package/dist/component/strava/public.d.ts.map +1 -1
- package/dist/component/strava/public.js +218 -92
- package/dist/component/strava/public.js.map +1 -1
- package/dist/component/strava/transform/activity.d.ts +19 -0
- package/dist/component/strava/transform/activity.d.ts.map +1 -0
- package/dist/{strava → component/strava/transform}/activity.js +21 -41
- package/dist/component/strava/transform/activity.js.map +1 -0
- package/dist/{strava → component/strava/transform}/athlete.d.ts +4 -10
- package/dist/component/strava/transform/athlete.d.ts.map +1 -0
- package/dist/{strava → component/strava/transform}/athlete.js +2 -8
- package/dist/component/strava/transform/athlete.js.map +1 -0
- package/dist/component/strava/transform/maps/sportType.d.ts +7 -0
- package/dist/component/strava/transform/maps/sportType.d.ts.map +1 -0
- package/dist/{strava/maps/sport-type.js → component/strava/transform/maps/sportType.js} +4 -2
- package/dist/component/strava/transform/maps/sportType.js.map +1 -0
- package/dist/component/strava/types/stravaApi/client/client.gen.d.ts +3 -0
- package/dist/component/strava/types/stravaApi/client/client.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/client/client.gen.js +236 -0
- package/dist/component/strava/types/stravaApi/client/client.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/client/index.d.ts +9 -0
- package/dist/component/strava/types/stravaApi/client/index.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/client/index.js +7 -0
- package/dist/component/strava/types/stravaApi/client/index.js.map +1 -0
- package/dist/component/strava/types/stravaApi/client/types.gen.d.ts +118 -0
- package/dist/component/strava/types/stravaApi/client/types.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/client/types.gen.js +3 -0
- package/dist/component/strava/types/stravaApi/client/types.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/client/utils.gen.d.ts +34 -0
- package/dist/component/strava/types/stravaApi/client/utils.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/client/utils.gen.js +229 -0
- package/dist/component/strava/types/stravaApi/client/utils.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/client.gen.d.ts +13 -0
- package/dist/component/strava/types/stravaApi/client.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/client.gen.js +4 -0
- package/dist/component/strava/types/stravaApi/client.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/core/auth.gen.d.ts +19 -0
- package/dist/component/strava/types/stravaApi/core/auth.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/core/auth.gen.js +15 -0
- package/dist/component/strava/types/stravaApi/core/auth.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/core/bodySerializer.gen.d.ts +26 -0
- package/dist/component/strava/types/stravaApi/core/bodySerializer.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/core/bodySerializer.gen.js +58 -0
- package/dist/component/strava/types/stravaApi/core/bodySerializer.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/core/params.gen.d.ts +44 -0
- package/dist/component/strava/types/stravaApi/core/params.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/core/params.gen.js +101 -0
- package/dist/component/strava/types/stravaApi/core/params.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/core/pathSerializer.gen.d.ts +34 -0
- package/dist/component/strava/types/stravaApi/core/pathSerializer.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/core/pathSerializer.gen.js +107 -0
- package/dist/component/strava/types/stravaApi/core/pathSerializer.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/core/queryKeySerializer.gen.d.ts +19 -0
- package/dist/component/strava/types/stravaApi/core/queryKeySerializer.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/core/queryKeySerializer.gen.js +93 -0
- package/dist/component/strava/types/stravaApi/core/queryKeySerializer.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/core/serverSentEvents.gen.d.ts +72 -0
- package/dist/component/strava/types/stravaApi/core/serverSentEvents.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/core/serverSentEvents.gen.js +134 -0
- package/dist/component/strava/types/stravaApi/core/serverSentEvents.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/core/types.gen.d.ts +79 -0
- package/dist/component/strava/types/stravaApi/core/types.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/core/types.gen.js +3 -0
- package/dist/component/strava/types/stravaApi/core/types.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/core/utils.gen.d.ts +20 -0
- package/dist/component/strava/types/stravaApi/core/utils.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/core/utils.gen.js +88 -0
- package/dist/component/strava/types/stravaApi/core/utils.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/index.d.ts +3 -0
- package/dist/component/strava/types/stravaApi/index.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/index.js +3 -0
- package/dist/component/strava/types/stravaApi/index.js.map +1 -0
- package/dist/component/strava/types/stravaApi/sdk.gen.d.ts +224 -0
- package/dist/component/strava/types/stravaApi/sdk.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/sdk.gen.js +361 -0
- package/dist/component/strava/types/stravaApi/sdk.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/types.gen.d.ts +2209 -0
- package/dist/component/strava/types/stravaApi/types.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/types.gen.js +3 -0
- package/dist/component/strava/types/stravaApi/types.gen.js.map +1 -0
- package/dist/component/strava/types/stravaApi/zod.gen.d.ts +5332 -0
- package/dist/component/strava/types/stravaApi/zod.gen.d.ts.map +1 -0
- package/dist/component/strava/types/stravaApi/zod.gen.js +1009 -0
- package/dist/component/strava/types/stravaApi/zod.gen.js.map +1 -0
- package/dist/component/strava/utils.d.ts +15 -0
- package/dist/component/strava/utils.d.ts.map +1 -0
- package/dist/component/strava/utils.js +36 -0
- package/dist/component/strava/utils.js.map +1 -0
- package/dist/component/utils.d.ts +5 -0
- package/dist/component/utils.d.ts.map +1 -0
- package/dist/component/utils.js +11 -0
- package/dist/component/utils.js.map +1 -0
- package/package.json +131 -130
- package/src/client/index.ts +121 -52
- package/src/component/_generated/api.ts +18 -0
- package/src/component/_generated/component.ts +44 -11
- package/src/component/garmin/auth.ts +0 -9
- package/src/component/garmin/private.ts +0 -12
- package/src/component/garmin/public.ts +8 -1
- package/src/component/schema.ts +5 -3
- package/src/{strava → component/strava}/auth.ts +143 -185
- package/src/component/strava/client.ts +20 -0
- package/src/component/strava/private.ts +147 -89
- package/src/component/strava/public.ts +268 -110
- package/src/{strava → component/strava/transform}/activity.ts +256 -276
- package/src/{strava → component/strava/transform}/athlete.ts +41 -47
- package/src/{strava/maps/sport-type.ts → component/strava/transform/maps/sportType.ts} +100 -99
- package/src/component/strava/types/specs/strava-api.json +4796 -0
- package/src/component/strava/types/stravaApi/client/client.gen.ts +290 -0
- package/src/component/strava/types/stravaApi/client/index.ts +25 -0
- package/src/component/strava/types/stravaApi/client/types.gen.ts +214 -0
- package/src/component/strava/types/stravaApi/client/utils.gen.ts +316 -0
- package/src/component/strava/types/stravaApi/client.gen.ts +16 -0
- package/src/component/strava/types/stravaApi/core/auth.gen.ts +41 -0
- package/src/component/strava/types/stravaApi/core/bodySerializer.gen.ts +82 -0
- package/src/component/strava/types/stravaApi/core/params.gen.ts +169 -0
- package/src/component/strava/types/stravaApi/core/pathSerializer.gen.ts +171 -0
- package/src/component/strava/types/stravaApi/core/queryKeySerializer.gen.ts +117 -0
- package/src/component/strava/types/stravaApi/core/serverSentEvents.gen.ts +243 -0
- package/src/component/strava/types/stravaApi/core/types.gen.ts +104 -0
- package/src/component/strava/types/stravaApi/core/utils.gen.ts +140 -0
- package/src/component/strava/types/stravaApi/index.ts +4 -0
- package/src/component/strava/types/stravaApi/sdk.gen.ts +410 -0
- package/src/component/strava/types/stravaApi/types.gen.ts +2435 -0
- package/src/component/strava/types/stravaApi/zod.gen.ts +1132 -0
- package/src/component/strava/utils.ts +52 -0
- package/src/component/utils.ts +11 -0
- package/dist/strava/activity.d.ts +0 -121
- package/dist/strava/activity.d.ts.map +0 -1
- package/dist/strava/activity.js.map +0 -1
- package/dist/strava/athlete.d.ts.map +0 -1
- package/dist/strava/athlete.js.map +0 -1
- package/dist/strava/auth.d.ts.map +0 -1
- package/dist/strava/auth.js.map +0 -1
- package/dist/strava/client.d.ts +0 -93
- package/dist/strava/client.d.ts.map +0 -1
- package/dist/strava/client.js +0 -158
- package/dist/strava/client.js.map +0 -1
- package/dist/strava/index.d.ts +0 -13
- package/dist/strava/index.d.ts.map +0 -1
- package/dist/strava/index.js +0 -17
- package/dist/strava/index.js.map +0 -1
- package/dist/strava/maps/sport-type.d.ts +0 -7
- package/dist/strava/maps/sport-type.d.ts.map +0 -1
- package/dist/strava/maps/sport-type.js.map +0 -1
- package/dist/strava/sync.d.ts +0 -104
- package/dist/strava/sync.d.ts.map +0 -1
- package/dist/strava/sync.js +0 -87
- package/dist/strava/sync.js.map +0 -1
- package/dist/strava/types.d.ts +0 -266
- package/dist/strava/types.d.ts.map +0 -1
- package/dist/strava/types.js +0 -8
- package/dist/strava/types.js.map +0 -1
- package/src/strava/activity.test.ts +0 -415
- package/src/strava/athlete.test.ts +0 -139
- package/src/strava/auth.test.ts +0 -78
- package/src/strava/client.ts +0 -212
- package/src/strava/index.ts +0 -54
- package/src/strava/maps/sport-type.test.ts +0 -69
- package/src/strava/sync.ts +0 -168
- package/src/strava/types.ts +0 -361
|
@@ -1,276 +1,256 @@
|
|
|
1
|
-
// ─── Activity Transformer ────────────────────────────────────────────────────
|
|
2
|
-
// Transforms a Strava DetailedActivity (+ optional streams/laps) into the
|
|
3
|
-
// Soma Activity schema shape.
|
|
4
|
-
|
|
5
|
-
import type { DetailedActivity, SummaryActivity, StreamSet, Lap } from "
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const start = new Date(startDate);
|
|
102
|
-
return new Date(start.getTime() +
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
) {
|
|
258
|
-
const hasPowerSummary =
|
|
259
|
-
activity.average_watts != null || activity.max_watts != null;
|
|
260
|
-
const wattsStream = streams?.watts?.data;
|
|
261
|
-
const hasWattsStream = wattsStream && wattsStream.length > 0 && timeStream;
|
|
262
|
-
|
|
263
|
-
if (!hasPowerSummary && !hasWattsStream) return undefined;
|
|
264
|
-
|
|
265
|
-
return {
|
|
266
|
-
avg_watts: activity.average_watts ?? undefined,
|
|
267
|
-
max_watts: activity.max_watts ?? undefined,
|
|
268
|
-
power_samples:
|
|
269
|
-
hasWattsStream && timeStream
|
|
270
|
-
? wattsStream.map((watts, i) => ({
|
|
271
|
-
timestamp: streamTimestamp(startDate, timeStream[i]),
|
|
272
|
-
watts,
|
|
273
|
-
}))
|
|
274
|
-
: undefined,
|
|
275
|
-
};
|
|
276
|
-
}
|
|
1
|
+
// ─── Activity Transformer ────────────────────────────────────────────────────
|
|
2
|
+
// Transforms a Strava DetailedActivity (+ optional streams/laps) into the
|
|
3
|
+
// Soma Activity schema shape.
|
|
4
|
+
|
|
5
|
+
import type { DetailedActivity, SummaryActivity, StreamSet, Lap } from "../types/stravaApi/types.gen.js";
|
|
6
|
+
import type { SomaActivity } from "../../validators/activity.js";
|
|
7
|
+
import { mapSportType } from "./maps/sportType.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Transform a Strava activity into a Soma Activity document shape.
|
|
11
|
+
*
|
|
12
|
+
* The returned object is ready to be spread into an `ingestActivity` call
|
|
13
|
+
* alongside `connectionId` and `userId`.
|
|
14
|
+
*
|
|
15
|
+
* Accepts either a DetailedActivity (from `GET /activities/{id}`) or a
|
|
16
|
+
* SummaryActivity (from `GET /athlete/activities`). When a DetailedActivity
|
|
17
|
+
* is provided, additional fields like `calories`, `segment_efforts`, and
|
|
18
|
+
* embedded `laps` are mapped. Optional streams and laps can also be supplied
|
|
19
|
+
* for time-series data (heart rate, power, position, etc.).
|
|
20
|
+
*/
|
|
21
|
+
export function transformActivity(
|
|
22
|
+
activity: DetailedActivity | SummaryActivity,
|
|
23
|
+
opts?: { streams?: StreamSet; laps?: Lap[] },
|
|
24
|
+
): SomaActivity {
|
|
25
|
+
if (activity.id == null || !activity.start_date || activity.elapsed_time == null) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Strava activity missing required fields (id=${activity.id}, start_date=${activity.start_date}, elapsed_time=${activity.elapsed_time})`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const streams = opts?.streams;
|
|
32
|
+
const laps = opts?.laps ?? (isDetailed(activity) ? activity.laps : undefined);
|
|
33
|
+
const timeStream = streams?.time?.data;
|
|
34
|
+
const startDate = activity.start_date;
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
metadata: {
|
|
38
|
+
summary_id: String(activity.id),
|
|
39
|
+
start_time: activity.start_date,
|
|
40
|
+
end_time: computeEndTime(activity.start_date, activity.elapsed_time),
|
|
41
|
+
type: mapSportType(activity.sport_type),
|
|
42
|
+
upload_type: activity.manual ? 2 : 1, // 2=Manual, 1=Automatic
|
|
43
|
+
name: activity.name ?? undefined,
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
active_durations_data: activity.moving_time != null
|
|
47
|
+
? { activity_seconds: activity.moving_time }
|
|
48
|
+
: undefined,
|
|
49
|
+
|
|
50
|
+
calories_data: isDetailed(activity) && activity.calories != null
|
|
51
|
+
? { total_burned_calories: activity.calories }
|
|
52
|
+
: undefined,
|
|
53
|
+
|
|
54
|
+
device_data: activity.device_name
|
|
55
|
+
? { name: activity.device_name }
|
|
56
|
+
: undefined,
|
|
57
|
+
|
|
58
|
+
distance_data: buildDistanceData(activity),
|
|
59
|
+
|
|
60
|
+
energy_data: activity.kilojoules != null
|
|
61
|
+
? { energy_kilojoules: activity.kilojoules }
|
|
62
|
+
: undefined,
|
|
63
|
+
|
|
64
|
+
heart_rate_data: buildHeartRateData(streams, timeStream, startDate),
|
|
65
|
+
|
|
66
|
+
lap_data: buildLapData(laps),
|
|
67
|
+
|
|
68
|
+
movement_data: buildMovementData(activity, streams, timeStream, startDate),
|
|
69
|
+
|
|
70
|
+
polyline_map_data: activity.map?.summary_polyline
|
|
71
|
+
? { summary_polyline: activity.map.summary_polyline }
|
|
72
|
+
: undefined,
|
|
73
|
+
|
|
74
|
+
position_data: buildPositionData(activity, streams, timeStream, startDate),
|
|
75
|
+
|
|
76
|
+
power_data: buildPowerData(activity, streams, timeStream, startDate),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
function isDetailed(
|
|
83
|
+
activity: DetailedActivity | SummaryActivity,
|
|
84
|
+
): activity is DetailedActivity {
|
|
85
|
+
return "description" in activity;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function computeEndTime(startDate: string, elapsedTimeSeconds: number): string {
|
|
89
|
+
const start = new Date(startDate);
|
|
90
|
+
return new Date(start.getTime() + elapsedTimeSeconds * 1000).toISOString();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Compute an ISO-8601 timestamp for a stream data point, given the
|
|
95
|
+
* activity start time and the time stream offset in seconds.
|
|
96
|
+
*/
|
|
97
|
+
function streamTimestamp(
|
|
98
|
+
startDate: string,
|
|
99
|
+
timeOffsetSeconds: number,
|
|
100
|
+
): string {
|
|
101
|
+
const start = new Date(startDate);
|
|
102
|
+
return new Date(start.getTime() + timeOffsetSeconds * 1000).toISOString();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function buildDistanceData(activity: DetailedActivity | SummaryActivity) {
|
|
106
|
+
if (activity.distance == null && activity.total_elevation_gain == null) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
summary: {
|
|
112
|
+
distance_meters: activity.distance ?? undefined,
|
|
113
|
+
elevation:
|
|
114
|
+
activity.total_elevation_gain != null
|
|
115
|
+
? {
|
|
116
|
+
gain_actual_meters: activity.total_elevation_gain,
|
|
117
|
+
max_meters: activity.elev_high ?? undefined,
|
|
118
|
+
min_meters: activity.elev_low ?? undefined,
|
|
119
|
+
}
|
|
120
|
+
: undefined,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function buildHeartRateData(
|
|
126
|
+
streams: StreamSet | undefined,
|
|
127
|
+
timeStream: number[] | undefined,
|
|
128
|
+
startDate: string,
|
|
129
|
+
) {
|
|
130
|
+
const hrStream = streams?.heartrate?.data;
|
|
131
|
+
const hasHrStream = hrStream && hrStream.length > 0 && timeStream;
|
|
132
|
+
|
|
133
|
+
if (!hasHrStream) return undefined;
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
detailed:
|
|
137
|
+
timeStream
|
|
138
|
+
? {
|
|
139
|
+
hr_samples: hrStream.map((bpm, i) => ({
|
|
140
|
+
timestamp: streamTimestamp(startDate, timeStream[i]),
|
|
141
|
+
bpm,
|
|
142
|
+
})),
|
|
143
|
+
}
|
|
144
|
+
: undefined,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function buildLapData(laps: Lap[] | undefined) {
|
|
149
|
+
if (!laps || laps.length === 0) return undefined;
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
laps: laps.flatMap((lap) => {
|
|
153
|
+
const startDate = lap.start_date;
|
|
154
|
+
const elapsedTime = lap.elapsed_time;
|
|
155
|
+
if (!startDate || elapsedTime == null) return [];
|
|
156
|
+
return [
|
|
157
|
+
{
|
|
158
|
+
start_time: startDate,
|
|
159
|
+
end_time: computeEndTime(startDate, elapsedTime),
|
|
160
|
+
distance_meters: lap.distance ?? undefined,
|
|
161
|
+
calories: undefined as number | undefined,
|
|
162
|
+
avg_speed_meters_per_second: lap.average_speed ?? undefined,
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
}),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function buildMovementData(
|
|
170
|
+
activity: DetailedActivity | SummaryActivity,
|
|
171
|
+
streams: StreamSet | undefined,
|
|
172
|
+
timeStream: number[] | undefined,
|
|
173
|
+
startDate: string,
|
|
174
|
+
) {
|
|
175
|
+
const hasMovement =
|
|
176
|
+
activity.average_speed != null || activity.max_speed != null;
|
|
177
|
+
const speedStream = streams?.velocity_smooth?.data;
|
|
178
|
+
const cadenceStream = streams?.cadence?.data;
|
|
179
|
+
const hasStreams =
|
|
180
|
+
((speedStream && speedStream.length > 0) ||
|
|
181
|
+
(cadenceStream && cadenceStream.length > 0)) &&
|
|
182
|
+
timeStream;
|
|
183
|
+
|
|
184
|
+
if (!hasMovement && !hasStreams) return undefined;
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
avg_speed_meters_per_second: activity.average_speed ?? undefined,
|
|
188
|
+
max_speed_meters_per_second: activity.max_speed ?? undefined,
|
|
189
|
+
speed_samples:
|
|
190
|
+
speedStream && timeStream
|
|
191
|
+
? speedStream.map((speed, i) => ({
|
|
192
|
+
timestamp: streamTimestamp(startDate, timeStream[i]),
|
|
193
|
+
speed_meters_per_second: speed,
|
|
194
|
+
}))
|
|
195
|
+
: undefined,
|
|
196
|
+
cadence_samples:
|
|
197
|
+
cadenceStream && timeStream
|
|
198
|
+
? cadenceStream.map((cadence, i) => ({
|
|
199
|
+
timestamp: streamTimestamp(startDate, timeStream[i]),
|
|
200
|
+
cadence_rpm: cadence,
|
|
201
|
+
}))
|
|
202
|
+
: undefined,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function buildPositionData(
|
|
207
|
+
activity: DetailedActivity | SummaryActivity,
|
|
208
|
+
streams: StreamSet | undefined,
|
|
209
|
+
timeStream: number[] | undefined,
|
|
210
|
+
startDate: string,
|
|
211
|
+
) {
|
|
212
|
+
const latlngStream = streams?.latlng?.data;
|
|
213
|
+
const hasPositionStream = latlngStream && latlngStream.length > 0 && timeStream;
|
|
214
|
+
const hasStartEnd =
|
|
215
|
+
activity.start_latlng != null || activity.end_latlng != null;
|
|
216
|
+
|
|
217
|
+
if (!hasPositionStream && !hasStartEnd) return undefined;
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
start_pos_lat_lng_deg: activity.start_latlng ?? undefined,
|
|
221
|
+
end_pos_lat_lng_deg: activity.end_latlng ?? undefined,
|
|
222
|
+
position_samples:
|
|
223
|
+
hasPositionStream && timeStream
|
|
224
|
+
? latlngStream.map((coords, i) => ({
|
|
225
|
+
timestamp: streamTimestamp(startDate, timeStream[i]),
|
|
226
|
+
coords_lat_lng_deg: coords,
|
|
227
|
+
}))
|
|
228
|
+
: undefined,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function buildPowerData(
|
|
233
|
+
activity: DetailedActivity | SummaryActivity,
|
|
234
|
+
streams: StreamSet | undefined,
|
|
235
|
+
timeStream: number[] | undefined,
|
|
236
|
+
startDate: string,
|
|
237
|
+
) {
|
|
238
|
+
const hasPowerSummary =
|
|
239
|
+
activity.average_watts != null || activity.max_watts != null;
|
|
240
|
+
const wattsStream = streams?.watts?.data;
|
|
241
|
+
const hasWattsStream = wattsStream && wattsStream.length > 0 && timeStream;
|
|
242
|
+
|
|
243
|
+
if (!hasPowerSummary && !hasWattsStream) return undefined;
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
avg_watts: activity.average_watts ?? undefined,
|
|
247
|
+
max_watts: activity.max_watts ?? undefined,
|
|
248
|
+
power_samples:
|
|
249
|
+
hasWattsStream && timeStream
|
|
250
|
+
? wattsStream.map((watts, i) => ({
|
|
251
|
+
timestamp: streamTimestamp(startDate, timeStream[i]),
|
|
252
|
+
watts,
|
|
253
|
+
}))
|
|
254
|
+
: undefined,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
@@ -1,47 +1,41 @@
|
|
|
1
|
-
// ─── Athlete Transformer ─────────────────────────────────────────────────────
|
|
2
|
-
// Transforms a Strava DetailedAthlete into the Soma Athlete schema shape.
|
|
3
|
-
|
|
4
|
-
import type { DetailedAthlete } from "
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The output shape of {@link transformAthlete}.
|
|
8
|
-
*/
|
|
9
|
-
export type AthleteData = ReturnType<typeof transformAthlete>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Transform a Strava athlete profile into a Soma Athlete document shape.
|
|
13
|
-
*
|
|
14
|
-
* Strava provides a relatively rich profile compared to HealthKit, including
|
|
15
|
-
* name, location, sex, and the date the athlete joined Strava.
|
|
16
|
-
*
|
|
17
|
-
* @param athlete - The Strava DetailedAthlete from `GET /athlete`
|
|
18
|
-
* @returns Soma Athlete fields (without connectionId/userId)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
...athlete.bikes.map((b) => ({ name: b.name, id: b.id })),
|
|
43
|
-
...athlete.shoes.map((s) => ({ name: s.name, id: s.id })),
|
|
44
|
-
]
|
|
45
|
-
: undefined,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
1
|
+
// ─── Athlete Transformer ─────────────────────────────────────────────────────
|
|
2
|
+
// Transforms a Strava DetailedAthlete into the Soma Athlete schema shape.
|
|
3
|
+
|
|
4
|
+
import type { DetailedAthlete } from "../types/stravaApi/types.gen.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The output shape of {@link transformAthlete}.
|
|
8
|
+
*/
|
|
9
|
+
export type AthleteData = ReturnType<typeof transformAthlete>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Transform a Strava athlete profile into a Soma Athlete document shape.
|
|
13
|
+
*
|
|
14
|
+
* Strava provides a relatively rich profile compared to HealthKit, including
|
|
15
|
+
* name, location, sex, and the date the athlete joined Strava.
|
|
16
|
+
*
|
|
17
|
+
* @param athlete - The Strava DetailedAthlete from `GET /athlete`
|
|
18
|
+
* @returns Soma Athlete fields (without connectionId/userId)
|
|
19
|
+
*/
|
|
20
|
+
export function transformAthlete(athlete: DetailedAthlete) {
|
|
21
|
+
const sexMap: Record<string, string> = {
|
|
22
|
+
M: "male",
|
|
23
|
+
F: "female",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
first_name: athlete.firstname ?? undefined,
|
|
28
|
+
last_name: athlete.lastname ?? undefined,
|
|
29
|
+
city: athlete.city ?? undefined,
|
|
30
|
+
state: athlete.state ?? undefined,
|
|
31
|
+
country: athlete.country ?? undefined,
|
|
32
|
+
sex: athlete.sex ? sexMap[athlete.sex] : undefined,
|
|
33
|
+
joined_provider: athlete.created_at ?? undefined,
|
|
34
|
+
devices: athlete.bikes && athlete.shoes
|
|
35
|
+
? [
|
|
36
|
+
...athlete.bikes.map((b) => ({ name: b.name ?? "", id: b.id ?? "" })),
|
|
37
|
+
...athlete.shoes.map((s) => ({ name: s.name ?? "", id: s.id ?? "" })),
|
|
38
|
+
]
|
|
39
|
+
: undefined,
|
|
40
|
+
};
|
|
41
|
+
}
|