@nativesquare/soma 0.11.0 → 0.13.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.
Files changed (60) hide show
  1. package/dist/client/garmin.d.ts +291 -0
  2. package/dist/client/garmin.d.ts.map +1 -0
  3. package/dist/client/garmin.js +493 -0
  4. package/dist/client/garmin.js.map +1 -0
  5. package/dist/client/index.d.ts +29 -394
  6. package/dist/client/index.d.ts.map +1 -1
  7. package/dist/client/index.js +30 -520
  8. package/dist/client/index.js.map +1 -1
  9. package/dist/client/strava.d.ts +97 -0
  10. package/dist/client/strava.d.ts.map +1 -0
  11. package/dist/client/strava.js +160 -0
  12. package/dist/client/strava.js.map +1 -0
  13. package/dist/client/types.d.ts +238 -0
  14. package/dist/client/types.d.ts.map +1 -1
  15. package/dist/component/_generated/component.d.ts +24 -12
  16. package/dist/component/_generated/component.d.ts.map +1 -1
  17. package/dist/component/garmin/private.d.ts +53 -68
  18. package/dist/component/garmin/private.d.ts.map +1 -1
  19. package/dist/component/garmin/private.js +87 -85
  20. package/dist/component/garmin/private.js.map +1 -1
  21. package/dist/component/garmin/public.d.ts +97 -53
  22. package/dist/component/garmin/public.d.ts.map +1 -1
  23. package/dist/component/garmin/public.js +75 -148
  24. package/dist/component/garmin/public.js.map +1 -1
  25. package/dist/component/garmin/webhooks.d.ts +22 -20
  26. package/dist/component/garmin/webhooks.d.ts.map +1 -1
  27. package/dist/component/garmin/webhooks.js +115 -76
  28. package/dist/component/garmin/webhooks.js.map +1 -1
  29. package/dist/component/public.d.ts +15 -15
  30. package/dist/component/schema.d.ts +25 -25
  31. package/dist/component/strava/public.d.ts +12 -8
  32. package/dist/component/strava/public.d.ts.map +1 -1
  33. package/dist/component/strava/public.js +7 -7
  34. package/dist/component/strava/public.js.map +1 -1
  35. package/dist/component/validators/activity.d.ts +4 -4
  36. package/dist/component/validators/body.d.ts +4 -4
  37. package/dist/component/validators/daily.d.ts +4 -4
  38. package/dist/component/validators/nutrition.d.ts +3 -3
  39. package/dist/component/validators/samples.d.ts +4 -4
  40. package/dist/component/validators/shared.d.ts +13 -4
  41. package/dist/component/validators/shared.d.ts.map +1 -1
  42. package/dist/component/validators/shared.js +7 -0
  43. package/dist/component/validators/shared.js.map +1 -1
  44. package/dist/component/validators/sleep.d.ts +5 -5
  45. package/dist/validators.d.ts +41 -40
  46. package/dist/validators.d.ts.map +1 -1
  47. package/dist/validators.js +1 -0
  48. package/dist/validators.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/client/garmin.ts +692 -0
  51. package/src/client/index.ts +68 -933
  52. package/src/client/strava.ts +199 -0
  53. package/src/client/types.ts +285 -0
  54. package/src/component/_generated/component.ts +19 -32
  55. package/src/component/garmin/private.ts +1872 -1870
  56. package/src/component/garmin/public.ts +1073 -1184
  57. package/src/component/garmin/webhooks.ts +898 -857
  58. package/src/component/strava/public.ts +393 -393
  59. package/src/component/validators/shared.ts +9 -0
  60. package/src/validators.ts +1 -0
@@ -0,0 +1,291 @@
1
+ import type { SomaComponent } from "./index.js";
2
+ import type { ActionCtx, SomaGarminConfig, RegisterRoutesOptions } from "./types.js";
3
+ import { type HttpRouter } from "convex/server";
4
+ export declare const GARMIN_OAUTH_CALLBACK_PATH = "/api/garmin/callback";
5
+ export declare const GARMIN_WEBHOOK_BASE_PATH = "/api/garmin/webhook";
6
+ export declare class SomaGarmin {
7
+ private component;
8
+ private requireConfig;
9
+ constructor(component: SomaComponent, requireConfig: () => SomaGarminConfig);
10
+ /**
11
+ * Generate a Garmin OAuth 2.0 authorization URL with PKCE.
12
+ *
13
+ * The state and code verifier are stored inside the component automatically,
14
+ * and the callback handler registered by `registerRoutes` completes
15
+ * the flow without further host-app intervention.
16
+ *
17
+ * @param ctx - Action context from the host app
18
+ * @param opts.userId - The host app's user identifier
19
+ * @param opts.redirectUri - Optional override for the OAuth callback URL
20
+ * @returns `{ authUrl, state }`
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const { authUrl } = await soma.garmin.getAuthUrl(ctx, {
25
+ * userId: "user_123",
26
+ * redirectUri: "https://your-app.convex.site/api/garmin/callback",
27
+ * });
28
+ * // Redirect user to authUrl — the callback is handled automatically
29
+ * ```
30
+ */
31
+ getAuthUrl(ctx: ActionCtx, opts: {
32
+ userId: string;
33
+ redirectUri?: string;
34
+ }): Promise<any>;
35
+ /**
36
+ * Disconnect a user from Garmin.
37
+ *
38
+ * Deregisters the user at Garmin (best-effort), deletes stored tokens,
39
+ * and sets the connection to inactive.
40
+ *
41
+ * @param ctx - Action context from the host app
42
+ * @param args.userId - The host app's user identifier
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * await soma.garmin.disconnect(ctx, { userId: "user_123" });
47
+ * ```
48
+ */
49
+ disconnect(ctx: ActionCtx, args: {
50
+ userId: string;
51
+ }): Promise<any>;
52
+ /**
53
+ * Pull activity summaries from Garmin.
54
+ *
55
+ * Fetches activities, transforms them into the normalized Soma schema,
56
+ * and ingests them with automatic deduplication.
57
+ *
58
+ * @param ctx - Action context from the host app
59
+ * @param args.userId - The host app's user identifier
60
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
61
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
62
+ */
63
+ pullActivities(ctx: ActionCtx, args: {
64
+ userId: string;
65
+ startTimeInSeconds?: number;
66
+ endTimeInSeconds?: number;
67
+ }): Promise<any>;
68
+ /**
69
+ * Pull daily wellness summaries from Garmin.
70
+ *
71
+ * @param ctx - Action context from the host app
72
+ * @param args.userId - The host app's user identifier
73
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
74
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
75
+ */
76
+ pullDailies(ctx: ActionCtx, args: {
77
+ userId: string;
78
+ startTimeInSeconds?: number;
79
+ endTimeInSeconds?: number;
80
+ }): Promise<any>;
81
+ /**
82
+ * Pull sleep summaries from Garmin.
83
+ *
84
+ * @param ctx - Action context from the host app
85
+ * @param args.userId - The host app's user identifier
86
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
87
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
88
+ */
89
+ pullSleep(ctx: ActionCtx, args: {
90
+ userId: string;
91
+ startTimeInSeconds?: number;
92
+ endTimeInSeconds?: number;
93
+ }): Promise<any>;
94
+ /**
95
+ * Pull body composition data from Garmin.
96
+ *
97
+ * @param ctx - Action context from the host app
98
+ * @param args.userId - The host app's user identifier
99
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
100
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
101
+ */
102
+ pullBody(ctx: ActionCtx, args: {
103
+ userId: string;
104
+ startTimeInSeconds?: number;
105
+ endTimeInSeconds?: number;
106
+ }): Promise<any>;
107
+ /**
108
+ * Pull menstrual cycle tracking data from Garmin.
109
+ *
110
+ * @param ctx - Action context from the host app
111
+ * @param args.userId - The host app's user identifier
112
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
113
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
114
+ */
115
+ pullMenstruation(ctx: ActionCtx, args: {
116
+ userId: string;
117
+ startTimeInSeconds?: number;
118
+ endTimeInSeconds?: number;
119
+ }): Promise<any>;
120
+ /**
121
+ * Pull blood pressure readings from Garmin.
122
+ *
123
+ * @param ctx - Action context from the host app
124
+ * @param args.userId - The host app's user identifier
125
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
126
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
127
+ */
128
+ pullBloodPressures(ctx: ActionCtx, args: {
129
+ userId: string;
130
+ startTimeInSeconds?: number;
131
+ endTimeInSeconds?: number;
132
+ }): Promise<any>;
133
+ /**
134
+ * Pull skin temperature data from Garmin.
135
+ *
136
+ * @param ctx - Action context from the host app
137
+ * @param args.userId - The host app's user identifier
138
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
139
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
140
+ */
141
+ pullSkinTemperature(ctx: ActionCtx, args: {
142
+ userId: string;
143
+ startTimeInSeconds?: number;
144
+ endTimeInSeconds?: number;
145
+ }): Promise<any>;
146
+ /**
147
+ * Pull user metrics (VO2 max, fitness age, etc.) from Garmin.
148
+ *
149
+ * @param ctx - Action context from the host app
150
+ * @param args.userId - The host app's user identifier
151
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
152
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
153
+ */
154
+ pullUserMetrics(ctx: ActionCtx, args: {
155
+ userId: string;
156
+ startTimeInSeconds?: number;
157
+ endTimeInSeconds?: number;
158
+ }): Promise<any>;
159
+ /**
160
+ * Pull heart rate variability (HRV) summaries from Garmin.
161
+ *
162
+ * @param ctx - Action context from the host app
163
+ * @param args.userId - The host app's user identifier
164
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
165
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
166
+ */
167
+ pullHRV(ctx: ActionCtx, args: {
168
+ userId: string;
169
+ startTimeInSeconds?: number;
170
+ endTimeInSeconds?: number;
171
+ }): Promise<any>;
172
+ /**
173
+ * Pull stress detail data from Garmin.
174
+ *
175
+ * @param ctx - Action context from the host app
176
+ * @param args.userId - The host app's user identifier
177
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
178
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
179
+ */
180
+ pullStressDetails(ctx: ActionCtx, args: {
181
+ userId: string;
182
+ startTimeInSeconds?: number;
183
+ endTimeInSeconds?: number;
184
+ }): Promise<any>;
185
+ /**
186
+ * Pull pulse oximetry (SpO2) data from Garmin.
187
+ *
188
+ * @param ctx - Action context from the host app
189
+ * @param args.userId - The host app's user identifier
190
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
191
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
192
+ */
193
+ pullPulseOx(ctx: ActionCtx, args: {
194
+ userId: string;
195
+ startTimeInSeconds?: number;
196
+ endTimeInSeconds?: number;
197
+ }): Promise<any>;
198
+ /**
199
+ * Pull respiration (breathing rate) data from Garmin.
200
+ *
201
+ * @param ctx - Action context from the host app
202
+ * @param args.userId - The host app's user identifier
203
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
204
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
205
+ */
206
+ pullRespiration(ctx: ActionCtx, args: {
207
+ userId: string;
208
+ startTimeInSeconds?: number;
209
+ endTimeInSeconds?: number;
210
+ }): Promise<any>;
211
+ /**
212
+ * Pull all supported data types from Garmin in a single call.
213
+ *
214
+ * Equivalent to calling every individual `pull*` method. Automatically
215
+ * refreshes the access token if expired.
216
+ *
217
+ * @param ctx - Action context from the host app
218
+ * @param args.userId - The host app's user identifier
219
+ * @param args.startTimeInSeconds - Optional Unix epoch lower bound
220
+ * @param args.endTimeInSeconds - Optional Unix epoch upper bound
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * await soma.garmin.pullAll(ctx, { userId: "user_123" });
225
+ * ```
226
+ */
227
+ pullAll(ctx: ActionCtx, args: {
228
+ userId: string;
229
+ startTimeInSeconds?: number;
230
+ endTimeInSeconds?: number;
231
+ }): Promise<any>;
232
+ /**
233
+ * Push a planned workout to Garmin Connect.
234
+ *
235
+ * Creates the workout on the user's Garmin account from a planned
236
+ * workout stored in Soma.
237
+ *
238
+ * @param ctx - Action context from the host app
239
+ * @param args.userId - The host app's user identifier
240
+ * @param args.plannedWorkoutId - The Soma planned workout document ID
241
+ * @param args.workoutProvider - Optional provider identifier for the workout source
242
+ */
243
+ pushWorkout(ctx: ActionCtx, args: {
244
+ userId: string;
245
+ plannedWorkoutId: string;
246
+ workoutProvider?: string;
247
+ }): Promise<any>;
248
+ /**
249
+ * Schedule a planned workout on the user's Garmin calendar.
250
+ *
251
+ * The workout must already exist on Garmin (via `pushWorkout`).
252
+ *
253
+ * @param ctx - Action context from the host app
254
+ * @param args.userId - The host app's user identifier
255
+ * @param args.plannedWorkoutId - The Soma planned workout document ID
256
+ * @param args.date - Optional target date (YYYY-MM-DD); defaults to the workout's planned_date
257
+ */
258
+ pushSchedule(ctx: ActionCtx, args: {
259
+ userId: string;
260
+ plannedWorkoutId: string;
261
+ date?: string;
262
+ }): Promise<any>;
263
+ /**
264
+ * Delete a planned workout from Garmin Connect.
265
+ *
266
+ * Removes the workout from the user's Garmin account.
267
+ *
268
+ * @param ctx - Action context from the host app
269
+ * @param args.userId - The host app's user identifier
270
+ * @param args.plannedWorkoutId - The Soma planned workout document ID
271
+ */
272
+ deleteWorkout(ctx: ActionCtx, args: {
273
+ userId: string;
274
+ plannedWorkoutId: string;
275
+ }): Promise<any>;
276
+ /**
277
+ * Remove a scheduled workout from the user's Garmin calendar.
278
+ *
279
+ * Unschedules the workout without deleting the workout itself.
280
+ *
281
+ * @param ctx - Action context from the host app
282
+ * @param args.userId - The host app's user identifier
283
+ * @param args.plannedWorkoutId - The Soma planned workout document ID
284
+ */
285
+ deleteSchedule(ctx: ActionCtx, args: {
286
+ userId: string;
287
+ plannedWorkoutId: string;
288
+ }): Promise<any>;
289
+ static registerRoutes(http: HttpRouter, component: SomaComponent, opts?: RegisterRoutesOptions["garmin"]): void;
290
+ }
291
+ //# sourceMappingURL=garmin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"garmin.d.ts","sourceRoot":"","sources":["../../src/client/garmin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EAKtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAGL,KAAK,UAAU,EAChB,MAAM,eAAe,CAAC;AAEvB,eAAO,MAAM,0BAA0B,yBAAyB,CAAC;AACjE,eAAO,MAAM,wBAAwB,wBAAwB,CAAC;AAE9D,qBAAa,UAAU;IAEnB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,aAAa;gBADb,SAAS,EAAE,aAAa,EACxB,aAAa,EAAE,MAAM,gBAAgB;IAG/C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