@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
package/src/projections/cycle.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { CycleOutT } from "../schemas/womens_health.js";
|
|
2
|
-
import { isObject, asArray, asBool, asNumber, asString, findByType } from "../lib/walk.js";
|
|
3
|
-
|
|
4
|
-
// /womens-health-service/v1/menstrual-cycle-insights?date=YYYY-MM-DD returns a
|
|
5
|
-
// tiles[] BFF (NOT flat fields). The data lives in:
|
|
6
|
-
// HEADER_TILE content.title_display "Cycle Day 11",
|
|
7
|
-
// content.subtitle_display "Luteal Phase", content.style "LUTEAL"
|
|
8
|
-
// CALENDAR_TILE content.calendar.days_of_month[]:
|
|
9
|
-
// { date "2026-05-21", phase, day_state "PERIOD", first_day_of_phase }
|
|
10
|
-
// TYPICAL_CYCLE_TILE content.stats[]: { title_display "CYCLE LENGTH", value_display "-"|"28" }
|
|
11
|
-
// CYCLE_PHASE_COACHING content.destination.parameters.phase "LUTEAL"
|
|
12
|
-
//
|
|
13
|
-
// Hormonal mode / contraception / pregnancy are account-settings that this BFF
|
|
14
|
-
// does NOT carry, so they stay null here.
|
|
15
|
-
//
|
|
16
|
-
// The previous projection looked for tile types CYCLE_PHASE_TILE / HORMONAL_MODE_TILE
|
|
17
|
-
// that don't exist in the response, so every field returned null even on a fully
|
|
18
|
-
// populated 200 (women's-health enabled, mid-cycle).
|
|
19
|
-
|
|
20
|
-
function tileByType(tiles: unknown[], type: string): Record<string, unknown> | null {
|
|
21
|
-
for (const t of tiles) {
|
|
22
|
-
if (isObject(t) && asString(t.type) === type) return t;
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function contentOf(tile: Record<string, unknown> | null): Record<string, unknown> {
|
|
28
|
-
return tile && isObject(tile.content) ? (tile.content as Record<string, unknown>) : {};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function projectCycle(raw: unknown, date: string): CycleOutT {
|
|
32
|
-
const root = isObject(raw) ? raw : {};
|
|
33
|
-
const tiles = asArray(root.tiles);
|
|
34
|
-
|
|
35
|
-
const header = contentOf(tileByType(tiles, "HEADER_TILE"));
|
|
36
|
-
// "Cycle Day 11" → 11
|
|
37
|
-
const dayMatch = (asString(header.title_display) ?? "").match(/(\d+)/);
|
|
38
|
-
const cycleDay = dayMatch ? Number(dayMatch[1]) : null;
|
|
39
|
-
// Human-readable phase ("Luteal Phase"); fall back to the style enum ("LUTEAL").
|
|
40
|
-
const phase = asString(header.subtitle_display) ?? asString(header.style);
|
|
41
|
-
|
|
42
|
-
// "CYCLE LENGTH" stat — value_display is "-" until there's enough history, so
|
|
43
|
-
// asNumber yields null in that case (correct).
|
|
44
|
-
const typical = contentOf(tileByType(tiles, "TYPICAL_CYCLE_TILE"));
|
|
45
|
-
let cycleLength: number | null = null;
|
|
46
|
-
for (const s of asArray(typical.stats)) {
|
|
47
|
-
if (isObject(s) && /CYCLE LENGTH/i.test(asString(s.title_display) ?? "")) {
|
|
48
|
-
cycleLength = asNumber(s.value_display);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Forward-looking predictions from the calendar: the earliest first-day-of-phase
|
|
53
|
-
// marker on/after `date` for menstruation (next period) and ovulation. Null when
|
|
54
|
-
// the predicted day falls outside the month the BFF returned.
|
|
55
|
-
const calendar = contentOf(tileByType(tiles, "CALENDAR_TILE"));
|
|
56
|
-
const calObj = isObject(calendar.calendar) ? (calendar.calendar as Record<string, unknown>) : {};
|
|
57
|
-
const days = asArray(calObj.days_of_month);
|
|
58
|
-
const nextPhaseStart = (phaseName: string): string | null => {
|
|
59
|
-
let best: string | null = null;
|
|
60
|
-
for (const d of days) {
|
|
61
|
-
if (!isObject(d) || d.first_day_of_phase !== true) continue;
|
|
62
|
-
if (asString(d.phase) !== phaseName) continue;
|
|
63
|
-
const dDate = asString(d.date);
|
|
64
|
-
if (!dDate || dDate < date) continue; // ISO dates compare lexicographically
|
|
65
|
-
if (best === null || dDate < best) best = dDate;
|
|
66
|
-
}
|
|
67
|
-
return best;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Hormonal mode / contraception / pregnancy aren't in this BFF; keep the
|
|
71
|
-
// defensive lookup in case a variant carries them, otherwise null.
|
|
72
|
-
const modeTile = findByType(root, "HORMONAL_MODE_TILE");
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
date,
|
|
76
|
-
phase,
|
|
77
|
-
cycle_day: cycleDay,
|
|
78
|
-
cycle_length: cycleLength,
|
|
79
|
-
next_period_predicted_date: nextPhaseStart("MENSTRUAL"),
|
|
80
|
-
ovulation_predicted_date: nextPhaseStart("OVULATORY"),
|
|
81
|
-
hormonal_mode: modeTile ? asString(modeTile.mode) : null,
|
|
82
|
-
contraception_type: modeTile ? asString(modeTile.contraception_type) : null,
|
|
83
|
-
is_pregnant: modeTile ? asBool(modeTile.is_pregnant) : null,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { HrZonesOutT } from "../schemas/settings.js";
|
|
2
|
-
import { isObject, asArray, asBool, asNumber, asString } from "../lib/walk.js";
|
|
3
|
-
|
|
4
|
-
interface ProjectHrZonesInput {
|
|
5
|
-
zones: unknown;
|
|
6
|
-
settings: unknown;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const VALID_ZONE_IDS = ["ZONE_1", "ZONE_2", "ZONE_3", "ZONE_4", "ZONE_5"] as const;
|
|
10
|
-
type ZoneId = typeof VALID_ZONE_IDS[number];
|
|
11
|
-
|
|
12
|
-
export function projectHrZones(input: ProjectHrZonesInput): HrZonesOutT {
|
|
13
|
-
const zones = isObject(input.zones) ? input.zones as Record<string, unknown> : {};
|
|
14
|
-
const settings = isObject(input.settings) ? input.settings as Record<string, unknown> : {};
|
|
15
|
-
|
|
16
|
-
// Max HR lives in settings.heart_rate_entry_row (an array of {id, value} rows,
|
|
17
|
-
// id "MAX_HR"); fall back to the zones-screen entry field.
|
|
18
|
-
let maxHr: number | null = null;
|
|
19
|
-
for (const r of asArray(settings.heart_rate_entry_row)) {
|
|
20
|
-
if (isObject(r) && asString(r.id) === "MAX_HR") maxHr = asNumber(r.value);
|
|
21
|
-
}
|
|
22
|
-
if (maxHr === null && isObject(zones.max_hr_entry_field)) {
|
|
23
|
-
maxHr = asNumber((zones.max_hr_entry_field as Record<string, unknown>).value);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const zoneList = asArray(zones.zones)
|
|
27
|
-
.map((z) => {
|
|
28
|
-
if (!isObject(z)) return null;
|
|
29
|
-
const id = asString(z.id);
|
|
30
|
-
if (!id || !(VALID_ZONE_IDS as readonly string[]).includes(id)) return null;
|
|
31
|
-
const min = asNumber(z.min) ?? 0;
|
|
32
|
-
const max = asNumber(z.max) ?? 0;
|
|
33
|
-
return { id: id as ZoneId, min, max };
|
|
34
|
-
})
|
|
35
|
-
.filter((z): z is { id: ZoneId; min: number; max: number } => z !== null);
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
max_hr: maxHr,
|
|
39
|
-
is_custom: asBool(zones.is_custom) ?? false,
|
|
40
|
-
effective_timestamp: asString(zones.effective_timestamp),
|
|
41
|
-
zones: zoneList,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { JournalOutT } from "../schemas/journal.js";
|
|
2
|
-
import { BEHAVIORS_BY_ID } from "../data/behaviors.js";
|
|
3
|
-
import { isObject, asArray, asNumber, asString, asBool } from "../lib/walk.js";
|
|
4
|
-
|
|
5
|
-
export function projectJournal(raw: unknown, date: string): JournalOutT {
|
|
6
|
-
let inputs: unknown[];
|
|
7
|
-
let cycleId: number | null = null;
|
|
8
|
-
let entryId: string | null = null;
|
|
9
|
-
let notes: string | null = null;
|
|
10
|
-
|
|
11
|
-
if (Array.isArray(raw)) {
|
|
12
|
-
inputs = raw;
|
|
13
|
-
} else if (isObject(raw)) {
|
|
14
|
-
const journal = isObject(raw.journal) ? raw.journal as Record<string, unknown> : null;
|
|
15
|
-
if (journal) {
|
|
16
|
-
inputs = asArray(journal.tracked_behaviors);
|
|
17
|
-
cycleId = asNumber(journal.cycle_id);
|
|
18
|
-
entryId = asString(journal.journal_entry_id);
|
|
19
|
-
notes = asString(journal.notes);
|
|
20
|
-
} else {
|
|
21
|
-
inputs = asArray(raw.records ?? raw.tracker_inputs ?? raw.items);
|
|
22
|
-
}
|
|
23
|
-
} else {
|
|
24
|
-
inputs = [];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const behaviors = inputs
|
|
28
|
-
.map((i) => {
|
|
29
|
-
if (!isObject(i)) return null;
|
|
30
|
-
// The v3 drafts endpoint nests each logged behavior as
|
|
31
|
-
// { behavior_tracker: { id, title, ... }, tracker_input: { behavior_tracker_id,
|
|
32
|
-
// answered_yes, magnitude_input_value, magnitude_input_label, ... } }
|
|
33
|
-
// The flat shape (the v2 write body, and older captures) puts those fields
|
|
34
|
-
// directly on the entry. Read whichever exists — missing this nesting is why
|
|
35
|
-
// every behavior was being dropped and `behaviors` came back empty (issue #2).
|
|
36
|
-
const input = isObject(i.tracker_input) ? (i.tracker_input as Record<string, unknown>) : i;
|
|
37
|
-
const tracker = isObject(i.behavior_tracker) ? (i.behavior_tracker as Record<string, unknown>) : null;
|
|
38
|
-
const id = asNumber(input.behavior_tracker_id ?? (tracker ? tracker.id : undefined) ?? i.behavior_id);
|
|
39
|
-
if (id === null) return null;
|
|
40
|
-
const meta = BEHAVIORS_BY_ID.get(id);
|
|
41
|
-
return {
|
|
42
|
-
behavior_tracker_id: id,
|
|
43
|
-
title: meta?.title ?? asString(tracker?.title) ?? "",
|
|
44
|
-
category: meta?.category ?? asString(tracker?.category) ?? "",
|
|
45
|
-
internal_name: meta?.internal_name ?? asString(tracker?.internal_name) ?? "",
|
|
46
|
-
answered_yes: asBool(input.answered_yes),
|
|
47
|
-
magnitude_value: asNumber(input.magnitude_input_value),
|
|
48
|
-
magnitude_label: asString(input.magnitude_input_label),
|
|
49
|
-
recorded_at: asString(input.recorded_at),
|
|
50
|
-
};
|
|
51
|
-
})
|
|
52
|
-
.filter((b): b is NonNullable<typeof b> => b !== null);
|
|
53
|
-
|
|
54
|
-
return { date, cycle_id: cycleId, journal_entry_id: entryId, notes, behaviors };
|
|
55
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { LeaderboardOutT } from "../schemas/leaderboard.js";
|
|
2
|
-
import { isObject, asArray, asNumber, asString } from "../lib/walk.js";
|
|
3
|
-
|
|
4
|
-
interface ProjectLeaderboardInput {
|
|
5
|
-
community_id: number;
|
|
6
|
-
community_name: string | null;
|
|
7
|
-
window: "day" | "week" | "month";
|
|
8
|
-
metric: "recovery" | "sleep" | "strain";
|
|
9
|
-
date: string;
|
|
10
|
-
board: unknown;
|
|
11
|
-
user_row: unknown | null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function projectLeaderboard(input: ProjectLeaderboardInput): LeaderboardOutT {
|
|
15
|
-
const board = isObject(input.board) ? input.board as Record<string, unknown> : {};
|
|
16
|
-
const records = asArray(board.records)
|
|
17
|
-
.map((r) => {
|
|
18
|
-
if (!isObject(r)) return null;
|
|
19
|
-
const score = asNumber(r.score ?? r.day_strain ?? r.duration);
|
|
20
|
-
return {
|
|
21
|
-
rank: asNumber(r.rank) ?? 0,
|
|
22
|
-
user_id: asNumber(r.user_id) ?? 0,
|
|
23
|
-
first_name: asString(r.first_name) ?? "",
|
|
24
|
-
last_name: asString(r.last_name) ?? "",
|
|
25
|
-
value: score,
|
|
26
|
-
secondary_value: asNumber(r.hrv ?? r.performance ?? r.calories),
|
|
27
|
-
};
|
|
28
|
-
})
|
|
29
|
-
.filter((r): r is NonNullable<typeof r> => r !== null);
|
|
30
|
-
|
|
31
|
-
const userRow = input.user_row && isObject(input.user_row) ? input.user_row as Record<string, unknown> : null;
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
community_id: input.community_id,
|
|
35
|
-
community_name: input.community_name,
|
|
36
|
-
window: input.window,
|
|
37
|
-
metric: input.metric,
|
|
38
|
-
date_label: input.date,
|
|
39
|
-
average: asNumber(board.average),
|
|
40
|
-
total_compliant: asNumber(board.total_compliant),
|
|
41
|
-
total_empty: asNumber(board.total_empty),
|
|
42
|
-
records,
|
|
43
|
-
your_position: {
|
|
44
|
-
rank: userRow ? asNumber(userRow.rank) : null,
|
|
45
|
-
value: userRow ? asNumber(userRow.score ?? userRow.day_strain ?? userRow.duration) : null,
|
|
46
|
-
in_window: userRow !== null,
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { LiftExerciseOutT } from "../schemas/strength.js";
|
|
2
|
-
import { ExerciseInfoSchema } from "../whoop/types.js";
|
|
3
|
-
import { extractSessions } from "../lib/walk.js";
|
|
4
|
-
|
|
5
|
-
interface ProjectLiftExerciseInput {
|
|
6
|
-
info: unknown;
|
|
7
|
-
history: unknown;
|
|
8
|
-
prs: unknown;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function projectLiftExercise(input: ProjectLiftExerciseInput): LiftExerciseOutT {
|
|
12
|
-
const info = ExerciseInfoSchema.parse(input.info);
|
|
13
|
-
return {
|
|
14
|
-
exercise: {
|
|
15
|
-
id: info.exercise_id,
|
|
16
|
-
name: info.name,
|
|
17
|
-
muscle_groups: info.muscle_groups,
|
|
18
|
-
equipment: info.equipment,
|
|
19
|
-
movement_pattern: info.movement_pattern,
|
|
20
|
-
laterality: info.laterality,
|
|
21
|
-
custom: info.custom_exercise,
|
|
22
|
-
volume_input_format: info.volume_input_format,
|
|
23
|
-
instructions: info.instructions,
|
|
24
|
-
video_url: info.video_url,
|
|
25
|
-
},
|
|
26
|
-
recent_sessions: extractSessions(input.history),
|
|
27
|
-
personal_records: extractSessions(input.prs),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import type { LiftHistoryOutT } from "../schemas/strength.js";
|
|
2
|
-
import { isObject, asArray, asNumber, asString } from "../lib/walk.js";
|
|
3
|
-
|
|
4
|
-
// Whoop returns these internal_name values for set-based strength workouts.
|
|
5
|
-
// "weightlifting_msk" = Strength Trainer. "weightlifting" and "powerlifting"
|
|
6
|
-
// are manual logs. None of them contain "strength" — match by broader pattern.
|
|
7
|
-
function isStrengthSport(name: string | null): boolean {
|
|
8
|
-
if (!name) return false;
|
|
9
|
-
return /weight|strength|powerlift/i.test(name);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Parse "5 Sets" → 5, "1 Set" → 1, "0 Sets" → 0. Returns null if not parseable.
|
|
13
|
-
function parseSetCount(s: string | null): number | null {
|
|
14
|
-
if (!s) return null;
|
|
15
|
-
const m = s.match(/^(\d+)\s*Sets?/i);
|
|
16
|
-
return m && m[1] ? parseInt(m[1], 10) : null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ProjectLiftHistoryInput {
|
|
20
|
-
workouts: unknown;
|
|
21
|
-
details: unknown[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function projectLiftHistory(input: ProjectLiftHistoryInput): LiftHistoryOutT {
|
|
25
|
-
const root = isObject(input.workouts) ? input.workouts : {};
|
|
26
|
-
const records = asArray(root.records).filter(
|
|
27
|
-
(r) => isObject(r) && isStrengthSport(asString((r as Record<string, unknown>).sport_name)),
|
|
28
|
-
);
|
|
29
|
-
const out: LiftHistoryOutT = [];
|
|
30
|
-
for (let i = 0; i < records.length; i++) {
|
|
31
|
-
const r = records[i] as Record<string, unknown>;
|
|
32
|
-
const detail = input.details[i];
|
|
33
|
-
if (!isObject(detail)) continue;
|
|
34
|
-
|
|
35
|
-
// Set-level data lives at:
|
|
36
|
-
// weightlifting_cardio_details.weightlifting_exercises.exercise_summary_carousel.items[]
|
|
37
|
-
// The first item is a SUMMARY row ("8 Exercises", "29 Sets") — skip it.
|
|
38
|
-
// Each subsequent item is one exercise with set_count + tonnage + total reps.
|
|
39
|
-
const wld = isObject(detail.weightlifting_cardio_details)
|
|
40
|
-
? (detail.weightlifting_cardio_details as Record<string, unknown>)
|
|
41
|
-
: {};
|
|
42
|
-
const wex = isObject(wld.weightlifting_exercises)
|
|
43
|
-
? (wld.weightlifting_exercises as Record<string, unknown>)
|
|
44
|
-
: {};
|
|
45
|
-
const carousel = isObject(wex.exercise_summary_carousel)
|
|
46
|
-
? (wex.exercise_summary_carousel as Record<string, unknown>)
|
|
47
|
-
: {};
|
|
48
|
-
const tonnageUnits = asString(wex.tonnage_units_display);
|
|
49
|
-
const items = asArray(carousel.items);
|
|
50
|
-
|
|
51
|
-
// The first carousel item is the aggregate row ("8 Exercises", "29 Sets",
|
|
52
|
-
// total tonnage in lbs). Read it before iterating real exercises.
|
|
53
|
-
let summaryTonnageLbs: number | null = null;
|
|
54
|
-
if (items.length > 0 && isObject(items[0])) {
|
|
55
|
-
const summary = items[0] as Record<string, unknown>;
|
|
56
|
-
const t = asString(summary.tonnage_display);
|
|
57
|
-
if (t) {
|
|
58
|
-
const n = parseFloat(t.replace(/,/g, ""));
|
|
59
|
-
if (Number.isFinite(n)) summaryTonnageLbs = n;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let setCount = 0;
|
|
64
|
-
const exercises: LiftHistoryOutT[number]["exercises"] = [];
|
|
65
|
-
for (let j = 0; j < items.length; j++) {
|
|
66
|
-
const it = items[j];
|
|
67
|
-
if (!isObject(it)) continue;
|
|
68
|
-
const exId = asString(it.exercise_id);
|
|
69
|
-
// Skip the aggregate summary row (no exercise_id)
|
|
70
|
-
if (exId === null) continue;
|
|
71
|
-
const itemSetCount = parseSetCount(asString(it.subtitle_display));
|
|
72
|
-
const tonnage = (() => {
|
|
73
|
-
const t = asString(it.tonnage_display);
|
|
74
|
-
if (!t) return null;
|
|
75
|
-
const n = parseFloat(t.replace(/,/g, ""));
|
|
76
|
-
return Number.isFinite(n) ? n : null;
|
|
77
|
-
})();
|
|
78
|
-
const totalReps = (() => {
|
|
79
|
-
const v = asString(it.volume_display);
|
|
80
|
-
if (!v) return null;
|
|
81
|
-
const n = parseInt(v.replace(/,/g, ""), 10);
|
|
82
|
-
return Number.isFinite(n) ? n : null;
|
|
83
|
-
})();
|
|
84
|
-
const achievements = asArray(it.achievement_icons)
|
|
85
|
-
.map((a) => asString(a))
|
|
86
|
-
.filter((a): a is string => a !== null);
|
|
87
|
-
|
|
88
|
-
exercises.push({
|
|
89
|
-
exercise_id: exId,
|
|
90
|
-
name: asString(it.title_display),
|
|
91
|
-
set_count: itemSetCount,
|
|
92
|
-
total_reps: totalReps,
|
|
93
|
-
tonnage,
|
|
94
|
-
tonnage_units: tonnageUnits,
|
|
95
|
-
achievements,
|
|
96
|
-
sets: [], // per-set detail not in cardio-details
|
|
97
|
-
});
|
|
98
|
-
setCount += itemSetCount ?? 0;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const start = asString(r.start) ?? "";
|
|
102
|
-
const end = asString(r.end) ?? "";
|
|
103
|
-
const score = isObject(r.score) ? (r.score as Record<string, unknown>) : {};
|
|
104
|
-
|
|
105
|
-
// MSK total volume comes from the carousel summary row (lbs). Convert to kg
|
|
106
|
-
// since the schema field is _kg and the iOS app shows kg in some locales.
|
|
107
|
-
const LBS_TO_KG = 0.45359237;
|
|
108
|
-
const mskVolumeKg = (() => {
|
|
109
|
-
if (summaryTonnageLbs === null) return null;
|
|
110
|
-
if (tonnageUnits && /kg/i.test(tonnageUnits)) return summaryTonnageLbs;
|
|
111
|
-
// default: assume lbs
|
|
112
|
-
return Math.round(summaryTonnageLbs * LBS_TO_KG);
|
|
113
|
-
})();
|
|
114
|
-
|
|
115
|
-
// MSK intensity % from strain_breakdown.msk_percent_display ("74%")
|
|
116
|
-
const strainBreakdown = isObject(detail.strain_breakdown)
|
|
117
|
-
? (detail.strain_breakdown as Record<string, unknown>)
|
|
118
|
-
: {};
|
|
119
|
-
const mskIntensityPct = (() => {
|
|
120
|
-
const v = asString(strainBreakdown.msk_percent_display);
|
|
121
|
-
if (!v) return null;
|
|
122
|
-
const n = parseFloat(v.replace("%", ""));
|
|
123
|
-
return Number.isFinite(n) ? n : null;
|
|
124
|
-
})();
|
|
125
|
-
|
|
126
|
-
out.push({
|
|
127
|
-
activity_id: asString(r.id) ?? "",
|
|
128
|
-
date: start.slice(0, 10),
|
|
129
|
-
name: asString(r.name) ?? null,
|
|
130
|
-
duration_ms: start && end ? new Date(end).getTime() - new Date(start).getTime() : 0,
|
|
131
|
-
strain: asNumber(score.strain),
|
|
132
|
-
msk_total_volume_kg: mskVolumeKg,
|
|
133
|
-
msk_intensity_pct: mskIntensityPct,
|
|
134
|
-
exercise_count: exercises.length,
|
|
135
|
-
set_count: setCount,
|
|
136
|
-
exercises,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return out;
|
|
140
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { LiftLibraryOutT } from "../schemas/strength.js";
|
|
2
|
-
import { isObject, asArray, asNumber, asString } from "../lib/walk.js";
|
|
3
|
-
|
|
4
|
-
export function projectLibraryList(raw: unknown): LiftLibraryOutT {
|
|
5
|
-
const root = isObject(raw) ? raw : {};
|
|
6
|
-
const my = asArray(root.my_workouts_list)
|
|
7
|
-
.map((w) => {
|
|
8
|
-
if (!isObject(w)) return null;
|
|
9
|
-
const tid = asNumber(w.template_id ?? w.id);
|
|
10
|
-
if (tid === null) return null;
|
|
11
|
-
return {
|
|
12
|
-
template_id: tid,
|
|
13
|
-
name: asString(w.name) ?? "",
|
|
14
|
-
exercise_count: asNumber(w.exercise_count) ?? 0,
|
|
15
|
-
last_used: asString(w.last_used),
|
|
16
|
-
};
|
|
17
|
-
})
|
|
18
|
-
.filter((x): x is NonNullable<typeof x> => x !== null);
|
|
19
|
-
const whoop = asArray(root.whoop_workouts_list)
|
|
20
|
-
.map((w) => {
|
|
21
|
-
if (!isObject(w)) return null;
|
|
22
|
-
const tid = asNumber(w.template_id ?? w.id);
|
|
23
|
-
if (tid === null) return null;
|
|
24
|
-
return {
|
|
25
|
-
template_id: tid,
|
|
26
|
-
name: asString(w.name) ?? "",
|
|
27
|
-
exercise_count: asNumber(w.exercise_count) ?? 0,
|
|
28
|
-
};
|
|
29
|
-
})
|
|
30
|
-
.filter((x): x is NonNullable<typeof x> => x !== null);
|
|
31
|
-
return { mode: "list" as const, my_workouts: my, whoop_workouts: whoop };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function projectLibrarySingle(raw: unknown): LiftLibraryOutT {
|
|
35
|
-
const root = isObject(raw) ? raw : {};
|
|
36
|
-
const exercises: Array<{
|
|
37
|
-
exercise_id: string;
|
|
38
|
-
name: string;
|
|
39
|
-
sets: { reps: number | null; weight: number | null; time_seconds: number | null }[];
|
|
40
|
-
}> = [];
|
|
41
|
-
for (const g of asArray(root.workout_groups)) {
|
|
42
|
-
if (!isObject(g)) continue;
|
|
43
|
-
for (const we of asArray(g.workout_exercises)) {
|
|
44
|
-
if (!isObject(we)) continue;
|
|
45
|
-
const ex = isObject(we.exercise_details) ? we.exercise_details as Record<string, unknown> : {};
|
|
46
|
-
const sets = asArray(we.sets)
|
|
47
|
-
.map((s) => {
|
|
48
|
-
if (!isObject(s)) return null;
|
|
49
|
-
const t = asNumber(s.time_in_seconds);
|
|
50
|
-
return {
|
|
51
|
-
reps: asNumber(s.number_of_reps),
|
|
52
|
-
weight: asNumber(s.weight),
|
|
53
|
-
time_seconds: t !== null ? Math.round(t) : null,
|
|
54
|
-
};
|
|
55
|
-
})
|
|
56
|
-
.filter((s): s is NonNullable<typeof s> => s !== null);
|
|
57
|
-
exercises.push({
|
|
58
|
-
exercise_id: asString(ex.exercise_id) ?? "",
|
|
59
|
-
name: asString(ex.name) ?? "",
|
|
60
|
-
sets,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
mode: "single" as const,
|
|
66
|
-
template_id: asNumber(root.workout_template_key ?? root.template_id) ?? 0,
|
|
67
|
-
name: asString(root.name) ?? "",
|
|
68
|
-
exercises,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { LiftProgressionOutT } from "../schemas/strength.js";
|
|
2
|
-
import { isObject, asArray, asNumber, asString, labelToNumber, timeLabelToMs } from "../lib/walk.js";
|
|
3
|
-
|
|
4
|
-
type SegLabel = "week" | "month" | "six_month" | "year";
|
|
5
|
-
|
|
6
|
-
// segment_controller.element_names is the canonical, in-order list of which
|
|
7
|
-
// windows this exercise actually has — e.g. ["M", "6M"] when there's no weekly
|
|
8
|
-
// data. Positional [week, month, ...] labeling was wrong whenever a window was
|
|
9
|
-
// absent (lifts are infrequent, so "week" often is). Map the codes instead.
|
|
10
|
-
function labelFromElementName(code: string): SegLabel | null {
|
|
11
|
-
switch (code.toUpperCase().replace(/\s/g, "")) {
|
|
12
|
-
case "W": case "1W": case "WEEK": return "week";
|
|
13
|
-
case "M": case "1M": case "MONTH": return "month";
|
|
14
|
-
case "6M": case "SIXMONTH": return "six_month";
|
|
15
|
-
case "Y": case "1Y": case "YEAR": return "year";
|
|
16
|
-
default: return null;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Whoop's /progression-service/v3/exercise/{id} mirrors the trend endpoint shape:
|
|
21
|
-
// {week,month,six_month,year}_time_segment with same metrics-array + graph layout.
|
|
22
|
-
// metrics array entry shape: { current_metric_value, previous_metric_value,
|
|
23
|
-
// metric_change, metric_units_display, metric_name_display, ... }
|
|
24
|
-
|
|
25
|
-
const NAMED_KEYS = [
|
|
26
|
-
"week_time_segment",
|
|
27
|
-
"month_time_segment",
|
|
28
|
-
"six_month_time_segment",
|
|
29
|
-
"year_time_segment",
|
|
30
|
-
] as const;
|
|
31
|
-
|
|
32
|
-
interface PointOut {
|
|
33
|
-
date: string;
|
|
34
|
-
volume: number | null;
|
|
35
|
-
reps: number | null;
|
|
36
|
-
top_weight: number | null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function parseDisplay(display: string | null, rawValue: unknown): number | null {
|
|
40
|
-
return labelToNumber(display) ?? timeLabelToMs(display) ?? asNumber(rawValue);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function extractPoints(graph: unknown): PointOut[] {
|
|
44
|
-
const g = isObject(graph) ? graph : {};
|
|
45
|
-
const out: PointOut[] = [];
|
|
46
|
-
for (const p of asArray(g.plots)) {
|
|
47
|
-
if (!isObject(p)) continue;
|
|
48
|
-
const plot = isObject(p.plot) ? (p.plot as Record<string, unknown>) : null;
|
|
49
|
-
if (!plot) continue;
|
|
50
|
-
for (const seg of asArray(plot.segments)) {
|
|
51
|
-
if (!isObject(seg)) continue;
|
|
52
|
-
for (const pt of asArray(seg.points)) {
|
|
53
|
-
if (!isObject(pt)) continue;
|
|
54
|
-
const dsd = isObject(pt.data_scrubber_details) ? (pt.data_scrubber_details as Record<string, unknown>) : {};
|
|
55
|
-
const graphLabel = isObject(pt.graph_label) ? (pt.graph_label as Record<string, unknown>) : null;
|
|
56
|
-
const labelStr = graphLabel ? asString(graphLabel.label) : null;
|
|
57
|
-
const valueDisplay = asString(dsd.value_display) ?? labelStr;
|
|
58
|
-
out.push({
|
|
59
|
-
date: asString(dsd.primary_contextual_display) ?? "",
|
|
60
|
-
volume: parseDisplay(valueDisplay, dsd.value),
|
|
61
|
-
reps: null,
|
|
62
|
-
top_weight: null,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// Bar plots: value + date live in bar_groups[].bars[].data_scrubber_details.
|
|
67
|
-
for (const grp of asArray(plot.bar_groups)) {
|
|
68
|
-
if (!isObject(grp)) continue;
|
|
69
|
-
const bars = asArray(grp.bars);
|
|
70
|
-
const topLabel = isObject(grp.top_label) ? asString((grp.top_label as Record<string, unknown>).label) : null;
|
|
71
|
-
const candidates = bars.length > 0 ? bars : [grp];
|
|
72
|
-
let chosen: { date: string; value_display: string | null; raw: unknown } | null = null;
|
|
73
|
-
for (const bar of candidates) {
|
|
74
|
-
if (!isObject(bar)) continue;
|
|
75
|
-
const dsd = isObject(bar.data_scrubber_details) ? (bar.data_scrubber_details as Record<string, unknown>) : {};
|
|
76
|
-
const vd = asString(dsd.value_display) ?? topLabel;
|
|
77
|
-
const cand = { date: asString(dsd.primary_contextual_display) ?? "", value_display: vd, raw: dsd.value };
|
|
78
|
-
if (chosen === null) chosen = cand;
|
|
79
|
-
if (vd !== null) { chosen = cand; break; }
|
|
80
|
-
}
|
|
81
|
-
if (chosen === null) continue;
|
|
82
|
-
out.push({
|
|
83
|
-
date: chosen.date,
|
|
84
|
-
volume: parseDisplay(chosen.value_display, chosen.raw),
|
|
85
|
-
reps: null,
|
|
86
|
-
top_weight: null,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return out;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function projectLiftProgression(raw: unknown, exerciseId: string, endDate: string): LiftProgressionOutT {
|
|
94
|
-
const root = isObject(raw) ? raw : {};
|
|
95
|
-
const segments: LiftProgressionOutT["segments"] = [];
|
|
96
|
-
|
|
97
|
-
function pushSeg(label: SegLabel, s: Record<string, unknown>) {
|
|
98
|
-
if (s.is_hidden === true) return;
|
|
99
|
-
const dp = isObject(s.date_picker) ? (s.date_picker as Record<string, unknown>) : {};
|
|
100
|
-
const metricsArr = asArray(s.metrics);
|
|
101
|
-
const m0 = isObject(metricsArr[0]) ? (metricsArr[0] as Record<string, unknown>) : null;
|
|
102
|
-
segments.push({
|
|
103
|
-
label,
|
|
104
|
-
start_date: asString(dp.current_date_range_display) ?? "",
|
|
105
|
-
end_date: asString(dp.next_date_time) ?? "",
|
|
106
|
-
avg_volume: m0 ? asNumber(m0.current_metric_value) : null,
|
|
107
|
-
delta_pct: m0 ? asNumber(m0.metric_change) : null,
|
|
108
|
-
unit: m0 ? asString(m0.metric_units_display) : null,
|
|
109
|
-
points: extractPoints(s.graph),
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (Array.isArray(root.time_segments)) {
|
|
114
|
-
// Label each segment from segment_controller.element_names (the windows this
|
|
115
|
-
// exercise actually has), falling back to positional order only if a code is
|
|
116
|
-
// unrecognized.
|
|
117
|
-
const controller = isObject(root.segment_controller) ? (root.segment_controller as Record<string, unknown>) : {};
|
|
118
|
-
const elementNames = asArray(controller.element_names).map((x) => asString(x));
|
|
119
|
-
const positional = ["week", "month", "six_month", "year"] as const;
|
|
120
|
-
for (const [i, s] of (root.time_segments as Record<string, unknown>[]).entries()) {
|
|
121
|
-
const code = elementNames[i];
|
|
122
|
-
const label = (code ? labelFromElementName(code) : null) ?? positional[i] ?? "year";
|
|
123
|
-
pushSeg(label, s);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
for (const k of NAMED_KEYS) {
|
|
127
|
-
const seg = root[k];
|
|
128
|
-
if (isObject(seg)) {
|
|
129
|
-
const label =
|
|
130
|
-
k.startsWith("week") ? "week" :
|
|
131
|
-
k.startsWith("month") ? "month" :
|
|
132
|
-
k.startsWith("six") ? "six_month" : "year";
|
|
133
|
-
pushSeg(label, seg as Record<string, unknown>);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return { exercise_id: exerciseId, end_date: endDate, segments };
|
|
138
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { LiftPrsOutT } from "../schemas/strength.js";
|
|
2
|
-
import { extractPrTiles, isObject, asArray, asString, asMedal } from "../lib/walk.js";
|
|
3
|
-
|
|
4
|
-
export function projectLiftPrs(raw: unknown): LiftPrsOutT {
|
|
5
|
-
const tiles = extractPrTiles(raw);
|
|
6
|
-
const rawTiles = isObject(raw) ? asArray((raw as Record<string, unknown>).tiles) : [];
|
|
7
|
-
return tiles.map((t) => {
|
|
8
|
-
const rawTile = rawTiles.find(
|
|
9
|
-
(x) => isObject(x) && (x as Record<string, unknown>).exercise_id === t.exercise_id,
|
|
10
|
-
);
|
|
11
|
-
return {
|
|
12
|
-
exercise_id: t.exercise_id,
|
|
13
|
-
name: t.name,
|
|
14
|
-
muscle_groups: t.muscle_groups,
|
|
15
|
-
equipment: t.equipment,
|
|
16
|
-
pr_value: t.pr_value,
|
|
17
|
-
pr_units: t.pr_units,
|
|
18
|
-
pr_date: isObject(rawTile) ? asString((rawTile as Record<string, unknown>).record_date) : null,
|
|
19
|
-
medal: isObject(rawTile) ? asMedal((rawTile as Record<string, unknown>).achievement_icon) : null,
|
|
20
|
-
custom_exercise: t.custom_exercise,
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { LiveHrOutT } from "../schemas/live.js";
|
|
2
|
-
import { isObject, asNumber, asString, asBool, findByType } from "../lib/walk.js";
|
|
3
|
-
|
|
4
|
-
export function projectLiveHr(raw: unknown): LiveHrOutT {
|
|
5
|
-
const root = isObject(raw) ? raw : {};
|
|
6
|
-
const showLive = asBool(root.show_live_hr) ?? false;
|
|
7
|
-
const hrTile =
|
|
8
|
-
findByType(root, "LIVE_HR") ??
|
|
9
|
-
findByType(root, "HEART_RATE_LIVE") ??
|
|
10
|
-
findByType(root, "LIVE_HEART_RATE_TILE");
|
|
11
|
-
const bpmRaw = hrTile ? asNumber(hrTile.value ?? hrTile.bpm) : null;
|
|
12
|
-
const bpm = bpmRaw !== null ? Math.round(bpmRaw) : null;
|
|
13
|
-
const zone = hrTile ? asNumber(hrTile.zone) : null;
|
|
14
|
-
return {
|
|
15
|
-
current_bpm: bpm,
|
|
16
|
-
hr_zone: zone !== null && zone >= 0 && zone <= 5 ? zone : null,
|
|
17
|
-
is_recording: bpm !== null && showLive,
|
|
18
|
-
last_updated_at: hrTile ? asString(hrTile.updated_at ?? hrTile.timestamp) : null,
|
|
19
|
-
show_live_hr: showLive,
|
|
20
|
-
};
|
|
21
|
-
}
|