@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,135 @@
1
+ import type { CommunitiesOutT } from "../schemas/communities.js";
2
+ import { isObject, asArray, asNumber, asString, asBool } from "../lib/walk.js";
3
+
4
+ // Conservative projection over /community-service/v1/communities/memberships.
5
+ // The endpoint returns `{total_count, offset, records}` (verified — same
6
+ // endpoint is already called by whoop_leaderboard for community auto-discovery).
7
+ // Per-record fields are inferred from sibling endpoints + community CRUD shapes.
8
+ // Every field is nullable in the schema so partial responses still parse;
9
+ // when Whoop's actual record shape differs, the projection just returns more
10
+ // nulls rather than throwing.
11
+
12
+ interface ProjectInput {
13
+ raw: unknown;
14
+ team_type: "ALL" | "COMMUNITY" | "TEAM" | "BUSINESS";
15
+ leaderboard_metric: "strain" | "sleep" | "recovery";
16
+ period: "day" | "week" | "month";
17
+ }
18
+
19
+ function pickString(obj: Record<string, unknown>, keys: string[]): string | null {
20
+ for (const k of keys) {
21
+ const v = asString(obj[k]);
22
+ if (v !== null) return v;
23
+ }
24
+ return null;
25
+ }
26
+
27
+ function pickNumber(obj: Record<string, unknown>, keys: string[]): number | null {
28
+ for (const k of keys) {
29
+ const v = asNumber(obj[k]);
30
+ if (v !== null) return v;
31
+ }
32
+ return null;
33
+ }
34
+
35
+ function pickBool(obj: Record<string, unknown>, keys: string[]): boolean | null {
36
+ for (const k of keys) {
37
+ const v = asBool(obj[k]);
38
+ if (v !== null) return v;
39
+ }
40
+ return null;
41
+ }
42
+
43
+ function projectRank(
44
+ source: Record<string, unknown>,
45
+ metric: string,
46
+ period: string,
47
+ ): CommunitiesOutT["communities"][number]["rank"] {
48
+ // The user's rank usually lives in either `user_rank`, `rank`, or
49
+ // `leaderboard_rank` depending on Whoop's flavor; try the common ones.
50
+ const candidate =
51
+ (isObject(source.user_rank) ? source.user_rank : null) ??
52
+ (isObject(source.rank) ? source.rank : null) ??
53
+ (isObject(source.leaderboard_rank) ? source.leaderboard_rank : null);
54
+ if (!candidate) return null;
55
+ const c = candidate as Record<string, unknown>;
56
+ return {
57
+ rank: pickNumber(c, ["rank", "position", "place"]) !== null
58
+ ? Math.trunc(pickNumber(c, ["rank", "position", "place"])!)
59
+ : null,
60
+ score: pickNumber(c, ["score", "value", "day_strain", "performance", "average"]),
61
+ metric,
62
+ period,
63
+ };
64
+ }
65
+
66
+ function projectMembership(
67
+ source: Record<string, unknown>,
68
+ ): CommunitiesOutT["communities"][number]["membership"] {
69
+ // The membership sub-object may be inline on the record or nested under
70
+ // `membership` / `user_membership`. Same defensive read.
71
+ const candidate =
72
+ (isObject(source.membership) ? source.membership : null) ??
73
+ (isObject(source.user_membership) ? source.user_membership : null) ??
74
+ source;
75
+ const c = candidate as Record<string, unknown>;
76
+ const unread = pickNumber(c, ["unread_count"]);
77
+ return {
78
+ member_type: pickString(c, ["member_type", "role"]),
79
+ notification_setting: pickString(c, ["notification_setting", "notifications"]),
80
+ unread_count: unread !== null ? Math.trunc(unread) : null,
81
+ online: pickBool(c, ["online", "is_online"]),
82
+ joined_at: pickString(c, ["joined_at", "created_at"]),
83
+ last_online: pickString(c, ["last_online", "last_seen"]),
84
+ };
85
+ }
86
+
87
+ export function projectCommunities(input: ProjectInput): CommunitiesOutT {
88
+ const root = isObject(input.raw) ? input.raw : {};
89
+ const totalCountRaw = pickNumber(root, ["total_count", "totalCount"]);
90
+ const offsetRaw = pickNumber(root, ["offset"]);
91
+
92
+ const records = asArray(root.records);
93
+
94
+ const communities = records.flatMap((r): CommunitiesOutT["communities"] => {
95
+ if (!isObject(r)) return [];
96
+ const rec = r as Record<string, unknown>;
97
+ // Community core fields may be inline or nested under `community` /
98
+ // `team` depending on the response variant.
99
+ const coreCandidate =
100
+ (isObject(rec.community) ? rec.community : null) ??
101
+ (isObject(rec.team) ? rec.team : null) ??
102
+ rec;
103
+ const core = coreCandidate as Record<string, unknown>;
104
+
105
+ const id = pickNumber(core, ["id", "community_id", "team_id"]);
106
+ const name = pickString(core, ["name", "title"]);
107
+ if (id === null || name === null) return []; // skip malformed records
108
+
109
+ const memberCount = pickNumber(core, ["member_count", "members", "total_members"]);
110
+ const ownerId = pickNumber(core, ["owner_id", "ownerId"]);
111
+
112
+ return [{
113
+ id: Math.trunc(id),
114
+ name,
115
+ avatar_url: pickString(core, ["avatar_url", "avatar", "avatarUrl"]),
116
+ banner_url: pickString(core, ["banner_url", "banner", "bannerUrl"]),
117
+ about: pickString(core, ["about", "description"]),
118
+ private: pickBool(core, ["private", "is_private"]),
119
+ member_count: memberCount !== null ? Math.trunc(memberCount) : null,
120
+ owner_id: ownerId !== null ? Math.trunc(ownerId) : null,
121
+ team_type: pickString(core, ["team_type", "type"]),
122
+ membership: projectMembership(rec),
123
+ rank: projectRank(rec, input.leaderboard_metric, input.period),
124
+ }];
125
+ });
126
+
127
+ return {
128
+ total_count: totalCountRaw !== null ? Math.trunc(totalCountRaw) : communities.length,
129
+ offset: offsetRaw !== null ? Math.trunc(offsetRaw) : 0,
130
+ team_type_filter: input.team_type,
131
+ leaderboard_metric: input.leaderboard_metric,
132
+ period: input.period,
133
+ communities,
134
+ };
135
+ }
@@ -0,0 +1,85 @@
1
+ import type { CycleOutT } from "../schemas/womens_health.js";
2
+ import { isObject, asArray, asBool, asNumber, asString, findByType } from "../lib/walk.js";
3
+
4
+ // /womens-health-service/v1/menstrual-cycle-insights?date=YYYY-MM-DD returns a
5
+ // tiles[] BFF (NOT flat fields). The data lives in:
6
+ // HEADER_TILE content.title_display "Cycle Day 11",
7
+ // content.subtitle_display "Luteal Phase", content.style "LUTEAL"
8
+ // CALENDAR_TILE content.calendar.days_of_month[]:
9
+ // { date "2026-05-21", phase, day_state "PERIOD", first_day_of_phase }
10
+ // TYPICAL_CYCLE_TILE content.stats[]: { title_display "CYCLE LENGTH", value_display "-"|"28" }
11
+ // CYCLE_PHASE_COACHING content.destination.parameters.phase "LUTEAL"
12
+ //
13
+ // Hormonal mode / contraception / pregnancy are account-settings that this BFF
14
+ // does NOT carry, so they stay null here.
15
+ //
16
+ // The previous projection looked for tile types CYCLE_PHASE_TILE / HORMONAL_MODE_TILE
17
+ // that don't exist in the response, so every field returned null even on a fully
18
+ // populated 200 (women's-health enabled, mid-cycle).
19
+
20
+ function tileByType(tiles: unknown[], type: string): Record<string, unknown> | null {
21
+ for (const t of tiles) {
22
+ if (isObject(t) && asString(t.type) === type) return t;
23
+ }
24
+ return null;
25
+ }
26
+
27
+ function contentOf(tile: Record<string, unknown> | null): Record<string, unknown> {
28
+ return tile && isObject(tile.content) ? (tile.content as Record<string, unknown>) : {};
29
+ }
30
+
31
+ export function projectCycle(raw: unknown, date: string): CycleOutT {
32
+ const root = isObject(raw) ? raw : {};
33
+ const tiles = asArray(root.tiles);
34
+
35
+ const header = contentOf(tileByType(tiles, "HEADER_TILE"));
36
+ // "Cycle Day 11" → 11
37
+ const dayMatch = (asString(header.title_display) ?? "").match(/(\d+)/);
38
+ const cycleDay = dayMatch ? Number(dayMatch[1]) : null;
39
+ // Human-readable phase ("Luteal Phase"); fall back to the style enum ("LUTEAL").
40
+ const phase = asString(header.subtitle_display) ?? asString(header.style);
41
+
42
+ // "CYCLE LENGTH" stat — value_display is "-" until there's enough history, so
43
+ // asNumber yields null in that case (correct).
44
+ const typical = contentOf(tileByType(tiles, "TYPICAL_CYCLE_TILE"));
45
+ let cycleLength: number | null = null;
46
+ for (const s of asArray(typical.stats)) {
47
+ if (isObject(s) && /CYCLE LENGTH/i.test(asString(s.title_display) ?? "")) {
48
+ cycleLength = asNumber(s.value_display);
49
+ }
50
+ }
51
+
52
+ // Forward-looking predictions from the calendar: the earliest first-day-of-phase
53
+ // marker on/after `date` for menstruation (next period) and ovulation. Null when
54
+ // the predicted day falls outside the month the BFF returned.
55
+ const calendar = contentOf(tileByType(tiles, "CALENDAR_TILE"));
56
+ const calObj = isObject(calendar.calendar) ? (calendar.calendar as Record<string, unknown>) : {};
57
+ const days = asArray(calObj.days_of_month);
58
+ const nextPhaseStart = (phaseName: string): string | null => {
59
+ let best: string | null = null;
60
+ for (const d of days) {
61
+ if (!isObject(d) || d.first_day_of_phase !== true) continue;
62
+ if (asString(d.phase) !== phaseName) continue;
63
+ const dDate = asString(d.date);
64
+ if (!dDate || dDate < date) continue; // ISO dates compare lexicographically
65
+ if (best === null || dDate < best) best = dDate;
66
+ }
67
+ return best;
68
+ };
69
+
70
+ // Hormonal mode / contraception / pregnancy aren't in this BFF; keep the
71
+ // defensive lookup in case a variant carries them, otherwise null.
72
+ const modeTile = findByType(root, "HORMONAL_MODE_TILE");
73
+
74
+ return {
75
+ date,
76
+ phase,
77
+ cycle_day: cycleDay,
78
+ cycle_length: cycleLength,
79
+ next_period_predicted_date: nextPhaseStart("MENSTRUAL"),
80
+ ovulation_predicted_date: nextPhaseStart("OVULATORY"),
81
+ hormonal_mode: modeTile ? asString(modeTile.mode) : null,
82
+ contraception_type: modeTile ? asString(modeTile.contraception_type) : null,
83
+ is_pregnant: modeTile ? asBool(modeTile.is_pregnant) : null,
84
+ };
85
+ }
@@ -0,0 +1,43 @@
1
+ import type { HrZonesOutT } from "../schemas/settings.js";
2
+ import { isObject, asArray, asBool, asNumber, asString } from "../lib/walk.js";
3
+
4
+ interface ProjectHrZonesInput {
5
+ zones: unknown;
6
+ settings: unknown;
7
+ }
8
+
9
+ const VALID_ZONE_IDS = ["ZONE_1", "ZONE_2", "ZONE_3", "ZONE_4", "ZONE_5"] as const;
10
+ type ZoneId = typeof VALID_ZONE_IDS[number];
11
+
12
+ export function projectHrZones(input: ProjectHrZonesInput): HrZonesOutT {
13
+ const zones = isObject(input.zones) ? input.zones as Record<string, unknown> : {};
14
+ const settings = isObject(input.settings) ? input.settings as Record<string, unknown> : {};
15
+
16
+ // Max HR lives in settings.heart_rate_entry_row (an array of {id, value} rows,
17
+ // id "MAX_HR"); fall back to the zones-screen entry field.
18
+ let maxHr: number | null = null;
19
+ for (const r of asArray(settings.heart_rate_entry_row)) {
20
+ if (isObject(r) && asString(r.id) === "MAX_HR") maxHr = asNumber(r.value);
21
+ }
22
+ if (maxHr === null && isObject(zones.max_hr_entry_field)) {
23
+ maxHr = asNumber((zones.max_hr_entry_field as Record<string, unknown>).value);
24
+ }
25
+
26
+ const zoneList = asArray(zones.zones)
27
+ .map((z) => {
28
+ if (!isObject(z)) return null;
29
+ const id = asString(z.id);
30
+ if (!id || !(VALID_ZONE_IDS as readonly string[]).includes(id)) return null;
31
+ const min = asNumber(z.min) ?? 0;
32
+ const max = asNumber(z.max) ?? 0;
33
+ return { id: id as ZoneId, min, max };
34
+ })
35
+ .filter((z): z is { id: ZoneId; min: number; max: number } => z !== null);
36
+
37
+ return {
38
+ max_hr: maxHr,
39
+ is_custom: asBool(zones.is_custom) ?? false,
40
+ effective_timestamp: asString(zones.effective_timestamp),
41
+ zones: zoneList,
42
+ };
43
+ }
@@ -0,0 +1,55 @@
1
+ import type { JournalOutT } from "../schemas/journal.js";
2
+ import { BEHAVIORS_BY_ID } from "../data/behaviors.js";
3
+ import { isObject, asArray, asNumber, asString, asBool } from "../lib/walk.js";
4
+
5
+ export function projectJournal(raw: unknown, date: string): JournalOutT {
6
+ let inputs: unknown[];
7
+ let cycleId: number | null = null;
8
+ let entryId: string | null = null;
9
+ let notes: string | null = null;
10
+
11
+ if (Array.isArray(raw)) {
12
+ inputs = raw;
13
+ } else if (isObject(raw)) {
14
+ const journal = isObject(raw.journal) ? raw.journal as Record<string, unknown> : null;
15
+ if (journal) {
16
+ inputs = asArray(journal.tracked_behaviors);
17
+ cycleId = asNumber(journal.cycle_id);
18
+ entryId = asString(journal.journal_entry_id);
19
+ notes = asString(journal.notes);
20
+ } else {
21
+ inputs = asArray(raw.records ?? raw.tracker_inputs ?? raw.items);
22
+ }
23
+ } else {
24
+ inputs = [];
25
+ }
26
+
27
+ const behaviors = inputs
28
+ .map((i) => {
29
+ if (!isObject(i)) return null;
30
+ // The v3 drafts endpoint nests each logged behavior as
31
+ // { behavior_tracker: { id, title, ... }, tracker_input: { behavior_tracker_id,
32
+ // answered_yes, magnitude_input_value, magnitude_input_label, ... } }
33
+ // The flat shape (the v2 write body, and older captures) puts those fields
34
+ // directly on the entry. Read whichever exists — missing this nesting is why
35
+ // every behavior was being dropped and `behaviors` came back empty (issue #2).
36
+ const input = isObject(i.tracker_input) ? (i.tracker_input as Record<string, unknown>) : i;
37
+ const tracker = isObject(i.behavior_tracker) ? (i.behavior_tracker as Record<string, unknown>) : null;
38
+ const id = asNumber(input.behavior_tracker_id ?? (tracker ? tracker.id : undefined) ?? i.behavior_id);
39
+ if (id === null) return null;
40
+ const meta = BEHAVIORS_BY_ID.get(id);
41
+ return {
42
+ behavior_tracker_id: id,
43
+ title: meta?.title ?? asString(tracker?.title) ?? "",
44
+ category: meta?.category ?? asString(tracker?.category) ?? "",
45
+ internal_name: meta?.internal_name ?? asString(tracker?.internal_name) ?? "",
46
+ answered_yes: asBool(input.answered_yes),
47
+ magnitude_value: asNumber(input.magnitude_input_value),
48
+ magnitude_label: asString(input.magnitude_input_label),
49
+ recorded_at: asString(input.recorded_at),
50
+ };
51
+ })
52
+ .filter((b): b is NonNullable<typeof b> => b !== null);
53
+
54
+ return { date, cycle_id: cycleId, journal_entry_id: entryId, notes, behaviors };
55
+ }
@@ -0,0 +1,49 @@
1
+ import type { LeaderboardOutT } from "../schemas/leaderboard.js";
2
+ import { isObject, asArray, asNumber, asString } from "../lib/walk.js";
3
+
4
+ interface ProjectLeaderboardInput {
5
+ community_id: number;
6
+ community_name: string | null;
7
+ window: "day" | "week" | "month";
8
+ metric: "recovery" | "sleep" | "strain";
9
+ date: string;
10
+ board: unknown;
11
+ user_row: unknown | null;
12
+ }
13
+
14
+ export function projectLeaderboard(input: ProjectLeaderboardInput): LeaderboardOutT {
15
+ const board = isObject(input.board) ? input.board as Record<string, unknown> : {};
16
+ const records = asArray(board.records)
17
+ .map((r) => {
18
+ if (!isObject(r)) return null;
19
+ const score = asNumber(r.score ?? r.day_strain ?? r.duration);
20
+ return {
21
+ rank: asNumber(r.rank) ?? 0,
22
+ user_id: asNumber(r.user_id) ?? 0,
23
+ first_name: asString(r.first_name) ?? "",
24
+ last_name: asString(r.last_name) ?? "",
25
+ value: score,
26
+ secondary_value: asNumber(r.hrv ?? r.performance ?? r.calories),
27
+ };
28
+ })
29
+ .filter((r): r is NonNullable<typeof r> => r !== null);
30
+
31
+ const userRow = input.user_row && isObject(input.user_row) ? input.user_row as Record<string, unknown> : null;
32
+
33
+ return {
34
+ community_id: input.community_id,
35
+ community_name: input.community_name,
36
+ window: input.window,
37
+ metric: input.metric,
38
+ date_label: input.date,
39
+ average: asNumber(board.average),
40
+ total_compliant: asNumber(board.total_compliant),
41
+ total_empty: asNumber(board.total_empty),
42
+ records,
43
+ your_position: {
44
+ rank: userRow ? asNumber(userRow.rank) : null,
45
+ value: userRow ? asNumber(userRow.score ?? userRow.day_strain ?? userRow.duration) : null,
46
+ in_window: userRow !== null,
47
+ },
48
+ };
49
+ }
@@ -0,0 +1,29 @@
1
+ import type { LiftExerciseOutT } from "../schemas/strength.js";
2
+ import { ExerciseInfoSchema } from "../whoop/types.js";
3
+ import { extractSessions } from "../lib/walk.js";
4
+
5
+ interface ProjectLiftExerciseInput {
6
+ info: unknown;
7
+ history: unknown;
8
+ prs: unknown;
9
+ }
10
+
11
+ export function projectLiftExercise(input: ProjectLiftExerciseInput): LiftExerciseOutT {
12
+ const info = ExerciseInfoSchema.parse(input.info);
13
+ return {
14
+ exercise: {
15
+ id: info.exercise_id,
16
+ name: info.name,
17
+ muscle_groups: info.muscle_groups,
18
+ equipment: info.equipment,
19
+ movement_pattern: info.movement_pattern,
20
+ laterality: info.laterality,
21
+ custom: info.custom_exercise,
22
+ volume_input_format: info.volume_input_format,
23
+ instructions: info.instructions,
24
+ video_url: info.video_url,
25
+ },
26
+ recent_sessions: extractSessions(input.history),
27
+ personal_records: extractSessions(input.prs),
28
+ };
29
+ }
@@ -0,0 +1,140 @@
1
+ import type { LiftHistoryOutT } from "../schemas/strength.js";
2
+ import { isObject, asArray, asNumber, asString } from "../lib/walk.js";
3
+
4
+ // Whoop returns these internal_name values for set-based strength workouts.
5
+ // "weightlifting_msk" = Strength Trainer. "weightlifting" and "powerlifting"
6
+ // are manual logs. None of them contain "strength" — match by broader pattern.
7
+ function isStrengthSport(name: string | null): boolean {
8
+ if (!name) return false;
9
+ return /weight|strength|powerlift/i.test(name);
10
+ }
11
+
12
+ // Parse "5 Sets" → 5, "1 Set" → 1, "0 Sets" → 0. Returns null if not parseable.
13
+ function parseSetCount(s: string | null): number | null {
14
+ if (!s) return null;
15
+ const m = s.match(/^(\d+)\s*Sets?/i);
16
+ return m && m[1] ? parseInt(m[1], 10) : null;
17
+ }
18
+
19
+ interface ProjectLiftHistoryInput {
20
+ workouts: unknown;
21
+ details: unknown[];
22
+ }
23
+
24
+ export function projectLiftHistory(input: ProjectLiftHistoryInput): LiftHistoryOutT {
25
+ const root = isObject(input.workouts) ? input.workouts : {};
26
+ const records = asArray(root.records).filter(
27
+ (r) => isObject(r) && isStrengthSport(asString((r as Record<string, unknown>).sport_name)),
28
+ );
29
+ const out: LiftHistoryOutT = [];
30
+ for (let i = 0; i < records.length; i++) {
31
+ const r = records[i] as Record<string, unknown>;
32
+ const detail = input.details[i];
33
+ if (!isObject(detail)) continue;
34
+
35
+ // Set-level data lives at:
36
+ // weightlifting_cardio_details.weightlifting_exercises.exercise_summary_carousel.items[]
37
+ // The first item is a SUMMARY row ("8 Exercises", "29 Sets") — skip it.
38
+ // Each subsequent item is one exercise with set_count + tonnage + total reps.
39
+ const wld = isObject(detail.weightlifting_cardio_details)
40
+ ? (detail.weightlifting_cardio_details as Record<string, unknown>)
41
+ : {};
42
+ const wex = isObject(wld.weightlifting_exercises)
43
+ ? (wld.weightlifting_exercises as Record<string, unknown>)
44
+ : {};
45
+ const carousel = isObject(wex.exercise_summary_carousel)
46
+ ? (wex.exercise_summary_carousel as Record<string, unknown>)
47
+ : {};
48
+ const tonnageUnits = asString(wex.tonnage_units_display);
49
+ const items = asArray(carousel.items);
50
+
51
+ // The first carousel item is the aggregate row ("8 Exercises", "29 Sets",
52
+ // total tonnage in lbs). Read it before iterating real exercises.
53
+ let summaryTonnageLbs: number | null = null;
54
+ if (items.length > 0 && isObject(items[0])) {
55
+ const summary = items[0] as Record<string, unknown>;
56
+ const t = asString(summary.tonnage_display);
57
+ if (t) {
58
+ const n = parseFloat(t.replace(/,/g, ""));
59
+ if (Number.isFinite(n)) summaryTonnageLbs = n;
60
+ }
61
+ }
62
+
63
+ let setCount = 0;
64
+ const exercises: LiftHistoryOutT[number]["exercises"] = [];
65
+ for (let j = 0; j < items.length; j++) {
66
+ const it = items[j];
67
+ if (!isObject(it)) continue;
68
+ const exId = asString(it.exercise_id);
69
+ // Skip the aggregate summary row (no exercise_id)
70
+ if (exId === null) continue;
71
+ const itemSetCount = parseSetCount(asString(it.subtitle_display));
72
+ const tonnage = (() => {
73
+ const t = asString(it.tonnage_display);
74
+ if (!t) return null;
75
+ const n = parseFloat(t.replace(/,/g, ""));
76
+ return Number.isFinite(n) ? n : null;
77
+ })();
78
+ const totalReps = (() => {
79
+ const v = asString(it.volume_display);
80
+ if (!v) return null;
81
+ const n = parseInt(v.replace(/,/g, ""), 10);
82
+ return Number.isFinite(n) ? n : null;
83
+ })();
84
+ const achievements = asArray(it.achievement_icons)
85
+ .map((a) => asString(a))
86
+ .filter((a): a is string => a !== null);
87
+
88
+ exercises.push({
89
+ exercise_id: exId,
90
+ name: asString(it.title_display),
91
+ set_count: itemSetCount,
92
+ total_reps: totalReps,
93
+ tonnage,
94
+ tonnage_units: tonnageUnits,
95
+ achievements,
96
+ sets: [], // per-set detail not in cardio-details
97
+ });
98
+ setCount += itemSetCount ?? 0;
99
+ }
100
+
101
+ const start = asString(r.start) ?? "";
102
+ const end = asString(r.end) ?? "";
103
+ const score = isObject(r.score) ? (r.score as Record<string, unknown>) : {};
104
+
105
+ // MSK total volume comes from the carousel summary row (lbs). Convert to kg
106
+ // since the schema field is _kg and the iOS app shows kg in some locales.
107
+ const LBS_TO_KG = 0.45359237;
108
+ const mskVolumeKg = (() => {
109
+ if (summaryTonnageLbs === null) return null;
110
+ if (tonnageUnits && /kg/i.test(tonnageUnits)) return summaryTonnageLbs;
111
+ // default: assume lbs
112
+ return Math.round(summaryTonnageLbs * LBS_TO_KG);
113
+ })();
114
+
115
+ // MSK intensity % from strain_breakdown.msk_percent_display ("74%")
116
+ const strainBreakdown = isObject(detail.strain_breakdown)
117
+ ? (detail.strain_breakdown as Record<string, unknown>)
118
+ : {};
119
+ const mskIntensityPct = (() => {
120
+ const v = asString(strainBreakdown.msk_percent_display);
121
+ if (!v) return null;
122
+ const n = parseFloat(v.replace("%", ""));
123
+ return Number.isFinite(n) ? n : null;
124
+ })();
125
+
126
+ out.push({
127
+ activity_id: asString(r.id) ?? "",
128
+ date: start.slice(0, 10),
129
+ name: asString(r.name) ?? null,
130
+ duration_ms: start && end ? new Date(end).getTime() - new Date(start).getTime() : 0,
131
+ strain: asNumber(score.strain),
132
+ msk_total_volume_kg: mskVolumeKg,
133
+ msk_intensity_pct: mskIntensityPct,
134
+ exercise_count: exercises.length,
135
+ set_count: setCount,
136
+ exercises,
137
+ });
138
+ }
139
+ return out;
140
+ }
@@ -0,0 +1,70 @@
1
+ import type { LiftLibraryOutT } from "../schemas/strength.js";
2
+ import { isObject, asArray, asNumber, asString } from "../lib/walk.js";
3
+
4
+ export function projectLibraryList(raw: unknown): LiftLibraryOutT {
5
+ const root = isObject(raw) ? raw : {};
6
+ const my = asArray(root.my_workouts_list)
7
+ .map((w) => {
8
+ if (!isObject(w)) return null;
9
+ const tid = asNumber(w.template_id ?? w.id);
10
+ if (tid === null) return null;
11
+ return {
12
+ template_id: tid,
13
+ name: asString(w.name) ?? "",
14
+ exercise_count: asNumber(w.exercise_count) ?? 0,
15
+ last_used: asString(w.last_used),
16
+ };
17
+ })
18
+ .filter((x): x is NonNullable<typeof x> => x !== null);
19
+ const whoop = asArray(root.whoop_workouts_list)
20
+ .map((w) => {
21
+ if (!isObject(w)) return null;
22
+ const tid = asNumber(w.template_id ?? w.id);
23
+ if (tid === null) return null;
24
+ return {
25
+ template_id: tid,
26
+ name: asString(w.name) ?? "",
27
+ exercise_count: asNumber(w.exercise_count) ?? 0,
28
+ };
29
+ })
30
+ .filter((x): x is NonNullable<typeof x> => x !== null);
31
+ return { mode: "list" as const, my_workouts: my, whoop_workouts: whoop };
32
+ }
33
+
34
+ export function projectLibrarySingle(raw: unknown): LiftLibraryOutT {
35
+ const root = isObject(raw) ? raw : {};
36
+ const exercises: Array<{
37
+ exercise_id: string;
38
+ name: string;
39
+ sets: { reps: number | null; weight: number | null; time_seconds: number | null }[];
40
+ }> = [];
41
+ for (const g of asArray(root.workout_groups)) {
42
+ if (!isObject(g)) continue;
43
+ for (const we of asArray(g.workout_exercises)) {
44
+ if (!isObject(we)) continue;
45
+ const ex = isObject(we.exercise_details) ? we.exercise_details as Record<string, unknown> : {};
46
+ const sets = asArray(we.sets)
47
+ .map((s) => {
48
+ if (!isObject(s)) return null;
49
+ const t = asNumber(s.time_in_seconds);
50
+ return {
51
+ reps: asNumber(s.number_of_reps),
52
+ weight: asNumber(s.weight),
53
+ time_seconds: t !== null ? Math.round(t) : null,
54
+ };
55
+ })
56
+ .filter((s): s is NonNullable<typeof s> => s !== null);
57
+ exercises.push({
58
+ exercise_id: asString(ex.exercise_id) ?? "",
59
+ name: asString(ex.name) ?? "",
60
+ sets,
61
+ });
62
+ }
63
+ }
64
+ return {
65
+ mode: "single" as const,
66
+ template_id: asNumber(root.workout_template_key ?? root.template_id) ?? 0,
67
+ name: asString(root.name) ?? "",
68
+ exercises,
69
+ };
70
+ }