hevy-shared 1.0.819 → 1.0.821
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 +11 -0
- package/built/API/APIClient.js +17 -6
- package/built/index.d.ts +0 -19
- package/package.json +1 -1
package/built/API/APIClient.d.ts
CHANGED
|
@@ -74,6 +74,16 @@ interface HevyAPIClientConfig {
|
|
|
74
74
|
* @default ...
|
|
75
75
|
*/
|
|
76
76
|
isAccessTokenInvalidResponse?(response: HTTPResponse<unknown>): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Callback for checking for a new token before calling the refresh endpoint.
|
|
79
|
+
* Used in cases where multiple APIClients are using the same credentials,
|
|
80
|
+
* such as multiple browser tabs with the web app.
|
|
81
|
+
*
|
|
82
|
+
* Optional.
|
|
83
|
+
*
|
|
84
|
+
* @default {undefined}
|
|
85
|
+
*/
|
|
86
|
+
localRefresh?(): ClientAuthToken;
|
|
77
87
|
}
|
|
78
88
|
export declare class HevyAPIClient {
|
|
79
89
|
private static readonly DEFAULT_TOKEN_EXPIRY_SAFETY_THRESHOLD_MS;
|
|
@@ -89,6 +99,7 @@ export declare class HevyAPIClient {
|
|
|
89
99
|
constructor(httpClient: HTTPClient, config: HevyAPIClientConfig);
|
|
90
100
|
private get _authHeaders();
|
|
91
101
|
private _addAuthHeaders;
|
|
102
|
+
private _isExpired;
|
|
92
103
|
private refreshExpiredAuthToken;
|
|
93
104
|
private forceRefreshAuthToken;
|
|
94
105
|
private waitForTokenRefresh;
|
package/built/API/APIClient.js
CHANGED
|
@@ -24,6 +24,9 @@ class HevyAPIClient {
|
|
|
24
24
|
this._authToken = null;
|
|
25
25
|
this._legacyAuthToken = null;
|
|
26
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) }));
|
|
27
|
+
this._isExpired = ({ now, authToken, }) => now.valueOf() >=
|
|
28
|
+
new Date(authToken.expires_at).valueOf() -
|
|
29
|
+
this._config.tokenExpirySafetyThresholdMs;
|
|
27
30
|
this._httpClient = httpClient;
|
|
28
31
|
this._config = Object.assign({ tokenExpirySafetyThresholdMs: HevyAPIClient.DEFAULT_TOKEN_EXPIRY_SAFETY_THRESHOLD_MS, accessTokenMinimumValidAgeMs: HevyAPIClient.DEFAULT_ACCESS_TOKEN_MINIMUM_VALID_AGE_MS, tokenRefreshThrottleMs: HevyAPIClient.DEFAULT_TOKEN_REFRESH_THROTTLE_MS, refreshAuthTokenApiEndpoint: HevyAPIClient.DEFAULT_REFRESH_AUTH_TOKEN_API_ENDPOINT, isAccessTokenExpiredResponse: (response) => response.status === 401 &&
|
|
29
32
|
(0, types_1.isHTTPErrorResponse)(response) &&
|
|
@@ -45,16 +48,24 @@ class HevyAPIClient {
|
|
|
45
48
|
}
|
|
46
49
|
refreshExpiredAuthToken() {
|
|
47
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const { _authToken } = this;
|
|
49
|
-
if (!
|
|
51
|
+
const { _authToken: authToken } = this;
|
|
52
|
+
if (!authToken)
|
|
50
53
|
return;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this._config.tokenExpirySafetyThresholdMs) {
|
|
54
|
+
const now = new Date();
|
|
55
|
+
if (!this._isExpired({ now, authToken })) {
|
|
54
56
|
// Token is still valid, at least according to the client. Don't refresh.
|
|
55
57
|
return;
|
|
56
58
|
}
|
|
57
|
-
|
|
59
|
+
if (this._config.localRefresh !== undefined) {
|
|
60
|
+
const authToken = this._config.localRefresh();
|
|
61
|
+
this._authToken = authToken;
|
|
62
|
+
this._lastTokenRefresh = undefined; // This isn't shared across processes
|
|
63
|
+
if (!this._isExpired({ now, authToken })) {
|
|
64
|
+
// Token was refreshed by a different process (e.g. other browser tab).
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
yield this._refreshAuthToken(authToken);
|
|
58
69
|
});
|
|
59
70
|
}
|
|
60
71
|
forceRefreshAuthToken() {
|
package/built/index.d.ts
CHANGED
|
@@ -1250,25 +1250,6 @@ export interface PostHevyTrainerProgramRequestBody {
|
|
|
1250
1250
|
workout_duration_minutes?: WorkoutDurationMinutes;
|
|
1251
1251
|
};
|
|
1252
1252
|
}
|
|
1253
|
-
export interface UpdateHevyTrainerProgramRequestBody {
|
|
1254
|
-
program: {
|
|
1255
|
-
programId: string;
|
|
1256
|
-
title: string;
|
|
1257
|
-
level: TrainingLevel;
|
|
1258
|
-
goal: TrainingGoal;
|
|
1259
|
-
equipments: HevyTrainerProgramEquipment[];
|
|
1260
|
-
weekly_frequency: WeeklyTrainingFrequency;
|
|
1261
|
-
focus_muscle?: SimplifiedMuscleGroup;
|
|
1262
|
-
next_workout_index?: number;
|
|
1263
|
-
workout_duration_minutes?: WorkoutDurationMinutes;
|
|
1264
|
-
routines: {
|
|
1265
|
-
id: string;
|
|
1266
|
-
title: string;
|
|
1267
|
-
notes: string | null;
|
|
1268
|
-
exercises: RoutineUpdateExercise[];
|
|
1269
|
-
}[];
|
|
1270
|
-
};
|
|
1271
|
-
}
|
|
1272
1253
|
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"];
|
|
1273
1254
|
type MeasurementProperties = {
|
|
1274
1255
|
[key in typeof measurementsList[number]]?: number;
|