@flow-js/garmin-connect 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +627 -0
  3. package/dist/common/CFClient.d.ts +22 -0
  4. package/dist/common/CFClient.js +137 -0
  5. package/dist/common/CFClient.js.map +1 -0
  6. package/dist/common/DateUtils.d.ts +1 -0
  7. package/dist/common/DateUtils.js +11 -0
  8. package/dist/common/DateUtils.js.map +1 -0
  9. package/dist/common/HttpClient.d.ts +37 -0
  10. package/dist/common/HttpClient.js +496 -0
  11. package/dist/common/HttpClient.js.map +1 -0
  12. package/dist/garmin/GarminConnect.d.ts +112 -0
  13. package/dist/garmin/GarminConnect.js +816 -0
  14. package/dist/garmin/GarminConnect.js.map +1 -0
  15. package/dist/garmin/UrlClass.d.ts +53 -0
  16. package/dist/garmin/UrlClass.js +267 -0
  17. package/dist/garmin/UrlClass.js.map +1 -0
  18. package/dist/garmin/Urls.d.ts +56 -0
  19. package/dist/garmin/Urls.js +88 -0
  20. package/dist/garmin/Urls.js.map +1 -0
  21. package/dist/garmin/common/DateUtils.d.ts +6 -0
  22. package/dist/garmin/common/DateUtils.js +38 -0
  23. package/dist/garmin/common/DateUtils.js.map +1 -0
  24. package/dist/garmin/common/GpxUtils.d.ts +2 -0
  25. package/dist/garmin/common/GpxUtils.js +28 -0
  26. package/dist/garmin/common/GpxUtils.js.map +1 -0
  27. package/dist/garmin/common/HydrationUtils.d.ts +2 -0
  28. package/dist/garmin/common/HydrationUtils.js +16 -0
  29. package/dist/garmin/common/HydrationUtils.js.map +1 -0
  30. package/dist/garmin/common/WeightUtils.d.ts +1 -0
  31. package/dist/garmin/common/WeightUtils.js +9 -0
  32. package/dist/garmin/common/WeightUtils.js.map +1 -0
  33. package/dist/garmin/types/activity.d.ts +408 -0
  34. package/dist/garmin/types/activity.js +27 -0
  35. package/dist/garmin/types/activity.js.map +1 -0
  36. package/dist/garmin/types/gear.d.ts +20 -0
  37. package/dist/garmin/types/gear.js +3 -0
  38. package/dist/garmin/types/gear.js.map +1 -0
  39. package/dist/garmin/types/golf.d.ts +67 -0
  40. package/dist/garmin/types/golf.js +3 -0
  41. package/dist/garmin/types/golf.js.map +1 -0
  42. package/dist/garmin/types/gpx.d.ts +171 -0
  43. package/dist/garmin/types/gpx.js +15 -0
  44. package/dist/garmin/types/gpx.js.map +1 -0
  45. package/dist/garmin/types/heartrate.d.ts +22 -0
  46. package/dist/garmin/types/heartrate.js +2 -0
  47. package/dist/garmin/types/heartrate.js.map +1 -0
  48. package/dist/garmin/types/hydration.d.ts +28 -0
  49. package/dist/garmin/types/hydration.js +2 -0
  50. package/dist/garmin/types/hydration.js.map +1 -0
  51. package/dist/garmin/types/index.d.ts +445 -0
  52. package/dist/garmin/types/index.js +37 -0
  53. package/dist/garmin/types/index.js.map +1 -0
  54. package/dist/garmin/types/sleep.d.ts +120 -0
  55. package/dist/garmin/types/sleep.js +3 -0
  56. package/dist/garmin/types/sleep.js.map +1 -0
  57. package/dist/garmin/types/weight.d.ts +42 -0
  58. package/dist/garmin/types/weight.js +3 -0
  59. package/dist/garmin/types/weight.js.map +1 -0
  60. package/dist/garmin/types/workout-builder.d.ts +138 -0
  61. package/dist/garmin/types/workout-builder.js +286 -0
  62. package/dist/garmin/types/workout-builder.js.map +1 -0
  63. package/dist/garmin/types/workout.d.ts +56 -0
  64. package/dist/garmin/types/workout.js +3 -0
  65. package/dist/garmin/types/workout.js.map +1 -0
  66. package/dist/garmin/types.d.ts +504 -0
  67. package/dist/garmin/types.js +3 -0
  68. package/dist/garmin/types.js.map +1 -0
  69. package/dist/garmin/workout-builder/duration.d.ts +87 -0
  70. package/dist/garmin/workout-builder/duration.js +173 -0
  71. package/dist/garmin/workout-builder/duration.js.map +1 -0
  72. package/dist/garmin/workout-builder/index.d.ts +5 -0
  73. package/dist/garmin/workout-builder/index.js +22 -0
  74. package/dist/garmin/workout-builder/index.js.map +1 -0
  75. package/dist/garmin/workout-builder/step.d.ts +28 -0
  76. package/dist/garmin/workout-builder/step.js +60 -0
  77. package/dist/garmin/workout-builder/step.js.map +1 -0
  78. package/dist/garmin/workout-builder/target.d.ts +49 -0
  79. package/dist/garmin/workout-builder/target.js +193 -0
  80. package/dist/garmin/workout-builder/target.js.map +1 -0
  81. package/dist/garmin/workout-builder/workout-builder.d.ts +12 -0
  82. package/dist/garmin/workout-builder/workout-builder.js +37 -0
  83. package/dist/garmin/workout-builder/workout-builder.js.map +1 -0
  84. package/dist/garmin/workout-builder/workout-type.d.ts +11 -0
  85. package/dist/garmin/workout-builder/workout-type.js +26 -0
  86. package/dist/garmin/workout-builder/workout-type.js.map +1 -0
  87. package/dist/garmin/workouts/Running.d.ts +16 -0
  88. package/dist/garmin/workouts/Running.js +64 -0
  89. package/dist/garmin/workouts/Running.js.map +1 -0
  90. package/dist/garmin/workouts/templates/RunningTemplate.d.ts +68 -0
  91. package/dist/garmin/workouts/templates/RunningTemplate.js +78 -0
  92. package/dist/garmin/workouts/templates/RunningTemplate.js.map +1 -0
  93. package/dist/garmin/workouts/workout-builder.d.ts +138 -0
  94. package/dist/garmin/workouts/workout-builder.js +286 -0
  95. package/dist/garmin/workouts/workout-builder.js.map +1 -0
  96. package/dist/garmin/workouts-builder/workout-builder.d.ts +138 -0
  97. package/dist/garmin/workouts-builder/workout-builder.js +286 -0
  98. package/dist/garmin/workouts-builder/workout-builder.js.map +1 -0
  99. package/dist/index.d.ts +4 -0
  100. package/dist/index.js +26 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/utils.d.ts +3 -0
  103. package/dist/utils.js +46 -0
  104. package/dist/utils.js.map +1 -0
  105. package/examples/assets/paris-marathon.gpx +2037 -0
  106. package/examples/example-gpx-file.js +54 -0
  107. package/examples/example-workout.js +162 -0
  108. package/examples/example.js +34 -0
  109. package/package.json +67 -0
@@ -0,0 +1,54 @@
1
+ const { GarminConnect } = require('../dist/index');
2
+ const fs = require('fs/promises');
3
+ const path = require('path');
4
+
5
+ const GPX_FILE_NAME = 'paris-marathon.gpx';
6
+ const GPX_FILE_FOLDER = './assets/';
7
+
8
+ (async function () {
9
+ const GARMIN_USERNAME = process.env.GARMIN_USERNAME;
10
+ const GARMIN_PASSWORD = process.env.GARMIN_PASSWORD;
11
+
12
+ if (!GARMIN_USERNAME || !GARMIN_PASSWORD) {
13
+ throw new Error(
14
+ 'GARMIN_USERNAME and GARMIN_PASSWORD must be set in the environment variables'
15
+ );
16
+ }
17
+
18
+ const GCClient = new GarminConnect({
19
+ username: GARMIN_USERNAME,
20
+ password: GARMIN_PASSWORD
21
+ });
22
+ await GCClient.login();
23
+
24
+ const fileContent = (
25
+ await fs.readFile(path.join(GPX_FILE_FOLDER, GPX_FILE_NAME), 'utf8')
26
+ ).toString();
27
+
28
+ const response = await GCClient.importGpx(GPX_FILE_NAME, fileContent);
29
+
30
+ const createCourseResponse = await GCClient.createCourse(
31
+ 1,
32
+ response.courseName,
33
+ response.geoPoints,
34
+ response.coursePoints
35
+ );
36
+
37
+ console.log(
38
+ 'Course created with id:',
39
+ createCourseResponse.courseId,
40
+ `https://connect.garmin.com/modern/course/${createCourseResponse.courseId}`
41
+ );
42
+
43
+ const listCourses = await GCClient.listCourses();
44
+ console.log(
45
+ 'Last course:',
46
+ listCourses.coursesForUser[0].courseId,
47
+ listCourses.coursesForUser[0].courseName
48
+ );
49
+
50
+ const downloadGpx = await GCClient.exportCourseAsGpx(
51
+ createCourseResponse.courseId
52
+ );
53
+ console.log('Downloaded GPX size:', downloadGpx.length);
54
+ })();
@@ -0,0 +1,162 @@
1
+ const {
2
+ GarminConnect,
3
+ CadenceTarget,
4
+ CaloriesDuration,
5
+ DistanceDuration,
6
+ HeartRateDuration,
7
+ HrmTarget,
8
+ HrmZoneTarget,
9
+ LapPressDuration,
10
+ PaceTarget,
11
+ PowerZone,
12
+ PowerZoneTarget,
13
+ TimeDuration,
14
+ WorkoutBuilder,
15
+ Step,
16
+ NoTarget,
17
+ StepType,
18
+ WorkoutType
19
+ } = require('garmin-connect');
20
+
21
+ (async function () {
22
+ const GARMIN_USERNAME = process.env.GARMIN_USERNAME;
23
+ const GARMIN_PASSWORD = process.env.GARMIN_PASSWORD;
24
+
25
+ if (!GARMIN_USERNAME || !GARMIN_PASSWORD) {
26
+ throw new Error(
27
+ 'GARMIN_USERNAME and GARMIN_PASSWORD must be set in the environment variables'
28
+ );
29
+ }
30
+
31
+ const wb = new WorkoutBuilder(
32
+ WorkoutType.Running,
33
+ 'Workout running ' + new Date().toISOString()
34
+ );
35
+
36
+ /**
37
+ * There are multiple StepTypes: WarmUp, Run, Recovery, Rest, Cooldown, Other
38
+ */
39
+ wb.addStep(
40
+ new Step(
41
+ StepType.Run,
42
+ TimeDuration.fromSeconds(45),
43
+ new NoTarget(),
44
+ 'Comment for the step: Run for 45 seconds'
45
+ )
46
+ );
47
+
48
+ wb.addStep(
49
+ new Step(
50
+ StepType.Recovery,
51
+ TimeDuration.hhmmss(0, 1, 30),
52
+ new NoTarget(),
53
+ 'Comment for the step: Run for 1 minute 30 seconds'
54
+ )
55
+ );
56
+
57
+ /** There are multiple durations: TimeDuration, DistanceDuration, HeartRateDuration, CaloriesDuration, LapPressDuration */
58
+ wb.addStep(
59
+ new Step(
60
+ StepType.Run,
61
+ DistanceDuration.fromKilometers(2),
62
+ new NoTarget(),
63
+ 'Run for 2km'
64
+ )
65
+ );
66
+
67
+ wb.addStep(
68
+ new Step(
69
+ StepType.WarmUp,
70
+ HeartRateDuration.greaterThan(130),
71
+ new NoTarget(),
72
+ 'Warm up until HR > 130 bpm'
73
+ )
74
+ );
75
+
76
+ wb.addStep(
77
+ new Step(
78
+ StepType.Cooldown,
79
+ new LapPressDuration(),
80
+ new NoTarget(),
81
+ 'Cooldown for as long as you need'
82
+ )
83
+ );
84
+
85
+ wb.addStep(
86
+ new Step(
87
+ StepType.Rest,
88
+ new CaloriesDuration(200),
89
+ new NoTarget(),
90
+ 'Rest until you burned 200 calories'
91
+ )
92
+ );
93
+
94
+ /**
95
+ * There are multiple targets: PaceTarget, HrmZoneTarget, HrmTarget, PowerZoneTarget, PowerZone, CadenceTarget, NoTarget
96
+ */
97
+ wb.addStep(
98
+ new Step(
99
+ StepType.Run,
100
+ TimeDuration.fromSeconds(30),
101
+ PaceTarget.pace(5, 30, 10),
102
+ 'Run at 5:30 min/km pace (+- 10 sec) for 30 seconds'
103
+ )
104
+ );
105
+
106
+ wb.addStep(
107
+ new Step(
108
+ StepType.Run,
109
+ TimeDuration.fromSeconds(30),
110
+ new HrmZoneTarget(5),
111
+ 'Run at HR zone 5 for 30 seconds'
112
+ )
113
+ );
114
+
115
+ wb.addStep(
116
+ new Step(
117
+ StepType.Run,
118
+ TimeDuration.fromSeconds(30),
119
+ HrmTarget.hrm(150, 10),
120
+ 'Run at HR 150 bpm (+- 10 bpm) for 30 seconds'
121
+ )
122
+ );
123
+
124
+ wb.addStep(
125
+ new Step(
126
+ StepType.Run,
127
+ TimeDuration.fromSeconds(30),
128
+ new PowerZoneTarget(3),
129
+ 'Run at Power zone 3 for 30 seconds'
130
+ )
131
+ );
132
+
133
+ wb.addStep(
134
+ new Step(
135
+ StepType.Run,
136
+ TimeDuration.fromSeconds(30),
137
+ PowerZone.power(250, 20),
138
+ 'Run at Power 250 watts (+- 20 watts) for 30 seconds'
139
+ )
140
+ );
141
+
142
+ wb.addStep(
143
+ new Step(
144
+ StepType.Run,
145
+ TimeDuration.fromSeconds(30),
146
+ CadenceTarget.cadence(80, 5),
147
+ 'Run at Cadence 80 rpm (+- 5 rpm) for 30 seconds'
148
+ )
149
+ );
150
+
151
+ const workout = wb.build();
152
+
153
+ // Save workout to Garmin Connect
154
+ const GCClient = new GarminConnect({
155
+ username: GARMIN_USERNAME,
156
+ password: GARMIN_PASSWORD
157
+ });
158
+
159
+ await GCClient.login();
160
+
161
+ await GCClient.createWorkout(workout);
162
+ })();
@@ -0,0 +1,34 @@
1
+ const { GarminConnect } = require('garmin-connect');
2
+
3
+ // Has to be run in an async function to be able to use the await keyword
4
+ const main = async () => {
5
+ // Create a new Garmin Connect Client
6
+ const GCClient = new GarminConnect({
7
+ username: 'your-email',
8
+ password: 'your-password'
9
+ });
10
+
11
+ // TODO: Test China Domain
12
+ // China Domain
13
+ // const GCClient = new GarminConnect({
14
+ // username: 'your-email',
15
+ // password: 'your-password'
16
+ // }, 'garmin.cn');
17
+
18
+ // Uses credentials from garmin.config.json or uses supplied params
19
+ await GCClient.login();
20
+
21
+ // // Get user info
22
+ // const info = await GCClient.getUserInfo();
23
+
24
+ // Log info to make sure signin was successful
25
+ // console.log(info);
26
+ // // Get user settings
27
+ const settings = await GCClient.getUserSettings();
28
+
29
+ // Log info to make sure signin was successful
30
+ console.log(settings);
31
+ };
32
+
33
+ // Run the code
34
+ main();
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@flow-js/garmin-connect",
3
+ "version": "1.6.3",
4
+ "description": "Makes it simple to interface with Garmin Connect to get or set any data point",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc --build --clean && find ./dist -type d -empty -delete; tsc",
9
+ "build:windows": "tsc --build --clean && tsc",
10
+ "build:watch": "npm run build -- --watch",
11
+ "build:watch-windows": "npm run build:windows -- --watch",
12
+ "prettier:all": "prettier --write .",
13
+ "pretty": "pretty-quick --staged",
14
+ "prepack": "npm run build"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/florianpasteur/garmin-connect.git"
19
+ },
20
+ "keywords": [
21
+ "garmin",
22
+ "connect",
23
+ "scraper",
24
+ "weight",
25
+ "running",
26
+ "workout",
27
+ "activity",
28
+ "activities",
29
+ "download",
30
+ "downloader"
31
+ ],
32
+ "author": "Oskar Bernberg (Pythe1337N)",
33
+ "license": "MIT",
34
+ "files": [
35
+ "dist/*",
36
+ "examples/*"
37
+ ],
38
+ "devDependencies": {
39
+ "@types/app-root-path": "^1.2.4",
40
+ "@types/lodash": "^4.14.199",
41
+ "@types/luxon": "^3.3.2",
42
+ "@types/node": "^18.11.15",
43
+ "@types/qs": "^6.9.7",
44
+ "@types/request-promise": "^4.1.48",
45
+ "pre-commit": "^1.2.2",
46
+ "prettier": "^2.8.1",
47
+ "pretty-quick": "^3.1.3",
48
+ "ts-node": "^10.9.2",
49
+ "typescript": "^4.9.4"
50
+ },
51
+ "homepage": "https://github.com/florianpasteur/garmin-connect#readme",
52
+ "bugs": {
53
+ "url": "https://github.com/florianpasteur/garmin-connect/issues"
54
+ },
55
+ "runkitExampleFilename": "./examples/example.js",
56
+ "dependencies": {
57
+ "app-root-path": "^3.1.0",
58
+ "axios": "^1.5.1",
59
+ "crypto": "^1.0.1",
60
+ "form-data": "^4.0.0",
61
+ "lodash": "^4.17.21",
62
+ "luxon": "^3.4.3",
63
+ "oauth-1.0a": "^2.2.6",
64
+ "qs": "^6.11.2"
65
+ },
66
+ "pre-commit": "pretty"
67
+ }