@trainheroic-unofficial/js 0.6.2 → 0.6.3

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as LibrarySnapshot, r as MemoryLibraryCache, t as LibraryCache } from "./library-cache-CDABOdIN.mjs";
2
- import { Advisory, AthletePrefs, AthleteProfileSummary, AthleteUser, AthleteWorkingMax, AthleteWorkoutView, BlockSpec, ExerciseHistoryDetail, ExerciseHistoryListItem, ExerciseRow, ExerciseSpec, ExerciseStats, ExerciseView, PersonalRecord, PresentedExerciseHistory, ProgramWorkout, ReadResult, ResolveResult, WorkoutDate } from "@trainheroic-unofficial/dto";
2
+ import { Advisory, AthletePrefs, AthleteProfileSummary, AthleteUser, AthleteWorkingMax, AthleteWorkoutSummary, AthleteWorkoutView, BlockSpec, CoachAthleteTraining, ExerciseHistoryDetail, ExerciseHistoryListItem, ExerciseRow, ExerciseSpec, ExerciseStats, ExerciseView, PersonalRecord, PresentedExerciseHistory, ProgramWorkout, ReadResult, ResolveResult, WorkoutDate } from "@trainheroic-unofficial/dto";
3
3
  import { ZodType } from "zod";
4
4
  export * from "@trainheroic-unofficial/dto";
5
5
 
@@ -144,6 +144,13 @@ declare function fetchPersonalRecords(client: TrainHeroicClient, exerciseId: num
144
144
  declare function fetchExerciseStats(client: TrainHeroicClient, exerciseId: number, userId: number, date: string): Promise<ExerciseStats>;
145
145
  /** Scheduled + completed workouts in an inclusive YYYY-MM-DD window. */
146
146
  declare function fetchAthleteWorkouts(client: TrainHeroicClient, startDate: string, endDate: string): Promise<ProgramWorkout[]>;
147
+ /**
148
+ * A coach's month view of a roster athlete's logged sessions
149
+ * (`/2.0/coach/athlete/calendar/summary`). The trailing path segment is required by the API but
150
+ * ignored (any value returns the whole month); it mirrors the coach web app, which sends 7. The
151
+ * `userId` in each row is the roster athlete, not the calling coach.
152
+ */
153
+ declare function fetchCoachAthleteCalendarSummary(client: TrainHeroicClient, athleteId: number, year: number, month: number): Promise<unknown[]>;
147
154
  declare function fetchLeaderboard(client: TrainHeroicClient, workoutId: number, opts?: {
148
155
  page?: number;
149
156
  pageSize?: number;
@@ -168,6 +175,21 @@ declare function selectWorkouts(list: readonly AthleteWorkoutView[], opts?: {
168
175
  loggedOnly?: boolean;
169
176
  limit?: number;
170
177
  }): AthleteWorkoutView[];
178
+ /**
179
+ * Project presented workouts to compact headers (date/title/program + logged flag + exercise
180
+ * counts), dropping the per-set block detail. A dense multi-program week of full views can be
181
+ * tens of KB; this keeps an overview question to one small row per session, with a drill-in
182
+ * (narrow the date range) when the detail is actually needed.
183
+ */
184
+ declare function summarizeAthleteWorkouts(list: readonly AthleteWorkoutView[]): AthleteWorkoutSummary[];
185
+ /**
186
+ * Flatten the coach athlete-calendar summary into compact per-session rows: title, the `logged`
187
+ * flag (the reliable did-they-train signal), rpe/duration/notes, and the exercises performed with
188
+ * the API's own set summary string (`abr`, e.g. "5 x 2 @ 205 lb"). The exercise titles here are
189
+ * the discovery handle a coach otherwise lacks: read what the athlete actually did, then pull the
190
+ * specific lift's PRs.
191
+ */
192
+ declare function presentCoachAthleteTraining(raw: readonly unknown[], athleteId: number, year: number, month: number): CoachAthleteTraining;
171
193
  /**
172
194
  * One set of entered values for a single exercise within a saved workout set.
173
195
  * `param1` and `param2` correspond to the exercise's first and second parameter types
@@ -364,4 +386,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
364
386
  stats(): Promise<Record<string, unknown>>;
365
387
  }
366
388
  //#endregion
367
- export { AddedExercise, ApiBase, BuildOptions, ClientResult, ExerciseIndex, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PersonalWorkoutCreated, RequestOptions, SetResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, addExercisesToWorkout, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseLogPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, createPersonalWorkout, deleteComment, exerciseUnits, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchStreams, fetchWorkingMaxes, findSavedWorkoutSet, isRecord, logAthleteSet, loginTrainHeroic, makeExercise, mapPool, presentAthleteWorkout, presentAthleteWorkouts, presentExercise, presentExerciseHistory, publishSession, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
389
+ export { AddedExercise, ApiBase, BuildOptions, ClientResult, ExerciseIndex, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PersonalWorkoutCreated, RequestOptions, SetResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, addExercisesToWorkout, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseLogPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, createPersonalWorkout, deleteComment, exerciseUnits, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchStreams, fetchWorkingMaxes, findSavedWorkoutSet, isRecord, logAthleteSet, loginTrainHeroic, makeExercise, mapPool, presentAthleteWorkout, presentAthleteWorkouts, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, publishSession, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, summarizeAthleteWorkouts, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
package/dist/index.mjs CHANGED
@@ -348,6 +348,15 @@ function fetchExerciseStats(client, exerciseId, userId, date) {
348
348
  function fetchAthleteWorkouts(client, startDate, endDate) {
349
349
  return getArray(client, `/3.0/athlete/programworkout/range?startDate=${startDate}&endDate=${endDate}`, "athlete workouts");
350
350
  }
351
+ /**
352
+ * A coach's month view of a roster athlete's logged sessions
353
+ * (`/2.0/coach/athlete/calendar/summary`). The trailing path segment is required by the API but
354
+ * ignored (any value returns the whole month); it mirrors the coach web app, which sends 7. The
355
+ * `userId` in each row is the roster athlete, not the calling coach.
356
+ */
357
+ function fetchCoachAthleteCalendarSummary(client, athleteId, year, month) {
358
+ return getArray(client, `/2.0/coach/athlete/calendar/summary/${athleteId}/${year}/${month}/7`, "coach athlete calendar summary");
359
+ }
351
360
  function fetchLeaderboard(client, workoutId, opts = {}) {
352
361
  const qs = new URLSearchParams();
353
362
  if (opts.page !== void 0) qs.set("page", String(opts.page));
@@ -532,6 +541,76 @@ function selectWorkouts(list, opts = {}) {
532
541
  if (opts.limit !== void 0) out = [...out].sort((a, b) => a.date < b.date ? 1 : a.date > b.date ? -1 : 0).slice(0, opts.limit);
533
542
  return out;
534
543
  }
544
+ /**
545
+ * Project presented workouts to compact headers (date/title/program + logged flag + exercise
546
+ * counts), dropping the per-set block detail. A dense multi-program week of full views can be
547
+ * tens of KB; this keeps an overview question to one small row per session, with a drill-in
548
+ * (narrow the date range) when the detail is actually needed.
549
+ */
550
+ function summarizeAthleteWorkouts(list) {
551
+ return list.map((w) => {
552
+ const exerciseCount = w.blocks.reduce((n, b) => n + b.exercises.length, 0);
553
+ const performedCount = w.blocks.reduce((n, b) => n + b.exercises.filter((e) => e.performed.length > 0).length, 0);
554
+ return {
555
+ id: w.id,
556
+ date: w.date,
557
+ title: w.title,
558
+ program: w.program,
559
+ team: w.team,
560
+ logged: w.logged,
561
+ exerciseCount,
562
+ performedCount
563
+ };
564
+ });
565
+ }
566
+ /**
567
+ * Flatten the coach athlete-calendar summary into compact per-session rows: title, the `logged`
568
+ * flag (the reliable did-they-train signal), rpe/duration/notes, and the exercises performed with
569
+ * the API's own set summary string (`abr`, e.g. "5 x 2 @ 205 lb"). The exercise titles here are
570
+ * the discovery handle a coach otherwise lacks: read what the athlete actually did, then pull the
571
+ * specific lift's PRs.
572
+ */
573
+ function presentCoachAthleteTraining(raw, athleteId, year, month) {
574
+ const sessions = [];
575
+ let athleteName = null;
576
+ for (const item of raw) {
577
+ if (!isRecord(item)) continue;
578
+ if (athleteName === null && typeof item.athleteName === "string") athleteName = item.athleteName;
579
+ const exercises = [];
580
+ const sets = Array.isArray(item.sets) ? item.sets : [];
581
+ for (const set of sets) {
582
+ if (!isRecord(set)) continue;
583
+ const exs = Array.isArray(set.exercises) ? set.exercises : [];
584
+ for (const ex of exs) {
585
+ if (!isRecord(ex)) continue;
586
+ exercises.push({
587
+ exerciseId: coerceInt(ex.exercise_id),
588
+ title: typeof ex.title === "string" ? ex.title : "",
589
+ summary: typeof ex.abr === "string" && ex.abr !== "" ? ex.abr : null,
590
+ completed: coerceInt(ex.completed) === 1
591
+ });
592
+ }
593
+ }
594
+ sessions.push({
595
+ workoutId: coerceInt(item.workout_id),
596
+ savedWorkoutId: coerceInt(item.saved_workout_id),
597
+ title: typeof item.workout_title === "string" ? item.workout_title : "",
598
+ logged: coerceInt(item.logged) === 1,
599
+ completed: coerceInt(item.completed) === 1,
600
+ rpe: coerceInt(item.rpe),
601
+ durationMin: coerceInt(item.session_duration),
602
+ notes: typeof item.notes === "string" && item.notes !== "" ? item.notes : null,
603
+ exercises
604
+ });
605
+ }
606
+ return {
607
+ athleteId,
608
+ athleteName,
609
+ year,
610
+ month,
611
+ sessions
612
+ };
613
+ }
535
614
  const MAX_PARAM_SLOTS = 10;
536
615
  /**
537
616
  * Build the body for `PUT /1.0/athlete/savedworkoutsetexercise/{id}`. The body uses
@@ -1291,4 +1370,4 @@ var ExerciseLibrary = class {
1291
1370
  }
1292
1371
  };
1293
1372
  //#endregion
1294
- export { ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, TrainHeroicAuthError, TrainHeroicClient, addExercisesToWorkout, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseLogPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, createPersonalWorkout, deleteComment, exerciseUnits, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchStreams, fetchWorkingMaxes, findSavedWorkoutSet, isRecord, logAthleteSet, loginTrainHeroic, makeExercise, mapPool, presentAthleteWorkout, presentAthleteWorkouts, presentExercise, presentExerciseHistory, publishSession, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
1373
+ export { ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, TrainHeroicAuthError, TrainHeroicClient, addExercisesToWorkout, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseLogPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, coerceInt, coerceNum, collectAdvisories, createPersonalWorkout, deleteComment, exerciseUnits, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchStreams, fetchWorkingMaxes, findSavedWorkoutSet, isRecord, logAthleteSet, loginTrainHeroic, makeExercise, mapPool, presentAthleteWorkout, presentAthleteWorkouts, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, publishSession, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, summarizeAthleteWorkouts, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/js",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
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": "0.6.2"
30
+ "@trainheroic-unofficial/dto": "0.6.3"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^26.0.0",