@openlifelog/sdk 1.0.6 → 1.0.7

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/dist/index.d.mts CHANGED
@@ -1018,6 +1018,7 @@ declare class GoalsResource {
1018
1018
  getNutritionGoalsHistory(params?: ListNutritionGoalsHistoryParams): Promise<ListResponse<UserNutritionGoals>>;
1019
1019
  getNutritionProgress(): Promise<DailyNutritionProgress>;
1020
1020
  getNutritionProgressByDate(date: string): Promise<DailyNutritionProgress>;
1021
+ private convertNutritionProgressFromMetric;
1021
1022
  }
1022
1023
 
1023
1024
  declare class AIResource {
package/dist/index.d.ts CHANGED
@@ -1018,6 +1018,7 @@ declare class GoalsResource {
1018
1018
  getNutritionGoalsHistory(params?: ListNutritionGoalsHistoryParams): Promise<ListResponse<UserNutritionGoals>>;
1019
1019
  getNutritionProgress(): Promise<DailyNutritionProgress>;
1020
1020
  getNutritionProgressByDate(date: string): Promise<DailyNutritionProgress>;
1021
+ private convertNutritionProgressFromMetric;
1021
1022
  }
1022
1023
 
1023
1024
  declare class AIResource {
package/dist/index.js CHANGED
@@ -2163,6 +2163,9 @@ var GoalsResource = class {
2163
2163
  */
2164
2164
  async getNutritionProgress() {
2165
2165
  const response = await this.http.get("/v1/nutrition/progress/today");
2166
+ if (this.config.autoConvertUnits) {
2167
+ return this.convertNutritionProgressFromMetric(response.data);
2168
+ }
2166
2169
  return response.data;
2167
2170
  }
2168
2171
  /**
@@ -2170,8 +2173,33 @@ var GoalsResource = class {
2170
2173
  */
2171
2174
  async getNutritionProgressByDate(date) {
2172
2175
  const response = await this.http.get(`/v1/nutrition/progress/date/${date}`);
2176
+ if (this.config.autoConvertUnits) {
2177
+ return this.convertNutritionProgressFromMetric(response.data);
2178
+ }
2173
2179
  return response.data;
2174
2180
  }
2181
+ /**
2182
+ * Convert nutrition progress data from metric to user's preferred units
2183
+ * Handles water values in the progress data
2184
+ */
2185
+ convertNutritionProgressFromMetric(data) {
2186
+ if (!data || !data.progress) {
2187
+ return data;
2188
+ }
2189
+ const converted = { ...data };
2190
+ converted.progress = data.progress.map((nutrient) => {
2191
+ if (nutrient.nutrientKey === "water" && this.config.measurementSystem === "imperial") {
2192
+ return {
2193
+ ...nutrient,
2194
+ current: nutrient.current ? VolumeConverter.fromMetric(nutrient.current, this.config.measurementSystem) : nutrient.current,
2195
+ target: nutrient.target ? VolumeConverter.fromMetric(nutrient.target, this.config.measurementSystem) : nutrient.target,
2196
+ remaining: nutrient.remaining ? VolumeConverter.fromMetric(nutrient.remaining, this.config.measurementSystem) : nutrient.remaining
2197
+ };
2198
+ }
2199
+ return nutrient;
2200
+ });
2201
+ return converted;
2202
+ }
2175
2203
  };
2176
2204
 
2177
2205
  // resources/ai.ts
package/dist/index.mjs CHANGED
@@ -2109,6 +2109,9 @@ var GoalsResource = class {
2109
2109
  */
2110
2110
  async getNutritionProgress() {
2111
2111
  const response = await this.http.get("/v1/nutrition/progress/today");
2112
+ if (this.config.autoConvertUnits) {
2113
+ return this.convertNutritionProgressFromMetric(response.data);
2114
+ }
2112
2115
  return response.data;
2113
2116
  }
2114
2117
  /**
@@ -2116,8 +2119,33 @@ var GoalsResource = class {
2116
2119
  */
2117
2120
  async getNutritionProgressByDate(date) {
2118
2121
  const response = await this.http.get(`/v1/nutrition/progress/date/${date}`);
2122
+ if (this.config.autoConvertUnits) {
2123
+ return this.convertNutritionProgressFromMetric(response.data);
2124
+ }
2119
2125
  return response.data;
2120
2126
  }
2127
+ /**
2128
+ * Convert nutrition progress data from metric to user's preferred units
2129
+ * Handles water values in the progress data
2130
+ */
2131
+ convertNutritionProgressFromMetric(data) {
2132
+ if (!data || !data.progress) {
2133
+ return data;
2134
+ }
2135
+ const converted = { ...data };
2136
+ converted.progress = data.progress.map((nutrient) => {
2137
+ if (nutrient.nutrientKey === "water" && this.config.measurementSystem === "imperial") {
2138
+ return {
2139
+ ...nutrient,
2140
+ current: nutrient.current ? VolumeConverter.fromMetric(nutrient.current, this.config.measurementSystem) : nutrient.current,
2141
+ target: nutrient.target ? VolumeConverter.fromMetric(nutrient.target, this.config.measurementSystem) : nutrient.target,
2142
+ remaining: nutrient.remaining ? VolumeConverter.fromMetric(nutrient.remaining, this.config.measurementSystem) : nutrient.remaining
2143
+ };
2144
+ }
2145
+ return nutrient;
2146
+ });
2147
+ return converted;
2148
+ }
2121
2149
  };
2122
2150
 
2123
2151
  // resources/ai.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openlifelog/sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
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",
@@ -14,7 +14,7 @@ import type {
14
14
  ListNutritionGoalsHistoryParams,
15
15
  ListResponse,
16
16
  } from '../types';
17
- import { convertNutritionGoalsToMetric, convertNutritionGoalsFromMetric } from '../utils/units';
17
+ import { convertNutritionGoalsToMetric, convertNutritionGoalsFromMetric, VolumeConverter } from '../utils/units';
18
18
 
19
19
  /**
20
20
  * Goals resource
@@ -177,6 +177,11 @@ export class GoalsResource {
177
177
  */
178
178
  async getNutritionProgress(): Promise<DailyNutritionProgress> {
179
179
  const response = await this.http.get<DailyNutritionProgress>('/v1/nutrition/progress/today');
180
+
181
+ if (this.config.autoConvertUnits) {
182
+ return this.convertNutritionProgressFromMetric(response.data);
183
+ }
184
+
180
185
  return response.data;
181
186
  }
182
187
 
@@ -185,6 +190,37 @@ export class GoalsResource {
185
190
  */
186
191
  async getNutritionProgressByDate(date: string): Promise<DailyNutritionProgress> {
187
192
  const response = await this.http.get<DailyNutritionProgress>(`/v1/nutrition/progress/date/${date}`);
193
+
194
+ if (this.config.autoConvertUnits) {
195
+ return this.convertNutritionProgressFromMetric(response.data);
196
+ }
197
+
188
198
  return response.data;
189
199
  }
200
+
201
+ /**
202
+ * Convert nutrition progress data from metric to user's preferred units
203
+ * Handles water values in the progress data
204
+ */
205
+ private convertNutritionProgressFromMetric(data: DailyNutritionProgress): DailyNutritionProgress {
206
+ if (!data || !data.progress) {
207
+ return data;
208
+ }
209
+
210
+ const converted = { ...data };
211
+ converted.progress = data.progress.map(nutrient => {
212
+ // Only convert water from ml to oz/fl oz for imperial users
213
+ if (nutrient.nutrientKey === 'water' && this.config.measurementSystem === 'imperial') {
214
+ return {
215
+ ...nutrient,
216
+ current: nutrient.current ? VolumeConverter.fromMetric(nutrient.current, this.config.measurementSystem) : nutrient.current,
217
+ target: nutrient.target ? VolumeConverter.fromMetric(nutrient.target, this.config.measurementSystem) : nutrient.target,
218
+ remaining: nutrient.remaining ? VolumeConverter.fromMetric(nutrient.remaining, this.config.measurementSystem) : nutrient.remaining,
219
+ };
220
+ }
221
+ return nutrient;
222
+ });
223
+
224
+ return converted;
225
+ }
190
226
  }