@trainheroic-unofficial/js 3.3.3 → 3.5.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 +39 -2
- package/dist/index.mjs +115 -29
- package/package.json +4 -4
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, AthleteWorkoutSummary, AthleteWorkoutView, BlockSpec, CoachAthleteTraining, ExerciseHistoryDetail, ExerciseHistoryListItem, ExerciseRow, ExerciseSpec, ExerciseStats, ExerciseView, PersonalRecord, PresentedExerciseHistory, ProgramWorkout, ReadResult, ResolveResult, RosterActivityRow, SessionTemplateCreate, TeamPublishPatch, TeamVolumeReport, WorkoutDate, WorkoutHistoryExport } from "@trainheroic-unofficial/dto";
|
|
2
|
+
import { Advisory, AthleteExerciseNoteOutput, AthletePrefs, AthleteProfileSummary, AthleteUser, AthleteWorkingMax, AthleteWorkoutNoteOutput, AthleteWorkoutSummary, AthleteWorkoutView, BlockSpec, CoachAthleteTraining, ExerciseHistoryDetail, ExerciseHistoryListItem, ExerciseRow, ExerciseSpec, ExerciseStats, ExerciseView, PersonalRecord, PresentedExerciseHistory, ProgramWorkout, ReadResult, ResolveResult, RosterActivityRow, SessionTemplateCreate, TeamPublishPatch, TeamVolumeReport, WorkoutDate, WorkoutHistoryExport } from "@trainheroic-unofficial/dto";
|
|
3
3
|
import { ZodType } from "zod";
|
|
4
4
|
export * from "@trainheroic-unofficial/dto";
|
|
5
5
|
//#region src/http-error.d.ts
|
|
@@ -146,6 +146,11 @@ declare function exerciseTitle(ex: Record<string, unknown>, fallback?: string):
|
|
|
146
146
|
* definition every consumer (presenter, find-or-create, the remove guard) reads through.
|
|
147
147
|
*/
|
|
148
148
|
declare function isPersonalSession(pw: unknown): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* The `saved_workout` blob on a program-workout range item, or null if the athlete has no saved
|
|
151
|
+
* copy yet. Session notes, RPE, and set writes all resolve through this.
|
|
152
|
+
*/
|
|
153
|
+
declare function savedWorkoutOf(pw: unknown): Record<string, unknown> | null;
|
|
149
154
|
/**
|
|
150
155
|
* Rank candidate rows for a free-text query (FTS5 replacement). Higher is better:
|
|
151
156
|
* exact title, then prefix, then count of matched tokens, with shorter titles and
|
|
@@ -224,6 +229,11 @@ declare function fetchPersonalRecords(client: TrainHeroicClient, exerciseId: num
|
|
|
224
229
|
declare function fetchExerciseStats(client: TrainHeroicClient, exerciseId: number, userId: number, date: string): Promise<ExerciseStats>;
|
|
225
230
|
/** Scheduled + completed workouts in an inclusive YYYY-MM-DD window. */
|
|
226
231
|
declare function fetchAthleteWorkouts(client: TrainHeroicClient, startDate: string, endDate: string): Promise<ProgramWorkout[]>;
|
|
232
|
+
/**
|
|
233
|
+
* The program-workout row with this id on this date. Throws if that id is not on the day's range;
|
|
234
|
+
* callers should take the id from `athlete_workouts`.
|
|
235
|
+
*/
|
|
236
|
+
declare function programWorkoutOnDate(client: TrainHeroicClient, date: string, programWorkoutId: number): Promise<ProgramWorkout>;
|
|
227
237
|
/** Split an inclusive `[start, end]` range into consecutive non-overlapping windows of `windowDays`. */
|
|
228
238
|
declare function dateWindows(startDate: string, endDate: string, windowDays: number): Array<{
|
|
229
239
|
start: string;
|
|
@@ -280,6 +290,7 @@ type LogSetTarget = {
|
|
|
280
290
|
savedWorkoutSetExerciseId: number;
|
|
281
291
|
title: string;
|
|
282
292
|
units: ReturnType<typeof exerciseUnits>;
|
|
293
|
+
notes: string | null;
|
|
283
294
|
prescribed: string[];
|
|
284
295
|
performed: string[];
|
|
285
296
|
}>;
|
|
@@ -681,6 +692,32 @@ declare function logSessionForAthlete(client: TrainHeroicClient, args: {
|
|
|
681
692
|
exercises: readonly SessionExercise[];
|
|
682
693
|
}): Promise<LogSessionResult>;
|
|
683
694
|
//#endregion
|
|
695
|
+
//#region src/athlete-workout-note.d.ts
|
|
696
|
+
/**
|
|
697
|
+
* PUT /1.0/athlete/savedworkout/{id} — set the athlete's session note (the free-text box on the
|
|
698
|
+
* workout screen) and/or session RPE. The date + programWorkoutId (`athlete_workouts` `id`) locate
|
|
699
|
+
* the saved workout; GET on that path 405s, so the range read is the lookup. A notes-only body
|
|
700
|
+
* leaves rpe untouched and vice versa. Empty `notes` clears the note. Coach-visible.
|
|
701
|
+
*/
|
|
702
|
+
declare function setAthleteWorkoutNote(client: TrainHeroicClient, args: {
|
|
703
|
+
date: string;
|
|
704
|
+
programWorkoutId: number | string;
|
|
705
|
+
notes?: string | undefined;
|
|
706
|
+
rpe?: number | undefined;
|
|
707
|
+
}): Promise<AthleteWorkoutNoteOutput>;
|
|
708
|
+
//#endregion
|
|
709
|
+
//#region src/athlete-exercise-note.d.ts
|
|
710
|
+
/**
|
|
711
|
+
* PUT /1.0/athlete/savedworkoutsetexercise/{id} — set the athlete's per-exercise note (the
|
|
712
|
+
* "Add exercise note" box on the exercise screen). A notes-only body leaves logged reps/weight
|
|
713
|
+
* untouched. Empty `notes` clears the note. GET on that path 405s; the range read and exercise
|
|
714
|
+
* history both echo the stored string. Coach-visible.
|
|
715
|
+
*/
|
|
716
|
+
declare function setAthleteExerciseNote(client: TrainHeroicClient, args: {
|
|
717
|
+
savedWorkoutSetExerciseId: number | string;
|
|
718
|
+
notes: string;
|
|
719
|
+
}): Promise<AthleteExerciseNoteOutput>;
|
|
720
|
+
//#endregion
|
|
684
721
|
//#region src/workout-export.d.ts
|
|
685
722
|
type WorkoutExportFormat = "json" | "csv" | "text";
|
|
686
723
|
/** A serialized export ready to write to a file or hand to a browser download. */
|
|
@@ -1070,4 +1107,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
1070
1107
|
stats(): Promise<Record<string, unknown>>;
|
|
1071
1108
|
}
|
|
1072
1109
|
//#endregion
|
|
1073
|
-
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, BuildOptions, ClientOptions, ClientResult, CoachAthleteCalendar, CoachRosterAthlete, CreatedProgram, DEFAULT_INVITE_MESSAGE, DeletedProgram, ExerciseDefaults, ExerciseIndex, ExerciseLibrary, type ExerciseSetInput, type ExerciseSetPayload, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, LoginOptions, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MainLiftFamily, MainLiftFamilyKey, MainLiftPR, MainLiftResolution, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PROGRAM_KINDS, PersonalWorkoutCreated, ProgramKind, RequestOptions, ResolvedLift, SESSION_TEMPLATES_LIST_PATH, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, type SetWriteMode, SwapExerciseResult, TeamPublishTarget, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, type TrainHeroicHttpErrorHandler, TrainHeroicSession, WorkoutExportFormat, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, dateWindows, defaultBlockType, definedProps, deleteComment, deleteProgram, exerciseTitle, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, updateTeamPublishSettings, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
|
1110
|
+
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, BuildOptions, ClientOptions, ClientResult, CoachAthleteCalendar, CoachRosterAthlete, CreatedProgram, DEFAULT_INVITE_MESSAGE, DeletedProgram, ExerciseDefaults, ExerciseIndex, ExerciseLibrary, type ExerciseSetInput, type ExerciseSetPayload, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, LoginOptions, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MainLiftFamily, MainLiftFamilyKey, MainLiftPR, MainLiftResolution, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PROGRAM_KINDS, PersonalWorkoutCreated, ProgramKind, RequestOptions, ResolvedLift, SESSION_TEMPLATES_LIST_PATH, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, type SetWriteMode, SwapExerciseResult, TeamPublishTarget, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, type TrainHeroicHttpErrorHandler, TrainHeroicSession, WorkoutExportFormat, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, dateWindows, defaultBlockType, definedProps, deleteComment, deleteProgram, exerciseTitle, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, programWorkoutOnDate, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, savedWorkoutOf, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setAthleteExerciseNote, setAthleteWorkoutNote, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, updateTeamPublishSettings, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
package/dist/index.mjs
CHANGED
|
@@ -340,6 +340,15 @@ function isPersonalSession(pw) {
|
|
|
340
340
|
return isRecord(pw) && pw.personal_cal === true;
|
|
341
341
|
}
|
|
342
342
|
/**
|
|
343
|
+
* The `saved_workout` blob on a program-workout range item, or null if the athlete has no saved
|
|
344
|
+
* copy yet. Session notes, RPE, and set writes all resolve through this.
|
|
345
|
+
*/
|
|
346
|
+
function savedWorkoutOf(pw) {
|
|
347
|
+
if (!isRecord(pw)) return null;
|
|
348
|
+
const ssw = isRecord(pw.summarizedSavedWorkout) ? pw.summarizedSavedWorkout : {};
|
|
349
|
+
return isRecord(ssw.saved_workout) ? ssw.saved_workout : null;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
343
352
|
* Rank candidate rows for a free-text query (FTS5 replacement). Higher is better:
|
|
344
353
|
* exact title, then prefix, then count of matched tokens, with shorter titles and
|
|
345
354
|
* standard (non-custom) exercises preferred on ties.
|
|
@@ -507,6 +516,15 @@ function fetchExerciseStats(client, exerciseId, userId, date) {
|
|
|
507
516
|
function fetchAthleteWorkouts(client, startDate, endDate) {
|
|
508
517
|
return getArray$1(client, `/3.0/athlete/programworkout/range?startDate=${startDate}&endDate=${endDate}`, "athlete workouts");
|
|
509
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* The program-workout row with this id on this date. Throws if that id is not on the day's range;
|
|
521
|
+
* callers should take the id from `athlete_workouts`.
|
|
522
|
+
*/
|
|
523
|
+
async function programWorkoutOnDate(client, date, programWorkoutId) {
|
|
524
|
+
const target = (await fetchAthleteWorkouts(client, date, date)).find((pw) => coerceInt(pw.id) === programWorkoutId);
|
|
525
|
+
if (target === void 0) throw new Error(`No workout with id ${programWorkoutId} on ${date}. Get the id and date from athlete_workouts.`);
|
|
526
|
+
return target;
|
|
527
|
+
}
|
|
510
528
|
/** Add `days` to a `YYYY-MM-DD` date (UTC), returning `YYYY-MM-DD`. */
|
|
511
529
|
function shiftDate(iso, days) {
|
|
512
530
|
const d = /* @__PURE__ */ new Date(`${iso}T00:00:00Z`);
|
|
@@ -645,6 +663,16 @@ function performedSlotsByExerciseId(sets) {
|
|
|
645
663
|
}
|
|
646
664
|
return map;
|
|
647
665
|
}
|
|
666
|
+
/** Per-exercise athlete notes keyed by the prescription template id (`workout_set_exercise_id`). */
|
|
667
|
+
function notesByTemplateId(sets) {
|
|
668
|
+
const map = /* @__PURE__ */ new Map();
|
|
669
|
+
for (const { exercises } of sets) for (const ex of exercises) {
|
|
670
|
+
const id = coerceInt(ex.workout_set_exercise_id);
|
|
671
|
+
const notes = str(ex.notes);
|
|
672
|
+
if (id !== null && notes !== null) map.set(id, notes);
|
|
673
|
+
}
|
|
674
|
+
return map;
|
|
675
|
+
}
|
|
648
676
|
/** Align an exercise's prescribed slots with the slots the athlete logged, per set index. */
|
|
649
677
|
function mergeExercise(prescribed, performed, meta) {
|
|
650
678
|
const indices = [.../* @__PURE__ */ new Set([...prescribed.keys(), ...performed.keys()])].sort((a, b) => a - b);
|
|
@@ -658,7 +686,7 @@ function mergeExercise(prescribed, performed, meta) {
|
|
|
658
686
|
};
|
|
659
687
|
}
|
|
660
688
|
/** A prescription block, each exercise aligned with the slots the athlete logged against it. */
|
|
661
|
-
function mergePrescriptionBlock(set, performedById) {
|
|
689
|
+
function mergePrescriptionBlock(set, performedById, notesById) {
|
|
662
690
|
const exercises = Array.isArray(set.workoutSetExercises) ? set.workoutSetExercises : [];
|
|
663
691
|
return {
|
|
664
692
|
order: coerceInt(set.order) ?? 0,
|
|
@@ -672,6 +700,7 @@ function mergePrescriptionBlock(set, performedById) {
|
|
|
672
700
|
exerciseId: coerceInt(ex.exercise_id),
|
|
673
701
|
title: typeof ex.title === "string" ? ex.title : "",
|
|
674
702
|
instruction: str(ex.instruction),
|
|
703
|
+
notes: id !== null ? notesById.get(id) ?? null : null,
|
|
675
704
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
676
705
|
});
|
|
677
706
|
})
|
|
@@ -688,6 +717,7 @@ function mergeSavedBlock(set, exercises) {
|
|
|
688
717
|
exerciseId: coerceInt(ex.exercise_id),
|
|
689
718
|
title: typeof ex.exercise_title === "string" ? ex.exercise_title : "",
|
|
690
719
|
instruction: str(ex.instruction),
|
|
720
|
+
notes: str(ex.notes),
|
|
691
721
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type)
|
|
692
722
|
}))
|
|
693
723
|
};
|
|
@@ -702,11 +732,12 @@ function mergeAthleteWorkout(raw) {
|
|
|
702
732
|
const rec = raw;
|
|
703
733
|
const ssw = isRecord(rec.summarizedSavedWorkout) ? rec.summarizedSavedWorkout : {};
|
|
704
734
|
const workout = isRecord(ssw.workout) ? ssw.workout : {};
|
|
705
|
-
const saved =
|
|
735
|
+
const saved = savedWorkoutOf(rec) ?? {};
|
|
706
736
|
const prescriptionSets = (Array.isArray(workout.workoutSets) ? workout.workoutSets : []).filter(isRecord);
|
|
707
737
|
const logged = savedSets(saved);
|
|
708
738
|
const performedById = performedSlotsByExerciseId(logged);
|
|
709
|
-
const
|
|
739
|
+
const notesById = notesByTemplateId(logged);
|
|
740
|
+
const blocks = prescriptionSets.map((s) => mergePrescriptionBlock(s, performedById, notesById)).sort((a, b) => a.order - b.order);
|
|
710
741
|
const prescribedIds = /* @__PURE__ */ new Set();
|
|
711
742
|
for (const s of prescriptionSets) {
|
|
712
743
|
const exs = Array.isArray(s.workoutSetExercises) ? s.workoutSetExercises : [];
|
|
@@ -731,6 +762,8 @@ function mergeAthleteWorkout(raw) {
|
|
|
731
762
|
program: str(rec.program_title),
|
|
732
763
|
team: str(rec.team_title),
|
|
733
764
|
instruction: str(workout.instruction),
|
|
765
|
+
notes: str(saved.notes),
|
|
766
|
+
rpe: coerceInt(saved.rpe),
|
|
734
767
|
logged: blocks.some((b) => b.exercises.some((e) => e.sets.some((s) => s.performed !== null))),
|
|
735
768
|
personal: isPersonalSession(rec),
|
|
736
769
|
blocks
|
|
@@ -750,6 +783,7 @@ function toStringExercise(ex) {
|
|
|
750
783
|
exerciseId: ex.exerciseId,
|
|
751
784
|
title: ex.title,
|
|
752
785
|
instruction: ex.instruction,
|
|
786
|
+
notes: ex.notes,
|
|
753
787
|
units: ex.units,
|
|
754
788
|
prescribed: sideStrings(ex.sets, (s) => s.prescribed),
|
|
755
789
|
performed: sideStrings(ex.sets, (s) => s.performed)
|
|
@@ -778,6 +812,8 @@ function presentAthleteWorkout(raw) {
|
|
|
778
812
|
program: w.program,
|
|
779
813
|
team: w.team,
|
|
780
814
|
instruction: w.instruction,
|
|
815
|
+
notes: w.notes,
|
|
816
|
+
rpe: w.rpe,
|
|
781
817
|
logged: w.logged,
|
|
782
818
|
personal: w.personal,
|
|
783
819
|
blocks: w.blocks.map(toStringBlock)
|
|
@@ -907,6 +943,7 @@ function presentLogTargets(list) {
|
|
|
907
943
|
savedWorkoutSetExerciseId: id,
|
|
908
944
|
title: exerciseTitle(ex),
|
|
909
945
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
946
|
+
notes: str(ex.notes),
|
|
910
947
|
prescribed: prescribedStrings(ex),
|
|
911
948
|
performed: performedStrings(ex)
|
|
912
949
|
};
|
|
@@ -997,7 +1034,7 @@ function presentCoachAthleteTraining(raw, athleteId, year, month) {
|
|
|
997
1034
|
completed: coerceInt(item.completed) === 1,
|
|
998
1035
|
rpe: coerceInt(item.rpe),
|
|
999
1036
|
durationMin: coerceInt(item.session_duration),
|
|
1000
|
-
notes:
|
|
1037
|
+
notes: str(item.notes),
|
|
1001
1038
|
exercises
|
|
1002
1039
|
});
|
|
1003
1040
|
}
|
|
@@ -1022,6 +1059,7 @@ function presentExerciseHistory(detail) {
|
|
|
1022
1059
|
sessions: (detail.history ?? []).map((h) => ({
|
|
1023
1060
|
date: h.dateCompleted,
|
|
1024
1061
|
abr: h.abr ?? null,
|
|
1062
|
+
notes: str(h.notes),
|
|
1025
1063
|
estimated1RM: h.bestEstimated1RM ?? null,
|
|
1026
1064
|
sets: (h.sets ?? []).map((s) => ({
|
|
1027
1065
|
setNumber: s.setNumber,
|
|
@@ -1217,9 +1255,7 @@ function assertUniqueExerciseResults(results) {
|
|
|
1217
1255
|
function findSavedWorkoutSet(workouts, savedWorkoutSetId) {
|
|
1218
1256
|
const available = [];
|
|
1219
1257
|
for (const pw of workouts) {
|
|
1220
|
-
const
|
|
1221
|
-
const ssw = isRecord(rec.summarizedSavedWorkout) ? rec.summarizedSavedWorkout : {};
|
|
1222
|
-
const sw = isRecord(ssw.saved_workout) ? ssw.saved_workout : null;
|
|
1258
|
+
const sw = savedWorkoutOf(pw);
|
|
1223
1259
|
if (!sw) continue;
|
|
1224
1260
|
const sets = Array.isArray(sw.workoutSets) ? sw.workoutSets : [];
|
|
1225
1261
|
for (const s of sets) {
|
|
@@ -1517,9 +1553,7 @@ async function addExercisesToWorkout(client, workoutId, exercises) {
|
|
|
1517
1553
|
* Throws on a non-ok response.
|
|
1518
1554
|
*/
|
|
1519
1555
|
async function removePersonalWorkout(client, args) {
|
|
1520
|
-
|
|
1521
|
-
if (target === void 0) throw new Error(`No workout with id ${args.programWorkoutId} on ${args.date}. Get the id and date from athlete_workouts.`);
|
|
1522
|
-
if (!isPersonalSession(target)) throw new Error(`Workout ${args.programWorkoutId} on ${args.date} is a coach-scheduled workout, not a personal session, so it can't be removed. To change logged results on a scheduled workout, use athlete_log_set.`);
|
|
1556
|
+
if (!isPersonalSession(await programWorkoutOnDate(client, args.date, args.programWorkoutId))) throw new Error(`Workout ${args.programWorkoutId} on ${args.date} is a coach-scheduled workout, not a personal session, so it can't be removed. To change logged results on a scheduled workout, use athlete_log_set.`);
|
|
1523
1557
|
const res = await client.request("DELETE", `/v5/programWorkouts/${args.programWorkoutId}`);
|
|
1524
1558
|
if (!res.ok) throw new Error(`Remove personal workout failed (HTTP ${res.status}).`);
|
|
1525
1559
|
}
|
|
@@ -1572,8 +1606,7 @@ function eachPrescribedExercise(workouts) {
|
|
|
1572
1606
|
const rows = [];
|
|
1573
1607
|
for (const pw of workouts) {
|
|
1574
1608
|
const rec = pw;
|
|
1575
|
-
const
|
|
1576
|
-
const sw = isRecord(ssw.saved_workout) ? ssw.saved_workout : null;
|
|
1609
|
+
const sw = savedWorkoutOf(rec);
|
|
1577
1610
|
if (!sw) continue;
|
|
1578
1611
|
const sets = [...Array.isArray(sw.workoutSets) ? sw.workoutSets : [], ...Array.isArray(sw.addedWorkoutSets) ? sw.addedWorkoutSets : []];
|
|
1579
1612
|
for (const s of sets) {
|
|
@@ -1743,6 +1776,75 @@ async function logSessionForAthlete(client, args) {
|
|
|
1743
1776
|
};
|
|
1744
1777
|
}
|
|
1745
1778
|
//#endregion
|
|
1779
|
+
//#region src/util.ts
|
|
1780
|
+
/**
|
|
1781
|
+
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
1782
|
+
* spread into an object under `exactOptionalPropertyTypes` without the per-key
|
|
1783
|
+
* `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
|
|
1784
|
+
* optional ones lose `undefined` from their value type.
|
|
1785
|
+
*
|
|
1786
|
+
* Example:
|
|
1787
|
+
* definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
|
|
1788
|
+
*/
|
|
1789
|
+
function definedProps(obj) {
|
|
1790
|
+
const result = {};
|
|
1791
|
+
for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
|
|
1792
|
+
return result;
|
|
1793
|
+
}
|
|
1794
|
+
//#endregion
|
|
1795
|
+
//#region src/athlete-workout-note.ts
|
|
1796
|
+
/**
|
|
1797
|
+
* PUT /1.0/athlete/savedworkout/{id} — set the athlete's session note (the free-text box on the
|
|
1798
|
+
* workout screen) and/or session RPE. The date + programWorkoutId (`athlete_workouts` `id`) locate
|
|
1799
|
+
* the saved workout; GET on that path 405s, so the range read is the lookup. A notes-only body
|
|
1800
|
+
* leaves rpe untouched and vice versa. Empty `notes` clears the note. Coach-visible.
|
|
1801
|
+
*/
|
|
1802
|
+
async function setAthleteWorkoutNote(client, args) {
|
|
1803
|
+
if (args.notes === void 0 && args.rpe === void 0) throw new Error("Provide notes and/or rpe.");
|
|
1804
|
+
const programWorkoutId = coerceInt(args.programWorkoutId);
|
|
1805
|
+
if (programWorkoutId === null) throw new Error(`Invalid programWorkoutId ${String(args.programWorkoutId)}.`);
|
|
1806
|
+
const saved = savedWorkoutOf(await programWorkoutOnDate(client, args.date, programWorkoutId));
|
|
1807
|
+
const savedWorkoutId = saved !== null ? coerceInt(saved.id) : null;
|
|
1808
|
+
if (savedWorkoutId === null) throw new Error(`Workout ${programWorkoutId} on ${args.date} has no saved workout to attach a note to.`);
|
|
1809
|
+
const body = definedProps({
|
|
1810
|
+
id: savedWorkoutId,
|
|
1811
|
+
notes: args.notes,
|
|
1812
|
+
rpe: args.rpe
|
|
1813
|
+
});
|
|
1814
|
+
const res = await client.request("PUT", `/1.0/athlete/savedworkout/${savedWorkoutId}`, { body });
|
|
1815
|
+
if (!res.ok) throw new Error(`Set workout note failed (HTTP ${res.status}).`);
|
|
1816
|
+
const data = isRecord(res.data) ? res.data : {};
|
|
1817
|
+
return {
|
|
1818
|
+
programWorkoutId,
|
|
1819
|
+
savedWorkoutId,
|
|
1820
|
+
date: args.date,
|
|
1821
|
+
notes: typeof data.notes === "string" ? data.notes : args.notes ?? "",
|
|
1822
|
+
rpe: coerceInt(data.rpe) ?? (args.rpe !== void 0 ? args.rpe : null)
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
//#endregion
|
|
1826
|
+
//#region src/athlete-exercise-note.ts
|
|
1827
|
+
/**
|
|
1828
|
+
* PUT /1.0/athlete/savedworkoutsetexercise/{id} — set the athlete's per-exercise note (the
|
|
1829
|
+
* "Add exercise note" box on the exercise screen). A notes-only body leaves logged reps/weight
|
|
1830
|
+
* untouched. Empty `notes` clears the note. GET on that path 405s; the range read and exercise
|
|
1831
|
+
* history both echo the stored string. Coach-visible.
|
|
1832
|
+
*/
|
|
1833
|
+
async function setAthleteExerciseNote(client, args) {
|
|
1834
|
+
const savedWorkoutSetExerciseId = coerceInt(args.savedWorkoutSetExerciseId);
|
|
1835
|
+
if (savedWorkoutSetExerciseId === null) throw new Error(`Invalid savedWorkoutSetExerciseId ${String(args.savedWorkoutSetExerciseId)}.`);
|
|
1836
|
+
const res = await client.request("PUT", `/1.0/athlete/savedworkoutsetexercise/${savedWorkoutSetExerciseId}`, { body: {
|
|
1837
|
+
id: savedWorkoutSetExerciseId,
|
|
1838
|
+
notes: args.notes
|
|
1839
|
+
} });
|
|
1840
|
+
if (!res.ok) throw new Error(`Set exercise note failed (HTTP ${res.status}).`);
|
|
1841
|
+
const data = isRecord(res.data) ? res.data : {};
|
|
1842
|
+
return {
|
|
1843
|
+
savedWorkoutSetExerciseId,
|
|
1844
|
+
notes: typeof data.notes === "string" ? data.notes : args.notes
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
//#endregion
|
|
1746
1848
|
//#region src/workout-export.ts
|
|
1747
1849
|
const DEFAULT_FILENAME_BASE = "trainheroic-workout-history";
|
|
1748
1850
|
/** Pretty-printed JSON of the structured workouts, exactly as `presentAthleteWorkoutsExport` yields. */
|
|
@@ -1869,22 +1971,6 @@ function serializeWorkoutHistory(workouts, format, opts = {}) {
|
|
|
1869
1971
|
};
|
|
1870
1972
|
}
|
|
1871
1973
|
//#endregion
|
|
1872
|
-
//#region src/util.ts
|
|
1873
|
-
/**
|
|
1874
|
-
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
1875
|
-
* spread into an object under `exactOptionalPropertyTypes` without the per-key
|
|
1876
|
-
* `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
|
|
1877
|
-
* optional ones lose `undefined` from their value type.
|
|
1878
|
-
*
|
|
1879
|
-
* Example:
|
|
1880
|
-
* definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
|
|
1881
|
-
*/
|
|
1882
|
-
function definedProps(obj) {
|
|
1883
|
-
const result = {};
|
|
1884
|
-
for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
|
|
1885
|
-
return result;
|
|
1886
|
-
}
|
|
1887
|
-
//#endregion
|
|
1888
1974
|
//#region src/workout-encode.ts
|
|
1889
1975
|
const LEADERBOARD_TYPE = {
|
|
1890
1976
|
completion: 0,
|
|
@@ -3187,4 +3273,4 @@ var ExerciseLibrary = class {
|
|
|
3187
3273
|
}
|
|
3188
3274
|
};
|
|
3189
3275
|
//#endregion
|
|
3190
|
-
export { ANALYTICS_METRIC_KEYS, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, DEFAULT_INVITE_MESSAGE, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PROGRAM_KINDS, SESSION_TEMPLATES_LIST_PATH, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, dateWindows, defaultBlockType, definedProps, deleteComment, deleteProgram, exerciseTitle, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, updateTeamPublishSettings, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
|
3276
|
+
export { ANALYTICS_METRIC_KEYS, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, DEFAULT_INVITE_MESSAGE, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PROGRAM_KINDS, SESSION_TEMPLATES_LIST_PATH, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, createProgram, createSessionTemplate, dateWindows, defaultBlockType, definedProps, deleteComment, deleteProgram, exerciseTitle, exerciseUnits, fetchAthleteCircuits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteProgrammingPrograms, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRecentExercises, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeAthleteSet, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, programWorkoutOnDate, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveBuildProgramId, resolveLeaderboard, savedWorkoutOf, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setAthleteExerciseNote, setAthleteWorkoutNote, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamPublishTarget, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, updateTeamPublishSettings, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"zod": "^4.4.3",
|
|
30
|
-
"@trainheroic-unofficial/dto": "3.
|
|
30
|
+
"@trainheroic-unofficial/dto": "3.5.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^26.
|
|
33
|
+
"@types/node": "^26.3.0",
|
|
34
34
|
"tsdown": "^0.22.14",
|
|
35
|
-
"vitest": "^4.1.
|
|
35
|
+
"vitest": "^4.1.11"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsdown",
|