@nativesquare/soma 0.14.0 → 0.16.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/garmin.d.ts +31 -0
- package/dist/client/garmin.d.ts.map +1 -1
- package/dist/client/garmin.js +34 -0
- package/dist/client/garmin.js.map +1 -1
- package/dist/client/healthkit.d.ts +267 -0
- package/dist/client/healthkit.d.ts.map +1 -0
- package/dist/client/healthkit.js +600 -0
- package/dist/client/healthkit.js.map +1 -0
- package/dist/client/index.d.ts +4 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +3 -2
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +26 -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 +7 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/garmin/private.d.ts +18 -85
- package/dist/component/garmin/private.d.ts.map +1 -1
- package/dist/component/garmin/private.js +12 -12
- package/dist/component/garmin/private.js.map +1 -1
- package/dist/component/garmin/public.d.ts +38 -65
- package/dist/component/garmin/public.d.ts.map +1 -1
- package/dist/component/garmin/public.js +132 -10
- package/dist/component/garmin/public.js.map +1 -1
- package/dist/component/garmin/utils.d.ts +48 -0
- package/dist/component/garmin/utils.d.ts.map +1 -1
- package/dist/component/garmin/utils.js +65 -0
- package/dist/component/garmin/utils.js.map +1 -1
- package/dist/component/garmin/webhooks.d.ts +1 -11
- package/dist/component/garmin/webhooks.d.ts.map +1 -1
- package/dist/component/garmin/webhooks.js.map +1 -1
- package/dist/component/healthkit/index.d.ts +14 -0
- package/dist/component/healthkit/index.d.ts.map +1 -0
- package/dist/{healthkit → component/healthkit}/index.js +11 -11
- package/dist/component/healthkit/index.js.map +1 -0
- package/dist/component/healthkit/transform/activity.d.ts +19 -0
- package/dist/component/healthkit/transform/activity.d.ts.map +1 -0
- package/dist/{healthkit → component/healthkit/transform}/activity.js +1 -1
- package/dist/component/healthkit/transform/activity.js.map +1 -0
- package/dist/{healthkit → component/healthkit/transform}/athlete.d.ts +3 -9
- package/dist/component/healthkit/transform/athlete.d.ts.map +1 -0
- package/dist/component/healthkit/transform/athlete.js.map +1 -0
- package/dist/component/healthkit/transform/body.d.ts +25 -0
- package/dist/component/healthkit/transform/body.d.ts.map +1 -0
- package/dist/component/healthkit/transform/body.js.map +1 -0
- package/dist/component/healthkit/transform/daily.d.ts +36 -0
- package/dist/component/healthkit/transform/daily.d.ts.map +1 -0
- package/dist/component/healthkit/transform/daily.js.map +1 -0
- package/dist/{healthkit/maps/activity-type.d.ts → component/healthkit/transform/maps/activityType.d.ts} +1 -1
- package/dist/component/healthkit/transform/maps/activityType.d.ts.map +1 -0
- package/dist/{healthkit/maps/activity-type.js → component/healthkit/transform/maps/activityType.js} +1 -1
- package/dist/component/healthkit/transform/maps/activityType.js.map +1 -0
- package/dist/{healthkit/maps/menstruation-flow.d.ts → component/healthkit/transform/maps/menstruationFlow.d.ts} +1 -1
- package/dist/component/healthkit/transform/maps/menstruationFlow.d.ts.map +1 -0
- package/dist/{healthkit/maps/menstruation-flow.js → component/healthkit/transform/maps/menstruationFlow.js} +2 -2
- package/dist/component/healthkit/transform/maps/menstruationFlow.js.map +1 -0
- package/dist/{healthkit/maps/sleep-level.d.ts → component/healthkit/transform/maps/sleepLevel.d.ts} +1 -1
- package/dist/component/healthkit/transform/maps/sleepLevel.d.ts.map +1 -0
- package/dist/{healthkit/maps/sleep-level.js → component/healthkit/transform/maps/sleepLevel.js} +2 -2
- package/dist/component/healthkit/transform/maps/sleepLevel.js.map +1 -0
- package/dist/{healthkit → component/healthkit/transform}/menstruation.d.ts +3 -17
- package/dist/component/healthkit/transform/menstruation.d.ts.map +1 -0
- package/dist/{healthkit → component/healthkit/transform}/menstruation.js +1 -1
- package/dist/component/healthkit/transform/menstruation.js.map +1 -0
- package/dist/component/healthkit/transform/nutrition.d.ts +25 -0
- package/dist/component/healthkit/transform/nutrition.d.ts.map +1 -0
- package/dist/component/healthkit/transform/nutrition.js.map +1 -0
- package/dist/component/healthkit/transform/sleep.d.ts +22 -0
- package/dist/component/healthkit/transform/sleep.d.ts.map +1 -0
- package/dist/{healthkit → component/healthkit/transform}/sleep.js +2 -2
- package/dist/component/healthkit/transform/sleep.js.map +1 -0
- package/dist/{healthkit → component/healthkit/transform}/utils.d.ts +1 -1
- package/dist/component/healthkit/transform/utils.d.ts.map +1 -0
- package/dist/component/healthkit/transform/utils.js.map +1 -0
- package/dist/component/healthkit/types.d.ts.map +1 -0
- package/dist/component/healthkit/types.js.map +1 -0
- package/dist/component/public.d.ts +3 -3
- package/dist/component/schema.d.ts +4 -4
- package/dist/component/strava/public.d.ts +4 -15
- package/dist/component/strava/public.d.ts.map +1 -1
- package/dist/component/strava/public.js +4 -3
- package/dist/component/strava/public.js.map +1 -1
- package/dist/component/strava/webhooks.d.ts +3 -10
- package/dist/component/strava/webhooks.d.ts.map +1 -1
- package/dist/component/strava/webhooks.js.map +1 -1
- package/dist/component/validators/daily.d.ts +2 -2
- package/dist/component/validators/shared.d.ts +16 -3
- package/dist/component/validators/shared.d.ts.map +1 -1
- package/dist/component/validators/shared.js +1 -1
- package/dist/component/validators/shared.js.map +1 -1
- package/dist/validators.d.ts +5 -4
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js.map +1 -1
- package/package.json +3 -3
- package/src/client/garmin.ts +42 -0
- package/src/client/healthkit.ts +791 -0
- package/src/client/index.ts +5 -0
- package/src/client/types.ts +4 -2
- package/src/component/_generated/api.ts +26 -0
- package/src/component/_generated/component.ts +13 -0
- package/src/component/garmin/private.ts +12 -12
- package/src/component/garmin/public.ts +166 -11
- package/src/component/garmin/utils.ts +102 -0
- package/src/component/garmin/webhooks.ts +1 -7
- package/src/{healthkit → component/healthkit}/index.ts +46 -59
- package/src/component/healthkit/transform/activity.ts +115 -0
- package/src/{healthkit → component/healthkit/transform}/athlete.ts +4 -8
- package/src/{healthkit → component/healthkit/transform}/body.ts +3 -7
- package/src/{healthkit → component/healthkit/transform}/daily.ts +4 -10
- package/src/{healthkit/maps/menstruation-flow.ts → component/healthkit/transform/maps/menstruationFlow.ts} +1 -1
- package/src/{healthkit/maps/sleep-level.ts → component/healthkit/transform/maps/sleepLevel.ts} +1 -1
- package/src/{healthkit → component/healthkit/transform}/menstruation.ts +4 -8
- package/src/{healthkit → component/healthkit/transform}/nutrition.ts +3 -7
- package/src/{healthkit → component/healthkit/transform}/sleep.ts +5 -9
- package/src/{healthkit → component/healthkit/transform}/utils.ts +1 -1
- package/src/component/strava/public.ts +6 -5
- package/src/component/strava/webhooks.ts +9 -11
- package/src/component/validators/shared.ts +47 -4
- package/src/validators.ts +1 -0
- package/dist/healthkit/activity.d.ts +0 -75
- package/dist/healthkit/activity.d.ts.map +0 -1
- package/dist/healthkit/activity.js.map +0 -1
- package/dist/healthkit/athlete.d.ts.map +0 -1
- package/dist/healthkit/athlete.js.map +0 -1
- package/dist/healthkit/body.d.ts +0 -102
- package/dist/healthkit/body.d.ts.map +0 -1
- package/dist/healthkit/body.js.map +0 -1
- package/dist/healthkit/daily.d.ts +0 -119
- package/dist/healthkit/daily.d.ts.map +0 -1
- package/dist/healthkit/daily.js.map +0 -1
- package/dist/healthkit/index.d.ts +0 -21
- package/dist/healthkit/index.d.ts.map +0 -1
- package/dist/healthkit/index.js.map +0 -1
- package/dist/healthkit/maps/activity-type.d.ts.map +0 -1
- package/dist/healthkit/maps/activity-type.js.map +0 -1
- package/dist/healthkit/maps/menstruation-flow.d.ts.map +0 -1
- package/dist/healthkit/maps/menstruation-flow.js.map +0 -1
- package/dist/healthkit/maps/sleep-level.d.ts.map +0 -1
- package/dist/healthkit/maps/sleep-level.js.map +0 -1
- package/dist/healthkit/menstruation.d.ts.map +0 -1
- package/dist/healthkit/menstruation.js.map +0 -1
- package/dist/healthkit/nutrition.d.ts +0 -77
- package/dist/healthkit/nutrition.d.ts.map +0 -1
- package/dist/healthkit/nutrition.js.map +0 -1
- package/dist/healthkit/sleep.d.ts +0 -60
- package/dist/healthkit/sleep.d.ts.map +0 -1
- package/dist/healthkit/sleep.js.map +0 -1
- package/dist/healthkit/types.d.ts.map +0 -1
- package/dist/healthkit/types.js.map +0 -1
- package/dist/healthkit/utils.d.ts.map +0 -1
- package/dist/healthkit/utils.js.map +0 -1
- package/src/healthkit/activity.ts +0 -120
- /package/dist/{healthkit → component/healthkit/transform}/athlete.js +0 -0
- /package/dist/{healthkit → component/healthkit/transform}/body.js +0 -0
- /package/dist/{healthkit → component/healthkit/transform}/daily.js +0 -0
- /package/dist/{healthkit → component/healthkit/transform}/nutrition.js +0 -0
- /package/dist/{healthkit → component/healthkit/transform}/utils.js +0 -0
- /package/dist/{healthkit → component/healthkit}/types.d.ts +0 -0
- /package/dist/{healthkit → component/healthkit}/types.js +0 -0
- /package/src/{healthkit/maps/activity-type.ts → component/healthkit/transform/maps/activityType.ts} +0 -0
- /package/src/{healthkit → component/healthkit}/types.ts +0 -0
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// ─── Activity Transformer ────────────────────────────────────────────────────
|
|
2
|
-
// Transforms an Apple HealthKit HKWorkout into the Soma Activity schema shape.
|
|
3
|
-
|
|
4
|
-
import type { HKWorkout } from "./types.js";
|
|
5
|
-
import { mapActivityType } from "./maps/activity-type.js";
|
|
6
|
-
import { buildDeviceData } from "./utils.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The output shape of {@link transformWorkout}, matching the Soma Activity
|
|
10
|
-
* validator minus `connectionId` and `userId` (added at ingestion time).
|
|
11
|
-
*/
|
|
12
|
-
export type ActivityData = ReturnType<typeof transformWorkout>;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Transform an HKWorkout into a Soma Activity document shape.
|
|
16
|
-
*
|
|
17
|
-
* The returned object is ready to be spread into an `ingestActivity` call
|
|
18
|
-
* alongside `connectionId` and `userId`.
|
|
19
|
-
*
|
|
20
|
-
* @param workout - The HKWorkout from HealthKit
|
|
21
|
-
* @returns Soma Activity fields (without connectionId/userId)
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const data = transformWorkout(hkWorkout);
|
|
26
|
-
* await soma.ingestActivity(ctx, { connectionId, userId, ...data });
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export function transformWorkout(workout: HKWorkout) {
|
|
30
|
-
const heartRateSamples = workout.heartRateSamples;
|
|
31
|
-
const hrValues = heartRateSamples?.map((s) => s.value) ?? [];
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
metadata: {
|
|
35
|
-
summary_id: workout.uuid,
|
|
36
|
-
start_time: workout.startDate,
|
|
37
|
-
end_time: workout.endDate,
|
|
38
|
-
type: mapActivityType(workout.workoutActivityType),
|
|
39
|
-
upload_type: 1 as const, // Automatic
|
|
40
|
-
name: undefined as string | undefined,
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
active_durations_data: {
|
|
44
|
-
activity_seconds: workout.duration,
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
calories_data:
|
|
48
|
-
workout.totalEnergyBurned != null
|
|
49
|
-
? {
|
|
50
|
-
total_burned_calories: workout.totalEnergyBurned,
|
|
51
|
-
}
|
|
52
|
-
: undefined,
|
|
53
|
-
|
|
54
|
-
device_data: buildDeviceData(workout.source, workout.device),
|
|
55
|
-
|
|
56
|
-
distance_data:
|
|
57
|
-
workout.totalDistance != null ||
|
|
58
|
-
workout.totalSwimmingStrokeCount != null ||
|
|
59
|
-
workout.totalFlightsClimbed != null
|
|
60
|
-
? {
|
|
61
|
-
summary: {
|
|
62
|
-
distance_meters: workout.totalDistance,
|
|
63
|
-
steps: undefined as number | undefined,
|
|
64
|
-
floors_climbed: workout.totalFlightsClimbed,
|
|
65
|
-
swimming:
|
|
66
|
-
workout.totalSwimmingStrokeCount != null
|
|
67
|
-
? { num_strokes: workout.totalSwimmingStrokeCount }
|
|
68
|
-
: undefined,
|
|
69
|
-
},
|
|
70
|
-
}
|
|
71
|
-
: undefined,
|
|
72
|
-
|
|
73
|
-
heart_rate_data:
|
|
74
|
-
heartRateSamples && heartRateSamples.length > 0
|
|
75
|
-
? {
|
|
76
|
-
detailed: {
|
|
77
|
-
hr_samples: heartRateSamples.map((s) => ({
|
|
78
|
-
timestamp: s.startDate,
|
|
79
|
-
bpm: s.value,
|
|
80
|
-
})),
|
|
81
|
-
},
|
|
82
|
-
summary: {
|
|
83
|
-
avg_hr_bpm:
|
|
84
|
-
hrValues.length > 0
|
|
85
|
-
? hrValues.reduce((a, b) => a + b, 0) / hrValues.length
|
|
86
|
-
: undefined,
|
|
87
|
-
max_hr_bpm:
|
|
88
|
-
hrValues.length > 0 ? Math.max(...hrValues) : undefined,
|
|
89
|
-
min_hr_bpm:
|
|
90
|
-
hrValues.length > 0 ? Math.min(...hrValues) : undefined,
|
|
91
|
-
},
|
|
92
|
-
}
|
|
93
|
-
: undefined,
|
|
94
|
-
|
|
95
|
-
position_data:
|
|
96
|
-
workout.routeData && workout.routeData.length > 0
|
|
97
|
-
? {
|
|
98
|
-
position_samples: workout.routeData.flatMap((route) =>
|
|
99
|
-
route.locations.map((loc) => ({
|
|
100
|
-
timestamp: loc.timestamp,
|
|
101
|
-
coords_lat_lng_deg: [loc.latitude, loc.longitude],
|
|
102
|
-
})),
|
|
103
|
-
),
|
|
104
|
-
start_pos_lat_lng_deg: (() => {
|
|
105
|
-
const first = workout.routeData[0]?.locations[0];
|
|
106
|
-
return first
|
|
107
|
-
? [first.latitude, first.longitude]
|
|
108
|
-
: undefined;
|
|
109
|
-
})(),
|
|
110
|
-
end_pos_lat_lng_deg: (() => {
|
|
111
|
-
const lastRoute =
|
|
112
|
-
workout.routeData[workout.routeData.length - 1];
|
|
113
|
-
const last =
|
|
114
|
-
lastRoute?.locations[lastRoute.locations.length - 1];
|
|
115
|
-
return last ? [last.latitude, last.longitude] : undefined;
|
|
116
|
-
})(),
|
|
117
|
-
}
|
|
118
|
-
: undefined,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/{healthkit/maps/activity-type.ts → component/healthkit/transform/maps/activityType.ts}
RENAMED
|
File without changes
|
|
File without changes
|