ts-garmin 0.1.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/LICENSE.md +21 -0
- package/README.md +358 -0
- package/dist/common/HttpClient.d.ts +22 -0
- package/dist/garmin/GarminConnect.d.ts +76 -0
- package/dist/garmin/UrlClass.d.ts +55 -0
- package/dist/garmin/common/DateUtils.d.ts +3 -0
- package/dist/garmin/common/GpxUtils.d.ts +2 -0
- package/dist/garmin/common/HydrationUtils.d.ts +2 -0
- package/dist/garmin/common/WeightUtils.d.ts +4 -0
- package/dist/garmin/types/activity.d.ts +401 -0
- package/dist/garmin/types/calendar.d.ts +108 -0
- package/dist/garmin/types/gear.d.ts +20 -0
- package/dist/garmin/types/gpx.d.ts +171 -0
- package/dist/garmin/types/heartrate.d.ts +22 -0
- package/dist/garmin/types/hydration.d.ts +17 -0
- package/dist/garmin/types/index.d.ts +353 -0
- package/dist/garmin/types/sleep.d.ts +120 -0
- package/dist/garmin/types/weight.d.ts +50 -0
- package/dist/garmin/types/wellness.d.ts +108 -0
- package/dist/garmin/types/workout.d.ts +56 -0
- package/dist/garmin/workout-builder/duration.d.ts +33 -0
- package/dist/garmin/workout-builder/index.d.ts +5 -0
- package/dist/garmin/workout-builder/step.d.ts +15 -0
- package/dist/garmin/workout-builder/target.d.ts +34 -0
- package/dist/garmin/workout-builder/workout-builder.d.ts +8 -0
- package/dist/garmin/workout-builder/workout-type.d.ts +8 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1511 -0
- package/dist/utils.d.ts +3 -0
- package/package.json +48 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Open Web Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
<p align="center"><img src=".github/art/cover.jpg" alt="Social Card of this repo"></p>
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/ts-watches)
|
|
4
|
+
[](https://github.com/stacksjs/ts-watches/actions?query=workflow%3Aci)
|
|
5
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
6
|
+
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
|
|
7
|
+
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
|
8
|
+
|
|
9
|
+
# ts-watches
|
|
10
|
+
|
|
11
|
+
A comprehensive TypeScript library for downloading, parsing, and analyzing data from smartwatches and fitness devices. Supports Garmin, Polar, Suunto, Coros, Wahoo, and Apple Watch with full FIT file parsing, cloud integrations, training analysis, and real-time data streaming.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
### Device Support
|
|
16
|
+
|
|
17
|
+
- **Garmin** - Full FIT file parsing for activities, monitoring, sleep, stress, HRV
|
|
18
|
+
- **Polar** - HRM and JSON file format support
|
|
19
|
+
- **Suunto** - SML (XML) format parsing
|
|
20
|
+
- **Coros** - FIT file support with device detection
|
|
21
|
+
- **Wahoo** - FIT file support for ELEMNT devices
|
|
22
|
+
- **Apple Watch** - Health XML export parsing
|
|
23
|
+
|
|
24
|
+
### Data Parsing
|
|
25
|
+
|
|
26
|
+
- **FIT Protocol** - Complete binary parser for Garmin's FIT format
|
|
27
|
+
- **Activity Data** - Runs, rides, swims, hikes with full GPS and metrics
|
|
28
|
+
- **Health Monitoring** - Heart rate, sleep, stress, SpO2, HRV, respiration
|
|
29
|
+
- **Training Metrics** - TSS, IF, NP, training load calculations
|
|
30
|
+
|
|
31
|
+
### Data Export
|
|
32
|
+
|
|
33
|
+
- **GPX 1.1** - With Garmin TrackPoint extensions for heart rate, cadence, power
|
|
34
|
+
- **TCX** - Training Center XML format for Strava and other platforms
|
|
35
|
+
- **CSV** - Flexible export for activities and monitoring data
|
|
36
|
+
- **GeoJSON** - For mapping applications with Douglas-Peucker simplification
|
|
37
|
+
|
|
38
|
+
### Cloud Integrations
|
|
39
|
+
|
|
40
|
+
- **Garmin Activity API** - Official OAuth 2.0 PKCE integration with webhook push notifications, backfill and deregistration
|
|
41
|
+
- **Garmin Connect** - Download activities, daily summaries, sleep, stress, body battery (unofficial, password-based)
|
|
42
|
+
- **Strava** - OAuth authentication, activity upload, stream data retrieval
|
|
43
|
+
|
|
44
|
+
### Training Analysis
|
|
45
|
+
|
|
46
|
+
- **Training Load** - TSS, ATL, CTL, TSB calculations with recommendations
|
|
47
|
+
- **Personal Records** - Track PRs for various distances and metrics
|
|
48
|
+
- **Heart Rate Zones** - Percentage, Karvonen (reserve), LTHR-based calculations
|
|
49
|
+
- **Power Zones** - FTP-based zone calculations
|
|
50
|
+
- **Race Predictor** - Riegel formula predictions, VO2max estimation, training paces
|
|
51
|
+
- **Running Dynamics** - Form analysis, ground contact time, vertical oscillation
|
|
52
|
+
|
|
53
|
+
### Workout Tools
|
|
54
|
+
|
|
55
|
+
- **Workout Builder** - Fluent API for creating structured workouts
|
|
56
|
+
- **Course Builder** - Create GPS courses with waypoints
|
|
57
|
+
- **Training Plans** - Generate marathon and 5K training plans
|
|
58
|
+
- **iCal Export** - Export training plans to calendar format
|
|
59
|
+
|
|
60
|
+
### Real-time Data
|
|
61
|
+
|
|
62
|
+
- **ANT+** - Heart rate, power, speed/cadence sensor protocols
|
|
63
|
+
- **Bluetooth LE** - BLE GATT services for fitness devices
|
|
64
|
+
- **Live Tracking** - Real-time position and metrics sharing
|
|
65
|
+
|
|
66
|
+
### Developer Experience
|
|
67
|
+
|
|
68
|
+
- **CLI Tool** - Download, parse, and analyze from command line
|
|
69
|
+
- **TypeScript** - Fully typed APIs with comprehensive type exports
|
|
70
|
+
- **Zero Dependencies** - Core FIT parser has no external dependencies
|
|
71
|
+
|
|
72
|
+
## Install
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
bun install ts-watches
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quick Start
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { createGarminDriver } from 'ts-watches'
|
|
82
|
+
|
|
83
|
+
const driver = createGarminDriver()
|
|
84
|
+
|
|
85
|
+
// Detect connected devices
|
|
86
|
+
const devices = await driver.detectDevices()
|
|
87
|
+
console.log('Found devices:', devices)
|
|
88
|
+
|
|
89
|
+
// Download data from a device
|
|
90
|
+
if (devices.length > 0) {
|
|
91
|
+
const result = await driver.downloadData(devices[0], {
|
|
92
|
+
outputDir: './my-watch-data',
|
|
93
|
+
includeActivities: true,
|
|
94
|
+
includeMonitoring: true,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
console.log(`Downloaded ${result.activities.length} activities`)
|
|
98
|
+
console.log(`Downloaded ${result.monitoring.size} days of monitoring data`)
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Usage Examples
|
|
103
|
+
|
|
104
|
+
### Parse FIT Files
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { createGarminDriver } from 'ts-watches'
|
|
108
|
+
|
|
109
|
+
const driver = createGarminDriver()
|
|
110
|
+
const activity = await driver.parseActivityFile('/path/to/activity.fit')
|
|
111
|
+
|
|
112
|
+
console.log(`${activity.sport}: ${(activity.totalDistance / 1000).toFixed(2)}km`)
|
|
113
|
+
console.log(`Duration: ${Math.floor(activity.totalTime / 60)} minutes`)
|
|
114
|
+
console.log(`Avg HR: ${activity.avgHeartRate} bpm`)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Export to GPX
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { activityToGpx, activityToTcx, activityToCsv } from 'ts-watches'
|
|
121
|
+
|
|
122
|
+
// Export activity to GPX
|
|
123
|
+
const gpx = activityToGpx(activity)
|
|
124
|
+
await Bun.write('activity.gpx', gpx)
|
|
125
|
+
|
|
126
|
+
// Export to TCX for Strava upload
|
|
127
|
+
const tcx = activityToTcx(activity)
|
|
128
|
+
await Bun.write('activity.tcx', tcx)
|
|
129
|
+
|
|
130
|
+
// Export to CSV for analysis
|
|
131
|
+
const csv = activityToCsv(activity)
|
|
132
|
+
await Bun.write('activity.csv', csv)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Training Analysis
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { calculateTSS, ZoneCalculator, RacePredictor } from 'ts-watches'
|
|
139
|
+
|
|
140
|
+
// Calculate Training Stress Score
|
|
141
|
+
const tss = calculateTSS(activity, { ftp: 250 })
|
|
142
|
+
|
|
143
|
+
// Analyze zones
|
|
144
|
+
const zones = new ZoneCalculator({ maxHR: 185, restingHR: 50, ftp: 250 })
|
|
145
|
+
const zoneAnalysis = zones.analyzeActivity(activity)
|
|
146
|
+
|
|
147
|
+
// Predict race times
|
|
148
|
+
const predictor = new RacePredictor()
|
|
149
|
+
const predictions = predictor.predictFromPerformance(5000, 20 * 60) // 5K in 20min
|
|
150
|
+
console.log(`Predicted marathon: ${predictions.marathon}`)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Cloud Integration
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { GarminActivityApiClient, GarminConnectClient, StravaClient } from 'ts-watches'
|
|
157
|
+
|
|
158
|
+
// Garmin Activity API (official, OAuth 2.0 PKCE, push notifications).
|
|
159
|
+
// The athlete approves on Garmin's own site and can revoke at any time.
|
|
160
|
+
const garmin = new GarminActivityApiClient({
|
|
161
|
+
clientId: process.env.GARMIN_CLIENT_ID!,
|
|
162
|
+
clientSecret: process.env.GARMIN_CLIENT_SECRET!,
|
|
163
|
+
redirectUri: 'https://example.com/garmin/callback',
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
const { verifier, challenge } = createPkcePair()
|
|
167
|
+
const url = garmin.buildAuthorizationUrl({ state, challenge }) // send the athlete here
|
|
168
|
+
const tokens = await garmin.exchangeCode(code, verifier) // on the callback
|
|
169
|
+
const userId = await garmin.getUserId(tokens.accessToken) // the key push notifications carry
|
|
170
|
+
|
|
171
|
+
// Garmin Connect (unofficial; needs the athlete's password, breaks under 2FA)
|
|
172
|
+
const legacy = new GarminConnectClient()
|
|
173
|
+
await legacy.login('email@example.com', 'password')
|
|
174
|
+
const activities = await legacy.getActivities(new Date('2024-01-01'))
|
|
175
|
+
|
|
176
|
+
// Strava
|
|
177
|
+
const strava = new StravaClient({
|
|
178
|
+
clientId: 'your-client-id',
|
|
179
|
+
clientSecret: 'your-client-secret',
|
|
180
|
+
})
|
|
181
|
+
const authUrl = strava.getAuthorizationUrl('http://localhost:3000/callback')
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Build Workouts
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { WorkoutBuilder, workoutTemplates } from 'ts-watches'
|
|
188
|
+
|
|
189
|
+
// Use a template
|
|
190
|
+
const intervals = workoutTemplates.vo2maxIntervals({ ftp: 250 })
|
|
191
|
+
|
|
192
|
+
// Or build custom workout
|
|
193
|
+
const workout = new WorkoutBuilder('Custom Threshold')
|
|
194
|
+
.warmup({ duration: 600, targetPower: { min: 100, max: 150 } })
|
|
195
|
+
.interval({ duration: 1200, targetPower: { min: 240, max: 260 } })
|
|
196
|
+
.recovery({ duration: 300, targetPower: { min: 100, max: 130 } })
|
|
197
|
+
.repeat(4)
|
|
198
|
+
.cooldown({ duration: 600, targetPower: { min: 100, max: 130 } })
|
|
199
|
+
.build()
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Real-time Data
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { createLiveTracking, createBleScanner } from 'ts-watches'
|
|
206
|
+
|
|
207
|
+
// Live tracking
|
|
208
|
+
const tracker = createLiveTracking({
|
|
209
|
+
updateInterval: 5000,
|
|
210
|
+
onUpdate: (session) => console.log(`Distance: ${session.totalDistance}m`),
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
tracker.start('Morning Run')
|
|
214
|
+
tracker.updatePosition({ lat: 37.7749, lng: -122.4194, altitude: 10 })
|
|
215
|
+
|
|
216
|
+
// BLE sensors
|
|
217
|
+
const ble = createBleScanner()
|
|
218
|
+
await ble.startScanning()
|
|
219
|
+
ble.on('data', (device, data) => {
|
|
220
|
+
if (data.type === 'heart_rate') {
|
|
221
|
+
console.log(`HR: ${data.data.heartRate} bpm`)
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## CLI
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# Detect connected watches
|
|
230
|
+
watch detect
|
|
231
|
+
|
|
232
|
+
# Download all data from connected watch
|
|
233
|
+
watch download
|
|
234
|
+
|
|
235
|
+
# Download to specific directory
|
|
236
|
+
watch download --output ./my-data
|
|
237
|
+
|
|
238
|
+
# Download only activities from the last week
|
|
239
|
+
watch download --activities --since 2024-01-01
|
|
240
|
+
|
|
241
|
+
# Parse a single FIT file
|
|
242
|
+
watch parse /path/to/activity.fit
|
|
243
|
+
|
|
244
|
+
# Parse and output as JSON
|
|
245
|
+
watch parse /path/to/activity.fit --format json
|
|
246
|
+
|
|
247
|
+
# Watch for device connection and auto-download
|
|
248
|
+
watch watch
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Supported Data Types
|
|
252
|
+
|
|
253
|
+
### Activities
|
|
254
|
+
|
|
255
|
+
- Running (treadmill, trail, track)
|
|
256
|
+
- Cycling (road, mountain, gravel, indoor)
|
|
257
|
+
- Swimming (pool, open water)
|
|
258
|
+
- Hiking, Walking
|
|
259
|
+
- Strength training, Cardio, HIIT
|
|
260
|
+
- Multisport (triathlon)
|
|
261
|
+
- And 50+ more sport types
|
|
262
|
+
|
|
263
|
+
### Health Metrics
|
|
264
|
+
|
|
265
|
+
| Metric | Description |
|
|
266
|
+
|--------|-------------|
|
|
267
|
+
| Heart Rate | Continuous monitoring, resting HR, zones |
|
|
268
|
+
| Sleep | Duration, stages (light, deep, REM), score |
|
|
269
|
+
| Stress | Stress levels throughout the day |
|
|
270
|
+
| Body Battery | Energy levels based on HRV |
|
|
271
|
+
| SpO2 | Blood oxygen saturation |
|
|
272
|
+
| Respiration | Breathing rate |
|
|
273
|
+
| HRV | Heart rate variability (RMSSD, SDRR) |
|
|
274
|
+
| Steps | Daily count, goals, intensity minutes |
|
|
275
|
+
|
|
276
|
+
### Training Metrics
|
|
277
|
+
|
|
278
|
+
| Metric | Description |
|
|
279
|
+
|--------|-------------|
|
|
280
|
+
| TSS | Training Stress Score |
|
|
281
|
+
| IF | Intensity Factor |
|
|
282
|
+
| NP | Normalized Power |
|
|
283
|
+
| ATL | Acute Training Load |
|
|
284
|
+
| CTL | Chronic Training Load (Fitness) |
|
|
285
|
+
| TSB | Training Stress Balance (Form) |
|
|
286
|
+
| TRIMP | Training Impulse |
|
|
287
|
+
|
|
288
|
+
## Device Setup
|
|
289
|
+
|
|
290
|
+
### Garmin
|
|
291
|
+
|
|
292
|
+
1. Connect your watch via USB
|
|
293
|
+
2. On the watch: **Settings > System > USB Mode > Mass Storage**
|
|
294
|
+
3. Close Garmin Express (it locks the device)
|
|
295
|
+
4. The watch appears as `/Volumes/GARMIN` on macOS
|
|
296
|
+
|
|
297
|
+
### Polar
|
|
298
|
+
|
|
299
|
+
1. Export data from Polar Flow web interface
|
|
300
|
+
2. Or use Polar's data export feature on the device
|
|
301
|
+
|
|
302
|
+
### Apple Watch
|
|
303
|
+
|
|
304
|
+
1. Open Health app on iPhone
|
|
305
|
+
2. Tap profile > Export All Health Data
|
|
306
|
+
3. Extract the ZIP file
|
|
307
|
+
|
|
308
|
+
## API Reference
|
|
309
|
+
|
|
310
|
+
See the [full API documentation](./docs/api.md) for detailed type definitions and method signatures.
|
|
311
|
+
|
|
312
|
+
## Testing
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
bun test
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Changelog
|
|
319
|
+
|
|
320
|
+
Please see our [releases](https://github.com/stacksjs/ts-watches/releases) page for more information on what has changed recently.
|
|
321
|
+
|
|
322
|
+
## Contributing
|
|
323
|
+
|
|
324
|
+
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
|
|
325
|
+
|
|
326
|
+
## Community
|
|
327
|
+
|
|
328
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
329
|
+
|
|
330
|
+
[Discussions on GitHub](https://github.com/stacksjs/ts-watches/discussions)
|
|
331
|
+
|
|
332
|
+
For casual chit-chat with others using this package:
|
|
333
|
+
|
|
334
|
+
[Join the Stacks Discord Server](https://stacksjs.com/discord)
|
|
335
|
+
|
|
336
|
+
## Postcardware
|
|
337
|
+
|
|
338
|
+
"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where Stacks is being used! We showcase them on our website too.
|
|
339
|
+
|
|
340
|
+
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States
|
|
341
|
+
|
|
342
|
+
## Sponsors
|
|
343
|
+
|
|
344
|
+
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
|
|
345
|
+
|
|
346
|
+
- [JetBrains](https://www.jetbrains.com/)
|
|
347
|
+
- [The Solana Foundation](https://solana.com/)
|
|
348
|
+
|
|
349
|
+
## License
|
|
350
|
+
|
|
351
|
+
The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.
|
|
352
|
+
|
|
353
|
+
Made with 💙
|
|
354
|
+
|
|
355
|
+
<!-- Badges -->
|
|
356
|
+
|
|
357
|
+
<!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/ts-watches/main?style=flat-square
|
|
358
|
+
[codecov-href]: https://codecov.io/gh/stacksjs/ts-watches -->
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IOauth1, IOauth1Consumer, IOauth1Token, IOauth2Token } from '../garmin/types/index';
|
|
2
|
+
import type { UrlClass } from '../garmin/UrlClass';
|
|
3
|
+
export declare class HttpClient {
|
|
4
|
+
url: UrlClass;
|
|
5
|
+
oauth1Token: IOauth1Token | undefined;
|
|
6
|
+
oauth2Token: IOauth2Token | undefined;
|
|
7
|
+
OAUTH_CONSUMER: IOauth1Consumer | undefined;
|
|
8
|
+
constructor(url: UrlClass);
|
|
9
|
+
fetchOauthConsumer(): Promise<void>;
|
|
10
|
+
checkTokenValid(): Promise<void>;
|
|
11
|
+
get<T>(url: string, config?: { params?: Record<string, unknown>, headers?: Record<string, string>, responseType?: string }): Promise<T>;
|
|
12
|
+
post<T>(url: string, data: unknown, config?: { headers?: Record<string, string> }): Promise<T>;
|
|
13
|
+
put<T>(url: string, data: unknown, config?: { headers?: Record<string, string> }): Promise<T>;
|
|
14
|
+
delete<T>(url: string, config?: { headers?: Record<string, string> }): Promise<T>;
|
|
15
|
+
login(username: string, password: string): Promise<HttpClient>;
|
|
16
|
+
handlePageTitle(htmlStr: string): void;
|
|
17
|
+
handleAccountLocked(htmlStr: string): void;
|
|
18
|
+
refreshOauth2Token(): Promise<void>;
|
|
19
|
+
getOauth1Token(ticket: string): Promise<IOauth1>;
|
|
20
|
+
exchange(oauth1: IOauth1): Promise<void>;
|
|
21
|
+
setOauth2TokenExpiresAt(token: IOauth2Token): IOauth2Token;
|
|
22
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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';
|
|
3
|
+
import type { CoursePoint, GeoPoint, GpxActivityType, ImportedGpxResponse } from './types/gpx';
|
|
4
|
+
import type { GearData } from './types/gear';
|
|
5
|
+
import type { HeartRate } from './types/heartrate';
|
|
6
|
+
import type { MonthCalendar, YearCalendar } from './types/calendar';
|
|
7
|
+
import type { SleepData } from './types/sleep';
|
|
8
|
+
import type { StressData, HrvData, TrainingReadiness, BodyBatteryData, DailySummaryStats } from './types/wellness';
|
|
9
|
+
import type { UpdateWeight, WeightData } from './types/weight';
|
|
10
|
+
import type { WaterIntake } from './types/hydration';
|
|
11
|
+
import type { Workout } from './types/workout';
|
|
12
|
+
export declare interface GCCredentials {
|
|
13
|
+
username: string
|
|
14
|
+
password: string
|
|
15
|
+
}
|
|
16
|
+
export declare interface Listeners {
|
|
17
|
+
[event: string]: EventCallback<unknown>[]
|
|
18
|
+
}
|
|
19
|
+
export type EventCallback<T> = (_data: T) => void;
|
|
20
|
+
export default class GarminConnect {
|
|
21
|
+
client: HttpClient;
|
|
22
|
+
constructor(credentials?: GCCredentials, domain?: GarminDomain);
|
|
23
|
+
login(username?: string, password?: string): Promise<GarminConnect>;
|
|
24
|
+
exportTokenToFile(dirPath: string): void;
|
|
25
|
+
loadTokenByFile(dirPath: string): void;
|
|
26
|
+
exportToken(): IGarminTokens;
|
|
27
|
+
loadToken(oauth1: IOauth1Token, oauth2: IOauth2Token): void;
|
|
28
|
+
getUserSettings(): Promise<IUserSettings>;
|
|
29
|
+
getUserProfile(): Promise<ISocialProfile>;
|
|
30
|
+
getActivities(start?: number, limit?: number, activityType?: ActivityType, subActivityType?: ActivitySubType): Promise<IActivity[]>;
|
|
31
|
+
getActivity(activity: { activityId: GCActivityId }): Promise<IActivity>;
|
|
32
|
+
countActivities(): Promise<ICountActivities>;
|
|
33
|
+
downloadOriginalActivityData(activity: { activityId: GCActivityId }, dir: string, type?: ExportFileTypeValue): Promise<void>;
|
|
34
|
+
uploadActivity(file: string, format?: UploadFileTypeValue): Promise<unknown>;
|
|
35
|
+
deleteActivity(activity: { activityId: GCActivityId }): Promise<void>;
|
|
36
|
+
getWorkouts(start: number, limit: number): Promise<IWorkout[]>;
|
|
37
|
+
getWorkoutDetail(workout: { workoutId: string }): Promise<IWorkoutDetail>;
|
|
38
|
+
createWorkout(workout: IWorkoutDetail): Promise<Workout>;
|
|
39
|
+
deleteWorkout(workout: { workoutId: string }): Promise<unknown>;
|
|
40
|
+
scheduleWorkout(workout: { workoutId: string }, scheduleDate: string): Promise<unknown>;
|
|
41
|
+
getSteps(date?: Date): Promise<number>;
|
|
42
|
+
getSleepData(date?: Date): Promise<SleepData>;
|
|
43
|
+
getSleepDuration(date?: Date): Promise<{ hours: number, minutes: number }>;
|
|
44
|
+
getDailyWeightData(date?: Date): Promise<WeightData>;
|
|
45
|
+
getDailyWeightInPounds(date?: Date): Promise<number>;
|
|
46
|
+
getDailyHydration(date?: Date): Promise<number>;
|
|
47
|
+
updateWeight(date?: Date | undefined, lbs: number, timezone: string): Promise<UpdateWeight>;
|
|
48
|
+
updateHydrationLogOunces(date?: Date | undefined, valueInOz: number): Promise<WaterIntake>;
|
|
49
|
+
getGolfSummary(): Promise<unknown>;
|
|
50
|
+
getGolfScorecard(scorecardId: number): Promise<unknown>;
|
|
51
|
+
getHeartRate(date?: Date): Promise<HeartRate>;
|
|
52
|
+
getStressData(date?: Date): Promise<StressData>;
|
|
53
|
+
getHrvData(date?: Date): Promise<HrvData>;
|
|
54
|
+
getTrainingReadiness(date?: Date): Promise<TrainingReadiness>;
|
|
55
|
+
getBodyBattery(date?: Date): Promise<BodyBatteryData>;
|
|
56
|
+
getDailySummary(date?: Date): Promise<DailySummaryStats>;
|
|
57
|
+
getGear(availableGearDate?: string): Promise<GearData[]>;
|
|
58
|
+
getGearsForActivity(activityId: GCActivityId): Promise<GearData[]>;
|
|
59
|
+
linkGearToActivity(activityId: GCActivityId, gearId: GCGearId): Promise<GearData>;
|
|
60
|
+
unlinkGearFromActivity(activityId: GCActivityId, gearId: GCGearId): Promise<GearData>;
|
|
61
|
+
workouts(): Promise<Workout[]>;
|
|
62
|
+
importGpx(fileName: string, fileContent: string): Promise<ImportedGpxResponse>;
|
|
63
|
+
createCourse(activityType: GpxActivityType, courseName: string, geoPoints: GeoPoint[], coursePoints?: CoursePoint[]): Promise<unknown>;
|
|
64
|
+
listCourses(): Promise<ListCoursesResponse>;
|
|
65
|
+
exportCourseAsGpx(courseId: number): Promise<string>;
|
|
66
|
+
getYearCalendarEvents(year: number): Promise<YearCalendar>;
|
|
67
|
+
getMonthCalendarEvents(year: number, month: number): Promise<MonthCalendar>;
|
|
68
|
+
getWeekCalendarEvents(year: number, month: number, day: number, firstDayOfWeek?: number): Promise<unknown>;
|
|
69
|
+
renameActivity(activityId: GCActivityId, newName: string): Promise<void>;
|
|
70
|
+
get<T>(url: string, data?: unknown): Promise<T>;
|
|
71
|
+
post<T>(url: string, _data: unknown): Promise<T>;
|
|
72
|
+
put<T>(url: string, _data: unknown): Promise<T>;
|
|
73
|
+
}
|
|
74
|
+
export declare enum Event {
|
|
75
|
+
sessionChange = 'sessionChange',
|
|
76
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { GCActivityId, GCGearId, GCUserProfileId, GCWorkoutId, GarminDomain } from './types/index';
|
|
2
|
+
export declare class UrlClass {
|
|
3
|
+
GC_MODERN: string;
|
|
4
|
+
GARMIN_SSO_ORIGIN: string;
|
|
5
|
+
GC_API: string;
|
|
6
|
+
constructor(domain?: GarminDomain);
|
|
7
|
+
get GARMIN_SSO(): string;
|
|
8
|
+
get GARMIN_SSO_EMBED(): string;
|
|
9
|
+
get BASE_URL(): string;
|
|
10
|
+
get SIGNIN_URL(): string;
|
|
11
|
+
get LOGIN_URL(): string;
|
|
12
|
+
get OAUTH_URL(): string;
|
|
13
|
+
get USER_SETTINGS(): string;
|
|
14
|
+
get USER_PROFILE(): string;
|
|
15
|
+
get ACTIVITIES(): string;
|
|
16
|
+
get ACTIVITY(): string;
|
|
17
|
+
ACTIVITY_BY_ID(activityId: GCActivityId): 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
|
+
get DAILY_STEPS(): string;
|
|
26
|
+
get DAILY_SLEEP(): string;
|
|
27
|
+
get DAILY_WEIGHT(): string;
|
|
28
|
+
get UPDATE_WEIGHT(): string;
|
|
29
|
+
get DAILY_HYDRATION(): string;
|
|
30
|
+
get HYDRATION_LOG(): string;
|
|
31
|
+
get GOLF_SCORECARD_SUMMARY(): string;
|
|
32
|
+
get GOLF_SCORECARD_DETAIL(): string;
|
|
33
|
+
get DAILY_HEART_RATE(): string;
|
|
34
|
+
WORKOUT(id?: GCWorkoutId): string;
|
|
35
|
+
get WORKOUTS(): string;
|
|
36
|
+
GEAR_OF_ACTIVITY(activityId: GCActivityId): string;
|
|
37
|
+
GEAR(userProfilePk: GCUserProfileId, availableGearDate?: string): string;
|
|
38
|
+
LINK_GEAR_TO_ACTIVITY(activityId: GCActivityId, gearId: GCGearId): string;
|
|
39
|
+
UNLINK_GEAR_FROM_ACTIVITY(activityId: GCActivityId, gearId: GCGearId): string;
|
|
40
|
+
WORKOUTS_LIST(start?: number, limit?: number, myWorkoutsOnly?: boolean, sharedWorkoutsOnly?: boolean, orderBy?: string, orderSeq?: 'ASC' | 'DESC', includeAtp?: boolean): string;
|
|
41
|
+
SCHEDULE_WORKOUT(workoutId: number): string;
|
|
42
|
+
get IMPORT_GPX_FILE(): string;
|
|
43
|
+
EXPORT_COURSE_GPX_FILE(courseId: number): string;
|
|
44
|
+
get CREATE_COURSE_GPX_FILE(): string;
|
|
45
|
+
UPDATE_COURSE_GPX_FILE(courseId: number): string;
|
|
46
|
+
get LIST_COURSES(): string;
|
|
47
|
+
CALENDAR_YEAR(year: number): string;
|
|
48
|
+
CALENDAR_MONTH(year: number, month: number): string;
|
|
49
|
+
CALENDAR_WEEK(year: number, month: number, day: number, firstDateOfWeek?: number): string;
|
|
50
|
+
DAILY_STRESS(date: string): string;
|
|
51
|
+
HRV_DATA(date: string): string;
|
|
52
|
+
TRAINING_READINESS(date: string): string;
|
|
53
|
+
BODY_BATTERY(date: string): string;
|
|
54
|
+
DAILY_SUMMARY(userId: number, date: string): string;
|
|
55
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function toDateString(date: Date): string;
|
|
2
|
+
export declare function calculateTimeDifference(sleepStartTimestampGMT: number, sleepEndTimestampGMT: number): { hours: number, minutes: number };
|
|
3
|
+
export declare function getLocalTimestamp(date: Date, timezone: string): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function gramsToPounds(weightInGrams: number): number;
|
|
2
|
+
export declare function poundsToGrams(weightInPounds: number): number;
|
|
3
|
+
export declare function kilogramsToGrams(weightInKg: number): number;
|
|
4
|
+
export declare function gramsToKilograms(weightInGrams: number): number;
|