@thebriangao/totem 1.4.4

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 (405) hide show
  1. package/.dockerignore +23 -0
  2. package/.env.example +66 -0
  3. package/CHANGELOG.md +283 -0
  4. package/CONTRIBUTING.md +149 -0
  5. package/Dockerfile +53 -0
  6. package/LICENSE +37 -0
  7. package/README.md +587 -0
  8. package/SECURITY.md +79 -0
  9. package/TOOLS.md +429 -0
  10. package/WHOOP.md +2673 -0
  11. package/assets/banner.svg +38 -0
  12. package/dist/cli/index.js +589 -0
  13. package/dist/cli/index.js.map +1 -0
  14. package/dist/cli/setup.js +1127 -0
  15. package/dist/cli/setup.js.map +1 -0
  16. package/dist/cli/ui.js +512 -0
  17. package/dist/cli/ui.js.map +1 -0
  18. package/dist/cli/update.js +465 -0
  19. package/dist/cli/update.js.map +1 -0
  20. package/dist/data/behaviors.js +2777 -0
  21. package/dist/data/behaviors.js.map +1 -0
  22. package/dist/data/endpoints.js +320 -0
  23. package/dist/data/endpoints.js.map +1 -0
  24. package/dist/data/exercises.js +4863 -0
  25. package/dist/data/exercises.js.map +1 -0
  26. package/dist/data/sports.js +212 -0
  27. package/dist/data/sports.js.map +1 -0
  28. package/dist/lib/concurrency.js +27 -0
  29. package/dist/lib/concurrency.js.map +1 -0
  30. package/dist/lib/dates.js +29 -0
  31. package/dist/lib/dates.js.map +1 -0
  32. package/dist/lib/format.js +22 -0
  33. package/dist/lib/format.js.map +1 -0
  34. package/dist/lib/stats.js +32 -0
  35. package/dist/lib/stats.js.map +1 -0
  36. package/dist/lib/timezone.js +249 -0
  37. package/dist/lib/timezone.js.map +1 -0
  38. package/dist/lib/walk.js +396 -0
  39. package/dist/lib/walk.js.map +1 -0
  40. package/dist/projections/behavior_impact.js +96 -0
  41. package/dist/projections/behavior_impact.js.map +1 -0
  42. package/dist/projections/calendar.js +33 -0
  43. package/dist/projections/calendar.js.map +1 -0
  44. package/dist/projections/communities.js +105 -0
  45. package/dist/projections/communities.js.map +1 -0
  46. package/dist/projections/cycle.js +81 -0
  47. package/dist/projections/cycle.js.map +1 -0
  48. package/dist/projections/hr_zones.js +35 -0
  49. package/dist/projections/hr_zones.js.map +1 -0
  50. package/dist/projections/journal.js +56 -0
  51. package/dist/projections/journal.js.map +1 -0
  52. package/dist/projections/leaderboard.js +37 -0
  53. package/dist/projections/leaderboard.js.map +1 -0
  54. package/dist/projections/lift_exercise.js +22 -0
  55. package/dist/projections/lift_exercise.js.map +1 -0
  56. package/dist/projections/lift_history.js +133 -0
  57. package/dist/projections/lift_history.js.map +1 -0
  58. package/dist/projections/lift_library.js +71 -0
  59. package/dist/projections/lift_library.js.map +1 -0
  60. package/dist/projections/lift_progression.js +138 -0
  61. package/dist/projections/lift_progression.js.map +1 -0
  62. package/dist/projections/lift_prs.js +20 -0
  63. package/dist/projections/lift_prs.js.map +1 -0
  64. package/dist/projections/live_hr.js +19 -0
  65. package/dist/projections/live_hr.js.map +1 -0
  66. package/dist/projections/live_state.js +23 -0
  67. package/dist/projections/live_state.js.map +1 -0
  68. package/dist/projections/live_stress.js +11 -0
  69. package/dist/projections/live_stress.js.map +1 -0
  70. package/dist/projections/performance_assessment.js +15 -0
  71. package/dist/projections/performance_assessment.js.map +1 -0
  72. package/dist/projections/profile.js +59 -0
  73. package/dist/projections/profile.js.map +1 -0
  74. package/dist/projections/recovery.js +131 -0
  75. package/dist/projections/recovery.js.map +1 -0
  76. package/dist/projections/sleep.js +256 -0
  77. package/dist/projections/sleep.js.map +1 -0
  78. package/dist/projections/sleep_need.js +32 -0
  79. package/dist/projections/sleep_need.js.map +1 -0
  80. package/dist/projections/smart_alarm.js +45 -0
  81. package/dist/projections/smart_alarm.js.map +1 -0
  82. package/dist/projections/strain.js +128 -0
  83. package/dist/projections/strain.js.map +1 -0
  84. package/dist/projections/stress.js +86 -0
  85. package/dist/projections/stress.js.map +1 -0
  86. package/dist/projections/today.js +129 -0
  87. package/dist/projections/today.js.map +1 -0
  88. package/dist/projections/trend.js +149 -0
  89. package/dist/projections/trend.js.map +1 -0
  90. package/dist/projections/workout.js +161 -0
  91. package/dist/projections/workout.js.map +1 -0
  92. package/dist/projections/workouts.js +37 -0
  93. package/dist/projections/workouts.js.map +1 -0
  94. package/dist/schemas/calendar.js +12 -0
  95. package/dist/schemas/calendar.js.map +1 -0
  96. package/dist/schemas/coach.js +11 -0
  97. package/dist/schemas/coach.js.map +1 -0
  98. package/dist/schemas/communities.js +51 -0
  99. package/dist/schemas/communities.js.map +1 -0
  100. package/dist/schemas/compare.js +15 -0
  101. package/dist/schemas/compare.js.map +1 -0
  102. package/dist/schemas/escape.js +18 -0
  103. package/dist/schemas/escape.js.map +1 -0
  104. package/dist/schemas/journal.js +69 -0
  105. package/dist/schemas/journal.js.map +1 -0
  106. package/dist/schemas/leaderboard.js +25 -0
  107. package/dist/schemas/leaderboard.js.map +1 -0
  108. package/dist/schemas/live.js +26 -0
  109. package/dist/schemas/live.js.map +1 -0
  110. package/dist/schemas/performance.js +12 -0
  111. package/dist/schemas/performance.js.map +1 -0
  112. package/dist/schemas/primitives.js +29 -0
  113. package/dist/schemas/primitives.js.map +1 -0
  114. package/dist/schemas/profile.js +39 -0
  115. package/dist/schemas/profile.js.map +1 -0
  116. package/dist/schemas/recovery.js +27 -0
  117. package/dist/schemas/recovery.js.map +1 -0
  118. package/dist/schemas/settings.js +26 -0
  119. package/dist/schemas/settings.js.map +1 -0
  120. package/dist/schemas/sleep.js +38 -0
  121. package/dist/schemas/sleep.js.map +1 -0
  122. package/dist/schemas/sleep_need.js +15 -0
  123. package/dist/schemas/sleep_need.js.map +1 -0
  124. package/dist/schemas/smart_alarm.js +36 -0
  125. package/dist/schemas/smart_alarm.js.map +1 -0
  126. package/dist/schemas/strain.js +24 -0
  127. package/dist/schemas/strain.js.map +1 -0
  128. package/dist/schemas/strength.js +170 -0
  129. package/dist/schemas/strength.js.map +1 -0
  130. package/dist/schemas/stress.js +16 -0
  131. package/dist/schemas/stress.js.map +1 -0
  132. package/dist/schemas/today.js +38 -0
  133. package/dist/schemas/today.js.map +1 -0
  134. package/dist/schemas/trend.js +50 -0
  135. package/dist/schemas/trend.js.map +1 -0
  136. package/dist/schemas/womens_health.js +23 -0
  137. package/dist/schemas/womens_health.js.map +1 -0
  138. package/dist/schemas/workouts.js +50 -0
  139. package/dist/schemas/workouts.js.map +1 -0
  140. package/dist/scripts/cognito_bootstrap.js +278 -0
  141. package/dist/scripts/cognito_bootstrap.js.map +1 -0
  142. package/dist/server-http.js +221 -0
  143. package/dist/server-http.js.map +1 -0
  144. package/dist/server.js +74 -0
  145. package/dist/server.js.map +1 -0
  146. package/dist/tools/register.js +117 -0
  147. package/dist/tools/register.js.map +1 -0
  148. package/dist/tools/v2/activity_create.js +64 -0
  149. package/dist/tools/v2/activity_create.js.map +1 -0
  150. package/dist/tools/v2/activity_delete.js +26 -0
  151. package/dist/tools/v2/activity_delete.js.map +1 -0
  152. package/dist/tools/v2/behavior_impact.js +36 -0
  153. package/dist/tools/v2/behavior_impact.js.map +1 -0
  154. package/dist/tools/v2/calendar.js +28 -0
  155. package/dist/tools/v2/calendar.js.map +1 -0
  156. package/dist/tools/v2/coach_ask.js +117 -0
  157. package/dist/tools/v2/coach_ask.js.map +1 -0
  158. package/dist/tools/v2/communities.js +60 -0
  159. package/dist/tools/v2/communities.js.map +1 -0
  160. package/dist/tools/v2/compare.js +67 -0
  161. package/dist/tools/v2/compare.js.map +1 -0
  162. package/dist/tools/v2/cycle.js +23 -0
  163. package/dist/tools/v2/cycle.js.map +1 -0
  164. package/dist/tools/v2/cycle_log.js +43 -0
  165. package/dist/tools/v2/cycle_log.js.map +1 -0
  166. package/dist/tools/v2/day.js +32 -0
  167. package/dist/tools/v2/day.js.map +1 -0
  168. package/dist/tools/v2/endpoints.js +28 -0
  169. package/dist/tools/v2/endpoints.js.map +1 -0
  170. package/dist/tools/v2/hidden_metric.js +28 -0
  171. package/dist/tools/v2/hidden_metric.js.map +1 -0
  172. package/dist/tools/v2/hr_zones.js +24 -0
  173. package/dist/tools/v2/hr_zones.js.map +1 -0
  174. package/dist/tools/v2/hr_zones_set.js +51 -0
  175. package/dist/tools/v2/hr_zones_set.js.map +1 -0
  176. package/dist/tools/v2/journal.js +26 -0
  177. package/dist/tools/v2/journal.js.map +1 -0
  178. package/dist/tools/v2/journal_autopop.js +19 -0
  179. package/dist/tools/v2/journal_autopop.js.map +1 -0
  180. package/dist/tools/v2/journal_catalog.js +44 -0
  181. package/dist/tools/v2/journal_catalog.js.map +1 -0
  182. package/dist/tools/v2/journal_log.js +78 -0
  183. package/dist/tools/v2/journal_log.js.map +1 -0
  184. package/dist/tools/v2/leaderboard.js +79 -0
  185. package/dist/tools/v2/leaderboard.js.map +1 -0
  186. package/dist/tools/v2/lift_catalog.js +47 -0
  187. package/dist/tools/v2/lift_catalog.js.map +1 -0
  188. package/dist/tools/v2/lift_custom_exercise.js +108 -0
  189. package/dist/tools/v2/lift_custom_exercise.js.map +1 -0
  190. package/dist/tools/v2/lift_exercise.js +31 -0
  191. package/dist/tools/v2/lift_exercise.js.map +1 -0
  192. package/dist/tools/v2/lift_history.js +39 -0
  193. package/dist/tools/v2/lift_history.js.map +1 -0
  194. package/dist/tools/v2/lift_library.js +22 -0
  195. package/dist/tools/v2/lift_library.js.map +1 -0
  196. package/dist/tools/v2/lift_log.js +95 -0
  197. package/dist/tools/v2/lift_log.js.map +1 -0
  198. package/dist/tools/v2/lift_progression.js +30 -0
  199. package/dist/tools/v2/lift_progression.js.map +1 -0
  200. package/dist/tools/v2/lift_prs.js +21 -0
  201. package/dist/tools/v2/lift_prs.js.map +1 -0
  202. package/dist/tools/v2/lift_template_save.js +83 -0
  203. package/dist/tools/v2/lift_template_save.js.map +1 -0
  204. package/dist/tools/v2/live_hr.js +21 -0
  205. package/dist/tools/v2/live_hr.js.map +1 -0
  206. package/dist/tools/v2/live_state.js +21 -0
  207. package/dist/tools/v2/live_state.js.map +1 -0
  208. package/dist/tools/v2/live_stress.js +22 -0
  209. package/dist/tools/v2/live_stress.js.map +1 -0
  210. package/dist/tools/v2/performance_assessment.js +38 -0
  211. package/dist/tools/v2/performance_assessment.js.map +1 -0
  212. package/dist/tools/v2/profile.js +28 -0
  213. package/dist/tools/v2/profile.js.map +1 -0
  214. package/dist/tools/v2/profile_update.js +66 -0
  215. package/dist/tools/v2/profile_update.js.map +1 -0
  216. package/dist/tools/v2/raw.js +43 -0
  217. package/dist/tools/v2/raw.js.map +1 -0
  218. package/dist/tools/v2/recovery.js +31 -0
  219. package/dist/tools/v2/recovery.js.map +1 -0
  220. package/dist/tools/v2/sleep.js +23 -0
  221. package/dist/tools/v2/sleep.js.map +1 -0
  222. package/dist/tools/v2/sleep_need.js +21 -0
  223. package/dist/tools/v2/sleep_need.js.map +1 -0
  224. package/dist/tools/v2/smart_alarm.js +24 -0
  225. package/dist/tools/v2/smart_alarm.js.map +1 -0
  226. package/dist/tools/v2/smart_alarm_set.js +94 -0
  227. package/dist/tools/v2/smart_alarm_set.js.map +1 -0
  228. package/dist/tools/v2/sports_catalog.js +26 -0
  229. package/dist/tools/v2/sports_catalog.js.map +1 -0
  230. package/dist/tools/v2/strain.js +23 -0
  231. package/dist/tools/v2/strain.js.map +1 -0
  232. package/dist/tools/v2/stress.js +23 -0
  233. package/dist/tools/v2/stress.js.map +1 -0
  234. package/dist/tools/v2/symptom_log.js +72 -0
  235. package/dist/tools/v2/symptom_log.js.map +1 -0
  236. package/dist/tools/v2/today.js +30 -0
  237. package/dist/tools/v2/today.js.map +1 -0
  238. package/dist/tools/v2/trend.js +26 -0
  239. package/dist/tools/v2/trend.js.map +1 -0
  240. package/dist/tools/v2/workout.js +23 -0
  241. package/dist/tools/v2/workout.js.map +1 -0
  242. package/dist/tools/v2/workouts.js +32 -0
  243. package/dist/tools/v2/workouts.js.map +1 -0
  244. package/dist/whoop/build_lift_body.js +67 -0
  245. package/dist/whoop/build_lift_body.js.map +1 -0
  246. package/dist/whoop/client.js +84 -0
  247. package/dist/whoop/client.js.map +1 -0
  248. package/dist/whoop/cognito.js +110 -0
  249. package/dist/whoop/cognito.js.map +1 -0
  250. package/dist/whoop/constants.js +4 -0
  251. package/dist/whoop/constants.js.map +1 -0
  252. package/dist/whoop/device.js +103 -0
  253. package/dist/whoop/device.js.map +1 -0
  254. package/dist/whoop/errors.js +42 -0
  255. package/dist/whoop/errors.js.map +1 -0
  256. package/dist/whoop/init_timezone.js +62 -0
  257. package/dist/whoop/init_timezone.js.map +1 -0
  258. package/dist/whoop/installation.js +62 -0
  259. package/dist/whoop/installation.js.map +1 -0
  260. package/dist/whoop/json_out.js +9 -0
  261. package/dist/whoop/json_out.js.map +1 -0
  262. package/dist/whoop/oauth_provider.js +297 -0
  263. package/dist/whoop/oauth_provider.js.map +1 -0
  264. package/dist/whoop/session_state.js +34 -0
  265. package/dist/whoop/session_state.js.map +1 -0
  266. package/dist/whoop/token_manager.js +60 -0
  267. package/dist/whoop/token_manager.js.map +1 -0
  268. package/dist/whoop/token_store.js +47 -0
  269. package/dist/whoop/token_store.js.map +1 -0
  270. package/dist/whoop/types.js +82 -0
  271. package/dist/whoop/types.js.map +1 -0
  272. package/dist/whoop/write_safety.js +23 -0
  273. package/dist/whoop/write_safety.js.map +1 -0
  274. package/package.json +66 -0
  275. package/src/cli/index.ts +597 -0
  276. package/src/cli/setup.ts +1106 -0
  277. package/src/cli/ui.ts +505 -0
  278. package/src/cli/update.ts +442 -0
  279. package/src/data/behaviors.ts +2784 -0
  280. package/src/data/endpoints.ts +319 -0
  281. package/src/data/exercises.ts +4868 -0
  282. package/src/data/sports.ts +218 -0
  283. package/src/lib/concurrency.ts +28 -0
  284. package/src/lib/dates.ts +35 -0
  285. package/src/lib/format.ts +27 -0
  286. package/src/lib/stats.ts +35 -0
  287. package/src/lib/timezone.ts +269 -0
  288. package/src/lib/walk.ts +418 -0
  289. package/src/projections/behavior_impact.ts +98 -0
  290. package/src/projections/calendar.ts +46 -0
  291. package/src/projections/communities.ts +135 -0
  292. package/src/projections/cycle.ts +85 -0
  293. package/src/projections/hr_zones.ts +43 -0
  294. package/src/projections/journal.ts +55 -0
  295. package/src/projections/leaderboard.ts +49 -0
  296. package/src/projections/lift_exercise.ts +29 -0
  297. package/src/projections/lift_history.ts +140 -0
  298. package/src/projections/lift_library.ts +70 -0
  299. package/src/projections/lift_progression.ts +138 -0
  300. package/src/projections/lift_prs.ts +23 -0
  301. package/src/projections/live_hr.ts +21 -0
  302. package/src/projections/live_state.ts +28 -0
  303. package/src/projections/live_stress.ts +13 -0
  304. package/src/projections/performance_assessment.ts +19 -0
  305. package/src/projections/profile.ts +71 -0
  306. package/src/projections/recovery.ts +133 -0
  307. package/src/projections/sleep.ts +276 -0
  308. package/src/projections/sleep_need.ts +36 -0
  309. package/src/projections/smart_alarm.ts +70 -0
  310. package/src/projections/strain.ts +131 -0
  311. package/src/projections/stress.ts +95 -0
  312. package/src/projections/today.ts +166 -0
  313. package/src/projections/trend.ts +149 -0
  314. package/src/projections/workout.ts +168 -0
  315. package/src/projections/workouts.ts +36 -0
  316. package/src/schemas/calendar.ts +13 -0
  317. package/src/schemas/coach.ts +11 -0
  318. package/src/schemas/communities.ts +56 -0
  319. package/src/schemas/compare.ts +17 -0
  320. package/src/schemas/escape.ts +21 -0
  321. package/src/schemas/journal.ts +80 -0
  322. package/src/schemas/leaderboard.ts +26 -0
  323. package/src/schemas/live.ts +31 -0
  324. package/src/schemas/performance.ts +13 -0
  325. package/src/schemas/primitives.ts +35 -0
  326. package/src/schemas/profile.ts +40 -0
  327. package/src/schemas/recovery.ts +28 -0
  328. package/src/schemas/settings.ts +30 -0
  329. package/src/schemas/sleep.ts +40 -0
  330. package/src/schemas/sleep_need.ts +16 -0
  331. package/src/schemas/smart_alarm.ts +40 -0
  332. package/src/schemas/strain.ts +25 -0
  333. package/src/schemas/strength.ts +189 -0
  334. package/src/schemas/stress.ts +17 -0
  335. package/src/schemas/today.ts +39 -0
  336. package/src/schemas/trend.ts +53 -0
  337. package/src/schemas/womens_health.ts +26 -0
  338. package/src/schemas/workouts.ts +55 -0
  339. package/src/scripts/cognito_bootstrap.ts +249 -0
  340. package/src/server-http.ts +241 -0
  341. package/src/server.ts +85 -0
  342. package/src/tools/register.ts +120 -0
  343. package/src/tools/v2/activity_create.ts +74 -0
  344. package/src/tools/v2/activity_delete.ts +33 -0
  345. package/src/tools/v2/behavior_impact.ts +39 -0
  346. package/src/tools/v2/calendar.ts +33 -0
  347. package/src/tools/v2/coach_ask.ts +131 -0
  348. package/src/tools/v2/communities.ts +65 -0
  349. package/src/tools/v2/compare.ts +83 -0
  350. package/src/tools/v2/cycle.ts +28 -0
  351. package/src/tools/v2/cycle_log.ts +51 -0
  352. package/src/tools/v2/day.ts +37 -0
  353. package/src/tools/v2/endpoints.ts +32 -0
  354. package/src/tools/v2/hidden_metric.ts +33 -0
  355. package/src/tools/v2/hr_zones.ts +29 -0
  356. package/src/tools/v2/hr_zones_set.ts +57 -0
  357. package/src/tools/v2/journal.ts +31 -0
  358. package/src/tools/v2/journal_autopop.ts +26 -0
  359. package/src/tools/v2/journal_catalog.ts +48 -0
  360. package/src/tools/v2/journal_log.ts +84 -0
  361. package/src/tools/v2/leaderboard.ts +92 -0
  362. package/src/tools/v2/lift_catalog.ts +48 -0
  363. package/src/tools/v2/lift_custom_exercise.ts +117 -0
  364. package/src/tools/v2/lift_exercise.ts +35 -0
  365. package/src/tools/v2/lift_history.ts +52 -0
  366. package/src/tools/v2/lift_library.ts +28 -0
  367. package/src/tools/v2/lift_log.ts +102 -0
  368. package/src/tools/v2/lift_progression.ts +34 -0
  369. package/src/tools/v2/lift_prs.ts +26 -0
  370. package/src/tools/v2/lift_template_save.ts +89 -0
  371. package/src/tools/v2/live_hr.ts +26 -0
  372. package/src/tools/v2/live_state.ts +26 -0
  373. package/src/tools/v2/live_stress.ts +27 -0
  374. package/src/tools/v2/performance_assessment.ts +44 -0
  375. package/src/tools/v2/profile.ts +33 -0
  376. package/src/tools/v2/profile_update.ts +76 -0
  377. package/src/tools/v2/raw.ts +50 -0
  378. package/src/tools/v2/recovery.ts +36 -0
  379. package/src/tools/v2/sleep.ts +28 -0
  380. package/src/tools/v2/sleep_need.ts +26 -0
  381. package/src/tools/v2/smart_alarm.ts +29 -0
  382. package/src/tools/v2/smart_alarm_set.ts +103 -0
  383. package/src/tools/v2/sports_catalog.ts +32 -0
  384. package/src/tools/v2/strain.ts +28 -0
  385. package/src/tools/v2/stress.ts +28 -0
  386. package/src/tools/v2/symptom_log.ts +78 -0
  387. package/src/tools/v2/today.ts +35 -0
  388. package/src/tools/v2/trend.ts +31 -0
  389. package/src/tools/v2/workout.ts +28 -0
  390. package/src/tools/v2/workouts.ts +37 -0
  391. package/src/whoop/build_lift_body.ts +84 -0
  392. package/src/whoop/client.ts +118 -0
  393. package/src/whoop/cognito.ts +150 -0
  394. package/src/whoop/constants.ts +3 -0
  395. package/src/whoop/device.ts +106 -0
  396. package/src/whoop/errors.ts +41 -0
  397. package/src/whoop/init_timezone.ts +64 -0
  398. package/src/whoop/installation.ts +58 -0
  399. package/src/whoop/json_out.ts +9 -0
  400. package/src/whoop/oauth_provider.ts +377 -0
  401. package/src/whoop/session_state.ts +41 -0
  402. package/src/whoop/token_manager.ts +76 -0
  403. package/src/whoop/token_store.ts +45 -0
  404. package/src/whoop/types.ts +89 -0
  405. package/src/whoop/write_safety.ts +30 -0
@@ -0,0 +1,166 @@
1
+ import type { TodayOutT } from "../schemas/today.js";
2
+ import { findByType, isObject, asArray, asNumber, asString } from "../lib/walk.js";
3
+ import { stateFromStyle } from "./recovery.js";
4
+
5
+ // Whoop's home payload's authoritative score source is SCORE_GAUGE_STICKY which
6
+ // contains a gauges[] array with one entry per pillar (SLEEP, RECOVERY, STRAIN).
7
+ // Each gauge has score_display (string), score_display_suffix, progress_fill_style.
8
+ // Sleep stages + start/end come from the lightweight /developer/v2/activity/sleep
9
+ // endpoint (~1 KB), NOT the 848 KB deep-dive — the full per-minute hypnogram is
10
+ // whoop_sleep's job. Activity state comes from /activities-service/v1/user-state.
11
+
12
+ interface ProjectTodayInput {
13
+ home: unknown;
14
+ sleep: unknown;
15
+ recovery: unknown;
16
+ state: unknown;
17
+ date: string;
18
+ }
19
+
20
+ function gauge(gauges: unknown[], title: string): Record<string, unknown> | null {
21
+ return (gauges.find(
22
+ (g) => isObject(g) && asString((g as Record<string, unknown>).title) === title,
23
+ ) as Record<string, unknown> | undefined) ?? null;
24
+ }
25
+
26
+ function gaugeScore(g: Record<string, unknown> | null): number | null {
27
+ if (!g) return null;
28
+ return asNumber(g.score_display);
29
+ }
30
+
31
+ interface SleepSummary {
32
+ performance_pct: number | null;
33
+ total_sleep_ms: number | null;
34
+ time_in_bed_ms: number | null;
35
+ efficiency_pct: number | null;
36
+ stages: { rem_ms: number | null; light_ms: number | null; sws_ms: number | null; wake_ms: number | null };
37
+ started_at: string | null;
38
+ ended_at: string | null;
39
+ }
40
+
41
+ // Map a /developer/v2/activity/sleep response → the snapshot's sleep summary.
42
+ // Picks the main (non-nap) sleep whose local end date matches `date`, else the
43
+ // most recent. All stage durations come straight from score.stage_summary.
44
+ function sleepSummary(resp: unknown, date: string): SleepSummary | null {
45
+ const root = isObject(resp) ? resp : {};
46
+ const records = asArray(root.records).filter(
47
+ (r): r is Record<string, unknown> => isObject(r) && r.nap !== true,
48
+ );
49
+ const pick = records.find((r) => asString(r.end)?.slice(0, 10) === date) ?? records[0];
50
+ if (!pick) return null;
51
+ const score = isObject(pick.score) ? (pick.score as Record<string, unknown>) : {};
52
+ const st = isObject(score.stage_summary) ? (score.stage_summary as Record<string, unknown>) : {};
53
+ const rem = asNumber(st.total_rem_sleep_time_milli);
54
+ const light = asNumber(st.total_light_sleep_time_milli);
55
+ const sws = asNumber(st.total_slow_wave_sleep_time_milli);
56
+ const wake = asNumber(st.total_awake_time_milli);
57
+ const inBed = asNumber(st.total_in_bed_time_milli);
58
+ const noData = asNumber(st.total_no_data_time_milli) ?? 0;
59
+ const totalSleep =
60
+ rem !== null && light !== null && sws !== null
61
+ ? rem + light + sws
62
+ : inBed !== null && wake !== null
63
+ ? inBed - wake - noData
64
+ : null;
65
+ const eff = asNumber(score.sleep_efficiency_percentage);
66
+ return {
67
+ performance_pct: asNumber(score.sleep_performance_percentage),
68
+ total_sleep_ms: totalSleep,
69
+ time_in_bed_ms: inBed,
70
+ efficiency_pct: eff === null ? null : Math.round(eff),
71
+ stages: { rem_ms: rem, light_ms: light, sws_ms: sws, wake_ms: wake },
72
+ started_at: asString(pick.start),
73
+ ended_at: asString(pick.end),
74
+ };
75
+ }
76
+
77
+ // HRV + RHR from the lightweight /developer/v2/recovery endpoint (the /home gauge
78
+ // only carries the recovery *score*, not the underlying HRV/RHR). Picks the
79
+ // recovery whose created date matches `date`, else the most recent.
80
+ function recoverySummary(resp: unknown, date: string): { hrv_ms: number | null; rhr_bpm: number | null } {
81
+ const records = asArray(isObject(resp) ? resp.records : null).filter(
82
+ (r): r is Record<string, unknown> => isObject(r),
83
+ );
84
+ const pick = records.find((r) => asString(r.created_at)?.slice(0, 10) === date) ?? records[0];
85
+ const score = pick && isObject(pick.score) ? (pick.score as Record<string, unknown>) : {};
86
+ const hrv = asNumber(score.hrv_rmssd_milli);
87
+ return { hrv_ms: hrv === null ? null : Math.round(hrv), rhr_bpm: asNumber(score.resting_heart_rate) };
88
+ }
89
+
90
+ export function projectToday(input: ProjectTodayInput): TodayOutT {
91
+ const { home, sleep, recovery, state, date } = input;
92
+ const sticky = findByType(home, "SCORE_GAUGE_STICKY");
93
+ const stickyContent = sticky && isObject(sticky.content) ? (sticky.content as Record<string, unknown>) : {};
94
+ const gauges = asArray(stickyContent.gauges);
95
+
96
+ const recoveryGauge = gauge(gauges, "RECOVERY");
97
+ const sleepGauge = gauge(gauges, "SLEEP");
98
+ const strainGauge = gauge(gauges, "STRAIN");
99
+
100
+ const recoveryStyle = recoveryGauge ? asString(recoveryGauge.progress_fill_style) : null;
101
+
102
+ // Count workouts: ACTIVITY tiles in home (excludes the navigation tiles by checking for content)
103
+ let workoutsCount = 0;
104
+ function countWorkouts(n: unknown): void {
105
+ if (Array.isArray(n)) {
106
+ for (const x of n) countWorkouts(x);
107
+ return;
108
+ }
109
+ if (!isObject(n)) return;
110
+ if (n.type === "ACTIVITY") {
111
+ const c = isObject(n.content) ? (n.content as Record<string, unknown>) : null;
112
+ if (c && asString(c.title)) workoutsCount++;
113
+ }
114
+ for (const v of Object.values(n)) countWorkouts(v);
115
+ }
116
+ countWorkouts(home);
117
+
118
+ // Sleep summary from the lightweight /developer/v2/activity/sleep endpoint
119
+ const sleepSum = sleep ? sleepSummary(sleep, date) : null;
120
+ const recSum = recovery ? recoverySummary(recovery, date) : null;
121
+
122
+ // Activity state
123
+ const stateObj = isObject(state) ? state : {};
124
+ const activityObj = isObject(stateObj.activity) ? (stateObj.activity as Record<string, unknown>) : null;
125
+ const rawState = asString(stateObj.state)?.toLowerCase() ?? null;
126
+ const KNOWN_STATES = ["workout", "sleep", "idle", "recovery"] as const;
127
+ const stateValue = rawState && (KNOWN_STATES as readonly string[]).includes(rawState)
128
+ ? (rawState as typeof KNOWN_STATES[number])
129
+ : null;
130
+
131
+ return {
132
+ date,
133
+ recovery: {
134
+ score: gaugeScore(recoveryGauge),
135
+ state: stateFromStyle(recoveryStyle),
136
+ hrv_ms: recSum?.hrv_ms ?? null,
137
+ rhr_bpm: recSum?.rhr_bpm ?? null,
138
+ },
139
+ sleep: {
140
+ performance_pct: gaugeScore(sleepGauge) ?? sleepSum?.performance_pct ?? null,
141
+ total_sleep_ms: sleepSum?.total_sleep_ms ?? null,
142
+ time_in_bed_ms: sleepSum?.time_in_bed_ms ?? null,
143
+ efficiency_pct: sleepSum?.efficiency_pct ?? null,
144
+ stages: {
145
+ rem_ms: sleepSum?.stages.rem_ms ?? null,
146
+ light_ms: sleepSum?.stages.light_ms ?? null,
147
+ sws_ms: sleepSum?.stages.sws_ms ?? null,
148
+ wake_ms: sleepSum?.stages.wake_ms ?? null,
149
+ },
150
+ started_at: sleepSum?.started_at ?? null,
151
+ ended_at: sleepSum?.ended_at ?? null,
152
+ },
153
+ strain: {
154
+ score: gaugeScore(strainGauge),
155
+ calories: null,
156
+ avg_hr_bpm: null,
157
+ max_hr_bpm: null,
158
+ workouts_count: workoutsCount,
159
+ },
160
+ current_state: {
161
+ state: stateValue,
162
+ sport_name: activityObj ? asString(activityObj.sport_name) : null,
163
+ started_at: asString(stateObj.startAt),
164
+ },
165
+ };
166
+ }
@@ -0,0 +1,149 @@
1
+ import type { TrendOutT } from "../schemas/trend.js";
2
+ import { isObject, asArray, asNumber, asString, labelToNumber, timeLabelToMs } from "../lib/walk.js";
3
+
4
+ // Whoop's /progression-service/v3/trends/{metric} returns named segments:
5
+ // week_time_segment / month_time_segment / six_month_time_segment / year_time_segment
6
+ // Each has shape:
7
+ // {
8
+ // date_picker: { current_date_range_display, next_date_time, previous_date_time },
9
+ // metrics: [{ trend_key, metric_name_display, metric_value_display,
10
+ // metric_units_display, trend_direction, trend_text_display,
11
+ // current_metric_value, previous_metric_value, metric_change }],
12
+ // graph: { plots: [{ plot: { segments: [{ points: [{ graph_label.label, data_scrubber_details:{ primary_contextual_display, value_display } }] }] } }] },
13
+ // is_hidden
14
+ // }
15
+ //
16
+ // CRITICAL: metrics is an ARRAY (one entry per overlaid metric). Not an object.
17
+ // The data_scrubber_details.value is null on every point — the actual number is
18
+ // in value_display (string) and graph_label.label (string).
19
+
20
+ const NAMED_KEYS = [
21
+ "week_time_segment",
22
+ "month_time_segment",
23
+ "six_month_time_segment",
24
+ "year_time_segment",
25
+ ] as const;
26
+ type WindowLabel = "week" | "month" | "six_month" | "year";
27
+
28
+ function labelFromKey(k: string): WindowLabel {
29
+ if (k.startsWith("week")) return "week";
30
+ if (k.startsWith("month")) return "month";
31
+ if (k.startsWith("six_month")) return "six_month";
32
+ return "year";
33
+ }
34
+
35
+ interface PointOut {
36
+ date: string;
37
+ value: number | null;
38
+ value_display: string | null;
39
+ }
40
+
41
+ // A display string like "41", "1,644", "97%", or a duration "11:14"/"0:05".
42
+ // labelToNumber handles plain/percent/comma numbers; durations fall through to
43
+ // timeLabelToMs (→ milliseconds), matching the metric's avg/min/max units which
44
+ // Whoop also reports in ms for time-based metrics. Last resort: the raw value.
45
+ function parseDisplay(display: string | null, rawValue: unknown): number | null {
46
+ return labelToNumber(display) ?? timeLabelToMs(display) ?? asNumber(rawValue);
47
+ }
48
+
49
+ function extractPoints(graph: unknown): PointOut[] {
50
+ const g = isObject(graph) ? graph : {};
51
+ const out: PointOut[] = [];
52
+ for (const p of asArray(g.plots)) {
53
+ if (!isObject(p)) continue;
54
+ const plot = isObject(p.plot) ? (p.plot as Record<string, unknown>) : null;
55
+ if (!plot) continue;
56
+ // Line plots: segments[].points[]
57
+ for (const seg of asArray(plot.segments)) {
58
+ if (!isObject(seg)) continue;
59
+ for (const pt of asArray(seg.points)) {
60
+ if (!isObject(pt)) continue;
61
+ const graphLabel = isObject(pt.graph_label) ? (pt.graph_label as Record<string, unknown>) : null;
62
+ const label = graphLabel ? asString(graphLabel.label) : null;
63
+ const dsd = isObject(pt.data_scrubber_details) ? (pt.data_scrubber_details as Record<string, unknown>) : {};
64
+ const valueDisplay = asString(dsd.value_display) ?? label;
65
+ out.push({
66
+ date: asString(dsd.primary_contextual_display) ?? "",
67
+ value: parseDisplay(valueDisplay, dsd.value),
68
+ value_display: valueDisplay,
69
+ });
70
+ }
71
+ }
72
+ // Bar plots: bar_groups[].bars[] — the per-bar data_scrubber_details carries
73
+ // both the date (primary_contextual_display) and the value (value_display).
74
+ // This is where time/duration metrics (time in bed, sleep debt, stress
75
+ // durations, HR-zone time, strength activity time) live; the older code read
76
+ // the group-level top_label and lost both. We emit one point per group, using
77
+ // the first bar that carries a value_display.
78
+ for (const grp of asArray(plot.bar_groups)) {
79
+ if (!isObject(grp)) continue;
80
+ const bars = asArray(grp.bars);
81
+ const topLabel = isObject(grp.top_label) ? asString((grp.top_label as Record<string, unknown>).label) : null;
82
+ const candidates = bars.length > 0 ? bars : [grp];
83
+ let chosen: { date: string; value_display: string | null; raw: unknown } | null = null;
84
+ for (const bar of candidates) {
85
+ if (!isObject(bar)) continue;
86
+ const dsd = isObject(bar.data_scrubber_details) ? (bar.data_scrubber_details as Record<string, unknown>) : {};
87
+ const vd = asString(dsd.value_display) ?? topLabel;
88
+ const cand = { date: asString(dsd.primary_contextual_display) ?? "", value_display: vd, raw: dsd.value };
89
+ if (chosen === null) chosen = cand;
90
+ if (vd !== null) { chosen = cand; break; }
91
+ }
92
+ if (chosen === null) continue;
93
+ out.push({
94
+ date: chosen.date,
95
+ value: parseDisplay(chosen.value_display, chosen.raw),
96
+ value_display: chosen.value_display,
97
+ });
98
+ }
99
+ }
100
+ return out;
101
+ }
102
+
103
+ export function projectTrend(raw: unknown, metric: TrendOutT["metric"], endDate: string): TrendOutT {
104
+ const root = isObject(raw) ? raw : {};
105
+ const segments: TrendOutT["segments"] = [];
106
+
107
+ function pushSegment(label: WindowLabel, s: Record<string, unknown>) {
108
+ if (s.is_hidden === true) return;
109
+ const dp = isObject(s.date_picker) ? (s.date_picker as Record<string, unknown>) : {};
110
+ // Metrics is an array; take the first (primary) row.
111
+ const metricsArr = asArray(s.metrics);
112
+ const m0 = isObject(metricsArr[0]) ? (metricsArr[0] as Record<string, unknown>) : null;
113
+ const avg = m0 ? asNumber(m0.current_metric_value) : null;
114
+ const deltaPct = m0 ? asNumber(m0.metric_change) : null;
115
+ const unit = m0 ? asString(m0.metric_units_display) : null;
116
+ const points = extractPoints(s.graph);
117
+ const numericPoints = points.map((p) => p.value).filter((v): v is number => v !== null);
118
+ segments.push({
119
+ label,
120
+ start_date: asString(dp.current_date_range_display) ?? "",
121
+ end_date: asString(dp.next_date_time) ?? "",
122
+ avg,
123
+ min: numericPoints.length > 0 ? Math.min(...numericPoints) : null,
124
+ max: numericPoints.length > 0 ? Math.max(...numericPoints) : null,
125
+ delta_pct: deltaPct,
126
+ unit,
127
+ points,
128
+ });
129
+ }
130
+
131
+ if (Array.isArray(root.time_segments)) {
132
+ for (const [i, s] of (root.time_segments as Record<string, unknown>[]).entries()) {
133
+ const labels = ["week", "month", "six_month", "year"] as const;
134
+ const label = labels[i] ?? "year";
135
+ pushSegment(label, s);
136
+ }
137
+ }
138
+ for (const k of NAMED_KEYS) {
139
+ const seg = root[k];
140
+ if (isObject(seg)) pushSegment(labelFromKey(k), seg as Record<string, unknown>);
141
+ }
142
+
143
+ return {
144
+ metric,
145
+ end_date: endDate,
146
+ segments,
147
+ cardio_fitness_level: asString(root.cardio_fitness_level),
148
+ };
149
+ }
@@ -0,0 +1,168 @@
1
+ import type { WorkoutOutT } from "../schemas/workouts.js";
2
+ import { isObject, asArray, asNumber, asString, labelToNumber, timeLabelToMs } from "../lib/walk.js";
3
+
4
+ // Whoop's /core-details-bff/v1/cardio-details returns:
5
+ // title_bar.title_display → sport name ("STRENGTH TRAINER")
6
+ // title_bar.subtitle_display → time range text ("9:49 AM to 12:24 PM")
7
+ // details_edit_components.start_time_selector.initial_time → ISO start
8
+ // details_edit_components.end_time_selector.initial_time → ISO end
9
+ // horizontal_stat.stat_main_value_display → activity strain ("17.7")
10
+ // key_metric_carousel.key_metric_tile[]:
11
+ // {DURATION "2:35"+":38" suffix, CALORIES "701", AVG HR "123", MAX HR "171"}
12
+ // bar_graph_container.heart_rate_zones[]:
13
+ // id ∈ {RESTORATIVE=0, VERY_LIGHT=1, LIGHT=2, MODERATE=3, HARD=4, MAX=5}
14
+ // bar_graph_tile_time_display: "0:54" / "1:21" / ...
15
+ // graph_response.plots[*].plot.segments[*].points → HR curve
16
+ // weightlifting_cardio_details.weightlifting_exercises.exercise_summary_carousel.items[0]:
17
+ // tonnage_display (string lbs), subtitle_display ("29 Sets")
18
+ // strain_breakdown.msk_percent_display ("74%") + cardio_percent_display ("26%")
19
+
20
+ const ZONE_ID_TO_INDEX: Record<string, 0 | 1 | 2 | 3 | 4 | 5> = {
21
+ RESTORATIVE: 0,
22
+ VERY_LIGHT: 1,
23
+ LIGHT: 2,
24
+ MODERATE: 3,
25
+ HARD: 4,
26
+ MAX: 5,
27
+ };
28
+
29
+ function tileByIcon(tiles: unknown[], icon: string): Record<string, unknown> | null {
30
+ return (tiles.find(
31
+ (t) => isObject(t) && asString((t as Record<string, unknown>).key_metric_tile_icon) === icon,
32
+ ) as Record<string, unknown> | undefined) ?? null;
33
+ }
34
+
35
+ function tileValue(t: Record<string, unknown> | null): string | null {
36
+ if (!t) return null;
37
+ return asString(t.key_metric_tile_stat_value_display);
38
+ }
39
+
40
+ export function projectWorkout(raw: unknown, activityId: string): WorkoutOutT {
41
+ const root = isObject(raw) ? raw : {};
42
+
43
+ const titleBar = isObject(root.title_bar) ? (root.title_bar as Record<string, unknown>) : {};
44
+ const editComps = isObject(root.details_edit_components) ? (root.details_edit_components as Record<string, unknown>) : {};
45
+ const startSelector = isObject(editComps.start_time_selector) ? (editComps.start_time_selector as Record<string, unknown>) : {};
46
+ const endSelector = isObject(editComps.end_time_selector) ? (editComps.end_time_selector as Record<string, unknown>) : {};
47
+
48
+ const start = asString(startSelector.initial_time);
49
+ const end = asString(endSelector.initial_time);
50
+ const durationMs = start && end ? new Date(end).getTime() - new Date(start).getTime() : null;
51
+
52
+ const horizontalStat = isObject(root.horizontal_stat) ? (root.horizontal_stat as Record<string, unknown>) : null;
53
+ const strain = horizontalStat ? labelToNumber(asString(horizontalStat.stat_main_value_display)) : null;
54
+
55
+ const keyMetric = isObject(root.key_metric_carousel) ? (root.key_metric_carousel as Record<string, unknown>) : {};
56
+ const tiles = asArray(keyMetric.key_metric_tile);
57
+ const calTile = tileByIcon(tiles, "CALORIES");
58
+ const avgTile = tileByIcon(tiles, "HEART_RATE");
59
+ const maxTile = tileByIcon(tiles, "MAX_HEART_RATE");
60
+
61
+ // Zones
62
+ const barContainer = isObject(root.bar_graph_container) ? (root.bar_graph_container as Record<string, unknown>) : {};
63
+ const zoneRows = asArray(barContainer.heart_rate_zones);
64
+ const zones: Record<0 | 1 | 2 | 3 | 4 | 5, number | null> = { 0: null, 1: null, 2: null, 3: null, 4: null, 5: null };
65
+ for (const z of zoneRows) {
66
+ if (!isObject(z)) continue;
67
+ const id = asString(z.id);
68
+ const idx = id ? ZONE_ID_TO_INDEX[id] : undefined;
69
+ if (idx === undefined) continue;
70
+ zones[idx] = timeLabelToMs(asString(z.bar_graph_tile_time_display));
71
+ }
72
+
73
+ // HR curve from graph_response. The points carry NO absolute timestamp — the
74
+ // bpm is in data_scrubber_details.value_display ("76", unit "bpm"), and the
75
+ // time is encoded as position_x (fraction 0..1 of the workout's [start,end]
76
+ // window). The old code read dsd.timestamp/pt.timestamp (never present), so
77
+ // every point was dropped and hr_curve came back empty. We rebuild absolute
78
+ // timestamps from start + position_x·duration, then evenly downsample (a real
79
+ // workout has hundreds–thousands of samples — far too many for context).
80
+ const MAX_HR_POINTS = 120;
81
+ const graph = isObject(root.graph_response) ? (root.graph_response as Record<string, unknown>) : {};
82
+ const startMs = start ? Date.parse(start) : NaN;
83
+ // Collect bpm points per plot; the HR line is the plot with the most of them
84
+ // (other plots are zone bands / overlays).
85
+ let bestPlot: { x: number; bpm: number }[] = [];
86
+ for (const p of asArray(graph.plots)) {
87
+ if (!isObject(p)) continue;
88
+ const plot = isObject(p.plot) ? (p.plot as Record<string, unknown>) : null;
89
+ if (!plot) continue;
90
+ const pts: { x: number; bpm: number }[] = [];
91
+ for (const seg of asArray(plot.segments)) {
92
+ if (!isObject(seg)) continue;
93
+ for (const pt of asArray(seg.points)) {
94
+ if (!isObject(pt)) continue;
95
+ const dsd = isObject(pt.data_scrubber_details) ? (pt.data_scrubber_details as Record<string, unknown>) : {};
96
+ if (asString(dsd.unit_display) !== "bpm") continue;
97
+ const bpm = labelToNumber(asString(dsd.value_display)) ?? asNumber(dsd.value);
98
+ const x = asNumber(pt.position_x);
99
+ if (bpm !== null && x !== null) pts.push({ x, bpm: Math.round(bpm) });
100
+ }
101
+ }
102
+ if (pts.length > bestPlot.length) bestPlot = pts;
103
+ }
104
+ bestPlot.sort((a, b) => a.x - b.x);
105
+ const sampled = bestPlot.length > MAX_HR_POINTS
106
+ ? Array.from({ length: MAX_HR_POINTS }, (_, i) => bestPlot[Math.floor((i * bestPlot.length) / MAX_HR_POINTS)]!)
107
+ : bestPlot;
108
+ const hrCurve: { at: string; bpm: number }[] = [];
109
+ if (Number.isFinite(startMs) && durationMs && durationMs > 0) {
110
+ for (const pt of sampled) {
111
+ const frac = Math.min(1, Math.max(0, pt.x));
112
+ hrCurve.push({ at: new Date(startMs + frac * durationMs).toISOString(), bpm: pt.bpm });
113
+ }
114
+ }
115
+
116
+ // MSK fields
117
+ const sportName = asString(titleBar.title_display);
118
+ const wlDetails = isObject(root.weightlifting_cardio_details) ? (root.weightlifting_cardio_details as Record<string, unknown>) : null;
119
+ const isStrength = !!wlDetails || (sportName ?? "").toUpperCase().includes("STRENGTH");
120
+
121
+ let totalVolumeKg: number | null = null;
122
+ if (wlDetails) {
123
+ const wlEx = isObject(wlDetails.weightlifting_exercises) ? (wlDetails.weightlifting_exercises as Record<string, unknown>) : null;
124
+ const carousel = wlEx && isObject(wlEx.exercise_summary_carousel)
125
+ ? (wlEx.exercise_summary_carousel as Record<string, unknown>)
126
+ : null;
127
+ const items = carousel ? asArray(carousel.items) : [];
128
+ const first = isObject(items[0]) ? (items[0] as Record<string, unknown>) : null;
129
+ const tonnageStr = first ? asString(first.tonnage_display) : null;
130
+ const units = wlEx ? asString(wlEx.tonnage_units_display) : null;
131
+ const tonnage = labelToNumber(tonnageStr);
132
+ if (tonnage !== null) {
133
+ // Convert lbs → kg if units say lbs
134
+ totalVolumeKg = units?.toLowerCase() === "lbs" ? Math.round(tonnage / 2.20462) : tonnage;
135
+ }
136
+ }
137
+
138
+ const strainBreakdown = isObject(root.strain_breakdown) ? (root.strain_breakdown as Record<string, unknown>) : null;
139
+ const mskPct = strainBreakdown ? labelToNumber(asString(strainBreakdown.msk_percent_display)) : null;
140
+
141
+ return {
142
+ id: activityId,
143
+ sport_name: sportName,
144
+ start,
145
+ end,
146
+ duration_ms: durationMs,
147
+ strain,
148
+ calories: labelToNumber(tileValue(calTile)),
149
+ distance_m: null,
150
+ avg_hr_bpm: labelToNumber(tileValue(avgTile)),
151
+ max_hr_bpm: labelToNumber(tileValue(maxTile)),
152
+ zone_durations: {
153
+ zone_0_ms: zones[0],
154
+ zone_1_ms: zones[1],
155
+ zone_2_ms: zones[2],
156
+ zone_3_ms: zones[3],
157
+ zone_4_ms: zones[4],
158
+ zone_5_ms: zones[5],
159
+ },
160
+ hr_curve: hrCurve,
161
+ msk: {
162
+ total_volume_kg: totalVolumeKg,
163
+ intensity_pct: mskPct,
164
+ strain_score: strain,
165
+ is_strength_workout: isStrength,
166
+ },
167
+ };
168
+ }
@@ -0,0 +1,36 @@
1
+ import type { WorkoutListOutT } from "../schemas/workouts.js";
2
+ import { isObject, asArray, asNumber, asString } from "../lib/walk.js";
3
+ import { kjToCal } from "../lib/format.js";
4
+
5
+ export function projectWorkoutsList(raw: unknown, sportFilter?: string, limit = 10): WorkoutListOutT {
6
+ const root = isObject(raw) ? raw : {};
7
+ const records = asArray(root.records);
8
+ const all = records
9
+ .map((r) => {
10
+ if (!isObject(r)) return null;
11
+ const id = asString(r.id);
12
+ const sportName = asString(r.sport_name);
13
+ const start = asString(r.start);
14
+ const end = asString(r.end);
15
+ if (!id || !sportName || !start || !end) return null;
16
+ const score = isObject(r.score) ? r.score as Record<string, unknown> : {};
17
+ const kj = asNumber(score.kilojoule);
18
+ return {
19
+ id,
20
+ sport_name: sportName,
21
+ start,
22
+ end,
23
+ duration_ms: new Date(end).getTime() - new Date(start).getTime(),
24
+ strain: asNumber(score.strain),
25
+ avg_hr_bpm: asNumber(score.average_heart_rate),
26
+ max_hr_bpm: asNumber(score.max_heart_rate),
27
+ calories: kj !== null ? kjToCal(kj) : null,
28
+ distance_m: asNumber(score.distance_meter),
29
+ };
30
+ })
31
+ .filter((w): w is NonNullable<typeof w> => w !== null);
32
+ const filtered = sportFilter
33
+ ? all.filter((w) => w.sport_name.toLowerCase().includes(sportFilter.toLowerCase()))
34
+ : all;
35
+ return filtered.slice(0, limit);
36
+ }
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+
3
+ export const CalendarOut = z.object({
4
+ month: z.string().regex(/^\d{4}-\d{2}$/),
5
+ days: z.array(z.object({
6
+ date: z.iso.date(),
7
+ recovery_score: z.number().nullable(),
8
+ recovery_state: z.enum(["GREEN", "YELLOW", "RED"]).nullable(),
9
+ sleep_score: z.number().nullable(),
10
+ day_strain: z.number().nullable(),
11
+ })),
12
+ });
13
+ export type CalendarOutT = z.infer<typeof CalendarOut>;
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ import { withPreview } from "./primitives.js";
3
+
4
+ export const CoachAskOut = withPreview(z.object({
5
+ conversation_id: z.string(),
6
+ turn_id: z.string(),
7
+ response_text: z.string().nullable(),
8
+ turn_status: z.string(),
9
+ polled_iterations: z.number().int(),
10
+ timed_out: z.boolean(),
11
+ }));
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+
3
+ // `whoop_communities` — your community memberships (teams / friend groups) +
4
+ // optionally your rank in each.
5
+ //
6
+ // Source: GET /community-service/v1/communities/memberships
7
+ // Query params: userId, teamType, includeOwnerDetails, includeUserRank,
8
+ // leaderboardType, period, offset, limit
9
+ //
10
+ // IMPORTANT — schema status: this is a working hypothesis based on the
11
+ // documented response shape `{total_count, offset, records}` plus inferred
12
+ // record fields from sibling community endpoints (join receipt, leaderboard
13
+ // rows). The exact `records[]` field set hasn't been captured against a live
14
+ // account at the time of writing — every nullable field is tolerant of
15
+ // missing data, and a `WhoopProjectionError` from this tool is the signal
16
+ // that Whoop's actual shape differs from these assumptions.
17
+
18
+ export const CommunityMembership = z.object({
19
+ member_type: z.string().nullable(),
20
+ notification_setting: z.string().nullable(),
21
+ unread_count: z.number().int().nullable(),
22
+ online: z.boolean().nullable(),
23
+ joined_at: z.string().nullable(),
24
+ last_online: z.string().nullable(),
25
+ });
26
+
27
+ export const CommunityRank = z.object({
28
+ rank: z.number().int().nullable(),
29
+ score: z.number().nullable(),
30
+ metric: z.string().nullable(),
31
+ period: z.string().nullable(),
32
+ });
33
+
34
+ export const CommunityRecord = z.object({
35
+ id: z.number().int(),
36
+ name: z.string(),
37
+ avatar_url: z.string().nullable(),
38
+ banner_url: z.string().nullable(),
39
+ about: z.string().nullable(),
40
+ private: z.boolean().nullable(),
41
+ member_count: z.number().int().nullable(),
42
+ owner_id: z.number().int().nullable(),
43
+ team_type: z.string().nullable(),
44
+ membership: CommunityMembership,
45
+ rank: CommunityRank.nullable(),
46
+ });
47
+
48
+ export const CommunitiesOut = z.object({
49
+ total_count: z.number().int(),
50
+ offset: z.number().int(),
51
+ team_type_filter: z.enum(["ALL", "COMMUNITY", "TEAM", "BUSINESS"]),
52
+ leaderboard_metric: z.enum(["strain", "sleep", "recovery"]),
53
+ period: z.enum(["day", "week", "month"]),
54
+ communities: z.array(CommunityRecord),
55
+ });
56
+ export type CommunitiesOutT = z.infer<typeof CommunitiesOut>;
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+
3
+ export const CompareOut = z.object({
4
+ window: z.enum(["week", "month"]),
5
+ a: z.object({ start_date: z.string(), end_date: z.iso.date() }),
6
+ b: z.object({ start_date: z.string(), end_date: z.iso.date() }),
7
+ metrics: z.array(z.object({
8
+ metric: z.string(),
9
+ a_avg: z.number().nullable(),
10
+ b_avg: z.number().nullable(),
11
+ delta_abs: z.number().nullable(),
12
+ delta_pct: z.number().nullable(),
13
+ unit: z.string().nullable(),
14
+ })),
15
+ });
16
+ export type CompareOutT = z.infer<typeof CompareOut>;
17
+ export type CompareMetricRow = CompareOutT["metrics"][number];
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ import { WritePreviewSchema } from "./primitives.js";
3
+
4
+ export const RawOut = z.union([
5
+ WritePreviewSchema,
6
+ z.object({
7
+ path: z.string(),
8
+ method: z.string(),
9
+ status: z.number().int(),
10
+ response: z.unknown(),
11
+ }),
12
+ ]);
13
+ export type RawOutT = z.infer<typeof RawOut>;
14
+
15
+ export const EndpointsOut = z.object({
16
+ total_in_catalog: z.number().int(),
17
+ matched: z.number().int(),
18
+ truncated: z.boolean(),
19
+ endpoints: z.array(z.string()),
20
+ });
21
+ export type EndpointsOutT = z.infer<typeof EndpointsOut>;