@trainheroic-unofficial/js 1.3.0 → 1.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 +51 -10
- package/dist/index.mjs +211 -81
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -66,6 +66,9 @@ declare const PARAM_WEIGHT = 1;
|
|
|
66
66
|
declare const PARAM_PCT_MAX = 2;
|
|
67
67
|
declare const PARAM_REPS = 3;
|
|
68
68
|
declare const PARAM_RPE = 14;
|
|
69
|
+
/** TrainHeroic stores up to 10 sets per exercise as `param_N_data_1..10`. One source of truth for
|
|
70
|
+
* the bound, shared by the workout presenters and the set-logging write path. */
|
|
71
|
+
declare const MAX_PARAM_SLOTS = 10;
|
|
69
72
|
declare function coerceInt(value: unknown): number | null;
|
|
70
73
|
declare function coerceNum(value: unknown): number | null;
|
|
71
74
|
declare function unitLabel(paramType: unknown): string | null;
|
|
@@ -88,6 +91,8 @@ declare function unwrapEnvelope(body: unknown): unknown;
|
|
|
88
91
|
/** Pull the exercise array out of whatever shape the bulk endpoint returns. */
|
|
89
92
|
declare function asExerciseList(body: unknown): Array<Record<string, unknown>>;
|
|
90
93
|
declare function isRecord(x: unknown): x is Record<string, unknown>;
|
|
94
|
+
/** A non-empty string, or null. Narrows a loosely-typed API field to a usable string. */
|
|
95
|
+
declare function str(v: unknown): string | null;
|
|
91
96
|
/**
|
|
92
97
|
* Rank candidate rows for a free-text query (FTS5 replacement). Higher is better:
|
|
93
98
|
* exact title, then prefix, then count of matched tokens, with shorter titles and
|
|
@@ -189,7 +194,11 @@ declare function presentAthleteWorkouts(list: readonly ProgramWorkout[]): Athlet
|
|
|
189
194
|
/** The minimal id scaffold `log-set` / `logForAthlete` needs for one saved workout set. */
|
|
190
195
|
type LogSetTarget = {
|
|
191
196
|
date: string;
|
|
192
|
-
workoutTitle: string; /** The
|
|
197
|
+
workoutTitle: string; /** The program this saved workout belongs to — lets a caller pick the right one of several. */
|
|
198
|
+
program: string | null;
|
|
199
|
+
programId: number | null;
|
|
200
|
+
team: string | null;
|
|
201
|
+
teamId: number | null; /** The id for `--set` (logAthleteSet/logForAthlete `savedWorkoutSetId`). */
|
|
193
202
|
savedWorkoutSetId: number;
|
|
194
203
|
setTitle: string | null;
|
|
195
204
|
exercises: Array<{
|
|
@@ -200,13 +209,27 @@ type LogSetTarget = {
|
|
|
200
209
|
performed: string[];
|
|
201
210
|
}>;
|
|
202
211
|
};
|
|
212
|
+
/**
|
|
213
|
+
* Narrow a coach-athlete workout range to a single program or team. The range endpoint returns
|
|
214
|
+
* every program the athlete is enrolled in on a date; for a high-enrollment athlete that is many
|
|
215
|
+
* workouts, so a caller wanting one program's session narrows it here. Match by `programId`/`teamId`
|
|
216
|
+
* (exact, on the raw `program_id`/`team_id`) or by `programTitle` (case-insensitive substring on the
|
|
217
|
+
* `program_title`/`team_title`) — the title match lets a caller target a program by name without
|
|
218
|
+
* first resolving its id. Any one match keeps the workout; with no filter the list is unchanged.
|
|
219
|
+
*/
|
|
220
|
+
declare function selectWorkoutsByProgram(list: readonly ProgramWorkout[], filter: {
|
|
221
|
+
programId?: number;
|
|
222
|
+
teamId?: number;
|
|
223
|
+
programTitle?: string;
|
|
224
|
+
}): ProgramWorkout[];
|
|
203
225
|
/**
|
|
204
226
|
* Project a workout range to just the ids a set-log write needs, read from the SAME saved-copy
|
|
205
227
|
* location {@link findSavedWorkoutSet} matches against (`summarizedSavedWorkout.saved_workout`).
|
|
206
228
|
* This is the self-service path for logging: instead of grepping the multi-KB `--raw` blob for
|
|
207
229
|
* which of several id fields maps to `--set`, callers read `savedWorkoutSetId` and each
|
|
208
|
-
* `savedWorkoutSetExerciseId` straight off these rows.
|
|
209
|
-
*
|
|
230
|
+
* `savedWorkoutSetExerciseId` straight off these rows. Each target also carries its program/team
|
|
231
|
+
* so a caller can pick the right session when the athlete is on several. One row per saved set,
|
|
232
|
+
* dropping any set with no resolvable id.
|
|
210
233
|
*/
|
|
211
234
|
declare function presentLogTargets(list: readonly ProgramWorkout[]): LogSetTarget[];
|
|
212
235
|
/**
|
|
@@ -234,16 +257,22 @@ declare function summarizeAthleteWorkouts(list: readonly AthleteWorkoutView[]):
|
|
|
234
257
|
* specific lift's PRs.
|
|
235
258
|
*/
|
|
236
259
|
declare function presentCoachAthleteTraining(raw: readonly unknown[], athleteId: number, year: number, month: number): CoachAthleteTraining;
|
|
260
|
+
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
261
|
+
declare function presentExerciseHistory(detail: ExerciseHistoryDetail): PresentedExerciseHistory;
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/athlete-set-write.d.ts
|
|
237
264
|
/**
|
|
238
265
|
* One set of entered values for a single exercise within a saved workout set.
|
|
239
266
|
* `param1` and `param2` correspond to the exercise's first and second parameter types
|
|
240
|
-
* (e.g. reps and weight).
|
|
267
|
+
* (e.g. reps and weight). Optional `slot` is the 1-based prescribed position this set fills;
|
|
268
|
+
* omit it and the sets fill positions sequentially from the first. At most 10 sets are supported.
|
|
241
269
|
*/
|
|
242
270
|
type SetResult = {
|
|
243
271
|
savedWorkoutSetExerciseId: number;
|
|
244
272
|
sets: Array<{
|
|
245
273
|
param1?: number | string;
|
|
246
274
|
param2?: number | string;
|
|
275
|
+
slot?: number;
|
|
247
276
|
}>;
|
|
248
277
|
};
|
|
249
278
|
/**
|
|
@@ -264,6 +293,7 @@ declare function toSetResults(results: ReadonlyArray<{
|
|
|
264
293
|
sets: ReadonlyArray<{
|
|
265
294
|
param1?: number | string | undefined;
|
|
266
295
|
param2?: number | string | undefined;
|
|
296
|
+
slot?: number | undefined;
|
|
267
297
|
}>;
|
|
268
298
|
}>): SetResult[];
|
|
269
299
|
/**
|
|
@@ -273,20 +303,31 @@ declare function toSetResults(results: ReadonlyArray<{
|
|
|
273
303
|
*
|
|
274
304
|
* `mode` selects which write this is — the same endpoint serves both:
|
|
275
305
|
* - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has data
|
|
276
|
-
* and the exercise `completed` flag is 1 when any set has data.
|
|
306
|
+
* and the exercise `completed` flag is 1 when any set has logged data.
|
|
277
307
|
* - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
|
|
278
308
|
* `completed` left at 0 so the set is not marked done. This matches what the app sends when a
|
|
279
309
|
* coach edits an athlete's prescribed reps/weight.
|
|
280
310
|
*
|
|
311
|
+
* Each set fills a 1-based slot: its explicit `slot`, or its sequential position in `results`
|
|
312
|
+
* when `slot` is omitted. A `log` carrying the live exercise record in `existing` keeps the slots
|
|
313
|
+
* it does not write that were ALREADY performed (`param_N_made === 1`), so logging a second part of
|
|
314
|
+
* a set does not wipe the earlier-logged sets. A slot holding only un-logged prescription pre-fill
|
|
315
|
+
* (`param_N_made === 0`) is left blank rather than carried over: marking the set completed makes
|
|
316
|
+
* the server flag every data-bearing slot performed, so preserving that pre-fill would fabricate
|
|
317
|
+
* sets the athlete never did. The prescription is unaffected (it lives in the separate `workout`
|
|
318
|
+
* copy, not this saved copy). A `prescribe` ignores `existing` and replaces the whole prescription.
|
|
319
|
+
*
|
|
281
320
|
* Only `savedWorkoutSetExerciseId`, `savedWorkoutSetId`, and `workoutSetExerciseId` are
|
|
282
|
-
* required from the live exercise record; everything else is derived from `results
|
|
321
|
+
* required from the live exercise record; everything else is derived from `results` and the
|
|
322
|
+
* preserved slots of `existing`.
|
|
283
323
|
*
|
|
284
324
|
* Exported for unit testing — callers should use `logAthleteSet` / `prescribeForAthlete` instead.
|
|
285
325
|
*/
|
|
286
326
|
declare function buildExerciseSetPayload(savedWorkoutSetExerciseId: number, savedWorkoutSetId: number, workoutSetExerciseId: number, results: readonly {
|
|
287
327
|
param1?: number | string;
|
|
288
328
|
param2?: number | string;
|
|
289
|
-
|
|
329
|
+
slot?: number;
|
|
330
|
+
}[], mode: SetWriteMode, existing?: Record<string, unknown>): Record<string, unknown>;
|
|
290
331
|
/**
|
|
291
332
|
* Locate the target saved workout set across all program workouts on the given day.
|
|
292
333
|
* Returns the `savedWorkoutId`, the matching set's `workoutSetExercises` array so callers
|
|
@@ -338,6 +379,7 @@ declare function logAthleteSet(client: TrainHeroicClient, args: {
|
|
|
338
379
|
}): Promise<{
|
|
339
380
|
savedWorkoutSetId: number;
|
|
340
381
|
exercisesLogged: number;
|
|
382
|
+
setCompleted: boolean;
|
|
341
383
|
}>;
|
|
342
384
|
/**
|
|
343
385
|
* Coach "Log for Athlete": record set results for a roster athlete on their behalf, via the
|
|
@@ -357,6 +399,7 @@ declare function logForAthlete(client: TrainHeroicClient, args: {
|
|
|
357
399
|
}): Promise<{
|
|
358
400
|
savedWorkoutSetId: number;
|
|
359
401
|
exercisesLogged: number;
|
|
402
|
+
setCompleted: boolean;
|
|
360
403
|
}>;
|
|
361
404
|
/**
|
|
362
405
|
* Coach prescription override: set the prescribed reps/weight for one of a roster athlete's saved
|
|
@@ -480,8 +523,6 @@ declare function logSessionForAthlete(client: TrainHeroicClient, args: {
|
|
|
480
523
|
date: string;
|
|
481
524
|
exercises: readonly SessionExercise[];
|
|
482
525
|
}): Promise<LogSessionResult>;
|
|
483
|
-
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
484
|
-
declare function presentExerciseHistory(detail: ExerciseHistoryDetail): PresentedExerciseHistory;
|
|
485
526
|
//#endregion
|
|
486
527
|
//#region src/main-lifts.d.ts
|
|
487
528
|
type MainLiftFamilyKey = "cleanjerk" | "snatch" | "deadlift" | "squat" | "bench" | "overhead";
|
|
@@ -757,4 +798,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
|
|
|
757
798
|
stats(): Promise<Record<string, unknown>>;
|
|
758
799
|
}
|
|
759
800
|
//#endregion
|
|
760
|
-
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BuildOptions, ClientResult, CoachRosterAthlete, DEFAULT_INVITE_MESSAGE, ExerciseIndex, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, MAIN_LIFT_FAMILIES, MainLiftFamily, MainLiftFamilyKey, MainLiftPR, MainLiftResolution, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PersonalWorkoutCreated, RequestOptions, ResolvedLift, SessionExercise, SetResult, SetWriteMode, SwapExerciseResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkouts, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, sortRosterByRecency, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
|
801
|
+
export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BuildOptions, ClientResult, CoachRosterAthlete, DEFAULT_INVITE_MESSAGE, ExerciseIndex, ExerciseLibrary, 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, SessionExercise, SetResult, SetWriteMode, SwapExerciseResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkouts, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { exerciseLibraryResponseSchema, exerciseResponseSchema, parseWorkoutDate, programsEditResponseSchema, sessionCreateResponseSchema } from "@trainheroic-unofficial/dto";
|
|
2
2
|
export * from "@trainheroic-unofficial/dto";
|
|
3
3
|
//#region src/auth.ts
|
|
4
|
-
const
|
|
4
|
+
const DEFAULT_AUTH_URL = "https://apis.trainheroic.com/auth";
|
|
5
|
+
/**
|
|
6
|
+
* The login endpoint, allowing an env override so a test harness can authenticate against a local
|
|
7
|
+
* fake backend. Precedence: an explicit `TH_AUTH_URL`, else `${TH_APIS_BASE}/auth` (login lives on
|
|
8
|
+
* the apis host, so it follows that base), else the real endpoint. Read via `globalThis.process`
|
|
9
|
+
* (no `import process`) to keep this module workerd-safe, and per call so a child-env override wins.
|
|
10
|
+
*/
|
|
11
|
+
function authUrl() {
|
|
12
|
+
const env = globalThis.process?.env;
|
|
13
|
+
if (env?.TH_AUTH_URL && env.TH_AUTH_URL.length > 0) return env.TH_AUTH_URL;
|
|
14
|
+
const apis = env?.TH_APIS_BASE;
|
|
15
|
+
if (apis && apis.length > 0) return `${apis.replace(/\/$/, "")}/auth`;
|
|
16
|
+
return DEFAULT_AUTH_URL;
|
|
17
|
+
}
|
|
5
18
|
/**
|
|
6
19
|
* Authenticate against TrainHeroic. Returns the session bundle, or null on bad
|
|
7
20
|
* credentials. TrainHeroic returns only { id, scope, role, session_id } (verified in
|
|
@@ -9,7 +22,7 @@ const AUTH_URL = "https://apis.trainheroic.com/auth";
|
|
|
9
22
|
* is sent as the `session-token` header and works against both API hosts.
|
|
10
23
|
*/
|
|
11
24
|
async function loginTrainHeroic(email, password) {
|
|
12
|
-
const res = await fetch(
|
|
25
|
+
const res = await fetch(authUrl(), {
|
|
13
26
|
method: "POST",
|
|
14
27
|
headers: {
|
|
15
28
|
"content-type": "application/x-www-form-urlencoded",
|
|
@@ -32,8 +45,19 @@ async function loginTrainHeroic(email, password) {
|
|
|
32
45
|
}
|
|
33
46
|
//#endregion
|
|
34
47
|
//#region src/client.ts
|
|
35
|
-
const
|
|
36
|
-
const
|
|
48
|
+
const DEFAULT_COACH_BASE = "https://api.trainheroic.com";
|
|
49
|
+
const DEFAULT_APIS_BASE = "https://apis.trainheroic.com";
|
|
50
|
+
/**
|
|
51
|
+
* Resolve an API host, allowing an env override. The override exists so a test harness can point
|
|
52
|
+
* the client at a local fake backend (and it doubles as a staging knob); production leaves these
|
|
53
|
+
* unset and gets the real hosts. Read through `globalThis.process?.env` — not an `import process`
|
|
54
|
+
* — so the runtime-agnostic `.` entry stays free of `node:*` and runs unchanged on workerd, and
|
|
55
|
+
* read per request (not at module load) so a value the harness sets in the child env always wins.
|
|
56
|
+
*/
|
|
57
|
+
function envBase(key, fallback) {
|
|
58
|
+
const v = (globalThis.process?.env)?.[key];
|
|
59
|
+
return v && v.length > 0 ? v : fallback;
|
|
60
|
+
}
|
|
37
61
|
var TrainHeroicAuthError = class extends Error {
|
|
38
62
|
name = "TrainHeroicAuthError";
|
|
39
63
|
};
|
|
@@ -72,7 +96,7 @@ var TrainHeroicClient = class {
|
|
|
72
96
|
return this.#sessionId;
|
|
73
97
|
}
|
|
74
98
|
async request(method, path, options = {}) {
|
|
75
|
-
const url = `${options.base === "apis" ?
|
|
99
|
+
const url = `${options.base === "apis" ? envBase("TH_APIS_BASE", DEFAULT_APIS_BASE) : envBase("TH_COACH_BASE", DEFAULT_COACH_BASE)}/${path.replace(/^\//, "")}`;
|
|
76
100
|
let session = await this.#ensureSession();
|
|
77
101
|
let res = await this.#send(method, url, session, options.body);
|
|
78
102
|
if (res.status === 401 || res.status === 403) {
|
|
@@ -153,6 +177,9 @@ const PARAM_WEIGHT = 1;
|
|
|
153
177
|
const PARAM_PCT_MAX = 2;
|
|
154
178
|
const PARAM_REPS = 3;
|
|
155
179
|
const PARAM_RPE = 14;
|
|
180
|
+
/** TrainHeroic stores up to 10 sets per exercise as `param_N_data_1..10`. One source of truth for
|
|
181
|
+
* the bound, shared by the workout presenters and the set-logging write path. */
|
|
182
|
+
const MAX_PARAM_SLOTS = 10;
|
|
156
183
|
function coerceInt(value) {
|
|
157
184
|
if (typeof value === "boolean") return value ? 1 : 0;
|
|
158
185
|
if (typeof value === "number") return Number.isFinite(value) ? Math.trunc(value) : null;
|
|
@@ -246,6 +273,10 @@ function asExerciseList(body) {
|
|
|
246
273
|
function isRecord(x) {
|
|
247
274
|
return typeof x === "object" && x !== null && !Array.isArray(x);
|
|
248
275
|
}
|
|
276
|
+
/** A non-empty string, or null. Narrows a loosely-typed API field to a usable string. */
|
|
277
|
+
function str(v) {
|
|
278
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
279
|
+
}
|
|
249
280
|
/**
|
|
250
281
|
* Rank candidate rows for a free-text query (FTS5 replacement). Higher is better:
|
|
251
282
|
* exact title, then prefix, then count of matched tokens, with shorter titles and
|
|
@@ -430,7 +461,6 @@ function fetchLeaderboard(client, workoutId, opts = {}) {
|
|
|
430
461
|
const query = qs.toString();
|
|
431
462
|
return getJson(client, `/3.0/athlete/leaderboard/${workoutId}${query ? `?${query}` : ""}`, "athlete leaderboard");
|
|
432
463
|
}
|
|
433
|
-
const SLOTS = 10;
|
|
434
464
|
function nonEmpty(value) {
|
|
435
465
|
return value !== void 0 && value !== null && String(value).trim() !== "";
|
|
436
466
|
}
|
|
@@ -441,7 +471,7 @@ function nonEmpty(value) {
|
|
|
441
471
|
*/
|
|
442
472
|
function prescribedSets(ex) {
|
|
443
473
|
const out = [];
|
|
444
|
-
for (let i = 1; i <=
|
|
474
|
+
for (let i = 1; i <= 10; i += 1) {
|
|
445
475
|
const p1 = ex[`param_1_data_${i}`];
|
|
446
476
|
const p2 = ex[`param_2_data_${i}`];
|
|
447
477
|
const has1 = nonEmpty(p1);
|
|
@@ -462,7 +492,7 @@ function prescribedSets(ex) {
|
|
|
462
492
|
*/
|
|
463
493
|
function performedSets(ex) {
|
|
464
494
|
const out = [];
|
|
465
|
-
for (let i = 1; i <=
|
|
495
|
+
for (let i = 1; i <= 10; i += 1) {
|
|
466
496
|
if (coerceInt(ex[`param_${i}_made`]) !== 1) continue;
|
|
467
497
|
const p1 = ex[`param_1_data_${i}`];
|
|
468
498
|
const p2 = ex[`param_2_data_${i}`];
|
|
@@ -496,9 +526,6 @@ function presentBlock(set, performedById) {
|
|
|
496
526
|
exercises: exercises.filter(isRecord).map((ex) => presentExercise$1(ex, performedById))
|
|
497
527
|
};
|
|
498
528
|
}
|
|
499
|
-
function str$1(v) {
|
|
500
|
-
return typeof v === "string" && v !== "" ? v : null;
|
|
501
|
-
}
|
|
502
529
|
/** Every logged set (programmed + athlete-added) in the saved copy, paired with its exercises. */
|
|
503
530
|
function savedSets(saved) {
|
|
504
531
|
const out = [];
|
|
@@ -583,11 +610,11 @@ function presentAthleteWorkout(raw) {
|
|
|
583
610
|
}
|
|
584
611
|
return {
|
|
585
612
|
id: coerceInt(rec.id),
|
|
586
|
-
date: str
|
|
587
|
-
title: str
|
|
588
|
-
program: str
|
|
589
|
-
team: str
|
|
590
|
-
instruction: str
|
|
613
|
+
date: str(rec.date) ?? "",
|
|
614
|
+
title: str(rec.workout_title) ?? "",
|
|
615
|
+
program: str(rec.program_title),
|
|
616
|
+
team: str(rec.team_title),
|
|
617
|
+
instruction: str(workout.instruction),
|
|
591
618
|
logged: blocks.some((b) => b.exercises.some((e) => e.performed.length > 0)),
|
|
592
619
|
blocks
|
|
593
620
|
};
|
|
@@ -596,12 +623,35 @@ function presentAthleteWorkouts(list) {
|
|
|
596
623
|
return list.map(presentAthleteWorkout);
|
|
597
624
|
}
|
|
598
625
|
/**
|
|
626
|
+
* Narrow a coach-athlete workout range to a single program or team. The range endpoint returns
|
|
627
|
+
* every program the athlete is enrolled in on a date; for a high-enrollment athlete that is many
|
|
628
|
+
* workouts, so a caller wanting one program's session narrows it here. Match by `programId`/`teamId`
|
|
629
|
+
* (exact, on the raw `program_id`/`team_id`) or by `programTitle` (case-insensitive substring on the
|
|
630
|
+
* `program_title`/`team_title`) — the title match lets a caller target a program by name without
|
|
631
|
+
* first resolving its id. Any one match keeps the workout; with no filter the list is unchanged.
|
|
632
|
+
*/
|
|
633
|
+
function selectWorkoutsByProgram(list, filter) {
|
|
634
|
+
const { programId, teamId, programTitle } = filter;
|
|
635
|
+
const needle = programTitle?.trim().toLowerCase();
|
|
636
|
+
if (programId === void 0 && teamId === void 0 && !needle) return [...list];
|
|
637
|
+
return list.filter((pw) => {
|
|
638
|
+
const rec = pw;
|
|
639
|
+
if (programId !== void 0 && coerceInt(rec.program_id) === programId) return true;
|
|
640
|
+
if (teamId !== void 0 && coerceInt(rec.team_id) === teamId) return true;
|
|
641
|
+
if (needle) {
|
|
642
|
+
if (`${str(rec.program_title) ?? ""} ${str(rec.team_title) ?? ""}`.toLowerCase().includes(needle)) return true;
|
|
643
|
+
}
|
|
644
|
+
return false;
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
599
648
|
* Project a workout range to just the ids a set-log write needs, read from the SAME saved-copy
|
|
600
649
|
* location {@link findSavedWorkoutSet} matches against (`summarizedSavedWorkout.saved_workout`).
|
|
601
650
|
* This is the self-service path for logging: instead of grepping the multi-KB `--raw` blob for
|
|
602
651
|
* which of several id fields maps to `--set`, callers read `savedWorkoutSetId` and each
|
|
603
|
-
* `savedWorkoutSetExerciseId` straight off these rows.
|
|
604
|
-
*
|
|
652
|
+
* `savedWorkoutSetExerciseId` straight off these rows. Each target also carries its program/team
|
|
653
|
+
* so a caller can pick the right session when the athlete is on several. One row per saved set,
|
|
654
|
+
* dropping any set with no resolvable id.
|
|
605
655
|
*/
|
|
606
656
|
function presentLogTargets(list) {
|
|
607
657
|
const targets = [];
|
|
@@ -610,8 +660,12 @@ function presentLogTargets(list) {
|
|
|
610
660
|
const ssw = isRecord(rec.summarizedSavedWorkout) ? rec.summarizedSavedWorkout : {};
|
|
611
661
|
const saved = isRecord(ssw.saved_workout) ? ssw.saved_workout : null;
|
|
612
662
|
if (!saved) continue;
|
|
613
|
-
const date = str
|
|
614
|
-
const workoutTitle = str
|
|
663
|
+
const date = str(rec.date) ?? "";
|
|
664
|
+
const workoutTitle = str(rec.workout_title) ?? "";
|
|
665
|
+
const program = str(rec.program_title);
|
|
666
|
+
const programId = coerceInt(rec.program_id);
|
|
667
|
+
const team = str(rec.team_title);
|
|
668
|
+
const teamId = coerceInt(rec.team_id);
|
|
615
669
|
const sets = Array.isArray(saved.workoutSets) ? saved.workoutSets : [];
|
|
616
670
|
for (const s of sets) {
|
|
617
671
|
if (!isRecord(s)) continue;
|
|
@@ -631,8 +685,12 @@ function presentLogTargets(list) {
|
|
|
631
685
|
targets.push({
|
|
632
686
|
date,
|
|
633
687
|
workoutTitle,
|
|
688
|
+
program,
|
|
689
|
+
programId,
|
|
690
|
+
team,
|
|
691
|
+
teamId,
|
|
634
692
|
savedWorkoutSetId,
|
|
635
|
-
setTitle: str
|
|
693
|
+
setTitle: str(s.title),
|
|
636
694
|
exercises
|
|
637
695
|
});
|
|
638
696
|
}
|
|
@@ -720,7 +778,29 @@ function presentCoachAthleteTraining(raw, athleteId, year, month) {
|
|
|
720
778
|
sessions
|
|
721
779
|
};
|
|
722
780
|
}
|
|
723
|
-
|
|
781
|
+
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
782
|
+
function presentExerciseHistory(detail) {
|
|
783
|
+
return {
|
|
784
|
+
liftPRs: (detail.liftPRs ?? []).map((p) => ({
|
|
785
|
+
description: p.description ?? null,
|
|
786
|
+
reps: p.reps ?? null,
|
|
787
|
+
weight: p.weight ?? null,
|
|
788
|
+
units: p.units ?? null,
|
|
789
|
+
date: p.dateCompleted ?? null
|
|
790
|
+
})),
|
|
791
|
+
sessions: (detail.history ?? []).map((h) => ({
|
|
792
|
+
date: h.dateCompleted,
|
|
793
|
+
abr: h.abr ?? null,
|
|
794
|
+
estimated1RM: h.bestEstimated1RM ?? null,
|
|
795
|
+
sets: (h.sets ?? []).map((s) => ({
|
|
796
|
+
setNumber: s.setNumber,
|
|
797
|
+
value: s.formattedValue ?? null
|
|
798
|
+
}))
|
|
799
|
+
}))
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region src/athlete-set-write.ts
|
|
724
804
|
/**
|
|
725
805
|
* Coerce the loosely-typed `results` from a validated log/prescribe args object into the SDK's
|
|
726
806
|
* {@link SetResult}[]. The dto schemas validate ids as a number or a numeric string and leave
|
|
@@ -735,10 +815,11 @@ function toSetResults(results) {
|
|
|
735
815
|
return {
|
|
736
816
|
savedWorkoutSetExerciseId: id,
|
|
737
817
|
sets: r.sets.map((s) => {
|
|
738
|
-
const
|
|
739
|
-
if (s.param1 !== void 0)
|
|
740
|
-
if (s.param2 !== void 0)
|
|
741
|
-
|
|
818
|
+
const set = {};
|
|
819
|
+
if (s.param1 !== void 0) set.param1 = s.param1;
|
|
820
|
+
if (s.param2 !== void 0) set.param2 = s.param2;
|
|
821
|
+
if (s.slot !== void 0) set.slot = s.slot;
|
|
822
|
+
return set;
|
|
742
823
|
})
|
|
743
824
|
};
|
|
744
825
|
});
|
|
@@ -750,36 +831,96 @@ function toSetResults(results) {
|
|
|
750
831
|
*
|
|
751
832
|
* `mode` selects which write this is — the same endpoint serves both:
|
|
752
833
|
* - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has data
|
|
753
|
-
* and the exercise `completed` flag is 1 when any set has data.
|
|
834
|
+
* and the exercise `completed` flag is 1 when any set has logged data.
|
|
754
835
|
* - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
|
|
755
836
|
* `completed` left at 0 so the set is not marked done. This matches what the app sends when a
|
|
756
837
|
* coach edits an athlete's prescribed reps/weight.
|
|
757
838
|
*
|
|
839
|
+
* Each set fills a 1-based slot: its explicit `slot`, or its sequential position in `results`
|
|
840
|
+
* when `slot` is omitted. A `log` carrying the live exercise record in `existing` keeps the slots
|
|
841
|
+
* it does not write that were ALREADY performed (`param_N_made === 1`), so logging a second part of
|
|
842
|
+
* a set does not wipe the earlier-logged sets. A slot holding only un-logged prescription pre-fill
|
|
843
|
+
* (`param_N_made === 0`) is left blank rather than carried over: marking the set completed makes
|
|
844
|
+
* the server flag every data-bearing slot performed, so preserving that pre-fill would fabricate
|
|
845
|
+
* sets the athlete never did. The prescription is unaffected (it lives in the separate `workout`
|
|
846
|
+
* copy, not this saved copy). A `prescribe` ignores `existing` and replaces the whole prescription.
|
|
847
|
+
*
|
|
758
848
|
* Only `savedWorkoutSetExerciseId`, `savedWorkoutSetId`, and `workoutSetExerciseId` are
|
|
759
|
-
* required from the live exercise record; everything else is derived from `results
|
|
849
|
+
* required from the live exercise record; everything else is derived from `results` and the
|
|
850
|
+
* preserved slots of `existing`.
|
|
760
851
|
*
|
|
761
852
|
* Exported for unit testing — callers should use `logAthleteSet` / `prescribeForAthlete` instead.
|
|
762
853
|
*/
|
|
763
|
-
function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, results, mode) {
|
|
764
|
-
if (results.length >
|
|
854
|
+
function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, results, mode, existing) {
|
|
855
|
+
if (results.length > 10) throw new Error(`At most 10 sets are supported per exercise; got ${results.length}.`);
|
|
856
|
+
const bySlot = /* @__PURE__ */ new Map();
|
|
857
|
+
results.forEach((set, i) => {
|
|
858
|
+
const slot = set.slot ?? i + 1;
|
|
859
|
+
if (slot < 1 || slot > 10) throw new Error(`Set slot ${slot} is out of range; slots are 1–10.`);
|
|
860
|
+
if (bySlot.has(slot)) throw new Error(`Two sets target slot ${slot}; each slot can be written once.`);
|
|
861
|
+
bySlot.set(slot, set);
|
|
862
|
+
});
|
|
765
863
|
const performed = mode === "log";
|
|
766
|
-
const
|
|
864
|
+
const carryOver = performed && existing !== void 0;
|
|
767
865
|
const body = {
|
|
768
866
|
id: savedWorkoutSetExerciseId,
|
|
769
867
|
saved_workout_set_id: savedWorkoutSetId,
|
|
770
|
-
workout_set_exercise_id: workoutSetExerciseId
|
|
771
|
-
completed: performed && hasData ? 1 : 0
|
|
868
|
+
workout_set_exercise_id: workoutSetExerciseId
|
|
772
869
|
};
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
const
|
|
776
|
-
|
|
777
|
-
|
|
870
|
+
let anyMade = false;
|
|
871
|
+
for (let i = 1; i <= 10; i += 1) {
|
|
872
|
+
const target = bySlot.get(i);
|
|
873
|
+
let p1;
|
|
874
|
+
let p2;
|
|
875
|
+
let made;
|
|
876
|
+
if (target) {
|
|
877
|
+
p1 = target.param1 !== void 0 ? String(target.param1) : "";
|
|
878
|
+
p2 = target.param2 !== void 0 ? String(target.param2) : "";
|
|
879
|
+
made = performed && (p1 !== "" || p2 !== "") ? 1 : 0;
|
|
880
|
+
} else if (carryOver && coerceInt(existing?.[`param_${i}_made`]) === 1) {
|
|
881
|
+
p1 = existingSlotData(existing, `param_1_data_${i}`);
|
|
882
|
+
p2 = existingSlotData(existing, `param_2_data_${i}`);
|
|
883
|
+
made = 1;
|
|
884
|
+
} else {
|
|
885
|
+
p1 = "";
|
|
886
|
+
p2 = "";
|
|
887
|
+
made = 0;
|
|
888
|
+
}
|
|
889
|
+
if (made === 1) anyMade = true;
|
|
890
|
+
body[`param_${i}_made`] = made;
|
|
778
891
|
body[`param_1_data_${i}`] = p1;
|
|
779
892
|
body[`param_2_data_${i}`] = p2;
|
|
780
893
|
}
|
|
894
|
+
body.completed = performed && anyMade ? 1 : 0;
|
|
781
895
|
return body;
|
|
782
896
|
}
|
|
897
|
+
/** Read a saved-copy slot value (`param_1_data_N` / `param_2_data_N`) as the string the body uses. */
|
|
898
|
+
function existingSlotData(existing, key) {
|
|
899
|
+
const v = existing?.[key];
|
|
900
|
+
return v === void 0 || v === null ? "" : String(v);
|
|
901
|
+
}
|
|
902
|
+
/** True when a saved-copy exercise already carries a performed slot (any `param_N_made` === 1). */
|
|
903
|
+
function exerciseHasLoggedData(ex) {
|
|
904
|
+
for (let i = 1; i <= 10; i += 1) if (coerceInt(ex[`param_${i}_made`]) === 1) return true;
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
/** True when a result carries at least one non-empty param value (so it produces a performed slot). */
|
|
908
|
+
function resultHasData(result) {
|
|
909
|
+
return result.sets.some((s) => s.param1 !== void 0 && String(s.param1) !== "" || s.param2 !== void 0 && String(s.param2) !== "");
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Whether every exercise in a saved workout set now has logged data — either written with data in
|
|
913
|
+
* this call (`loggedIds`) or already carrying a performed slot. Gates the set-completion PUT: a
|
|
914
|
+
* superset/circuit stays open until the last exercise is logged, so completing it on a partial log
|
|
915
|
+
* does not flip its still-empty siblings to "done". An exercise written with only empty values does
|
|
916
|
+
* not count (it would not be marked performed), so an all-empty log never completes the set.
|
|
917
|
+
*/
|
|
918
|
+
function isSetFullyLogged(exercises, loggedIds) {
|
|
919
|
+
return exercises.every((ex) => {
|
|
920
|
+
const id = coerceInt(ex.id);
|
|
921
|
+
return id !== null && loggedIds.has(id) || exerciseHasLoggedData(ex);
|
|
922
|
+
});
|
|
923
|
+
}
|
|
783
924
|
/**
|
|
784
925
|
* Locate the target saved workout set across all program workouts on the given day.
|
|
785
926
|
* Returns the `savedWorkoutId`, the matching set's `workoutSetExercises` array so callers
|
|
@@ -878,7 +1019,8 @@ async function logAthleteSet(client, args) {
|
|
|
878
1019
|
const r = await writeSetResults(client, { role: "athlete" }, await fetchAthleteWorkouts(client, args.date, args.date), args.savedWorkoutSetId, args.results, "log");
|
|
879
1020
|
return {
|
|
880
1021
|
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
881
|
-
exercisesLogged: r.exercisesWritten
|
|
1022
|
+
exercisesLogged: r.exercisesWritten,
|
|
1023
|
+
setCompleted: r.setCompleted
|
|
882
1024
|
};
|
|
883
1025
|
}
|
|
884
1026
|
/**
|
|
@@ -899,7 +1041,8 @@ async function logForAthlete(client, args) {
|
|
|
899
1041
|
}, workouts, args.savedWorkoutSetId, args.results, "log");
|
|
900
1042
|
return {
|
|
901
1043
|
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
902
|
-
exercisesLogged: r.exercisesWritten
|
|
1044
|
+
exercisesLogged: r.exercisesWritten,
|
|
1045
|
+
setCompleted: r.setCompleted
|
|
903
1046
|
};
|
|
904
1047
|
}
|
|
905
1048
|
/**
|
|
@@ -960,7 +1103,7 @@ async function swapAthleteExercise(client, args) {
|
|
|
960
1103
|
savedWorkoutSetExerciseId: args.savedWorkoutSetExerciseId,
|
|
961
1104
|
athleteId: coerceInt(row.user_id),
|
|
962
1105
|
newExerciseId: coerceInt(row.exercise_id) ?? args.exerciseId,
|
|
963
|
-
newExerciseTitle: str
|
|
1106
|
+
newExerciseTitle: str(exercise.title),
|
|
964
1107
|
originalTeamExerciseId: coerceInt(template.exercise_id)
|
|
965
1108
|
};
|
|
966
1109
|
}
|
|
@@ -992,9 +1135,9 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
|
|
|
992
1135
|
throw new Error(`savedWorkoutSetExerciseId ${result.savedWorkoutSetExerciseId} not found in saved workout set ${savedWorkoutSetId}. Exercises in this set: ${valid.join(", ") || "none"}.`);
|
|
993
1136
|
}
|
|
994
1137
|
const workoutSetExerciseId = coerceInt(ex.workout_set_exercise_id);
|
|
995
|
-
if (!workoutSetExerciseId) throw new Error(`
|
|
1138
|
+
if (!workoutSetExerciseId) throw new Error(`savedWorkoutSetExercise ${result.savedWorkoutSetExerciseId} is missing its workout_set_exercise_id (the prescription-template pointer the write needs). This is the savedWorkoutSetExerciseId, not an exercise_id — re-read the ids from athlete_saved_workouts.`);
|
|
996
1139
|
const body = {
|
|
997
|
-
...buildExerciseSetPayload(result.savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, result.sets, mode),
|
|
1140
|
+
...buildExerciseSetPayload(result.savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, result.sets, mode, ex),
|
|
998
1141
|
...extra
|
|
999
1142
|
};
|
|
1000
1143
|
const res = await client.request("PUT", `/1.0/${target.role}/savedworkoutsetexercise/${result.savedWorkoutSetExerciseId}${suffix}`, { body });
|
|
@@ -1004,17 +1147,22 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
|
|
|
1004
1147
|
}
|
|
1005
1148
|
exercisesWritten += 1;
|
|
1006
1149
|
}
|
|
1150
|
+
let setCompleted = false;
|
|
1007
1151
|
if (mode === "log") {
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1152
|
+
if (isSetFullyLogged(exercises, new Set(results.filter(resultHasData).map((r) => r.savedWorkoutSetExerciseId)))) {
|
|
1153
|
+
const setBody = {
|
|
1154
|
+
...buildSetCompletePayload(rawSet, exercises.map((e) => coerceInt(e.id)).filter((n) => n !== null), true),
|
|
1155
|
+
...extra
|
|
1156
|
+
};
|
|
1157
|
+
const setRes = await client.request("PUT", `/1.0/${target.role}/savedworkoutset/${savedWorkoutSetId}${suffix}`, { body: setBody });
|
|
1158
|
+
if (!setRes.ok) throw new Error(`Failed to mark workout set ${savedWorkoutSetId} completed (HTTP ${setRes.status}).`);
|
|
1159
|
+
setCompleted = true;
|
|
1160
|
+
}
|
|
1014
1161
|
}
|
|
1015
1162
|
return {
|
|
1016
1163
|
savedWorkoutSetId,
|
|
1017
|
-
exercisesWritten
|
|
1164
|
+
exercisesWritten,
|
|
1165
|
+
setCompleted
|
|
1018
1166
|
};
|
|
1019
1167
|
}
|
|
1020
1168
|
/**
|
|
@@ -1171,7 +1319,10 @@ async function logResolvedExercises(client, target, date, resolved) {
|
|
|
1171
1319
|
savedWorkoutSetId,
|
|
1172
1320
|
results
|
|
1173
1321
|
});
|
|
1174
|
-
out.push(
|
|
1322
|
+
out.push({
|
|
1323
|
+
savedWorkoutSetId: written.savedWorkoutSetId,
|
|
1324
|
+
exercisesLogged: written.exercisesLogged
|
|
1325
|
+
});
|
|
1175
1326
|
}
|
|
1176
1327
|
return out;
|
|
1177
1328
|
}
|
|
@@ -1249,27 +1400,6 @@ async function logSessionForAthlete(client, args) {
|
|
|
1249
1400
|
sets
|
|
1250
1401
|
};
|
|
1251
1402
|
}
|
|
1252
|
-
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
1253
|
-
function presentExerciseHistory(detail) {
|
|
1254
|
-
return {
|
|
1255
|
-
liftPRs: (detail.liftPRs ?? []).map((p) => ({
|
|
1256
|
-
description: p.description ?? null,
|
|
1257
|
-
reps: p.reps ?? null,
|
|
1258
|
-
weight: p.weight ?? null,
|
|
1259
|
-
units: p.units ?? null,
|
|
1260
|
-
date: p.dateCompleted ?? null
|
|
1261
|
-
})),
|
|
1262
|
-
sessions: (detail.history ?? []).map((h) => ({
|
|
1263
|
-
date: h.dateCompleted,
|
|
1264
|
-
abr: h.abr ?? null,
|
|
1265
|
-
estimated1RM: h.bestEstimated1RM ?? null,
|
|
1266
|
-
sets: (h.sets ?? []).map((s) => ({
|
|
1267
|
-
setNumber: s.setNumber,
|
|
1268
|
-
value: s.formattedValue ?? null
|
|
1269
|
-
}))
|
|
1270
|
-
}))
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
1403
|
//#endregion
|
|
1274
1404
|
//#region src/coach.ts
|
|
1275
1405
|
const DEFAULT_INVITE_MESSAGE = "Follow these steps and you'll be set up and ready to go!";
|
|
@@ -2093,7 +2223,7 @@ async function removeSession(client, programId, pwId) {
|
|
|
2093
2223
|
async function publishSession(client, pwId) {
|
|
2094
2224
|
await req(client, "POST", "/2.0/coach/calendar/programWorkout/publish", [pwId]);
|
|
2095
2225
|
}
|
|
2096
|
-
function str(value) {
|
|
2226
|
+
function str$1(value) {
|
|
2097
2227
|
return value === void 0 || value === null ? "" : String(value);
|
|
2098
2228
|
}
|
|
2099
2229
|
async function readSession(client, programId, date, pwId) {
|
|
@@ -2106,9 +2236,9 @@ async function readSession(client, programId, date, pwId) {
|
|
|
2106
2236
|
const blocks = Object.values(setsObj).sort((a, b) => Number(a.order) - Number(b.order)).map((b) => readBlock(b));
|
|
2107
2237
|
return {
|
|
2108
2238
|
pwId,
|
|
2109
|
-
date: `${str(pw.year)}-${str(pw.month)}-${str(pw.day)}`,
|
|
2239
|
+
date: `${str$1(pw.year)}-${str$1(pw.month)}-${str$1(pw.day)}`,
|
|
2110
2240
|
published: pw.published,
|
|
2111
|
-
instruction: str(pw.instruction),
|
|
2241
|
+
instruction: str$1(pw.instruction),
|
|
2112
2242
|
blocks
|
|
2113
2243
|
};
|
|
2114
2244
|
}
|
|
@@ -2119,7 +2249,7 @@ function readBlock(b) {
|
|
|
2119
2249
|
const exercises = (Array.isArray(b.exercises) ? b.exercises : []).sort((a, e) => Number(a.order) - Number(e.order)).map((ex) => readExercise(ex));
|
|
2120
2250
|
return {
|
|
2121
2251
|
order: Number(b.order),
|
|
2122
|
-
title: str(b.title),
|
|
2252
|
+
title: str$1(b.title),
|
|
2123
2253
|
leaderboard,
|
|
2124
2254
|
exercises
|
|
2125
2255
|
};
|
|
@@ -2128,19 +2258,19 @@ function readExercise(ex) {
|
|
|
2128
2258
|
const reps = [];
|
|
2129
2259
|
const load = [];
|
|
2130
2260
|
for (let i = 1; i <= 10; i += 1) {
|
|
2131
|
-
const r = str(ex[`param_1_data_${i}`]);
|
|
2261
|
+
const r = str$1(ex[`param_1_data_${i}`]);
|
|
2132
2262
|
if (r !== "") reps.push(r);
|
|
2133
|
-
const w = str(ex[`param_2_data_${i}`]);
|
|
2263
|
+
const w = str$1(ex[`param_2_data_${i}`]);
|
|
2134
2264
|
if (w !== "") load.push(w);
|
|
2135
2265
|
}
|
|
2136
2266
|
return {
|
|
2137
2267
|
order: Number(ex.order),
|
|
2138
|
-
title: str(ex.title),
|
|
2268
|
+
title: str$1(ex.title),
|
|
2139
2269
|
reps,
|
|
2140
2270
|
primaryUnit: unitLabel(coerceInt(ex.param_1_type)),
|
|
2141
2271
|
load,
|
|
2142
2272
|
loadUnit: unitLabel(coerceInt(ex.param_2_type)),
|
|
2143
|
-
instruction: str(ex.instruction)
|
|
2273
|
+
instruction: str$1(ex.instruction)
|
|
2144
2274
|
};
|
|
2145
2275
|
}
|
|
2146
2276
|
//#endregion
|
|
@@ -2376,4 +2506,4 @@ var ExerciseLibrary = class {
|
|
|
2376
2506
|
}
|
|
2377
2507
|
};
|
|
2378
2508
|
//#endregion
|
|
2379
|
-
export { ANALYTICS_METRIC_KEYS, DEFAULT_INVITE_MESSAGE, ExerciseLibrary, LEADERBOARD_LABEL, LEADERBOARD_TYPE, MAIN_LIFT_FAMILIES, 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, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkouts, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, sendComment, setSessionInstruction, sortRosterByRecency, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
|
2509
|
+
export { ANALYTICS_METRIC_KEYS, 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, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkouts, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
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": "1.
|
|
30
|
+
"@trainheroic-unofficial/dto": "1.5.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^26.0.0",
|