hevy-shared 1.0.821 → 1.0.823
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 +0 -11
- package/built/API/APIClient.js +6 -17
- package/package.json +1 -1
package/built/API/APIClient.d.ts
CHANGED
|
@@ -74,16 +74,6 @@ 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;
|
|
87
77
|
}
|
|
88
78
|
export declare class HevyAPIClient {
|
|
89
79
|
private static readonly DEFAULT_TOKEN_EXPIRY_SAFETY_THRESHOLD_MS;
|
|
@@ -99,7 +89,6 @@ export declare class HevyAPIClient {
|
|
|
99
89
|
constructor(httpClient: HTTPClient, config: HevyAPIClientConfig);
|
|
100
90
|
private get _authHeaders();
|
|
101
91
|
private _addAuthHeaders;
|
|
102
|
-
private _isExpired;
|
|
103
92
|
private refreshExpiredAuthToken;
|
|
104
93
|
private forceRefreshAuthToken;
|
|
105
94
|
private waitForTokenRefresh;
|
package/built/API/APIClient.js
CHANGED
|
@@ -24,9 +24,6 @@ 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;
|
|
30
27
|
this._httpClient = httpClient;
|
|
31
28
|
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 &&
|
|
32
29
|
(0, types_1.isHTTPErrorResponse)(response) &&
|
|
@@ -48,24 +45,16 @@ class HevyAPIClient {
|
|
|
48
45
|
}
|
|
49
46
|
refreshExpiredAuthToken() {
|
|
50
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const { _authToken
|
|
52
|
-
if (!
|
|
48
|
+
const { _authToken } = this;
|
|
49
|
+
if (!_authToken)
|
|
53
50
|
return;
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
if (new Date().valueOf() <=
|
|
52
|
+
new Date(_authToken.expires_at).valueOf() -
|
|
53
|
+
this._config.tokenExpirySafetyThresholdMs) {
|
|
56
54
|
// Token is still valid, at least according to the client. Don't refresh.
|
|
57
55
|
return;
|
|
58
56
|
}
|
|
59
|
-
|
|
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);
|
|
57
|
+
yield this._refreshAuthToken(_authToken);
|
|
69
58
|
});
|
|
70
59
|
}
|
|
71
60
|
forceRefreshAuthToken() {
|