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.
@@ -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
- ((ActivityType2) => {
542
- ActivityType2["Cycling"] = "cycling";
543
- ActivityType2["FitnessEquipment"] = "fitness_equipment";
544
- ActivityType2["Walking"] = "walking";
545
- ActivityType2["Hiking"] = "hiking";
546
- ActivityType2["Other"] = "other";
547
- ActivityType2["WaterSport"] = "water_sports";
548
- ActivityType2["Running"] = "street_running";
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
- ((ActivitySubType2) => {
552
- ActivitySubType2["IndoorCardio"] = "indoor_cardio";
553
- ActivitySubType2["StrengthTraining"] = "strength_training";
554
- ActivitySubType2["HIIT"] = "hiit";
555
- ActivitySubType2["Yoga"] = "yoga";
556
- ActivitySubType2["IndoorCycling"] = "indoor_cycling";
557
- ActivitySubType2["Breathwork"] = "breathwork";
558
- ActivitySubType2["Surfing"] = "surfing";
559
- ActivitySubType2["StreetRunning"] = "street_running";
560
- ActivitySubType2["TrailRunning"] = "trail_running";
561
- ActivitySubType2["IndoorRunning"] = "indoor_running";
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
- ((GpxActivityType2) => {
566
- GpxActivityType2[GpxActivityType2["Running"] = 1] = "Running";
567
- GpxActivityType2[GpxActivityType2["Running_Road"] = 1] = "Running_Road";
568
- GpxActivityType2[GpxActivityType2["Running_Trail"] = 1] = "Running_Trail";
569
- GpxActivityType2[GpxActivityType2["Cycling"] = 10] = "Cycling";
570
- GpxActivityType2[GpxActivityType2["Cycling_Road"] = 10] = "Cycling_Road";
571
- GpxActivityType2[GpxActivityType2["Cycling_Gravel"] = 143] = "Cycling_Gravel";
572
- GpxActivityType2[GpxActivityType2["Hiking"] = 3] = "Hiking";
573
- GpxActivityType2[GpxActivityType2["Other"] = 4] = "Other";
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
- ((ExportFileType2) => {
579
- ExportFileType2["tcx"] = "tcx";
580
- ExportFileType2["gpx"] = "gpx";
581
- ExportFileType2["kml"] = "kml";
582
- ExportFileType2["zip"] = "zip";
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
- ((UploadFileType2) => {
586
- UploadFileType2["tcx"] = "tcx";
587
- UploadFileType2["gpx"] = "gpx";
588
- UploadFileType2["fit"] = "fit";
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(activity2) {
724
- if (!activity2.activityId)
723
+ async getActivity(activity) {
724
+ if (!activity.activityId)
725
725
  throw new Error("Missing activityId");
726
- return this.client.get(`${this.url.ACTIVITY}${activity2.activityId}`);
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(activity2, dir, type = "zip") {
741
- if (!activity2.activityId)
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}${activity2.activityId}`;
756
+ url = `${this.url.DOWNLOAD_TCX}${activity.activityId}`;
750
757
  } else if (type === "gpx") {
751
- url = `${this.url.DOWNLOAD_GPX}${activity2.activityId}`;
758
+ url = `${this.url.DOWNLOAD_GPX}${activity.activityId}`;
752
759
  } else if (type === "kml") {
753
- url = `${this.url.DOWNLOAD_KML}${activity2.activityId}`;
760
+ url = `${this.url.DOWNLOAD_KML}${activity.activityId}`;
754
761
  } else if (type === "zip") {
755
- url = `${this.url.DOWNLOAD_ZIP}${activity2.activityId}`;
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, `${activity2.activityId}.${type}`), Buffer.from(fileBuffer));
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(activity2) {
780
- if (!activity2.activityId)
786
+ async deleteActivity(activity) {
787
+ if (!activity.activityId)
781
788
  throw new Error("Missing activityId");
782
- await this.client.delete(`${this.url.ACTIVITY}${activity2.activityId}`);
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(workout2) {
790
- if (!workout2.workoutId)
796
+ async getWorkoutDetail(workout) {
797
+ if (!workout.workoutId)
791
798
  throw new Error("Missing workoutId");
792
- return this.client.get(this.url.WORKOUT(workout2.workoutId));
799
+ return this.client.get(this.url.WORKOUT(workout.workoutId));
793
800
  }
794
- async createWorkout(workout2) {
795
- return this.client.post(this.url.WORKOUT(), workout2);
801
+ async createWorkout(workout) {
802
+ return this.client.post(this.url.WORKOUT(), workout);
796
803
  }
797
- async deleteWorkout(workout2) {
798
- if (!workout2.workoutId)
804
+ async deleteWorkout(workout) {
805
+ if (!workout.workoutId)
799
806
  throw new Error("Missing workout");
800
- return this.client.delete(this.url.WORKOUT(workout2.workoutId));
807
+ return this.client.delete(this.url.WORKOUT(workout.workoutId));
801
808
  }
802
- async scheduleWorkout(workout2, scheduleDate) {
803
- return this.client.post(this.url.SCHEDULE_WORKOUT(Number.parseInt(workout2.workoutId)), { date: scheduleDate });
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
- courseRequestTemplate,
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
- ActivitySubType
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
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ts-garmin",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "TypeScript library for interfacing with Garmin Connect API",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",