@thebriangao/totem 1.4.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dev.vars.example +5 -0
- package/.dockerignore +5 -0
- package/.env.example +29 -20
- package/CHANGELOG.md +99 -1
- package/CONTRIBUTING.md +48 -116
- package/Dockerfile +46 -12
- package/README.md +172 -498
- package/SECURITY.md +36 -59
- package/TOOLS.md +448 -311
- package/WHOOP.md +497 -2659
- package/assets/brand/SOURCES.md +38 -0
- package/assets/brand/totem.png +0 -0
- package/assets/brand/totem.svg +13 -0
- package/assets/fonts/Manrope-OFL.txt +93 -0
- package/assets/fonts/manrope-latin.woff2 +0 -0
- package/dist/build_info.js +5 -0
- package/dist/build_info.js.map +1 -0
- package/dist/cli/app.js +675 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/auth.js +297 -0
- package/dist/cli/auth.js.map +1 -0
- package/dist/cli/auth_flow.js +268 -0
- package/dist/cli/auth_flow.js.map +1 -0
- package/dist/cli/browser_login.js +368 -0
- package/dist/cli/browser_login.js.map +1 -0
- package/dist/cli/clients.js +403 -0
- package/dist/cli/clients.js.map +1 -0
- package/dist/cli/deploy_record.js +96 -0
- package/dist/cli/deploy_record.js.map +1 -0
- package/dist/cli/index.js +39 -575
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/links.js +28 -0
- package/dist/cli/links.js.map +1 -0
- package/dist/cli/logo.js +63 -0
- package/dist/cli/logo.js.map +1 -0
- package/dist/cli/setup.js +1157 -1017
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/spawn.js +80 -0
- package/dist/cli/spawn.js.map +1 -0
- package/dist/cli/sys.js +219 -0
- package/dist/cli/sys.js.map +1 -0
- package/dist/cli/ui.js +712 -463
- package/dist/cli/ui.js.map +1 -1
- package/dist/cli/update.js +425 -282
- package/dist/cli/update.js.map +1 -1
- package/dist/cloudflare/token_store.js +48 -0
- package/dist/cloudflare/token_store.js.map +1 -0
- package/dist/cloudflare/worker.js +155 -0
- package/dist/cloudflare/worker.js.map +1 -0
- package/dist/data/behaviors.js +2733 -617
- package/dist/data/behaviors.js.map +1 -1
- package/dist/data/endpoint_catalog.js +2681 -0
- package/dist/data/endpoint_catalog.js.map +1 -0
- package/dist/data/exercises.js +373 -4859
- package/dist/data/exercises.js.map +1 -1
- package/dist/data/garments.js +19 -0
- package/dist/data/garments.js.map +1 -0
- package/dist/data/sports.js +219 -208
- package/dist/data/sports.js.map +1 -1
- package/dist/lib/activity_list.js +123 -0
- package/dist/lib/activity_list.js.map +1 -0
- package/dist/lib/activity_records.js +195 -0
- package/dist/lib/activity_records.js.map +1 -0
- package/dist/lib/activity_results.js +44 -0
- package/dist/lib/activity_results.js.map +1 -0
- package/dist/lib/activity_types.js +164 -0
- package/dist/lib/activity_types.js.map +1 -0
- package/dist/lib/brand.js +63 -0
- package/dist/lib/brand.js.map +1 -0
- package/dist/lib/clock.js +24 -0
- package/dist/lib/clock.js.map +1 -0
- package/dist/lib/coach_session.js +345 -0
- package/dist/lib/coach_session.js.map +1 -0
- package/dist/lib/concurrency.js.map +1 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/env_file.js +195 -0
- package/dist/lib/env_file.js.map +1 -0
- package/dist/lib/health_plans_write.js +44 -0
- package/dist/lib/health_plans_write.js.map +1 -0
- package/dist/lib/heart_rate.js +34 -0
- package/dist/lib/heart_rate.js.map +1 -0
- package/dist/lib/highlight.js +81 -0
- package/dist/lib/highlight.js.map +1 -0
- package/dist/lib/install_links.js +47 -0
- package/dist/lib/install_links.js.map +1 -0
- package/dist/lib/instant.js +50 -0
- package/dist/lib/instant.js.map +1 -0
- package/dist/lib/journal_behaviors.js +382 -0
- package/dist/lib/journal_behaviors.js.map +1 -0
- package/dist/lib/lift_catalog.js +218 -0
- package/dist/lib/lift_catalog.js.map +1 -0
- package/dist/lib/lift_history.js +66 -0
- package/dist/lib/lift_history.js.map +1 -0
- package/dist/lib/lift_sets.js +146 -0
- package/dist/lib/lift_sets.js.map +1 -0
- package/dist/lib/lift_tool.js +20 -0
- package/dist/lib/lift_tool.js.map +1 -0
- package/dist/lib/profile_settings.js +101 -0
- package/dist/lib/profile_settings.js.map +1 -0
- package/dist/lib/screen_content.js +44 -0
- package/dist/lib/screen_content.js.map +1 -0
- package/dist/lib/timezone.js +48 -6
- package/dist/lib/timezone.js.map +1 -1
- package/dist/lib/walk.js +6 -1
- package/dist/lib/walk.js.map +1 -1
- package/dist/lib/weight_readings.js +61 -0
- package/dist/lib/weight_readings.js.map +1 -0
- package/dist/projections/activities.js +193 -0
- package/dist/projections/activities.js.map +1 -0
- package/dist/projections/alarm_schedule.js +102 -0
- package/dist/projections/alarm_schedule.js.map +1 -0
- package/dist/projections/coach.js +203 -0
- package/dist/projections/coach.js.map +1 -0
- package/dist/projections/community.js +165 -0
- package/dist/projections/community.js.map +1 -0
- package/dist/projections/health_features.js +167 -0
- package/dist/projections/health_features.js.map +1 -0
- package/dist/projections/hormonal_insights.js +239 -0
- package/dist/projections/hormonal_insights.js.map +1 -0
- package/dist/projections/journal_v2.js +157 -0
- package/dist/projections/journal_v2.js.map +1 -0
- package/dist/projections/lift_cards.js +115 -0
- package/dist/projections/lift_cards.js.map +1 -0
- package/dist/projections/lift_exercise_v2.js +131 -0
- package/dist/projections/lift_exercise_v2.js.map +1 -0
- package/dist/projections/lift_library_v2.js +67 -0
- package/dist/projections/lift_library_v2.js.map +1 -0
- package/dist/projections/lift_sessions.js +211 -0
- package/dist/projections/lift_sessions.js.map +1 -0
- package/dist/projections/memory.js +95 -0
- package/dist/projections/memory.js.map +1 -0
- package/dist/projections/milestones.js +119 -0
- package/dist/projections/milestones.js.map +1 -0
- package/dist/projections/profile_v2.js +150 -0
- package/dist/projections/profile_v2.js.map +1 -0
- package/dist/projections/settings_v2.js +153 -0
- package/dist/projections/settings_v2.js.map +1 -0
- package/dist/projections/sleep.js +4 -21
- package/dist/projections/sleep.js.map +1 -1
- package/dist/projections/v2/calendar.js +43 -0
- package/dist/projections/v2/calendar.js.map +1 -0
- package/dist/projections/v2/core_common.js +86 -0
- package/dist/projections/v2/core_common.js.map +1 -0
- package/dist/projections/v2/core_home.js +136 -0
- package/dist/projections/v2/core_home.js.map +1 -0
- package/dist/projections/v2/core_sleep_need.js +23 -0
- package/dist/projections/v2/core_sleep_need.js.map +1 -0
- package/dist/projections/v2/day.js +92 -0
- package/dist/projections/v2/day.js.map +1 -0
- package/dist/projections/v2/heart_rate.js +54 -0
- package/dist/projections/v2/heart_rate.js.map +1 -0
- package/dist/projections/v2/history.js +140 -0
- package/dist/projections/v2/history.js.map +1 -0
- package/dist/projections/v2/now.js +39 -0
- package/dist/projections/v2/now.js.map +1 -0
- package/dist/projections/v2/recovery.js +77 -0
- package/dist/projections/v2/recovery.js.map +1 -0
- package/dist/projections/v2/sleep.js +218 -0
- package/dist/projections/v2/sleep.js.map +1 -0
- package/dist/projections/v2/strain.js +39 -0
- package/dist/projections/v2/strain.js.map +1 -0
- package/dist/projections/v2/stress.js +92 -0
- package/dist/projections/v2/stress.js.map +1 -0
- package/dist/projections/v2/trend.js +205 -0
- package/dist/projections/v2/trend.js.map +1 -0
- package/dist/projections/weekly_plan.js +66 -0
- package/dist/projections/weekly_plan.js.map +1 -0
- package/dist/projections/weight_readings.js +57 -0
- package/dist/projections/weight_readings.js.map +1 -0
- package/dist/projections/workout.js +37 -15
- package/dist/projections/workout.js.map +1 -1
- package/dist/schemas/activities.js +123 -0
- package/dist/schemas/activities.js.map +1 -0
- package/dist/schemas/alarm_schedule.js +62 -0
- package/dist/schemas/alarm_schedule.js.map +1 -0
- package/dist/schemas/coach.js +76 -8
- package/dist/schemas/coach.js.map +1 -1
- package/dist/schemas/community.js +70 -0
- package/dist/schemas/community.js.map +1 -0
- package/dist/schemas/health.js +36 -0
- package/dist/schemas/health.js.map +1 -0
- package/dist/schemas/hormonal_insights.js +90 -0
- package/dist/schemas/hormonal_insights.js.map +1 -0
- package/dist/schemas/journal.js +4 -0
- package/dist/schemas/journal.js.map +1 -1
- package/dist/schemas/journal_v2.js +106 -0
- package/dist/schemas/journal_v2.js.map +1 -0
- package/dist/schemas/memory.js +42 -0
- package/dist/schemas/memory.js.map +1 -0
- package/dist/schemas/milestones.js +39 -0
- package/dist/schemas/milestones.js.map +1 -0
- package/dist/schemas/profile_v2.js +60 -0
- package/dist/schemas/profile_v2.js.map +1 -0
- package/dist/schemas/settings_v2.js +56 -0
- package/dist/schemas/settings_v2.js.map +1 -0
- package/dist/schemas/sleep.js +8 -1
- package/dist/schemas/sleep.js.map +1 -1
- package/dist/schemas/strength.js +10 -1
- package/dist/schemas/strength.js.map +1 -1
- package/dist/schemas/strength_v2.js +190 -0
- package/dist/schemas/strength_v2.js.map +1 -0
- package/dist/schemas/v2/calendar.js +8 -0
- package/dist/schemas/v2/calendar.js.map +1 -0
- package/dist/schemas/v2/core_common.js +42 -0
- package/dist/schemas/v2/core_common.js.map +1 -0
- package/dist/schemas/v2/day.js +73 -0
- package/dist/schemas/v2/day.js.map +1 -0
- package/dist/schemas/v2/now.js +25 -0
- package/dist/schemas/v2/now.js.map +1 -0
- package/dist/schemas/v2/recovery.js +35 -0
- package/dist/schemas/v2/recovery.js.map +1 -0
- package/dist/schemas/v2/sleep.js +44 -0
- package/dist/schemas/v2/sleep.js.map +1 -0
- package/dist/schemas/v2/strain.js +16 -0
- package/dist/schemas/v2/strain.js.map +1 -0
- package/dist/schemas/v2/stress.js +20 -0
- package/dist/schemas/v2/stress.js.map +1 -0
- package/dist/schemas/v2/trend.js +42 -0
- package/dist/schemas/v2/trend.js.map +1 -0
- package/dist/schemas/weekly_plan.js +31 -0
- package/dist/schemas/weekly_plan.js.map +1 -0
- package/dist/schemas/weight.js +28 -0
- package/dist/schemas/weight.js.map +1 -0
- package/dist/scripts/build_behaviors.js +114 -0
- package/dist/scripts/build_behaviors.js.map +1 -0
- package/dist/scripts/cognito_bootstrap.js +9 -277
- package/dist/scripts/cognito_bootstrap.js.map +1 -1
- package/dist/scripts/gen_activity_catalogs.js +104 -0
- package/dist/scripts/gen_activity_catalogs.js.map +1 -0
- package/dist/server-admin.js +156 -0
- package/dist/server-admin.js.map +1 -0
- package/dist/server-http.js +270 -48
- package/dist/server-http.js.map +1 -1
- package/dist/server.js +136 -23
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.js +15 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/define.js +31 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/register.js +59 -94
- package/dist/tools/register.js.map +1 -1
- package/dist/tools/resources.js +70 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/slim_schema.js +90 -0
- package/dist/tools/slim_schema.js.map +1 -0
- package/dist/tools/v2/activity_delete.js +63 -17
- package/dist/tools/v2/activity_delete.js.map +1 -1
- package/dist/tools/v2/activity_edit.js +396 -0
- package/dist/tools/v2/activity_edit.js.map +1 -0
- package/dist/tools/v2/activity_log.js +152 -0
- package/dist/tools/v2/activity_log.js.map +1 -0
- package/dist/tools/v2/calendar.js +19 -21
- package/dist/tools/v2/calendar.js.map +1 -1
- package/dist/tools/v2/coach_ask.js +74 -110
- package/dist/tools/v2/coach_ask.js.map +1 -1
- package/dist/tools/v2/coach_history.js +120 -0
- package/dist/tools/v2/coach_history.js.map +1 -0
- package/dist/tools/v2/community.js +124 -0
- package/dist/tools/v2/community.js.map +1 -0
- package/dist/tools/v2/cycle.js +63 -15
- package/dist/tools/v2/cycle.js.map +1 -1
- package/dist/tools/v2/cycle_log.js +289 -32
- package/dist/tools/v2/cycle_log.js.map +1 -1
- package/dist/tools/v2/day.js +126 -24
- package/dist/tools/v2/day.js.map +1 -1
- package/dist/tools/v2/health.js +116 -0
- package/dist/tools/v2/health.js.map +1 -0
- package/dist/tools/v2/hr_zones_set.js +134 -34
- package/dist/tools/v2/hr_zones_set.js.map +1 -1
- package/dist/tools/v2/journal.js +75 -17
- package/dist/tools/v2/journal.js.map +1 -1
- package/dist/tools/v2/journal_log.js +306 -65
- package/dist/tools/v2/journal_log.js.map +1 -1
- package/dist/tools/v2/lift_exercise.js +125 -22
- package/dist/tools/v2/lift_exercise.js.map +1 -1
- package/dist/tools/v2/lift_exercise_set.js +291 -0
- package/dist/tools/v2/lift_exercise_set.js.map +1 -0
- package/dist/tools/v2/lift_library.js +51 -12
- package/dist/tools/v2/lift_library.js.map +1 -1
- package/dist/tools/v2/lift_log.js +309 -72
- package/dist/tools/v2/lift_log.js.map +1 -1
- package/dist/tools/v2/lift_sessions.js +248 -0
- package/dist/tools/v2/lift_sessions.js.map +1 -0
- package/dist/tools/v2/lift_template.js +232 -0
- package/dist/tools/v2/lift_template.js.map +1 -0
- package/dist/tools/v2/memory.js +45 -0
- package/dist/tools/v2/memory.js.map +1 -0
- package/dist/tools/v2/memory_set.js +107 -0
- package/dist/tools/v2/memory_set.js.map +1 -0
- package/dist/tools/v2/milestones.js +50 -0
- package/dist/tools/v2/milestones.js.map +1 -0
- package/dist/tools/v2/now.js +49 -0
- package/dist/tools/v2/now.js.map +1 -0
- package/dist/tools/v2/preferences.js +51 -0
- package/dist/tools/v2/preferences.js.map +1 -0
- package/dist/tools/v2/preferences_set.js +388 -0
- package/dist/tools/v2/preferences_set.js.map +1 -0
- package/dist/tools/v2/profile.js +54 -22
- package/dist/tools/v2/profile.js.map +1 -1
- package/dist/tools/v2/profile_update.js +167 -55
- package/dist/tools/v2/profile_update.js.map +1 -1
- package/dist/tools/v2/raw.js +91 -34
- package/dist/tools/v2/raw.js.map +1 -1
- package/dist/tools/v2/recovery.js +37 -23
- package/dist/tools/v2/recovery.js.map +1 -1
- package/dist/tools/v2/sleep.js +52 -16
- package/dist/tools/v2/sleep.js.map +1 -1
- package/dist/tools/v2/smart_alarm.js +54 -20
- package/dist/tools/v2/smart_alarm.js.map +1 -1
- package/dist/tools/v2/smart_alarm_set.js +264 -86
- package/dist/tools/v2/smart_alarm_set.js.map +1 -1
- package/dist/tools/v2/strain.js +15 -15
- package/dist/tools/v2/strain.js.map +1 -1
- package/dist/tools/v2/stress.js +17 -15
- package/dist/tools/v2/stress.js.map +1 -1
- package/dist/tools/v2/trend.js +56 -20
- package/dist/tools/v2/trend.js.map +1 -1
- package/dist/tools/v2/weekly_plan.js +30 -0
- package/dist/tools/v2/weekly_plan.js.map +1 -0
- package/dist/tools/v2/weekly_plan_set.js +134 -0
- package/dist/tools/v2/weekly_plan_set.js.map +1 -0
- package/dist/tools/v2/weight.js +56 -0
- package/dist/tools/v2/weight.js.map +1 -0
- package/dist/tools/v2/weight_log.js +188 -0
- package/dist/tools/v2/weight_log.js.map +1 -0
- package/dist/tools/v2/workouts.js +159 -25
- package/dist/tools/v2/workouts.js.map +1 -1
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/whoop/bff.js +94 -0
- package/dist/whoop/bff.js.map +1 -0
- package/dist/whoop/client.js +392 -18
- package/dist/whoop/client.js.map +1 -1
- package/dist/whoop/cognito.js +106 -79
- package/dist/whoop/cognito.js.map +1 -1
- package/dist/whoop/connect_page.js +165 -0
- package/dist/whoop/connect_page.js.map +1 -0
- package/dist/whoop/consent_font.js +287 -0
- package/dist/whoop/consent_font.js.map +1 -0
- package/dist/whoop/consent_logos.js +22 -0
- package/dist/whoop/consent_logos.js.map +1 -0
- package/dist/whoop/consent_page.js +291 -0
- package/dist/whoop/consent_page.js.map +1 -0
- package/dist/whoop/constants.js +5 -1
- package/dist/whoop/constants.js.map +1 -1
- package/dist/whoop/device.js +4 -4
- package/dist/whoop/device.js.map +1 -1
- package/dist/whoop/errors.js +85 -4
- package/dist/whoop/errors.js.map +1 -1
- package/dist/whoop/init_timezone.js +57 -17
- package/dist/whoop/init_timezone.js.map +1 -1
- package/dist/whoop/installation.js +15 -10
- package/dist/whoop/installation.js.map +1 -1
- package/dist/whoop/json_out.js +52 -6
- package/dist/whoop/json_out.js.map +1 -1
- package/dist/whoop/oauth_provider.js +81 -78
- package/dist/whoop/oauth_provider.js.map +1 -1
- package/dist/whoop/token_lock.js +331 -0
- package/dist/whoop/token_lock.js.map +1 -0
- package/dist/whoop/token_manager.js +536 -42
- package/dist/whoop/token_manager.js.map +1 -1
- package/dist/whoop/token_store.js +303 -36
- package/dist/whoop/token_store.js.map +1 -1
- package/dist/whoop/units.js +28 -0
- package/dist/whoop/units.js.map +1 -0
- package/package.json +29 -13
- package/scripts/build-mcpb.mjs +72 -0
- package/scripts/embed-consent-font.mjs +34 -0
- package/scripts/readme-media.ts +195 -0
- package/scripts/tools-md.ts +89 -0
- package/scripts/whoop-md.ts +119 -0
- package/src/build_info.ts +4 -0
- package/src/cli/app.ts +696 -0
- package/src/cli/auth.ts +350 -0
- package/src/cli/auth_flow.ts +356 -0
- package/src/cli/browser_login.ts +402 -0
- package/src/cli/clients.ts +467 -0
- package/src/cli/deploy_record.ts +100 -0
- package/src/cli/index.ts +41 -583
- package/src/cli/links.ts +43 -0
- package/src/cli/logo.ts +64 -0
- package/src/cli/setup.ts +1147 -979
- package/src/cli/spawn.ts +88 -0
- package/src/cli/sys.ts +267 -0
- package/src/cli/ui.ts +778 -436
- package/src/cli/update.ts +436 -274
- package/src/cloudflare/runtime.d.ts +27 -0
- package/src/cloudflare/token_store.ts +57 -0
- package/src/cloudflare/worker.ts +174 -0
- package/src/data/behaviors.ts +2760 -622
- package/src/data/endpoint_catalog.ts +2695 -0
- package/src/data/exercises.ts +379 -4861
- package/src/data/garments.ts +28 -0
- package/src/data/sports.ts +239 -211
- package/src/lib/activity_list.ts +150 -0
- package/src/lib/activity_records.ts +213 -0
- package/src/lib/activity_results.ts +51 -0
- package/src/lib/activity_types.ts +176 -0
- package/src/lib/brand.ts +71 -0
- package/src/lib/clock.ts +16 -0
- package/src/lib/coach_session.ts +434 -0
- package/src/lib/dates.ts +18 -0
- package/src/lib/env_file.ts +191 -0
- package/src/lib/health_plans_write.ts +53 -0
- package/src/lib/heart_rate.ts +42 -0
- package/src/lib/highlight.ts +71 -0
- package/src/lib/install_links.ts +61 -0
- package/src/lib/instant.ts +54 -0
- package/src/lib/journal_behaviors.ts +453 -0
- package/src/lib/lift_catalog.ts +258 -0
- package/src/lib/lift_history.ts +75 -0
- package/src/lib/lift_sets.ts +164 -0
- package/src/lib/lift_tool.ts +25 -0
- package/src/lib/profile_settings.ts +102 -0
- package/src/lib/screen_content.ts +40 -0
- package/src/lib/timezone.ts +44 -8
- package/src/lib/walk.ts +4 -1
- package/src/lib/weight_readings.ts +82 -0
- package/src/projections/activities.ts +199 -0
- package/src/projections/alarm_schedule.ts +98 -0
- package/src/projections/coach.ts +218 -0
- package/src/projections/community.ts +187 -0
- package/src/projections/health_features.ts +191 -0
- package/src/projections/hormonal_insights.ts +277 -0
- package/src/projections/journal_v2.ts +173 -0
- package/src/projections/lift_cards.ts +131 -0
- package/src/projections/lift_exercise_v2.ts +147 -0
- package/src/projections/lift_library_v2.ts +77 -0
- package/src/projections/lift_sessions.ts +250 -0
- package/src/projections/memory.ts +100 -0
- package/src/projections/milestones.ts +133 -0
- package/src/projections/profile_v2.ts +166 -0
- package/src/projections/settings_v2.ts +179 -0
- package/src/projections/sleep.ts +7 -21
- package/src/projections/v2/calendar.ts +48 -0
- package/src/projections/v2/core_common.ts +95 -0
- package/src/projections/v2/core_home.ts +177 -0
- package/src/projections/v2/core_sleep_need.ts +37 -0
- package/src/projections/v2/day.ts +162 -0
- package/src/projections/v2/heart_rate.ts +73 -0
- package/src/projections/v2/history.ts +153 -0
- package/src/projections/v2/now.ts +59 -0
- package/src/projections/v2/recovery.ts +120 -0
- package/src/projections/v2/sleep.ts +281 -0
- package/src/projections/v2/strain.ts +63 -0
- package/src/projections/v2/stress.ts +111 -0
- package/src/projections/v2/trend.ts +242 -0
- package/src/projections/weekly_plan.ts +79 -0
- package/src/projections/weight_readings.ts +57 -0
- package/src/projections/workout.ts +36 -17
- package/src/schemas/activities.ts +136 -0
- package/src/schemas/alarm_schedule.ts +70 -0
- package/src/schemas/coach.ts +98 -8
- package/src/schemas/community.ts +77 -0
- package/src/schemas/health.ts +36 -0
- package/src/schemas/hormonal_insights.ts +108 -0
- package/src/schemas/journal.ts +4 -0
- package/src/schemas/journal_v2.ts +112 -0
- package/src/schemas/memory.ts +48 -0
- package/src/schemas/milestones.ts +48 -0
- package/src/schemas/profile_v2.ts +63 -0
- package/src/schemas/settings_v2.ts +63 -0
- package/src/schemas/sleep.ts +9 -1
- package/src/schemas/strength.ts +10 -1
- package/src/schemas/strength_v2.ts +210 -0
- package/src/schemas/v2/calendar.ts +8 -0
- package/src/schemas/v2/core_common.ts +50 -0
- package/src/schemas/v2/day.ts +79 -0
- package/src/schemas/v2/now.ts +25 -0
- package/src/schemas/v2/recovery.ts +38 -0
- package/src/schemas/v2/sleep.ts +46 -0
- package/src/schemas/v2/strain.ts +16 -0
- package/src/schemas/v2/stress.ts +20 -0
- package/src/schemas/v2/trend.ts +45 -0
- package/src/schemas/weekly_plan.ts +36 -0
- package/src/schemas/weight.ts +53 -0
- package/src/scripts/build_behaviors.ts +116 -0
- package/src/scripts/cognito_bootstrap.ts +10 -249
- package/src/scripts/gen_activity_catalogs.ts +121 -0
- package/src/server-admin.ts +171 -0
- package/src/server-http.ts +290 -53
- package/src/server.ts +130 -26
- package/src/tools/annotations.ts +25 -0
- package/src/tools/define.ts +53 -0
- package/src/tools/register.ts +64 -94
- package/src/tools/resources.ts +92 -0
- package/src/tools/slim_schema.ts +102 -0
- package/src/tools/v2/activity_delete.ts +61 -23
- package/src/tools/v2/activity_edit.ts +378 -0
- package/src/tools/v2/activity_log.ts +154 -0
- package/src/tools/v2/calendar.ts +22 -21
- package/src/tools/v2/coach_ask.ts +83 -119
- package/src/tools/v2/coach_history.ts +140 -0
- package/src/tools/v2/community.ts +137 -0
- package/src/tools/v2/cycle.ts +78 -20
- package/src/tools/v2/cycle_log.ts +291 -40
- package/src/tools/v2/day.ts +126 -25
- package/src/tools/v2/health.ts +114 -0
- package/src/tools/v2/hr_zones_set.ts +132 -45
- package/src/tools/v2/journal.ts +78 -23
- package/src/tools/v2/journal_log.ts +321 -69
- package/src/tools/v2/lift_exercise.ts +135 -27
- package/src/tools/v2/lift_exercise_set.ts +272 -0
- package/src/tools/v2/lift_library.ts +57 -21
- package/src/tools/v2/lift_log.ts +325 -83
- package/src/tools/v2/lift_sessions.ts +255 -0
- package/src/tools/v2/lift_template.ts +229 -0
- package/src/tools/v2/memory.ts +54 -0
- package/src/tools/v2/memory_set.ts +110 -0
- package/src/tools/v2/milestones.ts +59 -0
- package/src/tools/v2/now.ts +61 -0
- package/src/tools/v2/preferences.ts +61 -0
- package/src/tools/v2/preferences_set.ts +403 -0
- package/src/tools/v2/profile.ts +56 -26
- package/src/tools/v2/profile_update.ts +151 -60
- package/src/tools/v2/raw.ts +89 -36
- package/src/tools/v2/recovery.ts +44 -25
- package/src/tools/v2/sleep.ts +57 -18
- package/src/tools/v2/smart_alarm.ts +62 -24
- package/src/tools/v2/smart_alarm_set.ts +240 -90
- package/src/tools/v2/strain.ts +19 -16
- package/src/tools/v2/stress.ts +22 -17
- package/src/tools/v2/trend.ts +58 -20
- package/src/tools/v2/weekly_plan.ts +38 -0
- package/src/tools/v2/weekly_plan_set.ts +132 -0
- package/src/tools/v2/weight.ts +61 -0
- package/src/tools/v2/weight_log.ts +193 -0
- package/src/tools/v2/workouts.ts +156 -26
- package/src/version.ts +5 -0
- package/src/whoop/bff.ts +84 -0
- package/src/whoop/client.ts +448 -18
- package/src/whoop/cognito.ts +110 -99
- package/src/whoop/connect_page.ts +183 -0
- package/src/whoop/consent_font.ts +289 -0
- package/src/whoop/consent_logos.ts +24 -0
- package/src/whoop/consent_page.ts +326 -0
- package/src/whoop/constants.ts +5 -1
- package/src/whoop/device.ts +4 -4
- package/src/whoop/errors.ts +89 -4
- package/src/whoop/init_timezone.ts +57 -16
- package/src/whoop/installation.ts +16 -7
- package/src/whoop/json_out.ts +51 -6
- package/src/whoop/oauth_provider.ts +84 -91
- package/src/whoop/token_lock.ts +345 -0
- package/src/whoop/token_manager.ts +580 -53
- package/src/whoop/token_store.ts +341 -32
- package/src/whoop/units.ts +35 -0
- package/wrangler.jsonc +17 -0
- package/assets/banner.svg +0 -38
- package/dist/data/endpoints.js +0 -320
- package/dist/data/endpoints.js.map +0 -1
- package/dist/lib/format.js +0 -22
- package/dist/lib/format.js.map +0 -1
- package/dist/lib/stats.js +0 -32
- package/dist/lib/stats.js.map +0 -1
- package/dist/projections/calendar.js +0 -33
- package/dist/projections/calendar.js.map +0 -1
- package/dist/projections/communities.js +0 -105
- package/dist/projections/communities.js.map +0 -1
- package/dist/projections/cycle.js +0 -81
- package/dist/projections/cycle.js.map +0 -1
- package/dist/projections/hr_zones.js +0 -35
- package/dist/projections/hr_zones.js.map +0 -1
- package/dist/projections/journal.js +0 -56
- package/dist/projections/journal.js.map +0 -1
- package/dist/projections/leaderboard.js +0 -37
- package/dist/projections/leaderboard.js.map +0 -1
- package/dist/projections/lift_exercise.js +0 -22
- package/dist/projections/lift_exercise.js.map +0 -1
- package/dist/projections/lift_history.js +0 -133
- package/dist/projections/lift_history.js.map +0 -1
- package/dist/projections/lift_library.js +0 -71
- package/dist/projections/lift_library.js.map +0 -1
- package/dist/projections/lift_progression.js +0 -138
- package/dist/projections/lift_progression.js.map +0 -1
- package/dist/projections/lift_prs.js +0 -20
- package/dist/projections/lift_prs.js.map +0 -1
- package/dist/projections/live_hr.js +0 -19
- package/dist/projections/live_hr.js.map +0 -1
- package/dist/projections/live_state.js +0 -23
- package/dist/projections/live_state.js.map +0 -1
- package/dist/projections/live_stress.js +0 -11
- package/dist/projections/live_stress.js.map +0 -1
- package/dist/projections/performance_assessment.js +0 -15
- package/dist/projections/performance_assessment.js.map +0 -1
- package/dist/projections/profile.js +0 -59
- package/dist/projections/profile.js.map +0 -1
- package/dist/projections/recovery.js +0 -131
- package/dist/projections/recovery.js.map +0 -1
- package/dist/projections/sleep_need.js +0 -32
- package/dist/projections/sleep_need.js.map +0 -1
- package/dist/projections/smart_alarm.js +0 -45
- package/dist/projections/smart_alarm.js.map +0 -1
- package/dist/projections/strain.js +0 -128
- package/dist/projections/strain.js.map +0 -1
- package/dist/projections/stress.js +0 -86
- package/dist/projections/stress.js.map +0 -1
- package/dist/projections/today.js +0 -129
- package/dist/projections/today.js.map +0 -1
- package/dist/projections/trend.js +0 -149
- package/dist/projections/trend.js.map +0 -1
- package/dist/projections/workouts.js +0 -37
- package/dist/projections/workouts.js.map +0 -1
- package/dist/schemas/calendar.js +0 -12
- package/dist/schemas/calendar.js.map +0 -1
- package/dist/schemas/communities.js +0 -51
- package/dist/schemas/communities.js.map +0 -1
- package/dist/schemas/compare.js +0 -15
- package/dist/schemas/compare.js.map +0 -1
- package/dist/schemas/leaderboard.js +0 -25
- package/dist/schemas/leaderboard.js.map +0 -1
- package/dist/schemas/live.js +0 -26
- package/dist/schemas/live.js.map +0 -1
- package/dist/schemas/performance.js +0 -12
- package/dist/schemas/performance.js.map +0 -1
- package/dist/schemas/profile.js +0 -39
- package/dist/schemas/profile.js.map +0 -1
- package/dist/schemas/recovery.js +0 -27
- package/dist/schemas/recovery.js.map +0 -1
- package/dist/schemas/settings.js +0 -26
- package/dist/schemas/settings.js.map +0 -1
- package/dist/schemas/sleep_need.js +0 -15
- package/dist/schemas/sleep_need.js.map +0 -1
- package/dist/schemas/smart_alarm.js +0 -36
- package/dist/schemas/smart_alarm.js.map +0 -1
- package/dist/schemas/strain.js +0 -24
- package/dist/schemas/strain.js.map +0 -1
- package/dist/schemas/stress.js +0 -16
- package/dist/schemas/stress.js.map +0 -1
- package/dist/schemas/today.js +0 -38
- package/dist/schemas/today.js.map +0 -1
- package/dist/schemas/trend.js +0 -50
- package/dist/schemas/trend.js.map +0 -1
- package/dist/schemas/womens_health.js +0 -23
- package/dist/schemas/womens_health.js.map +0 -1
- package/dist/tools/v2/activity_create.js +0 -64
- package/dist/tools/v2/activity_create.js.map +0 -1
- package/dist/tools/v2/behavior_impact.js +0 -36
- package/dist/tools/v2/behavior_impact.js.map +0 -1
- package/dist/tools/v2/communities.js +0 -60
- package/dist/tools/v2/communities.js.map +0 -1
- package/dist/tools/v2/compare.js +0 -67
- package/dist/tools/v2/compare.js.map +0 -1
- package/dist/tools/v2/endpoints.js +0 -28
- package/dist/tools/v2/endpoints.js.map +0 -1
- package/dist/tools/v2/hidden_metric.js +0 -28
- package/dist/tools/v2/hidden_metric.js.map +0 -1
- package/dist/tools/v2/hr_zones.js +0 -24
- package/dist/tools/v2/hr_zones.js.map +0 -1
- package/dist/tools/v2/journal_autopop.js +0 -19
- package/dist/tools/v2/journal_autopop.js.map +0 -1
- package/dist/tools/v2/journal_catalog.js +0 -44
- package/dist/tools/v2/journal_catalog.js.map +0 -1
- package/dist/tools/v2/leaderboard.js +0 -79
- package/dist/tools/v2/leaderboard.js.map +0 -1
- package/dist/tools/v2/lift_catalog.js +0 -47
- package/dist/tools/v2/lift_catalog.js.map +0 -1
- package/dist/tools/v2/lift_custom_exercise.js +0 -108
- package/dist/tools/v2/lift_custom_exercise.js.map +0 -1
- package/dist/tools/v2/lift_history.js +0 -39
- package/dist/tools/v2/lift_history.js.map +0 -1
- package/dist/tools/v2/lift_progression.js +0 -30
- package/dist/tools/v2/lift_progression.js.map +0 -1
- package/dist/tools/v2/lift_prs.js +0 -21
- package/dist/tools/v2/lift_prs.js.map +0 -1
- package/dist/tools/v2/lift_template_save.js +0 -83
- package/dist/tools/v2/lift_template_save.js.map +0 -1
- package/dist/tools/v2/live_hr.js +0 -21
- package/dist/tools/v2/live_hr.js.map +0 -1
- package/dist/tools/v2/live_state.js +0 -21
- package/dist/tools/v2/live_state.js.map +0 -1
- package/dist/tools/v2/live_stress.js +0 -22
- package/dist/tools/v2/live_stress.js.map +0 -1
- package/dist/tools/v2/performance_assessment.js +0 -38
- package/dist/tools/v2/performance_assessment.js.map +0 -1
- package/dist/tools/v2/sleep_need.js +0 -21
- package/dist/tools/v2/sleep_need.js.map +0 -1
- package/dist/tools/v2/sports_catalog.js +0 -26
- package/dist/tools/v2/sports_catalog.js.map +0 -1
- package/dist/tools/v2/symptom_log.js +0 -72
- package/dist/tools/v2/symptom_log.js.map +0 -1
- package/dist/tools/v2/today.js +0 -30
- package/dist/tools/v2/today.js.map +0 -1
- package/dist/tools/v2/workout.js +0 -23
- package/dist/tools/v2/workout.js.map +0 -1
- package/dist/whoop/build_lift_body.js +0 -67
- package/dist/whoop/build_lift_body.js.map +0 -1
- package/dist/whoop/session_state.js +0 -34
- package/dist/whoop/session_state.js.map +0 -1
- package/dist/whoop/types.js +0 -82
- package/dist/whoop/types.js.map +0 -1
- package/src/data/endpoints.ts +0 -319
- package/src/lib/format.ts +0 -27
- package/src/lib/stats.ts +0 -35
- package/src/projections/calendar.ts +0 -46
- package/src/projections/communities.ts +0 -135
- package/src/projections/cycle.ts +0 -85
- package/src/projections/hr_zones.ts +0 -43
- package/src/projections/journal.ts +0 -55
- package/src/projections/leaderboard.ts +0 -49
- package/src/projections/lift_exercise.ts +0 -29
- package/src/projections/lift_history.ts +0 -140
- package/src/projections/lift_library.ts +0 -70
- package/src/projections/lift_progression.ts +0 -138
- package/src/projections/lift_prs.ts +0 -23
- package/src/projections/live_hr.ts +0 -21
- package/src/projections/live_state.ts +0 -28
- package/src/projections/live_stress.ts +0 -13
- package/src/projections/performance_assessment.ts +0 -19
- package/src/projections/profile.ts +0 -71
- package/src/projections/recovery.ts +0 -133
- package/src/projections/sleep_need.ts +0 -36
- package/src/projections/smart_alarm.ts +0 -70
- package/src/projections/strain.ts +0 -131
- package/src/projections/stress.ts +0 -95
- package/src/projections/today.ts +0 -166
- package/src/projections/trend.ts +0 -149
- package/src/projections/workouts.ts +0 -36
- package/src/schemas/calendar.ts +0 -13
- package/src/schemas/communities.ts +0 -56
- package/src/schemas/compare.ts +0 -17
- package/src/schemas/leaderboard.ts +0 -26
- package/src/schemas/live.ts +0 -31
- package/src/schemas/performance.ts +0 -13
- package/src/schemas/profile.ts +0 -40
- package/src/schemas/recovery.ts +0 -28
- package/src/schemas/settings.ts +0 -30
- package/src/schemas/sleep_need.ts +0 -16
- package/src/schemas/smart_alarm.ts +0 -40
- package/src/schemas/strain.ts +0 -25
- package/src/schemas/stress.ts +0 -17
- package/src/schemas/today.ts +0 -39
- package/src/schemas/trend.ts +0 -53
- package/src/schemas/womens_health.ts +0 -26
- package/src/tools/v2/activity_create.ts +0 -74
- package/src/tools/v2/behavior_impact.ts +0 -39
- package/src/tools/v2/communities.ts +0 -65
- package/src/tools/v2/compare.ts +0 -83
- package/src/tools/v2/endpoints.ts +0 -32
- package/src/tools/v2/hidden_metric.ts +0 -33
- package/src/tools/v2/hr_zones.ts +0 -29
- package/src/tools/v2/journal_autopop.ts +0 -26
- package/src/tools/v2/journal_catalog.ts +0 -48
- package/src/tools/v2/leaderboard.ts +0 -92
- package/src/tools/v2/lift_catalog.ts +0 -48
- package/src/tools/v2/lift_custom_exercise.ts +0 -117
- package/src/tools/v2/lift_history.ts +0 -52
- package/src/tools/v2/lift_progression.ts +0 -34
- package/src/tools/v2/lift_prs.ts +0 -26
- package/src/tools/v2/lift_template_save.ts +0 -89
- package/src/tools/v2/live_hr.ts +0 -26
- package/src/tools/v2/live_state.ts +0 -26
- package/src/tools/v2/live_stress.ts +0 -27
- package/src/tools/v2/performance_assessment.ts +0 -44
- package/src/tools/v2/sleep_need.ts +0 -26
- package/src/tools/v2/sports_catalog.ts +0 -32
- package/src/tools/v2/symptom_log.ts +0 -78
- package/src/tools/v2/today.ts +0 -35
- package/src/tools/v2/workout.ts +0 -28
- package/src/whoop/build_lift_body.ts +0 -84
- package/src/whoop/session_state.ts +0 -41
- package/src/whoop/types.ts +0 -89
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// whoop_lift_exercise projections: exercise metadata (v1/exercise row or a catalog
|
|
2
|
+
// row), the PR list (v3/prs tiles), the one-rep-max card + history, progression,
|
|
3
|
+
// and compact history/record rows from the exercise_history cards.
|
|
4
|
+
import { byId, byType, get, parseNumber, str, walk, type Node } from "../whoop/bff.js";
|
|
5
|
+
import type { ExerciseMetaOutT, OneRepMaxOutT } from "../schemas/strength_v2.js";
|
|
6
|
+
import { clockSeconds, displayDate, weightUnit, type LiftCard } from "./lift_cards.js";
|
|
7
|
+
|
|
8
|
+
const strings = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []);
|
|
9
|
+
const bool = (v: unknown): boolean | null => (typeof v === "boolean" ? v : null);
|
|
10
|
+
|
|
11
|
+
/** A WHOOP exercise row (v1/exercise/{id}, v2/exercise, or a rebuilt bundle row) → metadata. */
|
|
12
|
+
export function exerciseMeta(row: unknown, withInstructions = false): ExerciseMetaOutT {
|
|
13
|
+
const linked = get(row, "custom_exercise_info", "linked_exercise", "exercise_id");
|
|
14
|
+
const meta: ExerciseMetaOutT = {
|
|
15
|
+
id: String(get(row, "exercise_id") ?? ""),
|
|
16
|
+
name: String(get(row, "name") ?? ""),
|
|
17
|
+
custom: get(row, "custom_exercise") === true,
|
|
18
|
+
deleted: get(row, "deleted") === true,
|
|
19
|
+
format: str(get(row, "volume_input_format")),
|
|
20
|
+
e1rm: bool(get(row, "e1rm_eligible")),
|
|
21
|
+
trackable: bool(get(row, "trackable")),
|
|
22
|
+
muscles: strings(get(row, "muscle_groups")),
|
|
23
|
+
equipment: str(get(row, "equipment")),
|
|
24
|
+
pattern: str(get(row, "movement_pattern")),
|
|
25
|
+
linked: typeof linked === "string" ? linked : null,
|
|
26
|
+
};
|
|
27
|
+
if (withInstructions) meta.instructions = strings(get(row, "instructions"));
|
|
28
|
+
return meta;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const PR_COLS = ["id", "name", "value", "unit"];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* PR pages → [id, name, value, unit] rows, deduped by exercise_id (WHOOP reorders
|
|
35
|
+
* tiles between calls), deleted custom exercises dropped. Units: lb, kg, reps, s.
|
|
36
|
+
* Tiles carry no record date or medal.
|
|
37
|
+
*/
|
|
38
|
+
export function prRows(pages: unknown[]): Array<Array<string | number | null>> {
|
|
39
|
+
const seen = new Set<string>();
|
|
40
|
+
const out: Array<Array<string | number | null>> = [];
|
|
41
|
+
for (const page of pages) {
|
|
42
|
+
for (const t of (get(page, "tiles") ?? []) as unknown[]) {
|
|
43
|
+
const id = get(t, "exercise_id");
|
|
44
|
+
if (typeof id !== "string" || seen.has(id) || get(t, "deleted") === true) continue;
|
|
45
|
+
seen.add(id);
|
|
46
|
+
const rawValue = str(get(t, "volume_input_value"));
|
|
47
|
+
const rawUnit = str(get(t, "volume_input_units"));
|
|
48
|
+
const isTime = rawUnit === "min";
|
|
49
|
+
out.push([id, String(get(t, "name") ?? ""), isTime ? clockSeconds(rawValue) : parseNumber(rawValue), isTime ? "s" : (weightUnit(rawUnit) ?? rawUnit)]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A history card → {date, activity_id, sets:[[weight, reps|seconds]], medal}. */
|
|
56
|
+
export function historySession(card: LiftCard) {
|
|
57
|
+
return {
|
|
58
|
+
date: card.date,
|
|
59
|
+
activity_id: card.activity_id,
|
|
60
|
+
sets: card.sets.map((s) => [s.weight, s.time_seconds ?? s.reps]),
|
|
61
|
+
medal: card.medal,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The weight unit the cards use (first one found). */
|
|
66
|
+
export function cardsUnit(cards: LiftCard[]): "kg" | "lb" | null {
|
|
67
|
+
for (const c of cards) {
|
|
68
|
+
const u = c.total.unit ?? c.sets.find((s) => s.unit)?.unit;
|
|
69
|
+
if (u) return u;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function texts(node: unknown): string[] {
|
|
75
|
+
return byType(node, "MARKDOWN_TEXT").map((n) => str(get(n, "content", "text"))).filter((t): t is string => t !== null);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** GET /weightlifting-service/v3/one-rep-max/{id} → value, unit, source, date. */
|
|
79
|
+
export function oneRepMaxCard(raw: unknown): Omit<OneRepMaxOutT, "history"> & { unit: "kg" | "lb" | null } {
|
|
80
|
+
const valueRow = texts(byId(raw, "one_rep_max_value_row"));
|
|
81
|
+
const dateRow = texts(byId(raw, "one_rep_max_date_row"));
|
|
82
|
+
const sourceText = dateRow.find((t) => /estimated|manual/i.test(t)) ?? null;
|
|
83
|
+
const value = parseNumber(valueRow[0]);
|
|
84
|
+
return {
|
|
85
|
+
value,
|
|
86
|
+
unit: weightUnit(valueRow[1]) ?? weightUnit(get(byId(raw, "one_rep_max_measurement"), "value_section", "unit")),
|
|
87
|
+
source: sourceText ? (/manual/i.test(sourceText) ? "manual" : "estimated") : null,
|
|
88
|
+
date: value === null ? null : (dateRow.map(displayDate).find((d) => d !== null) ?? null),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface OneRepMaxEntry {
|
|
93
|
+
key: string;
|
|
94
|
+
source: "manual" | "estimated";
|
|
95
|
+
date: string | null;
|
|
96
|
+
value: number | null;
|
|
97
|
+
/** The unit WHOOP shows the value in (`title_suffix`). */
|
|
98
|
+
unit: "kg" | "lb" | null;
|
|
99
|
+
entry_id: string | null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* GET …/one-rep-max/{id}/history → entries. A manual entry's uuid (needed to edit
|
|
104
|
+
* or delete it) appears only inside its EDIT modal (`manual-entry/{uuid}`).
|
|
105
|
+
*/
|
|
106
|
+
export function oneRepMaxEntries(raw: unknown): OneRepMaxEntry[] {
|
|
107
|
+
const out: OneRepMaxEntry[] = [];
|
|
108
|
+
for (const n of walk(raw)) {
|
|
109
|
+
if (n.type !== "MEASUREMENT_ENTRY_ITEM") continue;
|
|
110
|
+
const c = (n.content ?? {}) as Node;
|
|
111
|
+
const key = str(c.id);
|
|
112
|
+
if (!key) continue;
|
|
113
|
+
const manual = /^MANUAL/i.test(key) || /manual/i.test(String(c.subtitle ?? ""));
|
|
114
|
+
const interaction = JSON.stringify(c.generic_interaction ?? null);
|
|
115
|
+
const entry = interaction.match(/manual-entry\/([0-9a-fA-F-]{8,})/)?.[1] ?? null;
|
|
116
|
+
out.push({
|
|
117
|
+
key,
|
|
118
|
+
source: manual ? "manual" : "estimated",
|
|
119
|
+
date: key.match(/(\d{4}-\d{2}-\d{2})$/)?.[1] ?? displayDate(c.subtitle_suffix),
|
|
120
|
+
value: parseNumber(c.title),
|
|
121
|
+
unit: weightUnit(c.title_suffix),
|
|
122
|
+
entry_id: manual ? entry : null,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Entries → [date, value, source, entry_id?] rows. */
|
|
129
|
+
export function oneRepMaxRows(entries: OneRepMaxEntry[]): Array<Array<string | number | null>> {
|
|
130
|
+
return entries.map((e) => (e.entry_id ? [e.date, e.value, e.source, e.entry_id] : [e.date, e.value, e.source]));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** GET /progression-service/v3/exercise/{id}?endDate= → one row per window (M, 6M, …). */
|
|
134
|
+
export function progressionRows(raw: unknown) {
|
|
135
|
+
const names = strings(get(raw, "segment_controller", "element_names"));
|
|
136
|
+
return ((get(raw, "time_segments") ?? []) as unknown[]).map((s, i) => {
|
|
137
|
+
const m = get(s, "metrics", 0);
|
|
138
|
+
return {
|
|
139
|
+
window: names[i] ?? String(i),
|
|
140
|
+
metric: str(get(m, "metric_name_display")),
|
|
141
|
+
value: parseNumber(get(m, "current_metric_value")) ?? parseNumber(get(m, "metric_value_display")),
|
|
142
|
+
prev: parseNumber(get(m, "previous_metric_value")),
|
|
143
|
+
change: parseNumber(get(m, "metric_change")),
|
|
144
|
+
unit: str(get(m, "metric_units_display")),
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// whoop_lift_library projections (PR #42 by @chaotix345 fixed the list fields:
|
|
2
|
+
// my_workouts_list[].workout_template_key, whoop_workouts_list[].title with string ids).
|
|
3
|
+
import { get, parseNumber, str } from "../whoop/bff.js";
|
|
4
|
+
import { setScheme } from "./lift_sessions.js";
|
|
5
|
+
|
|
6
|
+
const arr = (v: unknown): unknown[] => (Array.isArray(v) ? v : []);
|
|
7
|
+
|
|
8
|
+
/** GET /weightlifting-service/v3/workout-library → short rows; AI drafts hidden. */
|
|
9
|
+
export function libraryRows(raw: unknown): { my: Array<Array<number | string>>; whoop: Array<Array<number | string | null>> } {
|
|
10
|
+
const my = arr(get(raw, "my_workouts_list"))
|
|
11
|
+
.filter((w) => get(w, "is_draft") !== true && typeof get(w, "workout_template_key") === "number")
|
|
12
|
+
.map((w) => {
|
|
13
|
+
const row: Array<number | string> = [get(w, "workout_template_key") as number, String(get(w, "name") ?? "")];
|
|
14
|
+
if (get(w, "source") === "AI") row.push("AI");
|
|
15
|
+
return row;
|
|
16
|
+
});
|
|
17
|
+
const whoop = arr(get(raw, "whoop_workouts_list"))
|
|
18
|
+
.filter((w) => get(w, "id") !== undefined && get(w, "id") !== null)
|
|
19
|
+
.map((w) => [String(get(w, "id")), String(get(w, "title") ?? ""), parseNumber(get(w, "paragraph"))]);
|
|
20
|
+
return { my, whoop };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface GroupExercise {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string | null;
|
|
26
|
+
timed: boolean;
|
|
27
|
+
sets: Array<{ reps: number | null; weight: number | null; time: number | null }>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** workout_groups[].workout_exercises[] → exercises (supersets flattened in order). */
|
|
31
|
+
export function groupExercises(groups: unknown): GroupExercise[] {
|
|
32
|
+
return arr(groups).flatMap((g) => arr(get(g, "workout_exercises"))).map((we) => {
|
|
33
|
+
const details = get(we, "exercise_details");
|
|
34
|
+
return {
|
|
35
|
+
id: String(get(details, "exercise_id") ?? ""),
|
|
36
|
+
name: str(get(details, "name")),
|
|
37
|
+
timed: get(details, "volume_input_format") === "TIME",
|
|
38
|
+
sets: arr(get(we, "sets")).map((s) => ({
|
|
39
|
+
reps: parseNumber(get(s, "number_of_reps")),
|
|
40
|
+
weight: parseNumber(get(s, "weight")),
|
|
41
|
+
time: parseNumber(get(s, "time_in_seconds")),
|
|
42
|
+
})),
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** GET /weightlifting-service/v2/workout-template/{key} → sets as [weight, reps] ([weight, seconds] if timed). */
|
|
48
|
+
export function templateDetail(raw: unknown, unit: "kg" | "lb" | null) {
|
|
49
|
+
return {
|
|
50
|
+
key: Number(get(raw, "workout_template_key")),
|
|
51
|
+
name: String(get(raw, "name") ?? ""),
|
|
52
|
+
source: str(get(raw, "source")),
|
|
53
|
+
unit,
|
|
54
|
+
exercises: groupExercises(get(raw, "workout_groups")).map((e) => ({
|
|
55
|
+
id: e.id,
|
|
56
|
+
name: e.name,
|
|
57
|
+
sets: e.sets.map((s) => [s.weight, e.timed ? s.time : s.reps]),
|
|
58
|
+
})),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** GET /weightlifting-service/v2/prebuilt-workout-template/{id} → summary with set schemes (weights are 0). */
|
|
63
|
+
export function prebuiltDetail(raw: unknown, id: string) {
|
|
64
|
+
const tiles = arr(get(raw, "prebuilt_template_details_header", "title_metric_tiles"));
|
|
65
|
+
const duration = tiles.find((t) => /DURATION/i.test(String(get(t, "metric_subtitle_display") ?? "")));
|
|
66
|
+
return {
|
|
67
|
+
id,
|
|
68
|
+
title: str(get(raw, "prebuilt_template_details_header", "workout_title_display")) ?? str(get(raw, "workout_template", "name")),
|
|
69
|
+
summary: str(get(raw, "workout_summary_display")),
|
|
70
|
+
minutes: parseNumber(get(duration, "metric_value_display")),
|
|
71
|
+
exercises: groupExercises(get(raw, "workout_template", "workout_groups")).map((e) => ({
|
|
72
|
+
id: e.id,
|
|
73
|
+
name: e.name,
|
|
74
|
+
sets: setScheme(e.sets.map((s) => (e.timed ? s.time : s.reps)), e.timed ? "s" : ""),
|
|
75
|
+
})),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// whoop_lift_sessions projections. Sessions are found the way the app finds them
|
|
2
|
+
// (SPEC.md D1): ACTIVITY items on GET /home-service/v1/home?date= (every sport,
|
|
3
|
+
// pending included), then GET /core-details-bff/v1/cardio-details?activityId= per
|
|
4
|
+
// activity. A session is any activity whose details carry exercise cards (PR #41's
|
|
5
|
+
// hasLiftData, @chaotix345: lifts can sit on any sport). Unscored sessions have
|
|
6
|
+
// `weightlifting_cardio_details: null`; their sets come from exercise_history.
|
|
7
|
+
import { get, parseNumber, str, walk, type Node } from "../whoop/bff.js";
|
|
8
|
+
import { SESSION_EXERCISE_COLS, type LiftSessionOutT, type SessionExerciseOutT, type SessionExerciseRowT } from "../schemas/strength_v2.js";
|
|
9
|
+
import { clockSeconds, medal, weightUnit, type LiftCard, type MedalT } from "./lift_cards.js";
|
|
10
|
+
|
|
11
|
+
export interface HomeActivity {
|
|
12
|
+
activity_id: string;
|
|
13
|
+
internal_name: string | null;
|
|
14
|
+
type: string | null;
|
|
15
|
+
status: string | null;
|
|
16
|
+
score_display: string | null;
|
|
17
|
+
start: string | null;
|
|
18
|
+
end: string | null;
|
|
19
|
+
date: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** One set as parsed, before compacting. */
|
|
23
|
+
export interface ParsedSet {
|
|
24
|
+
weight: number | null;
|
|
25
|
+
reps: number | null;
|
|
26
|
+
time_seconds: number | null;
|
|
27
|
+
pct_1rm: number | null;
|
|
28
|
+
avg_hr: number | null;
|
|
29
|
+
medal: MedalT | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ParsedExercise {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string | null;
|
|
35
|
+
timed: boolean;
|
|
36
|
+
sets: ParsedSet[];
|
|
37
|
+
volume: number | null;
|
|
38
|
+
medals: MedalT[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ParsedSession {
|
|
42
|
+
exercises: ParsedExercise[];
|
|
43
|
+
volume: number | null;
|
|
44
|
+
unit: "kg" | "lb" | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** WHOOP's "+0000" offsets → canonical ISO with milliseconds; null if unparseable. */
|
|
48
|
+
export function isoTimestamp(v: unknown): string | null {
|
|
49
|
+
if (typeof v !== "string") return null;
|
|
50
|
+
const t = Date.parse(v.replace(/([+-]\d{2})(\d{2})$/, "$1:$2"));
|
|
51
|
+
return Number.isNaN(t) ? null : new Date(t).toISOString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Every activity tile on a home screen (keyed on `activity_v2_id`, never on position). */
|
|
55
|
+
export function homeActivities(raw: unknown, date: string): HomeActivity[] {
|
|
56
|
+
const seen = new Set<string>();
|
|
57
|
+
const out: HomeActivity[] = [];
|
|
58
|
+
for (const n of walk(raw)) {
|
|
59
|
+
const id = n.activity_v2_id;
|
|
60
|
+
if (typeof id !== "string" || seen.has(id)) continue;
|
|
61
|
+
seen.add(id);
|
|
62
|
+
out.push({
|
|
63
|
+
activity_id: id,
|
|
64
|
+
internal_name: str(n.internal_name),
|
|
65
|
+
type: str(n.type),
|
|
66
|
+
status: str(n.status),
|
|
67
|
+
score_display: str(n.score_display),
|
|
68
|
+
start: isoTimestamp(get(n, "during", "lower_endpoint")),
|
|
69
|
+
end: isoTimestamp(get(n, "during", "upper_endpoint")),
|
|
70
|
+
date,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function liftBlock(detail: unknown): Node | null {
|
|
77
|
+
const w = get(detail, "weightlifting_cardio_details", "weightlifting_exercises");
|
|
78
|
+
return typeof w === "object" && w !== null ? (w as Node) : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** True when cardio-details carry Strength Trainer exercise cards, whatever the sport. */
|
|
82
|
+
export function hasLiftData(detail: unknown): boolean {
|
|
83
|
+
const w = liftBlock(detail);
|
|
84
|
+
if (!w) return false;
|
|
85
|
+
const carousel = get(w, "exercise_summary_carousel", "items");
|
|
86
|
+
const groups = get(w, "exercise_summary", "exercise_card_groups");
|
|
87
|
+
const hasId = (xs: unknown) => Array.isArray(xs) && xs.some((x) => typeof get(x, "exercise_id") === "string");
|
|
88
|
+
return hasId(carousel) || (Array.isArray(groups) && groups.some((g) => hasId(get(g, "cards"))));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function displayInt(v: unknown): number | null {
|
|
92
|
+
const n = parseNumber(v);
|
|
93
|
+
return n === null ? null : Math.round(n);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const medalsOf = (sets: ParsedSet[]): MedalT[] => sets.map((s) => s.medal).filter((m): m is MedalT => m !== null);
|
|
97
|
+
|
|
98
|
+
/** Scored session: per-set stat_rows from cardio-details (carousel totals as a fallback). */
|
|
99
|
+
export function parseCardioDetails(detail: unknown): ParsedSession {
|
|
100
|
+
const w = liftBlock(detail);
|
|
101
|
+
if (!w) return { exercises: [], volume: null, unit: null };
|
|
102
|
+
const unit = weightUnit(w.tonnage_units_display);
|
|
103
|
+
const groups = (get(w, "exercise_summary", "exercise_card_groups") ?? []) as unknown[];
|
|
104
|
+
const cards = groups.flatMap((g) => (get(g, "cards") ?? []) as unknown[]).filter((c) => typeof get(c, "exercise_id") === "string");
|
|
105
|
+
let exercises: ParsedExercise[];
|
|
106
|
+
if (cards.length > 0) {
|
|
107
|
+
exercises = cards.map((c) => {
|
|
108
|
+
const timed = String(get(c, "volume_title_display") ?? "").toUpperCase() === "TIME";
|
|
109
|
+
const sets = ((get(c, "stat_rows") ?? []) as unknown[]).map((r): ParsedSet => ({
|
|
110
|
+
weight: parseNumber(get(r, "weight_display")),
|
|
111
|
+
reps: timed ? null : displayInt(get(r, "volume_display")),
|
|
112
|
+
time_seconds: timed ? clockSeconds(get(r, "volume_display")) : null,
|
|
113
|
+
pct_1rm: parseNumber(get(r, "intensity_display")),
|
|
114
|
+
avg_hr: displayInt(get(r, "avg_hr_display")),
|
|
115
|
+
medal: medal(get(r, "achievement_icon")),
|
|
116
|
+
}));
|
|
117
|
+
return { id: get(c, "exercise_id") as string, name: str(get(c, "title_display")), timed, sets, volume: parseNumber(get(c, "bottom_stats", "tonnage_display")), medals: medalsOf(sets) };
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
const items = ((get(w, "exercise_summary_carousel", "items") ?? []) as unknown[]).filter((it) => typeof get(it, "exercise_id") === "string");
|
|
121
|
+
exercises = items.map((it) => {
|
|
122
|
+
const icons = get(it, "achievement_icons");
|
|
123
|
+
return {
|
|
124
|
+
id: get(it, "exercise_id") as string,
|
|
125
|
+
name: str(get(it, "title_display")),
|
|
126
|
+
timed: /TIME/i.test(String(get(it, "volume_title_display") ?? "")),
|
|
127
|
+
sets: [],
|
|
128
|
+
volume: parseNumber(get(it, "tonnage_display")),
|
|
129
|
+
medals: (Array.isArray(icons) ? icons : []).map(medal).filter((m): m is MedalT => m !== null),
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const volume = parseNumber(get(w, "exercise_summary", "tonnage_display")) ?? parseNumber(get(w, "exercise_summary_carousel", "items", 0, "tonnage_display"));
|
|
134
|
+
return { exercises, volume, unit };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Unscored session: exercise_history cards that point at it (no HR or %1RM there). */
|
|
138
|
+
export function parseHistoryCards(cards: Array<{ exercise_id: string; name: string | null; card: LiftCard }>): ParsedSession {
|
|
139
|
+
let volume: number | null = null;
|
|
140
|
+
let unit: "kg" | "lb" | null = null;
|
|
141
|
+
const exercises = cards.map(({ exercise_id, name, card }): ParsedExercise => {
|
|
142
|
+
const sets = card.sets.map((s): ParsedSet => ({ weight: s.weight, reps: s.reps === null ? null : Math.round(s.reps), time_seconds: s.time_seconds, pct_1rm: null, avg_hr: null, medal: s.medal }));
|
|
143
|
+
if (card.total.volume !== null) volume = (volume ?? 0) + card.total.volume;
|
|
144
|
+
unit = unit ?? card.total.unit ?? card.sets.find((s) => s.unit)?.unit ?? null;
|
|
145
|
+
return { id: exercise_id, name, timed: card.sets.some((s) => s.time_seconds !== null), sets, volume: card.total.volume, medals: medalsOf(sets) };
|
|
146
|
+
});
|
|
147
|
+
return { exercises, volume, unit };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** "3x5" when every set matches, else "5/5/3"; timed sets as seconds ("2x300s"). */
|
|
151
|
+
export function setScheme(values: Array<number | null>, suffix = ""): string {
|
|
152
|
+
const vs = values.map((v) => (v === null ? "?" : String(v)));
|
|
153
|
+
if (vs.length === 0) return "0";
|
|
154
|
+
return vs.every((v) => v === vs[0]) ? `${vs.length}x${vs[0]}${suffix}` : vs.map((v) => v + suffix).join("/");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const MEDAL_RANK: Record<MedalT, number> = { GOLD: 3, SILVER: 2, BRONZE: 1 };
|
|
158
|
+
|
|
159
|
+
/** The best medal in a list (GOLD > SILVER > BRONZE). */
|
|
160
|
+
export function bestMedal(medals: MedalT[]): MedalT | null {
|
|
161
|
+
return medals.reduce<MedalT | null>((best, m) => (!best || MEDAL_RANK[m] > MEDAL_RANK[best] ? m : best), null);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Compact one exercise: summary always, per-set rows only when asked. "--" rows (not performed) are dropped. */
|
|
165
|
+
export function compactExercise(ex: ParsedExercise, withRows: boolean): SessionExerciseOutT {
|
|
166
|
+
const amount = (s: ParsedSet) => (ex.timed ? s.time_seconds : s.reps);
|
|
167
|
+
const sets = ex.sets.filter((s) => amount(s) !== null || s.weight !== null);
|
|
168
|
+
let top: number[] | null = null;
|
|
169
|
+
if (!ex.timed) {
|
|
170
|
+
for (const s of sets) {
|
|
171
|
+
if (s.weight === null || s.reps === null) continue;
|
|
172
|
+
if (!top || s.weight > top[0]! || (s.weight === top[0] && s.reps > top[1]!)) top = [s.weight, s.reps];
|
|
173
|
+
}
|
|
174
|
+
if (top && top[0] === 0) top = null; // bodyweight: the scheme says it all
|
|
175
|
+
}
|
|
176
|
+
const out: SessionExerciseOutT = {
|
|
177
|
+
id: ex.id,
|
|
178
|
+
sets: sets.length === 0 && ex.sets.length > 0 ? "skipped" : setScheme(sets.map(amount), ex.timed ? "s" : ""),
|
|
179
|
+
top,
|
|
180
|
+
volume: ex.volume,
|
|
181
|
+
medal: bestMedal(ex.medals),
|
|
182
|
+
};
|
|
183
|
+
if (withRows) {
|
|
184
|
+
const extra = sets.some((s) => s.pct_1rm !== null || s.avg_hr !== null);
|
|
185
|
+
out.rows = sets.map((s) => (extra ? [s.weight, amount(s), s.pct_1rm, s.avg_hr] : [s.weight, amount(s)]));
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** One exercise as a wire row, in SESSION_EXERCISE_COLS order (+ the per-set rows when present). */
|
|
191
|
+
export function exerciseRow(e: SessionExerciseOutT): SessionExerciseRowT {
|
|
192
|
+
const row: SessionExerciseRowT = [e.id, e.sets, e.top, e.volume, e.medal];
|
|
193
|
+
if (e.rows) row.push(e.rows);
|
|
194
|
+
return row;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The column names for a response's exercise rows; none when no session lists exercises. */
|
|
198
|
+
export function exerciseCols(sessions: Array<{ exercises: unknown[] }>, withRows: boolean): string[] {
|
|
199
|
+
if (!sessions.some((s) => s.exercises.length > 0)) return [];
|
|
200
|
+
return withRows ? [...SESSION_EXERCISE_COLS, "rows"] : [...SESSION_EXERCISE_COLS];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function strainOf(activity: HomeActivity, detail: unknown): number | null {
|
|
204
|
+
const shown = get(detail, "horizontal_stat", "stat_main_value_display");
|
|
205
|
+
const fromDetail = parseNumber(shown);
|
|
206
|
+
if (fromDetail !== null) return fromDetail;
|
|
207
|
+
// Not scored: the detail screen says "---", and an INCOMPLETE home tile still prints "0.0" (live 2026-11-21).
|
|
208
|
+
if (typeof shown === "string" || activity.status === "INCOMPLETE") return null;
|
|
209
|
+
return activity.type === "CARDIO" && activity.score_display && !activity.score_display.includes(":") ? parseNumber(activity.score_display) : null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Window and sport from cardio-details, for single-activity reads (no home tile). */
|
|
213
|
+
export function activityFromDetail(activityId: string, detail: unknown, fallbackDate: string): HomeActivity {
|
|
214
|
+
const start = isoTimestamp(get(detail, "details_edit_components", "start_time_selector", "initial_time"));
|
|
215
|
+
return {
|
|
216
|
+
activity_id: activityId,
|
|
217
|
+
internal_name: str(get(detail, "details_edit_components", "activity_type_internal_name")),
|
|
218
|
+
type: str(get(detail, "details_edit_components", "single_score_type")),
|
|
219
|
+
status: null,
|
|
220
|
+
score_display: null,
|
|
221
|
+
start,
|
|
222
|
+
end: isoTimestamp(get(detail, "details_edit_components", "end_time_selector", "initial_time")),
|
|
223
|
+
date: start ? start.slice(0, 10) : fallbackDate,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function buildSession(activity: HomeActivity, detail: unknown, parsed: ParsedSession, src: LiftSessionOutT["src"], withRows: boolean): LiftSessionOutT & { _unit: "kg" | "lb" | null } {
|
|
228
|
+
return {
|
|
229
|
+
id: activity.activity_id,
|
|
230
|
+
sport: activity.internal_name ?? str(get(detail, "details_edit_components", "activity_type_internal_name")),
|
|
231
|
+
start: activity.start,
|
|
232
|
+
end: activity.end,
|
|
233
|
+
strain: strainOf(activity, detail),
|
|
234
|
+
src,
|
|
235
|
+
volume: parsed.volume,
|
|
236
|
+
msk_pct: parseNumber(get(detail, "strain_breakdown", "msk_percent_display")),
|
|
237
|
+
unit: null,
|
|
238
|
+
exercises: parsed.exercises.map((e) => exerciseRow(compactExercise(e, withRows))),
|
|
239
|
+
_unit: parsed.unit,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** State the weight unit once: the first known unit goes top-level; sessions that differ keep their own. */
|
|
244
|
+
export function hoistUnit(sessions: Array<LiftSessionOutT & { _unit: "kg" | "lb" | null }>): { unit: "kg" | "lb" | null; sessions: LiftSessionOutT[] } {
|
|
245
|
+
const unit = sessions.find((s) => s._unit)?._unit ?? null;
|
|
246
|
+
return {
|
|
247
|
+
unit,
|
|
248
|
+
sessions: sessions.map(({ _unit, ...s }) => ({ ...s, unit: _unit && _unit !== unit ? _unit : null })),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Pure projections for the coach's memory (context hub) and AI settings.
|
|
2
|
+
// specs/ai.md §2.10–§2.11.
|
|
3
|
+
import { byType, get, str } from "../whoop/bff.js";
|
|
4
|
+
import type { MemoryOutT, MemoryRowT } from "../schemas/memory.js";
|
|
5
|
+
|
|
6
|
+
const arr = (v: unknown): unknown[] => (Array.isArray(v) ? v : []);
|
|
7
|
+
|
|
8
|
+
const MONTHS: Record<string, string> = {
|
|
9
|
+
jan: "01", feb: "02", mar: "03", apr: "04", may: "05", jun: "06",
|
|
10
|
+
jul: "07", aug: "08", sep: "09", oct: "10", nov: "11", dec: "12",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** "Start date: Nov 22, 2026" → "2026-11-22"; unparseable text is kept (label stripped). */
|
|
14
|
+
export function parseCardDate(text: string | null): string | null {
|
|
15
|
+
if (!text) return null;
|
|
16
|
+
const m = text.match(/\b([A-Za-z]{3})[a-z]*\.? (\d{1,2}), (\d{4})\b/);
|
|
17
|
+
const month = m ? MONTHS[m[1]!.toLowerCase()] : undefined;
|
|
18
|
+
if (m && month) return `${m[3]}-${month}-${m[2]!.padStart(2, "0")}`;
|
|
19
|
+
const stripped = text.replace(/^[^:]*:\s*/, "").trim();
|
|
20
|
+
return stripped || null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** CONTEXT_CARD content → compact row. The CONTEXT_DEFAULT tag carries the category label. */
|
|
24
|
+
export function projectContextCard(content: unknown): MemoryRowT | null {
|
|
25
|
+
const id = str(get(content, "id"));
|
|
26
|
+
if (!id) return null;
|
|
27
|
+
const categoryTag = arr(get(content, "tags")).find((t) => get(t, "tag_style") === "CONTEXT_DEFAULT");
|
|
28
|
+
return {
|
|
29
|
+
id,
|
|
30
|
+
title: str(get(content, "title")),
|
|
31
|
+
summary: clip(str(get(content, "subtitle")) ?? str(get(content, "description"))),
|
|
32
|
+
status: str(get(content, "status")),
|
|
33
|
+
category: str(get(categoryTag, "title")),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** List rows carry a short summary; the detail view has the full text. */
|
|
38
|
+
function clip(text: string | null, max = 140): string | null {
|
|
39
|
+
return text && text.length > max ? `${text.slice(0, max - 1).trimEnd()}…` : text;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The raw CONTEXT_CARD content for one id in an items response (for detail-free dates). */
|
|
43
|
+
export function findCardContent(raw: unknown, id: string): unknown {
|
|
44
|
+
return arr(get(raw, "items")).map((it) => get(it, "content")).find((c) => get(c, "id") === id);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Items response `{filters, items[CONTEXT_CARD]}` → rows (first `limit`) + the
|
|
49
|
+
* category keys that have items. Rows carry their category only on the
|
|
50
|
+
* all-categories timeline.
|
|
51
|
+
*/
|
|
52
|
+
export function projectMemoryItems(raw: unknown, category: string, limit = Infinity): Extract<MemoryOutT, { view: "items" }> {
|
|
53
|
+
const all = arr(get(raw, "items"))
|
|
54
|
+
.map((it) => projectContextCard(get(it, "content")))
|
|
55
|
+
.filter((it): it is MemoryRowT => it !== null);
|
|
56
|
+
const items = all.slice(0, limit).map((row) => {
|
|
57
|
+
if (category === "timeline") return row;
|
|
58
|
+
const { category: _omit, ...rest } = row;
|
|
59
|
+
return rest;
|
|
60
|
+
});
|
|
61
|
+
const categories = byType(get(raw, "filters"), "TAG").flatMap((tag) => {
|
|
62
|
+
// The selected pill has no action; fall back to its analytics label, then its title.
|
|
63
|
+
const path = str(get(tag, "content", "action", "parameters", "request", "path"));
|
|
64
|
+
const label = str(get(tag, "content", "title"));
|
|
65
|
+
const key = path?.match(/[?&]category=([^&]+)/)?.[1] ??
|
|
66
|
+
str(get(tag, "primary_analytic_event", "label")) ??
|
|
67
|
+
(label ? label.trim().toLowerCase().replace(/\s+/g, "_") : null);
|
|
68
|
+
return key ? [key] : [];
|
|
69
|
+
});
|
|
70
|
+
return { view: "items", category, categories, total: all.length, items };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** context-detail screen → header, toggle state and the "Relevant Conversations" lines. */
|
|
74
|
+
export function projectMemoryDetail(raw: unknown, id: string, card?: unknown): Extract<MemoryOutT, { view: "detail" }> {
|
|
75
|
+
const header = byType(raw, "CONTEXT_DETAIL_HEADER")[0];
|
|
76
|
+
const toggle = byType(raw, "CONTEXT_STATUS_TOGGLE")[0];
|
|
77
|
+
const changelog = byType(raw, "SECTION").find((s) => get(s, "content", "id") === "changelog_section");
|
|
78
|
+
const lines = byType(changelog, "MARKDOWN_TEXT")
|
|
79
|
+
.map((n) => str(get(n, "content", "text")))
|
|
80
|
+
.filter((t): t is string => t !== null && t !== "Relevant Conversations")
|
|
81
|
+
.map((t) => t.replace(/^-\s*/, "").replace(/\*\*/g, "").replace(/\s{2,}/g, " ").trim());
|
|
82
|
+
return {
|
|
83
|
+
view: "detail",
|
|
84
|
+
id,
|
|
85
|
+
title: str(get(header, "content", "title")),
|
|
86
|
+
summary: str(get(header, "content", "subtitle")),
|
|
87
|
+
status: str(get(toggle, "content", "current_state")),
|
|
88
|
+
started: parseCardDate(str(get(card, "last_updated_at_text"))),
|
|
89
|
+
expires: parseCardDate(str(get(card, "expires_at_text"))),
|
|
90
|
+
conversations: lines,
|
|
91
|
+
note: "Opening the detail marked this memory seen in the WHOOP app.",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** WHOOP_COACH_MEMORY from GET/PUT /ai-conversation-service/v1/settings. */
|
|
96
|
+
export function memoryEnabled(raw: unknown): boolean | null {
|
|
97
|
+
const row = arr(get(raw, "settings")).find((s) => get(s, "setting_key") === "WHOOP_COACH_MEMORY");
|
|
98
|
+
const active = get(row, "active");
|
|
99
|
+
return typeof active === "boolean" ? active : null;
|
|
100
|
+
}
|