@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,418 @@
1
+ // Tree-walking + type-coercion helpers used across projections.
2
+ // Defensive: every helper short-circuits on bad shapes instead of throwing.
3
+
4
+ export function isObject(x: unknown): x is Record<string, unknown> {
5
+ return typeof x === "object" && x !== null && !Array.isArray(x);
6
+ }
7
+
8
+ export function asArray(x: unknown): unknown[] {
9
+ return Array.isArray(x) ? x : [];
10
+ }
11
+
12
+ export function asString(x: unknown): string | null {
13
+ return typeof x === "string" ? x : null;
14
+ }
15
+
16
+ export function asNumber(x: unknown): number | null {
17
+ if (typeof x === "number") return x;
18
+ if (typeof x === "string") {
19
+ const cleaned = x.replace(/,/g, "");
20
+ const n = Number(cleaned);
21
+ return Number.isFinite(n) ? n : null;
22
+ }
23
+ return null;
24
+ }
25
+
26
+ export function asBool(x: unknown): boolean | null {
27
+ if (typeof x === "boolean") return x;
28
+ if (x === "true") return true;
29
+ if (x === "false") return false;
30
+ return null;
31
+ }
32
+
33
+ export function asMedal(x: unknown): "GOLD" | "SILVER" | "BRONZE" | null {
34
+ if (x === "BADGE_GOLD") return "GOLD";
35
+ if (x === "BADGE_SILVER") return "SILVER";
36
+ if (x === "BADGE_BRONZE") return "BRONZE";
37
+ return null;
38
+ }
39
+
40
+ export function findFirst(
41
+ node: unknown,
42
+ predicate: (n: Record<string, unknown>) => boolean,
43
+ ): Record<string, unknown> | null {
44
+ if (isObject(node)) {
45
+ if (predicate(node)) return node;
46
+ for (const v of Object.values(node)) {
47
+ const found = findFirst(v, predicate);
48
+ if (found) return found;
49
+ }
50
+ } else if (Array.isArray(node)) {
51
+ for (const v of node) {
52
+ const found = findFirst(v, predicate);
53
+ if (found) return found;
54
+ }
55
+ }
56
+ return null;
57
+ }
58
+
59
+ export function findAll(
60
+ node: unknown,
61
+ predicate: (n: Record<string, unknown>) => boolean,
62
+ ): Record<string, unknown>[] {
63
+ const out: Record<string, unknown>[] = [];
64
+ if (isObject(node)) {
65
+ if (predicate(node)) out.push(node);
66
+ for (const v of Object.values(node)) out.push(...findAll(v, predicate));
67
+ } else if (Array.isArray(node)) {
68
+ for (const v of node) out.push(...findAll(v, predicate));
69
+ }
70
+ return out;
71
+ }
72
+
73
+ export function findByType(node: unknown, type: string): Record<string, unknown> | null {
74
+ return findFirst(node, (n) => n.type === type);
75
+ }
76
+
77
+ export function findAllByType(node: unknown, type: string): Record<string, unknown>[] {
78
+ return findAll(node, (n) => n.type === type);
79
+ }
80
+
81
+ /**
82
+ * Find a GRAPHING_CARD whose content.title contains the given substring (case-insensitive).
83
+ * Used by recovery / strain / trend projections that identify cards by display title.
84
+ */
85
+ export function findCardByTitle(node: unknown, titleSubstr: string): Record<string, unknown> | null {
86
+ const upper = titleSubstr.toUpperCase();
87
+ return findFirst(node, (n) => {
88
+ if (n.type !== "GRAPHING_CARD") return false;
89
+ const content = isObject(n.content) ? (n.content as Record<string, unknown>) : null;
90
+ const title = content && typeof content.title === "string" ? content.title : "";
91
+ return title.toUpperCase().includes(upper);
92
+ });
93
+ }
94
+
95
+ /**
96
+ * Find a DETAILS_GRAPHING_CARD whose content.card_title contains the substring.
97
+ */
98
+ export function findDetailsCardByTitle(node: unknown, titleSubstr: string): Record<string, unknown> | null {
99
+ const upper = titleSubstr.toUpperCase();
100
+ return findFirst(node, (n) => {
101
+ if (n.type !== "DETAILS_GRAPHING_CARD") return false;
102
+ const content = isObject(n.content) ? (n.content as Record<string, unknown>) : null;
103
+ const title = content && typeof content.card_title === "string" ? content.card_title : "";
104
+ return title.toUpperCase().includes(upper);
105
+ });
106
+ }
107
+
108
+ /**
109
+ * Extract today's value from a GRAPHING_CARD. Handles two plot shapes:
110
+ * - segments[].points[last].graph_label.label (line plots)
111
+ * - bar_groups[last].top_label.label (bar plots)
112
+ * Returns the label as a string (often has units like "78%" or "1:41" or "4,880").
113
+ */
114
+ export function latestGraphLabel(card: Record<string, unknown> | null): string | null {
115
+ if (!card) return null;
116
+ const content = isObject(card.content) ? (card.content as Record<string, unknown>) : {};
117
+ const graph = isObject(content.graph) ? (content.graph as Record<string, unknown>) : {};
118
+ const plots = asArray(graph.plots);
119
+ for (const p of plots) {
120
+ if (!isObject(p)) continue;
121
+ const plot = isObject(p.plot) ? (p.plot as Record<string, unknown>) : null;
122
+ if (!plot) continue;
123
+ // Bar plot
124
+ const bars = asArray(plot.bar_groups);
125
+ if (bars.length > 0) {
126
+ const last = bars[bars.length - 1];
127
+ if (isObject(last)) {
128
+ const topLabel = isObject(last.top_label) ? (last.top_label as Record<string, unknown>) : null;
129
+ const label = topLabel && asString(topLabel.label);
130
+ if (label) return label;
131
+ }
132
+ }
133
+ // Line plot
134
+ const segments = asArray(plot.segments);
135
+ for (let i = segments.length - 1; i >= 0; i--) {
136
+ const seg = segments[i];
137
+ if (!isObject(seg)) continue;
138
+ const points = asArray(seg.points);
139
+ for (let j = points.length - 1; j >= 0; j--) {
140
+ const pt = points[j];
141
+ if (!isObject(pt)) continue;
142
+ const graphLabel = isObject(pt.graph_label) ? (pt.graph_label as Record<string, unknown>) : null;
143
+ const label = graphLabel && asString(graphLabel.label);
144
+ if (label) return label;
145
+ }
146
+ }
147
+ }
148
+ return null;
149
+ }
150
+
151
+ /**
152
+ * Extract numeric value from a label like "78%", "42", "14.7", "1,792".
153
+ * Strips trailing % and commas. Returns null for time labels like "1:41".
154
+ */
155
+ export function labelToNumber(label: string | null): number | null {
156
+ if (label === null) return null;
157
+ // Time format like "7:24" or "1:41" — not a number
158
+ if (/^\d+:\d+$/.test(label)) return null;
159
+ const cleaned = label.replace(/,/g, "").replace(/%$/, "");
160
+ const n = Number(cleaned);
161
+ return Number.isFinite(n) ? n : null;
162
+ }
163
+
164
+ /**
165
+ * Convert "H:MM" or "HH:MM" to milliseconds.
166
+ */
167
+ export function timeLabelToMs(label: string | null): number | null {
168
+ if (label === null) return null;
169
+ const m = label.match(/^(\d+):(\d+)$/);
170
+ if (!m) return null;
171
+ const hours = Number(m[1]);
172
+ const minutes = Number(m[2]);
173
+ if (!Number.isFinite(hours) || !Number.isFinite(minutes)) return null;
174
+ return (hours * 3600 + minutes * 60) * 1000;
175
+ }
176
+
177
+ /**
178
+ * Collect all data points from a GRAPHING_CARD as {date, value} pairs.
179
+ * Uses graph_label.label as the value source (fallback to data_scrubber_details.value_display).
180
+ */
181
+ export interface CardPoint {
182
+ date: string | null;
183
+ value: number | null;
184
+ label: string | null;
185
+ }
186
+ export function cardPoints(card: Record<string, unknown> | null): CardPoint[] {
187
+ if (!card) return [];
188
+ const content = isObject(card.content) ? (card.content as Record<string, unknown>) : {};
189
+ const graph = isObject(content.graph) ? (content.graph as Record<string, unknown>) : {};
190
+ const out: CardPoint[] = [];
191
+ for (const p of asArray(graph.plots)) {
192
+ if (!isObject(p)) continue;
193
+ const plot = isObject(p.plot) ? (p.plot as Record<string, unknown>) : null;
194
+ if (!plot) continue;
195
+ for (const seg of asArray(plot.segments)) {
196
+ if (!isObject(seg)) continue;
197
+ for (const pt of asArray(seg.points)) {
198
+ if (!isObject(pt)) continue;
199
+ const label = isObject(pt.graph_label) ? asString((pt.graph_label as Record<string, unknown>).label) : null;
200
+ const dsd = isObject(pt.data_scrubber_details) ? (pt.data_scrubber_details as Record<string, unknown>) : {};
201
+ out.push({
202
+ date: asString(dsd.primary_contextual_display),
203
+ value: labelToNumber(label) ?? asNumber(dsd.value),
204
+ label,
205
+ });
206
+ }
207
+ }
208
+ for (const group of asArray(plot.bar_groups)) {
209
+ if (!isObject(group)) continue;
210
+ const topLabel = isObject(group.top_label) ? asString((group.top_label as Record<string, unknown>).label) : null;
211
+ const dsd = isObject(group.data_scrubber_details) ? (group.data_scrubber_details as Record<string, unknown>) : {};
212
+ out.push({
213
+ date: asString(dsd.primary_contextual_display),
214
+ value: labelToNumber(topLabel),
215
+ label: topLabel,
216
+ });
217
+ }
218
+ }
219
+ return out;
220
+ }
221
+
222
+ // ─── LiftSession + PR + graph extraction (relocated from v1's whoop/parsers.ts) ───
223
+
224
+ export interface LiftSet {
225
+ reps: number;
226
+ weight: number | null;
227
+ units: string | null;
228
+ time_seconds: number | null;
229
+ medal: "GOLD" | "SILVER" | "BRONZE" | null;
230
+ }
231
+
232
+ export interface LiftSession {
233
+ date: string;
234
+ top_set: { reps: number; weight: number | null; units: string | null; medal: "GOLD" | "SILVER" | "BRONZE" | null };
235
+ sets: LiftSet[];
236
+ total_volume: number | null;
237
+ total_volume_units: string | null;
238
+ activity_id: string | null;
239
+ }
240
+
241
+ export interface GraphPoint {
242
+ primary_label: string | null;
243
+ secondary_label: string | null;
244
+ value: number | null;
245
+ value_display: string | null;
246
+ unit: string | null;
247
+ }
248
+
249
+ export interface PrTile {
250
+ exercise_id: string;
251
+ name: string;
252
+ muscle_groups: string[];
253
+ equipment: string;
254
+ pr_value: number | null;
255
+ pr_units: string | null;
256
+ image_url: string | null;
257
+ custom_exercise: boolean;
258
+ }
259
+
260
+ function extractSet(row: unknown): LiftSet | null {
261
+ if (!isObject(row)) return null;
262
+ const items = asArray(row.items);
263
+ if (items.length < 2) return null;
264
+ const repsCell = items[0];
265
+ const weightCell = items[1];
266
+ if (!isObject(repsCell) || !isObject(weightCell)) return null;
267
+ const reps = asNumber(repsCell.value);
268
+ if (reps === null) return null;
269
+ const weightOrTimeUnits = asString(weightCell.units);
270
+ const weightOrTimeValue = asNumber(weightCell.value);
271
+ const isTime = weightOrTimeUnits === "sec" || weightOrTimeUnits === "s";
272
+ return {
273
+ reps,
274
+ weight: isTime ? null : weightOrTimeValue,
275
+ units: isTime ? null : weightOrTimeUnits,
276
+ time_seconds: isTime ? (weightOrTimeValue !== null ? Math.round(weightOrTimeValue) : null) : null,
277
+ medal: asMedal(weightCell.achievement_icon),
278
+ };
279
+ }
280
+
281
+ function extractBreakdownSets(node: unknown): LiftSet[] {
282
+ if (!isObject(node)) return [];
283
+ if (node.type !== "EXERCISE_BREAKDOWN") return [];
284
+ const content = isObject(node.content) ? node.content : {};
285
+ return asArray(content.rows)
286
+ .map(extractSet)
287
+ .filter((s): s is LiftSet => s !== null);
288
+ }
289
+
290
+ export function extractSession(card: unknown): LiftSession | null {
291
+ if (!isObject(card)) return null;
292
+ const content = isObject(card.content) ? card.content : {};
293
+ let headerContent: Record<string, unknown> | null = null;
294
+ if (isObject(content.header_content)) {
295
+ const hc = content.header_content as Record<string, unknown>;
296
+ headerContent = isObject(hc.content) ? (hc.content as Record<string, unknown>) : hc;
297
+ }
298
+ if (!headerContent) return null;
299
+
300
+ const recordDate = asString(headerContent.record_date) ?? "";
301
+ const subtitle = isObject(headerContent.record_subtitle) ? headerContent.record_subtitle : {};
302
+ const title = isObject(headerContent.record_title) ? headerContent.record_title : {};
303
+ const medal = asMedal(headerContent.achievement_icon);
304
+ const reps = asNumber(subtitle.value) ?? 0;
305
+ const weight = asNumber(title.value);
306
+ const units = asString(title.unit);
307
+
308
+ const blocks = asArray(content.expanded_content);
309
+ const breakdowns = blocks.filter((b) => isObject(b) && b.type === "EXERCISE_BREAKDOWN");
310
+ const sets = breakdowns.length > 0 ? extractBreakdownSets(breakdowns[0]) : [];
311
+ let totalVolume: number | null = null;
312
+ let totalVolumeUnits: string | null = null;
313
+ if (breakdowns.length >= 2) {
314
+ const second = breakdowns[1] as Record<string, unknown>;
315
+ const secondContent = isObject(second.content) ? (second.content as Record<string, unknown>) : {};
316
+ const rows = asArray(secondContent.rows);
317
+ const totalRow = rows[0];
318
+ if (isObject(totalRow)) {
319
+ const items = asArray(totalRow.items);
320
+ if (items.length >= 2 && isObject(items[1])) {
321
+ totalVolume = asNumber((items[1] as Record<string, unknown>).value);
322
+ totalVolumeUnits = asString((items[1] as Record<string, unknown>).units);
323
+ }
324
+ }
325
+ }
326
+
327
+ let activityId: string | null = null;
328
+ for (const b of blocks) {
329
+ if (!isObject(b) || b.type !== "CARD_BUTTON") continue;
330
+ const bContent = isObject(b.content) ? (b.content as Record<string, unknown>) : {};
331
+ const dest = isObject(bContent.destination) ? (bContent.destination as Record<string, unknown>) : null;
332
+ const params = dest && isObject(dest.parameters) ? (dest.parameters as Record<string, unknown>) : null;
333
+ if (params && typeof params.activity_id === "string") {
334
+ activityId = params.activity_id;
335
+ break;
336
+ }
337
+ }
338
+
339
+ return {
340
+ date: recordDate,
341
+ top_set: { reps, weight, units, medal },
342
+ sets,
343
+ total_volume: totalVolume,
344
+ total_volume_units: totalVolumeUnits,
345
+ activity_id: activityId,
346
+ };
347
+ }
348
+
349
+ export function extractSessions(response: unknown): LiftSession[] {
350
+ if (!isObject(response)) return [];
351
+ return asArray(response.items)
352
+ .map(extractSession)
353
+ .filter((s): s is LiftSession => s !== null);
354
+ }
355
+
356
+ export function extractPrTiles(response: unknown): PrTile[] {
357
+ if (!isObject(response)) return [];
358
+ return asArray(response.tiles)
359
+ .map((t) => {
360
+ if (!isObject(t)) return null;
361
+ const exerciseId = asString(t.exercise_id);
362
+ const name = asString(t.name);
363
+ if (!exerciseId || !name) return null;
364
+ return {
365
+ exercise_id: exerciseId,
366
+ name,
367
+ muscle_groups: asArray(t.muscle_groups).filter((x): x is string => typeof x === "string"),
368
+ equipment: asString(t.equipment) ?? "",
369
+ pr_value: asNumber(t.volume_input_value),
370
+ pr_units: asString(t.volume_input_units),
371
+ image_url: asString(t.image_url),
372
+ custom_exercise: t.custom_exercise === true,
373
+ };
374
+ })
375
+ .filter((t): t is PrTile => t !== null);
376
+ }
377
+
378
+ export function extractGraphPoints(node: unknown): GraphPoint[] {
379
+ if (!isObject(node)) return [];
380
+ let graph: Record<string, unknown> = node;
381
+ if (isObject(node.graph)) graph = node.graph as Record<string, unknown>;
382
+ const plots = asArray(graph.plots);
383
+ const points: GraphPoint[] = [];
384
+ for (const p of plots) {
385
+ if (!isObject(p)) continue;
386
+ const plot = isObject(p.plot) ? (p.plot as Record<string, unknown>) : null;
387
+ if (!plot) continue;
388
+ for (const seg of asArray(plot.segments)) {
389
+ if (!isObject(seg)) continue;
390
+ for (const pt of asArray(seg.points)) {
391
+ if (!isObject(pt)) continue;
392
+ const dsd = isObject(pt.data_scrubber_details) ? (pt.data_scrubber_details as Record<string, unknown>) : {};
393
+ points.push({
394
+ primary_label: asString(dsd.primary_contextual_display),
395
+ secondary_label: asString(dsd.secondary_contextual_display),
396
+ value: asNumber(dsd.value),
397
+ value_display: asString(dsd.value_display),
398
+ unit: asString(dsd.unit_display),
399
+ });
400
+ }
401
+ }
402
+ for (const group of asArray(plot.bar_groups)) {
403
+ if (!isObject(group)) continue;
404
+ for (const bar of asArray(group.bars)) {
405
+ if (!isObject(bar)) continue;
406
+ const dsd = isObject(bar.data_scrubber_details) ? (bar.data_scrubber_details as Record<string, unknown>) : {};
407
+ points.push({
408
+ primary_label: asString(dsd.primary_contextual_display),
409
+ secondary_label: asString(dsd.secondary_contextual_display),
410
+ value: asNumber(dsd.value),
411
+ value_display: asString(dsd.value_display),
412
+ unit: asString(dsd.unit_display),
413
+ });
414
+ }
415
+ }
416
+ }
417
+ return points;
418
+ }
@@ -0,0 +1,98 @@
1
+ import type { BehaviorImpactOutT, BehaviorImpactListOutT } from "../schemas/journal.js";
2
+ import { isObject, asArray, asNumber, asString, findAll } from "../lib/walk.js";
3
+ import { BEHAVIORS_BY_ID } from "../data/behaviors.js";
4
+
5
+ // /behavior-impact-service/v1/impact returns a tiles[] BFF:
6
+ // tiles[].type "IMPACT_TILE" (enough data) | "INSUFFICIENT_IMPACT_TILE"
7
+ // tiles[].content.impact_cards[]:
8
+ // impact_uuid → the id whoop_behavior_impact(details) needs
9
+ // impact_card_title_display "Daylight Eating"
10
+ // impact_style "POSITIVE" | "NEGATIVE" | "INSUFFICIENT"
11
+ // impact_percentage_display "+7%" (null when insufficient)
12
+ //
13
+ // This is the ONLY place the impact UUIDs are exposed, so the list mode is what
14
+ // makes the detail mode reachable at all.
15
+ export function projectBehaviorImpactList(raw: unknown): BehaviorImpactListOutT {
16
+ const root = isObject(raw) ? raw : {};
17
+ const behaviors: BehaviorImpactListOutT["behaviors"] = [];
18
+ for (const tile of asArray(root.tiles)) {
19
+ if (!isObject(tile)) continue;
20
+ const sufficient = asString(tile.type) === "IMPACT_TILE";
21
+ const content = isObject(tile.content) ? (tile.content as Record<string, unknown>) : {};
22
+ for (const card of asArray(content.impact_cards)) {
23
+ if (!isObject(card)) continue;
24
+ const uuid = asString(card.impact_uuid);
25
+ const name = asString(card.impact_card_title_display);
26
+ if (!uuid || !name) continue;
27
+ const style = (asString(card.impact_style) ?? "").toUpperCase();
28
+ const direction =
29
+ style === "POSITIVE" ? "positive" :
30
+ style === "NEGATIVE" ? "negative" :
31
+ style === "INSUFFICIENT" ? "insufficient" : "neutral";
32
+ behaviors.push({
33
+ impact_uuid: uuid,
34
+ behavior_name: name,
35
+ direction,
36
+ impact_display: asString(card.impact_percentage_display),
37
+ has_sufficient_data: sufficient,
38
+ });
39
+ }
40
+ }
41
+ return { behaviors };
42
+ }
43
+
44
+ // /behavior-impact-service/v2/impact/details/{id} returns a BFF, not flat metrics:
45
+ // header.details_title_display → behavior name ("Daylight Eating")
46
+ // header.details_subtitle_display → insight text (may be "")
47
+ // header.details_impact_style → overall style ("POSITIVE"/"INSUFFICIENT"/…)
48
+ // sections[].items[].content.impact_card (and footer tiles) each:
49
+ // title_display "RECOVERY IMPACT"
50
+ // impact_style "POSITIVE" | "NEGATIVE" | "NEUTRAL"
51
+ // impact_percentage_value "+7"
52
+ // impact_percentage_symbol "%"
53
+ // sub_bar_percent "+3%" (whoop member average — not the user delta)
54
+ //
55
+ // The older projection read `sections[].type === METRIC_CARD`, which never
56
+ // matched, so every response came back with empty metrics.
57
+
58
+ function directionFromStyle(style: string | null): "positive" | "negative" | "neutral" {
59
+ const s = (style ?? "").toUpperCase();
60
+ if (s === "POSITIVE") return "positive";
61
+ if (s === "NEGATIVE") return "negative";
62
+ return "neutral";
63
+ }
64
+
65
+ export function projectBehaviorImpact(raw: unknown, behaviorId: number | string): BehaviorImpactOutT {
66
+ const root = isObject(raw) ? raw : {};
67
+ const header = isObject(root.header) ? (root.header as Record<string, unknown>) : {};
68
+
69
+ // Every impact card anywhere in the tree carries `impact_percentage_value`;
70
+ // collect them all (one per affected metric) and dedupe by metric name.
71
+ const cards = findAll(root, (n) => typeof n.impact_percentage_value === "string" && typeof n.title_display === "string");
72
+ const seen = new Set<string>();
73
+ const metrics: BehaviorImpactOutT["metrics"] = [];
74
+ for (const card of cards) {
75
+ const metricName = asString(card.title_display) ?? "";
76
+ if (seen.has(metricName)) continue;
77
+ seen.add(metricName);
78
+ metrics.push({
79
+ metric: metricName,
80
+ delta_avg: asNumber((asString(card.impact_percentage_value) ?? "").replace("+", "")),
81
+ delta_unit: asString(card.impact_percentage_symbol),
82
+ sample_size: null, // not exposed by this BFF
83
+ direction: directionFromStyle(asString(card.impact_style)),
84
+ });
85
+ }
86
+
87
+ const numericId = typeof behaviorId === "number" ? behaviorId : Number(behaviorId);
88
+ const meta = !isNaN(numericId) ? BEHAVIORS_BY_ID.get(numericId) : undefined;
89
+ const headerName = asString(header.details_title_display);
90
+ const subtitle = asString(header.details_subtitle_display);
91
+
92
+ return {
93
+ behavior_id: behaviorId,
94
+ behavior_name: headerName ?? meta?.title ?? null,
95
+ metrics,
96
+ insight: subtitle && subtitle.length > 0 ? subtitle : asString(header.details_tag_label_display),
97
+ };
98
+ }
@@ -0,0 +1,46 @@
1
+ import type { CalendarOutT } from "../schemas/calendar.js";
2
+ import { isObject, asArray, asString } from "../lib/walk.js";
3
+
4
+ // /home-service/v1/calendar/overview (and /recovery) return the month grid:
5
+ // { calendar_title_display: "MAY", days_of_month: [
6
+ // { date_value_display: "1", has_data: true, cycle_id, day_state: "MEDIUM_RECOVERY" }, ... ] }
7
+ // The grid only exposes the recovery STATE per day (LOW/MEDIUM/HIGH_RECOVERY),
8
+ // not numeric recovery/sleep/strain scores — those aren't in this payload, so
9
+ // they stay null. (Numeric per-day scores would require 30 deep-dive calls.)
10
+
11
+ interface ProjectCalendarInput {
12
+ overview: unknown;
13
+ recovery: unknown;
14
+ date: string;
15
+ }
16
+
17
+ const STATE: Record<string, "GREEN" | "YELLOW" | "RED"> = {
18
+ HIGH_RECOVERY: "GREEN",
19
+ MEDIUM_RECOVERY: "YELLOW",
20
+ LOW_RECOVERY: "RED",
21
+ };
22
+
23
+ export function projectCalendar(input: ProjectCalendarInput): CalendarOutT {
24
+ const month = input.date.slice(0, 7); // "2026-05"
25
+ // overview + recovery carry the same day_state grid; prefer recovery, fall back to overview.
26
+ const recovery = isObject(input.recovery) ? input.recovery : {};
27
+ const overview = isObject(input.overview) ? input.overview : {};
28
+ const grid = asArray(recovery.days_of_month).length ? asArray(recovery.days_of_month) : asArray(overview.days_of_month);
29
+
30
+ const days: CalendarOutT["days"] = [];
31
+ for (const d of grid) {
32
+ if (!isObject(d)) continue;
33
+ if (d.has_data === false) continue;
34
+ const dayNum = asString(d.date_value_display);
35
+ if (!dayNum) continue;
36
+ const state = asString(d.day_state);
37
+ days.push({
38
+ date: `${month}-${dayNum.padStart(2, "0")}`,
39
+ recovery_score: null,
40
+ recovery_state: state ? (STATE[state] ?? null) : null,
41
+ sleep_score: null,
42
+ day_strain: null,
43
+ });
44
+ }
45
+ return { month, days };
46
+ }