hevy-shared 1.0.832 → 1.0.833

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.
@@ -82,12 +82,11 @@ export declare class HevyAPIClient {
82
82
  private static readonly DEFAULT_REFRESH_AUTH_TOKEN_API_ENDPOINT;
83
83
  private readonly _config;
84
84
  private _errorHandlers;
85
- private _authTokenFactory;
85
+ private _authToken;
86
86
  private _legacyAuthToken;
87
87
  private _httpClient;
88
88
  private _lastTokenRefresh;
89
89
  constructor(httpClient: HTTPClient, config: HevyAPIClientConfig);
90
- private get _authToken();
91
90
  private get _authHeaders();
92
91
  private _addAuthHeaders;
93
92
  private refreshExpiredAuthToken;
@@ -102,14 +101,10 @@ export declare class HevyAPIClient {
102
101
  readonly method: "post";
103
102
  readonly url: string;
104
103
  };
105
- setAuthToken(newAuthToken: {
106
- authToken: DeepReadonly<ClientAuthToken> | null;
104
+ setAuthToken(newAuthToken: DeepReadonly<{
105
+ authToken: ClientAuthToken | null;
107
106
  legacyAuthToken: string | null;
108
- }): Promise<void>;
109
- setAuthToken(newAuthToken: {
110
- getAuthToken: () => ClientAuthToken | null;
111
- legacyAuthToken: string | null;
112
- }): Promise<void>;
107
+ }>): Promise<void>;
113
108
  clearAuthToken(): Promise<void>;
114
109
  attachErrorHandler(onError: HTTPErrorHandler<{
115
110
  willRetry: boolean;
@@ -21,10 +21,7 @@ const types_1 = require("./types");
21
21
  class HevyAPIClient {
22
22
  constructor(httpClient, config) {
23
23
  this._errorHandlers = [];
24
- this._authTokenFactory = {
25
- type: 'value',
26
- value: null,
27
- };
24
+ this._authToken = null;
28
25
  this._legacyAuthToken = null;
29
26
  this._addAuthHeaders = (config) => (Object.assign(Object.assign({}, config), { headers: Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.headers), this._authHeaders) }));
30
27
  this._httpClient = httpClient;
@@ -39,18 +36,12 @@ class HevyAPIClient {
39
36
  this[m] = this[m].bind(this);
40
37
  });
41
38
  }
42
- get _authToken() {
43
- switch (this._authTokenFactory.type) {
44
- case 'value':
45
- return this._authTokenFactory.value;
46
- case 'getter':
47
- return this._authTokenFactory.get();
48
- }
49
- }
50
39
  get _authHeaders() {
51
- return Object.assign(Object.assign({}, (this._authToken
40
+ return this._authToken
52
41
  ? { authorization: `Bearer ${this._authToken.access_token}` }
53
- : {})), (this._legacyAuthToken ? { 'auth-token': this._legacyAuthToken } : {}));
42
+ : this._legacyAuthToken
43
+ ? { 'auth-token': this._legacyAuthToken }
44
+ : null;
54
45
  }
55
46
  refreshExpiredAuthToken() {
56
47
  return __awaiter(this, void 0, void 0, function* () {
@@ -127,9 +118,7 @@ class HevyAPIClient {
127
118
  if (newToken.expires_at.valueOf() < earliestAutoRefreshUnixMs) {
128
119
  newToken.expires_at = new Date(earliestAutoRefreshUnixMs);
129
120
  }
130
- if (this._authTokenFactory.type === 'value') {
131
- this._authTokenFactory.value = newToken;
132
- }
121
+ this._authToken = newToken;
133
122
  this._config.onNewAuthToken(newToken);
134
123
  });
135
124
  }
@@ -191,16 +180,14 @@ class HevyAPIClient {
191
180
  setAuthToken(newAuthToken) {
192
181
  return __awaiter(this, void 0, void 0, function* () {
193
182
  yield this.waitForTokenRefresh();
194
- const { authToken, getAuthToken, legacyAuthToken } = newAuthToken;
195
- if (getAuthToken !== undefined && authToken === undefined) {
196
- this._authTokenFactory = { type: 'getter', get: getAuthToken };
197
- }
198
- else if (authToken !== undefined && getAuthToken === undefined) {
199
- this._authTokenFactory = { type: 'value', value: authToken };
200
- }
201
- else {
202
- throw new Error("Invalid arguments: exactly one of `authToken' or `getAuthToken' is required");
203
- }
183
+ const { authToken, legacyAuthToken } = newAuthToken;
184
+ this._authToken = authToken
185
+ ? {
186
+ access_token: authToken.access_token,
187
+ refresh_token: authToken.refresh_token,
188
+ expires_at: new Date(authToken.expires_at),
189
+ }
190
+ : null;
204
191
  this._legacyAuthToken = legacyAuthToken;
205
192
  this._lastTokenRefresh = undefined;
206
193
  });
@@ -208,7 +195,7 @@ class HevyAPIClient {
208
195
  clearAuthToken() {
209
196
  return __awaiter(this, void 0, void 0, function* () {
210
197
  yield this.waitForTokenRefresh();
211
- this._authTokenFactory = { type: 'value', value: null };
198
+ this._authToken = null;
212
199
  this._legacyAuthToken = null;
213
200
  this._lastTokenRefresh = undefined;
214
201
  });
package/built/async.d.ts CHANGED
@@ -38,9 +38,4 @@ type MethodDecorator<T> = (target: unknown, propertyKey: string | symbol, descri
38
38
  export declare function synchronized(queue: boolean): MethodDecorator<Promise<any>>;
39
39
  export declare function synchronized(queue: boolean, id: any): MethodDecorator<Promise<any>>;
40
40
  export declare function synchronized(target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>): void;
41
- export declare abstract class LockError extends Error {
42
- abstract readonly propertyKey: string | symbol;
43
- abstract readonly lockId: unknown;
44
- protected constructor(...args: any);
45
- }
46
41
  export {};
package/built/async.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LockError = exports.handleRejection = exports.allToResolveOrReject = void 0;
12
+ exports.handleRejection = exports.allToResolveOrReject = void 0;
13
13
  exports.synchronized = synchronized;
14
14
  /**
15
15
  * The difference between this and `Promise.all` is that `Promise.all` rejects
@@ -75,24 +75,7 @@ function synchronized(arg0, arg1, arg2) {
75
75
  }
76
76
  }
77
77
  const $queue = Symbol();
78
- class LockError extends Error {
79
- constructor(...args) {
80
- super(...args);
81
- }
82
- }
83
- exports.LockError = LockError;
84
- class $LockError extends LockError {
85
- constructor({ message: baseMessage, propertyKey, lockId, }) {
86
- const formattedLockId = lockId !== undefined ? `"${String(lockId)}"` : '(anonymous)';
87
- const message = `Cannot invoke "${String(propertyKey)}" (locked by ${formattedLockId}): ${baseMessage}`;
88
- super(message);
89
- this.name = 'LockError';
90
- this.message = message;
91
- this.propertyKey = propertyKey;
92
- this.lockId = lockId;
93
- }
94
- }
95
- function synchronizedDecoratorFactory(_target, propertyKey, descriptor, wait, id) {
78
+ function synchronizedDecoratorFactory(_target, _propertyKey, descriptor, wait, id) {
96
79
  const origFn = descriptor.value;
97
80
  const lockId = arguments.length === 5 ? id : Symbol();
98
81
  descriptor.value = function (...args) {
@@ -101,11 +84,7 @@ function synchronizedDecoratorFactory(_target, propertyKey, descriptor, wait, id
101
84
  var _c;
102
85
  const queue = ((_b = (_c = ((_a = this[$queue]) !== null && _a !== void 0 ? _a : (this[$queue] = {})))[lockId]) !== null && _b !== void 0 ? _b : (_c[lockId] = []));
103
86
  if (queue.length > 0 && !wait) {
104
- throw new $LockError({
105
- message: 'Operation is already in progress',
106
- propertyKey,
107
- lockId: id,
108
- });
87
+ throw new Error('Operation is already in progress');
109
88
  }
110
89
  let done;
111
90
  const thisCall = new Promise((resolve) => {
@@ -121,11 +100,7 @@ function synchronizedDecoratorFactory(_target, propertyKey, descriptor, wait, id
121
100
  done();
122
101
  if (queue.shift() !== thisCall) {
123
102
  // eslint-disable-next-line no-unsafe-finally
124
- throw new $LockError({
125
- message: 'Assertion failed: @synchronized queue is mangled',
126
- propertyKey,
127
- lockId: id,
128
- });
103
+ throw new Error('Assertion failed: @synchronized queue is mangled');
129
104
  }
130
105
  }
131
106
  });
package/built/index.d.ts CHANGED
@@ -210,7 +210,7 @@ export interface GoogleSignUpRequest {
210
210
  source?: 'web';
211
211
  gympassUserId?: string;
212
212
  }
213
- export interface SocialLoginResult extends ClientAuthTokenResponse {
213
+ export interface SocialLoginResult {
214
214
  auth_token: string;
215
215
  username: string;
216
216
  user_id: string;
@@ -230,7 +230,6 @@ export interface ClientAuthTokenResponse {
230
230
  refresh_token: string;
231
231
  expires_at: string;
232
232
  }
233
- export declare const parseClientAuthTokenResponse: (data: ClientAuthTokenResponse) => ClientAuthToken | null;
234
233
  export interface UsernameAvailabilityResponse {
235
234
  isAvailable: boolean;
236
235
  suggestions: string[];
@@ -321,11 +320,6 @@ export interface BackofficeAccountUpdate {
321
320
  /** `null` means we're unlinking the user's Gympass account */
322
321
  gympass_email?: string | null;
323
322
  gympass_subscription_active?: boolean;
324
- gympass_account?: {
325
- id: string;
326
- email: string;
327
- country_code?: string;
328
- };
329
323
  limited_discovery?: boolean;
330
324
  delete_profile_pic?: boolean;
331
325
  delete_link?: boolean;
@@ -565,6 +559,9 @@ export interface UserProfile {
565
559
  weekly_workout_durations: WeeklyWorkoutDuration[];
566
560
  mutual_followers: PreviewMutualUser[];
567
561
  }
562
+ export interface UserWorkoutStreakCount {
563
+ streak_count: number;
564
+ }
568
565
  export interface PublicUserProfile {
569
566
  private_profile: boolean;
570
567
  username: string;
@@ -858,6 +855,7 @@ export interface Workout {
858
855
  logged_by_coach_id?: string;
859
856
  biometrics?: WorkoutBiometrics;
860
857
  is_biometrics_public: boolean;
858
+ is_trainer_workout: boolean;
861
859
  trainer_program_id: string | undefined;
862
860
  }
863
861
  export interface CustomExerciseImage {
@@ -937,6 +935,7 @@ export interface PostWorkoutRequestWorkout {
937
935
  is_private: boolean;
938
936
  biometrics?: WorkoutBiometrics;
939
937
  is_biometrics_public: boolean;
938
+ is_trainer_workout: boolean;
940
939
  trainer_program_id: string | undefined;
941
940
  }
942
941
  export declare const isHeartRateSamples: (x: any) => x is HeartRateSample[];
@@ -1254,25 +1253,6 @@ export interface PostHevyTrainerProgramRequestBody {
1254
1253
  workout_duration_minutes?: WorkoutDurationMinutes;
1255
1254
  };
1256
1255
  }
1257
- export interface UpdateHevyTrainerProgramRequestBody {
1258
- program: {
1259
- programId: string;
1260
- title: string;
1261
- level: TrainingLevel;
1262
- goal: TrainingGoal;
1263
- equipments: HevyTrainerProgramEquipment[];
1264
- weekly_frequency: WeeklyTrainingFrequency;
1265
- focus_muscle?: SimplifiedMuscleGroup;
1266
- next_workout_index?: number;
1267
- workout_duration_minutes?: WorkoutDurationMinutes;
1268
- routines: {
1269
- id: string;
1270
- title: string;
1271
- notes: string | null;
1272
- exercises: RoutineUpdateExercise[];
1273
- }[];
1274
- };
1275
- }
1276
1256
  export declare const measurementsList: readonly ["weight_kg", "lean_mass_kg", "fat_percent", "neck_cm", "shoulder_cm", "chest_cm", "left_bicep_cm", "right_bicep_cm", "left_forearm_cm", "right_forearm_cm", "abdomen", "waist", "hips", "left_thigh", "right_thigh", "left_calf", "right_calf"];
1277
1257
  type MeasurementProperties = {
1278
1258
  [key in typeof measurementsList[number]]?: number;
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.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 = exports.isLanguage = exports.supportedLanguages = void 0;
18
- exports.isSuggestedUserSource = exports.isValidUserWorkoutMetricsType = exports.isBodyMeasurementKey = exports.measurementsList = exports.isHevyTrainerRoutine = exports.isWorkoutBiometrics = void 0;
17
+ 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.isCoachRole = exports.isErrorResponse = exports.isLivePRVolumeOption = exports.isTimerVolumeOption = exports.isWeekday = exports.orderedWeekdays = exports.isBodyMeasurementUnit = exports.isDistanceUnitShort = exports.isDistanceUnit = exports.isWeightUnit = exports.isLanguage = exports.supportedLanguages = void 0;
18
+ exports.isSuggestedUserSource = exports.isValidUserWorkoutMetricsType = exports.isBodyMeasurementKey = exports.measurementsList = exports.isHevyTrainerRoutine = void 0;
19
19
  const typeUtils_1 = require("./typeUtils");
20
20
  __exportStar(require("./constants"), exports);
21
21
  __exportStar(require("./utils"), exports);
@@ -94,22 +94,6 @@ exports.isErrorResponse = isErrorResponse;
94
94
  const _coachRoles = ['member', 'admin', 'owner'];
95
95
  const isCoachRole = (role) => (0, typeUtils_1.isInArray)(role, _coachRoles);
96
96
  exports.isCoachRole = isCoachRole;
97
- const parseClientAuthTokenResponse = (data) => typeof data === 'object' &&
98
- !!data &&
99
- typeof data.access_token === 'string' &&
100
- data.access_token.length > 0 &&
101
- typeof data.refresh_token === 'string' &&
102
- data.refresh_token.length > 0 &&
103
- typeof data.expires_at === 'string' &&
104
- data.expires_at.length > 0 &&
105
- !!new Date(data.expires_at).valueOf()
106
- ? {
107
- access_token: data.access_token,
108
- refresh_token: data.refresh_token,
109
- expires_at: new Date(data.expires_at),
110
- }
111
- : null;
112
- exports.parseClientAuthTokenResponse = parseClientAuthTokenResponse;
113
97
  exports.DefaultClientConfiguration = {
114
98
  is_chat_enabled: false,
115
99
  are_notifications_enabled: true,
@@ -35,6 +35,7 @@ export interface NormalizedWorkout {
35
35
  };
36
36
  clientId: string;
37
37
  biometrics?: WorkoutBiometrics;
38
+ isTrainerWorkout: boolean;
38
39
  trainerProgramId: string | undefined;
39
40
  }
40
41
  export interface NormalizedSet {
@@ -154,6 +154,7 @@ class WorkoutBuilder {
154
154
  wearosWatch: false,
155
155
  workoutVisibility: 'public',
156
156
  isWorkoutBiometricsPublic: true,
157
+ isTrainerWorkout: false,
157
158
  trainerProgramId: undefined,
158
159
  shareTo: {
159
160
  strava: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.832",
3
+ "version": "1.0.833",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",