hevy-shared 1.0.944 → 1.0.946

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.
@@ -49,9 +49,9 @@ class HevyAPIClient {
49
49
  }
50
50
  }
51
51
  get _authHeaders() {
52
- return Object.assign(Object.assign({}, (this._authToken
52
+ return Object.assign(Object.assign(Object.assign({}, (this._authToken
53
53
  ? { authorization: `Bearer ${this._authToken.access_token}` }
54
- : {})), (this._legacyAuthToken ? { 'auth-token': this._legacyAuthToken } : {}));
54
+ : {})), (this._legacyAuthToken ? { 'auth-token': this._legacyAuthToken } : {})), { 'x-client-time': String(new Date().valueOf() / 1000) });
55
55
  }
56
56
  refreshExpiredAuthToken(userContext) {
57
57
  return __awaiter(this, void 0, void 0, function* () {
@@ -99,7 +99,10 @@ class HevyAPIClient {
99
99
  this._lastTokenRefresh = new Date();
100
100
  const { access_token, refresh_token } = authToken;
101
101
  const { method, url } = this.refreshAuthTokenApiEndpoint;
102
- const headers = { authorization: `Bearer ${access_token}` };
102
+ const headers = {
103
+ authorization: `Bearer ${access_token}`,
104
+ 'x-client-time': String(new Date().valueOf() / 1000),
105
+ };
103
106
  // This will throw and bail out if the request fails.
104
107
  const response = yield this._handleResponse({
105
108
  method,
@@ -1,4 +1,5 @@
1
- import { EquipmentFilter, Language, LibraryExercise, MuscleGroupFilter, CustomExercise } from './index';
1
+ import { EquipmentFilter, LibraryExercise, MuscleGroupFilter, CustomExercise } from './index';
2
+ import { Language } from './translations';
2
3
  export interface SearchableLibraryExercise extends LibraryExercise {
3
4
  localized_muscle_group_name: string;
4
5
  }
@@ -1,4 +1,4 @@
1
- import { WeeklyTrainingFrequency, TrainingGoal, TrainingLevel, SimplifiedMuscleGroup, MuscleGroup, LibraryExercise, ExerciseCategory, GranularEquipment, HevyTrainerProgramEquipment, RestTimerLength } from '.';
1
+ import { WeeklyTrainingFrequency, TrainingGoal, TrainingLevel, SimplifiedMuscleGroup, MuscleGroup, LibraryExercise, ExerciseCategory, GranularEquipment, HevyTrainerProgramEquipment } from '.';
2
2
  export type HevyTrainerExerciseCategory = typeof hevyTrainerExerciseCategories[number];
3
3
  export type HevyTrainerRoutineName = typeof routineNames[number];
4
4
  export declare const workoutDurationOptions: readonly [40, 60, 80];
@@ -45,7 +45,6 @@ export interface ProgramGenerationParams<T extends HevyTrainerLibraryExercise> {
45
45
  selectedLevel: TrainingLevel;
46
46
  selectedEquipments: GranularEquipment[];
47
47
  selectedWorkoutDurationMinutes?: WorkoutDurationMinutes;
48
- selectedRestTimerLength: RestTimerLength;
49
48
  exerciseStore: T[];
50
49
  focusMuscle?: SimplifiedMuscleGroup;
51
50
  excludedExerciseIds?: Set<string>;
@@ -72,11 +71,8 @@ export type RepRanges = {
72
71
  export type RestTimersPerCategory = {
73
72
  [key in HevyTrainerExerciseCategory]: number;
74
73
  };
75
- export type CategoryPerRestTimerLength = {
76
- [key in RestTimerLength]: RestTimersPerCategory;
77
- };
78
74
  export type RestTimers = {
79
- [key in TrainingGoal]: CategoryPerRestTimerLength;
75
+ [key in TrainingGoal]: RestTimersPerCategory;
80
76
  };
81
77
  export type ExercisePriorities = {
82
78
  [key in MuscleGroup]: exerciseId[];
@@ -139,7 +135,7 @@ export interface TrainerProgram {
139
135
  }
140
136
  export declare const getTrainerSetCount: (trainerAlgorithmSettings: TrainerAlgorithmSettings, goal: TrainingGoal, frequency: WeeklyTrainingFrequency) => number;
141
137
  export declare const getTrainerRepRange: (trainerAlgorithmSettings: TrainerAlgorithmSettings, goal: TrainingGoal, exerciseCategory: HevyTrainerExerciseCategory) => RepRange;
142
- export declare const getTrainerRestTimerSeconds: (trainerAlgorithmSettings: TrainerAlgorithmSettings, goal: TrainingGoal, length: RestTimerLength, exerciseCategory: HevyTrainerExerciseCategory) => number;
138
+ export declare const getTrainerRestTimerSeconds: (trainerAlgorithmSettings: TrainerAlgorithmSettings, goal: TrainingGoal, exerciseCategory: HevyTrainerExerciseCategory) => number;
143
139
  /**
144
140
  * Normalizes the exercise category to a HevyTrainerExerciseCategory
145
141
  * - Treat custom exercises and exercises with no category as `compound`
@@ -203,8 +203,8 @@ const getTrainerRepRange = (trainerAlgorithmSettings, goal, exerciseCategory) =>
203
203
  return trainerAlgorithmSettings.rep_ranges[goal][exerciseCategory];
204
204
  };
205
205
  exports.getTrainerRepRange = getTrainerRepRange;
206
- const getTrainerRestTimerSeconds = (trainerAlgorithmSettings, goal, length, exerciseCategory) => {
207
- return trainerAlgorithmSettings.rest_timers[goal][length][exerciseCategory];
206
+ const getTrainerRestTimerSeconds = (trainerAlgorithmSettings, goal, exerciseCategory) => {
207
+ return trainerAlgorithmSettings.rest_timers[goal][exerciseCategory];
208
208
  };
209
209
  exports.getTrainerRestTimerSeconds = getTrainerRestTimerSeconds;
210
210
  /**
@@ -498,7 +498,7 @@ exports.pickExerciseForPrescription = pickExerciseForPrescription;
498
498
  */
499
499
  const generateProgram = (params) => {
500
500
  var _a;
501
- const { trainerAlgorithmSettings, selectedDays, selectedGoal, selectedLevel, selectedEquipments, selectedWorkoutDurationMinutes, selectedRestTimerLength, exerciseStore, focusMuscle, excludedExerciseIds, } = params;
501
+ const { trainerAlgorithmSettings, selectedDays, selectedGoal, selectedLevel, selectedEquipments, selectedWorkoutDurationMinutes, exerciseStore, focusMuscle, excludedExerciseIds, } = params;
502
502
  const routines = exports.programSplits[selectedDays];
503
503
  const program = {
504
504
  name: selectedDays,
@@ -565,7 +565,7 @@ const generateProgram = (params) => {
565
565
  sets: (0, exports.getTrainerSetCount)(trainerAlgorithmSettings, selectedGoal, selectedDays),
566
566
  repRangeStart: repRange.rep_range_start,
567
567
  repRangeEnd: repRange.rep_range_end,
568
- restTimerSeconds: (0, exports.getTrainerRestTimerSeconds)(trainerAlgorithmSettings, selectedGoal, selectedRestTimerLength, exercisePrescription.category),
568
+ restTimerSeconds: (0, exports.getTrainerRestTimerSeconds)(trainerAlgorithmSettings, selectedGoal, exercisePrescription.category),
569
569
  warmupSetCount: exercisePrescription.warmup_set_count,
570
570
  notes: (_a = trainerAlgorithmSettings.exercise_notes[exercise.id]) !== null && _a !== void 0 ? _a : '',
571
571
  });
package/built/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { WorkoutDurationMinutes } from './hevyTrainer';
2
- import { Language } from './translationUtils';
2
+ import { Language } from './translations';
3
3
  import { Lookup } from './typeUtils';
4
4
  export * from './constants';
5
5
  export * from './utils';
@@ -21,7 +21,7 @@ export * from './async';
21
21
  export * from './adminPermissions';
22
22
  export * from './adjustEventTokens';
23
23
  export * from './hevyTrainer';
24
- export * from './translationUtils';
24
+ export * from './translations';
25
25
  export type WeightUnit = 'kg' | 'lbs';
26
26
  export declare const isWeightUnit: (x: string) => x is WeightUnit;
27
27
  export type DistanceUnit = 'kilometers' | 'miles';
@@ -640,11 +640,9 @@ export declare const isCustomExerciseType: (x: any) => x is CustomExerciseType;
640
640
  export declare const trainingGoals: readonly ["strength", "build_muscle", "fat_loss"];
641
641
  export declare const trainingLevels: readonly ["beginner", "intermediate", "advanced"];
642
642
  export declare const exerciseCategories: readonly ["isolation", "compound", "assistance-compound"];
643
- export declare const restTimerLengths: readonly ["short", "medium", "long"];
644
643
  export type TrainingGoal = Lookup<typeof trainingGoals>;
645
644
  export type TrainingLevel = Lookup<typeof trainingLevels>;
646
645
  export type ExerciseCategory = Lookup<typeof exerciseCategories>;
647
- export type RestTimerLength = typeof restTimerLengths[number];
648
646
  export type HevyTrainerProgramEquipment = Extract<Equipment, 'barbell' | 'dumbbell' | 'machine'>;
649
647
  export declare const hevyTrainerProgramEquipments: readonly ["barbell", "dumbbell", "machine"];
650
648
  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"];
@@ -1261,7 +1259,6 @@ export interface HevyTrainerProgram {
1261
1259
  focus_muscle?: SimplifiedMuscleGroup;
1262
1260
  next_workout_index: number;
1263
1261
  workout_duration_minutes?: WorkoutDurationMinutes;
1264
- rest_timer_length: RestTimerLength;
1265
1262
  }
1266
1263
  export interface PostHevyTrainerProgramRequestBody {
1267
1264
  program: {
@@ -1274,7 +1271,6 @@ export interface PostHevyTrainerProgramRequestBody {
1274
1271
  routines: RoutineUpdate[];
1275
1272
  next_workout_index?: number;
1276
1273
  workout_duration_minutes?: WorkoutDurationMinutes;
1277
- rest_timer_length: RestTimerLength;
1278
1274
  };
1279
1275
  }
1280
1276
  export interface UpdateHevyTrainerProgramRequestBody {
@@ -1288,7 +1284,6 @@ export interface UpdateHevyTrainerProgramRequestBody {
1288
1284
  focus_muscle?: SimplifiedMuscleGroup;
1289
1285
  next_workout_index?: number;
1290
1286
  workout_duration_minutes?: WorkoutDurationMinutes;
1291
- rest_timer_length?: RestTimerLength;
1292
1287
  routines: {
1293
1288
  id: string;
1294
1289
  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.isPublicWorkout = exports.isSetType = exports.isRPE = exports.validRpeValues = exports.isSetPersonalRecordType = exports.supportedInstructionsLanguages = exports.weeklyTrainingFrequencies = exports.isGranularEquipment = exports.granularEquipments = exports.hevyTrainerProgramEquipments = exports.restTimerLengths = 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 = exports.isHeartRateSamples = void 0;
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;
19
19
  const typeUtils_1 = require("./typeUtils");
20
20
  __exportStar(require("./constants"), exports);
21
21
  __exportStar(require("./utils"), exports);
@@ -37,7 +37,7 @@ __exportStar(require("./async"), exports);
37
37
  __exportStar(require("./adminPermissions"), exports);
38
38
  __exportStar(require("./adjustEventTokens"), exports);
39
39
  __exportStar(require("./hevyTrainer"), exports);
40
- __exportStar(require("./translationUtils"), exports);
40
+ __exportStar(require("./translations"), exports);
41
41
  const isWeightUnit = (x) => {
42
42
  return x === 'kg' || x === 'lbs';
43
43
  };
@@ -227,7 +227,6 @@ exports.exerciseCategories = [
227
227
  'compound',
228
228
  'assistance-compound',
229
229
  ];
230
- exports.restTimerLengths = ['short', 'medium', 'long'];
231
230
  exports.hevyTrainerProgramEquipments = [
232
231
  'barbell',
233
232
  'dumbbell',
@@ -0,0 +1,2 @@
1
+ export * from './translationUtils';
2
+ export * from './types';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./translationUtils"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,2 @@
1
+ import { PositionalTextParams, NamedTextParams, PositionalReactParams, NamedReactParams } from './types';
2
+ export declare function interpolate<T extends string>(str: string, params: PositionalTextParams | NamedTextParams<T> | PositionalReactParams | NamedReactParams<T>): string | (string | number)[];
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interpolate = interpolate;
4
+ const hasReact = (params) => Object.values(params).some((v) => v !== null &&
5
+ v !== undefined &&
6
+ typeof v !== 'string' &&
7
+ typeof v !== 'number' &&
8
+ typeof v !== 'boolean');
9
+ function interpolate(str, params) {
10
+ if (Array.isArray(params)) {
11
+ const positionalParams = params;
12
+ const hasReactParams = hasReact(positionalParams);
13
+ const re = () => /(%s)/g;
14
+ let i = 0;
15
+ if (hasReactParams) {
16
+ return str
17
+ .split(/(%s)/g)
18
+ .filter((w) => !!w)
19
+ .map((w) => {
20
+ var _a, _b;
21
+ const [, key] = (_a = re().exec(w)) !== null && _a !== void 0 ? _a : [];
22
+ if (!key) {
23
+ return w;
24
+ }
25
+ else {
26
+ return ((_b = positionalParams[i++]) !== null && _b !== void 0 ? _b : (console.error(`Missing param ${i} in the string "${str}"`), w));
27
+ }
28
+ });
29
+ }
30
+ else {
31
+ return str.replace(re(), (_) => { var _a; return String((_a = positionalParams[i++]) !== null && _a !== void 0 ? _a : _); });
32
+ }
33
+ }
34
+ else {
35
+ const namedParams = params;
36
+ const hasReactParams = hasReact(namedParams);
37
+ const re = () => /%{([^}]*)}/g;
38
+ if (hasReactParams) {
39
+ return str
40
+ .split(/(%{[^}]*})/g)
41
+ .filter((w) => !!w)
42
+ .map((w) => {
43
+ var _a, _b;
44
+ const [, key] = (_a = re().exec(w)) !== null && _a !== void 0 ? _a : [];
45
+ if (!key) {
46
+ if (key === '') {
47
+ console.error(`Empty param in the string "${str}"`);
48
+ }
49
+ return w;
50
+ }
51
+ else {
52
+ return ((_b = namedParams[key]) !== null && _b !== void 0 ? _b : (console.error(`Missing param "${key}" in the string "${str}"`),
53
+ w));
54
+ }
55
+ });
56
+ }
57
+ else {
58
+ return str.replace(re(), (_, key) => { var _a; return String((_a = namedParams[key]) !== null && _a !== void 0 ? _a : _); });
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,8 @@
1
+ import { Lookup } from '../typeUtils';
2
+ export declare const supportedLanguages: readonly ["en", "es", "de", "fr", "it", "pt", "tr", "zh_CN", "zh_TW", "ru", "ja", "ko"];
3
+ export type Language = Lookup<typeof supportedLanguages>;
4
+ export declare const isLanguage: (x: string) => x is Language;
5
+ export type PositionalTextParams = (string | number)[];
6
+ export type NamedTextParams<T extends string> = Record<T, string | number>;
7
+ export type PositionalReactParams = (string | number | object)[];
8
+ export type NamedReactParams<T extends string> = Record<T, string | number | object>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLanguage = exports.supportedLanguages = void 0;
4
+ const typeUtils_1 = require("../typeUtils");
5
+ exports.supportedLanguages = [
6
+ 'en',
7
+ 'es',
8
+ 'de',
9
+ 'fr',
10
+ 'it',
11
+ 'pt',
12
+ 'tr',
13
+ 'zh_CN',
14
+ 'zh_TW',
15
+ 'ru',
16
+ 'ja',
17
+ 'ko',
18
+ ];
19
+ const isLanguage = (x) => (0, typeUtils_1.isInArray)(x, exports.supportedLanguages);
20
+ exports.isLanguage = isLanguage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.944",
3
+ "version": "1.0.946",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",
@@ -17,12 +17,16 @@
17
17
  },
18
18
  "exports": {
19
19
  ".": "./built/index.js",
20
- "./API": "./built/API/index.js"
20
+ "./API": "./built/API/index.js",
21
+ "./translations": "./built/translations/index.js"
21
22
  },
22
23
  "typesVersions": {
23
24
  "*": {
24
25
  "API": [
25
26
  "built/API/index.d.ts"
27
+ ],
28
+ "translations": [
29
+ "built/translations/index.d.ts"
26
30
  ]
27
31
  }
28
32
  },
@@ -1,5 +0,0 @@
1
- import { Lookup } from './typeUtils';
2
- export declare const supportedLanguages: readonly ["en", "es", "de", "fr", "it", "pt", "tr", "zh_CN", "zh_TW", "ru", "ja", "ko"];
3
- export type Language = Lookup<typeof supportedLanguages>;
4
- export declare const isLanguage: (x: string) => x is Language;
5
- export declare const interpolate: (str: string, params: any[]) => string;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.interpolate = exports.isLanguage = exports.supportedLanguages = void 0;
4
- const typeUtils_1 = require("./typeUtils");
5
- exports.supportedLanguages = [
6
- 'en',
7
- 'es',
8
- 'de',
9
- 'fr',
10
- 'it',
11
- 'pt',
12
- 'tr',
13
- 'zh_CN',
14
- 'zh_TW',
15
- 'ru',
16
- 'ja',
17
- 'ko',
18
- ];
19
- const isLanguage = (x) => (0, typeUtils_1.isInArray)(x, exports.supportedLanguages);
20
- exports.isLanguage = isLanguage;
21
- const interpolate = (str, params) => {
22
- let i = 0;
23
- return str
24
- .replace(/%s/g, () => {
25
- i += 1;
26
- return params[i - 1];
27
- })
28
- .replace(/%{([\w-]*)}/g, (__, key) => params[0][key]);
29
- };
30
- exports.interpolate = interpolate;