ts-garmin 0.1.2 → 0.1.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/README.md +1 -0
- package/dist/garmin/GarminConnect.d.ts +2 -1
- package/dist/index.js +16 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -172,6 +172,7 @@ const userId = await garmin.getUserId(tokens.accessToken) // the key push notifi
|
|
|
172
172
|
const legacy = new GarminConnectClient()
|
|
173
173
|
await legacy.login('email@example.com', 'password')
|
|
174
174
|
const activities = await legacy.getActivities(new Date('2024-01-01'))
|
|
175
|
+
const { bytes, filename } = await legacy.downloadOriginalActivity(activityId) // "Export Original" zip, in memory
|
|
175
176
|
|
|
176
177
|
// Strava
|
|
177
178
|
const strava = new StravaClient({
|
|
@@ -31,7 +31,8 @@ export default class GarminConnect {
|
|
|
31
31
|
getActivity(activity: { activityId: GCActivityId }): Promise<IActivity>;
|
|
32
32
|
getActivityDetails(activity: { activityId: GCActivityId }, maxChartSize?: number): Promise<IActivityDetails>;
|
|
33
33
|
countActivities(): Promise<ICountActivities>;
|
|
34
|
-
|
|
34
|
+
getOriginalActivityData(activity: { activityId: GCActivityId }, type?: ExportFileTypeValue): Promise<{ bytes: Uint8Array, filename: string }>;
|
|
35
|
+
downloadOriginalActivityData(activity: { activityId: GCActivityId }, dir: string, type?: ExportFileTypeValue): Promise<string>;
|
|
35
36
|
uploadActivity(file: string, format?: UploadFileTypeValue): Promise<unknown>;
|
|
36
37
|
deleteActivity(activity: { activityId: GCActivityId }): Promise<void>;
|
|
37
38
|
getWorkouts(start: number, limit: number): Promise<IWorkout[]>;
|
package/dist/index.js
CHANGED
|
@@ -143,13 +143,13 @@ class HttpClient {
|
|
|
143
143
|
const text = await response.text();
|
|
144
144
|
throw new Error(`HTTP Error: ${response.status} ${response.statusText} - ${text}`);
|
|
145
145
|
}
|
|
146
|
+
if (responseType === "arraybuffer") {
|
|
147
|
+
return response.arrayBuffer();
|
|
148
|
+
}
|
|
146
149
|
const contentType = response.headers.get("content-type");
|
|
147
150
|
if (contentType?.includes("application/json")) {
|
|
148
151
|
return response.json();
|
|
149
152
|
}
|
|
150
|
-
if (responseType === "arraybuffer") {
|
|
151
|
-
return response.arrayBuffer();
|
|
152
|
-
}
|
|
153
153
|
return response.text();
|
|
154
154
|
}
|
|
155
155
|
async get(url, config) {
|
|
@@ -744,13 +744,9 @@ class GarminConnect {
|
|
|
744
744
|
}
|
|
745
745
|
});
|
|
746
746
|
}
|
|
747
|
-
async
|
|
747
|
+
async getOriginalActivityData(activity, type = "zip") {
|
|
748
748
|
if (!activity.activityId)
|
|
749
749
|
throw new Error("Missing activityId");
|
|
750
|
-
if (!checkIsDirectory(dir)) {
|
|
751
|
-
createDirectory(dir);
|
|
752
|
-
}
|
|
753
|
-
let fileBuffer;
|
|
754
750
|
let url;
|
|
755
751
|
if (type === "tcx") {
|
|
756
752
|
url = `${this.url.DOWNLOAD_TCX}${activity.activityId}`;
|
|
@@ -761,10 +757,19 @@ class GarminConnect {
|
|
|
761
757
|
} else if (type === "zip") {
|
|
762
758
|
url = `${this.url.DOWNLOAD_ZIP}${activity.activityId}`;
|
|
763
759
|
} else {
|
|
764
|
-
throw new Error(`
|
|
760
|
+
throw new Error(`getOriginalActivityData - Invalid type: ${type}`);
|
|
761
|
+
}
|
|
762
|
+
const body = await this.client.get(url, { responseType: "arraybuffer" });
|
|
763
|
+
return { bytes: new Uint8Array(body), filename: `${activity.activityId}.${type}` };
|
|
764
|
+
}
|
|
765
|
+
async downloadOriginalActivityData(activity, dir, type = "zip") {
|
|
766
|
+
const { bytes, filename } = await this.getOriginalActivityData(activity, type);
|
|
767
|
+
if (!checkIsDirectory(dir)) {
|
|
768
|
+
createDirectory(dir);
|
|
765
769
|
}
|
|
766
|
-
|
|
767
|
-
writeToFile(
|
|
770
|
+
const file = path.join(dir, filename);
|
|
771
|
+
writeToFile(file, bytes);
|
|
772
|
+
return file;
|
|
768
773
|
}
|
|
769
774
|
async uploadActivity(file, format = "fit") {
|
|
770
775
|
const detectedFormat = (format || path.extname(file))?.toLowerCase();
|