hevy-shared 1.0.942 → 1.0.943
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientAuthToken, DeepReadonly } from '..';
|
|
2
|
-
import { RequestConfig, HTTPResponse, HTTPClient,
|
|
2
|
+
import { RequestConfig, HTTPResponse, HTTPClient, HTTPRequestCompletionCallback, HTTPErrorHandler } from './types';
|
|
3
3
|
interface HevyAPIClientConfig<UserContext> {
|
|
4
4
|
/**
|
|
5
5
|
* How long before predicted token expiry to request a new token. We request
|
|
@@ -90,7 +90,7 @@ export declare class HevyAPIClient<UserContext = never> {
|
|
|
90
90
|
private static readonly DEFAULT_TOKEN_REFRESH_THROTTLE_MS;
|
|
91
91
|
private static readonly DEFAULT_REFRESH_AUTH_TOKEN_API_ENDPOINT;
|
|
92
92
|
private readonly _config;
|
|
93
|
-
private
|
|
93
|
+
private _requestCompletionCallbacks;
|
|
94
94
|
private _errorHandlers;
|
|
95
95
|
private _authTokenFactory;
|
|
96
96
|
private _legacyAuthToken;
|
|
@@ -133,12 +133,12 @@ export declare class HevyAPIClient<UserContext = never> {
|
|
|
133
133
|
* This is a lower level API than {@link attachErrorHandler} - prefer using
|
|
134
134
|
* that one instead of this one if it's enough to suit your needs.
|
|
135
135
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
attachRequestCompletionCallback(onResult: HTTPRequestCompletionCallback): void;
|
|
137
|
+
removeRequestCompletionCallbacks(): void;
|
|
138
138
|
/**
|
|
139
139
|
* Adds a callback to be executed on receiving an HTTP error from the server.
|
|
140
140
|
* This callback will not be executed for any other type of error, such as a
|
|
141
|
-
* network error. For that and more, use {@link
|
|
141
|
+
* network error. For that and more, use {@link attachRequestCompletionCallback}.
|
|
142
142
|
*/
|
|
143
143
|
attachErrorHandler(onError: HTTPErrorHandler<{
|
|
144
144
|
willRetry: boolean;
|
package/built/API/APIClient.js
CHANGED
|
@@ -20,7 +20,7 @@ const __1 = require("..");
|
|
|
20
20
|
const types_1 = require("./types");
|
|
21
21
|
class HevyAPIClient {
|
|
22
22
|
constructor(httpClient, config) {
|
|
23
|
-
this.
|
|
23
|
+
this._requestCompletionCallbacks = [];
|
|
24
24
|
this._errorHandlers = [];
|
|
25
25
|
this._authTokenFactory = {
|
|
26
26
|
type: 'value',
|
|
@@ -146,11 +146,11 @@ class HevyAPIClient {
|
|
|
146
146
|
response,
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
|
-
this.
|
|
149
|
+
this._requestCompletionCallbacks.forEach((cb) => cb({ isSuccess: true, value: response }, request));
|
|
150
150
|
return response;
|
|
151
151
|
}
|
|
152
152
|
catch (e) {
|
|
153
|
-
this.
|
|
153
|
+
this._requestCompletionCallbacks.forEach((cb) => cb({ isSuccess: false, error: e }, request));
|
|
154
154
|
if (!(0, types_1.isHTTPError)(e))
|
|
155
155
|
throw e;
|
|
156
156
|
const { response } = e;
|
|
@@ -250,16 +250,16 @@ class HevyAPIClient {
|
|
|
250
250
|
* This is a lower level API than {@link attachErrorHandler} - prefer using
|
|
251
251
|
* that one instead of this one if it's enough to suit your needs.
|
|
252
252
|
*/
|
|
253
|
-
|
|
254
|
-
this.
|
|
253
|
+
attachRequestCompletionCallback(onResult) {
|
|
254
|
+
this._requestCompletionCallbacks.push(onResult);
|
|
255
255
|
}
|
|
256
|
-
|
|
257
|
-
this.
|
|
256
|
+
removeRequestCompletionCallbacks() {
|
|
257
|
+
this._requestCompletionCallbacks.length = 0;
|
|
258
258
|
}
|
|
259
259
|
/**
|
|
260
260
|
* Adds a callback to be executed on receiving an HTTP error from the server.
|
|
261
261
|
* This callback will not be executed for any other type of error, such as a
|
|
262
|
-
* network error. For that and more, use {@link
|
|
262
|
+
* network error. For that and more, use {@link attachRequestCompletionCallback}.
|
|
263
263
|
*/
|
|
264
264
|
attachErrorHandler(onError) {
|
|
265
265
|
this._errorHandlers.push(onError);
|
package/built/API/types.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface HTTPRequestFactory<T = unknown> {
|
|
|
23
23
|
headers: Record<string, string>;
|
|
24
24
|
try(): Promise<HTTPResponse<T>>;
|
|
25
25
|
}
|
|
26
|
-
export type
|
|
26
|
+
export type HTTPRequestCompletionCallback<T = unknown, R = unknown> = (result: Result<HTTPResponse<T>>, request: HTTPRequestFactory<R>) => void;
|
|
27
27
|
export type HTTPErrorHandler<E, T = unknown, R = unknown> = (response: HTTPResponse<T>, request: HTTPRequestFactory<R>, extraData: E) => void;
|
|
28
28
|
export interface HTTPResponse<T = unknown> {
|
|
29
29
|
status: number;
|