@trainheroic-unofficial/cli 3.1.1 → 3.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
CHANGED
|
@@ -317,6 +317,12 @@ const programCreateResponseSchema = z.looseObject({
|
|
|
317
317
|
program_type: intLike
|
|
318
318
|
}).optional()
|
|
319
319
|
});
|
|
320
|
+
const teamPublishPatchSchema = z.object({
|
|
321
|
+
pub_enabled: z.union([z.number(), z.boolean()]).optional(),
|
|
322
|
+
pub_days: z.unknown().optional(),
|
|
323
|
+
pub_time: z.unknown().optional(),
|
|
324
|
+
pub_timezone: z.string().optional()
|
|
325
|
+
}).refine((v) => v.pub_enabled !== void 0 || v.pub_days !== void 0 || v.pub_time !== void 0 || v.pub_timezone !== void 0, { message: "Provide at least one pub_* field" });
|
|
320
326
|
//#endregion
|
|
321
327
|
//#region ../dto/src/workout.ts
|
|
322
328
|
/** A single exercise prescription inside a block. */
|
|
@@ -384,6 +390,11 @@ function parseWorkoutDate(s) {
|
|
|
384
390
|
parts[2]
|
|
385
391
|
];
|
|
386
392
|
}
|
|
393
|
+
/** Body for `POST /v5/sessions/template` (library create, not save-from-session). */
|
|
394
|
+
const sessionTemplateCreateSchema = z.object({
|
|
395
|
+
title: z.string().min(1),
|
|
396
|
+
instruction: z.string().optional()
|
|
397
|
+
});
|
|
387
398
|
//#endregion
|
|
388
399
|
//#region ../js/src/http-error.ts
|
|
389
400
|
/**
|
|
@@ -851,6 +862,15 @@ function fetchWorkingMaxes(client) {
|
|
|
851
862
|
function fetchExerciseHistoryList(client) {
|
|
852
863
|
return getArray$1(client, "/v5/users/exercises/history", "athlete exercise history list");
|
|
853
864
|
}
|
|
865
|
+
function fetchRecentExercises(client) {
|
|
866
|
+
return getArray$1(client, "/v5/users/exercises/recent", "athlete recent exercises");
|
|
867
|
+
}
|
|
868
|
+
function fetchAthleteCircuits(client, kind = "recent") {
|
|
869
|
+
return getArray$1(client, `/v5/users/circuits/${kind}`, `athlete ${kind} circuits`);
|
|
870
|
+
}
|
|
871
|
+
function fetchAthleteProgrammingPrograms(client) {
|
|
872
|
+
return getArray$1(client, "/1.0/athlete/programming/programs", "athlete programming programs");
|
|
873
|
+
}
|
|
854
874
|
/** Free-text search over the athlete's logged exercises (FTS replacement via rankSearch). */
|
|
855
875
|
async function searchExerciseHistory(client, query, limit = 20) {
|
|
856
876
|
return rankSearch(await fetchExerciseHistoryList(client), query, limit);
|
|
@@ -2231,6 +2251,22 @@ function serializeWorkoutHistory(workouts, format, opts = {}) {
|
|
|
2231
2251
|
};
|
|
2232
2252
|
}
|
|
2233
2253
|
//#endregion
|
|
2254
|
+
//#region ../js/src/util.ts
|
|
2255
|
+
/**
|
|
2256
|
+
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
2257
|
+
* spread into an object under `exactOptionalPropertyTypes` without the per-key
|
|
2258
|
+
* `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
|
|
2259
|
+
* optional ones lose `undefined` from their value type.
|
|
2260
|
+
*
|
|
2261
|
+
* Example:
|
|
2262
|
+
* definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
|
|
2263
|
+
*/
|
|
2264
|
+
function definedProps(obj) {
|
|
2265
|
+
const result = {};
|
|
2266
|
+
for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
|
|
2267
|
+
return result;
|
|
2268
|
+
}
|
|
2269
|
+
//#endregion
|
|
2234
2270
|
//#region ../js/src/workout-encode.ts
|
|
2235
2271
|
const LEADERBOARD_TYPE = {
|
|
2236
2272
|
completion: 0,
|
|
@@ -2623,6 +2659,45 @@ async function createProgram(client, args) {
|
|
|
2623
2659
|
nameApplied: title === requestedName
|
|
2624
2660
|
};
|
|
2625
2661
|
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Delete a standalone program (`DELETE /v5/programs/{programId}`).
|
|
2664
|
+
*
|
|
2665
|
+
* The live API 401s when the path id is a list_programs container id. Pass either id: this
|
|
2666
|
+
* resolves a container to its `group_program` first. Team calendars are not in that list; their
|
|
2667
|
+
* program id is deleted as given. This is not idempotent against an unknown failure.
|
|
2668
|
+
*/
|
|
2669
|
+
async function deleteProgram(client, programId) {
|
|
2670
|
+
if (!Number.isInteger(programId) || programId <= 0) throw new Error("Program id must be a positive integer.");
|
|
2671
|
+
const programs = await client.request("GET", "/1.0/coach/programs");
|
|
2672
|
+
if (!programs.ok || !Array.isArray(programs.data)) {
|
|
2673
|
+
const detail = typeof programs.data === "string" ? programs.data : JSON.stringify(programs.data);
|
|
2674
|
+
throw new Error(`GET /1.0/coach/programs failed (HTTP ${programs.status}): ${detail}`);
|
|
2675
|
+
}
|
|
2676
|
+
let targetId = programId;
|
|
2677
|
+
let containerId = null;
|
|
2678
|
+
for (const item of programs.data) {
|
|
2679
|
+
if (!isRecord(item)) continue;
|
|
2680
|
+
const groupProgram = coerceInt(item.group_program);
|
|
2681
|
+
if (coerceInt(item.id) === programId && groupProgram !== null) {
|
|
2682
|
+
containerId = programId;
|
|
2683
|
+
targetId = groupProgram;
|
|
2684
|
+
break;
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
const res = await client.request("DELETE", `/v5/programs/${targetId}`, { expectedStatuses: [
|
|
2688
|
+
401,
|
|
2689
|
+
403,
|
|
2690
|
+
404
|
|
2691
|
+
] });
|
|
2692
|
+
if (!res.ok) {
|
|
2693
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
2694
|
+
throw new Error(`Program delete failed (HTTP ${res.status}): ${detail}`);
|
|
2695
|
+
}
|
|
2696
|
+
return {
|
|
2697
|
+
programId: targetId,
|
|
2698
|
+
containerId
|
|
2699
|
+
};
|
|
2700
|
+
}
|
|
2626
2701
|
/** Normalize one-or-many emails into a deduped, trimmed list. */
|
|
2627
2702
|
function emailList(emails) {
|
|
2628
2703
|
return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
|
|
@@ -2720,6 +2795,52 @@ async function updateTeam(client, args) {
|
|
|
2720
2795
|
}
|
|
2721
2796
|
return res.data;
|
|
2722
2797
|
}
|
|
2798
|
+
/** Collapse the MCP/CLI XOR flags into a single publish target. */
|
|
2799
|
+
function teamPublishTarget(ids) {
|
|
2800
|
+
if (ids.programId !== void 0 && ids.teamId !== void 0) throw new Error("Pass programId or teamId, not both.");
|
|
2801
|
+
if (ids.programId !== void 0) return { programId: ids.programId };
|
|
2802
|
+
if (ids.teamId !== void 0) return { teamId: ids.teamId };
|
|
2803
|
+
throw new Error("Pass programId or teamId.");
|
|
2804
|
+
}
|
|
2805
|
+
async function programIdForTeam(client, teamId) {
|
|
2806
|
+
if (teamId <= 0) throw new Error("teamId must be positive.");
|
|
2807
|
+
const team = await client.request("GET", `/v5/teams/${teamId}`);
|
|
2808
|
+
if (!team.ok || !isRecord(team.data)) {
|
|
2809
|
+
const detail = typeof team.data === "string" ? team.data : JSON.stringify(team.data);
|
|
2810
|
+
throw new Error(`GET /v5/teams/${teamId} failed (HTTP ${team.status}): ${detail}`);
|
|
2811
|
+
}
|
|
2812
|
+
const resolved = coerceInt(team.data.group_program) ?? coerceInt(team.data.programId);
|
|
2813
|
+
if (resolved === null || resolved <= 0) throw new Error(`Team ${teamId} has no group_program.`);
|
|
2814
|
+
return resolved;
|
|
2815
|
+
}
|
|
2816
|
+
async function resolvePublishProgramId(client, target) {
|
|
2817
|
+
if ("programId" in target) return target.programId;
|
|
2818
|
+
return programIdForTeam(client, target.teamId);
|
|
2819
|
+
}
|
|
2820
|
+
/**
|
|
2821
|
+
* Update a team's auto-publish settings (`POST /1.0/coach/team/updatePublishSettings`).
|
|
2822
|
+
* The live API 500s on a partial body; it wants the full program object from
|
|
2823
|
+
* `GET /3.0/coach/program/{programId}` with `pub_*` fields merged on top.
|
|
2824
|
+
*/
|
|
2825
|
+
async function updateTeamPublishSettings(client, args) {
|
|
2826
|
+
if (Object.keys(args.patch).length === 0) throw new Error("Provide at least one pub_* field to change.");
|
|
2827
|
+
const programId = await resolvePublishProgramId(client, args);
|
|
2828
|
+
if (programId <= 0) throw new Error("programId must be positive.");
|
|
2829
|
+
const current = await client.request("GET", `/3.0/coach/program/${programId}`);
|
|
2830
|
+
if (!current.ok || !isRecord(current.data)) {
|
|
2831
|
+
const detail = typeof current.data === "string" ? current.data : JSON.stringify(current.data);
|
|
2832
|
+
throw new Error(`GET /3.0/coach/program/${programId} failed (HTTP ${current.status}): ${detail}`);
|
|
2833
|
+
}
|
|
2834
|
+
const res = await client.request("POST", "/1.0/coach/team/updatePublishSettings", { body: {
|
|
2835
|
+
...current.data,
|
|
2836
|
+
...args.patch
|
|
2837
|
+
} });
|
|
2838
|
+
if (!res.ok) {
|
|
2839
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
2840
|
+
throw new Error(`updatePublishSettings failed (HTTP ${res.status}): ${detail}`);
|
|
2841
|
+
}
|
|
2842
|
+
return res.data;
|
|
2843
|
+
}
|
|
2723
2844
|
/**
|
|
2724
2845
|
* Copy/repeat a session to a target date on a program (`POST /2.0/coach/calendar/copyProgramWorkout`).
|
|
2725
2846
|
* The API wants the target date as a structured object (with weekday and an isToday flag),
|
|
@@ -2971,6 +3092,23 @@ async function teamVolume(client, args) {
|
|
|
2971
3092
|
totals
|
|
2972
3093
|
};
|
|
2973
3094
|
}
|
|
3095
|
+
/** Create a reusable session template in the coach library (`POST /v5/sessions/template`). */
|
|
3096
|
+
async function createSessionTemplate(client, args) {
|
|
3097
|
+
const title = args.title.trim();
|
|
3098
|
+
if (title === "") throw new Error("Session template title must not be blank.");
|
|
3099
|
+
const res = await client.request("POST", "/v5/sessions/template", { body: definedProps({
|
|
3100
|
+
title,
|
|
3101
|
+
instruction: args.instruction
|
|
3102
|
+
}) });
|
|
3103
|
+
if (!res.ok) {
|
|
3104
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
3105
|
+
throw new Error(`Session template create failed (HTTP ${res.status}): ${detail}`);
|
|
3106
|
+
}
|
|
3107
|
+
if (!isRecord(res.data) || coerceInt(res.data.id) === null) throw new Error("Session template create response is missing an id.");
|
|
3108
|
+
return res.data;
|
|
3109
|
+
}
|
|
3110
|
+
/** First page of the coach session-template library (`GET /1.0/coach/workouts`). */
|
|
3111
|
+
const SESSION_TEMPLATES_LIST_PATH = "/1.0/coach/workouts?page=1&pageSize=50";
|
|
2974
3112
|
//#endregion
|
|
2975
3113
|
//#region ../js/src/main-lifts.ts
|
|
2976
3114
|
/**
|
|
@@ -3179,22 +3317,6 @@ async function fetchRosterMainLiftPRs(client, opts = {}) {
|
|
|
3179
3317
|
});
|
|
3180
3318
|
}
|
|
3181
3319
|
//#endregion
|
|
3182
|
-
//#region ../js/src/util.ts
|
|
3183
|
-
/**
|
|
3184
|
-
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
3185
|
-
* spread into an object under `exactOptionalPropertyTypes` without the per-key
|
|
3186
|
-
* `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
|
|
3187
|
-
* optional ones lose `undefined` from their value type.
|
|
3188
|
-
*
|
|
3189
|
-
* Example:
|
|
3190
|
-
* definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
|
|
3191
|
-
*/
|
|
3192
|
-
function definedProps(obj) {
|
|
3193
|
-
const result = {};
|
|
3194
|
-
for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
|
|
3195
|
-
return result;
|
|
3196
|
-
}
|
|
3197
|
-
//#endregion
|
|
3198
3320
|
//#region ../js/src/messaging.ts
|
|
3199
3321
|
const BUCKETS = [
|
|
3200
3322
|
["team", "teams"],
|
|
@@ -3266,6 +3388,8 @@ var MemoryLibraryCache = class {
|
|
|
3266
3388
|
//#region ../js/src/exercise-index.ts
|
|
3267
3389
|
const LIBRARY_PATH = "/v5/exerciseLibrary/all";
|
|
3268
3390
|
const CREATE_PATH = "/2.0/coach/exercise/create";
|
|
3391
|
+
const UPDATE_PATH = (id) => `/2.0/coach/exercise/update/${id}`;
|
|
3392
|
+
const DELETE_PATH = (id) => `/v5/exercises/${id}`;
|
|
3269
3393
|
const TTL_MS$1 = 6048e5;
|
|
3270
3394
|
function toStored(ex) {
|
|
3271
3395
|
const id = coerceInt(ex.id);
|
|
@@ -3394,12 +3518,18 @@ var ExerciseLibrary = class {
|
|
|
3394
3518
|
};
|
|
3395
3519
|
}
|
|
3396
3520
|
async create(body) {
|
|
3521
|
+
return this.#writeThrough(CREATE_PATH, body, "create");
|
|
3522
|
+
}
|
|
3523
|
+
async update(id, body) {
|
|
3524
|
+
return this.#writeThrough(UPDATE_PATH(id), body, "update");
|
|
3525
|
+
}
|
|
3526
|
+
async #writeThrough(path, body, label) {
|
|
3397
3527
|
await this.ensureFresh();
|
|
3398
|
-
const res = await this.#client.request("POST",
|
|
3399
|
-
if (!res.ok) throw new Error(`Exercise
|
|
3528
|
+
const res = await this.#client.request("POST", path, { body });
|
|
3529
|
+
if (!res.ok) throw new Error(`Exercise ${label} failed (HTTP ${res.status}).`);
|
|
3400
3530
|
const ex = unwrapEnvelope(res.data);
|
|
3401
3531
|
if (ex && typeof ex === "object") {
|
|
3402
|
-
checkResponse(exerciseResponseSchema, ex,
|
|
3532
|
+
checkResponse(exerciseResponseSchema, ex, `exercise ${label}`);
|
|
3403
3533
|
const s = toStored(ex);
|
|
3404
3534
|
if (s) {
|
|
3405
3535
|
this.#byId.set(s.id, s);
|
|
@@ -3408,6 +3538,15 @@ var ExerciseLibrary = class {
|
|
|
3408
3538
|
}
|
|
3409
3539
|
return ex;
|
|
3410
3540
|
}
|
|
3541
|
+
async remove(id) {
|
|
3542
|
+
const res = await this.#client.request("DELETE", DELETE_PATH(id), { expectedStatuses: [
|
|
3543
|
+
401,
|
|
3544
|
+
403,
|
|
3545
|
+
404
|
|
3546
|
+
] });
|
|
3547
|
+
if (!res.ok) throw new Error(`Exercise delete failed (HTTP ${res.status}).`);
|
|
3548
|
+
await this.recordDelete(id);
|
|
3549
|
+
}
|
|
3411
3550
|
async recordDelete(id) {
|
|
3412
3551
|
await this.ensureFresh();
|
|
3413
3552
|
if (this.#byId.delete(id)) await this.#persist();
|
|
@@ -3538,8 +3677,10 @@ Coach — manage a roster (needs a coach account):
|
|
|
3538
3677
|
|
|
3539
3678
|
teams & join codes:
|
|
3540
3679
|
coach program-create --kind calendar|fixed --name "..."
|
|
3680
|
+
coach program-delete --program <id> --yes
|
|
3541
3681
|
coach team-create --title "..."
|
|
3542
3682
|
coach team-update --team <id> [--title "..."] [--group-program <id>]
|
|
3683
|
+
coach team-publish-settings (--team <id> | --program <id>) [--pub-enabled 0|1] --yes
|
|
3543
3684
|
coach team-delete --team <id> --yes
|
|
3544
3685
|
coach team-code-create --team <id> [--type N]
|
|
3545
3686
|
coach team-code-delete --code <id> --yes (--code is the id from team-code-create, not the join-code number)
|
|
@@ -3548,6 +3689,9 @@ Coach — manage a roster (needs a coach account):
|
|
|
3548
3689
|
coach session-copy --to-program <id> --pw <id> --to-date Y-M-D
|
|
3549
3690
|
coach session-unpublish --pw <id> --yes
|
|
3550
3691
|
coach session-save-template --workout <id>
|
|
3692
|
+
coach session-templates
|
|
3693
|
+
coach session-template-create --title "..." [--instruction "..."]
|
|
3694
|
+
coach session-template-delete --id <id> --yes
|
|
3551
3695
|
|
|
3552
3696
|
analytics (curated metrics; for team training volume/recency use roster-activity --metric instead):
|
|
3553
3697
|
coach analytics-query [--metric <key>] [--team <id>] [--users id,id] [--exercise <id>] [--date|--start|--end Y-M-D] [--use-metric]
|
|
@@ -3560,6 +3704,8 @@ Coach — manage a roster (needs a coach account):
|
|
|
3560
3704
|
coach exercise get <id>
|
|
3561
3705
|
coach exercise sync [--force]
|
|
3562
3706
|
coach exercise create <json>|--file f
|
|
3707
|
+
coach exercise update <id> <json>|--file f
|
|
3708
|
+
coach exercise delete <id> --yes
|
|
3563
3709
|
coach exercise forget <id> --yes
|
|
3564
3710
|
coach exercise stats
|
|
3565
3711
|
|
|
@@ -3582,6 +3728,9 @@ Athlete — the logged-in user's own training (a coach account works too):
|
|
|
3582
3728
|
athlete workouts --start Y-M-D --end Y-M-D [--raw] [--logged-only] [--limit N] [--summary] [--format json|csv|text] (reads what you did; --format exports history with reps/weight broken out; for the log ids use 'athlete log-targets')
|
|
3583
3729
|
athlete log-targets --start Y-M-D --end Y-M-D [--program <title>|--program-id <id>|--team <id>] [--raw] (the savedWorkoutSetId + savedWorkoutSetExerciseId log-set needs; --program narrows when several workouts share a date)
|
|
3584
3730
|
athlete exercises [--q <text>] [--limit N]
|
|
3731
|
+
athlete recent-exercises
|
|
3732
|
+
athlete circuits [--kind recent|history]
|
|
3733
|
+
athlete programs
|
|
3585
3734
|
athlete history <exerciseId> [--raw]
|
|
3586
3735
|
athlete prs <exerciseId>
|
|
3587
3736
|
athlete stats <exerciseId> --date Y-M-D
|
|
@@ -3702,6 +3851,20 @@ async function cmdExercise(client, rest) {
|
|
|
3702
3851
|
const exercise = validate(exerciseCreateSchema, body, "exercise");
|
|
3703
3852
|
return out(await lib.create(exercise));
|
|
3704
3853
|
}
|
|
3854
|
+
case "update": {
|
|
3855
|
+
const { values, positionals } = parse(a, { file: { type: "string" } });
|
|
3856
|
+
const id = toInt(need(positionals[0], "coach exercise update <id> <json>|--file f"), "id");
|
|
3857
|
+
const body = await jsonInput(positionals[1], values.file);
|
|
3858
|
+
const exercise = validate(exerciseCreateSchema, body, "exercise");
|
|
3859
|
+
return out(await lib.update(id, exercise));
|
|
3860
|
+
}
|
|
3861
|
+
case "delete": {
|
|
3862
|
+
const { values, positionals } = parse(a, { yes: { type: "boolean" } });
|
|
3863
|
+
const id = toInt(need(positionals[0], "coach exercise delete <id> --yes"), "id");
|
|
3864
|
+
if (values.yes !== true) fail(`add --yes to delete exercise ${id} from TrainHeroic.`);
|
|
3865
|
+
await lib.remove(id);
|
|
3866
|
+
return out({ deleted: id });
|
|
3867
|
+
}
|
|
3705
3868
|
case "forget": {
|
|
3706
3869
|
const { values, positionals } = parse(a, { yes: { type: "boolean" } });
|
|
3707
3870
|
const id = toInt(need(positionals[0], "coach exercise forget <id> --yes"), "id");
|
|
@@ -3710,7 +3873,7 @@ async function cmdExercise(client, rest) {
|
|
|
3710
3873
|
return out({ forgotten: id });
|
|
3711
3874
|
}
|
|
3712
3875
|
case "stats": return out(await lib.stats());
|
|
3713
|
-
default: return fail("usage: trainheroic coach exercise <resolve|search|get|sync|create|forget|stats>");
|
|
3876
|
+
default: return fail("usage: trainheroic coach exercise <resolve|search|get|sync|create|update|delete|forget|stats>");
|
|
3714
3877
|
}
|
|
3715
3878
|
}
|
|
3716
3879
|
async function cmdWorkoutBuild(client, a) {
|
|
@@ -4114,6 +4277,14 @@ async function cmdAthlete(client, rest) {
|
|
|
4114
4277
|
const q = values.q;
|
|
4115
4278
|
return out(q !== void 0 ? await searchExerciseHistory(client, q, limit) : await fetchExerciseHistoryList(client));
|
|
4116
4279
|
}
|
|
4280
|
+
case "recent-exercises": return out(await fetchRecentExercises(client));
|
|
4281
|
+
case "circuits": {
|
|
4282
|
+
const { values } = parse(a, { kind: { type: "string" } });
|
|
4283
|
+
const kind = values.kind ?? "recent";
|
|
4284
|
+
if (kind !== "recent" && kind !== "history") fail("athlete circuits --kind recent|history");
|
|
4285
|
+
return out(await fetchAthleteCircuits(client, kind));
|
|
4286
|
+
}
|
|
4287
|
+
case "programs": return out(await fetchAthleteProgrammingPrograms(client));
|
|
4117
4288
|
case "history": {
|
|
4118
4289
|
const { values, positionals } = parse(a, { raw: { type: "boolean" } });
|
|
4119
4290
|
const detail = await fetchExerciseHistoryDetail(client, toInt(need(positionals[0], "athlete history <exerciseId>"), "exerciseId"), await resolveAthleteUserId(client));
|
|
@@ -4147,7 +4318,7 @@ async function cmdAthlete(client, rest) {
|
|
|
4147
4318
|
case "log-session": return cmdAthleteLogSession(client, a);
|
|
4148
4319
|
case "session-remove": return cmdAthleteSessionRemove(client, a);
|
|
4149
4320
|
case "swap-exercise": return cmdAthleteSwapExercise(client, a);
|
|
4150
|
-
default: return fail("usage: trainheroic athlete <whoami|profile|prefs|workouts|log-targets|exercises|history|prs|stats|working-maxes|leaderboard|export|log-set|prescribe-set|log-session|session-remove|swap-exercise>");
|
|
4321
|
+
default: return fail("usage: trainheroic athlete <whoami|profile|prefs|workouts|log-targets|exercises|recent-exercises|circuits|programs|history|prs|stats|working-maxes|leaderboard|export|log-set|prescribe-set|log-session|session-remove|swap-exercise>");
|
|
4151
4322
|
}
|
|
4152
4323
|
}
|
|
4153
4324
|
async function cmdSkill(rest) {
|
|
@@ -4191,7 +4362,7 @@ async function cmdInstallSkill() {
|
|
|
4191
4362
|
}
|
|
4192
4363
|
out({ installed });
|
|
4193
4364
|
}
|
|
4194
|
-
const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|analytics|program <id>|program-create|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|main-lift-prs|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>";
|
|
4365
|
+
const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|notifications-list|subscriptions|prescription-templates|analytics|program <id>|program-create|program-delete|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|athlete-team-calendar|main-lift-prs|athlete-workouts|log-set|log-session|prescribe-set|swap-exercise|athlete-invite|athlete-archive|athlete-restore|team-create|team-update|team-publish-settings|team-delete|team-code-create|team-code-delete|session-copy|session-unpublish|session-save-template|session-templates|session-template-create|session-template-delete|analytics-query|exercise|workout|message>";
|
|
4195
4366
|
const COACH_LOG_SET_USAGE = "coach log-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson> --yes";
|
|
4196
4367
|
async function cmdCoachLogSet(client, a) {
|
|
4197
4368
|
const { values, positionals } = parse(a, {
|
|
@@ -4393,6 +4564,16 @@ async function cmdCoachProgramCreate(client, a) {
|
|
|
4393
4564
|
name
|
|
4394
4565
|
}));
|
|
4395
4566
|
}
|
|
4567
|
+
async function cmdCoachProgramDelete(client, a) {
|
|
4568
|
+
const usage = "coach program-delete --program <id> --yes";
|
|
4569
|
+
const { values } = parse(a, {
|
|
4570
|
+
program: { type: "string" },
|
|
4571
|
+
yes: { type: "boolean" }
|
|
4572
|
+
});
|
|
4573
|
+
const programId = toInt(need(values.program, usage), "--program");
|
|
4574
|
+
if (values.yes !== true) fail(`deleting program ${programId} removes the standalone calendar; add --yes.`);
|
|
4575
|
+
return out(await deleteProgram(client, programId));
|
|
4576
|
+
}
|
|
4396
4577
|
async function cmdCoachTeamUpdate(client, a) {
|
|
4397
4578
|
const usage = "coach team-update --team <id> [--title \"...\"] [--group-program <id>] (at least one of --title / --group-program)";
|
|
4398
4579
|
const { values } = parse(a, {
|
|
@@ -4467,6 +4648,58 @@ async function cmdCoachSessionSaveTemplate(client, a) {
|
|
|
4467
4648
|
const { values } = parse(a, { workout: { type: "string" } });
|
|
4468
4649
|
return out(await mutate(client, "POST", `/2.0/coach/calendar/programWorkout/saveWorkoutAsTemplate/${toInt(need(values.workout, usage), "--workout")}`));
|
|
4469
4650
|
}
|
|
4651
|
+
async function cmdCoachSessionTemplateCreate(client, a) {
|
|
4652
|
+
const usage = "coach session-template-create --title \"...\" [--instruction \"...\"]";
|
|
4653
|
+
const { values } = parse(a, {
|
|
4654
|
+
title: { type: "string" },
|
|
4655
|
+
instruction: { type: "string" }
|
|
4656
|
+
});
|
|
4657
|
+
const title = need(values.title, usage);
|
|
4658
|
+
const instruction = values.instruction;
|
|
4659
|
+
return out(await createSessionTemplate(client, validate(sessionTemplateCreateSchema, definedProps({
|
|
4660
|
+
title,
|
|
4661
|
+
instruction
|
|
4662
|
+
}), "session template")));
|
|
4663
|
+
}
|
|
4664
|
+
async function cmdCoachSessionTemplateDelete(client, a) {
|
|
4665
|
+
const usage = "coach session-template-delete --id <id> --yes";
|
|
4666
|
+
const { values } = parse(a, {
|
|
4667
|
+
id: { type: "string" },
|
|
4668
|
+
yes: { type: "boolean" }
|
|
4669
|
+
});
|
|
4670
|
+
const id = toInt(need(values.id, usage), "--id");
|
|
4671
|
+
if (values.yes !== true) fail(`add --yes to delete session template ${id}.`);
|
|
4672
|
+
return out(await mutate(client, "DELETE", `/v5/sessions/template/${id}`));
|
|
4673
|
+
}
|
|
4674
|
+
async function cmdCoachTeamPublishSettings(client, a) {
|
|
4675
|
+
const usage = "coach team-publish-settings (--team <id> | --program <id>) [--pub-enabled 0|1] [--pub-days ...] [--pub-time ...] [--pub-timezone ...] --yes";
|
|
4676
|
+
const { values } = parse(a, {
|
|
4677
|
+
team: { type: "string" },
|
|
4678
|
+
program: { type: "string" },
|
|
4679
|
+
"pub-enabled": { type: "string" },
|
|
4680
|
+
"pub-days": { type: "string" },
|
|
4681
|
+
"pub-time": { type: "string" },
|
|
4682
|
+
"pub-timezone": { type: "string" },
|
|
4683
|
+
yes: { type: "boolean" }
|
|
4684
|
+
});
|
|
4685
|
+
const teamRaw = values.team;
|
|
4686
|
+
const programRaw = values.program;
|
|
4687
|
+
if (teamRaw === void 0 === (programRaw === void 0)) fail(usage);
|
|
4688
|
+
if (values.yes !== true) fail("changing auto-publish is athlete-facing; add --yes.");
|
|
4689
|
+
const patch = validate(teamPublishPatchSchema, definedProps({
|
|
4690
|
+
pub_enabled: values["pub-enabled"] !== void 0 ? toInt(values["pub-enabled"], "--pub-enabled") : void 0,
|
|
4691
|
+
pub_days: values["pub-days"],
|
|
4692
|
+
pub_time: values["pub-time"],
|
|
4693
|
+
pub_timezone: values["pub-timezone"]
|
|
4694
|
+
}), "publish settings");
|
|
4695
|
+
return out(await updateTeamPublishSettings(client, {
|
|
4696
|
+
...teamPublishTarget(definedProps({
|
|
4697
|
+
teamId: teamRaw !== void 0 ? toInt(teamRaw, "--team") : void 0,
|
|
4698
|
+
programId: programRaw !== void 0 ? toInt(programRaw, "--program") : void 0
|
|
4699
|
+
})),
|
|
4700
|
+
patch
|
|
4701
|
+
}));
|
|
4702
|
+
}
|
|
4470
4703
|
async function cmdCoachAnalyticsQuery(client, a) {
|
|
4471
4704
|
const { values } = parse(a, {
|
|
4472
4705
|
metric: { type: "string" },
|
|
@@ -4553,15 +4786,25 @@ async function cmdCoachMainLiftPrs(client, a) {
|
|
|
4553
4786
|
...subset ? { athleteIds: subset } : {}
|
|
4554
4787
|
}));
|
|
4555
4788
|
}
|
|
4789
|
+
const COACH_SIMPLE_GETS = {
|
|
4790
|
+
"head-coach": "/v5/headCoach",
|
|
4791
|
+
athletes: "/v5/athletes",
|
|
4792
|
+
programs: "/1.0/coach/programs",
|
|
4793
|
+
teams: "/1.0/coach/teams",
|
|
4794
|
+
notifications: "/v5/notifications/counts",
|
|
4795
|
+
"notifications-list": "/v5/notifications",
|
|
4796
|
+
subscriptions: "/1.0/coach/subscriptions",
|
|
4797
|
+
"prescription-templates": "/2.0/coach/workoutSetExercise/template",
|
|
4798
|
+
analytics: "/v5/analytics",
|
|
4799
|
+
"session-templates": SESSION_TEMPLATES_LIST_PATH
|
|
4800
|
+
};
|
|
4556
4801
|
async function cmdCoach(client, rest) {
|
|
4557
4802
|
const [sub, ...a] = rest;
|
|
4803
|
+
if (sub !== void 0) {
|
|
4804
|
+
const path = COACH_SIMPLE_GETS[sub];
|
|
4805
|
+
if (path !== void 0) return out(await get(client, path));
|
|
4806
|
+
}
|
|
4558
4807
|
switch (sub) {
|
|
4559
|
-
case "head-coach": return out(await get(client, "/v5/headCoach"));
|
|
4560
|
-
case "athletes": return out(await get(client, "/v5/athletes"));
|
|
4561
|
-
case "programs": return out(await get(client, "/1.0/coach/programs"));
|
|
4562
|
-
case "teams": return out(await get(client, "/1.0/coach/teams"));
|
|
4563
|
-
case "notifications": return out(await get(client, "/v5/notifications/counts"));
|
|
4564
|
-
case "analytics": return out(await get(client, "/v5/analytics"));
|
|
4565
4808
|
case "program": return out(await get(client, `/3.0/coach/program/${encodeURIComponent(need(a[0], "coach program <id>"))}`));
|
|
4566
4809
|
case "team": return out(await get(client, `/v5/teams/${encodeURIComponent(need(a[0], "coach team <id>"))}`));
|
|
4567
4810
|
case "team-codes": return out(await get(client, `/v5/teams/${encodeURIComponent(need(a[0], "coach team-codes <id>"))}/teamCodes`));
|
|
@@ -4569,6 +4812,10 @@ async function cmdCoach(client, rest) {
|
|
|
4569
4812
|
case "team-volume": return cmdCoachTeamVolume(client, a);
|
|
4570
4813
|
case "athlete-training": return cmdCoachAthleteTraining(client, a);
|
|
4571
4814
|
case "athlete-lift-history": return cmdCoachAthleteLiftHistory(client, a);
|
|
4815
|
+
case "athlete-team-calendar": {
|
|
4816
|
+
const { values } = parse(a, { athlete: { type: "string" } });
|
|
4817
|
+
return out(await get(client, `/v5/calendars/athletes/${toInt(need(values.athlete, "coach athlete-team-calendar --athlete <id>"), "--athlete")}/coachAthleteTeam`));
|
|
4818
|
+
}
|
|
4572
4819
|
case "main-lift-prs": return cmdCoachMainLiftPrs(client, a);
|
|
4573
4820
|
case "athlete-workouts": return cmdCoachAthleteWorkouts(client, a);
|
|
4574
4821
|
case "log-set": return cmdCoachLogSet(client, a);
|
|
@@ -4580,13 +4827,17 @@ async function cmdCoach(client, rest) {
|
|
|
4580
4827
|
case "athlete-restore": return cmdCoachAthleteRestore(client, a);
|
|
4581
4828
|
case "team-create": return cmdCoachTeamCreate(client, a);
|
|
4582
4829
|
case "program-create": return cmdCoachProgramCreate(client, a);
|
|
4830
|
+
case "program-delete": return cmdCoachProgramDelete(client, a);
|
|
4583
4831
|
case "team-update": return cmdCoachTeamUpdate(client, a);
|
|
4832
|
+
case "team-publish-settings": return cmdCoachTeamPublishSettings(client, a);
|
|
4584
4833
|
case "team-delete": return cmdCoachTeamDelete(client, a);
|
|
4585
4834
|
case "team-code-create": return cmdCoachTeamCodeCreate(client, a);
|
|
4586
4835
|
case "team-code-delete": return cmdCoachTeamCodeDelete(client, a);
|
|
4587
4836
|
case "session-copy": return cmdCoachSessionCopy(client, a);
|
|
4588
4837
|
case "session-unpublish": return cmdCoachSessionUnpublish(client, a);
|
|
4589
4838
|
case "session-save-template": return cmdCoachSessionSaveTemplate(client, a);
|
|
4839
|
+
case "session-template-create": return cmdCoachSessionTemplateCreate(client, a);
|
|
4840
|
+
case "session-template-delete": return cmdCoachSessionTemplateDelete(client, a);
|
|
4590
4841
|
case "analytics-query": return cmdCoachAnalyticsQuery(client, a);
|
|
4591
4842
|
case "exercise": return cmdExercise(client, a);
|
|
4592
4843
|
case "workout": return cmdWorkout(client, a);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.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": "3.
|
|
25
|
-
"@trainheroic-unofficial/js": "3.
|
|
24
|
+
"@trainheroic-unofficial/dto": "3.2.0",
|
|
25
|
+
"@trainheroic-unofficial/js": "3.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.2.0",
|
|
@@ -105,8 +105,8 @@ startDate?/endDate? }`.
|
|
|
105
105
|
|
|
106
106
|
## Still unexplored
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
-
|
|
111
|
-
|
|
112
|
-
-
|
|
108
|
+
Living status table: `.agents/skills/reverse-engineer-api/coverage.md`.
|
|
109
|
+
|
|
110
|
+
In-scope athlete reads are wrapped (`athlete_circuits`, `athlete_programming_programs`,
|
|
111
|
+
`athlete_recent_exercises`). Closed without a wrap: `PUT /1.0/athlete/savedworkout/{id}`
|
|
112
|
+
(per-set logging is enough); working-max write (read exists; set/update never found).
|
|
@@ -86,18 +86,18 @@ response shape, or an area not covered here.
|
|
|
86
86
|
|
|
87
87
|
## What you can do
|
|
88
88
|
|
|
89
|
-
| Area | How
|
|
90
|
-
| ---------------------- |
|
|
91
|
-
| Athletes | `$TH coach athletes`; `coach athlete-invite\|athlete-archive\|athlete-restore`
|
|
92
|
-
| Teams / join codes | `$TH coach teams\|team <id>\|team-codes <id>`; `coach team-create\|team-update\|team-delete\|team-code-create\|team-code-delete`
|
|
93
|
-
| Programs | `$TH coach programs`, `$TH coach program <id>`, `$TH coach program-create --kind calendar\|fixed --name "..."`
|
|
94
|
-
| Exercises | `$TH coach exercise resolve\|search\|get\|sync\|create\|forget\|stats` (below)
|
|
95
|
-
| Sessions / workouts | `$TH coach workout build\|read\|publish\|remove`; `coach session-copy\|session-unpublish\|session-save-template`
|
|
96
|
-
| Roster training | `$TH coach roster-activity\|athlete-training\|athlete-lift-history\|athlete-workouts` (read another athlete's training)
|
|
97
|
-
| Team volume (windowed) | `$TH coach team-volume --team <id>\|--athletes <ids> --start Y-M-D --end Y-M-D` — date-scoped team volume (roster-activity is all-time)
|
|
98
|
-
| Log for an athlete | `$TH coach log-set` (by set id) or `coach log-session` (by exercise) — record a roster athlete's reps/weights (real athletes only; see below)
|
|
99
|
-
| Messaging | `$TH coach message list\|read\|draft\|send\|delete` (below)
|
|
100
|
-
| Analytics | `$TH coach analytics` (category list); `$TH coach analytics-query --metric <key> ...` (the report)
|
|
89
|
+
| Area | How |
|
|
90
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
91
|
+
| Athletes | `$TH coach athletes`; `coach athlete-invite\|athlete-archive\|athlete-restore` |
|
|
92
|
+
| Teams / join codes | `$TH coach teams\|team <id>\|team-codes <id>`; `coach team-create\|team-update\|team-delete\|team-code-create\|team-code-delete` |
|
|
93
|
+
| Programs | `$TH coach programs`, `$TH coach program <id>`, `$TH coach program-create --kind calendar\|fixed --name "..."`, `$TH coach program-delete --program <id> --yes` |
|
|
94
|
+
| Exercises | `$TH coach exercise resolve\|search\|get\|sync\|create\|delete\|forget\|stats` (below) |
|
|
95
|
+
| Sessions / workouts | `$TH coach workout build\|read\|publish\|remove`; `coach session-copy\|session-unpublish\|session-save-template\|session-templates` |
|
|
96
|
+
| Roster training | `$TH coach roster-activity\|athlete-training\|athlete-lift-history\|athlete-workouts` (read another athlete's training) |
|
|
97
|
+
| Team volume (windowed) | `$TH coach team-volume --team <id>\|--athletes <ids> --start Y-M-D --end Y-M-D` — date-scoped team volume (roster-activity is all-time) |
|
|
98
|
+
| Log for an athlete | `$TH coach log-set` (by set id) or `coach log-session` (by exercise) — record a roster athlete's reps/weights (real athletes only; see below) |
|
|
99
|
+
| Messaging | `$TH coach message list\|read\|draft\|send\|delete` (below) |
|
|
100
|
+
| Analytics | `$TH coach analytics` (category list); `$TH coach analytics-query --metric <key> ...` (the report) |
|
|
101
101
|
|
|
102
102
|
## Resolving exercises
|
|
103
103
|
|
|
@@ -119,7 +119,8 @@ deleting one via the API, drop it from the mirror:
|
|
|
119
119
|
|
|
120
120
|
```bash
|
|
121
121
|
$TH coach exercise create '{"title":"Sandbag Clean","param_1_type":3,"param_2_type":1}'
|
|
122
|
-
$TH coach exercise
|
|
122
|
+
$TH coach exercise delete 7721170 --yes # live DELETE /v5/exercises/{id} + cache
|
|
123
|
+
$TH coach exercise forget 7721170 --yes # cache-only, if you already deleted via the API
|
|
123
124
|
```
|
|
124
125
|
|
|
125
126
|
`$TH coach exercise stats` shows the cached row count.
|
|
@@ -294,6 +294,7 @@ Deletes an access code. No request body needed.
|
|
|
294
294
|
| GET | `/v5/programs/fixed` | Fixed programs |
|
|
295
295
|
| GET | `/1.0/coach/programs` | Coach programs list |
|
|
296
296
|
| POST | `/1.0/coach/programs/create` | Create a standalone program |
|
|
297
|
+
| DELETE | `/v5/programs/{programId}` | Delete a standalone program |
|
|
297
298
|
| GET | `/1.0/coach/programs/edit/{id}` | Program edit data |
|
|
298
299
|
| GET | `/3.0/coach/program/{id}` | Program metadata/detail |
|
|
299
300
|
| GET | `/1.0/coach/subscriptions` | Program subscriptions |
|
|
@@ -345,6 +346,14 @@ fixed-length program. The endpoint is not idempotent. Its response contains two
|
|
|
345
346
|
`group_program`) is the actual program id used by `/3.0/coach/program/{id}` and workout writes.
|
|
346
347
|
The live API may ignore `name` and assign a generated title; use the response's `title` as truth.
|
|
347
348
|
|
|
349
|
+
#### `DELETE /v5/programs/{programId}`
|
|
350
|
+
|
|
351
|
+
Deletes a standalone calendar or fixed program. The path id must be the underlying
|
|
352
|
+
`programId` (`group_program`), not the `list_programs` container `id` — a container id
|
|
353
|
+
returns 401. The SDK/`program_delete` tool resolves either id. Response body is the string
|
|
354
|
+
`Successfully deleted program`. There is no update/rename endpoint; PUT on this path 405s
|
|
355
|
+
(`Supported methods: DELETE`).
|
|
356
|
+
|
|
348
357
|
---
|
|
349
358
|
|
|
350
359
|
### Exercises
|
|
@@ -1369,15 +1378,8 @@ Updates the auto-publish settings for a team's program. Takes the full program o
|
|
|
1369
1378
|
|
|
1370
1379
|
## Still Unexplored
|
|
1371
1380
|
|
|
1372
|
-
|
|
1373
|
-
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
- `apis.trainheroic.com/user` endpoint (uses `api-token` header, returns full user profile with teams)
|
|
1378
|
-
- Circuit creation (vs superset — circuits may use different block type or field)
|
|
1379
|
-
- Prescription template CRUD
|
|
1380
|
-
- Coach preferences update (PATCH/PUT on `2.0/coach/prefs` returns 403/405)
|
|
1381
|
-
- Library settings
|
|
1382
|
-
- Session template update (edit existing template)
|
|
1383
|
-
- Workout set reorder / move exercises between blocks
|
|
1381
|
+
Living status table (remaining wrap gaps vs closed-without-a-wrap):
|
|
1382
|
+
`.agents/skills/reverse-engineer-api/coverage.md`.
|
|
1383
|
+
|
|
1384
|
+
Still to wrap: none (in-scope). See coverage.md Closed without a wrap for out-of-scope
|
|
1385
|
+
and unreachable paths.
|