@trainheroic-unofficial/js 0.6.0 → 0.6.1
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 +18 -2
- package/dist/index.mjs +119 -8
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -149,9 +149,25 @@ declare function fetchLeaderboard(client: TrainHeroicClient, workoutId: number,
|
|
|
149
149
|
pageSize?: number;
|
|
150
150
|
gender?: number;
|
|
151
151
|
}): Promise<unknown>;
|
|
152
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* Flatten one `/3.0/athlete/programworkout/range` item into a readable workout, merging the
|
|
154
|
+
* prescription (`summarizedSavedWorkout.workout`) with what the athlete logged
|
|
155
|
+
* (`summarizedSavedWorkout.saved_workout`). Each exercise carries both its `prescribed` and
|
|
156
|
+
* `performed` sets; athlete-added/personal work that has no prescription is appended as its
|
|
157
|
+
* own blocks. No `raw` is needed to see logged results.
|
|
158
|
+
*/
|
|
153
159
|
declare function presentAthleteWorkout(raw: ProgramWorkout): AthleteWorkoutView;
|
|
154
160
|
declare function presentAthleteWorkouts(list: readonly ProgramWorkout[]): AthleteWorkoutView[];
|
|
161
|
+
/**
|
|
162
|
+
* Narrow a presented workout list for the common "what did I actually do" reads. `loggedOnly`
|
|
163
|
+
* keeps only workouts the athlete logged a set on (the reliable signal, not the API's
|
|
164
|
+
* completion flag). `limit` keeps the most recent N by date (newest first). Both are pure
|
|
165
|
+
* post-filters over the presented view; the raw API path is left untouched.
|
|
166
|
+
*/
|
|
167
|
+
declare function selectWorkouts(list: readonly AthleteWorkoutView[], opts?: {
|
|
168
|
+
loggedOnly?: boolean;
|
|
169
|
+
limit?: number;
|
|
170
|
+
}): AthleteWorkoutView[];
|
|
155
171
|
/**
|
|
156
172
|
* One set of entered values for a single exercise within a saved workout set.
|
|
157
173
|
* `param1` and `param2` correspond to the exercise's first and second parameter types
|
|
@@ -348,4 +364,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
348
364
|
stats(): Promise<Record<string, unknown>>;
|
|
349
365
|
}
|
|
350
366
|
//#endregion
|
|
351
|
-
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, sendComment, setSessionInstruction, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -379,35 +379,134 @@ function prescribedSets(ex) {
|
|
|
379
379
|
}
|
|
380
380
|
return out;
|
|
381
381
|
}
|
|
382
|
-
|
|
382
|
+
/**
|
|
383
|
+
* The per-set values the athlete actually logged, read from a saved-copy exercise. A set
|
|
384
|
+
* counts as performed only when its `param_{i}_made` flag is 1: the saved copy pre-fills the
|
|
385
|
+
* `param_N_data` slots with the prescription, so the presence of data alone does not mean a
|
|
386
|
+
* set was done. `param_{i}_made` is the same per-set flag the logging write sets, and is the
|
|
387
|
+
* only reliable signal (the `completed` flags are often left at 0 on a logged session).
|
|
388
|
+
*/
|
|
389
|
+
function performedSets(ex) {
|
|
390
|
+
const out = [];
|
|
391
|
+
for (let i = 1; i <= SLOTS; i += 1) {
|
|
392
|
+
if (coerceInt(ex[`param_${i}_made`]) !== 1) continue;
|
|
393
|
+
const p1 = ex[`param_1_data_${i}`];
|
|
394
|
+
const p2 = ex[`param_2_data_${i}`];
|
|
395
|
+
const has1 = nonEmpty(p1);
|
|
396
|
+
const has2 = nonEmpty(p2);
|
|
397
|
+
if (has1 && has2) out.push(`${p1} @ ${p2}`);
|
|
398
|
+
else if (has1) out.push(String(p1));
|
|
399
|
+
else if (has2) out.push(`@ ${p2}`);
|
|
400
|
+
}
|
|
401
|
+
return out;
|
|
402
|
+
}
|
|
403
|
+
function presentExercise$1(ex, performedById) {
|
|
383
404
|
const instruction = typeof ex.instruction === "string" && ex.instruction !== "" ? ex.instruction : null;
|
|
405
|
+
const id = coerceInt(ex.id);
|
|
384
406
|
return {
|
|
385
407
|
exerciseId: coerceInt(ex.exercise_id),
|
|
386
408
|
title: typeof ex.title === "string" ? ex.title : "",
|
|
387
409
|
instruction,
|
|
388
410
|
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
389
|
-
prescribed: prescribedSets(ex)
|
|
411
|
+
prescribed: prescribedSets(ex),
|
|
412
|
+
performed: (id !== null ? performedById.get(id) : void 0) ?? []
|
|
390
413
|
};
|
|
391
414
|
}
|
|
392
|
-
function presentBlock(set) {
|
|
415
|
+
function presentBlock(set, performedById) {
|
|
393
416
|
const exercises = Array.isArray(set.workoutSetExercises) ? set.workoutSetExercises : [];
|
|
394
417
|
return {
|
|
395
418
|
order: coerceInt(set.order) ?? 0,
|
|
396
419
|
title: typeof set.title === "string" && set.title !== "" ? set.title : null,
|
|
397
420
|
instruction: typeof set.instruction === "string" && set.instruction !== "" ? set.instruction : null,
|
|
398
421
|
isTest: coerceInt(set.is_test) === 1,
|
|
399
|
-
exercises: exercises.filter(isRecord).map(presentExercise$1)
|
|
422
|
+
exercises: exercises.filter(isRecord).map((ex) => presentExercise$1(ex, performedById))
|
|
400
423
|
};
|
|
401
424
|
}
|
|
402
425
|
function str$1(v) {
|
|
403
426
|
return typeof v === "string" && v !== "" ? v : null;
|
|
404
427
|
}
|
|
405
|
-
/**
|
|
428
|
+
/** Every logged set (programmed + athlete-added) in the saved copy, paired with its exercises. */
|
|
429
|
+
function savedSets(saved) {
|
|
430
|
+
const out = [];
|
|
431
|
+
for (const key of ["workoutSets", "addedWorkoutSets"]) {
|
|
432
|
+
const sets = Array.isArray(saved[key]) ? saved[key] : [];
|
|
433
|
+
for (const set of sets) {
|
|
434
|
+
if (!isRecord(set)) continue;
|
|
435
|
+
const exercises = (Array.isArray(set.workoutSetExercises) ? set.workoutSetExercises : []).filter(isRecord);
|
|
436
|
+
out.push({
|
|
437
|
+
set,
|
|
438
|
+
exercises
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return out;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Map each prescription exercise id to the per-set values the athlete logged. In the saved
|
|
446
|
+
* copy, `workout_set_exercise_id` points back at the prescription exercise's `id`, and the
|
|
447
|
+
* entered values live in the same `param_N_data` slots as a prescription — so the
|
|
448
|
+
* prescription reader works on them unchanged.
|
|
449
|
+
*/
|
|
450
|
+
function performedByExerciseId(sets) {
|
|
451
|
+
const map = /* @__PURE__ */ new Map();
|
|
452
|
+
for (const { exercises } of sets) for (const ex of exercises) {
|
|
453
|
+
const id = coerceInt(ex.workout_set_exercise_id);
|
|
454
|
+
if (id === null) continue;
|
|
455
|
+
const values = performedSets(ex);
|
|
456
|
+
if (values.length > 0) map.set(id, values);
|
|
457
|
+
}
|
|
458
|
+
return map;
|
|
459
|
+
}
|
|
460
|
+
/** Present a logged set straight from the saved copy (athlete-added or personal work). */
|
|
461
|
+
function presentSavedBlock(set, exercises) {
|
|
462
|
+
return {
|
|
463
|
+
order: coerceInt(set.order) ?? 0,
|
|
464
|
+
title: typeof set.title === "string" && set.title !== "" ? set.title : null,
|
|
465
|
+
instruction: typeof set.instruction === "string" && set.instruction !== "" ? set.instruction : null,
|
|
466
|
+
isTest: coerceInt(set.is_test) === 1,
|
|
467
|
+
exercises: exercises.map((ex) => ({
|
|
468
|
+
exerciseId: coerceInt(ex.exercise_id),
|
|
469
|
+
title: typeof ex.exercise_title === "string" ? ex.exercise_title : "",
|
|
470
|
+
instruction: typeof ex.instruction === "string" && ex.instruction !== "" ? ex.instruction : null,
|
|
471
|
+
units: exerciseUnits(ex.param_1_type, ex.param_2_type),
|
|
472
|
+
prescribed: [],
|
|
473
|
+
performed: performedSets(ex)
|
|
474
|
+
}))
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Flatten one `/3.0/athlete/programworkout/range` item into a readable workout, merging the
|
|
479
|
+
* prescription (`summarizedSavedWorkout.workout`) with what the athlete logged
|
|
480
|
+
* (`summarizedSavedWorkout.saved_workout`). Each exercise carries both its `prescribed` and
|
|
481
|
+
* `performed` sets; athlete-added/personal work that has no prescription is appended as its
|
|
482
|
+
* own blocks. No `raw` is needed to see logged results.
|
|
483
|
+
*/
|
|
406
484
|
function presentAthleteWorkout(raw) {
|
|
407
485
|
const rec = raw;
|
|
408
486
|
const ssw = isRecord(rec.summarizedSavedWorkout) ? rec.summarizedSavedWorkout : {};
|
|
409
487
|
const workout = isRecord(ssw.workout) ? ssw.workout : {};
|
|
410
|
-
const
|
|
488
|
+
const saved = isRecord(ssw.saved_workout) ? ssw.saved_workout : {};
|
|
489
|
+
const prescriptionSets = (Array.isArray(workout.workoutSets) ? workout.workoutSets : []).filter(isRecord);
|
|
490
|
+
const logged = savedSets(saved);
|
|
491
|
+
const performedById = performedByExerciseId(logged);
|
|
492
|
+
const blocks = prescriptionSets.map((s) => presentBlock(s, performedById)).sort((a, b) => a.order - b.order);
|
|
493
|
+
const prescribedIds = /* @__PURE__ */ new Set();
|
|
494
|
+
for (const s of prescriptionSets) {
|
|
495
|
+
const exs = Array.isArray(s.workoutSetExercises) ? s.workoutSetExercises : [];
|
|
496
|
+
for (const ex of exs) {
|
|
497
|
+
if (!isRecord(ex)) continue;
|
|
498
|
+
const id = coerceInt(ex.id);
|
|
499
|
+
if (id !== null) prescribedIds.add(id);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
for (const { set, exercises } of logged) {
|
|
503
|
+
const extra = exercises.filter((ex) => {
|
|
504
|
+
if (performedSets(ex).length === 0) return false;
|
|
505
|
+
const id = coerceInt(ex.workout_set_exercise_id);
|
|
506
|
+
return id === null || !prescribedIds.has(id);
|
|
507
|
+
});
|
|
508
|
+
if (extra.length > 0) blocks.push(presentSavedBlock(set, extra));
|
|
509
|
+
}
|
|
411
510
|
return {
|
|
412
511
|
id: coerceInt(rec.id),
|
|
413
512
|
date: str$1(rec.date) ?? "",
|
|
@@ -415,12 +514,24 @@ function presentAthleteWorkout(raw) {
|
|
|
415
514
|
program: str$1(rec.program_title),
|
|
416
515
|
team: str$1(rec.team_title),
|
|
417
516
|
instruction: str$1(workout.instruction),
|
|
418
|
-
|
|
517
|
+
logged: blocks.some((b) => b.exercises.some((e) => e.performed.length > 0)),
|
|
518
|
+
blocks
|
|
419
519
|
};
|
|
420
520
|
}
|
|
421
521
|
function presentAthleteWorkouts(list) {
|
|
422
522
|
return list.map(presentAthleteWorkout);
|
|
423
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* Narrow a presented workout list for the common "what did I actually do" reads. `loggedOnly`
|
|
526
|
+
* keeps only workouts the athlete logged a set on (the reliable signal, not the API's
|
|
527
|
+
* completion flag). `limit` keeps the most recent N by date (newest first). Both are pure
|
|
528
|
+
* post-filters over the presented view; the raw API path is left untouched.
|
|
529
|
+
*/
|
|
530
|
+
function selectWorkouts(list, opts = {}) {
|
|
531
|
+
let out = opts.loggedOnly === true ? list.filter((w) => w.logged) : [...list];
|
|
532
|
+
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
|
+
return out;
|
|
534
|
+
}
|
|
424
535
|
const MAX_PARAM_SLOTS = 10;
|
|
425
536
|
/**
|
|
426
537
|
* Build the body for `PUT /1.0/athlete/savedworkoutsetexercise/{id}`. The body uses
|
|
@@ -1180,4 +1291,4 @@ var ExerciseLibrary = class {
|
|
|
1180
1291
|
}
|
|
1181
1292
|
};
|
|
1182
1293
|
//#endregion
|
|
1183
|
-
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, sendComment, setSessionInstruction, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/js",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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.
|
|
30
|
+
"@trainheroic-unofficial/dto": "0.6.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^26.0.0",
|