hevy-shared 1.0.833 → 1.0.835

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,11 +82,12 @@ 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 _authToken;
85
+ private _authTokenFactory;
86
86
  private _legacyAuthToken;
87
87
  private _httpClient;
88
88
  private _lastTokenRefresh;
89
89
  constructor(httpClient: HTTPClient, config: HevyAPIClientConfig);
90
+ private get _authToken();
90
91
  private get _authHeaders();
91
92
  private _addAuthHeaders;
92
93
  private refreshExpiredAuthToken;
@@ -101,10 +102,14 @@ export declare class HevyAPIClient {
101
102
  readonly method: "post";
102
103
  readonly url: string;
103
104
  };
104
- setAuthToken(newAuthToken: DeepReadonly<{
105
- authToken: ClientAuthToken | null;
105
+ setAuthToken(newAuthToken: {
106
+ authToken: DeepReadonly<ClientAuthToken> | null;
106
107
  legacyAuthToken: string | null;
107
- }>): Promise<void>;
108
+ }): Promise<void>;
109
+ setAuthToken(newAuthToken: {
110
+ getAuthToken: () => ClientAuthToken | null;
111
+ legacyAuthToken: string | null;
112
+ }): Promise<void>;
108
113
  clearAuthToken(): Promise<void>;
109
114
  attachErrorHandler(onError: HTTPErrorHandler<{
110
115
  willRetry: boolean;
@@ -21,7 +21,10 @@ const types_1 = require("./types");
21
21
  class HevyAPIClient {
22
22
  constructor(httpClient, config) {
23
23
  this._errorHandlers = [];
24
- this._authToken = null;
24
+ this._authTokenFactory = {
25
+ type: 'value',
26
+ value: null,
27
+ };
25
28
  this._legacyAuthToken = null;
26
29
  this._addAuthHeaders = (config) => (Object.assign(Object.assign({}, config), { headers: Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.headers), this._authHeaders) }));
27
30
  this._httpClient = httpClient;
@@ -36,12 +39,18 @@ class HevyAPIClient {
36
39
  this[m] = this[m].bind(this);
37
40
  });
38
41
  }
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
+ }
39
50
  get _authHeaders() {
40
- return this._authToken
51
+ return Object.assign(Object.assign({}, (this._authToken
41
52
  ? { authorization: `Bearer ${this._authToken.access_token}` }
42
- : this._legacyAuthToken
43
- ? { 'auth-token': this._legacyAuthToken }
44
- : null;
53
+ : {})), (this._legacyAuthToken ? { 'auth-token': this._legacyAuthToken } : {}));
45
54
  }
46
55
  refreshExpiredAuthToken() {
47
56
  return __awaiter(this, void 0, void 0, function* () {
@@ -118,7 +127,9 @@ class HevyAPIClient {
118
127
  if (newToken.expires_at.valueOf() < earliestAutoRefreshUnixMs) {
119
128
  newToken.expires_at = new Date(earliestAutoRefreshUnixMs);
120
129
  }
121
- this._authToken = newToken;
130
+ if (this._authTokenFactory.type === 'value') {
131
+ this._authTokenFactory.value = newToken;
132
+ }
122
133
  this._config.onNewAuthToken(newToken);
123
134
  });
124
135
  }
@@ -180,14 +191,16 @@ class HevyAPIClient {
180
191
  setAuthToken(newAuthToken) {
181
192
  return __awaiter(this, void 0, void 0, function* () {
182
193
  yield this.waitForTokenRefresh();
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;
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
+ }
191
204
  this._legacyAuthToken = legacyAuthToken;
192
205
  this._lastTokenRefresh = undefined;
193
206
  });
@@ -195,7 +208,7 @@ class HevyAPIClient {
195
208
  clearAuthToken() {
196
209
  return __awaiter(this, void 0, void 0, function* () {
197
210
  yield this.waitForTokenRefresh();
198
- this._authToken = null;
211
+ this._authTokenFactory = { type: 'value', value: null };
199
212
  this._legacyAuthToken = null;
200
213
  this._lastTokenRefresh = undefined;
201
214
  });
package/built/async.d.ts CHANGED
@@ -38,4 +38,9 @@ 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
+ }
41
46
  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.handleRejection = exports.allToResolveOrReject = void 0;
12
+ exports.LockError = 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,7 +75,24 @@ function synchronized(arg0, arg1, arg2) {
75
75
  }
76
76
  }
77
77
  const $queue = Symbol();
78
- function synchronizedDecoratorFactory(_target, _propertyKey, descriptor, wait, id) {
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) {
79
96
  const origFn = descriptor.value;
80
97
  const lockId = arguments.length === 5 ? id : Symbol();
81
98
  descriptor.value = function (...args) {
@@ -84,7 +101,11 @@ function synchronizedDecoratorFactory(_target, _propertyKey, descriptor, wait, i
84
101
  var _c;
85
102
  const queue = ((_b = (_c = ((_a = this[$queue]) !== null && _a !== void 0 ? _a : (this[$queue] = {})))[lockId]) !== null && _b !== void 0 ? _b : (_c[lockId] = []));
86
103
  if (queue.length > 0 && !wait) {
87
- throw new Error('Operation is already in progress');
104
+ throw new $LockError({
105
+ message: 'Operation is already in progress',
106
+ propertyKey,
107
+ lockId: id,
108
+ });
88
109
  }
89
110
  let done;
90
111
  const thisCall = new Promise((resolve) => {
@@ -100,7 +121,11 @@ function synchronizedDecoratorFactory(_target, _propertyKey, descriptor, wait, i
100
121
  done();
101
122
  if (queue.shift() !== thisCall) {
102
123
  // eslint-disable-next-line no-unsafe-finally
103
- throw new Error('Assertion failed: @synchronized queue is mangled');
124
+ throw new $LockError({
125
+ message: 'Assertion failed: @synchronized queue is mangled',
126
+ propertyKey,
127
+ lockId: id,
128
+ });
104
129
  }
105
130
  }
106
131
  });
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 {
213
+ export interface SocialLoginResult extends ClientAuthTokenResponse {
214
214
  auth_token: string;
215
215
  username: string;
216
216
  user_id: string;
@@ -230,6 +230,7 @@ export interface ClientAuthTokenResponse {
230
230
  refresh_token: string;
231
231
  expires_at: string;
232
232
  }
233
+ export declare const parseClientAuthTokenResponse: (data: ClientAuthTokenResponse) => ClientAuthToken | null;
233
234
  export interface UsernameAvailabilityResponse {
234
235
  isAvailable: boolean;
235
236
  suggestions: string[];
@@ -320,6 +321,11 @@ export interface BackofficeAccountUpdate {
320
321
  /** `null` means we're unlinking the user's Gympass account */
321
322
  gympass_email?: string | null;
322
323
  gympass_subscription_active?: boolean;
324
+ gympass_account?: {
325
+ id: string;
326
+ email: string;
327
+ country_code?: string;
328
+ };
323
329
  limited_discovery?: boolean;
324
330
  delete_profile_pic?: boolean;
325
331
  delete_link?: boolean;
@@ -559,9 +565,6 @@ export interface UserProfile {
559
565
  weekly_workout_durations: WeeklyWorkoutDuration[];
560
566
  mutual_followers: PreviewMutualUser[];
561
567
  }
562
- export interface UserWorkoutStreakCount {
563
- streak_count: number;
564
- }
565
568
  export interface PublicUserProfile {
566
569
  private_profile: boolean;
567
570
  username: string;
@@ -855,7 +858,6 @@ export interface Workout {
855
858
  logged_by_coach_id?: string;
856
859
  biometrics?: WorkoutBiometrics;
857
860
  is_biometrics_public: boolean;
858
- is_trainer_workout: boolean;
859
861
  trainer_program_id: string | undefined;
860
862
  }
861
863
  export interface CustomExerciseImage {
@@ -935,7 +937,6 @@ export interface PostWorkoutRequestWorkout {
935
937
  is_private: boolean;
936
938
  biometrics?: WorkoutBiometrics;
937
939
  is_biometrics_public: boolean;
938
- is_trainer_workout: boolean;
939
940
  trainer_program_id: string | undefined;
940
941
  }
941
942
  export declare const isHeartRateSamples: (x: any) => x is HeartRateSample[];
@@ -1253,6 +1254,25 @@ export interface PostHevyTrainerProgramRequestBody {
1253
1254
  workout_duration_minutes?: WorkoutDurationMinutes;
1254
1255
  };
1255
1256
  }
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
+ }
1256
1276
  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"];
1257
1277
  type MeasurementProperties = {
1258
1278
  [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.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;
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;
19
19
  const typeUtils_1 = require("./typeUtils");
20
20
  __exportStar(require("./constants"), exports);
21
21
  __exportStar(require("./utils"), exports);
@@ -94,6 +94,22 @@ 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;
97
113
  exports.DefaultClientConfiguration = {
98
114
  is_chat_enabled: false,
99
115
  are_notifications_enabled: true,
@@ -35,7 +35,6 @@ export interface NormalizedWorkout {
35
35
  };
36
36
  clientId: string;
37
37
  biometrics?: WorkoutBiometrics;
38
- isTrainerWorkout: boolean;
39
38
  trainerProgramId: string | undefined;
40
39
  }
41
40
  export interface NormalizedSet {
@@ -154,7 +154,6 @@ class WorkoutBuilder {
154
154
  wearosWatch: false,
155
155
  workoutVisibility: 'public',
156
156
  isWorkoutBiometricsPublic: true,
157
- isTrainerWorkout: false,
158
157
  trainerProgramId: undefined,
159
158
  shareTo: {
160
159
  strava: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.833",
3
+ "version": "1.0.835",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",