@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,277 @@
|
|
|
1
|
+
// Women's health (SPEC.md D10, §4.9; specs/health.md §2.2). Pure projections over:
|
|
2
|
+
// GET /womens-health-service/v1/hormonal-insights/overview?date= (LIST of items)
|
|
3
|
+
// GET /womens-health-service/v1/menstrual-cycle-insights?date= (old tiles[] BFF, fallback)
|
|
4
|
+
// GET …/hormonal-insights/settings, …/menstrual-cycle-insights/cycles, …/symptoms
|
|
5
|
+
// GET …/symptom-insights/log/symptoms/screen?requestDate= (day log + live enums)
|
|
6
|
+
// Both overview forms carry HEADER_TILE, a calendar and TYPICAL_CYCLE_TILE; in the old
|
|
7
|
+
// form the stats tile sits inside MCI_TILE_SECTION.content.items[], so everything is
|
|
8
|
+
// found by type with the BFF walker, never by position. Calendar `cycle_id`s are dropped.
|
|
9
|
+
import type {
|
|
10
|
+
CycleCalendarT,
|
|
11
|
+
CycleEntryT,
|
|
12
|
+
CycleSummaryT,
|
|
13
|
+
DayLogT,
|
|
14
|
+
HormonalSettingsT,
|
|
15
|
+
SymptomInputT,
|
|
16
|
+
SymptomSegmentT,
|
|
17
|
+
} from "../schemas/hormonal_insights.js";
|
|
18
|
+
import { byId, byType, findAll, get, parseNumber, str, type Node } from "../whoop/bff.js";
|
|
19
|
+
|
|
20
|
+
const isObj = (v: unknown): v is Node => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
21
|
+
const arr = (v: unknown): unknown[] => (Array.isArray(v) ? v : []);
|
|
22
|
+
const bool = (v: unknown): boolean | null => (typeof v === "boolean" ? v : null);
|
|
23
|
+
const int = (re: RegExp, s: string | null): number | null => {
|
|
24
|
+
const m = s?.match(re);
|
|
25
|
+
return m ? Number(m[1]) : null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Calendar days from either form: typed HORMONAL_INSIGHTS_CALENDAR_DAY items or CALENDAR_TILE rows. */
|
|
29
|
+
function calendarDays(raw: unknown): Node[] {
|
|
30
|
+
const typed = byType(raw, "HORMONAL_INSIGHTS_CALENDAR_DAY")
|
|
31
|
+
.map((d) => d.content)
|
|
32
|
+
.filter(isObj);
|
|
33
|
+
if (typed.length) return typed;
|
|
34
|
+
const tile = byType(raw, "CALENDAR_TILE")[0];
|
|
35
|
+
return arr(get(tile, "content", "calendar", "days_of_month")).filter(isObj);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function statValue(stats: unknown, title: RegExp): number | null {
|
|
39
|
+
for (const s of arr(stats)) {
|
|
40
|
+
if (isObj(s) && title.test(str(s.title_display) ?? "")) return parseNumber(s.value_display);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function tags(raw: unknown, id: string): string[] {
|
|
46
|
+
return arr(get(byId(raw, id), "tags"))
|
|
47
|
+
.map((t) => (isObj(t) ? str(t.title) : null))
|
|
48
|
+
.filter((t): t is string => t !== null);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function projectCycleSummary(raw: unknown, date: string): CycleSummaryT {
|
|
52
|
+
const header = byType(raw, "HEADER_TILE")[0];
|
|
53
|
+
const h = isObj(header?.content) ? header.content : null;
|
|
54
|
+
const title = h ? str(h.title_display) : null;
|
|
55
|
+
const subtitle = h ? str(h.subtitle_display) : null;
|
|
56
|
+
const description = h ? str(h.description_display) : null;
|
|
57
|
+
const nextText = [description, subtitle].find((s) => s && /next period/i.test(s)) ?? null;
|
|
58
|
+
const range = nextText?.match(/(\d+)(?:\s*[-–]\s*(\d+))?\s*day/i);
|
|
59
|
+
const stats = get(byType(raw, "TYPICAL_CYCLE_TILE")[0], "content", "stats");
|
|
60
|
+
const today = calendarDays(raw).find((d) => d.date === date);
|
|
61
|
+
return {
|
|
62
|
+
status: title,
|
|
63
|
+
detail: description && description !== nextText ? description : null,
|
|
64
|
+
phase: h ? str(h.style) : null,
|
|
65
|
+
cycle_day: int(/cycle day\s+(\d+)/i, title),
|
|
66
|
+
period_day: int(/period day\s+(\d+)/i, title),
|
|
67
|
+
next_period: nextText
|
|
68
|
+
? { min_days: range ? Number(range[1]) : null, max_days: range ? Number(range[2] ?? range[1]) : null }
|
|
69
|
+
: null,
|
|
70
|
+
today: today ? { state: str(today.day_state), phase: str(today.phase), symptoms: today.bottom_state === "SYMPTOMS" } : null,
|
|
71
|
+
journal: {
|
|
72
|
+
symptoms: tags(raw, "cycle_journal_symptom_tile"),
|
|
73
|
+
period: tags(raw, "cycle_journal_period_tile"),
|
|
74
|
+
ovulation: tags(raw, "cycle_journal_ovulation_tile"),
|
|
75
|
+
},
|
|
76
|
+
typical: {
|
|
77
|
+
period_days: statValue(stats, /PERIOD LENGTH/i),
|
|
78
|
+
cycle_days: statValue(stats, /CYCLE LENGTH/i),
|
|
79
|
+
variation_days: statValue(stats, /VARIATION/i),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The month as runs of consecutive days sharing a state and phase. */
|
|
85
|
+
export function projectCycleCalendar(raw: unknown): CycleCalendarT | null {
|
|
86
|
+
const days = calendarDays(raw)
|
|
87
|
+
.map((d) => ({ date: str(d.date), state: str(d.day_state), phase: str(d.phase), symptoms: d.bottom_state === "SYMPTOMS" }))
|
|
88
|
+
.filter((d): d is { date: string; state: string | null; phase: string | null; symptoms: boolean } =>
|
|
89
|
+
d.date !== null && /^\d{4}-\d{2}-\d{2}$/.test(d.date))
|
|
90
|
+
.sort((a, b) => a.date.localeCompare(b.date));
|
|
91
|
+
if (!days.length) return null;
|
|
92
|
+
const month = days[0]!.date.slice(0, 7);
|
|
93
|
+
const runs: CycleCalendarT["runs"] = [];
|
|
94
|
+
for (const d of days) {
|
|
95
|
+
if (d.date.slice(0, 7) !== month) continue;
|
|
96
|
+
const day = Number(d.date.slice(8, 10));
|
|
97
|
+
const last = runs[runs.length - 1];
|
|
98
|
+
if (last && last[1] === day - 1 && last[2] === d.state && last[3] === d.phase) last[1] = day;
|
|
99
|
+
else runs.push([day, day, d.state, d.phase]);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
month,
|
|
103
|
+
runs,
|
|
104
|
+
symptom_days: days.filter((d) => d.symptoms && d.date.startsWith(month)).map((d) => Number(d.date.slice(8, 10))),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function sameDate(value: unknown, date: string): boolean {
|
|
109
|
+
if (typeof value === "string") return value === date;
|
|
110
|
+
if (Array.isArray(value) && value.length === 3) {
|
|
111
|
+
return `${value[0]}-${String(value[1]).padStart(2, "0")}-${String(value[2]).padStart(2, "0")}` === date;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* What is logged on `date`, from an overview selected on that date:
|
|
118
|
+
* - period_day: the calendar day is PERIOD (a logged period day, not a prediction);
|
|
119
|
+
* - ovulation_logged: the ovulation tile's toggle action. When ovulation is logged
|
|
120
|
+
* the app's action is the REMOVE body (ovulation answered_yes:false); otherwise it
|
|
121
|
+
* is the LOG body (ovulation answered_yes:true). null when not determinable.
|
|
122
|
+
*/
|
|
123
|
+
export function loggedOnDate(raw: unknown, date: string): { period_day: boolean | null; ovulation_logged: boolean | null } {
|
|
124
|
+
const day = calendarDays(raw).find((d) => d.date === date);
|
|
125
|
+
let ovulation: boolean | null = null;
|
|
126
|
+
const tile = byId(raw, "cycle_journal_ovulation_tile");
|
|
127
|
+
for (const n of findAll(tile, (x) => Array.isArray(x.period_logs))) {
|
|
128
|
+
const entry = arr(n.period_logs).find((e) => isObj(e) && sameDate(e.date, date));
|
|
129
|
+
const yes = isObj(entry) ? get(entry, "ovulation", "answered_yes") : undefined;
|
|
130
|
+
if (typeof yes === "boolean") ovulation = !yes;
|
|
131
|
+
}
|
|
132
|
+
return { period_day: day ? day.day_state === "PERIOD" : null, ovulation_logged: ovulation };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function projectHormonalSettings(raw: unknown): HormonalSettingsT {
|
|
136
|
+
const root = isObj(raw) ? raw : {};
|
|
137
|
+
const toggle = (type: string): boolean | null => {
|
|
138
|
+
const t = byType(root.tiles, "SETTINGS_TOGGLE").find((x) => get(x, "content", "type") === type);
|
|
139
|
+
return bool(get(t, "content", "enabled"));
|
|
140
|
+
};
|
|
141
|
+
const selected = (drawer: unknown, flag: "selected" | "is_selected"): string[] =>
|
|
142
|
+
arr(get(drawer, "options"))
|
|
143
|
+
.filter((o) => isObj(o) && o[flag] === true)
|
|
144
|
+
.map((o) => str((o as Node).value))
|
|
145
|
+
.filter((v): v is string => v !== null);
|
|
146
|
+
return {
|
|
147
|
+
enabled: toggle("HORMONAL_INSIGHTS"),
|
|
148
|
+
trends_overlay: toggle("MENSTRUAL_CYCLE_TRENDS_OVERLAY"),
|
|
149
|
+
mode: selected(root.hormonal_insights_mode_drawer, "selected")[0] ?? null,
|
|
150
|
+
contraception: selected(root.contraception_type_drawer, "selected")[0] ?? null,
|
|
151
|
+
goals: selected(root.goals_drawer, "is_selected"),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function projectCycles(raw: unknown): CycleEntryT[] {
|
|
156
|
+
return findAll(raw, (n) => isObj(n.cycle) && isObj(get(n, "cycle", "header"))).map((item) => {
|
|
157
|
+
const label = str(get(item, "cycle", "header", "subtitle_display"));
|
|
158
|
+
const sheet = get(item, "bottom_sheet");
|
|
159
|
+
const rangeDates = arr(get(sheet, "hide_option", "date_range") ?? get(sheet, "unhide_option", "date_range"));
|
|
160
|
+
const iso = (v: unknown): string | null => (typeof v === "string" && /^\d{4}-\d{2}-\d{2}$/.test(v) ? v : null);
|
|
161
|
+
return {
|
|
162
|
+
start: iso(get(sheet, "edit_option", "date")) ?? iso(rangeDates[0]),
|
|
163
|
+
end: iso(rangeDates[1]),
|
|
164
|
+
days: int(/(\d+)\s*day/i, label),
|
|
165
|
+
period_days: arr(get(item, "cycle", "tick_marks")).filter((t) => isObj(t) && t.style === "MENSTRUAL").length,
|
|
166
|
+
current: /current/i.test(label ?? ""),
|
|
167
|
+
hidden: item.hidden === true,
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function symptomSegment(seg: unknown): SymptomSegmentT | null {
|
|
173
|
+
if (!isObj(seg)) return null;
|
|
174
|
+
const header = byType(seg.tiles, "HEADER_TILE")[0];
|
|
175
|
+
return {
|
|
176
|
+
logged: parseNumber(get(header, "content", "title_display")),
|
|
177
|
+
rows: byType(seg.tiles, "DAILY_TICK_MARK").flatMap((row) => {
|
|
178
|
+
// The first row is the phase strip (no header); the rest are one symptom each.
|
|
179
|
+
const name = str(get(row, "content", "header", "subtitle_display"));
|
|
180
|
+
if (!name) return [];
|
|
181
|
+
return [{
|
|
182
|
+
name,
|
|
183
|
+
logs: parseNumber(get(row, "content", "header", "right_aligned_description")),
|
|
184
|
+
next: str(get(row, "content", "footer", "title")),
|
|
185
|
+
}];
|
|
186
|
+
}),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function projectSymptomPatterns(raw: unknown) {
|
|
191
|
+
const root = isObj(raw) ? raw : {};
|
|
192
|
+
return {
|
|
193
|
+
current: symptomSegment(root.current_cycle_segment),
|
|
194
|
+
last_3: symptomSegment(root.last_three_cycles_segment),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface ScreenTracker {
|
|
199
|
+
id: number;
|
|
200
|
+
name: string;
|
|
201
|
+
group: string | null;
|
|
202
|
+
magnitude: { type: "step"; choices: number[] } | { type: "range"; min: number; max: number } | null;
|
|
203
|
+
input: SymptomInputT | null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface SymptomScreen {
|
|
207
|
+
menstruation: string | null;
|
|
208
|
+
cervical_mucus: string | null;
|
|
209
|
+
options: { menstruation: string[]; cervical_mucus: string[] };
|
|
210
|
+
trackers: ScreenTracker[];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function cellList(raw: unknown, id: string): { options: string[]; selected: string | null } {
|
|
214
|
+
const list = byType(raw, "SELECTABLE_CELL_LIST").find((l) => get(l, "content", "id") === id);
|
|
215
|
+
const cells = arr(get(list, "content", "cells")).filter(isObj);
|
|
216
|
+
return {
|
|
217
|
+
options: cells.map((c) => str(c.id)).filter((v): v is string => v !== null),
|
|
218
|
+
selected: str(cells.find((c) => c.selected === true)?.id),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** The symptom log screen: the day's selections and the live enums / tracker specs. */
|
|
223
|
+
export function projectSymptomScreen(raw: unknown): SymptomScreen {
|
|
224
|
+
const state = get(raw, "lifecycle_interactions", "on_start", "action", "parameters", "state");
|
|
225
|
+
const flow = cellList(raw, "menstruation");
|
|
226
|
+
const mucus = cellList(raw, "cervical_mucus");
|
|
227
|
+
const trackers: ScreenTracker[] = [];
|
|
228
|
+
const sections = arr(get(raw, "content", "item", "content", "items"));
|
|
229
|
+
const groups = sections.length ? sections : [raw];
|
|
230
|
+
for (const section of groups) {
|
|
231
|
+
const group = isObj(section) ? str(section.type) : null;
|
|
232
|
+
for (const t of byType(section, "TRACKED_BEHAVIOR")) {
|
|
233
|
+
const bt = get(t, "content", "behavior_tracker");
|
|
234
|
+
const id = get(bt, "id");
|
|
235
|
+
const name = str(get(bt, "title"));
|
|
236
|
+
if (typeof id !== "number" || !name || trackers.some((x) => x.id === id)) continue;
|
|
237
|
+
const mag = get(bt, "magnitude");
|
|
238
|
+
const choices = arr(get(mag, "choices")).map((c) => get(c, "value")).filter((v): v is number => typeof v === "number");
|
|
239
|
+
const min = get(mag, "minimum_inclusive");
|
|
240
|
+
const max = get(mag, "maximum_inclusive");
|
|
241
|
+
const ti = get(t, "content", "tracker_input");
|
|
242
|
+
trackers.push({
|
|
243
|
+
id,
|
|
244
|
+
name,
|
|
245
|
+
group: group && group !== "SINGLE_ITEM" ? group : null,
|
|
246
|
+
magnitude: get(mag, "type") === "step" && choices.length
|
|
247
|
+
? { type: "step", choices }
|
|
248
|
+
: typeof min === "number" && typeof max === "number"
|
|
249
|
+
? { type: "range", min, max }
|
|
250
|
+
: null,
|
|
251
|
+
input: isObj(ti)
|
|
252
|
+
? {
|
|
253
|
+
id,
|
|
254
|
+
name,
|
|
255
|
+
yes: bool(ti.answered_yes),
|
|
256
|
+
mag: typeof ti.magnitude_input_value === "number" ? ti.magnitude_input_value : null,
|
|
257
|
+
}
|
|
258
|
+
: null,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
menstruation: flow.selected ?? str(get(state, "$menstruation_id")),
|
|
264
|
+
cervical_mucus: mucus.selected ?? str(get(state, "$cervical_mucus_id")),
|
|
265
|
+
options: { menstruation: flow.options, cervical_mucus: mucus.options },
|
|
266
|
+
trackers,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Answered symptom rows (yes:false = removed but still stored). */
|
|
271
|
+
export function answeredSymptoms(screen: SymptomScreen): SymptomInputT[] {
|
|
272
|
+
return screen.trackers.flatMap((t) => (t.input && t.input.yes !== null ? [t.input] : []));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function dayLogFromScreen(screen: SymptomScreen): DayLogT {
|
|
276
|
+
return { flow: screen.menstruation, mucus: screen.cervical_mucus, symptoms: answeredSymptoms(screen) };
|
|
277
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// whoop_journal projections: the day's answered rows, the live behaviour
|
|
2
|
+
// catalog (compact, filtered), and behaviour impact (personal or member-average).
|
|
3
|
+
import type { z } from "zod";
|
|
4
|
+
import type { BehaviorCatalogRow, BehaviorImpactRow, JournalAnsweredRow } from "../schemas/journal_v2.js";
|
|
5
|
+
import {
|
|
6
|
+
describeChoices,
|
|
7
|
+
isAnswered,
|
|
8
|
+
similarity,
|
|
9
|
+
type BehaviorCatalog,
|
|
10
|
+
type BehaviorSpec,
|
|
11
|
+
type DraftDay,
|
|
12
|
+
type StoredInput,
|
|
13
|
+
} from "../lib/journal_behaviors.js";
|
|
14
|
+
import { parseNumber } from "../whoop/bff.js";
|
|
15
|
+
import { asArray, asString, isObject } from "../lib/walk.js";
|
|
16
|
+
|
|
17
|
+
type AnsweredRow = z.infer<typeof JournalAnsweredRow>;
|
|
18
|
+
type CatalogRow = z.infer<typeof BehaviorCatalogRow>;
|
|
19
|
+
type ImpactRow = z.infer<typeof BehaviorImpactRow>;
|
|
20
|
+
|
|
21
|
+
export function answeredRow(spec: BehaviorSpec, input: StoredInput): AnsweredRow {
|
|
22
|
+
const step = spec.magnitude?.type === "step";
|
|
23
|
+
const value = input.magnitude_input_value;
|
|
24
|
+
return {
|
|
25
|
+
id: spec.id,
|
|
26
|
+
name: spec.title,
|
|
27
|
+
yes: input.answered_yes,
|
|
28
|
+
value,
|
|
29
|
+
label: value !== null && step ? input.magnitude_input_label ?? spec.magnitude!.choices.find((c) => c.value === value)?.label ?? null : null,
|
|
30
|
+
unit: value !== null ? spec.magnitude?.units ?? null : null,
|
|
31
|
+
time: input.time_input_value === null ? null : new Date(input.time_input_value * 1000).toISOString(),
|
|
32
|
+
src: input.source === "AI" ? "AI" : null,
|
|
33
|
+
ever_ai: input.ever_ai_sourced === true && input.source !== "AI" ? true : null,
|
|
34
|
+
custom: spec.custom ? true : null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function projectJournalDay(day: DraftDay, opts: { includeUnanswered?: boolean } = {}) {
|
|
39
|
+
const answered: AnsweredRow[] = [];
|
|
40
|
+
const unanswered: Array<[number, string]> = [];
|
|
41
|
+
for (const { spec, input } of day.rows) {
|
|
42
|
+
if (isAnswered(input)) answered.push(answeredRow(spec, input));
|
|
43
|
+
else unanswered.push([spec.id, spec.title]);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
date: day.date,
|
|
47
|
+
reviewed: day.user_reviewed,
|
|
48
|
+
notes: day.notes,
|
|
49
|
+
answered,
|
|
50
|
+
...(opts.includeUnanswered ? { unanswered } : {}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function catalogRow(s: BehaviorSpec, detail: boolean): CatalogRow {
|
|
55
|
+
const m = s.magnitude;
|
|
56
|
+
const row: CatalogRow = {
|
|
57
|
+
id: s.id,
|
|
58
|
+
name: s.title,
|
|
59
|
+
type: m ? m.type : "yn",
|
|
60
|
+
time: s.time_label ? true : null,
|
|
61
|
+
custom: s.custom ? true : null,
|
|
62
|
+
tracked: s.tracked === false ? false : null,
|
|
63
|
+
};
|
|
64
|
+
if (detail) {
|
|
65
|
+
row.unit = m?.units ?? null;
|
|
66
|
+
row.min = m?.type === "range" ? m.minimum : null;
|
|
67
|
+
row.max = m?.type === "range" ? m.maximum : null;
|
|
68
|
+
row.choices = m?.type === "step" ? describeChoices(m) : null;
|
|
69
|
+
row.time_q = s.time_label;
|
|
70
|
+
}
|
|
71
|
+
return row;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The catalog, filtered by search (name, internal name or category) and/or
|
|
76
|
+
* category. Unfiltered calls get the category counts and a short first page.
|
|
77
|
+
*/
|
|
78
|
+
export function projectBehaviorCatalog(
|
|
79
|
+
catalog: BehaviorCatalog,
|
|
80
|
+
filter: { search?: string | undefined; category?: string | undefined; detail?: boolean },
|
|
81
|
+
) {
|
|
82
|
+
const all = [...catalog.specs.values()].sort((a, b) =>
|
|
83
|
+
Number(b.tracked !== false) - Number(a.tracked !== false) || a.title.localeCompare(b.title));
|
|
84
|
+
const q = filter.search?.trim().toLowerCase();
|
|
85
|
+
const cat = filter.category?.trim().toLowerCase();
|
|
86
|
+
let matches = cat ? all.filter((s) => (s.category ?? "").toLowerCase().includes(cat)) : all;
|
|
87
|
+
if (q) {
|
|
88
|
+
const direct = matches.filter((s) =>
|
|
89
|
+
s.title.toLowerCase().includes(q) || (s.internal_name ?? "").toLowerCase().includes(q) || (s.category ?? "").toLowerCase().includes(q));
|
|
90
|
+
matches = direct.length > 0
|
|
91
|
+
? direct
|
|
92
|
+
: matches.map((s) => ({ s, score: Math.max(similarity(q, s.title), similarity(q, s.internal_name ?? "")) }))
|
|
93
|
+
.filter((x) => x.score > 0.45).sort((a, b) => b.score - a.score).map((x) => x.s);
|
|
94
|
+
}
|
|
95
|
+
const filtered = Boolean(q || cat);
|
|
96
|
+
const limit = filtered ? 80 : 30;
|
|
97
|
+
let categories: Record<string, number> | null = null;
|
|
98
|
+
if (!filtered) {
|
|
99
|
+
categories = {};
|
|
100
|
+
for (const s of all) if (s.category) categories[s.category] = (categories[s.category] ?? 0) + 1;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
source: catalog.source === "bundled" ? "bundled" as const : null,
|
|
104
|
+
total: all.length,
|
|
105
|
+
matched: matches.length,
|
|
106
|
+
truncated: matches.length > limit ? true as const : null,
|
|
107
|
+
categories,
|
|
108
|
+
rows: matches.slice(0, limit).map((s) => catalogRow(s, filter.detail === true)),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function direction(style: string | null): ImpactRow["dir"] {
|
|
113
|
+
const s = (style ?? "").toUpperCase();
|
|
114
|
+
if (s === "INSUFFICIENT") return "insufficient";
|
|
115
|
+
if (s.startsWith("NEGLIGIBLE")) return "neutral";
|
|
116
|
+
if (s.endsWith("POSITIVE")) return "positive";
|
|
117
|
+
if (s.endsWith("NEGATIVE")) return "negative";
|
|
118
|
+
return "neutral";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** A member-average block: "WHOOP members discovered" (HEADER_ITEMS_CARD, MEMBERS_LIKE_YOU). */
|
|
122
|
+
function isMemberBlock(node: Record<string, unknown>): boolean {
|
|
123
|
+
const content = isObject(node.content) ? node.content : {};
|
|
124
|
+
return node.type === "HEADER_ITEMS_CARD"
|
|
125
|
+
|| content.title_icon === "MEMBERS_LIKE_YOU"
|
|
126
|
+
|| /members/i.test(asString(content.title) ?? "");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* GET /behavior-impact-service/v1/impact. Established accounts put personal
|
|
131
|
+
* cards in `tiles[].content.impact_cards`; new accounts nest member-average
|
|
132
|
+
* "recommended" cards under `HEADER_ITEMS_CARD.content.items[].content`. Walk
|
|
133
|
+
* the whole tree and mark which kind each card is.
|
|
134
|
+
*/
|
|
135
|
+
export function projectBehaviorImpacts(raw: unknown) {
|
|
136
|
+
const rows: Array<ImpactRow & { uuid: string | null }> = [];
|
|
137
|
+
const seen = new Set<string>();
|
|
138
|
+
const visit = (node: unknown, rec: boolean, insufficient: boolean): void => {
|
|
139
|
+
if (Array.isArray(node)) {
|
|
140
|
+
for (const n of node) visit(n, rec, insufficient);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!isObject(node)) return;
|
|
144
|
+
const recHere = rec || isMemberBlock(node);
|
|
145
|
+
const insuffHere = insufficient || node.type === "INSUFFICIENT_IMPACT_TILE";
|
|
146
|
+
const title = asString(node.impact_card_title_display);
|
|
147
|
+
if (title !== null && ("impact_uuid" in node || "impact_style" in node)) {
|
|
148
|
+
const uuid = asString(node.impact_uuid);
|
|
149
|
+
const key = `${uuid ?? title}|${recHere}`;
|
|
150
|
+
if (!seen.has(key)) {
|
|
151
|
+
seen.add(key);
|
|
152
|
+
const pct = parseNumber(node.impact_percentage_display);
|
|
153
|
+
const dir = direction(asString(node.impact_style));
|
|
154
|
+
rows.push({
|
|
155
|
+
id: recHere ? null : uuid,
|
|
156
|
+
uuid,
|
|
157
|
+
name: title,
|
|
158
|
+
pct,
|
|
159
|
+
dir: insuffHere && pct === null ? "insufficient" : dir,
|
|
160
|
+
rec: recHere ? true : null,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
for (const v of Object.values(node)) visit(v, recHere, insuffHere);
|
|
166
|
+
};
|
|
167
|
+
visit(isObject(raw) ? asArray(raw.tiles) : [], false, false);
|
|
168
|
+
return {
|
|
169
|
+
personal: rows.filter((r) => r.rec === null).length,
|
|
170
|
+
// uuid kept internally to recognise a member card passed as impact_id.
|
|
171
|
+
rows,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Parsers for the Strength Trainer card screens shared by whoop_lift_sessions and
|
|
2
|
+
// whoop_lift_exercise: GET /weightlifting-service/v3/exercise/{id}/exercise_history
|
|
3
|
+
// and …/personal_records. Both return EXPANDABLE_CARDs, one per workout (history)
|
|
4
|
+
// or per medal (records):
|
|
5
|
+
// header_content.EXERCISE_RECORD_HEADER{record_title{value,unit}, record_subtitle, achievement_icon, record_date}
|
|
6
|
+
// expanded_content[EXERCISE_BREAKDOWN{table_titles ["REPS","WEIGHT"]|["TIME","WEIGHT"], rows[].items[]{value, units, achievement_icon}},
|
|
7
|
+
// EXERCISE_BREAKDOWN{table_titles ["TOTAL"]}, CARD_BUTTON → destination.parameters.activity_id]
|
|
8
|
+
// Values are display strings in the account's current unit ("209" + "lbs", "5:00" + "min", "1,000").
|
|
9
|
+
import { byType, get, parseNumber, str, type Node } from "../whoop/bff.js";
|
|
10
|
+
|
|
11
|
+
export type MedalT = "GOLD" | "SILVER" | "BRONZE";
|
|
12
|
+
|
|
13
|
+
export function medal(icon: unknown): MedalT | null {
|
|
14
|
+
if (icon === "BADGE_GOLD") return "GOLD";
|
|
15
|
+
if (icon === "BADGE_SILVER") return "SILVER";
|
|
16
|
+
if (icon === "BADGE_BRONZE") return "BRONZE";
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** "lbs" / "lb" → "lb", "kg" → "kg"; anything else (reps, min, null) → null. */
|
|
21
|
+
export function weightUnit(u: unknown): "kg" | "lb" | null {
|
|
22
|
+
if (typeof u !== "string") return null;
|
|
23
|
+
if (/^kgs?$/i.test(u.trim())) return "kg";
|
|
24
|
+
if (/^lbs?$/i.test(u.trim())) return "lb";
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Lift time displays are m:ss ("5:00" = 5 min) or h:mm:ss. "--" / "" → null. */
|
|
29
|
+
export function clockSeconds(display: unknown): number | null {
|
|
30
|
+
if (typeof display !== "string") return null;
|
|
31
|
+
const m = display.trim().match(/^(?:(\d+):)?(\d+):(\d{2})$/);
|
|
32
|
+
if (!m) return null;
|
|
33
|
+
return Number(m[1] ?? 0) * 3600 + Number(m[2]) * 60 + Number(m[3]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const MONTHS = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
|
|
37
|
+
|
|
38
|
+
/** "November 21, 2026" / "Nov 21, 2026" / "· Nov 21, 2026" → "2026-11-21"; null if unparseable. */
|
|
39
|
+
export function displayDate(display: unknown): string | null {
|
|
40
|
+
if (typeof display !== "string") return null;
|
|
41
|
+
const m = display.match(/([A-Za-z]{3,})\.?\s+(\d{1,2}),\s*(\d{4})/);
|
|
42
|
+
if (!m) return null;
|
|
43
|
+
const idx = MONTHS.findIndex((name) => name.startsWith(m[1]!.toLowerCase()));
|
|
44
|
+
if (idx < 0) return null;
|
|
45
|
+
return `${m[3]}-${String(idx + 1).padStart(2, "0")}-${m[2]!.padStart(2, "0")}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface CardSet {
|
|
49
|
+
reps: number | null;
|
|
50
|
+
time_seconds: number | null;
|
|
51
|
+
weight: number | null;
|
|
52
|
+
unit: "kg" | "lb" | null;
|
|
53
|
+
medal: MedalT | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface LiftCard {
|
|
57
|
+
date: string | null;
|
|
58
|
+
activity_id: string | null;
|
|
59
|
+
medal: MedalT | null;
|
|
60
|
+
/** The card's headline record, e.g. {value: 209, unit: "lbs"} or {value: 8, unit: "reps"}. */
|
|
61
|
+
record: { value: number | null; display: string | null; unit: string | null };
|
|
62
|
+
sets: CardSet[];
|
|
63
|
+
total: { reps: number | null; time_seconds: number | null; volume: number | null; unit: "kg" | "lb" | null };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function cellValue(item: unknown): { value: string | null; units: string | null; medal: MedalT | null } {
|
|
67
|
+
return { value: str(get(item, "value")), units: str(get(item, "units")), medal: medal(get(item, "achievement_icon")) };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseBreakdownRow(titles: string[], items: unknown[]): CardSet {
|
|
71
|
+
const set: CardSet = { reps: null, time_seconds: null, weight: null, unit: null, medal: null };
|
|
72
|
+
titles.forEach((title, i) => {
|
|
73
|
+
const cell = cellValue(items[i]);
|
|
74
|
+
set.medal = set.medal ?? cell.medal;
|
|
75
|
+
const t = title.toUpperCase();
|
|
76
|
+
if (t === "REPS") set.reps = parseNumber(cell.value);
|
|
77
|
+
else if (t === "TIME") set.time_seconds = clockSeconds(cell.value);
|
|
78
|
+
else if (t === "WEIGHT") {
|
|
79
|
+
set.weight = parseNumber(cell.value);
|
|
80
|
+
set.unit = weightUnit(cell.units);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return set;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** One EXPANDABLE_CARD → a workout's sets for one exercise. */
|
|
87
|
+
export function parseLiftCard(card: Node): LiftCard {
|
|
88
|
+
const header = (byType(card, "EXERCISE_RECORD_HEADER")[0]?.content ?? {}) as Node;
|
|
89
|
+
const breakdowns = byType(card, "EXERCISE_BREAKDOWN").map((b) => (b.content ?? {}) as Node);
|
|
90
|
+
const titlesOf = (b: Node): string[] => (Array.isArray(b.table_titles) ? b.table_titles.filter((t): t is string => typeof t === "string") : []);
|
|
91
|
+
const setTable = breakdowns.find((b) => !titlesOf(b).includes("TOTAL"));
|
|
92
|
+
const totalTable = breakdowns.find((b) => titlesOf(b).includes("TOTAL"));
|
|
93
|
+
const columns = setTable ? titlesOf(setTable) : [];
|
|
94
|
+
const rows = (Array.isArray(setTable?.rows) ? setTable.rows : []) as Node[];
|
|
95
|
+
const sets = rows.map((r) => parseBreakdownRow(columns, Array.isArray(r.items) ? r.items : []));
|
|
96
|
+
|
|
97
|
+
// The TOTAL row uses the set table's columns: [reps|time total, weight total].
|
|
98
|
+
const totalItems = (get(totalTable, "rows", 0, "items") ?? []) as unknown[];
|
|
99
|
+
const firstTotal = cellValue(totalItems[0]);
|
|
100
|
+
const secondTotal = cellValue(totalItems[1]);
|
|
101
|
+
const timeBased = columns[0]?.toUpperCase() === "TIME";
|
|
102
|
+
const button = byType(card, "CARD_BUTTON").find((b) => typeof get(b, "content", "destination", "parameters", "activity_id") === "string");
|
|
103
|
+
const title = get(header, "record_title");
|
|
104
|
+
const titleValue = str(get(title, "value"));
|
|
105
|
+
return {
|
|
106
|
+
date: displayDate(get(header, "record_date")),
|
|
107
|
+
activity_id: (get(button, "content", "destination", "parameters", "activity_id") as string | undefined) ?? null,
|
|
108
|
+
medal: medal(get(header, "achievement_icon")),
|
|
109
|
+
record: {
|
|
110
|
+
value: str(get(title, "unit")) === "min" ? clockSeconds(titleValue) : parseNumber(titleValue),
|
|
111
|
+
display: titleValue && str(get(title, "unit")) ? `${titleValue} ${str(get(title, "unit"))}` : titleValue,
|
|
112
|
+
unit: str(get(title, "unit")) === "min" ? "s" : (weightUnit(get(title, "unit")) ?? str(get(title, "unit"))),
|
|
113
|
+
},
|
|
114
|
+
sets,
|
|
115
|
+
total: {
|
|
116
|
+
reps: timeBased ? null : parseNumber(firstTotal.value),
|
|
117
|
+
time_seconds: timeBased ? clockSeconds(firstTotal.value) : null,
|
|
118
|
+
volume: parseNumber(secondTotal.value),
|
|
119
|
+
unit: weightUnit(secondTotal.units),
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** exercise_history / personal_records → cards plus the `startDate` cursor for the next (older) page. */
|
|
125
|
+
export function parseLiftCards(raw: unknown): { cards: LiftCard[]; next_cursor: string | null } {
|
|
126
|
+
const items = (Array.isArray(get(raw, "items")) ? get(raw, "items") : []) as unknown[];
|
|
127
|
+
const cards = items
|
|
128
|
+
.filter((it): it is Node => typeof it === "object" && it !== null && (it as Node).type === "EXPANDABLE_CARD")
|
|
129
|
+
.map(parseLiftCard);
|
|
130
|
+
return { cards, next_cursor: str(get(raw, "show_more", "next_start_date")) };
|
|
131
|
+
}
|