@openlifelog/sdk 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openlifelog/sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "TypeScript SDK for the OpenLifeLog API - A comprehensive fitness and nutrition tracking platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,4 +1,5 @@
1
1
  import type { HttpClient } from '../utils/http';
2
+ import type { ResolvedConfig } from '../config';
2
3
  import type {
3
4
  UserGoal,
4
5
  CreateUserGoalRequest,
@@ -13,13 +14,14 @@ import type {
13
14
  ListNutritionGoalsHistoryParams,
14
15
  ListResponse,
15
16
  } from '../types';
17
+ import { convertNutritionGoalsToMetric, convertNutritionGoalsFromMetric } from '../utils/units';
16
18
 
17
19
  /**
18
20
  * Goals resource
19
- * Handles user goals and nutrition goals
21
+ * Handles user goals and nutrition goals with automatic unit conversion
20
22
  */
21
23
  export class GoalsResource {
22
- constructor(private http: HttpClient) {}
24
+ constructor(private http: HttpClient, private config: ResolvedConfig) {}
23
25
 
24
26
  /**
25
27
  * Get active user goals
@@ -81,6 +83,11 @@ export class GoalsResource {
81
83
  */
82
84
  async getNutritionGoals(): Promise<UserNutritionGoals> {
83
85
  const response = await this.http.get<UserNutritionGoals>('/v1/nutrition/goals');
86
+
87
+ if (this.config.autoConvertUnits) {
88
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
89
+ }
90
+
84
91
  return response.data;
85
92
  }
86
93
 
@@ -89,6 +96,11 @@ export class GoalsResource {
89
96
  */
90
97
  async getNutritionGoalsByDate(date: string): Promise<UserNutritionGoals> {
91
98
  const response = await this.http.get<UserNutritionGoals>(`/v1/nutrition/goals/date/${date}`);
99
+
100
+ if (this.config.autoConvertUnits) {
101
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
102
+ }
103
+
92
104
  return response.data;
93
105
  }
94
106
 
@@ -96,7 +108,16 @@ export class GoalsResource {
96
108
  * Create nutrition goals
97
109
  */
98
110
  async createNutritionGoals(request: CreateNutritionGoalsRequest): Promise<UserNutritionGoals> {
99
- const response = await this.http.post<UserNutritionGoals>('/v1/nutrition/goals', request);
111
+ const requestToSend = this.config.autoConvertUnits
112
+ ? convertNutritionGoalsToMetric(request, this.config.measurementSystem)
113
+ : request;
114
+
115
+ const response = await this.http.post<UserNutritionGoals>('/v1/nutrition/goals', requestToSend);
116
+
117
+ if (this.config.autoConvertUnits) {
118
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
119
+ }
120
+
100
121
  return response.data;
101
122
  }
102
123
 
@@ -104,7 +125,16 @@ export class GoalsResource {
104
125
  * Update nutrition goals for a specific date
105
126
  */
106
127
  async updateNutritionGoals(date: string, request: UpdateNutritionGoalsRequest): Promise<UserNutritionGoals> {
107
- const response = await this.http.put<UserNutritionGoals>(`/v1/nutrition/goals/date/${date}`, request);
128
+ const requestToSend = this.config.autoConvertUnits
129
+ ? convertNutritionGoalsToMetric(request, this.config.measurementSystem)
130
+ : request;
131
+
132
+ const response = await this.http.put<UserNutritionGoals>(`/v1/nutrition/goals/date/${date}`, requestToSend);
133
+
134
+ if (this.config.autoConvertUnits) {
135
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
136
+ }
137
+
108
138
  return response.data;
109
139
  }
110
140
 
@@ -134,6 +164,11 @@ export class GoalsResource {
134
164
  */
135
165
  async getNutritionGoalsHistory(params?: ListNutritionGoalsHistoryParams): Promise<ListResponse<UserNutritionGoals>> {
136
166
  const response = await this.http.get<ListResponse<UserNutritionGoals>>('/v1/nutrition/goals/history', params);
167
+
168
+ if (this.config.autoConvertUnits) {
169
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
170
+ }
171
+
137
172
  return response.data;
138
173
  }
139
174
 
@@ -1,4 +1,5 @@
1
1
  import type { HttpClient } from '../utils/http';
2
+ import type { ResolvedConfig } from '../config';
2
3
  import type {
3
4
  Metric,
4
5
  MetricEvent,
@@ -11,13 +12,14 @@ import type {
11
12
  ListResponse,
12
13
  } from '../types';
13
14
  import { createPaginatedIterator, type PaginatedIterator } from '../utils/pagination';
15
+ import { WeightConverter } from '../utils/units';
14
16
 
15
17
  /**
16
18
  * Metrics resource
17
- * Handles metric tracking operations
19
+ * Handles metric tracking operations with automatic unit conversion
18
20
  */
19
21
  export class MetricsResource {
20
- constructor(private http: HttpClient) {}
22
+ constructor(private http: HttpClient, private config: ResolvedConfig) {}
21
23
 
22
24
  /**
23
25
  * List available metrics
@@ -48,6 +50,15 @@ export class MetricsResource {
48
50
  */
49
51
  async getDailyMetric(metricKey: string, params?: GetDailyMetricParams): Promise<DailyMetricAggregate> {
50
52
  const response = await this.http.get<DailyMetricAggregate>(`/v1/metrics/daily/${metricKey}`, params);
53
+
54
+ // Convert weight metrics from kg to user preference
55
+ if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== undefined) {
56
+ const isWeightMetric = metricKey.includes('weight') || metricKey.includes('bodyweight');
57
+ if (isWeightMetric) {
58
+ response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
59
+ }
60
+ }
61
+
51
62
  return response.data;
52
63
  }
53
64
 
@@ -56,6 +67,23 @@ export class MetricsResource {
56
67
  */
57
68
  async listEvents(params?: ListMetricEventsParams): Promise<ListResponse<MetricEvent>> {
58
69
  const response = await this.http.get<ListResponse<MetricEvent>>('/v1/metric-events', params);
70
+
71
+ // Convert weight values in metric events
72
+ if (this.config.autoConvertUnits && response.data.data) {
73
+ response.data.data = response.data.data.map((event: MetricEvent) => {
74
+ if (event.value !== null && event.value !== undefined) {
75
+ const isWeightMetric = event.metricKey?.includes('weight') || event.metricKey?.includes('bodyweight');
76
+ if (isWeightMetric) {
77
+ return {
78
+ ...event,
79
+ value: WeightConverter.fromMetric(event.value, this.config.measurementSystem),
80
+ };
81
+ }
82
+ }
83
+ return event;
84
+ });
85
+ }
86
+
59
87
  return response.data;
60
88
  }
61
89
 
@@ -73,6 +101,15 @@ export class MetricsResource {
73
101
  */
74
102
  async getEvent(eventId: string): Promise<MetricEvent> {
75
103
  const response = await this.http.get<MetricEvent>(`/v1/metric-events/${eventId}`);
104
+
105
+ // Convert weight value if it's a weight metric
106
+ if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== undefined) {
107
+ const isWeightMetric = response.data.metricKey?.includes('weight') || response.data.metricKey?.includes('bodyweight');
108
+ if (isWeightMetric) {
109
+ response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
110
+ }
111
+ }
112
+
76
113
  return response.data;
77
114
  }
78
115
 
@@ -80,7 +117,25 @@ export class MetricsResource {
80
117
  * Log a metric value (convenience method)
81
118
  */
82
119
  async log(request: CreateMetricEventRequest): Promise<MetricEvent> {
83
- const response = await this.http.post<MetricEvent>('/v1/metric-events', request);
120
+ // Convert weight value to metric before sending
121
+ const requestToSend = { ...request };
122
+ if (this.config.autoConvertUnits && requestToSend.value !== null && requestToSend.value !== undefined) {
123
+ const isWeightMetric = requestToSend.metricKey?.includes('weight') || requestToSend.metricKey?.includes('bodyweight');
124
+ if (isWeightMetric) {
125
+ requestToSend.value = WeightConverter.toMetric(requestToSend.value, this.config.measurementSystem);
126
+ }
127
+ }
128
+
129
+ const response = await this.http.post<MetricEvent>('/v1/metric-events', requestToSend);
130
+
131
+ // Convert response back to user preference
132
+ if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== undefined) {
133
+ const isWeightMetric = response.data.metricKey?.includes('weight') || response.data.metricKey?.includes('bodyweight');
134
+ if (isWeightMetric) {
135
+ response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
136
+ }
137
+ }
138
+
84
139
  return response.data;
85
140
  }
86
141
 
@@ -95,14 +150,42 @@ export class MetricsResource {
95
150
  * Bulk create metric events
96
151
  */
97
152
  async bulkCreateEvents(request: BulkCreateMetricEventsRequest): Promise<void> {
98
- await this.http.post('/v1/metric-events/bulk', request);
153
+ // Convert weight values in bulk request
154
+ const requestToSend = { ...request };
155
+ if (this.config.autoConvertUnits && requestToSend.metrics) {
156
+ requestToSend.metrics = requestToSend.metrics.map((event: CreateMetricEventRequest) => {
157
+ if (event.value !== null && event.value !== undefined) {
158
+ const isWeightMetric = event.metricKey?.includes('weight') || event.metricKey?.includes('bodyweight');
159
+ if (isWeightMetric) {
160
+ return {
161
+ ...event,
162
+ value: WeightConverter.toMetric(event.value, this.config.measurementSystem),
163
+ };
164
+ }
165
+ }
166
+ return event;
167
+ });
168
+ }
169
+
170
+ await this.http.post('/v1/metric-events/bulk', requestToSend);
99
171
  }
100
172
 
101
173
  /**
102
174
  * Update a metric event
175
+ * Note: metricKey cannot be changed, so we can't determine if this is a weight metric from the request alone.
176
+ * We'll convert the value assuming it follows the user's preference setting.
103
177
  */
104
178
  async updateEvent(eventId: string, request: UpdateMetricEventRequest): Promise<MetricEvent> {
105
179
  const response = await this.http.put<MetricEvent>(`/v1/metric-events/${eventId}`, request);
180
+
181
+ // Convert response back to user preference
182
+ if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== undefined) {
183
+ const isWeightMetric = response.data.metricKey?.includes('weight') || response.data.metricKey?.includes('bodyweight');
184
+ if (isWeightMetric) {
185
+ response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
186
+ }
187
+ }
188
+
106
189
  return response.data;
107
190
  }
108
191
 
@@ -1,4 +1,5 @@
1
1
  import type { HttpClient } from '../utils/http';
2
+ import type { ResolvedConfig } from '../config';
2
3
  import type {
3
4
  Program,
4
5
  CreateProgramRequest,
@@ -11,19 +12,25 @@ import type {
11
12
  ListResponse,
12
13
  ListParams,
13
14
  } from '../types';
15
+ import { convertWorkoutDataToMetric, convertWorkoutDataFromMetric } from '../utils/units';
14
16
 
15
17
  /**
16
18
  * Programs resource
17
- * Handles training program operations
19
+ * Handles training program operations with automatic unit conversion
18
20
  */
19
21
  export class ProgramsResource {
20
- constructor(private http: HttpClient) {}
22
+ constructor(private http: HttpClient, private config: ResolvedConfig) {}
21
23
 
22
24
  /**
23
25
  * List user's programs and enrollments
24
26
  */
25
27
  async list(params?: ListParams): Promise<ListResponse<Program>> {
26
28
  const response = await this.http.get<ListResponse<Program>>('/v1/programs', params);
29
+
30
+ if (this.config.autoConvertUnits) {
31
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
32
+ }
33
+
27
34
  return response.data;
28
35
  }
29
36
 
@@ -32,6 +39,11 @@ export class ProgramsResource {
32
39
  */
33
40
  async listTemplates(params?: ListParams): Promise<ListResponse<Program>> {
34
41
  const response = await this.http.get<ListResponse<Program>>('/v1/programs/templates', params);
42
+
43
+ if (this.config.autoConvertUnits) {
44
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
45
+ }
46
+
35
47
  return response.data;
36
48
  }
37
49
 
@@ -39,7 +51,16 @@ export class ProgramsResource {
39
51
  * Create a new program
40
52
  */
41
53
  async create(request: CreateProgramRequest): Promise<Program> {
42
- const response = await this.http.post<Program>('/v1/programs', request);
54
+ const requestToSend = this.config.autoConvertUnits
55
+ ? convertWorkoutDataToMetric(request, this.config.measurementSystem)
56
+ : request;
57
+
58
+ const response = await this.http.post<Program>('/v1/programs', requestToSend);
59
+
60
+ if (this.config.autoConvertUnits) {
61
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
62
+ }
63
+
43
64
  return response.data;
44
65
  }
45
66
 
@@ -48,6 +69,11 @@ export class ProgramsResource {
48
69
  */
49
70
  async get(programId: string): Promise<Program> {
50
71
  const response = await this.http.get<Program>(`/v1/programs/${programId}`);
72
+
73
+ if (this.config.autoConvertUnits) {
74
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
75
+ }
76
+
51
77
  return response.data;
52
78
  }
53
79
 
@@ -55,7 +81,16 @@ export class ProgramsResource {
55
81
  * Update a program
56
82
  */
57
83
  async update(programId: string, request: UpdateProgramRequest): Promise<Program> {
58
- const response = await this.http.put<Program>(`/v1/programs/${programId}`, request);
84
+ const requestToSend = this.config.autoConvertUnits
85
+ ? convertWorkoutDataToMetric(request, this.config.measurementSystem)
86
+ : request;
87
+
88
+ const response = await this.http.put<Program>(`/v1/programs/${programId}`, requestToSend);
89
+
90
+ if (this.config.autoConvertUnits) {
91
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
92
+ }
93
+
59
94
  return response.data;
60
95
  }
61
96
 
@@ -118,6 +153,11 @@ export class ProgramsResource {
118
153
  */
119
154
  async getCurrentWeek(enrollmentId: string): Promise<CurrentWeekSchedule> {
120
155
  const response = await this.http.get<CurrentWeekSchedule>(`/v1/enrollments/${enrollmentId}/current-week`);
156
+
157
+ if (this.config.autoConvertUnits) {
158
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
159
+ }
160
+
121
161
  return response.data;
122
162
  }
123
163
  }
@@ -1,4 +1,5 @@
1
1
  import type { HttpClient } from '../utils/http';
2
+ import type { ResolvedConfig } from '../config';
2
3
  import type {
3
4
  WorkoutSession,
4
5
  CreateWorkoutSessionRequest,
@@ -11,19 +12,25 @@ import type {
11
12
  AddExerciseItem,
12
13
  } from '../types';
13
14
  import { createPaginatedIterator, type PaginatedIterator } from '../utils/pagination';
15
+ import { convertWorkoutDataToMetric, convertWorkoutDataFromMetric } from '../utils/units';
14
16
 
15
17
  /**
16
18
  * Workout Sessions resource
17
- * Handles workout performance tracking
19
+ * Handles workout performance tracking with automatic unit conversion
18
20
  */
19
21
  export class SessionsResource {
20
- constructor(private http: HttpClient) {}
22
+ constructor(private http: HttpClient, private config: ResolvedConfig) {}
21
23
 
22
24
  /**
23
25
  * List workout sessions with filtering
24
26
  */
25
27
  async list(params?: ListWorkoutSessionsParams): Promise<ListResponse<WorkoutSession>> {
26
28
  const response = await this.http.get<ListResponse<WorkoutSession>>('/v1/workout-sessions', params);
29
+
30
+ if (this.config.autoConvertUnits) {
31
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
32
+ }
33
+
27
34
  return response.data;
28
35
  }
29
36
 
@@ -40,7 +47,16 @@ export class SessionsResource {
40
47
  * Create a new workout session
41
48
  */
42
49
  async create(request: CreateWorkoutSessionRequest): Promise<WorkoutSession> {
43
- const response = await this.http.post<WorkoutSession>('/v1/workout-sessions', request);
50
+ const requestToSend = this.config.autoConvertUnits
51
+ ? convertWorkoutDataToMetric(request, this.config.measurementSystem)
52
+ : request;
53
+
54
+ const response = await this.http.post<WorkoutSession>('/v1/workout-sessions', requestToSend);
55
+
56
+ if (this.config.autoConvertUnits) {
57
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
58
+ }
59
+
44
60
  return response.data;
45
61
  }
46
62
 
@@ -56,6 +72,11 @@ export class SessionsResource {
56
72
  */
57
73
  async get(sessionId: string): Promise<WorkoutSession> {
58
74
  const response = await this.http.get<WorkoutSession>(`/v1/workout-sessions/${sessionId}`);
75
+
76
+ if (this.config.autoConvertUnits) {
77
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
78
+ }
79
+
59
80
  return response.data;
60
81
  }
61
82
 
@@ -63,7 +84,16 @@ export class SessionsResource {
63
84
  * Update a workout session
64
85
  */
65
86
  async update(sessionId: string, request: UpdateWorkoutSessionRequest): Promise<WorkoutSession> {
66
- const response = await this.http.patch<WorkoutSession>(`/v1/workout-sessions/${sessionId}`, request);
87
+ const requestToSend = this.config.autoConvertUnits
88
+ ? convertWorkoutDataToMetric(request, this.config.measurementSystem)
89
+ : request;
90
+
91
+ const response = await this.http.patch<WorkoutSession>(`/v1/workout-sessions/${sessionId}`, requestToSend);
92
+
93
+ if (this.config.autoConvertUnits) {
94
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
95
+ }
96
+
67
97
  return response.data;
68
98
  }
69
99
 
@@ -105,6 +135,11 @@ export class SessionsResource {
105
135
  */
106
136
  async getSessionsByWorkout(workoutId: string, params?: ListWorkoutSessionsParams): Promise<ListResponse<WorkoutSession>> {
107
137
  const response = await this.http.get<ListResponse<WorkoutSession>>(`/v1/workouts/${workoutId}/sessions`, params);
138
+
139
+ if (this.config.autoConvertUnits) {
140
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
141
+ }
142
+
108
143
  return response.data;
109
144
  }
110
145
 
@@ -113,6 +148,11 @@ export class SessionsResource {
113
148
  */
114
149
  async getExerciseHistory(exerciseId: string): Promise<ExerciseHistory> {
115
150
  const response = await this.http.get<ExerciseHistory>(`/v1/exercises/${exerciseId}/history`);
151
+
152
+ if (this.config.autoConvertUnits) {
153
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
154
+ }
155
+
116
156
  return response.data;
117
157
  }
118
158
 
@@ -121,6 +161,11 @@ export class SessionsResource {
121
161
  */
122
162
  async getPersonalRecords(): Promise<ListResponse<PersonalRecord>> {
123
163
  const response = await this.http.get<ListResponse<PersonalRecord>>('/v1/personal-records');
164
+
165
+ if (this.config.autoConvertUnits) {
166
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
167
+ }
168
+
124
169
  return response.data;
125
170
  }
126
171
 
@@ -129,6 +174,11 @@ export class SessionsResource {
129
174
  */
130
175
  async getExercisePersonalRecords(exerciseId: string): Promise<ListResponse<PersonalRecord>> {
131
176
  const response = await this.http.get<ListResponse<PersonalRecord>>(`/v1/exercises/${exerciseId}/personal-records`);
177
+
178
+ if (this.config.autoConvertUnits) {
179
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
180
+ }
181
+
132
182
  return response.data;
133
183
  }
134
184
 
@@ -137,6 +187,11 @@ export class SessionsResource {
137
187
  */
138
188
  async getPersonalRecordHistory(exerciseId: string): Promise<ListResponse<PersonalRecordHistory>> {
139
189
  const response = await this.http.get<ListResponse<PersonalRecordHistory>>(`/v1/exercises/${exerciseId}/personal-records/history`);
190
+
191
+ if (this.config.autoConvertUnits) {
192
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
193
+ }
194
+
140
195
  return response.data;
141
196
  }
142
197
  }
@@ -1,4 +1,5 @@
1
1
  import type { HttpClient } from '../utils/http';
2
+ import type { ResolvedConfig } from '../config';
2
3
  import type {
3
4
  Workout,
4
5
  CreateWorkoutRequest,
@@ -10,19 +11,25 @@ import type {
10
11
  CountResponse,
11
12
  } from '../types';
12
13
  import { createPaginatedIterator, type PaginatedIterator } from '../utils/pagination';
14
+ import { convertWorkoutDataToMetric, convertWorkoutDataFromMetric } from '../utils/units';
13
15
 
14
16
  /**
15
17
  * Workouts resource
16
- * Handles workout template operations
18
+ * Handles workout template operations with automatic unit conversion
17
19
  */
18
20
  export class WorkoutsResource {
19
- constructor(private http: HttpClient) {}
21
+ constructor(private http: HttpClient, private config: ResolvedConfig) {}
20
22
 
21
23
  /**
22
24
  * List workout templates
23
25
  */
24
26
  async list(params?: ListWorkoutsParams): Promise<ListResponse<Workout>> {
25
27
  const response = await this.http.get<ListResponse<Workout>>('/v1/workouts', params);
28
+
29
+ if (this.config.autoConvertUnits) {
30
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
31
+ }
32
+
26
33
  return response.data;
27
34
  }
28
35
 
@@ -48,6 +55,11 @@ export class WorkoutsResource {
48
55
  */
49
56
  async search(params: { q: string; limit?: number; cursor?: string }): Promise<ListResponse<Workout>> {
50
57
  const response = await this.http.get<ListResponse<Workout>>('/v1/workouts/search', params);
58
+
59
+ if (this.config.autoConvertUnits) {
60
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
61
+ }
62
+
51
63
  return response.data;
52
64
  }
53
65
 
@@ -56,6 +68,11 @@ export class WorkoutsResource {
56
68
  */
57
69
  async get(workoutId: string): Promise<Workout> {
58
70
  const response = await this.http.get<Workout>(`/v1/workouts/${workoutId}`);
71
+
72
+ if (this.config.autoConvertUnits) {
73
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
74
+ }
75
+
59
76
  return response.data;
60
77
  }
61
78
 
@@ -64,6 +81,11 @@ export class WorkoutsResource {
64
81
  */
65
82
  async create(request: CreateWorkoutRequest): Promise<Workout> {
66
83
  const response = await this.http.post<Workout>('/v1/workouts', request);
84
+
85
+ if (this.config.autoConvertUnits) {
86
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
87
+ }
88
+
67
89
  return response.data;
68
90
  }
69
91
 
@@ -72,6 +94,11 @@ export class WorkoutsResource {
72
94
  */
73
95
  async update(workoutId: string, request: UpdateWorkoutRequest): Promise<Workout> {
74
96
  const response = await this.http.put<Workout>(`/v1/workouts/${workoutId}`, request);
97
+
98
+ if (this.config.autoConvertUnits) {
99
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
100
+ }
101
+
75
102
  return response.data;
76
103
  }
77
104
 
@@ -80,6 +107,11 @@ export class WorkoutsResource {
80
107
  */
81
108
  async clone(workoutId: string): Promise<Workout> {
82
109
  const response = await this.http.post<Workout>(`/v1/workouts/${workoutId}/clone`);
110
+
111
+ if (this.config.autoConvertUnits) {
112
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
113
+ }
114
+
83
115
  return response.data;
84
116
  }
85
117
 
@@ -94,7 +126,11 @@ export class WorkoutsResource {
94
126
  * Add exercises to workout
95
127
  */
96
128
  async addExercises(workoutId: string, request: AddExercisesToWorkoutRequest): Promise<void> {
97
- await this.http.post(`/v1/workouts/${workoutId}/exercises`, request);
129
+ const requestToSend = this.config.autoConvertUnits
130
+ ? convertWorkoutDataToMetric(request, this.config.measurementSystem)
131
+ : request;
132
+
133
+ await this.http.post(`/v1/workouts/${workoutId}/exercises`, requestToSend);
98
134
  }
99
135
 
100
136
  /**
@@ -105,7 +141,11 @@ export class WorkoutsResource {
105
141
  exerciseId: string,
106
142
  request: UpdateWorkoutExerciseRequest
107
143
  ): Promise<void> {
108
- await this.http.put(`/v1/workouts/${workoutId}/exercises/${exerciseId}`, request);
144
+ const requestToSend = this.config.autoConvertUnits
145
+ ? convertWorkoutDataToMetric(request, this.config.measurementSystem)
146
+ : request;
147
+
148
+ await this.http.put(`/v1/workouts/${workoutId}/exercises/${exerciseId}`, requestToSend);
109
149
  }
110
150
 
111
151
  /**
@@ -120,6 +160,11 @@ export class WorkoutsResource {
120
160
  */
121
161
  async getWorkoutsByExercise(exerciseId: string): Promise<ListResponse<Workout>> {
122
162
  const response = await this.http.get<ListResponse<Workout>>(`/v1/exercises/${exerciseId}/workouts`);
163
+
164
+ if (this.config.autoConvertUnits) {
165
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
166
+ }
167
+
123
168
  return response.data;
124
169
  }
125
170
 
@@ -128,6 +173,11 @@ export class WorkoutsResource {
128
173
  */
129
174
  async getFavorites(params?: ListWorkoutsParams): Promise<ListResponse<Workout>> {
130
175
  const response = await this.http.get<ListResponse<Workout>>('/v1/workouts/favorites', params);
176
+
177
+ if (this.config.autoConvertUnits) {
178
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
179
+ }
180
+
131
181
  return response.data;
132
182
  }
133
183
 
package/types/exercise.ts CHANGED
@@ -18,7 +18,7 @@ import type {
18
18
  */
19
19
  export interface ExerciseCapabilities {
20
20
  supportsWeight: boolean;
21
- supportsBodyweightOnly: boolean;
21
+ isBodyweight: boolean;
22
22
  supportsAssistance: boolean;
23
23
  supportsDistance: boolean;
24
24
  supportsDuration: boolean;