@trainheroic-unofficial/js 1.2.0 → 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 +95 -1
- package/dist/index.mjs +240 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -483,8 +483,102 @@ declare function logSessionForAthlete(client: TrainHeroicClient, args: {
|
|
|
483
483
|
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
484
484
|
declare function presentExerciseHistory(detail: ExerciseHistoryDetail): PresentedExerciseHistory;
|
|
485
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
|
|
486
568
|
//#region src/coach.d.ts
|
|
487
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[]>;
|
|
488
582
|
/**
|
|
489
583
|
* Invite athletes to a team — TrainHeroic's two-step "create athlete" flow: validate the
|
|
490
584
|
* addresses (`POST /v5/emails/validate`), then invite the validated ones
|
|
@@ -663,4 +757,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
663
757
|
stats(): Promise<Record<string, unknown>>;
|
|
664
758
|
}
|
|
665
759
|
//#endregion
|
|
666
|
-
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, SetWriteMode, SwapExerciseResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, 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, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, sortRosterByRecency, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
|
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
|
@@ -1256,6 +1256,7 @@ function presentExerciseHistory(detail) {
|
|
|
1256
1256
|
description: p.description ?? null,
|
|
1257
1257
|
reps: p.reps ?? null,
|
|
1258
1258
|
weight: p.weight ?? null,
|
|
1259
|
+
units: p.units ?? null,
|
|
1259
1260
|
date: p.dateCompleted ?? null
|
|
1260
1261
|
})),
|
|
1261
1262
|
sessions: (detail.history ?? []).map((h) => ({
|
|
@@ -1276,6 +1277,37 @@ const DEFAULT_INVITE_MESSAGE = "Follow these steps and you'll be set up and read
|
|
|
1276
1277
|
function emailList(emails) {
|
|
1277
1278
|
return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
|
|
1278
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
|
+
}
|
|
1279
1311
|
/**
|
|
1280
1312
|
* Invite athletes to a team — TrainHeroic's two-step "create athlete" flow: validate the
|
|
1281
1313
|
* addresses (`POST /v5/emails/validate`), then invite the validated ones
|
|
@@ -1555,6 +1587,213 @@ async function teamVolume(client, args) {
|
|
|
1555
1587
|
};
|
|
1556
1588
|
}
|
|
1557
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
|
|
1558
1797
|
//#region src/util.ts
|
|
1559
1798
|
/**
|
|
1560
1799
|
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
@@ -2137,4 +2376,4 @@ var ExerciseLibrary = class {
|
|
|
2137
2376
|
}
|
|
2138
2377
|
};
|
|
2139
2378
|
//#endregion
|
|
2140
|
-
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, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, 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, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, sortRosterByRecency, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
|
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",
|