@flow-js/garmin-connect 1.6.5 → 1.6.7
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 +705 -523
- package/dist/garmin/GarminConnect.d.ts +293 -4
- package/dist/garmin/GarminConnect.js +311 -56
- package/dist/garmin/GarminConnect.js.map +1 -1
- package/dist/garmin/UrlClass.d.ts +1 -0
- package/dist/garmin/UrlClass.js +3 -0
- package/dist/garmin/UrlClass.js.map +1 -1
- package/dist/garmin/types/calendar.d.ts +82 -158
- package/examples/example-workout.js +1 -1
- package/examples/example.js +1 -1
- package/package.json +1 -1
- package/dist/garmin/workouts/Running.d.ts +0 -16
- package/dist/garmin/workouts/Running.js +0 -64
- package/dist/garmin/workouts/Running.js.map +0 -1
- package/dist/garmin/workouts/templates/RunningTemplate.d.ts +0 -68
- package/dist/garmin/workouts/templates/RunningTemplate.js +0 -78
- package/dist/garmin/workouts/templates/RunningTemplate.js.map +0 -1
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -84,7 +73,6 @@ var HttpClient_1 = require("../common/HttpClient");
|
|
|
84
73
|
var utils_1 = require("../utils");
|
|
85
74
|
var UrlClass_1 = require("./UrlClass");
|
|
86
75
|
var types_1 = require("./types");
|
|
87
|
-
var Running_1 = __importDefault(require("./workouts/Running"));
|
|
88
76
|
var DateUtils_1 = require("./common/DateUtils");
|
|
89
77
|
var WeightUtils_1 = require("./common/WeightUtils");
|
|
90
78
|
var HydrationUtils_1 = require("./common/HydrationUtils");
|
|
@@ -114,6 +102,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
114
102
|
this._userHash = undefined;
|
|
115
103
|
this.listeners = {};
|
|
116
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Login to Garmin Connect with provided credentials or those set during construction
|
|
107
|
+
* @param username - Optional username to override the one in credentials
|
|
108
|
+
* @param password - Optional password to override the one in credentials
|
|
109
|
+
* @returns The GarminConnect instance for chaining
|
|
110
|
+
*/
|
|
117
111
|
GarminConnect.prototype.login = function (username, password) {
|
|
118
112
|
return __awaiter(this, void 0, void 0, function () {
|
|
119
113
|
return __generator(this, function (_a) {
|
|
@@ -131,6 +125,10 @@ var GarminConnect = /** @class */ (function () {
|
|
|
131
125
|
});
|
|
132
126
|
});
|
|
133
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* Exports OAuth tokens to files in the specified directory
|
|
130
|
+
* @param dirPath - Directory path where token files will be saved
|
|
131
|
+
*/
|
|
134
132
|
GarminConnect.prototype.exportTokenToFile = function (dirPath) {
|
|
135
133
|
if (!(0, utils_1.checkIsDirectory)(dirPath)) {
|
|
136
134
|
(0, utils_1.createDirectory)(dirPath);
|
|
@@ -143,6 +141,11 @@ var GarminConnect = /** @class */ (function () {
|
|
|
143
141
|
(0, utils_1.writeToFile)(path.join(dirPath, 'oauth2_token.json'), JSON.stringify(this.client.oauth2Token));
|
|
144
142
|
}
|
|
145
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* Loads OAuth tokens from files in the specified directory
|
|
146
|
+
* @param dirPath - Directory path where token files are stored
|
|
147
|
+
* @throws Error if directory not found
|
|
148
|
+
*/
|
|
146
149
|
GarminConnect.prototype.loadTokenByFile = function (dirPath) {
|
|
147
150
|
if (!(0, utils_1.checkIsDirectory)(dirPath)) {
|
|
148
151
|
throw new Error('loadTokenByFile: Directory not found: ' + dirPath);
|
|
@@ -154,6 +157,11 @@ var GarminConnect = /** @class */ (function () {
|
|
|
154
157
|
var oauth2 = JSON.parse(oauth2Data);
|
|
155
158
|
this.client.oauth2Token = oauth2;
|
|
156
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Exports OAuth tokens as an object
|
|
162
|
+
* @returns Object containing OAuth1 and OAuth2 tokens
|
|
163
|
+
* @throws Error if tokens are not found
|
|
164
|
+
*/
|
|
157
165
|
GarminConnect.prototype.exportToken = function () {
|
|
158
166
|
if (!this.client.oauth1Token || !this.client.oauth2Token) {
|
|
159
167
|
throw new Error('exportToken: Token not found');
|
|
@@ -163,11 +171,19 @@ var GarminConnect = /** @class */ (function () {
|
|
|
163
171
|
oauth2: this.client.oauth2Token
|
|
164
172
|
};
|
|
165
173
|
};
|
|
166
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Loads OAuth tokens from provided token objects (e.g., from DB or localStorage)
|
|
176
|
+
* @param oauth1 - OAuth1 token object
|
|
177
|
+
* @param oauth2 - OAuth2 token object
|
|
178
|
+
*/
|
|
167
179
|
GarminConnect.prototype.loadToken = function (oauth1, oauth2) {
|
|
168
180
|
this.client.oauth1Token = oauth1;
|
|
169
181
|
this.client.oauth2Token = oauth2;
|
|
170
182
|
};
|
|
183
|
+
/**
|
|
184
|
+
* Retrieves the user's settings from Garmin Connect
|
|
185
|
+
* @returns User settings data
|
|
186
|
+
*/
|
|
171
187
|
GarminConnect.prototype.getUserSettings = function () {
|
|
172
188
|
return __awaiter(this, void 0, void 0, function () {
|
|
173
189
|
return __generator(this, function (_a) {
|
|
@@ -175,6 +191,10 @@ var GarminConnect = /** @class */ (function () {
|
|
|
175
191
|
});
|
|
176
192
|
});
|
|
177
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* Retrieves the user's social profile from Garmin Connect
|
|
196
|
+
* @returns User's social profile data
|
|
197
|
+
*/
|
|
178
198
|
GarminConnect.prototype.getUserProfile = function () {
|
|
179
199
|
return __awaiter(this, void 0, void 0, function () {
|
|
180
200
|
return __generator(this, function (_a) {
|
|
@@ -182,6 +202,14 @@ var GarminConnect = /** @class */ (function () {
|
|
|
182
202
|
});
|
|
183
203
|
});
|
|
184
204
|
};
|
|
205
|
+
/**
|
|
206
|
+
* Retrieves a list of activities matching the specified criteria
|
|
207
|
+
* @param start - Optional starting index for pagination
|
|
208
|
+
* @param limit - Optional limit for pagination
|
|
209
|
+
* @param activityType - Optional activity type filter
|
|
210
|
+
* @param subActivityType - Optional activity subtype filter
|
|
211
|
+
* @returns Array of activities matching the criteria
|
|
212
|
+
*/
|
|
185
213
|
GarminConnect.prototype.getActivities = function (start, limit, activityType, subActivityType) {
|
|
186
214
|
return __awaiter(this, void 0, void 0, function () {
|
|
187
215
|
return __generator(this, function (_a) {
|
|
@@ -191,6 +219,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
191
219
|
});
|
|
192
220
|
});
|
|
193
221
|
};
|
|
222
|
+
/**
|
|
223
|
+
* Retrieves a specific activity by its ID
|
|
224
|
+
* @param activity - Object containing activityId
|
|
225
|
+
* @returns Details of the specified activity
|
|
226
|
+
* @throws Error if activityId is missing
|
|
227
|
+
*/
|
|
194
228
|
GarminConnect.prototype.getActivity = function (activity) {
|
|
195
229
|
return __awaiter(this, void 0, void 0, function () {
|
|
196
230
|
return __generator(this, function (_a) {
|
|
@@ -200,6 +234,10 @@ var GarminConnect = /** @class */ (function () {
|
|
|
200
234
|
});
|
|
201
235
|
});
|
|
202
236
|
};
|
|
237
|
+
/**
|
|
238
|
+
* Counts lifetime activities
|
|
239
|
+
* @returns Activity statistics including counts by type
|
|
240
|
+
*/
|
|
203
241
|
GarminConnect.prototype.countActivities = function () {
|
|
204
242
|
return __awaiter(this, void 0, void 0, function () {
|
|
205
243
|
return __generator(this, function (_a) {
|
|
@@ -214,6 +252,23 @@ var GarminConnect = /** @class */ (function () {
|
|
|
214
252
|
});
|
|
215
253
|
});
|
|
216
254
|
};
|
|
255
|
+
/**
|
|
256
|
+
* Download activity original data file
|
|
257
|
+
*
|
|
258
|
+
* Use the activityId to download the original activity data. Usually this is supplied as a .zip file.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```js
|
|
262
|
+
* const [activity] = await GCClient.getActivities(0, 1);
|
|
263
|
+
* // Directory path is optional and defaults to the current working directory.
|
|
264
|
+
* // Downloads filename will be supplied by Garmin.
|
|
265
|
+
* GCClient.downloadOriginalActivityData(activity, './some/path/that/exists');
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @param activity - with activityId
|
|
269
|
+
* @param dir - directory to save the file
|
|
270
|
+
* @param type - 'zip' | 'gpx' | 'tcx' | 'kml' (default: 'zip')
|
|
271
|
+
*/
|
|
217
272
|
GarminConnect.prototype.downloadOriginalActivityData = function (activity, dir, type) {
|
|
218
273
|
if (type === void 0) { type = 'zip'; }
|
|
219
274
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -259,6 +314,11 @@ var GarminConnect = /** @class */ (function () {
|
|
|
259
314
|
});
|
|
260
315
|
});
|
|
261
316
|
};
|
|
317
|
+
/**
|
|
318
|
+
* Uploads an activity file
|
|
319
|
+
* @param file
|
|
320
|
+
* @param format - 'fit' | 'gpx' | 'tcx'
|
|
321
|
+
*/
|
|
262
322
|
GarminConnect.prototype.uploadActivity = function (file, format) {
|
|
263
323
|
var _a;
|
|
264
324
|
if (format === void 0) { format = 'fit'; }
|
|
@@ -286,6 +346,18 @@ var GarminConnect = /** @class */ (function () {
|
|
|
286
346
|
});
|
|
287
347
|
});
|
|
288
348
|
};
|
|
349
|
+
/**
|
|
350
|
+
* Deletes an activity by activityId
|
|
351
|
+
* @param activity - with activityId
|
|
352
|
+
* @returns void
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```js
|
|
356
|
+
* const activities = await GCClient.getActivities(0, 1);
|
|
357
|
+
* const activity = activities[0];
|
|
358
|
+
* await GCClient.deleteActivity(activity);
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
289
361
|
GarminConnect.prototype.deleteActivity = function (activity) {
|
|
290
362
|
return __awaiter(this, void 0, void 0, function () {
|
|
291
363
|
return __generator(this, function (_a) {
|
|
@@ -301,6 +373,11 @@ var GarminConnect = /** @class */ (function () {
|
|
|
301
373
|
});
|
|
302
374
|
});
|
|
303
375
|
};
|
|
376
|
+
/**
|
|
377
|
+
* Gets the list of workouts
|
|
378
|
+
* @param start
|
|
379
|
+
* @param limit
|
|
380
|
+
*/
|
|
304
381
|
GarminConnect.prototype.getWorkouts = function (start, limit) {
|
|
305
382
|
return __awaiter(this, void 0, void 0, function () {
|
|
306
383
|
return __generator(this, function (_a) {
|
|
@@ -313,6 +390,11 @@ var GarminConnect = /** @class */ (function () {
|
|
|
313
390
|
});
|
|
314
391
|
});
|
|
315
392
|
};
|
|
393
|
+
/**
|
|
394
|
+
* Gets the workout detail by workoutId
|
|
395
|
+
* @param workout
|
|
396
|
+
* @returns workout detail - IWorkoutDetail
|
|
397
|
+
*/
|
|
316
398
|
GarminConnect.prototype.getWorkoutDetail = function (workout) {
|
|
317
399
|
return __awaiter(this, void 0, void 0, function () {
|
|
318
400
|
return __generator(this, function (_a) {
|
|
@@ -322,6 +404,33 @@ var GarminConnect = /** @class */ (function () {
|
|
|
322
404
|
});
|
|
323
405
|
});
|
|
324
406
|
};
|
|
407
|
+
/**
|
|
408
|
+
* Creates a new workout
|
|
409
|
+
*
|
|
410
|
+
* Use workoutBuilder to create the workout object. See the example in the examples/example-workout.js for more complex workouts.
|
|
411
|
+
*
|
|
412
|
+
* @param workout - workout detail
|
|
413
|
+
* @returns Response from the workout creation operation
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```js
|
|
417
|
+
* const wb = new WorkoutBuilder(
|
|
418
|
+
* WorkoutType.Running,
|
|
419
|
+
* 'Workout running ' + new Date().toISOString()
|
|
420
|
+
* );
|
|
421
|
+
*
|
|
422
|
+
* wb.addStep(
|
|
423
|
+
* new Step(
|
|
424
|
+
* StepType.Run,
|
|
425
|
+
* TimeDuration.fromSeconds(45),
|
|
426
|
+
* new NoTarget(),
|
|
427
|
+
* 'Comment for the step: Run for 45 seconds'
|
|
428
|
+
* )
|
|
429
|
+
* );
|
|
430
|
+
*
|
|
431
|
+
* GCClient.createWorkout(wb.build());
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
325
434
|
GarminConnect.prototype.createWorkout = function (workout) {
|
|
326
435
|
return __awaiter(this, void 0, void 0, function () {
|
|
327
436
|
return __generator(this, function (_a) {
|
|
@@ -329,48 +438,17 @@ var GarminConnect = /** @class */ (function () {
|
|
|
329
438
|
});
|
|
330
439
|
});
|
|
331
440
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
return [2 /*return*/, this.client.post(this.url.WORKOUT(), data)];
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
newWorkout = lodash_1.default.omit(workout, [
|
|
348
|
-
'workoutId',
|
|
349
|
-
'ownerId',
|
|
350
|
-
'updatedDate',
|
|
351
|
-
'createdDate',
|
|
352
|
-
'author'
|
|
353
|
-
]);
|
|
354
|
-
if (!newWorkout.description) {
|
|
355
|
-
newWorkout.description = 'Added by garmin-connect for Node.js';
|
|
356
|
-
}
|
|
357
|
-
// console.log('addWorkout - newWorkout:', newWorkout)
|
|
358
|
-
return [2 /*return*/, this.client.post(this.url.WORKOUT(), newWorkout)];
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
};
|
|
362
|
-
GarminConnect.prototype.addRunningWorkout = function (name, meters, description) {
|
|
363
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
364
|
-
var running;
|
|
365
|
-
return __generator(this, function (_a) {
|
|
366
|
-
running = new Running_1.default();
|
|
367
|
-
running.name = name;
|
|
368
|
-
running.distance = meters;
|
|
369
|
-
running.description = description;
|
|
370
|
-
return [2 /*return*/, this.addWorkout(running)];
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
};
|
|
441
|
+
/**
|
|
442
|
+
* Deletes a workout by workoutId
|
|
443
|
+
* @param workout - with workoutId
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```js
|
|
447
|
+
* const workouts = await GCClient.getWorkouts();
|
|
448
|
+
* const id = workouts[0].workoutId;
|
|
449
|
+
* GCClient.deleteWorkout({ workoutId: id });
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
374
452
|
GarminConnect.prototype.deleteWorkout = function (workout) {
|
|
375
453
|
return __awaiter(this, void 0, void 0, function () {
|
|
376
454
|
return __generator(this, function (_a) {
|
|
@@ -382,8 +460,18 @@ var GarminConnect = /** @class */ (function () {
|
|
|
382
460
|
};
|
|
383
461
|
/**
|
|
384
462
|
* Schedule a workout by workoutId to a specific date
|
|
463
|
+
*
|
|
464
|
+
* To add a workout to your calendar, provide the workout id and the date to schedule it on.
|
|
465
|
+
*
|
|
385
466
|
* @param workout - with workoutId
|
|
386
|
-
* @param scheduleDate - 'YYYY-MM-DD'
|
|
467
|
+
* @param scheduleDate - 'YYYY-MM-DD' format date string
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```js
|
|
471
|
+
* const workouts = await GCClient.getWorkouts();
|
|
472
|
+
* const id = workouts[0].workoutId;
|
|
473
|
+
* GCClient.scheduleWorkout({ workoutId: id }, new Date('2025-12-01'));
|
|
474
|
+
* ```
|
|
387
475
|
*/
|
|
388
476
|
GarminConnect.prototype.scheduleWorkout = function (workout, scheduleDate) {
|
|
389
477
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -392,6 +480,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
392
480
|
});
|
|
393
481
|
});
|
|
394
482
|
};
|
|
483
|
+
/**
|
|
484
|
+
* Retrieves step count for a specific date
|
|
485
|
+
* @param date - The date to get step count for, defaults to current date
|
|
486
|
+
* @returns Total step count for the specified date
|
|
487
|
+
* @throws Error if steps data not found for the date
|
|
488
|
+
*/
|
|
395
489
|
GarminConnect.prototype.getSteps = function (date) {
|
|
396
490
|
if (date === void 0) { date = new Date(); }
|
|
397
491
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -415,6 +509,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
415
509
|
});
|
|
416
510
|
});
|
|
417
511
|
};
|
|
512
|
+
/**
|
|
513
|
+
* Retrieves sleep data for a specific date
|
|
514
|
+
* @param date - The date to get sleep data for, defaults to current date
|
|
515
|
+
* @returns Sleep data for the specified date
|
|
516
|
+
* @throws Error if sleep data is invalid or empty
|
|
517
|
+
*/
|
|
418
518
|
GarminConnect.prototype.getSleepData = function (date) {
|
|
419
519
|
if (date === void 0) { date = new Date(); }
|
|
420
520
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -439,6 +539,21 @@ var GarminConnect = /** @class */ (function () {
|
|
|
439
539
|
});
|
|
440
540
|
});
|
|
441
541
|
};
|
|
542
|
+
/**
|
|
543
|
+
* Calculates sleep duration for a specific date
|
|
544
|
+
*
|
|
545
|
+
* Retrieves hours and minutes slept for a given date.
|
|
546
|
+
*
|
|
547
|
+
* @param date - The date to get sleep duration for, defaults to current date
|
|
548
|
+
* @returns Object with hours and minutes of sleep
|
|
549
|
+
* @throws Error if sleep data is missing or invalid
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```js
|
|
553
|
+
* const detailedSleep = await GCClient.getSleepDuration(new Date('2020-03-24'));
|
|
554
|
+
* console.log(`Hours: ${detailedSleep.hours}, Minutes: ${detailedSleep.minutes}`);
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
442
557
|
GarminConnect.prototype.getSleepDuration = function (date) {
|
|
443
558
|
if (date === void 0) { date = new Date(); }
|
|
444
559
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -471,6 +586,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
471
586
|
});
|
|
472
587
|
});
|
|
473
588
|
};
|
|
589
|
+
/**
|
|
590
|
+
* Retrieves weight data for a specific date
|
|
591
|
+
* @param date - The date to get weight data for, defaults to current date
|
|
592
|
+
* @returns Weight data for the specified date
|
|
593
|
+
* @throws Error if weight data is invalid or empty
|
|
594
|
+
*/
|
|
474
595
|
GarminConnect.prototype.getDailyWeightData = function (date) {
|
|
475
596
|
if (date === void 0) { date = new Date(); }
|
|
476
597
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -495,6 +616,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
495
616
|
});
|
|
496
617
|
});
|
|
497
618
|
};
|
|
619
|
+
/**
|
|
620
|
+
* Retrieves weight data in pounds for a specific date
|
|
621
|
+
* @param date - The date to get weight data for, defaults to current date
|
|
622
|
+
* @returns Weight in pounds for the specified date
|
|
623
|
+
* @throws Error if valid weight data not found for the date
|
|
624
|
+
*/
|
|
498
625
|
GarminConnect.prototype.getDailyWeightInPounds = function (date) {
|
|
499
626
|
if (date === void 0) { date = new Date(); }
|
|
500
627
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -516,6 +643,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
516
643
|
});
|
|
517
644
|
});
|
|
518
645
|
};
|
|
646
|
+
/**
|
|
647
|
+
* Retrieves hydration data in fluid ounces for a specific date
|
|
648
|
+
* @param date - The date to get hydration data for, defaults to current date
|
|
649
|
+
* @returns Hydration value in fluid ounces for the specified date
|
|
650
|
+
* @throws Error if hydration data is invalid or empty
|
|
651
|
+
*/
|
|
519
652
|
GarminConnect.prototype.getDailyHydration = function (date) {
|
|
520
653
|
if (date === void 0) { date = new Date(); }
|
|
521
654
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -540,6 +673,14 @@ var GarminConnect = /** @class */ (function () {
|
|
|
540
673
|
});
|
|
541
674
|
});
|
|
542
675
|
};
|
|
676
|
+
/**
|
|
677
|
+
* Updates weight data for a specific date
|
|
678
|
+
* @param date - The date for the weight data, defaults to current date
|
|
679
|
+
* @param lbs - Weight value in pounds
|
|
680
|
+
* @param timezone - Timezone string for correct timestamp conversion
|
|
681
|
+
* @returns Response from the weight update operation
|
|
682
|
+
* @throws Error if update fails
|
|
683
|
+
*/
|
|
543
684
|
GarminConnect.prototype.updateWeight = function (date, lbs, timezone) {
|
|
544
685
|
if (date === void 0) { date = new Date(); }
|
|
545
686
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -565,6 +706,13 @@ var GarminConnect = /** @class */ (function () {
|
|
|
565
706
|
});
|
|
566
707
|
});
|
|
567
708
|
};
|
|
709
|
+
/**
|
|
710
|
+
* Updates hydration log with fluid ounces for a specific date
|
|
711
|
+
* @param date - The date for the hydration data, defaults to current date
|
|
712
|
+
* @param valueInOz - Hydration value in fluid ounces
|
|
713
|
+
* @returns Response from the hydration update operation
|
|
714
|
+
* @throws Error if update fails
|
|
715
|
+
*/
|
|
568
716
|
GarminConnect.prototype.updateHydrationLogOunces = function (date, valueInOz) {
|
|
569
717
|
if (date === void 0) { date = new Date(); }
|
|
570
718
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -596,6 +744,11 @@ var GarminConnect = /** @class */ (function () {
|
|
|
596
744
|
});
|
|
597
745
|
});
|
|
598
746
|
};
|
|
747
|
+
/**
|
|
748
|
+
* Retrieves golf summary data
|
|
749
|
+
* @returns Summary of golf activities
|
|
750
|
+
* @throws Error if golf summary data is invalid or empty
|
|
751
|
+
*/
|
|
599
752
|
GarminConnect.prototype.getGolfSummary = function () {
|
|
600
753
|
return __awaiter(this, void 0, void 0, function () {
|
|
601
754
|
var golfSummary, error_7;
|
|
@@ -618,6 +771,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
618
771
|
});
|
|
619
772
|
});
|
|
620
773
|
};
|
|
774
|
+
/**
|
|
775
|
+
* Retrieves golf scorecard for a specific round
|
|
776
|
+
* @param scorecardId - ID of the scorecard to retrieve
|
|
777
|
+
* @returns Golf scorecard data
|
|
778
|
+
* @throws Error if golf scorecard data is invalid or empty
|
|
779
|
+
*/
|
|
621
780
|
GarminConnect.prototype.getGolfScorecard = function (scorecardId) {
|
|
622
781
|
return __awaiter(this, void 0, void 0, function () {
|
|
623
782
|
var golfScorecard, error_8;
|
|
@@ -640,6 +799,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
640
799
|
});
|
|
641
800
|
});
|
|
642
801
|
};
|
|
802
|
+
/**
|
|
803
|
+
* Retrieves heart rate data for a specific date
|
|
804
|
+
* @param date - The date to get heart rate data for, defaults to current date
|
|
805
|
+
* @returns Heart rate data for the specified date
|
|
806
|
+
* @throws Error if the operation fails
|
|
807
|
+
*/
|
|
643
808
|
GarminConnect.prototype.getHeartRate = function (date) {
|
|
644
809
|
if (date === void 0) { date = new Date(); }
|
|
645
810
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -715,6 +880,10 @@ var GarminConnect = /** @class */ (function () {
|
|
|
715
880
|
});
|
|
716
881
|
});
|
|
717
882
|
};
|
|
883
|
+
/**
|
|
884
|
+
* Retrieves all workouts
|
|
885
|
+
* @returns List of workouts
|
|
886
|
+
*/
|
|
718
887
|
GarminConnect.prototype.workouts = function () {
|
|
719
888
|
return __awaiter(this, void 0, void 0, function () {
|
|
720
889
|
return __generator(this, function (_a) {
|
|
@@ -722,6 +891,14 @@ var GarminConnect = /** @class */ (function () {
|
|
|
722
891
|
});
|
|
723
892
|
});
|
|
724
893
|
};
|
|
894
|
+
/**
|
|
895
|
+
* Imports GPX file content
|
|
896
|
+
*
|
|
897
|
+
* @example ./examples/example-gpx-file.js
|
|
898
|
+
* @param fileName - Name of the GPX file
|
|
899
|
+
* @param fileContent - Content of the GPX file as string
|
|
900
|
+
* @returns Response from the GPX import operation
|
|
901
|
+
*/
|
|
725
902
|
GarminConnect.prototype.importGpx = function (fileName, fileContent) {
|
|
726
903
|
return __awaiter(this, void 0, void 0, function () {
|
|
727
904
|
var form;
|
|
@@ -744,6 +921,17 @@ var GarminConnect = /** @class */ (function () {
|
|
|
744
921
|
});
|
|
745
922
|
});
|
|
746
923
|
};
|
|
924
|
+
/**
|
|
925
|
+
* Creates a course from GPX data
|
|
926
|
+
* You can get geoPoints and coursePoints from the imported GPX file response.
|
|
927
|
+
*
|
|
928
|
+
* @example ./examples/example-gpx-file.js
|
|
929
|
+
* @param activityType - Type of activity for the course
|
|
930
|
+
* @param courseName - Name of the course
|
|
931
|
+
* @param geoPoints - Array of geographical points making up the course
|
|
932
|
+
* @param coursePoints - Optional array of course points (waypoints)
|
|
933
|
+
* @returns Response from the course creation operation
|
|
934
|
+
*/
|
|
747
935
|
GarminConnect.prototype.createCourse = function (activityType, courseName, geoPoints, coursePoints) {
|
|
748
936
|
if (coursePoints === void 0) { coursePoints = []; }
|
|
749
937
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -755,6 +943,10 @@ var GarminConnect = /** @class */ (function () {
|
|
|
755
943
|
});
|
|
756
944
|
});
|
|
757
945
|
};
|
|
946
|
+
/**
|
|
947
|
+
* Lists all courses
|
|
948
|
+
* @returns List of courses
|
|
949
|
+
*/
|
|
758
950
|
GarminConnect.prototype.listCourses = function () {
|
|
759
951
|
return __awaiter(this, void 0, void 0, function () {
|
|
760
952
|
return __generator(this, function (_a) {
|
|
@@ -762,6 +954,11 @@ var GarminConnect = /** @class */ (function () {
|
|
|
762
954
|
});
|
|
763
955
|
});
|
|
764
956
|
};
|
|
957
|
+
/**
|
|
958
|
+
* Exports a course as GPX file content
|
|
959
|
+
* @param courseId - ID of the course to export
|
|
960
|
+
* @returns GPX file content as string
|
|
961
|
+
*/
|
|
765
962
|
GarminConnect.prototype.exportCourseAsGpx = function (courseId) {
|
|
766
963
|
return __awaiter(this, void 0, void 0, function () {
|
|
767
964
|
return __generator(this, function (_a) {
|
|
@@ -771,6 +968,10 @@ var GarminConnect = /** @class */ (function () {
|
|
|
771
968
|
});
|
|
772
969
|
});
|
|
773
970
|
};
|
|
971
|
+
/**
|
|
972
|
+
* Retrieves calendar events for a specific year.
|
|
973
|
+
* @param year {number} - The year for which to retrieve calendar events.
|
|
974
|
+
*/
|
|
774
975
|
GarminConnect.prototype.getYearCalendarEvents = function (year) {
|
|
775
976
|
return __awaiter(this, void 0, void 0, function () {
|
|
776
977
|
return __generator(this, function (_a) {
|
|
@@ -778,6 +979,11 @@ var GarminConnect = /** @class */ (function () {
|
|
|
778
979
|
});
|
|
779
980
|
});
|
|
780
981
|
};
|
|
982
|
+
/**
|
|
983
|
+
* Retrieves calendar events for a specific month and year.
|
|
984
|
+
* @param year {number} - The year for which to retrieve calendar events.
|
|
985
|
+
* @param month {number} - The month (0-11) for which to retrieve calendar events.
|
|
986
|
+
*/
|
|
781
987
|
GarminConnect.prototype.getMonthCalendarEvents = function (year, month) {
|
|
782
988
|
return __awaiter(this, void 0, void 0, function () {
|
|
783
989
|
return __generator(this, function (_a) {
|
|
@@ -785,6 +991,13 @@ var GarminConnect = /** @class */ (function () {
|
|
|
785
991
|
});
|
|
786
992
|
});
|
|
787
993
|
};
|
|
994
|
+
/**
|
|
995
|
+
* Retrieves calendar events for a specific week containing the given date.
|
|
996
|
+
* @param year {number} - The year of the date.
|
|
997
|
+
* @param month {number} - The month (0-11) of the date.
|
|
998
|
+
* @param day {number} - The day of the first day of the week.
|
|
999
|
+
* @param firstDayOfWeek {number} - Optional first day of the week, default is 1
|
|
1000
|
+
*/
|
|
788
1001
|
GarminConnect.prototype.getWeekCalendarEvents = function (year, month, day, firstDayOfWeek) {
|
|
789
1002
|
return __awaiter(this, void 0, void 0, function () {
|
|
790
1003
|
return __generator(this, function (_a) {
|
|
@@ -792,6 +1005,36 @@ var GarminConnect = /** @class */ (function () {
|
|
|
792
1005
|
});
|
|
793
1006
|
});
|
|
794
1007
|
};
|
|
1008
|
+
/**
|
|
1009
|
+
* Renames an activity with the given activityId to the newName.
|
|
1010
|
+
* @param activityId
|
|
1011
|
+
* @param newName
|
|
1012
|
+
*/
|
|
1013
|
+
GarminConnect.prototype.renameActivity = function (activityId, newName) {
|
|
1014
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1015
|
+
return __generator(this, function (_a) {
|
|
1016
|
+
switch (_a.label) {
|
|
1017
|
+
case 0:
|
|
1018
|
+
if (!activityId)
|
|
1019
|
+
throw new Error('Missing activityId');
|
|
1020
|
+
if (!newName)
|
|
1021
|
+
throw new Error('Missing newName');
|
|
1022
|
+
return [4 /*yield*/, this.client.put(this.url.ACTIVITY_BY_ID(activityId), {
|
|
1023
|
+
activityName: newName
|
|
1024
|
+
})];
|
|
1025
|
+
case 1:
|
|
1026
|
+
_a.sent();
|
|
1027
|
+
return [2 /*return*/];
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
});
|
|
1031
|
+
};
|
|
1032
|
+
/**
|
|
1033
|
+
* Performs a GET request to the specified URL
|
|
1034
|
+
* @param url - URL to send the request to
|
|
1035
|
+
* @param data - Optional query parameters or request configuration
|
|
1036
|
+
* @returns Response data of type T
|
|
1037
|
+
*/
|
|
795
1038
|
GarminConnect.prototype.get = function (url, data) {
|
|
796
1039
|
return __awaiter(this, void 0, void 0, function () {
|
|
797
1040
|
var response;
|
|
@@ -805,6 +1048,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
805
1048
|
});
|
|
806
1049
|
});
|
|
807
1050
|
};
|
|
1051
|
+
/**
|
|
1052
|
+
* Performs a POST request to the specified URL
|
|
1053
|
+
* @param url - URL to send the request to
|
|
1054
|
+
* @param data - Data to send in the request body
|
|
1055
|
+
* @returns Response data of type T
|
|
1056
|
+
*/
|
|
808
1057
|
GarminConnect.prototype.post = function (url, data) {
|
|
809
1058
|
return __awaiter(this, void 0, void 0, function () {
|
|
810
1059
|
var response;
|
|
@@ -818,6 +1067,12 @@ var GarminConnect = /** @class */ (function () {
|
|
|
818
1067
|
});
|
|
819
1068
|
});
|
|
820
1069
|
};
|
|
1070
|
+
/**
|
|
1071
|
+
* Performs a PUT request to the specified URL
|
|
1072
|
+
* @param url - URL to send the request to
|
|
1073
|
+
* @param data - Data to send in the request body
|
|
1074
|
+
* @returns Response data of type T
|
|
1075
|
+
*/
|
|
821
1076
|
GarminConnect.prototype.put = function (url, data) {
|
|
822
1077
|
return __awaiter(this, void 0, void 0, function () {
|
|
823
1078
|
var response;
|