ts-garmin 0.1.1 → 0.1.2
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/garmin/GarminConnect.d.ts +2 -1
- package/dist/garmin/types/activity.d.ts +18 -0
- package/dist/index.js +92 -85
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpClient } from '../common/HttpClient';
|
|
2
|
-
import type { ActivitySubType, ActivityType, ExportFileTypeValue, GCActivityId, GCGearId, GarminDomain, IActivity, ICountActivities, IGarminTokens, IOauth1Token, IOauth2Token, ISocialProfile, IUserSettings, IWorkout, IWorkoutDetail, ListCoursesResponse, UploadFileTypeValue } from './types/index';
|
|
2
|
+
import type { ActivitySubType, ActivityType, ExportFileTypeValue, GCActivityId, GCGearId, GarminDomain, IActivity, IActivityDetails, ICountActivities, IGarminTokens, IOauth1Token, IOauth2Token, ISocialProfile, IUserSettings, IWorkout, IWorkoutDetail, ListCoursesResponse, UploadFileTypeValue } from './types/index';
|
|
3
3
|
import type { CoursePoint, GeoPoint, GpxActivityType, ImportedGpxResponse } from './types/gpx';
|
|
4
4
|
import type { GearData } from './types/gear';
|
|
5
5
|
import type { HeartRate } from './types/heartrate';
|
|
@@ -29,6 +29,7 @@ export default class GarminConnect {
|
|
|
29
29
|
getUserProfile(): Promise<ISocialProfile>;
|
|
30
30
|
getActivities(start?: number, limit?: number, activityType?: ActivityType, subActivityType?: ActivitySubType): Promise<IActivity[]>;
|
|
31
31
|
getActivity(activity: { activityId: GCActivityId }): Promise<IActivity>;
|
|
32
|
+
getActivityDetails(activity: { activityId: GCActivityId }, maxChartSize?: number): Promise<IActivityDetails>;
|
|
32
33
|
countActivities(): Promise<ICountActivities>;
|
|
33
34
|
downloadOriginalActivityData(activity: { activityId: GCActivityId }, dir: string, type?: ExportFileTypeValue): Promise<void>;
|
|
34
35
|
uploadActivity(file: string, format?: UploadFileTypeValue): Promise<unknown>;
|
|
@@ -377,6 +377,24 @@ export declare interface IActivityDetails {
|
|
|
377
377
|
maxDistance: number
|
|
378
378
|
}[] | null
|
|
379
379
|
}
|
|
380
|
+
/** One series in an activity's details, e.g. directHeartRate or sumDuration. */
|
|
381
|
+
export declare interface IActivityDetailMetricDescriptor {
|
|
382
|
+
metricsIndex: number
|
|
383
|
+
key: string
|
|
384
|
+
unit?: { id?: number, key?: string, factor?: number }
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* An activity's recorded time series from activity-service's details
|
|
388
|
+
* endpoint: `activityDetailMetrics[i].metrics[metricsIndex]` is sample i of
|
|
389
|
+
* the series the descriptor names. Garmin downsamples to `maxChartSize`.
|
|
390
|
+
*/
|
|
391
|
+
export declare interface IActivityDetails {
|
|
392
|
+
activityId: number
|
|
393
|
+
measurementCount?: number
|
|
394
|
+
metricsCount?: number
|
|
395
|
+
metricDescriptors: IActivityDetailMetricDescriptor[]
|
|
396
|
+
activityDetailMetrics: Array<{ metrics: Array<number | null> }>
|
|
397
|
+
}
|
|
380
398
|
export type GCActivityId = number;
|
|
381
399
|
export declare enum ActivityType {
|
|
382
400
|
Cycling = 'cycling',
|
package/dist/index.js
CHANGED
|
@@ -538,54 +538,54 @@ class UrlClass {
|
|
|
538
538
|
|
|
539
539
|
// src/garmin/types/activity.ts
|
|
540
540
|
var ActivityType;
|
|
541
|
-
((
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
541
|
+
((ActivityType) => {
|
|
542
|
+
ActivityType["Cycling"] = "cycling";
|
|
543
|
+
ActivityType["FitnessEquipment"] = "fitness_equipment";
|
|
544
|
+
ActivityType["Walking"] = "walking";
|
|
545
|
+
ActivityType["Hiking"] = "hiking";
|
|
546
|
+
ActivityType["Other"] = "other";
|
|
547
|
+
ActivityType["WaterSport"] = "water_sports";
|
|
548
|
+
ActivityType["Running"] = "street_running";
|
|
549
549
|
})(ActivityType ||= {});
|
|
550
550
|
var ActivitySubType;
|
|
551
|
-
((
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
551
|
+
((ActivitySubType) => {
|
|
552
|
+
ActivitySubType["IndoorCardio"] = "indoor_cardio";
|
|
553
|
+
ActivitySubType["StrengthTraining"] = "strength_training";
|
|
554
|
+
ActivitySubType["HIIT"] = "hiit";
|
|
555
|
+
ActivitySubType["Yoga"] = "yoga";
|
|
556
|
+
ActivitySubType["IndoorCycling"] = "indoor_cycling";
|
|
557
|
+
ActivitySubType["Breathwork"] = "breathwork";
|
|
558
|
+
ActivitySubType["Surfing"] = "surfing";
|
|
559
|
+
ActivitySubType["StreetRunning"] = "street_running";
|
|
560
|
+
ActivitySubType["TrailRunning"] = "trail_running";
|
|
561
|
+
ActivitySubType["IndoorRunning"] = "indoor_running";
|
|
562
562
|
})(ActivitySubType ||= {});
|
|
563
563
|
// src/garmin/types/gpx.ts
|
|
564
564
|
var GpxActivityType;
|
|
565
|
-
((
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
565
|
+
((GpxActivityType) => {
|
|
566
|
+
GpxActivityType[GpxActivityType["Running"] = 1] = "Running";
|
|
567
|
+
GpxActivityType[GpxActivityType["Running_Road"] = 1] = "Running_Road";
|
|
568
|
+
GpxActivityType[GpxActivityType["Running_Trail"] = 1] = "Running_Trail";
|
|
569
|
+
GpxActivityType[GpxActivityType["Cycling"] = 10] = "Cycling";
|
|
570
|
+
GpxActivityType[GpxActivityType["Cycling_Road"] = 10] = "Cycling_Road";
|
|
571
|
+
GpxActivityType[GpxActivityType["Cycling_Gravel"] = 143] = "Cycling_Gravel";
|
|
572
|
+
GpxActivityType[GpxActivityType["Hiking"] = 3] = "Hiking";
|
|
573
|
+
GpxActivityType[GpxActivityType["Other"] = 4] = "Other";
|
|
574
574
|
})(GpxActivityType ||= {});
|
|
575
575
|
|
|
576
576
|
// src/garmin/types/index.ts
|
|
577
577
|
var ExportFileType;
|
|
578
|
-
((
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
578
|
+
((ExportFileType) => {
|
|
579
|
+
ExportFileType["tcx"] = "tcx";
|
|
580
|
+
ExportFileType["gpx"] = "gpx";
|
|
581
|
+
ExportFileType["kml"] = "kml";
|
|
582
|
+
ExportFileType["zip"] = "zip";
|
|
583
583
|
})(ExportFileType ||= {});
|
|
584
584
|
var UploadFileType;
|
|
585
|
-
((
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
585
|
+
((UploadFileType) => {
|
|
586
|
+
UploadFileType["tcx"] = "tcx";
|
|
587
|
+
UploadFileType["gpx"] = "gpx";
|
|
588
|
+
UploadFileType["fit"] = "fit";
|
|
589
589
|
})(UploadFileType ||= {});
|
|
590
590
|
|
|
591
591
|
// src/garmin/common/DateUtils.ts
|
|
@@ -720,10 +720,17 @@ class GarminConnect {
|
|
|
720
720
|
params: { start, limit, activityType, subActivityType }
|
|
721
721
|
});
|
|
722
722
|
}
|
|
723
|
-
async getActivity(
|
|
724
|
-
if (!
|
|
723
|
+
async getActivity(activity) {
|
|
724
|
+
if (!activity.activityId)
|
|
725
725
|
throw new Error("Missing activityId");
|
|
726
|
-
return this.client.get(`${this.url.ACTIVITY}${
|
|
726
|
+
return this.client.get(`${this.url.ACTIVITY}${activity.activityId}`);
|
|
727
|
+
}
|
|
728
|
+
async getActivityDetails(activity, maxChartSize = 2000) {
|
|
729
|
+
if (!activity.activityId)
|
|
730
|
+
throw new Error("Missing activityId");
|
|
731
|
+
return this.client.get(`${this.url.ACTIVITY_BY_ID(activity.activityId)}/details`, {
|
|
732
|
+
params: { maxChartSize, maxPolylineSize: 0, maxHeatMapSize: 0 }
|
|
733
|
+
});
|
|
727
734
|
}
|
|
728
735
|
async countActivities() {
|
|
729
736
|
const now = new Date;
|
|
@@ -737,8 +744,8 @@ class GarminConnect {
|
|
|
737
744
|
}
|
|
738
745
|
});
|
|
739
746
|
}
|
|
740
|
-
async downloadOriginalActivityData(
|
|
741
|
-
if (!
|
|
747
|
+
async downloadOriginalActivityData(activity, dir, type = "zip") {
|
|
748
|
+
if (!activity.activityId)
|
|
742
749
|
throw new Error("Missing activityId");
|
|
743
750
|
if (!checkIsDirectory(dir)) {
|
|
744
751
|
createDirectory(dir);
|
|
@@ -746,18 +753,18 @@ class GarminConnect {
|
|
|
746
753
|
let fileBuffer;
|
|
747
754
|
let url;
|
|
748
755
|
if (type === "tcx") {
|
|
749
|
-
url = `${this.url.DOWNLOAD_TCX}${
|
|
756
|
+
url = `${this.url.DOWNLOAD_TCX}${activity.activityId}`;
|
|
750
757
|
} else if (type === "gpx") {
|
|
751
|
-
url = `${this.url.DOWNLOAD_GPX}${
|
|
758
|
+
url = `${this.url.DOWNLOAD_GPX}${activity.activityId}`;
|
|
752
759
|
} else if (type === "kml") {
|
|
753
|
-
url = `${this.url.DOWNLOAD_KML}${
|
|
760
|
+
url = `${this.url.DOWNLOAD_KML}${activity.activityId}`;
|
|
754
761
|
} else if (type === "zip") {
|
|
755
|
-
url = `${this.url.DOWNLOAD_ZIP}${
|
|
762
|
+
url = `${this.url.DOWNLOAD_ZIP}${activity.activityId}`;
|
|
756
763
|
} else {
|
|
757
764
|
throw new Error(`downloadOriginalActivityData - Invalid type: ${type}`);
|
|
758
765
|
}
|
|
759
766
|
fileBuffer = await this.client.get(url, { responseType: "arraybuffer" });
|
|
760
|
-
writeToFile(path.join(dir, `${
|
|
767
|
+
writeToFile(path.join(dir, `${activity.activityId}.${type}`), Buffer.from(fileBuffer));
|
|
761
768
|
}
|
|
762
769
|
async uploadActivity(file, format = "fit") {
|
|
763
770
|
const detectedFormat = (format || path.extname(file))?.toLowerCase();
|
|
@@ -776,31 +783,31 @@ class GarminConnect {
|
|
|
776
783
|
});
|
|
777
784
|
return response.json();
|
|
778
785
|
}
|
|
779
|
-
async deleteActivity(
|
|
780
|
-
if (!
|
|
786
|
+
async deleteActivity(activity) {
|
|
787
|
+
if (!activity.activityId)
|
|
781
788
|
throw new Error("Missing activityId");
|
|
782
|
-
await this.client.delete(`${this.url.ACTIVITY}${
|
|
789
|
+
await this.client.delete(`${this.url.ACTIVITY}${activity.activityId}`);
|
|
783
790
|
}
|
|
784
791
|
async getWorkouts(start, limit) {
|
|
785
792
|
return this.client.get(this.url.WORKOUTS, {
|
|
786
793
|
params: { start, limit }
|
|
787
794
|
});
|
|
788
795
|
}
|
|
789
|
-
async getWorkoutDetail(
|
|
790
|
-
if (!
|
|
796
|
+
async getWorkoutDetail(workout) {
|
|
797
|
+
if (!workout.workoutId)
|
|
791
798
|
throw new Error("Missing workoutId");
|
|
792
|
-
return this.client.get(this.url.WORKOUT(
|
|
799
|
+
return this.client.get(this.url.WORKOUT(workout.workoutId));
|
|
793
800
|
}
|
|
794
|
-
async createWorkout(
|
|
795
|
-
return this.client.post(this.url.WORKOUT(),
|
|
801
|
+
async createWorkout(workout) {
|
|
802
|
+
return this.client.post(this.url.WORKOUT(), workout);
|
|
796
803
|
}
|
|
797
|
-
async deleteWorkout(
|
|
798
|
-
if (!
|
|
804
|
+
async deleteWorkout(workout) {
|
|
805
|
+
if (!workout.workoutId)
|
|
799
806
|
throw new Error("Missing workout");
|
|
800
|
-
return this.client.delete(this.url.WORKOUT(
|
|
807
|
+
return this.client.delete(this.url.WORKOUT(workout.workoutId));
|
|
801
808
|
}
|
|
802
|
-
async scheduleWorkout(
|
|
803
|
-
return this.client.post(this.url.SCHEDULE_WORKOUT(Number.parseInt(
|
|
809
|
+
async scheduleWorkout(workout, scheduleDate) {
|
|
810
|
+
return this.client.post(this.url.SCHEDULE_WORKOUT(Number.parseInt(workout.workoutId)), { date: scheduleDate });
|
|
804
811
|
}
|
|
805
812
|
async getSteps(date = new Date) {
|
|
806
813
|
const dateString = toDateString(date);
|
|
@@ -1482,30 +1489,30 @@ class WorkoutType {
|
|
|
1482
1489
|
static Cardio = new WorkoutType("cardio_training", 6);
|
|
1483
1490
|
}
|
|
1484
1491
|
export {
|
|
1485
|
-
|
|
1486
|
-
WorkoutType,
|
|
1487
|
-
WorkoutBuilder,
|
|
1488
|
-
UploadFileType,
|
|
1489
|
-
TimeDuration,
|
|
1490
|
-
Target,
|
|
1491
|
-
StepType,
|
|
1492
|
-
Step,
|
|
1493
|
-
PowerZoneTarget,
|
|
1494
|
-
PowerZone,
|
|
1495
|
-
PaceTarget,
|
|
1496
|
-
NoTarget,
|
|
1497
|
-
NoDuration,
|
|
1498
|
-
LapPressDuration,
|
|
1499
|
-
HrmZoneTarget,
|
|
1500
|
-
HrmTarget,
|
|
1501
|
-
HeartRateDuration,
|
|
1502
|
-
GpxActivityType,
|
|
1503
|
-
GarminConnect,
|
|
1504
|
-
ExportFileType,
|
|
1505
|
-
Duration,
|
|
1506
|
-
DistanceDuration,
|
|
1507
|
-
CaloriesDuration,
|
|
1508
|
-
CadenceTarget,
|
|
1492
|
+
ActivitySubType,
|
|
1509
1493
|
ActivityType,
|
|
1510
|
-
|
|
1494
|
+
CadenceTarget,
|
|
1495
|
+
CaloriesDuration,
|
|
1496
|
+
DistanceDuration,
|
|
1497
|
+
Duration,
|
|
1498
|
+
ExportFileType,
|
|
1499
|
+
GarminConnect,
|
|
1500
|
+
GpxActivityType,
|
|
1501
|
+
HeartRateDuration,
|
|
1502
|
+
HrmTarget,
|
|
1503
|
+
HrmZoneTarget,
|
|
1504
|
+
LapPressDuration,
|
|
1505
|
+
NoDuration,
|
|
1506
|
+
NoTarget,
|
|
1507
|
+
PaceTarget,
|
|
1508
|
+
PowerZone,
|
|
1509
|
+
PowerZoneTarget,
|
|
1510
|
+
Step,
|
|
1511
|
+
StepType,
|
|
1512
|
+
Target,
|
|
1513
|
+
TimeDuration,
|
|
1514
|
+
UploadFileType,
|
|
1515
|
+
WorkoutBuilder,
|
|
1516
|
+
WorkoutType,
|
|
1517
|
+
courseRequestTemplate
|
|
1511
1518
|
};
|