@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/dist/index.js CHANGED
@@ -397,6 +397,8 @@ var METERS_TO_FEET = 3.28084;
397
397
  var FEET_TO_METERS = 1 / METERS_TO_FEET;
398
398
  var CM_TO_INCHES = 0.393701;
399
399
  var INCHES_TO_CM = 1 / CM_TO_INCHES;
400
+ var ML_TO_FL_OZ = 0.033814;
401
+ var FL_OZ_TO_ML = 1 / ML_TO_FL_OZ;
400
402
  var WeightConverter = class {
401
403
  /**
402
404
  * Convert kilograms to pounds
@@ -525,6 +527,38 @@ var HeightConverter = class {
525
527
  return value;
526
528
  }
527
529
  };
530
+ var VolumeConverter = class {
531
+ /**
532
+ * Convert milliliters to fluid ounces
533
+ */
534
+ static mlToFlOz(ml) {
535
+ return ml * ML_TO_FL_OZ;
536
+ }
537
+ /**
538
+ * Convert fluid ounces to milliliters
539
+ */
540
+ static flOzToMl(flOz) {
541
+ return flOz * FL_OZ_TO_ML;
542
+ }
543
+ /**
544
+ * Convert volume from metric to the target measurement system
545
+ */
546
+ static fromMetric(ml, targetSystem) {
547
+ if (targetSystem === "imperial") {
548
+ return this.mlToFlOz(ml);
549
+ }
550
+ return ml;
551
+ }
552
+ /**
553
+ * Convert volume to metric from the source measurement system
554
+ */
555
+ static toMetric(value, sourceSystem) {
556
+ if (sourceSystem === "imperial") {
557
+ return this.flOzToMl(value);
558
+ }
559
+ return value;
560
+ }
561
+ };
528
562
  var UnitConverter = class {
529
563
  constructor(measurementSystem = "metric") {
530
564
  this.measurementSystem = measurementSystem;
@@ -614,6 +648,183 @@ var UnitConverter = class {
614
648
  function createUnitConverter(measurementSystem = "metric") {
615
649
  return new UnitConverter(measurementSystem);
616
650
  }
651
+ function convertSetDataToMetric(setData, measurementSystem) {
652
+ if (!setData || typeof setData !== "object") {
653
+ return setData;
654
+ }
655
+ const converted = { ...setData };
656
+ if (converted.weight !== null && converted.weight !== void 0) {
657
+ converted.weight = WeightConverter.toMetric(converted.weight, measurementSystem);
658
+ }
659
+ if (converted.distance !== null && converted.distance !== void 0) {
660
+ const isMiles = measurementSystem === "imperial" && converted.distance <= 200;
661
+ converted.distance = DistanceConverter.toMetric(converted.distance, measurementSystem, isMiles);
662
+ }
663
+ return converted;
664
+ }
665
+ function convertSetDataFromMetric(setData, measurementSystem) {
666
+ if (!setData || typeof setData !== "object") {
667
+ return setData;
668
+ }
669
+ const converted = { ...setData };
670
+ if (converted.weight !== null && converted.weight !== void 0) {
671
+ converted.weight = WeightConverter.fromMetric(converted.weight, measurementSystem);
672
+ }
673
+ if (converted.distance !== null && converted.distance !== void 0) {
674
+ const preferMiles = measurementSystem === "imperial" && converted.distance > 1609;
675
+ converted.distance = DistanceConverter.fromMetric(converted.distance, measurementSystem, preferMiles);
676
+ }
677
+ return converted;
678
+ }
679
+ function convertSetsDataToMetric(setsData, measurementSystem) {
680
+ if (!setsData || !Array.isArray(setsData)) {
681
+ return setsData || [];
682
+ }
683
+ return setsData.map((setData) => convertSetDataToMetric(setData, measurementSystem));
684
+ }
685
+ function convertSetsDataFromMetric(setsData, measurementSystem) {
686
+ if (!setsData || !Array.isArray(setsData)) {
687
+ return setsData || [];
688
+ }
689
+ return setsData.map((setData) => convertSetDataFromMetric(setData, measurementSystem));
690
+ }
691
+ function convertWorkoutDataToMetric(data, measurementSystem) {
692
+ if (!data || typeof data !== "object") {
693
+ return data;
694
+ }
695
+ if (Array.isArray(data)) {
696
+ return data.map((item) => convertWorkoutDataToMetric(item, measurementSystem));
697
+ }
698
+ const converted = { ...data };
699
+ if (converted.setsData && Array.isArray(converted.setsData)) {
700
+ converted.setsData = convertSetsDataToMetric(converted.setsData, measurementSystem);
701
+ }
702
+ if (converted.sets && Array.isArray(converted.sets)) {
703
+ converted.sets = convertSetsDataToMetric(converted.sets, measurementSystem);
704
+ }
705
+ if (converted.exercises && Array.isArray(converted.exercises)) {
706
+ converted.exercises = converted.exercises.map(
707
+ (exercise) => convertWorkoutDataToMetric(exercise, measurementSystem)
708
+ );
709
+ }
710
+ if (converted.schedule && Array.isArray(converted.schedule)) {
711
+ converted.schedule = converted.schedule.map(
712
+ (day) => convertWorkoutDataToMetric(day, measurementSystem)
713
+ );
714
+ }
715
+ if (converted.userBodyweight !== null && converted.userBodyweight !== void 0) {
716
+ converted.userBodyweight = WeightConverter.toMetric(converted.userBodyweight, measurementSystem);
717
+ }
718
+ if (converted.totalVolume !== null && converted.totalVolume !== void 0) {
719
+ converted.totalVolume = WeightConverter.toMetric(converted.totalVolume, measurementSystem);
720
+ }
721
+ if (converted.totalDistance !== null && converted.totalDistance !== void 0) {
722
+ const preferMiles = measurementSystem === "imperial" && converted.totalDistance <= 200;
723
+ converted.totalDistance = DistanceConverter.toMetric(converted.totalDistance, measurementSystem, preferMiles);
724
+ }
725
+ return converted;
726
+ }
727
+ function convertWorkoutDataFromMetric(data, measurementSystem) {
728
+ if (!data || typeof data !== "object") {
729
+ return data;
730
+ }
731
+ if (Array.isArray(data)) {
732
+ return data.map((item) => convertWorkoutDataFromMetric(item, measurementSystem));
733
+ }
734
+ const converted = { ...data };
735
+ if (converted.setsData && Array.isArray(converted.setsData)) {
736
+ converted.setsData = convertSetsDataFromMetric(converted.setsData, measurementSystem);
737
+ }
738
+ if (converted.sets && Array.isArray(converted.sets)) {
739
+ converted.sets = convertSetsDataFromMetric(converted.sets, measurementSystem);
740
+ }
741
+ if (converted.exercises && Array.isArray(converted.exercises)) {
742
+ converted.exercises = converted.exercises.map(
743
+ (exercise) => convertWorkoutDataFromMetric(exercise, measurementSystem)
744
+ );
745
+ }
746
+ if (converted.schedule && Array.isArray(converted.schedule)) {
747
+ converted.schedule = converted.schedule.map(
748
+ (day) => convertWorkoutDataFromMetric(day, measurementSystem)
749
+ );
750
+ }
751
+ if (converted.data && Array.isArray(converted.data)) {
752
+ converted.data = converted.data.map(
753
+ (item) => convertWorkoutDataFromMetric(item, measurementSystem)
754
+ );
755
+ }
756
+ if (converted.userBodyweight !== null && converted.userBodyweight !== void 0) {
757
+ converted.userBodyweight = WeightConverter.fromMetric(converted.userBodyweight, measurementSystem);
758
+ }
759
+ if (converted.totalVolume !== null && converted.totalVolume !== void 0) {
760
+ converted.totalVolume = WeightConverter.fromMetric(converted.totalVolume, measurementSystem);
761
+ }
762
+ if (converted.totalDistance !== null && converted.totalDistance !== void 0) {
763
+ const preferMiles = measurementSystem === "imperial" && converted.totalDistance > 1609;
764
+ converted.totalDistance = DistanceConverter.fromMetric(converted.totalDistance, measurementSystem, preferMiles);
765
+ }
766
+ if (converted.value !== null && converted.value !== void 0 && converted.unit) {
767
+ if (converted.unit === "kg" || converted.unit === "lbs") {
768
+ converted.value = WeightConverter.fromMetric(converted.value, measurementSystem);
769
+ converted.unit = measurementSystem === "imperial" ? "lbs" : "kg";
770
+ }
771
+ }
772
+ return converted;
773
+ }
774
+ function convertNutritionGoalsToMetric(data, measurementSystem) {
775
+ if (!data || typeof data !== "object") {
776
+ return data;
777
+ }
778
+ const converted = { ...data };
779
+ if (converted.goals && typeof converted.goals === "object") {
780
+ converted.goals = { ...converted.goals };
781
+ if (converted.goals.water && typeof converted.goals.water === "object") {
782
+ const waterGoal = { ...converted.goals.water };
783
+ if (waterGoal.value !== null && waterGoal.value !== void 0) {
784
+ waterGoal.value = VolumeConverter.toMetric(waterGoal.value, measurementSystem);
785
+ }
786
+ if (waterGoal.min !== null && waterGoal.min !== void 0) {
787
+ waterGoal.min = VolumeConverter.toMetric(waterGoal.min, measurementSystem);
788
+ }
789
+ if (waterGoal.max !== null && waterGoal.max !== void 0) {
790
+ waterGoal.max = VolumeConverter.toMetric(waterGoal.max, measurementSystem);
791
+ }
792
+ converted.goals.water = waterGoal;
793
+ }
794
+ }
795
+ return converted;
796
+ }
797
+ function convertNutritionGoalsFromMetric(data, measurementSystem) {
798
+ if (!data || typeof data !== "object") {
799
+ return data;
800
+ }
801
+ if (Array.isArray(data)) {
802
+ return data.map((item) => convertNutritionGoalsFromMetric(item, measurementSystem));
803
+ }
804
+ const converted = { ...data };
805
+ if (converted.data && Array.isArray(converted.data)) {
806
+ converted.data = converted.data.map(
807
+ (item) => convertNutritionGoalsFromMetric(item, measurementSystem)
808
+ );
809
+ }
810
+ if (converted.goals && typeof converted.goals === "object") {
811
+ converted.goals = { ...converted.goals };
812
+ if (converted.goals.water && typeof converted.goals.water === "object") {
813
+ const waterGoal = { ...converted.goals.water };
814
+ if (waterGoal.value !== null && waterGoal.value !== void 0) {
815
+ waterGoal.value = VolumeConverter.fromMetric(waterGoal.value, measurementSystem);
816
+ }
817
+ if (waterGoal.min !== null && waterGoal.min !== void 0) {
818
+ waterGoal.min = VolumeConverter.fromMetric(waterGoal.min, measurementSystem);
819
+ }
820
+ if (waterGoal.max !== null && waterGoal.max !== void 0) {
821
+ waterGoal.max = VolumeConverter.fromMetric(waterGoal.max, measurementSystem);
822
+ }
823
+ converted.goals.water = waterGoal;
824
+ }
825
+ }
826
+ return converted;
827
+ }
617
828
 
618
829
  // resources/auth.ts
619
830
  var AuthResource = class {
@@ -1241,14 +1452,18 @@ var ExercisesResource = class {
1241
1452
 
1242
1453
  // resources/workouts.ts
1243
1454
  var WorkoutsResource = class {
1244
- constructor(http) {
1455
+ constructor(http, config) {
1245
1456
  this.http = http;
1457
+ this.config = config;
1246
1458
  }
1247
1459
  /**
1248
1460
  * List workout templates
1249
1461
  */
1250
1462
  async list(params) {
1251
1463
  const response = await this.http.get("/v1/workouts", params);
1464
+ if (this.config.autoConvertUnits) {
1465
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1466
+ }
1252
1467
  return response.data;
1253
1468
  }
1254
1469
  /**
@@ -1271,6 +1486,9 @@ var WorkoutsResource = class {
1271
1486
  */
1272
1487
  async search(params) {
1273
1488
  const response = await this.http.get("/v1/workouts/search", params);
1489
+ if (this.config.autoConvertUnits) {
1490
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1491
+ }
1274
1492
  return response.data;
1275
1493
  }
1276
1494
  /**
@@ -1278,6 +1496,9 @@ var WorkoutsResource = class {
1278
1496
  */
1279
1497
  async get(workoutId) {
1280
1498
  const response = await this.http.get(`/v1/workouts/${workoutId}`);
1499
+ if (this.config.autoConvertUnits) {
1500
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1501
+ }
1281
1502
  return response.data;
1282
1503
  }
1283
1504
  /**
@@ -1285,6 +1506,9 @@ var WorkoutsResource = class {
1285
1506
  */
1286
1507
  async create(request) {
1287
1508
  const response = await this.http.post("/v1/workouts", request);
1509
+ if (this.config.autoConvertUnits) {
1510
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1511
+ }
1288
1512
  return response.data;
1289
1513
  }
1290
1514
  /**
@@ -1292,6 +1516,9 @@ var WorkoutsResource = class {
1292
1516
  */
1293
1517
  async update(workoutId, request) {
1294
1518
  const response = await this.http.put(`/v1/workouts/${workoutId}`, request);
1519
+ if (this.config.autoConvertUnits) {
1520
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1521
+ }
1295
1522
  return response.data;
1296
1523
  }
1297
1524
  /**
@@ -1299,6 +1526,9 @@ var WorkoutsResource = class {
1299
1526
  */
1300
1527
  async clone(workoutId) {
1301
1528
  const response = await this.http.post(`/v1/workouts/${workoutId}/clone`);
1529
+ if (this.config.autoConvertUnits) {
1530
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1531
+ }
1302
1532
  return response.data;
1303
1533
  }
1304
1534
  /**
@@ -1311,13 +1541,15 @@ var WorkoutsResource = class {
1311
1541
  * Add exercises to workout
1312
1542
  */
1313
1543
  async addExercises(workoutId, request) {
1314
- await this.http.post(`/v1/workouts/${workoutId}/exercises`, request);
1544
+ const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
1545
+ await this.http.post(`/v1/workouts/${workoutId}/exercises`, requestToSend);
1315
1546
  }
1316
1547
  /**
1317
1548
  * Update exercise in workout
1318
1549
  */
1319
1550
  async updateExercise(workoutId, exerciseId, request) {
1320
- await this.http.put(`/v1/workouts/${workoutId}/exercises/${exerciseId}`, request);
1551
+ const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
1552
+ await this.http.put(`/v1/workouts/${workoutId}/exercises/${exerciseId}`, requestToSend);
1321
1553
  }
1322
1554
  /**
1323
1555
  * Remove exercise from workout
@@ -1330,6 +1562,9 @@ var WorkoutsResource = class {
1330
1562
  */
1331
1563
  async getWorkoutsByExercise(exerciseId) {
1332
1564
  const response = await this.http.get(`/v1/exercises/${exerciseId}/workouts`);
1565
+ if (this.config.autoConvertUnits) {
1566
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1567
+ }
1333
1568
  return response.data;
1334
1569
  }
1335
1570
  /**
@@ -1337,6 +1572,9 @@ var WorkoutsResource = class {
1337
1572
  */
1338
1573
  async getFavorites(params) {
1339
1574
  const response = await this.http.get("/v1/workouts/favorites", params);
1575
+ if (this.config.autoConvertUnits) {
1576
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1577
+ }
1340
1578
  return response.data;
1341
1579
  }
1342
1580
  /**
@@ -1355,14 +1593,18 @@ var WorkoutsResource = class {
1355
1593
 
1356
1594
  // resources/sessions.ts
1357
1595
  var SessionsResource = class {
1358
- constructor(http) {
1596
+ constructor(http, config) {
1359
1597
  this.http = http;
1598
+ this.config = config;
1360
1599
  }
1361
1600
  /**
1362
1601
  * List workout sessions with filtering
1363
1602
  */
1364
1603
  async list(params) {
1365
1604
  const response = await this.http.get("/v1/workout-sessions", params);
1605
+ if (this.config.autoConvertUnits) {
1606
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1607
+ }
1366
1608
  return response.data;
1367
1609
  }
1368
1610
  /**
@@ -1377,7 +1619,11 @@ var SessionsResource = class {
1377
1619
  * Create a new workout session
1378
1620
  */
1379
1621
  async create(request) {
1380
- const response = await this.http.post("/v1/workout-sessions", request);
1622
+ const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
1623
+ const response = await this.http.post("/v1/workout-sessions", requestToSend);
1624
+ if (this.config.autoConvertUnits) {
1625
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1626
+ }
1381
1627
  return response.data;
1382
1628
  }
1383
1629
  /**
@@ -1391,13 +1637,20 @@ var SessionsResource = class {
1391
1637
  */
1392
1638
  async get(sessionId) {
1393
1639
  const response = await this.http.get(`/v1/workout-sessions/${sessionId}`);
1640
+ if (this.config.autoConvertUnits) {
1641
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1642
+ }
1394
1643
  return response.data;
1395
1644
  }
1396
1645
  /**
1397
1646
  * Update a workout session
1398
1647
  */
1399
1648
  async update(sessionId, request) {
1400
- const response = await this.http.patch(`/v1/workout-sessions/${sessionId}`, request);
1649
+ const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
1650
+ const response = await this.http.patch(`/v1/workout-sessions/${sessionId}`, requestToSend);
1651
+ if (this.config.autoConvertUnits) {
1652
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1653
+ }
1401
1654
  return response.data;
1402
1655
  }
1403
1656
  /**
@@ -1435,6 +1688,9 @@ var SessionsResource = class {
1435
1688
  */
1436
1689
  async getSessionsByWorkout(workoutId, params) {
1437
1690
  const response = await this.http.get(`/v1/workouts/${workoutId}/sessions`, params);
1691
+ if (this.config.autoConvertUnits) {
1692
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1693
+ }
1438
1694
  return response.data;
1439
1695
  }
1440
1696
  /**
@@ -1442,6 +1698,9 @@ var SessionsResource = class {
1442
1698
  */
1443
1699
  async getExerciseHistory(exerciseId) {
1444
1700
  const response = await this.http.get(`/v1/exercises/${exerciseId}/history`);
1701
+ if (this.config.autoConvertUnits) {
1702
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1703
+ }
1445
1704
  return response.data;
1446
1705
  }
1447
1706
  /**
@@ -1449,6 +1708,9 @@ var SessionsResource = class {
1449
1708
  */
1450
1709
  async getPersonalRecords() {
1451
1710
  const response = await this.http.get("/v1/personal-records");
1711
+ if (this.config.autoConvertUnits) {
1712
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1713
+ }
1452
1714
  return response.data;
1453
1715
  }
1454
1716
  /**
@@ -1456,6 +1718,9 @@ var SessionsResource = class {
1456
1718
  */
1457
1719
  async getExercisePersonalRecords(exerciseId) {
1458
1720
  const response = await this.http.get(`/v1/exercises/${exerciseId}/personal-records`);
1721
+ if (this.config.autoConvertUnits) {
1722
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1723
+ }
1459
1724
  return response.data;
1460
1725
  }
1461
1726
  /**
@@ -1463,20 +1728,27 @@ var SessionsResource = class {
1463
1728
  */
1464
1729
  async getPersonalRecordHistory(exerciseId) {
1465
1730
  const response = await this.http.get(`/v1/exercises/${exerciseId}/personal-records/history`);
1731
+ if (this.config.autoConvertUnits) {
1732
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1733
+ }
1466
1734
  return response.data;
1467
1735
  }
1468
1736
  };
1469
1737
 
1470
1738
  // resources/programs.ts
1471
1739
  var ProgramsResource = class {
1472
- constructor(http) {
1740
+ constructor(http, config) {
1473
1741
  this.http = http;
1742
+ this.config = config;
1474
1743
  }
1475
1744
  /**
1476
1745
  * List user's programs and enrollments
1477
1746
  */
1478
1747
  async list(params) {
1479
1748
  const response = await this.http.get("/v1/programs", params);
1749
+ if (this.config.autoConvertUnits) {
1750
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1751
+ }
1480
1752
  return response.data;
1481
1753
  }
1482
1754
  /**
@@ -1484,13 +1756,20 @@ var ProgramsResource = class {
1484
1756
  */
1485
1757
  async listTemplates(params) {
1486
1758
  const response = await this.http.get("/v1/programs/templates", params);
1759
+ if (this.config.autoConvertUnits) {
1760
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1761
+ }
1487
1762
  return response.data;
1488
1763
  }
1489
1764
  /**
1490
1765
  * Create a new program
1491
1766
  */
1492
1767
  async create(request) {
1493
- const response = await this.http.post("/v1/programs", request);
1768
+ const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
1769
+ const response = await this.http.post("/v1/programs", requestToSend);
1770
+ if (this.config.autoConvertUnits) {
1771
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1772
+ }
1494
1773
  return response.data;
1495
1774
  }
1496
1775
  /**
@@ -1498,13 +1777,20 @@ var ProgramsResource = class {
1498
1777
  */
1499
1778
  async get(programId) {
1500
1779
  const response = await this.http.get(`/v1/programs/${programId}`);
1780
+ if (this.config.autoConvertUnits) {
1781
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1782
+ }
1501
1783
  return response.data;
1502
1784
  }
1503
1785
  /**
1504
1786
  * Update a program
1505
1787
  */
1506
1788
  async update(programId, request) {
1507
- const response = await this.http.put(`/v1/programs/${programId}`, request);
1789
+ const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
1790
+ const response = await this.http.put(`/v1/programs/${programId}`, requestToSend);
1791
+ if (this.config.autoConvertUnits) {
1792
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1793
+ }
1508
1794
  return response.data;
1509
1795
  }
1510
1796
  /**
@@ -1559,14 +1845,18 @@ var ProgramsResource = class {
1559
1845
  */
1560
1846
  async getCurrentWeek(enrollmentId) {
1561
1847
  const response = await this.http.get(`/v1/enrollments/${enrollmentId}/current-week`);
1848
+ if (this.config.autoConvertUnits) {
1849
+ return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
1850
+ }
1562
1851
  return response.data;
1563
1852
  }
1564
1853
  };
1565
1854
 
1566
1855
  // resources/metrics.ts
1567
1856
  var MetricsResource = class {
1568
- constructor(http) {
1857
+ constructor(http, config) {
1569
1858
  this.http = http;
1859
+ this.config = config;
1570
1860
  }
1571
1861
  /**
1572
1862
  * List available metrics
@@ -1594,6 +1884,12 @@ var MetricsResource = class {
1594
1884
  */
1595
1885
  async getDailyMetric(metricKey, params) {
1596
1886
  const response = await this.http.get(`/v1/metrics/daily/${metricKey}`, params);
1887
+ if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== void 0) {
1888
+ const isWeightMetric = metricKey.includes("weight") || metricKey.includes("bodyweight");
1889
+ if (isWeightMetric) {
1890
+ response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
1891
+ }
1892
+ }
1597
1893
  return response.data;
1598
1894
  }
1599
1895
  /**
@@ -1601,6 +1897,20 @@ var MetricsResource = class {
1601
1897
  */
1602
1898
  async listEvents(params) {
1603
1899
  const response = await this.http.get("/v1/metric-events", params);
1900
+ if (this.config.autoConvertUnits && response.data.data) {
1901
+ response.data.data = response.data.data.map((event) => {
1902
+ if (event.value !== null && event.value !== void 0) {
1903
+ const isWeightMetric = event.metricKey?.includes("weight") || event.metricKey?.includes("bodyweight");
1904
+ if (isWeightMetric) {
1905
+ return {
1906
+ ...event,
1907
+ value: WeightConverter.fromMetric(event.value, this.config.measurementSystem)
1908
+ };
1909
+ }
1910
+ }
1911
+ return event;
1912
+ });
1913
+ }
1604
1914
  return response.data;
1605
1915
  }
1606
1916
  /**
@@ -1616,13 +1926,32 @@ var MetricsResource = class {
1616
1926
  */
1617
1927
  async getEvent(eventId) {
1618
1928
  const response = await this.http.get(`/v1/metric-events/${eventId}`);
1929
+ if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== void 0) {
1930
+ const isWeightMetric = response.data.metricKey?.includes("weight") || response.data.metricKey?.includes("bodyweight");
1931
+ if (isWeightMetric) {
1932
+ response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
1933
+ }
1934
+ }
1619
1935
  return response.data;
1620
1936
  }
1621
1937
  /**
1622
1938
  * Log a metric value (convenience method)
1623
1939
  */
1624
1940
  async log(request) {
1625
- const response = await this.http.post("/v1/metric-events", request);
1941
+ const requestToSend = { ...request };
1942
+ if (this.config.autoConvertUnits && requestToSend.value !== null && requestToSend.value !== void 0) {
1943
+ const isWeightMetric = requestToSend.metricKey?.includes("weight") || requestToSend.metricKey?.includes("bodyweight");
1944
+ if (isWeightMetric) {
1945
+ requestToSend.value = WeightConverter.toMetric(requestToSend.value, this.config.measurementSystem);
1946
+ }
1947
+ }
1948
+ const response = await this.http.post("/v1/metric-events", requestToSend);
1949
+ if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== void 0) {
1950
+ const isWeightMetric = response.data.metricKey?.includes("weight") || response.data.metricKey?.includes("bodyweight");
1951
+ if (isWeightMetric) {
1952
+ response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
1953
+ }
1954
+ }
1626
1955
  return response.data;
1627
1956
  }
1628
1957
  /**
@@ -1635,13 +1964,36 @@ var MetricsResource = class {
1635
1964
  * Bulk create metric events
1636
1965
  */
1637
1966
  async bulkCreateEvents(request) {
1638
- await this.http.post("/v1/metric-events/bulk", request);
1967
+ const requestToSend = { ...request };
1968
+ if (this.config.autoConvertUnits && requestToSend.metrics) {
1969
+ requestToSend.metrics = requestToSend.metrics.map((event) => {
1970
+ if (event.value !== null && event.value !== void 0) {
1971
+ const isWeightMetric = event.metricKey?.includes("weight") || event.metricKey?.includes("bodyweight");
1972
+ if (isWeightMetric) {
1973
+ return {
1974
+ ...event,
1975
+ value: WeightConverter.toMetric(event.value, this.config.measurementSystem)
1976
+ };
1977
+ }
1978
+ }
1979
+ return event;
1980
+ });
1981
+ }
1982
+ await this.http.post("/v1/metric-events/bulk", requestToSend);
1639
1983
  }
1640
1984
  /**
1641
1985
  * Update a metric event
1986
+ * Note: metricKey cannot be changed, so we can't determine if this is a weight metric from the request alone.
1987
+ * We'll convert the value assuming it follows the user's preference setting.
1642
1988
  */
1643
1989
  async updateEvent(eventId, request) {
1644
1990
  const response = await this.http.put(`/v1/metric-events/${eventId}`, request);
1991
+ if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== void 0) {
1992
+ const isWeightMetric = response.data.metricKey?.includes("weight") || response.data.metricKey?.includes("bodyweight");
1993
+ if (isWeightMetric) {
1994
+ response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
1995
+ }
1996
+ }
1645
1997
  return response.data;
1646
1998
  }
1647
1999
  /**
@@ -1654,8 +2006,9 @@ var MetricsResource = class {
1654
2006
 
1655
2007
  // resources/goals.ts
1656
2008
  var GoalsResource = class {
1657
- constructor(http) {
2009
+ constructor(http, config) {
1658
2010
  this.http = http;
2011
+ this.config = config;
1659
2012
  }
1660
2013
  /**
1661
2014
  * Get active user goals
@@ -1710,6 +2063,9 @@ var GoalsResource = class {
1710
2063
  */
1711
2064
  async getNutritionGoals() {
1712
2065
  const response = await this.http.get("/v1/nutrition/goals");
2066
+ if (this.config.autoConvertUnits) {
2067
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
2068
+ }
1713
2069
  return response.data;
1714
2070
  }
1715
2071
  /**
@@ -1717,20 +2073,31 @@ var GoalsResource = class {
1717
2073
  */
1718
2074
  async getNutritionGoalsByDate(date) {
1719
2075
  const response = await this.http.get(`/v1/nutrition/goals/date/${date}`);
2076
+ if (this.config.autoConvertUnits) {
2077
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
2078
+ }
1720
2079
  return response.data;
1721
2080
  }
1722
2081
  /**
1723
2082
  * Create nutrition goals
1724
2083
  */
1725
2084
  async createNutritionGoals(request) {
1726
- const response = await this.http.post("/v1/nutrition/goals", request);
2085
+ const requestToSend = this.config.autoConvertUnits ? convertNutritionGoalsToMetric(request, this.config.measurementSystem) : request;
2086
+ const response = await this.http.post("/v1/nutrition/goals", requestToSend);
2087
+ if (this.config.autoConvertUnits) {
2088
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
2089
+ }
1727
2090
  return response.data;
1728
2091
  }
1729
2092
  /**
1730
2093
  * Update nutrition goals for a specific date
1731
2094
  */
1732
2095
  async updateNutritionGoals(date, request) {
1733
- const response = await this.http.put(`/v1/nutrition/goals/date/${date}`, request);
2096
+ const requestToSend = this.config.autoConvertUnits ? convertNutritionGoalsToMetric(request, this.config.measurementSystem) : request;
2097
+ const response = await this.http.put(`/v1/nutrition/goals/date/${date}`, requestToSend);
2098
+ if (this.config.autoConvertUnits) {
2099
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
2100
+ }
1734
2101
  return response.data;
1735
2102
  }
1736
2103
  /**
@@ -1756,6 +2123,9 @@ var GoalsResource = class {
1756
2123
  */
1757
2124
  async getNutritionGoalsHistory(params) {
1758
2125
  const response = await this.http.get("/v1/nutrition/goals/history", params);
2126
+ if (this.config.autoConvertUnits) {
2127
+ return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
2128
+ }
1759
2129
  return response.data;
1760
2130
  }
1761
2131
  /**
@@ -1807,11 +2177,11 @@ var OpenLifeLog = class {
1807
2177
  this.foods = new FoodsResource(this.httpClient);
1808
2178
  this.foodLogs = new FoodLogsResource(this.httpClient);
1809
2179
  this.exercises = new ExercisesResource(this.httpClient);
1810
- this.workouts = new WorkoutsResource(this.httpClient);
1811
- this.sessions = new SessionsResource(this.httpClient);
1812
- this.programs = new ProgramsResource(this.httpClient);
1813
- this.metrics = new MetricsResource(this.httpClient);
1814
- this.goals = new GoalsResource(this.httpClient);
2180
+ this.workouts = new WorkoutsResource(this.httpClient, this.config);
2181
+ this.sessions = new SessionsResource(this.httpClient, this.config);
2182
+ this.programs = new ProgramsResource(this.httpClient, this.config);
2183
+ this.metrics = new MetricsResource(this.httpClient, this.config);
2184
+ this.goals = new GoalsResource(this.httpClient, this.config);
1815
2185
  this.ai = new AIResource(this.httpClient);
1816
2186
  }
1817
2187
  /**