@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.
Files changed (164) hide show
  1. package/dist/client/garmin.d.ts +31 -0
  2. package/dist/client/garmin.d.ts.map +1 -1
  3. package/dist/client/garmin.js +34 -0
  4. package/dist/client/garmin.js.map +1 -1
  5. package/dist/client/healthkit.d.ts +267 -0
  6. package/dist/client/healthkit.d.ts.map +1 -0
  7. package/dist/client/healthkit.js +600 -0
  8. package/dist/client/healthkit.js.map +1 -0
  9. package/dist/client/index.d.ts +4 -1
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client/index.js +4 -0
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/client/types.d.ts +3 -2
  14. package/dist/client/types.d.ts.map +1 -1
  15. package/dist/component/_generated/api.d.ts +26 -0
  16. package/dist/component/_generated/api.d.ts.map +1 -1
  17. package/dist/component/_generated/api.js.map +1 -1
  18. package/dist/component/_generated/component.d.ts +7 -0
  19. package/dist/component/_generated/component.d.ts.map +1 -1
  20. package/dist/component/garmin/private.d.ts +18 -85
  21. package/dist/component/garmin/private.d.ts.map +1 -1
  22. package/dist/component/garmin/private.js +12 -12
  23. package/dist/component/garmin/private.js.map +1 -1
  24. package/dist/component/garmin/public.d.ts +38 -65
  25. package/dist/component/garmin/public.d.ts.map +1 -1
  26. package/dist/component/garmin/public.js +132 -10
  27. package/dist/component/garmin/public.js.map +1 -1
  28. package/dist/component/garmin/utils.d.ts +48 -0
  29. package/dist/component/garmin/utils.d.ts.map +1 -1
  30. package/dist/component/garmin/utils.js +65 -0
  31. package/dist/component/garmin/utils.js.map +1 -1
  32. package/dist/component/garmin/webhooks.d.ts +1 -11
  33. package/dist/component/garmin/webhooks.d.ts.map +1 -1
  34. package/dist/component/garmin/webhooks.js.map +1 -1
  35. package/dist/component/healthkit/index.d.ts +14 -0
  36. package/dist/component/healthkit/index.d.ts.map +1 -0
  37. package/dist/{healthkit → component/healthkit}/index.js +11 -11
  38. package/dist/component/healthkit/index.js.map +1 -0
  39. package/dist/component/healthkit/transform/activity.d.ts +19 -0
  40. package/dist/component/healthkit/transform/activity.d.ts.map +1 -0
  41. package/dist/{healthkit → component/healthkit/transform}/activity.js +1 -1
  42. package/dist/component/healthkit/transform/activity.js.map +1 -0
  43. package/dist/{healthkit → component/healthkit/transform}/athlete.d.ts +3 -9
  44. package/dist/component/healthkit/transform/athlete.d.ts.map +1 -0
  45. package/dist/component/healthkit/transform/athlete.js.map +1 -0
  46. package/dist/component/healthkit/transform/body.d.ts +25 -0
  47. package/dist/component/healthkit/transform/body.d.ts.map +1 -0
  48. package/dist/component/healthkit/transform/body.js.map +1 -0
  49. package/dist/component/healthkit/transform/daily.d.ts +36 -0
  50. package/dist/component/healthkit/transform/daily.d.ts.map +1 -0
  51. package/dist/component/healthkit/transform/daily.js.map +1 -0
  52. package/dist/{healthkit/maps/activity-type.d.ts → component/healthkit/transform/maps/activityType.d.ts} +1 -1
  53. package/dist/component/healthkit/transform/maps/activityType.d.ts.map +1 -0
  54. package/dist/{healthkit/maps/activity-type.js → component/healthkit/transform/maps/activityType.js} +1 -1
  55. package/dist/component/healthkit/transform/maps/activityType.js.map +1 -0
  56. package/dist/{healthkit/maps/menstruation-flow.d.ts → component/healthkit/transform/maps/menstruationFlow.d.ts} +1 -1
  57. package/dist/component/healthkit/transform/maps/menstruationFlow.d.ts.map +1 -0
  58. package/dist/{healthkit/maps/menstruation-flow.js → component/healthkit/transform/maps/menstruationFlow.js} +2 -2
  59. package/dist/component/healthkit/transform/maps/menstruationFlow.js.map +1 -0
  60. package/dist/{healthkit/maps/sleep-level.d.ts → component/healthkit/transform/maps/sleepLevel.d.ts} +1 -1
  61. package/dist/component/healthkit/transform/maps/sleepLevel.d.ts.map +1 -0
  62. package/dist/{healthkit/maps/sleep-level.js → component/healthkit/transform/maps/sleepLevel.js} +2 -2
  63. package/dist/component/healthkit/transform/maps/sleepLevel.js.map +1 -0
  64. package/dist/{healthkit → component/healthkit/transform}/menstruation.d.ts +3 -17
  65. package/dist/component/healthkit/transform/menstruation.d.ts.map +1 -0
  66. package/dist/{healthkit → component/healthkit/transform}/menstruation.js +1 -1
  67. package/dist/component/healthkit/transform/menstruation.js.map +1 -0
  68. package/dist/component/healthkit/transform/nutrition.d.ts +25 -0
  69. package/dist/component/healthkit/transform/nutrition.d.ts.map +1 -0
  70. package/dist/component/healthkit/transform/nutrition.js.map +1 -0
  71. package/dist/component/healthkit/transform/sleep.d.ts +22 -0
  72. package/dist/component/healthkit/transform/sleep.d.ts.map +1 -0
  73. package/dist/{healthkit → component/healthkit/transform}/sleep.js +2 -2
  74. package/dist/component/healthkit/transform/sleep.js.map +1 -0
  75. package/dist/{healthkit → component/healthkit/transform}/utils.d.ts +1 -1
  76. package/dist/component/healthkit/transform/utils.d.ts.map +1 -0
  77. package/dist/component/healthkit/transform/utils.js.map +1 -0
  78. package/dist/component/healthkit/types.d.ts.map +1 -0
  79. package/dist/component/healthkit/types.js.map +1 -0
  80. package/dist/component/public.d.ts +3 -3
  81. package/dist/component/schema.d.ts +4 -4
  82. package/dist/component/strava/public.d.ts +4 -15
  83. package/dist/component/strava/public.d.ts.map +1 -1
  84. package/dist/component/strava/public.js +4 -3
  85. package/dist/component/strava/public.js.map +1 -1
  86. package/dist/component/strava/webhooks.d.ts +3 -10
  87. package/dist/component/strava/webhooks.d.ts.map +1 -1
  88. package/dist/component/strava/webhooks.js.map +1 -1
  89. package/dist/component/validators/daily.d.ts +2 -2
  90. package/dist/component/validators/shared.d.ts +16 -3
  91. package/dist/component/validators/shared.d.ts.map +1 -1
  92. package/dist/component/validators/shared.js +1 -1
  93. package/dist/component/validators/shared.js.map +1 -1
  94. package/dist/validators.d.ts +5 -4
  95. package/dist/validators.d.ts.map +1 -1
  96. package/dist/validators.js.map +1 -1
  97. package/package.json +3 -3
  98. package/src/client/garmin.ts +42 -0
  99. package/src/client/healthkit.ts +791 -0
  100. package/src/client/index.ts +5 -0
  101. package/src/client/types.ts +4 -2
  102. package/src/component/_generated/api.ts +26 -0
  103. package/src/component/_generated/component.ts +13 -0
  104. package/src/component/garmin/private.ts +12 -12
  105. package/src/component/garmin/public.ts +166 -11
  106. package/src/component/garmin/utils.ts +102 -0
  107. package/src/component/garmin/webhooks.ts +1 -7
  108. package/src/{healthkit → component/healthkit}/index.ts +46 -59
  109. package/src/component/healthkit/transform/activity.ts +115 -0
  110. package/src/{healthkit → component/healthkit/transform}/athlete.ts +4 -8
  111. package/src/{healthkit → component/healthkit/transform}/body.ts +3 -7
  112. package/src/{healthkit → component/healthkit/transform}/daily.ts +4 -10
  113. package/src/{healthkit/maps/menstruation-flow.ts → component/healthkit/transform/maps/menstruationFlow.ts} +1 -1
  114. package/src/{healthkit/maps/sleep-level.ts → component/healthkit/transform/maps/sleepLevel.ts} +1 -1
  115. package/src/{healthkit → component/healthkit/transform}/menstruation.ts +4 -8
  116. package/src/{healthkit → component/healthkit/transform}/nutrition.ts +3 -7
  117. package/src/{healthkit → component/healthkit/transform}/sleep.ts +5 -9
  118. package/src/{healthkit → component/healthkit/transform}/utils.ts +1 -1
  119. package/src/component/strava/public.ts +6 -5
  120. package/src/component/strava/webhooks.ts +9 -11
  121. package/src/component/validators/shared.ts +47 -4
  122. package/src/validators.ts +1 -0
  123. package/dist/healthkit/activity.d.ts +0 -75
  124. package/dist/healthkit/activity.d.ts.map +0 -1
  125. package/dist/healthkit/activity.js.map +0 -1
  126. package/dist/healthkit/athlete.d.ts.map +0 -1
  127. package/dist/healthkit/athlete.js.map +0 -1
  128. package/dist/healthkit/body.d.ts +0 -102
  129. package/dist/healthkit/body.d.ts.map +0 -1
  130. package/dist/healthkit/body.js.map +0 -1
  131. package/dist/healthkit/daily.d.ts +0 -119
  132. package/dist/healthkit/daily.d.ts.map +0 -1
  133. package/dist/healthkit/daily.js.map +0 -1
  134. package/dist/healthkit/index.d.ts +0 -21
  135. package/dist/healthkit/index.d.ts.map +0 -1
  136. package/dist/healthkit/index.js.map +0 -1
  137. package/dist/healthkit/maps/activity-type.d.ts.map +0 -1
  138. package/dist/healthkit/maps/activity-type.js.map +0 -1
  139. package/dist/healthkit/maps/menstruation-flow.d.ts.map +0 -1
  140. package/dist/healthkit/maps/menstruation-flow.js.map +0 -1
  141. package/dist/healthkit/maps/sleep-level.d.ts.map +0 -1
  142. package/dist/healthkit/maps/sleep-level.js.map +0 -1
  143. package/dist/healthkit/menstruation.d.ts.map +0 -1
  144. package/dist/healthkit/menstruation.js.map +0 -1
  145. package/dist/healthkit/nutrition.d.ts +0 -77
  146. package/dist/healthkit/nutrition.d.ts.map +0 -1
  147. package/dist/healthkit/nutrition.js.map +0 -1
  148. package/dist/healthkit/sleep.d.ts +0 -60
  149. package/dist/healthkit/sleep.d.ts.map +0 -1
  150. package/dist/healthkit/sleep.js.map +0 -1
  151. package/dist/healthkit/types.d.ts.map +0 -1
  152. package/dist/healthkit/types.js.map +0 -1
  153. package/dist/healthkit/utils.d.ts.map +0 -1
  154. package/dist/healthkit/utils.js.map +0 -1
  155. package/src/healthkit/activity.ts +0 -120
  156. /package/dist/{healthkit → component/healthkit/transform}/athlete.js +0 -0
  157. /package/dist/{healthkit → component/healthkit/transform}/body.js +0 -0
  158. /package/dist/{healthkit → component/healthkit/transform}/daily.js +0 -0
  159. /package/dist/{healthkit → component/healthkit/transform}/nutrition.js +0 -0
  160. /package/dist/{healthkit → component/healthkit/transform}/utils.js +0 -0
  161. /package/dist/{healthkit → component/healthkit}/types.d.ts +0 -0
  162. /package/dist/{healthkit → component/healthkit}/types.js +0 -0
  163. /package/src/{healthkit/maps/activity-type.ts → component/healthkit/transform/maps/activityType.ts} +0 -0
  164. /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