@trainheroic-unofficial/js 1.1.1 → 1.3.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/dist/index.d.mts +183 -8
- package/dist/index.mjs +376 -31
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -247,20 +247,46 @@ type SetResult = {
|
|
|
247
247
|
}>;
|
|
248
248
|
};
|
|
249
249
|
/**
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
|
|
250
|
+
* Which write a set-write is: `"log"` records a performed result (and marks the set done),
|
|
251
|
+
* `"prescribe"` sets prescribed targets without marking it done. Threaded through
|
|
252
|
+
* {@link buildExerciseSetPayload} and the set-write helper so the two contracts share one path.
|
|
253
|
+
*/
|
|
254
|
+
type SetWriteMode = "log" | "prescribe";
|
|
255
|
+
/**
|
|
256
|
+
* Coerce the loosely-typed `results` from a validated log/prescribe args object into the SDK's
|
|
257
|
+
* {@link SetResult}[]. The dto schemas validate ids as a number or a numeric string and leave
|
|
258
|
+
* empty param slots optional; this narrows the id to a number and copies only the present per-set
|
|
259
|
+
* values (so the per-set type stays free of `undefined` under exactOptionalPropertyTypes). Shared
|
|
260
|
+
* by the MCP tools and the CLI so the mapping lives in one place rather than once per surface.
|
|
261
|
+
*/
|
|
262
|
+
declare function toSetResults(results: ReadonlyArray<{
|
|
263
|
+
savedWorkoutSetExerciseId: number | string;
|
|
264
|
+
sets: ReadonlyArray<{
|
|
265
|
+
param1?: number | string | undefined;
|
|
266
|
+
param2?: number | string | undefined;
|
|
267
|
+
}>;
|
|
268
|
+
}>): SetResult[];
|
|
269
|
+
/**
|
|
270
|
+
* Build the body for `PUT /1.0/{role}/savedworkoutsetexercise/{id}`. The body uses snake_case
|
|
271
|
+
* keys matching the live API response shape. Each set slot (1-10) carries `param_1_data_N` /
|
|
272
|
+
* `param_2_data_N` string values plus a `param_N_made` flag.
|
|
273
|
+
*
|
|
274
|
+
* `mode` selects which write this is — the same endpoint serves both:
|
|
275
|
+
* - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has data
|
|
276
|
+
* and the exercise `completed` flag is 1 when any set has data.
|
|
277
|
+
* - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
|
|
278
|
+
* `completed` left at 0 so the set is not marked done. This matches what the app sends when a
|
|
279
|
+
* coach edits an athlete's prescribed reps/weight.
|
|
254
280
|
*
|
|
255
281
|
* Only `savedWorkoutSetExerciseId`, `savedWorkoutSetId`, and `workoutSetExerciseId` are
|
|
256
282
|
* required from the live exercise record; everything else is derived from `results`.
|
|
257
283
|
*
|
|
258
|
-
* Exported for unit testing — callers should use `logAthleteSet` instead.
|
|
284
|
+
* Exported for unit testing — callers should use `logAthleteSet` / `prescribeForAthlete` instead.
|
|
259
285
|
*/
|
|
260
|
-
declare function
|
|
286
|
+
declare function buildExerciseSetPayload(savedWorkoutSetExerciseId: number, savedWorkoutSetId: number, workoutSetExerciseId: number, results: readonly {
|
|
261
287
|
param1?: number | string;
|
|
262
288
|
param2?: number | string;
|
|
263
|
-
}[]): Record<string, unknown>;
|
|
289
|
+
}[], mode: SetWriteMode): Record<string, unknown>;
|
|
264
290
|
/**
|
|
265
291
|
* Locate the target saved workout set across all program workouts on the given day.
|
|
266
292
|
* Returns the `savedWorkoutId`, the matching set's `workoutSetExercises` array so callers
|
|
@@ -332,6 +358,61 @@ declare function logForAthlete(client: TrainHeroicClient, args: {
|
|
|
332
358
|
savedWorkoutSetId: number;
|
|
333
359
|
exercisesLogged: number;
|
|
334
360
|
}>;
|
|
361
|
+
/**
|
|
362
|
+
* Coach prescription override: set the prescribed reps/weight for one of a roster athlete's saved
|
|
363
|
+
* workout sets WITHOUT marking it performed — the API equivalent of the app's editing an athlete's
|
|
364
|
+
* prescribed values. Writes each exercise's per-set targets via
|
|
365
|
+
* `PUT /1.0/coach/savedworkoutsetexercise/{id}/{athleteId}` with `param_N_made = 0` /
|
|
366
|
+
* `completed = 0`, and (unlike {@link logForAthlete}) skips the set-completion step, so the set
|
|
367
|
+
* stays open for the athlete to log against.
|
|
368
|
+
*
|
|
369
|
+
* Overrides only this athlete's copy of the set; the team/program prescription is untouched, so
|
|
370
|
+
* other athletes on the same program keep the original targets. The write REPLACES the slot's
|
|
371
|
+
* prescribed values, so pass the full per-set prescription you want — `param1` is reps, `param2`
|
|
372
|
+
* is weight, and an omitted param is written empty (clearing it), not left as-is.
|
|
373
|
+
*
|
|
374
|
+
* NOTE: TrainHeroic's seeded *demo* athletes are read-only and return 401/403; real (invited)
|
|
375
|
+
* athletes accept it.
|
|
376
|
+
*/
|
|
377
|
+
declare function prescribeForAthlete(client: TrainHeroicClient, args: {
|
|
378
|
+
athleteId: number;
|
|
379
|
+
date: string;
|
|
380
|
+
savedWorkoutSetId: number;
|
|
381
|
+
results: readonly SetResult[];
|
|
382
|
+
}): Promise<{
|
|
383
|
+
savedWorkoutSetId: number;
|
|
384
|
+
exercisesPrescribed: number;
|
|
385
|
+
}>;
|
|
386
|
+
/** Outcome of a per-athlete exercise swap: the slot that changed and what it changed to/from. */
|
|
387
|
+
type SwapExerciseResult = {
|
|
388
|
+
savedWorkoutSetExerciseId: number; /** The athlete who owns the slot (`user_id` off the updated row), when the API returns it. */
|
|
389
|
+
athleteId: number | null; /** The exercise now scheduled in the slot. */
|
|
390
|
+
newExerciseId: number;
|
|
391
|
+
newExerciseTitle: string | null; /** The team/program's original prescription, left untouched (`workout_set_exercise.exercise_id`). */
|
|
392
|
+
originalTeamExerciseId: number | null;
|
|
393
|
+
};
|
|
394
|
+
/**
|
|
395
|
+
* Swap the exercise prescribed in one of an athlete's saved-workout slots for a different
|
|
396
|
+
* exercise — the API equivalent of the app's per-athlete "swap exercise":
|
|
397
|
+
* `PUT /v5/savedWorkoutSetExercises/{savedWorkoutSetExerciseId}?exerciseId={exerciseId}` with an
|
|
398
|
+
* empty body. The new exercise rides in the query string, not the body.
|
|
399
|
+
*
|
|
400
|
+
* This overrides only this athlete's copy of the slot; the underlying team/program prescription
|
|
401
|
+
* (`workout_set_exercise.exercise_id`) is untouched, so other athletes on the same program keep
|
|
402
|
+
* the original exercise. A coach's session token may write another user's row because the row
|
|
403
|
+
* already carries its owner's `user_id`.
|
|
404
|
+
*
|
|
405
|
+
* `savedWorkoutSetExerciseId` is the same id {@link logForAthlete}/{@link logAthleteSet} use,
|
|
406
|
+
* read off the athlete's saved workouts (the raw view). `exerciseId` is any exercise id the org
|
|
407
|
+
* can use (resolve one via the exercise index).
|
|
408
|
+
*
|
|
409
|
+
* NOTE: as with logging, TrainHeroic's seeded *demo* athletes are read-only and return 401/403;
|
|
410
|
+
* real (invited) athletes accept the swap.
|
|
411
|
+
*/
|
|
412
|
+
declare function swapAthleteExercise(client: TrainHeroicClient, args: {
|
|
413
|
+
savedWorkoutSetExerciseId: number;
|
|
414
|
+
exerciseId: number;
|
|
415
|
+
}): Promise<SwapExerciseResult>;
|
|
335
416
|
type PersonalWorkoutCreated = {
|
|
336
417
|
programWorkoutId: number;
|
|
337
418
|
workoutId: number;
|
|
@@ -402,8 +483,102 @@ declare function logSessionForAthlete(client: TrainHeroicClient, args: {
|
|
|
402
483
|
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
403
484
|
declare function presentExerciseHistory(detail: ExerciseHistoryDetail): PresentedExerciseHistory;
|
|
404
485
|
//#endregion
|
|
486
|
+
//#region src/main-lifts.d.ts
|
|
487
|
+
type MainLiftFamilyKey = "cleanjerk" | "snatch" | "deadlift" | "squat" | "bench" | "overhead";
|
|
488
|
+
type MainLiftFamily = {
|
|
489
|
+
key: MainLiftFamilyKey;
|
|
490
|
+
label: string; /** True when a lowercased exercise title belongs to this family. */
|
|
491
|
+
matches: (titleLower: string) => boolean;
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* The "main lifts" — Big 4 plus the two Olympic lifts. ORDER MATTERS: a title is classified by the
|
|
495
|
+
* first family that matches, so the more specific / easily-confused families come before the broad
|
|
496
|
+
* overhead-press rule. That ordering is why "Bench Press" classifies as `bench` and never gets
|
|
497
|
+
* swept up as an overhead press, and why "Clean & Jerk" is not mistaken for a clean-only movement.
|
|
498
|
+
* This is the single place to edit the lift set.
|
|
499
|
+
*/
|
|
500
|
+
declare const MAIN_LIFT_FAMILIES: readonly MainLiftFamily[];
|
|
501
|
+
/** The lift family a logged exercise title belongs to, or null if it is not a main lift. */
|
|
502
|
+
declare function classifyMainLift(title: string): MainLiftFamilyKey | null;
|
|
503
|
+
/** The main-lift variant an athlete actually logs (the most-used exercise in that family). */
|
|
504
|
+
type ResolvedLift = {
|
|
505
|
+
family: MainLiftFamilyKey;
|
|
506
|
+
label: string;
|
|
507
|
+
exerciseId: number;
|
|
508
|
+
title: string;
|
|
509
|
+
};
|
|
510
|
+
type MainLiftResolution = {
|
|
511
|
+
athleteId: number;
|
|
512
|
+
athleteName: string | null;
|
|
513
|
+
lifts: ResolvedLift[];
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* Discover a roster athlete's main lifts from what they actually logged. Reads the athlete's
|
|
517
|
+
* logged workouts over the last `months` (default 12) — the program-workout range, the reliable
|
|
518
|
+
* record of performed sets — buckets every performed exercise into a lift family, and for each
|
|
519
|
+
* family picks the variant logged most often. Returns one entry per family the athlete has logged;
|
|
520
|
+
* families they never trained are simply absent. (The monthly calendar summary is not used: it
|
|
521
|
+
* comes back empty for some accounts that have logged sets in the range endpoint.)
|
|
522
|
+
*/
|
|
523
|
+
declare function resolveAthleteMainLifts(client: TrainHeroicClient, athleteId: number, opts?: {
|
|
524
|
+
months?: number;
|
|
525
|
+
now?: Date;
|
|
526
|
+
}): Promise<MainLiftResolution>;
|
|
527
|
+
/** One main lift's best PR for an athlete. A family the athlete has not logged has a null body. */
|
|
528
|
+
type MainLiftPR = {
|
|
529
|
+
family: MainLiftFamilyKey;
|
|
530
|
+
label: string;
|
|
531
|
+
exerciseId: number | null;
|
|
532
|
+
title: string | null;
|
|
533
|
+
weight: number | null;
|
|
534
|
+
reps: number | null;
|
|
535
|
+
units: string | null;
|
|
536
|
+
date: string | null;
|
|
537
|
+
};
|
|
538
|
+
type AthleteMainLiftPRs = {
|
|
539
|
+
athleteId: number;
|
|
540
|
+
athleteName: string | null;
|
|
541
|
+
prs: MainLiftPR[];
|
|
542
|
+
};
|
|
543
|
+
/**
|
|
544
|
+
* A roster athlete's best PR for each main lift. Discovers the lift variants they log
|
|
545
|
+
* ({@link resolveAthleteMainLifts}), then pulls each variant's PR board and keeps the heaviest set.
|
|
546
|
+
* The result always carries one entry per family in {@link MAIN_LIFT_FAMILIES} order; a family the
|
|
547
|
+
* athlete has not logged comes back with null fields (the "no PR yet" case), so a dashboard can
|
|
548
|
+
* render a stable row of columns.
|
|
549
|
+
*/
|
|
550
|
+
declare function fetchAthleteMainLiftPRs(client: TrainHeroicClient, athleteId: number, opts?: {
|
|
551
|
+
months?: number;
|
|
552
|
+
now?: Date;
|
|
553
|
+
}): Promise<AthleteMainLiftPRs>;
|
|
554
|
+
/**
|
|
555
|
+
* Every roster athlete's main-lift PRs in one call: list the roster ({@link fetchCoachRoster}) and
|
|
556
|
+
* resolve each athlete's board ({@link fetchAthleteMainLiftPRs}), fanned out with a bounded pool.
|
|
557
|
+
* `athleteIds` restricts to a subset (else the whole roster). Each entry's `athleteName` falls back
|
|
558
|
+
* to the roster name when the per-athlete read can't supply one. This is the single roster-level
|
|
559
|
+
* primitive the CLI, the MCP tool, and the warehouse store all build on.
|
|
560
|
+
*/
|
|
561
|
+
declare function fetchRosterMainLiftPRs(client: TrainHeroicClient, opts?: {
|
|
562
|
+
athleteIds?: readonly number[];
|
|
563
|
+
months?: number;
|
|
564
|
+
now?: Date;
|
|
565
|
+
concurrency?: number;
|
|
566
|
+
}): Promise<AthleteMainLiftPRs[]>;
|
|
567
|
+
//#endregion
|
|
405
568
|
//#region src/coach.d.ts
|
|
406
569
|
declare const DEFAULT_INVITE_MESSAGE = "Follow these steps and you'll be set up and ready to go!";
|
|
570
|
+
/** A roster member as id + display name. */
|
|
571
|
+
type CoachRosterAthlete = {
|
|
572
|
+
id: number;
|
|
573
|
+
name: string | null;
|
|
574
|
+
};
|
|
575
|
+
/**
|
|
576
|
+
* The coach's roster as id + display name, from /v5/athletes. One home for the id coercion and the
|
|
577
|
+
* name-field choice (the API uses `fullName` / `firstName`+`lastName`), so the CLI, the MCP tools,
|
|
578
|
+
* and the warehouse store map the roster identically. Includes the account owner and
|
|
579
|
+
* demo/placeholder athletes (the raw roster does); pass `ids` to keep only a subset.
|
|
580
|
+
*/
|
|
581
|
+
declare function fetchCoachRoster(client: TrainHeroicClient, ids?: readonly number[]): Promise<CoachRosterAthlete[]>;
|
|
407
582
|
/**
|
|
408
583
|
* Invite athletes to a team — TrainHeroic's two-step "create athlete" flow: validate the
|
|
409
584
|
* addresses (`POST /v5/emails/validate`), then invite the validated ones
|
|
@@ -582,4 +757,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
582
757
|
stats(): Promise<Record<string, unknown>>;
|
|
583
758
|
}
|
|
584
759
|
//#endregion
|
|
585
|
-
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, BuildOptions, ClientResult, DEFAULT_INVITE_MESSAGE, ExerciseIndex, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PersonalWorkoutCreated, RequestOptions, SessionExercise, SetResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload,
|
|
760
|
+
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BuildOptions, ClientResult, CoachRosterAthlete, DEFAULT_INVITE_MESSAGE, ExerciseIndex, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, MAIN_LIFT_FAMILIES, MainLiftFamily, MainLiftFamilyKey, MainLiftPR, MainLiftResolution, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PersonalWorkoutCreated, RequestOptions, ResolvedLift, SessionExercise, SetResult, SetWriteMode, SwapExerciseResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkouts, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, sortRosterByRecency, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
package/dist/index.mjs
CHANGED
|
@@ -722,29 +722,59 @@ function presentCoachAthleteTraining(raw, athleteId, year, month) {
|
|
|
722
722
|
}
|
|
723
723
|
const MAX_PARAM_SLOTS = 10;
|
|
724
724
|
/**
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
*
|
|
728
|
-
* `
|
|
725
|
+
* Coerce the loosely-typed `results` from a validated log/prescribe args object into the SDK's
|
|
726
|
+
* {@link SetResult}[]. The dto schemas validate ids as a number or a numeric string and leave
|
|
727
|
+
* empty param slots optional; this narrows the id to a number and copies only the present per-set
|
|
728
|
+
* values (so the per-set type stays free of `undefined` under exactOptionalPropertyTypes). Shared
|
|
729
|
+
* by the MCP tools and the CLI so the mapping lives in one place rather than once per surface.
|
|
730
|
+
*/
|
|
731
|
+
function toSetResults(results) {
|
|
732
|
+
return results.map((r) => {
|
|
733
|
+
const id = coerceInt(r.savedWorkoutSetExerciseId);
|
|
734
|
+
if (id === null) throw new Error(`Invalid savedWorkoutSetExerciseId: ${String(r.savedWorkoutSetExerciseId)}`);
|
|
735
|
+
return {
|
|
736
|
+
savedWorkoutSetExerciseId: id,
|
|
737
|
+
sets: r.sets.map((s) => {
|
|
738
|
+
const slot = {};
|
|
739
|
+
if (s.param1 !== void 0) slot.param1 = s.param1;
|
|
740
|
+
if (s.param2 !== void 0) slot.param2 = s.param2;
|
|
741
|
+
return slot;
|
|
742
|
+
})
|
|
743
|
+
};
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Build the body for `PUT /1.0/{role}/savedworkoutsetexercise/{id}`. The body uses snake_case
|
|
748
|
+
* keys matching the live API response shape. Each set slot (1-10) carries `param_1_data_N` /
|
|
749
|
+
* `param_2_data_N` string values plus a `param_N_made` flag.
|
|
750
|
+
*
|
|
751
|
+
* `mode` selects which write this is — the same endpoint serves both:
|
|
752
|
+
* - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has data
|
|
753
|
+
* and the exercise `completed` flag is 1 when any set has data.
|
|
754
|
+
* - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
|
|
755
|
+
* `completed` left at 0 so the set is not marked done. This matches what the app sends when a
|
|
756
|
+
* coach edits an athlete's prescribed reps/weight.
|
|
729
757
|
*
|
|
730
758
|
* Only `savedWorkoutSetExerciseId`, `savedWorkoutSetId`, and `workoutSetExerciseId` are
|
|
731
759
|
* required from the live exercise record; everything else is derived from `results`.
|
|
732
760
|
*
|
|
733
|
-
* Exported for unit testing — callers should use `logAthleteSet` instead.
|
|
761
|
+
* Exported for unit testing — callers should use `logAthleteSet` / `prescribeForAthlete` instead.
|
|
734
762
|
*/
|
|
735
|
-
function
|
|
763
|
+
function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, results, mode) {
|
|
736
764
|
if (results.length > MAX_PARAM_SLOTS) throw new Error(`At most ${MAX_PARAM_SLOTS} sets are supported per exercise; got ${results.length}.`);
|
|
765
|
+
const performed = mode === "log";
|
|
766
|
+
const hasData = results.some((s) => s.param1 !== void 0 || s.param2 !== void 0);
|
|
737
767
|
const body = {
|
|
738
768
|
id: savedWorkoutSetExerciseId,
|
|
739
769
|
saved_workout_set_id: savedWorkoutSetId,
|
|
740
770
|
workout_set_exercise_id: workoutSetExerciseId,
|
|
741
|
-
completed:
|
|
771
|
+
completed: performed && hasData ? 1 : 0
|
|
742
772
|
};
|
|
743
773
|
for (let i = 1; i <= MAX_PARAM_SLOTS; i += 1) {
|
|
744
774
|
const slot = results[i - 1];
|
|
745
775
|
const p1 = slot?.param1 !== void 0 ? String(slot.param1) : "";
|
|
746
776
|
const p2 = slot?.param2 !== void 0 ? String(slot.param2) : "";
|
|
747
|
-
body[`param_${i}_made`] = p1 !== "" || p2 !== "" ? 1 : 0;
|
|
777
|
+
body[`param_${i}_made`] = performed && (p1 !== "" || p2 !== "") ? 1 : 0;
|
|
748
778
|
body[`param_1_data_${i}`] = p1;
|
|
749
779
|
body[`param_2_data_${i}`] = p2;
|
|
750
780
|
}
|
|
@@ -845,7 +875,11 @@ function buildSetCompletePayload(rawSet, exerciseIds, complete) {
|
|
|
845
875
|
* by the respective PUT bodies.
|
|
846
876
|
*/
|
|
847
877
|
async function logAthleteSet(client, args) {
|
|
848
|
-
|
|
878
|
+
const r = await writeSetResults(client, { role: "athlete" }, await fetchAthleteWorkouts(client, args.date, args.date), args.savedWorkoutSetId, args.results, "log");
|
|
879
|
+
return {
|
|
880
|
+
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
881
|
+
exercisesLogged: r.exercisesWritten
|
|
882
|
+
};
|
|
849
883
|
}
|
|
850
884
|
/**
|
|
851
885
|
* Coach "Log for Athlete": record set results for a roster athlete on their behalf, via the
|
|
@@ -859,24 +893,94 @@ async function logAthleteSet(client, args) {
|
|
|
859
893
|
*/
|
|
860
894
|
async function logForAthlete(client, args) {
|
|
861
895
|
const workouts = await fetchCoachAthleteWorkouts(client, args.athleteId, args.date, args.date);
|
|
862
|
-
|
|
896
|
+
const r = await writeSetResults(client, {
|
|
897
|
+
role: "coach",
|
|
898
|
+
athleteId: args.athleteId
|
|
899
|
+
}, workouts, args.savedWorkoutSetId, args.results, "log");
|
|
900
|
+
return {
|
|
901
|
+
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
902
|
+
exercisesLogged: r.exercisesWritten
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Coach prescription override: set the prescribed reps/weight for one of a roster athlete's saved
|
|
907
|
+
* workout sets WITHOUT marking it performed — the API equivalent of the app's editing an athlete's
|
|
908
|
+
* prescribed values. Writes each exercise's per-set targets via
|
|
909
|
+
* `PUT /1.0/coach/savedworkoutsetexercise/{id}/{athleteId}` with `param_N_made = 0` /
|
|
910
|
+
* `completed = 0`, and (unlike {@link logForAthlete}) skips the set-completion step, so the set
|
|
911
|
+
* stays open for the athlete to log against.
|
|
912
|
+
*
|
|
913
|
+
* Overrides only this athlete's copy of the set; the team/program prescription is untouched, so
|
|
914
|
+
* other athletes on the same program keep the original targets. The write REPLACES the slot's
|
|
915
|
+
* prescribed values, so pass the full per-set prescription you want — `param1` is reps, `param2`
|
|
916
|
+
* is weight, and an omitted param is written empty (clearing it), not left as-is.
|
|
917
|
+
*
|
|
918
|
+
* NOTE: TrainHeroic's seeded *demo* athletes are read-only and return 401/403; real (invited)
|
|
919
|
+
* athletes accept it.
|
|
920
|
+
*/
|
|
921
|
+
async function prescribeForAthlete(client, args) {
|
|
922
|
+
const workouts = await fetchCoachAthleteWorkouts(client, args.athleteId, args.date, args.date);
|
|
923
|
+
const r = await writeSetResults(client, {
|
|
863
924
|
role: "coach",
|
|
864
925
|
athleteId: args.athleteId
|
|
865
|
-
}, workouts, args.savedWorkoutSetId, args.results);
|
|
926
|
+
}, workouts, args.savedWorkoutSetId, args.results, "prescribe");
|
|
927
|
+
return {
|
|
928
|
+
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
929
|
+
exercisesPrescribed: r.exercisesWritten
|
|
930
|
+
};
|
|
866
931
|
}
|
|
867
932
|
/**
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
*
|
|
873
|
-
*
|
|
933
|
+
* Swap the exercise prescribed in one of an athlete's saved-workout slots for a different
|
|
934
|
+
* exercise — the API equivalent of the app's per-athlete "swap exercise":
|
|
935
|
+
* `PUT /v5/savedWorkoutSetExercises/{savedWorkoutSetExerciseId}?exerciseId={exerciseId}` with an
|
|
936
|
+
* empty body. The new exercise rides in the query string, not the body.
|
|
937
|
+
*
|
|
938
|
+
* This overrides only this athlete's copy of the slot; the underlying team/program prescription
|
|
939
|
+
* (`workout_set_exercise.exercise_id`) is untouched, so other athletes on the same program keep
|
|
940
|
+
* the original exercise. A coach's session token may write another user's row because the row
|
|
941
|
+
* already carries its owner's `user_id`.
|
|
942
|
+
*
|
|
943
|
+
* `savedWorkoutSetExerciseId` is the same id {@link logForAthlete}/{@link logAthleteSet} use,
|
|
944
|
+
* read off the athlete's saved workouts (the raw view). `exerciseId` is any exercise id the org
|
|
945
|
+
* can use (resolve one via the exercise index).
|
|
946
|
+
*
|
|
947
|
+
* NOTE: as with logging, TrainHeroic's seeded *demo* athletes are read-only and return 401/403;
|
|
948
|
+
* real (invited) athletes accept the swap.
|
|
874
949
|
*/
|
|
875
|
-
async function
|
|
950
|
+
async function swapAthleteExercise(client, args) {
|
|
951
|
+
const res = await client.request("PUT", `/v5/savedWorkoutSetExercises/${args.savedWorkoutSetExerciseId}?exerciseId=${args.exerciseId}`);
|
|
952
|
+
if (!res.ok) {
|
|
953
|
+
const readOnly = res.status === 401 || res.status === 403 ? ` Athlete may be read-only for changes — TrainHeroic's seeded demo/sample athletes return ${res.status} here; swaps only persist for real (invited) athletes.` : "";
|
|
954
|
+
throw new Error(`Swap failed (HTTP ${res.status}) for savedWorkoutSetExercise ${args.savedWorkoutSetExerciseId}.${readOnly}`);
|
|
955
|
+
}
|
|
956
|
+
const row = isRecord(res.data) ? res.data : {};
|
|
957
|
+
const template = isRecord(row.workout_set_exercise) ? row.workout_set_exercise : {};
|
|
958
|
+
const exercise = isRecord(row.exercise) ? row.exercise : {};
|
|
959
|
+
return {
|
|
960
|
+
savedWorkoutSetExerciseId: args.savedWorkoutSetExerciseId,
|
|
961
|
+
athleteId: coerceInt(row.user_id),
|
|
962
|
+
newExerciseId: coerceInt(row.exercise_id) ?? args.exerciseId,
|
|
963
|
+
newExerciseTitle: str$1(exercise.title),
|
|
964
|
+
originalTeamExerciseId: coerceInt(template.exercise_id)
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Shared set-write behind {@link logAthleteSet}, {@link logForAthlete}, and
|
|
969
|
+
* {@link prescribeForAthlete}. `target` selects the surface: `athlete` writes `/1.0/athlete/...`;
|
|
970
|
+
* `coach` writes `/1.0/coach/...{athleteId}` and stamps `athleteId` into each body.
|
|
971
|
+
*
|
|
972
|
+
* Step 1 PUTs each exercise's per-set values to its own endpoint (the only path that actually
|
|
973
|
+
* stores reps and weight). `mode` decides what those values mean: `"log"` records them as a
|
|
974
|
+
* performed result and runs Step 2, which marks the set completed (that body needs the app's
|
|
975
|
+
* camelCase in-memory shape and the full list of savedWorkoutSetExercise IDs in the set, not only
|
|
976
|
+
* the written ones); `"prescribe"` writes them as a prescription and skips Step 2, leaving the set
|
|
977
|
+
* open.
|
|
978
|
+
*/
|
|
979
|
+
async function writeSetResults(client, target, workouts, savedWorkoutSetId, results, mode) {
|
|
876
980
|
const { exercises, rawSet } = findSavedWorkoutSet(workouts, savedWorkoutSetId);
|
|
877
981
|
const suffix = target.role === "coach" ? `/${target.athleteId}` : "";
|
|
878
982
|
const extra = target.role === "coach" ? { athleteId: target.athleteId } : {};
|
|
879
|
-
let
|
|
983
|
+
let exercisesWritten = 0;
|
|
880
984
|
for (const result of results) {
|
|
881
985
|
const ex = exercises.find((e) => coerceInt(e.id) === result.savedWorkoutSetExerciseId);
|
|
882
986
|
if (!ex) {
|
|
@@ -890,25 +994,27 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
|
|
|
890
994
|
const workoutSetExerciseId = coerceInt(ex.workout_set_exercise_id);
|
|
891
995
|
if (!workoutSetExerciseId) throw new Error(`Could not resolve workout_set_exercise_id for exercise ${result.savedWorkoutSetExerciseId}.`);
|
|
892
996
|
const body = {
|
|
893
|
-
...
|
|
997
|
+
...buildExerciseSetPayload(result.savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, result.sets, mode),
|
|
894
998
|
...extra
|
|
895
999
|
};
|
|
896
1000
|
const res = await client.request("PUT", `/1.0/${target.role}/savedworkoutsetexercise/${result.savedWorkoutSetExerciseId}${suffix}`, { body });
|
|
897
1001
|
if (!res.ok) {
|
|
898
|
-
const readOnly = target.role === "coach" && (res.status === 401 || res.status === 403) ? ` Athlete ${target.athleteId} appears to be read-only for
|
|
899
|
-
throw new Error(`Failed to
|
|
1002
|
+
const readOnly = target.role === "coach" && (res.status === 401 || res.status === 403) ? ` Athlete ${target.athleteId} appears to be read-only for changes — TrainHeroic's seeded demo/sample athletes return ${res.status} here; writes only persist for real (invited) athletes.` : "";
|
|
1003
|
+
throw new Error(`Failed to write exercise ${result.savedWorkoutSetExerciseId} (HTTP ${res.status}).${readOnly}`);
|
|
900
1004
|
}
|
|
901
|
-
|
|
1005
|
+
exercisesWritten += 1;
|
|
1006
|
+
}
|
|
1007
|
+
if (mode === "log") {
|
|
1008
|
+
const setBody = {
|
|
1009
|
+
...buildSetCompletePayload(rawSet, exercises.map((e) => coerceInt(e.id)).filter((n) => n !== null), true),
|
|
1010
|
+
...extra
|
|
1011
|
+
};
|
|
1012
|
+
const setRes = await client.request("PUT", `/1.0/${target.role}/savedworkoutset/${savedWorkoutSetId}${suffix}`, { body: setBody });
|
|
1013
|
+
if (!setRes.ok) throw new Error(`Failed to mark workout set ${savedWorkoutSetId} completed (HTTP ${setRes.status}).`);
|
|
902
1014
|
}
|
|
903
|
-
const setBody = {
|
|
904
|
-
...buildSetCompletePayload(rawSet, exercises.map((e) => coerceInt(e.id)).filter((n) => n !== null), true),
|
|
905
|
-
...extra
|
|
906
|
-
};
|
|
907
|
-
const setRes = await client.request("PUT", `/1.0/${target.role}/savedworkoutset/${savedWorkoutSetId}${suffix}`, { body: setBody });
|
|
908
|
-
if (!setRes.ok) throw new Error(`Failed to mark workout set ${savedWorkoutSetId} completed (HTTP ${setRes.status}).`);
|
|
909
1015
|
return {
|
|
910
1016
|
savedWorkoutSetId,
|
|
911
|
-
|
|
1017
|
+
exercisesWritten
|
|
912
1018
|
};
|
|
913
1019
|
}
|
|
914
1020
|
/**
|
|
@@ -1150,6 +1256,7 @@ function presentExerciseHistory(detail) {
|
|
|
1150
1256
|
description: p.description ?? null,
|
|
1151
1257
|
reps: p.reps ?? null,
|
|
1152
1258
|
weight: p.weight ?? null,
|
|
1259
|
+
units: p.units ?? null,
|
|
1153
1260
|
date: p.dateCompleted ?? null
|
|
1154
1261
|
})),
|
|
1155
1262
|
sessions: (detail.history ?? []).map((h) => ({
|
|
@@ -1170,6 +1277,37 @@ const DEFAULT_INVITE_MESSAGE = "Follow these steps and you'll be set up and read
|
|
|
1170
1277
|
function emailList(emails) {
|
|
1171
1278
|
return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
|
|
1172
1279
|
}
|
|
1280
|
+
/** The display name on a /v5/athletes row: `fullName` (e.g. "Cohen, A"), else first+last. */
|
|
1281
|
+
function rosterName(rec) {
|
|
1282
|
+
const full = typeof rec.fullName === "string" ? rec.fullName.trim() : "";
|
|
1283
|
+
if (full !== "") return full;
|
|
1284
|
+
const combined = `${typeof rec.firstName === "string" ? rec.firstName : ""} ${typeof rec.lastName === "string" ? rec.lastName : ""}`.trim();
|
|
1285
|
+
return combined !== "" ? combined : null;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* The coach's roster as id + display name, from /v5/athletes. One home for the id coercion and the
|
|
1289
|
+
* name-field choice (the API uses `fullName` / `firstName`+`lastName`), so the CLI, the MCP tools,
|
|
1290
|
+
* and the warehouse store map the roster identically. Includes the account owner and
|
|
1291
|
+
* demo/placeholder athletes (the raw roster does); pass `ids` to keep only a subset.
|
|
1292
|
+
*/
|
|
1293
|
+
async function fetchCoachRoster(client, ids) {
|
|
1294
|
+
const res = await client.request("GET", "/v5/athletes");
|
|
1295
|
+
if (!res.ok || !Array.isArray(res.data)) throw new Error(`List athletes failed (HTTP ${res.status}).`);
|
|
1296
|
+
const keep = ids && ids.length > 0 ? new Set(ids) : null;
|
|
1297
|
+
const out = [];
|
|
1298
|
+
for (const row of res.data) {
|
|
1299
|
+
if (typeof row !== "object" || row === null) continue;
|
|
1300
|
+
const rec = row;
|
|
1301
|
+
const id = coerceInt(rec.id);
|
|
1302
|
+
if (id === null || id <= 0) continue;
|
|
1303
|
+
if (keep && !keep.has(id)) continue;
|
|
1304
|
+
out.push({
|
|
1305
|
+
id,
|
|
1306
|
+
name: rosterName(rec)
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
return out;
|
|
1310
|
+
}
|
|
1173
1311
|
/**
|
|
1174
1312
|
* Invite athletes to a team — TrainHeroic's two-step "create athlete" flow: validate the
|
|
1175
1313
|
* addresses (`POST /v5/emails/validate`), then invite the validated ones
|
|
@@ -1449,6 +1587,213 @@ async function teamVolume(client, args) {
|
|
|
1449
1587
|
};
|
|
1450
1588
|
}
|
|
1451
1589
|
//#endregion
|
|
1590
|
+
//#region src/main-lifts.ts
|
|
1591
|
+
/**
|
|
1592
|
+
* The "main lifts" — Big 4 plus the two Olympic lifts. ORDER MATTERS: a title is classified by the
|
|
1593
|
+
* first family that matches, so the more specific / easily-confused families come before the broad
|
|
1594
|
+
* overhead-press rule. That ordering is why "Bench Press" classifies as `bench` and never gets
|
|
1595
|
+
* swept up as an overhead press, and why "Clean & Jerk" is not mistaken for a clean-only movement.
|
|
1596
|
+
* This is the single place to edit the lift set.
|
|
1597
|
+
*/
|
|
1598
|
+
const MAIN_LIFT_FAMILIES = [
|
|
1599
|
+
{
|
|
1600
|
+
key: "cleanjerk",
|
|
1601
|
+
label: "Clean & Jerk",
|
|
1602
|
+
matches: (t) => t.includes("jerk") || t.includes("clean") && !t.includes("clean pull")
|
|
1603
|
+
},
|
|
1604
|
+
{
|
|
1605
|
+
key: "snatch",
|
|
1606
|
+
label: "Snatch",
|
|
1607
|
+
matches: (t) => t.includes("snatch")
|
|
1608
|
+
},
|
|
1609
|
+
{
|
|
1610
|
+
key: "deadlift",
|
|
1611
|
+
label: "Deadlift",
|
|
1612
|
+
matches: (t) => t.includes("deadlift")
|
|
1613
|
+
},
|
|
1614
|
+
{
|
|
1615
|
+
key: "squat",
|
|
1616
|
+
label: "Squat",
|
|
1617
|
+
matches: (t) => t.includes("squat")
|
|
1618
|
+
},
|
|
1619
|
+
{
|
|
1620
|
+
key: "bench",
|
|
1621
|
+
label: "Bench Press",
|
|
1622
|
+
matches: (t) => t.includes("bench")
|
|
1623
|
+
},
|
|
1624
|
+
{
|
|
1625
|
+
key: "overhead",
|
|
1626
|
+
label: "Overhead Press",
|
|
1627
|
+
matches: (t) => t.includes("ohp") || (t.includes("overhead") || t.includes("shoulder") || t.includes("military") || t.includes("strict") || t.includes("push")) && t.includes("press")
|
|
1628
|
+
}
|
|
1629
|
+
];
|
|
1630
|
+
/** The lift family a logged exercise title belongs to, or null if it is not a main lift. */
|
|
1631
|
+
function classifyMainLift(title) {
|
|
1632
|
+
const t = title.toLowerCase();
|
|
1633
|
+
for (const family of MAIN_LIFT_FAMILIES) if (family.matches(t)) return family.key;
|
|
1634
|
+
return null;
|
|
1635
|
+
}
|
|
1636
|
+
const DEFAULT_MONTHS = 12;
|
|
1637
|
+
function pad2(n) {
|
|
1638
|
+
return String(n).padStart(2, "0");
|
|
1639
|
+
}
|
|
1640
|
+
/** A local Date as a YYYY-MM-DD day string (the range endpoint's date format). */
|
|
1641
|
+
function isoDay(d) {
|
|
1642
|
+
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Discover a roster athlete's main lifts from what they actually logged. Reads the athlete's
|
|
1646
|
+
* logged workouts over the last `months` (default 12) — the program-workout range, the reliable
|
|
1647
|
+
* record of performed sets — buckets every performed exercise into a lift family, and for each
|
|
1648
|
+
* family picks the variant logged most often. Returns one entry per family the athlete has logged;
|
|
1649
|
+
* families they never trained are simply absent. (The monthly calendar summary is not used: it
|
|
1650
|
+
* comes back empty for some accounts that have logged sets in the range endpoint.)
|
|
1651
|
+
*/
|
|
1652
|
+
async function resolveAthleteMainLifts(client, athleteId, opts = {}) {
|
|
1653
|
+
const months = opts.months ?? DEFAULT_MONTHS;
|
|
1654
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
1655
|
+
const start = new Date(now.getFullYear(), now.getMonth() - (months - 1), 1);
|
|
1656
|
+
const tally = /* @__PURE__ */ new Map();
|
|
1657
|
+
let workouts = [];
|
|
1658
|
+
try {
|
|
1659
|
+
workouts = await fetchCoachAthleteWorkouts(client, athleteId, isoDay(start), isoDay(now));
|
|
1660
|
+
} catch {
|
|
1661
|
+
workouts = [];
|
|
1662
|
+
}
|
|
1663
|
+
for (const view of presentAthleteWorkouts(workouts)) for (const block of view.blocks) for (const ex of block.exercises) {
|
|
1664
|
+
if (ex.performed.length === 0 || ex.exerciseId === null) continue;
|
|
1665
|
+
const family = classifyMainLift(ex.title);
|
|
1666
|
+
if (family === null) continue;
|
|
1667
|
+
const byId = tally.get(family) ?? /* @__PURE__ */ new Map();
|
|
1668
|
+
const prev = byId.get(ex.exerciseId);
|
|
1669
|
+
byId.set(ex.exerciseId, {
|
|
1670
|
+
count: (prev?.count ?? 0) + 1,
|
|
1671
|
+
title: prev?.title ?? ex.title
|
|
1672
|
+
});
|
|
1673
|
+
tally.set(family, byId);
|
|
1674
|
+
}
|
|
1675
|
+
const lifts = [];
|
|
1676
|
+
for (const family of MAIN_LIFT_FAMILIES) {
|
|
1677
|
+
const byId = tally.get(family.key);
|
|
1678
|
+
if (!byId || byId.size === 0) continue;
|
|
1679
|
+
let best = null;
|
|
1680
|
+
for (const [exerciseId, { count, title }] of byId) if (best === null || count > best.count || count === best.count && exerciseId < best.exerciseId) best = {
|
|
1681
|
+
exerciseId,
|
|
1682
|
+
count,
|
|
1683
|
+
title
|
|
1684
|
+
};
|
|
1685
|
+
if (best) lifts.push({
|
|
1686
|
+
family: family.key,
|
|
1687
|
+
label: family.label,
|
|
1688
|
+
exerciseId: best.exerciseId,
|
|
1689
|
+
title: best.title
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
return {
|
|
1693
|
+
athleteId,
|
|
1694
|
+
athleteName: null,
|
|
1695
|
+
lifts
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
const PR_CONCURRENCY = 5;
|
|
1699
|
+
/** The heaviest PR on an exercise's board (ties broken by more reps). */
|
|
1700
|
+
function bestPr(liftPRs) {
|
|
1701
|
+
let best = null;
|
|
1702
|
+
for (const pr of liftPRs) {
|
|
1703
|
+
const weight = coerceNum(pr.weight);
|
|
1704
|
+
if (weight === null) continue;
|
|
1705
|
+
const reps = coerceInt(pr.reps);
|
|
1706
|
+
if (best === null || weight > best.weight || weight === best.weight && (reps ?? 0) > (best.reps ?? 0)) best = {
|
|
1707
|
+
weight,
|
|
1708
|
+
reps,
|
|
1709
|
+
units: pr.units,
|
|
1710
|
+
date: pr.date
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
return best;
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* A roster athlete's best PR for each main lift. Discovers the lift variants they log
|
|
1717
|
+
* ({@link resolveAthleteMainLifts}), then pulls each variant's PR board and keeps the heaviest set.
|
|
1718
|
+
* The result always carries one entry per family in {@link MAIN_LIFT_FAMILIES} order; a family the
|
|
1719
|
+
* athlete has not logged comes back with null fields (the "no PR yet" case), so a dashboard can
|
|
1720
|
+
* render a stable row of columns.
|
|
1721
|
+
*/
|
|
1722
|
+
async function fetchAthleteMainLiftPRs(client, athleteId, opts = {}) {
|
|
1723
|
+
const { athleteName, lifts } = await resolveAthleteMainLifts(client, athleteId, opts);
|
|
1724
|
+
const byFamily = new Map(lifts.map((l) => [l.family, l]));
|
|
1725
|
+
return {
|
|
1726
|
+
athleteId,
|
|
1727
|
+
athleteName,
|
|
1728
|
+
prs: await mapPool(MAIN_LIFT_FAMILIES, PR_CONCURRENCY, async (family) => {
|
|
1729
|
+
const lift = byFamily.get(family.key);
|
|
1730
|
+
const base = {
|
|
1731
|
+
family: family.key,
|
|
1732
|
+
label: family.label
|
|
1733
|
+
};
|
|
1734
|
+
const empty = {
|
|
1735
|
+
exerciseId: null,
|
|
1736
|
+
title: null,
|
|
1737
|
+
weight: null,
|
|
1738
|
+
reps: null,
|
|
1739
|
+
units: null,
|
|
1740
|
+
date: null
|
|
1741
|
+
};
|
|
1742
|
+
if (!lift) return {
|
|
1743
|
+
...base,
|
|
1744
|
+
...empty
|
|
1745
|
+
};
|
|
1746
|
+
const known = {
|
|
1747
|
+
exerciseId: lift.exerciseId,
|
|
1748
|
+
title: lift.title
|
|
1749
|
+
};
|
|
1750
|
+
try {
|
|
1751
|
+
const best = bestPr(presentExerciseHistory(await fetchExerciseHistoryDetail(client, lift.exerciseId, athleteId)).liftPRs);
|
|
1752
|
+
return {
|
|
1753
|
+
...base,
|
|
1754
|
+
...known,
|
|
1755
|
+
weight: best?.weight ?? null,
|
|
1756
|
+
reps: best?.reps ?? null,
|
|
1757
|
+
units: best?.units ?? null,
|
|
1758
|
+
date: best?.date ?? null
|
|
1759
|
+
};
|
|
1760
|
+
} catch {
|
|
1761
|
+
return {
|
|
1762
|
+
...base,
|
|
1763
|
+
...known,
|
|
1764
|
+
weight: null,
|
|
1765
|
+
reps: null,
|
|
1766
|
+
units: null,
|
|
1767
|
+
date: null
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
})
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
const ROSTER_CONCURRENCY = 4;
|
|
1774
|
+
/**
|
|
1775
|
+
* Every roster athlete's main-lift PRs in one call: list the roster ({@link fetchCoachRoster}) and
|
|
1776
|
+
* resolve each athlete's board ({@link fetchAthleteMainLiftPRs}), fanned out with a bounded pool.
|
|
1777
|
+
* `athleteIds` restricts to a subset (else the whole roster). Each entry's `athleteName` falls back
|
|
1778
|
+
* to the roster name when the per-athlete read can't supply one. This is the single roster-level
|
|
1779
|
+
* primitive the CLI, the MCP tool, and the warehouse store all build on.
|
|
1780
|
+
*/
|
|
1781
|
+
async function fetchRosterMainLiftPRs(client, opts = {}) {
|
|
1782
|
+
const roster = await fetchCoachRoster(client, opts.athleteIds);
|
|
1783
|
+
const inner = {
|
|
1784
|
+
...opts.months !== void 0 ? { months: opts.months } : {},
|
|
1785
|
+
...opts.now !== void 0 ? { now: opts.now } : {}
|
|
1786
|
+
};
|
|
1787
|
+
return mapPool(roster, opts.concurrency ?? ROSTER_CONCURRENCY, async (athlete) => {
|
|
1788
|
+
const result = await fetchAthleteMainLiftPRs(client, athlete.id, inner);
|
|
1789
|
+
return {
|
|
1790
|
+
athleteId: athlete.id,
|
|
1791
|
+
athleteName: result.athleteName ?? athlete.name,
|
|
1792
|
+
prs: result.prs
|
|
1793
|
+
};
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
//#endregion
|
|
1452
1797
|
//#region src/util.ts
|
|
1453
1798
|
/**
|
|
1454
1799
|
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
@@ -2031,4 +2376,4 @@ var ExerciseLibrary = class {
|
|
|
2031
2376
|
}
|
|
2032
2377
|
};
|
|
2033
2378
|
//#endregion
|
|
2034
|
-
export { ANALYTICS_METRIC_KEYS, DEFAULT_INVITE_MESSAGE, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, TrainHeroicAuthError, TrainHeroicClient, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload,
|
|
2379
|
+
export { ANALYTICS_METRIC_KEYS, DEFAULT_INVITE_MESSAGE, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MAIN_LIFT_FAMILIES, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, TrainHeroicAuthError, TrainHeroicClient, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkouts, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, sortRosterByRecency, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"zod": "^4.4.3",
|
|
30
|
-
"@trainheroic-unofficial/dto": "1.
|
|
30
|
+
"@trainheroic-unofficial/dto": "1.3.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^26.0.0",
|