@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,133 @@
|
|
|
1
|
+
// Milestones and the data streak (SPEC.md §4.7; specs/discovery.md §2.13), via the BFF walker.
|
|
2
|
+
// GET /milestones-service/v1/bff/milestones/hub: a header ROW of MARKDOWN_TEXT value/label
|
|
3
|
+
// pairs (Total / Unique / Rare), then TAG_SELECTOR.content.tag_maps[tag] →
|
|
4
|
+
// CELEBRATION_MEDIA_WITH_CAPTION{caption_text, media.text_overlay (count),
|
|
5
|
+
// sub_caption_text ("Top 18%" | "**1** of 5"), destination.parameters.milestone_type}.
|
|
6
|
+
// Tags: all, sleep, recovery, strain, healthspan, other, activities ("all" repeats the rest).
|
|
7
|
+
// GET …/milestones/{type}/details: TITLE_SUBTITLE, CELEBRATION_MEDIA (count),
|
|
8
|
+
// MILESTONE_PROGRESS_CARD_V2{title "4 more", progress_percent}, earned grid with dates.
|
|
9
|
+
// GET /streaks-service/v1/bff/streaks/data-streak: value, state, started / max, week tracker.
|
|
10
|
+
// Not /achievements-service/v1/progression: that's a static 2021 level table.
|
|
11
|
+
import type { BadgeT, MilestoneDetailOutT, StreakT } from "../schemas/milestones.js";
|
|
12
|
+
import { byType, get, parseNumber, str, walk, type Node } from "../whoop/bff.js";
|
|
13
|
+
|
|
14
|
+
const isObj = (v: unknown): v is Node => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
15
|
+
const arr = (v: unknown): unknown[] => (Array.isArray(v) ? v : []);
|
|
16
|
+
const MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
17
|
+
|
|
18
|
+
/** "Nov 21, 2026" → "2026-11-21". */
|
|
19
|
+
export function displayDate(s: unknown): string | null {
|
|
20
|
+
const m = typeof s === "string" ? s.match(/^([A-Za-z]{3})[a-z]*\.?\s+(\d{1,2}),\s*(\d{4})$/) : null;
|
|
21
|
+
const month = m ? MONTHS.indexOf(m[1]!.toLowerCase()) : -1;
|
|
22
|
+
return m && month >= 0 ? `${m[3]}-${String(month + 1).padStart(2, "0")}-${m[2]!.padStart(2, "0")}` : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function badgeStatus(sub: string | null): string | null {
|
|
26
|
+
if (!sub) return null;
|
|
27
|
+
const plain = sub.replace(/\*/g, "").trim();
|
|
28
|
+
const top = plain.match(/top\s*(\d+(?:\.\d+)?)\s*%/i);
|
|
29
|
+
if (top) return `top ${top[1]}%`;
|
|
30
|
+
const of = plain.match(/(\d+)\s*of\s*(\d+)/i);
|
|
31
|
+
return of ? `${of[1]}/${of[2]}` : plain;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function badge(cell: Node, tag: string): BadgeT | null {
|
|
35
|
+
const c = cell.content;
|
|
36
|
+
const type = str(get(c, "destination", "parameters", "milestone_type"));
|
|
37
|
+
if (!type) return null;
|
|
38
|
+
return {
|
|
39
|
+
type,
|
|
40
|
+
tag,
|
|
41
|
+
name: str(get(c, "caption_text")),
|
|
42
|
+
// Locked badges (Healthspan before it unlocks) carry an empty overlay: no count, not zero.
|
|
43
|
+
count: parseNumber(get(c, "media", "text_overlay")),
|
|
44
|
+
status: badgeStatus(str(get(c, "sub_caption_text"))),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function projectMilestonesHub(raw: unknown): { totals: { total: number | null; unique: number | null; rare: number | null }; badges: BadgeT[] } {
|
|
49
|
+
// Header counts: the value text precedes its label in document order.
|
|
50
|
+
const totals = { total: null as number | null, unique: null as number | null, rare: null as number | null };
|
|
51
|
+
const header = byType(raw, "ROW")[0];
|
|
52
|
+
let last: number | null = null;
|
|
53
|
+
for (const n of walk(header)) {
|
|
54
|
+
if (n.type !== "MARKDOWN_TEXT") continue;
|
|
55
|
+
const text = str(get(n, "content", "text"));
|
|
56
|
+
const label = text?.trim().toLowerCase();
|
|
57
|
+
if (label === "total" || label === "unique" || label === "rare") totals[label] = last;
|
|
58
|
+
else last = parseNumber(text);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const tagMaps = get(byType(raw, "TAG_SELECTOR")[0], "content", "tag_maps");
|
|
62
|
+
const groups: Array<[string, unknown]> = isObj(tagMaps)
|
|
63
|
+
? Object.entries(tagMaps).filter(([tag]) => tag !== "all")
|
|
64
|
+
: byType(raw, "SECTION")
|
|
65
|
+
.map((s) => [String(get(s, "content", "id") ?? "").replace(/^section-/, ""), s] as [string, unknown])
|
|
66
|
+
.filter(([tag]) => tag && tag !== "all");
|
|
67
|
+
const badges: BadgeT[] = [];
|
|
68
|
+
for (const [tag, node] of groups) {
|
|
69
|
+
for (const cell of byType(node, "CELEBRATION_MEDIA_WITH_CAPTION")) {
|
|
70
|
+
const b = badge(cell, tag);
|
|
71
|
+
if (b && !badges.some((x) => x.type === b.type)) badges.push(b);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { totals, badges };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const topPct = (b: BadgeT): number => Number(b.status?.match(/^top ([\d.]+)%$/)?.[1] ?? 101);
|
|
78
|
+
const progressFrac = (b: BadgeT): number => {
|
|
79
|
+
const m = b.status?.match(/^(\d+)\/(\d+)$/);
|
|
80
|
+
return m ? Number(m[1]) / Number(m[2]) : 0;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Earned badges, most-earned (then rarest) first. */
|
|
84
|
+
export function topBadges(badges: BadgeT[], n = 5): BadgeT[] {
|
|
85
|
+
return badges.filter((b) => (b.count ?? 0) > 0).sort((a, b) => (b.count ?? 0) - (a.count ?? 0) || topPct(a) - topPct(b)).slice(0, n);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Unearned badges closest to their first level. */
|
|
89
|
+
export function nearestBadges(badges: BadgeT[], n = 3): BadgeT[] {
|
|
90
|
+
return badges.filter((b) => b.count === 0 && progressFrac(b) > 0).sort((a, b) => progressFrac(b) - progressFrac(a)).slice(0, n);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function projectDataStreak(raw: unknown): StreakT {
|
|
94
|
+
const list = arr(get(byType(raw, "HORIZONTAL_DIVIDED_LIST")[0], "content", "list_items")).filter(isObj);
|
|
95
|
+
const item = (re: RegExp) => list.find((i) => re.test(str(i.subtitle) ?? ""));
|
|
96
|
+
const tracked = arr(get(byType(raw, "HORIZONTAL_TRACKER")[0], "content", "tracked_items")).filter(isObj);
|
|
97
|
+
const card = byType(raw, "MILESTONE_PROGRESS_CARD")[0];
|
|
98
|
+
const week = tracked.length
|
|
99
|
+
? {
|
|
100
|
+
worn: tracked.filter((t) => /\/active\//.test(str(t.icon_url) ?? "")).map((t) => str(t.title) ?? ""),
|
|
101
|
+
missed: tracked.filter((t) => /circle_cross/.test(str(t.icon_url) ?? "")).map((t) => str(t.title) ?? ""),
|
|
102
|
+
}
|
|
103
|
+
: null;
|
|
104
|
+
return {
|
|
105
|
+
days: parseNumber(get(raw, "streak_value")),
|
|
106
|
+
state: str(get(raw, "today_streak_state")),
|
|
107
|
+
started: displayDate(item(/started/i)?.title),
|
|
108
|
+
max: parseNumber(item(/max/i)?.title),
|
|
109
|
+
next_milestone_in_days: parseNumber(get(card, "content", "title")),
|
|
110
|
+
this_week: week,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function projectMilestoneDetail(raw: unknown, type: string): MilestoneDetailOutT {
|
|
115
|
+
const title = byType(raw, "TITLE_SUBTITLE")[0];
|
|
116
|
+
const media = byType(raw, "CELEBRATION_MEDIA")[0];
|
|
117
|
+
const card = byType(raw, "MILESTONE_PROGRESS_CARD_V2")[0];
|
|
118
|
+
const pct = get(card, "content", "progress_percent");
|
|
119
|
+
const earned = byType(raw, "CELEBRATION_MEDIA_WITH_CAPTION").map((cell) => [
|
|
120
|
+
parseNumber(get(cell, "content", "media", "text_overlay")),
|
|
121
|
+
displayDate(get(cell, "content", "sub_caption_text")),
|
|
122
|
+
] as [number | null, string | null]).filter(([, d]) => d !== null);
|
|
123
|
+
return {
|
|
124
|
+
type,
|
|
125
|
+
name: str(get(title, "content", "title")),
|
|
126
|
+
about: str(get(title, "content", "subtitle")),
|
|
127
|
+
count: parseNumber(get(media, "content", "text_overlay")),
|
|
128
|
+
next: card
|
|
129
|
+
? { more: parseNumber(get(card, "content", "title")), pct: typeof pct === "number" ? Math.round(pct * 1000) / 10 : null }
|
|
130
|
+
: null,
|
|
131
|
+
earned,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// whoop_profile projections (SPEC.md §4.8 profile, §4.11 integrations/privacy).
|
|
2
|
+
// The profile-edit screen is the source of truth for PUT-format fields;
|
|
3
|
+
// bootstrap fills the rest (bio data, membership, timezone).
|
|
4
|
+
import { asArray, asBool, asNumber, asString, isObject } from "../lib/walk.js";
|
|
5
|
+
import { decodePrivacyPillar } from "../lib/profile_settings.js";
|
|
6
|
+
|
|
7
|
+
/** The PUT-format profile fields from GET /profile-service/v1/profile/bff/edit. */
|
|
8
|
+
export interface EditableProfile {
|
|
9
|
+
first_name: string | null;
|
|
10
|
+
last_name: string | null;
|
|
11
|
+
email: string | null;
|
|
12
|
+
birthday: string | null;
|
|
13
|
+
gender: string | null;
|
|
14
|
+
physiological_baseline: string | null;
|
|
15
|
+
height: number | null;
|
|
16
|
+
weight: number | null;
|
|
17
|
+
city: string | null;
|
|
18
|
+
state: string | null;
|
|
19
|
+
country: string | null;
|
|
20
|
+
unit_system: string | null;
|
|
21
|
+
locked_fields: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function parseProfileEdit(raw: unknown): EditableProfile | null {
|
|
25
|
+
if (!isObject(raw)) return null;
|
|
26
|
+
const birthday = asString(raw.birthday);
|
|
27
|
+
return {
|
|
28
|
+
first_name: asString(raw.first_name),
|
|
29
|
+
last_name: asString(raw.last_name),
|
|
30
|
+
email: asString(raw.email),
|
|
31
|
+
birthday: birthday ? birthday.slice(0, 10) : null,
|
|
32
|
+
gender: asString(raw.gender),
|
|
33
|
+
physiological_baseline: asString(raw.physiological_baseline),
|
|
34
|
+
height: asNumber(raw.height),
|
|
35
|
+
weight: asNumber(raw.weight),
|
|
36
|
+
city: asString(raw.city),
|
|
37
|
+
state: asString(raw.state),
|
|
38
|
+
country: asString(raw.country),
|
|
39
|
+
unit_system: asString(raw.unit_system),
|
|
40
|
+
locked_fields: asArray(raw.locked_fields).filter((f): f is string => typeof f === "string"),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const obj = (v: unknown): Record<string, unknown> => (isObject(v) ? v : {});
|
|
45
|
+
|
|
46
|
+
export function projectProfileV2(input: {
|
|
47
|
+
bootstrap: unknown;
|
|
48
|
+
edit: unknown;
|
|
49
|
+
hidden: Record<string, unknown>;
|
|
50
|
+
stealth: unknown;
|
|
51
|
+
}) {
|
|
52
|
+
const boot = obj(input.bootstrap);
|
|
53
|
+
const user = obj(boot.user);
|
|
54
|
+
const account = obj(boot.account);
|
|
55
|
+
const profile = obj(boot.profile);
|
|
56
|
+
const bio = obj(boot.bio_data);
|
|
57
|
+
const edit = parseProfileEdit(input.edit);
|
|
58
|
+
const bootBirthday = asString(profile.birthday);
|
|
59
|
+
return {
|
|
60
|
+
user_id: asNumber(user.id) ?? asNumber(account.user_id),
|
|
61
|
+
first_name: edit?.first_name ?? asString(user.first_name),
|
|
62
|
+
last_name: edit?.last_name ?? asString(user.last_name),
|
|
63
|
+
email: edit?.email ?? asString(account.email),
|
|
64
|
+
birthday: edit?.birthday ?? (bootBirthday ? bootBirthday.slice(0, 10) : null),
|
|
65
|
+
// Bootstrap's gender is a display string ("i prefer not to choose") and its
|
|
66
|
+
// baseline is always null; only bff/edit has the PUT enums.
|
|
67
|
+
gender: edit?.gender ?? null,
|
|
68
|
+
physiological_baseline: edit?.physiological_baseline ?? null,
|
|
69
|
+
height_m: edit?.height ?? asNumber(profile.height),
|
|
70
|
+
weight_kg: edit?.weight ?? asNumber(profile.weight),
|
|
71
|
+
unit_system: edit?.unit_system ?? asString(profile.unit_system),
|
|
72
|
+
city: edit?.city ?? asString(user.city),
|
|
73
|
+
state: edit?.state ?? asString(user.admin_division),
|
|
74
|
+
country: edit?.country ?? asString(user.country),
|
|
75
|
+
tz_offset: asString(profile.timezone_offset),
|
|
76
|
+
max_hr: asNumber(bio.max_heart_rate),
|
|
77
|
+
resting_hr: asNumber(bio.resting_heart_rate),
|
|
78
|
+
fitness_level: asString(profile.fitness_level),
|
|
79
|
+
membership: asString(obj(boot.membership).status),
|
|
80
|
+
hidden_metrics: Object.entries(input.hidden).filter(([, v]) => isObject(v) && v.is_hidden === true).map(([k]) => k),
|
|
81
|
+
// GET /users-service/v1/stealth-mode answers a bare JSON boolean.
|
|
82
|
+
stealth: typeof input.stealth === "boolean" ? input.stealth : isObject(input.stealth) ? asBool(input.stealth.enabled) : null,
|
|
83
|
+
locked_fields: edit?.locked_fields ?? [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** GET /entitlement-service/v1/entitlements → count on, and why each one is off. */
|
|
88
|
+
export function projectEntitlements(raw: unknown) {
|
|
89
|
+
const map = obj(obj(raw).entitlements);
|
|
90
|
+
let on = 0;
|
|
91
|
+
const off: Record<string, string> = {};
|
|
92
|
+
for (const [feature, value] of Object.entries(map)) {
|
|
93
|
+
if (!isObject(value)) continue;
|
|
94
|
+
if (value.entitled === true) { on++; continue; }
|
|
95
|
+
off[feature] = asArray(value.reasons).flatMap((r) => {
|
|
96
|
+
if (!isObject(r)) return [];
|
|
97
|
+
const required = asString(r.required_value) ?? "?";
|
|
98
|
+
return [`${asString(r.reason_type) ?? "REASON"}: needs ${required.length > 30 ? `${required.slice(0, 30)}…` : required} (has ${asString(r.current_value) ?? "?"})`];
|
|
99
|
+
}).join("; ") || "not entitled";
|
|
100
|
+
}
|
|
101
|
+
return { on, off };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* GET /integrations-bff/v1/integrations/discovery. Only names and the connected
|
|
106
|
+
* flag are projected, so OAuth URLs and state nonces (S24) never reach output.
|
|
107
|
+
*/
|
|
108
|
+
export function projectIntegrations(raw: unknown) {
|
|
109
|
+
const connected: string[] = [];
|
|
110
|
+
const available: string[] = [];
|
|
111
|
+
const seen = new Set<string>();
|
|
112
|
+
const visit = (node: unknown): void => {
|
|
113
|
+
if (Array.isArray(node)) { node.forEach(visit); return; }
|
|
114
|
+
if (!isObject(node)) return;
|
|
115
|
+
if (typeof node.connected === "boolean" && (asString(node.title_display) || asString(node.reporting_key))) {
|
|
116
|
+
const name = asString(node.title_display) ?? asString(node.reporting_key)!;
|
|
117
|
+
const key = asString(node.id) ?? name;
|
|
118
|
+
if (!seen.has(key)) {
|
|
119
|
+
seen.add(key);
|
|
120
|
+
(node.connected ? connected : available).push(name);
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
Object.values(node).forEach(visit);
|
|
125
|
+
};
|
|
126
|
+
visit(raw);
|
|
127
|
+
return { connected, available };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const VISIBILITY_FIELDS: Record<string, string> = {
|
|
131
|
+
community_list_visibility: "community_list",
|
|
132
|
+
age_visibility: "age",
|
|
133
|
+
region_visibility: "region",
|
|
134
|
+
data_highlights: "data_highlights",
|
|
135
|
+
activity_summary: "activity_summary",
|
|
136
|
+
healthspan: "healthspan",
|
|
137
|
+
achievements: "achievements",
|
|
138
|
+
moments_on_profile: "moments",
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const pillar = (v: unknown) => {
|
|
142
|
+
const d = decodePrivacyPillar(asString(v));
|
|
143
|
+
return d ? { to: d.audience, trends: d.trends, daily: d.daily_stats } : null;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** GET /privacy-service/v1/community/privacy/settings, with the composite pillar strings decoded. */
|
|
147
|
+
export function projectPrivacy(raw: unknown) {
|
|
148
|
+
const r = obj(raw);
|
|
149
|
+
const visibility: Record<string, string> = {};
|
|
150
|
+
for (const [field, key] of Object.entries(VISIBILITY_FIELDS)) {
|
|
151
|
+
const v = asString(r[field]);
|
|
152
|
+
if (v) visibility[key] = v;
|
|
153
|
+
}
|
|
154
|
+
const deviations = obj(r.activity_type_sharing_deviations);
|
|
155
|
+
const overrides: Record<string, string> = {};
|
|
156
|
+
for (const [sport, v] of Object.entries(deviations)) if (typeof v === "string") overrides[sport] = v;
|
|
157
|
+
return {
|
|
158
|
+
searchable: asBool(r.searchable),
|
|
159
|
+
mutual_sharing: asBool(r.mutual_community_sharing),
|
|
160
|
+
visibility,
|
|
161
|
+
sleep: pillar(r.sleep),
|
|
162
|
+
recovery: pillar(r.recovery),
|
|
163
|
+
strain: pillar(r.strain),
|
|
164
|
+
activity_overrides: Object.keys(overrides).length > 0 ? overrides : null,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// Pure projections for preferences and HR zones (SPEC.md §4.6, §4.8).
|
|
2
|
+
import { asArray, asBool, asNumber, asString, isObject } from "../lib/walk.js";
|
|
3
|
+
import { FIXED_GAUGES } from "../lib/profile_settings.js";
|
|
4
|
+
import { BEHAVIORS_BY_ID } from "../data/behaviors.js";
|
|
5
|
+
import type { HrZonesV2OutT } from "../schemas/settings_v2.js";
|
|
6
|
+
|
|
7
|
+
/** GET /journal-service/v1/journals/preferences. */
|
|
8
|
+
export function projectJournalPrefs(raw: unknown) {
|
|
9
|
+
const r = isObject(raw) ? raw : {};
|
|
10
|
+
return {
|
|
11
|
+
journal_enabled: asBool(r.journal_enabled),
|
|
12
|
+
journal_autopop_enabled: asBool(r.journal_autopop_enabled),
|
|
13
|
+
ai_autopop_enabled: asBool(r.ai_autopop_enabled),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** GET /notification-service/v1/notifications/user-settings/bff → {namespace: active}. `active:false` = blocked. */
|
|
18
|
+
export function projectNotifications(raw: unknown): Record<string, boolean | null> {
|
|
19
|
+
const out: Record<string, boolean | null> = {};
|
|
20
|
+
for (const s of asArray(isObject(raw) ? raw.settings : null)) {
|
|
21
|
+
if (isObject(s) && asString(s.push_namespace)) out[s.push_namespace as string] = asBool(s.active);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** GET /ai-conversation-service/v1/settings → {setting_key: active}. */
|
|
27
|
+
export function projectAiSettings(raw: unknown): Record<string, boolean | null> {
|
|
28
|
+
const out: Record<string, boolean | null> = {};
|
|
29
|
+
for (const s of asArray(isObject(raw) ? raw.settings : null)) {
|
|
30
|
+
if (isObject(s) && asString(s.setting_key)) out[s.setting_key as string] = asBool(s.active);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const metricsOf = (section: unknown): string[] =>
|
|
36
|
+
asArray(isObject(section) ? section.metrics : null).flatMap((m) => (isObject(m) && asString(m.metric) ? [m.metric as string] : []));
|
|
37
|
+
|
|
38
|
+
/** GET /home-service/v2/home/dashboard/customize: the user's gauges are slots 1 and 3. */
|
|
39
|
+
export function projectDashboard(raw: unknown) {
|
|
40
|
+
const r = isObject(raw) ? raw : {};
|
|
41
|
+
const gauges = asArray(r.gauge_metrics)
|
|
42
|
+
.flatMap((g) => (isObject(g) && asString(g.metric) ? [{ index: asNumber(g.index) ?? -1, metric: g.metric as string }] : []))
|
|
43
|
+
.sort((a, b) => a.index - b.index);
|
|
44
|
+
const fixed = FIXED_GAUGES as readonly string[];
|
|
45
|
+
const user = gauges.filter((g) => g.index === 1 || g.index === 3);
|
|
46
|
+
return {
|
|
47
|
+
gauges: (user.length > 0 ? user : gauges.filter((g) => !fixed.includes(g.metric))).map((g) => g.metric),
|
|
48
|
+
pinned: metricsOf(r.pinned_metrics_section),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* What the dashboard screen offers this account: the gauge picker
|
|
54
|
+
* (`bottom_sheet_metrics`) and every metric that can be pinned (the pinned and
|
|
55
|
+
* unpinned sections). The app only ever sends values from these lists.
|
|
56
|
+
*/
|
|
57
|
+
export function dashboardOptions(raw: unknown) {
|
|
58
|
+
const r = isObject(raw) ? raw : {};
|
|
59
|
+
return {
|
|
60
|
+
gauges: asArray(r.bottom_sheet_metrics).flatMap((m) => (isObject(m) && asString(m.metric) ? [m.metric as string] : typeof m === "string" ? [m] : [])),
|
|
61
|
+
pinnable: [...metricsOf(r.pinned_metrics_section), ...metricsOf(r.unpinned_metrics_section)],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface BehaviorToggle {
|
|
66
|
+
id: number;
|
|
67
|
+
title: string | null;
|
|
68
|
+
internal_name: string | null;
|
|
69
|
+
question: string | null;
|
|
70
|
+
custom: boolean;
|
|
71
|
+
selected: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* GET /journal-service/v3/journals/behaviors (the app's customize-journal
|
|
76
|
+
* screen) → every behaviour with its `selected` flag: the tracked set.
|
|
77
|
+
* `GET /activities-service/v1/journals/behaviors/user` is NOT the tracked set:
|
|
78
|
+
* it lists stock behaviours only, so a tracked custom behaviour is missing
|
|
79
|
+
* from it (verified live 2026-11-21: 309 there, 310 selected here).
|
|
80
|
+
* `complete` is false when there are no toggles or one lacks a boolean `selected`.
|
|
81
|
+
*/
|
|
82
|
+
export function projectBehaviorToggles(raw: unknown) {
|
|
83
|
+
const toggles: BehaviorToggle[] = [];
|
|
84
|
+
const seen = new Set<number>();
|
|
85
|
+
let complete = true;
|
|
86
|
+
for (const group of asArray(isObject(raw) ? raw.grouped_toggles : null)) {
|
|
87
|
+
for (const t of asArray(isObject(group) ? group.toggles : null)) {
|
|
88
|
+
const id = isObject(t) ? asNumber(t.id) : null;
|
|
89
|
+
if (!isObject(t) || id === null || !Number.isInteger(id) || typeof t.selected !== "boolean") {
|
|
90
|
+
complete = false;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (seen.has(id)) continue;
|
|
94
|
+
seen.add(id);
|
|
95
|
+
toggles.push({
|
|
96
|
+
id,
|
|
97
|
+
title: asString(t.title),
|
|
98
|
+
internal_name: asString(t.internal_name),
|
|
99
|
+
question: asString(t.subtitle),
|
|
100
|
+
custom: t.custom === true || !BEHAVIORS_BY_ID.has(id),
|
|
101
|
+
selected: t.selected,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const tracked = toggles.filter((t) => t.selected);
|
|
106
|
+
return {
|
|
107
|
+
toggles,
|
|
108
|
+
ids: tracked.map((t) => t.id),
|
|
109
|
+
count: tracked.length,
|
|
110
|
+
custom_count: tracked.filter((t) => t.custom).length,
|
|
111
|
+
complete: complete && toggles.length > 0,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type ZoneId = "ZONE_0" | "ZONE_1" | "ZONE_2" | "ZONE_3" | "ZONE_4" | "ZONE_5";
|
|
116
|
+
export interface ZoneRow { id: ZoneId; min: number; max: number }
|
|
117
|
+
/** HR zones as the write tool works with them; `hrZonesOut` makes the compact output. */
|
|
118
|
+
export interface HrZonesState {
|
|
119
|
+
max_hr: number | null;
|
|
120
|
+
resting_hr: number | null;
|
|
121
|
+
is_custom: boolean | null;
|
|
122
|
+
zones: ZoneRow[];
|
|
123
|
+
default_zones: ZoneRow[];
|
|
124
|
+
}
|
|
125
|
+
const ZONE_IDS: readonly string[] = ["ZONE_0", "ZONE_1", "ZONE_2", "ZONE_3", "ZONE_4", "ZONE_5"];
|
|
126
|
+
|
|
127
|
+
function zoneRows(list: unknown): ZoneRow[] {
|
|
128
|
+
return asArray(list)
|
|
129
|
+
.flatMap((z) => {
|
|
130
|
+
if (!isObject(z)) return [];
|
|
131
|
+
const id = asString(z.id);
|
|
132
|
+
const min = asNumber(z.min);
|
|
133
|
+
const max = asNumber(z.max);
|
|
134
|
+
return id && ZONE_IDS.includes(id) && min !== null && max !== null ? [{ id: id as ZoneId, min: Math.round(min), max: Math.round(max) }] : [];
|
|
135
|
+
})
|
|
136
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* GET /hr-zones-service/v1/bff/zones + /bff/settings. `is_custom` lives only in
|
|
141
|
+
* settings (`manual_heart_rate_zones_form.toggle_value`); the effective zones
|
|
142
|
+
* are the settings form rows, with ZONE_0 from bff/zones.
|
|
143
|
+
*/
|
|
144
|
+
export function parseHrZones(input: { zones: unknown; settings: unknown }): HrZonesState {
|
|
145
|
+
const zones = isObject(input.zones) ? input.zones : {};
|
|
146
|
+
const settings = isObject(input.settings) ? input.settings : {};
|
|
147
|
+
let maxHr: number | null = null;
|
|
148
|
+
let restingHr: number | null = null;
|
|
149
|
+
for (const row of asArray(settings.heart_rate_entry_row)) {
|
|
150
|
+
if (!isObject(row)) continue;
|
|
151
|
+
if (row.id === "MAX_HR") maxHr = asNumber(row.value);
|
|
152
|
+
if (row.id === "RESTING_HR") restingHr = asNumber(row.value);
|
|
153
|
+
}
|
|
154
|
+
const form = isObject(settings.manual_heart_rate_zones_form) ? settings.manual_heart_rate_zones_form : null;
|
|
155
|
+
const fromZones = zoneRows(zones.zones);
|
|
156
|
+
const fromForm = zoneRows(form?.zone_rows);
|
|
157
|
+
const effective = fromForm.length === 5 ? [...fromZones.filter((z) => z.id === "ZONE_0"), ...fromForm] : fromZones;
|
|
158
|
+
return {
|
|
159
|
+
max_hr: maxHr === null ? null : Math.round(maxHr),
|
|
160
|
+
resting_hr: restingHr === null ? null : Math.round(restingHr),
|
|
161
|
+
is_custom: form ? asBool(form.toggle_value) : null,
|
|
162
|
+
zones: effective,
|
|
163
|
+
default_zones: zoneRows(settings.default_hr_zones),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const zoneMap = (rows: ZoneRow[]): Record<string, [number, number]> =>
|
|
168
|
+
Object.fromEntries(rows.map((z) => [z.id.replace("ONE_", ""), [z.min, z.max]]));
|
|
169
|
+
|
|
170
|
+
/** Compact output: {Z0: [min, max], …}; defaults only when the zones are custom. */
|
|
171
|
+
export function hrZonesOut(state: HrZonesState): HrZonesV2OutT {
|
|
172
|
+
return {
|
|
173
|
+
max_hr: state.max_hr,
|
|
174
|
+
resting_hr: state.resting_hr,
|
|
175
|
+
is_custom: state.is_custom,
|
|
176
|
+
zones: zoneMap(state.zones),
|
|
177
|
+
defaults: state.is_custom && state.default_zones.length > 0 ? zoneMap(state.default_zones) : null,
|
|
178
|
+
};
|
|
179
|
+
}
|
package/src/projections/sleep.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
asArray,
|
|
5
5
|
asNumber,
|
|
6
6
|
asString,
|
|
7
|
-
|
|
7
|
+
findFirst,
|
|
8
8
|
findDetailsCardByTitle,
|
|
9
9
|
labelToNumber,
|
|
10
10
|
timeLabelToMs,
|
|
@@ -94,7 +94,7 @@ interface StagePoint {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// "1:24 AM" / "11:52 PM" → minutes since midnight (0..1439), or null.
|
|
97
|
-
function parseClockMinutes(s: string | null): number | null {
|
|
97
|
+
export function parseClockMinutes(s: string | null): number | null {
|
|
98
98
|
if (!s) return null;
|
|
99
99
|
const m = /^(\d{1,2}):(\d{2})\s*([AP]M)$/i.exec(s.trim());
|
|
100
100
|
if (!m) return null;
|
|
@@ -222,25 +222,11 @@ export function projectSleep(raw: unknown, date: string): SleepOutT {
|
|
|
222
222
|
const sws = stageTime(raw, "SWS_SLEEP");
|
|
223
223
|
const wake = stageTime(raw, "AWAKE");
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (asString(content.title) === "WAKE EVENTS") {
|
|
231
|
-
// Find the numeric stat inside the tile
|
|
232
|
-
const tiles = asArray(content.metric_tiles ?? content.tiles ?? content.items);
|
|
233
|
-
for (const t of tiles) {
|
|
234
|
-
if (isObject(t)) {
|
|
235
|
-
const v = asNumber(t.value ?? t.metric_value);
|
|
236
|
-
if (v !== null) {
|
|
237
|
-
disturbances = v;
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
225
|
+
const wakeTile = findFirst(
|
|
226
|
+
raw,
|
|
227
|
+
(n) => n.type === "DETAILS_METRIC_TILES" && isObject(n.content) && asString(n.content.title) === "WAKE EVENTS",
|
|
228
|
+
);
|
|
229
|
+
const disturbances = labelToNumber(arrowStat(wakeTile) || null);
|
|
244
230
|
|
|
245
231
|
const startedAt = params ? asString(params.start_time) : null;
|
|
246
232
|
const endedAt = params ? asString(params.end_time) : null;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// whoop_calendar: GET /home-service/v1/calendar/{recovery|strain|sleep}?date=
|
|
2
|
+
// (SPEC.md §4.2), and for journal GET /journal-service/v2/journals/{date}/calendar
|
|
3
|
+
// (same days_of_month shape; day_state HAS_JOURNAL_ENTRY or NO_DATA; route from
|
|
4
|
+
// @Acetone1's Android list, live 2026-11-22). Days carry only "1".."31" (no full
|
|
5
|
+
// date) and cycle_id (dropped: unstable, useless here). Encoded as one character
|
|
6
|
+
// per day of the month: H/M/L = high/medium/low, J = journal entry, "-" = data but
|
|
7
|
+
// no score, "." = no data.
|
|
8
|
+
import { get, isNode, nodes, str } from "./core_common.js";
|
|
9
|
+
|
|
10
|
+
export const CALENDAR_PILLARS = ["recovery", "strain", "sleep", "journal"] as const;
|
|
11
|
+
export type CalendarPillar = (typeof CALENDAR_PILLARS)[number];
|
|
12
|
+
|
|
13
|
+
export interface CalendarV2 {
|
|
14
|
+
pillar: CalendarPillar;
|
|
15
|
+
month: string;
|
|
16
|
+
/** days[i] is day i+1 of the month. */
|
|
17
|
+
days: string;
|
|
18
|
+
/** WHOOP's thresholds for the letters that apply to this pillar. */
|
|
19
|
+
key: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function stateChar(state: string | null, hasData: boolean): string {
|
|
23
|
+
if (state && state !== "NO_DATA") {
|
|
24
|
+
if (state === "HAS_JOURNAL_ENTRY") return "J";
|
|
25
|
+
if (state.startsWith("HIGH")) return "H";
|
|
26
|
+
if (state.startsWith("MEDIUM")) return "M";
|
|
27
|
+
if (state.startsWith("LOW")) return "L";
|
|
28
|
+
return "?";
|
|
29
|
+
}
|
|
30
|
+
return hasData ? "-" : ".";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function projectCalendarV2(raw: unknown, pillar: CalendarPillar, anyDate: string): CalendarV2 {
|
|
34
|
+
const month = anyDate.slice(0, 7);
|
|
35
|
+
const chars: string[] = [];
|
|
36
|
+
for (const d of nodes(get(raw, "days_of_month"))) {
|
|
37
|
+
const n = Number(str(d.date_value_display));
|
|
38
|
+
if (!Number.isInteger(n) || n < 1 || n > 31) continue;
|
|
39
|
+
chars[n - 1] = stateChar(str(d.day_state), d.has_data === true);
|
|
40
|
+
}
|
|
41
|
+
const key: Record<string, string> = {};
|
|
42
|
+
for (const k of nodes(isNode(raw) ? raw.calendar_key : null)) {
|
|
43
|
+
const label = str(k.text_display);
|
|
44
|
+
if (label) key[stateChar(str(k.state), true)] = label;
|
|
45
|
+
}
|
|
46
|
+
if (pillar === "journal" && !Object.keys(key).length) key.J = "Journal entry";
|
|
47
|
+
return { pillar, month, days: Array.from(chars, (c) => c ?? ".").join(""), key };
|
|
48
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Shared parsing helpers for the reads-core v2 tools (whoop_day, whoop_recovery,
|
|
2
|
+
// whoop_sleep, whoop_strain, whoop_stress, whoop_now, whoop_trend, whoop_calendar).
|
|
3
|
+
// Pure functions over WHOOP's server-driven ("BFF") payloads. Everything keys
|
|
4
|
+
// off stable `type` / `id` values and degrades to null instead of throwing.
|
|
5
|
+
import { byType, findFirst, get, parseDurationMs, parseNumber, str, type Node } from "../../whoop/bff.js";
|
|
6
|
+
|
|
7
|
+
export const isNode = (v: unknown): v is Node => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
8
|
+
export const arr = (v: unknown): unknown[] => (Array.isArray(v) ? v : []);
|
|
9
|
+
export const nodes = (v: unknown): Node[] => arr(v).filter(isNode);
|
|
10
|
+
|
|
11
|
+
/** WHOOP timestamp ("…+0000", "…-08:00", microseconds) → canonical ISO UTC with ms, or null. */
|
|
12
|
+
export function isoInstant(v: unknown): string | null {
|
|
13
|
+
if (typeof v === "number" && Number.isFinite(v)) return new Date(v).toISOString();
|
|
14
|
+
if (typeof v !== "string" || v.trim() === "") return null;
|
|
15
|
+
const ms = Date.parse(v);
|
|
16
|
+
return Number.isNaN(ms) ? null : new Date(ms).toISOString();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A display number that is not a clock value: "42" → 42, "1,234" → 1234, "0:20" / "--" → null. */
|
|
20
|
+
export function displayNumber(v: unknown): number | null {
|
|
21
|
+
if (typeof v === "string" && /^\s*-?\d+:\d{2}/.test(v)) return null;
|
|
22
|
+
return parseNumber(v);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** "h:mm" / "h:mm:ss" display → ms; "-:--", "--", "" → null. */
|
|
26
|
+
export function displayDurationMs(v: unknown): number | null {
|
|
27
|
+
return parseDurationMs(v);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Durations in reads-core outputs are minutes (shorter than ms, and what people say). */
|
|
31
|
+
export function msToMin(ms: number | null): number | null {
|
|
32
|
+
return ms === null || !Number.isFinite(ms) ? null : Math.round(ms / 6000) / 10;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** "h:mm" display → minutes; "-:--" / "--" → null. */
|
|
36
|
+
export function displayMinutes(v: unknown): number | null {
|
|
37
|
+
return msToMin(parseDurationMs(v));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Integer ms or null (zod schemas use .int()). */
|
|
41
|
+
export function intOrNull(v: number | null): number | null {
|
|
42
|
+
return v === null || !Number.isFinite(v) ? null : Math.round(v);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function round1(v: number | null): number | null {
|
|
46
|
+
return v === null ? null : Math.round(v * 10) / 10;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Percent change of `current` vs `baseline`, one decimal. */
|
|
50
|
+
export function deltaPct(current: number | null, baseline: number | null): number | null {
|
|
51
|
+
if (current === null || baseline === null || baseline === 0) return null;
|
|
52
|
+
return Math.round(((current - baseline) / baseline) * 1000) / 10;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The `content` of the first node of `type` whose content.id equals `id`. */
|
|
56
|
+
export function contentById(root: unknown, type: string, id: string): Node | null {
|
|
57
|
+
const hit = byType(root, type).find((n) => isNode(n.content) && n.content.id === id);
|
|
58
|
+
return hit && isNode(hit.content) ? hit.content : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A CONTRIBUTORS_TILE metric by id suffix (CONTRIBUTORS_TILE_HRV …). */
|
|
62
|
+
export function contributor(tile: Node | null, suffix: string): Node | null {
|
|
63
|
+
if (!tile) return null;
|
|
64
|
+
return nodes(tile.metrics).find((m) => typeof m.id === "string" && m.id.toUpperCase().endsWith(`_${suffix}`)) ?? null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Calibration { filled: number; total: number }
|
|
68
|
+
|
|
69
|
+
/** Calibration progress from the first DISCRETE STEPPER ("Wear WHOOP to sleep for 4 nights…"). */
|
|
70
|
+
export function stepperCalibration(root: unknown): Calibration | null {
|
|
71
|
+
const step = byType(root, "STEPPER").find((n) => get(n, "content", "progress_bar", "type") === "DISCRETE");
|
|
72
|
+
if (!step) return null;
|
|
73
|
+
const filled = get(step, "content", "progress_bar", "discrete_filled_total");
|
|
74
|
+
const total = get(step, "content", "progress_bar", "discrete_step_total");
|
|
75
|
+
return typeof filled === "number" && typeof total === "number" ? { filled, total } : null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function addDays(isoDate: string, days: number): string {
|
|
79
|
+
return new Date(Date.parse(`${isoDate}T00:00:00.000Z`) + days * 86_400_000).toISOString().slice(0, 10);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Postgres-style half-open date range "['2026-10-01','2026-11-01')" →
|
|
84
|
+
* inclusive {start, end} ("2026-10-01".."2026-10-31"). Null when unparsable.
|
|
85
|
+
*/
|
|
86
|
+
export function pgDateRangeInclusive(v: unknown): { start: string; end: string } | null {
|
|
87
|
+
if (typeof v !== "string") return null;
|
|
88
|
+
const m = v.match(/^[[(]'?(\d{4}-\d{2}-\d{2})[^',]*'?,\s*'?(\d{4}-\d{2}-\d{2})[^']*'?([\])])$/);
|
|
89
|
+
if (!m) return null;
|
|
90
|
+
const end = m[3] === ")" ? addDays(m[2]!, -1) : m[2]!;
|
|
91
|
+
return { start: m[1]!, end };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { byType, findFirst, get, parseNumber, str };
|
|
95
|
+
export type { Node };
|