@trainheroic-unofficial/js 0.6.3 → 0.6.4
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 +16 -2
- package/dist/index.mjs +57 -1
- package/package.json +2 -2
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, 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, RosterActivityRow, WorkoutDate } from "@trainheroic-unofficial/dto";
|
|
3
3
|
import { ZodType } from "zod";
|
|
4
4
|
export * from "@trainheroic-unofficial/dto";
|
|
5
5
|
|
|
@@ -133,6 +133,20 @@ declare function resolveAthleteUserId(client: TrainHeroicClient): Promise<number
|
|
|
133
133
|
/** Lifetime training totals. `use_metric` is required by the API (omitting it 400s). */
|
|
134
134
|
declare function fetchAthleteProfileSummary(client: TrainHeroicClient, userId: number, useMetric?: boolean): Promise<AthleteProfileSummary>;
|
|
135
135
|
declare function fetchAthleteUser(client: TrainHeroicClient, userId: number): Promise<AthleteUser>;
|
|
136
|
+
/**
|
|
137
|
+
* Sort a roster-activity list most-recently-active first; never-logged rows (null date) last.
|
|
138
|
+
* Athletes tied on lastLoggedDate break by session count (more sessions first), so a tie is not
|
|
139
|
+
* left to arbitrary input order.
|
|
140
|
+
*/
|
|
141
|
+
declare function sortRosterByRecency(rows: readonly RosterActivityRow[]): RosterActivityRow[];
|
|
142
|
+
/**
|
|
143
|
+
* A coach's roster-activity ranking: each athlete's all-time training snapshot (session count,
|
|
144
|
+
* first/last logged date, total reps/volume), sorted most-recently-active first. There is no
|
|
145
|
+
* single roster-activity endpoint, so this fans out `/v5/athleteProfile/summary` per athlete with
|
|
146
|
+
* a small concurrency cap; pass the subset you care about for a large org. A failed or missing
|
|
147
|
+
* summary becomes a null-data row (sorted last), not an error.
|
|
148
|
+
*/
|
|
149
|
+
declare function fetchRosterActivity(client: TrainHeroicClient, athleteIds: readonly number[], useMetric?: boolean): Promise<RosterActivityRow[]>;
|
|
136
150
|
declare function fetchAthletePrefs(client: TrainHeroicClient): Promise<AthletePrefs>;
|
|
137
151
|
declare function fetchWorkingMaxes(client: TrainHeroicClient): Promise<AthleteWorkingMax[]>;
|
|
138
152
|
declare function fetchExerciseHistoryList(client: TrainHeroicClient): Promise<ExerciseHistoryListItem[]>;
|
|
@@ -386,4 +400,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
386
400
|
stats(): Promise<Record<string, unknown>>;
|
|
387
401
|
}
|
|
388
402
|
//#endregion
|
|
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 };
|
|
403
|
+
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, fetchRosterActivity, 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, sortRosterByRecency, summarizeAthleteWorkouts, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
package/dist/index.mjs
CHANGED
|
@@ -321,6 +321,62 @@ function fetchAthleteProfileSummary(client, userId, useMetric = false) {
|
|
|
321
321
|
function fetchAthleteUser(client, userId) {
|
|
322
322
|
return getJson(client, `/v5/users/${userId}`, "athlete user");
|
|
323
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* Sort a roster-activity list most-recently-active first; never-logged rows (null date) last.
|
|
326
|
+
* Athletes tied on lastLoggedDate break by session count (more sessions first), so a tie is not
|
|
327
|
+
* left to arbitrary input order.
|
|
328
|
+
*/
|
|
329
|
+
function sortRosterByRecency(rows) {
|
|
330
|
+
return [...rows].sort((a, b) => {
|
|
331
|
+
if (a.lastLoggedDate !== b.lastLoggedDate) {
|
|
332
|
+
if (a.lastLoggedDate === null) return 1;
|
|
333
|
+
if (b.lastLoggedDate === null) return -1;
|
|
334
|
+
return a.lastLoggedDate < b.lastLoggedDate ? 1 : -1;
|
|
335
|
+
}
|
|
336
|
+
return (b.sessionsCount ?? 0) - (a.sessionsCount ?? 0);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* A coach's roster-activity ranking: each athlete's all-time training snapshot (session count,
|
|
341
|
+
* first/last logged date, total reps/volume), sorted most-recently-active first. There is no
|
|
342
|
+
* single roster-activity endpoint, so this fans out `/v5/athleteProfile/summary` per athlete with
|
|
343
|
+
* a small concurrency cap; pass the subset you care about for a large org. A failed or missing
|
|
344
|
+
* summary becomes a null-data row (sorted last), not an error.
|
|
345
|
+
*/
|
|
346
|
+
async function fetchRosterActivity(client, athleteIds, useMetric = false) {
|
|
347
|
+
const rows = [];
|
|
348
|
+
const concurrency = 6;
|
|
349
|
+
for (let i = 0; i < athleteIds.length; i += concurrency) {
|
|
350
|
+
const chunk = athleteIds.slice(i, i + concurrency);
|
|
351
|
+
const settled = await Promise.all(chunk.map(async (id) => {
|
|
352
|
+
try {
|
|
353
|
+
return {
|
|
354
|
+
id,
|
|
355
|
+
summary: await fetchAthleteProfileSummary(client, id, useMetric)
|
|
356
|
+
};
|
|
357
|
+
} catch {
|
|
358
|
+
return {
|
|
359
|
+
id,
|
|
360
|
+
summary: null
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}));
|
|
364
|
+
for (const { id, summary } of settled) {
|
|
365
|
+
const count = summary?.sessions_count ?? null;
|
|
366
|
+
const hasSessions = count !== null && count > 0;
|
|
367
|
+
const normDate = (d) => hasSessions && d !== void 0 && d !== "" && !d.startsWith("1970") ? d : null;
|
|
368
|
+
rows.push({
|
|
369
|
+
athleteId: id,
|
|
370
|
+
sessionsCount: count,
|
|
371
|
+
firstLoggedDate: normDate(summary?.first_logged_date),
|
|
372
|
+
lastLoggedDate: normDate(summary?.last_logged_date),
|
|
373
|
+
totalReps: summary?.reps_sum ?? null,
|
|
374
|
+
totalVolume: summary?.volume_sum ?? null
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return sortRosterByRecency(rows);
|
|
379
|
+
}
|
|
324
380
|
function fetchAthletePrefs(client) {
|
|
325
381
|
return getJson(client, "/1.0/athlete/prefs", "athlete prefs");
|
|
326
382
|
}
|
|
@@ -1370,4 +1426,4 @@ var ExerciseLibrary = class {
|
|
|
1370
1426
|
}
|
|
1371
1427
|
};
|
|
1372
1428
|
//#endregion
|
|
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 };
|
|
1429
|
+
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, fetchRosterActivity, 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, sortRosterByRecency, 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.
|
|
3
|
+
"version": "0.6.4",
|
|
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.4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^26.0.0",
|