@flow-js/garmin-connect 1.6.6 → 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 +271 -4
- package/dist/garmin/GarminConnect.js +271 -56
- package/dist/garmin/GarminConnect.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,6 +1,5 @@
|
|
|
1
1
|
import { HttpClient } from '../common/HttpClient';
|
|
2
2
|
import { ExportFileTypeValue, GarminDomain, GCGearId, ICountActivities, IGarminTokens, IOauth1Token, IOauth2Token, ISocialProfile, IUserSettings, IWorkout, IWorkoutDetail, ListCoursesResponse, UploadFileTypeTypeValue } from './types';
|
|
3
|
-
import Running from './workouts/Running';
|
|
4
3
|
import { SleepData } from './types/sleep';
|
|
5
4
|
import { ActivitySubType, ActivityType, GCActivityId, IActivity } from './types/activity';
|
|
6
5
|
import { GearData } from './types/gear';
|
|
@@ -27,56 +26,274 @@ export default class GarminConnect {
|
|
|
27
26
|
private listeners;
|
|
28
27
|
private url;
|
|
29
28
|
constructor(credentials?: GCCredentials | undefined, domain?: GarminDomain);
|
|
29
|
+
/**
|
|
30
|
+
* Login to Garmin Connect with provided credentials or those set during construction
|
|
31
|
+
* @param username - Optional username to override the one in credentials
|
|
32
|
+
* @param password - Optional password to override the one in credentials
|
|
33
|
+
* @returns The GarminConnect instance for chaining
|
|
34
|
+
*/
|
|
30
35
|
login(username?: string, password?: string): Promise<GarminConnect>;
|
|
36
|
+
/**
|
|
37
|
+
* Exports OAuth tokens to files in the specified directory
|
|
38
|
+
* @param dirPath - Directory path where token files will be saved
|
|
39
|
+
*/
|
|
31
40
|
exportTokenToFile(dirPath: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Loads OAuth tokens from files in the specified directory
|
|
43
|
+
* @param dirPath - Directory path where token files are stored
|
|
44
|
+
* @throws Error if directory not found
|
|
45
|
+
*/
|
|
32
46
|
loadTokenByFile(dirPath: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Exports OAuth tokens as an object
|
|
49
|
+
* @returns Object containing OAuth1 and OAuth2 tokens
|
|
50
|
+
* @throws Error if tokens are not found
|
|
51
|
+
*/
|
|
33
52
|
exportToken(): IGarminTokens;
|
|
53
|
+
/**
|
|
54
|
+
* Loads OAuth tokens from provided token objects (e.g., from DB or localStorage)
|
|
55
|
+
* @param oauth1 - OAuth1 token object
|
|
56
|
+
* @param oauth2 - OAuth2 token object
|
|
57
|
+
*/
|
|
34
58
|
loadToken(oauth1: IOauth1Token, oauth2: IOauth2Token): void;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the user's settings from Garmin Connect
|
|
61
|
+
* @returns User settings data
|
|
62
|
+
*/
|
|
35
63
|
getUserSettings(): Promise<IUserSettings>;
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves the user's social profile from Garmin Connect
|
|
66
|
+
* @returns User's social profile data
|
|
67
|
+
*/
|
|
36
68
|
getUserProfile(): Promise<ISocialProfile>;
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves a list of activities matching the specified criteria
|
|
71
|
+
* @param start - Optional starting index for pagination
|
|
72
|
+
* @param limit - Optional limit for pagination
|
|
73
|
+
* @param activityType - Optional activity type filter
|
|
74
|
+
* @param subActivityType - Optional activity subtype filter
|
|
75
|
+
* @returns Array of activities matching the criteria
|
|
76
|
+
*/
|
|
37
77
|
getActivities(start?: number, limit?: number, activityType?: ActivityType, subActivityType?: ActivitySubType): Promise<IActivity[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves a specific activity by its ID
|
|
80
|
+
* @param activity - Object containing activityId
|
|
81
|
+
* @returns Details of the specified activity
|
|
82
|
+
* @throws Error if activityId is missing
|
|
83
|
+
*/
|
|
38
84
|
getActivity(activity: {
|
|
39
85
|
activityId: GCActivityId;
|
|
40
86
|
}): Promise<IActivity>;
|
|
87
|
+
/**
|
|
88
|
+
* Counts lifetime activities
|
|
89
|
+
* @returns Activity statistics including counts by type
|
|
90
|
+
*/
|
|
41
91
|
countActivities(): Promise<ICountActivities>;
|
|
92
|
+
/**
|
|
93
|
+
* Download activity original data file
|
|
94
|
+
*
|
|
95
|
+
* Use the activityId to download the original activity data. Usually this is supplied as a .zip file.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```js
|
|
99
|
+
* const [activity] = await GCClient.getActivities(0, 1);
|
|
100
|
+
* // Directory path is optional and defaults to the current working directory.
|
|
101
|
+
* // Downloads filename will be supplied by Garmin.
|
|
102
|
+
* GCClient.downloadOriginalActivityData(activity, './some/path/that/exists');
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @param activity - with activityId
|
|
106
|
+
* @param dir - directory to save the file
|
|
107
|
+
* @param type - 'zip' | 'gpx' | 'tcx' | 'kml' (default: 'zip')
|
|
108
|
+
*/
|
|
42
109
|
downloadOriginalActivityData(activity: {
|
|
43
110
|
activityId: GCActivityId;
|
|
44
111
|
}, dir: string, type?: ExportFileTypeValue): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Uploads an activity file
|
|
114
|
+
* @param file
|
|
115
|
+
* @param format - 'fit' | 'gpx' | 'tcx'
|
|
116
|
+
*/
|
|
45
117
|
uploadActivity(file: string, format?: UploadFileTypeTypeValue): Promise<unknown>;
|
|
118
|
+
/**
|
|
119
|
+
* Deletes an activity by activityId
|
|
120
|
+
* @param activity - with activityId
|
|
121
|
+
* @returns void
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```js
|
|
125
|
+
* const activities = await GCClient.getActivities(0, 1);
|
|
126
|
+
* const activity = activities[0];
|
|
127
|
+
* await GCClient.deleteActivity(activity);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
46
130
|
deleteActivity(activity: {
|
|
47
131
|
activityId: GCActivityId;
|
|
48
132
|
}): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Gets the list of workouts
|
|
135
|
+
* @param start
|
|
136
|
+
* @param limit
|
|
137
|
+
*/
|
|
49
138
|
getWorkouts(start: number, limit: number): Promise<IWorkout[]>;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the workout detail by workoutId
|
|
141
|
+
* @param workout
|
|
142
|
+
* @returns workout detail - IWorkoutDetail
|
|
143
|
+
*/
|
|
50
144
|
getWorkoutDetail(workout: {
|
|
51
145
|
workoutId: string;
|
|
52
146
|
}): Promise<IWorkoutDetail>;
|
|
147
|
+
/**
|
|
148
|
+
* Creates a new workout
|
|
149
|
+
*
|
|
150
|
+
* Use workoutBuilder to create the workout object. See the example in the examples/example-workout.js for more complex workouts.
|
|
151
|
+
*
|
|
152
|
+
* @param workout - workout detail
|
|
153
|
+
* @returns Response from the workout creation operation
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```js
|
|
157
|
+
* const wb = new WorkoutBuilder(
|
|
158
|
+
* WorkoutType.Running,
|
|
159
|
+
* 'Workout running ' + new Date().toISOString()
|
|
160
|
+
* );
|
|
161
|
+
*
|
|
162
|
+
* wb.addStep(
|
|
163
|
+
* new Step(
|
|
164
|
+
* StepType.Run,
|
|
165
|
+
* TimeDuration.fromSeconds(45),
|
|
166
|
+
* new NoTarget(),
|
|
167
|
+
* 'Comment for the step: Run for 45 seconds'
|
|
168
|
+
* )
|
|
169
|
+
* );
|
|
170
|
+
*
|
|
171
|
+
* GCClient.createWorkout(wb.build());
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
53
174
|
createWorkout(workout: IWorkoutDetail): Promise<Workout>;
|
|
54
|
-
|
|
55
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Deletes a workout by workoutId
|
|
177
|
+
* @param workout - with workoutId
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```js
|
|
181
|
+
* const workouts = await GCClient.getWorkouts();
|
|
182
|
+
* const id = workouts[0].workoutId;
|
|
183
|
+
* GCClient.deleteWorkout({ workoutId: id });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
56
186
|
deleteWorkout(workout: {
|
|
57
187
|
workoutId: string;
|
|
58
188
|
}): Promise<unknown>;
|
|
59
189
|
/**
|
|
60
190
|
* Schedule a workout by workoutId to a specific date
|
|
191
|
+
*
|
|
192
|
+
* To add a workout to your calendar, provide the workout id and the date to schedule it on.
|
|
193
|
+
*
|
|
61
194
|
* @param workout - with workoutId
|
|
62
|
-
* @param scheduleDate - 'YYYY-MM-DD'
|
|
195
|
+
* @param scheduleDate - 'YYYY-MM-DD' format date string
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```js
|
|
199
|
+
* const workouts = await GCClient.getWorkouts();
|
|
200
|
+
* const id = workouts[0].workoutId;
|
|
201
|
+
* GCClient.scheduleWorkout({ workoutId: id }, new Date('2025-12-01'));
|
|
202
|
+
* ```
|
|
63
203
|
*/
|
|
64
204
|
scheduleWorkout(workout: {
|
|
65
205
|
workoutId: string;
|
|
66
206
|
}, scheduleDate: string): Promise<unknown>;
|
|
207
|
+
/**
|
|
208
|
+
* Retrieves step count for a specific date
|
|
209
|
+
* @param date - The date to get step count for, defaults to current date
|
|
210
|
+
* @returns Total step count for the specified date
|
|
211
|
+
* @throws Error if steps data not found for the date
|
|
212
|
+
*/
|
|
67
213
|
getSteps(date?: Date): Promise<number>;
|
|
214
|
+
/**
|
|
215
|
+
* Retrieves sleep data for a specific date
|
|
216
|
+
* @param date - The date to get sleep data for, defaults to current date
|
|
217
|
+
* @returns Sleep data for the specified date
|
|
218
|
+
* @throws Error if sleep data is invalid or empty
|
|
219
|
+
*/
|
|
68
220
|
getSleepData(date?: Date): Promise<SleepData>;
|
|
221
|
+
/**
|
|
222
|
+
* Calculates sleep duration for a specific date
|
|
223
|
+
*
|
|
224
|
+
* Retrieves hours and minutes slept for a given date.
|
|
225
|
+
*
|
|
226
|
+
* @param date - The date to get sleep duration for, defaults to current date
|
|
227
|
+
* @returns Object with hours and minutes of sleep
|
|
228
|
+
* @throws Error if sleep data is missing or invalid
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```js
|
|
232
|
+
* const detailedSleep = await GCClient.getSleepDuration(new Date('2020-03-24'));
|
|
233
|
+
* console.log(`Hours: ${detailedSleep.hours}, Minutes: ${detailedSleep.minutes}`);
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
69
236
|
getSleepDuration(date?: Date): Promise<{
|
|
70
237
|
hours: number;
|
|
71
238
|
minutes: number;
|
|
72
239
|
}>;
|
|
240
|
+
/**
|
|
241
|
+
* Retrieves weight data for a specific date
|
|
242
|
+
* @param date - The date to get weight data for, defaults to current date
|
|
243
|
+
* @returns Weight data for the specified date
|
|
244
|
+
* @throws Error if weight data is invalid or empty
|
|
245
|
+
*/
|
|
73
246
|
getDailyWeightData(date?: Date): Promise<WeightData>;
|
|
247
|
+
/**
|
|
248
|
+
* Retrieves weight data in pounds for a specific date
|
|
249
|
+
* @param date - The date to get weight data for, defaults to current date
|
|
250
|
+
* @returns Weight in pounds for the specified date
|
|
251
|
+
* @throws Error if valid weight data not found for the date
|
|
252
|
+
*/
|
|
74
253
|
getDailyWeightInPounds(date?: Date): Promise<number>;
|
|
254
|
+
/**
|
|
255
|
+
* Retrieves hydration data in fluid ounces for a specific date
|
|
256
|
+
* @param date - The date to get hydration data for, defaults to current date
|
|
257
|
+
* @returns Hydration value in fluid ounces for the specified date
|
|
258
|
+
* @throws Error if hydration data is invalid or empty
|
|
259
|
+
*/
|
|
75
260
|
getDailyHydration(date?: Date): Promise<number>;
|
|
261
|
+
/**
|
|
262
|
+
* Updates weight data for a specific date
|
|
263
|
+
* @param date - The date for the weight data, defaults to current date
|
|
264
|
+
* @param lbs - Weight value in pounds
|
|
265
|
+
* @param timezone - Timezone string for correct timestamp conversion
|
|
266
|
+
* @returns Response from the weight update operation
|
|
267
|
+
* @throws Error if update fails
|
|
268
|
+
*/
|
|
76
269
|
updateWeight(date: Date | undefined, lbs: number, timezone: string): Promise<UpdateWeight>;
|
|
270
|
+
/**
|
|
271
|
+
* Updates hydration log with fluid ounces for a specific date
|
|
272
|
+
* @param date - The date for the hydration data, defaults to current date
|
|
273
|
+
* @param valueInOz - Hydration value in fluid ounces
|
|
274
|
+
* @returns Response from the hydration update operation
|
|
275
|
+
* @throws Error if update fails
|
|
276
|
+
*/
|
|
77
277
|
updateHydrationLogOunces(date: Date | undefined, valueInOz: number): Promise<WaterIntake>;
|
|
278
|
+
/**
|
|
279
|
+
* Retrieves golf summary data
|
|
280
|
+
* @returns Summary of golf activities
|
|
281
|
+
* @throws Error if golf summary data is invalid or empty
|
|
282
|
+
*/
|
|
78
283
|
getGolfSummary(): Promise<GolfSummary>;
|
|
284
|
+
/**
|
|
285
|
+
* Retrieves golf scorecard for a specific round
|
|
286
|
+
* @param scorecardId - ID of the scorecard to retrieve
|
|
287
|
+
* @returns Golf scorecard data
|
|
288
|
+
* @throws Error if golf scorecard data is invalid or empty
|
|
289
|
+
*/
|
|
79
290
|
getGolfScorecard(scorecardId: number): Promise<GolfScorecard>;
|
|
291
|
+
/**
|
|
292
|
+
* Retrieves heart rate data for a specific date
|
|
293
|
+
* @param date - The date to get heart rate data for, defaults to current date
|
|
294
|
+
* @returns Heart rate data for the specified date
|
|
295
|
+
* @throws Error if the operation fails
|
|
296
|
+
*/
|
|
80
297
|
getHeartRate(date?: Date): Promise<HeartRate>;
|
|
81
298
|
/**
|
|
82
299
|
* Returns the gear data for the user.
|
|
@@ -102,10 +319,42 @@ export default class GarminConnect {
|
|
|
102
319
|
* @return GearData - the unlinked gear item data
|
|
103
320
|
*/
|
|
104
321
|
unlinkGearFromActivity(activityId: GCActivityId, gearId: GCGearId): Promise<GearData>;
|
|
322
|
+
/**
|
|
323
|
+
* Retrieves all workouts
|
|
324
|
+
* @returns List of workouts
|
|
325
|
+
*/
|
|
105
326
|
workouts(): Promise<Workout[]>;
|
|
327
|
+
/**
|
|
328
|
+
* Imports GPX file content
|
|
329
|
+
*
|
|
330
|
+
* @example ./examples/example-gpx-file.js
|
|
331
|
+
* @param fileName - Name of the GPX file
|
|
332
|
+
* @param fileContent - Content of the GPX file as string
|
|
333
|
+
* @returns Response from the GPX import operation
|
|
334
|
+
*/
|
|
106
335
|
importGpx(fileName: string, fileContent: string): Promise<ImportedGpxResponse>;
|
|
336
|
+
/**
|
|
337
|
+
* Creates a course from GPX data
|
|
338
|
+
* You can get geoPoints and coursePoints from the imported GPX file response.
|
|
339
|
+
*
|
|
340
|
+
* @example ./examples/example-gpx-file.js
|
|
341
|
+
* @param activityType - Type of activity for the course
|
|
342
|
+
* @param courseName - Name of the course
|
|
343
|
+
* @param geoPoints - Array of geographical points making up the course
|
|
344
|
+
* @param coursePoints - Optional array of course points (waypoints)
|
|
345
|
+
* @returns Response from the course creation operation
|
|
346
|
+
*/
|
|
107
347
|
createCourse(activityType: GpxActivityType, courseName: string, geoPoints: GeoPoint[], coursePoints?: CoursePoint[]): Promise<unknown>;
|
|
348
|
+
/**
|
|
349
|
+
* Lists all courses
|
|
350
|
+
* @returns List of courses
|
|
351
|
+
*/
|
|
108
352
|
listCourses(): Promise<ListCoursesResponse>;
|
|
353
|
+
/**
|
|
354
|
+
* Exports a course as GPX file content
|
|
355
|
+
* @param courseId - ID of the course to export
|
|
356
|
+
* @returns GPX file content as string
|
|
357
|
+
*/
|
|
109
358
|
exportCourseAsGpx(courseId: number): Promise<string>;
|
|
110
359
|
/**
|
|
111
360
|
* Retrieves calendar events for a specific year.
|
|
@@ -132,7 +381,25 @@ export default class GarminConnect {
|
|
|
132
381
|
* @param newName
|
|
133
382
|
*/
|
|
134
383
|
renameActivity(activityId: GCActivityId, newName: string): Promise<void>;
|
|
384
|
+
/**
|
|
385
|
+
* Performs a GET request to the specified URL
|
|
386
|
+
* @param url - URL to send the request to
|
|
387
|
+
* @param data - Optional query parameters or request configuration
|
|
388
|
+
* @returns Response data of type T
|
|
389
|
+
*/
|
|
135
390
|
get<T>(url: string, data?: any): Promise<T>;
|
|
391
|
+
/**
|
|
392
|
+
* Performs a POST request to the specified URL
|
|
393
|
+
* @param url - URL to send the request to
|
|
394
|
+
* @param data - Data to send in the request body
|
|
395
|
+
* @returns Response data of type T
|
|
396
|
+
*/
|
|
136
397
|
post<T>(url: string, data: any): Promise<T>;
|
|
398
|
+
/**
|
|
399
|
+
* Performs a PUT request to the specified URL
|
|
400
|
+
* @param url - URL to send the request to
|
|
401
|
+
* @param data - Data to send in the request body
|
|
402
|
+
* @returns Response data of type T
|
|
403
|
+
*/
|
|
137
404
|
put<T>(url: string, data: any): Promise<T>;
|
|
138
405
|
}
|