@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.
- package/LICENSE +21 -0
- package/README.md +627 -0
- package/dist/common/CFClient.d.ts +22 -0
- package/dist/common/CFClient.js +137 -0
- package/dist/common/CFClient.js.map +1 -0
- package/dist/common/DateUtils.d.ts +1 -0
- package/dist/common/DateUtils.js +11 -0
- package/dist/common/DateUtils.js.map +1 -0
- package/dist/common/HttpClient.d.ts +37 -0
- package/dist/common/HttpClient.js +496 -0
- package/dist/common/HttpClient.js.map +1 -0
- package/dist/garmin/GarminConnect.d.ts +112 -0
- package/dist/garmin/GarminConnect.js +816 -0
- package/dist/garmin/GarminConnect.js.map +1 -0
- package/dist/garmin/UrlClass.d.ts +53 -0
- package/dist/garmin/UrlClass.js +267 -0
- package/dist/garmin/UrlClass.js.map +1 -0
- package/dist/garmin/Urls.d.ts +56 -0
- package/dist/garmin/Urls.js +88 -0
- package/dist/garmin/Urls.js.map +1 -0
- package/dist/garmin/common/DateUtils.d.ts +6 -0
- package/dist/garmin/common/DateUtils.js +38 -0
- package/dist/garmin/common/DateUtils.js.map +1 -0
- package/dist/garmin/common/GpxUtils.d.ts +2 -0
- package/dist/garmin/common/GpxUtils.js +28 -0
- package/dist/garmin/common/GpxUtils.js.map +1 -0
- package/dist/garmin/common/HydrationUtils.d.ts +2 -0
- package/dist/garmin/common/HydrationUtils.js +16 -0
- package/dist/garmin/common/HydrationUtils.js.map +1 -0
- package/dist/garmin/common/WeightUtils.d.ts +1 -0
- package/dist/garmin/common/WeightUtils.js +9 -0
- package/dist/garmin/common/WeightUtils.js.map +1 -0
- package/dist/garmin/types/activity.d.ts +408 -0
- package/dist/garmin/types/activity.js +27 -0
- package/dist/garmin/types/activity.js.map +1 -0
- package/dist/garmin/types/gear.d.ts +20 -0
- package/dist/garmin/types/gear.js +3 -0
- package/dist/garmin/types/gear.js.map +1 -0
- package/dist/garmin/types/golf.d.ts +67 -0
- package/dist/garmin/types/golf.js +3 -0
- package/dist/garmin/types/golf.js.map +1 -0
- package/dist/garmin/types/gpx.d.ts +171 -0
- package/dist/garmin/types/gpx.js +15 -0
- package/dist/garmin/types/gpx.js.map +1 -0
- package/dist/garmin/types/heartrate.d.ts +22 -0
- package/dist/garmin/types/heartrate.js +2 -0
- package/dist/garmin/types/heartrate.js.map +1 -0
- package/dist/garmin/types/hydration.d.ts +28 -0
- package/dist/garmin/types/hydration.js +2 -0
- package/dist/garmin/types/hydration.js.map +1 -0
- package/dist/garmin/types/index.d.ts +445 -0
- package/dist/garmin/types/index.js +37 -0
- package/dist/garmin/types/index.js.map +1 -0
- package/dist/garmin/types/sleep.d.ts +120 -0
- package/dist/garmin/types/sleep.js +3 -0
- package/dist/garmin/types/sleep.js.map +1 -0
- package/dist/garmin/types/weight.d.ts +42 -0
- package/dist/garmin/types/weight.js +3 -0
- package/dist/garmin/types/weight.js.map +1 -0
- package/dist/garmin/types/workout-builder.d.ts +138 -0
- package/dist/garmin/types/workout-builder.js +286 -0
- package/dist/garmin/types/workout-builder.js.map +1 -0
- package/dist/garmin/types/workout.d.ts +56 -0
- package/dist/garmin/types/workout.js +3 -0
- package/dist/garmin/types/workout.js.map +1 -0
- package/dist/garmin/types.d.ts +504 -0
- package/dist/garmin/types.js +3 -0
- package/dist/garmin/types.js.map +1 -0
- package/dist/garmin/workout-builder/duration.d.ts +87 -0
- package/dist/garmin/workout-builder/duration.js +173 -0
- package/dist/garmin/workout-builder/duration.js.map +1 -0
- package/dist/garmin/workout-builder/index.d.ts +5 -0
- package/dist/garmin/workout-builder/index.js +22 -0
- package/dist/garmin/workout-builder/index.js.map +1 -0
- package/dist/garmin/workout-builder/step.d.ts +28 -0
- package/dist/garmin/workout-builder/step.js +60 -0
- package/dist/garmin/workout-builder/step.js.map +1 -0
- package/dist/garmin/workout-builder/target.d.ts +49 -0
- package/dist/garmin/workout-builder/target.js +193 -0
- package/dist/garmin/workout-builder/target.js.map +1 -0
- package/dist/garmin/workout-builder/workout-builder.d.ts +12 -0
- package/dist/garmin/workout-builder/workout-builder.js +37 -0
- package/dist/garmin/workout-builder/workout-builder.js.map +1 -0
- package/dist/garmin/workout-builder/workout-type.d.ts +11 -0
- package/dist/garmin/workout-builder/workout-type.js +26 -0
- package/dist/garmin/workout-builder/workout-type.js.map +1 -0
- package/dist/garmin/workouts/Running.d.ts +16 -0
- package/dist/garmin/workouts/Running.js +64 -0
- 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 -0
- package/dist/garmin/workouts/templates/RunningTemplate.js.map +1 -0
- package/dist/garmin/workouts/workout-builder.d.ts +138 -0
- package/dist/garmin/workouts/workout-builder.js +286 -0
- package/dist/garmin/workouts/workout-builder.js.map +1 -0
- package/dist/garmin/workouts-builder/workout-builder.d.ts +138 -0
- package/dist/garmin/workouts-builder/workout-builder.js +286 -0
- package/dist/garmin/workouts-builder/workout-builder.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +26 -0
- 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/assets/paris-marathon.gpx +2037 -0
- package/examples/example-gpx-file.js +54 -0
- package/examples/example-workout.js +162 -0
- package/examples/example.js +34 -0
- package/package.json +67 -0
|
@@ -0,0 +1,816 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
+
switch (op[0]) {
|
|
55
|
+
case 0: case 1: t = op; break;
|
|
56
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
+
default:
|
|
60
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
+
if (t[2]) _.ops.pop();
|
|
65
|
+
_.trys.pop(); continue;
|
|
66
|
+
}
|
|
67
|
+
op = body.call(thisArg, _);
|
|
68
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
73
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
|
+
};
|
|
75
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
|
+
exports.Event = void 0;
|
|
77
|
+
var app_root_path_1 = __importDefault(require("app-root-path"));
|
|
78
|
+
var form_data_1 = __importDefault(require("form-data"));
|
|
79
|
+
var lodash_1 = __importDefault(require("lodash"));
|
|
80
|
+
var luxon_1 = require("luxon");
|
|
81
|
+
var fs = __importStar(require("fs"));
|
|
82
|
+
var path = __importStar(require("path"));
|
|
83
|
+
var HttpClient_1 = require("../common/HttpClient");
|
|
84
|
+
var utils_1 = require("../utils");
|
|
85
|
+
var UrlClass_1 = require("./UrlClass");
|
|
86
|
+
var types_1 = require("./types");
|
|
87
|
+
var Running_1 = __importDefault(require("./workouts/Running"));
|
|
88
|
+
var DateUtils_1 = require("./common/DateUtils");
|
|
89
|
+
var WeightUtils_1 = require("./common/WeightUtils");
|
|
90
|
+
var HydrationUtils_1 = require("./common/HydrationUtils");
|
|
91
|
+
var GpxUtils_1 = require("./common/GpxUtils");
|
|
92
|
+
var config = undefined;
|
|
93
|
+
try {
|
|
94
|
+
config = app_root_path_1.default.require('/garmin.config.json');
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
// Do nothing
|
|
98
|
+
}
|
|
99
|
+
var Event;
|
|
100
|
+
(function (Event) {
|
|
101
|
+
Event["sessionChange"] = "sessionChange";
|
|
102
|
+
})(Event = exports.Event || (exports.Event = {}));
|
|
103
|
+
var GarminConnect = /** @class */ (function () {
|
|
104
|
+
// private oauth1: OAuth;
|
|
105
|
+
function GarminConnect(credentials, domain) {
|
|
106
|
+
if (credentials === void 0) { credentials = config; }
|
|
107
|
+
if (domain === void 0) { domain = 'garmin.com'; }
|
|
108
|
+
if (!credentials) {
|
|
109
|
+
throw new Error('Missing credentials');
|
|
110
|
+
}
|
|
111
|
+
this.credentials = credentials;
|
|
112
|
+
this.url = new UrlClass_1.UrlClass(domain);
|
|
113
|
+
this.client = new HttpClient_1.HttpClient(this.url);
|
|
114
|
+
this._userHash = undefined;
|
|
115
|
+
this.listeners = {};
|
|
116
|
+
}
|
|
117
|
+
GarminConnect.prototype.login = function (username, password) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
switch (_a.label) {
|
|
121
|
+
case 0:
|
|
122
|
+
if (username && password) {
|
|
123
|
+
this.credentials.username = username;
|
|
124
|
+
this.credentials.password = password;
|
|
125
|
+
}
|
|
126
|
+
return [4 /*yield*/, this.client.login(this.credentials.username, this.credentials.password)];
|
|
127
|
+
case 1:
|
|
128
|
+
_a.sent();
|
|
129
|
+
return [2 /*return*/, this];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
GarminConnect.prototype.exportTokenToFile = function (dirPath) {
|
|
135
|
+
if (!(0, utils_1.checkIsDirectory)(dirPath)) {
|
|
136
|
+
(0, utils_1.createDirectory)(dirPath);
|
|
137
|
+
}
|
|
138
|
+
// save oauth1 to json
|
|
139
|
+
if (this.client.oauth1Token) {
|
|
140
|
+
(0, utils_1.writeToFile)(path.join(dirPath, 'oauth1_token.json'), JSON.stringify(this.client.oauth1Token));
|
|
141
|
+
}
|
|
142
|
+
if (this.client.oauth2Token) {
|
|
143
|
+
(0, utils_1.writeToFile)(path.join(dirPath, 'oauth2_token.json'), JSON.stringify(this.client.oauth2Token));
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
GarminConnect.prototype.loadTokenByFile = function (dirPath) {
|
|
147
|
+
if (!(0, utils_1.checkIsDirectory)(dirPath)) {
|
|
148
|
+
throw new Error('loadTokenByFile: Directory not found: ' + dirPath);
|
|
149
|
+
}
|
|
150
|
+
var oauth1Data = fs.readFileSync(path.join(dirPath, 'oauth1_token.json'));
|
|
151
|
+
var oauth1 = JSON.parse(oauth1Data);
|
|
152
|
+
this.client.oauth1Token = oauth1;
|
|
153
|
+
var oauth2Data = fs.readFileSync(path.join(dirPath, 'oauth2_token.json'));
|
|
154
|
+
var oauth2 = JSON.parse(oauth2Data);
|
|
155
|
+
this.client.oauth2Token = oauth2;
|
|
156
|
+
};
|
|
157
|
+
GarminConnect.prototype.exportToken = function () {
|
|
158
|
+
if (!this.client.oauth1Token || !this.client.oauth2Token) {
|
|
159
|
+
throw new Error('exportToken: Token not found');
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
oauth1: this.client.oauth1Token,
|
|
163
|
+
oauth2: this.client.oauth2Token
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
// from db or localstorage etc
|
|
167
|
+
GarminConnect.prototype.loadToken = function (oauth1, oauth2) {
|
|
168
|
+
this.client.oauth1Token = oauth1;
|
|
169
|
+
this.client.oauth2Token = oauth2;
|
|
170
|
+
};
|
|
171
|
+
GarminConnect.prototype.getUserSettings = function () {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
173
|
+
return __generator(this, function (_a) {
|
|
174
|
+
return [2 /*return*/, this.client.get(this.url.USER_SETTINGS)];
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
GarminConnect.prototype.getUserProfile = function () {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
return [2 /*return*/, this.client.get(this.url.USER_PROFILE)];
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
GarminConnect.prototype.getActivities = function (start, limit, activityType, subActivityType) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
+
return __generator(this, function (_a) {
|
|
188
|
+
return [2 /*return*/, this.client.get(this.url.ACTIVITIES, {
|
|
189
|
+
params: { start: start, limit: limit, activityType: activityType, subActivityType: subActivityType }
|
|
190
|
+
})];
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
GarminConnect.prototype.getActivity = function (activity) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
+
return __generator(this, function (_a) {
|
|
197
|
+
if (!activity.activityId)
|
|
198
|
+
throw new Error('Missing activityId');
|
|
199
|
+
return [2 /*return*/, this.client.get(this.url.ACTIVITY + activity.activityId)];
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
GarminConnect.prototype.countActivities = function () {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
+
return __generator(this, function (_a) {
|
|
206
|
+
return [2 /*return*/, this.client.get(this.url.STAT_ACTIVITIES, {
|
|
207
|
+
params: {
|
|
208
|
+
aggregation: 'lifetime',
|
|
209
|
+
startDate: '1970-01-01',
|
|
210
|
+
endDate: luxon_1.DateTime.now().toFormat('yyyy-MM-dd'),
|
|
211
|
+
metric: 'duration'
|
|
212
|
+
}
|
|
213
|
+
})];
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
GarminConnect.prototype.downloadOriginalActivityData = function (activity, dir, type) {
|
|
218
|
+
if (type === void 0) { type = 'zip'; }
|
|
219
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
+
var fileBuffer;
|
|
221
|
+
return __generator(this, function (_a) {
|
|
222
|
+
switch (_a.label) {
|
|
223
|
+
case 0:
|
|
224
|
+
if (!activity.activityId)
|
|
225
|
+
throw new Error('Missing activityId');
|
|
226
|
+
if (!(0, utils_1.checkIsDirectory)(dir)) {
|
|
227
|
+
(0, utils_1.createDirectory)(dir);
|
|
228
|
+
}
|
|
229
|
+
if (!(type === 'tcx')) return [3 /*break*/, 2];
|
|
230
|
+
return [4 /*yield*/, this.client.get(this.url.DOWNLOAD_TCX + activity.activityId)];
|
|
231
|
+
case 1:
|
|
232
|
+
fileBuffer = _a.sent();
|
|
233
|
+
return [3 /*break*/, 9];
|
|
234
|
+
case 2:
|
|
235
|
+
if (!(type === 'gpx')) return [3 /*break*/, 4];
|
|
236
|
+
return [4 /*yield*/, this.client.get(this.url.DOWNLOAD_GPX + activity.activityId)];
|
|
237
|
+
case 3:
|
|
238
|
+
fileBuffer = _a.sent();
|
|
239
|
+
return [3 /*break*/, 9];
|
|
240
|
+
case 4:
|
|
241
|
+
if (!(type === 'kml')) return [3 /*break*/, 6];
|
|
242
|
+
return [4 /*yield*/, this.client.get(this.url.DOWNLOAD_KML + activity.activityId)];
|
|
243
|
+
case 5:
|
|
244
|
+
fileBuffer = _a.sent();
|
|
245
|
+
return [3 /*break*/, 9];
|
|
246
|
+
case 6:
|
|
247
|
+
if (!(type === 'zip')) return [3 /*break*/, 8];
|
|
248
|
+
return [4 /*yield*/, this.client.get(this.url.DOWNLOAD_ZIP + activity.activityId, {
|
|
249
|
+
responseType: 'arraybuffer'
|
|
250
|
+
})];
|
|
251
|
+
case 7:
|
|
252
|
+
fileBuffer = _a.sent();
|
|
253
|
+
return [3 /*break*/, 9];
|
|
254
|
+
case 8: throw new Error('downloadOriginalActivityData - Invalid type: ' + type);
|
|
255
|
+
case 9:
|
|
256
|
+
(0, utils_1.writeToFile)(path.join(dir, "".concat(activity.activityId, ".").concat(type)), fileBuffer);
|
|
257
|
+
return [2 /*return*/];
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
GarminConnect.prototype.uploadActivity = function (file, format) {
|
|
263
|
+
var _a;
|
|
264
|
+
if (format === void 0) { format = 'fit'; }
|
|
265
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
266
|
+
var detectedFormat, fileBuffer, form, response;
|
|
267
|
+
return __generator(this, function (_b) {
|
|
268
|
+
switch (_b.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
detectedFormat = (_a = (format || path.extname(file))) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
271
|
+
if (!lodash_1.default.includes(types_1.UploadFileType, detectedFormat)) {
|
|
272
|
+
throw new Error('uploadActivity - Invalid format: ' + format);
|
|
273
|
+
}
|
|
274
|
+
fileBuffer = fs.createReadStream(file);
|
|
275
|
+
form = new form_data_1.default();
|
|
276
|
+
form.append('userfile', fileBuffer);
|
|
277
|
+
return [4 /*yield*/, this.client.post(this.url.UPLOAD + '.' + format, form, {
|
|
278
|
+
headers: {
|
|
279
|
+
'Content-Type': form.getHeaders()['content-type']
|
|
280
|
+
}
|
|
281
|
+
})];
|
|
282
|
+
case 1:
|
|
283
|
+
response = _b.sent();
|
|
284
|
+
return [2 /*return*/, response];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
GarminConnect.prototype.deleteActivity = function (activity) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
+
return __generator(this, function (_a) {
|
|
292
|
+
switch (_a.label) {
|
|
293
|
+
case 0:
|
|
294
|
+
if (!activity.activityId)
|
|
295
|
+
throw new Error('Missing activityId');
|
|
296
|
+
return [4 /*yield*/, this.client.delete(this.url.ACTIVITY + activity.activityId)];
|
|
297
|
+
case 1:
|
|
298
|
+
_a.sent();
|
|
299
|
+
return [2 /*return*/];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
GarminConnect.prototype.getWorkouts = function (start, limit) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
306
|
+
return __generator(this, function (_a) {
|
|
307
|
+
return [2 /*return*/, this.client.get(this.url.WORKOUTS, {
|
|
308
|
+
params: {
|
|
309
|
+
start: start,
|
|
310
|
+
limit: limit
|
|
311
|
+
}
|
|
312
|
+
})];
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
GarminConnect.prototype.getWorkoutDetail = function (workout) {
|
|
317
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
318
|
+
return __generator(this, function (_a) {
|
|
319
|
+
if (!workout.workoutId)
|
|
320
|
+
throw new Error('Missing workoutId');
|
|
321
|
+
return [2 /*return*/, this.client.get(this.url.WORKOUT(workout.workoutId))];
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
GarminConnect.prototype.createWorkout = function (workout) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
327
|
+
return __generator(this, function (_a) {
|
|
328
|
+
return [2 /*return*/, this.client.post(this.url.WORKOUT(), workout)];
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
GarminConnect.prototype.addWorkout = function (workout) {
|
|
333
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
334
|
+
var data, newWorkout;
|
|
335
|
+
return __generator(this, function (_a) {
|
|
336
|
+
if (!workout)
|
|
337
|
+
throw new Error('Missing workout');
|
|
338
|
+
if (workout instanceof Running_1.default) {
|
|
339
|
+
if (workout.isValid()) {
|
|
340
|
+
data = __assign({}, workout.toJson());
|
|
341
|
+
if (!data.description) {
|
|
342
|
+
data.description = 'Added by garmin-connect for Node.js';
|
|
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
|
+
};
|
|
374
|
+
GarminConnect.prototype.deleteWorkout = function (workout) {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
376
|
+
return __generator(this, function (_a) {
|
|
377
|
+
if (!workout.workoutId)
|
|
378
|
+
throw new Error('Missing workout');
|
|
379
|
+
return [2 /*return*/, this.client.delete(this.url.WORKOUT(workout.workoutId))];
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Schedule a workout by workoutId to a specific date
|
|
385
|
+
* @param workout - with workoutId
|
|
386
|
+
* @param scheduleDate - 'YYYY-MM-DD'
|
|
387
|
+
*/
|
|
388
|
+
GarminConnect.prototype.scheduleWorkout = function (workout, scheduleDate) {
|
|
389
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
390
|
+
return __generator(this, function (_a) {
|
|
391
|
+
return [2 /*return*/, this.client.post(this.url.SCHEDULE_WORKOUT(parseInt(workout.workoutId)), { date: scheduleDate })];
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
};
|
|
395
|
+
GarminConnect.prototype.getSteps = function (date) {
|
|
396
|
+
if (date === void 0) { date = new Date(); }
|
|
397
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
+
var dateString, days, dayStats;
|
|
399
|
+
return __generator(this, function (_a) {
|
|
400
|
+
switch (_a.label) {
|
|
401
|
+
case 0:
|
|
402
|
+
dateString = (0, DateUtils_1.toDateString)(date);
|
|
403
|
+
return [4 /*yield*/, this.client.get("".concat(this.url.DAILY_STEPS).concat(dateString, "/").concat(dateString))];
|
|
404
|
+
case 1:
|
|
405
|
+
days = _a.sent();
|
|
406
|
+
dayStats = days.find(function (_a) {
|
|
407
|
+
var calendarDate = _a.calendarDate;
|
|
408
|
+
return calendarDate === dateString;
|
|
409
|
+
});
|
|
410
|
+
if (!dayStats) {
|
|
411
|
+
throw new Error("Can't find daily steps for this date.");
|
|
412
|
+
}
|
|
413
|
+
return [2 /*return*/, dayStats.totalSteps];
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
GarminConnect.prototype.getSleepData = function (date) {
|
|
419
|
+
if (date === void 0) { date = new Date(); }
|
|
420
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
421
|
+
var dateString, sleepData, error_1;
|
|
422
|
+
return __generator(this, function (_a) {
|
|
423
|
+
switch (_a.label) {
|
|
424
|
+
case 0:
|
|
425
|
+
_a.trys.push([0, 2, , 3]);
|
|
426
|
+
dateString = (0, DateUtils_1.toDateString)(date);
|
|
427
|
+
return [4 /*yield*/, this.client.get("".concat(this.url.DAILY_SLEEP), { params: { date: dateString } })];
|
|
428
|
+
case 1:
|
|
429
|
+
sleepData = _a.sent();
|
|
430
|
+
if (!sleepData) {
|
|
431
|
+
throw new Error('Invalid or empty sleep data response.');
|
|
432
|
+
}
|
|
433
|
+
return [2 /*return*/, sleepData];
|
|
434
|
+
case 2:
|
|
435
|
+
error_1 = _a.sent();
|
|
436
|
+
throw new Error("Error in getSleepData: ".concat(error_1.message));
|
|
437
|
+
case 3: return [2 /*return*/];
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
GarminConnect.prototype.getSleepDuration = function (date) {
|
|
443
|
+
if (date === void 0) { date = new Date(); }
|
|
444
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
445
|
+
var sleepData, sleepStartTimestampGMT, sleepEndTimestampGMT, _a, hours, minutes, error_2;
|
|
446
|
+
return __generator(this, function (_b) {
|
|
447
|
+
switch (_b.label) {
|
|
448
|
+
case 0:
|
|
449
|
+
_b.trys.push([0, 2, , 3]);
|
|
450
|
+
return [4 /*yield*/, this.getSleepData(date)];
|
|
451
|
+
case 1:
|
|
452
|
+
sleepData = _b.sent();
|
|
453
|
+
if (!sleepData ||
|
|
454
|
+
!sleepData.dailySleepDTO ||
|
|
455
|
+
sleepData.dailySleepDTO.sleepStartTimestampGMT === undefined ||
|
|
456
|
+
sleepData.dailySleepDTO.sleepEndTimestampGMT === undefined) {
|
|
457
|
+
throw new Error('Invalid or missing sleep data for the specified date.');
|
|
458
|
+
}
|
|
459
|
+
sleepStartTimestampGMT = sleepData.dailySleepDTO.sleepStartTimestampGMT;
|
|
460
|
+
sleepEndTimestampGMT = sleepData.dailySleepDTO.sleepEndTimestampGMT;
|
|
461
|
+
_a = (0, DateUtils_1.calculateTimeDifference)(sleepStartTimestampGMT, sleepEndTimestampGMT), hours = _a.hours, minutes = _a.minutes;
|
|
462
|
+
return [2 /*return*/, {
|
|
463
|
+
hours: hours,
|
|
464
|
+
minutes: minutes
|
|
465
|
+
}];
|
|
466
|
+
case 2:
|
|
467
|
+
error_2 = _b.sent();
|
|
468
|
+
throw new Error("Error in getSleepDuration: ".concat(error_2.message));
|
|
469
|
+
case 3: return [2 /*return*/];
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
GarminConnect.prototype.getDailyWeightData = function (date) {
|
|
475
|
+
if (date === void 0) { date = new Date(); }
|
|
476
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
477
|
+
var dateString, weightData, error_3;
|
|
478
|
+
return __generator(this, function (_a) {
|
|
479
|
+
switch (_a.label) {
|
|
480
|
+
case 0:
|
|
481
|
+
_a.trys.push([0, 2, , 3]);
|
|
482
|
+
dateString = (0, DateUtils_1.toDateString)(date);
|
|
483
|
+
return [4 /*yield*/, this.client.get("".concat(this.url.DAILY_WEIGHT, "/").concat(dateString))];
|
|
484
|
+
case 1:
|
|
485
|
+
weightData = _a.sent();
|
|
486
|
+
if (!weightData) {
|
|
487
|
+
throw new Error('Invalid or empty weight data response.');
|
|
488
|
+
}
|
|
489
|
+
return [2 /*return*/, weightData];
|
|
490
|
+
case 2:
|
|
491
|
+
error_3 = _a.sent();
|
|
492
|
+
throw new Error("Error in getDailyWeightData: ".concat(error_3.message));
|
|
493
|
+
case 3: return [2 /*return*/];
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
GarminConnect.prototype.getDailyWeightInPounds = function (date) {
|
|
499
|
+
if (date === void 0) { date = new Date(); }
|
|
500
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
501
|
+
var weightData;
|
|
502
|
+
return __generator(this, function (_a) {
|
|
503
|
+
switch (_a.label) {
|
|
504
|
+
case 0: return [4 /*yield*/, this.getDailyWeightData(date)];
|
|
505
|
+
case 1:
|
|
506
|
+
weightData = _a.sent();
|
|
507
|
+
if (weightData.totalAverage &&
|
|
508
|
+
typeof weightData.totalAverage.weight === 'number') {
|
|
509
|
+
return [2 /*return*/, (0, WeightUtils_1.gramsToPounds)(weightData.totalAverage.weight)];
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
throw new Error("Can't find valid daily weight for this date.");
|
|
513
|
+
}
|
|
514
|
+
return [2 /*return*/];
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
GarminConnect.prototype.getDailyHydration = function (date) {
|
|
520
|
+
if (date === void 0) { date = new Date(); }
|
|
521
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
522
|
+
var dateString, hydrationData, error_4;
|
|
523
|
+
return __generator(this, function (_a) {
|
|
524
|
+
switch (_a.label) {
|
|
525
|
+
case 0:
|
|
526
|
+
_a.trys.push([0, 2, , 3]);
|
|
527
|
+
dateString = (0, DateUtils_1.toDateString)(date);
|
|
528
|
+
return [4 /*yield*/, this.client.get("".concat(this.url.DAILY_HYDRATION, "/").concat(dateString))];
|
|
529
|
+
case 1:
|
|
530
|
+
hydrationData = _a.sent();
|
|
531
|
+
if (!hydrationData || !hydrationData.valueInML) {
|
|
532
|
+
throw new Error('Invalid or empty hydration data response.');
|
|
533
|
+
}
|
|
534
|
+
return [2 /*return*/, (0, HydrationUtils_1.convertMLToOunces)(hydrationData.valueInML)];
|
|
535
|
+
case 2:
|
|
536
|
+
error_4 = _a.sent();
|
|
537
|
+
throw new Error("Error in getDailyHydration: ".concat(error_4.message));
|
|
538
|
+
case 3: return [2 /*return*/];
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
GarminConnect.prototype.updateWeight = function (date, lbs, timezone) {
|
|
544
|
+
if (date === void 0) { date = new Date(); }
|
|
545
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
546
|
+
var weightData, error_5;
|
|
547
|
+
return __generator(this, function (_a) {
|
|
548
|
+
switch (_a.label) {
|
|
549
|
+
case 0:
|
|
550
|
+
_a.trys.push([0, 2, , 3]);
|
|
551
|
+
return [4 /*yield*/, this.client.post("".concat(this.url.UPDATE_WEIGHT), {
|
|
552
|
+
dateTimestamp: (0, DateUtils_1.getLocalTimestamp)(date, timezone),
|
|
553
|
+
gmtTimestamp: date.toISOString().substring(0, 23),
|
|
554
|
+
unitKey: 'lbs',
|
|
555
|
+
value: lbs
|
|
556
|
+
})];
|
|
557
|
+
case 1:
|
|
558
|
+
weightData = _a.sent();
|
|
559
|
+
return [2 /*return*/, weightData];
|
|
560
|
+
case 2:
|
|
561
|
+
error_5 = _a.sent();
|
|
562
|
+
throw new Error("Error in updateWeight: ".concat(error_5.message));
|
|
563
|
+
case 3: return [2 /*return*/];
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
GarminConnect.prototype.updateHydrationLogOunces = function (date, valueInOz) {
|
|
569
|
+
if (date === void 0) { date = new Date(); }
|
|
570
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
571
|
+
var dateString, hydrationData, _a, _b, _c, error_6;
|
|
572
|
+
var _d;
|
|
573
|
+
return __generator(this, function (_e) {
|
|
574
|
+
switch (_e.label) {
|
|
575
|
+
case 0:
|
|
576
|
+
_e.trys.push([0, 3, , 4]);
|
|
577
|
+
dateString = (0, DateUtils_1.toDateString)(date);
|
|
578
|
+
_b = (_a = this.client).put;
|
|
579
|
+
_c = ["".concat(this.url.HYDRATION_LOG)];
|
|
580
|
+
_d = {
|
|
581
|
+
calendarDate: dateString,
|
|
582
|
+
valueInML: (0, HydrationUtils_1.convertOuncesToML)(valueInOz)
|
|
583
|
+
};
|
|
584
|
+
return [4 /*yield*/, this.getUserProfile()];
|
|
585
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.userProfileId = (_e.sent()).profileId,
|
|
586
|
+
_d.timestampLocal = date.toISOString().substring(0, 23),
|
|
587
|
+
_d)]))];
|
|
588
|
+
case 2:
|
|
589
|
+
hydrationData = _e.sent();
|
|
590
|
+
return [2 /*return*/, hydrationData];
|
|
591
|
+
case 3:
|
|
592
|
+
error_6 = _e.sent();
|
|
593
|
+
throw new Error("Error in updateHydrationLogOunces: ".concat(error_6.message));
|
|
594
|
+
case 4: return [2 /*return*/];
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
GarminConnect.prototype.getGolfSummary = function () {
|
|
600
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
601
|
+
var golfSummary, error_7;
|
|
602
|
+
return __generator(this, function (_a) {
|
|
603
|
+
switch (_a.label) {
|
|
604
|
+
case 0:
|
|
605
|
+
_a.trys.push([0, 2, , 3]);
|
|
606
|
+
return [4 /*yield*/, this.client.get("".concat(this.url.GOLF_SCORECARD_SUMMARY))];
|
|
607
|
+
case 1:
|
|
608
|
+
golfSummary = _a.sent();
|
|
609
|
+
if (!golfSummary) {
|
|
610
|
+
throw new Error('Invalid or empty golf summary data response.');
|
|
611
|
+
}
|
|
612
|
+
return [2 /*return*/, golfSummary];
|
|
613
|
+
case 2:
|
|
614
|
+
error_7 = _a.sent();
|
|
615
|
+
throw new Error("Error in getGolfSummary: ".concat(error_7.message));
|
|
616
|
+
case 3: return [2 /*return*/];
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
};
|
|
621
|
+
GarminConnect.prototype.getGolfScorecard = function (scorecardId) {
|
|
622
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
623
|
+
var golfScorecard, error_8;
|
|
624
|
+
return __generator(this, function (_a) {
|
|
625
|
+
switch (_a.label) {
|
|
626
|
+
case 0:
|
|
627
|
+
_a.trys.push([0, 2, , 3]);
|
|
628
|
+
return [4 /*yield*/, this.client.get("".concat(this.url.GOLF_SCORECARD_DETAIL), { params: { 'scorecard-ids': scorecardId } })];
|
|
629
|
+
case 1:
|
|
630
|
+
golfScorecard = _a.sent();
|
|
631
|
+
if (!golfScorecard) {
|
|
632
|
+
throw new Error('Invalid or empty golf scorecard data response.');
|
|
633
|
+
}
|
|
634
|
+
return [2 /*return*/, golfScorecard];
|
|
635
|
+
case 2:
|
|
636
|
+
error_8 = _a.sent();
|
|
637
|
+
throw new Error("Error in getGolfScorecard: ".concat(error_8.message));
|
|
638
|
+
case 3: return [2 /*return*/];
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
};
|
|
643
|
+
GarminConnect.prototype.getHeartRate = function (date) {
|
|
644
|
+
if (date === void 0) { date = new Date(); }
|
|
645
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
646
|
+
var dateString, heartRate, error_9;
|
|
647
|
+
return __generator(this, function (_a) {
|
|
648
|
+
switch (_a.label) {
|
|
649
|
+
case 0:
|
|
650
|
+
_a.trys.push([0, 2, , 3]);
|
|
651
|
+
dateString = (0, DateUtils_1.toDateString)(date);
|
|
652
|
+
return [4 /*yield*/, this.client.get("".concat(this.url.DAILY_HEART_RATE), { params: { date: dateString } })];
|
|
653
|
+
case 1:
|
|
654
|
+
heartRate = _a.sent();
|
|
655
|
+
return [2 /*return*/, heartRate];
|
|
656
|
+
case 2:
|
|
657
|
+
error_9 = _a.sent();
|
|
658
|
+
throw new Error("Error in getHeartRate: ".concat(error_9.message));
|
|
659
|
+
case 3: return [2 /*return*/];
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
};
|
|
664
|
+
/**
|
|
665
|
+
* Returns the gear data for the user.
|
|
666
|
+
* @param availableGearDate - Optional date to filter the gear available at the date (format: 'YYYY-MM-DD').
|
|
667
|
+
*/
|
|
668
|
+
GarminConnect.prototype.getGear = function (availableGearDate) {
|
|
669
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
670
|
+
var id;
|
|
671
|
+
return __generator(this, function (_a) {
|
|
672
|
+
switch (_a.label) {
|
|
673
|
+
case 0: return [4 /*yield*/, this.getUserProfile()];
|
|
674
|
+
case 1:
|
|
675
|
+
id = (_a.sent()).profileId;
|
|
676
|
+
return [2 /*return*/, this.client.get(this.url.GEAR(id, availableGearDate))];
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
};
|
|
681
|
+
/**
|
|
682
|
+
* Returns the gear data assigned with a specific activity.
|
|
683
|
+
* @param activityId
|
|
684
|
+
*/
|
|
685
|
+
GarminConnect.prototype.getGearsForActivity = function (activityId) {
|
|
686
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
687
|
+
return __generator(this, function (_a) {
|
|
688
|
+
return [2 /*return*/, this.client.get(this.url.GEAR_OF_ACTIVITY(activityId))];
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
/**
|
|
693
|
+
* Links a gear item to an activity.
|
|
694
|
+
* @param activityId
|
|
695
|
+
* @param gearId - uuid field from GearData
|
|
696
|
+
* @return GearData - the linked gear item data
|
|
697
|
+
*/
|
|
698
|
+
GarminConnect.prototype.linkGearToActivity = function (activityId, gearId) {
|
|
699
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
700
|
+
return __generator(this, function (_a) {
|
|
701
|
+
return [2 /*return*/, this.client.put(this.url.LINK_GEAR_TO_ACTIVITY(activityId, gearId), {})];
|
|
702
|
+
});
|
|
703
|
+
});
|
|
704
|
+
};
|
|
705
|
+
/**
|
|
706
|
+
* Unlinks a gear item from an activity.
|
|
707
|
+
* @param activityId
|
|
708
|
+
* @param gearId - uuid field from GearData
|
|
709
|
+
* @return GearData - the unlinked gear item data
|
|
710
|
+
*/
|
|
711
|
+
GarminConnect.prototype.unlinkGearFromActivity = function (activityId, gearId) {
|
|
712
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
713
|
+
return __generator(this, function (_a) {
|
|
714
|
+
return [2 /*return*/, this.client.put(this.url.UNLINK_GEAR_FROM_ACTIVITY(activityId, gearId), {})];
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
};
|
|
718
|
+
GarminConnect.prototype.workouts = function () {
|
|
719
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
720
|
+
return __generator(this, function (_a) {
|
|
721
|
+
return [2 /*return*/, this.client.get(this.url.WORKOUTS_LIST())];
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
};
|
|
725
|
+
GarminConnect.prototype.importGpx = function (fileName, fileContent) {
|
|
726
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
727
|
+
var form;
|
|
728
|
+
return __generator(this, function (_a) {
|
|
729
|
+
switch (_a.label) {
|
|
730
|
+
case 0:
|
|
731
|
+
form = new form_data_1.default();
|
|
732
|
+
form.append('file', fileContent, {
|
|
733
|
+
filename: fileName,
|
|
734
|
+
contentType: 'application/octet-stream'
|
|
735
|
+
});
|
|
736
|
+
return [4 /*yield*/, this.client.post(this.url.IMPORT_GPX_FILE, form, {
|
|
737
|
+
headers: {
|
|
738
|
+
'Content-Type': form.getHeaders()['content-type'],
|
|
739
|
+
'Content-Length': form.getLengthSync()
|
|
740
|
+
}
|
|
741
|
+
})];
|
|
742
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
};
|
|
747
|
+
GarminConnect.prototype.createCourse = function (activityType, courseName, geoPoints, coursePoints) {
|
|
748
|
+
if (coursePoints === void 0) { coursePoints = []; }
|
|
749
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
750
|
+
return __generator(this, function (_a) {
|
|
751
|
+
switch (_a.label) {
|
|
752
|
+
case 0: return [4 /*yield*/, this.client.post(this.url.CREATE_COURSE_GPX_FILE, (0, GpxUtils_1.courseRequestTemplate)(activityType, courseName, geoPoints, coursePoints), {})];
|
|
753
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
};
|
|
758
|
+
GarminConnect.prototype.listCourses = function () {
|
|
759
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
760
|
+
return __generator(this, function (_a) {
|
|
761
|
+
return [2 /*return*/, this.client.get(this.url.LIST_COURSES)];
|
|
762
|
+
});
|
|
763
|
+
});
|
|
764
|
+
};
|
|
765
|
+
GarminConnect.prototype.exportCourseAsGpx = function (courseId) {
|
|
766
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
767
|
+
return __generator(this, function (_a) {
|
|
768
|
+
return [2 /*return*/, this.client.get(this.url.EXPORT_COURSE_GPX_FILE(courseId), {
|
|
769
|
+
responseType: 'text'
|
|
770
|
+
})];
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
};
|
|
774
|
+
GarminConnect.prototype.get = function (url, data) {
|
|
775
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
776
|
+
var response;
|
|
777
|
+
return __generator(this, function (_a) {
|
|
778
|
+
switch (_a.label) {
|
|
779
|
+
case 0: return [4 /*yield*/, this.client.get(url, data)];
|
|
780
|
+
case 1:
|
|
781
|
+
response = _a.sent();
|
|
782
|
+
return [2 /*return*/, response];
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
};
|
|
787
|
+
GarminConnect.prototype.post = function (url, data) {
|
|
788
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
789
|
+
var response;
|
|
790
|
+
return __generator(this, function (_a) {
|
|
791
|
+
switch (_a.label) {
|
|
792
|
+
case 0: return [4 /*yield*/, this.client.post(url, data, {})];
|
|
793
|
+
case 1:
|
|
794
|
+
response = _a.sent();
|
|
795
|
+
return [2 /*return*/, response];
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
};
|
|
800
|
+
GarminConnect.prototype.put = function (url, data) {
|
|
801
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
802
|
+
var response;
|
|
803
|
+
return __generator(this, function (_a) {
|
|
804
|
+
switch (_a.label) {
|
|
805
|
+
case 0: return [4 /*yield*/, this.client.put(url, data, {})];
|
|
806
|
+
case 1:
|
|
807
|
+
response = _a.sent();
|
|
808
|
+
return [2 /*return*/, response];
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
});
|
|
812
|
+
};
|
|
813
|
+
return GarminConnect;
|
|
814
|
+
}());
|
|
815
|
+
exports.default = GarminConnect;
|
|
816
|
+
//# sourceMappingURL=GarminConnect.js.map
|