@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.
Files changed (763) hide show
  1. package/.dev.vars.example +5 -0
  2. package/.dockerignore +5 -0
  3. package/.env.example +29 -20
  4. package/CHANGELOG.md +99 -1
  5. package/CONTRIBUTING.md +48 -116
  6. package/Dockerfile +46 -12
  7. package/README.md +172 -498
  8. package/SECURITY.md +36 -59
  9. package/TOOLS.md +448 -311
  10. package/WHOOP.md +497 -2659
  11. package/assets/brand/SOURCES.md +38 -0
  12. package/assets/brand/totem.png +0 -0
  13. package/assets/brand/totem.svg +13 -0
  14. package/assets/fonts/Manrope-OFL.txt +93 -0
  15. package/assets/fonts/manrope-latin.woff2 +0 -0
  16. package/dist/build_info.js +5 -0
  17. package/dist/build_info.js.map +1 -0
  18. package/dist/cli/app.js +675 -0
  19. package/dist/cli/app.js.map +1 -0
  20. package/dist/cli/auth.js +297 -0
  21. package/dist/cli/auth.js.map +1 -0
  22. package/dist/cli/auth_flow.js +268 -0
  23. package/dist/cli/auth_flow.js.map +1 -0
  24. package/dist/cli/browser_login.js +368 -0
  25. package/dist/cli/browser_login.js.map +1 -0
  26. package/dist/cli/clients.js +403 -0
  27. package/dist/cli/clients.js.map +1 -0
  28. package/dist/cli/deploy_record.js +96 -0
  29. package/dist/cli/deploy_record.js.map +1 -0
  30. package/dist/cli/index.js +39 -575
  31. package/dist/cli/index.js.map +1 -1
  32. package/dist/cli/links.js +28 -0
  33. package/dist/cli/links.js.map +1 -0
  34. package/dist/cli/logo.js +63 -0
  35. package/dist/cli/logo.js.map +1 -0
  36. package/dist/cli/setup.js +1157 -1017
  37. package/dist/cli/setup.js.map +1 -1
  38. package/dist/cli/spawn.js +80 -0
  39. package/dist/cli/spawn.js.map +1 -0
  40. package/dist/cli/sys.js +219 -0
  41. package/dist/cli/sys.js.map +1 -0
  42. package/dist/cli/ui.js +712 -463
  43. package/dist/cli/ui.js.map +1 -1
  44. package/dist/cli/update.js +425 -282
  45. package/dist/cli/update.js.map +1 -1
  46. package/dist/cloudflare/token_store.js +48 -0
  47. package/dist/cloudflare/token_store.js.map +1 -0
  48. package/dist/cloudflare/worker.js +155 -0
  49. package/dist/cloudflare/worker.js.map +1 -0
  50. package/dist/data/behaviors.js +2733 -617
  51. package/dist/data/behaviors.js.map +1 -1
  52. package/dist/data/endpoint_catalog.js +2681 -0
  53. package/dist/data/endpoint_catalog.js.map +1 -0
  54. package/dist/data/exercises.js +373 -4859
  55. package/dist/data/exercises.js.map +1 -1
  56. package/dist/data/garments.js +19 -0
  57. package/dist/data/garments.js.map +1 -0
  58. package/dist/data/sports.js +219 -208
  59. package/dist/data/sports.js.map +1 -1
  60. package/dist/lib/activity_list.js +123 -0
  61. package/dist/lib/activity_list.js.map +1 -0
  62. package/dist/lib/activity_records.js +195 -0
  63. package/dist/lib/activity_records.js.map +1 -0
  64. package/dist/lib/activity_results.js +44 -0
  65. package/dist/lib/activity_results.js.map +1 -0
  66. package/dist/lib/activity_types.js +164 -0
  67. package/dist/lib/activity_types.js.map +1 -0
  68. package/dist/lib/brand.js +63 -0
  69. package/dist/lib/brand.js.map +1 -0
  70. package/dist/lib/clock.js +24 -0
  71. package/dist/lib/clock.js.map +1 -0
  72. package/dist/lib/coach_session.js +345 -0
  73. package/dist/lib/coach_session.js.map +1 -0
  74. package/dist/lib/concurrency.js.map +1 -1
  75. package/dist/lib/dates.js +19 -0
  76. package/dist/lib/dates.js.map +1 -1
  77. package/dist/lib/env_file.js +195 -0
  78. package/dist/lib/env_file.js.map +1 -0
  79. package/dist/lib/health_plans_write.js +44 -0
  80. package/dist/lib/health_plans_write.js.map +1 -0
  81. package/dist/lib/heart_rate.js +34 -0
  82. package/dist/lib/heart_rate.js.map +1 -0
  83. package/dist/lib/highlight.js +81 -0
  84. package/dist/lib/highlight.js.map +1 -0
  85. package/dist/lib/install_links.js +47 -0
  86. package/dist/lib/install_links.js.map +1 -0
  87. package/dist/lib/instant.js +50 -0
  88. package/dist/lib/instant.js.map +1 -0
  89. package/dist/lib/journal_behaviors.js +382 -0
  90. package/dist/lib/journal_behaviors.js.map +1 -0
  91. package/dist/lib/lift_catalog.js +218 -0
  92. package/dist/lib/lift_catalog.js.map +1 -0
  93. package/dist/lib/lift_history.js +66 -0
  94. package/dist/lib/lift_history.js.map +1 -0
  95. package/dist/lib/lift_sets.js +146 -0
  96. package/dist/lib/lift_sets.js.map +1 -0
  97. package/dist/lib/lift_tool.js +20 -0
  98. package/dist/lib/lift_tool.js.map +1 -0
  99. package/dist/lib/profile_settings.js +101 -0
  100. package/dist/lib/profile_settings.js.map +1 -0
  101. package/dist/lib/screen_content.js +44 -0
  102. package/dist/lib/screen_content.js.map +1 -0
  103. package/dist/lib/timezone.js +48 -6
  104. package/dist/lib/timezone.js.map +1 -1
  105. package/dist/lib/walk.js +6 -1
  106. package/dist/lib/walk.js.map +1 -1
  107. package/dist/lib/weight_readings.js +61 -0
  108. package/dist/lib/weight_readings.js.map +1 -0
  109. package/dist/projections/activities.js +193 -0
  110. package/dist/projections/activities.js.map +1 -0
  111. package/dist/projections/alarm_schedule.js +102 -0
  112. package/dist/projections/alarm_schedule.js.map +1 -0
  113. package/dist/projections/coach.js +203 -0
  114. package/dist/projections/coach.js.map +1 -0
  115. package/dist/projections/community.js +165 -0
  116. package/dist/projections/community.js.map +1 -0
  117. package/dist/projections/health_features.js +167 -0
  118. package/dist/projections/health_features.js.map +1 -0
  119. package/dist/projections/hormonal_insights.js +239 -0
  120. package/dist/projections/hormonal_insights.js.map +1 -0
  121. package/dist/projections/journal_v2.js +157 -0
  122. package/dist/projections/journal_v2.js.map +1 -0
  123. package/dist/projections/lift_cards.js +115 -0
  124. package/dist/projections/lift_cards.js.map +1 -0
  125. package/dist/projections/lift_exercise_v2.js +131 -0
  126. package/dist/projections/lift_exercise_v2.js.map +1 -0
  127. package/dist/projections/lift_library_v2.js +67 -0
  128. package/dist/projections/lift_library_v2.js.map +1 -0
  129. package/dist/projections/lift_sessions.js +211 -0
  130. package/dist/projections/lift_sessions.js.map +1 -0
  131. package/dist/projections/memory.js +95 -0
  132. package/dist/projections/memory.js.map +1 -0
  133. package/dist/projections/milestones.js +119 -0
  134. package/dist/projections/milestones.js.map +1 -0
  135. package/dist/projections/profile_v2.js +150 -0
  136. package/dist/projections/profile_v2.js.map +1 -0
  137. package/dist/projections/settings_v2.js +153 -0
  138. package/dist/projections/settings_v2.js.map +1 -0
  139. package/dist/projections/sleep.js +4 -21
  140. package/dist/projections/sleep.js.map +1 -1
  141. package/dist/projections/v2/calendar.js +43 -0
  142. package/dist/projections/v2/calendar.js.map +1 -0
  143. package/dist/projections/v2/core_common.js +86 -0
  144. package/dist/projections/v2/core_common.js.map +1 -0
  145. package/dist/projections/v2/core_home.js +136 -0
  146. package/dist/projections/v2/core_home.js.map +1 -0
  147. package/dist/projections/v2/core_sleep_need.js +23 -0
  148. package/dist/projections/v2/core_sleep_need.js.map +1 -0
  149. package/dist/projections/v2/day.js +92 -0
  150. package/dist/projections/v2/day.js.map +1 -0
  151. package/dist/projections/v2/heart_rate.js +54 -0
  152. package/dist/projections/v2/heart_rate.js.map +1 -0
  153. package/dist/projections/v2/history.js +140 -0
  154. package/dist/projections/v2/history.js.map +1 -0
  155. package/dist/projections/v2/now.js +39 -0
  156. package/dist/projections/v2/now.js.map +1 -0
  157. package/dist/projections/v2/recovery.js +77 -0
  158. package/dist/projections/v2/recovery.js.map +1 -0
  159. package/dist/projections/v2/sleep.js +218 -0
  160. package/dist/projections/v2/sleep.js.map +1 -0
  161. package/dist/projections/v2/strain.js +39 -0
  162. package/dist/projections/v2/strain.js.map +1 -0
  163. package/dist/projections/v2/stress.js +92 -0
  164. package/dist/projections/v2/stress.js.map +1 -0
  165. package/dist/projections/v2/trend.js +205 -0
  166. package/dist/projections/v2/trend.js.map +1 -0
  167. package/dist/projections/weekly_plan.js +66 -0
  168. package/dist/projections/weekly_plan.js.map +1 -0
  169. package/dist/projections/weight_readings.js +57 -0
  170. package/dist/projections/weight_readings.js.map +1 -0
  171. package/dist/projections/workout.js +37 -15
  172. package/dist/projections/workout.js.map +1 -1
  173. package/dist/schemas/activities.js +123 -0
  174. package/dist/schemas/activities.js.map +1 -0
  175. package/dist/schemas/alarm_schedule.js +62 -0
  176. package/dist/schemas/alarm_schedule.js.map +1 -0
  177. package/dist/schemas/coach.js +76 -8
  178. package/dist/schemas/coach.js.map +1 -1
  179. package/dist/schemas/community.js +70 -0
  180. package/dist/schemas/community.js.map +1 -0
  181. package/dist/schemas/health.js +36 -0
  182. package/dist/schemas/health.js.map +1 -0
  183. package/dist/schemas/hormonal_insights.js +90 -0
  184. package/dist/schemas/hormonal_insights.js.map +1 -0
  185. package/dist/schemas/journal.js +4 -0
  186. package/dist/schemas/journal.js.map +1 -1
  187. package/dist/schemas/journal_v2.js +106 -0
  188. package/dist/schemas/journal_v2.js.map +1 -0
  189. package/dist/schemas/memory.js +42 -0
  190. package/dist/schemas/memory.js.map +1 -0
  191. package/dist/schemas/milestones.js +39 -0
  192. package/dist/schemas/milestones.js.map +1 -0
  193. package/dist/schemas/profile_v2.js +60 -0
  194. package/dist/schemas/profile_v2.js.map +1 -0
  195. package/dist/schemas/settings_v2.js +56 -0
  196. package/dist/schemas/settings_v2.js.map +1 -0
  197. package/dist/schemas/sleep.js +8 -1
  198. package/dist/schemas/sleep.js.map +1 -1
  199. package/dist/schemas/strength.js +10 -1
  200. package/dist/schemas/strength.js.map +1 -1
  201. package/dist/schemas/strength_v2.js +190 -0
  202. package/dist/schemas/strength_v2.js.map +1 -0
  203. package/dist/schemas/v2/calendar.js +8 -0
  204. package/dist/schemas/v2/calendar.js.map +1 -0
  205. package/dist/schemas/v2/core_common.js +42 -0
  206. package/dist/schemas/v2/core_common.js.map +1 -0
  207. package/dist/schemas/v2/day.js +73 -0
  208. package/dist/schemas/v2/day.js.map +1 -0
  209. package/dist/schemas/v2/now.js +25 -0
  210. package/dist/schemas/v2/now.js.map +1 -0
  211. package/dist/schemas/v2/recovery.js +35 -0
  212. package/dist/schemas/v2/recovery.js.map +1 -0
  213. package/dist/schemas/v2/sleep.js +44 -0
  214. package/dist/schemas/v2/sleep.js.map +1 -0
  215. package/dist/schemas/v2/strain.js +16 -0
  216. package/dist/schemas/v2/strain.js.map +1 -0
  217. package/dist/schemas/v2/stress.js +20 -0
  218. package/dist/schemas/v2/stress.js.map +1 -0
  219. package/dist/schemas/v2/trend.js +42 -0
  220. package/dist/schemas/v2/trend.js.map +1 -0
  221. package/dist/schemas/weekly_plan.js +31 -0
  222. package/dist/schemas/weekly_plan.js.map +1 -0
  223. package/dist/schemas/weight.js +28 -0
  224. package/dist/schemas/weight.js.map +1 -0
  225. package/dist/scripts/build_behaviors.js +114 -0
  226. package/dist/scripts/build_behaviors.js.map +1 -0
  227. package/dist/scripts/cognito_bootstrap.js +9 -277
  228. package/dist/scripts/cognito_bootstrap.js.map +1 -1
  229. package/dist/scripts/gen_activity_catalogs.js +104 -0
  230. package/dist/scripts/gen_activity_catalogs.js.map +1 -0
  231. package/dist/server-admin.js +156 -0
  232. package/dist/server-admin.js.map +1 -0
  233. package/dist/server-http.js +270 -48
  234. package/dist/server-http.js.map +1 -1
  235. package/dist/server.js +136 -23
  236. package/dist/server.js.map +1 -1
  237. package/dist/tools/annotations.js +15 -0
  238. package/dist/tools/annotations.js.map +1 -0
  239. package/dist/tools/define.js +31 -0
  240. package/dist/tools/define.js.map +1 -0
  241. package/dist/tools/register.js +59 -94
  242. package/dist/tools/register.js.map +1 -1
  243. package/dist/tools/resources.js +70 -0
  244. package/dist/tools/resources.js.map +1 -0
  245. package/dist/tools/slim_schema.js +90 -0
  246. package/dist/tools/slim_schema.js.map +1 -0
  247. package/dist/tools/v2/activity_delete.js +63 -17
  248. package/dist/tools/v2/activity_delete.js.map +1 -1
  249. package/dist/tools/v2/activity_edit.js +396 -0
  250. package/dist/tools/v2/activity_edit.js.map +1 -0
  251. package/dist/tools/v2/activity_log.js +152 -0
  252. package/dist/tools/v2/activity_log.js.map +1 -0
  253. package/dist/tools/v2/calendar.js +19 -21
  254. package/dist/tools/v2/calendar.js.map +1 -1
  255. package/dist/tools/v2/coach_ask.js +74 -110
  256. package/dist/tools/v2/coach_ask.js.map +1 -1
  257. package/dist/tools/v2/coach_history.js +120 -0
  258. package/dist/tools/v2/coach_history.js.map +1 -0
  259. package/dist/tools/v2/community.js +124 -0
  260. package/dist/tools/v2/community.js.map +1 -0
  261. package/dist/tools/v2/cycle.js +63 -15
  262. package/dist/tools/v2/cycle.js.map +1 -1
  263. package/dist/tools/v2/cycle_log.js +289 -32
  264. package/dist/tools/v2/cycle_log.js.map +1 -1
  265. package/dist/tools/v2/day.js +126 -24
  266. package/dist/tools/v2/day.js.map +1 -1
  267. package/dist/tools/v2/health.js +116 -0
  268. package/dist/tools/v2/health.js.map +1 -0
  269. package/dist/tools/v2/hr_zones_set.js +134 -34
  270. package/dist/tools/v2/hr_zones_set.js.map +1 -1
  271. package/dist/tools/v2/journal.js +75 -17
  272. package/dist/tools/v2/journal.js.map +1 -1
  273. package/dist/tools/v2/journal_log.js +306 -65
  274. package/dist/tools/v2/journal_log.js.map +1 -1
  275. package/dist/tools/v2/lift_exercise.js +125 -22
  276. package/dist/tools/v2/lift_exercise.js.map +1 -1
  277. package/dist/tools/v2/lift_exercise_set.js +291 -0
  278. package/dist/tools/v2/lift_exercise_set.js.map +1 -0
  279. package/dist/tools/v2/lift_library.js +51 -12
  280. package/dist/tools/v2/lift_library.js.map +1 -1
  281. package/dist/tools/v2/lift_log.js +309 -72
  282. package/dist/tools/v2/lift_log.js.map +1 -1
  283. package/dist/tools/v2/lift_sessions.js +248 -0
  284. package/dist/tools/v2/lift_sessions.js.map +1 -0
  285. package/dist/tools/v2/lift_template.js +232 -0
  286. package/dist/tools/v2/lift_template.js.map +1 -0
  287. package/dist/tools/v2/memory.js +45 -0
  288. package/dist/tools/v2/memory.js.map +1 -0
  289. package/dist/tools/v2/memory_set.js +107 -0
  290. package/dist/tools/v2/memory_set.js.map +1 -0
  291. package/dist/tools/v2/milestones.js +50 -0
  292. package/dist/tools/v2/milestones.js.map +1 -0
  293. package/dist/tools/v2/now.js +49 -0
  294. package/dist/tools/v2/now.js.map +1 -0
  295. package/dist/tools/v2/preferences.js +51 -0
  296. package/dist/tools/v2/preferences.js.map +1 -0
  297. package/dist/tools/v2/preferences_set.js +388 -0
  298. package/dist/tools/v2/preferences_set.js.map +1 -0
  299. package/dist/tools/v2/profile.js +54 -22
  300. package/dist/tools/v2/profile.js.map +1 -1
  301. package/dist/tools/v2/profile_update.js +167 -55
  302. package/dist/tools/v2/profile_update.js.map +1 -1
  303. package/dist/tools/v2/raw.js +91 -34
  304. package/dist/tools/v2/raw.js.map +1 -1
  305. package/dist/tools/v2/recovery.js +37 -23
  306. package/dist/tools/v2/recovery.js.map +1 -1
  307. package/dist/tools/v2/sleep.js +52 -16
  308. package/dist/tools/v2/sleep.js.map +1 -1
  309. package/dist/tools/v2/smart_alarm.js +54 -20
  310. package/dist/tools/v2/smart_alarm.js.map +1 -1
  311. package/dist/tools/v2/smart_alarm_set.js +264 -86
  312. package/dist/tools/v2/smart_alarm_set.js.map +1 -1
  313. package/dist/tools/v2/strain.js +15 -15
  314. package/dist/tools/v2/strain.js.map +1 -1
  315. package/dist/tools/v2/stress.js +17 -15
  316. package/dist/tools/v2/stress.js.map +1 -1
  317. package/dist/tools/v2/trend.js +56 -20
  318. package/dist/tools/v2/trend.js.map +1 -1
  319. package/dist/tools/v2/weekly_plan.js +30 -0
  320. package/dist/tools/v2/weekly_plan.js.map +1 -0
  321. package/dist/tools/v2/weekly_plan_set.js +134 -0
  322. package/dist/tools/v2/weekly_plan_set.js.map +1 -0
  323. package/dist/tools/v2/weight.js +56 -0
  324. package/dist/tools/v2/weight.js.map +1 -0
  325. package/dist/tools/v2/weight_log.js +188 -0
  326. package/dist/tools/v2/weight_log.js.map +1 -0
  327. package/dist/tools/v2/workouts.js +159 -25
  328. package/dist/tools/v2/workouts.js.map +1 -1
  329. package/dist/version.js +6 -0
  330. package/dist/version.js.map +1 -0
  331. package/dist/whoop/bff.js +94 -0
  332. package/dist/whoop/bff.js.map +1 -0
  333. package/dist/whoop/client.js +392 -18
  334. package/dist/whoop/client.js.map +1 -1
  335. package/dist/whoop/cognito.js +106 -79
  336. package/dist/whoop/cognito.js.map +1 -1
  337. package/dist/whoop/connect_page.js +165 -0
  338. package/dist/whoop/connect_page.js.map +1 -0
  339. package/dist/whoop/consent_font.js +287 -0
  340. package/dist/whoop/consent_font.js.map +1 -0
  341. package/dist/whoop/consent_logos.js +22 -0
  342. package/dist/whoop/consent_logos.js.map +1 -0
  343. package/dist/whoop/consent_page.js +291 -0
  344. package/dist/whoop/consent_page.js.map +1 -0
  345. package/dist/whoop/constants.js +5 -1
  346. package/dist/whoop/constants.js.map +1 -1
  347. package/dist/whoop/device.js +4 -4
  348. package/dist/whoop/device.js.map +1 -1
  349. package/dist/whoop/errors.js +85 -4
  350. package/dist/whoop/errors.js.map +1 -1
  351. package/dist/whoop/init_timezone.js +57 -17
  352. package/dist/whoop/init_timezone.js.map +1 -1
  353. package/dist/whoop/installation.js +15 -10
  354. package/dist/whoop/installation.js.map +1 -1
  355. package/dist/whoop/json_out.js +52 -6
  356. package/dist/whoop/json_out.js.map +1 -1
  357. package/dist/whoop/oauth_provider.js +81 -78
  358. package/dist/whoop/oauth_provider.js.map +1 -1
  359. package/dist/whoop/token_lock.js +331 -0
  360. package/dist/whoop/token_lock.js.map +1 -0
  361. package/dist/whoop/token_manager.js +536 -42
  362. package/dist/whoop/token_manager.js.map +1 -1
  363. package/dist/whoop/token_store.js +303 -36
  364. package/dist/whoop/token_store.js.map +1 -1
  365. package/dist/whoop/units.js +28 -0
  366. package/dist/whoop/units.js.map +1 -0
  367. package/package.json +29 -13
  368. package/scripts/build-mcpb.mjs +72 -0
  369. package/scripts/embed-consent-font.mjs +34 -0
  370. package/scripts/readme-media.ts +195 -0
  371. package/scripts/tools-md.ts +89 -0
  372. package/scripts/whoop-md.ts +119 -0
  373. package/src/build_info.ts +4 -0
  374. package/src/cli/app.ts +696 -0
  375. package/src/cli/auth.ts +350 -0
  376. package/src/cli/auth_flow.ts +356 -0
  377. package/src/cli/browser_login.ts +402 -0
  378. package/src/cli/clients.ts +467 -0
  379. package/src/cli/deploy_record.ts +100 -0
  380. package/src/cli/index.ts +41 -583
  381. package/src/cli/links.ts +43 -0
  382. package/src/cli/logo.ts +64 -0
  383. package/src/cli/setup.ts +1147 -979
  384. package/src/cli/spawn.ts +88 -0
  385. package/src/cli/sys.ts +267 -0
  386. package/src/cli/ui.ts +778 -436
  387. package/src/cli/update.ts +436 -274
  388. package/src/cloudflare/runtime.d.ts +27 -0
  389. package/src/cloudflare/token_store.ts +57 -0
  390. package/src/cloudflare/worker.ts +174 -0
  391. package/src/data/behaviors.ts +2760 -622
  392. package/src/data/endpoint_catalog.ts +2695 -0
  393. package/src/data/exercises.ts +379 -4861
  394. package/src/data/garments.ts +28 -0
  395. package/src/data/sports.ts +239 -211
  396. package/src/lib/activity_list.ts +150 -0
  397. package/src/lib/activity_records.ts +213 -0
  398. package/src/lib/activity_results.ts +51 -0
  399. package/src/lib/activity_types.ts +176 -0
  400. package/src/lib/brand.ts +71 -0
  401. package/src/lib/clock.ts +16 -0
  402. package/src/lib/coach_session.ts +434 -0
  403. package/src/lib/dates.ts +18 -0
  404. package/src/lib/env_file.ts +191 -0
  405. package/src/lib/health_plans_write.ts +53 -0
  406. package/src/lib/heart_rate.ts +42 -0
  407. package/src/lib/highlight.ts +71 -0
  408. package/src/lib/install_links.ts +61 -0
  409. package/src/lib/instant.ts +54 -0
  410. package/src/lib/journal_behaviors.ts +453 -0
  411. package/src/lib/lift_catalog.ts +258 -0
  412. package/src/lib/lift_history.ts +75 -0
  413. package/src/lib/lift_sets.ts +164 -0
  414. package/src/lib/lift_tool.ts +25 -0
  415. package/src/lib/profile_settings.ts +102 -0
  416. package/src/lib/screen_content.ts +40 -0
  417. package/src/lib/timezone.ts +44 -8
  418. package/src/lib/walk.ts +4 -1
  419. package/src/lib/weight_readings.ts +82 -0
  420. package/src/projections/activities.ts +199 -0
  421. package/src/projections/alarm_schedule.ts +98 -0
  422. package/src/projections/coach.ts +218 -0
  423. package/src/projections/community.ts +187 -0
  424. package/src/projections/health_features.ts +191 -0
  425. package/src/projections/hormonal_insights.ts +277 -0
  426. package/src/projections/journal_v2.ts +173 -0
  427. package/src/projections/lift_cards.ts +131 -0
  428. package/src/projections/lift_exercise_v2.ts +147 -0
  429. package/src/projections/lift_library_v2.ts +77 -0
  430. package/src/projections/lift_sessions.ts +250 -0
  431. package/src/projections/memory.ts +100 -0
  432. package/src/projections/milestones.ts +133 -0
  433. package/src/projections/profile_v2.ts +166 -0
  434. package/src/projections/settings_v2.ts +179 -0
  435. package/src/projections/sleep.ts +7 -21
  436. package/src/projections/v2/calendar.ts +48 -0
  437. package/src/projections/v2/core_common.ts +95 -0
  438. package/src/projections/v2/core_home.ts +177 -0
  439. package/src/projections/v2/core_sleep_need.ts +37 -0
  440. package/src/projections/v2/day.ts +162 -0
  441. package/src/projections/v2/heart_rate.ts +73 -0
  442. package/src/projections/v2/history.ts +153 -0
  443. package/src/projections/v2/now.ts +59 -0
  444. package/src/projections/v2/recovery.ts +120 -0
  445. package/src/projections/v2/sleep.ts +281 -0
  446. package/src/projections/v2/strain.ts +63 -0
  447. package/src/projections/v2/stress.ts +111 -0
  448. package/src/projections/v2/trend.ts +242 -0
  449. package/src/projections/weekly_plan.ts +79 -0
  450. package/src/projections/weight_readings.ts +57 -0
  451. package/src/projections/workout.ts +36 -17
  452. package/src/schemas/activities.ts +136 -0
  453. package/src/schemas/alarm_schedule.ts +70 -0
  454. package/src/schemas/coach.ts +98 -8
  455. package/src/schemas/community.ts +77 -0
  456. package/src/schemas/health.ts +36 -0
  457. package/src/schemas/hormonal_insights.ts +108 -0
  458. package/src/schemas/journal.ts +4 -0
  459. package/src/schemas/journal_v2.ts +112 -0
  460. package/src/schemas/memory.ts +48 -0
  461. package/src/schemas/milestones.ts +48 -0
  462. package/src/schemas/profile_v2.ts +63 -0
  463. package/src/schemas/settings_v2.ts +63 -0
  464. package/src/schemas/sleep.ts +9 -1
  465. package/src/schemas/strength.ts +10 -1
  466. package/src/schemas/strength_v2.ts +210 -0
  467. package/src/schemas/v2/calendar.ts +8 -0
  468. package/src/schemas/v2/core_common.ts +50 -0
  469. package/src/schemas/v2/day.ts +79 -0
  470. package/src/schemas/v2/now.ts +25 -0
  471. package/src/schemas/v2/recovery.ts +38 -0
  472. package/src/schemas/v2/sleep.ts +46 -0
  473. package/src/schemas/v2/strain.ts +16 -0
  474. package/src/schemas/v2/stress.ts +20 -0
  475. package/src/schemas/v2/trend.ts +45 -0
  476. package/src/schemas/weekly_plan.ts +36 -0
  477. package/src/schemas/weight.ts +53 -0
  478. package/src/scripts/build_behaviors.ts +116 -0
  479. package/src/scripts/cognito_bootstrap.ts +10 -249
  480. package/src/scripts/gen_activity_catalogs.ts +121 -0
  481. package/src/server-admin.ts +171 -0
  482. package/src/server-http.ts +290 -53
  483. package/src/server.ts +130 -26
  484. package/src/tools/annotations.ts +25 -0
  485. package/src/tools/define.ts +53 -0
  486. package/src/tools/register.ts +64 -94
  487. package/src/tools/resources.ts +92 -0
  488. package/src/tools/slim_schema.ts +102 -0
  489. package/src/tools/v2/activity_delete.ts +61 -23
  490. package/src/tools/v2/activity_edit.ts +378 -0
  491. package/src/tools/v2/activity_log.ts +154 -0
  492. package/src/tools/v2/calendar.ts +22 -21
  493. package/src/tools/v2/coach_ask.ts +83 -119
  494. package/src/tools/v2/coach_history.ts +140 -0
  495. package/src/tools/v2/community.ts +137 -0
  496. package/src/tools/v2/cycle.ts +78 -20
  497. package/src/tools/v2/cycle_log.ts +291 -40
  498. package/src/tools/v2/day.ts +126 -25
  499. package/src/tools/v2/health.ts +114 -0
  500. package/src/tools/v2/hr_zones_set.ts +132 -45
  501. package/src/tools/v2/journal.ts +78 -23
  502. package/src/tools/v2/journal_log.ts +321 -69
  503. package/src/tools/v2/lift_exercise.ts +135 -27
  504. package/src/tools/v2/lift_exercise_set.ts +272 -0
  505. package/src/tools/v2/lift_library.ts +57 -21
  506. package/src/tools/v2/lift_log.ts +325 -83
  507. package/src/tools/v2/lift_sessions.ts +255 -0
  508. package/src/tools/v2/lift_template.ts +229 -0
  509. package/src/tools/v2/memory.ts +54 -0
  510. package/src/tools/v2/memory_set.ts +110 -0
  511. package/src/tools/v2/milestones.ts +59 -0
  512. package/src/tools/v2/now.ts +61 -0
  513. package/src/tools/v2/preferences.ts +61 -0
  514. package/src/tools/v2/preferences_set.ts +403 -0
  515. package/src/tools/v2/profile.ts +56 -26
  516. package/src/tools/v2/profile_update.ts +151 -60
  517. package/src/tools/v2/raw.ts +89 -36
  518. package/src/tools/v2/recovery.ts +44 -25
  519. package/src/tools/v2/sleep.ts +57 -18
  520. package/src/tools/v2/smart_alarm.ts +62 -24
  521. package/src/tools/v2/smart_alarm_set.ts +240 -90
  522. package/src/tools/v2/strain.ts +19 -16
  523. package/src/tools/v2/stress.ts +22 -17
  524. package/src/tools/v2/trend.ts +58 -20
  525. package/src/tools/v2/weekly_plan.ts +38 -0
  526. package/src/tools/v2/weekly_plan_set.ts +132 -0
  527. package/src/tools/v2/weight.ts +61 -0
  528. package/src/tools/v2/weight_log.ts +193 -0
  529. package/src/tools/v2/workouts.ts +156 -26
  530. package/src/version.ts +5 -0
  531. package/src/whoop/bff.ts +84 -0
  532. package/src/whoop/client.ts +448 -18
  533. package/src/whoop/cognito.ts +110 -99
  534. package/src/whoop/connect_page.ts +183 -0
  535. package/src/whoop/consent_font.ts +289 -0
  536. package/src/whoop/consent_logos.ts +24 -0
  537. package/src/whoop/consent_page.ts +326 -0
  538. package/src/whoop/constants.ts +5 -1
  539. package/src/whoop/device.ts +4 -4
  540. package/src/whoop/errors.ts +89 -4
  541. package/src/whoop/init_timezone.ts +57 -16
  542. package/src/whoop/installation.ts +16 -7
  543. package/src/whoop/json_out.ts +51 -6
  544. package/src/whoop/oauth_provider.ts +84 -91
  545. package/src/whoop/token_lock.ts +345 -0
  546. package/src/whoop/token_manager.ts +580 -53
  547. package/src/whoop/token_store.ts +341 -32
  548. package/src/whoop/units.ts +35 -0
  549. package/wrangler.jsonc +17 -0
  550. package/assets/banner.svg +0 -38
  551. package/dist/data/endpoints.js +0 -320
  552. package/dist/data/endpoints.js.map +0 -1
  553. package/dist/lib/format.js +0 -22
  554. package/dist/lib/format.js.map +0 -1
  555. package/dist/lib/stats.js +0 -32
  556. package/dist/lib/stats.js.map +0 -1
  557. package/dist/projections/calendar.js +0 -33
  558. package/dist/projections/calendar.js.map +0 -1
  559. package/dist/projections/communities.js +0 -105
  560. package/dist/projections/communities.js.map +0 -1
  561. package/dist/projections/cycle.js +0 -81
  562. package/dist/projections/cycle.js.map +0 -1
  563. package/dist/projections/hr_zones.js +0 -35
  564. package/dist/projections/hr_zones.js.map +0 -1
  565. package/dist/projections/journal.js +0 -56
  566. package/dist/projections/journal.js.map +0 -1
  567. package/dist/projections/leaderboard.js +0 -37
  568. package/dist/projections/leaderboard.js.map +0 -1
  569. package/dist/projections/lift_exercise.js +0 -22
  570. package/dist/projections/lift_exercise.js.map +0 -1
  571. package/dist/projections/lift_history.js +0 -133
  572. package/dist/projections/lift_history.js.map +0 -1
  573. package/dist/projections/lift_library.js +0 -71
  574. package/dist/projections/lift_library.js.map +0 -1
  575. package/dist/projections/lift_progression.js +0 -138
  576. package/dist/projections/lift_progression.js.map +0 -1
  577. package/dist/projections/lift_prs.js +0 -20
  578. package/dist/projections/lift_prs.js.map +0 -1
  579. package/dist/projections/live_hr.js +0 -19
  580. package/dist/projections/live_hr.js.map +0 -1
  581. package/dist/projections/live_state.js +0 -23
  582. package/dist/projections/live_state.js.map +0 -1
  583. package/dist/projections/live_stress.js +0 -11
  584. package/dist/projections/live_stress.js.map +0 -1
  585. package/dist/projections/performance_assessment.js +0 -15
  586. package/dist/projections/performance_assessment.js.map +0 -1
  587. package/dist/projections/profile.js +0 -59
  588. package/dist/projections/profile.js.map +0 -1
  589. package/dist/projections/recovery.js +0 -131
  590. package/dist/projections/recovery.js.map +0 -1
  591. package/dist/projections/sleep_need.js +0 -32
  592. package/dist/projections/sleep_need.js.map +0 -1
  593. package/dist/projections/smart_alarm.js +0 -45
  594. package/dist/projections/smart_alarm.js.map +0 -1
  595. package/dist/projections/strain.js +0 -128
  596. package/dist/projections/strain.js.map +0 -1
  597. package/dist/projections/stress.js +0 -86
  598. package/dist/projections/stress.js.map +0 -1
  599. package/dist/projections/today.js +0 -129
  600. package/dist/projections/today.js.map +0 -1
  601. package/dist/projections/trend.js +0 -149
  602. package/dist/projections/trend.js.map +0 -1
  603. package/dist/projections/workouts.js +0 -37
  604. package/dist/projections/workouts.js.map +0 -1
  605. package/dist/schemas/calendar.js +0 -12
  606. package/dist/schemas/calendar.js.map +0 -1
  607. package/dist/schemas/communities.js +0 -51
  608. package/dist/schemas/communities.js.map +0 -1
  609. package/dist/schemas/compare.js +0 -15
  610. package/dist/schemas/compare.js.map +0 -1
  611. package/dist/schemas/leaderboard.js +0 -25
  612. package/dist/schemas/leaderboard.js.map +0 -1
  613. package/dist/schemas/live.js +0 -26
  614. package/dist/schemas/live.js.map +0 -1
  615. package/dist/schemas/performance.js +0 -12
  616. package/dist/schemas/performance.js.map +0 -1
  617. package/dist/schemas/profile.js +0 -39
  618. package/dist/schemas/profile.js.map +0 -1
  619. package/dist/schemas/recovery.js +0 -27
  620. package/dist/schemas/recovery.js.map +0 -1
  621. package/dist/schemas/settings.js +0 -26
  622. package/dist/schemas/settings.js.map +0 -1
  623. package/dist/schemas/sleep_need.js +0 -15
  624. package/dist/schemas/sleep_need.js.map +0 -1
  625. package/dist/schemas/smart_alarm.js +0 -36
  626. package/dist/schemas/smart_alarm.js.map +0 -1
  627. package/dist/schemas/strain.js +0 -24
  628. package/dist/schemas/strain.js.map +0 -1
  629. package/dist/schemas/stress.js +0 -16
  630. package/dist/schemas/stress.js.map +0 -1
  631. package/dist/schemas/today.js +0 -38
  632. package/dist/schemas/today.js.map +0 -1
  633. package/dist/schemas/trend.js +0 -50
  634. package/dist/schemas/trend.js.map +0 -1
  635. package/dist/schemas/womens_health.js +0 -23
  636. package/dist/schemas/womens_health.js.map +0 -1
  637. package/dist/tools/v2/activity_create.js +0 -64
  638. package/dist/tools/v2/activity_create.js.map +0 -1
  639. package/dist/tools/v2/behavior_impact.js +0 -36
  640. package/dist/tools/v2/behavior_impact.js.map +0 -1
  641. package/dist/tools/v2/communities.js +0 -60
  642. package/dist/tools/v2/communities.js.map +0 -1
  643. package/dist/tools/v2/compare.js +0 -67
  644. package/dist/tools/v2/compare.js.map +0 -1
  645. package/dist/tools/v2/endpoints.js +0 -28
  646. package/dist/tools/v2/endpoints.js.map +0 -1
  647. package/dist/tools/v2/hidden_metric.js +0 -28
  648. package/dist/tools/v2/hidden_metric.js.map +0 -1
  649. package/dist/tools/v2/hr_zones.js +0 -24
  650. package/dist/tools/v2/hr_zones.js.map +0 -1
  651. package/dist/tools/v2/journal_autopop.js +0 -19
  652. package/dist/tools/v2/journal_autopop.js.map +0 -1
  653. package/dist/tools/v2/journal_catalog.js +0 -44
  654. package/dist/tools/v2/journal_catalog.js.map +0 -1
  655. package/dist/tools/v2/leaderboard.js +0 -79
  656. package/dist/tools/v2/leaderboard.js.map +0 -1
  657. package/dist/tools/v2/lift_catalog.js +0 -47
  658. package/dist/tools/v2/lift_catalog.js.map +0 -1
  659. package/dist/tools/v2/lift_custom_exercise.js +0 -108
  660. package/dist/tools/v2/lift_custom_exercise.js.map +0 -1
  661. package/dist/tools/v2/lift_history.js +0 -39
  662. package/dist/tools/v2/lift_history.js.map +0 -1
  663. package/dist/tools/v2/lift_progression.js +0 -30
  664. package/dist/tools/v2/lift_progression.js.map +0 -1
  665. package/dist/tools/v2/lift_prs.js +0 -21
  666. package/dist/tools/v2/lift_prs.js.map +0 -1
  667. package/dist/tools/v2/lift_template_save.js +0 -83
  668. package/dist/tools/v2/lift_template_save.js.map +0 -1
  669. package/dist/tools/v2/live_hr.js +0 -21
  670. package/dist/tools/v2/live_hr.js.map +0 -1
  671. package/dist/tools/v2/live_state.js +0 -21
  672. package/dist/tools/v2/live_state.js.map +0 -1
  673. package/dist/tools/v2/live_stress.js +0 -22
  674. package/dist/tools/v2/live_stress.js.map +0 -1
  675. package/dist/tools/v2/performance_assessment.js +0 -38
  676. package/dist/tools/v2/performance_assessment.js.map +0 -1
  677. package/dist/tools/v2/sleep_need.js +0 -21
  678. package/dist/tools/v2/sleep_need.js.map +0 -1
  679. package/dist/tools/v2/sports_catalog.js +0 -26
  680. package/dist/tools/v2/sports_catalog.js.map +0 -1
  681. package/dist/tools/v2/symptom_log.js +0 -72
  682. package/dist/tools/v2/symptom_log.js.map +0 -1
  683. package/dist/tools/v2/today.js +0 -30
  684. package/dist/tools/v2/today.js.map +0 -1
  685. package/dist/tools/v2/workout.js +0 -23
  686. package/dist/tools/v2/workout.js.map +0 -1
  687. package/dist/whoop/build_lift_body.js +0 -67
  688. package/dist/whoop/build_lift_body.js.map +0 -1
  689. package/dist/whoop/session_state.js +0 -34
  690. package/dist/whoop/session_state.js.map +0 -1
  691. package/dist/whoop/types.js +0 -82
  692. package/dist/whoop/types.js.map +0 -1
  693. package/src/data/endpoints.ts +0 -319
  694. package/src/lib/format.ts +0 -27
  695. package/src/lib/stats.ts +0 -35
  696. package/src/projections/calendar.ts +0 -46
  697. package/src/projections/communities.ts +0 -135
  698. package/src/projections/cycle.ts +0 -85
  699. package/src/projections/hr_zones.ts +0 -43
  700. package/src/projections/journal.ts +0 -55
  701. package/src/projections/leaderboard.ts +0 -49
  702. package/src/projections/lift_exercise.ts +0 -29
  703. package/src/projections/lift_history.ts +0 -140
  704. package/src/projections/lift_library.ts +0 -70
  705. package/src/projections/lift_progression.ts +0 -138
  706. package/src/projections/lift_prs.ts +0 -23
  707. package/src/projections/live_hr.ts +0 -21
  708. package/src/projections/live_state.ts +0 -28
  709. package/src/projections/live_stress.ts +0 -13
  710. package/src/projections/performance_assessment.ts +0 -19
  711. package/src/projections/profile.ts +0 -71
  712. package/src/projections/recovery.ts +0 -133
  713. package/src/projections/sleep_need.ts +0 -36
  714. package/src/projections/smart_alarm.ts +0 -70
  715. package/src/projections/strain.ts +0 -131
  716. package/src/projections/stress.ts +0 -95
  717. package/src/projections/today.ts +0 -166
  718. package/src/projections/trend.ts +0 -149
  719. package/src/projections/workouts.ts +0 -36
  720. package/src/schemas/calendar.ts +0 -13
  721. package/src/schemas/communities.ts +0 -56
  722. package/src/schemas/compare.ts +0 -17
  723. package/src/schemas/leaderboard.ts +0 -26
  724. package/src/schemas/live.ts +0 -31
  725. package/src/schemas/performance.ts +0 -13
  726. package/src/schemas/profile.ts +0 -40
  727. package/src/schemas/recovery.ts +0 -28
  728. package/src/schemas/settings.ts +0 -30
  729. package/src/schemas/sleep_need.ts +0 -16
  730. package/src/schemas/smart_alarm.ts +0 -40
  731. package/src/schemas/strain.ts +0 -25
  732. package/src/schemas/stress.ts +0 -17
  733. package/src/schemas/today.ts +0 -39
  734. package/src/schemas/trend.ts +0 -53
  735. package/src/schemas/womens_health.ts +0 -26
  736. package/src/tools/v2/activity_create.ts +0 -74
  737. package/src/tools/v2/behavior_impact.ts +0 -39
  738. package/src/tools/v2/communities.ts +0 -65
  739. package/src/tools/v2/compare.ts +0 -83
  740. package/src/tools/v2/endpoints.ts +0 -32
  741. package/src/tools/v2/hidden_metric.ts +0 -33
  742. package/src/tools/v2/hr_zones.ts +0 -29
  743. package/src/tools/v2/journal_autopop.ts +0 -26
  744. package/src/tools/v2/journal_catalog.ts +0 -48
  745. package/src/tools/v2/leaderboard.ts +0 -92
  746. package/src/tools/v2/lift_catalog.ts +0 -48
  747. package/src/tools/v2/lift_custom_exercise.ts +0 -117
  748. package/src/tools/v2/lift_history.ts +0 -52
  749. package/src/tools/v2/lift_progression.ts +0 -34
  750. package/src/tools/v2/lift_prs.ts +0 -26
  751. package/src/tools/v2/lift_template_save.ts +0 -89
  752. package/src/tools/v2/live_hr.ts +0 -26
  753. package/src/tools/v2/live_state.ts +0 -26
  754. package/src/tools/v2/live_stress.ts +0 -27
  755. package/src/tools/v2/performance_assessment.ts +0 -44
  756. package/src/tools/v2/sleep_need.ts +0 -26
  757. package/src/tools/v2/sports_catalog.ts +0 -32
  758. package/src/tools/v2/symptom_log.ts +0 -78
  759. package/src/tools/v2/today.ts +0 -35
  760. package/src/tools/v2/workout.ts +0 -28
  761. package/src/whoop/build_lift_body.ts +0 -84
  762. package/src/whoop/session_state.ts +0 -41
  763. package/src/whoop/types.ts +0 -89
@@ -1,60 +1,554 @@
1
- // Holds the current access token + refresh token, auto-refreshes via Cognito
2
- // when the access token is within `refreshSkewSeconds` of expiry. Writes
3
- // rotated tokens to an injected TokenStore so server restarts pick up fresh
4
- // state without re-bootstrapping.
5
- import { decodeJwtExp, refreshCognitoSession } from "./cognito.js";
6
- import { EnvFileTokenStore } from "./token_store.js";
1
+ // Holds the WHOOP login, refreshes it, and keeps it alive.
2
+ //
3
+ // - Durable (G6): every rotated refresh token is written to the TokenStore
4
+ // BEFORE the new access token is handed out. A failed write is fatal: the old
5
+ // refresh token is already spent, so carrying on would strand the login at the
6
+ // next restart.
7
+ // - Keep-alive (G7): refresh when less than 10 minutes of access life remain,
8
+ // plus a periodic refresh (default every 12 h, TOTEM_KEEPALIVE_HOURS) so an
9
+ // idle server never lets the refresh token go unused. The timer is unref'd and
10
+ // shares the single-flight with on-demand refreshes.
11
+ // - One owner (G8): with a TokenLock, only the lock holder refreshes. Another
12
+ // process on the same token file runs as a follower: it picks up the owner's
13
+ // rotated tokens from the file and never refreshes; it takes over only when
14
+ // the owner's lock goes stale, and otherwise fails with WhoopTokenOwnedError.
15
+ // - The file is the source of truth: when another writer changes it (`totem
16
+ // auth`, a push to the admin endpoint), the manager adopts the new login on
17
+ // its next call, without a restart.
18
+ // - G9: WhoopAuthExpiredError only when Cognito refuses the refresh itself.
19
+ import { CognitoError, decodeJwtExp, refreshCognitoSession } from "./cognito.js";
20
+ import { WhoopAuthExpiredError } from "./errors.js";
21
+ import { WhoopTokenOwnedError } from "./token_lock.js";
22
+ import { isHandoff } from "./token_store.js";
23
+ const MINUTE = 60_000;
24
+ const HOUR = 60 * MINUTE;
25
+ /**
26
+ * The keep-alive timer wakes at least this often and compares wall clocks.
27
+ * Node's timers count running time, which on Linux excludes suspend: a timer
28
+ * set for "in 12 hours" would fire 12 hours of awake time later.
29
+ */
30
+ const MAX_TICK_MS = MINUTE;
31
+ /**
32
+ * A token we refreshed less than this long ago is used as it is, whatever its
33
+ * `exp` says. Without it a clock running far ahead (every new token looks
34
+ * expired on arrival), an undecodable token or a tiny TOTEM_KEEPALIVE_HOURS
35
+ * turns every call or every second into a refresh, and each refresh rotates
36
+ * the refresh token. A 401 still forces a refresh (see invalidate()).
37
+ */
38
+ const MIN_REFRESH_GAP_MS = 5 * MINUTE;
39
+ /** A follower lets the owner go first, then checks. */
40
+ const FOLLOWER_GRACE_MS = 2 * MINUTE;
41
+ /** A follower re-checks this often while a live owner hasn't refreshed yet. */
42
+ const FOLLOWER_POLL_MS = 5 * MINUTE;
43
+ /** A follower keeps using an access token until this close to expiry. */
44
+ const FOLLOWER_MIN_LIFE_MS = 30_000;
45
+ /** No login saved on this server or machine. */
46
+ export class WhoopNotLoggedInError extends WhoopAuthExpiredError {
47
+ constructor(where) {
48
+ super();
49
+ this.message = `No WHOOP login on this server (${where}). Run \`totem auth\` to log in (without the totem command: \`npx @thebriangao/totem auth --local\`).`;
50
+ this.name = "WhoopNotLoggedInError";
51
+ }
52
+ }
53
+ /** This copy's login was pushed to a deployment by `totem auth`; it must not refresh. */
54
+ export class WhoopLoginHandedOffError extends WhoopAuthExpiredError {
55
+ to;
56
+ constructor(to, at) {
57
+ super();
58
+ this.to = to;
59
+ this.message =
60
+ `This WHOOP login was handed to ${to} (${at.slice(0, 10)}), so this copy no longer refreshes it. ` +
61
+ "Run `totem auth --local` to give this machine its own login.";
62
+ this.name = "WhoopLoginHandedOffError";
63
+ }
64
+ }
65
+ /** The rotated refresh token could not be written. Fatal: the old one is spent. */
66
+ export class WhoopTokenPersistError extends Error {
67
+ constructor(where, cause) {
68
+ super(`Couldn't save the rotated WHOOP refresh token to ${where} (${cause instanceof Error ? cause.message : String(cause)}). ` +
69
+ "The previous refresh token is already spent, so this login can't survive a restart. Fix the disk, then run `totem auth`.");
70
+ this.name = "WhoopTokenPersistError";
71
+ }
72
+ }
73
+ /**
74
+ * The token directory can't be written right now, found out BEFORE spending the
75
+ * refresh token. Nothing is lost: the login is still valid and refreshes again
76
+ * once the disk is writable.
77
+ */
78
+ export class WhoopTokenUnwritableError extends Error {
79
+ constructor(where, cause) {
80
+ super(`Can't write next to the WHOOP token file ${where} (${cause instanceof Error ? cause.message : String(cause)}), ` +
81
+ "so the token wasn't refreshed (a rotated refresh token that can't be saved would end the login). Fix the disk or its permissions.");
82
+ this.name = "WhoopTokenUnwritableError";
83
+ }
84
+ }
85
+ /** The refresh failed for a reason other than a refused login (network, throttling, outage). */
86
+ export class WhoopRefreshUnavailableError extends Error {
87
+ constructor(cause) {
88
+ super(`Couldn't reach WHOOP's login service to refresh the token (${cause instanceof Error ? cause.message : String(cause)}). Try again shortly.`);
89
+ this.name = "WhoopRefreshUnavailableError";
90
+ }
91
+ }
7
92
  export class TokenManager {
8
- email;
9
- accessToken;
10
- refreshToken;
11
- expiresAt; // epoch ms
12
- skewMs;
13
93
  store;
94
+ lock;
95
+ skewMs;
96
+ keepAliveMs;
97
+ retryBaseMs;
98
+ saveAttempts;
99
+ now;
100
+ refreshFn;
101
+ log;
102
+ onFatal;
103
+ onLoginChange;
104
+ record = null;
105
+ handoff = null;
106
+ expired = null;
107
+ fatal = null;
108
+ forceRefresh = false;
109
+ lastRefreshAt = 0;
110
+ seenVersion = null;
111
+ /** Version of a token file that failed to load (reported once). */
112
+ unreadableVersion = undefined;
113
+ loaded = false;
14
114
  refreshing = null;
115
+ timer = null;
116
+ nextAt = null;
117
+ retryMs;
118
+ stopped = true;
119
+ ownerHint = null;
15
120
  constructor(config) {
16
- this.email = config.email;
17
- this.accessToken = config.accessToken;
18
- this.refreshToken = config.refreshToken;
19
- this.skewMs = (config.refreshSkewSeconds ?? 60) * 1000;
20
- this.expiresAt = decodeJwtExp(config.accessToken) * 1000;
21
- if (config.store) {
22
- this.store = config.store;
121
+ this.store = config.store;
122
+ this.lock = config.lock ?? null;
123
+ this.skewMs = config.refreshSkewMs ?? 10 * MINUTE;
124
+ this.keepAliveMs = config.keepAliveMs ?? 12 * HOUR;
125
+ this.retryBaseMs = config.retryBaseMs ?? MINUTE;
126
+ this.retryMs = this.retryBaseMs;
127
+ this.saveAttempts = Math.max(1, config.saveAttempts ?? 3);
128
+ this.now = config.now ?? Date.now;
129
+ this.refreshFn = config.refresh ?? refreshCognitoSession;
130
+ this.log = config.log ?? ((m) => console.error(`[totem] ${m}`));
131
+ this.onFatal = config.onFatal;
132
+ this.onLoginChange = config.onLoginChange;
133
+ }
134
+ /** Load the saved login, claim ownership, and start the keep-alive timer. */
135
+ start() {
136
+ this.stopped = false;
137
+ this.sync(true);
138
+ if (this.lock) {
139
+ const result = this.lock.tryAcquire();
140
+ if (result.acquired) {
141
+ this.lock.startHeartbeat(() => this.log("lost the token lock to another process; this process won't refresh any more"));
142
+ }
143
+ else {
144
+ this.ownerHint = result.holder;
145
+ this.log(`another totem process (pid ${result.holder?.pid ?? "?"}) owns this login; this one follows its token file and won't refresh`);
146
+ }
23
147
  }
24
- else if (config.envPath) {
25
- this.store = new EnvFileTokenStore(config.envPath);
148
+ this.schedule();
149
+ }
150
+ /** Stop the timer and release the lock. */
151
+ stop() {
152
+ this.stopped = true;
153
+ this.clearTimer();
154
+ this.lock?.release();
155
+ }
156
+ /**
157
+ * When the keep-alive next means to refresh (epoch ms), or null when there is
158
+ * nothing to keep alive. A host that may freeze the process between requests
159
+ * (a Cloudflare Durable Object) schedules its own wake-up for this time.
160
+ */
161
+ nextRefreshAt() {
162
+ return this.nextAt;
163
+ }
164
+ /**
165
+ * Run the keep-alive now if it is due: the host's scheduled wake-up, for when
166
+ * a timer can't be trusted to survive. Errors are handled as the timer's are
167
+ * (logged, retried with backoff), so this never throws.
168
+ */
169
+ async wake() {
170
+ if (this.stopped)
171
+ return;
172
+ this.sync();
173
+ if (!this.record || this.handoff || this.fatal || this.expired)
174
+ return;
175
+ if (this.now() < this.dueAt(this.record))
176
+ return;
177
+ this.clearTimer();
178
+ await this.keepAlive();
179
+ }
180
+ /** The current access token, refreshing first when needed. */
181
+ async getToken() {
182
+ this.sync();
183
+ const record = this.usable();
184
+ if (!this.needsRefresh(record))
185
+ return record.access_token;
186
+ await this.ensureFresh("on demand", (r) => this.needsRefresh(r));
187
+ return this.usable().access_token;
188
+ }
189
+ /**
190
+ * WHOOP answered 401 with `rejectedToken`: force the next getToken() to refresh.
191
+ * Ignored when that token is no longer current (parallel 401s cost one refresh)
192
+ * or within a minute of the last refresh (a token WHOOP keeps rejecting is
193
+ * path-specific, not expired; see client.ts).
194
+ */
195
+ invalidate(rejectedToken) {
196
+ if (rejectedToken !== this.record?.access_token)
197
+ return;
198
+ if (this.now() - this.lastRefreshAt < MINUTE)
199
+ return;
200
+ this.forceRefresh = true;
201
+ }
202
+ /**
203
+ * Install a new login (POST /admin/tokens). Persists it first; throws when the
204
+ * write fails, leaving the previous login in place.
205
+ */
206
+ adopt(record) {
207
+ if (this.lock && !this.lock.held) {
208
+ const result = this.lock.tryAcquire();
209
+ if (result.acquired)
210
+ this.lock.startHeartbeat();
26
211
  }
27
- else {
28
- throw new Error("TokenManager: pass either `store` or `envPath`");
212
+ this.store.save(record);
213
+ this.seenVersion = this.store.version();
214
+ this.loaded = true;
215
+ this.setRecord(record, null);
216
+ this.lastRefreshAt = 0;
217
+ this.fatal = null;
218
+ this.retryMs = this.retryBaseMs;
219
+ this.log(`installed a new WHOOP login (${record.source}); saved to ${this.store.description}`);
220
+ this.schedule();
221
+ }
222
+ /** Record extra fields on the current login (owner only, best-effort). */
223
+ annotate(patch) {
224
+ // Start from the file, and only as the proven owner: writing our in-memory
225
+ // copy as a process that lost the lock would put a spent refresh token back
226
+ // over the one the new owner rotated.
227
+ this.sync();
228
+ if (!this.record || (this.lock && !this.lock.verify()))
229
+ return;
230
+ const next = { ...this.record };
231
+ if (patch.user_id !== undefined)
232
+ next.user_id = patch.user_id;
233
+ if (patch.installation_id !== undefined)
234
+ next.installation_id = patch.installation_id;
235
+ try {
236
+ this.store.save(next);
237
+ this.seenVersion = this.store.version();
238
+ this.record = next;
239
+ }
240
+ catch (error) {
241
+ this.log(`couldn't update ${this.store.description}: ${error.message}`);
29
242
  }
30
243
  }
31
- async getToken() {
32
- if (this.isFresh())
33
- return this.accessToken;
34
- // Single-flight: if a refresh is already running, wait on it
244
+ /** The current login, if any (after picking up file changes). */
245
+ current() {
246
+ this.sync();
247
+ return this.record;
248
+ }
249
+ status() {
250
+ this.sync();
251
+ const role = !this.lock ? "solo" : this.lock.held ? "owner" : "follower";
252
+ const r = this.record;
253
+ const state = this.fatal ? "fatal"
254
+ : this.handoff ? "handed-off"
255
+ : !r ? "no-login"
256
+ : this.expired ? "expired"
257
+ : "ok";
258
+ const exp = r ? decodeJwtExp(r.access_token) * 1000 : 0;
259
+ const owner = role === "follower" ? (this.lock?.readHolder() ?? this.ownerHint) : null;
260
+ return {
261
+ state,
262
+ role,
263
+ store: this.store.description,
264
+ source: r?.source,
265
+ client_id: r?.client_id,
266
+ user_id: r?.user_id ?? this.handoff?.user_id,
267
+ saved_at: r?.saved_at ?? this.handoff?.saved_at,
268
+ refreshed_at: r?.refreshed_at,
269
+ access_expires_at: exp ? new Date(exp).toISOString() : undefined,
270
+ next_keepalive_at: this.nextAt ? new Date(this.nextAt).toISOString() : undefined,
271
+ handed_off_to: this.handoff?.handed_off_to,
272
+ owner: owner ? { pid: owner.pid, host: owner.host } : undefined,
273
+ detail: this.fatal?.message ?? this.expired ?? undefined,
274
+ };
275
+ }
276
+ // ── internals ────────────────────────────────────────────────────────────
277
+ /** The current record, or the error explaining why there isn't a usable one. */
278
+ usable() {
279
+ if (this.fatal)
280
+ throw this.fatal;
281
+ if (this.handoff)
282
+ throw new WhoopLoginHandedOffError(this.handoff.handed_off_to, this.handoff.saved_at);
283
+ if (!this.record)
284
+ throw new WhoopNotLoggedInError(this.store.description);
285
+ if (this.expired)
286
+ throw new WhoopAuthExpiredError(this.expired);
287
+ return this.record;
288
+ }
289
+ timeLeft(record) {
290
+ return decodeJwtExp(record.access_token) * 1000 - this.now();
291
+ }
292
+ /** Last refresh (or login) time of a record, epoch ms. */
293
+ refreshedAt(record) {
294
+ const t = Date.parse(record.refreshed_at ?? record.saved_at);
295
+ return Number.isFinite(t) ? t : 0;
296
+ }
297
+ /**
298
+ * Whether this record came out of a refresh less than MIN_REFRESH_GAP_MS ago
299
+ * (by `refreshed_at`, which only a refresh writes; a timestamp in the future
300
+ * means the clock was changed, and counts as "no").
301
+ */
302
+ justRefreshed(record) {
303
+ const at = Date.parse(record.refreshed_at ?? "");
304
+ if (!Number.isFinite(at))
305
+ return false;
306
+ const since = this.now() - at;
307
+ return since >= 0 && since < MIN_REFRESH_GAP_MS;
308
+ }
309
+ /** Whether a call must refresh before it gets a token. */
310
+ needsRefresh(record) {
311
+ if (this.forceRefresh)
312
+ return true;
313
+ return this.timeLeft(record) <= this.skewMs && !this.justRefreshed(record);
314
+ }
315
+ /** When the keep-alive should next refresh this record. */
316
+ dueAt(record) {
317
+ const byExpiry = decodeJwtExp(record.access_token) * 1000 - this.skewMs;
318
+ const byPeriod = this.keepAliveMs > 0 ? this.refreshedAt(record) + this.keepAliveMs : Infinity;
319
+ const due = Math.min(byExpiry, byPeriod);
320
+ return this.justRefreshed(record) ? Math.max(due, Date.parse(record.refreshed_at) + MIN_REFRESH_GAP_MS) : due;
321
+ }
322
+ /** dueAt, plus a grace period for a follower so the owner goes first. */
323
+ followerAwareDue(record) {
324
+ return this.dueAt(record) + (this.lock && !this.lock.held ? FOLLOWER_GRACE_MS : 0);
325
+ }
326
+ /** Re-read the store when it changed (or when forced). */
327
+ sync(force = false) {
328
+ const version = this.store.version();
329
+ if (!force && this.loaded && version === this.seenVersion)
330
+ return;
331
+ let content;
332
+ try {
333
+ content = this.store.load();
334
+ }
335
+ catch (error) {
336
+ // Keep what we have and look again on the next call. Say so once per
337
+ // bad file, not on every call.
338
+ if (version !== this.unreadableVersion)
339
+ this.log(error.message);
340
+ this.unreadableVersion = version;
341
+ return;
342
+ }
343
+ this.unreadableVersion = undefined;
344
+ this.loaded = true;
345
+ this.seenVersion = version;
346
+ if (!content)
347
+ this.setRecord(null, null);
348
+ else if (isHandoff(content))
349
+ this.setRecord(null, content);
350
+ else
351
+ this.setRecord(content, null);
352
+ }
353
+ setRecord(record, handoff) {
354
+ const before = this.record;
355
+ const newLogin = (before?.saved_at ?? null) !== (record?.saved_at ?? null) ||
356
+ (before?.source ?? null) !== (record?.source ?? null) ||
357
+ Boolean(this.handoff) !== Boolean(handoff);
358
+ if (before?.refresh_token !== record?.refresh_token) {
359
+ this.expired = null;
360
+ this.forceRefresh = false;
361
+ }
362
+ this.record = record;
363
+ this.handoff = handoff;
364
+ if (newLogin && this.loaded) {
365
+ this.onLoginChange?.(record);
366
+ if (!this.stopped)
367
+ this.schedule();
368
+ }
369
+ }
370
+ /** Make sure we own the login (or may take it over). */
371
+ claim() {
372
+ if (!this.lock)
373
+ return true;
374
+ if (!this.lock.held) {
375
+ const result = this.lock.tryAcquire();
376
+ if (!result.acquired) {
377
+ this.ownerHint = result.holder;
378
+ return false;
379
+ }
380
+ this.log(`took over the WHOOP login${this.ownerHint ? ` from pid ${this.ownerHint.pid}, which stopped` : ""}`);
381
+ this.ownerHint = null;
382
+ this.lock.startHeartbeat(() => this.log("lost the token lock to another process; this process won't refresh any more"));
383
+ }
384
+ // Whether we held the lock all along or took it over a moment ago: prove,
385
+ // under the guard, that the lock file names us, and stamp a fresh heartbeat,
386
+ // right before the refresh token is spent. Believing isn't enough: after a
387
+ // laptop sleep our heartbeat is hours old and a follower waking beside us
388
+ // would take the "stale" lock while our refresh is on the wire.
389
+ let state;
390
+ try {
391
+ state = this.lock.confirm();
392
+ }
393
+ catch (error) {
394
+ // The lock sits next to the token file. If it can't be written, the
395
+ // rotated refresh token couldn't be saved either: don't spend this one.
396
+ throw new WhoopTokenUnwritableError(this.store.description, error);
397
+ }
398
+ if (state === "held")
399
+ return true;
400
+ this.ownerHint = this.lock.readHolder(); // lost, or another process is changing the lock right now
401
+ return false;
402
+ }
403
+ ensureFresh(reason, mustRefresh) {
35
404
  if (!this.refreshing) {
36
- this.refreshing = this.doRefresh().finally(() => {
405
+ this.refreshing = this.refreshOnce(reason, mustRefresh).finally(() => {
37
406
  this.refreshing = null;
38
407
  });
39
408
  }
40
- await this.refreshing;
41
- return this.accessToken;
409
+ return this.refreshing;
42
410
  }
43
- isFresh() {
44
- return Date.now() < this.expiresAt - this.skewMs;
411
+ async refreshOnce(reason, mustRefresh) {
412
+ if (!this.claim()) {
413
+ // Follower: the owner refreshes and writes the file; we only read it.
414
+ this.sync(true);
415
+ const record = this.usable();
416
+ this.forceRefresh = false;
417
+ if (this.timeLeft(record) > FOLLOWER_MIN_LIFE_MS || this.justRefreshed(record))
418
+ return;
419
+ throw new WhoopTokenOwnedError(this.ownerHint, this.lock.path);
420
+ }
421
+ // Pick up a login another writer saved (`totem auth`) before spending ours.
422
+ this.sync();
423
+ const before = this.usable();
424
+ if (!mustRefresh(before))
425
+ return;
426
+ const versionBefore = this.store.version();
427
+ let next;
428
+ try {
429
+ next = await this.refreshFn(before.refresh_token, before.client_id);
430
+ }
431
+ catch (error) {
432
+ if (error instanceof CognitoError && error.isAuthFailure) {
433
+ this.expired = error.message;
434
+ this.log(`WHOOP refused the refresh token (${error.message}). Run \`totem auth\` to log in again.`);
435
+ throw new WhoopAuthExpiredError(error.message);
436
+ }
437
+ throw new WhoopRefreshUnavailableError(error);
438
+ }
439
+ // The file changed while we were refreshing. If `totem auth` replaced the
440
+ // login, handed it to a deployment, or the file was removed, that wins: the
441
+ // session we just refreshed is abandoned, never written back over it.
442
+ if (this.store.version() !== versionBefore) {
443
+ this.sync(true);
444
+ if (!this.record) {
445
+ this.log("the login was handed off or removed while refreshing; not saving the refreshed session");
446
+ return;
447
+ }
448
+ if (this.record.refresh_token !== before.refresh_token) {
449
+ this.log("the login was replaced while refreshing; using the new one");
450
+ return;
451
+ }
452
+ }
453
+ const record = {
454
+ ...(this.record ?? before), // the same login, with anything annotate() added meanwhile
455
+ access_token: next.accessToken,
456
+ refresh_token: next.refreshToken || before.refresh_token,
457
+ refreshed_at: new Date(this.now()).toISOString(),
458
+ };
459
+ this.persist(record); // before anyone sees the new access token
460
+ this.record = record;
461
+ this.forceRefresh = false;
462
+ this.lastRefreshAt = this.now();
463
+ const exp = decodeJwtExp(record.access_token) * 1000;
464
+ this.log(`refreshed the WHOOP access token (${reason}); it expires ${exp ? new Date(exp).toISOString() : "at an unknown time"}` +
465
+ `${record.refresh_token !== before.refresh_token ? "; rotated refresh token saved" : ""}`);
466
+ this.schedule();
45
467
  }
46
- async doRefresh() {
47
- const next = await refreshCognitoSession(this.email, this.refreshToken);
48
- this.accessToken = next.accessToken;
49
- // Cognito may rotate the refresh token; if it does, persist the new one.
50
- if (next.refreshToken && next.refreshToken !== this.refreshToken) {
51
- this.refreshToken = next.refreshToken;
52
- // Observable so a memory-store (non-persisting) deploy can tell when a
53
- // restart would strand the old token. See SECURITY.md → token hygiene.
54
- console.error("[totem] Cognito rotated the refresh token — persisting the new one.");
468
+ persist(record) {
469
+ let lastError;
470
+ for (let attempt = 0; attempt < this.saveAttempts; attempt++) {
471
+ try {
472
+ this.store.save(record);
473
+ this.seenVersion = this.store.version();
474
+ return;
475
+ }
476
+ catch (error) {
477
+ lastError = error;
478
+ }
55
479
  }
56
- this.expiresAt = next.expiresAt;
57
- this.store.save({ accessToken: this.accessToken, refreshToken: this.refreshToken });
480
+ const fatal = new WhoopTokenPersistError(this.store.description, lastError);
481
+ this.fatal = fatal;
482
+ this.clearTimer();
483
+ this.log(fatal.message);
484
+ this.onFatal?.(fatal);
485
+ throw fatal;
486
+ }
487
+ // ── keep-alive ───────────────────────────────────────────────────────────
488
+ clearTimer() {
489
+ if (this.timer)
490
+ clearTimeout(this.timer);
491
+ this.timer = null;
492
+ this.nextAt = null;
493
+ }
494
+ schedule(delayOverride) {
495
+ this.clearTimer();
496
+ if (this.stopped || this.fatal || this.handoff || this.expired || !this.record)
497
+ return;
498
+ const delay = Math.max(delayOverride ?? this.followerAwareDue(this.record) - this.now(), 1_000);
499
+ this.nextAt = this.now() + delay;
500
+ this.arm();
58
501
  }
502
+ /** Sleep until `nextAt` by the wall clock, in steps of at most MAX_TICK_MS. */
503
+ arm() {
504
+ if (this.nextAt === null)
505
+ return;
506
+ const wait = Math.min(Math.max(this.nextAt - this.now(), 0), MAX_TICK_MS);
507
+ this.timer = setTimeout(() => void this.keepAlive(), wait);
508
+ this.timer.unref?.();
509
+ }
510
+ async keepAlive() {
511
+ this.timer = null;
512
+ if (this.stopped)
513
+ return;
514
+ if (this.nextAt !== null && this.now() < this.nextAt) {
515
+ this.arm(); // only a tick: not due yet by the wall clock
516
+ return;
517
+ }
518
+ this.nextAt = null;
519
+ try {
520
+ this.sync();
521
+ if (!this.record || this.handoff || this.fatal || this.expired)
522
+ return;
523
+ await this.ensureFresh("keep-alive", (r) => this.now() >= this.dueAt(r));
524
+ this.retryMs = this.retryBaseMs;
525
+ // A follower whose live owner hasn't refreshed yet polls instead of spinning.
526
+ const waiting = this.record && this.followerAwareDue(this.record) <= this.now();
527
+ this.schedule(waiting ? FOLLOWER_POLL_MS : undefined);
528
+ }
529
+ catch (error) {
530
+ if (error instanceof WhoopTokenOwnedError) {
531
+ this.schedule(FOLLOWER_POLL_MS);
532
+ }
533
+ else if (error instanceof WhoopAuthExpiredError || error instanceof WhoopTokenPersistError) {
534
+ // Logged where it happened; nothing to retry until a new login arrives.
535
+ }
536
+ else {
537
+ this.log(`keep-alive refresh failed (${error.message}); retrying in ${Math.round(this.retryMs / 1000)}s`);
538
+ const delay = this.retryMs;
539
+ this.retryMs = Math.min(this.retryMs * 2, 15 * MINUTE);
540
+ this.schedule(delay);
541
+ }
542
+ }
543
+ }
544
+ }
545
+ /** Keep-alive interval from TOTEM_KEEPALIVE_HOURS (default 12; 0 = expiry-driven only). */
546
+ export function keepAliveMsFromEnv(value) {
547
+ if (value === undefined || value.trim() === "")
548
+ return 12 * HOUR;
549
+ const hours = Number(value);
550
+ if (!Number.isFinite(hours) || hours < 0)
551
+ return 12 * HOUR;
552
+ return Math.round(hours * HOUR);
59
553
  }
60
554
  //# sourceMappingURL=token_manager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"token_manager.js","sourceRoot":"","sources":["../../src/whoop/token_manager.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,yEAAyE;AACzE,4EAA4E;AAC5E,kCAAkC;AAClC,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AAiBtE,MAAM,OAAO,YAAY;IACf,KAAK,CAAS;IACd,WAAW,CAAS;IACpB,YAAY,CAAS;IACrB,SAAS,CAAS,CAAC,WAAW;IAC9B,MAAM,CAAS;IACf,KAAK,CAAa;IAClB,UAAU,GAAyB,IAAI,CAAC;IAEhD,YAAY,MAA0B;QACpC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,kBAAkB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QACvD,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;QACzD,IAAI,MAAM,CAAC,KAA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