hevy-shared 1.0.875 → 1.0.876

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.
@@ -95,6 +95,7 @@ export declare class HevyAPIClient<UserContext = never> {
95
95
  private _legacyAuthToken;
96
96
  private _httpClient;
97
97
  private _lastTokenRefresh;
98
+ private _lastSessionDelete;
98
99
  constructor(httpClient: HTTPClient, config: HevyAPIClientConfig<UserContext>);
99
100
  private get _authToken();
100
101
  private get _authHeaders();
@@ -121,9 +122,11 @@ export declare class HevyAPIClient<UserContext = never> {
121
122
  }): Promise<void>;
122
123
  clearAuthToken(): Promise<void>;
123
124
  get isAuthenticated(): boolean;
125
+ markSessionDeleted(): void;
124
126
  attachErrorHandler(onError: HTTPErrorHandler<{
125
127
  willRetry: boolean;
126
128
  isTokenRefreshedAfterRequest: boolean;
129
+ isPreviousSession: boolean;
127
130
  }>): void;
128
131
  removeErrorHandlers(): void;
129
132
  get<T = never>(url: string, config?: RequestConfig): Promise<HTTPResponse<T>>;
@@ -161,9 +161,19 @@ class HevyAPIClient {
161
161
  */
162
162
  const isTokenRefreshedAfterRequest = this._lastTokenRefresh !== undefined &&
163
163
  requestTime < this._lastTokenRefresh;
164
+ /**
165
+ * Similar to the above, but this will be `true` if the user has logged
166
+ * out after the request was made, i.e. the session that the request was
167
+ * made within is is (probably) no longer valid. In this case, we don't
168
+ * want to retry the request, but we also don't want to log the user out,
169
+ * in case that they've logged in to another session in the meantime.
170
+ */
171
+ const isPreviousSession = this._lastSessionDelete !== undefined &&
172
+ requestTime < this._lastSessionDelete;
164
173
  this._errorHandlers.forEach((cb) => cb(response, request, {
165
174
  willRetry: retryOnFailure,
166
175
  isTokenRefreshedAfterRequest,
176
+ isPreviousSession,
167
177
  }));
168
178
  if (retryOnFailure && this.isAccessTokenExpiredResponse(response)) {
169
179
  yield this.forceRefreshAuthToken(userContext);
@@ -171,7 +181,8 @@ class HevyAPIClient {
171
181
  }
172
182
  else if (retryOnFailure &&
173
183
  this.isAccessTokenInvalidResponse(response) &&
174
- isTokenRefreshedAfterRequest) {
184
+ isTokenRefreshedAfterRequest &&
185
+ !isPreviousSession) {
175
186
  yield this.waitForTokenRefresh();
176
187
  return yield this._handleResponse(request, userContext, false);
177
188
  }
@@ -224,6 +235,9 @@ class HevyAPIClient {
224
235
  return true;
225
236
  }
226
237
  }
238
+ markSessionDeleted() {
239
+ this._lastSessionDelete = new Date();
240
+ }
227
241
  attachErrorHandler(onError) {
228
242
  this._errorHandlers.push(onError);
229
243
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.875",
3
+ "version": "1.0.876",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",