@gooin/garmin-connect 1.4.4 → 1.6.0
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 +225 -35
- package/dist/common/CFClient.d.ts +22 -0
- package/dist/common/CFClient.js +137 -140
- package/dist/common/CFClient.js.map +1 -0
- package/dist/common/DateUtils.d.ts +1 -0
- package/dist/common/DateUtils.js +11 -10
- package/dist/common/DateUtils.js.map +1 -0
- package/dist/common/HttpClient.d.ts +34 -0
- package/dist/common/HttpClient.js +299 -0
- package/dist/common/HttpClient.js.map +1 -0
- package/dist/garmin/GarminConnect.d.ts +40 -0
- package/dist/garmin/GarminConnect.js +178 -438
- package/dist/garmin/GarminConnect.js.map +1 -0
- package/dist/garmin/UrlClass.d.ts +25 -0
- package/dist/garmin/UrlClass.js +64 -0
- package/dist/garmin/UrlClass.js.map +1 -0
- package/dist/garmin/Urls.d.ts +64 -0
- package/dist/garmin/Urls.js +104 -102
- package/dist/garmin/Urls.js.map +1 -0
- package/dist/garmin/types.d.ts +706 -0
- package/dist/garmin/types.js +17 -0
- package/dist/garmin/types.js.map +1 -0
- package/dist/garmin/workouts/Running.d.ts +16 -0
- package/dist/garmin/workouts/Running.js +47 -53
- package/dist/garmin/workouts/Running.js.map +1 -0
- package/dist/garmin/workouts/templates/RunningTemplate.d.ts +68 -0
- package/dist/garmin/workouts/templates/RunningTemplate.js +78 -48
- package/dist/garmin/workouts/templates/RunningTemplate.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +46 -0
- package/dist/utils.js.map +1 -0
- package/examples/example.js +21 -6
- package/package.json +66 -51
- package/dist/common/Client.js +0 -189
- package/dist/garmin/workouts/index.js +0 -5
|
@@ -1,438 +1,178 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
* Get detailed sleep data for a specific date
|
|
180
|
-
* @param date
|
|
181
|
-
* @returns {Promise<*>}
|
|
182
|
-
*/
|
|
183
|
-
async getSleepData(date = new Date()) {
|
|
184
|
-
const dateString = toDateString(date);
|
|
185
|
-
return this.get(urls.dailySleepData(this.userHash), { date: dateString });
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Get sleep data summary for a specific date
|
|
190
|
-
* @param date
|
|
191
|
-
* @returns {Promise<*>}
|
|
192
|
-
*/
|
|
193
|
-
async getSleep(date = new Date()) {
|
|
194
|
-
const dateString = toDateString(date);
|
|
195
|
-
return this.get(urls.dailySleep(), { date: dateString });
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Heart rate
|
|
199
|
-
/**
|
|
200
|
-
* Get heart rate measurements for a specific date
|
|
201
|
-
* @param date
|
|
202
|
-
* @returns {Promise<*>}
|
|
203
|
-
*/
|
|
204
|
-
async getHeartRate(date = new Date()) {
|
|
205
|
-
const dateString = toDateString(date);
|
|
206
|
-
return this.get(urls.dailyHeartRate(this.userHash), { date: dateString });
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Weight
|
|
210
|
-
/**
|
|
211
|
-
* Post a new body weight
|
|
212
|
-
* @param weight
|
|
213
|
-
* @returns {Promise<*>}
|
|
214
|
-
*/
|
|
215
|
-
async setBodyWeight(weight) {
|
|
216
|
-
if (weight) {
|
|
217
|
-
const roundWeight = Math.round(weight * 1000);
|
|
218
|
-
const data = { userData: { weight: roundWeight } };
|
|
219
|
-
return this.put(urls.userSettings(), data);
|
|
220
|
-
}
|
|
221
|
-
return Promise.reject();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Activites
|
|
225
|
-
/**
|
|
226
|
-
* Get list of activites
|
|
227
|
-
* @param start
|
|
228
|
-
* @param limit
|
|
229
|
-
* @returns {Promise<*>}
|
|
230
|
-
*/
|
|
231
|
-
async getActivities(start, limit) {
|
|
232
|
-
return this.get(urls.activities(), { start, limit });
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Get details about an activity
|
|
237
|
-
* @param activity
|
|
238
|
-
* @param maxChartSize
|
|
239
|
-
* @param maxPolylineSize
|
|
240
|
-
* @returns {Promise<*>}
|
|
241
|
-
*/
|
|
242
|
-
async getActivity(activity, maxChartSize, maxPolylineSize) {
|
|
243
|
-
const { activityId } = activity || {};
|
|
244
|
-
if (activityId) {
|
|
245
|
-
return this.get(urls.activityDetails(activityId), { maxChartSize, maxPolylineSize });
|
|
246
|
-
}
|
|
247
|
-
return Promise.reject();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Get weather data from an activity
|
|
252
|
-
* @param activity
|
|
253
|
-
* @returns {Promise<*>}
|
|
254
|
-
*/
|
|
255
|
-
async getActivityWeather(activity) {
|
|
256
|
-
const { activityId } = activity || {};
|
|
257
|
-
if (activityId) {
|
|
258
|
-
return this.get(urls.weather(activityId));
|
|
259
|
-
}
|
|
260
|
-
return Promise.reject();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Updates an activity
|
|
265
|
-
* @param activity
|
|
266
|
-
* @returns {Promise<*>}
|
|
267
|
-
*/
|
|
268
|
-
async updateActivity(activity) {
|
|
269
|
-
return this.put(urls.activity(activity.activityId), activity);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Deletes an activity
|
|
274
|
-
* @param activity
|
|
275
|
-
* @returns {Promise<*>}
|
|
276
|
-
*/
|
|
277
|
-
async deleteActivity(activity) {
|
|
278
|
-
const { activityId } = activity || {};
|
|
279
|
-
if (activityId) {
|
|
280
|
-
const headers = { 'x-http-method-override': 'DELETE' };
|
|
281
|
-
return this.client.postJson(urls.activity(activityId), undefined, undefined, headers);
|
|
282
|
-
}
|
|
283
|
-
return Promise.reject();
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Get list of activities in your news feed
|
|
288
|
-
* @param start
|
|
289
|
-
* @param limit
|
|
290
|
-
* @returns {Promise<*>}
|
|
291
|
-
*/
|
|
292
|
-
async getNewsFeed(start, limit) {
|
|
293
|
-
return this.get(urls.newsFeed(), { start, limit });
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// Steps
|
|
297
|
-
/**
|
|
298
|
-
* Get step count for a specific date
|
|
299
|
-
* @param date
|
|
300
|
-
* @returns {Promise<*>}
|
|
301
|
-
*/
|
|
302
|
-
async getSteps(date = new Date()) {
|
|
303
|
-
const dateString = toDateString(date);
|
|
304
|
-
return this.get(urls.dailySummaryChart(this.userHash), { date: dateString });
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Workouts
|
|
308
|
-
/**
|
|
309
|
-
* Get list of workouts
|
|
310
|
-
* @param start
|
|
311
|
-
* @param limit
|
|
312
|
-
* @returns {Promise<*>}
|
|
313
|
-
*/
|
|
314
|
-
async getWorkouts(start, limit) {
|
|
315
|
-
return this.get(urls.workouts(), { start, limit });
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Download original activity data to disk as zip
|
|
320
|
-
* Resolves to absolute path for the downloaded file
|
|
321
|
-
* @param activity : any
|
|
322
|
-
* @param dir Will default to current working directory
|
|
323
|
-
* @param type : string - Will default to 'zip'. Other possible values are 'tcx', 'gpx' or 'kml'.
|
|
324
|
-
* @returns {Promise<*>}
|
|
325
|
-
*/
|
|
326
|
-
async downloadOriginalActivityData(activity, dir, type = '') {
|
|
327
|
-
const { activityId } = activity || {};
|
|
328
|
-
if (activityId) {
|
|
329
|
-
const url = type === '' || type === 'zip'
|
|
330
|
-
? urls.originalFile(activityId)
|
|
331
|
-
: urls.exportFile(activityId, type);
|
|
332
|
-
return this.client.downloadBlob(dir, url);
|
|
333
|
-
}
|
|
334
|
-
return Promise.reject();
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Uploads an activity file ('gpx', 'tcx', or 'fit')
|
|
339
|
-
* @param file the file to upload
|
|
340
|
-
* @param format the format of the file. If undefined, the extension of the file will be used.
|
|
341
|
-
* @returns {Promise<*>}
|
|
342
|
-
*/
|
|
343
|
-
async uploadActivity(file, format) {
|
|
344
|
-
// throw new Error('uploadActivity method is disabled in this version');
|
|
345
|
-
|
|
346
|
-
const detectedFormat = format || `.${file.split('.').pop()}`;
|
|
347
|
-
if (detectedFormat !== '.gpx' && detectedFormat !== '.tcx' && detectedFormat !== '.fit') {
|
|
348
|
-
Promise.reject();
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const fileBinary = fs.createReadStream(file);
|
|
352
|
-
return this.client.post(urls.upload(format), {
|
|
353
|
-
file: fileBinary,
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Adds a running workout with one step of completeing a set distance.
|
|
359
|
-
* @param name
|
|
360
|
-
* @param meters
|
|
361
|
-
* @param description
|
|
362
|
-
* @returns {Promise<*>}
|
|
363
|
-
*/
|
|
364
|
-
async addRunningWorkout(name, meters, description) {
|
|
365
|
-
const running = new Running();
|
|
366
|
-
running.name = name;
|
|
367
|
-
running.distance = meters;
|
|
368
|
-
running.description = description;
|
|
369
|
-
return this.addWorkout(running);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Add a new workout preset.
|
|
374
|
-
* @param workout
|
|
375
|
-
* @returns {Promise<*>}
|
|
376
|
-
*/
|
|
377
|
-
async addWorkout(workout) {
|
|
378
|
-
if (workout.isValid()) {
|
|
379
|
-
const data = { ...workout.toJson() };
|
|
380
|
-
if (!data.description) {
|
|
381
|
-
data.description = 'Added by garmin-connect for Node.js';
|
|
382
|
-
}
|
|
383
|
-
return this.post(urls.workout(), data);
|
|
384
|
-
}
|
|
385
|
-
return Promise.reject();
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Add a workout to your workout calendar.
|
|
390
|
-
* @param workout
|
|
391
|
-
* @param date
|
|
392
|
-
* @returns {Promise<*>}
|
|
393
|
-
*/
|
|
394
|
-
async scheduleWorkout(workout, date) {
|
|
395
|
-
const { workoutId } = workout || {};
|
|
396
|
-
if (workoutId && date) {
|
|
397
|
-
const dateString = toDateString(date);
|
|
398
|
-
return this.post(urls.schedule(workoutId), { date: dateString });
|
|
399
|
-
}
|
|
400
|
-
return Promise.reject();
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Delete a workout based on a workout object.
|
|
405
|
-
* @param workout
|
|
406
|
-
* @returns {Promise<*>}
|
|
407
|
-
*/
|
|
408
|
-
async deleteWorkout(workout) {
|
|
409
|
-
const { workoutId } = workout || {};
|
|
410
|
-
if (workoutId) {
|
|
411
|
-
const headers = { 'x-http-method-override': 'DELETE' };
|
|
412
|
-
return this.client.postJson(urls.workout(workoutId), undefined, undefined, headers);
|
|
413
|
-
}
|
|
414
|
-
return Promise.reject();
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// General methods
|
|
418
|
-
|
|
419
|
-
async get(url, data) {
|
|
420
|
-
const response = await this.client.get(url, data);
|
|
421
|
-
this.triggerEvent(this.events.sessionChange, this.sessionJson);
|
|
422
|
-
return response;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
async post(url, data) {
|
|
426
|
-
const response = await this.client.postJson(url, data);
|
|
427
|
-
this.triggerEvent(this.events.sessionChange, this.sessionJson);
|
|
428
|
-
return response;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
async put(url, data) {
|
|
432
|
-
const response = await this.client.putJson(url, data);
|
|
433
|
-
this.triggerEvent(this.events.sessionChange, this.sessionJson);
|
|
434
|
-
return response;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
module.exports = GarminConnect;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Event = void 0;
|
|
30
|
+
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
31
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
32
|
+
const luxon_1 = require("luxon");
|
|
33
|
+
const fs = __importStar(require("node:fs"));
|
|
34
|
+
const path = __importStar(require("node:path"));
|
|
35
|
+
const HttpClient_1 = require("../common/HttpClient");
|
|
36
|
+
const utils_1 = require("../utils");
|
|
37
|
+
const UrlClass_1 = require("./UrlClass");
|
|
38
|
+
const types_1 = require("./types");
|
|
39
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
40
|
+
let config = undefined;
|
|
41
|
+
try {
|
|
42
|
+
config = app_root_path_1.default.require('/garmin.config.json');
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
// Do nothing
|
|
46
|
+
}
|
|
47
|
+
var Event;
|
|
48
|
+
(function (Event) {
|
|
49
|
+
Event["sessionChange"] = "sessionChange";
|
|
50
|
+
})(Event = exports.Event || (exports.Event = {}));
|
|
51
|
+
class GarminConnect {
|
|
52
|
+
// private oauth1: OAuth;
|
|
53
|
+
constructor(credentials = config, domain = 'garmin.com') {
|
|
54
|
+
if (!credentials) {
|
|
55
|
+
throw new Error('Missing credentials');
|
|
56
|
+
}
|
|
57
|
+
this.credentials = credentials;
|
|
58
|
+
this.url = new UrlClass_1.UrlClass(domain);
|
|
59
|
+
this.client = new HttpClient_1.HttpClient(this.url);
|
|
60
|
+
this._userHash = undefined;
|
|
61
|
+
this.listeners = {};
|
|
62
|
+
}
|
|
63
|
+
async login(username, password) {
|
|
64
|
+
if (username && password) {
|
|
65
|
+
this.credentials.username = username;
|
|
66
|
+
this.credentials.password = password;
|
|
67
|
+
}
|
|
68
|
+
await this.client.login(this.credentials.username, this.credentials.password);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
exportTokenToFile(dirPath) {
|
|
72
|
+
if (!(0, utils_1.checkIsDirectory)(dirPath)) {
|
|
73
|
+
(0, utils_1.createDirectory)(dirPath);
|
|
74
|
+
}
|
|
75
|
+
// save oauth1 to json
|
|
76
|
+
if (this.client.oauth1Token) {
|
|
77
|
+
(0, utils_1.writeToFile)(path.join(dirPath, 'oauth1_token.json'), JSON.stringify(this.client.oauth1Token));
|
|
78
|
+
}
|
|
79
|
+
if (this.client.oauth2Token) {
|
|
80
|
+
(0, utils_1.writeToFile)(path.join(dirPath, 'oauth2_token.json'), JSON.stringify(this.client.oauth2Token));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
loadTokenByFile(dirPath) {
|
|
84
|
+
if (!(0, utils_1.checkIsDirectory)(dirPath)) {
|
|
85
|
+
throw new Error('loadTokenByFile: Directory not found: ' + dirPath);
|
|
86
|
+
}
|
|
87
|
+
let oauth1Data = fs.readFileSync(path.join(dirPath, 'oauth1_token.json'));
|
|
88
|
+
const oauth1 = JSON.parse(oauth1Data);
|
|
89
|
+
this.client.oauth1Token = oauth1;
|
|
90
|
+
let oauth2Data = fs.readFileSync(path.join(dirPath, 'oauth2_token.json'));
|
|
91
|
+
const oauth2 = JSON.parse(oauth2Data);
|
|
92
|
+
this.client.oauth2Token = oauth2;
|
|
93
|
+
}
|
|
94
|
+
// from db or localstorage etc
|
|
95
|
+
loadToken(oauth1, oauth2) {
|
|
96
|
+
this.client.oauth1Token = oauth1;
|
|
97
|
+
this.client.oauth2Token = oauth2;
|
|
98
|
+
}
|
|
99
|
+
async getUserSettings() {
|
|
100
|
+
return this.client.get(this.url.USER_SETTINGS);
|
|
101
|
+
}
|
|
102
|
+
async getUserProfile() {
|
|
103
|
+
return this.client.get(this.url.USER_PROFILE);
|
|
104
|
+
}
|
|
105
|
+
async getActivities(start, limit) {
|
|
106
|
+
return this.client.get(this.url.ACTIVITIES, {
|
|
107
|
+
params: { start, limit }
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async getActivity(activity) {
|
|
111
|
+
if (!activity.activityId)
|
|
112
|
+
throw new Error('Missing activityId');
|
|
113
|
+
return this.client.get(this.url.ACTIVITY + activity.activityId);
|
|
114
|
+
}
|
|
115
|
+
async countActivities() {
|
|
116
|
+
return this.client.get(this.url.STAT_ACTIVITIES, {
|
|
117
|
+
params: {
|
|
118
|
+
aggregation: 'lifetime',
|
|
119
|
+
startDate: '1970-01-01',
|
|
120
|
+
endDate: luxon_1.DateTime.now().toFormat('yyyy-MM-dd'),
|
|
121
|
+
metric: 'duration'
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async downloadOriginalActivityData(activity, dir, type = 'zip') {
|
|
126
|
+
if (!activity.activityId)
|
|
127
|
+
throw new Error('Missing activityId');
|
|
128
|
+
if (!(0, utils_1.checkIsDirectory)(dir)) {
|
|
129
|
+
(0, utils_1.createDirectory)(dir);
|
|
130
|
+
}
|
|
131
|
+
let fileBuffer;
|
|
132
|
+
if (type === 'tcx') {
|
|
133
|
+
fileBuffer = await this.client.get(this.url.DOWNLOAD_TCX + activity.activityId);
|
|
134
|
+
}
|
|
135
|
+
else if (type === 'gpx') {
|
|
136
|
+
fileBuffer = await this.client.get(this.url.DOWNLOAD_GPX + activity.activityId);
|
|
137
|
+
}
|
|
138
|
+
else if (type === 'kml') {
|
|
139
|
+
fileBuffer = await this.client.get(this.url.DOWNLOAD_KML + activity.activityId);
|
|
140
|
+
}
|
|
141
|
+
else if (type === 'zip') {
|
|
142
|
+
fileBuffer = await this.client.get(this.url.DOWNLOAD_ZIP + activity.activityId, {
|
|
143
|
+
responseType: 'arraybuffer'
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
throw new Error('downloadOriginalActivityData - Invalid type: ' + type);
|
|
148
|
+
}
|
|
149
|
+
(0, utils_1.writeToFile)(path.join(dir, `${activity.activityId}.${type}`), fileBuffer);
|
|
150
|
+
}
|
|
151
|
+
async uploadActivity(file, format = 'fit') {
|
|
152
|
+
var _a;
|
|
153
|
+
const detectedFormat = (_a = (format || path.extname(file))) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
154
|
+
if (!lodash_1.default.includes(types_1.UploadFileType, detectedFormat)) {
|
|
155
|
+
throw new Error('uploadActivity - Invalid format: ' + format);
|
|
156
|
+
}
|
|
157
|
+
const fileBuffer = fs.createReadStream(file);
|
|
158
|
+
const form = new form_data_1.default();
|
|
159
|
+
form.append('userfile', fileBuffer);
|
|
160
|
+
const response = this.client.post(this.url.UPLOAD + '.' + format, form, {
|
|
161
|
+
headers: {
|
|
162
|
+
'Content-Type': form.getHeaders()['content-type']
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return response;
|
|
166
|
+
}
|
|
167
|
+
async deleteActivity(activity) {
|
|
168
|
+
if (!activity.activityId)
|
|
169
|
+
throw new Error('Missing activityId');
|
|
170
|
+
await this.client.post(this.url.ACTIVITY + activity.activityId, null, {
|
|
171
|
+
headers: {
|
|
172
|
+
'X-Http-Method-Override': 'DELETE'
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.default = GarminConnect;
|
|
178
|
+
//# sourceMappingURL=GarminConnect.js.map
|
|
@@ -0,0 +1 @@
|
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'./types';
|
|
2
|
+
export declare class UrlClass {
|
|
3
|
+
private domain;
|
|
4
|
+
GC_MODERN: string;
|
|
5
|
+
GARMIN_SSO_ORIGIN: string;
|
|
6
|
+
GC_API: string;
|
|
7
|
+
constructor(domain?: GarminDomain);
|
|
8
|
+
get GARMIN_SSO(): string;
|
|
9
|
+
get GARMIN_SSO_EMBED(): string;
|
|
10
|
+
get BASE_URL(): string;
|
|
11
|
+
get SIGNIN_URL(): string;
|
|
12
|
+
get LOGIN_URL(): string;
|
|
13
|
+
get OAUTH_URL(): string;
|
|
14
|
+
get USER_SETTINGS(): string;
|
|
15
|
+
get USER_PROFILE(): string;
|
|
16
|
+
get ACTIVITIES(): string;
|
|
17
|
+
get ACTIVITY(): string;
|
|
18
|
+
get STAT_ACTIVITIES(): string;
|
|
19
|
+
get DOWNLOAD_ZIP(): string;
|
|
20
|
+
get DOWNLOAD_GPX(): string;
|
|
21
|
+
get DOWNLOAD_TCX(): string;
|
|
22
|
+
get DOWNLOAD_KML(): string;
|
|
23
|
+
get UPLOAD(): string;
|
|
24
|
+
get IMPORT_DATA(): string;
|
|
25
|
+
}
|