hevy-shared 1.0.823 → 1.0.825
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
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,6 +39,14 @@ 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
51
|
return this._authToken
|
|
41
52
|
? { authorization: `Bearer ${this._authToken.access_token}` }
|
|
@@ -118,7 +129,9 @@ class HevyAPIClient {
|
|
|
118
129
|
if (newToken.expires_at.valueOf() < earliestAutoRefreshUnixMs) {
|
|
119
130
|
newToken.expires_at = new Date(earliestAutoRefreshUnixMs);
|
|
120
131
|
}
|
|
121
|
-
this.
|
|
132
|
+
if (this._authTokenFactory.type === 'value') {
|
|
133
|
+
this._authTokenFactory.value = newToken;
|
|
134
|
+
}
|
|
122
135
|
this._config.onNewAuthToken(newToken);
|
|
123
136
|
});
|
|
124
137
|
}
|
|
@@ -180,14 +193,16 @@ class HevyAPIClient {
|
|
|
180
193
|
setAuthToken(newAuthToken) {
|
|
181
194
|
return __awaiter(this, void 0, void 0, function* () {
|
|
182
195
|
yield this.waitForTokenRefresh();
|
|
183
|
-
const { authToken, legacyAuthToken } = newAuthToken;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
196
|
+
const { authToken, getAuthToken, legacyAuthToken } = newAuthToken;
|
|
197
|
+
if (getAuthToken !== undefined && authToken === undefined) {
|
|
198
|
+
this._authTokenFactory = { type: 'getter', get: getAuthToken };
|
|
199
|
+
}
|
|
200
|
+
else if (authToken !== undefined && getAuthToken === undefined) {
|
|
201
|
+
this._authTokenFactory = { type: 'value', value: authToken };
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
throw new Error("Invalid arguments: exactly one of `authToken' or `getAuthToken' is required");
|
|
205
|
+
}
|
|
191
206
|
this._legacyAuthToken = legacyAuthToken;
|
|
192
207
|
this._lastTokenRefresh = undefined;
|
|
193
208
|
});
|
|
@@ -195,7 +210,7 @@ class HevyAPIClient {
|
|
|
195
210
|
clearAuthToken() {
|
|
196
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
197
212
|
yield this.waitForTokenRefresh();
|
|
198
|
-
this.
|
|
213
|
+
this._authTokenFactory = { type: 'value', value: null };
|
|
199
214
|
this._legacyAuthToken = null;
|
|
200
215
|
this._lastTokenRefresh = undefined;
|
|
201
216
|
});
|
package/built/index.d.ts
CHANGED
|
@@ -852,7 +852,6 @@ export interface Workout {
|
|
|
852
852
|
logged_by_coach_id?: string;
|
|
853
853
|
biometrics?: WorkoutBiometrics;
|
|
854
854
|
is_biometrics_public: boolean;
|
|
855
|
-
is_trainer_workout: boolean;
|
|
856
855
|
trainer_program_id: string | undefined;
|
|
857
856
|
}
|
|
858
857
|
export interface CustomExerciseImage {
|
|
@@ -932,7 +931,6 @@ export interface PostWorkoutRequestWorkout {
|
|
|
932
931
|
is_private: boolean;
|
|
933
932
|
biometrics?: WorkoutBiometrics;
|
|
934
933
|
is_biometrics_public: boolean;
|
|
935
|
-
is_trainer_workout: boolean;
|
|
936
934
|
trainer_program_id: string | undefined;
|
|
937
935
|
}
|
|
938
936
|
export declare const isHeartRateSamples: (x: any) => x is HeartRateSample[];
|
package/built/tests/testUtils.js
CHANGED