@openlifelog/sdk 1.0.2 → 1.0.4
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/client.ts +6 -6
- package/dist/index.d.mts +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +390 -20
- package/dist/index.mjs +390 -20
- package/package.json +1 -1
- package/resources/goals.ts +39 -4
- package/resources/metrics.ts +87 -4
- package/resources/programs.ts +44 -4
- package/resources/sessions.ts +59 -4
- package/resources/workouts.ts +54 -4
- package/types/exercise.ts +1 -1
- package/utils/units.ts +357 -0
package/dist/index.mjs
CHANGED
|
@@ -343,6 +343,8 @@ var METERS_TO_FEET = 3.28084;
|
|
|
343
343
|
var FEET_TO_METERS = 1 / METERS_TO_FEET;
|
|
344
344
|
var CM_TO_INCHES = 0.393701;
|
|
345
345
|
var INCHES_TO_CM = 1 / CM_TO_INCHES;
|
|
346
|
+
var ML_TO_FL_OZ = 0.033814;
|
|
347
|
+
var FL_OZ_TO_ML = 1 / ML_TO_FL_OZ;
|
|
346
348
|
var WeightConverter = class {
|
|
347
349
|
/**
|
|
348
350
|
* Convert kilograms to pounds
|
|
@@ -471,6 +473,38 @@ var HeightConverter = class {
|
|
|
471
473
|
return value;
|
|
472
474
|
}
|
|
473
475
|
};
|
|
476
|
+
var VolumeConverter = class {
|
|
477
|
+
/**
|
|
478
|
+
* Convert milliliters to fluid ounces
|
|
479
|
+
*/
|
|
480
|
+
static mlToFlOz(ml) {
|
|
481
|
+
return ml * ML_TO_FL_OZ;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Convert fluid ounces to milliliters
|
|
485
|
+
*/
|
|
486
|
+
static flOzToMl(flOz) {
|
|
487
|
+
return flOz * FL_OZ_TO_ML;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Convert volume from metric to the target measurement system
|
|
491
|
+
*/
|
|
492
|
+
static fromMetric(ml, targetSystem) {
|
|
493
|
+
if (targetSystem === "imperial") {
|
|
494
|
+
return this.mlToFlOz(ml);
|
|
495
|
+
}
|
|
496
|
+
return ml;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Convert volume to metric from the source measurement system
|
|
500
|
+
*/
|
|
501
|
+
static toMetric(value, sourceSystem) {
|
|
502
|
+
if (sourceSystem === "imperial") {
|
|
503
|
+
return this.flOzToMl(value);
|
|
504
|
+
}
|
|
505
|
+
return value;
|
|
506
|
+
}
|
|
507
|
+
};
|
|
474
508
|
var UnitConverter = class {
|
|
475
509
|
constructor(measurementSystem = "metric") {
|
|
476
510
|
this.measurementSystem = measurementSystem;
|
|
@@ -560,6 +594,183 @@ var UnitConverter = class {
|
|
|
560
594
|
function createUnitConverter(measurementSystem = "metric") {
|
|
561
595
|
return new UnitConverter(measurementSystem);
|
|
562
596
|
}
|
|
597
|
+
function convertSetDataToMetric(setData, measurementSystem) {
|
|
598
|
+
if (!setData || typeof setData !== "object") {
|
|
599
|
+
return setData;
|
|
600
|
+
}
|
|
601
|
+
const converted = { ...setData };
|
|
602
|
+
if (converted.weight !== null && converted.weight !== void 0) {
|
|
603
|
+
converted.weight = WeightConverter.toMetric(converted.weight, measurementSystem);
|
|
604
|
+
}
|
|
605
|
+
if (converted.distance !== null && converted.distance !== void 0) {
|
|
606
|
+
const isMiles = measurementSystem === "imperial" && converted.distance <= 200;
|
|
607
|
+
converted.distance = DistanceConverter.toMetric(converted.distance, measurementSystem, isMiles);
|
|
608
|
+
}
|
|
609
|
+
return converted;
|
|
610
|
+
}
|
|
611
|
+
function convertSetDataFromMetric(setData, measurementSystem) {
|
|
612
|
+
if (!setData || typeof setData !== "object") {
|
|
613
|
+
return setData;
|
|
614
|
+
}
|
|
615
|
+
const converted = { ...setData };
|
|
616
|
+
if (converted.weight !== null && converted.weight !== void 0) {
|
|
617
|
+
converted.weight = WeightConverter.fromMetric(converted.weight, measurementSystem);
|
|
618
|
+
}
|
|
619
|
+
if (converted.distance !== null && converted.distance !== void 0) {
|
|
620
|
+
const preferMiles = measurementSystem === "imperial" && converted.distance > 1609;
|
|
621
|
+
converted.distance = DistanceConverter.fromMetric(converted.distance, measurementSystem, preferMiles);
|
|
622
|
+
}
|
|
623
|
+
return converted;
|
|
624
|
+
}
|
|
625
|
+
function convertSetsDataToMetric(setsData, measurementSystem) {
|
|
626
|
+
if (!setsData || !Array.isArray(setsData)) {
|
|
627
|
+
return setsData || [];
|
|
628
|
+
}
|
|
629
|
+
return setsData.map((setData) => convertSetDataToMetric(setData, measurementSystem));
|
|
630
|
+
}
|
|
631
|
+
function convertSetsDataFromMetric(setsData, measurementSystem) {
|
|
632
|
+
if (!setsData || !Array.isArray(setsData)) {
|
|
633
|
+
return setsData || [];
|
|
634
|
+
}
|
|
635
|
+
return setsData.map((setData) => convertSetDataFromMetric(setData, measurementSystem));
|
|
636
|
+
}
|
|
637
|
+
function convertWorkoutDataToMetric(data, measurementSystem) {
|
|
638
|
+
if (!data || typeof data !== "object") {
|
|
639
|
+
return data;
|
|
640
|
+
}
|
|
641
|
+
if (Array.isArray(data)) {
|
|
642
|
+
return data.map((item) => convertWorkoutDataToMetric(item, measurementSystem));
|
|
643
|
+
}
|
|
644
|
+
const converted = { ...data };
|
|
645
|
+
if (converted.setsData && Array.isArray(converted.setsData)) {
|
|
646
|
+
converted.setsData = convertSetsDataToMetric(converted.setsData, measurementSystem);
|
|
647
|
+
}
|
|
648
|
+
if (converted.sets && Array.isArray(converted.sets)) {
|
|
649
|
+
converted.sets = convertSetsDataToMetric(converted.sets, measurementSystem);
|
|
650
|
+
}
|
|
651
|
+
if (converted.exercises && Array.isArray(converted.exercises)) {
|
|
652
|
+
converted.exercises = converted.exercises.map(
|
|
653
|
+
(exercise) => convertWorkoutDataToMetric(exercise, measurementSystem)
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
if (converted.schedule && Array.isArray(converted.schedule)) {
|
|
657
|
+
converted.schedule = converted.schedule.map(
|
|
658
|
+
(day) => convertWorkoutDataToMetric(day, measurementSystem)
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
if (converted.userBodyweight !== null && converted.userBodyweight !== void 0) {
|
|
662
|
+
converted.userBodyweight = WeightConverter.toMetric(converted.userBodyweight, measurementSystem);
|
|
663
|
+
}
|
|
664
|
+
if (converted.totalVolume !== null && converted.totalVolume !== void 0) {
|
|
665
|
+
converted.totalVolume = WeightConverter.toMetric(converted.totalVolume, measurementSystem);
|
|
666
|
+
}
|
|
667
|
+
if (converted.totalDistance !== null && converted.totalDistance !== void 0) {
|
|
668
|
+
const preferMiles = measurementSystem === "imperial" && converted.totalDistance <= 200;
|
|
669
|
+
converted.totalDistance = DistanceConverter.toMetric(converted.totalDistance, measurementSystem, preferMiles);
|
|
670
|
+
}
|
|
671
|
+
return converted;
|
|
672
|
+
}
|
|
673
|
+
function convertWorkoutDataFromMetric(data, measurementSystem) {
|
|
674
|
+
if (!data || typeof data !== "object") {
|
|
675
|
+
return data;
|
|
676
|
+
}
|
|
677
|
+
if (Array.isArray(data)) {
|
|
678
|
+
return data.map((item) => convertWorkoutDataFromMetric(item, measurementSystem));
|
|
679
|
+
}
|
|
680
|
+
const converted = { ...data };
|
|
681
|
+
if (converted.setsData && Array.isArray(converted.setsData)) {
|
|
682
|
+
converted.setsData = convertSetsDataFromMetric(converted.setsData, measurementSystem);
|
|
683
|
+
}
|
|
684
|
+
if (converted.sets && Array.isArray(converted.sets)) {
|
|
685
|
+
converted.sets = convertSetsDataFromMetric(converted.sets, measurementSystem);
|
|
686
|
+
}
|
|
687
|
+
if (converted.exercises && Array.isArray(converted.exercises)) {
|
|
688
|
+
converted.exercises = converted.exercises.map(
|
|
689
|
+
(exercise) => convertWorkoutDataFromMetric(exercise, measurementSystem)
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
if (converted.schedule && Array.isArray(converted.schedule)) {
|
|
693
|
+
converted.schedule = converted.schedule.map(
|
|
694
|
+
(day) => convertWorkoutDataFromMetric(day, measurementSystem)
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
if (converted.data && Array.isArray(converted.data)) {
|
|
698
|
+
converted.data = converted.data.map(
|
|
699
|
+
(item) => convertWorkoutDataFromMetric(item, measurementSystem)
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
if (converted.userBodyweight !== null && converted.userBodyweight !== void 0) {
|
|
703
|
+
converted.userBodyweight = WeightConverter.fromMetric(converted.userBodyweight, measurementSystem);
|
|
704
|
+
}
|
|
705
|
+
if (converted.totalVolume !== null && converted.totalVolume !== void 0) {
|
|
706
|
+
converted.totalVolume = WeightConverter.fromMetric(converted.totalVolume, measurementSystem);
|
|
707
|
+
}
|
|
708
|
+
if (converted.totalDistance !== null && converted.totalDistance !== void 0) {
|
|
709
|
+
const preferMiles = measurementSystem === "imperial" && converted.totalDistance > 1609;
|
|
710
|
+
converted.totalDistance = DistanceConverter.fromMetric(converted.totalDistance, measurementSystem, preferMiles);
|
|
711
|
+
}
|
|
712
|
+
if (converted.value !== null && converted.value !== void 0 && converted.unit) {
|
|
713
|
+
if (converted.unit === "kg" || converted.unit === "lbs") {
|
|
714
|
+
converted.value = WeightConverter.fromMetric(converted.value, measurementSystem);
|
|
715
|
+
converted.unit = measurementSystem === "imperial" ? "lbs" : "kg";
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return converted;
|
|
719
|
+
}
|
|
720
|
+
function convertNutritionGoalsToMetric(data, measurementSystem) {
|
|
721
|
+
if (!data || typeof data !== "object") {
|
|
722
|
+
return data;
|
|
723
|
+
}
|
|
724
|
+
const converted = { ...data };
|
|
725
|
+
if (converted.goals && typeof converted.goals === "object") {
|
|
726
|
+
converted.goals = { ...converted.goals };
|
|
727
|
+
if (converted.goals.water && typeof converted.goals.water === "object") {
|
|
728
|
+
const waterGoal = { ...converted.goals.water };
|
|
729
|
+
if (waterGoal.value !== null && waterGoal.value !== void 0) {
|
|
730
|
+
waterGoal.value = VolumeConverter.toMetric(waterGoal.value, measurementSystem);
|
|
731
|
+
}
|
|
732
|
+
if (waterGoal.min !== null && waterGoal.min !== void 0) {
|
|
733
|
+
waterGoal.min = VolumeConverter.toMetric(waterGoal.min, measurementSystem);
|
|
734
|
+
}
|
|
735
|
+
if (waterGoal.max !== null && waterGoal.max !== void 0) {
|
|
736
|
+
waterGoal.max = VolumeConverter.toMetric(waterGoal.max, measurementSystem);
|
|
737
|
+
}
|
|
738
|
+
converted.goals.water = waterGoal;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return converted;
|
|
742
|
+
}
|
|
743
|
+
function convertNutritionGoalsFromMetric(data, measurementSystem) {
|
|
744
|
+
if (!data || typeof data !== "object") {
|
|
745
|
+
return data;
|
|
746
|
+
}
|
|
747
|
+
if (Array.isArray(data)) {
|
|
748
|
+
return data.map((item) => convertNutritionGoalsFromMetric(item, measurementSystem));
|
|
749
|
+
}
|
|
750
|
+
const converted = { ...data };
|
|
751
|
+
if (converted.data && Array.isArray(converted.data)) {
|
|
752
|
+
converted.data = converted.data.map(
|
|
753
|
+
(item) => convertNutritionGoalsFromMetric(item, measurementSystem)
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
if (converted.goals && typeof converted.goals === "object") {
|
|
757
|
+
converted.goals = { ...converted.goals };
|
|
758
|
+
if (converted.goals.water && typeof converted.goals.water === "object") {
|
|
759
|
+
const waterGoal = { ...converted.goals.water };
|
|
760
|
+
if (waterGoal.value !== null && waterGoal.value !== void 0) {
|
|
761
|
+
waterGoal.value = VolumeConverter.fromMetric(waterGoal.value, measurementSystem);
|
|
762
|
+
}
|
|
763
|
+
if (waterGoal.min !== null && waterGoal.min !== void 0) {
|
|
764
|
+
waterGoal.min = VolumeConverter.fromMetric(waterGoal.min, measurementSystem);
|
|
765
|
+
}
|
|
766
|
+
if (waterGoal.max !== null && waterGoal.max !== void 0) {
|
|
767
|
+
waterGoal.max = VolumeConverter.fromMetric(waterGoal.max, measurementSystem);
|
|
768
|
+
}
|
|
769
|
+
converted.goals.water = waterGoal;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
return converted;
|
|
773
|
+
}
|
|
563
774
|
|
|
564
775
|
// resources/auth.ts
|
|
565
776
|
var AuthResource = class {
|
|
@@ -1187,14 +1398,18 @@ var ExercisesResource = class {
|
|
|
1187
1398
|
|
|
1188
1399
|
// resources/workouts.ts
|
|
1189
1400
|
var WorkoutsResource = class {
|
|
1190
|
-
constructor(http) {
|
|
1401
|
+
constructor(http, config) {
|
|
1191
1402
|
this.http = http;
|
|
1403
|
+
this.config = config;
|
|
1192
1404
|
}
|
|
1193
1405
|
/**
|
|
1194
1406
|
* List workout templates
|
|
1195
1407
|
*/
|
|
1196
1408
|
async list(params) {
|
|
1197
1409
|
const response = await this.http.get("/v1/workouts", params);
|
|
1410
|
+
if (this.config.autoConvertUnits) {
|
|
1411
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1412
|
+
}
|
|
1198
1413
|
return response.data;
|
|
1199
1414
|
}
|
|
1200
1415
|
/**
|
|
@@ -1217,6 +1432,9 @@ var WorkoutsResource = class {
|
|
|
1217
1432
|
*/
|
|
1218
1433
|
async search(params) {
|
|
1219
1434
|
const response = await this.http.get("/v1/workouts/search", params);
|
|
1435
|
+
if (this.config.autoConvertUnits) {
|
|
1436
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1437
|
+
}
|
|
1220
1438
|
return response.data;
|
|
1221
1439
|
}
|
|
1222
1440
|
/**
|
|
@@ -1224,6 +1442,9 @@ var WorkoutsResource = class {
|
|
|
1224
1442
|
*/
|
|
1225
1443
|
async get(workoutId) {
|
|
1226
1444
|
const response = await this.http.get(`/v1/workouts/${workoutId}`);
|
|
1445
|
+
if (this.config.autoConvertUnits) {
|
|
1446
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1447
|
+
}
|
|
1227
1448
|
return response.data;
|
|
1228
1449
|
}
|
|
1229
1450
|
/**
|
|
@@ -1231,6 +1452,9 @@ var WorkoutsResource = class {
|
|
|
1231
1452
|
*/
|
|
1232
1453
|
async create(request) {
|
|
1233
1454
|
const response = await this.http.post("/v1/workouts", request);
|
|
1455
|
+
if (this.config.autoConvertUnits) {
|
|
1456
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1457
|
+
}
|
|
1234
1458
|
return response.data;
|
|
1235
1459
|
}
|
|
1236
1460
|
/**
|
|
@@ -1238,6 +1462,9 @@ var WorkoutsResource = class {
|
|
|
1238
1462
|
*/
|
|
1239
1463
|
async update(workoutId, request) {
|
|
1240
1464
|
const response = await this.http.put(`/v1/workouts/${workoutId}`, request);
|
|
1465
|
+
if (this.config.autoConvertUnits) {
|
|
1466
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1467
|
+
}
|
|
1241
1468
|
return response.data;
|
|
1242
1469
|
}
|
|
1243
1470
|
/**
|
|
@@ -1245,6 +1472,9 @@ var WorkoutsResource = class {
|
|
|
1245
1472
|
*/
|
|
1246
1473
|
async clone(workoutId) {
|
|
1247
1474
|
const response = await this.http.post(`/v1/workouts/${workoutId}/clone`);
|
|
1475
|
+
if (this.config.autoConvertUnits) {
|
|
1476
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1477
|
+
}
|
|
1248
1478
|
return response.data;
|
|
1249
1479
|
}
|
|
1250
1480
|
/**
|
|
@@ -1257,13 +1487,15 @@ var WorkoutsResource = class {
|
|
|
1257
1487
|
* Add exercises to workout
|
|
1258
1488
|
*/
|
|
1259
1489
|
async addExercises(workoutId, request) {
|
|
1260
|
-
|
|
1490
|
+
const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
|
|
1491
|
+
await this.http.post(`/v1/workouts/${workoutId}/exercises`, requestToSend);
|
|
1261
1492
|
}
|
|
1262
1493
|
/**
|
|
1263
1494
|
* Update exercise in workout
|
|
1264
1495
|
*/
|
|
1265
1496
|
async updateExercise(workoutId, exerciseId, request) {
|
|
1266
|
-
|
|
1497
|
+
const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
|
|
1498
|
+
await this.http.put(`/v1/workouts/${workoutId}/exercises/${exerciseId}`, requestToSend);
|
|
1267
1499
|
}
|
|
1268
1500
|
/**
|
|
1269
1501
|
* Remove exercise from workout
|
|
@@ -1276,6 +1508,9 @@ var WorkoutsResource = class {
|
|
|
1276
1508
|
*/
|
|
1277
1509
|
async getWorkoutsByExercise(exerciseId) {
|
|
1278
1510
|
const response = await this.http.get(`/v1/exercises/${exerciseId}/workouts`);
|
|
1511
|
+
if (this.config.autoConvertUnits) {
|
|
1512
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1513
|
+
}
|
|
1279
1514
|
return response.data;
|
|
1280
1515
|
}
|
|
1281
1516
|
/**
|
|
@@ -1283,6 +1518,9 @@ var WorkoutsResource = class {
|
|
|
1283
1518
|
*/
|
|
1284
1519
|
async getFavorites(params) {
|
|
1285
1520
|
const response = await this.http.get("/v1/workouts/favorites", params);
|
|
1521
|
+
if (this.config.autoConvertUnits) {
|
|
1522
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1523
|
+
}
|
|
1286
1524
|
return response.data;
|
|
1287
1525
|
}
|
|
1288
1526
|
/**
|
|
@@ -1301,14 +1539,18 @@ var WorkoutsResource = class {
|
|
|
1301
1539
|
|
|
1302
1540
|
// resources/sessions.ts
|
|
1303
1541
|
var SessionsResource = class {
|
|
1304
|
-
constructor(http) {
|
|
1542
|
+
constructor(http, config) {
|
|
1305
1543
|
this.http = http;
|
|
1544
|
+
this.config = config;
|
|
1306
1545
|
}
|
|
1307
1546
|
/**
|
|
1308
1547
|
* List workout sessions with filtering
|
|
1309
1548
|
*/
|
|
1310
1549
|
async list(params) {
|
|
1311
1550
|
const response = await this.http.get("/v1/workout-sessions", params);
|
|
1551
|
+
if (this.config.autoConvertUnits) {
|
|
1552
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1553
|
+
}
|
|
1312
1554
|
return response.data;
|
|
1313
1555
|
}
|
|
1314
1556
|
/**
|
|
@@ -1323,7 +1565,11 @@ var SessionsResource = class {
|
|
|
1323
1565
|
* Create a new workout session
|
|
1324
1566
|
*/
|
|
1325
1567
|
async create(request) {
|
|
1326
|
-
const
|
|
1568
|
+
const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
|
|
1569
|
+
const response = await this.http.post("/v1/workout-sessions", requestToSend);
|
|
1570
|
+
if (this.config.autoConvertUnits) {
|
|
1571
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1572
|
+
}
|
|
1327
1573
|
return response.data;
|
|
1328
1574
|
}
|
|
1329
1575
|
/**
|
|
@@ -1337,13 +1583,20 @@ var SessionsResource = class {
|
|
|
1337
1583
|
*/
|
|
1338
1584
|
async get(sessionId) {
|
|
1339
1585
|
const response = await this.http.get(`/v1/workout-sessions/${sessionId}`);
|
|
1586
|
+
if (this.config.autoConvertUnits) {
|
|
1587
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1588
|
+
}
|
|
1340
1589
|
return response.data;
|
|
1341
1590
|
}
|
|
1342
1591
|
/**
|
|
1343
1592
|
* Update a workout session
|
|
1344
1593
|
*/
|
|
1345
1594
|
async update(sessionId, request) {
|
|
1346
|
-
const
|
|
1595
|
+
const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
|
|
1596
|
+
const response = await this.http.patch(`/v1/workout-sessions/${sessionId}`, requestToSend);
|
|
1597
|
+
if (this.config.autoConvertUnits) {
|
|
1598
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1599
|
+
}
|
|
1347
1600
|
return response.data;
|
|
1348
1601
|
}
|
|
1349
1602
|
/**
|
|
@@ -1381,6 +1634,9 @@ var SessionsResource = class {
|
|
|
1381
1634
|
*/
|
|
1382
1635
|
async getSessionsByWorkout(workoutId, params) {
|
|
1383
1636
|
const response = await this.http.get(`/v1/workouts/${workoutId}/sessions`, params);
|
|
1637
|
+
if (this.config.autoConvertUnits) {
|
|
1638
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1639
|
+
}
|
|
1384
1640
|
return response.data;
|
|
1385
1641
|
}
|
|
1386
1642
|
/**
|
|
@@ -1388,6 +1644,9 @@ var SessionsResource = class {
|
|
|
1388
1644
|
*/
|
|
1389
1645
|
async getExerciseHistory(exerciseId) {
|
|
1390
1646
|
const response = await this.http.get(`/v1/exercises/${exerciseId}/history`);
|
|
1647
|
+
if (this.config.autoConvertUnits) {
|
|
1648
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1649
|
+
}
|
|
1391
1650
|
return response.data;
|
|
1392
1651
|
}
|
|
1393
1652
|
/**
|
|
@@ -1395,6 +1654,9 @@ var SessionsResource = class {
|
|
|
1395
1654
|
*/
|
|
1396
1655
|
async getPersonalRecords() {
|
|
1397
1656
|
const response = await this.http.get("/v1/personal-records");
|
|
1657
|
+
if (this.config.autoConvertUnits) {
|
|
1658
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1659
|
+
}
|
|
1398
1660
|
return response.data;
|
|
1399
1661
|
}
|
|
1400
1662
|
/**
|
|
@@ -1402,6 +1664,9 @@ var SessionsResource = class {
|
|
|
1402
1664
|
*/
|
|
1403
1665
|
async getExercisePersonalRecords(exerciseId) {
|
|
1404
1666
|
const response = await this.http.get(`/v1/exercises/${exerciseId}/personal-records`);
|
|
1667
|
+
if (this.config.autoConvertUnits) {
|
|
1668
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1669
|
+
}
|
|
1405
1670
|
return response.data;
|
|
1406
1671
|
}
|
|
1407
1672
|
/**
|
|
@@ -1409,20 +1674,27 @@ var SessionsResource = class {
|
|
|
1409
1674
|
*/
|
|
1410
1675
|
async getPersonalRecordHistory(exerciseId) {
|
|
1411
1676
|
const response = await this.http.get(`/v1/exercises/${exerciseId}/personal-records/history`);
|
|
1677
|
+
if (this.config.autoConvertUnits) {
|
|
1678
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1679
|
+
}
|
|
1412
1680
|
return response.data;
|
|
1413
1681
|
}
|
|
1414
1682
|
};
|
|
1415
1683
|
|
|
1416
1684
|
// resources/programs.ts
|
|
1417
1685
|
var ProgramsResource = class {
|
|
1418
|
-
constructor(http) {
|
|
1686
|
+
constructor(http, config) {
|
|
1419
1687
|
this.http = http;
|
|
1688
|
+
this.config = config;
|
|
1420
1689
|
}
|
|
1421
1690
|
/**
|
|
1422
1691
|
* List user's programs and enrollments
|
|
1423
1692
|
*/
|
|
1424
1693
|
async list(params) {
|
|
1425
1694
|
const response = await this.http.get("/v1/programs", params);
|
|
1695
|
+
if (this.config.autoConvertUnits) {
|
|
1696
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1697
|
+
}
|
|
1426
1698
|
return response.data;
|
|
1427
1699
|
}
|
|
1428
1700
|
/**
|
|
@@ -1430,13 +1702,20 @@ var ProgramsResource = class {
|
|
|
1430
1702
|
*/
|
|
1431
1703
|
async listTemplates(params) {
|
|
1432
1704
|
const response = await this.http.get("/v1/programs/templates", params);
|
|
1705
|
+
if (this.config.autoConvertUnits) {
|
|
1706
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1707
|
+
}
|
|
1433
1708
|
return response.data;
|
|
1434
1709
|
}
|
|
1435
1710
|
/**
|
|
1436
1711
|
* Create a new program
|
|
1437
1712
|
*/
|
|
1438
1713
|
async create(request) {
|
|
1439
|
-
const
|
|
1714
|
+
const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
|
|
1715
|
+
const response = await this.http.post("/v1/programs", requestToSend);
|
|
1716
|
+
if (this.config.autoConvertUnits) {
|
|
1717
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1718
|
+
}
|
|
1440
1719
|
return response.data;
|
|
1441
1720
|
}
|
|
1442
1721
|
/**
|
|
@@ -1444,13 +1723,20 @@ var ProgramsResource = class {
|
|
|
1444
1723
|
*/
|
|
1445
1724
|
async get(programId) {
|
|
1446
1725
|
const response = await this.http.get(`/v1/programs/${programId}`);
|
|
1726
|
+
if (this.config.autoConvertUnits) {
|
|
1727
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1728
|
+
}
|
|
1447
1729
|
return response.data;
|
|
1448
1730
|
}
|
|
1449
1731
|
/**
|
|
1450
1732
|
* Update a program
|
|
1451
1733
|
*/
|
|
1452
1734
|
async update(programId, request) {
|
|
1453
|
-
const
|
|
1735
|
+
const requestToSend = this.config.autoConvertUnits ? convertWorkoutDataToMetric(request, this.config.measurementSystem) : request;
|
|
1736
|
+
const response = await this.http.put(`/v1/programs/${programId}`, requestToSend);
|
|
1737
|
+
if (this.config.autoConvertUnits) {
|
|
1738
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1739
|
+
}
|
|
1454
1740
|
return response.data;
|
|
1455
1741
|
}
|
|
1456
1742
|
/**
|
|
@@ -1505,14 +1791,18 @@ var ProgramsResource = class {
|
|
|
1505
1791
|
*/
|
|
1506
1792
|
async getCurrentWeek(enrollmentId) {
|
|
1507
1793
|
const response = await this.http.get(`/v1/enrollments/${enrollmentId}/current-week`);
|
|
1794
|
+
if (this.config.autoConvertUnits) {
|
|
1795
|
+
return convertWorkoutDataFromMetric(response.data, this.config.measurementSystem);
|
|
1796
|
+
}
|
|
1508
1797
|
return response.data;
|
|
1509
1798
|
}
|
|
1510
1799
|
};
|
|
1511
1800
|
|
|
1512
1801
|
// resources/metrics.ts
|
|
1513
1802
|
var MetricsResource = class {
|
|
1514
|
-
constructor(http) {
|
|
1803
|
+
constructor(http, config) {
|
|
1515
1804
|
this.http = http;
|
|
1805
|
+
this.config = config;
|
|
1516
1806
|
}
|
|
1517
1807
|
/**
|
|
1518
1808
|
* List available metrics
|
|
@@ -1540,6 +1830,12 @@ var MetricsResource = class {
|
|
|
1540
1830
|
*/
|
|
1541
1831
|
async getDailyMetric(metricKey, params) {
|
|
1542
1832
|
const response = await this.http.get(`/v1/metrics/daily/${metricKey}`, params);
|
|
1833
|
+
if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== void 0) {
|
|
1834
|
+
const isWeightMetric = metricKey.includes("weight") || metricKey.includes("bodyweight");
|
|
1835
|
+
if (isWeightMetric) {
|
|
1836
|
+
response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1543
1839
|
return response.data;
|
|
1544
1840
|
}
|
|
1545
1841
|
/**
|
|
@@ -1547,6 +1843,20 @@ var MetricsResource = class {
|
|
|
1547
1843
|
*/
|
|
1548
1844
|
async listEvents(params) {
|
|
1549
1845
|
const response = await this.http.get("/v1/metric-events", params);
|
|
1846
|
+
if (this.config.autoConvertUnits && response.data.data) {
|
|
1847
|
+
response.data.data = response.data.data.map((event) => {
|
|
1848
|
+
if (event.value !== null && event.value !== void 0) {
|
|
1849
|
+
const isWeightMetric = event.metricKey?.includes("weight") || event.metricKey?.includes("bodyweight");
|
|
1850
|
+
if (isWeightMetric) {
|
|
1851
|
+
return {
|
|
1852
|
+
...event,
|
|
1853
|
+
value: WeightConverter.fromMetric(event.value, this.config.measurementSystem)
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
return event;
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1550
1860
|
return response.data;
|
|
1551
1861
|
}
|
|
1552
1862
|
/**
|
|
@@ -1562,13 +1872,32 @@ var MetricsResource = class {
|
|
|
1562
1872
|
*/
|
|
1563
1873
|
async getEvent(eventId) {
|
|
1564
1874
|
const response = await this.http.get(`/v1/metric-events/${eventId}`);
|
|
1875
|
+
if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== void 0) {
|
|
1876
|
+
const isWeightMetric = response.data.metricKey?.includes("weight") || response.data.metricKey?.includes("bodyweight");
|
|
1877
|
+
if (isWeightMetric) {
|
|
1878
|
+
response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1565
1881
|
return response.data;
|
|
1566
1882
|
}
|
|
1567
1883
|
/**
|
|
1568
1884
|
* Log a metric value (convenience method)
|
|
1569
1885
|
*/
|
|
1570
1886
|
async log(request) {
|
|
1571
|
-
const
|
|
1887
|
+
const requestToSend = { ...request };
|
|
1888
|
+
if (this.config.autoConvertUnits && requestToSend.value !== null && requestToSend.value !== void 0) {
|
|
1889
|
+
const isWeightMetric = requestToSend.metricKey?.includes("weight") || requestToSend.metricKey?.includes("bodyweight");
|
|
1890
|
+
if (isWeightMetric) {
|
|
1891
|
+
requestToSend.value = WeightConverter.toMetric(requestToSend.value, this.config.measurementSystem);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
const response = await this.http.post("/v1/metric-events", requestToSend);
|
|
1895
|
+
if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== void 0) {
|
|
1896
|
+
const isWeightMetric = response.data.metricKey?.includes("weight") || response.data.metricKey?.includes("bodyweight");
|
|
1897
|
+
if (isWeightMetric) {
|
|
1898
|
+
response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1572
1901
|
return response.data;
|
|
1573
1902
|
}
|
|
1574
1903
|
/**
|
|
@@ -1581,13 +1910,36 @@ var MetricsResource = class {
|
|
|
1581
1910
|
* Bulk create metric events
|
|
1582
1911
|
*/
|
|
1583
1912
|
async bulkCreateEvents(request) {
|
|
1584
|
-
|
|
1913
|
+
const requestToSend = { ...request };
|
|
1914
|
+
if (this.config.autoConvertUnits && requestToSend.metrics) {
|
|
1915
|
+
requestToSend.metrics = requestToSend.metrics.map((event) => {
|
|
1916
|
+
if (event.value !== null && event.value !== void 0) {
|
|
1917
|
+
const isWeightMetric = event.metricKey?.includes("weight") || event.metricKey?.includes("bodyweight");
|
|
1918
|
+
if (isWeightMetric) {
|
|
1919
|
+
return {
|
|
1920
|
+
...event,
|
|
1921
|
+
value: WeightConverter.toMetric(event.value, this.config.measurementSystem)
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
return event;
|
|
1926
|
+
});
|
|
1927
|
+
}
|
|
1928
|
+
await this.http.post("/v1/metric-events/bulk", requestToSend);
|
|
1585
1929
|
}
|
|
1586
1930
|
/**
|
|
1587
1931
|
* Update a metric event
|
|
1932
|
+
* Note: metricKey cannot be changed, so we can't determine if this is a weight metric from the request alone.
|
|
1933
|
+
* We'll convert the value assuming it follows the user's preference setting.
|
|
1588
1934
|
*/
|
|
1589
1935
|
async updateEvent(eventId, request) {
|
|
1590
1936
|
const response = await this.http.put(`/v1/metric-events/${eventId}`, request);
|
|
1937
|
+
if (this.config.autoConvertUnits && response.data.value !== null && response.data.value !== void 0) {
|
|
1938
|
+
const isWeightMetric = response.data.metricKey?.includes("weight") || response.data.metricKey?.includes("bodyweight");
|
|
1939
|
+
if (isWeightMetric) {
|
|
1940
|
+
response.data.value = WeightConverter.fromMetric(response.data.value, this.config.measurementSystem);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1591
1943
|
return response.data;
|
|
1592
1944
|
}
|
|
1593
1945
|
/**
|
|
@@ -1600,8 +1952,9 @@ var MetricsResource = class {
|
|
|
1600
1952
|
|
|
1601
1953
|
// resources/goals.ts
|
|
1602
1954
|
var GoalsResource = class {
|
|
1603
|
-
constructor(http) {
|
|
1955
|
+
constructor(http, config) {
|
|
1604
1956
|
this.http = http;
|
|
1957
|
+
this.config = config;
|
|
1605
1958
|
}
|
|
1606
1959
|
/**
|
|
1607
1960
|
* Get active user goals
|
|
@@ -1656,6 +2009,9 @@ var GoalsResource = class {
|
|
|
1656
2009
|
*/
|
|
1657
2010
|
async getNutritionGoals() {
|
|
1658
2011
|
const response = await this.http.get("/v1/nutrition/goals");
|
|
2012
|
+
if (this.config.autoConvertUnits) {
|
|
2013
|
+
return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
|
|
2014
|
+
}
|
|
1659
2015
|
return response.data;
|
|
1660
2016
|
}
|
|
1661
2017
|
/**
|
|
@@ -1663,20 +2019,31 @@ var GoalsResource = class {
|
|
|
1663
2019
|
*/
|
|
1664
2020
|
async getNutritionGoalsByDate(date) {
|
|
1665
2021
|
const response = await this.http.get(`/v1/nutrition/goals/date/${date}`);
|
|
2022
|
+
if (this.config.autoConvertUnits) {
|
|
2023
|
+
return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
|
|
2024
|
+
}
|
|
1666
2025
|
return response.data;
|
|
1667
2026
|
}
|
|
1668
2027
|
/**
|
|
1669
2028
|
* Create nutrition goals
|
|
1670
2029
|
*/
|
|
1671
2030
|
async createNutritionGoals(request) {
|
|
1672
|
-
const
|
|
2031
|
+
const requestToSend = this.config.autoConvertUnits ? convertNutritionGoalsToMetric(request, this.config.measurementSystem) : request;
|
|
2032
|
+
const response = await this.http.post("/v1/nutrition/goals", requestToSend);
|
|
2033
|
+
if (this.config.autoConvertUnits) {
|
|
2034
|
+
return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
|
|
2035
|
+
}
|
|
1673
2036
|
return response.data;
|
|
1674
2037
|
}
|
|
1675
2038
|
/**
|
|
1676
2039
|
* Update nutrition goals for a specific date
|
|
1677
2040
|
*/
|
|
1678
2041
|
async updateNutritionGoals(date, request) {
|
|
1679
|
-
const
|
|
2042
|
+
const requestToSend = this.config.autoConvertUnits ? convertNutritionGoalsToMetric(request, this.config.measurementSystem) : request;
|
|
2043
|
+
const response = await this.http.put(`/v1/nutrition/goals/date/${date}`, requestToSend);
|
|
2044
|
+
if (this.config.autoConvertUnits) {
|
|
2045
|
+
return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
|
|
2046
|
+
}
|
|
1680
2047
|
return response.data;
|
|
1681
2048
|
}
|
|
1682
2049
|
/**
|
|
@@ -1702,6 +2069,9 @@ var GoalsResource = class {
|
|
|
1702
2069
|
*/
|
|
1703
2070
|
async getNutritionGoalsHistory(params) {
|
|
1704
2071
|
const response = await this.http.get("/v1/nutrition/goals/history", params);
|
|
2072
|
+
if (this.config.autoConvertUnits) {
|
|
2073
|
+
return convertNutritionGoalsFromMetric(response.data, this.config.measurementSystem);
|
|
2074
|
+
}
|
|
1705
2075
|
return response.data;
|
|
1706
2076
|
}
|
|
1707
2077
|
/**
|
|
@@ -1753,11 +2123,11 @@ var OpenLifeLog = class {
|
|
|
1753
2123
|
this.foods = new FoodsResource(this.httpClient);
|
|
1754
2124
|
this.foodLogs = new FoodLogsResource(this.httpClient);
|
|
1755
2125
|
this.exercises = new ExercisesResource(this.httpClient);
|
|
1756
|
-
this.workouts = new WorkoutsResource(this.httpClient);
|
|
1757
|
-
this.sessions = new SessionsResource(this.httpClient);
|
|
1758
|
-
this.programs = new ProgramsResource(this.httpClient);
|
|
1759
|
-
this.metrics = new MetricsResource(this.httpClient);
|
|
1760
|
-
this.goals = new GoalsResource(this.httpClient);
|
|
2126
|
+
this.workouts = new WorkoutsResource(this.httpClient, this.config);
|
|
2127
|
+
this.sessions = new SessionsResource(this.httpClient, this.config);
|
|
2128
|
+
this.programs = new ProgramsResource(this.httpClient, this.config);
|
|
2129
|
+
this.metrics = new MetricsResource(this.httpClient, this.config);
|
|
2130
|
+
this.goals = new GoalsResource(this.httpClient, this.config);
|
|
1761
2131
|
this.ai = new AIResource(this.httpClient);
|
|
1762
2132
|
}
|
|
1763
2133
|
/**
|