@trainheroic-unofficial/js 2.1.0 → 3.0.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/README.md +15 -0
- package/dist/index.d.mts +36 -12
- package/dist/index.mjs +61 -21
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -110,6 +110,21 @@ const client = new TrainHeroicClient(
|
|
|
110
110
|
If the reused token has expired, the next request gets a 401/403; the client logs in once with
|
|
111
111
|
the credentials, retries, and updates `client.sessionId` to the new token.
|
|
112
112
|
|
|
113
|
+
The optional fourth constructor argument can persist renewed sessions and report final HTTP
|
|
114
|
+
failures without coupling the SDK to a telemetry vendor:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const client = new TrainHeroicClient(email, password, savedSession, {
|
|
118
|
+
onSession: saveSession,
|
|
119
|
+
onHttpError: (error) => telemetry.captureException(error),
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`onHttpError` receives a `TrainHeroicHttpError` containing only the method, status, and host.
|
|
124
|
+
Paths, query strings, bodies, credentials, and session tokens are excluded. A transient 401/403
|
|
125
|
+
that succeeds after automatic re-login does not call the hook, and synchronous or asynchronous
|
|
126
|
+
hook failures never change the request result.
|
|
127
|
+
|
|
113
128
|
## Two entry points
|
|
114
129
|
|
|
115
130
|
```ts
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,21 @@ import { n as LibrarySnapshot, r as MemoryLibraryCache, t as LibraryCache } from
|
|
|
2
2
|
import { Advisory, AthletePrefs, AthleteProfileSummary, AthleteUser, AthleteWorkingMax, AthleteWorkoutSummary, AthleteWorkoutView, BlockSpec, CoachAthleteTraining, ExerciseHistoryDetail, ExerciseHistoryListItem, ExerciseRow, ExerciseSpec, ExerciseStats, ExerciseView, PersonalRecord, PresentedExerciseHistory, ProgramWorkout, ReadResult, ResolveResult, RosterActivityRow, TeamVolumeReport, WorkoutDate, WorkoutHistoryExport } from "@trainheroic-unofficial/dto";
|
|
3
3
|
import { ZodType } from "zod";
|
|
4
4
|
export * from "@trainheroic-unofficial/dto";
|
|
5
|
+
//#region src/http-error.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A final non-2xx response from TrainHeroic. The error deliberately carries only request
|
|
8
|
+
* metadata that is safe to send to telemetry: never the path, query string, request body,
|
|
9
|
+
* response body, credentials, or session token.
|
|
10
|
+
*/
|
|
11
|
+
declare class TrainHeroicHttpError extends Error {
|
|
12
|
+
readonly name = "TrainHeroicHttpError";
|
|
13
|
+
readonly method: string;
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly host: string;
|
|
16
|
+
constructor(method: string, url: string, status: number);
|
|
17
|
+
}
|
|
18
|
+
type TrainHeroicHttpErrorHandler = (error: TrainHeroicHttpError) => void | PromiseLike<void>;
|
|
19
|
+
//#endregion
|
|
5
20
|
//#region src/auth.d.ts
|
|
6
21
|
type TrainHeroicSession = {
|
|
7
22
|
thUserId: number;
|
|
@@ -9,13 +24,17 @@ type TrainHeroicSession = {
|
|
|
9
24
|
scope: string;
|
|
10
25
|
role: string;
|
|
11
26
|
};
|
|
27
|
+
type LoginOptions = {
|
|
28
|
+
/** Called for every non-2xx login response; callback failures never change the result. */
|
|
29
|
+
onHttpError?: TrainHeroicHttpErrorHandler;
|
|
30
|
+
};
|
|
12
31
|
/**
|
|
13
32
|
* Authenticate against TrainHeroic. Returns the session bundle, or null on bad
|
|
14
33
|
* credentials. TrainHeroic returns only { id, scope, role, session_id } (verified in
|
|
15
34
|
* the Phase 0 spike: no refresh_token, no api_token, no TTL). The 48-char session_id
|
|
16
35
|
* is sent as the `session-token` header and works against both API hosts.
|
|
17
36
|
*/
|
|
18
|
-
declare function loginTrainHeroic(email: string, password: string): Promise<TrainHeroicSession | null>;
|
|
37
|
+
declare function loginTrainHeroic(email: string, password: string, options?: LoginOptions): Promise<TrainHeroicSession | null>;
|
|
19
38
|
//#endregion
|
|
20
39
|
//#region src/client.d.ts
|
|
21
40
|
declare class TrainHeroicAuthError extends Error {
|
|
@@ -39,6 +58,12 @@ type ClientOptions = {
|
|
|
39
58
|
* instead of logging in again.
|
|
40
59
|
*/
|
|
41
60
|
onSession?: (sessionId: string) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Called once when a login or API request finishes with a non-2xx response. Transient 401/403
|
|
63
|
+
* API responses that succeed after the built-in re-login are not reported. The callback is
|
|
64
|
+
* best-effort: telemetry failures never change the API result returned to the caller.
|
|
65
|
+
*/
|
|
66
|
+
onHttpError?: TrainHeroicHttpErrorHandler;
|
|
42
67
|
};
|
|
43
68
|
/**
|
|
44
69
|
* Authenticated TrainHeroic API client. Holds the credentials (on the hosted Worker, from the
|
|
@@ -138,16 +163,17 @@ declare function mapPool<T, R>(items: readonly T[], limit: number, fn: (item: T,
|
|
|
138
163
|
* The exercise-library surface the tools depend on, so the tools work over either a
|
|
139
164
|
* D1-backed mirror (hosted, multi-tenant) or an in-memory cache (local, single-user).
|
|
140
165
|
*/
|
|
166
|
+
type ExerciseDefaults = {
|
|
167
|
+
param1: number | null;
|
|
168
|
+
param2: number | null;
|
|
169
|
+
};
|
|
141
170
|
interface ExerciseIndex {
|
|
142
171
|
ensureFresh(): Promise<void>;
|
|
143
172
|
refresh(): Promise<Record<string, unknown>>;
|
|
144
173
|
resolve(name: string): Promise<ResolveResult>;
|
|
145
174
|
search(query: string, limit?: number): Promise<ExerciseView[]>;
|
|
146
175
|
get(id: number): Promise<Record<string, unknown> | null>;
|
|
147
|
-
|
|
148
|
-
param1: number | null;
|
|
149
|
-
param2: number | null;
|
|
150
|
-
} | null>;
|
|
176
|
+
defaultsMany(ids: readonly number[]): Promise<Map<number, ExerciseDefaults>>;
|
|
151
177
|
create(body: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
152
178
|
recordDelete(id: number): Promise<void>;
|
|
153
179
|
stats(): Promise<Record<string, unknown>>;
|
|
@@ -853,6 +879,7 @@ declare function teamVolume(client: TrainHeroicClient, args: {
|
|
|
853
879
|
declare function definedProps<T extends object>(obj: T): { [K in keyof T]: Exclude<T[K], undefined>; };
|
|
854
880
|
//#endregion
|
|
855
881
|
//#region src/workout-encode.d.ts
|
|
882
|
+
type AdvisoryIndex = Pick<ExerciseIndex, "defaultsMany" | "ensureFresh">;
|
|
856
883
|
declare const LEADERBOARD_TYPE: Readonly<Record<string, number>>;
|
|
857
884
|
declare const LEADERBOARD_LABEL: Readonly<Record<number, string>>;
|
|
858
885
|
type Leaderboard = {
|
|
@@ -882,10 +909,10 @@ declare function unitAdvisory(blockTitle: string, ex: ExerciseSpec, defaults: {
|
|
|
882
909
|
/**
|
|
883
910
|
* Run unit advisories across a whole block list against an exercise index. Shared by the
|
|
884
911
|
* MCP workout_build tool and the CLI so both surface the same notes/warnings. Ensures the
|
|
885
|
-
* index is loaded first, otherwise
|
|
912
|
+
* index is loaded first, otherwise the defaults map is empty on a cold index and every
|
|
886
913
|
* advisory is silently dropped.
|
|
887
914
|
*/
|
|
888
|
-
declare function collectAdvisories(blocks: readonly BlockSpec[], index:
|
|
915
|
+
declare function collectAdvisories(blocks: readonly BlockSpec[], index: AdvisoryIndex): Promise<Advisory>;
|
|
889
916
|
//#endregion
|
|
890
917
|
//#region src/workout-session.d.ts
|
|
891
918
|
type BuildOptions = {
|
|
@@ -945,10 +972,7 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
945
972
|
ensureFresh(): Promise<void>;
|
|
946
973
|
refresh(): Promise<Record<string, unknown>>;
|
|
947
974
|
get(id: number): Promise<Record<string, unknown> | null>;
|
|
948
|
-
|
|
949
|
-
param1: number | null;
|
|
950
|
-
param2: number | null;
|
|
951
|
-
} | null>;
|
|
975
|
+
defaultsMany(ids: readonly number[]): Promise<Map<number, ExerciseDefaults>>;
|
|
952
976
|
search(query: string, limit?: number): Promise<ExerciseView[]>;
|
|
953
977
|
resolve(name: string): Promise<ResolveResult>;
|
|
954
978
|
create(body: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
@@ -956,4 +980,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
956
980
|
stats(): Promise<Record<string, unknown>>;
|
|
957
981
|
}
|
|
958
982
|
//#endregion
|
|
959
|
-
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, BuildOptions, ClientOptions, ClientResult, CoachAthleteCalendar, CoachRosterAthlete, DEFAULT_INVITE_MESSAGE, ExerciseIndex, ExerciseLibrary, type ExerciseSetInput, type ExerciseSetPayload, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MainLiftFamily, MainLiftFamilyKey, MainLiftPR, MainLiftResolution, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PersonalWorkoutCreated, RequestOptions, ResolvedLift, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, type SetWriteMode, SwapExerciseResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, WorkoutExportFormat, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, dateWindows, defaultBlockType, definedProps, deleteComment, exerciseTitle, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, 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, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
|
983
|
+
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BLOCK_TYPE_CONDITIONING, BLOCK_TYPE_HYPERTROPHY, BuildOptions, ClientOptions, ClientResult, CoachAthleteCalendar, CoachRosterAthlete, DEFAULT_INVITE_MESSAGE, 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, PersonalWorkoutCreated, RequestOptions, ResolvedLift, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, type SetWriteMode, SwapExerciseResult, 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, dateWindows, defaultBlockType, definedProps, deleteComment, exerciseTitle, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, 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, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { blockSpecSchema, exerciseLibraryResponseSchema, exerciseResponseSchema, parseWorkoutDate, programsEditResponseSchema, sessionCreateResponseSchema } from "@trainheroic-unofficial/dto";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
export * from "@trainheroic-unofficial/dto";
|
|
4
|
+
//#region src/http-error.ts
|
|
5
|
+
/**
|
|
6
|
+
* A final non-2xx response from TrainHeroic. The error deliberately carries only request
|
|
7
|
+
* metadata that is safe to send to telemetry: never the path, query string, request body,
|
|
8
|
+
* response body, credentials, or session token.
|
|
9
|
+
*/
|
|
10
|
+
var TrainHeroicHttpError = class extends Error {
|
|
11
|
+
name = "TrainHeroicHttpError";
|
|
12
|
+
method;
|
|
13
|
+
status;
|
|
14
|
+
host;
|
|
15
|
+
constructor(method, url, status) {
|
|
16
|
+
const parsed = new URL(url);
|
|
17
|
+
const normalizedMethod = method.toUpperCase();
|
|
18
|
+
super(`TrainHeroic ${normalizedMethod} request failed with HTTP ${status}`);
|
|
19
|
+
this.method = normalizedMethod;
|
|
20
|
+
this.status = status;
|
|
21
|
+
this.host = parsed.host;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/** Call observability hooks without allowing them to change SDK behavior. */
|
|
25
|
+
function notifyHttpError(handler, method, url, status) {
|
|
26
|
+
if (!handler) return;
|
|
27
|
+
try {
|
|
28
|
+
Promise.resolve(handler(new TrainHeroicHttpError(method, url, status))).catch(() => {});
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
4
32
|
//#region src/auth.ts
|
|
5
33
|
const DEFAULT_AUTH_URL = "https://apis.trainheroic.com/auth";
|
|
6
34
|
/**
|
|
@@ -22,8 +50,9 @@ function authUrl() {
|
|
|
22
50
|
* the Phase 0 spike: no refresh_token, no api_token, no TTL). The 48-char session_id
|
|
23
51
|
* is sent as the `session-token` header and works against both API hosts.
|
|
24
52
|
*/
|
|
25
|
-
async function loginTrainHeroic(email, password) {
|
|
26
|
-
const
|
|
53
|
+
async function loginTrainHeroic(email, password, options = {}) {
|
|
54
|
+
const url = authUrl();
|
|
55
|
+
const res = await fetch(url, {
|
|
27
56
|
method: "POST",
|
|
28
57
|
headers: {
|
|
29
58
|
"content-type": "application/x-www-form-urlencoded",
|
|
@@ -34,7 +63,10 @@ async function loginTrainHeroic(email, password) {
|
|
|
34
63
|
password
|
|
35
64
|
}).toString()
|
|
36
65
|
});
|
|
37
|
-
if (!res.ok)
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
notifyHttpError(options.onHttpError, "POST", url, res.status);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
38
70
|
const data = await res.json().catch(() => null);
|
|
39
71
|
if (!data || typeof data.id !== "number" || !data.session_id) return null;
|
|
40
72
|
return {
|
|
@@ -77,6 +109,7 @@ var TrainHeroicClient = class {
|
|
|
77
109
|
#email;
|
|
78
110
|
#password;
|
|
79
111
|
#onSession;
|
|
112
|
+
#onHttpError;
|
|
80
113
|
#sessionId;
|
|
81
114
|
#loginInFlight = null;
|
|
82
115
|
constructor(email, password, sessionId = null, options = {}) {
|
|
@@ -84,6 +117,7 @@ var TrainHeroicClient = class {
|
|
|
84
117
|
this.#password = password;
|
|
85
118
|
this.#sessionId = sessionId;
|
|
86
119
|
this.#onSession = options.onSession;
|
|
120
|
+
this.#onHttpError = options.onHttpError;
|
|
87
121
|
}
|
|
88
122
|
get sessionId() {
|
|
89
123
|
return this.#sessionId;
|
|
@@ -98,7 +132,7 @@ var TrainHeroicClient = class {
|
|
|
98
132
|
}
|
|
99
133
|
}
|
|
100
134
|
async #login() {
|
|
101
|
-
const session = await loginTrainHeroic(this.#email, this.#password);
|
|
135
|
+
const session = await loginTrainHeroic(this.#email, this.#password, this.#onHttpError ? { onHttpError: this.#onHttpError } : {});
|
|
102
136
|
if (!session) throw new TrainHeroicAuthError("TrainHeroic login failed");
|
|
103
137
|
this.#sessionId = session.sessionId;
|
|
104
138
|
try {
|
|
@@ -115,6 +149,7 @@ var TrainHeroicClient = class {
|
|
|
115
149
|
session = await this.#ensureSession();
|
|
116
150
|
res = await this.#send(method, url, session, options.body);
|
|
117
151
|
}
|
|
152
|
+
if (!res.ok) notifyHttpError(this.#onHttpError, method, url, res.status);
|
|
118
153
|
const text = await res.text();
|
|
119
154
|
let data = text;
|
|
120
155
|
if (text.length > 0) try {
|
|
@@ -2006,8 +2041,10 @@ function unitAdvisory(blockTitle, ex, defaults) {
|
|
|
2006
2041
|
if (ex.weight !== void 0 && ex.weight !== null) {
|
|
2007
2042
|
const sentP2 = Math.trunc(Number(ex.param_2_type ?? 1));
|
|
2008
2043
|
const effP2 = defaults.param2 === 0 || defaults.param2 === null ? 1 : defaults.param2;
|
|
2009
|
-
if (sentP2 !== effP2)
|
|
2010
|
-
|
|
2044
|
+
if (sentP2 !== effP2) {
|
|
2045
|
+
if (sentP2 === 2 || sentP2 === 14) warnings.push(`${label}: ${u(sentP2)} does not stick on this exercise — it renders as ${u(effP2)}. Put it in the exercise 'instr' text and leave load blank.`);
|
|
2046
|
+
else warnings.push(`${label}: load renders as ${u(effP2)}, not ${u(sentP2)} (this exercise's secondary unit is fixed).`);
|
|
2047
|
+
}
|
|
2011
2048
|
}
|
|
2012
2049
|
return {
|
|
2013
2050
|
notes,
|
|
@@ -2017,7 +2054,7 @@ function unitAdvisory(blockTitle, ex, defaults) {
|
|
|
2017
2054
|
/**
|
|
2018
2055
|
* Run unit advisories across a whole block list against an exercise index. Shared by the
|
|
2019
2056
|
* MCP workout_build tool and the CLI so both surface the same notes/warnings. Ensures the
|
|
2020
|
-
* index is loaded first, otherwise
|
|
2057
|
+
* index is loaded first, otherwise the defaults map is empty on a cold index and every
|
|
2021
2058
|
* advisory is silently dropped.
|
|
2022
2059
|
*/
|
|
2023
2060
|
async function collectAdvisories(blocks, index) {
|
|
@@ -2026,14 +2063,12 @@ async function collectAdvisories(blocks, index) {
|
|
|
2026
2063
|
block: b,
|
|
2027
2064
|
ex
|
|
2028
2065
|
})));
|
|
2029
|
-
const
|
|
2030
|
-
|
|
2031
|
-
return Number.isFinite(id) ? index.defaults(id) : Promise.resolve(null);
|
|
2032
|
-
}));
|
|
2066
|
+
const ids = [...new Set(pairs.map((p) => Number(p.ex.id)).filter((id) => Number.isFinite(id)))];
|
|
2067
|
+
const defaultsById = await index.defaultsMany(ids);
|
|
2033
2068
|
const notes = [];
|
|
2034
2069
|
const warnings = [];
|
|
2035
|
-
pairs.forEach((p
|
|
2036
|
-
const def =
|
|
2070
|
+
pairs.forEach((p) => {
|
|
2071
|
+
const def = defaultsById.get(Number(p.ex.id));
|
|
2037
2072
|
if (!def) return;
|
|
2038
2073
|
const advisory = unitAdvisory(p.block.title, p.ex, def);
|
|
2039
2074
|
notes.push(...advisory.notes);
|
|
@@ -2293,7 +2328,8 @@ async function copySession(client, args) {
|
|
|
2293
2328
|
year,
|
|
2294
2329
|
dayOfWeek,
|
|
2295
2330
|
isToday: false
|
|
2296
|
-
}
|
|
2331
|
+
},
|
|
2332
|
+
toTimelineDate: null
|
|
2297
2333
|
} });
|
|
2298
2334
|
if (!res.ok) {
|
|
2299
2335
|
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
@@ -2901,12 +2937,16 @@ var ExerciseLibrary = class {
|
|
|
2901
2937
|
if (!s) return null;
|
|
2902
2938
|
return presentExercise(s.raw);
|
|
2903
2939
|
}
|
|
2904
|
-
async
|
|
2905
|
-
const
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2940
|
+
async defaultsMany(ids) {
|
|
2941
|
+
const result = /* @__PURE__ */ new Map();
|
|
2942
|
+
for (const id of ids) {
|
|
2943
|
+
const s = this.#byId.get(id);
|
|
2944
|
+
if (s) result.set(id, {
|
|
2945
|
+
param1: s.param_1_type,
|
|
2946
|
+
param2: s.param_2_type
|
|
2947
|
+
});
|
|
2948
|
+
}
|
|
2949
|
+
return result;
|
|
2910
2950
|
}
|
|
2911
2951
|
async search(query, limit = 20) {
|
|
2912
2952
|
await this.ensureFresh();
|
|
@@ -2979,4 +3019,4 @@ var ExerciseLibrary = class {
|
|
|
2979
3019
|
}
|
|
2980
3020
|
};
|
|
2981
3021
|
//#endregion
|
|
2982
|
-
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, TrainHeroicAuthError, TrainHeroicClient, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, dateWindows, defaultBlockType, definedProps, deleteComment, exerciseTitle, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, 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, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
|
3022
|
+
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, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicHttpError, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, calendarWriteError, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, dateWindows, defaultBlockType, definedProps, deleteComment, exerciseTitle, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendar, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, 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, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, updateTeam, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"zod": "^4.4.3",
|
|
30
|
-
"@trainheroic-unofficial/dto": "
|
|
30
|
+
"@trainheroic-unofficial/dto": "3.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^26.
|
|
33
|
+
"@types/node": "^26.2.0",
|
|
34
34
|
"tsdown": "^0.22.14",
|
|
35
35
|
"vitest": "^4.1.10"
|
|
36
36
|
},
|