hevy-shared 1.0.839 → 1.0.840
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/built/API/APIClient.d.ts +9 -4
- package/built/API/APIClient.js +28 -15
- package/built/adjustEventTokens.d.ts +1 -0
- package/built/adjustEventTokens.js +1 -0
- package/built/async.d.ts +5 -0
- package/built/async.js +29 -4
- package/built/index.d.ts +30 -3
- package/built/index.js +18 -2
- package/built/normalizedWorkoutUtils.d.ts +0 -1
- package/built/tests/testUtils.js +0 -1
- package/package.json +1 -1
package/built/API/APIClient.d.ts
CHANGED
|
@@ -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
|
|
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:
|
|
105
|
-
authToken: ClientAuthToken | null;
|
|
105
|
+
setAuthToken(newAuthToken: {
|
|
106
|
+
authToken: DeepReadonly<ClientAuthToken> | null;
|
|
106
107
|
legacyAuthToken: string | null;
|
|
107
|
-
}
|
|
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;
|
package/built/API/APIClient.js
CHANGED
|
@@ -21,7 +21,10 @@ const types_1 = require("./types");
|
|
|
21
21
|
class HevyAPIClient {
|
|
22
22
|
constructor(httpClient, config) {
|
|
23
23
|
this._errorHandlers = [];
|
|
24
|
-
this.
|
|
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.
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
@@ -173,6 +173,7 @@ export interface AppleSignUpRequest {
|
|
|
173
173
|
appleUserId: string;
|
|
174
174
|
identityToken: string;
|
|
175
175
|
gympassUserId?: string;
|
|
176
|
+
useAuth2_0?: boolean;
|
|
176
177
|
}
|
|
177
178
|
export interface AppleSignInRequestCoachMobile {
|
|
178
179
|
email?: string;
|
|
@@ -185,6 +186,7 @@ export interface AppleSignInRequest {
|
|
|
185
186
|
appleUserId: string;
|
|
186
187
|
identityToken: string;
|
|
187
188
|
gympassUserId?: string;
|
|
189
|
+
useAuth2_0?: boolean;
|
|
188
190
|
}
|
|
189
191
|
export interface AppleSignUpWebRequest {
|
|
190
192
|
email?: string;
|
|
@@ -202,6 +204,7 @@ export interface GoogleSignInRequest {
|
|
|
202
204
|
idToken: string;
|
|
203
205
|
source?: 'web';
|
|
204
206
|
gympassUserId?: string;
|
|
207
|
+
useAuth2_0?: boolean;
|
|
205
208
|
}
|
|
206
209
|
export interface GoogleSignUpRequest {
|
|
207
210
|
email: string;
|
|
@@ -209,8 +212,9 @@ export interface GoogleSignUpRequest {
|
|
|
209
212
|
idToken: string;
|
|
210
213
|
source?: 'web';
|
|
211
214
|
gympassUserId?: string;
|
|
215
|
+
useAuth2_0?: boolean;
|
|
212
216
|
}
|
|
213
|
-
export interface SocialLoginResult {
|
|
217
|
+
export interface SocialLoginResult extends ClientAuthTokenResponse {
|
|
214
218
|
auth_token: string;
|
|
215
219
|
username: string;
|
|
216
220
|
user_id: string;
|
|
@@ -230,6 +234,7 @@ export interface ClientAuthTokenResponse {
|
|
|
230
234
|
refresh_token: string;
|
|
231
235
|
expires_at: string;
|
|
232
236
|
}
|
|
237
|
+
export declare const parseClientAuthTokenResponse: (data: ClientAuthTokenResponse) => ClientAuthToken | null;
|
|
233
238
|
export interface UsernameAvailabilityResponse {
|
|
234
239
|
isAvailable: boolean;
|
|
235
240
|
suggestions: string[];
|
|
@@ -320,6 +325,11 @@ export interface BackofficeAccountUpdate {
|
|
|
320
325
|
/** `null` means we're unlinking the user's Gympass account */
|
|
321
326
|
gympass_email?: string | null;
|
|
322
327
|
gympass_subscription_active?: boolean;
|
|
328
|
+
gympass_account?: {
|
|
329
|
+
id: string;
|
|
330
|
+
email: string;
|
|
331
|
+
country_code?: string;
|
|
332
|
+
};
|
|
323
333
|
limited_discovery?: boolean;
|
|
324
334
|
delete_profile_pic?: boolean;
|
|
325
335
|
delete_link?: boolean;
|
|
@@ -859,7 +869,6 @@ export interface Workout {
|
|
|
859
869
|
logged_by_coach_id?: string;
|
|
860
870
|
biometrics?: WorkoutBiometrics;
|
|
861
871
|
is_biometrics_public: boolean;
|
|
862
|
-
is_trainer_workout: boolean;
|
|
863
872
|
trainer_program_id: string | undefined;
|
|
864
873
|
}
|
|
865
874
|
export interface CustomExerciseImage {
|
|
@@ -939,7 +948,6 @@ export interface PostWorkoutRequestWorkout {
|
|
|
939
948
|
is_private: boolean;
|
|
940
949
|
biometrics?: WorkoutBiometrics;
|
|
941
950
|
is_biometrics_public: boolean;
|
|
942
|
-
is_trainer_workout: boolean;
|
|
943
951
|
trainer_program_id: string | undefined;
|
|
944
952
|
}
|
|
945
953
|
export declare const isHeartRateSamples: (x: any) => x is HeartRateSample[];
|
|
@@ -1257,6 +1265,25 @@ export interface PostHevyTrainerProgramRequestBody {
|
|
|
1257
1265
|
workout_duration_minutes?: WorkoutDurationMinutes;
|
|
1258
1266
|
};
|
|
1259
1267
|
}
|
|
1268
|
+
export interface UpdateHevyTrainerProgramRequestBody {
|
|
1269
|
+
program: {
|
|
1270
|
+
programId: string;
|
|
1271
|
+
title: string;
|
|
1272
|
+
level: TrainingLevel;
|
|
1273
|
+
goal: TrainingGoal;
|
|
1274
|
+
equipments: HevyTrainerProgramEquipment[];
|
|
1275
|
+
weekly_frequency: WeeklyTrainingFrequency;
|
|
1276
|
+
focus_muscle?: SimplifiedMuscleGroup;
|
|
1277
|
+
next_workout_index?: number;
|
|
1278
|
+
workout_duration_minutes?: WorkoutDurationMinutes;
|
|
1279
|
+
routines: {
|
|
1280
|
+
id: string;
|
|
1281
|
+
title: string;
|
|
1282
|
+
notes: string | null;
|
|
1283
|
+
exercises: RoutineUpdateExercise[];
|
|
1284
|
+
}[];
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1260
1287
|
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"];
|
|
1261
1288
|
type MeasurementProperties = {
|
|
1262
1289
|
[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.
|
|
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,
|
package/built/tests/testUtils.js
CHANGED