hevy-shared 1.0.918 → 1.0.920
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, HTTPErrorHandler } from './types';
|
|
2
|
+
import { RequestConfig, HTTPResponse, HTTPClient, HTTPResponseHandler, 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,6 +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 _responseHandlers;
|
|
93
94
|
private _errorHandlers;
|
|
94
95
|
private _authTokenFactory;
|
|
95
96
|
private _legacyAuthToken;
|
|
@@ -123,6 +124,22 @@ export declare class HevyAPIClient<UserContext = never> {
|
|
|
123
124
|
clearAuthToken(): Promise<void>;
|
|
124
125
|
get isAuthenticated(): boolean;
|
|
125
126
|
markSessionDeleted(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Adds a callback to be executed whenever a request has finished processing.
|
|
129
|
+
* This means either that the request has received a response, or that there
|
|
130
|
+
* was an error. In the case of an error, it may be either an HTTP error from
|
|
131
|
+
* the server, or some other type of error, such as a network error.
|
|
132
|
+
*
|
|
133
|
+
* This is a lower level API than {@link attachErrorHandler} - prefer using
|
|
134
|
+
* that one instead of this one if it's enough to suit your needs.
|
|
135
|
+
*/
|
|
136
|
+
attachResponseHandler(onResponse: HTTPResponseHandler): void;
|
|
137
|
+
removeResponseHandlers(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Adds a callback to be executed on receiving an HTTP error from the server.
|
|
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 attachResponseHandler}.
|
|
142
|
+
*/
|
|
126
143
|
attachErrorHandler(onError: HTTPErrorHandler<{
|
|
127
144
|
willRetry: boolean;
|
|
128
145
|
isTokenRefreshedAfterRequest: boolean;
|
package/built/API/APIClient.js
CHANGED
|
@@ -20,6 +20,7 @@ const __1 = require("..");
|
|
|
20
20
|
const types_1 = require("./types");
|
|
21
21
|
class HevyAPIClient {
|
|
22
22
|
constructor(httpClient, config) {
|
|
23
|
+
this._responseHandlers = [];
|
|
23
24
|
this._errorHandlers = [];
|
|
24
25
|
this._authTokenFactory = {
|
|
25
26
|
type: 'value',
|
|
@@ -145,9 +146,11 @@ class HevyAPIClient {
|
|
|
145
146
|
response,
|
|
146
147
|
});
|
|
147
148
|
}
|
|
149
|
+
this._responseHandlers.forEach((cb) => cb({ isSuccess: true, value: response }, request));
|
|
148
150
|
return response;
|
|
149
151
|
}
|
|
150
152
|
catch (e) {
|
|
153
|
+
this._responseHandlers.forEach((cb) => cb({ isSuccess: false, error: e }, request));
|
|
151
154
|
if (!(0, types_1.isHTTPError)(e))
|
|
152
155
|
throw e;
|
|
153
156
|
const { response } = e;
|
|
@@ -238,6 +241,26 @@ class HevyAPIClient {
|
|
|
238
241
|
markSessionDeleted() {
|
|
239
242
|
this._lastSessionDelete = new Date();
|
|
240
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Adds a callback to be executed whenever a request has finished processing.
|
|
246
|
+
* This means either that the request has received a response, or that there
|
|
247
|
+
* was an error. In the case of an error, it may be either an HTTP error from
|
|
248
|
+
* the server, or some other type of error, such as a network error.
|
|
249
|
+
*
|
|
250
|
+
* This is a lower level API than {@link attachErrorHandler} - prefer using
|
|
251
|
+
* that one instead of this one if it's enough to suit your needs.
|
|
252
|
+
*/
|
|
253
|
+
attachResponseHandler(onResponse) {
|
|
254
|
+
this._responseHandlers.push(onResponse);
|
|
255
|
+
}
|
|
256
|
+
removeResponseHandlers() {
|
|
257
|
+
this._responseHandlers.length = 0;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Adds a callback to be executed on receiving an HTTP error from the server.
|
|
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 attachResponseHandler}.
|
|
263
|
+
*/
|
|
241
264
|
attachErrorHandler(onError) {
|
|
242
265
|
this._errorHandlers.push(onError);
|
|
243
266
|
}
|
package/built/API/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Result } from '..';
|
|
1
2
|
export interface HTTPClient {
|
|
2
3
|
get<T>(url: string, config?: RequestConfig): Promise<HTTPResponse<T>>;
|
|
3
4
|
delete<T>(url: string, config?: RequestConfig): Promise<HTTPResponse<T>>;
|
|
@@ -22,6 +23,7 @@ export interface HTTPRequestFactory<T = unknown> {
|
|
|
22
23
|
headers: Record<string, string>;
|
|
23
24
|
try(): Promise<HTTPResponse<T>>;
|
|
24
25
|
}
|
|
26
|
+
export type HTTPResponseHandler<T = unknown, R = unknown> = (response: Result<HTTPResponse<T>>, request: HTTPRequestFactory<R>) => void;
|
|
25
27
|
export type HTTPErrorHandler<E, T = unknown, R = unknown> = (response: HTTPResponse<T>, request: HTTPRequestFactory<R>, extraData: E) => void;
|
|
26
28
|
export interface HTTPResponse<T = unknown> {
|
|
27
29
|
status: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Lookup } from './typeUtils';
|
|
2
|
-
export declare const AdminPermissions: readonly ["become_user", "ip_blacklists", "featured_users", "feature_flags", "hevy_trainer", "user_account_management", "import_strong_csv", "community_management", "user_app_logs"];
|
|
2
|
+
export declare const AdminPermissions: readonly ["become_user", "ip_blacklists", "featured_users", "feature_flags", "hevy_trainer", "user_account_management", "import_strong_csv", "community_management", "user_app_logs", "backend_maintenance"];
|
|
3
3
|
export type AdminPermission = Lookup<typeof AdminPermissions>;
|
|
4
4
|
export declare const isAdminPermission: (permission?: any) => permission is AdminPermission;
|
package/built/index.d.ts
CHANGED
|
@@ -246,8 +246,7 @@ export interface UsernameAvailabilityResponse {
|
|
|
246
246
|
isAvailable: boolean;
|
|
247
247
|
suggestions: string[];
|
|
248
248
|
}
|
|
249
|
-
export interface CoachLoginResult {
|
|
250
|
-
auth_token: string;
|
|
249
|
+
export interface CoachLoginResult extends ClientAuthTokenResponse {
|
|
251
250
|
is_first_login_to_coach_platform: boolean;
|
|
252
251
|
}
|
|
253
252
|
export interface CoachSocialLoginResult extends SocialLoginResult {
|