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.
@@ -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 _authToken;
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: DeepReadonly<{
105
- authToken: ClientAuthToken | null;
105
+ setAuthToken(newAuthToken: {
106
+ authToken: DeepReadonly<ClientAuthToken> | null;
106
107
  legacyAuthToken: string | null;
107
- }>): Promise<void>;
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;
@@ -21,7 +21,10 @@ const types_1 = require("./types");
21
21
  class HevyAPIClient {
22
22
  constructor(httpClient, config) {
23
23
  this._errorHandlers = [];
24
- this._authToken = null;
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._authToken = newToken;
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
- this._authToken = authToken
185
- ? {
186
- access_token: authToken.access_token,
187
- refresh_token: authToken.refresh_token,
188
- expires_at: new Date(authToken.expires_at),
189
- }
190
- : null;
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._authToken = null;
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[];
@@ -35,7 +35,6 @@ export interface NormalizedWorkout {
35
35
  };
36
36
  clientId: string;
37
37
  biometrics?: WorkoutBiometrics;
38
- isTrainerWorkout: boolean;
39
38
  trainerProgramId: string | undefined;
40
39
  }
41
40
  export interface NormalizedSet {
@@ -154,7 +154,6 @@ class WorkoutBuilder {
154
154
  wearosWatch: false,
155
155
  workoutVisibility: 'public',
156
156
  isWorkoutBiometricsPublic: true,
157
- isTrainerWorkout: false,
158
157
  trainerProgramId: undefined,
159
158
  shareTo: {
160
159
  strava: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.823",
3
+ "version": "1.0.825",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",