@trainheroic-unofficial/cli 1.1.1 → 1.2.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/cli.mjs +219 -51
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -181,6 +181,26 @@ const logSetArgsSchema = z.object({
|
|
|
181
181
|
*/
|
|
182
182
|
const coachLogSetArgsSchema = logSetArgsSchema.extend({ athleteId: idArgSchema });
|
|
183
183
|
/**
|
|
184
|
+
* Args for the coach prescription-override write. Structurally the same as
|
|
185
|
+
* {@link coachLogSetArgsSchema} (athleteId + date + savedWorkoutSetId + per-exercise `sets`), but
|
|
186
|
+
* the values are prescribed targets (param1 = reps, param2 = weight) written to the athlete's
|
|
187
|
+
* plan without marking the set performed. It is a separate schema (not an alias) so a future
|
|
188
|
+
* prescribe-only constraint can be added here without changing the log args, and the write
|
|
189
|
+
* replaces the slot's prescribed values for this athlete only.
|
|
190
|
+
*/
|
|
191
|
+
const coachPrescribeSetArgsSchema = logSetArgsSchema.extend({ athleteId: idArgSchema });
|
|
192
|
+
/**
|
|
193
|
+
* Args for the coach per-athlete exercise swap: replace the exercise prescribed in one of a
|
|
194
|
+
* roster athlete's saved-workout slots with a different exercise, the API equivalent of the
|
|
195
|
+
* app's per-athlete "swap exercise". `savedWorkoutSetExerciseId` is that athlete's own slot id
|
|
196
|
+
* (the same id `coachLogSetArgsSchema` uses, read off athlete_saved_workouts raw);
|
|
197
|
+
* `exerciseId` is the replacement exercise. The team/program prescription is left untouched.
|
|
198
|
+
*/
|
|
199
|
+
const swapAthleteExerciseArgsSchema = z.object({
|
|
200
|
+
savedWorkoutSetExerciseId: idArgSchema,
|
|
201
|
+
exerciseId: idArgSchema
|
|
202
|
+
});
|
|
203
|
+
/**
|
|
184
204
|
* Args for logging a whole session by exercise (rather than by saved-workout-set id). Each
|
|
185
205
|
* exercise carries its entered sets and an optional 1-based `order`. The athlete path creates
|
|
186
206
|
* or reuses a personal session for the date and logs against it; the coach path resolves each
|
|
@@ -1002,29 +1022,59 @@ function presentCoachAthleteTraining(raw, athleteId, year, month) {
|
|
|
1002
1022
|
}
|
|
1003
1023
|
const MAX_PARAM_SLOTS = 10;
|
|
1004
1024
|
/**
|
|
1005
|
-
*
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
* `
|
|
1025
|
+
* Coerce the loosely-typed `results` from a validated log/prescribe args object into the SDK's
|
|
1026
|
+
* {@link SetResult}[]. The dto schemas validate ids as a number or a numeric string and leave
|
|
1027
|
+
* empty param slots optional; this narrows the id to a number and copies only the present per-set
|
|
1028
|
+
* values (so the per-set type stays free of `undefined` under exactOptionalPropertyTypes). Shared
|
|
1029
|
+
* by the MCP tools and the CLI so the mapping lives in one place rather than once per surface.
|
|
1030
|
+
*/
|
|
1031
|
+
function toSetResults(results) {
|
|
1032
|
+
return results.map((r) => {
|
|
1033
|
+
const id = coerceInt(r.savedWorkoutSetExerciseId);
|
|
1034
|
+
if (id === null) throw new Error(`Invalid savedWorkoutSetExerciseId: ${String(r.savedWorkoutSetExerciseId)}`);
|
|
1035
|
+
return {
|
|
1036
|
+
savedWorkoutSetExerciseId: id,
|
|
1037
|
+
sets: r.sets.map((s) => {
|
|
1038
|
+
const slot = {};
|
|
1039
|
+
if (s.param1 !== void 0) slot.param1 = s.param1;
|
|
1040
|
+
if (s.param2 !== void 0) slot.param2 = s.param2;
|
|
1041
|
+
return slot;
|
|
1042
|
+
})
|
|
1043
|
+
};
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Build the body for `PUT /1.0/{role}/savedworkoutsetexercise/{id}`. The body uses snake_case
|
|
1048
|
+
* keys matching the live API response shape. Each set slot (1-10) carries `param_1_data_N` /
|
|
1049
|
+
* `param_2_data_N` string values plus a `param_N_made` flag.
|
|
1050
|
+
*
|
|
1051
|
+
* `mode` selects which write this is — the same endpoint serves both:
|
|
1052
|
+
* - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has data
|
|
1053
|
+
* and the exercise `completed` flag is 1 when any set has data.
|
|
1054
|
+
* - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
|
|
1055
|
+
* `completed` left at 0 so the set is not marked done. This matches what the app sends when a
|
|
1056
|
+
* coach edits an athlete's prescribed reps/weight.
|
|
1009
1057
|
*
|
|
1010
1058
|
* Only `savedWorkoutSetExerciseId`, `savedWorkoutSetId`, and `workoutSetExerciseId` are
|
|
1011
1059
|
* required from the live exercise record; everything else is derived from `results`.
|
|
1012
1060
|
*
|
|
1013
|
-
* Exported for unit testing — callers should use `logAthleteSet` instead.
|
|
1061
|
+
* Exported for unit testing — callers should use `logAthleteSet` / `prescribeForAthlete` instead.
|
|
1014
1062
|
*/
|
|
1015
|
-
function
|
|
1063
|
+
function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, results, mode) {
|
|
1016
1064
|
if (results.length > MAX_PARAM_SLOTS) throw new Error(`At most ${MAX_PARAM_SLOTS} sets are supported per exercise; got ${results.length}.`);
|
|
1065
|
+
const performed = mode === "log";
|
|
1066
|
+
const hasData = results.some((s) => s.param1 !== void 0 || s.param2 !== void 0);
|
|
1017
1067
|
const body = {
|
|
1018
1068
|
id: savedWorkoutSetExerciseId,
|
|
1019
1069
|
saved_workout_set_id: savedWorkoutSetId,
|
|
1020
1070
|
workout_set_exercise_id: workoutSetExerciseId,
|
|
1021
|
-
completed:
|
|
1071
|
+
completed: performed && hasData ? 1 : 0
|
|
1022
1072
|
};
|
|
1023
1073
|
for (let i = 1; i <= MAX_PARAM_SLOTS; i += 1) {
|
|
1024
1074
|
const slot = results[i - 1];
|
|
1025
1075
|
const p1 = slot?.param1 !== void 0 ? String(slot.param1) : "";
|
|
1026
1076
|
const p2 = slot?.param2 !== void 0 ? String(slot.param2) : "";
|
|
1027
|
-
body[`param_${i}_made`] = p1 !== "" || p2 !== "" ? 1 : 0;
|
|
1077
|
+
body[`param_${i}_made`] = performed && (p1 !== "" || p2 !== "") ? 1 : 0;
|
|
1028
1078
|
body[`param_1_data_${i}`] = p1;
|
|
1029
1079
|
body[`param_2_data_${i}`] = p2;
|
|
1030
1080
|
}
|
|
@@ -1125,7 +1175,11 @@ function buildSetCompletePayload(rawSet, exerciseIds, complete) {
|
|
|
1125
1175
|
* by the respective PUT bodies.
|
|
1126
1176
|
*/
|
|
1127
1177
|
async function logAthleteSet(client, args) {
|
|
1128
|
-
|
|
1178
|
+
const r = await writeSetResults(client, { role: "athlete" }, await fetchAthleteWorkouts(client, args.date, args.date), args.savedWorkoutSetId, args.results, "log");
|
|
1179
|
+
return {
|
|
1180
|
+
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
1181
|
+
exercisesLogged: r.exercisesWritten
|
|
1182
|
+
};
|
|
1129
1183
|
}
|
|
1130
1184
|
/**
|
|
1131
1185
|
* Coach "Log for Athlete": record set results for a roster athlete on their behalf, via the
|
|
@@ -1139,24 +1193,94 @@ async function logAthleteSet(client, args) {
|
|
|
1139
1193
|
*/
|
|
1140
1194
|
async function logForAthlete(client, args) {
|
|
1141
1195
|
const workouts = await fetchCoachAthleteWorkouts(client, args.athleteId, args.date, args.date);
|
|
1142
|
-
|
|
1196
|
+
const r = await writeSetResults(client, {
|
|
1197
|
+
role: "coach",
|
|
1198
|
+
athleteId: args.athleteId
|
|
1199
|
+
}, workouts, args.savedWorkoutSetId, args.results, "log");
|
|
1200
|
+
return {
|
|
1201
|
+
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
1202
|
+
exercisesLogged: r.exercisesWritten
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Coach prescription override: set the prescribed reps/weight for one of a roster athlete's saved
|
|
1207
|
+
* workout sets WITHOUT marking it performed — the API equivalent of the app's editing an athlete's
|
|
1208
|
+
* prescribed values. Writes each exercise's per-set targets via
|
|
1209
|
+
* `PUT /1.0/coach/savedworkoutsetexercise/{id}/{athleteId}` with `param_N_made = 0` /
|
|
1210
|
+
* `completed = 0`, and (unlike {@link logForAthlete}) skips the set-completion step, so the set
|
|
1211
|
+
* stays open for the athlete to log against.
|
|
1212
|
+
*
|
|
1213
|
+
* Overrides only this athlete's copy of the set; the team/program prescription is untouched, so
|
|
1214
|
+
* other athletes on the same program keep the original targets. The write REPLACES the slot's
|
|
1215
|
+
* prescribed values, so pass the full per-set prescription you want — `param1` is reps, `param2`
|
|
1216
|
+
* is weight, and an omitted param is written empty (clearing it), not left as-is.
|
|
1217
|
+
*
|
|
1218
|
+
* NOTE: TrainHeroic's seeded *demo* athletes are read-only and return 401/403; real (invited)
|
|
1219
|
+
* athletes accept it.
|
|
1220
|
+
*/
|
|
1221
|
+
async function prescribeForAthlete(client, args) {
|
|
1222
|
+
const workouts = await fetchCoachAthleteWorkouts(client, args.athleteId, args.date, args.date);
|
|
1223
|
+
const r = await writeSetResults(client, {
|
|
1143
1224
|
role: "coach",
|
|
1144
1225
|
athleteId: args.athleteId
|
|
1145
|
-
}, workouts, args.savedWorkoutSetId, args.results);
|
|
1226
|
+
}, workouts, args.savedWorkoutSetId, args.results, "prescribe");
|
|
1227
|
+
return {
|
|
1228
|
+
savedWorkoutSetId: r.savedWorkoutSetId,
|
|
1229
|
+
exercisesPrescribed: r.exercisesWritten
|
|
1230
|
+
};
|
|
1146
1231
|
}
|
|
1147
1232
|
/**
|
|
1148
|
-
*
|
|
1149
|
-
*
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1152
|
-
*
|
|
1153
|
-
*
|
|
1233
|
+
* Swap the exercise prescribed in one of an athlete's saved-workout slots for a different
|
|
1234
|
+
* exercise — the API equivalent of the app's per-athlete "swap exercise":
|
|
1235
|
+
* `PUT /v5/savedWorkoutSetExercises/{savedWorkoutSetExerciseId}?exerciseId={exerciseId}` with an
|
|
1236
|
+
* empty body. The new exercise rides in the query string, not the body.
|
|
1237
|
+
*
|
|
1238
|
+
* This overrides only this athlete's copy of the slot; the underlying team/program prescription
|
|
1239
|
+
* (`workout_set_exercise.exercise_id`) is untouched, so other athletes on the same program keep
|
|
1240
|
+
* the original exercise. A coach's session token may write another user's row because the row
|
|
1241
|
+
* already carries its owner's `user_id`.
|
|
1242
|
+
*
|
|
1243
|
+
* `savedWorkoutSetExerciseId` is the same id {@link logForAthlete}/{@link logAthleteSet} use,
|
|
1244
|
+
* read off the athlete's saved workouts (the raw view). `exerciseId` is any exercise id the org
|
|
1245
|
+
* can use (resolve one via the exercise index).
|
|
1246
|
+
*
|
|
1247
|
+
* NOTE: as with logging, TrainHeroic's seeded *demo* athletes are read-only and return 401/403;
|
|
1248
|
+
* real (invited) athletes accept the swap.
|
|
1249
|
+
*/
|
|
1250
|
+
async function swapAthleteExercise(client, args) {
|
|
1251
|
+
const res = await client.request("PUT", `/v5/savedWorkoutSetExercises/${args.savedWorkoutSetExerciseId}?exerciseId=${args.exerciseId}`);
|
|
1252
|
+
if (!res.ok) {
|
|
1253
|
+
const readOnly = res.status === 401 || res.status === 403 ? ` Athlete may be read-only for changes — TrainHeroic's seeded demo/sample athletes return ${res.status} here; swaps only persist for real (invited) athletes.` : "";
|
|
1254
|
+
throw new Error(`Swap failed (HTTP ${res.status}) for savedWorkoutSetExercise ${args.savedWorkoutSetExerciseId}.${readOnly}`);
|
|
1255
|
+
}
|
|
1256
|
+
const row = isRecord(res.data) ? res.data : {};
|
|
1257
|
+
const template = isRecord(row.workout_set_exercise) ? row.workout_set_exercise : {};
|
|
1258
|
+
const exercise = isRecord(row.exercise) ? row.exercise : {};
|
|
1259
|
+
return {
|
|
1260
|
+
savedWorkoutSetExerciseId: args.savedWorkoutSetExerciseId,
|
|
1261
|
+
athleteId: coerceInt(row.user_id),
|
|
1262
|
+
newExerciseId: coerceInt(row.exercise_id) ?? args.exerciseId,
|
|
1263
|
+
newExerciseTitle: str$1(exercise.title),
|
|
1264
|
+
originalTeamExerciseId: coerceInt(template.exercise_id)
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Shared set-write behind {@link logAthleteSet}, {@link logForAthlete}, and
|
|
1269
|
+
* {@link prescribeForAthlete}. `target` selects the surface: `athlete` writes `/1.0/athlete/...`;
|
|
1270
|
+
* `coach` writes `/1.0/coach/...{athleteId}` and stamps `athleteId` into each body.
|
|
1271
|
+
*
|
|
1272
|
+
* Step 1 PUTs each exercise's per-set values to its own endpoint (the only path that actually
|
|
1273
|
+
* stores reps and weight). `mode` decides what those values mean: `"log"` records them as a
|
|
1274
|
+
* performed result and runs Step 2, which marks the set completed (that body needs the app's
|
|
1275
|
+
* camelCase in-memory shape and the full list of savedWorkoutSetExercise IDs in the set, not only
|
|
1276
|
+
* the written ones); `"prescribe"` writes them as a prescription and skips Step 2, leaving the set
|
|
1277
|
+
* open.
|
|
1154
1278
|
*/
|
|
1155
|
-
async function writeSetResults(client, target, workouts, savedWorkoutSetId, results) {
|
|
1279
|
+
async function writeSetResults(client, target, workouts, savedWorkoutSetId, results, mode) {
|
|
1156
1280
|
const { exercises, rawSet } = findSavedWorkoutSet(workouts, savedWorkoutSetId);
|
|
1157
1281
|
const suffix = target.role === "coach" ? `/${target.athleteId}` : "";
|
|
1158
1282
|
const extra = target.role === "coach" ? { athleteId: target.athleteId } : {};
|
|
1159
|
-
let
|
|
1283
|
+
let exercisesWritten = 0;
|
|
1160
1284
|
for (const result of results) {
|
|
1161
1285
|
const ex = exercises.find((e) => coerceInt(e.id) === result.savedWorkoutSetExerciseId);
|
|
1162
1286
|
if (!ex) {
|
|
@@ -1170,25 +1294,27 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
|
|
|
1170
1294
|
const workoutSetExerciseId = coerceInt(ex.workout_set_exercise_id);
|
|
1171
1295
|
if (!workoutSetExerciseId) throw new Error(`Could not resolve workout_set_exercise_id for exercise ${result.savedWorkoutSetExerciseId}.`);
|
|
1172
1296
|
const body = {
|
|
1173
|
-
...
|
|
1297
|
+
...buildExerciseSetPayload(result.savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, result.sets, mode),
|
|
1174
1298
|
...extra
|
|
1175
1299
|
};
|
|
1176
1300
|
const res = await client.request("PUT", `/1.0/${target.role}/savedworkoutsetexercise/${result.savedWorkoutSetExerciseId}${suffix}`, { body });
|
|
1177
1301
|
if (!res.ok) {
|
|
1178
|
-
const readOnly = target.role === "coach" && (res.status === 401 || res.status === 403) ? ` Athlete ${target.athleteId} appears to be read-only for
|
|
1179
|
-
throw new Error(`Failed to
|
|
1302
|
+
const readOnly = target.role === "coach" && (res.status === 401 || res.status === 403) ? ` Athlete ${target.athleteId} appears to be read-only for changes — TrainHeroic's seeded demo/sample athletes return ${res.status} here; writes only persist for real (invited) athletes.` : "";
|
|
1303
|
+
throw new Error(`Failed to write exercise ${result.savedWorkoutSetExerciseId} (HTTP ${res.status}).${readOnly}`);
|
|
1180
1304
|
}
|
|
1181
|
-
|
|
1305
|
+
exercisesWritten += 1;
|
|
1306
|
+
}
|
|
1307
|
+
if (mode === "log") {
|
|
1308
|
+
const setBody = {
|
|
1309
|
+
...buildSetCompletePayload(rawSet, exercises.map((e) => coerceInt(e.id)).filter((n) => n !== null), true),
|
|
1310
|
+
...extra
|
|
1311
|
+
};
|
|
1312
|
+
const setRes = await client.request("PUT", `/1.0/${target.role}/savedworkoutset/${savedWorkoutSetId}${suffix}`, { body: setBody });
|
|
1313
|
+
if (!setRes.ok) throw new Error(`Failed to mark workout set ${savedWorkoutSetId} completed (HTTP ${setRes.status}).`);
|
|
1182
1314
|
}
|
|
1183
|
-
const setBody = {
|
|
1184
|
-
...buildSetCompletePayload(rawSet, exercises.map((e) => coerceInt(e.id)).filter((n) => n !== null), true),
|
|
1185
|
-
...extra
|
|
1186
|
-
};
|
|
1187
|
-
const setRes = await client.request("PUT", `/1.0/${target.role}/savedworkoutset/${savedWorkoutSetId}${suffix}`, { body: setBody });
|
|
1188
|
-
if (!setRes.ok) throw new Error(`Failed to mark workout set ${savedWorkoutSetId} completed (HTTP ${setRes.status}).`);
|
|
1189
1315
|
return {
|
|
1190
1316
|
savedWorkoutSetId,
|
|
1191
|
-
|
|
1317
|
+
exercisesWritten
|
|
1192
1318
|
};
|
|
1193
1319
|
}
|
|
1194
1320
|
/**
|
|
@@ -2393,11 +2519,24 @@ Coach — manage a roster (needs a coach account):
|
|
|
2393
2519
|
coach log-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson>|--file f --yes
|
|
2394
2520
|
--date is the workout's SCHEDULED date (not necessarily today); get --set (savedWorkoutSetId)
|
|
2395
2521
|
and each result's savedWorkoutSetExerciseId from 'coach athlete-workouts ... --log-ids'
|
|
2522
|
+
resultsJson: [{"savedWorkoutSetExerciseId":N,"sets":[{"param1":reps,"param2":weight}, ...]}, ...]
|
|
2396
2523
|
coach log-session --athlete <id> --date Y-M-D <exercisesJson>|--file f --yes
|
|
2397
2524
|
log by exercise instead of by set id: each exercise (exerciseId + sets) is matched to a set
|
|
2398
2525
|
already on the athlete's calendar that day. The API can't put an off-plan session on an
|
|
2399
2526
|
athlete's calendar, so an unprescribed exercise fails (it names what IS prescribed).
|
|
2400
2527
|
JSON is the exercises array: [{"exerciseId":N,"sets":[{"param1":reps,"param2":weight}, ...]}, ...]
|
|
2528
|
+
coach swap-exercise --set-exercise <savedWorkoutSetExerciseId> --exercise <exerciseId> --yes
|
|
2529
|
+
swap one exercise in the athlete's scheduled workout for a different one, that athlete only
|
|
2530
|
+
(the team prescription stays put). Get --set-exercise from 'coach athlete-workouts ... --log-ids'
|
|
2531
|
+
and --exercise from 'coach exercise resolve/search'.
|
|
2532
|
+
|
|
2533
|
+
prescribe weights/reps for an athlete (set their targets WITHOUT marking the set done; that athlete only):
|
|
2534
|
+
coach prescribe-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson>|--file f --yes
|
|
2535
|
+
set the prescribed values on a scheduled set; the set stays open for the athlete to log against,
|
|
2536
|
+
and the team prescription is untouched. param1 is reps, param2 is weight; one sets[] entry per
|
|
2537
|
+
prescribed set, and the write REPLACES the slot's prescription (an omitted param clears it).
|
|
2538
|
+
resultsJson: [{"savedWorkoutSetExerciseId":N,"sets":[{"param1":reps,"param2":weight}, ...]}, ...]
|
|
2539
|
+
Same ids as log-set, from 'coach athlete-workouts ... --log-ids'. Use log-set to record a set as PERFORMED.
|
|
2401
2540
|
|
|
2402
2541
|
roster management:
|
|
2403
2542
|
coach athlete-invite --team <id> --emails a@x,b@y [--message "..."] --yes
|
|
@@ -2782,19 +2921,10 @@ async function cmdAthleteLogSet(client, a) {
|
|
|
2782
2921
|
results: await jsonInput(positionals[0], values.file)
|
|
2783
2922
|
}, "log-set args");
|
|
2784
2923
|
if (values.yes !== true) fail(`logging to set ${savedWorkoutSetId} writes to your coach-visible log; add --yes.`);
|
|
2785
|
-
const mapped = args.results.map((r) => ({
|
|
2786
|
-
savedWorkoutSetExerciseId: toInt(String(r.savedWorkoutSetExerciseId), "savedWorkoutSetExerciseId"),
|
|
2787
|
-
sets: r.sets.map((s) => {
|
|
2788
|
-
const slot = {};
|
|
2789
|
-
if (s.param1 !== void 0) slot.param1 = s.param1;
|
|
2790
|
-
if (s.param2 !== void 0) slot.param2 = s.param2;
|
|
2791
|
-
return slot;
|
|
2792
|
-
})
|
|
2793
|
-
}));
|
|
2794
2924
|
return out(await logAthleteSet(client, {
|
|
2795
2925
|
date: args.date,
|
|
2796
2926
|
savedWorkoutSetId,
|
|
2797
|
-
results:
|
|
2927
|
+
results: toSetResults(args.results)
|
|
2798
2928
|
}));
|
|
2799
2929
|
}
|
|
2800
2930
|
const LOG_SESSION_USAGE = "athlete log-session --date Y-M-D <exercisesJson>|--file f --yes";
|
|
@@ -2947,7 +3077,7 @@ async function cmdInstallSkill() {
|
|
|
2947
3077
|
}
|
|
2948
3078
|
out({ installed });
|
|
2949
3079
|
}
|
|
2950
|
-
const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|analytics|program <id>|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|athlete-workouts|log-set|log-session|athlete-invite|athlete-archive|athlete-restore|team-create|team-update|team-delete|team-code-create|team-code-delete|session-copy|session-unpublish|session-save-template|analytics-query|exercise|workout|message>";
|
|
3080
|
+
const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|analytics|program <id>|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|athlete-workouts|log-set|log-session|prescribe-set|swap-exercise|athlete-invite|athlete-archive|athlete-restore|team-create|team-update|team-delete|team-code-create|team-code-delete|session-copy|session-unpublish|session-save-template|analytics-query|exercise|workout|message>";
|
|
2951
3081
|
const COACH_LOG_SET_USAGE = "coach log-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson> --yes";
|
|
2952
3082
|
async function cmdCoachLogSet(client, a) {
|
|
2953
3083
|
const { values, positionals } = parse(a, {
|
|
@@ -2967,20 +3097,37 @@ async function cmdCoachLogSet(client, a) {
|
|
|
2967
3097
|
results: await jsonInput(positionals[0], values.file)
|
|
2968
3098
|
}, "coach log-set args");
|
|
2969
3099
|
if (values.yes !== true) fail(`logging to athlete ${athleteId}'s set ${savedWorkoutSetId} writes to their training log; add --yes.`);
|
|
2970
|
-
const mapped = args.results.map((r) => ({
|
|
2971
|
-
savedWorkoutSetExerciseId: toInt(String(r.savedWorkoutSetExerciseId), "savedWorkoutSetExerciseId"),
|
|
2972
|
-
sets: r.sets.map((s) => {
|
|
2973
|
-
const slot = {};
|
|
2974
|
-
if (s.param1 !== void 0) slot.param1 = s.param1;
|
|
2975
|
-
if (s.param2 !== void 0) slot.param2 = s.param2;
|
|
2976
|
-
return slot;
|
|
2977
|
-
})
|
|
2978
|
-
}));
|
|
2979
3100
|
return out(await logForAthlete(client, {
|
|
2980
3101
|
athleteId,
|
|
2981
3102
|
date: args.date,
|
|
2982
3103
|
savedWorkoutSetId,
|
|
2983
|
-
results:
|
|
3104
|
+
results: toSetResults(args.results)
|
|
3105
|
+
}));
|
|
3106
|
+
}
|
|
3107
|
+
const COACH_PRESCRIBE_SET_USAGE = "coach prescribe-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson>|--file f --yes";
|
|
3108
|
+
async function cmdCoachPrescribeSet(client, a) {
|
|
3109
|
+
const { values, positionals } = parse(a, {
|
|
3110
|
+
athlete: { type: "string" },
|
|
3111
|
+
date: { type: "string" },
|
|
3112
|
+
set: { type: "string" },
|
|
3113
|
+
file: { type: "string" },
|
|
3114
|
+
yes: { type: "boolean" }
|
|
3115
|
+
});
|
|
3116
|
+
const athleteId = toInt(need(values.athlete, COACH_PRESCRIBE_SET_USAGE), "--athlete");
|
|
3117
|
+
const date = isoDate(need(values.date, COACH_PRESCRIBE_SET_USAGE), "--date");
|
|
3118
|
+
const savedWorkoutSetId = toInt(need(values.set, COACH_PRESCRIBE_SET_USAGE), "--set");
|
|
3119
|
+
const args = validate(coachPrescribeSetArgsSchema, {
|
|
3120
|
+
athleteId,
|
|
3121
|
+
date,
|
|
3122
|
+
savedWorkoutSetId,
|
|
3123
|
+
results: await jsonInput(positionals[0], values.file)
|
|
3124
|
+
}, "coach prescribe-set args");
|
|
3125
|
+
if (values.yes !== true) fail(`prescribing to athlete ${athleteId}'s set ${savedWorkoutSetId} changes their plan; add --yes.`);
|
|
3126
|
+
return out(await prescribeForAthlete(client, {
|
|
3127
|
+
athleteId,
|
|
3128
|
+
date: args.date,
|
|
3129
|
+
savedWorkoutSetId,
|
|
3130
|
+
results: toSetResults(args.results)
|
|
2984
3131
|
}));
|
|
2985
3132
|
}
|
|
2986
3133
|
const COACH_LOG_SESSION_USAGE = "coach log-session --athlete <id> --date Y-M-D <exercisesJson>|--file f --yes";
|
|
@@ -3004,6 +3151,25 @@ async function cmdCoachLogSession(client, a) {
|
|
|
3004
3151
|
exercises: toSessionExercises(args.exercises)
|
|
3005
3152
|
}));
|
|
3006
3153
|
}
|
|
3154
|
+
const COACH_SWAP_EXERCISE_USAGE = "coach swap-exercise --set-exercise <savedWorkoutSetExerciseId> --exercise <exerciseId> --yes";
|
|
3155
|
+
async function cmdCoachSwapExercise(client, a) {
|
|
3156
|
+
const { values } = parse(a, {
|
|
3157
|
+
"set-exercise": { type: "string" },
|
|
3158
|
+
exercise: { type: "string" },
|
|
3159
|
+
yes: { type: "boolean" }
|
|
3160
|
+
});
|
|
3161
|
+
const savedWorkoutSetExerciseId = toInt(need(values["set-exercise"], COACH_SWAP_EXERCISE_USAGE), "--set-exercise");
|
|
3162
|
+
const exerciseId = toInt(need(values.exercise, COACH_SWAP_EXERCISE_USAGE), "--exercise");
|
|
3163
|
+
validate(swapAthleteExerciseArgsSchema, {
|
|
3164
|
+
savedWorkoutSetExerciseId,
|
|
3165
|
+
exerciseId
|
|
3166
|
+
}, "coach swap-exercise args");
|
|
3167
|
+
if (values.yes !== true) fail(`swapping slot ${savedWorkoutSetExerciseId} changes what the athlete is prescribed; add --yes.`);
|
|
3168
|
+
return out(await swapAthleteExercise(client, {
|
|
3169
|
+
savedWorkoutSetExerciseId,
|
|
3170
|
+
exerciseId
|
|
3171
|
+
}));
|
|
3172
|
+
}
|
|
3007
3173
|
async function cmdCoachTeamVolume(client, a) {
|
|
3008
3174
|
const usage = "coach team-volume (--team <id> | --athletes <id,id,...>) --start Y-M-D --end Y-M-D";
|
|
3009
3175
|
const { values } = parse(a, {
|
|
@@ -3246,6 +3412,8 @@ async function cmdCoach(client, rest) {
|
|
|
3246
3412
|
case "athlete-workouts": return cmdCoachAthleteWorkouts(client, a);
|
|
3247
3413
|
case "log-set": return cmdCoachLogSet(client, a);
|
|
3248
3414
|
case "log-session": return cmdCoachLogSession(client, a);
|
|
3415
|
+
case "prescribe-set": return cmdCoachPrescribeSet(client, a);
|
|
3416
|
+
case "swap-exercise": return cmdCoachSwapExercise(client, a);
|
|
3249
3417
|
case "athlete-invite": return cmdCoachAthleteInvite(client, a);
|
|
3250
3418
|
case "athlete-archive": return cmdCoachAthleteArchive(client, a);
|
|
3251
3419
|
case "athlete-restore": return cmdCoachAthleteRestore(client, a);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/dto": "1.
|
|
25
|
-
"@trainheroic-unofficial/js": "1.
|
|
24
|
+
"@trainheroic-unofficial/dto": "1.2.0",
|
|
25
|
+
"@trainheroic-unofficial/js": "1.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.0.0",
|