hevy-shared 1.0.918 → 1.0.919

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.
@@ -1,5 +1,5 @@
1
1
  import { ClientAuthToken, DeepReadonly } from '..';
2
- import { RequestConfig, HTTPResponse, HTTPClient, HTTPErrorHandler } from './types';
2
+ import { RequestConfig, HTTPResponse, HTTPClient, HTTPResponseHandler, HTTPErrorHandler } from './types';
3
3
  interface HevyAPIClientConfig<UserContext> {
4
4
  /**
5
5
  * How long before predicted token expiry to request a new token. We request
@@ -90,6 +90,7 @@ export declare class HevyAPIClient<UserContext = never> {
90
90
  private static readonly DEFAULT_TOKEN_REFRESH_THROTTLE_MS;
91
91
  private static readonly DEFAULT_REFRESH_AUTH_TOKEN_API_ENDPOINT;
92
92
  private readonly _config;
93
+ private _responseHandlers;
93
94
  private _errorHandlers;
94
95
  private _authTokenFactory;
95
96
  private _legacyAuthToken;
@@ -123,6 +124,22 @@ export declare class HevyAPIClient<UserContext = never> {
123
124
  clearAuthToken(): Promise<void>;
124
125
  get isAuthenticated(): boolean;
125
126
  markSessionDeleted(): void;
127
+ /**
128
+ * Adds a callback to be executed whenever a request has finished processing.
129
+ * This means either that the request has received a response, or that there
130
+ * was an error. In the case of an error, it may be either an HTTP error from
131
+ * the server, or some other type of error, such as a network error.
132
+ *
133
+ * This is a lower level API than {@link attachErrorHandler} - prefer using
134
+ * that one instead of this one if it's enough to suit your needs.
135
+ */
136
+ attachResponseHandler(onResponse: HTTPResponseHandler): void;
137
+ removeResponseHandlers(): void;
138
+ /**
139
+ * Adds a callback to be executed on receiving an HTTP error from the server.
140
+ * This callback will not be executed for any other type of error, such as a
141
+ * network error. For that and more, use {@link attachResponseHandler}.
142
+ */
126
143
  attachErrorHandler(onError: HTTPErrorHandler<{
127
144
  willRetry: boolean;
128
145
  isTokenRefreshedAfterRequest: boolean;
@@ -20,6 +20,7 @@ const __1 = require("..");
20
20
  const types_1 = require("./types");
21
21
  class HevyAPIClient {
22
22
  constructor(httpClient, config) {
23
+ this._responseHandlers = [];
23
24
  this._errorHandlers = [];
24
25
  this._authTokenFactory = {
25
26
  type: 'value',
@@ -145,9 +146,11 @@ class HevyAPIClient {
145
146
  response,
146
147
  });
147
148
  }
149
+ this._responseHandlers.forEach((cb) => cb({ isSuccess: true, value: response }, request));
148
150
  return response;
149
151
  }
150
152
  catch (e) {
153
+ this._responseHandlers.forEach((cb) => cb({ isSuccess: false, error: e }, request));
151
154
  if (!(0, types_1.isHTTPError)(e))
152
155
  throw e;
153
156
  const { response } = e;
@@ -238,6 +241,26 @@ class HevyAPIClient {
238
241
  markSessionDeleted() {
239
242
  this._lastSessionDelete = new Date();
240
243
  }
244
+ /**
245
+ * Adds a callback to be executed whenever a request has finished processing.
246
+ * This means either that the request has received a response, or that there
247
+ * was an error. In the case of an error, it may be either an HTTP error from
248
+ * the server, or some other type of error, such as a network error.
249
+ *
250
+ * This is a lower level API than {@link attachErrorHandler} - prefer using
251
+ * that one instead of this one if it's enough to suit your needs.
252
+ */
253
+ attachResponseHandler(onResponse) {
254
+ this._responseHandlers.push(onResponse);
255
+ }
256
+ removeResponseHandlers() {
257
+ this._responseHandlers.length = 0;
258
+ }
259
+ /**
260
+ * Adds a callback to be executed on receiving an HTTP error from the server.
261
+ * This callback will not be executed for any other type of error, such as a
262
+ * network error. For that and more, use {@link attachResponseHandler}.
263
+ */
241
264
  attachErrorHandler(onError) {
242
265
  this._errorHandlers.push(onError);
243
266
  }
@@ -1,3 +1,4 @@
1
+ import { Result } from '..';
1
2
  export interface HTTPClient {
2
3
  get<T>(url: string, config?: RequestConfig): Promise<HTTPResponse<T>>;
3
4
  delete<T>(url: string, config?: RequestConfig): Promise<HTTPResponse<T>>;
@@ -22,6 +23,7 @@ export interface HTTPRequestFactory<T = unknown> {
22
23
  headers: Record<string, string>;
23
24
  try(): Promise<HTTPResponse<T>>;
24
25
  }
26
+ export type HTTPResponseHandler<T = unknown, R = unknown> = (response: Result<HTTPResponse<T>>, request: HTTPRequestFactory<R>) => void;
25
27
  export type HTTPErrorHandler<E, T = unknown, R = unknown> = (response: HTTPResponse<T>, request: HTTPRequestFactory<R>, extraData: E) => void;
26
28
  export interface HTTPResponse<T = unknown> {
27
29
  status: number;
@@ -1,4 +1,4 @@
1
1
  import { Lookup } from './typeUtils';
2
- export declare const AdminPermissions: readonly ["become_user", "ip_blacklists", "featured_users", "feature_flags", "hevy_trainer", "user_account_management", "import_strong_csv", "community_management", "user_app_logs"];
2
+ export declare const AdminPermissions: readonly ["become_user", "ip_blacklists", "featured_users", "feature_flags", "hevy_trainer", "user_account_management", "import_strong_csv", "community_management", "user_app_logs", "backend_maintenance"];
3
3
  export type AdminPermission = Lookup<typeof AdminPermissions>;
4
4
  export declare const isAdminPermission: (permission?: any) => permission is AdminPermission;
@@ -11,6 +11,7 @@ exports.AdminPermissions = [
11
11
  'import_strong_csv',
12
12
  'community_management',
13
13
  'user_app_logs',
14
+ 'backend_maintenance',
14
15
  ];
15
16
  const isAdminPermission = (permission) => {
16
17
  if (!permission || typeof permission !== 'string') {
@@ -1,26 +1,16 @@
1
- import { WeeklyTrainingFrequency, TrainingGoal, TrainingLevel, SimplifiedMuscleGroup, MuscleGroup, LibraryExercise, ExerciseCategory, GranularEquipment, HevyTrainerProgramEquipment } from '.';
1
+ import { WeeklyTrainingFrequency, TrainingGoal, TrainingLevel, Equipment, SimplifiedMuscleGroup, MuscleGroup, LibraryExercise, ExerciseCategory } from '.';
2
2
  export type HevyTrainerExerciseCategory = typeof hevyTrainerExerciseCategories[number];
3
3
  export type HevyTrainerRoutineName = typeof routineNames[number];
4
- export declare const workoutDurationOptions: readonly [40, 60, 80];
5
- export type WorkoutDurationMinutes = typeof workoutDurationOptions[number];
6
- export declare const trainerGymTypes: readonly ["home_gym", "garage_gym", "commercial_gym", "full_gym"];
7
- export type TrainerGymType = typeof trainerGymTypes[number];
8
- export declare const granularEquipmentDefaults: {
9
- [key in TrainerGymType]: GranularEquipment[];
10
- };
11
- export declare const trainerEquipmentToGranularEquipments: (equipments: HevyTrainerProgramEquipment[]) => GranularEquipment[];
12
- /**
13
- * Converts granular equipment values back to the old HevyTrainerProgramEquipment
14
- * types for backwards compatibility with old mobile clients.
15
- */
16
- export declare const granularEquipmentsToTrainerEquipments: (granularEquipments: GranularEquipment[]) => HevyTrainerProgramEquipment[];
4
+ export type HevyTrainerProgramEquipment = Extract<Equipment, 'barbell' | 'dumbbell' | 'machine'>;
17
5
  export declare const hevyTrainerExerciseCategories: readonly ["compound", "isolation"];
6
+ export type WorkoutDurationMinutes = typeof workoutDurationOptions[number];
7
+ export declare const workoutDurationOptions: readonly [40, 60, 80];
18
8
  export declare const defaultDurationPerFrequency: Record<WeeklyTrainingFrequency, WorkoutDurationMinutes>;
19
9
  export declare const routineNames: readonly ["full_body_1", "full_body_2_a", "full_body_2_b", "full_body_3_a", "full_body_3_b", "full_body_3_c", "upper_1_a", "lower_1_a", "upper_1_b", "lower_1_b", "push_1", "pull_1", "legs_1", "upper_2", "lower_2", "push_2_a", "pull_2_a", "legs_2_a", "push_2_b", "pull_2_b", "legs_2_b"];
20
10
  export type exerciseId = string;
21
11
  export interface ExerciseSelectionCriteria {
22
12
  exerciseCategory: HevyTrainerExerciseCategory | 'all';
23
- equipments: GranularEquipment[];
13
+ equipments: HevyTrainerProgramEquipment[];
24
14
  routineBarbellExerciseCount: number;
25
15
  level: TrainingLevel;
26
16
  goal: TrainingGoal;
@@ -42,7 +32,7 @@ export interface ProgramGenerationParams<T extends HevyTrainerLibraryExercise> {
42
32
  selectedDays: WeeklyTrainingFrequency;
43
33
  selectedGoal: TrainingGoal;
44
34
  selectedLevel: TrainingLevel;
45
- selectedEquipments: GranularEquipment[];
35
+ selectedEquipments: HevyTrainerProgramEquipment[];
46
36
  selectedWorkoutDurationMinutes?: WorkoutDurationMinutes;
47
37
  exerciseStore: T[];
48
38
  focusMuscle?: SimplifiedMuscleGroup;
@@ -147,13 +137,6 @@ export declare const normalizeExerciseCategory: (exercise: {
147
137
  is_custom: boolean;
148
138
  category?: ExerciseCategory;
149
139
  }) => HevyTrainerExerciseCategory;
150
- /**
151
- * Checks if an exercise is compatible with the user's selected granular equipments
152
- *
153
- * - If the exercise has no granular equipments, it is compatible no matter what the user has selected
154
- * - Otherwise, the exercise is only allowed if the user has all the granular equipments
155
- */
156
- export declare const isEquipmentCompatible: (exercise: HevyTrainerLibraryExercise, userSelectedGranularEquipments: GranularEquipment[]) => boolean;
157
140
  /**
158
141
  * Sorts exercises by priority for each muscle group based on the provided priorities
159
142
  * and adds any remaining exercises from the store that weren't in the priorities.
@@ -167,7 +150,7 @@ export declare const getPrioritySortedExercises: <T extends HevyTrainerLibraryEx
167
150
  * Selects the best exercise for a given prescription using a multi-pass strategy
168
151
  */
169
152
  export declare const pickExerciseForPrescription: <T extends HevyTrainerLibraryExercise>(params: ExerciseSelectionParams<T>) => T | undefined;
170
- export type HevyTrainerLibraryExercise = Pick<LibraryExercise, 'id' | 'title' | 'priority' | 'muscle_group' | 'other_muscles' | 'exercise_type' | 'equipment_category' | 'category' | 'level' | 'goal' | 'granular_equipments'>;
153
+ export type HevyTrainerLibraryExercise = Pick<LibraryExercise, 'id' | 'title' | 'priority' | 'muscle_group' | 'other_muscles' | 'exercise_type' | 'equipment_category' | 'category' | 'level' | 'goal'>;
171
154
  export interface ExercisePrescriptionError {
172
155
  type: 'exercise_not_found';
173
156
  prescription: ExercisePrescription;
@@ -175,7 +158,7 @@ export interface ExercisePrescriptionError {
175
158
  context: {
176
159
  goal: TrainingGoal;
177
160
  level: TrainingLevel;
178
- equipments: GranularEquipment[];
161
+ equipments: HevyTrainerProgramEquipment[];
179
162
  focusMuscle?: SimplifiedMuscleGroup;
180
163
  };
181
164
  }
@@ -1,146 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateProgram = exports.pickExerciseForPrescription = exports.getPrioritySortedExercises = exports.isEquipmentCompatible = exports.normalizeExerciseCategory = exports.getTrainerRestTimerSeconds = exports.getTrainerRepRange = exports.getTrainerSetCount = exports.programSplits = exports.frequencyMap = exports.routineNames = exports.defaultDurationPerFrequency = exports.hevyTrainerExerciseCategories = exports.granularEquipmentsToTrainerEquipments = exports.trainerEquipmentToGranularEquipments = exports.granularEquipmentDefaults = exports.trainerGymTypes = exports.workoutDurationOptions = void 0;
3
+ exports.generateProgram = exports.pickExerciseForPrescription = exports.getPrioritySortedExercises = exports.normalizeExerciseCategory = exports.getTrainerRestTimerSeconds = exports.getTrainerRepRange = exports.getTrainerSetCount = exports.programSplits = exports.frequencyMap = exports.routineNames = exports.defaultDurationPerFrequency = exports.workoutDurationOptions = exports.hevyTrainerExerciseCategories = void 0;
4
4
  const _1 = require(".");
5
5
  const MAX_BARBELL_EXERCISES_PER_ROUTINE = 2;
6
- exports.workoutDurationOptions = [40, 60, 80];
7
- exports.trainerGymTypes = [
8
- 'home_gym',
9
- 'garage_gym',
10
- 'commercial_gym',
11
- 'full_gym',
12
- ];
13
- exports.granularEquipmentDefaults = {
14
- home_gym: ['dumbbell', 'pullup_bar', 'adjustable_bench'],
15
- garage_gym: [
16
- 'dumbbell',
17
- 'kettlebell',
18
- 'barbell',
19
- 'plate',
20
- 'pullup_bar',
21
- 'dip_bar',
22
- 'squat_rack',
23
- 'adjustable_bench',
24
- 'spinning',
25
- ],
26
- commercial_gym: [
27
- 'dumbbell',
28
- 'barbell',
29
- 'plate',
30
- 'ez_bar',
31
- 'pullup_bar',
32
- 'dip_bar',
33
- 'squat_rack',
34
- 'adjustable_bench',
35
- 'single_cable_machine',
36
- 'lat_pulldown_cable',
37
- 'leg_press_machine',
38
- 'smith_machine',
39
- 'stack_machines',
40
- 'treadmill',
41
- 'elliptical_trainer',
42
- 'spinning',
43
- ],
44
- // All equipment is available in a full gym
45
- full_gym: [
46
- 'barbell',
47
- 'dumbbell',
48
- 'kettlebell',
49
- 'plate',
50
- 'medicine_ball',
51
- 'ez_bar',
52
- 'landmine',
53
- 'trap_bar',
54
- 'pullup_bar',
55
- 'dip_bar',
56
- 'squat_rack',
57
- 'flat_bench',
58
- 'adjustable_bench',
59
- 'dual_cable_machine',
60
- 'single_cable_machine',
61
- 'lat_pulldown_cable',
62
- 'leg_press_machine',
63
- 'smith_machine',
64
- 't_bar',
65
- 'plate_machines',
66
- 'stack_machines',
67
- 'treadmill',
68
- 'elliptical_trainer',
69
- 'rowing_machine',
70
- 'spinning',
71
- 'stair_machine',
72
- 'air_bike',
73
- 'suspension_band',
74
- 'battle_rope',
75
- 'rings',
76
- 'jump_rope',
77
- ],
78
- };
79
- const trainerEquipmentToGranularEquipmentsMap = {
80
- barbell: [
81
- 'adjustable_bench',
82
- 'barbell',
83
- 'ez_bar',
84
- 'flat_bench',
85
- 'landmine',
86
- 'plate',
87
- 'squat_rack',
88
- 't_bar',
89
- ],
90
- dumbbell: ['adjustable_bench', 'dumbbell', 'flat_bench'],
91
- machine: [
92
- 'adjustable_bench',
93
- 'dip_bar',
94
- 'dual_cable_machine',
95
- 'flat_bench',
96
- 'lat_pulldown_cable',
97
- 'leg_press_machine',
98
- 'plate',
99
- 'plate_machines',
100
- 'pullup_bar',
101
- 'single_cable_machine',
102
- 'smith_machine',
103
- 'stack_machines',
104
- ],
105
- };
106
- const trainerEquipmentToGranularEquipments = (equipments) => {
107
- const granularEquipments = [];
108
- equipments.forEach((equipment) => {
109
- granularEquipments.push(...trainerEquipmentToGranularEquipmentsMap[equipment]);
110
- });
111
- return Array.from(new Set(granularEquipments));
112
- };
113
- exports.trainerEquipmentToGranularEquipments = trainerEquipmentToGranularEquipments;
114
- const MACHINE_SPECIFIC_GRANULAR_EQUIPMENTS = [
115
- 'smith_machine',
116
- 'leg_press_machine',
117
- 'dual_cable_machine',
118
- 'single_cable_machine',
119
- 'lat_pulldown_cable',
120
- 'plate_machines',
121
- 'stack_machines',
122
- 'dip_bar',
123
- 'pullup_bar',
124
- ];
125
- /**
126
- * Converts granular equipment values back to the old HevyTrainerProgramEquipment
127
- * types for backwards compatibility with old mobile clients.
128
- */
129
- const granularEquipmentsToTrainerEquipments = (granularEquipments) => {
130
- const result = [];
131
- if (granularEquipments.includes('barbell')) {
132
- result.push('barbell');
133
- }
134
- if (granularEquipments.includes('dumbbell')) {
135
- result.push('dumbbell');
136
- }
137
- if (granularEquipments.some((eq) => MACHINE_SPECIFIC_GRANULAR_EQUIPMENTS.includes(eq))) {
138
- result.push('machine');
139
- }
140
- return result;
141
- };
142
- exports.granularEquipmentsToTrainerEquipments = granularEquipmentsToTrainerEquipments;
143
6
  exports.hevyTrainerExerciseCategories = ['compound', 'isolation'];
7
+ exports.workoutDurationOptions = [40, 60, 80];
144
8
  // These are the values that Philip decided for the default duration per frequency
145
9
  exports.defaultDurationPerFrequency = {
146
10
  1: 80,
@@ -256,28 +120,19 @@ const isFocusMuscleExtraExerciseAllowed = (templateName, focusMuscle) => {
256
120
  }
257
121
  };
258
122
  /**
259
- * Checks if an exercise is compatible with the user's selected granular equipments
123
+ * Checks if an exercise is compatible with the user's equipments
260
124
  *
261
- * - If the exercise has no granular equipments, it is compatible no matter what the user has selected
262
- * - Otherwise, the exercise is only allowed if the user has all the granular equipments
125
+ * - We enable plate exercises where users have barbell as an equipment
126
+ * - None and other equipment categories are also always allowed
127
+ * - Otherwise, the exercise is only allowed if the user has that equipment
263
128
  */
264
- const isEquipmentCompatible = (exercise, userSelectedGranularEquipments) => {
265
- if (!exercise.granular_equipments ||
266
- exercise.granular_equipments.length === 0) {
267
- return true;
268
- }
269
- const allowedEquipments = [...userSelectedGranularEquipments];
270
- // Special case: adjustable bench can substitute for flat bench
271
- if (userSelectedGranularEquipments.includes('adjustable_bench')) {
272
- allowedEquipments.push('flat_bench');
273
- }
274
- // Special case: dual cable machine can substitute for single cable machine
275
- if (userSelectedGranularEquipments.includes('dual_cable_machine')) {
276
- allowedEquipments.push('single_cable_machine');
277
- }
278
- return exercise.granular_equipments.every((granularEquipment) => allowedEquipments.includes(granularEquipment));
129
+ const isEquipmentCompatible = (exercise, allowedEquipments) => {
130
+ return (allowedEquipments.includes(exercise.equipment_category) ||
131
+ exercise.equipment_category === 'none' ||
132
+ exercise.equipment_category === 'other' ||
133
+ (exercise.equipment_category === 'plate' &&
134
+ allowedEquipments.includes('barbell')));
279
135
  };
280
- exports.isEquipmentCompatible = isEquipmentCompatible;
281
136
  /**
282
137
  * Checks if the routine barbell exercise limit is exceeded
283
138
  *
@@ -377,7 +232,7 @@ const isExerciseMatch = (exercise, criteria) => {
377
232
  criteria.exerciseCategory === 'compound');
378
233
  const levelMatch = (_b = (_a = exercise.level) === null || _a === void 0 ? void 0 : _a.includes(criteria.level)) !== null && _b !== void 0 ? _b : false;
379
234
  const goalMatch = (_d = (_c = exercise.goal) === null || _c === void 0 ? void 0 : _c.includes(criteria.goal)) !== null && _d !== void 0 ? _d : false;
380
- const equipmentMatch = (0, exports.isEquipmentCompatible)(exercise, criteria.equipments);
235
+ const equipmentMatch = isEquipmentCompatible(exercise, criteria.equipments);
381
236
  const barbellLimitOk = !isBarbellLimitExceeded(exercise, criteria.routineBarbellExerciseCount, criteria.equipments);
382
237
  return (categoryMatch && levelMatch && goalMatch && equipmentMatch && barbellLimitOk);
383
238
  };
@@ -388,7 +243,7 @@ const isAlternativeIsolationExerciseMatch = (exercise, criteria) => {
388
243
  var _a, _b;
389
244
  const isIsolationCategory = criteria.exerciseCategory === 'isolation';
390
245
  const isAlternativeExercise = isolationExerciseAlternatives[criteria.muscleGroup].includes(exercise.id);
391
- const equipmentMatch = (0, exports.isEquipmentCompatible)(exercise, criteria.equipments);
246
+ const equipmentMatch = isEquipmentCompatible(exercise, criteria.equipments);
392
247
  const levelMatch = (_b = (_a = exercise.level) === null || _a === void 0 ? void 0 : _a.includes(criteria.level)) !== null && _b !== void 0 ? _b : false;
393
248
  return (isIsolationCategory && isAlternativeExercise && equipmentMatch && levelMatch);
394
249
  };
package/built/index.d.ts CHANGED
@@ -246,8 +246,7 @@ export interface UsernameAvailabilityResponse {
246
246
  isAvailable: boolean;
247
247
  suggestions: string[];
248
248
  }
249
- export interface CoachLoginResult {
250
- auth_token: string;
249
+ export interface CoachLoginResult extends ClientAuthTokenResponse {
251
250
  is_first_login_to_coach_platform: boolean;
252
251
  }
253
252
  export interface CoachSocialLoginResult extends SocialLoginResult {
@@ -647,9 +646,6 @@ export type TrainingLevel = Lookup<typeof trainingLevels>;
647
646
  export type ExerciseCategory = Lookup<typeof exerciseCategories>;
648
647
  export type HevyTrainerProgramEquipment = Extract<Equipment, 'barbell' | 'dumbbell' | 'machine'>;
649
648
  export declare const hevyTrainerProgramEquipments: readonly ["barbell", "dumbbell", "machine"];
650
- export declare const granularEquipments: readonly ["barbell", "dumbbell", "kettlebell", "plate", "medicine_ball", "ez_bar", "landmine", "trap_bar", "pullup_bar", "dip_bar", "squat_rack", "flat_bench", "adjustable_bench", "dual_cable_machine", "single_cable_machine", "lat_pulldown_cable", "leg_press_machine", "smith_machine", "t_bar", "plate_machines", "stack_machines", "treadmill", "elliptical_trainer", "rowing_machine", "spinning", "stair_machine", "air_bike", "suspension_band", "resistance_band", "battle_rope", "rings", "jump_rope"];
651
- export type GranularEquipment = Lookup<typeof granularEquipments>;
652
- export declare const isGranularEquipment: (x: string) => x is GranularEquipment;
653
649
  export declare const weeklyTrainingFrequencies: readonly [1, 2, 3, 4, 5, 6];
654
650
  export type WeeklyTrainingFrequency = Lookup<typeof weeklyTrainingFrequencies>;
655
651
  /**
@@ -701,7 +697,6 @@ export interface LibraryExercise extends BaseExerciseTemplate {
701
697
  goal: TrainingGoal[] | undefined;
702
698
  level: TrainingLevel[] | undefined;
703
699
  category: ExerciseCategory | undefined;
704
- granular_equipments: GranularEquipment[] | undefined;
705
700
  url_female?: string;
706
701
  thumbnail_url_female?: string;
707
702
  }
@@ -1249,53 +1244,6 @@ export interface OutstandingInvitesForCoachTeamResponse {
1249
1244
  invites: CoachTeamInvite[];
1250
1245
  }
1251
1246
  export interface HevyTrainerProgram {
1252
- id: string;
1253
- created_at: string;
1254
- updated_at: string;
1255
- title: string;
1256
- level: TrainingLevel;
1257
- goal: TrainingGoal;
1258
- equipments: GranularEquipment[];
1259
- weekly_frequency: WeeklyTrainingFrequency;
1260
- routines: HevyTrainerRoutine[];
1261
- focus_muscle?: SimplifiedMuscleGroup;
1262
- next_workout_index: number;
1263
- workout_duration_minutes?: WorkoutDurationMinutes;
1264
- }
1265
- export interface PostHevyTrainerProgramRequestBody {
1266
- program: {
1267
- title: string;
1268
- level: TrainingLevel;
1269
- goal: TrainingGoal;
1270
- equipments: GranularEquipment[];
1271
- weekly_frequency: WeeklyTrainingFrequency;
1272
- focus_muscle?: SimplifiedMuscleGroup;
1273
- routines: RoutineUpdate[];
1274
- next_workout_index?: number;
1275
- workout_duration_minutes?: WorkoutDurationMinutes;
1276
- };
1277
- }
1278
- export interface UpdateHevyTrainerProgramRequestBody {
1279
- program: {
1280
- programId: string;
1281
- title: string;
1282
- level: TrainingLevel;
1283
- goal: TrainingGoal;
1284
- equipments: GranularEquipment[];
1285
- weekly_frequency: WeeklyTrainingFrequency;
1286
- focus_muscle?: SimplifiedMuscleGroup;
1287
- next_workout_index?: number;
1288
- workout_duration_minutes?: WorkoutDurationMinutes;
1289
- routines: {
1290
- id: string;
1291
- title: string;
1292
- notes: string | null;
1293
- exercises: RoutineUpdateExercise[];
1294
- }[];
1295
- };
1296
- }
1297
- /** @deprecated Use HevyTrainerProgram instead */
1298
- export interface HevyTrainerProgramOld {
1299
1247
  id: string;
1300
1248
  created_at: string;
1301
1249
  updated_at: string;
@@ -1309,8 +1257,7 @@ export interface HevyTrainerProgramOld {
1309
1257
  next_workout_index: number;
1310
1258
  workout_duration_minutes?: WorkoutDurationMinutes;
1311
1259
  }
1312
- /** @deprecated Use PostHevyTrainerProgramRequestBody instead */
1313
- export interface PostHevyTrainerProgramOldRequestBody {
1260
+ export interface PostHevyTrainerProgramRequestBody {
1314
1261
  program: {
1315
1262
  title: string;
1316
1263
  level: TrainingLevel;
@@ -1323,8 +1270,7 @@ export interface PostHevyTrainerProgramOldRequestBody {
1323
1270
  workout_duration_minutes?: WorkoutDurationMinutes;
1324
1271
  };
1325
1272
  }
1326
- /** @deprecated Use UpdateHevyTrainerProgramRequestBody instead */
1327
- export interface UpdateHevyTrainerProgramOldRequestBody {
1273
+ export interface UpdateHevyTrainerProgramRequestBody {
1328
1274
  program: {
1329
1275
  programId: string;
1330
1276
  title: string;
package/built/index.js CHANGED
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.isHeartRateSamples = exports.isPublicWorkout = exports.isSetType = exports.isRPE = exports.validRpeValues = exports.isSetPersonalRecordType = exports.supportedInstructionsLanguages = exports.weeklyTrainingFrequencies = exports.isGranularEquipment = exports.granularEquipments = exports.hevyTrainerProgramEquipments = exports.exerciseCategories = exports.trainingLevels = exports.trainingGoals = exports.isCustomExerciseType = exports.customExericseTypes = exports.isExerciseType = exports.exerciseTypes = exports.isExerciseRepType = exports.exerciseRepTypes = exports.isEquipmentFilter = exports.equipmentFilters = exports.isEquipment = exports.equipments = exports.simplifiedMuscleGroupToMuscleGroups = exports.isMuscleGroupFilter = exports.muscleGroupFilters = exports.isMuscleGroup = exports.muscleGroups = exports.isSimplifiedMuscleGroup = exports.simplifiedMuscleGroups = exports.miscellaneousMuscles = exports.chestMuscles = exports.backMuscles = exports.legMuscles = exports.armMuscles = exports.shoulderMuscles = exports.coreMuscles = exports.DefaultClientConfiguration = exports.parseClientAuthTokenResponse = exports.isCoachRole = exports.isErrorResponse = exports.isLivePRVolumeOption = exports.isTimerVolumeOption = exports.isWeekday = exports.orderedWeekdays = exports.isBodyMeasurementUnit = exports.isDistanceUnitShort = exports.isDistanceUnit = exports.isWeightUnit = void 0;
18
- exports.isOAuthScope = exports.supportedScopes = exports.isSuggestedUserSource = exports.isValidUserWorkoutMetricsType = exports.isBodyMeasurementKey = exports.measurementsList = exports.isHevyTrainerRoutine = exports.isWorkoutBiometrics = void 0;
17
+ exports.isHevyTrainerRoutine = exports.isWorkoutBiometrics = exports.isHeartRateSamples = exports.isPublicWorkout = exports.isSetType = exports.isRPE = exports.validRpeValues = exports.isSetPersonalRecordType = exports.supportedInstructionsLanguages = exports.weeklyTrainingFrequencies = exports.hevyTrainerProgramEquipments = exports.exerciseCategories = exports.trainingLevels = exports.trainingGoals = exports.isCustomExerciseType = exports.customExericseTypes = exports.isExerciseType = exports.exerciseTypes = exports.isExerciseRepType = exports.exerciseRepTypes = exports.isEquipmentFilter = exports.equipmentFilters = exports.isEquipment = exports.equipments = exports.simplifiedMuscleGroupToMuscleGroups = exports.isMuscleGroupFilter = exports.muscleGroupFilters = exports.isMuscleGroup = exports.muscleGroups = exports.isSimplifiedMuscleGroup = exports.simplifiedMuscleGroups = exports.miscellaneousMuscles = exports.chestMuscles = exports.backMuscles = exports.legMuscles = exports.armMuscles = exports.shoulderMuscles = exports.coreMuscles = exports.DefaultClientConfiguration = exports.parseClientAuthTokenResponse = exports.isCoachRole = exports.isErrorResponse = exports.isLivePRVolumeOption = exports.isTimerVolumeOption = exports.isWeekday = exports.orderedWeekdays = exports.isBodyMeasurementUnit = exports.isDistanceUnitShort = exports.isDistanceUnit = exports.isWeightUnit = void 0;
18
+ exports.isOAuthScope = exports.supportedScopes = exports.isSuggestedUserSource = exports.isValidUserWorkoutMetricsType = exports.isBodyMeasurementKey = exports.measurementsList = void 0;
19
19
  const typeUtils_1 = require("./typeUtils");
20
20
  __exportStar(require("./constants"), exports);
21
21
  __exportStar(require("./utils"), exports);
@@ -232,42 +232,6 @@ exports.hevyTrainerProgramEquipments = [
232
232
  'dumbbell',
233
233
  'machine',
234
234
  ];
235
- exports.granularEquipments = [
236
- 'barbell',
237
- 'dumbbell',
238
- 'kettlebell',
239
- 'plate',
240
- 'medicine_ball',
241
- 'ez_bar',
242
- 'landmine',
243
- 'trap_bar',
244
- 'pullup_bar',
245
- 'dip_bar',
246
- 'squat_rack',
247
- 'flat_bench',
248
- 'adjustable_bench',
249
- 'dual_cable_machine',
250
- 'single_cable_machine',
251
- 'lat_pulldown_cable',
252
- 'leg_press_machine',
253
- 'smith_machine',
254
- 't_bar',
255
- 'plate_machines',
256
- 'stack_machines',
257
- 'treadmill',
258
- 'elliptical_trainer',
259
- 'rowing_machine',
260
- 'spinning',
261
- 'stair_machine',
262
- 'air_bike',
263
- 'suspension_band',
264
- 'resistance_band',
265
- 'battle_rope',
266
- 'rings',
267
- 'jump_rope',
268
- ];
269
- const isGranularEquipment = (x) => (0, typeUtils_1.isInArray)(x, exports.granularEquipments);
270
- exports.isGranularEquipment = isGranularEquipment;
271
235
  exports.weeklyTrainingFrequencies = [1, 2, 3, 4, 5, 6];
272
236
  exports.supportedInstructionsLanguages = [
273
237
  'en',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.918",
3
+ "version": "1.0.919",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",
@@ -1 +0,0 @@
1
- export {};
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const hevyTrainer_1 = require("../hevyTrainer");
4
- const sortGranular = (arr) => [...arr].sort();
5
- describe('trainerEquipmentToGranularEquipments', () => {
6
- it('returns empty array when no equipments are provided', () => {
7
- expect((0, hevyTrainer_1.trainerEquipmentToGranularEquipments)([])).toEqual([]);
8
- });
9
- it('returns expected granular equipments for barbell only', () => {
10
- const result = (0, hevyTrainer_1.trainerEquipmentToGranularEquipments)(['barbell']);
11
- expect(sortGranular(result)).toEqual(sortGranular([
12
- 'adjustable_bench',
13
- 'barbell',
14
- 'ez_bar',
15
- 'flat_bench',
16
- 'landmine',
17
- 'plate',
18
- 'squat_rack',
19
- 't_bar',
20
- ]));
21
- });
22
- it('returns expected granular equipments for dumbbell only', () => {
23
- const result = (0, hevyTrainer_1.trainerEquipmentToGranularEquipments)(['dumbbell']);
24
- expect(sortGranular(result)).toEqual(sortGranular(['adjustable_bench', 'dumbbell', 'flat_bench']));
25
- });
26
- it('returns expected granular equipments for machine only', () => {
27
- const result = (0, hevyTrainer_1.trainerEquipmentToGranularEquipments)(['machine']);
28
- expect(sortGranular(result)).toEqual(sortGranular([
29
- 'adjustable_bench',
30
- 'dip_bar',
31
- 'dual_cable_machine',
32
- 'flat_bench',
33
- 'lat_pulldown_cable',
34
- 'leg_press_machine',
35
- 'plate',
36
- 'plate_machines',
37
- 'pullup_bar',
38
- 'single_cable_machine',
39
- 'smith_machine',
40
- 'stack_machines',
41
- ]));
42
- });
43
- it('returns deduped union for multiple equipments', () => {
44
- const equipments = ['barbell', 'dumbbell'];
45
- const result = (0, hevyTrainer_1.trainerEquipmentToGranularEquipments)(equipments);
46
- const barbellOnly = (0, hevyTrainer_1.trainerEquipmentToGranularEquipments)(['barbell']);
47
- const dumbbellOnly = (0, hevyTrainer_1.trainerEquipmentToGranularEquipments)(['dumbbell']);
48
- const combined = sortGranular(Array.from(new Set([...barbellOnly, ...dumbbellOnly])));
49
- expect(sortGranular(result)).toEqual(combined);
50
- });
51
- });
52
- const createExercise = (granularEquipments) => ({
53
- id: 'test-exercise',
54
- title: 'Test Exercise',
55
- granular_equipments: granularEquipments,
56
- });
57
- describe('isEquipmentCompatible', () => {
58
- it('returns true when exercise has no granular equipments', () => {
59
- const exercise = createExercise(undefined);
60
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['barbell'])).toBe(true);
61
- });
62
- it('returns true when exercise has empty granular equipments', () => {
63
- const exercise = createExercise([]);
64
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['barbell'])).toBe(true);
65
- });
66
- it('returns true when user has all required equipments', () => {
67
- const exercise = createExercise(['barbell', 'squat_rack']);
68
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['barbell', 'squat_rack'])).toBe(true);
69
- });
70
- it('returns false when user is missing required equipment', () => {
71
- const exercise = createExercise(['barbell', 'squat_rack']);
72
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['barbell'])).toBe(false);
73
- });
74
- it('returns true when user has more equipment than required', () => {
75
- const exercise = createExercise(['barbell']);
76
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['barbell', 'squat_rack', 'dumbbell'])).toBe(true);
77
- });
78
- describe('special case: adjustable_bench / flat_bench substitution', () => {
79
- it('allows adjustable_bench to substitute for flat_bench when exercise requires flat_bench', () => {
80
- const exercise = createExercise(['flat_bench']);
81
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['adjustable_bench'])).toBe(true);
82
- });
83
- it('does NOT allow flat_bench to substitute for adjustable_bench when exercise requires adjustable_bench', () => {
84
- const exercise = createExercise(['adjustable_bench']);
85
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['flat_bench'])).toBe(false);
86
- });
87
- });
88
- describe('special case: dual_cable_machine / single_cable_machine substitution', () => {
89
- it('allows dual_cable_machine to substitute for single_cable_machine when exercise requires single_cable_machine', () => {
90
- const exercise = createExercise(['single_cable_machine']);
91
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['dual_cable_machine'])).toBe(true);
92
- });
93
- it('does NOT allow single_cable_machine to substitute for dual_cable_machine when exercise requires dual_cable_machine', () => {
94
- const exercise = createExercise(['dual_cable_machine']);
95
- expect((0, hevyTrainer_1.isEquipmentCompatible)(exercise, ['single_cable_machine'])).toBe(false);
96
- });
97
- });
98
- });
99
- const __1 = require("..");
100
- describe('hevyTrainer gym types and defaults', () => {
101
- it('defines granular equipment defaults for every trainer gym type', () => {
102
- __1.trainerGymTypes.forEach((gymType) => {
103
- const defaults = __1.granularEquipmentDefaults[gymType];
104
- expect(Array.isArray(defaults)).toBe(true);
105
- expect(defaults.length).toBeGreaterThan(0);
106
- });
107
- });
108
- it('granular equipment defaults only contain granular equipment values', () => {
109
- Object.keys(__1.granularEquipmentDefaults).forEach((gymType) => {
110
- const defaults = __1.granularEquipmentDefaults[gymType];
111
- defaults.forEach((equipment) => {
112
- // Type assertion ensures the mapping stays within the GranularEquipment union.
113
- const typed = equipment;
114
- expect(typeof typed).toBe('string');
115
- });
116
- });
117
- });
118
- });