@nativesquare/soma 0.16.2 → 0.16.3
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/healthkit.d.ts +4 -84
- package/dist/client/healthkit.d.ts.map +1 -1
- package/dist/client/healthkit.js +13 -505
- package/dist/client/healthkit.js.map +1 -1
- package/dist/component/_generated/api.d.ts +4 -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 +472 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/healthkit/index.d.ts +1 -0
- package/dist/component/healthkit/index.d.ts.map +1 -1
- package/dist/component/healthkit/index.js +5 -0
- package/dist/component/healthkit/index.js.map +1 -1
- package/dist/component/healthkit/public.d.ts +451 -0
- package/dist/component/healthkit/public.d.ts.map +1 -0
- package/dist/component/healthkit/public.js +386 -0
- package/dist/component/healthkit/public.js.map +1 -0
- package/dist/component/healthkit/types.d.ts +13 -76
- package/dist/component/healthkit/types.d.ts.map +1 -1
- package/dist/component/healthkit/types.js +9 -6
- package/dist/component/healthkit/types.js.map +1 -1
- package/dist/component/healthkit/validators.d.ts +1933 -0
- package/dist/component/healthkit/validators.d.ts.map +1 -0
- package/dist/component/healthkit/validators.js +199 -0
- package/dist/component/healthkit/validators.js.map +1 -0
- package/dist/component/strava/types/stravaApi/zod.gen.d.ts +3 -3
- package/package.json +1 -1
- package/src/client/healthkit.ts +43 -624
- package/src/component/_generated/api.ts +4 -0
- package/src/component/_generated/component.ts +412 -0
- package/src/component/healthkit/index.ts +74 -46
- package/src/component/healthkit/public.ts +597 -0
- package/src/component/healthkit/types.ts +45 -114
- package/src/component/healthkit/validators.ts +253 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SomaComponent } from "./index.js";
|
|
2
|
-
import type { MutationCtx, SomaResult } from "./types.js";
|
|
2
|
+
import type { MutationCtx, SomaError, SomaResult } from "./types.js";
|
|
3
3
|
import type { HKWorkout, HKCategorySample, HKQuantitySample, HKActivitySummary, HKCharacteristics } from "../component/healthkit/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Client class for Apple HealthKit integration with Soma.
|
|
@@ -7,8 +7,8 @@ import type { HKWorkout, HKCategorySample, HKQuantitySample, HKActivitySummary,
|
|
|
7
7
|
* Unlike {@link import("./strava.js").SomaStrava | SomaStrava} and
|
|
8
8
|
* {@link import("./garmin.js").SomaGarmin | SomaGarmin}, HealthKit is an
|
|
9
9
|
* on-device provider — data is queried locally on iOS, not fetched from a
|
|
10
|
-
* cloud API. This class
|
|
11
|
-
*
|
|
10
|
+
* cloud API. This class is a thin wrapper over the component's public
|
|
11
|
+
* mutations, which own the transform + ingest pipeline.
|
|
12
12
|
*
|
|
13
13
|
* Because HealthKit permissions are managed in iOS Settings, the server
|
|
14
14
|
* cannot independently verify whether the user has granted or revoked
|
|
@@ -57,10 +57,6 @@ export declare class SomaHealthKit {
|
|
|
57
57
|
* permissions were granted. Creates the APPLE connection if missing,
|
|
58
58
|
* or re-activates it if previously disconnected. Idempotent.
|
|
59
59
|
*
|
|
60
|
-
* Because iOS permission grants happen on-device, the server cannot
|
|
61
|
-
* verify them independently — this method records the host app's
|
|
62
|
-
* assertion that the user has authorized HealthKit access.
|
|
63
|
-
*
|
|
64
60
|
* @param ctx - Mutation context from the host app
|
|
65
61
|
* @param args.userId - The host app's user identifier
|
|
66
62
|
* @returns The connection document ID
|
|
@@ -90,10 +86,6 @@ export declare class SomaHealthKit {
|
|
|
90
86
|
*
|
|
91
87
|
* Transforms each `HKWorkout` into the Soma Activity schema and ingests it
|
|
92
88
|
* with automatic deduplication by `workout.uuid`.
|
|
93
|
-
*
|
|
94
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
95
|
-
* @param args.userId - The host app's user identifier
|
|
96
|
-
* @param args.workouts - Array of HKWorkout objects from HealthKit
|
|
97
89
|
*/
|
|
98
90
|
syncActivities(ctx: MutationCtx, args: {
|
|
99
91
|
userId: string;
|
|
@@ -107,10 +99,6 @@ export declare class SomaHealthKit {
|
|
|
107
99
|
* Each inner array represents one sleep session (all `HKCategorySample`
|
|
108
100
|
* stage records for a single night). Each session is aggregated into a
|
|
109
101
|
* single Soma Sleep document.
|
|
110
|
-
*
|
|
111
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
112
|
-
* @param args.userId - The host app's user identifier
|
|
113
|
-
* @param args.sessions - Array of sessions, each an array of sleep-stage samples
|
|
114
102
|
*/
|
|
115
103
|
syncSleep(ctx: MutationCtx, args: {
|
|
116
104
|
userId: string;
|
|
@@ -124,11 +112,6 @@ export declare class SomaHealthKit {
|
|
|
124
112
|
* Accepts a mixed array of body-related quantity samples (heart rate, HRV,
|
|
125
113
|
* blood pressure, SpO2, weight, etc.) for a single time window and produces
|
|
126
114
|
* one Soma Body document.
|
|
127
|
-
*
|
|
128
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
129
|
-
* @param args.userId - The host app's user identifier
|
|
130
|
-
* @param args.samples - Array of HKQuantitySample for the desired time range
|
|
131
|
-
* @param args.timeRange - Optional explicit time range; auto-detected from samples if omitted
|
|
132
115
|
*/
|
|
133
116
|
syncBody(ctx: MutationCtx, args: {
|
|
134
117
|
userId: string;
|
|
@@ -142,14 +125,6 @@ export declare class SomaHealthKit {
|
|
|
142
125
|
}>>;
|
|
143
126
|
/**
|
|
144
127
|
* Sync daily activity data from HealthKit quantity samples.
|
|
145
|
-
*
|
|
146
|
-
* Accepts samples for a single day (steps, distance, energy, exercise time,
|
|
147
|
-
* heart rate, etc.) and produces one Soma Daily document.
|
|
148
|
-
*
|
|
149
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
150
|
-
* @param args.userId - The host app's user identifier
|
|
151
|
-
* @param args.samples - Array of HKQuantitySample for the desired day
|
|
152
|
-
* @param args.timeRange - Optional explicit time range; auto-detected from samples if omitted
|
|
153
128
|
*/
|
|
154
129
|
syncDaily(ctx: MutationCtx, args: {
|
|
155
130
|
userId: string;
|
|
@@ -163,13 +138,6 @@ export declare class SomaHealthKit {
|
|
|
163
138
|
}>>;
|
|
164
139
|
/**
|
|
165
140
|
* Sync daily activity data from HealthKit activity ring summaries.
|
|
166
|
-
*
|
|
167
|
-
* Each `HKActivitySummary` represents one day's activity rings (Move,
|
|
168
|
-
* Exercise, Stand). Each summary produces one Soma Daily document.
|
|
169
|
-
*
|
|
170
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
171
|
-
* @param args.userId - The host app's user identifier
|
|
172
|
-
* @param args.summaries - Array of HKActivitySummary from HealthKit
|
|
173
141
|
*/
|
|
174
142
|
syncDailyFromSummary(ctx: MutationCtx, args: {
|
|
175
143
|
userId: string;
|
|
@@ -179,14 +147,6 @@ export declare class SomaHealthKit {
|
|
|
179
147
|
}>>;
|
|
180
148
|
/**
|
|
181
149
|
* Sync nutrition data from HealthKit.
|
|
182
|
-
*
|
|
183
|
-
* Accepts dietary quantity samples for a single time window and produces
|
|
184
|
-
* one Soma Nutrition document with macros and micros.
|
|
185
|
-
*
|
|
186
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
187
|
-
* @param args.userId - The host app's user identifier
|
|
188
|
-
* @param args.samples - Array of HKQuantitySample with dietary type identifiers
|
|
189
|
-
* @param args.timeRange - Optional explicit time range; auto-detected from samples if omitted
|
|
190
150
|
*/
|
|
191
151
|
syncNutrition(ctx: MutationCtx, args: {
|
|
192
152
|
userId: string;
|
|
@@ -200,14 +160,6 @@ export declare class SomaHealthKit {
|
|
|
200
160
|
}>>;
|
|
201
161
|
/**
|
|
202
162
|
* Sync menstruation data from HealthKit.
|
|
203
|
-
*
|
|
204
|
-
* Accepts menstrual flow category samples for a single time window and
|
|
205
|
-
* produces one Soma Menstruation document.
|
|
206
|
-
*
|
|
207
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
208
|
-
* @param args.userId - The host app's user identifier
|
|
209
|
-
* @param args.samples - Array of HKCategorySample with menstrual flow values
|
|
210
|
-
* @param args.timeRange - Optional explicit time range; auto-detected from samples if omitted
|
|
211
163
|
*/
|
|
212
164
|
syncMenstruation(ctx: MutationCtx, args: {
|
|
213
165
|
userId: string;
|
|
@@ -224,10 +176,6 @@ export declare class SomaHealthKit {
|
|
|
224
176
|
*
|
|
225
177
|
* HealthKit exposes limited profile data (biological sex, date of birth).
|
|
226
178
|
* Produces one Soma Athlete document per connection.
|
|
227
|
-
*
|
|
228
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
229
|
-
* @param args.userId - The host app's user identifier
|
|
230
|
-
* @param args.characteristics - The HKCharacteristics from HealthKit
|
|
231
179
|
*/
|
|
232
180
|
syncAthlete(ctx: MutationCtx, args: {
|
|
233
181
|
userId: string;
|
|
@@ -241,17 +189,6 @@ export declare class SomaHealthKit {
|
|
|
241
189
|
* Only data types with values provided are synced. Errors from individual
|
|
242
190
|
* data types are collected — one failing type does not block others.
|
|
243
191
|
*
|
|
244
|
-
* @param ctx - Mutation (or action) context from the host app
|
|
245
|
-
* @param args.userId - The host app's user identifier
|
|
246
|
-
* @param args.workouts - Optional array of HKWorkout objects
|
|
247
|
-
* @param args.sleepSessions - Optional array of sleep sessions (each an array of stage samples)
|
|
248
|
-
* @param args.bodySamples - Optional body-related quantity samples
|
|
249
|
-
* @param args.dailySamples - Optional daily activity quantity samples
|
|
250
|
-
* @param args.dailySummaries - Optional daily activity ring summaries
|
|
251
|
-
* @param args.nutritionSamples - Optional dietary quantity samples
|
|
252
|
-
* @param args.menstruationSamples - Optional menstrual flow category samples
|
|
253
|
-
* @param args.characteristics - Optional user characteristics
|
|
254
|
-
*
|
|
255
192
|
* @example
|
|
256
193
|
* ```ts
|
|
257
194
|
* const result = await soma.healthkit.syncAll(ctx, {
|
|
@@ -291,23 +228,6 @@ export declare class SomaHealthKit {
|
|
|
291
228
|
};
|
|
292
229
|
characteristics?: HKCharacteristics;
|
|
293
230
|
}): Promise<SomaResult<Record<string, number>>>;
|
|
294
|
-
/**
|
|
295
|
-
* Load the active APPLE connection for a user, or throw if missing/inactive.
|
|
296
|
-
*
|
|
297
|
-
* HealthKit permissions are managed on-device, so the connection state is
|
|
298
|
-
* an assertion made by the host app via {@link SomaHealthKit.connect} and
|
|
299
|
-
* {@link SomaHealthKit.disconnect}. Sync methods refuse to run without an
|
|
300
|
-
* active connection — the host app must explicitly reconnect to resume.
|
|
301
|
-
*/
|
|
302
|
-
private requireActiveConnection;
|
|
303
|
-
private updateLastDataUpdate;
|
|
304
|
-
private syncActivitiesInternal;
|
|
305
|
-
private syncSleepInternal;
|
|
306
|
-
private syncBodyInternal;
|
|
307
|
-
private syncDailyInternal;
|
|
308
|
-
private syncDailyFromSummaryInternal;
|
|
309
|
-
private syncNutritionInternal;
|
|
310
|
-
private syncMenstruationInternal;
|
|
311
|
-
private syncAthleteInternal;
|
|
312
231
|
}
|
|
232
|
+
export type { SomaError };
|
|
313
233
|
//# sourceMappingURL=healthkit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"healthkit.d.ts","sourceRoot":"","sources":["../../src/client/healthkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"healthkit.d.ts","sourceRoot":"","sources":["../../src/client/healthkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,iCAAiC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAI5C;;;;;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