@trainheroic-unofficial/js 1.7.2 → 1.7.3

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 CHANGED
@@ -301,6 +301,30 @@ declare function presentCoachAthleteTraining(raw: readonly unknown[], athleteId:
301
301
  /** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
302
302
  declare function presentExerciseHistory(detail: ExerciseHistoryDetail): PresentedExerciseHistory;
303
303
  //#endregion
304
+ //#region src/exercise-set-payload.d.ts
305
+ type SetWriteMode = "log" | "prescribe";
306
+ type ExerciseSetInput = {
307
+ param1?: number | string;
308
+ param2?: number | string;
309
+ slot?: number;
310
+ };
311
+ type ExerciseSetPayload = Record<string, unknown> & {
312
+ id: number;
313
+ saved_workout_set_id: number;
314
+ workout_set_exercise_id: number;
315
+ completed: 0 | 1;
316
+ };
317
+ /**
318
+ * Build the typed body for `PUT /1.0/{role}/savedworkoutsetexercise/{id}`.
319
+ *
320
+ * A log marks only slots carrying reps as performed. The exercise completes only when every active
321
+ * slot is performed; active slots are prescribed values, prior performed values, or slots targeted
322
+ * by this write. Untargeted performed slots carry over, while untouched prescription values are
323
+ * blanked so TrainHeroic cannot fabricate performed results from them. A prescription replaces the
324
+ * full payload and never marks slots or the exercise complete.
325
+ */
326
+ declare function buildExerciseSetPayload(savedWorkoutSetExerciseId: number, savedWorkoutSetId: number, workoutSetExerciseId: number, results: readonly ExerciseSetInput[], mode: SetWriteMode, existing?: Record<string, unknown>): ExerciseSetPayload;
327
+ //#endregion
304
328
  //#region src/athlete-set-write.d.ts
305
329
  /**
306
330
  * One set of entered values for a single exercise within a saved workout set.
@@ -316,12 +340,6 @@ type SetResult = {
316
340
  slot?: number;
317
341
  }>;
318
342
  };
319
- /**
320
- * Which write a set-write is: `"log"` records a performed result (and marks the set done),
321
- * `"prescribe"` sets prescribed targets without marking it done. Threaded through
322
- * {@link buildExerciseSetPayload} and the set-write helper so the two contracts share one path.
323
- */
324
- type SetWriteMode = "log" | "prescribe";
325
343
  /**
326
344
  * Coerce the loosely-typed `results` from a validated log/prescribe args object into the SDK's
327
345
  * {@link SetResult}[]. The dto schemas validate ids as a number or a numeric string and leave
@@ -337,40 +355,6 @@ declare function toSetResults(results: ReadonlyArray<{
337
355
  slot?: number | undefined;
338
356
  }>;
339
357
  }>): SetResult[];
340
- /**
341
- * Build the body for `PUT /1.0/{role}/savedworkoutsetexercise/{id}`. The body uses snake_case
342
- * keys matching the live API response shape. Each set slot (1-10) carries `param_1_data_N` /
343
- * `param_2_data_N` string values plus a `param_N_made` flag.
344
- *
345
- * `mode` selects which write this is — the same endpoint serves both:
346
- * - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has reps
347
- * entered (`param1`) and the exercise `completed` flag is 1 when any set is performed. A slot
348
- * carrying only a weight (`param2`) with no reps is a target, not a performed set, so it stays
349
- * un-made — matching the app, which shows no completion checkmark until reps are logged.
350
- * - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
351
- * `completed` left at 0 so the set is not marked done. This matches what the app sends when a
352
- * coach edits an athlete's prescribed reps/weight.
353
- *
354
- * Each set fills a 1-based slot: its explicit `slot`, or its sequential position in `results`
355
- * when `slot` is omitted. A `log` carrying the live exercise record in `existing` keeps the slots
356
- * it does not write that were ALREADY performed (`param_N_made === 1`), so logging a second part of
357
- * a set does not wipe the earlier-logged sets. A slot holding only un-logged prescription pre-fill
358
- * (`param_N_made === 0`) is left blank rather than carried over: marking the set completed makes
359
- * the server flag every data-bearing slot performed, so preserving that pre-fill would fabricate
360
- * sets the athlete never did. The prescription is unaffected (it lives in the separate `workout`
361
- * copy, not this saved copy). A `prescribe` ignores `existing` and replaces the whole prescription.
362
- *
363
- * Only `savedWorkoutSetExerciseId`, `savedWorkoutSetId`, and `workoutSetExerciseId` are
364
- * required from the live exercise record; everything else is derived from `results` and the
365
- * preserved slots of `existing`.
366
- *
367
- * Exported for unit testing — callers should use `logAthleteSet` / `prescribeForAthlete` instead.
368
- */
369
- declare function buildExerciseSetPayload(savedWorkoutSetExerciseId: number, savedWorkoutSetId: number, workoutSetExerciseId: number, results: readonly {
370
- param1?: number | string;
371
- param2?: number | string;
372
- slot?: number;
373
- }[], mode: SetWriteMode, existing?: Record<string, unknown>): Record<string, unknown>;
374
358
  /**
375
359
  * Locate the target saved workout set across all program workouts on the given day.
376
360
  * Returns the `savedWorkoutId`, the matching set's `workoutSetExercises` array so callers
@@ -894,4 +878,4 @@ declare class ExerciseLibrary implements ExerciseIndex {
894
878
  stats(): Promise<Record<string, unknown>>;
895
879
  }
896
880
  //#endregion
897
- 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, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, SetWriteMode, SwapExerciseResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, WorkoutExportFormat, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, dateWindows, definedProps, deleteComment, exerciseTitle, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
881
+ export { ANALYTICS_METRIC_KEYS, AddedExercise, AnalyticsMetric, AnalyticsQueryArgs, ApiBase, AthleteMainLiftPRs, BuildOptions, ClientResult, CoachRosterAthlete, DEFAULT_INVITE_MESSAGE, ExerciseIndex, ExerciseLibrary, type ExerciseSetInput, type ExerciseSetPayload, LEADERBOARD_LABEL, LEADERBOARD_TYPE, Leaderboard, LibraryCache, LibrarySnapshot, LogSessionResult, LogSetTarget, MAIN_LIFT_FAMILIES, MAX_PARAM_SLOTS, MainLiftFamily, MainLiftFamilyKey, MainLiftPR, MainLiftResolution, MemoryLibraryCache, PARAM_NONE, PARAM_PCT_MAX, PARAM_REPS, PARAM_RPE, PARAM_UNIT, PARAM_WEIGHT, PersonalWorkoutCreated, RequestOptions, ResolvedLift, ScheduledAlternative, SerializedExport, SessionExercise, SetResult, type SetWriteMode, SwapExerciseResult, TrainHeroicAuthError, TrainHeroicClient, TrainHeroicSession, WorkoutExportFormat, addExercisesToWorkout, analyticsMetricCatalog, asExerciseList, buildBlockPayload, buildCommentPayload, buildExerciseSetPayload, buildSearchText, buildSession, buildSetCompletePayload, checkResponse, chunk, classifyMainLift, coerceInt, coerceNum, collectAdvisories, copySession, createPersonalWorkout, dateWindows, definedProps, deleteComment, exerciseTitle, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchAthleteWorkoutsChunked, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchCoachRoster, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, findSavedWorkoutSet, inviteAthletes, isPersonalSession, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, loginTrainHeroic, makeExercise, mapPool, mergeWorkoutsById, prescribeForAthlete, presentAthleteWorkout, presentAthleteWorkoutExport, presentAthleteWorkouts, presentAthleteWorkoutsExport, presentCoachAthleteTraining, presentExercise, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, rankSearch, readLive, readSession, removePersonalWorkout, removeSession, repsList, resolveAthleteMainLifts, resolveAthleteUserId, resolveLeaderboard, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, serializeWorkoutHistory, setSessionInstruction, sortRosterByRecency, str, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults, unitAdvisory, unitLabel, unwrapEnvelope, withUnits, workoutsToCsv, workoutsToJson, workoutsToText };
package/dist/index.mjs CHANGED
@@ -993,6 +993,75 @@ function presentExerciseHistory(detail) {
993
993
  };
994
994
  }
995
995
  //#endregion
996
+ //#region src/exercise-set-payload.ts
997
+ function slotData(exercise, key) {
998
+ const value = exercise?.[key];
999
+ return value === void 0 || value === null ? "" : String(value);
1000
+ }
1001
+ function slotIsActive(exercise, slot, targeted = false) {
1002
+ return targeted || slotData(exercise, `param_1_data_${slot}`) !== "" || slotData(exercise, `param_2_data_${slot}`) !== "" || coerceInt(exercise?.[`param_${slot}_made`]) === 1;
1003
+ }
1004
+ /** True when an existing saved-copy exercise has at least one active slot and all are performed. */
1005
+ function exerciseIsFullyLogged(exercise) {
1006
+ let anyActive = false;
1007
+ for (let slot = 1; slot <= 10; slot += 1) {
1008
+ if (!slotIsActive(exercise, slot)) continue;
1009
+ anyActive = true;
1010
+ if (coerceInt(exercise[`param_${slot}_made`]) !== 1) return false;
1011
+ }
1012
+ return anyActive;
1013
+ }
1014
+ /**
1015
+ * Build the typed body for `PUT /1.0/{role}/savedworkoutsetexercise/{id}`.
1016
+ *
1017
+ * A log marks only slots carrying reps as performed. The exercise completes only when every active
1018
+ * slot is performed; active slots are prescribed values, prior performed values, or slots targeted
1019
+ * by this write. Untargeted performed slots carry over, while untouched prescription values are
1020
+ * blanked so TrainHeroic cannot fabricate performed results from them. A prescription replaces the
1021
+ * full payload and never marks slots or the exercise complete.
1022
+ */
1023
+ function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, results, mode, existing) {
1024
+ if (results.length > 10) throw new Error(`At most 10 sets are supported per exercise; got ${results.length}.`);
1025
+ const bySlot = /* @__PURE__ */ new Map();
1026
+ results.forEach((set, index) => {
1027
+ const slot = set.slot ?? index + 1;
1028
+ if (slot < 1 || slot > 10) throw new Error(`Set slot ${slot} is out of range; slots are 1–10.`);
1029
+ if (bySlot.has(slot)) throw new Error(`Two sets target slot ${slot}; each slot can be written once.`);
1030
+ bySlot.set(slot, set);
1031
+ });
1032
+ const logging = mode === "log";
1033
+ const body = {
1034
+ id: savedWorkoutSetExerciseId,
1035
+ saved_workout_set_id: savedWorkoutSetId,
1036
+ workout_set_exercise_id: workoutSetExerciseId,
1037
+ completed: 0
1038
+ };
1039
+ let anyMade = false;
1040
+ let allActiveSlotsMade = true;
1041
+ for (let slot = 1; slot <= 10; slot += 1) {
1042
+ const target = bySlot.get(slot);
1043
+ let param1 = "";
1044
+ let param2 = "";
1045
+ let made = 0;
1046
+ if (target) {
1047
+ param1 = target.param1 === void 0 ? "" : String(target.param1);
1048
+ param2 = target.param2 === void 0 ? "" : String(target.param2);
1049
+ made = logging && param1 !== "" ? 1 : 0;
1050
+ } else if (logging && coerceInt(existing?.[`param_${slot}_made`]) === 1) {
1051
+ param1 = slotData(existing, `param_1_data_${slot}`);
1052
+ param2 = slotData(existing, `param_2_data_${slot}`);
1053
+ made = 1;
1054
+ }
1055
+ anyMade ||= made === 1;
1056
+ if (slotIsActive(existing, slot, target !== void 0) && made !== 1) allActiveSlotsMade = false;
1057
+ body[`param_${slot}_made`] = made;
1058
+ body[`param_1_data_${slot}`] = param1;
1059
+ body[`param_2_data_${slot}`] = param2;
1060
+ }
1061
+ body.completed = logging && anyMade && allActiveSlotsMade ? 1 : 0;
1062
+ return body;
1063
+ }
1064
+ //#endregion
996
1065
  //#region src/athlete-set-write.ts
997
1066
  /**
998
1067
  * Coerce the loosely-typed `results` from a validated log/prescribe args object into the SDK's
@@ -1018,107 +1087,25 @@ function toSetResults(results) {
1018
1087
  });
1019
1088
  }
1020
1089
  /**
1021
- * Build the body for `PUT /1.0/{role}/savedworkoutsetexercise/{id}`. The body uses snake_case
1022
- * keys matching the live API response shape. Each set slot (1-10) carries `param_1_data_N` /
1023
- * `param_2_data_N` string values plus a `param_N_made` flag.
1024
- *
1025
- * `mode` selects which write this is — the same endpoint serves both:
1026
- * - `"log"`: the values ARE a performed result, so `param_N_made` is 1 where the slot has reps
1027
- * entered (`param1`) and the exercise `completed` flag is 1 when any set is performed. A slot
1028
- * carrying only a weight (`param2`) with no reps is a target, not a performed set, so it stays
1029
- * un-made — matching the app, which shows no completion checkmark until reps are logged.
1030
- * - `"prescribe"`: the values are prescribed targets, written with every `param_N_made` and
1031
- * `completed` left at 0 so the set is not marked done. This matches what the app sends when a
1032
- * coach edits an athlete's prescribed reps/weight.
1033
- *
1034
- * Each set fills a 1-based slot: its explicit `slot`, or its sequential position in `results`
1035
- * when `slot` is omitted. A `log` carrying the live exercise record in `existing` keeps the slots
1036
- * it does not write that were ALREADY performed (`param_N_made === 1`), so logging a second part of
1037
- * a set does not wipe the earlier-logged sets. A slot holding only un-logged prescription pre-fill
1038
- * (`param_N_made === 0`) is left blank rather than carried over: marking the set completed makes
1039
- * the server flag every data-bearing slot performed, so preserving that pre-fill would fabricate
1040
- * sets the athlete never did. The prescription is unaffected (it lives in the separate `workout`
1041
- * copy, not this saved copy). A `prescribe` ignores `existing` and replaces the whole prescription.
1042
- *
1043
- * Only `savedWorkoutSetExerciseId`, `savedWorkoutSetId`, and `workoutSetExerciseId` are
1044
- * required from the live exercise record; everything else is derived from `results` and the
1045
- * preserved slots of `existing`.
1046
- *
1047
- * Exported for unit testing — callers should use `logAthleteSet` / `prescribeForAthlete` instead.
1048
- */
1049
- function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, workoutSetExerciseId, results, mode, existing) {
1050
- if (results.length > 10) throw new Error(`At most 10 sets are supported per exercise; got ${results.length}.`);
1051
- const bySlot = /* @__PURE__ */ new Map();
1052
- results.forEach((set, i) => {
1053
- const slot = set.slot ?? i + 1;
1054
- if (slot < 1 || slot > 10) throw new Error(`Set slot ${slot} is out of range; slots are 1–10.`);
1055
- if (bySlot.has(slot)) throw new Error(`Two sets target slot ${slot}; each slot can be written once.`);
1056
- bySlot.set(slot, set);
1057
- });
1058
- const performed = mode === "log";
1059
- const carryOver = performed && existing !== void 0;
1060
- const body = {
1061
- id: savedWorkoutSetExerciseId,
1062
- saved_workout_set_id: savedWorkoutSetId,
1063
- workout_set_exercise_id: workoutSetExerciseId
1064
- };
1065
- let anyMade = false;
1066
- for (let i = 1; i <= 10; i += 1) {
1067
- const target = bySlot.get(i);
1068
- let p1;
1069
- let p2;
1070
- let made;
1071
- if (target) {
1072
- p1 = target.param1 !== void 0 ? String(target.param1) : "";
1073
- p2 = target.param2 !== void 0 ? String(target.param2) : "";
1074
- made = performed && p1 !== "" ? 1 : 0;
1075
- } else if (carryOver && coerceInt(existing?.[`param_${i}_made`]) === 1) {
1076
- p1 = existingSlotData(existing, `param_1_data_${i}`);
1077
- p2 = existingSlotData(existing, `param_2_data_${i}`);
1078
- made = 1;
1079
- } else {
1080
- p1 = "";
1081
- p2 = "";
1082
- made = 0;
1083
- }
1084
- if (made === 1) anyMade = true;
1085
- body[`param_${i}_made`] = made;
1086
- body[`param_1_data_${i}`] = p1;
1087
- body[`param_2_data_${i}`] = p2;
1088
- }
1089
- body.completed = performed && anyMade ? 1 : 0;
1090
- return body;
1091
- }
1092
- /** Read a saved-copy slot value (`param_1_data_N` / `param_2_data_N`) as the string the body uses. */
1093
- function existingSlotData(existing, key) {
1094
- const v = existing?.[key];
1095
- return v === void 0 || v === null ? "" : String(v);
1096
- }
1097
- /** True when a saved-copy exercise already carries a performed slot (any `param_N_made` === 1). */
1098
- function exerciseHasLoggedData(ex) {
1099
- for (let i = 1; i <= 10; i += 1) if (coerceInt(ex[`param_${i}_made`]) === 1) return true;
1100
- return false;
1101
- }
1102
- /** True when a result carries at least one set with reps entered (so it produces a performed slot).
1103
- * A weight-only set (`param2` set, `param1` blank) is a target, not a performed result, and so does
1104
- * not count — mirroring the `made` rule in {@link buildExerciseSetPayload}. */
1105
- function resultHasPerformedSet(result) {
1106
- return result.sets.some((s) => s.param1 !== void 0 && String(s.param1) !== "");
1107
- }
1108
- /**
1109
- * Whether every exercise in a saved workout set now has logged data — either written with data in
1110
- * this call (`loggedIds`) or already carrying a performed slot. Gates the set-completion PUT: a
1111
- * superset/circuit stays open until the last exercise is logged, so completing it on a partial log
1112
- * does not flip its still-empty siblings to "done". An exercise written with no reps — empty values,
1113
- * or a weight (`param2`) with no reps (`param1`) — does not count (it would not be marked performed),
1114
- * so a no-reps log never completes the set.
1090
+ * Whether every exercise in a saved workout set is fully logged — either completed by its projected
1091
+ * payload in this call (`projectedCompletion`) or already carrying made flags for every active slot.
1092
+ * This gates the set-completion PUT so a partial exercise cannot close a superset/circuit and cause
1093
+ * TrainHeroic to backfill its omitted slots or untouched siblings.
1115
1094
  */
1116
- function isSetFullyLogged(exercises, loggedIds) {
1095
+ function isSetFullyLogged(exercises, projectedCompletion) {
1117
1096
  return exercises.every((ex) => {
1118
1097
  const id = coerceInt(ex.id);
1119
- return id !== null && loggedIds.has(id) || exerciseHasLoggedData(ex);
1098
+ if (id !== null && projectedCompletion.has(id)) return projectedCompletion.get(id) === true;
1099
+ return exerciseIsFullyLogged(ex);
1120
1100
  });
1121
1101
  }
1102
+ function assertUniqueExerciseResults(results) {
1103
+ const seen = /* @__PURE__ */ new Set();
1104
+ for (const result of results) {
1105
+ if (seen.has(result.savedWorkoutSetExerciseId)) throw new Error(`savedWorkoutSetExerciseId ${result.savedWorkoutSetExerciseId} appears more than once; combine its sets into one result.`);
1106
+ seen.add(result.savedWorkoutSetExerciseId);
1107
+ }
1108
+ }
1122
1109
  /**
1123
1110
  * Locate the target saved workout set across all program workouts on the given day.
1124
1111
  * Returns the `savedWorkoutId`, the matching set's `workoutSetExercises` array so callers
@@ -1318,9 +1305,11 @@ async function swapAthleteExercise(client, args) {
1318
1305
  */
1319
1306
  async function writeSetResults(client, target, workouts, savedWorkoutSetId, results, mode) {
1320
1307
  const { exercises, rawSet } = findSavedWorkoutSet(workouts, savedWorkoutSetId);
1308
+ assertUniqueExerciseResults(results);
1321
1309
  const suffix = target.role === "coach" ? `/${target.athleteId}` : "";
1322
1310
  const extra = target.role === "coach" ? { athleteId: target.athleteId } : {};
1323
1311
  let exercisesWritten = 0;
1312
+ const projectedCompletion = /* @__PURE__ */ new Map();
1324
1313
  for (const result of results) {
1325
1314
  const ex = exercises.find((e) => coerceInt(e.id) === result.savedWorkoutSetExerciseId);
1326
1315
  if (!ex) {
@@ -1341,11 +1330,12 @@ async function writeSetResults(client, target, workouts, savedWorkoutSetId, resu
1341
1330
  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.` : "";
1342
1331
  throw new Error(`Failed to write exercise ${result.savedWorkoutSetExerciseId} (HTTP ${res.status}).${readOnly}`);
1343
1332
  }
1333
+ projectedCompletion.set(result.savedWorkoutSetExerciseId, body.completed === 1);
1344
1334
  exercisesWritten += 1;
1345
1335
  }
1346
1336
  let setCompleted = false;
1347
1337
  if (mode === "log") {
1348
- if (isSetFullyLogged(exercises, new Set(results.filter(resultHasPerformedSet).map((r) => r.savedWorkoutSetExerciseId)))) {
1338
+ if (isSetFullyLogged(exercises, projectedCompletion)) {
1349
1339
  const setBody = {
1350
1340
  ...buildSetCompletePayload(rawSet, exercises.map((e) => coerceInt(e.id)).filter((n) => n !== null), true),
1351
1341
  ...extra
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/js",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,12 +27,12 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "zod": "^4.4.3",
30
- "@trainheroic-unofficial/dto": "1.7.2"
30
+ "@trainheroic-unofficial/dto": "1.7.3"
31
31
  },
32
32
  "devDependencies": {
33
- "@types/node": "^26.0.1",
33
+ "@types/node": "^26.1.0",
34
34
  "tsdown": "^0.22.3",
35
- "vitest": "^4.1.9"
35
+ "vitest": "^4.1.10"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "tsdown",